1
0

- Fixed Bug #99 -> Mobs no longer bother you in creative mode

- refactored many things in the Monster system

git-svn-id: http://mc-server.googlecode.com/svn/trunk@112 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
lapayo94@gmail.com 2011-12-25 22:47:12 +00:00
parent adb4dbc904
commit e8f230f24e
42 changed files with 386 additions and 1238 deletions

View File

@ -214,6 +214,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\source\cAggressiveMonster.cpp" />
<ClCompile Include="..\Source\cAuthenticator.cpp" />
<ClCompile Include="..\source\cBlockingTCPLink.cpp" />
<ClCompile Include="..\source\cCavespider.cpp" />
@ -246,6 +247,8 @@
<ClCompile Include="..\Source\cMonster.cpp" />
<ClCompile Include="..\source\cMonsterConfig.cpp" />
<ClCompile Include="..\source\cNoise.cpp" />
<ClCompile Include="..\source\cPassiveAggressiveMonster.cpp" />
<ClCompile Include="..\source\cPassiveMonster.cpp" />
<ClCompile Include="..\Source\cPawn.cpp" />
<ClCompile Include="..\source\cPig.cpp" />
<ClCompile Include="..\source\cPiston.cpp" />
@ -353,6 +356,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Source\BlockID.h" />
<ClInclude Include="..\source\cAggressiveMonster.h" />
<ClInclude Include="..\Source\cAuthenticator.h" />
<ClInclude Include="..\source\cBlockingTCPLink.h" />
<ClInclude Include="..\source\cCavespider.h" />
@ -383,6 +387,8 @@
<ClInclude Include="..\Source\cMonster.h" />
<ClInclude Include="..\source\cMonsterConfig.h" />
<ClInclude Include="..\source\cNoise.h" />
<ClInclude Include="..\source\cPassiveAggressiveMonster.h" />
<ClInclude Include="..\source\cPassiveMonster.h" />
<ClInclude Include="..\Source\cPawn.h" />
<ClInclude Include="..\source\cPig.h" />
<ClInclude Include="..\source\cPiston.h" />

View File

@ -406,6 +406,18 @@
<Filter Include="cFluidSimulator\cLavaSimulator">
<UniqueIdentifier>{b0401fd9-4021-4ab7-bf61-c8de112b4196}</UniqueIdentifier>
</Filter>
<Filter Include="cEntity\cPawn\cMonster\Personalities">
<UniqueIdentifier>{b0f7c883-e2ca-4bba-89e3-c36656c3de39}</UniqueIdentifier>
</Filter>
<Filter Include="cEntity\cPawn\cMonster\Personalities\Aggressive">
<UniqueIdentifier>{dd40c965-2dae-451b-8c78-8946b428a0b8}</UniqueIdentifier>
</Filter>
<Filter Include="cEntity\cPawn\cMonster\Personalities\Passive">
<UniqueIdentifier>{be4ace95-e07a-4aca-ac63-912de68ba01d}</UniqueIdentifier>
</Filter>
<Filter Include="cEntity\cPawn\cMonster\Personalities\PassiveAggressive">
<UniqueIdentifier>{71574b1c-a518-4a17-92c1-e3ea340f73bc}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\source\cServer.cpp">
@ -814,6 +826,15 @@
<ClCompile Include="..\source\cFluidSimulator.cpp">
<Filter>cFluidSimulator</Filter>
</ClCompile>
<ClCompile Include="..\source\cAggressiveMonster.cpp">
<Filter>cEntity\cPawn\cMonster\Personalities\Aggressive</Filter>
</ClCompile>
<ClCompile Include="..\source\cPassiveAggressiveMonster.cpp">
<Filter>cEntity\cPawn\cMonster\Personalities\PassiveAggressive</Filter>
</ClCompile>
<ClCompile Include="..\source\cPassiveMonster.cpp">
<Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\source\cServer.h">
@ -1257,6 +1278,15 @@
<ClInclude Include="..\source\cFluidSimulator.h">
<Filter>cFluidSimulator</Filter>
</ClInclude>
<ClInclude Include="..\source\cAggressiveMonster.h">
<Filter>cEntity\cPawn\cMonster\Personalities\Aggressive</Filter>
</ClInclude>
<ClInclude Include="..\source\cPassiveAggressiveMonster.h">
<Filter>cEntity\cPawn\cMonster\Personalities\PassiveAggressive</Filter>
</ClInclude>
<ClInclude Include="..\source\cPassiveMonster.h">
<Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\source\AllToLua.pkg">

