Modified the material API

develop
simon 2010-04-28 18:09:32 +02:00
parent 8065867a3b
commit 82dbf08d0b
10 changed files with 113 additions and 106 deletions

@ -76,18 +76,34 @@ namespace DFHack
Materials(DFHack::APIPrivate * _d);
~Materials();
std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);
void ReadAllMaterials(void);
/*
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// bool ReadPlantMaterials (std::vector<t_matglossPlant> & output);
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
*/
private:
class Private;
Private* d;

@ -197,33 +197,33 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
return true;
}
bool Materials::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
bool Materials::ReadInorganicMaterials (void)
{
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_inorganics"), inorganic );
}
bool Materials::ReadOrganicMaterials (vector<t_matgloss> & organic)
bool Materials::ReadOrganicMaterials (void)
{
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_all"), organic );
}
bool Materials::ReadWoodMaterials (vector<t_matgloss> & trees)
bool Materials::ReadWoodMaterials (void)
{
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_trees"), trees );
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_trees"), tree );
}
bool Materials::ReadPlantMaterials (vector<t_matgloss> & plants)
bool Materials::ReadPlantMaterials (void)
{
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_plants"), plants );
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_organics_plants"), plant );
}
bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
bool Materials::ReadCreatureTypes (void)
{
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("creature_type_vector"), creatures );
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("creature_type_vector"), race );
return true;
}
bool Materials::ReadDescriptorColors (vector<t_descriptor_color> & color)
bool Materials::ReadDescriptorColors (void)
{
Process * p = d->owner;
DfVector <uint32_t> p_colors (p, p->getDescriptor()->getAddress ("descriptor_colors_vector"));
@ -246,7 +246,7 @@ bool Materials::ReadDescriptorColors (vector<t_descriptor_color> & color)
return true;
}
bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
bool Materials::ReadCreatureTypesEx (void)
{
Process *p = d->owner;
memory_info *mem = d->owner->getDescriptor();
@ -257,8 +257,8 @@ bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
uint32_t sizecas = 0;
uint32_t tile_offset = mem->getOffset ("creature_tile");
uint32_t tile_color_offset = mem->getOffset ("creature_tile_color");
creatures.clear();
creatures.reserve (size);
raceEx.clear();
raceEx.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_creaturetype mat;
@ -279,8 +279,18 @@ bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset );
mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 );
mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 );
creatures.push_back(mat);
raceEx.push_back(mat);
}
return true;
}
void Materials::ReadAllMaterials(void)
{
this->ReadInorganicMaterials();
this->ReadOrganicMaterials();
this->ReadWoodMaterials();
this->ReadPlantMaterials();
this->ReadCreatureTypes();
this->ReadCreatureTypesEx();
this->ReadDescriptorColors();
}

