base support for creatures

develop
Petr Mrázek 2009-10-23 01:39:19 +00:00
parent f05f0b16b2
commit 876dcbf7cc
5 changed files with 96 additions and 7 deletions

@ -56,6 +56,7 @@ DFHackAPIImpl::DFHackAPIImpl(const string path_to_xml)
{
xml = path_to_xml;
constructionsInited = false;
creaturesInited = false;
buildingsInited = false;
vegetationInited = false;
pm = NULL;
@ -378,6 +379,34 @@ bool DFHackAPIImpl::ReadPlantMatgloss(vector<t_matgloss> & plants)
return true;
}
bool DFHackAPIImpl::ReadCreatureMatgloss(vector<t_matgloss> & creatures)
{
int matgloss_address = offset_descriptor->getAddress("matgloss");
int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip");
DfVector p_matgloss = dm->readVector(matgloss_address + matgloss_offset*4, 4);
creatures.clear();
// TODO: use green?
t_matgloss mat;
mat.fore = 7;
mat.back = 0;
mat.bright = 0;
for (uint32_t i = 0; i< p_matgloss.getSize();i++)
{
uint32_t temp;
// read the matgloss pointer from the vector into temp
p_matgloss.read((uint32_t)i,(uint8_t *)&temp);
// read the string pointed at by
fill_char_buf(mat.id, dm->readSTLString(temp)); // reads a C string given an address
creatures.push_back(mat);
}
return true;
}
//vector<uint16_t> v_geology[eBiomeCount];
bool DFHackAPIImpl::ReadGeology( vector < vector <uint16_t> >& assign )
{
@ -565,7 +594,7 @@ uint32_t DFHackAPIImpl::InitReadVegetation()
{
vegetationInited = true;
int vegetation = offset_descriptor->getAddress("vegetation");
treeoffset = offset_descriptor->getOffset("tree_desc_offset");
tree_offset = offset_descriptor->getOffset("tree_desc_offset");
assert(vegetation && treeoffset);
p_veg = new DfVector(dm->readVector(vegetation,4));
return p_veg->getSize();
@ -579,10 +608,10 @@ bool DFHackAPIImpl::ReadVegetation(const uint32_t &index, t_tree_desc & shrubber
// read pointer from vector at position
p_veg->read(index,(uint8_t *)&temp);
//read construction from memory
Mread(temp + treeoffset, sizeof(t_tree_desc), (uint8_t *) &shrubbery);
Mread(temp + tree_offset, sizeof(t_tree_desc), (uint8_t *) &shrubbery);
// FIXME: this is completely wrong. type isn't just tree/shrub but also different kinds of trees. stuff that grows around ponds has its own type ID
if(shrubbery.material.type == 3) shrubbery.material.type = 2;
return true;
return true;
}
@ -592,6 +621,36 @@ void DFHackAPIImpl::FinishReadVegetation()
}
uint32_t DFHackAPIImpl::InitReadCreatures()
{
creaturesInited = true;
int creatures = offset_descriptor->getAddress("creatures");
creature_pos_offset = offset_descriptor->getOffset("creature_position");
creature_type_offset = offset_descriptor->getOffset("creature_type");
assert(creatures && creatureposoffset && creaturetypeoffset);
p_cre = new DfVector(dm->readVector(creatures, 4));
return p_cre->getSize();
}
bool DFHackAPIImpl::ReadCreature(const uint32_t &index, t_creature & furball)
{
assert(vegetationInited);
uint32_t temp;
// read pointer from vector at position
p_cre->read(index,(uint8_t *)&temp);
//read creature from memory
Mread(temp + creature_pos_offset, 3 * sizeof(uint16_t), (uint8_t *) &(furball.x)); // xyz really
Mread(temp + creature_type_offset, sizeof(uint32_t), (uint8_t *) &furball.type);
return true;
}
void DFHackAPIImpl::FinishReadCreatures()
{
creaturesInited = false;
}
bool DFHackAPIImpl::Attach()
{
// detach all processes, destroy manager

@ -75,6 +75,7 @@ public:
virtual bool ReadWoodMatgloss (vector<t_matgloss> & output) = 0;
virtual bool ReadMetalMatgloss(vector<t_matgloss> & output) = 0;
virtual bool ReadPlantMatgloss(vector<t_matgloss> & output) = 0;
virtual bool ReadCreatureMatgloss(vector<t_matgloss> & output) = 0;
// FIXME: add creatures for all the creature products
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
@ -154,6 +155,10 @@ public:
virtual uint32_t InitReadVegetation() = 0;
virtual bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery) = 0;
virtual void FinishReadVegetation() = 0;
virtual uint32_t InitReadCreatures() = 0;
virtual bool ReadCreature(const uint32_t &index, t_creature & furball) = 0;
virtual void FinishReadCreatures() = 0;
};
#ifdef BUILD_DFHACK_LIB
@ -179,6 +184,9 @@ private:
uint32_t designation_offset;
uint32_t occupancy_offset;
uint32_t creature_pos_offset;
uint32_t creature_type_offset;
ProcessManager* pm;
Process* p;
DataModel* dm;
@ -189,7 +197,9 @@ private:
bool constructionsInited;
bool buildingsInited;
bool vegetationInited;
uint32_t treeoffset;
bool creaturesInited;
uint32_t tree_offset;
DfVector *p_cre;
DfVector *p_cons;
DfVector *p_bld;
DfVector *p_veg;
@ -210,7 +220,7 @@ public:
bool ReadWoodMatgloss (vector<t_matgloss> & output);
bool ReadMetalMatgloss(vector<t_matgloss> & output);
bool ReadPlantMatgloss(vector<t_matgloss> & output);
// FIXME: add creatures for all the creature products
bool ReadCreatureMatgloss(vector<t_matgloss> & output);
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss
@ -289,6 +299,10 @@ public:
uint32_t InitReadVegetation();
bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery);
void FinishReadVegetation();
uint32_t InitReadCreatures();
bool ReadCreature(const uint32_t &index, t_creature & furball);
void FinishReadCreatures();
};
#endif

