Reduced most mobs' constructors to oneliners by passing parameters to superclasses

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1095 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-12-22 09:39:13 +00:00
parent 48c00fdaee
commit aebe130299
38 changed files with 122 additions and 236 deletions

View File

@ -726,10 +726,6 @@
RelativePath="..\source\Mobs\AggressiveMonster.h"
>
</File>
<File
RelativePath="..\source\Mobs\Bat.cpp"
>
</File>
<File
RelativePath="..\source\Mobs\Bat.h"
>
@ -814,10 +810,6 @@
RelativePath="..\source\Mobs\Mooshroom.h"
>
</File>
<File
RelativePath="..\source\Mobs\Ocelot.cpp"
>
</File>
<File
RelativePath="..\source\Mobs\Ocelot.h"
>
@ -854,10 +846,6 @@
RelativePath="..\source\Mobs\Sheep.h"
>
</File>
<File
RelativePath="..\source\Mobs\Silverfish.cpp"
>
</File>
<File
RelativePath="..\source\Mobs\Silverfish.h"
>
@ -910,10 +898,6 @@
RelativePath="..\source\Mobs\Witch.h"
>
</File>
<File
RelativePath="..\source\Mobs\Wolf.cpp"
>
</File>
<File
RelativePath="..\source\Mobs\Wolf.h"
>

View File

@ -11,8 +11,9 @@
cAggressiveMonster::cAggressiveMonster()
: m_ChaseTime(999999)
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath),
m_ChaseTime(999999)
{
m_EMPersonality = AGGRESSIVE;
}

View File

@ -13,7 +13,7 @@ class cAggressiveMonster :
typedef cMonster super;
public:
cAggressiveMonster(void);
cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
virtual void Tick(float a_Dt) override;
virtual void InStateChasing(float a_Dt) override;

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Bat.h"
cBat::cBat(void)
{
m_MobType = 65;
m_SoundHurt = "mob.bat.hurt";
m_SoundDeath = "mob.bat.death";
GetMonsterConfig("Bat");
}

View File

@ -13,7 +13,10 @@ class cBat :
typedef cPassiveMonster super;
public:
cBat(void);
cBat(void) :
super("Bat", 65, "mob.bat.hurt", "mob.bat.death")
{
}
CLASS_PROTODEF(cBat);
} ;

View File

@ -7,12 +7,9 @@
cBlaze::cBlaze(void)
cBlaze::cBlaze(void) :
super("Blaze", 61, "mob.blaze.hit", "mob.blaze.death")
{
m_MobType = 61;
m_SoundHurt = "mob.blaze.hit";
m_SoundDeath = "mob.blaze.death";
GetMonsterConfig("Blaze");
}

View File

@ -7,12 +7,9 @@
cCavespider::cCavespider(void)
cCavespider::cCavespider(void) :
super("Cavespider", 59, "mob.spider.say", "mob.spider.death")
{
m_MobType = 59;
m_SoundHurt = "mob.spider.say";
m_SoundDeath = "mob.spider.death";
GetMonsterConfig("Cavespider");
}

View File

@ -13,12 +13,9 @@
cChicken::cChicken(void)
cChicken::cChicken(void) :
super("Chicken", 93, "mob.chicken.hurt", "mob.chicken.hurt")
{
m_MobType = 93;
m_SoundHurt = "mob.chicken.hurt";
m_SoundDeath = "mob.chicken.hurt";
GetMonsterConfig("Chicken");
}

View File

@ -13,12 +13,9 @@
cCow::cCow(void)
cCow::cCow(void) :
super("Cow", 92, "mob.cow.hurt", "mob.cow.hurt")
{
m_MobType = 92;
m_SoundHurt = "mob.cow.hurt";
m_SoundDeath = "mob.cow.hurt";
GetMonsterConfig("Cow");
}

View File

@ -7,12 +7,9 @@
cCreeper::cCreeper(void)
cCreeper::cCreeper(void) :
super("Creeper", 50, "mob.creeper.say", "mob.creeper.say")
{
m_MobType = 50;
m_SoundHurt = "mob.creeper.say";
m_SoundDeath = "mob.creeper.say";
GetMonsterConfig("Creeper");
}

View File

@ -7,12 +7,9 @@
cEnderman::cEnderman(void)
cEnderman::cEnderman(void) :
super("Enderman", 58, "mob.endermen.hit", "mob.endermen.death")
{
m_MobType = 58;
m_SoundHurt = "mob.endermen.hit";
m_SoundDeath = "mob.endermen.death";
GetMonsterConfig("Enderman");
}