@ -28,7 +28,6 @@ using namespace DFHack;
int main ( int argc, char** argv )
{
vector<DFHack::t_creaturetype> creaturestypes;
DFHack::memory_info *mem;
DFHack::Process *proc;
uint32_t creature_pregnancy_offset;
@ -89,7 +88,7 @@ int main ( int argc, char** argv )
DFHack::Creatures *Cre = DF.getCreatures();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
if(!Mats->ReadCreatureTypesEx(creaturestypes))
if(!Mats->ReadCreatureTypesEx())
{
cerr << "Can't get the creature types." << endl;
#ifndef LINUX_BUILD
@ -123,17 +122,17 @@ int main ( int argc, char** argv )
{
DFHack::t_creature creature;
Cre->ReadCreature(i,creature);
DFHack::t_creaturetype & crt = creaturestypes[creature.race];
DFHack::t_creaturetype & crt = Mats->raceEx[creature.race];
string castename = crt.castes[creature.sex].rawname;
if(castename == "FEMALE")
{
female_counts[creaturestypes[creature.race].rawname].push_back(creature);
male_counts[creaturestypes[creature.race].rawname].size();
female_counts[Mats->raceEx[creature.race].rawname].push_back(creature);
male_counts[Mats->raceEx[creature.race].rawname].size();
}
else // male, other, etc.
{
male_counts[creaturestypes[creature.race].rawname].push_back(creature);
female_counts[creaturestypes[creature.race].rawname].size(); //auto initialize the females as well
male_counts[Mats->raceEx[creature.race].rawname].push_back(creature);
female_counts[Mats->raceEx[creature.race].rawname].size(); //auto initialize the females as well
}
}

@ -43,8 +43,7 @@ int main (int numargs, const char ** args)
DFHack::Constructions *Cons = DF.getConstructions();
DFHack::Materials *Mats = DF.getMaterials();
vector<t_matgloss> inorganics;
Mats->ReadInorganicMaterials(inorganics);
Mats->ReadInorganicMaterials();
uint32_t numConstr;
Cons->Start(numConstr);
@ -65,7 +64,7 @@ int main (int numargs, const char ** args)
if(con.mat_type == 0)
{
if(con.mat_idx != 0xffffffff)
matstr = inorganics[con.mat_idx].id;
matstr = Mats->inorganic[con.mat_idx].id;
else matstr = "inorganic";
}
switch(con.form)

@ -18,14 +18,6 @@ using namespace std;
#include <modules/Translation.h>
#include "miscutils.h"
struct matGlosses
{
vector<DFHack::t_matglossPlant> plantMat;
vector<DFHack::t_matgloss> woodMat;
vector<DFHack::t_matgloss> stoneMat;
vector<DFHack::t_matgloss> metalMat;
vector<DFHack::t_matgloss> creatureMat;
};
enum likeType
{
FAIL = 0,
@ -34,8 +26,7 @@ enum likeType
FOOD = 3
};
vector<DFHack::t_creaturetype> creaturestypes;
matGlosses mat;
DFHack::Materials * Materials;
vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
@ -149,11 +140,11 @@ likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector<
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.race].rawname
<< "[" << creaturestypes[creature.race].tile_character
<< "," << creaturestypes[creature.race].tilecolor.fore
<< "," << creaturestypes[creature.race].tilecolor.back
<< "," << creaturestypes[creature.race].tilecolor.bright
cout << "address: " << hex << creature.origin << dec << " creature type: " << Materials->raceEx[creature.race].rawname
<< "[" << Materials->raceEx[creature.race].tile_character
<< "," << Materials->raceEx[creature.race].tilecolor.fore
<< "," << Materials->raceEx[creature.race].tilecolor.back
<< "," << Materials->raceEx[creature.race].tilecolor.bright
<< "]"
<< ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false;
@ -242,7 +233,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
}
cout << endl;
if(creature.mood != -1)
if((creature.mood != -1) && (creature.mood<5))
{
cout << "mood: " << creature.mood << ", skill: " << mem->getSkill(creature.mood_skill) << endl;
vector<DFHack::t_material> mymat;
@ -257,8 +248,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
case 0:
if(mymat[i].typeD>=0)
{
if(mymat[i].typeD<=mat.metalMat.size())
sprintf(maintype, "%s bar", mat.metalMat[mymat[i].typeD].id);
if(mymat[i].typeD<=Materials->inorganic.size())
sprintf(maintype, "%s bar", Materials->inorganic[mymat[i].typeD].id);
else
strcpy(maintype, "invalid metal bar");
}
@ -289,12 +280,21 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
case 24:
strcpy(maintype, "weapon?");
break;
case 26:
strcpy(maintype, "footwear");
break;
case 28:
strcpy(maintype, "headwear");
break;
case 54:
strcpy(maintype, "leather");
break;
case 57:
strcpy(maintype, "cloth");
break;
case 71:
strcpy(maintype, "food");
break;
default:
strcpy(maintype, "unknown");
break;
@ -464,12 +464,12 @@ int main (int numargs, char ** args)
}
mem = DF.getMemoryInfo();
if(!Materials->ReadInorganicMaterials(mat.metalMat))
if(!Materials->ReadInorganicMaterials())
{
cerr << "Can't get the inorganics types." << endl;
return 1;
}
if(!Materials->ReadCreatureTypesEx(creaturestypes))
if(!Materials->ReadCreatureTypesEx())
{
cerr << "Can't get the creature types." << endl;
return 1;
@ -486,7 +486,7 @@ int main (int numargs, char ** args)
{
DFHack::t_creature temp;
Creatures->ReadCreature(i,temp);
if(check.empty() || string(creaturestypes[temp.race].rawname) == check)
if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check)
{
cout << "index " << i << " ";

@ -43,39 +43,36 @@ int main (int numargs, const char ** args)
DFHack::Materials *Materials = DF.getMaterials();
cout << "----==== Inorganic ====----" << endl;
vector<DFHack::t_matgloss> matgloss;
Materials->ReadInorganicMaterials (matgloss);
for(uint32_t i = 0; i < matgloss.size();i++)
Materials->ReadInorganicMaterials ();
for(uint32_t i = 0; i < Materials->inorganic.size();i++)
{
cout << i << ": " << matgloss[i].id << endl;
cout << i << ": " << Materials->inorganic[i].id << endl;
}
cout << endl << "----==== Organic ====----" << endl;
vector<DFHack::t_matgloss> organic;
Materials->ReadOrganicMaterials (matgloss);
for(uint32_t i = 0; i < matgloss.size();i++)
Materials->ReadOrganicMaterials ();
for(uint32_t i = 0; i < Materials->organic.size();i++)
{
cout << i << ": " << matgloss[i].id << endl;
cout << i << ": " << Materials->organic[i].id << endl;
}
cout << endl << "----==== Organic - trees ====----" << endl;
Materials->ReadWoodMaterials (matgloss);
for(uint32_t i = 0; i < matgloss.size();i++)
Materials->ReadWoodMaterials ();
for(uint32_t i = 0; i < Materials->tree.size();i++)
{
cout << i << ": " << matgloss[i].id << endl;
cout << i << ": " << Materials->tree[i].id << endl;
}
cout << endl << "----==== Organic - plants ====----" << endl;
Materials->ReadPlantMaterials (matgloss);
for(uint32_t i = 0; i < matgloss.size();i++)
Materials->ReadPlantMaterials ();
for(uint32_t i = 0; i < Materials->plant.size();i++)
{
cout << i << ": " << matgloss[i].id << endl;
cout << i << ": " << Materials->plant[i].id << endl;
}
cout << endl << "----==== Creature types ====----" << endl;
vector<DFHack::t_creaturetype> creature;
Materials->ReadCreatureTypesEx (creature);
for(uint32_t i = 0; i < creature.size();i++)
Materials->ReadCreatureTypesEx ();
for(uint32_t i = 0; i < Materials->raceEx.size();i++)
{
cout << i << ": " << creature[i].rawname << endl;
vector<DFHack::t_creaturecaste> & castes = creature[i].castes;
cout << i << ": " << Materials->raceEx[i].rawname << endl;
vector<DFHack::t_creaturecaste> & castes = Materials->raceEx[i].castes;
for(uint32_t j = 0; j < castes.size();j++)
{
cout << " ["
@ -88,14 +85,13 @@ int main (int numargs, const char ** args)
cout << endl;
}
cout << endl << "----==== Color descriptors ====----" << endl;
vector<DFHack::t_descriptor_color> colors;
Materials->ReadDescriptorColors(colors);
for(uint32_t i = 0; i < colors.size();i++)
Materials->ReadDescriptorColors();
for(uint32_t i = 0; i < Materials->color.size();i++)
{
cout << i << ": " << colors[i].id << " - " << colors[i].name << "["
<< (unsigned int) (colors[i].r*255) << ":"
<< (unsigned int) (colors[i].v*255) << ":"
<< (unsigned int) (colors[i].b*255) << ":"
cout << i << ": " << Materials->color[i].id << " - " << Materials->color[i].name << "["
<< (unsigned int) (Materials->color[i].r*255) << ":"
<< (unsigned int) (Materials->color[i].v*255) << ":"
<< (unsigned int) (Materials->color[i].b*255) << ":"
<< "]" << endl;
}
#ifndef LINUX_BUILD

@ -100,9 +100,8 @@ int main (int numargs, const char ** args)
DFHack::Maps *Maps =DF.getMaps();
DFHack::Position *Pos =DF.getPosition();
DFHack::Materials *Mats =DF.getMaterials();
vector<t_matgloss> creature_types;
Mats->ReadCreatureTypes(creature_types);
Mats->ReadCreatureTypes();
// init the map
if(!Maps->Start())
@ -133,7 +132,7 @@ int main (int numargs, const char ** args)
for(uint32_t i = 0; i < splatter.size(); i++)
{
printf("Splatter %d\nmat1: %d\nunknown: %d\nmat2: %d\nmat3: %d\n",i,splatter[i].mat1,splatter[i].unk1,splatter[i].mat2,splatter[i].mat3);
cout << PrintSplatterType(splatter[i].mat1,splatter[i].mat2,creature_types) << endl;
cout << PrintSplatterType(splatter[i].mat1,splatter[i].mat2,Mats->race) << endl;
printf("Address 0x%08x\n",splatter[i].address_of);
for(uint32_t yyy = 0; yyy < 16; yyy++)
{
@ -168,7 +167,7 @@ int main (int numargs, const char ** args)
for(uint32_t i = 0; i < splatter.size(); i++)
{
printf("Splatter %d\nmat1: %d\nunknown: %d\nmat2: %d\nmat3: %d\n",i,splatter[i].mat1,splatter[i].unk1,splatter[i].mat2,splatter[i].mat3);
PrintSplatterType(splatter[i].mat1,splatter[i].mat2,creature_types);
PrintSplatterType(splatter[i].mat1,splatter[i].mat2,Mats->race);
cout << endl;
printf("Address 0x%08x\n",splatter[i].address_of);
for(uint32_t y = 0; y < 16; y++)

@ -49,8 +49,7 @@ int main (int numargs, const char ** args)
DFHack::Position * pos = DF.getPosition();
DFHack::Vegetation * v = DF.getVegetation();
DFHack::Materials * mat = DF.getMaterials();
vector<DFHack::t_matgloss> organics;
mat->ReadOrganicMaterials(organics);
mat->ReadOrganicMaterials();
int32_t x,y,z;
pos->getCursorCoords(x,y,z);
@ -82,7 +81,7 @@ int main (int numargs, const char ** args)
{
cout << "near-water ";
}
cout << organics[tree.material].id << " ";
cout << mat->organic[tree.material].id << " ";
if(tree.type == 0 || tree.type == 1)
{
cout << "tree";

@ -15,17 +15,7 @@ using namespace std;
#include <modules/Creatures.h>
#include <modules/Translation.h>
struct matGlosses
{
vector<DFHack::t_matglossPlant> plantMat;
vector<DFHack::t_matgloss> woodMat;
vector<DFHack::t_matgloss> stoneMat;
vector<DFHack::t_matgloss> metalMat;
vector<DFHack::t_matgloss> creatureMat;
};
vector<DFHack::t_creaturetype> creaturestypes;
matGlosses mat;
DFHack::Materials * Materials;
vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
@ -53,7 +43,7 @@ int main (int numargs, char ** args)
check = args[1];
DFHack::Creatures * Creatures = DF.getCreatures();
DFHack::Materials * Materials = DF.getMaterials();
Materials = DF.getMaterials();
DFHack::Translation * Tran = DF.getTranslation();
uint32_t numCreatures;
@ -75,13 +65,13 @@ int main (int numargs, char ** args)
}
mem = DF.getMemoryInfo();
if(!Materials->ReadInorganicMaterials(mat.metalMat))
if(!Materials->ReadInorganicMaterials())
{
cerr << "Can't get the inorganics types." << endl;
return 1;
}
if(!Materials->ReadCreatureTypesEx(creaturestypes))
if(!Materials->ReadCreatureTypesEx())
{
cerr << "Can't get the creature types." << endl;
return 1;

@ -57,7 +57,6 @@ int main (int argc, const char* argv[])
DFHack::mapblock40d Block;
map <int16_t, uint32_t> materials;
materials.clear();
vector<DFHack::t_matgloss> stonetypes;
vector<DFHack::t_feature> global_features;
std::map <DFHack::planecoord, std::vector<DFHack::t_feature *> > local_features;
@ -110,7 +109,7 @@ int main (int argc, const char* argv[])
return 1;
}
// get stone matgloss mapping
if(!Mats->ReadInorganicMaterials(stonetypes))
if(!Mats->ReadInorganicMaterials())
{
//DF.DestroyMap();
cerr << "Can't get the materials." << endl;
@ -289,7 +288,7 @@ int main (int argc, const char* argv[])
}
else
{
cout << stonetypes[p->first].id << " : " << p->second << endl;
cout << Mats->inorganic[p->first].id << " : " << p->second << endl;
}
}
DF.Detach();