fix for the ambiguous abs() call, slowly reworking creatures

develop
Petr Mrázek 2009-11-13 13:35:44 +00:00
parent 35b15aeacf
commit 7489fe51ab
5 changed files with 91 additions and 61 deletions

@ -766,7 +766,7 @@ uint32_t API::InitReadCreatures()
return false; return false;
} }
} }
/*
//This code was mostly adapted fromh dwarftherapist by chmod //This code was mostly adapted fromh dwarftherapist by chmod
string API::Private::getLastNameByAddress(const uint32_t &address, bool use_generic) string API::Private::getLastNameByAddress(const uint32_t &address, bool use_generic)
{ {
@ -920,13 +920,12 @@ void API::Private::getSkillsByAddress(const uint32_t &address, vector<t_skill> &
tempSkill.name = offset_descriptor->getSkill(tempSkill.id); tempSkill.name = offset_descriptor->getSkill(tempSkill.id);
tempSkill.experience = MreadWord(temp+8); tempSkill.experience = MreadWord(temp+8);
tempSkill.rating = MreadByte(temp+4); tempSkill.rating = MreadByte(temp+4);
/* // add up all the experience per level
add up all the experience per level // for (int j = 0; j < tempSkill.rating; ++j)
for (int j = 0; j < tempSkill.rating; ++j) // {
{ // tempSkill.experience += 500 + (j * 100);
tempSkill.experience += 500 + (j * 100); // }
} //
*/
skills.push_back(tempSkill); skills.push_back(tempSkill);
} }
} }
@ -954,7 +953,7 @@ void API::Private::getLaborsByAddress(const uint32_t &address, vector<t_labor> &
tempLabor.value = laborArray[i]; tempLabor.value = laborArray[i];
labors.push_back(tempLabor); labors.push_back(tempLabor);
} }
} }*/
bool API::ReadCreature(const uint32_t &index, t_creature & furball) bool API::ReadCreature(const uint32_t &index, t_creature & furball)
{ {
assert(d->creaturesInited); assert(d->creaturesInited);
@ -966,19 +965,24 @@ bool API::ReadCreature(const uint32_t &index, t_creature & furball)
MreadDWord(temp + d->creature_type_offset, furball.type); MreadDWord(temp + d->creature_type_offset, furball.type);
MreadDWord(temp + d->creature_flags1_offset, furball.flags1.whole); MreadDWord(temp + d->creature_flags1_offset, furball.flags1.whole);
MreadDWord(temp + d->creature_flags2_offset, furball.flags2.whole); MreadDWord(temp + d->creature_flags2_offset, furball.flags2.whole);
// names // normal names
furball.first_name = d->dm->readSTLString(temp+d->creature_first_name_offset); fill_char_buf(furball.first_name, d->dm->readSTLString(temp+d->creature_first_name_offset));
furball.nick_name = d->dm->readSTLString(temp+d->creature_nick_name_offset); fill_char_buf(furball.nick_name, d->dm->readSTLString(temp+d->creature_nick_name_offset));
furball.trans_name = d->getLastNameByAddress(temp+d->creature_last_name_offset); // crazy composited names
furball.generic_name = d->getLastNameByAddress(temp+d->creature_last_name_offset,true); Mread(temp + d->creature_last_name_offset,sizeof(t_lastname), (uint8_t *) &furball.last_name );
furball.generic_squad_name = d->getSquadNameByAddress(temp+d->creature_squad_name_offset, true); Mread(temp + d->creature_squad_name_offset,sizeof(t_squadname), (uint8_t *) &furball.squad_name );
furball.trans_squad_name = d->getSquadNameByAddress(temp+d->creature_squad_name_offset, false); // custom profession
furball.custom_profession = d->dm->readSTLString(temp+d->creature_custom_profession_offset); fill_char_buf(furball.custom_profession, d->dm->readSTLString(temp+d->creature_first_name_offset));
/*
furball.profession = d->getProfessionByAddress(temp+d->creature_profession_offset); furball.profession = d->getProfessionByAddress(temp+d->creature_profession_offset);
furball.current_job = d->getCurrentJobByAddress(temp+d->creature_current_job_offset); furball.current_job = d->getCurrentJobByAddress(temp+d->creature_current_job_offset);
d->getSkillsByAddress(temp+d->creature_skills_offset,furball.skills); d->getSkillsByAddress(temp+d->creature_skills_offset,furball.skills);
d->getTraitsByAddress(temp+d->creature_traits_offset,furball.traits); d->getTraitsByAddress(temp+d->creature_traits_offset,furball.traits);
d->getLaborsByAddress(temp+d->creature_labors_offset,furball.labors); d->getLaborsByAddress(temp+d->creature_labors_offset,furball.labors);
*/
MreadDWord(temp + d->creature_happiness_offset, furball.happiness); MreadDWord(temp + d->creature_happiness_offset, furball.happiness);
MreadDWord(temp + d->creature_id_offset, furball.id); MreadDWord(temp + d->creature_id_offset, furball.id);
@ -986,7 +990,7 @@ bool API::ReadCreature(const uint32_t &index, t_creature & furball)
MreadDWord(temp + d->creature_strength_offset, furball.strength); MreadDWord(temp + d->creature_strength_offset, furball.strength);
MreadDWord(temp + d->creature_toughness_offset, furball.toughness); MreadDWord(temp + d->creature_toughness_offset, furball.toughness);
MreadDWord(temp + d->creature_money_offset, furball.money); MreadDWord(temp + d->creature_money_offset, furball.money);
furball.squad_leader_id = int32_t(MreadDWord(temp + d->creature_squad_leader_id_offset)); furball.squad_leader_id = (int32_t) MreadDWord(temp + d->creature_squad_leader_id_offset);
MreadByte(temp + d->creature_sex_offset, furball.sex); MreadByte(temp + d->creature_sex_offset, furball.sex);
return true; return true;
} }

