2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2011-06-16 15:53:39 -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-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2010-04-04 16:48:19 -06:00
|
|
|
#ifndef CL_MOD_MATERIALS
|
|
|
|
#define CL_MOD_MATERIALS
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \defgroup grp_materials Materials module - used for reading raws mostly
|
|
|
|
* @ingroup grp_modules
|
2010-06-24 23:11:26 -06:00
|
|
|
*/
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "BitArray.h"
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/material.h"
|
2012-01-21 09:12:26 -07:00
|
|
|
#include "df/inorganic_raw.h"
|
|
|
|
#include "df/plant_raw.h"
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2011-07-20 07:18:50 -06:00
|
|
|
#include <vector>
|
2011-07-21 14:37:02 -06:00
|
|
|
#include <string>
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct item;
|
|
|
|
struct plant_raw;
|
|
|
|
struct creature_raw;
|
|
|
|
struct historical_figure;
|
2012-01-04 07:46:39 -07:00
|
|
|
struct material_vec_ref;
|
2012-01-05 11:04:05 -07:00
|
|
|
struct job_item;
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
union job_material_category;
|
2012-01-10 06:23:37 -07:00
|
|
|
union dfhack_material_category;
|
2012-01-05 11:04:05 -07:00
|
|
|
union job_item_flags1;
|
|
|
|
union job_item_flags2;
|
|
|
|
union job_item_flags3;
|
2012-01-03 08:25:55 -07:00
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
struct t_matpair {
|
|
|
|
int16_t mat_type;
|
|
|
|
int32_t mat_index;
|
|
|
|
|
|
|
|
t_matpair(int16_t type = -1, int32_t index = -1)
|
|
|
|
: mat_type(type), mat_index(index) {}
|
|
|
|
};
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
struct DFHACK_EXPORT MaterialInfo {
|
|
|
|
static const int NUM_BUILTIN = 19;
|
|
|
|
static const int GROUP_SIZE = 200;
|
|
|
|
static const int CREATURE_BASE = NUM_BUILTIN;
|
|
|
|
static const int FIGURE_BASE = NUM_BUILTIN + GROUP_SIZE;
|
|
|
|
static const int PLANT_BASE = NUM_BUILTIN + GROUP_SIZE*2;
|
|
|
|
static const int END_BASE = NUM_BUILTIN + GROUP_SIZE*3;
|
|
|
|
|
|
|
|
int16_t type;
|
|
|
|
int32_t index;
|
|
|
|
|
|
|
|
df::material *material;
|
|
|
|
|
|
|
|
enum Mode {
|
2012-01-24 04:36:30 -07:00
|
|
|
None,
|
2012-01-03 08:25:55 -07:00
|
|
|
Builtin,
|
|
|
|
Inorganic,
|
|
|
|
Creature,
|
|
|
|
Plant
|
|
|
|
};
|
|
|
|
Mode mode;
|
|
|
|
|
|
|
|
int16_t subtype;
|
|
|
|
df::inorganic_raw *inorganic;
|
|
|
|
df::creature_raw *creature;
|
|
|
|
df::plant_raw *plant;
|
|
|
|
|
|
|
|
df::historical_figure *figure;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MaterialInfo(int16_t type = -1, int32_t index = -1) { decode(type, index); }
|
2012-04-19 09:17:07 -06:00
|
|
|
MaterialInfo(const t_matpair &mp) { decode(mp.mat_type, mp.mat_index); }
|
2012-01-04 07:46:39 -07:00
|
|
|
template<class T> MaterialInfo(T *ptr) { decode(ptr); }
|
2012-01-03 08:25:55 -07:00
|
|
|
|
|
|
|
bool isValid() const { return material != NULL; }
|
|
|
|
|
2012-01-24 04:36:30 -07:00
|
|
|
bool isNone() const { return mode == None; }
|
|
|
|
bool isBuiltin() const { return mode == Builtin; }
|
|
|
|
bool isInorganic() const { return mode == Inorganic; }
|
|
|
|
bool isCreature() const { return mode == Creature; }
|
|
|
|
bool isPlant() const { return mode == Plant; }
|
|
|
|
|
|
|
|
bool isAnyInorganic() const { return type == 0; }
|
|
|
|
bool isInorganicWildcard() const { return isAnyInorganic() && isBuiltin(); }
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
bool decode(int16_t type, int32_t index = -1);
|
|
|
|
bool decode(df::item *item);
|
2012-01-04 07:46:39 -07:00
|
|
|
bool decode(const df::material_vec_ref &vr, int idx);
|
2012-04-19 09:17:07 -06:00
|
|
|
bool decode(const t_matpair &mp) { return decode(mp.mat_type, mp.mat_index); }
|
2012-01-04 07:46:39 -07:00
|
|
|
|
|
|
|
template<class T> bool decode(T *ptr) {
|
|
|
|
// Assume and exploit a certain naming convention
|
|
|
|
return ptr ? decode(ptr->mat_type, ptr->mat_index) : decode(-1);
|
|
|
|
}
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2012-01-08 09:02:12 -07:00
|
|
|
bool find(const std::string &token);
|
2012-04-06 09:56:19 -06:00
|
|
|
bool find(const std::vector<std::string> &tokens);
|
2012-01-08 09:02:12 -07:00
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
bool findBuiltin(const std::string &token);
|
|
|
|
bool findInorganic(const std::string &token);
|
|
|
|
bool findPlant(const std::string &token, const std::string &subtoken);
|
|
|
|
bool findCreature(const std::string &token, const std::string &subtoken);
|
|
|
|
|
2012-09-17 11:15:51 -06:00
|
|
|
bool findProduct(df::material *material, const std::string &name);
|
|
|
|
bool findProduct(const MaterialInfo &info, const std::string &name) {
|
|
|
|
return findProduct(info.material, name);
|
|
|
|
}
|
|
|
|
|
2020-10-04 21:05:08 -06:00
|
|
|
std::string getToken() const;
|
|
|
|
std::string toString(uint16_t temp = 10015, bool named = true) const;
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2012-01-05 11:04:05 -07:00
|
|
|
bool isAnyCloth();
|
|
|
|
|
|
|
|
void getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &mask);
|
|
|
|
void getMatchBits(df::job_item_flags2 &ok, df::job_item_flags2 &mask);
|
|
|
|
void getMatchBits(df::job_item_flags3 &ok, df::job_item_flags3 &mask);
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
df::craft_material_class getCraftClass();
|
2012-01-05 11:04:05 -07:00
|
|
|
|
2012-01-10 06:23:37 -07:00
|
|
|
bool matches(const MaterialInfo &mat)
|
|
|
|
{
|
|
|
|
if (!mat.isValid()) return true;
|
|
|
|
return (type == mat.type) &&
|
|
|
|
(mat.index == -1 || index == mat.index);
|
|
|
|
}
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
bool matches(const df::job_material_category &cat);
|
2012-01-10 06:23:37 -07:00
|
|
|
bool matches(const df::dfhack_material_category &cat);
|
2012-01-05 11:04:05 -07:00
|
|
|
bool matches(const df::job_item &item);
|
2012-01-03 08:25:55 -07:00
|
|
|
};
|
|
|
|
|
2012-01-08 09:02:12 -07:00
|
|
|
DFHACK_EXPORT bool parseJobMaterialCategory(df::job_material_category *cat, const std::string &token);
|
2012-01-10 06:23:37 -07:00
|
|
|
DFHACK_EXPORT bool parseJobMaterialCategory(df::dfhack_material_category *cat, const std::string &token);
|
2012-01-08 09:02:12 -07:00
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
inline bool operator== (const MaterialInfo &a, const MaterialInfo &b) {
|
|
|
|
return a.type == b.type && a.index == b.index;
|
|
|
|
}
|
|
|
|
inline bool operator!= (const MaterialInfo &a, const MaterialInfo &b) {
|
|
|
|
return a.type != b.type || a.index != b.index;
|
|
|
|
}
|
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
DFHACK_EXPORT bool isSoilInorganic(int material);
|
|
|
|
DFHACK_EXPORT bool isStoneInorganic(int material);
|
|
|
|
|
2011-11-02 22:01:25 -06:00
|
|
|
typedef int32_t t_materialIndex;
|
|
|
|
typedef int16_t t_materialType, t_itemType, t_itemSubtype;
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
2011-07-21 14:37:02 -06:00
|
|
|
* A copy of the game's material data.
|
2011-03-18 04:09:26 -06:00
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2011-07-20 07:18:50 -06:00
|
|
|
class DFHACK_EXPORT t_matgloss
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2011-07-20 07:18:50 -06:00
|
|
|
public:
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id; // raw name
|
|
|
|
std::string name; // a sensible human-readable name
|
|
|
|
uint8_t fore;
|
2010-04-04 16:48:19 -06:00
|
|
|
uint8_t back;
|
|
|
|
uint8_t bright;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
int32_t value; // Material value
|
2011-07-21 19:00:56 -06:00
|
|
|
uint8_t wall_tile; // Tile when a natural wall
|
|
|
|
uint8_t boulder_tile; // Tile when a dug-out stone;
|
2011-09-23 22:48:06 -06:00
|
|
|
bool is_gem;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
public:
|
|
|
|
t_matgloss();
|
2010-04-04 16:48:19 -06:00
|
|
|
};
|
2011-07-21 14:37:02 -06:00
|
|
|
/**
|
|
|
|
* A copy of the game's inorganic material data.
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2011-07-20 07:18:50 -06:00
|
|
|
class DFHACK_EXPORT t_matglossInorganic : public t_matgloss
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Types of metals the ore will produce when smelted. Each number
|
|
|
|
// is an index into the inorganic matglass vector.
|
2011-07-21 14:37:02 -06:00
|
|
|
std::vector<int16_t> ore_types;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
// Percent chance that the ore will produce each type of metal
|
|
|
|
// when smelted.
|
2011-07-21 14:37:02 -06:00
|
|
|
std::vector<int16_t> ore_chances;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
// Types of metals the ore will produce from strand extraction.
|
|
|
|
// Each number is an index into the inorganic matglass vector.
|
2011-07-21 14:37:02 -06:00
|
|
|
std::vector<int16_t> strand_types;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
// Percent chance that the ore will produce each type of metal
|
|
|
|
// fram strand extraction.
|
2011-07-21 14:37:02 -06:00
|
|
|
std::vector<int16_t> strand_chances;
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
public:
|
2011-07-21 18:44:36 -06:00
|
|
|
//t_matglossInorganic();
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
bool isOre();
|
|
|
|
bool isGem();
|
|
|
|
};
|
2012-01-21 09:12:26 -07:00
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-20 10:25:52 -06:00
|
|
|
struct t_descriptor_color
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
|
|
|
std::string name;
|
2011-05-06 19:48:41 -06:00
|
|
|
float red;
|
|
|
|
float green;
|
|
|
|
float blue;
|
2010-04-20 10:25:52 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-04 16:48:19 -06:00
|
|
|
struct t_matglossPlant
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
|
|
|
std::string name;
|
|
|
|
uint8_t fore;
|
2010-04-04 16:48:19 -06:00
|
|
|
uint8_t back;
|
|
|
|
uint8_t bright;
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string drink_name;
|
|
|
|
std::string food_name;
|
|
|
|
std::string extract_name;
|
2010-04-04 16:48:19 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-05-05 05:48:01 -06:00
|
|
|
struct t_bodypart
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
|
|
|
std::string category;
|
|
|
|
std::string singular;
|
|
|
|
std::string plural;
|
2010-05-05 05:48:01 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-05-05 05:48:01 -06:00
|
|
|
struct t_colormodifier
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string part;
|
2010-05-05 05:48:01 -06:00
|
|
|
std::vector<uint32_t> colorlist;
|
2010-05-12 06:21:31 -06:00
|
|
|
uint32_t startdate; /* in days */
|
|
|
|
uint32_t enddate; /* in days */
|
2010-05-05 05:48:01 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-14 14:12:02 -06:00
|
|
|
struct t_creaturecaste
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
|
|
|
std::string singular;
|
|
|
|
std::string plural;
|
|
|
|
std::string adjective;
|
2010-05-05 05:48:01 -06:00
|
|
|
std::vector<t_colormodifier> ColorModifier;
|
|
|
|
std::vector<t_bodypart> bodypart;
|
2010-05-10 04:58:54 -06:00
|
|
|
|
2012-01-21 12:24:38 -07:00
|
|
|
int32_t strength[7];
|
|
|
|
int32_t agility[7];
|
|
|
|
int32_t toughness[7];
|
|
|
|
int32_t endurance[7];
|
|
|
|
int32_t recuperation[7];
|
|
|
|
int32_t disease_resistance[7];
|
|
|
|
int32_t analytical_ability[7];
|
|
|
|
int32_t focus[7];
|
|
|
|
int32_t willpower[7];
|
|
|
|
int32_t creativity[7];
|
|
|
|
int32_t intuition[7];
|
|
|
|
int32_t patience[7];
|
|
|
|
int32_t memory[7];
|
|
|
|
int32_t linguistic_ability[7];
|
|
|
|
int32_t spatial_sense[7];
|
|
|
|
int32_t musicality[7];
|
|
|
|
int32_t kinesthetic_sense[7];
|
|
|
|
int32_t empathy[7];
|
|
|
|
int32_t social_awareness[7];
|
2010-04-14 14:12:02 -06:00
|
|
|
};
|
2011-03-24 19:31:27 -06:00
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-30 09:42:31 -06:00
|
|
|
struct t_matglossOther
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
2010-04-30 09:42:31 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-30 09:03:21 -06:00
|
|
|
struct t_creatureextract
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
2010-04-30 09:03:21 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-14 14:12:02 -06:00
|
|
|
struct t_creaturetype
|
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
std::string id;
|
2010-06-04 16:02:02 -06:00
|
|
|
std::vector <t_creaturecaste> castes;
|
|
|
|
std::vector <t_creatureextract> extract;
|
|
|
|
uint8_t tile_character;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint16_t fore;
|
|
|
|
uint16_t back;
|
|
|
|
uint16_t bright;
|
|
|
|
} tilecolor;
|
2010-04-14 14:12:02 -06:00
|
|
|
};
|
2010-04-28 09:40:27 -06:00
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* this structure describes what are things made of in the DF world
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-04-28 09:40:27 -06:00
|
|
|
struct t_material
|
|
|
|
{
|
2012-11-16 14:35:34 -07:00
|
|
|
t_itemType item_type;
|
|
|
|
t_itemSubtype item_subtype;
|
|
|
|
t_materialType mat_type;
|
|
|
|
t_materialIndex mat_index;
|
2010-06-04 16:02:02 -06:00
|
|
|
uint32_t flags;
|
2010-04-28 09:40:27 -06:00
|
|
|
};
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* The Materials module
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_materials
|
|
|
|
*/
|
2010-06-24 23:11:26 -06:00
|
|
|
class DFHACK_EXPORT Materials : public Module
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
public:
|
2011-06-17 07:02:43 -06:00
|
|
|
Materials();
|
2010-06-04 16:02:02 -06:00
|
|
|
~Materials();
|
2010-06-24 23:11:26 -06:00
|
|
|
bool Finish();
|
2010-04-28 10:09:32 -06:00
|
|
|
|
2010-06-04 16:02:02 -06:00
|
|
|
std::vector<t_matgloss> race;
|
|
|
|
std::vector<t_creaturetype> raceEx;
|
|
|
|
std::vector<t_descriptor_color> color;
|
|
|
|
std::vector<t_matglossOther> other;
|
|
|
|
std::vector<t_matgloss> alldesc;
|
2010-04-28 10:09:32 -06:00
|
|
|
|
2011-11-02 21:30:59 -06:00
|
|
|
bool CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic);
|
|
|
|
bool CopyOrganicMaterials (std::vector<t_matgloss> & organic);
|
|
|
|
bool CopyWoodMaterials (std::vector<t_matgloss> & tree);
|
|
|
|
bool CopyPlantMaterials (std::vector<t_matgloss> & plant);
|
|
|
|
|
2010-06-04 16:02:02 -06:00
|
|
|
bool ReadCreatureTypes (void);
|
|
|
|
bool ReadCreatureTypesEx (void);
|
|
|
|
bool ReadDescriptorColors(void);
|
|
|
|
bool ReadOthers (void);
|
2010-04-28 10:24:27 -06:00
|
|
|
|
2011-08-04 16:41:31 -06:00
|
|
|
bool ReadAllMaterials(void);
|
2010-05-02 04:50:51 -06:00
|
|
|
|
2011-04-12 05:59:07 -06:00
|
|
|
std::string getType(const t_material & mat);
|
|
|
|
std::string getDescription(const t_material & mat);
|
2010-06-04 16:02:02 -06:00
|
|
|
};
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|