2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 15:09:57 -07:00
|
|
|
#include "MonsterConfig.h"
|
2012-09-23 13:53:08 -07:00
|
|
|
#include "Mobs/Monster.h"
|
2012-06-14 06:06:06 -07:00
|
|
|
#include "../iniFile/iniFile.h"
|
|
|
|
//#include <cstdio>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct cMonsterConfig::sAttributesStruct
|
|
|
|
{
|
|
|
|
AString m_name;
|
|
|
|
float m_SightDistance;
|
|
|
|
float m_AttackDamage;
|
|
|
|
float m_AttackRange;
|
|
|
|
float m_AttackRate;
|
|
|
|
int m_MaxHealth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct cMonsterConfig::sMonsterConfigState
|
|
|
|
{
|
|
|
|
AString MonsterTypes;
|
|
|
|
std::list< sAttributesStruct > AttributesList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cMonsterConfig::cMonsterConfig(void)
|
|
|
|
: m_pState( new sMonsterConfigState )
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 01:39:13 -08:00
|
|
|
cMonsterConfig::~cMonsterConfig()
|
|
|
|
{
|
2012-06-14 06:06:06 -07:00
|
|
|
delete m_pState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 01:39:13 -08:00
|
|
|
void cMonsterConfig::Initialize()
|
|
|
|
{
|
2012-06-14 06:06:06 -07:00
|
|
|
sAttributesStruct Attributes;
|
|
|
|
cIniFile SettingsIniFile("settings.ini");
|
|
|
|
cIniFile MonstersIniFile("monsters.ini");
|
|
|
|
|
|
|
|
if (!SettingsIniFile.ReadFile() || !MonstersIniFile.ReadFile())
|
|
|
|
{
|
|
|
|
LOGWARNING("cMonsterConfig: Must have both settings.ini and monsters.ini to configure attributes\n\tusing default attributes \n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-22 01:39:13 -08:00
|
|
|
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters", "Types", "");
|
2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
if ( m_pState->MonsterTypes.empty() )
|
|
|
|
{
|
|
|
|
LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-22 01:39:13 -08:00
|
|
|
AStringVector SplitList = StringSplit(m_pState->MonsterTypes, ",");
|
2012-06-14 06:06:06 -07:00
|
|
|
for (unsigned int i = 0; i < SplitList.size(); ++i)
|
|
|
|
{
|
|
|
|
if (!SplitList[i].empty())
|
|
|
|
{
|
2012-12-22 01:39:13 -08:00
|
|
|
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);
|
2012-06-14 06:06:06 -07:00
|
|
|
m_pState->AttributesList.push_front(Attributes);
|
|
|
|
}
|
|
|
|
} // for i - SplitList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 01:39:13 -08:00
|
|
|
void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Name)
|
2012-06-14 06:06:06 -07:00
|
|
|
{
|
|
|
|
std::list<sAttributesStruct>::const_iterator itr;
|
|
|
|
for (itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr)
|
|
|
|
{
|
2012-12-22 01:39:13 -08:00
|
|
|
if (itr->m_name.compare(a_Name) == 0)
|
2012-06-14 06:06:06 -07:00
|
|
|
{
|
2012-12-22 01:39:13 -08:00
|
|
|
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;
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
|
|
|
} // for itr - m_pState->AttributesList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|