@ -180,7 +180,7 @@ public:
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z); bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z);
/*
// FIXME: add a real creature class, move these // FIXME: add a real creature class, move these
string getLastName(const uint32_t &index, bool); string getLastName(const uint32_t &index, bool);
string getSquadName(const uint32_t &index, bool); string getSquadName(const uint32_t &index, bool);
@ -189,7 +189,7 @@ public:
vector<t_skill> getSkills(const uint32_t &index); vector<t_skill> getSkills(const uint32_t &index);
vector<t_trait> getTraits(const uint32_t &index); vector<t_trait> getTraits(const uint32_t &index);
vector<t_labor> getLabors(const uint32_t &index); vector<t_labor> getLabors(const uint32_t &index);
*/
void InitReadNameTables(); void InitReadNameTables();
void FinishReadNameTables(); void FinishReadNameTables();
}; };

@ -442,40 +442,52 @@ string memory_info::getSkill (uint32_t key)
return string("Skill is not Defined"); return string("Skill is not Defined");
} }
string memory_info::getTrait (uint32_t key, uint32_t absVal) // FIXME: ugly hack that needs to die
{ int absolute (int number)
if(traits.size() > key){ {
int diff = abs(absVal-50); if (number < 0)
if(diff < 10){ return -number;
return string(""); return number;
} }
if (absVal >= 91)
return traits[key][5]; string memory_info::getTrait (uint32_t traitIdx, uint32_t traitValue)
else if (absVal >= 76) {
return traits[key][4]; if(traits.size() > traitIdx)
else if (absVal >= 61) {
return traits[key][3]; int diff = absolute(traitValue-50);
else if (absVal >= 25) if(diff < 10)
return traits[key][2]; {
else if (absVal >= 10) return string("");
return traits[key][1]; }
else if (traitValue >= 91)
return traits[key][0]; return traits[traitIdx][5];
} else if (traitValue >= 76)
return string("Trait is not Defined"); return traits[traitIdx][4];
else if (traitValue >= 61)
return traits[traitIdx][3];
else if (traitValue >= 25)
return traits[traitIdx][2];
else if (traitValue >= 10)
return traits[traitIdx][1];
else
return traits[traitIdx][0];
}
return string("Trait is not Defined");
} }
string memory_info::getTraitName(uint32_t key) string memory_info::getTraitName(uint32_t key)
{ {
if(traits.size() > key){ if(traits.size() > key)
return traits[key][traits[key].size()-1]; {
} return traits[key][traits[key].size()-1];
return string("Trait is not Defined"); }
return string("Trait is not Defined");
} }
string memory_info::getLabor (uint32_t key) string memory_info::getLabor (uint32_t key)
{ {
if(labors.count(key)){ if(labors.count(key))
{
return labors[key]; return labors[key];
} }
return string(""); return string("");

@ -396,7 +396,6 @@ struct t_labor
value=b.value; value=b.value;
return *this; return *this;
} }
}; };
struct t_skill struct t_skill
{ {
@ -448,6 +447,16 @@ struct t_trait
} }
}; };
struct t_lastname
{
int names[7];
};
struct t_squadname
{
int names[6];
};
struct t_creature struct t_creature
{ {
uint16_t x; uint16_t x;
@ -456,16 +465,15 @@ struct t_creature
uint32_t type; uint32_t type;
t_creaturflags1 flags1; t_creaturflags1 flags1;
t_creaturflags2 flags2; t_creaturflags2 flags2;
string first_name; char first_name [128];
string nick_name; char nick_name [128];
t_lastname last_name;
t_squadname squad_name;
char custom_profession[128];
/*
//string last_name; //string last_name;
string trans_name;
string generic_name;
string generic_squad_name;
string trans_squad_name;
string profession;
string custom_profession;
string current_job; string current_job;
*/
uint32_t happiness; uint32_t happiness;
uint32_t id; uint32_t id;
uint32_t agility; uint32_t agility;
@ -474,6 +482,8 @@ struct t_creature
uint32_t money; uint32_t money;
int32_t squad_leader_id; int32_t squad_leader_id;
uint8_t sex; uint8_t sex;
uint8_t profession;
/*
vector <t_skill> skills; vector <t_skill> skills;
vector <t_trait> traits; vector <t_trait> traits;
vector <t_labor> labors; vector <t_labor> labors;
@ -542,7 +552,7 @@ struct t_creature
skills = b.skills; skills = b.skills;
traits = b.traits; traits = b.traits;
return *this; return *this;
} }*/
}; };
// TODO: research this further? consult DF hacker wizards? // TODO: research this further? consult DF hacker wizards?

