Support for creature castes

develop
Petr Mrázek 2010-04-14 22:12:02 +02:00
parent e8a3106b10
commit ab3a842fdb
5 changed files with 69 additions and 10 deletions

@ -29,6 +29,20 @@ namespace DFHack
char extract_name[128]; char extract_name[128];
}; };
struct t_creaturecaste
{
char rawname[128];
char singular[128];
char plural[128];
char adjective[128];
};
struct t_creaturetype
{
char rawname[128];
vector <t_creaturecaste> castes;
};
class DFHACK_EXPORT Materials class DFHACK_EXPORT Materials
{ {
public: public:
@ -45,6 +59,7 @@ namespace DFHack
// TODO: maybe move to creatures? // TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output); bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
private: private:
APIPrivate* d; APIPrivate* d;
}; };

@ -212,3 +212,34 @@ bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures ); return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures );
return true; return true;
} }
bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
{
DfVector p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector"), 4);
uint32_t castes_vector_offset = d->offset_descriptor->getOffset ("creature_type_caste_vector");
uint32_t sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string");
uint32_t size = p_races.getSize();
uint32_t sizecas = 0;
creatures.clear();
creatures.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_creaturetype mat;
g_pProcess->readSTLString (*(uint32_t *) p_races[i], mat.rawname, sizeof(mat.rawname));
DfVector p_castes(g_pProcess,(*(uint32_t *) p_races[i]) + castes_vector_offset, 4);
sizecas = p_castes.getSize();
for (uint32_t j = 0; j < sizecas;j++)
{
t_creaturecaste caste;
uint32_t caste_start = *(uint32_t *)p_castes[j];
g_pProcess->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname));
g_pProcess->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular));
g_pProcess->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural));
g_pProcess->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective));
mat.castes.push_back(caste);
}
creatures.push_back(mat);
}
return true;
}

@ -407,7 +407,7 @@ int main (void)
{ {
DFHack::t_creature temp; DFHack::t_creature temp;
Creatures->ReadCreature(i,temp); Creatures->ReadCreature(i,temp);
if(string(creaturestypes[temp.race].id) == "DWARF") if(string(creaturestypes[temp.race].id) == "HORSE")
{ {
cout << "index " << i << " "; cout << "index " << i << " ";
@ -415,7 +415,7 @@ int main (void)
addrs.push_back(temp.origin); addrs.push_back(temp.origin);
} }
} }
//interleave_hex(DF,addrs,200); interleave_hex(DF,addrs,200);
/* /*
uint32_t currentIdx; uint32_t currentIdx;
DFHack::t_creature currentCreature; DFHack::t_creature currentCreature;

@ -69,11 +69,22 @@ int main (int numargs, const char ** args)
cout << i << ": " << matgloss[i].id << endl; cout << i << ": " << matgloss[i].id << endl;
} }
cout << endl << "----==== Creature types ====----" << endl; cout << endl << "----==== Creature types ====----" << endl;
vector<DFHack::t_matgloss> creature; vector<DFHack::t_creaturetype> creature;
Materials->ReadCreatureTypes (matgloss); Materials->ReadCreatureTypesEx (creature);
for(uint32_t i = 0; i < matgloss.size();i++) for(uint32_t i = 0; i < creature.size();i++)
{ {
cout << i << ": " << matgloss[i].id << endl ; cout << i << ": " << creature[i].rawname << endl;
vector<DFHack::t_creaturecaste> & castes = creature[i].castes;
for(uint32_t j = 0; j < castes.size();j++)
{
cout << " ["
<< castes[j].rawname << ":"
<< castes[j].singular << ":"
<< castes[j].plural << ":"
<< castes[j].adjective << "] ";
cout << endl;
}
cout << endl;
} }
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;

@ -1191,9 +1191,10 @@ map_data_1b60_offset 0x1B9c
just wood, WORLD + 0x54BDC just wood, WORLD + 0x54BDC
<Address name="mat_organics_trees">0x16afd64</Address> <Address name="mat_organics_trees">0x16afd64</Address>
creature types actually used for creatures, WORLD + 0x54CD0 creature types actually used for creatures,
WORLD + 0x54CD0
<Address name="creature_type_vector">0x016AFE58</Address> <Address name="creature_type_vector">0x016AFE58</Address>
<Offset name="creature_type_caste_vector">0x138</Offset>
<!-- <!--
NOT used yet NOT used yet
@ -1370,8 +1371,9 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_side">0X120</Offset> <Offset name="creature_side">0X120</Offset>
<Offset name="creature_soulskill_vector">0X1F4</Offset> <Offset name="creature_soulskill_vector">0X1F4</Offset>
<Offset name="creature_pickup_equipment_bit">0X21C</Offset> <Offset name="creature_pickup_equipment_bit">0X21C</Offset>
<Offset name="creature_mood">0x238</Offset> <!--<Offset name="creature_mood">0x238</Offset>-->
<!--<Offset name="creature_pregnancy">0x23C</Offset>--> <Offset name="creature_pregnancy">0x28C</Offset>
<Offset name="creature_pregnancy_ptr">0x290</Offset>
<Offset name="creature_physical">0x464</Offset> <Offset name="creature_physical">0x464</Offset>
<!-- <!--