diff --git a/library/DFMemInfo.cpp b/library/DFMemInfo.cpp index 76934b5a8..ff748b738 100644 --- a/library/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -27,6 +27,8 @@ distribution. #include "dfhack/DFError.h" #include "dfhack/DFProcess.h" +//Inital amount of space in levels vector (since we usually know the number, efficent!) +#define NUM_RESERVE_LVLS 20 using namespace DFHack; /* @@ -92,6 +94,7 @@ class memory_info::Private vector professions; vector jobs; vector skills; + vector levels; vector< vector > traits; map labors; @@ -120,6 +123,7 @@ memory_info::memory_info() d->base = 0; d->p = 0; d->classindex = 0; + d->levels.reserve(NUM_RESERVE_LVLS); } // copy constructor @@ -146,6 +150,7 @@ memory_info::memory_info(const memory_info &old) d->skills = old.d->skills; d->traits = old.d->traits; d->labors = old.d->labors; + d->levels = old.d->levels; } void memory_info::setParentProcess(Process * _p) { @@ -300,6 +305,22 @@ void memory_info::setSkill (const string & key, const string & value) d->skills[keyInt] = value; } +void memory_info::setLevel(const std::string &nLevel, + const std::string &nName, + const std::string &nMin_xp, + const std::string &nMax_xp) +{ + uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10); + + if(d->skills.size() <= keyInt) + d->skills.resize(keyInt+1); + + d->levels[keyInt].level = keyInt; + d->levels[keyInt].name = nName; + d->levels[keyInt].min_xp = strtol(nMin_xp.c_str(), NULL, 10); + d->levels[keyInt].max_xp = strtol(nMax_xp.c_str(), NULL, 10); +} + void memory_info::setTrait(const string & key, const string & value, const string & zero, @@ -628,6 +649,15 @@ string memory_info::getSkill (const uint32_t key) const throw Error::MissingMemoryDefinition("skill", key); } +DFHack::t_level memory_info::getLevelInfo(const uint32_t level) const +{ + if(d->levels.size() > level) + { + return d->levels[level]; + } + throw Error::MissingMemoryDefinition("Level", level); +} + // FIXME: ugly hack that needs to die int absolute (int number) { diff --git a/library/DFMemInfoManager.cpp b/library/DFMemInfoManager.cpp index a2c0140ce..021e909b7 100644 --- a/library/DFMemInfoManager.cpp +++ b/library/DFMemInfoManager.cpp @@ -152,8 +152,12 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map Value(); - const char *cstr_name = pMemEntry->Attribute("name"); + const char *cstr_name = pMemEntry->Attribute("name"); const char *cstr_value = pMemEntry->GetText(); + + if(!cstr_value) + cstr_value = pMemEntry->Attribute("id"); + // check for missing parts string type, name, value; type = cstr_type; @@ -203,6 +207,10 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map setLabor(value,name); + } + else if (type == "Level") + { + mem->setLevel(value, name, pMemEntry->Attribute("min_xp"), pMemEntry->Attribute("max_xp")); } else { diff --git a/library/include/dfhack/DFMemInfo.h b/library/include/dfhack/DFMemInfo.h index 941faf6f2..a5aa5284c 100644 --- a/library/include/dfhack/DFMemInfo.h +++ b/library/include/dfhack/DFMemInfo.h @@ -27,6 +27,8 @@ distribution. #include "DFPragma.h" #include "DFExport.h" +#include "dfhack/DFTypes.h" + namespace DFHack { /* @@ -72,6 +74,8 @@ namespace DFHack std::string getTraitName(const uint32_t) const; std::string getLabor (const uint32_t); + DFHack::t_level getLevelInfo(const uint32_t level) const; + void setVersion(const char *); void setVersion(const std::string&); std::string getVersion(); @@ -98,8 +102,12 @@ namespace DFHack void setProfession(const std::string &, const std::string &); void setJob(const std::string &, const std::string &); void setSkill(const std::string &, const std::string &); - void setTrait(const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &,const std::string &); + void setTrait(const std::string &, const std::string &, const std::string &, + const std::string &, const std::string &, + const std::string &, const std::string &, const std::string &); void setLabor(const std::string &, const std::string &); + void setLevel(const std::string &nLevel, const std::string &nName, + const std::string &nMin_xp, const std::string &nMax_xp); void RebaseVTable(const int32_t offset); void setParentProcess(Process * _p); diff --git a/library/include/dfhack/DFTypes.h b/library/include/dfhack/DFTypes.h index 95ab11ccd..bcf15432b 100644 --- a/library/include/dfhack/DFTypes.h +++ b/library/include/dfhack/DFTypes.h @@ -211,5 +211,13 @@ struct t_attrib uint32_t field_18; }; +struct t_level +{ + uint32_t level; + std::string name; + uint32_t min_xp; + uint32_t max_xp; +}; + }// namespace DFHack #endif // TYPES_H_INCLUDED