View File

@ -0,0 +1,73 @@
#include "cAggressiveMonster.h"
#include "Vector3f.h"
#include "cPlayer.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::E_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)
{
int rem = rand() % 3 + 1; //check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if(rem >= 2)
{
if(m_EMState == CHASING){
CheckEventLostPlayer();
} else {
CheckEventSeePlayer();
}
}
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include "cMonster.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;
};

View File

@ -1,28 +1,7 @@
#include "cCavespider.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cCavespider::cCavespider() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cCavespider::cCavespider()
{
m_MobType = 59;
GetMonsterConfig("Cavespider");
}
@ -33,7 +12,6 @@ cCavespider::~cCavespider()
bool cCavespider::IsA( const char* a_EntityType )
{
//LOG("IsA( cCavespider ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cCavespider" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
@ -41,7 +19,7 @@ bool cCavespider::IsA( const char* a_EntityType )
void cCavespider::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
m_EMPersonality = (GetWorld()->GetWorldTime() < (12000 + 1000) )? PASSIVE:AGGRESSIVE;
m_EMPersonality = (GetWorld()->GetWorldTime() < (12000 + 1000) ) ? PASSIVE : AGGRESSIVE;
}
void cCavespider::KilledBy( cEntity* a_Killer )
@ -52,35 +30,3 @@ void cCavespider::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cCavespider::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cCavespider::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cCavespider::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cCavespider::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,15 @@
#pragma once
#include "cMonster.h"
class cCavespider : public cMonster
{
public:
cCavespider();
#pragma once
#include "cAggressiveMonster.h"
class cCavespider : public cAggressiveMonster
{
public:
cCavespider();
~cCavespider();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
};

View File

@ -1,34 +1,10 @@
#include "cChicken.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
#include <string>
// TODO: Drop egg every 5-10 minutes
//TODO Drop egg every 5-10 minutes
cChicken::cChicken()
: m_ChaseTime( 999999 )
{
//LOG("SPAWNING A CHICKEN!!!!!!!!!!!!!!!!!!!!!");
m_EMPersonality = PASSIVE;
m_MobType = 93;
GetMonsterConfig("Chicken");
}
@ -39,16 +15,10 @@ cChicken::~cChicken()
bool cChicken::IsA( const char* a_EntityType )
{
//LOG("IsA( cChicken ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cChicken" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cChicken::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cChicken::KilledBy( cEntity* a_Killer )
{
//Drops 0-2 Feathers
@ -56,36 +26,7 @@ void cChicken::KilledBy( cEntity* a_Killer )
// Raw Chicken
// TODO: (Check wheather it is burning to drop cooked Chicken)
//Drops 0-2 Lether
cMonster::DropItem(E_ITEM_RAW_CHICKEN, 1);
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cChicken::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cChicken::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cChicken::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
}

View File

@ -1,21 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cPassiveMonster.h"
class cChicken : public cMonster
class cChicken : public cPassiveMonster
{
public:
cChicken();
~cChicken();
~cChicken();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,32 +1,9 @@
#include "cCow.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
#include <string>
//TODO: Milk Cow
cCow::cCow()
: m_ChaseTime( 999999 )
{
//LOG("SPAWNING A Cow!!!!!!!!!!!!!!!!!!!!!");
m_EMPersonality = PASSIVE;
m_MobType = 92;
GetMonsterConfig("Cow");
}
@ -37,16 +14,10 @@ cCow::~cCow()
bool cCow::IsA( const char* a_EntityType )
{
//LOG("IsA( cCow ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cCow" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cCow::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cCow::KilledBy( cEntity* a_Killer )
{
//Drops 0-2 Lether
@ -59,30 +30,3 @@ void cCow::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cCow::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cCow::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cCow::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "cMonster.h"
#include "cPassiveMonster.h"
class cCow : public cMonster
class cCow : public cPassiveMonster
{
public:
cCow();
@ -10,12 +10,5 @@ public:
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};

View File

@ -1,28 +1,7 @@
#include "cCreeper.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cCreeper::cCreeper() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cCreeper::cCreeper()
{
m_MobType = 50;
GetMonsterConfig("Creeper");
}
@ -33,53 +12,16 @@ cCreeper::~cCreeper()
bool cCreeper::IsA( const char* a_EntityType )
{
//LOG("IsA( cCreeper ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cCreeper" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cCreeper::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cCreeper::KilledBy( cEntity* a_Killer )
{
cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
//Todo: Check if killed by a skeleton then drop random music disk
//TODO Check if killed by a skeleton then drop random music disk
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cCreeper::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cCreeper::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cCreeper::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cCreeper::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}
}

View File

@ -1,22 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cCreeper : public cMonster
class cCreeper : public cAggressiveMonster
{
public:
cCreeper();
~cCreeper();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};

View File

@ -1,28 +1,7 @@
#include "cEnderman.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cEnderman::cEnderman() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = PASSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cEnderman::cEnderman()
{
m_MobType = 58;
GetMonsterConfig("Enderman");
}
@ -33,7 +12,6 @@ cEnderman::~cEnderman()
bool cEnderman::IsA( const char* a_EntityType )
{
//LOG("IsA( cEnderman ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cEnderman" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
@ -41,6 +19,8 @@ bool cEnderman::IsA( const char* a_EntityType )
void cEnderman::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
//TODO Same as stated in cSkeleton
if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight
m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D
}
@ -53,35 +33,3 @@ void cEnderman::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cEnderman::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cEnderman::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cEnderman::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cEnderman::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,15 @@
#pragma once
#include "cMonster.h"
#include "cPassiveAggressiveMonster.h"
class cEnderman : public cMonster
class cEnderman : public cPassiveAggressiveMonster
{
public:
cEnderman();
~cEnderman();
~cEnderman();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,28 +1,7 @@
#include "cGhast.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cGhast::cGhast() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cGhast::cGhast()
{
m_MobType = 56;
GetMonsterConfig("Ghast");
}
@ -33,16 +12,10 @@ cGhast::~cGhast()
bool cGhast::IsA( const char* a_EntityType )
{
//LOG("IsA( cGhast ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cGhast" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cGhast::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cGhast::KilledBy( cEntity* a_Killer )
{
cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
@ -52,34 +25,3 @@ void cGhast::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cGhast::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cGhast::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cGhast::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cGhast::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cGhast : public cMonster
class cGhast : public cAggressiveMonster
{
public:
cGhast();
~cGhast();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
~cGhast();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -10,6 +10,7 @@
#include "Defines.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "packets/cPacket_SpawnMob.h"
#include "packets/cPacket_EntityLook.h"
@ -47,18 +48,17 @@ cMonster::cMonster()
, m_MobType( 0 )
, m_EMState(IDLE)
, m_SightDistance(25)
,m_SeePlayerInterval (0)
,m_EMPersonality(AGGRESSIVE)
,m_AttackDamage(1.0)
,m_AttackRange(5.0)
,m_AttackInterval(0)
,m_AttackRate(3)
,m_bPassiveAggressive(false)
,idle_interval(0)
,m_bBurnable(true)
,m_EMMetaState(NORMAL)
,m_FireDamageInterval(0)
,m_BurnPeriod(0)
, m_SeePlayerInterval (0)
, m_EMPersonality(AGGRESSIVE)
, m_AttackDamage(1.0)
, m_AttackRange(5.0)
, m_AttackInterval(0)
, m_AttackRate(3)
, idle_interval(0)
, m_bBurnable(true)
, m_EMMetaState(NORMAL)
, m_FireDamageInterval(0)
, m_BurnPeriod(0)
{
LOG("cMonster::cMonster()");
LOG("In state: %s",GetState());
@ -77,7 +77,6 @@ cMonster::cMonster()
cMonster::~cMonster()
{
LOG("cMonster::~cMonster()");
delete m_Destination;
delete m_Speed;
@ -85,7 +84,6 @@ cMonster::~cMonster()
bool cMonster::IsA( const char* a_EntityType )
{
//LOG("IsA( cMonster ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cMonster" ) == 0 ) return true;
return cPawn::IsA( a_EntityType );
}
@ -102,7 +100,6 @@ void cMonster::SpawnOn( cClientHandle* a_Target )
Spawn.m_MetaDataSize = 1;
Spawn.m_MetaData = new char[Spawn.m_MetaDataSize];
Spawn.m_MetaData[0] = 0x7f; // not on fire/crouching/riding
//Spawn.m_MetaData[1] = 0x7f; // terminator
if( a_Target == 0 )
{
cChunk* Chunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
@ -142,8 +139,7 @@ void cMonster::Tick(float a_Dt)
return;
}
//a_Dt/=1000;
a_Dt/=1000;
a_Dt /= 1000;
if( m_bMovingToDestination )
{
@ -153,7 +149,7 @@ void cMonster::Tick(float a_Dt)
{
Distance.y = 0;
Distance.Normalize();
Distance*=3;
Distance *= 3;
m_Speed->x = Distance.x;
m_Speed->z = Distance.z;
}
@ -210,24 +206,6 @@ void cMonster::Tick(float a_Dt)
InStateEscaping(a_Dt);
}
m_SeePlayerInterval += a_Dt;
if(m_SeePlayerInterval > 1) {
int rem = rand()%3 + 1; //check most of the time but miss occasionally
//LOG("See Player Interval: %3.3f",m_SeePlayerInterval);
m_SeePlayerInterval = 0.0;
if(rem >= 2) {
if(m_EMState == IDLE && m_EMPersonality != PASSIVE) {
CheckEventSeePlayer();
return;
}
if(m_EMState == CHASING || m_EMState == ESCAPING){
CheckEventLostPlayer();
return;
}
}
}
}
void cMonster::ReplicateMovement()
@ -284,6 +262,8 @@ void cMonster::ReplicateMovement()
m_LastPosZ = GetPosZ();
m_bDirtyPosition = false;
}
MoveToCorrectChunk();
}
void cMonster::HandlePhysics(float a_Dt)
@ -350,20 +330,11 @@ void cMonster::HandlePhysics(float a_Dt)
}
}
void cMonster::TakeDamage( int a_Damage, cEntity* a_Instigator )
void cMonster::TakeDamage(int a_Damage, cEntity* a_Instigator)
{
cPawn::TakeDamage( a_Damage, a_Instigator );
m_Target = a_Instigator;
AddReference( m_Target );
if(m_EMPersonality == AGGRESSIVE) {
m_EMState = CHASING;
}
if(m_EMPersonality == COWARDLY || m_EMPersonality == PASSIVE) {
//m_bPassiveAggressive can be set so if the monster based on time of day for example
//so the monster will only attack if provoked
m_EMState = (m_bPassiveAggressive)? CHASING : ESCAPING;
}
//LOG("Take damage");
m_Target = a_Instigator;
AddReference( m_Target );
}
void cMonster::KilledBy( cEntity* a_Killer )
@ -392,7 +363,8 @@ const char *cMonster::GetState() {
}
//for debugging
void cMonster::SetState(const char* a_str) {
void cMonster::SetState(const char* a_str)
{
std::string str = a_str;
if(str.compare("Idle") == 0 ) {
m_EMState = IDLE;
@ -407,48 +379,38 @@ void cMonster::SetState(const char* a_str) {
//Checks to see if EventSeePlayer should be fired
//monster sez: Do I see the player
void cMonster::CheckEventSeePlayer() {
//LOG("Checking if I see any players");
void cMonster::CheckEventSeePlayer()
{
cMonster::ListClosePlayers(this);
}
void cMonster::CheckEventLostPlayer() {
void cMonster::CheckEventLostPlayer()
{
Vector3f pos;
cTracer LineOfSight(GetWorld() );
//LOG("Checking if I lost my enemy");
if(m_Target != 0) {
pos = m_Target->GetPosition();
if((pos - *m_Pos).Length() > m_SightDistance || LineOfSight.Trace(*m_Pos,(pos - *m_Pos), (int)(pos - *m_Pos).Length())){
//LOG("Losing Player: %5.5f",(pos - *m_Pos).Length());
if((pos - *m_Pos).Length() > m_SightDistance || LineOfSight.Trace(*m_Pos,(pos - *m_Pos), (int)(pos - *m_Pos).Length()))
{
EventLosePlayer();
}
} else {
LOG("Enemy went poof");
EventLosePlayer();
}
}
//What to do if player is seen
//default to change state to chasing
void cMonster::EventSeePlayer(cEntity *a_SeenPlayer) {
void cMonster::EventSeePlayer(cEntity *a_SeenPlayer)
{
m_Target = a_SeenPlayer;
AddReference( m_Target );
if(m_EMPersonality == AGGRESSIVE) {
m_EMState = CHASING;
}
if(m_EMPersonality == COWARDLY) {
m_EMState = ESCAPING;
}
//LOG("Saw Player: %s",GetState());
}
void cMonster::EventLosePlayer(){
Dereference(m_Target);
m_Target = 0;
//LOG("Lost Player");
m_EMState = IDLE;
}
@ -495,7 +457,6 @@ void cMonster::InStateBurning(float a_Dt) {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
m_EMMetaState = NORMAL;
cPacket_Metadata md(NORMAL, GetUniqueID());
//md.m_UniqueID = GetUniqueID();
InChunk->Broadcast(md);
m_BurnPeriod = 0;
@ -527,9 +488,8 @@ void cMonster::InStateEscaping(float a_Dt) {
//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;
m_AttackInterval += a_Dt * m_AttackRate;
if(m_Target != 0 && m_AttackInterval > 3.0) { //Setting this higher gives us more wiggle room for attackrate
//LOG("ATTACK!");
m_AttackInterval = 0.0;
((cPawn *)m_Target)->TakeDamage((int)m_AttackDamage,this);
}
@ -543,7 +503,6 @@ void cMonster::CheckMetaDataBurn() {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
if(!InChunk)
return;
//printf("I should burn");
m_EMMetaState = BURNING;
cPacket_Metadata md(BURNING,GetUniqueID());
InChunk->Broadcast(md);
@ -575,8 +534,8 @@ void cMonster::ListClosePlayers(cMonster *m) {
if((*itr)->GetEntityType() == cEntity::E_PLAYER){
Vector3f pos = (*itr)->GetPosition();
if((pos - *(m->m_Pos)).Length() <= m->m_SightDistance){
if(!LineOfSight.Trace(*(m->m_Pos),(pos - *(m->m_Pos)),(int)(pos - *(m->m_Pos)).Length())){
//LOG("I SEE PLAYER !!!!!!!!!!!!!!!!!");
if(!LineOfSight.Trace(*(m->m_Pos),(pos - *(m->m_Pos)),(int)(pos - *(m->m_Pos)).Length()))
{
m->EventSeePlayer(*itr);
return; //get the first one in sight later we can reiterate and check
//for the closest out of all that match and make it more realistic
@ -585,8 +544,8 @@ void cMonster::ListClosePlayers(cMonster *m) {
}
}
if(tries > 100) {
//LOG("I Give Up");
if(tries > 100)
{
m->EventLosePlayer();
return;
}
@ -594,7 +553,7 @@ void cMonster::ListClosePlayers(cMonster *m) {
}
void cMonster::GetMonsterConfig(const char* pm_name) {
(void)pm_name;
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this, pm_name);
}
void cMonster::SetAttackRate(int ar) {

View File

@ -1,5 +1,7 @@
#pragma once
#include "cPawn.h"
#include "Defines.h"
#include "cWorld.h"
#include "BlockID.h"
class Vector3f;
@ -86,4 +88,5 @@ protected:
void DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count);
void RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max);
}; //tolua_export

View File

@ -0,0 +1,32 @@
#include "cPassiveAggressiveMonster.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::E_PLAYER)
{
cPlayer * Player = (cPlayer *) m_Target;
if(Player->GetGameMode() != 1)
{
m_EMState = CHASING;
}
}
}
void cPassiveAggressiveMonster::EventSeePlayer(cEntity *a_Entity)
{
return cMonster::EventSeePlayer(a_Entity);
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "cAggressiveMonster.h"
class cPassiveAggressiveMonster : public cAggressiveMonster
{
public:
cPassiveAggressiveMonster();
~cPassiveAggressiveMonster();
virtual void TakeDamage(int a_Damage, cEntity* a_Instigator);
void EventSeePlayer(cEntity *a_Entity);
};

View File

@ -0,0 +1,37 @@
#include "cPassiveMonster.h"
cPassiveMonster::cPassiveMonster()
{
m_EMPersonality = PASSIVE;
}
cPassiveMonster::~cPassiveMonster()
{
}
void cPassiveMonster::TakeDamage(int a_Damage, cEntity* a_Instigator)
{
cMonster::TakeDamage(a_Damage, a_Instigator);
m_EMState = ESCAPING;
}
void cPassiveMonster::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
m_SeePlayerInterval += a_Dt;
if(m_SeePlayerInterval > 1)
{
int rem = rand() % 3 + 1; //check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if(rem >= 2) {
if(m_EMState == ESCAPING)
{
CheckEventLostPlayer();
}
}
}
}

14
source/cPassiveMonster.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "cMonster.h"
class cPassiveMonster : public cMonster
{
public:
cPassiveMonster();
~cPassiveMonster();
virtual void Tick(float a_Dt);
virtual void TakeDamage(int a_Damage, cEntity* a_Instigator);
};

View File

@ -1,32 +1,9 @@
#include "cPig.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
#include <string>
cPig::cPig()
: m_ChaseTime( 999999 )
{
//LOG("SPAWNING A Pig!!!!!!!!!!!!!!!!!!!!!");
m_EMPersonality = PASSIVE;
m_MobType = 90;
GetMonsterConfig("Pig");
}
@ -37,16 +14,10 @@ cPig::~cPig()
bool cPig::IsA( const char* a_EntityType )
{
//LOG("IsA( cPig ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cPig" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cPig::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cPig::KilledBy( cEntity* a_Killer )
{
//Drops 0-2 meat
@ -55,31 +26,4 @@ void cPig::KilledBy( cEntity* a_Killer )
//TODO: Check for burning state
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cPig::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cPig::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cPig::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
}

View File

@ -1,21 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cPassiveMonster.h"
class cPig : public cMonster
class cPig : public cPassiveMonster
{
public:
cPig();
~cPig();
~cPig();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,32 +1,9 @@
#include "cSheep.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
#include <string>
//Todo: Implement color
cSheep::cSheep()
: m_ChaseTime( 999999 )
{
//LOG("SPAWNING A Sheep!!!!!!!!!!!!!!!!!!!!!");
m_EMPersonality = PASSIVE;
m_MobType = 91;
GetMonsterConfig("Sheep");
}
@ -37,16 +14,10 @@ cSheep::~cSheep()
bool cSheep::IsA( const char* a_EntityType )
{
//LOG("IsA( cSheep ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSheep" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cSheep::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cSheep::KilledBy( cEntity* a_Killer )
{
//Todo: Check wheather it is sheared
@ -55,31 +26,4 @@ void cSheep::KilledBy( cEntity* a_Killer )
cMonster::DropItem(E_ITEM_WHITE_CLOTH, 1);
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSheep::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSheep::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSheep::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
}

View File

@ -1,21 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cPassiveMonster.h"
class cSheep : public cMonster
class cSheep : public cPassiveMonster
{
public:
cSheep();
~cSheep();
~cSheep();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,28 +1,7 @@
#include "cSilverfish.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cSilverfish::cSilverfish() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cSilverfish::cSilverfish()
{
m_MobType = 60;
GetMonsterConfig("Silverfish");
}
@ -33,50 +12,7 @@ cSilverfish::~cSilverfish()
bool cSilverfish::IsA( const char* a_EntityType )
{
//LOG("IsA( cSilverfish ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSilverfish" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cSilverfish::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cSilverfish::KilledBy( cEntity* a_Killer )
{
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSilverfish::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSilverfish::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSilverfish::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cSilverfish::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,12 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cSilverfish : public cMonster
class cSilverfish : public cAggressiveMonster
{
public:
cSilverfish();
~cSilverfish();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
~cSilverfish();
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
virtual bool IsA( const char* a_EntityType );
};

View File

@ -1,28 +1,7 @@
#include "cSkeleton.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cSkeleton::cSkeleton() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = false;
//m_AttackRate = 1;
cSkeleton::cSkeleton()
{
m_MobType = 51;
GetMonsterConfig("Skeleton");
}
@ -33,7 +12,6 @@ cSkeleton::~cSkeleton()
bool cSkeleton::IsA( const char* a_EntityType )
{
//LOG("IsA( cSkeleton ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSkeleton" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
@ -41,6 +19,9 @@ bool cSkeleton::IsA( const char* 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) ) { //if daylight
m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D
}
@ -54,35 +35,3 @@ void cSkeleton::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSkeleton::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSkeleton::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSkeleton::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cSkeleton::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,16 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cSkeleton : public cMonster
class cSkeleton : public cAggressiveMonster
{
public:
cSkeleton();
~cSkeleton();
~cSkeleton();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,30 +1,9 @@
#include "cSlime.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
//TODO Implement sized slimes
cSlime::cSlime() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cSlime::cSlime()
{
m_MobType = 55;
GetMonsterConfig("Slime");
}
@ -35,52 +14,14 @@ cSlime::~cSlime()
bool cSlime::IsA( const char* a_EntityType )
{
//LOG("IsA( cSlime ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSlime" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cSlime::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cSlime::KilledBy( cEntity* a_Killer )
{
//TODO: only when tiny
cMonster::RandomDropItem(E_ITEM_SLIMEBALL, 0, 2);
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSlime::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSlime::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSlime::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cSlime::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}
}

View File

@ -1,22 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cSlime : public cMonster
class cSlime : public cAggressiveMonster
{
public:
cSlime();
~cSlime();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
~cSlime();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,28 +1,7 @@
#include "cSpider.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cSpider::cSpider() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cSpider::cSpider()
{
m_MobType = 52;
GetMonsterConfig("Spider");
}
@ -33,17 +12,10 @@ cSpider::~cSpider()
bool cSpider::IsA( const char* a_EntityType )
{
//LOG("IsA( cSpider ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSpider" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cSpider::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
m_EMPersonality = (GetWorld()->GetWorldTime() < (12000 + 1000) )? PASSIVE:AGGRESSIVE;
}
void cSpider::KilledBy( cEntity* a_Killer )
{
cMonster::RandomDropItem(E_ITEM_STRING, 0, 2);
@ -52,35 +24,3 @@ void cSpider::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSpider::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSpider::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSpider::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cSpider::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,14 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cSpider : public cMonster
class cSpider : public cAggressiveMonster
{
public:
cSpider();
~cSpider();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
~cSpider();
virtual bool IsA( const char* a_EntityType );
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,32 +1,7 @@
#include "cSquid.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
#include <string>
cSquid::cSquid()
: m_ChaseTime( 999999 )
{
//LOG("SPAWNING A Squid!!!!!!!!!!!!!!!!!!!!!");
m_EMPersonality = PASSIVE;
m_MobType = 94;
GetMonsterConfig("Squid");
}
@ -37,16 +12,10 @@ cSquid::~cSquid()
bool cSquid::IsA( const char* a_EntityType )
{
//LOG("IsA( cSquid ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cSquid" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cSquid::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cSquid::KilledBy( cEntity* a_Killer )
{
//Drops 0-3 Ink Sacs
@ -54,30 +23,3 @@ void cSquid::KilledBy( cEntity* a_Killer )
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cSquid::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cSquid::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cSquid::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}

View File

@ -1,21 +1,13 @@
#pragma once
#include "cMonster.h"
#include "cPassiveMonster.h"
class cSquid : public cMonster
class cSquid : public cPassiveMonster
{
public:
cSquid();
~cSquid();
virtual bool IsA( const char* a_EntityType );
~cSquid();
virtual void Tick(float a_Dt);
virtual bool IsA( const char* a_EntityType );
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,28 +1,7 @@
#include "cWolf.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cWolf::cWolf() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = PASSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cWolf::cWolf()
{
m_MobType = 95;
GetMonsterConfig("Wolf");
}
@ -33,50 +12,6 @@ cWolf::~cWolf()
bool cWolf::IsA( const char* a_EntityType )
{
//LOG("IsA( cWolf ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cWolf" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
void cWolf::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
}
void cWolf::KilledBy( cEntity* a_Killer )
{
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cWolf::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cWolf::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cWolf::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cWolf::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,12 @@
#pragma once
#include "cMonster.h"
#include "cPassiveAggressiveMonster.h"
class cWolf : public cMonster
class cWolf : public cPassiveAggressiveMonster
{
public:
cWolf();
~cWolf();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
~cWolf();
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
virtual bool IsA( const char* a_EntityType );
};

View File

@ -1,28 +1,7 @@
#include "cZombie.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cZombie::cZombie() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
m_bPassiveAggressive = false;
//m_AttackRate = 1;
cZombie::cZombie()
{
m_MobType = 54;
GetMonsterConfig("Zombie");
}
@ -33,7 +12,6 @@ cZombie::~cZombie()
bool cZombie::IsA( const char* a_EntityType )
{
//LOG("IsA( cZombie ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cZombie" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
@ -41,6 +19,8 @@ bool cZombie::IsA( const char* a_EntityType )
void cZombie::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
//TODO Same as in cSkeleton :D
if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight
m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D
}
@ -50,38 +30,5 @@ void cZombie::KilledBy( cEntity* a_Killer )
{
cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cZombie::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cZombie::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cZombie::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cZombie::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,15 @@
#pragma once
#include "cMonster.h"
#include "cAggressiveMonster.h"
class cZombie : public cMonster
class cZombie : public cAggressiveMonster
{
public:
cZombie();
~cZombie();
~cZombie();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};

View File

@ -1,28 +1,7 @@
#include "cZombiepigman.h"
#include "Vector3f.h"
#include "Vector3d.h"
#include "Defines.h"
#include "cRoot.h"
#include "cWorld.h"
#include "cPickup.h"
#include "cItem.h"
#include "cMonsterConfig.h"
#include "cMCLogger.h"
#ifndef _WIN32
#include <stdlib.h> // rand()
#include <cstring>
#endif
cZombiepigman::cZombiepigman() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = PASSIVE;
m_bPassiveAggressive = true;
//m_AttackRate = 1;
cZombiepigman::cZombiepigman()
{
m_MobType = 57;
GetMonsterConfig("Zombiepigman");
}
@ -33,7 +12,6 @@ cZombiepigman::~cZombiepigman()
bool cZombiepigman::IsA( const char* a_EntityType )
{
//LOG("IsA( cZombiepigman ) : %s", a_EntityType);
if( strcmp( a_EntityType, "cZombiepigman" ) == 0 ) return true;
return cMonster::IsA( a_EntityType );
}
@ -41,6 +19,8 @@ bool cZombiepigman::IsA( const char* a_EntityType )
void cZombiepigman::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
//TODO Same as noticed in cSkeleton AND Do they really burn? :D In the neather there is no sun :D
if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight
m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D
}
@ -48,43 +28,8 @@ void cZombiepigman::Tick(float a_Dt)
void cZombiepigman::KilledBy( cEntity* a_Killer )
{
//Drops 0-1 Rottenflesh
cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
//Drops 0-1 gold nuggets
cMonster::RandomDropItem(E_ITEM_GOLD_NUGGET, 0, 2);
cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 1);
cMonster::RandomDropItem(E_ITEM_GOLD_NUGGET, 0, 1);
cMonster::KilledBy( a_Killer );
}
//What to do if in Idle State
void cZombiepigman::InStateIdle(float a_Dt) {
cMonster::InStateIdle(a_Dt);
}
//What to do if in Chasing State
void cZombiepigman::InStateChasing(float a_Dt) {
cMonster::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if( m_Target )
{
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 cZombiepigman::InStateEscaping(float a_Dt) {
cMonster::InStateEscaping(a_Dt);
}
void cZombiepigman::GetMonsterConfig(const char* pm_name) {
LOG("I am gettin my attributes: %s", pm_name);
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this,pm_name);
}

View File

@ -1,22 +1,15 @@
#pragma once
#include "cMonster.h"
#include "cPassiveAggressiveMonster.h"
class cZombiepigman : public cMonster
class cZombiepigman : public cPassiveAggressiveMonster
{
public:
cZombiepigman();
~cZombiepigman();
~cZombiepigman();
virtual bool IsA( const char* a_EntityType );
virtual void GetMonsterConfig(const char* pm_name);
virtual void Tick(float a_Dt);
virtual void KilledBy( cEntity* a_Killer );
virtual void InStateIdle(float a_Dt);
virtual void InStateChasing(float a_Dt);
virtual void InStateEscaping(float a_Dt);
//float m_ChaseTime;
protected:
float m_ChaseTime;
};
};