2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2011-12-25 14:34:31 -05:00
|
|
|
#include "cMonsterConfig.h"
|
|
|
|
#include "cMonster.h"
|
|
|
|
#include "../iniFile/iniFile.h"
|
2012-02-08 12:14:12 -05:00
|
|
|
//#include <cstdio>
|
2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
struct cMonsterConfig::sAttributesStruct
|
|
|
|
{
|
|
|
|
AString m_name;
|
|
|
|
float m_SightDistance;
|
|
|
|
float m_AttackDamage;
|
|
|
|
float m_AttackRange;
|
|
|
|
float m_AttackRate;
|
|
|
|
int m_MaxHealth;
|
|
|
|
};
|
2011-12-25 14:34:31 -05:00
|
|
|
|
2012-02-01 04:12:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 14:34:31 -05:00
|
|
|
|
|
|
|
struct cMonsterConfig::sMonsterConfigState
|
|
|
|
{
|
2012-02-08 12:14:12 -05:00
|
|
|
AString MonsterTypes;
|
|
|
|
std::list< sAttributesStruct > AttributesList;
|
2011-12-25 14:34:31 -05:00
|
|
|
};
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-17 06:40:14 -05:00
|
|
|
cMonsterConfig::cMonsterConfig(void)
|
2011-12-25 14:34:31 -05:00
|
|
|
: m_pState( new sMonsterConfigState )
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 14:34:31 -05:00
|
|
|
cMonsterConfig::~cMonsterConfig() {
|
|
|
|
delete m_pState;
|
|
|
|
}
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 14:34:31 -05:00
|
|
|
void cMonsterConfig::Initialize() {
|
|
|
|
|
|
|
|
sAttributesStruct Attributes;
|
|
|
|
cIniFile SettingsIniFile("settings.ini");
|
|
|
|
cIniFile MonstersIniFile("monsters.ini");
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
if (!SettingsIniFile.ReadFile() || !MonstersIniFile.ReadFile())
|
|
|
|
{
|
|
|
|
LOGWARNING("cMonsterConfig: Must have both settings.ini and monsters.ini to configure attributes\n\tusing default attributes \n");
|
2011-12-25 14:34:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types","");
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
if ( m_pState->MonsterTypes.empty() )
|
|
|
|
{
|
|
|
|
LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n");
|
2011-12-25 14:34:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 04:12:54 -05:00
|
|
|
AStringVector SplitList = StringSplit(m_pState->MonsterTypes,",");
|
2012-02-08 12:14:12 -05:00
|
|
|
for (unsigned int i = 0; i < SplitList.size(); ++i)
|
|
|
|
{
|
|
|
|
if (!SplitList[i].empty())
|
|
|
|
{
|
2011-12-25 14:34:31 -05:00
|
|
|
Attributes.m_name = SplitList[i].c_str();
|
2012-02-08 12:14:12 -05:00
|
|
|
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);
|
2011-12-25 14:34:31 -05:00
|
|
|
m_pState->AttributesList.push_front(Attributes);
|
|
|
|
}
|
2012-02-08 12:14:12 -05:00
|
|
|
} // for i - SplitList[]
|
2011-12-25 14:34:31 -05:00
|
|
|
}
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 14:34:31 -05:00
|
|
|
void cMonsterConfig::AssignAttributes(cMonster *m, const char* n)
|
|
|
|
{
|
2012-02-08 12:14:12 -05:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
m->SetAttackDamage (itr->m_AttackDamage);
|
|
|
|
m->SetAttackRange (itr->m_AttackRange);
|
2011-12-25 14:34:31 -05:00
|
|
|
m->SetSightDistance(itr->m_SightDistance);
|
2012-02-08 12:14:12 -05:00
|
|
|
m->SetAttackRate ((int)itr->m_AttackRate);
|
2012-02-16 12:45:26 -05:00
|
|
|
m->SetMaxHealth ((short)itr->m_MaxHealth);
|
2011-12-25 14:34:31 -05:00
|
|
|
}
|
2012-02-08 12:14:12 -05:00
|
|
|
} // for itr - m_pState->AttributesList[]
|
2011-12-25 14:34:31 -05:00
|
|
|
}
|
|
|
|
|
2012-02-08 12:14:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|