|
|
@ -30,6 +30,7 @@ distribution.
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <map>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +53,7 @@ struct Creatures::Private
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool Inited;
|
|
|
|
bool Inited;
|
|
|
|
bool Started;
|
|
|
|
bool Started;
|
|
|
|
|
|
|
|
/*
|
|
|
|
bool Ft_basic;
|
|
|
|
bool Ft_basic;
|
|
|
|
bool Ft_advanced;
|
|
|
|
bool Ft_advanced;
|
|
|
|
bool Ft_jobs;
|
|
|
|
bool Ft_jobs;
|
|
|
@ -111,12 +113,13 @@ struct Creatures::Private
|
|
|
|
int32_t job_material_flags_o;
|
|
|
|
int32_t job_material_flags_o;
|
|
|
|
// creature job material stuff
|
|
|
|
// creature job material stuff
|
|
|
|
} creatures;
|
|
|
|
} creatures;
|
|
|
|
|
|
|
|
*/
|
|
|
|
uint32_t creature_module;
|
|
|
|
uint32_t creature_module;
|
|
|
|
uint32_t dwarf_race_index_addr;
|
|
|
|
uint32_t dwarf_race_index_addr;
|
|
|
|
uint32_t dwarf_civ_id_addr;
|
|
|
|
uint32_t dwarf_civ_id_addr;
|
|
|
|
bool IdMapReady;
|
|
|
|
bool IdMapReady;
|
|
|
|
std::map<int32_t, int32_t> IdMap;
|
|
|
|
std::map<int32_t, int32_t> IdMap;
|
|
|
|
DfVector <uint32_t> *p_cre;
|
|
|
|
//DfVector <uint32_t> *p_cre;
|
|
|
|
Process *owner;
|
|
|
|
Process *owner;
|
|
|
|
Translation * trans;
|
|
|
|
Translation * trans;
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -129,13 +132,13 @@ Module* DFHack::createCreatures()
|
|
|
|
Creatures::Creatures()
|
|
|
|
Creatures::Creatures()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Core & c = Core::getInstance();
|
|
|
|
Core & c = Core::getInstance();
|
|
|
|
|
|
|
|
creatures = 0;
|
|
|
|
d = new Private;
|
|
|
|
d = new Private;
|
|
|
|
d->owner = c.p;
|
|
|
|
d->owner = c.p;
|
|
|
|
VersionInfo * minfo = c.vinfo;
|
|
|
|
VersionInfo * minfo = c.vinfo;
|
|
|
|
d->Inited = false;
|
|
|
|
d->Inited = false;
|
|
|
|
d->Started = false;
|
|
|
|
d->Started = false;
|
|
|
|
d->IdMapReady = false;
|
|
|
|
d->IdMapReady = false;
|
|
|
|
d->p_cre = NULL;
|
|
|
|
|
|
|
|
d->trans = c.getTranslation();
|
|
|
|
d->trans = c.getTranslation();
|
|
|
|
d->trans->InitReadNames(); // throws on error
|
|
|
|
d->trans->InitReadNames(); // throws on error
|
|
|
|
|
|
|
|
|
|
|
@ -146,90 +149,12 @@ Creatures::Creatures()
|
|
|
|
OffsetGroup * OG_name = minfo->getGroup("name");
|
|
|
|
OffsetGroup * OG_name = minfo->getGroup("name");
|
|
|
|
OffsetGroup * OG_jobs = OG_Creatures->getGroup("job");
|
|
|
|
OffsetGroup * OG_jobs = OG_Creatures->getGroup("job");
|
|
|
|
OffsetGroup * OG_job_mats = OG_jobs->getGroup("material");
|
|
|
|
OffsetGroup * OG_job_mats = OG_jobs->getGroup("material");
|
|
|
|
d->Ft_basic = d->Ft_advanced = d->Ft_jobs = d->Ft_soul = d->Ft_inventory = d->Ft_owned_items = d->Ft_job_materials = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Private::t_offsets &creatures = d->creatures;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Creatures
|
|
|
|
creatures = (vector <df_creature *> *) OG_Creatures->getAddress ("vector");
|
|
|
|
creatures.vector = OG_Creatures->getAddress ("vector");
|
|
|
|
|
|
|
|
d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race");
|
|
|
|
d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race");
|
|
|
|
d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ");
|
|
|
|
d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ");
|
|
|
|
// Creatures/creature
|
|
|
|
|
|
|
|
creatures.name_offset = OG_creature->getOffset ("name");
|
|
|
|
|
|
|
|
creatures.custom_profession_offset = OG_creature->getOffset ("custom_profession");
|
|
|
|
|
|
|
|
creatures.profession_offset = OG_creature->getOffset ("profession");
|
|
|
|
|
|
|
|
creatures.race_offset = OG_creature->getOffset ("race");
|
|
|
|
|
|
|
|
creatures.pos_offset = OG_creature->getOffset ("position");
|
|
|
|
|
|
|
|
creatures.flags1_offset = OG_creature->getOffset ("flags1");
|
|
|
|
|
|
|
|
creatures.flags2_offset = OG_creature->getOffset ("flags2");
|
|
|
|
|
|
|
|
creatures.flags3_offset = OG_creature->getOffset ("flags3");
|
|
|
|
|
|
|
|
creatures.sex_offset = OG_creature->getOffset ("sex");
|
|
|
|
|
|
|
|
creatures.caste_offset = OG_creature->getOffset ("caste");
|
|
|
|
|
|
|
|
creatures.id_offset = OG_creature->getOffset ("id");
|
|
|
|
|
|
|
|
creatures.civ_offset = OG_creature->getOffset ("civ");
|
|
|
|
|
|
|
|
// name struct
|
|
|
|
|
|
|
|
creatures.name_firstname_offset = OG_name->getOffset("first");
|
|
|
|
|
|
|
|
creatures.name_nickname_offset = OG_name->getOffset("nick");
|
|
|
|
|
|
|
|
creatures.name_words_offset = OG_name->getOffset("second_words");
|
|
|
|
|
|
|
|
d->Ft_basic = true;
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.pickup_equipment_bit = OG_creature_ex->getOffset("pickup_equipment_bit");
|
|
|
|
|
|
|
|
creatures.mood_offset = OG_creature_ex->getOffset("mood");
|
|
|
|
|
|
|
|
creatures.pregnancy_offset = OG_creature_ex->getOffset("pregnancy");
|
|
|
|
|
|
|
|
creatures.pregnancy_ptr_offset = OG_creature_ex->getOffset("pregnancy_ptr");
|
|
|
|
|
|
|
|
creatures.birth_year_offset = OG_creature_ex->getOffset("birth_year");
|
|
|
|
|
|
|
|
creatures.birth_time_offset = OG_creature_ex->getOffset("birth_time");
|
|
|
|
|
|
|
|
creatures.current_job_offset = OG_creature_ex->getOffset("current_job");
|
|
|
|
|
|
|
|
creatures.mood_skill_offset = OG_creature_ex->getOffset("current_job_skill");
|
|
|
|
|
|
|
|
creatures.physical_offset = OG_creature_ex->getOffset("physical");
|
|
|
|
|
|
|
|
creatures.appearance_vector_offset = OG_creature_ex->getOffset("appearance_vector");
|
|
|
|
|
|
|
|
creatures.artifact_name_offset = OG_creature_ex->getOffset("artifact_name");
|
|
|
|
|
|
|
|
creatures.labors_offset = OG_creature_ex->getOffset ("labors");
|
|
|
|
|
|
|
|
creatures.happiness_offset = OG_creature_ex->getOffset ("happiness");
|
|
|
|
|
|
|
|
d->Ft_advanced = true;
|
|
|
|
|
|
|
|
}catch(Error::All&){};
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.inventory_offset = OG_creature_ex->getOffset("inventory_vector");
|
|
|
|
|
|
|
|
d->Ft_inventory = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All&){};
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.owned_items_offset = OG_creature_ex->getOffset("owned_items_vector");
|
|
|
|
|
|
|
|
d->Ft_owned_items = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All&){};
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector");
|
|
|
|
|
|
|
|
creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul");
|
|
|
|
|
|
|
|
creatures.soul_mental_offset = OG_soul->getOffset("mental");
|
|
|
|
|
|
|
|
creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector");
|
|
|
|
|
|
|
|
creatures.soul_traits_offset = OG_soul->getOffset("traits");
|
|
|
|
|
|
|
|
d->Ft_soul = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All&){};
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.job_type_offset = OG_jobs->getOffset("type");
|
|
|
|
|
|
|
|
creatures.job_id_offset = OG_jobs->getOffset("id");
|
|
|
|
|
|
|
|
d->Ft_jobs = true;
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
creatures.job_materials_vector = OG_jobs->getOffset("materials_vector");
|
|
|
|
|
|
|
|
creatures.job_material_itemtype_o = OG_job_mats->getOffset("maintype");
|
|
|
|
|
|
|
|
creatures.job_material_subtype_o = OG_job_mats->getOffset("sectype1");
|
|
|
|
|
|
|
|
creatures.job_material_subindex_o = OG_job_mats->getOffset("sectype2");
|
|
|
|
|
|
|
|
creatures.job_material_index_o = OG_job_mats->getOffset("sectype3");
|
|
|
|
|
|
|
|
creatures.job_material_flags_o = OG_job_mats->getOffset("flags");
|
|
|
|
|
|
|
|
d->Ft_job_materials = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All&){};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All&){};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Error::All&){};
|
|
|
|
catch(Error::All&){};
|
|
|
|
d->Inited = true;
|
|
|
|
d->Inited = true;
|
|
|
@ -243,11 +168,10 @@ Creatures::~Creatures()
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::Start( uint32_t &numcreatures )
|
|
|
|
bool Creatures::Start( uint32_t &numcreatures )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(d->Ft_basic)
|
|
|
|
if(creatures)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
d->p_cre = new DfVector <uint32_t> (d->creatures.vector);
|
|
|
|
|
|
|
|
d->Started = true;
|
|
|
|
d->Started = true;
|
|
|
|
numcreatures = d->p_cre->size();
|
|
|
|
numcreatures = creatures->size();
|
|
|
|
d->IdMapReady = false;
|
|
|
|
d->IdMapReady = false;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -256,81 +180,104 @@ bool Creatures::Start( uint32_t &numcreatures )
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::Finish()
|
|
|
|
bool Creatures::Finish()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(d->p_cre)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete d->p_cre;
|
|
|
|
|
|
|
|
d->p_cre = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
d->Started = false;
|
|
|
|
d->Started = false;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
|
|
|
|
df_creature * Creatures::GetCreature (const int32_t index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started) return false;
|
|
|
|
if(!d->Started) return nullptr;
|
|
|
|
memset(&furball, 0, sizeof(t_creature));
|
|
|
|
|
|
|
|
// SHM fast path
|
|
|
|
// read pointer from vector at position
|
|
|
|
|
|
|
|
if(index > creatures->size())
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return creatures->at(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns index of creature actually read or -1 if no creature can be found
|
|
|
|
|
|
|
|
int32_t Creatures::GetCreatureInBox (int32_t index, df_creature ** furball,
|
|
|
|
|
|
|
|
const uint16_t x1, const uint16_t y1, const uint16_t z1,
|
|
|
|
|
|
|
|
const uint16_t x2, const uint16_t y2, const uint16_t z2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!d->Started)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
Process *p = d->owner;
|
|
|
|
Process *p = d->owner;
|
|
|
|
|
|
|
|
uint16_t coords[3];
|
|
|
|
|
|
|
|
uint32_t size = creatures->size();
|
|
|
|
|
|
|
|
while (uint32_t(index) < size)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// read pointer from vector at position
|
|
|
|
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
|
|
|
|
if (temp->x >= x1 && temp->x < x2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (temp->y >= y1 && temp->y < y2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (temp->z >= z1 && temp->z < z2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
*furball = temp;
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*furball = nullptr;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Creatures::CopyCreature(df_creature * source, t_creature & furball)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!d->Started) return;
|
|
|
|
// read pointer from vector at position
|
|
|
|
// read pointer from vector at position
|
|
|
|
uint32_t addr_cr = d->p_cre->at (index);
|
|
|
|
furball.origin = source;
|
|
|
|
furball.origin = addr_cr;
|
|
|
|
|
|
|
|
Private::t_offsets &offs = d->creatures;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//read creature from memory
|
|
|
|
//read creature from memory
|
|
|
|
if(d->Ft_basic)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// name
|
|
|
|
// name
|
|
|
|
d->trans->readName(furball.name,addr_cr + offs.name_offset);
|
|
|
|
d->trans->readName(furball.name,&source->name);
|
|
|
|
|
|
|
|
|
|
|
|
// basic stuff
|
|
|
|
// basic stuff
|
|
|
|
p->readDWord (addr_cr + offs.id_offset, furball.id);
|
|
|
|
furball.id = source->id;
|
|
|
|
p->read (addr_cr + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
|
|
|
|
furball.x = source->x;
|
|
|
|
p->readDWord (addr_cr + offs.race_offset, furball.race);
|
|
|
|
furball.y = source->y;
|
|
|
|
furball.civ = p->readDWord (addr_cr + offs.civ_offset);
|
|
|
|
furball.z = source->z;
|
|
|
|
p->readByte (addr_cr + offs.sex_offset, furball.sex);
|
|
|
|
furball.race = source->race;
|
|
|
|
p->readWord (addr_cr + offs.caste_offset, furball.caste);
|
|
|
|
furball.civ = source->civ;
|
|
|
|
p->readDWord (addr_cr + offs.flags1_offset, furball.flags1.whole);
|
|
|
|
furball.sex = source->sex;
|
|
|
|
p->readDWord (addr_cr + offs.flags2_offset, furball.flags2.whole);
|
|
|
|
furball.caste = source->caste;
|
|
|
|
p->readDWord (addr_cr + offs.flags3_offset, furball.flags3.whole);
|
|
|
|
furball.flags1.whole = source->flags1.whole;
|
|
|
|
|
|
|
|
furball.flags2.whole = source->flags2.whole;
|
|
|
|
|
|
|
|
furball.flags3.whole = source->flags3.whole;
|
|
|
|
// custom profession
|
|
|
|
// custom profession
|
|
|
|
p->readSTLString(addr_cr + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession));
|
|
|
|
furball.custom_profession = source->custom_profession;
|
|
|
|
// profession
|
|
|
|
// profession
|
|
|
|
furball.profession = p->readByte (addr_cr + offs.profession_offset);
|
|
|
|
furball.profession = source->profession;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d->Ft_advanced)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// happiness
|
|
|
|
// happiness
|
|
|
|
p->readDWord (addr_cr + offs.happiness_offset, furball.happiness);
|
|
|
|
furball.happiness = source->happiness;
|
|
|
|
|
|
|
|
|
|
|
|
// physical attributes
|
|
|
|
// physical attributes
|
|
|
|
p->read(addr_cr + offs.physical_offset,
|
|
|
|
memcpy(&furball.strength, source->physical, sizeof(source->physical));
|
|
|
|
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
|
|
|
|
|
|
|
|
(uint8_t *)&furball.strength);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// mood stuff
|
|
|
|
// mood stuff
|
|
|
|
furball.mood = (int16_t) p->readWord (addr_cr + offs.mood_offset);
|
|
|
|
furball.mood = source->mood;
|
|
|
|
furball.mood_skill = p->readWord (addr_cr + offs.mood_skill_offset);
|
|
|
|
furball.mood_skill = source->unk_2f8; // FIXME: really? More like currently used skill anyway.
|
|
|
|
d->trans->readName(furball.artifact_name, addr_cr + offs.artifact_name_offset);
|
|
|
|
d->trans->readName(furball.artifact_name, &source->artifact_name);
|
|
|
|
|
|
|
|
|
|
|
|
// labors
|
|
|
|
// labors
|
|
|
|
p->read (addr_cr + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
|
|
|
|
memcpy(&furball.labors, &source->labors, sizeof(furball.labors));
|
|
|
|
|
|
|
|
|
|
|
|
furball.birth_year = p->readDWord (addr_cr + offs.birth_year_offset );
|
|
|
|
|
|
|
|
furball.birth_time = p->readDWord (addr_cr + offs.birth_time_offset );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
furball.pregnancy_timer = p->readDWord (addr_cr + offs.pregnancy_offset );
|
|
|
|
furball.birth_year = source->birth_year;
|
|
|
|
|
|
|
|
furball.birth_time = source->birth_time;
|
|
|
|
|
|
|
|
furball.pregnancy_timer = source->pregnancy_timer;
|
|
|
|
// appearance
|
|
|
|
// appearance
|
|
|
|
DfVector <uint32_t> app(addr_cr + offs.appearance_vector_offset);
|
|
|
|
furball.nbcolors = source->appearance.size();
|
|
|
|
furball.nbcolors = app.size();
|
|
|
|
|
|
|
|
if(furball.nbcolors>MAX_COLORS)
|
|
|
|
if(furball.nbcolors>MAX_COLORS)
|
|
|
|
furball.nbcolors = MAX_COLORS;
|
|
|
|
furball.nbcolors = MAX_COLORS;
|
|
|
|
for(uint32_t i = 0; i < furball.nbcolors; i++)
|
|
|
|
for(uint32_t i = 0; i < furball.nbcolors; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
furball.color[i] = app[i];
|
|
|
|
furball.color[i] = source->appearance[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//likes
|
|
|
|
//likes. FIXME: where do they fit in now? The soul?
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
|
|
|
|
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
|
|
|
|
furball.numLikes = likes.getSize();
|
|
|
|
furball.numLikes = likes.getSize();
|
|
|
@ -338,14 +285,11 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t temp2 = *(uint32_t *) likes[i];
|
|
|
|
uint32_t temp2 = *(uint32_t *) likes[i];
|
|
|
|
p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
|
|
|
|
p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(d->Ft_soul)
|
|
|
|
if(d->Ft_soul)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
|
|
// enum soul pointer vector
|
|
|
|
|
|
|
|
DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t soul = p->readDWord(addr_cr + offs.default_soul_offset);
|
|
|
|
uint32_t soul = p->readDWord(addr_cr + offs.default_soul_offset);
|
|
|
|
furball.has_default_soul = false;
|
|
|
|
furball.has_default_soul = false;
|
|
|
|
|
|
|
|
|
|
|
@ -378,8 +322,8 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
|
|
|
|
(uint8_t *) &furball.defaultSoul.traits);
|
|
|
|
(uint8_t *) &furball.defaultSoul.traits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(d->Ft_jobs)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
furball.current_job.occupationPtr = p->readDWord (addr_cr + offs.current_job_offset);
|
|
|
|
furball.current_job.occupationPtr = p->readDWord (addr_cr + offs.current_job_offset);
|
|
|
|
if(furball.current_job.occupationPtr)
|
|
|
|
if(furball.current_job.occupationPtr)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -391,63 +335,26 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
furball.current_job.active = false;
|
|
|
|
furball.current_job.active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
else
|
|
|
|
// no jobs for now...
|
|
|
|
{
|
|
|
|
{
|
|
|
|
furball.current_job.active = false;
|
|
|
|
furball.current_job.active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// returns index of creature actually read or -1 if no creature can be found
|
|
|
|
|
|
|
|
int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
|
|
|
|
|
|
|
|
const uint16_t x1, const uint16_t y1, const uint16_t z1,
|
|
|
|
|
|
|
|
const uint16_t x2, const uint16_t y2, const uint16_t z2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!d->Started)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Process *p = d->owner;
|
|
|
|
|
|
|
|
uint16_t coords[3];
|
|
|
|
|
|
|
|
uint32_t size = d->p_cre->size();
|
|
|
|
|
|
|
|
while (uint32_t(index) < size)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// read pointer from vector at position
|
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at(index);
|
|
|
|
|
|
|
|
p->read (temp + d->creatures.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
|
|
|
|
|
|
|
|
if (coords[0] >= x1 && coords[0] < x2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (coords[1] >= y1 && coords[1] < y2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (coords[2] >= z1 && coords[2] < z2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ReadCreature (index, furball);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t Creatures::FindIndexById(int32_t creature_id)
|
|
|
|
int32_t Creatures::FindIndexById(int32_t creature_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!d->Started || !d->Ft_basic)
|
|
|
|
if (!d->Started)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
if (!d->IdMapReady)
|
|
|
|
if (!d->IdMapReady)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
d->IdMap.clear();
|
|
|
|
d->IdMap.clear();
|
|
|
|
|
|
|
|
|
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t size = creatures->size();
|
|
|
|
Private::t_offsets &offs = d->creatures;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t size = d->p_cre->size();
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < size; index++)
|
|
|
|
for (uint32_t index = 0; index < size; index++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t temp = d->p_cre->at(index);
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
int32_t id = p->readDWord (temp + offs.id_offset);
|
|
|
|
int32_t id = temp->id;
|
|
|
|
d->IdMap[id] = index;
|
|
|
|
d->IdMap[id] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -459,7 +366,7 @@ int32_t Creatures::FindIndexById(int32_t creature_id)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return it->second;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
|
|
|
|
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
|
|
@ -665,7 +572,7 @@ bool Creatures::WritePregnancy(const uint32_t index, const uint32_t pregTimer)
|
|
|
|
p->writeDWord(temp + d->creatures.pregnancy_offset, pregTimer);
|
|
|
|
p->writeDWord(temp + d->creatures.pregnancy_offset, pregTimer);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
uint32_t Creatures::GetDwarfRaceIndex()
|
|
|
|
uint32_t Creatures::GetDwarfRaceIndex()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Inited) return 0;
|
|
|
|
if(!d->Inited) return 0;
|
|
|
@ -688,7 +595,7 @@ bool Creatures::getCurrentCursorCreature(uint32_t & creature_index)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
|
|
|
|
bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int i;
|
|
|
@ -709,67 +616,56 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
bool Creatures::ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item)
|
|
|
|
bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<t_item *> & item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_inventory) return false;
|
|
|
|
if(!d->Started) return false;
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
if(index >= creatures->size()) return false;
|
|
|
|
return this->ReadInventoryPtr(temp, item);
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
|
|
|
|
return this->ReadInventoryByPtr(temp, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::ReadInventoryPtr(const uint32_t temp, std::vector<uint32_t> & item)
|
|
|
|
bool Creatures::ReadInventoryByPtr(const df_creature * temp, std::vector<t_item *> & items)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if(!d->Started) return false;
|
|
|
|
if(!d->Started || !d->Ft_inventory) return false;
|
|
|
|
items = temp->inventory;
|
|
|
|
Process * p = d->owner;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DfVector <uint32_t> citem(temp + d->creatures.inventory_offset);
|
|
|
|
|
|
|
|
if(citem.size() == 0)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item.resize(citem.size());
|
|
|
|
|
|
|
|
for(i=0;i<citem.size();i++)
|
|
|
|
|
|
|
|
item[i] = p->readDWord(citem[i]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::ReadOwnedItemsIdx(const uint32_t index, std::vector<int32_t> & item)
|
|
|
|
bool Creatures::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_owned_items) return false;
|
|
|
|
if(!d->Started ) return false;
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
if(index >= creatures->size()) return false;
|
|
|
|
return this->ReadOwnedItemsPtr(temp, item);
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
|
|
|
|
return this->ReadOwnedItemsByPtr(temp, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::ReadOwnedItemsPtr(const uint32_t temp, std::vector<int32_t> & item)
|
|
|
|
bool Creatures::ReadOwnedItemsByPtr(const df_creature * temp, std::vector<int32_t> & items)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int i;
|
|
|
|
if(!d->Started || !d->Ft_owned_items) return false;
|
|
|
|
if(!d->Started) return false;
|
|
|
|
Process * p = d->owner;
|
|
|
|
items = temp->owned_items;
|
|
|
|
|
|
|
|
|
|
|
|
DfVector <int32_t> citem(temp + d->creatures.owned_items_offset);
|
|
|
|
|
|
|
|
if(citem.size() == 0)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item.resize(citem.size());
|
|
|
|
|
|
|
|
for(i=0;i<citem.size();i++)
|
|
|
|
|
|
|
|
item[i] = citem[i];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::RemoveOwnedItemIdx(const uint32_t index, int32_t id)
|
|
|
|
bool Creatures::RemoveOwnedItemByIdx(const uint32_t index, int32_t id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_owned_items)
|
|
|
|
if(!d->Started)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cerr << "!d->Started || !d->Ft_owned_items FAIL" << endl;
|
|
|
|
cerr << "!d->Started FAIL" << endl;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
df_creature * temp = creatures->at (index);
|
|
|
|
return this->RemoveOwnedItemPtr(temp, id);
|
|
|
|
return this->RemoveOwnedItemByPtr(temp, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Creatures::RemoveOwnedItemPtr(const uint32_t temp, int32_t id)
|
|
|
|
bool Creatures::RemoveOwnedItemByPtr(df_creature * temp, int32_t id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_owned_items) return false;
|
|
|
|
if(!d->Started) return false;
|
|
|
|
Process * p = d->owner;
|
|
|
|
Process * p = d->owner;
|
|
|
|
|
|
|
|
vector <int32_t> & vec = temp->owned_items;
|
|
|
|
|
|
|
|
vec.erase(std::remove(vec.begin(), vec.end(), id), vec.end());
|
|
|
|
|
|
|
|
/*
|
|
|
|
DfVector <int32_t> citem(temp + d->creatures.owned_items_offset);
|
|
|
|
DfVector <int32_t> citem(temp + d->creatures.owned_items_offset);
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < citem.size(); i++) {
|
|
|
|
for (unsigned i = 0; i < citem.size(); i++) {
|
|
|
@ -778,15 +674,12 @@ bool Creatures::RemoveOwnedItemPtr(const uint32_t temp, int32_t id)
|
|
|
|
if (!citem.remove(i--))
|
|
|
|
if (!citem.remove(i--))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Creatures::CopyNameTo(t_creature &creature, uint32_t address)
|
|
|
|
void Creatures::CopyNameTo(df_creature * creature, df_name * target)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Private::t_offsets &offs = d->creatures;
|
|
|
|
d->trans->copyName(&creature->name, target);
|
|
|
|
|
|
|
|
|
|
|
|
if(d->Ft_basic)
|
|
|
|
|
|
|
|
d->trans->copyName(creature.origin + offs.name_offset, address);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|