|
|
@ -1,54 +1,23 @@
|
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
// stockpiles plugin
|
|
|
|
|
|
|
|
#include "proto/stockpiles.pb.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dfhack
|
|
|
|
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// df
|
|
|
|
#include "df/itemdef.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
|
|
|
|
#include "df/world_data.h"
|
|
|
|
|
|
|
|
#include "df/organic_mat_category.h"
|
|
|
|
#include "df/organic_mat_category.h"
|
|
|
|
#include "df/furniture_type.h"
|
|
|
|
|
|
|
|
#include "df/item_quality.h"
|
|
|
|
|
|
|
|
#include "df/item_type.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include "proto/stockpiles.pb.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
#include <istream>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace df {
|
|
|
|
namespace df
|
|
|
|
|
|
|
|
{
|
|
|
|
struct building_stockpilest;
|
|
|
|
struct building_stockpilest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Null buffer that acts like /dev/null for when debug is disabled
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class NullBuffer : public std::streambuf
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
int overflow ( int c );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NullStream : public std::ostream
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
NullStream();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
NullBuffer m_sb;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Class for serializing the stockpile_settings structure into a Google protobuf
|
|
|
|
* Class for serializing the stockpile_settings structure into a Google protobuf
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class StockpileSerializer
|
|
|
|
class StockpileSerializer {
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param out for debugging
|
|
|
|
* @param out for debugging
|
|
|
@ -59,8 +28,6 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
~StockpileSerializer();
|
|
|
|
~StockpileSerializer();
|
|
|
|
|
|
|
|
|
|
|
|
void enable_debug ( std::ostream &out );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Since we depend on protobuf-lite, not the full lib, we copy this function from
|
|
|
|
* Since we depend on protobuf-lite, not the full lib, we copy this function from
|
|
|
|
* protobuf message.cc
|
|
|
|
* protobuf message.cc
|
|
|
@ -78,17 +45,12 @@ public:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
bool parse_from_istream(std::istream* input);
|
|
|
|
bool parse_from_istream(std::istream* input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Read stockpile settings from file
|
|
|
|
* Read stockpile settings from file
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
bool unserialize_from_file(const std::string& file);
|
|
|
|
bool unserialize_from_file(const std::string& file);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
bool mDebug;
|
|
|
|
|
|
|
|
std::ostream * mOut;
|
|
|
|
|
|
|
|
NullStream mNull;
|
|
|
|
|
|
|
|
df::building_stockpilest* mPile;
|
|
|
|
df::building_stockpilest* mPile;
|
|
|
|
dfstockpiles::StockpileSettings mBuffer;
|
|
|
|
dfstockpiles::StockpileSettings mBuffer;
|
|
|
|
std::map<int, std::string> mOtherMatsFurniture;
|
|
|
|
std::map<int, std::string> mOtherMatsFurniture;
|
|
|
@ -97,9 +59,6 @@ private:
|
|
|
|
std::map<int, std::string> mOtherMatsBlocks;
|
|
|
|
std::map<int, std::string> mOtherMatsBlocks;
|
|
|
|
std::map<int, std::string> mOtherMatsWeaponsArmor;
|
|
|
|
std::map<int, std::string> mOtherMatsWeaponsArmor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream & debug();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
read memory structures and serialize to protobuf
|
|
|
|
read memory structures and serialize to protobuf
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -115,19 +74,15 @@ private:
|
|
|
|
* @return the enum's value, -1 if not found
|
|
|
|
* @return the enum's value, -1 if not found
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <typename E>
|
|
|
|
template <typename E>
|
|
|
|
static typename df::enum_traits<E>::base_type linear_index ( std::ostream & out, df::enum_traits<E> traits, const std::string &token )
|
|
|
|
static typename df::enum_traits<E>::base_type linear_index(df::enum_traits<E> traits, const std::string& token) {
|
|
|
|
{
|
|
|
|
|
|
|
|
auto j = traits.first_item_value;
|
|
|
|
auto j = traits.first_item_value;
|
|
|
|
auto limit = traits.last_item_value;
|
|
|
|
auto limit = traits.last_item_value;
|
|
|
|
// sometimes enums start at -1, which is bad news for array indexing
|
|
|
|
// sometimes enums start at -1, which is bad news for array indexing
|
|
|
|
if ( j < 0 )
|
|
|
|
if (j < 0) {
|
|
|
|
{
|
|
|
|
|
|
|
|
j += abs(traits.first_item_value);
|
|
|
|
j += abs(traits.first_item_value);
|
|
|
|
limit += abs(traits.first_item_value);
|
|
|
|
limit += abs(traits.first_item_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ( ; j <= limit; ++j )
|
|
|
|
for (; j <= limit; ++j) {
|
|
|
|
{
|
|
|
|
|
|
|
|
// out << " linear_index("<< token <<") = table["<<j<<"/"<<limit<<"]: " <<traits.key_table[j] << endl;
|
|
|
|
|
|
|
|
if (token.compare(traits.key_table[j]) == 0)
|
|
|
|
if (token.compare(traits.key_table[j]) == 0)
|
|
|
|
return j;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -144,8 +99,7 @@ private:
|
|
|
|
typedef std::function<bool(const DFHack::MaterialInfo&)> FuncMaterialAllowed;
|
|
|
|
typedef std::function<bool(const DFHack::MaterialInfo&)> FuncMaterialAllowed;
|
|
|
|
|
|
|
|
|
|
|
|
// convenient struct for parsing food stockpile items
|
|
|
|
// convenient struct for parsing food stockpile items
|
|
|
|
struct food_pair
|
|
|
|
struct food_pair {
|
|
|
|
{
|
|
|
|
|
|
|
|
// exporting
|
|
|
|
// exporting
|
|
|
|
FuncWriteExport set_value;
|
|
|
|
FuncWriteExport set_value;
|
|
|
|
std::vector<char>* stockpile_values;
|
|
|
|
std::vector<char>* stockpile_values;
|
|
|
@ -155,12 +109,7 @@ private:
|
|
|
|
bool valid;
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
|
|
|
|
food_pair(FuncWriteExport s, std::vector<char>* sp_v, FuncReadImport g, size_t count)
|
|
|
|
food_pair(FuncWriteExport s, std::vector<char>* sp_v, FuncReadImport g, size_t count)
|
|
|
|
: set_value ( s )
|
|
|
|
: set_value(s), stockpile_values(sp_v), get_value(g), serialized_count(count), valid(true) { }
|
|
|
|
, stockpile_values ( sp_v )
|
|
|
|
|
|
|
|
, get_value ( g )
|
|
|
|
|
|
|
|
, serialized_count ( count )
|
|
|
|
|
|
|
|
, valid ( true )
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
food_pair(): valid(false) { }
|
|
|
|
food_pair(): valid(false) { }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -184,19 +133,16 @@ private:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void unserialize_list_organic_mat(FuncReadImport get_value, size_t list_size, std::vector<char>* pile_list, df::enums::organic_mat_category::organic_mat_category cat);
|
|
|
|
void unserialize_list_organic_mat(FuncReadImport get_value, size_t list_size, std::vector<char>* pile_list, df::enums::organic_mat_category::organic_mat_category cat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void serialize_list_item_type(FuncItemAllowed is_allowed, FuncWriteExport add_value, const std::vector<char>& list);
|
|
|
|
void serialize_list_item_type(FuncItemAllowed is_allowed, FuncWriteExport add_value, const std::vector<char>& list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void unserialize_list_item_type(FuncItemAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list);
|
|
|
|
void unserialize_list_item_type(FuncItemAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -217,13 +163,11 @@ private:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void quality_clear(bool(&pile_list)[7]);
|
|
|
|
void quality_clear(bool(&pile_list)[7]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void unserialize_list_quality(FuncReadImport read_value, int32_t list_size, bool(&pile_list)[7]);
|
|
|
|
void unserialize_list_quality(FuncReadImport read_value, int32_t list_size, bool(&pile_list)[7]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -234,19 +178,16 @@ private:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void unserialize_list_other_mats(const std::map<int, std::string> other_mats, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list);
|
|
|
|
void unserialize_list_other_mats(const std::map<int, std::string> other_mats, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void serialize_list_itemdef(FuncWriteExport add_value, std::vector<char> list, std::vector<df::itemdef*> items, df::enums::item_type::item_type type);
|
|
|
|
void serialize_list_itemdef(FuncWriteExport add_value, std::vector<char> list, std::vector<df::itemdef*> items, df::enums::item_type::item_type type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void unserialize_list_itemdef(FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list, df::enums::item_type::item_type type);
|
|
|
|
void unserialize_list_itemdef(FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list, df::enums::item_type::item_type type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Given a list of other_materials and an index, return its corresponding token
|
|
|
|
* Given a list of other_materials and an index, return its corresponding token
|
|
|
|
* @return empty string if not found
|
|
|
|
* @return empty string if not found
|
|
|
@ -264,14 +205,11 @@ private:
|
|
|
|
void write_general();
|
|
|
|
void write_general();
|
|
|
|
void read_general();
|
|
|
|
void read_general();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void write_animals();
|
|
|
|
void write_animals();
|
|
|
|
void read_animals();
|
|
|
|
void read_animals();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
food_pair food_map(df::enums::organic_mat_category::organic_mat_category cat);
|
|
|
|
food_pair food_map(df::enums::organic_mat_category::organic_mat_category cat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void write_food();
|
|
|
|
void write_food();
|
|
|
|
void read_food();
|
|
|
|
void read_food();
|
|
|
|
|
|
|
|
|
|
|
@ -282,13 +220,10 @@ private:
|
|
|
|
|
|
|
|
|
|
|
|
bool refuse_creature_is_allowed(const df::creature_raw* raw);
|
|
|
|
bool refuse_creature_is_allowed(const df::creature_raw* raw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void refuse_write_helper(std::function<void(const std::string&)> add_value, const std::vector<char>& list);
|
|
|
|
void refuse_write_helper(std::function<void(const std::string&)> add_value, const std::vector<char>& list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool refuse_type_is_allowed(df::enums::item_type::item_type type);
|
|
|
|
bool refuse_type_is_allowed(df::enums::item_type::item_type type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void write_refuse();
|
|
|
|
void write_refuse();
|
|
|
|
void refuse_read_helper(std::function<std::string(const size_t&)> get_value, size_t list_size, std::vector<char>* pile_list);
|
|
|
|
void refuse_read_helper(std::function<std::string(const size_t&)> get_value, size_t list_size, std::vector<char>* pile_list);
|
|
|
|
|
|
|
|
|
|
|
@ -345,5 +280,4 @@ private:
|
|
|
|
bool armor_mat_is_allowed(const DFHack::MaterialInfo& mi);
|
|
|
|
bool armor_mat_is_allowed(const DFHack::MaterialInfo& mi);
|
|
|
|
void write_armor();
|
|
|
|
void write_armor();
|
|
|
|
void read_armor();
|
|
|
|
void read_armor();
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|