2010-04-02 19:52:46 -06:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-06-16 15:53:39 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <cstring>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-06-12 15:17:40 -06:00
|
|
|
#include "dfhack/Types.h"
|
2010-05-26 00:42:09 -06:00
|
|
|
#include "dfhack/modules/Materials.h"
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2011-06-12 15:17:40 -06:00
|
|
|
#include "dfhack/Process.h"
|
|
|
|
#include "dfhack/Vector.h"
|
|
|
|
#include <dfhack/Error.h>
|
2011-03-18 01:53:59 -06:00
|
|
|
#include "ModuleFactory.h"
|
2011-06-17 07:02:43 -06:00
|
|
|
#include <dfhack/Core.h>
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Module* DFHack::createMaterials()
|
2011-03-18 01:53:59 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
return new Materials();
|
2011-03-18 01:53:59 -06:00
|
|
|
}
|
|
|
|
|
2010-04-18 13:30:02 -06:00
|
|
|
class Materials::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Process * owner;
|
2010-08-28 07:43:53 -06:00
|
|
|
OffsetGroup * OG_Materials;
|
2010-08-29 16:08:17 -06:00
|
|
|
uint32_t vector_races;
|
|
|
|
uint32_t vector_other;
|
2010-04-18 13:30:02 -06:00
|
|
|
};
|
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Materials::Materials()
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
Core & c = Core::getInstance();
|
2010-04-18 16:32:50 -06:00
|
|
|
d = new Private;
|
2011-06-17 07:02:43 -06:00
|
|
|
d->owner = c.p;
|
2011-10-27 20:40:35 -06:00
|
|
|
df_organic = 0;
|
|
|
|
df_trees = 0;
|
|
|
|
df_plants = 0;
|
|
|
|
df_inorganic = 0;
|
2011-06-17 07:02:43 -06:00
|
|
|
OffsetGroup *OG_Materials = d->OG_Materials = c.vinfo->getGroup("Materials");
|
2010-08-29 16:08:17 -06:00
|
|
|
{
|
2011-10-27 20:40:35 -06:00
|
|
|
OG_Materials->getSafeAddress("inorganics",(uint32_t &)df_inorganic);
|
|
|
|
OG_Materials->getSafeAddress("organics_all",(uint32_t &)df_organic);
|
|
|
|
OG_Materials->getSafeAddress("organics_plants",(uint32_t &)df_plants);
|
|
|
|
OG_Materials->getSafeAddress("organics_trees",(uint32_t &)df_trees);
|
2010-08-29 16:08:17 -06:00
|
|
|
d->vector_races = OG_Materials->getAddress("creature_type_vector");
|
|
|
|
}
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2010-04-18 16:32:50 -06:00
|
|
|
Materials::~Materials()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
2010-06-24 23:11:26 -06:00
|
|
|
|
|
|
|
bool Materials::Finish()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-20 07:18:50 -06:00
|
|
|
t_matgloss::t_matgloss()
|
|
|
|
{
|
|
|
|
fore = 0;
|
|
|
|
back = 0;
|
|
|
|
bright = 0;
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
wall_tile = 0;
|
|
|
|
boulder_tile = 0;
|
|
|
|
}
|
2011-07-21 19:00:56 -06:00
|
|
|
|
2011-07-20 07:18:50 -06:00
|
|
|
bool t_matglossInorganic::isOre()
|
|
|
|
{
|
2011-07-21 19:00:56 -06:00
|
|
|
if (!ore_chances.empty())
|
|
|
|
return true;
|
|
|
|
if (!strand_chances.empty())
|
|
|
|
return true;
|
2011-07-20 07:18:50 -06:00
|
|
|
return false;
|
|
|
|
}
|
2011-09-23 22:48:06 -06:00
|
|
|
|
2011-07-20 07:18:50 -06:00
|
|
|
bool t_matglossInorganic::isGem()
|
|
|
|
{
|
2011-09-23 22:48:06 -06:00
|
|
|
return is_gem;
|
2011-07-20 07:18:50 -06:00
|
|
|
}
|
|
|
|
|
2010-04-04 02:10:00 -06:00
|
|
|
// good for now
|
|
|
|
inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & names)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_matgloss (address);
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t size = p_matgloss.size();
|
2010-04-04 02:10:00 -06:00
|
|
|
names.clear();
|
|
|
|
names.reserve (size);
|
|
|
|
for (uint32_t i = 0; i < size;i++)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-04 02:10:00 -06:00
|
|
|
t_matgloss mat;
|
2011-07-21 14:37:02 -06:00
|
|
|
mat.id = *(std::string *)p_matgloss[i];
|
2010-04-04 02:10:00 -06:00
|
|
|
names.push_back(mat);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadInorganicMaterials (void)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-28 15:48:50 -06:00
|
|
|
Process * p = d->owner;
|
2011-10-27 20:40:35 -06:00
|
|
|
if(!df_inorganic)
|
|
|
|
return false;
|
2011-07-21 14:37:02 -06:00
|
|
|
uint32_t size = df_inorganic->size();
|
2010-04-28 15:48:50 -06:00
|
|
|
inorganic.clear();
|
|
|
|
inorganic.reserve (size);
|
|
|
|
for (uint32_t i = 0; i < size;i++)
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
df_inorganic_material * orig = df_inorganic->at(i);
|
2011-07-20 07:18:50 -06:00
|
|
|
t_matglossInorganic mat;
|
2011-07-21 14:37:02 -06:00
|
|
|
mat.id = orig->Inorganic_ID;
|
|
|
|
mat.name = orig->STONE_NAME;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2011-07-21 14:37:02 -06:00
|
|
|
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->MATERIAL_VALUE;
|
|
|
|
mat.wall_tile = orig->TILE;
|
|
|
|
mat.boulder_tile = orig->ITEM_SYMBOL;
|
|
|
|
mat.bright = orig->BASIC_COLOR_bright;
|
|
|
|
mat.fore = orig->BASIC_COLOR_foreground;
|
2011-09-23 22:48:06 -06:00
|
|
|
mat.is_gem = orig->mat_flags.is_set(MATERIAL_IS_GEM);
|
2010-04-28 15:48:50 -06:00
|
|
|
inorganic.push_back(mat);
|
|
|
|
}
|
|
|
|
return true;
|
2010-04-04 02:10:00 -06:00
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadOrganicMaterials (void)
|
2010-04-04 02:10:00 -06:00
|
|
|
{
|
2011-10-27 20:40:35 -06:00
|
|
|
if(df_organic)
|
|
|
|
return ReadNamesOnly(d->owner, (uint32_t) df_organic, organic );
|
|
|
|
else return false;
|
2010-04-04 02:10:00 -06:00
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadWoodMaterials (void)
|
2010-04-04 02:10:00 -06:00
|
|
|
{
|
2011-10-27 20:40:35 -06:00
|
|
|
if(df_trees)
|
|
|
|
return ReadNamesOnly(d->owner, (uint32_t) df_trees, tree );
|
|
|
|
else return false;
|
2010-04-04 02:10:00 -06:00
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadPlantMaterials (void)
|
2010-04-04 02:10:00 -06:00
|
|
|
{
|
2011-10-27 20:40:35 -06:00
|
|
|
if(df_plants)
|
|
|
|
return ReadNamesOnly(d->owner, (uint32_t) df_plants, plant );
|
|
|
|
else return false;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-04-18 13:30:02 -06:00
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadCreatureTypes (void)
|
2010-04-04 04:29:56 -06:00
|
|
|
{
|
2010-08-29 16:08:17 -06:00
|
|
|
return ReadNamesOnly(d->owner, d->vector_races, race );
|
2010-04-04 04:29:56 -06:00
|
|
|
}
|
2010-04-14 14:12:02 -06:00
|
|
|
|
2010-04-30 09:42:31 -06:00
|
|
|
bool Materials::ReadOthers(void)
|
|
|
|
{
|
2010-08-12 13:38:15 -06:00
|
|
|
Process * p = d->owner;
|
2010-08-28 07:43:53 -06:00
|
|
|
uint32_t matBase = d->OG_Materials->getAddress ("other");
|
2010-08-12 13:38:15 -06:00
|
|
|
uint32_t i = 0;
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string * ptr;
|
2010-04-30 09:42:31 -06:00
|
|
|
|
2010-08-12 13:38:15 -06:00
|
|
|
other.clear();
|
2010-04-30 09:42:31 -06:00
|
|
|
|
2010-08-12 13:38:15 -06:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
t_matglossOther mat;
|
2011-07-21 14:37:02 -06:00
|
|
|
ptr = (std::string *) p->readDWord(matBase + i*4);
|
2010-08-12 13:38:15 -06:00
|
|
|
if(ptr==0)
|
|
|
|
break;
|
2011-07-21 14:37:02 -06:00
|
|
|
mat.id = *ptr;
|
2010-08-12 13:38:15 -06:00
|
|
|
other.push_back(mat);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return true;
|
2010-04-30 09:42:31 -06:00
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadDescriptorColors (void)
|
2010-04-20 10:25:52 -06:00
|
|
|
{
|
2010-05-25 15:52:04 -06:00
|
|
|
Process * p = d->owner;
|
2010-08-29 16:08:17 -06:00
|
|
|
OffsetGroup * OG_Descriptors = p->getDescriptor()->getGroup("Materials")->getGroup("descriptors");
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_colors (OG_Descriptors->getAddress ("colors_vector"));
|
2010-05-25 15:52:04 -06:00
|
|
|
uint32_t size = p_colors.size();
|
|
|
|
|
|
|
|
color.clear();
|
|
|
|
if(size == 0)
|
|
|
|
return false;
|
|
|
|
color.reserve(size);
|
|
|
|
for (uint32_t i = 0; i < size;i++)
|
|
|
|
{
|
|
|
|
t_descriptor_color col;
|
2011-07-21 14:37:02 -06:00
|
|
|
col.id = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("rawname") );
|
|
|
|
col.name = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("name") );
|
2011-05-06 19:48:41 -06:00
|
|
|
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") );
|
2010-05-25 15:52:04 -06:00
|
|
|
color.push_back(col);
|
|
|
|
}
|
2010-08-29 16:08:17 -06:00
|
|
|
return ReadNamesOnly(d->owner, OG_Descriptors->getAddress ("all_colors_vector"), alldesc );
|
2010-05-25 15:52:04 -06:00
|
|
|
return true;
|
2010-04-20 10:25:52 -06:00
|
|
|
}
|
|
|
|
|
2010-04-28 10:09:32 -06:00
|
|
|
bool Materials::ReadCreatureTypesEx (void)
|
2010-04-14 14:12:02 -06:00
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *p = d->owner;
|
2010-08-29 16:08:17 -06:00
|
|
|
VersionInfo *mem = p->getDescriptor();
|
|
|
|
OffsetGroup * OG_string = mem->getGroup("string");
|
|
|
|
uint32_t sizeof_string = OG_string->getHexValue ("sizeof");
|
|
|
|
|
|
|
|
OffsetGroup * OG_Mats = mem->getGroup("Materials");
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_races (OG_Mats->getAddress ("creature_type_vector"));
|
2010-08-29 16:08:17 -06:00
|
|
|
|
|
|
|
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");
|
2010-08-30 22:52:03 -06:00
|
|
|
uint32_t tile_offset = OG_Creature->getOffset ("tile");
|
|
|
|
uint32_t tile_color_offset = OG_Creature->getOffset ("tile_color");
|
2010-09-02 19:01:37 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2010-08-29 16:08:17 -06:00
|
|
|
OffsetGroup * OG_Caste = OG_Creature->getGroup("caste");
|
2010-09-02 19:01:37 -06:00
|
|
|
caste_colormod_offset = OG_Caste->getOffset ("color_modifiers");
|
|
|
|
caste_attributes_offset = OG_Caste->getOffset ("attributes");
|
|
|
|
caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector");
|
2010-08-29 16:08:17 -06:00
|
|
|
OffsetGroup * OG_CasteBodyparts = OG_Creature->getGroup("caste_bodyparts");
|
2010-09-02 19:01:37 -06:00
|
|
|
bodypart_id_offset = OG_CasteBodyparts->getOffset ("id");
|
|
|
|
bodypart_category_offset = OG_CasteBodyparts->getOffset ("category");
|
2010-08-29 16:08:17 -06:00
|
|
|
OffsetGroup * OG_CasteColorMods = OG_Creature->getGroup("caste_color_mods");
|
2010-09-02 19:01:37 -06:00
|
|
|
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 &){};
|
2010-08-29 16:08:17 -06:00
|
|
|
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t size = p_races.size();
|
2010-04-14 14:12:02 -06:00
|
|
|
uint32_t sizecas = 0;
|
2010-05-05 03:17:40 -06:00
|
|
|
uint32_t sizecolormod;
|
|
|
|
uint32_t sizecolorlist;
|
2010-05-05 05:48:01 -06:00
|
|
|
uint32_t sizebp;
|
2010-04-28 10:09:32 -06:00
|
|
|
raceEx.clear();
|
|
|
|
raceEx.reserve (size);
|
2010-04-14 14:12:02 -06:00
|
|
|
for (uint32_t i = 0; i < size;i++)
|
|
|
|
{
|
|
|
|
t_creaturetype mat;
|
2011-07-21 14:37:02 -06:00
|
|
|
mat.id = p->readSTLString (p_races[i]);
|
2010-06-18 19:47:09 -06:00
|
|
|
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 );
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_castes(p_races[i] + castes_vector_offset);
|
2010-04-18 06:56:09 -06:00
|
|
|
sizecas = p_castes.size();
|
2010-04-14 14:12:02 -06:00
|
|
|
for (uint32_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
2010-05-05 05:48:01 -06:00
|
|
|
/* caste name */
|
2010-04-14 14:12:02 -06:00
|
|
|
t_creaturecaste caste;
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t caste_start = p_castes[j];
|
2011-07-21 14:37:02 -06:00
|
|
|
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);
|
2010-10-06 17:23:35 -06:00
|
|
|
//cout << "Caste " << caste.rawname << " " << caste.singular << ": 0x" << hex << caste_start << endl;
|
2010-09-02 19:01:37 -06:00
|
|
|
if(have_advanced)
|
2010-05-05 05:48:01 -06:00
|
|
|
{
|
2010-09-02 19:01:37 -06:00
|
|
|
/* color mod reading */
|
2010-09-18 22:17:48 -06:00
|
|
|
// Caste + offset > color mod vector
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_colormod(caste_start + caste_colormod_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
sizecolormod = p_colormod.size();
|
|
|
|
caste.ColorModifier.resize(sizecolormod);
|
|
|
|
for(uint32_t k = 0; k < sizecolormod;k++)
|
|
|
|
{
|
2010-09-18 22:17:48 -06:00
|
|
|
// color mod [0] -> color list
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_colorlist(p_colormod[k]);
|
2010-09-02 19:01:37 -06:00
|
|
|
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];
|
2010-09-18 22:17:48 -06:00
|
|
|
// color mod [color_modifier_part_offset] = string part
|
2011-07-21 14:37:02 -06:00
|
|
|
caste.ColorModifier[k].part = p->readSTLString( p_colormod[k] + color_modifier_part_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
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 */
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_bodypart(caste_start + caste_bodypart_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
caste.bodypart.empty();
|
|
|
|
sizebp = p_bodypart.size();
|
|
|
|
for(uint32_t k = 0; k < sizebp; k++)
|
|
|
|
{
|
|
|
|
t_bodypart part;
|
2011-07-21 14:37:02 -06:00
|
|
|
part.id = p->readSTLString (p_bodypart[k] + bodypart_id_offset);
|
|
|
|
part.category = p->readSTLString (p_bodypart[k] + bodypart_category_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
caste.bodypart.push_back(part);
|
|
|
|
}
|
2011-03-24 19:31:27 -06:00
|
|
|
p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * NUM_CREAT_ATTRIBS, (uint8_t *)&caste.strength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&caste.strength, 0, sizeof(t_attrib) * NUM_CREAT_ATTRIBS);
|
2010-05-05 05:48:01 -06:00
|
|
|
}
|
2010-04-14 14:12:02 -06:00
|
|
|
mat.castes.push_back(caste);
|
|
|
|
}
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> p_extract(p_races[i] + extract_vector_offset);
|
2010-05-25 15:52:04 -06:00
|
|
|
for(uint32_t j = 0; j < p_extract.size(); j++)
|
|
|
|
{
|
|
|
|
t_creatureextract extract;
|
2011-07-21 14:37:02 -06:00
|
|
|
extract.id = p->readSTLString( p_extract[j] );
|
2010-05-25 15:52:04 -06:00
|
|
|
mat.extract.push_back(extract);
|
|
|
|
}
|
2010-04-28 10:09:32 -06:00
|
|
|
raceEx.push_back(mat);
|
2010-04-14 14:12:02 -06:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:41:31 -06:00
|
|
|
bool Materials::ReadAllMaterials(void)
|
2010-04-28 10:09:32 -06:00
|
|
|
{
|
2011-08-04 16:41:31 -06:00
|
|
|
bool ok = true;
|
|
|
|
ok &= this->ReadInorganicMaterials();
|
|
|
|
ok &= this->ReadOrganicMaterials();
|
|
|
|
ok &= this->ReadWoodMaterials();
|
|
|
|
ok &= this->ReadPlantMaterials();
|
|
|
|
ok &= this->ReadCreatureTypes();
|
|
|
|
ok &= this->ReadCreatureTypesEx();
|
|
|
|
ok &= this->ReadDescriptorColors();
|
|
|
|
ok &= this->ReadOthers();
|
|
|
|
return ok;
|
2010-04-28 10:09:32 -06:00
|
|
|
}
|
2010-04-28 10:24:27 -06:00
|
|
|
|
2011-04-14 07:16:12 -06:00
|
|
|
/// miserable pile of magic. The material system is insane.
|
2011-05-15 14:24:40 -06:00
|
|
|
// FIXME: this contains potential errors when the indexes are -1 and compared to unsigned numbers!
|
2011-04-12 05:59:07 -06:00
|
|
|
std::string Materials::getDescription(const t_material & mat)
|
2010-04-28 10:24:27 -06:00
|
|
|
{
|
2010-06-24 23:11:26 -06:00
|
|
|
std::string out;
|
|
|
|
int32_t typeC;
|
2011-10-26 14:18:13 -06:00
|
|
|
if ( (mat.material<419) || (mat.material>618) )
|
2010-05-02 04:50:51 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if ( (mat.material<19) || (mat.material>218) )
|
2010-05-02 04:50:51 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if (mat.material)
|
|
|
|
if (mat.material>0x292)
|
2010-05-02 04:50:51 -06:00
|
|
|
return "?";
|
|
|
|
else
|
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if (mat.material>=this->other.size())
|
2010-06-24 23:11:26 -06:00
|
|
|
{
|
2010-10-27 21:30:58 -06:00
|
|
|
if (mat.itemType == 0) {
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material<0)
|
2010-10-27 21:30:58 -06:00
|
|
|
return "any inorganic";
|
|
|
|
else
|
2011-10-26 14:18:13 -06:00
|
|
|
return this->inorganic[mat.material].id;
|
2010-10-27 21:30:58 -06:00
|
|
|
}
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material<0)
|
2010-06-24 23:11:26 -06:00
|
|
|
return "any";
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material>=this->raceEx.size())
|
2010-06-24 23:11:26 -06:00
|
|
|
return "stuff";
|
2011-10-26 14:18:13 -06:00
|
|
|
return this->raceEx[mat.material].id;
|
2010-06-24 23:11:26 -06:00
|
|
|
}
|
2010-05-02 04:50:51 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mat.index==-1)
|
2011-10-26 14:18:13 -06:00
|
|
|
return std::string(this->other[mat.material].id);
|
2010-05-02 04:50:51 -06:00
|
|
|
else
|
2011-10-26 14:18:13 -06:00
|
|
|
return std::string(this->other[mat.material].id) + " derivate";
|
2010-05-02 04:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-06-24 23:11:26 -06:00
|
|
|
if(mat.index<0)
|
|
|
|
return "any inorganic";
|
2011-10-24 20:48:06 -06:00
|
|
|
else if (mat.index < inorganic.size())
|
2010-06-24 23:11:26 -06:00
|
|
|
return this->inorganic[mat.index].id;
|
2011-10-24 20:48:06 -06:00
|
|
|
else
|
|
|
|
return "INDEX OUT OF BOUNDS!";
|
2010-05-02 04:50:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mat.index>=this->raceEx.size())
|
|
|
|
return "unknown race";
|
2011-10-26 14:18:13 -06:00
|
|
|
typeC = mat.material;
|
2010-06-24 23:11:26 -06:00
|
|
|
typeC -=19;
|
2010-05-02 04:50:51 -06:00
|
|
|
if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size()))
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
return string(this->raceEx[mat.index].id).append(" extract");
|
2010-05-02 04:50:51 -06:00
|
|
|
}
|
2011-07-21 14:37:02 -06:00
|
|
|
return std::string(this->raceEx[mat.index].id).append(" ").append(this->raceEx[mat.index].extract[typeC].id);
|
2010-05-02 04:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->organic[mat.index].id;
|
|
|
|
}
|
2010-06-24 23:11:26 -06:00
|
|
|
return out;
|
2010-04-28 10:24:27 -06:00
|
|
|
}
|
|
|
|
|
2010-07-15 05:57:45 -06:00
|
|
|
//type of material only so we know which vector to retrieve
|
2011-05-15 14:24:40 -06:00
|
|
|
// FIXME: this also contains potential errors when the indexes are -1 and compared to unsigned numbers!
|
2011-04-12 05:59:07 -06:00
|
|
|
std::string Materials::getType(const t_material & mat)
|
2010-07-15 05:57:45 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if((mat.material<419) || (mat.material>618))
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if((mat.material<19) || (mat.material>218))
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material)
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material>0x292)
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material>=this->other.size())
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material<0)
|
2011-04-11 14:13:06 -06:00
|
|
|
return "any";
|
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
if(mat.material>=this->raceEx.size())
|
2011-04-11 14:13:06 -06:00
|
|
|
return "unknown";
|
|
|
|
|
|
|
|
return "racex";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mat.index==-1)
|
|
|
|
return "other";
|
|
|
|
else
|
|
|
|
return "other derivate";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "inorganic";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mat.index>=this->raceEx.size())
|
|
|
|
return "unknown";
|
|
|
|
|
|
|
|
return "racex extract";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "organic";
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
}
|