Added levels done (unless issues)

develop
Simon Jackson 2010-06-10 23:53:25 +08:00 committed by Petr Mrázek
parent ec7b6edeb3
commit a89fd106e2
4 changed files with 56 additions and 2 deletions

@ -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<string> professions;
vector<string> jobs;
vector<string> skills;
vector<DFHack::t_level> levels;
vector< vector<string> > traits;
map <uint32_t, string> 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)
{

@ -152,8 +152,12 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{
// only elements get processed
const char *cstr_type = pMemEntry->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 <str
else if (type == "Labor")
{
mem->setLabor(value,name);
}
else if (type == "Level")
{
mem->setLevel(value, name, pMemEntry->Attribute("min_xp"), pMemEntry->Attribute("max_xp"));
}
else
{

@ -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);

@ -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