diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-23 22:53:08 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-23 22:53:08 +0200 |
commit | 16f44ab7de445e153d949a611104f9ca1cac265c (patch) | |
tree | 8abf5a3442a1877855f2c80d9482611a04922683 /source/Mobs | |
parent | Source files cleanup: WorldStorage-related files in a separate subfolder (diff) | |
download | cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar.gz cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar.bz2 cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar.lz cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar.xz cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.tar.zst cuberite-16f44ab7de445e153d949a611104f9ca1cac265c.zip |
Diffstat (limited to 'source/Mobs')
40 files changed, 1986 insertions, 0 deletions
diff --git a/source/Mobs/AggressiveMonster.cpp b/source/Mobs/AggressiveMonster.cpp new file mode 100644 index 000000000..2a5370968 --- /dev/null +++ b/source/Mobs/AggressiveMonster.cpp @@ -0,0 +1,78 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "AggressiveMonster.h" + +#include "../Vector3f.h" +#include "../cPlayer.h" +#include "../MersenneTwister.h" + + +cAggressiveMonster::cAggressiveMonster() + : m_ChaseTime(999999) +{ + m_EMPersonality = AGGRESSIVE; +} + +cAggressiveMonster::~cAggressiveMonster() +{ +} + +//What to do if in Chasing State +void cAggressiveMonster::InStateChasing(float a_Dt) { + cMonster::InStateChasing(a_Dt); + m_ChaseTime += a_Dt; + if( m_Target ) + { + if(m_Target->GetEntityType() == cEntity::eEntityType_Player) + { + cPlayer * Player = (cPlayer *) m_Target; + if(Player->GetGameMode() == 1) + { + m_EMState = IDLE; + return; + } + } + + Vector3f Pos = Vector3f( m_Pos ); + Vector3f Their = Vector3f( m_Target->GetPosition() ); + if( (Their - Pos).Length() <= m_AttackRange) { + cMonster::Attack(a_Dt); + } + MoveToPosition( Their + Vector3f(0, 0.65f, 0) ); + } else if( m_ChaseTime > 5.f ) { + m_ChaseTime = 0; + m_EMState = IDLE; + } +} + + + +void cAggressiveMonster::EventSeePlayer(cEntity *a_Entity) +{ + cMonster::EventSeePlayer(a_Entity); + m_EMState = CHASING; +} + +void cAggressiveMonster::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + m_SeePlayerInterval += a_Dt; + + if(m_SeePlayerInterval > 1) + { + MTRand r1; + int rem = r1.randInt() % 3 + 1; //check most of the time but miss occasionally + + m_SeePlayerInterval = 0.0; + if(rem >= 2) + { + if(m_EMState == CHASING){ + CheckEventLostPlayer(); + } else { + CheckEventSeePlayer(); + } + } + } +}
\ No newline at end of file diff --git a/source/Mobs/AggressiveMonster.h b/source/Mobs/AggressiveMonster.h new file mode 100644 index 000000000..7d741dc9a --- /dev/null +++ b/source/Mobs/AggressiveMonster.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Monster.h" + +class cAggressiveMonster : public cMonster +{ +public: + cAggressiveMonster(); + ~cAggressiveMonster(); + + virtual void Tick(float a_Dt); + virtual void InStateChasing(float a_Dt); + + virtual void EventSeePlayer(cEntity *); +protected: + float m_ChaseTime; +}; diff --git a/source/Mobs/Cavespider.cpp b/source/Mobs/Cavespider.cpp new file mode 100644 index 000000000..b2188da3d --- /dev/null +++ b/source/Mobs/Cavespider.cpp @@ -0,0 +1,59 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Cavespider.h" + + + + + +cCavespider::cCavespider() +{ + m_MobType = 59; + GetMonsterConfig("Cavespider"); +} + + + + + +cCavespider::~cCavespider() +{ +} + + + + + +bool cCavespider::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cCavespider" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cCavespider::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + m_EMPersonality = (GetWorld()->GetWorldTime() < (12000 + 1000) ) ? PASSIVE : AGGRESSIVE; +} + + + + + +void cCavespider::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_STRING); + AddRandomDropItem(Drops, 0, 1, E_ITEM_SPIDER_EYE); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Cavespider.h b/source/Mobs/Cavespider.h new file mode 100644 index 000000000..163bb1f92 --- /dev/null +++ b/source/Mobs/Cavespider.h @@ -0,0 +1,15 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cCavespider : public cAggressiveMonster +{ +public: + cCavespider(); + ~cCavespider(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void Tick(float a_Dt); + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Chicken.cpp b/source/Mobs/Chicken.cpp new file mode 100644 index 000000000..940491ad4 --- /dev/null +++ b/source/Mobs/Chicken.cpp @@ -0,0 +1,56 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Chicken.h" + + + + + +// TODO Drop egg every 5-10 minutes + + + + + +cChicken::cChicken() +{ + m_MobType = 93; + GetMonsterConfig("Chicken"); +} + + + + + +cChicken::~cChicken() +{ +} + + + + + +bool cChicken::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cChicken" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cChicken::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_FEATHER); + Drops.push_back(cItem((GetMetaData() == BURNING) ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN, 1)); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Chicken.h b/source/Mobs/Chicken.h new file mode 100644 index 000000000..acfb202e3 --- /dev/null +++ b/source/Mobs/Chicken.h @@ -0,0 +1,14 @@ +#pragma once + +#include "PassiveMonster.h" + +class cChicken : public cPassiveMonster +{ +public: + cChicken(); + ~cChicken(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Cow.cpp b/source/Mobs/Cow.cpp new file mode 100644 index 000000000..0d107e1b5 --- /dev/null +++ b/source/Mobs/Cow.cpp @@ -0,0 +1,56 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Cow.h" + + + + + +// TODO: Milk Cow + + + + + +cCow::cCow() +{ + m_MobType = 92; + GetMonsterConfig("Cow"); +} + + + + + +cCow::~cCow() +{ +} + + + + + +bool cCow::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cCow" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cCow::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_LEATHER); + AddRandomDropItem(Drops, 1, 3, (GetMetaData() == BURNING) ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Cow.h b/source/Mobs/Cow.h new file mode 100644 index 000000000..bb604bad4 --- /dev/null +++ b/source/Mobs/Cow.h @@ -0,0 +1,14 @@ +#pragma once + +#include "PassiveMonster.h" + +class cCow : public cPassiveMonster +{ +public: + cCow(); + ~cCow(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Creeper.cpp b/source/Mobs/Creeper.cpp new file mode 100644 index 000000000..b42d5690b --- /dev/null +++ b/source/Mobs/Creeper.cpp @@ -0,0 +1,52 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Creeper.h" + + + + + +cCreeper::cCreeper() +{ + m_MobType = 50; + GetMonsterConfig("Creeper"); +} + + + + + +cCreeper::~cCreeper() +{ +} + + + + + +bool cCreeper::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cCreeper" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cCreeper::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_GUNPOWDER); + + // TODO Check if killed by a skeleton, then drop random music disk + + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Creeper.h b/source/Mobs/Creeper.h new file mode 100644 index 000000000..e5c755103 --- /dev/null +++ b/source/Mobs/Creeper.h @@ -0,0 +1,14 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cCreeper : public cAggressiveMonster +{ +public: + cCreeper(); + ~cCreeper(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Enderman.cpp b/source/Mobs/Enderman.cpp new file mode 100644 index 000000000..36ee975b1 --- /dev/null +++ b/source/Mobs/Enderman.cpp @@ -0,0 +1,63 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Enderman.h" + + + + + +cEnderman::cEnderman() +{ + m_MobType = 58; + GetMonsterConfig("Enderman"); +} + + + + + +cEnderman::~cEnderman() +{ +} + + + + + +bool cEnderman::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cEnderman" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cEnderman::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + //TODO Same as stated in cSkeleton + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D + } +} + + + + + +void cEnderman::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 1, E_ITEM_ENDER_PEARL); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Enderman.h b/source/Mobs/Enderman.h new file mode 100644 index 000000000..788cc1314 --- /dev/null +++ b/source/Mobs/Enderman.h @@ -0,0 +1,15 @@ +#pragma once + +#include "PassiveAggressiveMonster.h" + +class cEnderman : public cPassiveAggressiveMonster +{ +public: + cEnderman(); + ~cEnderman(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void Tick(float a_Dt); + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Ghast.cpp b/source/Mobs/Ghast.cpp new file mode 100644 index 000000000..4993f25c0 --- /dev/null +++ b/source/Mobs/Ghast.cpp @@ -0,0 +1,49 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Ghast.h" + + + + + +cGhast::cGhast() +{ + m_MobType = 56; + GetMonsterConfig("Ghast"); +} + + + + + +cGhast::~cGhast() +{ +} + + + + + +bool cGhast::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cGhast" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cGhast::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_GUNPOWDER); + AddRandomDropItem(Drops, 0, 1, E_ITEM_GHAST_TEAR); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Ghast.h b/source/Mobs/Ghast.h new file mode 100644 index 000000000..6991419e7 --- /dev/null +++ b/source/Mobs/Ghast.h @@ -0,0 +1,14 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cGhast : public cAggressiveMonster +{ +public: + cGhast(); + ~cGhast(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp new file mode 100644 index 000000000..9142bd6a8 --- /dev/null +++ b/source/Mobs/Monster.cpp @@ -0,0 +1,590 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Monster.h" +#include "../cRoot.h" +#include "../cServer.h" +#include "../cClientHandle.h" +#include "../cWorld.h" +#include "../cPlayer.h" +#include "../Defines.h" +#include "../cMonsterConfig.h" +#include "../MersenneTwister.h" + +#include "../Vector3f.h" +#include "../Vector3i.h" +#include "../Vector3d.h" + +#include "../cTracer.h" +#include "../../iniFile/iniFile.h" + +/* +#ifndef _WIN32 + #include <unistd.h> +#endif +*/ + + + + + +cMonster::cMonster() + : m_Target(0) + , m_bMovingToDestination(false) + , m_DestinationTime( 0 ) + , m_Gravity( -9.81f) + , m_bOnGround( false ) + , m_DestroyTimer( 0 ) + , m_Jump(0) + , m_MobType( 0 ) + , m_EMState(IDLE) + , m_SightDistance(25) + , m_SeePlayerInterval (0) + , m_EMPersonality(AGGRESSIVE) + , m_AttackDamage(1.0f) + , m_AttackRange(5.0f) + , m_AttackInterval(0) + , m_AttackRate(3) + , idle_interval(0) +{ + LOG("cMonster::cMonster()"); + LOG("In state: %s", GetState()); + + m_bBurnable = true; + m_MetaData = NORMAL; +} + + + + + +cMonster::~cMonster() +{ + LOG("cMonster::~cMonster()"); +} + + + + + +bool cMonster::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cMonster" ) == 0 ) return true; + return cPawn::IsA( a_EntityType ); +} + + + + + +void cMonster::SpawnOn(cClientHandle & a_Client) +{ + a_Client.SendSpawnMob(*this); +} + + + + + +void cMonster::MoveToPosition( const Vector3f & a_Position ) +{ + m_bMovingToDestination = true; + + m_Destination = a_Position; +} + + + + + +bool cMonster::ReachedDestination() +{ + Vector3f Distance = (m_Destination) - Vector3f( m_Pos ); + if( Distance.SqrLength() < 2.f ) + return true; + + return false; +} + + + + + +void cMonster::Tick(float a_Dt) +{ + cPawn::Tick(a_Dt); + + if( m_Health <= 0 ) + { + m_DestroyTimer += a_Dt/1000; + if( m_DestroyTimer > 1 ) + { + Destroy(); + } + return; + } + + a_Dt /= 1000; + + if( m_bMovingToDestination ) + { + Vector3f Pos( m_Pos ); + Vector3f Distance = m_Destination - Pos; + if( !ReachedDestination() ) + { + Distance.y = 0; + Distance.Normalize(); + Distance *= 3; + m_Speed.x = Distance.x; + m_Speed.z = Distance.z; + + if (m_EMState == ESCAPING) + { //Runs Faster when escaping :D otherwise they just walk away + m_Speed.x *= 2.f; + m_Speed.z *= 2.f; + } + } + else + { + m_bMovingToDestination = false; + } + + if( m_Speed.SqrLength() > 0.f ) + { + if( m_bOnGround ) + { + Vector3f NormSpeed = m_Speed.NormalizeCopy(); + Vector3f NextBlock = Vector3f( m_Pos ) + NormSpeed; + double NextHeight = (double)GetWorld()->GetHeight( (int)NextBlock.x, (int)NextBlock.z ); + if( NextHeight > m_Pos.y - 1.2 && NextHeight - m_Pos.y < 2.5 ) + { + m_bOnGround = false; + m_Speed.y = 7.f; // Jump!! + } + } + } + } + + HandlePhysics( a_Dt ); + + ReplicateMovement(); + + Vector3f Distance = m_Destination - Vector3f( m_Pos ); + if (Distance.SqrLength() > 0.1f) + { + float Rotation, Pitch; + Distance.Normalize(); + VectorToEuler( Distance.x, Distance.y, Distance.z, Rotation, Pitch ); + SetRotation( Rotation ); + SetPitch( Pitch ); + } + + if (m_EMState == IDLE) + { + // If enemy passive we ignore checks for player visibility + InStateIdle(a_Dt); + } + + if (m_EMState == CHASING) + { + // If we do not see a player anymore skip chasing action + InStateChasing(a_Dt); + } + + if (m_EMState == ESCAPING) + { + InStateEscaping(a_Dt); + } +} + + + + + +void cMonster::ReplicateMovement() +{ + if (m_bDirtyOrientation && !m_bDirtyPosition) + { + m_World->BroadcastEntLook(*this); + m_bDirtyOrientation = false; + } + + if (m_bDirtyPosition) + { + float DiffX = (float)(GetPosX() - m_LastPosX); + float DiffY = (float)(GetPosY() - m_LastPosY); + float DiffZ = (float)(GetPosZ() - m_LastPosZ); + float SqrDist = DiffX * DiffX + DiffY * DiffY + DiffZ * DiffZ; + if ( + (SqrDist > 4 * 4) // 4 blocks is max Relative Move + || (cWorld::GetTime() - m_TimeLastTeleportPacket > 2) // Send an absolute position every 2 seconds + ) + { + // LOGD("Teleported %f", sqrtf(SqrDist) ); + m_World->BroadcastTeleportEntity(*this); + m_TimeLastTeleportPacket = cWorld::GetTime(); + } + else + { + // Relative move sucks balls! It's always wrong wtf! + if (m_bDirtyOrientation) + { + m_World->BroadcastEntRelMoveLook(*this, (char)(DiffX * 32), (char)(DiffY * 32), (char)(DiffZ * 32)); + m_bDirtyOrientation = false; + } + else + { + m_World->BroadcastEntRelMove(*this, (char)(DiffX * 32), (char)(DiffY * 32), (char)(DiffZ * 32)); + } + } + m_LastPosX = GetPosX(); + m_LastPosY = GetPosY(); + m_LastPosZ = GetPosZ(); + m_bDirtyPosition = false; + } + + MoveToCorrectChunk(); +} + + + + + +void cMonster::HandlePhysics(float a_Dt) +{ + if( m_bOnGround ) // check if it's still on the ground + { + cWorld* World = GetWorld(); + if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y -1, (int)m_Pos.z ) == E_BLOCK_AIR ) + { + m_bOnGround = false; + } + if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z ) != E_BLOCK_AIR ) // If in ground itself, push it out + { + m_bOnGround = true; + m_Pos.y += 0.2; + m_bDirtyPosition = true; + } + m_Speed.x *= 0.7f/(1+a_Dt); + if( fabs(m_Speed.x) < 0.05 ) m_Speed.x = 0; + m_Speed.z *= 0.7f/(1+a_Dt); + if( fabs(m_Speed.z) < 0.05 ) m_Speed.z = 0; + } + + if( !m_bOnGround ) + { + float Gravity = -9.81f*a_Dt; + m_Speed.y += Gravity; + } + + if( m_Speed.SqrLength() > 0.f ) + { + cTracer Tracer( GetWorld() ); + int Ret = Tracer.Trace( m_Pos, m_Speed, 2 ); + if( Ret ) // Oh noez! we hit something + { + // Set to hit position + if( (Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_Speed * a_Dt ).SqrLength() ) + { + if( Ret == 1 ) + { + + if( Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f; + if( Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f; + if( Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f; + + if( Tracer.HitNormal.y > 0 ) // means on ground + { + m_bOnGround = true; + } + } + m_Pos = Tracer.RealHit; + m_Pos += Tracer.HitNormal * 0.2f; + + } + else + m_Pos += m_Speed*a_Dt; + } + else + { // We didn't hit anything, so move =] + m_Pos += m_Speed*a_Dt; + } + + m_bDirtyPosition = true; + } +} + + + + + +void cMonster::TakeDamage(int a_Damage, cEntity* a_Instigator) +{ + cPawn::TakeDamage( a_Damage, a_Instigator ); + m_Target = a_Instigator; + AddReference( m_Target ); +} + + + + + +void cMonster::KilledBy( cEntity* a_Killer ) +{ + cPawn::KilledBy( a_Killer ); + m_DestroyTimer = 0; +} + + + + + +//----State Logic + +const char *cMonster::GetState() +{ + switch(m_EMState) + { + case IDLE: return "Idle"; + case ATTACKING: return "Attacking"; + case CHASING: return "Chasing"; + default: return "Unknown"; + } +} + + + + + +// for debugging +void cMonster::SetState(const AString & a_State) +{ + if (a_State.compare("Idle") == 0) + { + m_EMState = IDLE; + } + else if (a_State.compare("Attacking") == 0) + { + m_EMState = ATTACKING; + } + else if (a_State.compare("Chasing") == 0) + { + m_EMState = CHASING; + } + else + { + printf("Invalid State"); + } +} + + + + + +//Checks to see if EventSeePlayer should be fired +//monster sez: Do I see the player +void cMonster::CheckEventSeePlayer() +{ + cPlayer *Closest = FindClosestPlayer(); + + if (Closest) + { + EventSeePlayer(Closest); + } +} + + + + + +void cMonster::CheckEventLostPlayer() +{ + Vector3f pos; + cTracer LineOfSight(GetWorld()); + + if (m_Target != NULL) + { + pos = m_Target->GetPosition(); + if ((pos - m_Pos).Length() > m_SightDistance || LineOfSight.Trace(m_Pos,(pos - m_Pos), (int)(pos - m_Pos).Length())) + { + EventLosePlayer(); + } + } + else + { + EventLosePlayer(); + } +} + + + + + +// What to do if player is seen +// default to change state to chasing +void cMonster::EventSeePlayer(cEntity *a_SeenPlayer) +{ + m_Target = a_SeenPlayer; + AddReference( m_Target ); +} + + + + + +void cMonster::EventLosePlayer() +{ + Dereference(m_Target); + m_Target = 0; + m_EMState = IDLE; +} + + + + + +//What to do if in Idle State +void cMonster::InStateIdle(float a_Dt) +{ + idle_interval += a_Dt; + if (idle_interval > 1) + { + // at this interval the results are predictable + MTRand r1; + int rem = r1.randInt()%6 + 1; + // LOGD("Moving: int: %3.3f rem: %i",idle_interval,rem); + idle_interval -= 1; // So nothing gets dropped when the server hangs for a few seconds + Vector3f Dist; + Dist.x = (float)((r1.randInt()%11)-5); + Dist.z = (float)((r1.randInt()%11)-5); + if( Dist.SqrLength() > 2 && rem >= 3) + { + m_Destination.x = (float)(m_Pos.x + Dist.x); + m_Destination.z = (float)(m_Pos.z + Dist.z); + m_Destination.y = (float)GetWorld()->GetHeight( (int)m_Destination.x, (int)m_Destination.z ) + 1.2f; + MoveToPosition( m_Destination ); + } + } +} + + + + + +// What to do if in Chasing State +// This state should always be defined in each child class +void cMonster::InStateChasing(float a_Dt) +{ + UNUSED(a_Dt); +} + + + + + +// What to do if in Escaping State +void cMonster::InStateEscaping(float a_Dt) +{ + (void)a_Dt; + if(m_Target) + { + Vector3d newloc = m_Pos; + newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance); + newloc.z = (m_Target->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance); + MoveToPosition(newloc); + } + else + { + m_EMState = IDLE; //this shouldnt be required but just to be safe + } +} + + + + + +// Do attack here +// a_Dt is passed so we can set attack rate +void cMonster::Attack(float a_Dt) +{ + m_AttackInterval += a_Dt * m_AttackRate; + if ((m_Target != NULL) && (m_AttackInterval > 3.0)) + { + // Setting this higher gives us more wiggle room for attackrate + m_AttackInterval = 0.0; + ((cPawn *)m_Target)->TakeDamage((int)m_AttackDamage, this); + } +} + + + + + +// Checks for Players close by and if they are visible return the closest +cPlayer * cMonster::FindClosestPlayer(void) +{ + return m_World->FindClosestPlayer(m_Pos, m_SightDistance); +} + + + + + +void cMonster::GetMonsterConfig(const char* pm_name) +{ + cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, pm_name); +} + + + + + +void cMonster::SetAttackRate(int ar) +{ + m_AttackRate = (float)ar; +} + + + + + +void cMonster::SetAttackRange(float ar) +{ + m_AttackRange = ar; +} + + + + + +void cMonster::SetAttackDamage(float ad) +{ + m_AttackDamage = ad; +} + + + + + +void cMonster::SetSightDistance(float sd) +{ + m_SightDistance = sd; +} + + + + + +void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth) +{ + MTRand r1; + int Count = r1.randInt() % (a_Max + 1 - a_Min) + a_Min; + if (Count > 0) + { + a_Drops.push_back(cItem(a_Item, Count, a_ItemHealth)); + } +} + + + + diff --git a/source/Mobs/Monster.h b/source/Mobs/Monster.h new file mode 100644 index 000000000..0958d182c --- /dev/null +++ b/source/Mobs/Monster.h @@ -0,0 +1,101 @@ + +#pragma once + +#include "../cPawn.h" +#include "../Defines.h" +#include "../cWorld.h" +#include "../BlockID.h" +#include "../cItem.h" + + + + + +class Vector3f; +class cClientHandle; + + + + +class cMonster : public cPawn //tolua_export +{ //tolua_export +public: + + cMonster(); + virtual ~cMonster(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void SpawnOn(cClientHandle & a_ClientHandle) override; + + virtual void Tick(float a_Dt) override; + + virtual void HandlePhysics(float a_Dt); + virtual void ReplicateMovement(void); + + virtual void TakeDamage(int a_Damage, cEntity * a_Instigator) override; + virtual void KilledBy(cEntity * a_Killer) override; + + virtual void MoveToPosition(const Vector3f & a_Position); + virtual bool ReachedDestination(void); + + char GetMobType(void) const {return m_MobType; } + + const char * GetState(); + void SetState(const AString & str); + + virtual void CheckEventSeePlayer(); + virtual void EventSeePlayer(cEntity *); + float m_SightDistance; + virtual cPlayer *FindClosestPlayer(); //non static is easier. also virtual so other mobs can implement their own searching algo + virtual void GetMonsterConfig(const char* pm_name); + virtual void EventLosePlayer(); + virtual void CheckEventLostPlayer(); + + virtual void InStateIdle(float a_Dt); + virtual void InStateChasing(float a_Dt); + virtual void InStateEscaping(float a_Dt); + + virtual void Attack(float a_Dt); + int GetMobType() {return m_MobType;} + int GetAttackRate(){return (int)m_AttackRate;} + void SetAttackRate(int ar); + void SetAttackRange(float ar); + void SetAttackDamage(float ad); + void SetSightDistance(float sd); + + enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState; + enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality; + +protected: + + cEntity* m_Target; + float m_AttackRate; + float idle_interval; + + Vector3f m_Destination; + bool m_bMovingToDestination; + bool m_bPassiveAggressive; + + Vector3f m_Speed; + float m_DestinationTime; + + float m_Gravity; + bool m_bOnGround; + + float m_DestroyTimer; + float m_Jump; + + char m_MobType; + + float m_SeePlayerInterval; + float m_AttackDamage; + float m_AttackRange; + float m_AttackInterval; + + void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); +}; //tolua_export + + + + diff --git a/source/Mobs/PassiveAggressiveMonster.cpp b/source/Mobs/PassiveAggressiveMonster.cpp new file mode 100644 index 000000000..abf37ee59 --- /dev/null +++ b/source/Mobs/PassiveAggressiveMonster.cpp @@ -0,0 +1,38 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "PassiveAggressiveMonster.h" + +#include "../cPlayer.h" + + + + + +cPassiveAggressiveMonster::cPassiveAggressiveMonster() +{ + m_EMPersonality = PASSIVE; +} + +cPassiveAggressiveMonster::~cPassiveAggressiveMonster() +{ +} + +void cPassiveAggressiveMonster::TakeDamage(int a_Damage, cEntity* a_Instigator) +{ + cMonster::TakeDamage(a_Damage, a_Instigator); + if(m_Target->GetEntityType() == cEntity::eEntityType_Player) + { + cPlayer * Player = (cPlayer *) m_Target; + if(Player->GetGameMode() != 1) + { + m_EMState = CHASING; + } + } + +} + +void cPassiveAggressiveMonster::EventSeePlayer(cEntity *a_Entity) +{ + return cMonster::EventSeePlayer(a_Entity); +}
\ No newline at end of file diff --git a/source/Mobs/PassiveAggressiveMonster.h b/source/Mobs/PassiveAggressiveMonster.h new file mode 100644 index 000000000..972d2a11d --- /dev/null +++ b/source/Mobs/PassiveAggressiveMonster.h @@ -0,0 +1,13 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cPassiveAggressiveMonster : public cAggressiveMonster +{ +public: + cPassiveAggressiveMonster(); + ~cPassiveAggressiveMonster(); + + virtual void TakeDamage(int a_Damage, cEntity* a_Instigator); + void EventSeePlayer(cEntity *a_Entity); +}; diff --git a/source/Mobs/PassiveMonster.cpp b/source/Mobs/PassiveMonster.cpp new file mode 100644 index 000000000..bc3f70b4b --- /dev/null +++ b/source/Mobs/PassiveMonster.cpp @@ -0,0 +1,46 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "PassiveMonster.h" +#include "../MersenneTwister.h" + + + + + +cPassiveMonster::cPassiveMonster() +{ + m_EMPersonality = PASSIVE; +} + +cPassiveMonster::~cPassiveMonster() +{ +} + +void cPassiveMonster::TakeDamage(int a_Damage, cEntity* a_Instigator) +{ + cMonster::TakeDamage(a_Damage, a_Instigator); + if(a_Instigator != this) + m_EMState = ESCAPING; +} + +void cPassiveMonster::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + m_SeePlayerInterval += a_Dt; + + if(m_SeePlayerInterval > 1) + { + MTRand r1; + int rem = r1.randInt() % 3 + 1; //check most of the time but miss occasionally + + m_SeePlayerInterval = 0.0; + if(rem >= 2) { + if(m_EMState == ESCAPING) + { + CheckEventLostPlayer(); + } + } + } +}
\ No newline at end of file diff --git a/source/Mobs/PassiveMonster.h b/source/Mobs/PassiveMonster.h new file mode 100644 index 000000000..1265dc737 --- /dev/null +++ b/source/Mobs/PassiveMonster.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Monster.h" + +class cPassiveMonster : public cMonster +{ +public: + cPassiveMonster(); + ~cPassiveMonster(); + + virtual void Tick(float a_Dt); + + virtual void TakeDamage(int a_Damage, cEntity* a_Instigator); +}; diff --git a/source/Mobs/Pig.cpp b/source/Mobs/Pig.cpp new file mode 100644 index 000000000..48954dc73 --- /dev/null +++ b/source/Mobs/Pig.cpp @@ -0,0 +1,51 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Pig.h" + + + + + +cPig::cPig() +{ + m_MobType = 90; + GetMonsterConfig("Pig"); +} + + + + + +cPig::~cPig() +{ +} + + + + + +bool cPig::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cPig" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cPig::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_RAW_MEAT); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + // TODO: Check for burning state + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Pig.h b/source/Mobs/Pig.h new file mode 100644 index 000000000..e701535ba --- /dev/null +++ b/source/Mobs/Pig.h @@ -0,0 +1,14 @@ +#pragma once + +#include "PassiveMonster.h" + +class cPig : public cPassiveMonster +{ +public: + cPig(); + ~cPig(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp new file mode 100644 index 000000000..1f5f1815f --- /dev/null +++ b/source/Mobs/Sheep.cpp @@ -0,0 +1,65 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Sheep.h" + + + + + +//Todo: Implement color + + + + + +cSheep::cSheep(void) : + m_IsSheared(false), + m_WoolColor(0) // TODO: E_META_WOOL_WHITE +{ + m_MobType = 91; + GetMonsterConfig("Sheep"); +} + + + + + +cSheep::~cSheep() +{ +} + + + + + +bool cSheep::IsA( const char* a_EntityType ) +{ + if (strcmp( a_EntityType, "cSheep" ) == 0) + { + return true; + } + return cMonster::IsA( a_EntityType ); +} + + + + + +void cSheep::KilledBy( cEntity* a_Killer ) +{ + // TODO: Check whether it is sheared + // TODO: Check color + + if (!m_IsSheared) + { + cItems Drops; + Drops.push_back(cItem(E_ITEM_WHITE_CLOTH, 1, m_WoolColor)); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + } + + cMonster::KilledBy( a_Killer ); +} + + + diff --git a/source/Mobs/Sheep.h b/source/Mobs/Sheep.h new file mode 100644 index 000000000..28c2b97dc --- /dev/null +++ b/source/Mobs/Sheep.h @@ -0,0 +1,17 @@ +#pragma once + +#include "PassiveMonster.h" + +class cSheep : public cPassiveMonster +{ +public: + cSheep(); + ~cSheep(); + + bool m_IsSheared; + NIBBLETYPE m_WoolColor; // Uses E_META_WOOL_ constants for colors + + virtual bool IsA(const char * a_EntityType); + + virtual void KilledBy(cEntity * a_Killer); +}; diff --git a/source/Mobs/Silverfish.cpp b/source/Mobs/Silverfish.cpp new file mode 100644 index 000000000..1525966c4 --- /dev/null +++ b/source/Mobs/Silverfish.cpp @@ -0,0 +1,25 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Silverfish.h" + + + + + +cSilverfish::cSilverfish() +{ + m_MobType = 60; + GetMonsterConfig("Silverfish"); +} + +cSilverfish::~cSilverfish() +{ +} + +bool cSilverfish::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cSilverfish" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + diff --git a/source/Mobs/Silverfish.h b/source/Mobs/Silverfish.h new file mode 100644 index 000000000..fe23a4ba1 --- /dev/null +++ b/source/Mobs/Silverfish.h @@ -0,0 +1,12 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cSilverfish : public cAggressiveMonster +{ +public: + cSilverfish(); + ~cSilverfish(); + + virtual bool IsA( const char* a_EntityType ); +}; diff --git a/source/Mobs/Skeleton.cpp b/source/Mobs/Skeleton.cpp new file mode 100644 index 000000000..56bbb9310 --- /dev/null +++ b/source/Mobs/Skeleton.cpp @@ -0,0 +1,65 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Skeleton.h" + + + + + +cSkeleton::cSkeleton() +{ + m_MobType = 51; + GetMonsterConfig("Skeleton"); +} + + + + + +cSkeleton::~cSkeleton() +{ +} + + + + + +bool cSkeleton::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cSkeleton" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cSkeleton::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + //TODO Outsource + //TODO should do lightcheck, not daylight -> mobs in the dark donīt burn + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING ) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D + } +} + + + + + +void cSkeleton::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_ARROW); + AddRandomDropItem(Drops, 0, 2, E_ITEM_BONE); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Skeleton.h b/source/Mobs/Skeleton.h new file mode 100644 index 000000000..84a434905 --- /dev/null +++ b/source/Mobs/Skeleton.h @@ -0,0 +1,16 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cSkeleton : public cAggressiveMonster +{ +public: + cSkeleton(); + ~cSkeleton(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void Tick(float a_Dt); + virtual void KilledBy( cEntity* a_Killer ); + +}; diff --git a/source/Mobs/Slime.cpp b/source/Mobs/Slime.cpp new file mode 100644 index 000000000..b8dc52d7c --- /dev/null +++ b/source/Mobs/Slime.cpp @@ -0,0 +1,52 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Slime.h" + +//TODO Implement sized slimes + + + + + +cSlime::cSlime() +{ + m_MobType = 55; + GetMonsterConfig("Slime"); +} + + + + + +cSlime::~cSlime() +{ +} + + + + + +bool cSlime::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cSlime" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cSlime::KilledBy( cEntity* a_Killer ) +{ + //TODO: only when tiny + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_SLIMEBALL); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Slime.h b/source/Mobs/Slime.h new file mode 100644 index 000000000..cceac617d --- /dev/null +++ b/source/Mobs/Slime.h @@ -0,0 +1,14 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cSlime : public cAggressiveMonster +{ +public: + cSlime(); + ~cSlime(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Spider.cpp b/source/Mobs/Spider.cpp new file mode 100644 index 000000000..dfa7a8a6a --- /dev/null +++ b/source/Mobs/Spider.cpp @@ -0,0 +1,50 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Spider.h" + + + + + +cSpider::cSpider() +{ + m_MobType = 52; + GetMonsterConfig("Spider"); +} + + + + + +cSpider::~cSpider() +{ +} + + + + + +bool cSpider::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cSpider" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cSpider::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_STRING); + AddRandomDropItem(Drops, 0, 1, E_ITEM_SPIDER_EYE); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Spider.h b/source/Mobs/Spider.h new file mode 100644 index 000000000..12133bdb8 --- /dev/null +++ b/source/Mobs/Spider.h @@ -0,0 +1,14 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cSpider : public cAggressiveMonster +{ +public: + cSpider(); + ~cSpider(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Squid.cpp b/source/Mobs/Squid.cpp new file mode 100644 index 000000000..f88c295a4 --- /dev/null +++ b/source/Mobs/Squid.cpp @@ -0,0 +1,60 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Squid.h" +#include "../Vector3d.h" + + + + + +cSquid::cSquid() +{ + m_MobType = 94; + GetMonsterConfig("Squid"); + m_NoWater = 0.f; +} + +cSquid::~cSquid() +{ + +} + +bool cSquid::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cSquid" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cSquid::KilledBy( cEntity* a_Killer ) +{ + // Drops 0-3 Ink Sacs + cItems Drops; + AddRandomDropItem(Drops, 0, 3, E_ITEM_DYE, E_META_DYE_BLACK); + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + + +void cSquid::Tick(float a_Dt) +{ + cPassiveMonster::Tick(a_Dt); + + Vector3d Pos = GetPosition(); + + + //TODO Not a real behavior, but cool :D + if(!IsBlockWater(GetWorld()->GetBlock((int) Pos.x, (int) Pos.y, (int) Pos.z)) && GetMetaData() != BURNING) + { + SetMetaData(BURNING); + } + +}
\ No newline at end of file diff --git a/source/Mobs/Squid.h b/source/Mobs/Squid.h new file mode 100644 index 000000000..eaf13b5c7 --- /dev/null +++ b/source/Mobs/Squid.h @@ -0,0 +1,18 @@ +#pragma once + +#include "PassiveMonster.h" + +class cSquid : public cPassiveMonster +{ +public: + cSquid(); + ~cSquid(); + + virtual void Tick(float a_Dt); + + virtual bool IsA( const char* a_EntityType ); + virtual void KilledBy( cEntity* a_Killer ); + +protected: + float m_NoWater; +}; diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp new file mode 100644 index 000000000..bd7fa213b --- /dev/null +++ b/source/Mobs/Wolf.cpp @@ -0,0 +1,20 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Wolf.h" + +cWolf::cWolf() +{ + m_MobType = 95; + GetMonsterConfig("Wolf"); +} + +cWolf::~cWolf() +{ +} + +bool cWolf::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cWolf" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} diff --git a/source/Mobs/Wolf.h b/source/Mobs/Wolf.h new file mode 100644 index 000000000..bde5b9d32 --- /dev/null +++ b/source/Mobs/Wolf.h @@ -0,0 +1,12 @@ +#pragma once + +#include "PassiveAggressiveMonster.h" + +class cWolf : public cPassiveAggressiveMonster +{ +public: + cWolf(); + ~cWolf(); + + virtual bool IsA( const char* a_EntityType ); +}; diff --git a/source/Mobs/Zombie.cpp b/source/Mobs/Zombie.cpp new file mode 100644 index 000000000..b51931904 --- /dev/null +++ b/source/Mobs/Zombie.cpp @@ -0,0 +1,66 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Zombie.h" + + + + + +cZombie::cZombie() +{ + m_MobType = 54; + GetMonsterConfig("Zombie"); +} + + + + + +cZombie::~cZombie() +{ +} + + + + + +bool cZombie::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cZombie" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cZombie::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + //TODO Same as in cSkeleton :D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D + } +} + + + + + +void cZombie::KilledBy( cEntity* a_Killer ) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 2, E_ITEM_ROTTEN_FLESH); + + // TODO: Rare drops + + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Zombie.h b/source/Mobs/Zombie.h new file mode 100644 index 000000000..6adaaf41f --- /dev/null +++ b/source/Mobs/Zombie.h @@ -0,0 +1,15 @@ +#pragma once + +#include "AggressiveMonster.h" + +class cZombie : public cAggressiveMonster +{ +public: + cZombie(); + ~cZombie(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void Tick(float a_Dt); + virtual void KilledBy( cEntity* a_Killer ); +}; diff --git a/source/Mobs/Zombiepigman.cpp b/source/Mobs/Zombiepigman.cpp new file mode 100644 index 000000000..65293cfce --- /dev/null +++ b/source/Mobs/Zombiepigman.cpp @@ -0,0 +1,67 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Zombiepigman.h" + + + + + +cZombiepigman::cZombiepigman() +{ + m_MobType = 57; + GetMonsterConfig("Zombiepigman"); +} + + + + + +cZombiepigman::~cZombiepigman() +{ +} + + + + + +bool cZombiepigman::IsA( const char* a_EntityType ) +{ + if( strcmp( a_EntityType, "cZombiepigman" ) == 0 ) return true; + return cMonster::IsA( a_EntityType ); +} + + + + + +void cZombiepigman::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + + //TODO Same as noticed in cSkeleton AND Do they really burn by sun?? :D In the neather is no sun :D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING ) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D + } +} + + + + + +void cZombiepigman::KilledBy(cEntity * a_Killer) +{ + cItems Drops; + AddRandomDropItem(Drops, 0, 1, E_ITEM_ROTTEN_FLESH); + AddRandomDropItem(Drops, 0, 1, E_ITEM_GOLD_NUGGET); + + // TODO: Rare drops + + m_World->SpawnItemPickups(Drops, m_Pos.x, m_Pos.y, m_Pos.z); + + cMonster::KilledBy( a_Killer ); +} + + + + diff --git a/source/Mobs/Zombiepigman.h b/source/Mobs/Zombiepigman.h new file mode 100644 index 000000000..93fe2d607 --- /dev/null +++ b/source/Mobs/Zombiepigman.h @@ -0,0 +1,15 @@ +#pragma once + +#include "PassiveAggressiveMonster.h" + +class cZombiepigman : public cPassiveAggressiveMonster +{ +public: + cZombiepigman(); + ~cZombiepigman(); + + virtual bool IsA( const char* a_EntityType ); + + virtual void Tick(float a_Dt); + virtual void KilledBy( cEntity* a_Killer ); +}; |