dfhack/library/include/modules/Materials.h

387 lines
11 KiB
C

/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
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.
*/
#pragma once
2010-04-04 16:48:19 -06:00
#ifndef CL_MOD_MATERIALS
#define CL_MOD_MATERIALS
/**
* \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"
#include "DataDefs.h"
#include "df/material.h"
#include "df/inorganic_raw.h"
#include "df/plant_raw.h"
#include <vector>
#include <string>
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;
union job_material_category;
union dfhack_material_category;
2012-01-05 11:04:05 -07:00
union job_item_flags1;
union job_item_flags2;
union job_item_flags3;
}
2010-04-04 16:48:19 -06:00
namespace DFHack
{
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) {}
};
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 {
None,
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:
2020-11-12 23:44:38 -07:00
MaterialInfo(int16_t type = -1, int32_t index = -1) { decode(type, index); }
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); }
bool isValid() const { return material != NULL; }
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(); }
2020-11-12 23:44:38 -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);
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);
}
bool find(const std::string &token);
2012-04-06 09:56:19 -06:00
bool find(const std::vector<std::string> &tokens);
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);
bool findProduct(df::material *material, const std::string &name);
bool findProduct(const MaterialInfo &info, const std::string &name) {
return findProduct(info.material, name);
}
prep buildingplan for core algorithm changes player-visible changes - removed text that showed up if you used the wrong hotkeys. no other dfhack screen does this, and it seems unneeded. can add back if others think otherwise, though internal changes - changed signature of lua-exported isPlannableBuilding to take subtype and custom type in addition to building type. this is only used by quickfort, and it already sends all three params in preparation for this change - added lua-exported scheduleCycle(), which is like doCycle(), but only takes effect on the next non-paused frame. this lets quickfort run only one buildingplan cycle regardless of how many #build blueprints were run - declared a few dfhack library methods and params const so buildingplan could call them from const methods - converted buildingplan internal debug logging fn to have a printf api - reshaped buildingplan-planner API and refactored implementation in preparation for upcoming core algorithm changes for supporing all building types (no externally-visible functionality changes) - changed df::building_type params to type, subtype, custom tuple keys - introduced capability to return multiple filters per building type (though the current buildings all only have one filter per) - split monolith hook functions in buildingplan.cpp into one per scope. this significantly cleans up the code and preps the hooks to handle iterating through multiple item filters. - got rid of send_key function and replaced with better reporting of whether keys have been handled
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-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);
df::craft_material_class getCraftClass();
2012-01-05 11:04:05 -07:00
bool matches(const MaterialInfo &mat)
{
if (!mat.isValid()) return true;
return (type == mat.type) &&
(mat.index == -1 || index == mat.index);
}
bool matches(const df::job_material_category &cat);
bool matches(const df::dfhack_material_category &cat);
2020-11-12 23:44:38 -07:00
bool matches(const df::job_item &item,
df::item_type itype = df::item_type::NONE);
};
DFHACK_EXPORT bool parseJobMaterialCategory(df::job_material_category *cat, const std::string &token);
DFHACK_EXPORT bool parseJobMaterialCategory(df::dfhack_material_category *cat, const std::string &token);
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;
}
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;
/**
* A copy of the game's material data.
* \ingroup grp_materials
*/
class DFHACK_EXPORT t_matgloss
2010-04-04 16:48:19 -06:00
{
public:
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;
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;
bool is_gem;
public:
t_matgloss();
2010-04-04 16:48:19 -06:00
};
/**
* A copy of the game's inorganic material data.
* \ingroup grp_materials
*/
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.
std::vector<int16_t> ore_types;
// Percent chance that the ore will produce each type of metal
// when smelted.
std::vector<int16_t> ore_chances;
// Types of metals the ore will produce from strand extraction.
// Each number is an index into the inorganic matglass vector.
std::vector<int16_t> strand_types;
// Percent chance that the ore will produce each type of metal
// fram strand extraction.
std::vector<int16_t> strand_chances;
public:
2011-07-21 18:44:36 -06:00
//t_matglossInorganic();
bool isOre();
bool isGem();
};
/**
* \ingroup grp_materials
*/
2010-04-20 10:25:52 -06:00
struct t_descriptor_color
{
std::string id;
std::string name;
float red;
float green;
float blue;
2010-04-20 10:25:52 -06:00
};
/**
* \ingroup grp_materials
*/
2010-04-04 16:48:19 -06:00
struct t_matglossPlant
{
std::string id;
std::string name;
uint8_t fore;
2010-04-04 16:48:19 -06:00
uint8_t back;
uint8_t bright;
std::string drink_name;
std::string food_name;
std::string extract_name;
2010-04-04 16:48:19 -06:00
};
/**
* \ingroup grp_materials
*/
struct t_bodypart
{
std::string id;
std::string category;
std::string singular;
std::string plural;
};
/**
* \ingroup grp_materials
*/
struct t_colormodifier
{
std::string part;
std::vector<uint32_t> colorlist;
uint32_t startdate; /* in days */
uint32_t enddate; /* in days */
};
/**
* \ingroup grp_materials
*/
2010-04-14 14:12:02 -06:00
struct t_creaturecaste
{
std::string id;
std::string singular;
std::string plural;
std::string adjective;
std::vector<t_colormodifier> ColorModifier;
std::vector<t_bodypart> bodypart;
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
};
/**
* \ingroup grp_materials
*/
struct t_matglossOther
{
std::string id;
};
/**
* \ingroup grp_materials
*/
2010-04-30 09:03:21 -06:00
struct t_creatureextract
{
std::string id;
2010-04-30 09:03:21 -06:00
};
/**
* \ingroup grp_materials
*/
2010-04-14 14:12:02 -06:00
struct t_creaturetype
{
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
};
/**
* this structure describes what are things made of in the DF world
* \ingroup grp_materials
*/
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;
};
/**
* 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:
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);
bool ReadAllMaterials(void);
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