1
0

cMonsterConfig: removed excessive logging

git-svn-id: http://mc-server.googlecode.com/svn/trunk@246 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-02-08 17:14:12 +00:00
parent 32880153ab
commit 6651343261

View File

@ -4,14 +4,7 @@
#include "cMonsterConfig.h" #include "cMonsterConfig.h"
#include "cMonster.h" #include "cMonster.h"
#include "../iniFile/iniFile.h" #include "../iniFile/iniFile.h"
#include <cstdio> //#include <cstdio>
//#include "../source/cprintf.h"
using namespace std;
@ -19,21 +12,29 @@ using namespace std;
struct cMonsterConfig::sAttributesStruct struct cMonsterConfig::sAttributesStruct
{ {
string m_name; AString m_name;
float m_SightDistance; float m_SightDistance;
float m_AttackDamage; float m_AttackDamage;
float m_AttackRange; float m_AttackRange;
float m_AttackRate; float m_AttackRate;
int m_MaxHealth; int m_MaxHealth;
}; };
struct cMonsterConfig::sMonsterConfigState struct cMonsterConfig::sMonsterConfigState
{ {
int TypeCount; int TypeCount;
string MonsterTypes; AString MonsterTypes;
list< sAttributesStruct > AttributesList; std::list< sAttributesStruct > AttributesList;
}; };
cMonsterConfig::cMonsterConfig(int TypeC) cMonsterConfig::cMonsterConfig(int TypeC)
: m_pState( new sMonsterConfigState ) : m_pState( new sMonsterConfigState )
{ {
@ -41,64 +42,82 @@ cMonsterConfig::cMonsterConfig(int TypeC)
Initialize(); Initialize();
} }
cMonsterConfig::~cMonsterConfig() { cMonsterConfig::~cMonsterConfig() {
delete m_pState; delete m_pState;
} }
void cMonsterConfig::Initialize() { void cMonsterConfig::Initialize() {
sAttributesStruct Attributes; sAttributesStruct Attributes;
cIniFile SettingsIniFile("settings.ini"); cIniFile SettingsIniFile("settings.ini");
cIniFile MonstersIniFile("monsters.ini"); cIniFile MonstersIniFile("monsters.ini");
if(!SettingsIniFile.ReadFile() || !MonstersIniFile.ReadFile()) { if (!SettingsIniFile.ReadFile() || !MonstersIniFile.ReadFile())
printf("Error: Must have both settings.ini and monsters.ini to configure attributes\n\tusing default attributes \n"); {
LOGWARNING("cMonsterConfig: Must have both settings.ini and monsters.ini to configure attributes\n\tusing default attributes \n");
return; return;
} }
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types",""); m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types","");
if( m_pState->MonsterTypes.empty() ) { if ( m_pState->MonsterTypes.empty() )
printf("Error: No Monster types listed in config file, using default attributes \n"); {
LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n");
return; return;
} }
AStringVector SplitList = StringSplit(m_pState->MonsterTypes,","); AStringVector SplitList = StringSplit(m_pState->MonsterTypes,",");
for(unsigned int i = 0; i < SplitList.size(); ++i) { for (unsigned int i = 0; i < SplitList.size(); ++i)
if(!SplitList[i].empty()) { {
printf("Getting Attributes for: %s \n",SplitList[i].c_str()); if (!SplitList[i].empty())
{
Attributes.m_name = SplitList[i].c_str(); Attributes.m_name = SplitList[i].c_str();
Attributes.m_AttackDamage = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(),"AttackDamage",0); Attributes.m_AttackDamage = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackDamage", 0);
printf("Got AttackDamage: %3.3f \n",Attributes.m_AttackDamage); Attributes.m_AttackRange = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackRange", 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);
printf("Got AttackRange: %3.3f \n",Attributes.m_AttackRange); Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(), "AttackRate", 0);
Attributes.m_SightDistance = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(),"SightDistance",0); Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i].c_str(), "MaxHealth", 0);
printf("Got SightDistance: %3.3f \n",Attributes.m_SightDistance);
Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(),"AttackRate",0);
printf("Got AttackRate: %3.3f \n",Attributes.m_AttackRate);
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i].c_str(),"MaxHealth",0);
printf("Got MaxHealth: %d \n",Attributes.m_MaxHealth);
m_pState->AttributesList.push_front(Attributes); m_pState->AttributesList.push_front(Attributes);
} }
} } // for i - SplitList[]
} }
void cMonsterConfig::AssignAttributes(cMonster *m, const char* n) void cMonsterConfig::AssignAttributes(cMonster *m, const char* n)
{ {
list<sAttributesStruct>::iterator itr; std::list<sAttributesStruct>::const_iterator itr;
for(itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr) { for (itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr)
if(itr->m_name.compare(n) == 0) { {
//printf("found my attribs: %s :\n",itr->m_name.c_str()); if(itr->m_name.compare(n) == 0)
m->SetAttackDamage(itr->m_AttackDamage); {
m->SetAttackRange(itr->m_AttackRange); m->SetAttackDamage (itr->m_AttackDamage);
m->SetAttackRange (itr->m_AttackRange);
m->SetSightDistance(itr->m_SightDistance); m->SetSightDistance(itr->m_SightDistance);
m->SetAttackRate((int)itr->m_AttackRate); m->SetAttackRate ((int)itr->m_AttackRate);
m->SetMaxHealth((int)itr->m_MaxHealth); m->SetMaxHealth ((int)itr->m_MaxHealth);
} }
} } // for itr - m_pState->AttributesList[]
} }
cMonsterConfig *cMonsterConfig::Get() { cMonsterConfig *cMonsterConfig::Get() {
return this; return this;
} }