@ -46,16 +46,17 @@ int main (void)
DF.ReadCreature(i, temp); DF.ReadCreature(i, temp);
cout << "creature type " << creaturestypes[temp.type].id << ", position:" << temp.x << " " << temp.y << " "<< temp.z << endl; cout << "creature type " << creaturestypes[temp.type].id << ", position:" << temp.x << " " << temp.y << " "<< temp.z << endl;
bool addendl = false; bool addendl = false;
if(!temp.first_name.empty()) if(temp.first_name[0])
{ {
cout << "first name: " << temp.first_name; cout << "first name: " << temp.first_name;
addendl = true; addendl = true;
} }
if(!temp.nick_name.empty()) if(temp.nick_name[0])
{ {
cout << ", nick name: " << temp.nick_name; cout << ", nick name: " << temp.nick_name;
addendl = true; addendl = true;
} }
/*
if(!temp.trans_name.empty()){ if(!temp.trans_name.empty()){
cout << ", trans name: " << temp.trans_name; cout << ", trans name: " << temp.trans_name;
addendl =true; addendl =true;
@ -64,11 +65,13 @@ int main (void)
cout << ", generic name: " << temp.generic_name; cout << ", generic name: " << temp.generic_name;
addendl=true; addendl=true;
} }
*/
if(addendl) if(addendl)
{ {
cout << endl; cout << endl;
addendl = false; addendl = false;
} }
/*
if(!temp.profession.empty()){ if(!temp.profession.empty()){
cout << ", profession: " << temp.profession; cout << ", profession: " << temp.profession;
addendl = false; addendl = false;
@ -81,6 +84,7 @@ int main (void)
cout << ", current job: " << temp.current_job; cout << ", current job: " << temp.current_job;
addendl = false; addendl = false;
} }
*/
if(addendl) if(addendl)
{ {
cout << endl; cout << endl;
@ -99,7 +103,7 @@ int main (void)
cout <<", Male"; cout <<", Male";
} }
cout << endl; cout << endl;
/*
//skills //skills
for(unsigned int i = 0; i < temp.skills.size();i++){ for(unsigned int i = 0; i < temp.skills.size();i++){
if(i > 0){ if(i > 0){
@ -107,7 +111,7 @@ int main (void)
} }
cout << temp.skills[i].name << ": " << temp.skills[i].rating; cout << temp.skills[i].name << ": " << temp.skills[i].rating;
} }
*/
/* /*
* FLAGS 1 * FLAGS 1
*/ */