Added more constants into eEntityType; made them a compulsory parameter to the constructor, so that all entities have proper type.

Also added a few utility functions to cEntity for distinguishing the types (IsPlayer(), IsPickup() etc.)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1092 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-12-21 12:52:14 +00:00
parent e690694aa2
commit afaf104b40
15 changed files with 230 additions and 162 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 12/21/12 21:19:57.
** Generated automatically by tolua++-1.0.92 on 12/21/12 21:44:41.
*/
#ifndef __cplusplus
@ -4020,7 +4020,7 @@ static int tolua_AllToLua_cEntity_GetEntityType00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEntityType'", NULL);
#endif
{
unsigned int tolua_ret = (unsigned int) self->GetEntityType();
cEntity::eEntityType tolua_ret = (cEntity::eEntityType) self->GetEntityType();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@ -4033,6 +4033,102 @@ static int tolua_AllToLua_cEntity_GetEntityType00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: IsPlayer of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_IsPlayer00
static int tolua_AllToLua_cEntity_IsPlayer00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsPlayer'", NULL);
#endif
{
bool tolua_ret = (bool) self->IsPlayer();
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'IsPlayer'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: IsPickup of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_IsPickup00
static int tolua_AllToLua_cEntity_IsPickup00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsPickup'", NULL);
#endif
{
bool tolua_ret = (bool) self->IsPickup();
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'IsPickup'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: IsMob of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_IsMob00
static int tolua_AllToLua_cEntity_IsMob00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsMob'", NULL);
#endif
{
bool tolua_ret = (bool) self->IsMob();
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'IsMob'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: IsA of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_IsA00
static int tolua_AllToLua_cEntity_IsA00(lua_State* tolua_S)
@ -5023,16 +5119,6 @@ public:
} else {
return ( void ) cEntity:: Initialize(a_World);
};
};
unsigned int GetEntityType( void )const {
if (push_method("GetEntityType", tolua_AllToLua_cEntity_GetEntityType00)) {
ToluaBase::dbcall(lua_state, 1, 1);
unsigned int tolua_ret = (unsigned int )tolua_tonumber(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return (unsigned int ) cEntity:: GetEntityType();
};
};
bool IsA( const char* a_ClassName)const {
if (push_method("IsA", tolua_AllToLua_cEntity_IsA00)) {
@ -5090,9 +5176,6 @@ public:
void cEntity__Initialize( cWorld* a_World) {
return ( void )cEntity::Initialize(a_World);
};
unsigned int cEntity__GetEntityType( void ) {
return (unsigned int )cEntity::GetEntityType();
};
bool cEntity__IsA( const char* a_ClassName) {
return ( bool )cEntity::IsA(a_ClassName);
@ -5106,7 +5189,7 @@ public:
void cEntity__SpawnOn( cClientHandle& a_Client) {
return ( void )cEntity::SpawnOn(a_Client);
};
Lua__cEntity( double a_X, double a_Y, double a_Z): cEntity(a_X,a_Y,a_Z){};
Lua__cEntity( cEntity::eEntityType a_EntityType, double a_X, double a_Y, double a_Z): cEntity(a_EntityType,a_X,a_Y,a_Z){};
};
/* method: tolua__set_instance of class Lua__cEntity */
@ -5175,38 +5258,6 @@ static int tolua_AllToLua_Lua__cEntity_cEntity__Initialize00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: cEntity__GetEntityType of class Lua__cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cEntity_cEntity__GetEntityType00
static int tolua_AllToLua_Lua__cEntity_cEntity__GetEntityType00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Lua__cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Lua__cEntity* self = (Lua__cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cEntity__GetEntityType'", NULL);
#endif
{
unsigned int tolua_ret = (unsigned int) self->cEntity__GetEntityType();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'cEntity__GetEntityType'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: cEntity__IsA of class Lua__cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cEntity_cEntity__IsA00
static int tolua_AllToLua_Lua__cEntity_cEntity__IsA00(lua_State* tolua_S)
@ -5349,17 +5400,19 @@ static int tolua_AllToLua_Lua__cEntity_new00(lua_State* tolua_S)
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,6,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
double a_X = ((double) tolua_tonumber(tolua_S,2,0));
double a_Y = ((double) tolua_tonumber(tolua_S,3,0));
double a_Z = ((double) tolua_tonumber(tolua_S,4,0));
cEntity::eEntityType a_EntityType = ((cEntity::eEntityType) (int) tolua_tonumber(tolua_S,2,0));
double a_X = ((double) tolua_tonumber(tolua_S,3,0));
double a_Y = ((double) tolua_tonumber(tolua_S,4,0));
double a_Z = ((double) tolua_tonumber(tolua_S,5,0));
{
Lua__cEntity* tolua_ret = (Lua__cEntity*) Mtolua_new((Lua__cEntity)(a_X,a_Y,a_Z));
Lua__cEntity* tolua_ret = (Lua__cEntity*) Mtolua_new((Lua__cEntity)(a_EntityType,a_X,a_Y,a_Z));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cEntity");
}
}
@ -5383,17 +5436,19 @@ static int tolua_AllToLua_Lua__cEntity_new00_local(lua_State* tolua_S)
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,6,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
double a_X = ((double) tolua_tonumber(tolua_S,2,0));
double a_Y = ((double) tolua_tonumber(tolua_S,3,0));
double a_Z = ((double) tolua_tonumber(tolua_S,4,0));
cEntity::eEntityType a_EntityType = ((cEntity::eEntityType) (int) tolua_tonumber(tolua_S,2,0));
double a_X = ((double) tolua_tonumber(tolua_S,3,0));
double a_Y = ((double) tolua_tonumber(tolua_S,4,0));
double a_Z = ((double) tolua_tonumber(tolua_S,5,0));
{
Lua__cEntity* tolua_ret = (Lua__cEntity*) Mtolua_new((Lua__cEntity)(a_X,a_Y,a_Z));
Lua__cEntity* tolua_ret = (Lua__cEntity*) Mtolua_new((Lua__cEntity)(a_EntityType,a_X,a_Y,a_Z));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cEntity");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
}
@ -6346,16 +6401,6 @@ public:
} else {
return ( void ) cPawn:: Initialize(a_World);
};
};
unsigned int GetEntityType( void )const {
if (push_method("GetEntityType", tolua_AllToLua_cEntity_GetEntityType00)) {
ToluaBase::dbcall(lua_state, 1, 1);
unsigned int tolua_ret = (unsigned int )tolua_tonumber(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return (unsigned int ) cPawn:: GetEntityType();
};
};
bool IsA( const char* a_ClassName)const {
if (push_method("IsA", tolua_AllToLua_cEntity_IsA00)) {
@ -6449,9 +6494,6 @@ public:
};
void cPawn__Initialize( cWorld* a_World) {
return ( void )cPawn::Initialize(a_World);
};
unsigned int cPawn__GetEntityType( void ) {
return (unsigned int )cPawn::GetEntityType();
};
bool cPawn__IsA( const char* a_ClassName) {
return ( bool )cPawn::IsA(a_ClassName);
@ -8348,16 +8390,6 @@ public:
} else {
return ( cItem ) cPlayer:: GetEquippedBoots();
};
};
unsigned int GetEntityType( void )const {
if (push_method("GetEntityType", tolua_AllToLua_cEntity_GetEntityType00)) {
ToluaBase::dbcall(lua_state, 1, 1);
unsigned int tolua_ret = (unsigned int )tolua_tonumber(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return (unsigned int ) cPlayer:: GetEntityType();
};
};
bool IsA( const char* a_ClassName)const {
if (push_method("IsA", tolua_AllToLua_cEntity_IsA00)) {
@ -8454,9 +8486,6 @@ public:
};
cItem cPlayer__GetEquippedBoots( void ) {
return ( cItem )cPlayer::GetEquippedBoots();
};
unsigned int cPlayer__GetEntityType( void ) {
return (unsigned int )cPlayer::GetEntityType();
};
bool cPlayer__IsA( const char* a_ClassName) {
return ( bool )cPlayer::IsA(a_ClassName);
@ -16114,16 +16143,6 @@ public:
} else {
return ( void ) cPickup:: Initialize(a_World);
};
};
unsigned int GetEntityType( void )const {
if (push_method("GetEntityType", tolua_AllToLua_cEntity_GetEntityType00)) {
ToluaBase::dbcall(lua_state, 1, 1);
unsigned int tolua_ret = (unsigned int )tolua_tonumber(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return (unsigned int ) cPickup:: GetEntityType();
};
};
bool IsA( const char* a_ClassName)const {
if (push_method("IsA", tolua_AllToLua_cEntity_IsA00)) {
@ -16184,9 +16203,6 @@ public:
};
void cPickup__Initialize( cWorld* a_World) {
return ( void )cPickup::Initialize(a_World);
};
unsigned int cPickup__GetEntityType( void ) {
return (unsigned int )cPickup::GetEntityType();
};
bool cPickup__IsA( const char* a_ClassName) {
return ( bool )cPickup::IsA(a_ClassName);
@ -24000,12 +24016,21 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"ENTITY_STATUS_WOLF_SHAKING",cEntity::ENTITY_STATUS_WOLF_SHAKING);
tolua_constant(tolua_S,"ENTITY_STATUS_EATING_ACCEPTED",cEntity::ENTITY_STATUS_EATING_ACCEPTED);
tolua_constant(tolua_S,"ENTITY_STATUS_SHEEP_EATING",cEntity::ENTITY_STATUS_SHEEP_EATING);
tolua_function(tolua_S,"delete",tolua_AllToLua_cEntity_delete00);
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cEntity_Initialize00);
tolua_constant(tolua_S,"etEntity",cEntity::etEntity);
tolua_constant(tolua_S,"etPlayer",cEntity::etPlayer);
tolua_constant(tolua_S,"etPickup",cEntity::etPickup);
tolua_constant(tolua_S,"etMob",cEntity::etMob);
tolua_constant(tolua_S,"etFallingBlock",cEntity::etFallingBlock);
tolua_constant(tolua_S,"eEntityType_Entity",cEntity::eEntityType_Entity);
tolua_constant(tolua_S,"eEntityType_Player",cEntity::eEntityType_Player);
tolua_constant(tolua_S,"eEntityType_Pickup",cEntity::eEntityType_Pickup);
tolua_constant(tolua_S,"eEntityType_Mob",cEntity::eEntityType_Mob);
tolua_function(tolua_S,"delete",tolua_AllToLua_cEntity_delete00);
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cEntity_Initialize00);
tolua_function(tolua_S,"GetEntityType",tolua_AllToLua_cEntity_GetEntityType00);
tolua_function(tolua_S,"IsPlayer",tolua_AllToLua_cEntity_IsPlayer00);
tolua_function(tolua_S,"IsPickup",tolua_AllToLua_cEntity_IsPickup00);
tolua_function(tolua_S,"IsMob",tolua_AllToLua_cEntity_IsMob00);
tolua_function(tolua_S,"IsA",tolua_AllToLua_cEntity_IsA00);
tolua_function(tolua_S,"GetClass",tolua_AllToLua_cEntity_GetClass00);
tolua_function(tolua_S,"GetParentClass",tolua_AllToLua_cEntity_GetParentClass00);
@ -24045,7 +24070,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_beginmodule(tolua_S,"Lua__cEntity");
tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cEntity_tolua__set_instance00);
tolua_function(tolua_S,"cEntity__Initialize",tolua_AllToLua_Lua__cEntity_cEntity__Initialize00);
tolua_function(tolua_S,"cEntity__GetEntityType",tolua_AllToLua_Lua__cEntity_cEntity__GetEntityType00);
tolua_function(tolua_S,"cEntity__IsA",tolua_AllToLua_Lua__cEntity_cEntity__IsA00);
tolua_function(tolua_S,"cEntity__GetClass",tolua_AllToLua_Lua__cEntity_cEntity__GetClass00);
tolua_function(tolua_S,"cEntity__GetParentClass",tolua_AllToLua_Lua__cEntity_cEntity__GetParentClass00);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 12/21/12 21:19:58.
** Generated automatically by tolua++-1.0.92 on 12/21/12 21:44:41.
*/
/* Exported function */

View File

@ -115,7 +115,7 @@ cChunk::~cChunk()
cEntityList Entities;
for (cEntityList::const_iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr)
{
if ((*itr)->GetEntityType() != cEntity::eEntityType_Player)
if (!(*itr)->IsPlayer())
{
Entities.push_back(*itr);
}
@ -1382,7 +1382,7 @@ void cChunk::CollectPickupsByPlayer(cPlayer * a_Player)
for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr)
{
if ( (*itr)->GetEntityType() != cEntity::eEntityType_Pickup )
if (!(*itr)->IsPickup())
{
continue; // Only pickups
}
@ -1515,13 +1515,13 @@ bool cChunk::HasAnyClients(void)
void cChunk::AddEntity( cEntity * a_Entity)
void cChunk::AddEntity(cEntity * a_Entity)
{
if (a_Entity->GetEntityType() != cEntity::eEntityType_Player)
if (!a_Entity->IsPlayer())
{
MarkDirty();
}
m_Entities.push_back( a_Entity );
m_Entities.push_back(a_Entity);
}
@ -1537,7 +1537,7 @@ void cChunk::RemoveEntity(cEntity * a_Entity)
if (SizeBefore != SizeAfter)
{
// Mark as dirty if it was a server-generated entity:
if (a_Entity->GetEntityType() != cEntity::eEntityType_Player)
if (!a_Entity->IsPlayer())
{
MarkDirty();
}

View File

@ -22,7 +22,7 @@ cCriticalSection cEntity::m_CSCount;
cEntity::cEntity(double a_X, double a_Y, double a_Z)
cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z)
: m_UniqueID( 0 )
, m_Referencers( new cReferenceManager( cReferenceManager::RFMNGR_REFERENCERS ) )
, m_References( new cReferenceManager( cReferenceManager::RFMNGR_REFERENCES ) )
@ -33,8 +33,8 @@ cEntity::cEntity(double a_X, double a_Y, double a_Z)
, m_bDirtyPosition( true )
, m_bDirtyOrientation( true )
, m_bDestroyed( false )
, m_EntityType( eEntityType_Entity )
, m_World( 0 )
, m_EntityType(a_EntityType)
, m_World(NULL)
, m_bRemovedFromChunk( false )
, m_FireDamageInterval(0.f)
, m_BurnPeriod(0.f)

View File

@ -77,19 +77,31 @@ public:
ENTITY_STATUS_SHEEP_EATING = 10,
} ;
cEntity(double a_X, double a_Y, double a_Z);
enum eEntityType
{
etEntity, // For all other types
etPlayer,
etPickup,
etMob,
etFallingBlock,
// Older constants, left over for compatibility reasons (plugins)
eEntityType_Entity = etEntity,
eEntityType_Player = etPlayer,
eEntityType_Pickup = etPickup,
eEntityType_Mob = etMob,
} ;
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z);
virtual ~cEntity();
virtual void Initialize(cWorld * a_World);
enum eEntityType
{
eEntityType_Entity,
eEntityType_Player,
eEntityType_Pickup
};
virtual unsigned int GetEntityType(void) const { return m_EntityType; }
eEntityType GetEntityType(void) const { return m_EntityType; }
bool IsPlayer(void) const { return (m_EntityType == etPlayer); }
bool IsPickup(void) const { return (m_EntityType == etPickup); }
bool IsMob (void) const { return (m_EntityType == etMob); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;

View File

@ -9,7 +9,7 @@
cFallingBlock::cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_BlockType)
: super( a_BlockPosition.x + 0.5f, a_BlockPosition.y + 0.5f, a_BlockPosition.z + 0.5f )
: super(etFallingBlock, a_BlockPosition.x + 0.5f, a_BlockPosition.y + 0.5f, a_BlockPosition.z + 0.5f )
, m_BlockType( a_BlockType )
, m_OriginalPosition( a_BlockPosition )
, m_SpeedY( 0 )

View File

@ -8,26 +8,30 @@
#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);
// What to do if in Chasing State
void cAggressiveMonster::InStateChasing(float a_Dt)
{
super::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
if (m_Target != NULL)
{
if(m_Target->GetEntityType() == cEntity::eEntityType_Player)
if (m_Target->IsPlayer())
{
cPlayer * Player = (cPlayer *) m_Target;
if(Player->GetGameMode() == 1)
if (Player->GetGameMode() == 1)
{
m_EMState = IDLE;
return;
@ -36,11 +40,14 @@ void cAggressiveMonster::InStateChasing(float a_Dt) {
Vector3f Pos = Vector3f( m_Pos );
Vector3f Their = Vector3f( m_Target->GetPosition() );
if( (Their - Pos).Length() <= m_AttackRange) {
if ((Their - Pos).Length() <= m_AttackRange)
{
cMonster::Attack(a_Dt);
}
MoveToPosition( Their + Vector3f(0, 0.65f, 0) );
} else if( m_ChaseTime > 5.f ) {
MoveToPosition(Their + Vector3f(0, 0.65f, 0));
}
else if (m_ChaseTime > 5.f)
{
m_ChaseTime = 0;
m_EMState = IDLE;
}
@ -48,31 +55,44 @@ void cAggressiveMonster::InStateChasing(float a_Dt) {
void cAggressiveMonster::EventSeePlayer(cEntity *a_Entity)
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
{
cMonster::EventSeePlayer(a_Entity);
super::EventSeePlayer(a_Entity);
m_EMState = CHASING;
}
void cAggressiveMonster::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
super::Tick(a_Dt);
m_SeePlayerInterval += a_Dt;
if(m_SeePlayerInterval > 1)
if (m_SeePlayerInterval > 1)
{
MTRand r1;
int rem = r1.randInt() % 3 + 1; //check most of the time but miss occasionally
int rem = r1.randInt() % 3 + 1; // Check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if(rem >= 2)
if (rem >= 2)
{
if(m_EMState == CHASING){
if (m_EMState == CHASING)
{
CheckEventLostPlayer();
} else {
}
else
{
CheckEventSeePlayer();
}
}
}
}
}

View File

@ -1,17 +1,29 @@
#pragma once
#include "Monster.h"
class cAggressiveMonster : public cMonster
{
public:
cAggressiveMonster();
~cAggressiveMonster();
virtual void Tick(float a_Dt);
virtual void InStateChasing(float a_Dt);
class cAggressiveMonster :
public cMonster
{
typedef cMonster super;
public:
cAggressiveMonster(void);
virtual void Tick(float a_Dt) override;
virtual void InStateChasing(float a_Dt) override;
virtual void EventSeePlayer(cEntity *) override;
virtual void EventSeePlayer(cEntity *);
protected:
float m_ChaseTime;
};
} ;

View File

@ -29,7 +29,8 @@
cMonster::cMonster(void)
: m_Target(NULL)
: super(etMob)
, m_Target(NULL)
, m_bMovingToDestination(false)
, m_DestinationTime( 0 )
, m_Gravity( -9.81f)

View File

@ -20,7 +20,9 @@ cPassiveAggressiveMonster::cPassiveAggressiveMonster(void)
void cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if ((m_Target != NULL) && (m_Target->GetEntityType() == cEntity::eEntityType_Player))
super::DoTakeDamage(a_TDI);
if ((m_Target != NULL) && (m_Target->IsPlayer()))
{
cPlayer * Player = (cPlayer *) m_Target;
if (Player->GetGameMode() != 1)

View File

@ -48,7 +48,7 @@ void cZombiepigman::KilledBy(cPawn * a_Killer)
{
super::KilledBy(a_Killer);
if ((a_Killer != NULL) && (a_Killer->GetEntityType() == eEntityType_Player))
if ((a_Killer != NULL) && (a_Killer->IsPlayer()))
{
// TODO: Anger all nearby zombie pigmen
// TODO: In vanilla, if one player angers ZPs, do they attack any nearby player, or only that one attacker?

View File

@ -15,8 +15,8 @@
cPawn::cPawn(void)
: cEntity( 0, 0, 0 )
cPawn::cPawn(eEntityType a_EntityType)
: cEntity(a_EntityType, 0, 0, 0)
, m_Health(1)
, m_MaxHealth(1)
, m_LastPosX( 0.0 )

View File

@ -81,7 +81,7 @@ class cPawn :
public:
CLASS_PROTODEF(cPawn);
cPawn(void);
cPawn(eEntityType a_EntityType);
virtual void Tick(float a_Dt) override;

View File

@ -25,7 +25,7 @@
cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */)
: cEntity( ((double)(a_X))/32, ((double)(a_Y))/32, ((double)(a_Z))/32 )
: cEntity(etPickup, ((double)(a_X))/32, ((double)(a_Y))/32, ((double)(a_Z))/32 )
, m_Speed( a_SpeedX, a_SpeedY, a_SpeedZ )
, m_bOnGround( false )
, m_bReplicated( false )
@ -33,9 +33,6 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
, m_Item( new cItem( a_Item ) )
, m_bCollected( false )
{
// LOGD("New pickup: ID(%i) Amount(%i) Health(%i)", m_Item.m_ItemID, m_Item.m_ItemCount, m_Item.m_ItemHealth );
m_EntityType = eEntityType_Pickup;
}

View File

@ -33,7 +33,8 @@
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
: m_GameMode(eGameMode_NotSet)
: super(etPlayer)
, m_GameMode(eGameMode_NotSet)
, m_IP("")
, m_LastBlockActionTime( 0 )
, m_LastBlockActionCnt( 0 )
@ -54,7 +55,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
this, GetUniqueID()
);
m_EntityType = eEntityType_Player;
m_InventoryWindow = new cInventoryWindow(*this);
m_CurrentWindow = m_InventoryWindow;