@ -1068,6 +1068,6 @@ DFHACKAPI int getVegetationType(int in)
case 34: //shrub
return SHRUB_OK;
}
// ????
return -1;
// ????
return -1;
}

@ -129,6 +129,14 @@ struct t_tree_desc
uint16_t z;
};
struct t_creature
{
uint16_t x;
uint16_t y;
uint16_t z;
uint32_t type;
};
/*
case 10:
ret += "leather";

@ -65,6 +65,7 @@
<Address name="constructions">0x0156F8B0</Address>
<Address name="buildings">0x015838a0</Address>
<Address name="vegetation">0x01587A24</Address>
<Address name="creatures">0x01583224</Address>
<!-- size of the map -->
<Address name="x_count">0x015C4D70</Address>
@ -84,6 +85,10 @@
<Offset name="occupancy">0x0664</Offset>
<Offset name="biome_stuffs">0x1D64</Offset>
<!-- creature offsets -->
<Offset name="creature_position">0x94</Offset>
<Offset name="creature_type">0x8C</Offset>
<!-- tree and shrub offsets -->
<Offset name="tree_desc_offset">0x70</Offset>
@ -210,6 +215,8 @@
<Address name="constructions">0x014da5e0</Address>
<Address name="buildings">0x014ee978</Address>
<Address name="vegetation">0x014F4B4C</Address>
<Address name="creatures">0x014edfcc</Address>
<!-- tree and shrub offsets -->
<Offset name="tree_desc_offset">0x70</Offset>
@ -276,6 +283,7 @@
<Address name="constructions">0x015A33B8</Address>
<Address name="buildings">0x015B7750</Address>
<Address name="vegetation">0x015BD924</Address>
<Address name="creatures">0x015B6DA4</Address>
<!-- size of the map -->
<Address name="x_count">0x015FACEC</Address>