Major cleanup of Materials modul, precursor to eventually nuking it

develop
Quietust 2012-01-21 10:12:26 -06:00
parent d504479fc2
commit 118e5c6617
3 changed files with 211 additions and 811 deletions

@ -36,6 +36,8 @@ distribution.
#include "DataDefs.h"
#include "df/material.h"
#include "df/inorganic_raw.h"
#include "df/plant_raw.h"
#include <vector>
#include <string>
@ -43,7 +45,6 @@ distribution.
namespace df
{
struct item;
struct inorganic_raw;
struct plant_raw;
struct creature_raw;
struct historical_figure;
@ -144,317 +145,6 @@ namespace DFHack
typedef int32_t t_materialIndex;
typedef int16_t t_materialType, t_itemType, t_itemSubtype;
struct t_syndrome
{
// it's lonely here...
};
/**
* \ingroup grp_materials
*/
enum e_matter_state
{
state_solid,
state_liquid,
state_gas,
state_powder,
state_paste,
state_pressed,
NUM_MATTER_STATES
};
/**
* \ingroup grp_materials
*/
enum material_flags
{
MATERIAL_BONE = 0,
MATERIAL_MEAT,
MATERIAL_EDIBLE_VERMIN,
MATERIAL_EDIBLE_RAW,
MATERIAL_EDIBLE_COOKED,
MATERIAL_UNK5,
MATERIAL_ITEMS_METAL,
MATERIAL_ITEMS_BARRED,
MATERIAL_ITEMS_SCALED = 8,
MATERIAL_ITEMS_LEATHER,
MATERIAL_ITEMS_SOFT,
MATERIAL_ITEMS_HARD,
MATERIAL_IMPLIES_ANIMAL_KILL,
MATERIAL_ALCOHOL_PLANT,
MATERIAL_ALCOHOL_CREATURE,
MATERIAL_CHEESE_PLANT,
MATERIAL_CHEESE_CREATURE = 16,
MATERIAL_POWDER_MISC_PLANT,
MATERIAL_POWDER_MISC_CREATURE,
MATERIAL_STOCKPILE_GLOB,
MATERIAL_LIQUID_MISC_PLANT,
MATERIAL_LIQUID_MISC_CREATURE,
MATERIAL_LIQUID_MISC_OTHER,
MATERIAL_WOOD,
MATERIAL_THREAD_PLANT = 24,
MATERIAL_TOOTH,
MATERIAL_HORN,
MATERIAL_PEARL,
MATERIAL_SHELL,
MATERIAL_LEATHER,
MATERIAL_SILK,
MATERIAL_SOAP,
MATERIAL_ROTS = 32,
MATERIAL_UNK33,
MATERIAL_UNK34,
MATERIAL_UNK35,
MATERIAL_STRUCTURAL_PLANT_MAT,
MATERIAL_SEED_MAT,
MATERIAL_LEAF_MAT,
MATERIAL_UNK39,
MATERIAL_ENTERS_BLOOD = 40,
MATERIAL_BLOOD_MAP_DESCRIPTOR,
MATERIAL_ICHOR_MAP_DESCRIPTOR,
MATERIAL_GOO_MAP_DESCRIPTOR,
MATERIAL_SLIME_MAP_DESCRIPTOR,
MATERIAL_PUS_MAP_DESCRIPTOR,
MATERIAL_GENERATES_MIASMA,
MATERIAL_IS_METAL,
MATERIAL_IS_GEM = 48,
MATERIAL_IS_GLASS,
MATERIAL_CRYSTAL_GLASSABLE,
MATERIAL_ITEMS_WEAPON,
MATERIAL_ITEMS_WEAPON_RANGED,
MATERIAL_ITEMS_ANVIL,
MATERIAL_ITEMS_AMMO,
MATERIAL_ITEMS_DIGGER,
MATERIAL_ITEMS_ARMOR = 56,
MATERIAL_ITEMS_DELICATE,
MATERIAL_ITEMS_SIEGE_ENGINE,
MATERIAL_ITEMS_QUERN,
MATERIAL_IS_STONE,
MATERIAL_UNDIGGABLE,
MATERIAL_YARN,
MATERIAL_STOCKPILE_GLOB_PASTE,
MATERIAL_STOCKPILE_GLOB_PRESSED = 64,
MATERIAL_DISPLAY_UNGLAZED,
MATERIAL_DO_NOT_CLEAN_GLOB,
MATERIAL_NO_STONE_STOCKPILE,
MATERIAL_STOCKPILE_THREAD_METAL,
MATERIAL_UNK69,
MATERIAL_UNK70,
MATERIAL_UNK71,
MATERIAL_UNK72 = 72,
MATERIAL_UNK73,
MATERIAL_UNK74,
MATERIAL_UNK75,
MATERIAL_UNK76,
MATERIAL_UNK77,
MATERIAL_UNK78,
MATERIAL_UNK79,
};
/**
* \ingroup grp_materials
*/
enum inorganic_flags
{
INORGANIC_LAVA = 0,
INORGANIC_UNK1,
INORGANIC_UNK2,
INORGANIC_SEDIMENTARY,
INORGANIC_SEDIMENTARY_OCEAN_SHALLOW,
INORGANIC_IGNEOUS_INTRUSIVE,
INORGANIC_IGNEOUS_EXTRUSIVE,
INORGANIC_METAMORPHIC,
INORGANIC_DEEP_SURFACE = 8,
INORGANIC_METAL_ORE, // maybe
INORGANIC_AQUIFER,
INORGANIC_SOIL_ANY, // any soil
INORGANIC_SOIL_OCEAN,
INORGANIC_SOIL_SAND,
INORGANIC_SEDIMENTARY_OCEAN_DEEP,
INORGANIC_THREAD_METAL, // maybe
INORGANIC_DEEP = 16, // in general
INORGANIC_SOIL, // specific soil
INORGANIC_DEEP_SPECIAL,
INORGANIC_UNK19,
INORGANIC_UNK20,
INORGANIC_UNK21,
INORGANIC_UNK22,
INORGANIC_UNK23,
INORGANIC_UNK24 = 24,
INORGANIC_WAFERS,
INORGANIC_UNK26,
INORGANIC_UNK27,
INORGANIC_UNK28,
INORGANIC_UNK29,
INORGANIC_UNK30,
INORGANIC_UNK31,
};
/**
* Environment locations
* \ingroup grp_materials
*/
enum environment_location
{
ENV_SOIL,
ENV_SOIL_OCEAN,
ENV_SOIL_SAND,
ENV_METAMORPHIC,
ENV_SEDIMENTARY,
ENV_IGNEOUS_INTRUSIVE,
ENV_IGNEOUS_EXTRUSIVE,
ENV_ALLUVIAL,
};
/**
* Inclusion types
* \ingroup grp_materials
*/
enum inclusion_type
{
INCLUSION_NONE, // maybe
INCLUSION_VEIN,
INCLUSION_CLUSTER,
INCLUSION_CLUSTER_SMALL,
INCLUSION_CLUSTER_ONE,
};
/**
* The reversed generic material struct
* Research by Quietust
* \ingroup grp_materials
*/
struct df_material
{
std::string Material_ID;
std::string IS_GEM_singular;
std::string IS_GEM_plural;
std::string STONE_NAME;
int16_t SPEC_HEAT;
int16_t HEATDAM_POINT;
int16_t COLDDAM_POINT;
int16_t IGNITE_POINT;
int16_t MELTING_POINT;
int16_t BOILING_POINT;
int16_t MAT_FIXED_TEMP;
//int16_t padding; // added by compiler automatically
int32_t SOLID_DENSITY;
int32_t LIQUID_DENSITY;
int32_t MOLAR_MASS;
int32_t state_color[NUM_MATTER_STATES]; // color token indexes
std::string state_name[NUM_MATTER_STATES];
std::string state_adj[NUM_MATTER_STATES];
int32_t ABSORPTION;
int32_t BENDING_YIELD;
int32_t SHEAR_YIELD;
int32_t TORSION_YIELD;
int32_t IMPACT_YIELD;
int32_t TENSILE_YIELD;
int32_t COMPRESSIVE_YIELD;
int32_t BENDING_FRACTURE;
int32_t SHEAR_FRACTURE;
int32_t TORSION_FRACTURE;
int32_t IMPACT_FRACTURE;
int32_t TENSILE_FRACTURE;
int32_t COMPRESSIVE_FRACTURE;
int32_t BENDING_STRAIN_AT_YIELD;
int32_t SHEAR_STRAIN_AT_YIELD;
int32_t TORSION_STRAIN_AT_YIELD;
int32_t IMPACT_STRAIN_AT_YIELD;
int32_t TENSILE_STRAIN_AT_YIELD;
int32_t COMPRESSIVE_STRAIN_AT_YIELD;
int32_t MAX_EDGE;
int32_t MATERIAL_VALUE;
BitArray <material_flags> mat_flags;
t_itemType EXTRACT_STORAGE;
t_itemType BUTCHER_SPECIAL_type;
t_itemSubtype BUTCHER_SPECIAL_subtype;
//int16_t padding; // added by compiler
std::string MEAT_NAME_1st_parm; // (adj)
std::string MEAT_NAME_2nd_parm;
std::string MEAT_NAME_3rd_parm;
std::string BLOCK_NAME_1st_parm;
std::string BLOCK_NAME_2nd_parm;
std::vector <std::string> MATERIAL_REACTION_PRODUCT_1st_parm;// (e.g. TAN_MAT)
std::vector <void *> unknown1;
std::vector <void *> unknown2;
std::vector <std::string> MATERIAL_REACTION_PRODUCT_2nd_parm;// (e.g. LOCAL_CREATURE_MAT)
std::vector <std::string> MATERIAL_REACTION_PRODUCT_3rd_parm;// (e.g. LEATHER)
std::vector <std::string> MATERIAL_REACTION_PRODUCT_4th_parm;// (if you used CREATURE_MAT or PLANT_MAT)
int16_t unknown3;
//int16_t padding; // added by compiler
int32_t unknown4;
std::string HARDENS_WITH_WATER_1st_parm;// (e.g. INORGANIC)
std::string HARDENS_WITH_WATER_2nd_parm;// (e.g. GYPSUM)
std::string HARDENS_WITH_WATER_3rd_parm;// (if you used CREATURE_MAT or PLANT_MAT)
std::vector <std::string> REACTION_CLASS;
int8_t TILE; // Tile when material is a natural wall
int16_t BASIC_COLOR_foreground;
int16_t BASIC_COLOR_bright;
// what exactly ARE those colors?
int16_t BUILD_COLOR_foreground;
int16_t BUILD_COLOR_background;
int16_t BUILD_COLOR_bright;
// same...
int16_t TILE_COLOR_foreground;
int16_t TILE_COLOR_background;
int16_t TILE_COLOR_bright;
int8_t ITEM_SYMBOL; // Tile when material is a dug out stone
int16_t POWDER_DYE; // (color token index)
int16_t TEMP_DIET_INFO;// (whatever it means)
std::vector <t_syndrome *> SYNDROME;
int32_t SOAP_LEVEL;
std::string PREFIX;
// etc...
bool isGem()
{
return mat_flags.is_set(MATERIAL_IS_GEM);
};
bool isStone()
{
return mat_flags.is_set(MATERIAL_IS_STONE);
};
};
/**
* The reversed inorganic material struct
* Research by Quietust
* \ingroup grp_materials
*/
struct df_inorganic_type
{
std::string ID;
BitArray<inorganic_flags> inorg_flags;
std::vector <uint32_t> empty1;
std::vector <int16_t> METAL_ORE_matID; // Vector of indexes of metals produced when ore is smelted
std::vector <int16_t> METAL_ORE_prob; // Vector of percent chance of each type of metal being produced on smelting
std::vector <uint32_t> empty2;
std::vector <int16_t> THREAD_METAL_matID;// Vector of indexes of metals produced when ore undergoes strand extraction
std::vector <int16_t> THREAD_METAL_prob; // Vector of percent chance of each type of metal being produced on strand extraction
std::vector <uint32_t> unknown_in_1;
std::vector <uint32_t> empty3;
std::vector <int16_t> ENVIRONMENT_SPEC_matID;
std::vector <int16_t> ENVIRONMENT_SPEC_inclusion_type;
std::vector <int8_t> ENVIRONMENT_SPEC_prob;
std::vector <int16_t> ENVIRONMENT_location;
std::vector <int16_t> ENVIRONMENT_inclusion_type;
std::vector <int8_t> ENVIRONMENT_prob;
int32_t unknown_in_2;
df_material mat;
bool isOre()
{
if(!METAL_ORE_matID.empty())
return true;
if(!THREAD_METAL_matID.empty())
return true;
return false;
}
};
/**
* A copy of the game's material data.
* \ingroup grp_materials
@ -505,173 +195,7 @@ namespace DFHack
bool isOre();
bool isGem();
};
/**
* The plant flags
* \ingroup grp_materials
*/
enum plant_flags
{
// byte 0
PLANT_SPRING,
PLANT_SUMMER,
PLANT_AUTUMN,
PLANT_WINTER,
PLANT_UNK1,
PLANT_SEED,
PLANT_LEAVES,
PLANT_DRINK,
// byte 1
PLANT_EXTRACT_BARREL,
PLANT_EXTRACT_VIAL,
PLANT_EXTRACT_STILL_VIAL,
PLANT_UNK2,
PLANT_THREAD,
PLANT_MILL,
PLANT_UNK3,
PLANT_UNK4,
// byte 2
PLANT_UNK5,
PLANT_UNK6,
PLANT_UNK7,
PLANT_UNK8,
PLANT_WET,
PLANT_DRY,
PLANT_BIOME_MOUNTAIN,
PLANT_BIOME_GLACIER,
// byte 3
PLANT_BIOME_TUNDRA,
PLANT_BIOME_SWAMP_TEMPERATE_FRESHWATER,
PLANT_BIOME_SWAMP_TEMPERATE_SALTWATER,
PLANT_BIOME_MARSH_TEMPERATE_FRESHWATER,
PLANT_BIOME_MARSH_TEMPERATE_SALTWATER,
PLANT_BIOME_SWAMP_TROPICAL_FRESHWATER,
PLANT_BIOME_SWAMP_TROPICAL_SALTWATER,
PLANT_BIOME_SWAMP_MANGROVE,
// byte 4
PLANT_BIOME_MARSH_TROPICAL_FRESHWATER,
PLANT_BIOME_MARSH_TROPICAL_SALTWATER,
PLANT_BIOME_FOREST_TAIGA,
PLANT_BIOME_FOREST_TEMPERATE_CONIFER,
PLANT_BIOME_FOREST_TEMPERATE_BROADLEAF,
PLANT_BIOME_FOREST_TROPICAL_CONIFER,
PLANT_BIOME_FOREST_TROPICAL_DRY_BROADLEAF,
PLANT_BIOME_FOREST_TROPICAL_MOIST_BROADLEAF,
// byte 5
PLANT_BIOME_GRASSLAND_TEMPERATE,
PLANT_BIOME_SAVANNA_TEMPERATE,
PLANT_BIOME_SHRUBLAND_TEMPERATE,
PLANT_BIOME_GRASSLAND_TROPICAL,
PLANT_BIOME_SAVANNA_TROPICAL,
PLANT_BIOME_SHRUBLAND_TROPICAL,
PLANT_BIOME_DESERT_BADLAND,
PLANT_BIOME_DESERT_ROCK,
// byte 6
PLANT_BIOME_DESERT_SAND,
PLANT_BIOME_OCEAN_TROPICAL,
PLANT_BIOME_OCEAN_TEMPERATE,
PLANT_BIOME_OCEAN_ARCTIC,
PLANT_BIOME_POOL_TEMPERATE_FRESHWATER,
PLANT_BIOME_SUBTERRANEAN_WATER,
PLANT_BIOME_SUBTERRANEAN_CHASM,
PLANT_BIOME_SUBTERRANEAN_LAVA,
// byte 7
PLANT_GOOD,
PLANT_EVIL,
PLANT_SAVAGE,
PLANT_BIOME_POOL_TEMPERATE_BRACKISHWATER,
PLANT_BIOME_POOL_TEMPERATE_SALTWATER,
PLANT_BIOME_POOL_TROPICAL_FRESHWATER,
PLANT_BIOME_POOL_TROPICAL_BRACKISHWATER,
PLANT_BIOME_POOL_TROPICAL_SALTWATER,
// byte 8
PLANT_BIOME_LAKE_TEMPERATE_FRESHWATER,
PLANT_BIOME_LAKE_TEMPERATE_BRACKISHWATER,
PLANT_BIOME_LAKE_TEMPERATE_SALTWATER,
PLANT_BIOME_LAKE_TROPICAL_FRESHWATER,
PLANT_BIOME_LAKE_TROPICAL_BRACKISHWATER,
PLANT_BIOME_LAKE_TROPICAL_SALTWATER,
PLANT_BIOME_RIVER_TEMPERATE_FRESHWATER,
PLANT_BIOME_RIVER_TEMPERATE_BRACKISHWATER,
// byte 9
PLANT_BIOME_RIVER_TEMPERATE_SALTWATER,
PLANT_BIOME_RIVER_TROPICAL_FRESHWATER,
PLANT_BIOME_RIVER_TROPICAL_BRACKISHWATER,
PLANT_BIOME_RIVER_TROPICAL_SALTWATER,
PLANT_AUTUMNCOLOR,
PLANT_SAPLING,
PLANT_TREE,
PLANT_GRASS,
};
/**
* The plant RAWs in memory
* \ingroup grp_materials
*/
struct df_plant_type
{
std::string ID;
BitArray <plant_flags> flags;
std::string name, name_plural, adj;
std::string seed_singular, seed_plural;
std::string leaves_singular, leaves_plural;
uint8_t unk1;
uint8_t unk2;
char picked_tile, dead_picked_tile;
char shrub_tile, dead_shrub_tile;
char leaves_tile;
char tree_tile, dead_tree_tile;
char sapling_tile, dead_sapling_tile;
char grass_tiles[16];
char alt_grass_tiles[12];
int32_t growdur;
int32_t value;
int8_t picked_color[3], dead_picked_color[3];
int8_t shrub_color[3], dead_shrub_color[3];
int8_t seed_color[3];
int8_t leaves_color[3], dead_leaves_color[3];
int8_t tree_color[3], dead_tree_color[3];
int8_t sapling_color[3], dead_sapling_color[3];
int8_t grass_colors_0[20], grass_colors_1[20], grass_colors_2[20];
int32_t alt_period[2];
int8_t shrub_drown_level;
int8_t tree_drown_level;
int8_t sapling_drown_level;
int16_t frequency;
int16_t clustersize;
std::vector<std::string *> prefstring;
std::vector<df_material *> materials;
// materials and material indexes - only valid when appropriate flags in the BitArray are set
int16_t material_type_basic_mat;
int16_t material_type_tree;
int16_t material_type_drink;
int16_t material_type_seed;
int16_t material_type_thread;
int16_t material_type_mill;
int16_t material_type_extract_vial;
int16_t material_type_extract_barrel;
int16_t material_type_extract_still_vial;
int16_t material_type_leaves;
int32_t material_idx_basic_mat;
int32_t material_idx_tree;
int32_t material_idx_drink;
int32_t material_idx_seed;
int32_t material_idx_thread;
int32_t material_idx_mill;
int32_t material_idx_extract_vial;
int32_t material_idx_extract_barrel;
int32_t material_idx_extract_still_vial;
int32_t material_idx_leaves;
std::string material_str_basic_mat[3];
std::string material_str_tree[3];
std::string material_str_drink[3];
std::string material_str_seed[3];
std::string material_str_thread[3];
std::string material_str_mill[3];
std::string material_str_extract_vial[3];
std::string material_str_extract_barrel[3];
std::string material_str_extract_still_vial[3];
std::string material_str_leaves[3];
int32_t underground_depth[2];
};
/**
* \ingroup grp_materials
*/
@ -746,8 +270,9 @@ namespace DFHack
t_attrib spatial_sense;
t_attrib musicality;
t_attrib kinesthetic_sense;
t_attrib empathy;
t_attrib social_awareness;
};
#define NUM_CREAT_ATTRIBS 17
/**
* \ingroup grp_materials
@ -804,34 +329,6 @@ namespace DFHack
~Materials();
bool Finish();
enum base_material
{
INORGANIC,
AMBER,
CORAL,
GLASS_GREEN,
GLASS_CLEAR,
GLASS_CRYSTAL,
WATER,
COAL,
POTASH,
ASH,
PEARLASH,
LYE,
MUD,
VOMIT,
SALT,
FILTH_B,
FILTH_Y,
UNKNOWN_SUBSTANCE,
GRIME
};
std::vector<df_inorganic_type*>* df_inorganic;
std::vector<df_plant_type*>* df_organic;
std::vector<df_plant_type*>* df_trees;
std::vector<df_plant_type*>* df_plants;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;

@ -44,10 +44,9 @@ using namespace std;
#include "df/world.h"
#include "df/ui.h"
#include "df/item.h"
#include "df/inorganic_raw.h"
#include "df/plant_raw.h"
#include "df/plant_raw_flags.h"
#include "df/creature_raw.h"
#include "df/caste_raw.h"
#include "df/body_part_raw.h"
#include "df/historical_figure.h"
#include "df/job_item.h"
@ -55,9 +54,15 @@ using namespace std;
#include "df/dfhack_material_category.h"
#include "df/matter_state.h"
#include "df/material_vec_ref.h"
#include "df/builtin_mats.h"
#include "df/descriptor_color.h"
#include "df/descriptor_pattern.h"
#include "df/descriptor_shape.h"
using namespace DFHack;
using namespace df::enums;
using df::global::world;
bool MaterialInfo::decode(df::item *item)
{
@ -514,16 +519,8 @@ Materials::Materials()
Core & c = Core::getInstance();
d = new Private;
d->owner = c.p;
df_organic = 0;
df_trees = 0;
df_plants = 0;
df_inorganic = 0;
OffsetGroup *OG_Materials = d->OG_Materials = c.vinfo->getGroup("Materials");
{
OG_Materials->getSafeAddress("inorganics",(void * &)df_inorganic);
OG_Materials->getSafeAddress("organics_all",(void * &)df_organic);
OG_Materials->getSafeAddress("organics_plants",(void * &)df_plants);
OG_Materials->getSafeAddress("organics_trees",(void * &)df_trees);
d->vector_races = OG_Materials->getAddress("creature_type_vector");
}
}
@ -563,47 +560,29 @@ bool t_matglossInorganic::isGem()
return is_gem;
}
// good for now
inline bool ReadNamesOnly(Process* p, void * address, vector<t_matgloss> & names)
{
vector <string *> * p_names = (vector <string *> *) address;
uint32_t size = p_names->size();
names.clear();
names.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = *p_names->at(i);
names.push_back(mat);
}
return true;
}
bool Materials::CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic)
{
Process * p = d->owner;
if(!df_inorganic)
return false;
uint32_t size = df_inorganic->size();
uint32_t size = world->raws.inorganics.size();
inorganic.clear();
inorganic.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
df_inorganic_type * orig = df_inorganic->at(i);
df::inorganic_raw *orig = world->raws.inorganics[i];
t_matglossInorganic mat;
mat.id = orig->ID;
mat.name = orig->mat.STONE_NAME;
mat.ore_types = orig->METAL_ORE_matID;
mat.ore_chances = orig->METAL_ORE_prob;
mat.strand_types = orig->THREAD_METAL_matID;
mat.strand_chances = orig->THREAD_METAL_prob;
mat.value = orig->mat.MATERIAL_VALUE;
mat.wall_tile = orig->mat.TILE;
mat.boulder_tile = orig->mat.ITEM_SYMBOL;
mat.bright = orig->mat.BASIC_COLOR_bright;
mat.fore = orig->mat.BASIC_COLOR_foreground;
mat.is_gem = orig->mat.mat_flags.is_set(MATERIAL_IS_GEM);
mat.id = orig->id;
mat.name = orig->material.stone_name;
mat.ore_types = orig->metal_ore.mat_index;
mat.ore_chances = orig->metal_ore.probability;
mat.strand_types = orig->thread_metal.mat_index;
mat.strand_chances = orig->thread_metal.probability;
mat.value = orig->material.material_value;
mat.wall_tile = orig->material.tile;
mat.boulder_tile = orig->material.item_symbol;
mat.fore = orig->material.basic_color[0];
mat.bright = orig->material.basic_color[1];
mat.is_gem = orig->material.flags.is_set(material_flags::IS_GEM);
inorganic.push_back(mat);
}
return true;
@ -611,58 +590,77 @@ bool Materials::CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorg
bool Materials::CopyOrganicMaterials (std::vector<t_matgloss> & organic)
{
if(df_organic)
return ReadNamesOnly(d->owner, (void *) df_organic, organic );
else return false;
uint32_t size = world->raws.plants.all.size();
organic.clear();
organic.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = world->raws.plants.all[i]->id;
organic.push_back(mat);
}
return true;
}
bool Materials::CopyWoodMaterials (std::vector<t_matgloss> & tree)
{
if(df_trees)
return ReadNamesOnly(d->owner, (void *) df_trees, tree );
else return false;
uint32_t size = world->raws.plants.trees.size();
tree.clear();
tree.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = world->raws.plants.trees[i]->id;
tree.push_back(mat);
}
return true;
}
bool Materials::CopyPlantMaterials (std::vector<t_matgloss> & plant)
{
if(df_plants)
return ReadNamesOnly(d->owner, (void *) df_plants, plant );
else return false;
uint32_t size = world->raws.plants.bushes.size();
plant.clear();
plant.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = world->raws.plants.bushes[i]->id;
plant.push_back(mat);
}
return true;
}
bool Materials::ReadCreatureTypes (void)
{
return ReadNamesOnly(d->owner, d->vector_races, race );
uint32_t size = world->raws.creatures.all.size();
race.clear();
race.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = world->raws.creatures.all[i]->creature_id;
race.push_back(mat);
}
return true;
}
bool Materials::ReadOthers(void)
{
Process * p = d->owner;
char * matBase = d->OG_Materials->getAddress ("other");
uint32_t i = 0;
std::string * ptr;
uint32_t size = df::enums::builtin_mats::_last_item_of_builtin_mats + 1;
other.clear();
while(1)
other.reserve(size);
for (uint32_t i = 0; i < size;i++)
{
t_matglossOther mat;
ptr = (std::string *) p->readPtr(matBase + i*4);
if(ptr==0)
break;
mat.id = *ptr;
mat.id = world->raws.mat_table.builtin[i]->id;
other.push_back(mat);
i++;
}
return true;
}
bool Materials::ReadDescriptorColors (void)
{
Process * p = d->owner;
OffsetGroup * OG_Descriptors = p->getDescriptor()->getGroup("Materials")->getGroup("descriptors");
vector <char *> & p_colors = *(vector<char*> *) OG_Descriptors->getAddress ("colors_vector");
uint32_t size = p_colors.size();
uint32_t size = world->raws.language.colors.size();
color.clear();
if(size == 0)
@ -670,100 +668,64 @@ bool Materials::ReadDescriptorColors (void)
color.reserve(size);
for (uint32_t i = 0; i < size;i++)
{
df::descriptor_color *c = world->raws.language.colors[i];
t_descriptor_color col;
col.id = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("rawname") );
col.name = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("name") );
col.red = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_r") );
col.green = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_v") );
col.blue = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_b") );
col.id = c->id;
col.name = c->name;
col.red = c->red;
col.green = c->green;
col.blue = c->blue;
color.push_back(col);
}
return ReadNamesOnly(d->owner, OG_Descriptors->getAddress ("all_colors_vector"), alldesc );
size = world->raws.language.patterns.size();
alldesc.clear();
alldesc.reserve(size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
mat.id = world->raws.language.patterns[i]->id;
alldesc.push_back(mat);
}
return true;
}
bool Materials::ReadCreatureTypesEx (void)
{
Process *p = d->owner;
VersionInfo *mem = p->getDescriptor();
OffsetGroup * OG_string = mem->getGroup("string");
uint32_t sizeof_string = OG_string->getHexValue ("sizeof");
OffsetGroup * OG_Mats = mem->getGroup("Materials");
vector <char *> & p_races = *(vector<char*> *) OG_Mats->getAddress ("creature_type_vector");
OffsetGroup * OG_Creature = OG_Mats->getGroup("creature");
uint32_t castes_vector_offset = OG_Creature->getOffset ("caste_vector");
uint32_t extract_vector_offset = OG_Creature->getOffset ("extract_vector");
uint32_t tile_offset = OG_Creature->getOffset ("tile");
uint32_t tile_color_offset = OG_Creature->getOffset ("tile_color");
bool have_advanced = false;
uint32_t caste_colormod_offset;
uint32_t caste_attributes_offset;
uint32_t caste_bodypart_offset;
uint32_t bodypart_id_offset;
uint32_t bodypart_category_offset;
uint32_t color_modifier_part_offset;
uint32_t color_modifier_startdate_offset;
uint32_t color_modifier_enddate_offset;
try
{
OffsetGroup * OG_Caste = OG_Creature->getGroup("caste");
caste_colormod_offset = OG_Caste->getOffset ("color_modifiers");
caste_attributes_offset = OG_Caste->getOffset ("attributes");
caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector");
OffsetGroup * OG_CasteBodyparts = OG_Creature->getGroup("caste_bodyparts");
bodypart_id_offset = OG_CasteBodyparts->getOffset ("id");
bodypart_category_offset = OG_CasteBodyparts->getOffset ("category");
OffsetGroup * OG_CasteColorMods = OG_Creature->getGroup("caste_color_mods");
color_modifier_part_offset = OG_CasteColorMods->getOffset ("part");
color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate");
color_modifier_enddate_offset = OG_CasteColorMods->getOffset ("enddate");
have_advanced = true;
}
catch (Error::All &){};
uint32_t size = p_races.size();
uint32_t sizecas = 0;
uint32_t sizecolormod;
uint32_t sizecolorlist;
uint32_t sizebp;
uint32_t size = world->raws.creatures.all.size();
raceEx.clear();
raceEx.reserve (size);
for (uint32_t i = 0; i < size; i++)
{
df::creature_raw *cr = world->raws.creatures.all[i];
t_creaturetype mat;
mat.id = p->readSTLString (p_races[i]);
mat.tile_character = p->readByte( p_races[i] + tile_offset );
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 );
vector <char *> & p_castes = *(vector<char*> *) (p_races[i] + castes_vector_offset);
sizecas = p_castes.size();
mat.id = cr->creature_id;
mat.tile_character = cr->creature_tile;
mat.tilecolor.fore = cr->color[0];
mat.tilecolor.back = cr->color[1];
mat.tilecolor.bright = cr->color[2];
uint32_t sizecas = cr->caste.size();
for (uint32_t j = 0; j < sizecas;j++)
{
df::caste_raw *ca = cr->caste[j];
/* caste name */
t_creaturecaste caste;
char * caste_start = p_castes[j];
caste.id = p->readSTLString (caste_start);
caste.singular = p->readSTLString (caste_start + sizeof_string);
caste.plural = p->readSTLString (caste_start + 2 * sizeof_string);
caste.adjective = p->readSTLString (caste_start + 3 * sizeof_string);
//cout << "Caste " << caste.rawname << " " << caste.singular << ": 0x" << hex << caste_start << endl;
if(have_advanced)
{
/* color mod reading */
caste.id = ca->caste_id;
caste.singular = ca->caste_name[0];
caste.plural = ca->caste_name[1];
caste.adjective = ca->caste_name[2];
/*
// color mod reading
// Caste + offset > color mod vector
vector <char *> & p_colormod = *(vector<char*> *) (caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size();
vector <char *> & p_colormod = *(vector<char*> *) (world->raws.creatures.all[i]->caste + caste_colormod_offset);
uint32_t sizecolormod = p_colormod.size();
caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++)
{
// color mod [0] -> color list
vector <uint32_t> & p_colorlist = *(vector<uint32_t> *) (p_colormod[k]);
sizecolorlist = p_colorlist.size();
uint32_t sizecolorlist = p_colorlist.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++)
caste.ColorModifier[k].colorlist[l] = p_colorlist[l];
@ -772,30 +734,68 @@ bool Materials::ReadCreatureTypesEx (void)
caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset );
caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset );
}
/* body parts */
vector <char *> & p_bodypart = *(vector<char*> *) (caste_start + caste_bodypart_offset);
*/
// body parts
caste.bodypart.empty();
sizebp = p_bodypart.size();
uint32_t sizebp = ca->body_parts.size();
for (uint32_t k = 0; k < sizebp; k++)
{
df::body_part_raw *bp = ca->body_parts[k];
t_bodypart part;
part.id = p->readSTLString (p_bodypart[k] + bodypart_id_offset);
part.category = p->readSTLString (p_bodypart[k] + bodypart_category_offset);
part.id = bp->part_code;
part.category = bp->part_name;
caste.bodypart.push_back(part);
}
p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * NUM_CREAT_ATTRIBS, (uint8_t *)&caste.strength);
}
else
t_attrib *phys[] = {
&caste.strength,
&caste.agility,
&caste.toughness,
&caste.endurance,
&caste.recuperation,
&caste.disease_resistance
};
for (uint32_t k = 0; k < 6; k++)
{
phys[k]->level = ca->attributes.phys_att_range[k][0];
phys[k]->field_4 = ca->attributes.phys_att_range[k][1];
phys[k]->field_8 = ca->attributes.phys_att_range[k][2];
phys[k]->field_C = ca->attributes.phys_att_range[k][3];
phys[k]->leveldiff = ca->attributes.phys_att_range[k][4];
phys[k]->field_14 = ca->attributes.phys_att_range[k][5];
phys[k]->field_18 = ca->attributes.phys_att_range[k][6];
}
t_attrib *ment[] = {
&caste.analytical_ability,
&caste.focus,
&caste.willpower,
&caste.creativity,
&caste.intuition,
&caste.patience,
&caste.memory,
&caste.linguistic_ability,
&caste.spatial_sense,
&caste.musicality,
&caste.kinesthetic_sense,
&caste.empathy,
&caste.social_awareness
};
for (uint32_t k = 0; k < 13; k++)
{
memset(&caste.strength, 0, sizeof(t_attrib) * NUM_CREAT_ATTRIBS);
ment[k]->level = ca->attributes.ment_att_range[k][0];
ment[k]->field_4 = ca->attributes.ment_att_range[k][1];
ment[k]->field_8 = ca->attributes.ment_att_range[k][2];
ment[k]->field_C = ca->attributes.ment_att_range[k][3];
ment[k]->leveldiff = ca->attributes.ment_att_range[k][4];
ment[k]->field_14 = ca->attributes.ment_att_range[k][5];
ment[k]->field_18 = ca->attributes.ment_att_range[k][6];
}
mat.castes.push_back(caste);
}
vector <void *> & p_extract = *(vector<void*> *) (p_races[i] + extract_vector_offset);
for(uint32_t j = 0; j < p_extract.size(); j++)
for (uint32_t j = 0; j < world->raws.creatures.all[i]->material.size(); j++)
{
t_creatureextract extract;
extract.id = p->readSTLString( p_extract[j] );
extract.id = world->raws.creatures.all[i]->material[j]->id;
mat.extract.push_back(extract);
}
raceEx.push_back(mat);
@ -813,119 +813,33 @@ bool Materials::ReadAllMaterials(void)
return ok;
}
/// miserable pile of magic. The material system is insane.
// FIXME: this contains potential errors when the indexes are -1 and compared to unsigned numbers!
std::string Materials::getDescription(const t_material & mat)
{
std::string out;
int32_t typeC;
if ( (mat.material<419) || (mat.material>618) )
{
if ( (mat.material<19) || (mat.material>218) )
{
if (mat.material)
if (mat.material>0x292)
return "?";
else
{
if (mat.material>=this->other.size())
{
if (mat.itemType == 0) {
if(mat.material<0)
return "any inorganic";
else
return this->df_inorganic->at(mat.material)->ID;
}
if(mat.material<0)
return "any";
if(mat.material>=this->raceEx.size())
return "stuff";
return this->raceEx[mat.material].id;
}
else
{
if (mat.index==-1)
return std::string(this->other[mat.material].id);
else
return std::string(this->other[mat.material].id) + " derivate";
}
}
else
if(mat.index<0)
return "any inorganic";
else if (mat.index < df_inorganic->size())
return this->df_inorganic->at(mat.index)->ID;
MaterialInfo mi(mat.material, mat.index);
if (mi.creature)
return mi.creature->creature_id + " " + mi.material->id;
else if (mi.plant)
return mi.plant->id + " " + mi.material->id;
else
return "INDEX OUT OF BOUNDS!";
}
else
{
if (mat.index>=this->raceEx.size())
return "unknown race";
typeC = mat.material;
typeC -=19;
if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size()))
{
return string(this->raceEx[mat.index].id).append(" extract");
}
return std::string(this->raceEx[mat.index].id).append(" ").append(this->raceEx[mat.index].extract[typeC].id);
}
}
else
{
return this->df_organic->at(mat.material)->ID;
}
return out;
return mi.material->id;
}
// type of material only so we know which vector to retrieve
// FIXME: this also contains potential errors when the indexes are -1 and compared to unsigned numbers!
// This is completely worthless now
std::string Materials::getType(const t_material & mat)
{
if((mat.material<419) || (mat.material>618))
{
if((mat.material<19) || (mat.material>218))
{
if(mat.material)
MaterialInfo mi(mat.material, mat.index);
switch (mi.mode)
{
if(mat.material>0x292)
{
return "unknown";
}
else
{
if(mat.material>=this->other.size())
{
if(mat.material<0)
return "any";
if(mat.material>=this->raceEx.size())
return "unknown";
return "racex";
}
else
{
if (mat.index==-1)
return "other";
else
return "other derivate";
}
}
}
else
case MaterialInfo::Builtin:
return "builtin";
case MaterialInfo::Inorganic:
return "inorganic";
}
else
{
if (mat.index>=this->raceEx.size())
case MaterialInfo::Creature:
return "creature";
case MaterialInfo::Plant:
return "plant";
default:
return "unknown";
return "racex extract";
}
}
else
{
return "organic";
}
}

