From a26a0e3825bb337a4be0f0c7f171e4cbd450bded Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Tue, 25 Oct 2011 23:46:01 +0000 Subject: git-svn-id: http://mc-server.googlecode.com/svn/trunk@10 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cCavespider.cpp | 92 +++++++++++++++++++++++++++++++++ source/cCavespider.h | 22 ++++++++ source/cCow.cpp | 90 ++++++++++++++++++++++++++++++++ source/cCow.h | 21 ++++++++ source/cCreeper.cpp | 91 +++++++++++++++++++++++++++++++++ source/cCreeper.h | 22 ++++++++ source/cEnderman.cpp | 94 ++++++++++++++++++++++++++++++++++ source/cEnderman.h | 22 ++++++++ source/cGhast.cpp | 91 +++++++++++++++++++++++++++++++++ source/cGhast.h | 22 ++++++++ source/cPig.cpp | 90 ++++++++++++++++++++++++++++++++ source/cPig.h | 21 ++++++++ source/cSheep.cpp | 90 ++++++++++++++++++++++++++++++++ source/cSheep.h | 21 ++++++++ source/cSilverfish.cpp | 91 +++++++++++++++++++++++++++++++++ source/cSilverfish.h | 22 ++++++++ source/cSkeleton.cpp | 94 ++++++++++++++++++++++++++++++++++ source/cSkeleton.h | 22 ++++++++ source/cSlime.cpp | 91 +++++++++++++++++++++++++++++++++ source/cSlime.h | 22 ++++++++ source/cSquid.cpp | 90 ++++++++++++++++++++++++++++++++ source/cSquid.h | 21 ++++++++ source/cWolf.cpp | 91 +++++++++++++++++++++++++++++++++ source/cWolf.h | 22 ++++++++ source/cWorld.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++---- source/cZombie.cpp | 94 ++++++++++++++++++++++++++++++++++ source/cZombie.h | 22 ++++++++ source/cZombiepigman.cpp | 94 ++++++++++++++++++++++++++++++++++ source/cZombiepigman.h | 22 ++++++++ 29 files changed, 1707 insertions(+), 10 deletions(-) create mode 100644 source/cCavespider.cpp create mode 100644 source/cCavespider.h create mode 100644 source/cCow.cpp create mode 100644 source/cCow.h create mode 100644 source/cCreeper.cpp create mode 100644 source/cCreeper.h create mode 100644 source/cEnderman.cpp create mode 100644 source/cEnderman.h create mode 100644 source/cGhast.cpp create mode 100644 source/cGhast.h create mode 100644 source/cPig.cpp create mode 100644 source/cPig.h create mode 100644 source/cSheep.cpp create mode 100644 source/cSheep.h create mode 100644 source/cSilverfish.cpp create mode 100644 source/cSilverfish.h create mode 100644 source/cSkeleton.cpp create mode 100644 source/cSkeleton.h create mode 100644 source/cSlime.cpp create mode 100644 source/cSlime.h create mode 100644 source/cSquid.cpp create mode 100644 source/cSquid.h create mode 100644 source/cWolf.cpp create mode 100644 source/cWolf.h create mode 100644 source/cZombie.cpp create mode 100644 source/cZombie.h create mode 100644 source/cZombiepigman.cpp create mode 100644 source/cZombiepigman.h (limited to 'source') diff --git a/source/cCavespider.cpp b/source/cCavespider.cpp new file mode 100644 index 000000000..75673d5ec --- /dev/null +++ b/source/cCavespider.cpp @@ -0,0 +1,92 @@ +#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 // rand() +#include +#endif + +cCavespider::cCavespider() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 59; + GetMonsterConfig("Cavespider"); +} + +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 ); +} + +void cCavespider::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + m_EMPersonality = (cRoot::Get()->GetWorld()->GetWorldTime() < (12000 + 1000) )? PASSIVE:AGGRESSIVE; +} + +void cCavespider::KilledBy( cEntity* a_Killer ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cCavespider.h b/source/cCavespider.h new file mode 100644 index 000000000..4709e3392 --- /dev/null +++ b/source/cCavespider.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cCavespider : public cMonster +{ +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; +}; diff --git a/source/cCow.cpp b/source/cCow.cpp new file mode 100644 index 000000000..3f6286dec --- /dev/null +++ b/source/cCow.cpp @@ -0,0 +1,90 @@ +#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 // rand() +#include +#endif + +#include + + + +cCow::cCow() + : m_ChaseTime( 999999 ) + +{ + //LOG("SPAWNING A Cow!!!!!!!!!!!!!!!!!!!!!"); + m_EMPersonality = PASSIVE; + m_MobType = 92; + GetMonsterConfig("Cow"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cCow.h b/source/cCow.h new file mode 100644 index 000000000..512bb3ed3 --- /dev/null +++ b/source/cCow.h @@ -0,0 +1,21 @@ +#pragma once + +#include "cMonster.h" + +class cCow : public cMonster +{ +public: + cCow(); + ~cCow(); + + 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; +}; diff --git a/source/cCreeper.cpp b/source/cCreeper.cpp new file mode 100644 index 000000000..ffebc2c58 --- /dev/null +++ b/source/cCreeper.cpp @@ -0,0 +1,91 @@ +#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 // rand() +#include +#endif + +cCreeper::cCreeper() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 50; + GetMonsterConfig("Creeper"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cCreeper.h b/source/cCreeper.h new file mode 100644 index 000000000..66dfac2e8 --- /dev/null +++ b/source/cCreeper.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cCreeper : public cMonster +{ +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; +}; diff --git a/source/cEnderman.cpp b/source/cEnderman.cpp new file mode 100644 index 000000000..42a57a613 --- /dev/null +++ b/source/cEnderman.cpp @@ -0,0 +1,94 @@ +#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 // rand() +#include +#endif + +cEnderman::cEnderman() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = PASSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 58; + GetMonsterConfig("Enderman"); +} + +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 ); +} + +void cEnderman::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + if (cRoot::Get()->GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight + m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + } +} + +void cEnderman::KilledBy( cEntity* a_Killer ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cEnderman.h b/source/cEnderman.h new file mode 100644 index 000000000..56d3f87bd --- /dev/null +++ b/source/cEnderman.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cEnderman : public cMonster +{ +public: + 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; +}; diff --git a/source/cGhast.cpp b/source/cGhast.cpp new file mode 100644 index 000000000..54c89a279 --- /dev/null +++ b/source/cGhast.cpp @@ -0,0 +1,91 @@ +#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 // rand() +#include +#endif + +cGhast::cGhast() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 56; + GetMonsterConfig("Ghast"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cGhast.h b/source/cGhast.h new file mode 100644 index 000000000..c35e0ec19 --- /dev/null +++ b/source/cGhast.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cGhast : public cMonster +{ +public: + cGhast(); + ~cGhast(); + + 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; +}; diff --git a/source/cPig.cpp b/source/cPig.cpp new file mode 100644 index 000000000..fa86949ab --- /dev/null +++ b/source/cPig.cpp @@ -0,0 +1,90 @@ +#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 // rand() +#include +#endif + +#include + + + +cPig::cPig() + : m_ChaseTime( 999999 ) + +{ + //LOG("SPAWNING A Pig!!!!!!!!!!!!!!!!!!!!!"); + m_EMPersonality = PASSIVE; + m_MobType = 90; + GetMonsterConfig("Pig"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cPig.h b/source/cPig.h new file mode 100644 index 000000000..7bc958ed0 --- /dev/null +++ b/source/cPig.h @@ -0,0 +1,21 @@ +#pragma once + +#include "cMonster.h" + +class cPig : public cMonster +{ +public: + 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; +}; diff --git a/source/cSheep.cpp b/source/cSheep.cpp new file mode 100644 index 000000000..98d17e4d4 --- /dev/null +++ b/source/cSheep.cpp @@ -0,0 +1,90 @@ +#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 // rand() +#include +#endif + +#include + + + +cSheep::cSheep() + : m_ChaseTime( 999999 ) + +{ + //LOG("SPAWNING A Sheep!!!!!!!!!!!!!!!!!!!!!"); + m_EMPersonality = PASSIVE; + m_MobType = 91; + GetMonsterConfig("Sheep"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cSheep.h b/source/cSheep.h new file mode 100644 index 000000000..948df55f4 --- /dev/null +++ b/source/cSheep.h @@ -0,0 +1,21 @@ +#pragma once + +#include "cMonster.h" + +class cSheep : public cMonster +{ +public: + 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; +}; diff --git a/source/cSilverfish.cpp b/source/cSilverfish.cpp new file mode 100644 index 000000000..25a3befa6 --- /dev/null +++ b/source/cSilverfish.cpp @@ -0,0 +1,91 @@ +#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 // rand() +#include +#endif + +cSilverfish::cSilverfish() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 60; + GetMonsterConfig("Silverfish"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cSilverfish.h b/source/cSilverfish.h new file mode 100644 index 000000000..471a0274d --- /dev/null +++ b/source/cSilverfish.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cSilverfish : public cMonster +{ +public: + cSilverfish(); + ~cSilverfish(); + + 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; +}; diff --git a/source/cSkeleton.cpp b/source/cSkeleton.cpp new file mode 100644 index 000000000..84de27d7a --- /dev/null +++ b/source/cSkeleton.cpp @@ -0,0 +1,94 @@ +#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 // rand() +#include +#endif + +cSkeleton::cSkeleton() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = false; + //m_AttackRate = 1; + m_MobType = 51; + GetMonsterConfig("Skeleton"); +} + +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 ); +} + +void cSkeleton::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + if (cRoot::Get()->GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight + m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + } +} + +void cSkeleton::KilledBy( cEntity* a_Killer ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cSkeleton.h b/source/cSkeleton.h new file mode 100644 index 000000000..f30ef23c4 --- /dev/null +++ b/source/cSkeleton.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cSkeleton : public cMonster +{ +public: + 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; +}; diff --git a/source/cSlime.cpp b/source/cSlime.cpp new file mode 100644 index 000000000..c568ac78c --- /dev/null +++ b/source/cSlime.cpp @@ -0,0 +1,91 @@ +#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 // rand() +#include +#endif + +cSlime::cSlime() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 55; + GetMonsterConfig("Slime"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cSlime.h b/source/cSlime.h new file mode 100644 index 000000000..5f492ebe6 --- /dev/null +++ b/source/cSlime.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cSlime : public cMonster +{ +public: + cSlime(); + ~cSlime(); + + 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; +}; diff --git a/source/cSquid.cpp b/source/cSquid.cpp new file mode 100644 index 000000000..e528e7e95 --- /dev/null +++ b/source/cSquid.cpp @@ -0,0 +1,90 @@ +#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 // rand() +#include +#endif + +#include + + + +cSquid::cSquid() + : m_ChaseTime( 999999 ) + +{ + //LOG("SPAWNING A Squid!!!!!!!!!!!!!!!!!!!!!"); + m_EMPersonality = PASSIVE; + m_MobType = 94; + GetMonsterConfig("Squid"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cSquid.h b/source/cSquid.h new file mode 100644 index 000000000..429bd50ac --- /dev/null +++ b/source/cSquid.h @@ -0,0 +1,21 @@ +#pragma once + +#include "cMonster.h" + +class cSquid : public cMonster +{ +public: + cSquid(); + ~cSquid(); + + 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; +}; diff --git a/source/cWolf.cpp b/source/cWolf.cpp new file mode 100644 index 000000000..5a2c14f83 --- /dev/null +++ b/source/cWolf.cpp @@ -0,0 +1,91 @@ +#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 // rand() +#include +#endif + +cWolf::cWolf() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = PASSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 95; + GetMonsterConfig("Wolf"); +} + +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 ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cWolf.h b/source/cWolf.h new file mode 100644 index 000000000..5cb30700b --- /dev/null +++ b/source/cWolf.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cWolf : public cMonster +{ +public: + cWolf(); + ~cWolf(); + + 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; +}; diff --git a/source/cWorld.cpp b/source/cWorld.cpp index e634ea112..aa1c8ba22 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -15,6 +15,20 @@ #include "cWaterSimulator.h" #include "cChicken.h" #include "cSpider.h" +#include "cCow.h" //cow +#include "cSquid.h" //Squid +#include "cWolf.h" //wolf +#include "cSlime.h" //slime +#include "cSkeleton.h" //Skeleton +#include "cSilverfish.h" //Silverfish +#include "cPig.h" //pig +#include "cSheep.h" //sheep +#include "cZombie.h" //zombie +#include "cEnderman.h" //enderman +#include "cCreeper.h" //creeper +#include "cCavespider.h" //cavespider +#include "cGhast.h" //Ghast +#include "cZombiepigman.h" //Zombiepigman #include "cGenSettings.h" @@ -316,8 +330,29 @@ void cWorld::Tick(float a_Dt) m_SpawnMonsterTime = m_Time; if( m_pState->m_Players.size() > 0 ) { - cChicken *Chicken; - cSpider *Spider; + + cChicken *Chicken; + cCow *Cow; + cPig *Pig; + cSheep *Sheep; + cSquid *Squid; + cWolf *Wolf; + + cSpider *Spider; + cZombie *Zombie; + cEnderman *Enderman; + cCreeper *Creeper; + cGhast *Ghast; + cCavespider *Cavespider; + cZombiepigman *Zombiepigman; + cSkeleton *Skeleton; + cSlime *Slime; + cSilverfish *Silverfish; + + srand ( time(NULL) ); //added mob code + int dayRand = rand() % 6; //added mob code + int nightRand = rand() % 10; //added mob code + int RandomPlayerIdx = rand() & m_pState->m_Players.size(); PlayerList::iterator itr = m_pState->m_Players.begin(); for( int i = 1; i < RandomPlayerIdx; i++ ) @@ -330,15 +365,90 @@ void cWorld::Tick(float a_Dt) //cMonster* Monster = new cChicken(); if(m_WorldTime >= 12000 + 1000) { - Spider = new cSpider(); - Spider->Initialize(); - Spider->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Spider->SpawnOn( 0 ); + if (nightRand == 0) { //random percent to spawn for night + Spider = new cSpider(); + Spider->Initialize(); + Spider->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Spider->SpawnOn( 0 ); + } else if (nightRand == 1) { + Zombie = new cZombie(); + Zombie->Initialize(); + Zombie->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Zombie->SpawnOn( 0 ); + } else if (nightRand == 2) { + Enderman = new cEnderman(); + Enderman->Initialize(); + Enderman->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Enderman->SpawnOn( 0 ); + } else if (nightRand == 3) { + Creeper = new cCreeper(); + Creeper->Initialize(); + Creeper->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Creeper->SpawnOn( 0 ); + } else if (nightRand == 4) { + Cavespider = new cCavespider(); + Cavespider->Initialize(); + Cavespider->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Cavespider->SpawnOn( 0 ); + } else if (nightRand == 5) { + Ghast = new cGhast(); + Ghast->Initialize(); + Ghast->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Ghast->SpawnOn( 0 ); + } else if (nightRand == 6) { + Zombiepigman = new cZombiepigman(); + Zombiepigman->Initialize(); + Zombiepigman->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Zombiepigman->SpawnOn( 0 ); + } else if (nightRand == 7) { + Slime = new cSlime(); + Slime->Initialize(); + Slime->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Slime->SpawnOn( 0 ); + } else if (nightRand == 8) { + Silverfish = new cSilverfish(); + Silverfish->Initialize(); + Silverfish->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Silverfish->SpawnOn( 0 ); + } else if (nightRand == 9) { + Skeleton = new cSkeleton(); + Skeleton->Initialize(); + Skeleton->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Skeleton->SpawnOn( 0 ); + } //end random percent to spawn for night + } else { - Chicken = new cChicken(); - Chicken->Initialize(); - Chicken->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Chicken->SpawnOn( 0 ); + if (dayRand == 0) { //random percent to spawn for day + Chicken = new cChicken(); + Chicken->Initialize(); + Chicken->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Chicken->SpawnOn( 0 ); + } else if (dayRand == 1) { + Cow = new cCow(); + Cow->Initialize(); + Cow->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Cow->SpawnOn( 0 ); + } else if (dayRand == 2) { + Pig = new cPig(); + Pig->Initialize(); + Pig->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Pig->SpawnOn( 0 ); + } else if (dayRand == 3) { + Sheep = new cSheep(); + Sheep->Initialize(); + Sheep->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Sheep->SpawnOn( 0 ); + } else if (dayRand == 4) { + Squid = new cSquid(); + Squid->Initialize(); + Squid->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Squid->SpawnOn( 0 ); + } else if (dayRand == 5) { + Wolf = new cWolf(); + Wolf->Initialize(); + Wolf->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Wolf->SpawnOn( 0 ); + } //end random percent to spawn for day } //Monster->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); //Monster->SpawnOn( 0 ); diff --git a/source/cZombie.cpp b/source/cZombie.cpp new file mode 100644 index 000000000..23953f274 --- /dev/null +++ b/source/cZombie.cpp @@ -0,0 +1,94 @@ +#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 // rand() +#include +#endif + +cZombie::cZombie() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = AGGRESSIVE; + m_bPassiveAggressive = false; + //m_AttackRate = 1; + m_MobType = 54; + GetMonsterConfig("Zombie"); +} + +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 ); +} + +void cZombie::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + if (cRoot::Get()->GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight + m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + } +} + +void cZombie::KilledBy( cEntity* a_Killer ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cZombie.h b/source/cZombie.h new file mode 100644 index 000000000..fdc628822 --- /dev/null +++ b/source/cZombie.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cZombie : public cMonster +{ +public: + 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; +}; diff --git a/source/cZombiepigman.cpp b/source/cZombiepigman.cpp new file mode 100644 index 000000000..5ace226af --- /dev/null +++ b/source/cZombiepigman.cpp @@ -0,0 +1,94 @@ +#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 // rand() +#include +#endif + +cZombiepigman::cZombiepigman() : m_ChaseTime(999999) { + m_bBurnable = true; + m_EMPersonality = PASSIVE; + m_bPassiveAggressive = true; + //m_AttackRate = 1; + m_MobType = 57; + GetMonsterConfig("Zombiepigman"); +} + +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 ); +} + +void cZombiepigman::Tick(float a_Dt) +{ + cMonster::Tick(a_Dt); + if (cRoot::Get()->GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight + m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + } +} + +void cZombiepigman::KilledBy( cEntity* a_Killer ) +{ + if( (rand() % 5) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) ); + Pickup->Initialize(); + } + if( (rand() % 1) == 0 ) + { + cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) ); + Pickup->Initialize(); + } + 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); +} diff --git a/source/cZombiepigman.h b/source/cZombiepigman.h new file mode 100644 index 000000000..45c588dcd --- /dev/null +++ b/source/cZombiepigman.h @@ -0,0 +1,22 @@ +#pragma once + +#include "cMonster.h" + +class cZombiepigman : public cMonster +{ +public: + 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; +}; -- cgit v1.2.3