diff options
author | cedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-14 15:06:06 +0200 |
---|---|---|
committer | cedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-14 15:06:06 +0200 |
commit | 92c59963f82f81aa3202657e7fdbb2592924ede3 (patch) | |
tree | b7eb2474528a4998fa102e3ec9119b908cee08b4 /source/cMonsterConfig.cpp | |
parent | Added HOOK_WEATHER_CHANGE. (diff) | |
download | cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.gz cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.bz2 cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.lz cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.xz cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.zst cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.zip |
Diffstat (limited to 'source/cMonsterConfig.cpp')
-rw-r--r-- | source/cMonsterConfig.cpp | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/source/cMonsterConfig.cpp b/source/cMonsterConfig.cpp index 92f65aeec..f8bc9e16f 100644 --- a/source/cMonsterConfig.cpp +++ b/source/cMonsterConfig.cpp @@ -1,114 +1,114 @@ -
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "cMonsterConfig.h"
-#include "cMonster.h"
-#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();
-}
-
-
-
-
-
-cMonsterConfig::~cMonsterConfig() {
- delete m_pState;
-}
-
-
-
-
-
-void cMonsterConfig::Initialize() {
-
- 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;
- }
-
- m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types","");
-
- if ( m_pState->MonsterTypes.empty() )
- {
- LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n");
- return;
- }
-
- 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);
- m_pState->AttributesList.push_front(Attributes);
- }
- } // for i - SplitList[]
-}
-
-
-
-
-
-void cMonsterConfig::AssignAttributes(cMonster *m, const char* n)
-{
- 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);
- m->SetSightDistance(itr->m_SightDistance);
- m->SetAttackRate ((int)itr->m_AttackRate);
- m->SetMaxHealth ((short)itr->m_MaxHealth);
- }
- } // for itr - m_pState->AttributesList[]
-}
-
-
-
-
-
+ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cMonsterConfig.h" +#include "cMonster.h" +#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(); +} + + + + + +cMonsterConfig::~cMonsterConfig() { + delete m_pState; +} + + + + + +void cMonsterConfig::Initialize() { + + 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; + } + + m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters","Types",""); + + if ( m_pState->MonsterTypes.empty() ) + { + LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n"); + return; + } + + 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); + m_pState->AttributesList.push_front(Attributes); + } + } // for i - SplitList[] +} + + + + + +void cMonsterConfig::AssignAttributes(cMonster *m, const char* n) +{ + 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); + m->SetSightDistance(itr->m_SightDistance); + m->SetAttackRate ((int)itr->m_AttackRate); + m->SetMaxHealth ((short)itr->m_MaxHealth); + } + } // for itr - m_pState->AttributesList[] +} + + + + + |