View File

@ -7,12 +7,9 @@
cGhast::cGhast(void)
cGhast::cGhast(void) :
super("Ghast", 56, "mob.ghast.scream", "mob.ghast.death")
{
m_MobType = 56;
m_SoundHurt = "mob.ghast.scream";
m_SoundDeath = "mob.ghast.death";
GetMonsterConfig("Ghast");
}

View File

@ -7,12 +7,9 @@
cMagmacube::cMagmacube()
cMagmacube::cMagmacube(void) :
super("Magmacube", 62, "mob.magmacube.big", "mob.magmacube.big")
{
m_MobType = 62;
m_SoundHurt = "mob.magmacube.big";
m_SoundDeath = "mob.magmacube.big";
GetMonsterConfig("Magmacube");
}

View File

@ -16,19 +16,13 @@
#include "../Vector3d.h"
#include "../Tracer.h"
#include "../../iniFile/iniFile.h"
/*
#ifndef _WIN32
#include <unistd.h>
#endif
*/
// #include "../../iniFile/iniFile.h"
cMonster::cMonster(void)
cMonster::cMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath)
: super(etMob)
, m_Target(NULL)
, m_bMovingToDestination(false)
@ -37,9 +31,9 @@ cMonster::cMonster(void)
, m_bOnGround( false )
, m_DestroyTimer( 0 )
, m_Jump(0)
, m_MobType( 0 )
, m_SoundHurt( "" )
, m_SoundDeath( "" )
, m_MobType(a_ProtocolMobType)
, m_SoundHurt(a_SoundHurt)
, m_SoundDeath(a_SoundDeath)
, m_EMState(IDLE)
, m_SightDistance(25)
, m_SeePlayerInterval (0)
@ -50,11 +44,10 @@ cMonster::cMonster(void)
, m_AttackRate(3)
, idle_interval(0)
{
LOGD("cMonster::cMonster()");
LOGD("In state: %s", GetState());
m_bBurnable = true;
m_MetaData = NORMAL;
if (!a_ConfigName.empty())
{
GetMonsterConfig(a_ConfigName);
}
}
@ -520,9 +513,9 @@ cPlayer * cMonster::FindClosestPlayer(void)
void cMonster::GetMonsterConfig(const char* pm_name)
void cMonster::GetMonsterConfig(const AString & a_Name)
{
cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, pm_name);
cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name);
}

View File

@ -25,7 +25,12 @@ class cMonster :
public:
// tolua_end
cMonster(void);
/** Creates the mob object.
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
* a_ProtocolMobType is the ID of the mob used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22)
* a_SoundHurt and a_SoundDeath are assigned into m_SoundHurt and m_SoundDeath, respectively
*/
cMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
CLASS_PROTODEF(cMonster);
@ -52,7 +57,10 @@ public:
virtual void EventSeePlayer(cEntity *);
float m_SightDistance;
virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo
virtual void GetMonsterConfig(const char* pm_name);
/// Reads the monster configuration for the specified monster name and assigns it to this object.
void GetMonsterConfig(const AString & a_Name);
virtual void EventLosePlayer();
virtual void CheckEventLostPlayer();

View File

@ -13,12 +13,9 @@
cMooshroom::cMooshroom(void)
cMooshroom::cMooshroom(void) :
super("Mooshroom", 96, "mob.cow.hurt", "mob.cow.hurt")
{
m_MobType = 96;
m_SoundHurt = "mob.cow.hurt";
m_SoundDeath = "mob.cow.hurt";
GetMonsterConfig("Mooshroom");
}

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Ocelot.h"
cOcelot::cOcelot()
{
m_MobType = 98;
m_SoundHurt = "mob.cat.hitt";
m_SoundDeath = "mob.cat.hitt";
GetMonsterConfig("Ocelot");
}

View File

@ -13,7 +13,10 @@ class cOcelot :
typedef cPassiveMonster super;
public:
cOcelot();
cOcelot(void) :
super("Ocelot", 98, "mob.cat.hitt", "mob.cat.hitt")
{
}
CLASS_PROTODEF(cOcelot);
} ;

View File

@ -9,7 +9,8 @@
cPassiveAggressiveMonster::cPassiveAggressiveMonster(void)
cPassiveAggressiveMonster::cPassiveAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath)
{
m_EMPersonality = PASSIVE;
}

