2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "MonsterConfig.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "Mobs/Monster.h"
|
2013-11-26 12:14:46 -05:00
|
|
|
#include "inifile/iniFile.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct cMonsterConfig::sAttributesStruct
|
|
|
|
{
|
2013-07-07 11:09:05 -04:00
|
|
|
AString m_Name;
|
2014-01-24 14:57:32 -05:00
|
|
|
int m_SightDistance;
|
|
|
|
int m_AttackDamage;
|
|
|
|
int m_AttackRange;
|
2013-07-07 11:09:05 -04:00
|
|
|
double m_AttackRate;
|
2012-06-14 09:06:06 -04:00
|
|
|
int m_MaxHealth;
|
2014-04-22 19:17:42 -04:00
|
|
|
bool m_IsFireproof;
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct cMonsterConfig::sMonsterConfigState
|
|
|
|
{
|
|
|
|
AString MonsterTypes;
|
|
|
|
std::list< sAttributesStruct > AttributesList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cMonsterConfig::cMonsterConfig(void)
|
|
|
|
: m_pState( new sMonsterConfigState )
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
cMonsterConfig::~cMonsterConfig()
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
delete m_pState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
void cMonsterConfig::Initialize()
|
|
|
|
{
|
2013-10-25 05:15:44 -04:00
|
|
|
cIniFile MonstersIniFile;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-10-25 05:15:44 -04:00
|
|
|
if (!MonstersIniFile.ReadFile("monsters.ini"))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-07-07 11:09:05 -04:00
|
|
|
LOGWARNING("%s: Cannot read monsters.ini file, monster attributes not available", __FUNCTION__);
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-25 05:38:14 -04:00
|
|
|
for (int i = (int)MonstersIniFile.GetNumKeys(); i >= 0; i--)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-07-07 11:09:05 -04:00
|
|
|
sAttributesStruct Attributes;
|
2013-10-25 05:38:14 -04:00
|
|
|
AString Name = MonstersIniFile.GetKeyName(i);
|
2013-07-07 11:09:05 -04:00
|
|
|
Attributes.m_Name = Name;
|
2014-01-24 14:57:32 -05:00
|
|
|
Attributes.m_AttackDamage = MonstersIniFile.GetValueI(Name, "AttackDamage", 0);
|
|
|
|
Attributes.m_AttackRange = MonstersIniFile.GetValueI(Name, "AttackRange", 0);
|
|
|
|
Attributes.m_SightDistance = MonstersIniFile.GetValueI(Name, "SightDistance", 0);
|
2013-07-07 11:09:05 -04:00
|
|
|
Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0);
|
|
|
|
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1);
|
2014-04-22 19:17:42 -04:00
|
|
|
Attributes.m_IsFireproof = MonstersIniFile.GetValueB(Name, "IsFireproof", false);
|
2013-07-07 11:09:05 -04:00
|
|
|
m_pState->AttributesList.push_front(Attributes);
|
2012-06-14 09:06:06 -04:00
|
|
|
} // for i - SplitList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Name)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
std::list<sAttributesStruct>::const_iterator itr;
|
|
|
|
for (itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr)
|
|
|
|
{
|
2013-07-07 11:09:05 -04:00
|
|
|
if (itr->m_Name.compare(a_Name) == 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
a_Monster->SetAttackDamage (itr->m_AttackDamage);
|
|
|
|
a_Monster->SetAttackRange (itr->m_AttackRange);
|
|
|
|
a_Monster->SetSightDistance(itr->m_SightDistance);
|
|
|
|
a_Monster->SetAttackRate ((float)itr->m_AttackRate);
|
2013-07-07 11:09:05 -04:00
|
|
|
a_Monster->SetMaxHealth (itr->m_MaxHealth);
|
2014-04-23 03:12:37 -04:00
|
|
|
a_Monster->SetIsFireproof (itr->m_IsFireproof);
|
2012-12-22 04:39:13 -05:00
|
|
|
return;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
} // for itr - m_pState->AttributesList[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|