2014-12-02 04:06:01 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "df/itemdef.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
#include "df/organic_mat_category.h"
|
2023-05-28 03:26:06 -06:00
|
|
|
#include "df/stockpile_settings.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "proto/stockpiles.pb.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
#include <functional>
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
namespace df
|
2014-12-02 04:06:01 -07:00
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
struct building_stockpilest;
|
|
|
|
}
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-15 22:54:48 -06:00
|
|
|
enum IncludedElements {
|
|
|
|
INCLUDED_ELEMENTS_NONE = 0x00,
|
|
|
|
INCLUDED_ELEMENTS_CONTAINERS = 0x01,
|
|
|
|
INCLUDED_ELEMENTS_GENERAL = 0x02,
|
|
|
|
INCLUDED_ELEMENTS_CATEGORIES = 0x04,
|
|
|
|
INCLUDED_ELEMENTS_TYPES = 0x08,
|
2023-05-03 19:01:11 -06:00
|
|
|
INCLUDED_ELEMENTS_FEATURES = 0x10,
|
2023-03-15 22:54:48 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum DeserializeMode {
|
|
|
|
DESERIALIZE_MODE_SET = 0,
|
|
|
|
DESERIALIZE_MODE_ENABLE = 1,
|
|
|
|
DESERIALIZE_MODE_DISABLE = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
// read the token from the serialized list during import
|
|
|
|
typedef std::function<std::string(const size_t&)> FuncReadImport;
|
|
|
|
// add the token to the serialized list during export
|
|
|
|
typedef std::function<void(const std::string&)> FuncWriteExport;
|
|
|
|
// are item's of item_type allowed?
|
|
|
|
typedef std::function<bool(df::enums::item_type::item_type)> FuncItemAllowed;
|
|
|
|
// is this material allowed?
|
|
|
|
typedef std::function<bool(const DFHack::MaterialInfo&)> FuncMaterialAllowed;
|
|
|
|
|
|
|
|
// convenient struct for parsing food stockpile items
|
|
|
|
struct food_pair {
|
2023-03-20 23:29:26 -06:00
|
|
|
const char * name;
|
2023-03-15 22:54:48 -06:00
|
|
|
// exporting
|
|
|
|
FuncWriteExport set_value;
|
|
|
|
std::vector<char>* stockpile_values;
|
|
|
|
// importing
|
|
|
|
FuncReadImport get_value;
|
|
|
|
size_t serialized_count;
|
|
|
|
bool valid;
|
|
|
|
|
2023-03-20 23:29:26 -06:00
|
|
|
food_pair(const char * n, FuncWriteExport s, std::vector<char>* sp_v, FuncReadImport g, size_t count)
|
|
|
|
: name(n), set_value(s), stockpile_values(sp_v), get_value(g), serialized_count(count),
|
|
|
|
valid(true) { }
|
2023-03-15 22:54:48 -06:00
|
|
|
food_pair(): valid(false) { }
|
|
|
|
};
|
|
|
|
|
2014-12-02 04:06:01 -07:00
|
|
|
/**
|
|
|
|
* Class for serializing the stockpile_settings structure into a Google protobuf
|
|
|
|
*/
|
2023-05-28 03:26:06 -06:00
|
|
|
class StockpileSettingsSerializer {
|
2014-12-02 04:06:01 -07:00
|
|
|
public:
|
2023-03-10 15:08:31 -07:00
|
|
|
/**
|
2023-05-28 03:26:06 -06:00
|
|
|
* @param settings settings to read or write to
|
2023-03-10 15:08:31 -07:00
|
|
|
*/
|
2023-05-28 03:26:06 -06:00
|
|
|
StockpileSettingsSerializer(df::stockpile_settings *settings);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-05-28 03:26:06 -06:00
|
|
|
~StockpileSettingsSerializer();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
/**
|
|
|
|
* Since we depend on protobuf-lite, not the full lib, we copy this function from
|
|
|
|
* protobuf message.cc
|
|
|
|
*/
|
2023-03-15 22:54:48 -06:00
|
|
|
bool serialize_to_ostream(std::ostream* output, uint32_t includedElements);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
/**
|
|
|
|
* Will serialize stockpile settings to a file (overwrites existing files)
|
|
|
|
* @return success/failure
|
|
|
|
*/
|
2023-03-15 22:54:48 -06:00
|
|
|
bool serialize_to_file(const std::string& file, uint32_t includedElements);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
/**
|
|
|
|
* Again, copied from message.cc
|
|
|
|
*/
|
2023-05-03 19:01:11 -06:00
|
|
|
bool parse_from_istream(DFHack::color_ostream &out, std::istream* input, DeserializeMode mode, const std::vector<std::string>& filters);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
/**
|
|
|
|
* Read stockpile settings from file
|
|
|
|
*/
|
2023-05-03 19:01:11 -06:00
|
|
|
bool unserialize_from_file(DFHack::color_ostream &out, const std::string& file, DeserializeMode mode, const std::vector<std::string>& filters);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-05-28 03:26:06 -06:00
|
|
|
protected:
|
2023-03-10 15:08:31 -07:00
|
|
|
dfstockpiles::StockpileSettings mBuffer;
|
|
|
|
|
2023-03-15 22:54:48 -06:00
|
|
|
// read memory structures and serialize to protobuf
|
2023-05-28 03:26:06 -06:00
|
|
|
virtual void write(uint32_t includedElements);
|
2023-03-10 15:08:31 -07:00
|
|
|
|
2023-03-15 22:54:48 -06:00
|
|
|
// parse serialized data into ui indices
|
2023-05-28 03:26:06 -06:00
|
|
|
virtual void read(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-10 15:08:31 -07:00
|
|
|
|
2023-05-28 03:26:06 -06:00
|
|
|
virtual void write_general();
|
|
|
|
virtual void read_general(DeserializeMode mode);
|
|
|
|
|
|
|
|
private:
|
|
|
|
df::stockpile_settings *mSettings;
|
2023-03-10 15:08:31 -07:00
|
|
|
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_ammo(dfstockpiles::StockpileSettings::AmmoSet* ammo);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_ammo(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_animals(dfstockpiles::StockpileSettings::AnimalsSet* animals);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_animals(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_armor(dfstockpiles::StockpileSettings::ArmorSet* armor);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_armor(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_bars_blocks(dfstockpiles::StockpileSettings::BarsBlocksSet* bars_blocks);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_bars_blocks(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_cloth(dfstockpiles::StockpileSettings::ClothSet* cloth);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_cloth(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_coins(dfstockpiles::StockpileSettings::CoinSet* coins);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_coins(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_finished_goods(dfstockpiles::StockpileSettings::FinishedGoodsSet* finished_goods);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_finished_goods(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-10 15:08:31 -07:00
|
|
|
food_pair food_map(df::enums::organic_mat_category::organic_mat_category cat);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_food(dfstockpiles::StockpileSettings::FoodSet* food);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_food(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_furniture(dfstockpiles::StockpileSettings::FurnitureSet* furniture);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_furniture(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_gems(dfstockpiles::StockpileSettings::GemsSet* gems);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_gems(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_leather(dfstockpiles::StockpileSettings::LeatherSet* leather);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_leather(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_corpses(dfstockpiles::StockpileSettings::CorpsesSet* corpses);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_corpses(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_refuse(dfstockpiles::StockpileSettings::RefuseSet* refuse);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_refuse(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_sheet(dfstockpiles::StockpileSettings::SheetSet* sheet);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_sheet(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_stone(dfstockpiles::StockpileSettings::StoneSet* stone);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_stone(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_weapons(dfstockpiles::StockpileSettings::WeaponsSet* weapons);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_weapons(DeserializeMode mode, const std::vector<std::string>& filters);
|
2023-03-19 18:31:35 -06:00
|
|
|
bool write_wood(dfstockpiles::StockpileSettings::WoodSet* wood);
|
2023-03-21 00:25:52 -06:00
|
|
|
void read_wood(DeserializeMode mode, const std::vector<std::string>& filters);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-05-28 03:26:06 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for serializing a stockpile into a Google protobuf
|
|
|
|
*/
|
|
|
|
class StockpileSerializer : public StockpileSettingsSerializer {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param stockpile stockpile to read or write settings to
|
|
|
|
*/
|
|
|
|
StockpileSerializer(df::building_stockpilest* stockpile);
|
|
|
|
|
|
|
|
~StockpileSerializer();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// read memory structures and serialize to protobuf
|
|
|
|
virtual void write(uint32_t includedElements);
|
|
|
|
|
|
|
|
// parse serialized data into ui indices
|
|
|
|
virtual void read(DeserializeMode mode, const std::vector<std::string>& filters);
|
|
|
|
|
|
|
|
virtual void write_general();
|
|
|
|
virtual void read_general(DeserializeMode mode);
|
|
|
|
|
|
|
|
private:
|
|
|
|
df::building_stockpilest* mPile;
|
|
|
|
|
|
|
|
void write_containers();
|
|
|
|
void read_containers(DeserializeMode mode);
|
2023-04-18 09:22:52 -06:00
|
|
|
void write_features();
|
|
|
|
void read_features(DeserializeMode mode);
|
2023-05-28 03:26:06 -06:00
|
|
|
};
|