View File

@ -13,7 +13,7 @@ class cPassiveAggressiveMonster :
typedef cAggressiveMonster super;
public:
cPassiveAggressiveMonster(void);
cPassiveAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;

View File

@ -8,7 +8,8 @@
cPassiveMonster::cPassiveMonster(void)
cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath)
{
m_EMPersonality = PASSIVE;
}
@ -32,7 +33,7 @@ void cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
void cPassiveMonster::Tick(float a_Dt)
{
cMonster::Tick(a_Dt);
super::Tick(a_Dt);
m_SeePlayerInterval += a_Dt;

View File

@ -13,7 +13,7 @@ class cPassiveMonster :
typedef cMonster super;
public:
cPassiveMonster(void);
cPassiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
virtual void Tick(float a_Dt) override;

View File

@ -7,12 +7,9 @@
cPig::cPig(void)
cPig::cPig(void) :
super("Pig", 90, "mob.pig.say", "mob.pig.death")
{
m_MobType = 90;
m_SoundHurt = "mob.pig.say";
m_SoundDeath = "mob.pig.death";
GetMonsterConfig("Pig");
}

View File

@ -9,13 +9,10 @@
cSheep::cSheep(void) :
super("Sheep", 91, "mob.sheep.say", "mob.sheep.say"),
m_IsSheared(false),
m_WoolColor(E_META_WOOL_WHITE)
{
m_MobType = 91;
m_SoundHurt = "mob.sheep.say";
m_SoundDeath = "mob.sheep.say";
GetMonsterConfig("Sheep");
}

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Silverfish.h"
cSilverfish::cSilverfish(void)
{
m_MobType = 60;
m_SoundHurt = "mob.silverfish.hit";
m_SoundDeath = "mob.silverfish.kill";
GetMonsterConfig("Silverfish");
}

View File

@ -13,7 +13,10 @@ class cSilverfish :
typedef cAggressiveMonster super;
public:
cSilverfish(void);
cSilverfish(void) :
super("Silverfish", 60, "mob.silverfish.hit", "mob.silverfish.kill")
{
}
CLASS_PROTODEF(cSilverfish);
} ;

View File

@ -7,12 +7,9 @@
cSkeleton::cSkeleton(void)
cSkeleton::cSkeleton(void) :
super("Skeleton", 51, "mob.skeleton.hurt", "mob.skeleton.death")
{
m_MobType = 51;
m_SoundHurt = "mob.skeleton.hurt";
m_SoundDeath = "mob.skeleton.death";
GetMonsterConfig("Skeleton");
}

View File

@ -9,12 +9,9 @@
cSlime::cSlime(void)
cSlime::cSlime(void) :
super("Slime", 55, "mob.slime.attack", "mob.slime.attack")
{
m_MobType = 55;
m_SoundHurt = "mob.slime.attack";
m_SoundDeath = "mob.slime.attack";
GetMonsterConfig("Slime");
}

View File

@ -7,12 +7,9 @@
cSpider::cSpider()
cSpider::cSpider(void) :
super("Spider", 52, "mob.spider.say", "mob.spider.death")
{
m_MobType = 52;
m_SoundHurt = "mob.spider.say";
m_SoundDeath = "mob.spider.death";
GetMonsterConfig("Spider");
}

View File

@ -8,10 +8,9 @@
cSquid::cSquid()
cSquid::cSquid(void) :
super("Squid", 94, "", "")
{
m_MobType = 94;
GetMonsterConfig("Squid");
}

View File

@ -7,10 +7,9 @@
cVillager::cVillager()
cVillager::cVillager(void) :
super("Villager", 120, "", "")
{
m_MobType = 120;
GetMonsterConfig("Villager");
}

View File

@ -7,10 +7,9 @@
cWitch::cWitch()
cWitch::cWitch(void) :
super("Witch", 66, "", "")
{
m_MobType = 66;
GetMonsterConfig("Witch");
}

View File

@ -1,20 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Wolf.h"
cWolf::cWolf(void)
{
m_MobType = 95;
m_SoundHurt = "mob.wolf.hurt";
m_SoundDeath = "mob.wolf.death";
GetMonsterConfig("Wolf");
}

View File

@ -13,7 +13,10 @@ class cWolf :
typedef cPassiveAggressiveMonster super;
public:
cWolf(void);
cWolf(void) :
super("Wolf", 95, "mob.wolf.hurt", "mob.wolf.death")
{
}
CLASS_PROTODEF(cWolf);
} ;

