2014-12-02 04:06:01 -07:00
|
|
|
// stockpiles plugin
|
|
|
|
#include "OrganicMatLookup.h"
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "StockpileSerializer.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
#include "StockpileUtils.h"
|
|
|
|
|
|
|
|
// dfhack
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "Debug.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
#include "MiscUtils.h"
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "modules/Items.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// df
|
|
|
|
#include "df/building_stockpilest.h"
|
|
|
|
#include "df/inorganic_raw.h"
|
2023-03-10 15:08:31 -07:00
|
|
|
#include "df/item_quality.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
#include <df/itemdef_ammost.h>
|
|
|
|
#include <df/itemdef_armorst.h>
|
|
|
|
#include <df/itemdef_glovesst.h>
|
2023-03-10 15:08:31 -07:00
|
|
|
#include <df/itemdef_helmst.h>
|
2014-12-02 04:06:01 -07:00
|
|
|
#include <df/itemdef_pantsst.h>
|
|
|
|
#include <df/itemdef_shieldst.h>
|
2023-03-10 15:08:31 -07:00
|
|
|
#include <df/itemdef_shoesst.h>
|
|
|
|
#include <df/itemdef_trapcompst.h>
|
|
|
|
#include <df/itemdef_weaponst.h>
|
|
|
|
#include "df/furniture_type.h"
|
|
|
|
#include "df/material.h"
|
|
|
|
#include "df/plant_raw.h"
|
|
|
|
#include "df/stockpile_group_set.h"
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// protobuf
|
|
|
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
|
|
|
|
2022-12-10 19:06:53 -07:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2014-12-02 04:06:01 -07:00
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
using namespace google::protobuf;
|
|
|
|
using namespace dfstockpiles;
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
using std::placeholders::_1;
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
namespace DFHack {
|
|
|
|
DBG_EXTERN(stockpiles, log);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
StockpileSerializer::StockpileSerializer(df::building_stockpilest* stockpile)
|
|
|
|
: mPile(stockpile) {
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// build other_mats indices
|
|
|
|
furniture_setup_other_mats();
|
|
|
|
bars_blocks_setup_other_mats();
|
|
|
|
finished_goods_setup_other_mats();
|
|
|
|
weapons_armor_setup_other_mats();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
StockpileSerializer::~StockpileSerializer() { }
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::serialize_to_ostream(std::ostream* output) {
|
|
|
|
if (output->fail())
|
|
|
|
return false;
|
2014-12-02 04:06:01 -07:00
|
|
|
mBuffer.Clear();
|
|
|
|
write();
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
io::OstreamOutputStream zero_copy_output(output);
|
|
|
|
if (!mBuffer.SerializeToZeroCopyStream(&zero_copy_output))
|
|
|
|
return false;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
return output->good();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::serialize_to_file(const std::string& file) {
|
|
|
|
std::fstream output(file, std::ios::out | std::ios::binary | std::ios::trunc);
|
|
|
|
if (output.fail()) {
|
|
|
|
WARN(log).print("ERROR: failed to open file for writing: '%s'\n", file.c_str());
|
2014-12-04 02:47:17 -07:00
|
|
|
return false;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
return serialize_to_ostream(&output);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::parse_from_istream(std::istream* input) {
|
|
|
|
if (input->fail())
|
|
|
|
return false;
|
2014-12-02 04:06:01 -07:00
|
|
|
mBuffer.Clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
io::IstreamInputStream zero_copy_input(input);
|
|
|
|
const bool res = mBuffer.ParseFromZeroCopyStream(&zero_copy_input) && input->eof();
|
|
|
|
if (res)
|
|
|
|
read();
|
2014-12-02 04:06:01 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::unserialize_from_file(const std::string& file) {
|
|
|
|
std::fstream input(file, std::ios::in | std::ios::binary);
|
|
|
|
if (input.fail()) {
|
|
|
|
WARN(log).print("failed to open file for reading: '%s'\n", file.c_str());
|
2014-12-04 02:47:17 -07:00
|
|
|
return false;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
return parse_from_istream(&input);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write() {
|
|
|
|
DEBUG(log).print("GROUP SET %s\n", bitfield_to_string(mPile->settings.flags).c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
write_general();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.animals)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_animals();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.food)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_food();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.furniture)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_furniture();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.refuse)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_refuse();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.stone)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_stone();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.ammo)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_ammo();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.coins)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_coins();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.bars_blocks)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_bars_blocks();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.gems)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_gems();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.finished_goods)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_finished_goods();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.leather)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_leather();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.cloth)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_cloth();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.wood)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_wood();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.weapons)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_weapons();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.flags.bits.armor)
|
2014-12-02 04:06:01 -07:00
|
|
|
write_armor();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read() {
|
|
|
|
DEBUG(log).print("==READ==\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
read_general();
|
|
|
|
read_animals();
|
|
|
|
read_food();
|
|
|
|
read_furniture();
|
|
|
|
read_refuse();
|
|
|
|
read_stone();
|
|
|
|
read_ammo();
|
|
|
|
read_coins();
|
|
|
|
read_bars_blocks();
|
|
|
|
read_gems();
|
|
|
|
read_finished_goods();
|
|
|
|
read_leather();
|
|
|
|
read_cloth();
|
|
|
|
read_wood();
|
|
|
|
read_weapons();
|
|
|
|
read_armor();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_organic_mat(FuncWriteExport add_value, const std::vector<char>* list, organic_mat_category::organic_mat_category cat) {
|
|
|
|
if (!list) {
|
|
|
|
DEBUG(log).print("serialize_list_organic_mat: list null\n");
|
|
|
|
return;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < list->size(); ++i) {
|
|
|
|
if (list->at(i)) {
|
|
|
|
std::string token = OrganicMatLookup::food_token_by_idx(cat, i);
|
|
|
|
if (token.empty()) {
|
|
|
|
DEBUG(log).print("food mat invalid :(\n");
|
|
|
|
continue;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("organic_material %zd is %s\n", i, token.c_str());
|
|
|
|
add_value(token);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_organic_mat(FuncReadImport get_value, size_t list_size, std::vector<char>* pile_list, organic_mat_category::organic_mat_category cat) {
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(OrganicMatLookup::food_max_size(cat), '\0');
|
|
|
|
for (size_t i = 0; i < list_size; ++i) {
|
|
|
|
std::string token = get_value(i);
|
|
|
|
int16_t idx = OrganicMatLookup::food_idx_by_token(cat, token);
|
|
|
|
DEBUG(log).print(" organic_material %d is %s\n", idx, token.c_str());
|
|
|
|
if (size_t(idx) >= pile_list->size()) {
|
|
|
|
WARN(log).print("organic mat index too large! idx[%d] max_size[%zd]\n", idx, pile_list->size());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_item_type(FuncItemAllowed is_allowed, FuncWriteExport add_value, const std::vector<char>& list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
using df::enums::item_type::item_type;
|
2018-04-06 20:22:48 -06:00
|
|
|
using type_traits = df::enum_traits<item_type>;
|
2023-03-10 15:08:31 -07:00
|
|
|
size_t num_item_types = list.size();
|
|
|
|
DEBUG(log).print("item_type size = %zd size limit = %d typecasted: %zd\n", num_item_types, type_traits::last_item_value, (size_t)type_traits::last_item_value);
|
|
|
|
for (size_t i = 0; i <= (size_t)type_traits::last_item_value; ++i) {
|
|
|
|
if (i < num_item_types && !list.at(i))
|
|
|
|
continue;
|
|
|
|
const item_type type = (item_type)((df::enum_traits<item_type>::base_type)i);
|
|
|
|
std::string r_type(type_traits::key_table[i + 1]);
|
|
|
|
if (!is_allowed(type))
|
|
|
|
continue;
|
|
|
|
add_value(r_type);
|
|
|
|
DEBUG(log).print("item_type key_table[%zd] type[%d] is %s\n", i + 1, (int16_t)type, r_type.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_item_type(FuncItemAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(112, '\0'); // TODO remove hardcoded list size value
|
|
|
|
for (size_t i = 0; i < pile_list->size(); ++i) {
|
|
|
|
pile_list->at(i) = is_allowed((item_type::item_type)i) ? 0 : 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
using df::enums::item_type::item_type;
|
|
|
|
df::enum_traits<item_type> type_traits;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int32_t i = 0; i < list_size; ++i) {
|
|
|
|
const std::string token = read_value(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
// subtract one because item_type starts at -1
|
2023-03-10 15:08:31 -07:00
|
|
|
const df::enum_traits<item_type>::base_type idx = linear_index(type_traits, token) - 1;
|
|
|
|
const item_type type = (item_type)idx;
|
|
|
|
if (!is_allowed(type))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("item_type %d is %s\n", idx, token.c_str());
|
|
|
|
if (size_t(idx) >= pile_list->size()) {
|
|
|
|
WARN(log).print("error item_type index too large! idx[%d] max_size[%zd]\n", idx, pile_list->size());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_material(FuncMaterialAllowed is_allowed, FuncWriteExport add_value, const std::vector<char>& list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < list.size(); ++i) {
|
|
|
|
if (list.at(i)) {
|
|
|
|
mi.decode(0, i);
|
|
|
|
if (!is_allowed(mi))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("material %zd is %s\n", i, mi.getToken().c_str());
|
|
|
|
add_value(mi.getToken());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_material(FuncMaterialAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
// we initialize all possible (allowed) values to 0,
|
|
|
|
// then all other not-allowed values to 1
|
|
|
|
// why? because that's how the memory is in DF before
|
|
|
|
// we muck with it.
|
|
|
|
std::set<int32_t> idx_set;
|
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(world->raws.inorganics.size(), 0);
|
|
|
|
for (size_t i = 0; i < pile_list->size(); ++i) {
|
|
|
|
MaterialInfo mi(0, i);
|
|
|
|
pile_list->at(i) = is_allowed(mi) ? 0 : 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int i = 0; i < list_size; ++i) {
|
|
|
|
const std::string token = read_value(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
2023-03-10 15:08:31 -07:00
|
|
|
mi.find(token);
|
|
|
|
if (!is_allowed(mi))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("material %d is %s\n", mi.index, token.c_str());
|
|
|
|
if (size_t(mi.index) >= pile_list->size()) {
|
|
|
|
WARN(log).print("material index too large! idx[%d] max_size[%zd]\n", mi.index, pile_list->size());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->at(mi.index) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_quality(FuncWriteExport add_value, const bool(&quality_list)[7]) {
|
2014-12-02 04:06:01 -07:00
|
|
|
using df::enums::item_quality::item_quality;
|
2018-04-06 20:22:48 -06:00
|
|
|
using quality_traits = df::enum_traits<item_quality>;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < 7; ++i) {
|
|
|
|
if (quality_list[i]) {
|
|
|
|
const std::string f_type(quality_traits::key_table[i]);
|
|
|
|
add_value(f_type);
|
|
|
|
DEBUG(log).print("quality: %zd is %s\n", i, f_type.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::quality_clear(bool(&pile_list)[7]) {
|
|
|
|
std::fill(pile_list, pile_list + 7, false);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_quality(FuncReadImport read_value, int32_t list_size, bool(&pile_list)[7]) {
|
|
|
|
quality_clear(pile_list);
|
|
|
|
if (list_size > 0 && list_size <= 7) {
|
2014-12-02 04:06:01 -07:00
|
|
|
using df::enums::item_quality::item_quality;
|
|
|
|
df::enum_traits<item_quality> quality_traits;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int i = 0; i < list_size; ++i) {
|
|
|
|
const std::string quality = read_value(i);
|
|
|
|
df::enum_traits<item_quality>::base_type idx = linear_index(quality_traits, quality);
|
|
|
|
if (idx < 0) {
|
|
|
|
WARN(log).print("invalid quality token: %s\n", quality.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("quality: %d is %s\n", idx, quality.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list[idx] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_other_mats(const std::map<int, std::string> other_mats, FuncWriteExport add_value, std::vector<char> list) {
|
|
|
|
for (size_t i = 0; i < list.size(); ++i) {
|
|
|
|
if (list.at(i)) {
|
|
|
|
const std::string token = other_mats_index(other_mats, i);
|
|
|
|
if (token.empty()) {
|
|
|
|
WARN(log).print("invalid other material with index %zd\n", i);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
add_value(token);
|
|
|
|
DEBUG(log).print("other mats %zd is %s\n", i, token.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_other_mats(const std::map<int, std::string> other_mats, FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(other_mats.size(), '\0');
|
|
|
|
for (int i = 0; i < list_size; ++i) {
|
|
|
|
const std::string token = read_value(i);
|
|
|
|
size_t idx = other_mats_token(other_mats, token);
|
|
|
|
if (idx < 0) {
|
|
|
|
WARN(log).print("invalid other mat with token %s\n", token.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("other_mats %zd is %s\n", idx, token.c_str());
|
|
|
|
if (idx >= pile_list->size()) {
|
|
|
|
WARN(log).print("other_mats index too large! idx[%zd] max_size[%zd]\n", idx, pile_list->size());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::serialize_list_itemdef(FuncWriteExport add_value, std::vector<char> list, std::vector<df::itemdef*> items, item_type::item_type type) {
|
|
|
|
for (size_t i = 0; i < list.size(); ++i) {
|
|
|
|
if (list.at(i)) {
|
|
|
|
const df::itemdef* a = items.at(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
// skip procedurally generated items
|
2023-03-10 15:08:31 -07:00
|
|
|
if (a->base_flags.is_set(df::itemdef_flags::GENERATED))
|
|
|
|
continue;
|
2014-12-02 04:06:01 -07:00
|
|
|
ItemTypeInfo ii;
|
2023-03-10 15:08:31 -07:00
|
|
|
if (!ii.decode(type, i))
|
|
|
|
continue;
|
|
|
|
add_value(ii.getToken());
|
|
|
|
DEBUG(log).print("itemdef type %zd is %s\n", i, ii.getToken().c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::unserialize_list_itemdef(FuncReadImport read_value, int32_t list_size, std::vector<char>* pile_list, item_type::item_type type) {
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(Items::getSubtypeCount(type), '\0');
|
|
|
|
for (int i = 0; i < list_size; ++i) {
|
|
|
|
std::string token = read_value(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
ItemTypeInfo ii;
|
2023-03-10 15:08:31 -07:00
|
|
|
if (!ii.find(token))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("itemdef %d is %s\n", ii.subtype, token.c_str());
|
|
|
|
if (size_t(ii.subtype) >= pile_list->size()) {
|
|
|
|
WARN(log).print("itemdef index too large! idx[%d] max_size[%zd]\n", ii.subtype, pile_list->size());
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->at(ii.subtype) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
std::string StockpileSerializer::other_mats_index(const std::map<int, std::string> other_mats, int idx) {
|
|
|
|
auto it = other_mats.find(idx);
|
|
|
|
if (it == other_mats.end())
|
2014-12-02 04:06:01 -07:00
|
|
|
return std::string();
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
int StockpileSerializer::other_mats_token(const std::map<int, std::string> other_mats, const std::string& token) {
|
|
|
|
for (auto it = other_mats.begin(); it != other_mats.end(); ++it) {
|
|
|
|
if (it->second == token)
|
2014-12-02 04:06:01 -07:00
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_general() {
|
|
|
|
mBuffer.set_max_bins(mPile->max_bins);
|
|
|
|
mBuffer.set_max_wheelbarrows(mPile->max_wheelbarrows);
|
|
|
|
mBuffer.set_max_barrels(mPile->max_barrels);
|
|
|
|
mBuffer.set_use_links_only(mPile->use_links_only);
|
|
|
|
mBuffer.set_allow_inorganic(mPile->settings.allow_inorganic);
|
|
|
|
mBuffer.set_allow_organic(mPile->settings.allow_organic);
|
|
|
|
mBuffer.set_corpses(mPile->settings.flags.bits.corpses);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_general() {
|
|
|
|
if (mBuffer.has_max_bins())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->max_bins = mBuffer.max_bins();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_max_wheelbarrows())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->max_wheelbarrows = mBuffer.max_wheelbarrows();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_max_barrels())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->max_barrels = mBuffer.max_barrels();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_use_links_only())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->use_links_only = mBuffer.use_links_only();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_allow_inorganic())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.allow_inorganic = mBuffer.allow_inorganic();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_allow_organic())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.allow_organic = mBuffer.allow_organic();
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_corpses())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.corpses = mBuffer.corpses();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_animals() {
|
|
|
|
StockpileSettings::AnimalsSet* animals = mBuffer.mutable_animals();
|
|
|
|
animals->set_empty_cages(mPile->settings.animals.empty_cages);
|
|
|
|
animals->set_empty_traps(mPile->settings.animals.empty_traps);
|
|
|
|
for (size_t i = 0; i < mPile->settings.animals.enabled.size(); ++i) {
|
|
|
|
if (mPile->settings.animals.enabled.at(i) == 1) {
|
|
|
|
df::creature_raw* r = find_creature(i);
|
|
|
|
DEBUG(log).print("creature %s %zd\n", r->creature_id.c_str(), i);
|
|
|
|
animals->add_enabled(r->creature_id);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_animals() {
|
|
|
|
if (mBuffer.has_animals()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.animals = 1;
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("animals:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.animals.empty_cages = mBuffer.animals().empty_cages();
|
|
|
|
mPile->settings.animals.empty_traps = mBuffer.animals().empty_traps();
|
|
|
|
|
|
|
|
mPile->settings.animals.enabled.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.animals.enabled.resize(world->raws.creatures.all.size(), '\0');
|
|
|
|
DEBUG(log).print("pile has %zd\n", mPile->settings.animals.enabled.size());
|
|
|
|
for (auto i = 0; i < mBuffer.animals().enabled_size(); ++i) {
|
|
|
|
std::string id = mBuffer.animals().enabled(i);
|
|
|
|
int idx = find_creature(id);
|
|
|
|
DEBUG(log).print("%s %d\n", id.c_str(), idx);
|
|
|
|
if (idx < 0 || size_t(idx) >= mPile->settings.animals.enabled.size()) {
|
|
|
|
WARN(log).print("animal index invalid: %d\n", idx);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.animals.enabled.at(idx) = (char)1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.animals.enabled.clear();
|
|
|
|
mPile->settings.flags.bits.animals = 0;
|
|
|
|
mPile->settings.animals.empty_cages = false;
|
|
|
|
mPile->settings.animals.empty_traps = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
StockpileSerializer::food_pair StockpileSerializer::food_map(organic_mat_category::organic_mat_category cat) {
|
2014-12-02 04:06:01 -07:00
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
|
|
|
using namespace std::placeholders;
|
2023-03-10 15:08:31 -07:00
|
|
|
switch (cat) {
|
2014-12-02 04:06:01 -07:00
|
|
|
case organic_mat_category::Meat:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_meat(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().meat(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.meat, getter, mBuffer.food().meat_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Fish:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_fish(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().fish(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.fish, getter, mBuffer.food().fish_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::UnpreparedFish:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_unprepared_fish(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().unprepared_fish(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.unprepared_fish, getter, mBuffer.food().unprepared_fish_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Eggs:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_egg(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().egg(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.egg, getter, mBuffer.food().egg_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Plants:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_plants(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().plants(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.plants, getter, mBuffer.food().plants_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::PlantDrink:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_drink_plant(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().drink_plant(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.drink_plant, getter, mBuffer.food().drink_plant_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::CreatureDrink:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_drink_animal(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().drink_animal(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.drink_animal, getter, mBuffer.food().drink_animal_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::PlantCheese:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_cheese_plant(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().cheese_plant(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.cheese_plant, getter, mBuffer.food().cheese_plant_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::CreatureCheese:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_cheese_animal(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().cheese_animal(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.cheese_animal, getter, mBuffer.food().cheese_animal_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Seed:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_seeds(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().seeds(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.seeds, getter, mBuffer.food().seeds_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Leaf:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_leaves(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().leaves(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.leaves, getter, mBuffer.food().leaves_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::PlantPowder:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_powder_plant(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().powder_plant(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.powder_plant, getter, mBuffer.food().powder_plant_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::CreaturePowder:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_powder_creature(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().powder_creature(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.powder_creature, getter, mBuffer.food().powder_creature_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Glob:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_glob(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().glob(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.glob, getter, mBuffer.food().glob_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::PlantLiquid:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_liquid_plant(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().liquid_plant(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.liquid_plant, getter, mBuffer.food().liquid_plant_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::CreatureLiquid:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_liquid_animal(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().liquid_animal(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.liquid_animal, getter, mBuffer.food().liquid_animal_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::MiscLiquid:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_liquid_misc(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().liquid_misc(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.liquid_misc, getter, mBuffer.food().liquid_misc_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case organic_mat_category::Paste:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_glob_paste(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().glob_paste(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.glob_paste, getter, mBuffer.food().glob_paste_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Pressed:
|
|
|
|
{
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
mBuffer.mutable_food()->add_glob_pressed(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncReadImport getter = [=](size_t idx) -> std::string { return mBuffer.food().glob_pressed(idx); };
|
|
|
|
return food_pair(setter, &mPile->settings.food.glob_pressed, getter, mBuffer.food().glob_pressed_size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
case organic_mat_category::Leather:
|
|
|
|
case organic_mat_category::Silk:
|
|
|
|
case organic_mat_category::PlantFiber:
|
|
|
|
case organic_mat_category::Bone:
|
|
|
|
case organic_mat_category::Shell:
|
|
|
|
case organic_mat_category::Wood:
|
|
|
|
case organic_mat_category::Horn:
|
|
|
|
case organic_mat_category::Pearl:
|
|
|
|
case organic_mat_category::Tooth:
|
|
|
|
case organic_mat_category::EdibleCheese:
|
|
|
|
case organic_mat_category::AnyDrink:
|
|
|
|
case organic_mat_category::EdiblePlant:
|
|
|
|
case organic_mat_category::CookableLiquid:
|
|
|
|
case organic_mat_category::CookablePowder:
|
|
|
|
case organic_mat_category::CookableSeed:
|
|
|
|
case organic_mat_category::CookableLeaf:
|
|
|
|
case organic_mat_category::Yarn:
|
|
|
|
case organic_mat_category::MetalThread:
|
|
|
|
default:
|
|
|
|
// not used in stockpile food menu
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return food_pair();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_food() {
|
|
|
|
StockpileSettings::FoodSet* food = mBuffer.mutable_food();
|
|
|
|
DEBUG(log).print("food:\n");
|
|
|
|
food->set_prepared_meals(mPile->settings.food.prepared_meals);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
2018-04-06 20:22:48 -06:00
|
|
|
using traits = df::enum_traits<organic_mat_category>;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int32_t mat_category = traits::first_item_value; mat_category < traits::last_item_value; ++mat_category) {
|
|
|
|
food_pair p = food_map((organic_mat_category)mat_category);
|
|
|
|
if (!p.valid)
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("food: %s\n", traits::key_table[mat_category]);
|
|
|
|
serialize_list_organic_mat(p.set_value, p.stockpile_values, (organic_mat_category)mat_category);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_food() {
|
2014-12-02 04:06:01 -07:00
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
2018-04-06 20:22:48 -06:00
|
|
|
using traits = df::enum_traits<organic_mat_category>;
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mBuffer.has_food()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.food = 1;
|
|
|
|
const StockpileSettings::FoodSet food = mBuffer.food();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("food:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
if (food.has_prepared_meals())
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.food.prepared_meals = food.prepared_meals();
|
|
|
|
else
|
|
|
|
mPile->settings.food.prepared_meals = true;
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("prepared_meals: %d\n", mPile->settings.food.prepared_meals);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int32_t mat_category = traits::first_item_value; mat_category < traits::last_item_value; ++mat_category) {
|
|
|
|
food_pair p = food_map((organic_mat_category)mat_category);
|
|
|
|
if (!p.valid)
|
|
|
|
continue;
|
|
|
|
unserialize_list_organic_mat(p.get_value, p.serialized_count, p.stockpile_values, (organic_mat_category)mat_category);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
|
|
|
for (int32_t mat_category = traits::first_item_value; mat_category < traits::last_item_value; ++mat_category) {
|
|
|
|
food_pair p = food_map((organic_mat_category)mat_category);
|
|
|
|
if (!p.valid)
|
|
|
|
continue;
|
2014-12-02 04:06:01 -07:00
|
|
|
p.stockpile_values->clear();
|
|
|
|
}
|
|
|
|
mPile->settings.flags.bits.food = 0;
|
|
|
|
mPile->settings.food.prepared_meals = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::furniture_setup_other_mats() {
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(0, "WOOD"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(1, "PLANT_CLOTH"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(2, "BONE"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(3, "TOOTH"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(4, "HORN"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(5, "PEARL"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(6, "SHELL"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(7, "LEATHER"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(8, "SILK"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(9, "AMBER"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(10, "CORAL"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(11, "GREEN_GLASS"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(12, "CLEAR_GLASS"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(13, "CRYSTAL_GLASS"));
|
|
|
|
mOtherMatsFurniture.insert(std::make_pair(14, "YARN"));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_furniture() {
|
|
|
|
StockpileSettings::FurnitureSet* furniture = mBuffer.mutable_furniture();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// FURNITURE type
|
|
|
|
using df::enums::furniture_type::furniture_type;
|
2018-04-06 20:22:48 -06:00
|
|
|
using type_traits = df::enum_traits<furniture_type>;
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < mPile->settings.furniture.type.size(); ++i) {
|
|
|
|
if (mPile->settings.furniture.type.at(i)) {
|
|
|
|
std::string f_type(type_traits::key_table[i]);
|
|
|
|
furniture->add_type(f_type);
|
|
|
|
DEBUG(log).print("furniture_type %zd is %s\n", i, f_type.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// metal, stone/clay materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::furniture_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { furniture->add_mats(token); },
|
|
|
|
mPile->settings.furniture.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsFurniture, [=](const std::string& token) { furniture->add_other_mats(token); },
|
|
|
|
mPile->settings.furniture.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { furniture->add_quality_core(token); },
|
|
|
|
mPile->settings.furniture.quality_core);
|
|
|
|
serialize_list_quality([=](const std::string& token) { furniture->add_quality_total(token); },
|
|
|
|
mPile->settings.furniture.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::furniture_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && (mi.material->flags.is_set(material_flags::IS_METAL) || mi.material->flags.is_set(material_flags::IS_STONE));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_furniture() {
|
|
|
|
if (mBuffer.has_furniture()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.furniture = 1;
|
|
|
|
const StockpileSettings::FurnitureSet furniture = mBuffer.furniture();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("furniture:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// type
|
|
|
|
using df::enums::furniture_type::furniture_type;
|
|
|
|
df::enum_traits<furniture_type> type_traits;
|
|
|
|
mPile->settings.furniture.type.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.furniture.type.resize(type_traits.last_item_value + 1, '\0');
|
|
|
|
if (furniture.type_size() > 0) {
|
|
|
|
for (int i = 0; i < furniture.type_size(); ++i) {
|
|
|
|
const std::string type = furniture.type(i);
|
|
|
|
df::enum_traits<furniture_type>::base_type idx = linear_index(type_traits, type);
|
|
|
|
DEBUG(log).print("type %d is %s\n", idx, type.c_str());
|
|
|
|
if (idx < 0 || size_t(idx) >= mPile->settings.furniture.type.size()) {
|
|
|
|
WARN(log).print("furniture type index invalid %s, idx=%d\n", type.c_str(), idx);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.furniture.type.at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::furniture_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return furniture.mats(idx); },
|
|
|
|
furniture.mats_size(), &mPile->settings.furniture.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other materials
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsFurniture, [=](const size_t& idx) -> const std::string& { return furniture.other_mats(idx); },
|
|
|
|
furniture.other_mats_size(), &mPile->settings.furniture.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// core quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return furniture.quality_core(idx); },
|
|
|
|
furniture.quality_core_size(), mPile->settings.furniture.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// total quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return furniture.quality_total(idx); },
|
|
|
|
furniture.quality_total_size(), mPile->settings.furniture.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.furniture = 0;
|
|
|
|
mPile->settings.furniture.type.clear();
|
|
|
|
mPile->settings.furniture.other_mats.clear();
|
|
|
|
mPile->settings.furniture.mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
quality_clear(mPile->settings.furniture.quality_core);
|
|
|
|
quality_clear(mPile->settings.furniture.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::refuse_creature_is_allowed(const df::creature_raw* raw) {
|
|
|
|
if (!raw)
|
|
|
|
return false;
|
2014-12-02 04:06:01 -07:00
|
|
|
// wagon and generated creatures not allowed, except angels
|
|
|
|
const bool is_wagon = raw->creature_id == "EQUIPMENT_WAGON";
|
2023-03-10 15:08:31 -07:00
|
|
|
const bool is_generated = raw->flags.is_set(creature_raw_flags::GENERATED);
|
|
|
|
const bool is_angel = is_generated && raw->creature_id.find("DIVINE_") != std::string::npos;
|
|
|
|
return !is_wagon && !(is_generated && !is_angel);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::refuse_write_helper(std::function<void(const string&)> add_value, const vector<char>& list) {
|
|
|
|
for (size_t i = 0; i < list.size(); ++i) {
|
|
|
|
if (list.at(i) == 1) {
|
|
|
|
df::creature_raw* r = find_creature(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
// skip forgotten beasts, titans, demons, and night creatures
|
2023-03-10 15:08:31 -07:00
|
|
|
if (!refuse_creature_is_allowed(r))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("creature %s %zd\n", r->creature_id.c_str(), i);
|
|
|
|
add_value(r->creature_id);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::refuse_type_is_allowed(item_type::item_type type) {
|
|
|
|
if (type == item_type::NONE || type == item_type::BAR || type == item_type::SMALLGEM || type == item_type::BLOCKS || type == item_type::ROUGH || type == item_type::BOULDER || type == item_type::CORPSE || type == item_type::CORPSEPIECE || type == item_type::ROCK || type == item_type::ORTHOPEDIC_CAST)
|
|
|
|
return false;
|
2014-12-02 04:06:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_refuse() {
|
|
|
|
DEBUG(log).print("refuse:\n");
|
|
|
|
StockpileSettings::RefuseSet* refuse = mBuffer.mutable_refuse();
|
|
|
|
refuse->set_fresh_raw_hide(mPile->settings.refuse.fresh_raw_hide);
|
|
|
|
refuse->set_rotten_raw_hide(mPile->settings.refuse.rotten_raw_hide);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// type
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("getting types\n");
|
|
|
|
FuncItemAllowed filter = std::bind(&StockpileSerializer::refuse_type_is_allowed, this, _1);
|
|
|
|
serialize_list_item_type(
|
|
|
|
filter, [=](const std::string& token) {
|
|
|
|
DEBUG(log).print("adding type: %s\n", token.c_str());
|
|
|
|
refuse->add_type(token);
|
|
|
|
},
|
|
|
|
mPile->settings.refuse.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// corpses
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_corpses(id); },
|
|
|
|
mPile->settings.refuse.corpses);
|
2014-12-02 04:06:01 -07:00
|
|
|
// body_parts
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_body_parts(id); },
|
|
|
|
mPile->settings.refuse.body_parts);
|
2014-12-02 04:06:01 -07:00
|
|
|
// skulls
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_skulls(id); },
|
|
|
|
mPile->settings.refuse.skulls);
|
2014-12-02 04:06:01 -07:00
|
|
|
// bones
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_bones(id); },
|
|
|
|
mPile->settings.refuse.bones);
|
2014-12-02 04:06:01 -07:00
|
|
|
// hair
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_hair(id); },
|
|
|
|
mPile->settings.refuse.hair);
|
2014-12-02 04:06:01 -07:00
|
|
|
// shells
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_shells(id); },
|
|
|
|
mPile->settings.refuse.shells);
|
2014-12-02 04:06:01 -07:00
|
|
|
// teeth
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_teeth(id); },
|
|
|
|
mPile->settings.refuse.teeth);
|
2014-12-02 04:06:01 -07:00
|
|
|
// horns
|
2023-03-10 15:08:31 -07:00
|
|
|
refuse_write_helper([=](const std::string& id) { refuse->add_horns(id); },
|
|
|
|
mPile->settings.refuse.horns);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::refuse_read_helper(std::function<std::string(const size_t&)> get_value, size_t list_size, std::vector<char>* pile_list) {
|
2014-12-02 04:06:01 -07:00
|
|
|
pile_list->clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
pile_list->resize(world->raws.creatures.all.size(), '\0');
|
|
|
|
if (list_size > 0) {
|
|
|
|
for (size_t i = 0; i < list_size; ++i) {
|
|
|
|
const std::string creature_id = get_value(i);
|
|
|
|
const int idx = find_creature(creature_id);
|
|
|
|
const df::creature_raw* creature = find_creature(idx);
|
|
|
|
if (idx < 0 || !refuse_creature_is_allowed(creature) || size_t(idx) >= pile_list->size()) {
|
|
|
|
WARN(log).print("invalid refuse creature %s, idx=%d\n", creature_id.c_str(), idx);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("creature %d is %s\n", idx, creature_id.c_str());
|
|
|
|
pile_list->at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_refuse() {
|
|
|
|
if (mBuffer.has_refuse()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.refuse = 1;
|
|
|
|
const StockpileSettings::RefuseSet refuse = mBuffer.refuse();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("refuse:\n");
|
|
|
|
DEBUG(log).print(" fresh hide %d\n", refuse.fresh_raw_hide());
|
|
|
|
DEBUG(log).print(" rotten hide %d\n", refuse.rotten_raw_hide());
|
|
|
|
mPile->settings.refuse.fresh_raw_hide = refuse.fresh_raw_hide();
|
|
|
|
mPile->settings.refuse.rotten_raw_hide = refuse.rotten_raw_hide();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// type
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncItemAllowed filter = std::bind(&StockpileSerializer::refuse_type_is_allowed, this, _1);
|
|
|
|
unserialize_list_item_type(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return refuse.type(idx); },
|
|
|
|
refuse.type_size(), &mPile->settings.refuse.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// corpses
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" corpses\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.corpses(idx); },
|
|
|
|
refuse.corpses_size(), &mPile->settings.refuse.corpses);
|
2014-12-02 04:06:01 -07:00
|
|
|
// body_parts
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" body_parts\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.body_parts(idx); },
|
|
|
|
refuse.body_parts_size(), &mPile->settings.refuse.body_parts);
|
2014-12-02 04:06:01 -07:00
|
|
|
// skulls
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" skulls\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.skulls(idx); },
|
|
|
|
refuse.skulls_size(), &mPile->settings.refuse.skulls);
|
2014-12-02 04:06:01 -07:00
|
|
|
// bones
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" bones\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.bones(idx); },
|
|
|
|
refuse.bones_size(), &mPile->settings.refuse.bones);
|
2014-12-02 04:06:01 -07:00
|
|
|
// hair
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" hair\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.hair(idx); },
|
|
|
|
refuse.hair_size(), &mPile->settings.refuse.hair);
|
2014-12-02 04:06:01 -07:00
|
|
|
// shells
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" shells\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.shells(idx); },
|
|
|
|
refuse.shells_size(), &mPile->settings.refuse.shells);
|
2014-12-02 04:06:01 -07:00
|
|
|
// teeth
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" teeth\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.teeth(idx); },
|
|
|
|
refuse.teeth_size(), &mPile->settings.refuse.teeth);
|
2014-12-02 04:06:01 -07:00
|
|
|
// horns
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print(" horns\n");
|
|
|
|
refuse_read_helper([=](const size_t& idx) -> const std::string& { return refuse.horns(idx); },
|
|
|
|
refuse.horns_size(), &mPile->settings.refuse.horns);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.refuse = 0;
|
|
|
|
mPile->settings.refuse.type.clear();
|
|
|
|
mPile->settings.refuse.corpses.clear();
|
|
|
|
mPile->settings.refuse.body_parts.clear();
|
|
|
|
mPile->settings.refuse.skulls.clear();
|
|
|
|
mPile->settings.refuse.bones.clear();
|
|
|
|
mPile->settings.refuse.hair.clear();
|
|
|
|
mPile->settings.refuse.shells.clear();
|
|
|
|
mPile->settings.refuse.teeth.clear();
|
|
|
|
mPile->settings.refuse.horns.clear();
|
|
|
|
mPile->settings.refuse.fresh_raw_hide = false;
|
|
|
|
mPile->settings.refuse.rotten_raw_hide = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::stone_is_allowed(const MaterialInfo& mi) {
|
|
|
|
if (!mi.isValid())
|
|
|
|
return false;
|
|
|
|
const bool is_allowed_soil = mi.inorganic->flags.is_set(inorganic_flags::SOIL) && !mi.inorganic->flags.is_set(inorganic_flags::AQUIFER);
|
|
|
|
const bool is_allowed_stone = mi.material->flags.is_set(material_flags::IS_STONE) && !mi.material->flags.is_set(material_flags::NO_STONE_STOCKPILE);
|
|
|
|
return is_allowed_soil || is_allowed_stone;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_stone() {
|
|
|
|
StockpileSettings::StoneSet* stone = mBuffer.mutable_stone();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::stone_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { stone->add_mats(token); },
|
|
|
|
mPile->settings.stone.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_stone() {
|
|
|
|
if (mBuffer.has_stone()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.stone = 1;
|
|
|
|
const StockpileSettings::StoneSet stone = mBuffer.stone();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("stone:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::stone_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return stone.mats(idx); },
|
|
|
|
stone.mats_size(), &mPile->settings.stone.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.stone = 0;
|
|
|
|
mPile->settings.stone.mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::ammo_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set(material_flags::IS_METAL);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_ammo() {
|
|
|
|
StockpileSettings::AmmoSet* ammo = mBuffer.mutable_ammo();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// ammo type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { ammo->add_type(token); },
|
|
|
|
mPile->settings.ammo.type,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.ammo.begin(), world->raws.itemdefs.ammo.end()),
|
|
|
|
item_type::AMMO);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// metal
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::ammo_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { ammo->add_mats(token); },
|
|
|
|
mPile->settings.ammo.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats - only wood and bone
|
2023-03-10 15:08:31 -07:00
|
|
|
if (mPile->settings.ammo.other_mats.size() > 2) {
|
|
|
|
WARN(log).print("ammo other materials > 2: %zd\n", mPile->settings.ammo.other_mats.size());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < std::min(size_t(2), mPile->settings.ammo.other_mats.size()); ++i) {
|
|
|
|
if (!mPile->settings.ammo.other_mats.at(i))
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
2023-03-10 15:08:31 -07:00
|
|
|
const std::string token = i == 0 ? "WOOD" : "BONE";
|
|
|
|
ammo->add_other_mats(token);
|
|
|
|
DEBUG(log).print(" other mats %zd is %s\n", i, token.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quality core
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { ammo->add_quality_core(token); },
|
|
|
|
mPile->settings.ammo.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality total
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { ammo->add_quality_total(token); },
|
|
|
|
mPile->settings.ammo.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_ammo() {
|
|
|
|
if (mBuffer.has_ammo()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.ammo = 1;
|
|
|
|
const StockpileSettings::AmmoSet ammo = mBuffer.ammo();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("ammo:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// ammo type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return ammo.type(idx); },
|
|
|
|
ammo.type_size(), &mPile->settings.ammo.type, item_type::AMMO);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials metals
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::ammo_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return ammo.mats(idx); },
|
|
|
|
ammo.mats_size(), &mPile->settings.ammo.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// others
|
|
|
|
mPile->settings.ammo.other_mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.ammo.other_mats.resize(2, '\0');
|
|
|
|
if (ammo.other_mats_size() > 0) {
|
2014-12-02 04:06:01 -07:00
|
|
|
// TODO remove hardcoded value
|
2023-03-10 15:08:31 -07:00
|
|
|
for (int i = 0; i < ammo.other_mats_size(); ++i) {
|
|
|
|
const std::string token = ammo.other_mats(i);
|
|
|
|
const int32_t idx = token == "WOOD" ? 0 : token == "BONE" ? 1
|
|
|
|
: -1;
|
|
|
|
DEBUG(log).print("other mats %d is %s\n", idx, token.c_str());
|
|
|
|
if (idx != -1)
|
|
|
|
mPile->settings.ammo.other_mats.at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// core quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return ammo.quality_core(idx); },
|
|
|
|
ammo.quality_core_size(), mPile->settings.ammo.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// total quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return ammo.quality_total(idx); },
|
|
|
|
ammo.quality_total_size(), mPile->settings.ammo.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.ammo = 0;
|
|
|
|
mPile->settings.ammo.type.clear();
|
|
|
|
mPile->settings.ammo.mats.clear();
|
|
|
|
mPile->settings.ammo.other_mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
quality_clear(mPile->settings.ammo.quality_core);
|
|
|
|
quality_clear(mPile->settings.ammo.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::coins_mat_is_allowed(const MaterialInfo& mi) {
|
2014-12-02 04:06:01 -07:00
|
|
|
return mi.isValid();
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_coins() {
|
|
|
|
StockpileSettings::CoinSet* coins = mBuffer.mutable_coin();
|
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::coins_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { coins->add_mats(token); },
|
|
|
|
mPile->settings.coins.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_coins() {
|
|
|
|
if (mBuffer.has_coin()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.coins = 1;
|
|
|
|
const StockpileSettings::CoinSet coins = mBuffer.coin();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("coins:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::coins_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return coins.mats(idx); },
|
|
|
|
coins.mats_size(), &mPile->settings.coins.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.coins = 0;
|
|
|
|
mPile->settings.coins.mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::bars_blocks_setup_other_mats() {
|
|
|
|
mOtherMatsBars.insert(std::make_pair(0, "COAL"));
|
|
|
|
mOtherMatsBars.insert(std::make_pair(1, "POTASH"));
|
|
|
|
mOtherMatsBars.insert(std::make_pair(2, "ASH"));
|
|
|
|
mOtherMatsBars.insert(std::make_pair(3, "PEARLASH"));
|
|
|
|
mOtherMatsBars.insert(std::make_pair(4, "SOAP"));
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
mOtherMatsBlocks.insert(std::make_pair(0, "GREEN_GLASS"));
|
|
|
|
mOtherMatsBlocks.insert(std::make_pair(1, "CLEAR_GLASS"));
|
|
|
|
mOtherMatsBlocks.insert(std::make_pair(2, "CRYSTAL_GLASS"));
|
|
|
|
mOtherMatsBlocks.insert(std::make_pair(3, "WOOD"));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::bars_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set(material_flags::IS_METAL);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::blocks_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && (mi.material->flags.is_set(material_flags::IS_METAL) || mi.material->flags.is_set(material_flags::IS_STONE));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_bars_blocks() {
|
|
|
|
StockpileSettings::BarsBlocksSet* bars_blocks = mBuffer.mutable_barsblocks();
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::bars_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { bars_blocks->add_bars_mats(token); },
|
|
|
|
mPile->settings.bars_blocks.bars_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// blocks mats
|
2023-03-10 15:08:31 -07:00
|
|
|
filter = std::bind(&StockpileSerializer::blocks_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter, [=](const std::string& token) { bars_blocks->add_blocks_mats(token); },
|
|
|
|
mPile->settings.bars_blocks.blocks_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// bars other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsBars, [=](const std::string& token) { bars_blocks->add_bars_other_mats(token); },
|
|
|
|
mPile->settings.bars_blocks.bars_other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// blocks other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsBlocks, [=](const std::string& token) { bars_blocks->add_blocks_other_mats(token); },
|
|
|
|
mPile->settings.bars_blocks.blocks_other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_bars_blocks() {
|
|
|
|
if (mBuffer.has_barsblocks()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.bars_blocks = 1;
|
|
|
|
const StockpileSettings::BarsBlocksSet bars_blocks = mBuffer.barsblocks();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("bars_blocks:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
// bars
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind(&StockpileSerializer::bars_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return bars_blocks.bars_mats(idx); },
|
|
|
|
bars_blocks.bars_mats_size(), &mPile->settings.bars_blocks.bars_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// blocks
|
2023-03-10 15:08:31 -07:00
|
|
|
filter = std::bind(&StockpileSerializer::blocks_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return bars_blocks.blocks_mats(idx); },
|
|
|
|
bars_blocks.blocks_mats_size(), &mPile->settings.bars_blocks.blocks_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
// bars other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsBars, [=](const size_t& idx) -> const std::string& { return bars_blocks.bars_other_mats(idx); },
|
|
|
|
bars_blocks.bars_other_mats_size(), &mPile->settings.bars_blocks.bars_other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// blocks other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsBlocks, [=](const size_t& idx) -> const std::string& { return bars_blocks.blocks_other_mats(idx); },
|
|
|
|
bars_blocks.blocks_other_mats_size(), &mPile->settings.bars_blocks.blocks_other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.bars_blocks = 0;
|
|
|
|
mPile->settings.bars_blocks.bars_other_mats.clear();
|
|
|
|
mPile->settings.bars_blocks.bars_mats.clear();
|
|
|
|
mPile->settings.bars_blocks.blocks_other_mats.clear();
|
|
|
|
mPile->settings.bars_blocks.blocks_mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::gem_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set(material_flags::IS_GEM);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::gem_cut_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && (mi.material->flags.is_set(material_flags::IS_GEM) || mi.material->flags.is_set(material_flags::IS_STONE));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::gem_other_mat_is_allowed(MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && (mi.getToken() == "GLASS_GREEN" || mi.getToken() == "GLASS_CLEAR" || mi.getToken() == "GLASS_CRYSTAL");
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_gems() {
|
|
|
|
StockpileSettings::GemsSet* gems = mBuffer.mutable_gems();
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
|
|
|
// rough mats
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter_rough = std::bind(&StockpileSerializer::gem_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter_rough, [=](const std::string& token) { gems->add_rough_mats(token); },
|
|
|
|
mPile->settings.gems.rough_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
// cut mats
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter_cut = std::bind(&StockpileSerializer::gem_cut_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
filter_cut, [=](const std::string& token) { gems->add_cut_mats(token); },
|
|
|
|
mPile->settings.gems.cut_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
// rough other
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < mPile->settings.gems.rough_other_mats.size(); ++i) {
|
|
|
|
if (mPile->settings.gems.rough_other_mats.at(i)) {
|
|
|
|
mi.decode(i, -1);
|
|
|
|
if (!gem_other_mat_is_allowed(mi))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("gem rough_other mat %zd is %s\n", i, mi.getToken().c_str());
|
|
|
|
gems->add_rough_other_mats(mi.getToken());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// cut other
|
2023-03-10 15:08:31 -07:00
|
|
|
for (size_t i = 0; i < mPile->settings.gems.cut_other_mats.size(); ++i) {
|
|
|
|
if (mPile->settings.gems.cut_other_mats.at(i)) {
|
|
|
|
mi.decode(i, -1);
|
|
|
|
if (!mi.isValid())
|
|
|
|
mi.decode(0, i);
|
|
|
|
if (!gem_other_mat_is_allowed(mi))
|
|
|
|
continue;
|
|
|
|
DEBUG(log).print("gem cut_other mat %zd is %s\n", i, mi.getToken().c_str());
|
|
|
|
gems->add_cut_other_mats(mi.getToken());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_gems() {
|
|
|
|
if (mBuffer.has_gems()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.gems = 1;
|
|
|
|
const StockpileSettings::GemsSet gems = mBuffer.gems();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("gems:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
// rough
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter_rough = std::bind(&StockpileSerializer::gem_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter_rough, [=](const size_t& idx) -> const std::string& { return gems.rough_mats(idx); },
|
|
|
|
gems.rough_mats_size(), &mPile->settings.gems.rough_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// cut
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed filter_cut = std::bind(&StockpileSerializer::gem_cut_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
filter_cut, [=](const size_t& idx) -> const std::string& { return gems.cut_mats(idx); },
|
|
|
|
gems.cut_mats_size(), &mPile->settings.gems.cut_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
const size_t builtin_size = std::extent<decltype(world->raws.mat_table.builtin)>::value;
|
2014-12-02 04:06:01 -07:00
|
|
|
// rough other
|
|
|
|
mPile->settings.gems.rough_other_mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.gems.rough_other_mats.resize(builtin_size, '\0');
|
|
|
|
for (int i = 0; i < gems.rough_other_mats_size(); ++i) {
|
|
|
|
const std::string token = gems.rough_other_mats(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
2023-03-10 15:08:31 -07:00
|
|
|
mi.find(token);
|
|
|
|
if (!mi.isValid() || size_t(mi.type) >= builtin_size) {
|
|
|
|
WARN(log).print("invalid gem mat %s idx=%d\n", token.c_str(), mi.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("rough_other mats %d is %s\n", mi.type, token.c_str());
|
|
|
|
mPile->settings.gems.rough_other_mats.at(mi.type) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// cut other
|
|
|
|
mPile->settings.gems.cut_other_mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.gems.cut_other_mats.resize(builtin_size, '\0');
|
|
|
|
for (int i = 0; i < gems.cut_other_mats_size(); ++i) {
|
|
|
|
const std::string token = gems.cut_other_mats(i);
|
2014-12-02 04:06:01 -07:00
|
|
|
MaterialInfo mi;
|
2023-03-10 15:08:31 -07:00
|
|
|
mi.find(token);
|
|
|
|
if (!mi.isValid() || size_t(mi.type) >= builtin_size) {
|
|
|
|
WARN(log).print("invalid gem mat %s idx=%d\n", token.c_str(), mi.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("cut_other mats %d is %s\n", mi.type, token.c_str());
|
|
|
|
mPile->settings.gems.cut_other_mats.at(mi.type) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.gems = 0;
|
|
|
|
mPile->settings.gems.cut_other_mats.clear();
|
|
|
|
mPile->settings.gems.cut_mats.clear();
|
|
|
|
mPile->settings.gems.rough_other_mats.clear();
|
|
|
|
mPile->settings.gems.rough_mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::finished_goods_type_is_allowed(item_type::item_type type) {
|
|
|
|
switch (type) {
|
2014-12-02 04:06:01 -07:00
|
|
|
case item_type::CHAIN:
|
|
|
|
case item_type::FLASK:
|
|
|
|
case item_type::GOBLET:
|
|
|
|
case item_type::INSTRUMENT:
|
|
|
|
case item_type::TOY:
|
|
|
|
case item_type::ARMOR:
|
|
|
|
case item_type::SHOES:
|
|
|
|
case item_type::HELM:
|
|
|
|
case item_type::GLOVES:
|
|
|
|
case item_type::FIGURINE:
|
|
|
|
case item_type::AMULET:
|
|
|
|
case item_type::SCEPTER:
|
|
|
|
case item_type::CROWN:
|
|
|
|
case item_type::RING:
|
|
|
|
case item_type::EARRING:
|
|
|
|
case item_type::BRACELET:
|
|
|
|
case item_type::GEM:
|
|
|
|
case item_type::TOTEM:
|
|
|
|
case item_type::PANTS:
|
|
|
|
case item_type::BACKPACK:
|
|
|
|
case item_type::QUIVER:
|
|
|
|
case item_type::SPLINT:
|
|
|
|
case item_type::CRUTCH:
|
|
|
|
case item_type::TOOL:
|
|
|
|
case item_type::BOOK:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::finished_goods_setup_other_mats() {
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(0, "WOOD"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(1, "PLANT_CLOTH"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(2, "BONE"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(3, "TOOTH"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(4, "HORN"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(5, "PEARL"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(6, "SHELL"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(7, "LEATHER"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(8, "SILK"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(9, "AMBER"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(10, "CORAL"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(11, "GREEN_GLASS"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(12, "CLEAR_GLASS"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(13, "CRYSTAL_GLASS"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(14, "YARN"));
|
|
|
|
mOtherMatsFinishedGoods.insert(std::make_pair(15, "WAX"));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::finished_goods_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && (mi.material->flags.is_set(material_flags::IS_GEM) || mi.material->flags.is_set(material_flags::IS_METAL) || mi.material->flags.is_set(material_flags::IS_STONE));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_finished_goods() {
|
|
|
|
StockpileSettings::FinishedGoodsSet* finished_goods = mBuffer.mutable_finished_goods();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// type
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncItemAllowed filter = std::bind(&StockpileSerializer::finished_goods_type_is_allowed, this, _1);
|
|
|
|
serialize_list_item_type(
|
|
|
|
filter, [=](const std::string& token) { finished_goods->add_type(token); },
|
|
|
|
mPile->settings.finished_goods.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::finished_goods_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
mat_filter, [=](const std::string& token) { finished_goods->add_mats(token); },
|
|
|
|
mPile->settings.finished_goods.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsFinishedGoods, [=](const std::string& token) { finished_goods->add_other_mats(token); },
|
|
|
|
mPile->settings.finished_goods.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality core
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { finished_goods->add_quality_core(token); },
|
|
|
|
mPile->settings.finished_goods.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality total
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { finished_goods->add_quality_total(token); },
|
|
|
|
mPile->settings.finished_goods.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_finished_goods() {
|
|
|
|
if (mBuffer.has_finished_goods()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.finished_goods = 1;
|
|
|
|
const StockpileSettings::FinishedGoodsSet finished_goods = mBuffer.finished_goods();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("finished_goods:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// type
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncItemAllowed filter = std::bind(&StockpileSerializer::finished_goods_type_is_allowed, this, _1);
|
|
|
|
unserialize_list_item_type(
|
|
|
|
filter, [=](const size_t& idx) -> const std::string& { return finished_goods.type(idx); },
|
|
|
|
finished_goods.type_size(), &mPile->settings.finished_goods.type);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::finished_goods_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
mat_filter, [=](const size_t& idx) -> const std::string& { return finished_goods.mats(idx); },
|
|
|
|
finished_goods.mats_size(), &mPile->settings.finished_goods.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsFinishedGoods, [=](const size_t& idx) -> const std::string& { return finished_goods.other_mats(idx); },
|
|
|
|
finished_goods.other_mats_size(), &mPile->settings.finished_goods.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// core quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return finished_goods.quality_core(idx); },
|
|
|
|
finished_goods.quality_core_size(), mPile->settings.finished_goods.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// total quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return finished_goods.quality_total(idx); },
|
|
|
|
finished_goods.quality_total_size(), mPile->settings.finished_goods.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.finished_goods = 0;
|
|
|
|
mPile->settings.finished_goods.type.clear();
|
|
|
|
mPile->settings.finished_goods.other_mats.clear();
|
|
|
|
mPile->settings.finished_goods.mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
quality_clear(mPile->settings.finished_goods.quality_core);
|
|
|
|
quality_clear(mPile->settings.finished_goods.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_leather() {
|
|
|
|
StockpileSettings::LeatherSet* leather = mBuffer.mutable_leather();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncWriteExport setter = [=](const std::string& id) {
|
|
|
|
leather->add_mats(id);
|
2014-12-02 04:06:01 -07:00
|
|
|
};
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat(setter, &mPile->settings.leather.mats, organic_mat_category::Leather);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_leather() {
|
|
|
|
if (mBuffer.has_leather()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.leather = 1;
|
|
|
|
const StockpileSettings::LeatherSet leather = mBuffer.leather();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("leather:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return leather.mats(idx); },
|
|
|
|
leather.mats_size(), &mPile->settings.leather.mats, organic_mat_category::Leather);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.leather = 0;
|
|
|
|
mPile->settings.leather.mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_cloth() {
|
|
|
|
StockpileSettings::ClothSet* cloth = mBuffer.mutable_cloth();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_thread_silk(token); },
|
|
|
|
&mPile->settings.cloth.thread_silk, organic_mat_category::Silk);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_thread_plant(token); },
|
|
|
|
&mPile->settings.cloth.thread_plant, organic_mat_category::PlantFiber);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_thread_yarn(token); },
|
|
|
|
&mPile->settings.cloth.thread_yarn, organic_mat_category::Yarn);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_thread_metal(token); },
|
|
|
|
&mPile->settings.cloth.thread_metal, organic_mat_category::MetalThread);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_cloth_silk(token); },
|
|
|
|
&mPile->settings.cloth.cloth_silk, organic_mat_category::Silk);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_cloth_plant(token); },
|
|
|
|
&mPile->settings.cloth.cloth_plant, organic_mat_category::PlantFiber);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_cloth_yarn(token); },
|
|
|
|
&mPile->settings.cloth.cloth_yarn, organic_mat_category::Yarn);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_organic_mat([=](const std::string& token) { cloth->add_cloth_metal(token); },
|
|
|
|
&mPile->settings.cloth.cloth_metal, organic_mat_category::MetalThread);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_cloth() {
|
|
|
|
if (mBuffer.has_cloth()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.cloth = 1;
|
|
|
|
const StockpileSettings::ClothSet cloth = mBuffer.cloth();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("cloth:\n");
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.thread_silk(idx); },
|
|
|
|
cloth.thread_silk_size(), &mPile->settings.cloth.thread_silk, organic_mat_category::Silk);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.thread_plant(idx); },
|
|
|
|
cloth.thread_plant_size(), &mPile->settings.cloth.thread_plant, organic_mat_category::PlantFiber);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.thread_yarn(idx); },
|
|
|
|
cloth.thread_yarn_size(), &mPile->settings.cloth.thread_yarn, organic_mat_category::Yarn);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.thread_metal(idx); },
|
|
|
|
cloth.thread_metal_size(), &mPile->settings.cloth.thread_metal, organic_mat_category::MetalThread);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.cloth_silk(idx); },
|
|
|
|
cloth.cloth_silk_size(), &mPile->settings.cloth.cloth_silk, organic_mat_category::Silk);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.cloth_plant(idx); },
|
|
|
|
cloth.cloth_plant_size(), &mPile->settings.cloth.cloth_plant, organic_mat_category::PlantFiber);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.cloth_yarn(idx); },
|
|
|
|
cloth.cloth_yarn_size(), &mPile->settings.cloth.cloth_yarn, organic_mat_category::Yarn);
|
|
|
|
|
|
|
|
unserialize_list_organic_mat([=](size_t idx) -> std::string { return cloth.cloth_metal(idx); },
|
|
|
|
cloth.cloth_metal_size(), &mPile->settings.cloth.cloth_metal, organic_mat_category::MetalThread);
|
|
|
|
}
|
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.cloth.thread_metal.clear();
|
|
|
|
mPile->settings.cloth.thread_plant.clear();
|
|
|
|
mPile->settings.cloth.thread_silk.clear();
|
|
|
|
mPile->settings.cloth.thread_yarn.clear();
|
|
|
|
mPile->settings.cloth.cloth_metal.clear();
|
|
|
|
mPile->settings.cloth.cloth_plant.clear();
|
|
|
|
mPile->settings.cloth.cloth_silk.clear();
|
|
|
|
mPile->settings.cloth.cloth_yarn.clear();
|
|
|
|
mPile->settings.flags.bits.cloth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::wood_mat_is_allowed(const df::plant_raw* plant) {
|
|
|
|
return plant && plant->flags.is_set(plant_raw_flags::TREE);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_wood() {
|
|
|
|
StockpileSettings::WoodSet* wood = mBuffer.mutable_wood();
|
|
|
|
for (size_t i = 0; i < mPile->settings.wood.mats.size(); ++i) {
|
|
|
|
if (mPile->settings.wood.mats.at(i)) {
|
|
|
|
const df::plant_raw* plant = find_plant(i);
|
|
|
|
if (!wood_mat_is_allowed(plant))
|
|
|
|
continue;
|
|
|
|
wood->add_mats(plant->id);
|
|
|
|
DEBUG(log).print("plant %zd is %s\n", i, plant->id.c_str());
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_wood() {
|
|
|
|
if (mBuffer.has_wood()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.wood = 1;
|
|
|
|
const StockpileSettings::WoodSet wood = mBuffer.wood();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("wood: \n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
mPile->settings.wood.mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
mPile->settings.wood.mats.resize(world->raws.plants.all.size(), '\0');
|
|
|
|
for (int i = 0; i < wood.mats_size(); ++i) {
|
|
|
|
const std::string token = wood.mats(i);
|
|
|
|
const size_t idx = find_plant(token);
|
|
|
|
if (idx < 0 || idx >= mPile->settings.wood.mats.size()) {
|
|
|
|
WARN(log).print("wood mat index invalid %s idx=%zd\n", token.c_str(), idx);
|
2014-12-02 04:06:01 -07:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("plant %zd is %s\n", idx, token.c_str());
|
|
|
|
mPile->settings.wood.mats.at(idx) = 1;
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.wood = 0;
|
|
|
|
mPile->settings.wood.mats.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::weapons_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && (mi.material->flags.is_set(material_flags::IS_METAL) || mi.material->flags.is_set(material_flags::IS_STONE));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_weapons() {
|
|
|
|
StockpileSettings::WeaponsSet* weapons = mBuffer.mutable_weapons();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
weapons->set_unusable(mPile->settings.weapons.unusable);
|
|
|
|
weapons->set_usable(mPile->settings.weapons.usable);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// weapon type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { weapons->add_weapon_type(token); },
|
|
|
|
mPile->settings.weapons.weapon_type,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.weapons.begin(), world->raws.itemdefs.weapons.end()),
|
|
|
|
item_type::WEAPON);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// trapcomp type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { weapons->add_trapcomp_type(token); },
|
|
|
|
mPile->settings.weapons.trapcomp_type,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.trapcomps.begin(), world->raws.itemdefs.trapcomps.end()),
|
|
|
|
item_type::TRAPCOMP);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::weapons_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
mat_filter, [=](const std::string& token) { weapons->add_mats(token); },
|
|
|
|
mPile->settings.weapons.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsWeaponsArmor, [=](const std::string& token) { weapons->add_other_mats(token); },
|
|
|
|
mPile->settings.weapons.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality core
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { weapons->add_quality_core(token); },
|
|
|
|
mPile->settings.weapons.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality total
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { weapons->add_quality_total(token); },
|
|
|
|
mPile->settings.weapons.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_weapons() {
|
|
|
|
if (mBuffer.has_weapons()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.weapons = 1;
|
|
|
|
const StockpileSettings::WeaponsSet weapons = mBuffer.weapons();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("weapons: \n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
bool unusable = weapons.unusable();
|
|
|
|
bool usable = weapons.usable();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("unusable %d\n", unusable);
|
|
|
|
DEBUG(log).print("usable %d\n", usable);
|
2018-06-14 13:18:15 -06:00
|
|
|
mPile->settings.weapons.unusable = unusable;
|
|
|
|
mPile->settings.weapons.usable = usable;
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// weapon type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return weapons.weapon_type(idx); },
|
|
|
|
weapons.weapon_type_size(), &mPile->settings.weapons.weapon_type, item_type::WEAPON);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// trapcomp type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return weapons.trapcomp_type(idx); },
|
|
|
|
weapons.trapcomp_type_size(), &mPile->settings.weapons.trapcomp_type, item_type::TRAPCOMP);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::weapons_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
mat_filter, [=](const size_t& idx) -> const std::string& { return weapons.mats(idx); },
|
|
|
|
weapons.mats_size(), &mPile->settings.weapons.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsWeaponsArmor, [=](const size_t& idx) -> const std::string& { return weapons.other_mats(idx); },
|
|
|
|
weapons.other_mats_size(), &mPile->settings.weapons.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// core quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return weapons.quality_core(idx); },
|
|
|
|
weapons.quality_core_size(), mPile->settings.weapons.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
// total quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return weapons.quality_total(idx); },
|
|
|
|
weapons.quality_total_size(), mPile->settings.weapons.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.weapons = 0;
|
|
|
|
mPile->settings.weapons.weapon_type.clear();
|
|
|
|
mPile->settings.weapons.trapcomp_type.clear();
|
|
|
|
mPile->settings.weapons.other_mats.clear();
|
|
|
|
mPile->settings.weapons.mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
quality_clear(mPile->settings.weapons.quality_core);
|
|
|
|
quality_clear(mPile->settings.weapons.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::weapons_armor_setup_other_mats() {
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(0, "WOOD"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(1, "PLANT_CLOTH"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(2, "BONE"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(3, "SHELL"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(4, "LEATHER"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(5, "SILK"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(6, "GREEN_GLASS"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(7, "CLEAR_GLASS"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(8, "CRYSTAL_GLASS"));
|
|
|
|
mOtherMatsWeaponsArmor.insert(std::make_pair(9, "YARN"));
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
bool StockpileSerializer::armor_mat_is_allowed(const MaterialInfo& mi) {
|
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set(material_flags::IS_METAL);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::write_armor() {
|
|
|
|
StockpileSettings::ArmorSet* armor = mBuffer.mutable_armor();
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
armor->set_unusable(mPile->settings.armor.unusable);
|
|
|
|
armor->set_usable(mPile->settings.armor.usable);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// armor type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_body(token); },
|
|
|
|
mPile->settings.armor.body,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.armor.begin(), world->raws.itemdefs.armor.end()),
|
|
|
|
item_type::ARMOR);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// helm type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_head(token); },
|
|
|
|
mPile->settings.armor.head,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.helms.begin(), world->raws.itemdefs.helms.end()),
|
|
|
|
item_type::HELM);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// shoes type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_feet(token); },
|
|
|
|
mPile->settings.armor.feet,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.shoes.begin(), world->raws.itemdefs.shoes.end()),
|
|
|
|
item_type::SHOES);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// gloves type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_hands(token); },
|
|
|
|
mPile->settings.armor.hands,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.gloves.begin(), world->raws.itemdefs.gloves.end()),
|
|
|
|
item_type::GLOVES);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// pant type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_legs(token); },
|
|
|
|
mPile->settings.armor.legs,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.pants.begin(), world->raws.itemdefs.pants.end()),
|
|
|
|
item_type::PANTS);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// shield type
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_itemdef([=](const std::string& token) { armor->add_shield(token); },
|
|
|
|
mPile->settings.armor.shield,
|
|
|
|
std::vector<df::itemdef*>(world->raws.itemdefs.shields.begin(), world->raws.itemdefs.shields.end()),
|
|
|
|
item_type::SHIELD);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::armor_mat_is_allowed, this, _1);
|
|
|
|
serialize_list_material(
|
|
|
|
mat_filter, [=](const std::string& token) { armor->add_mats(token); },
|
|
|
|
mPile->settings.armor.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_other_mats(
|
|
|
|
mOtherMatsWeaponsArmor, [=](const std::string& token) { armor->add_other_mats(token); },
|
|
|
|
mPile->settings.armor.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality core
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { armor->add_quality_core(token); },
|
|
|
|
mPile->settings.armor.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// quality total
|
2023-03-10 15:08:31 -07:00
|
|
|
serialize_list_quality([=](const std::string& token) { armor->add_quality_total(token); },
|
|
|
|
mPile->settings.armor.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
|
2023-03-10 15:08:31 -07:00
|
|
|
void StockpileSerializer::read_armor() {
|
|
|
|
if (mBuffer.has_armor()) {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.armor = 1;
|
|
|
|
const StockpileSettings::ArmorSet armor = mBuffer.armor();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("armor:\n");
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
bool unusable = armor.unusable();
|
|
|
|
bool usable = armor.usable();
|
2023-03-10 15:08:31 -07:00
|
|
|
DEBUG(log).print("unusable %d\n", unusable);
|
|
|
|
DEBUG(log).print("usable %d\n", usable);
|
2018-06-14 13:18:15 -06:00
|
|
|
mPile->settings.armor.unusable = unusable;
|
|
|
|
mPile->settings.armor.usable = usable;
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// body type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.body(idx); },
|
|
|
|
armor.body_size(), &mPile->settings.armor.body, item_type::ARMOR);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// head type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.head(idx); },
|
|
|
|
armor.head_size(), &mPile->settings.armor.head, item_type::HELM);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// feet type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.feet(idx); },
|
|
|
|
armor.feet_size(), &mPile->settings.armor.feet, item_type::SHOES);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// hands type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.hands(idx); },
|
|
|
|
armor.hands_size(), &mPile->settings.armor.hands, item_type::GLOVES);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// legs type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.legs(idx); },
|
|
|
|
armor.legs_size(), &mPile->settings.armor.legs, item_type::PANTS);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// shield type
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_itemdef([=](const size_t& idx) -> const std::string& { return armor.shield(idx); },
|
|
|
|
armor.shield_size(), &mPile->settings.armor.shield, item_type::SHIELD);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// materials
|
2023-03-10 15:08:31 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind(&StockpileSerializer::armor_mat_is_allowed, this, _1);
|
|
|
|
unserialize_list_material(
|
|
|
|
mat_filter, [=](const size_t& idx) -> const std::string& { return armor.mats(idx); },
|
|
|
|
armor.mats_size(), &mPile->settings.armor.mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// other mats
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_other_mats(
|
|
|
|
mOtherMatsWeaponsArmor, [=](const size_t& idx) -> const std::string& { return armor.other_mats(idx); },
|
|
|
|
armor.other_mats_size(), &mPile->settings.armor.other_mats);
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// core quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return armor.quality_core(idx); },
|
|
|
|
armor.quality_core_size(), mPile->settings.armor.quality_core);
|
2014-12-02 04:06:01 -07:00
|
|
|
// total quality
|
2023-03-10 15:08:31 -07:00
|
|
|
unserialize_list_quality([=](const size_t& idx) -> const std::string& { return armor.quality_total(idx); },
|
|
|
|
armor.quality_total_size(), mPile->settings.armor.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
2023-03-10 15:08:31 -07:00
|
|
|
else {
|
2014-12-02 04:06:01 -07:00
|
|
|
mPile->settings.flags.bits.armor = 0;
|
|
|
|
mPile->settings.armor.body.clear();
|
|
|
|
mPile->settings.armor.head.clear();
|
|
|
|
mPile->settings.armor.feet.clear();
|
|
|
|
mPile->settings.armor.hands.clear();
|
|
|
|
mPile->settings.armor.legs.clear();
|
|
|
|
mPile->settings.armor.shield.clear();
|
|
|
|
mPile->settings.armor.other_mats.clear();
|
|
|
|
mPile->settings.armor.mats.clear();
|
2023-03-10 15:08:31 -07:00
|
|
|
quality_clear(mPile->settings.armor.quality_core);
|
|
|
|
quality_clear(mPile->settings.armor.quality_total);
|
2014-12-02 04:06:01 -07:00
|
|
|
}
|
|
|
|
}
|