@ -23,6 +23,7 @@ using namespace std;
#include "df/world.h"
using namespace DFHack;
using df::global::world;
struct matdata
{
@ -95,18 +96,16 @@ static void printMatdata(DFHack::Console & con, const matdata &data)
con <<" Z:" << std::setw(4) << data.lower_z << std::endl;
}
static int getValue(const df_inorganic_type &info)
static int getValue(const df::inorganic_raw &info)
{
return info.mat.MATERIAL_VALUE;
return info.material.material_value;
}
static int getValue(const df_plant_type &info)
static int getValue(const df::plant_raw &info)
{
return info.value;
}
// printMats() accepts a vector of pointers to t_matgloss so that it can
// deal t_matgloss and all subclasses.
template <typename T>
void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, bool show_value)
{
@ -128,7 +127,8 @@ void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, b
continue;
}
T* mat = materials[it->first];
con << std::setw(25) << mat->ID << " : ";
// Somewhat of a hack, but it works because df::inorganic_raw and df::plant_raw both have a field named "id"
con << std::setw(25) << mat->id << " : ";
if (show_value)
con << std::setw(3) << getValue(*mat) << " : ";
printMatdata(con, it->second);
@ -147,9 +147,9 @@ void printVeins(DFHack::Console & con, MatMap &mat_map,
for (MatMap::const_iterator it = mat_map.begin(); it != mat_map.end(); ++it)
{
DFHack::df_inorganic_type *gloss = mats->df_inorganic->at(it->first);
df::inorganic_raw *gloss = world->raws.inorganics[it->first];
if (gloss->mat.isGem())
if (gloss->material.isGem())
gems[it->first] = it->second;
else if (gloss->isOre())
ores[it->first] = it->second;
@ -158,13 +158,13 @@ void printVeins(DFHack::Console & con, MatMap &mat_map,
}
con << "Ores:" << std::endl;
printMats(con, ores, *mats->df_inorganic, show_value);
printMats(con, ores, world->raws.inorganics, show_value);
con << "Gems:" << std::endl;
printMats(con, gems, *mats->df_inorganic, show_value);
printMats(con, gems, world->raws.inorganics, show_value);
con << "Other vein stone:" << std::endl;
printMats(con, rest, *mats->df_inorganic, show_value);
printMats(con, rest, world->raws.inorganics, show_value);
}
DFhackCExport command_result prospector (Core * c, vector <string> & parameters);
@ -234,17 +234,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
MapExtras::MapCache map;
DFHack::Materials *mats = c->getMaterials();
if (!mats->df_inorganic)
{
con.printerr("Unable to read inorganic material definitons!\n");
c->Resume();
return CR_FAILURE;
}
if (showPlants && !mats->df_organic)
{
con.printerr("Unable to read organic material definitons; plants won't be listed!\n");
showPlants = false;
}
DFHack::t_feature blockFeatureGlobal;
DFHack::t_feature blockFeatureLocal;
@ -459,16 +448,16 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
}
con << std::endl << "Layer materials:" << std::endl;
printMats(con, layerMats, *mats->df_inorganic, showValue);
printMats(con, layerMats, world->raws.inorganics, showValue);
printVeins(con, veinMats, mats, showValue);
if (showPlants)
{
con << "Shrubs:" << std::endl;
printMats(con, plantMats, *mats->df_organic, showValue);
printMats(con, plantMats, world->raws.plants.all, showValue);
con << "Wood in trees:" << std::endl;
printMats(con, treeMats, *mats->df_organic, showValue);
printMats(con, treeMats, world->raws.plants.all, showValue);
}
if (hasAquifer)