View File

@ -7,12 +7,9 @@
cZombie::cZombie()
cZombie::cZombie(void) :
super("Zombie", 54, "mob.zombie.hurt", "mob.zombie.death")
{
m_MobType = 54;
m_SoundHurt = "mob.zombie.hurt";
m_SoundDeath = "mob.zombie.death";
GetMonsterConfig("Zombie");
}

View File

@ -7,12 +7,9 @@
cZombiepigman::cZombiepigman()
cZombiepigman::cZombiepigman(void) :
super("Zombiepigman", 57, "mob.zombiepig.zpighurt", "mob.zombiepig.zpigdeath")
{
m_MobType = 57;
m_SoundHurt = "mob.zombiepig.zpighurt";
m_SoundDeath = "mob.zombiepig.zpigdeath";
GetMonsterConfig("Zombiepigman");
}

View File

@ -44,7 +44,8 @@ cMonsterConfig::cMonsterConfig(void)
cMonsterConfig::~cMonsterConfig() {
cMonsterConfig::~cMonsterConfig()
{
delete m_pState;
}
@ -52,8 +53,8 @@ cMonsterConfig::~cMonsterConfig() {
void cMonsterConfig::Initialize() {
void cMonsterConfig::Initialize()
{
sAttributesStruct Attributes;
cIniFile SettingsIniFile("settings.ini");
cIniFile MonstersIniFile("monsters.ini");
@ -64,7 +65,7 @@ void cMonsterConfig::Initialize() {
return;
}
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types","");
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters", "Types", "");
if ( m_pState->MonsterTypes.empty() )
{
@ -72,17 +73,17 @@ void cMonsterConfig::Initialize() {
return;
}
AStringVector SplitList = StringSplit(m_pState->MonsterTypes,",");
AStringVector SplitList = StringSplit(m_pState->MonsterTypes, ",");
for (unsigned int i = 0; i < SplitList.size(); ++i)
{
if (!SplitList[i].empty())
{
Attributes.m_name = SplitList[i].c_str();
Attributes.m_AttackDamage = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackDamage", 0);
Attributes.m_AttackRange = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackRange", 0);
Attributes.m_SightDistance = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "SightDistance", 0);
Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackRate", 0);
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i].c_str(), "MaxHealth", 0);
Attributes.m_name = SplitList[i];
Attributes.m_AttackDamage = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackDamage", 0);
Attributes.m_AttackRange = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackRange", 0);
Attributes.m_SightDistance = (float)MonstersIniFile.GetValueF(SplitList[i], "SightDistance", 0);
Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackRate", 0);
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i], "MaxHealth", 0);
m_pState->AttributesList.push_front(Attributes);
}
} // for i - SplitList[]
@ -92,18 +93,19 @@ void cMonsterConfig::Initialize() {
void cMonsterConfig::AssignAttributes(cMonster *m, const char* n)
void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Name)
{
std::list<sAttributesStruct>::const_iterator itr;
for (itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr)
{
if(itr->m_name.compare(n) == 0)
if (itr->m_name.compare(a_Name) == 0)
{
m->SetAttackDamage (itr->m_AttackDamage);
m->SetAttackRange (itr->m_AttackRange);
m->SetSightDistance(itr->m_SightDistance);
m->SetAttackRate ((int)itr->m_AttackRate);
m->SetMaxHealth ((short)itr->m_MaxHealth);
a_Monster->SetAttackDamage (itr->m_AttackDamage);
a_Monster->SetAttackRange (itr->m_AttackRange);
a_Monster->SetSightDistance(itr->m_SightDistance);
a_Monster->SetAttackRate ((int)itr->m_AttackRate);
a_Monster->SetMaxHealth ((short)itr->m_MaxHealth);
return;
}
} // for itr - m_pState->AttributesList[]
}

View File

@ -1,17 +1,32 @@
#pragma once
// fwd:
class cMonster;
class cMonsterConfig
{
public:
cMonsterConfig(void);
~cMonsterConfig();
void AssignAttributes(cMonster *m, const char* n);
void AssignAttributes(cMonster * a_Monster, const AString & a_Name);
private:
struct sAttributesStruct;
struct sMonsterConfigState;
sMonsterConfigState* m_pState;
void Initialize();
};
} ;