From ff7a2945eb108ce8d84276e24036db61584f271f Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 11 Jun 2023 23:15:03 -0700 Subject: [PATCH] finish merge --- plugins/stockpiles/StockpileSerializer.cpp | 117 +++++++++++---------- plugins/stockpiles/StockpileSerializer.h | 18 ++-- plugins/stockpiles/proto/stockpiles.proto | 1 + plugins/stockpiles/stockpiles.cpp | 2 +- 4 files changed, 73 insertions(+), 65 deletions(-) diff --git a/plugins/stockpiles/StockpileSerializer.cpp b/plugins/stockpiles/StockpileSerializer.cpp index 0cfc7284c..ebee71520 100644 --- a/plugins/stockpiles/StockpileSerializer.cpp +++ b/plugins/stockpiles/StockpileSerializer.cpp @@ -677,96 +677,96 @@ void StockpileSettingsSerializer::write(color_ostream& out, uint32_t includedEle if (!(includedElements & INCLUDED_ELEMENTS_CATEGORIES)) return; - DEBUG(log).print("GROUP SET %s\n", + DEBUG(log, out).print("GROUP SET %s\n", bitfield_to_string(mSettings->flags).c_str()); bool include_types = 0 != (includedElements & INCLUDED_ELEMENTS_TYPES); - write_cat("ammo", include_types, + write_cat(out, "ammo", include_types, mSettings->flags.whole, mSettings->flags.mask_ammo, std::bind(&StockpileSettings::mutable_ammo, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_ammo, this, _1)); - write_cat("animals", include_types, + std::bind(&StockpileSettingsSerializer::write_ammo, this, _1, _2)); + write_cat(out, "animals", include_types, mSettings->flags.whole, mSettings->flags.mask_animals, std::bind(&StockpileSettings::mutable_animals, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_animals, this, _1)); - write_cat("armor", include_types, + std::bind(&StockpileSettingsSerializer::write_animals, this, _1, _2)); + write_cat(out, "armor", include_types, mSettings->flags.whole, mSettings->flags.mask_armor, std::bind(&StockpileSettings::mutable_armor, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_armor, this, _1)); - write_cat("bars_blocks", include_types, + std::bind(&StockpileSettingsSerializer::write_armor, this, _1, _2)); + write_cat(out, "bars_blocks", include_types, mSettings->flags.whole, mSettings->flags.mask_bars_blocks, std::bind(&StockpileSettings::mutable_barsblocks, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_bars_blocks, this, _1)); - write_cat("cloth", include_types, + std::bind(&StockpileSettingsSerializer::write_bars_blocks, this, _1, _2)); + write_cat(out, "cloth", include_types, mSettings->flags.whole, mSettings->flags.mask_cloth, std::bind(&StockpileSettings::mutable_cloth, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_cloth, this, _1)); - write_cat("coin", include_types, + std::bind(&StockpileSettingsSerializer::write_cloth, this, _1, _2)); + write_cat(out, "coin", include_types, mSettings->flags.whole, mSettings->flags.mask_coins, std::bind(&StockpileSettings::mutable_coin, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_coins, this, _1)); - write_cat("finished_goods", include_types, + std::bind(&StockpileSettingsSerializer::write_coins, this, _1, _2)); + write_cat(out, "finished_goods", include_types, mSettings->flags.whole, mSettings->flags.mask_finished_goods, std::bind(&StockpileSettings::mutable_finished_goods, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_finished_goods, this, _1)); - write_cat("food", include_types, + std::bind(&StockpileSettingsSerializer::write_finished_goods, this, _1, _2)); + write_cat(out, "food", include_types, mSettings->flags.whole, mSettings->flags.mask_food, std::bind(&StockpileSettings::mutable_food, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_food, this, _1)); - write_cat("furniture", include_types, + std::bind(&StockpileSettingsSerializer::write_food, this, _1, _2)); + write_cat(out, "furniture", include_types, mSettings->flags.whole, mSettings->flags.mask_furniture, std::bind(&StockpileSettings::mutable_furniture, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_furniture, this, _1)); - write_cat("gems", include_types, + std::bind(&StockpileSettingsSerializer::write_furniture, this, _1, _2)); + write_cat(out, "gems", include_types, mSettings->flags.whole, mSettings->flags.mask_gems, std::bind(&StockpileSettings::mutable_gems, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_gems, this, _1)); - write_cat("leather", include_types, + std::bind(&StockpileSettingsSerializer::write_gems, this, _1, _2)); + write_cat(out, "leather", include_types, mSettings->flags.whole, mSettings->flags.mask_leather, std::bind(&StockpileSettings::mutable_leather, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_leather, this, _1)); - write_cat("corpses", include_types, + std::bind(&StockpileSettingsSerializer::write_leather, this, _1, _2)); + write_cat(out, "corpses", include_types, mSettings->flags.whole, mSettings->flags.mask_corpses, std::bind(&StockpileSettings::mutable_corpses_v50, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_corpses, this, _1)); - write_cat("refuse", include_types, + std::bind(&StockpileSettingsSerializer::write_corpses, this, _1, _2)); + write_cat(out, "refuse", include_types, mSettings->flags.whole, mSettings->flags.mask_refuse, std::bind(&StockpileSettings::mutable_refuse, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_refuse, this, _1)); - write_cat("sheet", include_types, + std::bind(&StockpileSettingsSerializer::write_refuse, this, _1, _2)); + write_cat(out, "sheet", include_types, mSettings->flags.whole, mSettings->flags.mask_sheet, std::bind(&StockpileSettings::mutable_sheet, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_sheet, this, _1)); - write_cat("stone", include_types, + std::bind(&StockpileSettingsSerializer::write_sheet, this, _1, _2)); + write_cat(out, "stone", include_types, mSettings->flags.whole, mSettings->flags.mask_stone, std::bind(&StockpileSettings::mutable_stone, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_stone, this, _1)); - write_cat("weapons", include_types, + std::bind(&StockpileSettingsSerializer::write_stone, this, _1, _2)); + write_cat(out, "weapons", include_types, mSettings->flags.whole, mSettings->flags.mask_weapons, std::bind(&StockpileSettings::mutable_weapons, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_weapons, this, _1)); - write_cat("wood", include_types, + std::bind(&StockpileSettingsSerializer::write_weapons, this, _1, _2)); + write_cat(out, "wood", include_types, mSettings->flags.whole, mSettings->flags.mask_wood, std::bind(&StockpileSettings::mutable_wood, &mBuffer), - std::bind(&StockpileSettingsSerializer::write_wood, this, _1)); + std::bind(&StockpileSettingsSerializer::write_wood, this, _1, _2)); } void StockpileSerializer::write(color_ostream& out, uint32_t includedElements) { @@ -775,23 +775,23 @@ void StockpileSerializer::write(color_ostream& out, uint32_t includedElements) { if (includedElements & INCLUDED_ELEMENTS_CONTAINERS) write_containers(out); - StockpileSettingsSerializer::write(includedElements); + StockpileSettingsSerializer::write(out, includedElements); } void StockpileSettingsSerializer::read(color_ostream &out, DeserializeMode mode, const vector& filters) { DEBUG(log).print("==READ==\n"); - read_general(mode); - read_ammo(mode, filters); - read_animals(mode, filters); - read_armor(mode, filters); - read_bars_blocks(mode, filters); - read_cloth(mode, filters); - read_coins(mode, filters); - read_finished_goods(mode, filters); - read_food(mode, filters); - read_furniture(mode, filters); - read_gems(mode, filters); - read_leather(mode, filters); + read_general(out, mode); + read_ammo(out, mode, filters); + read_animals(out, mode, filters); + read_armor(out, mode, filters); + read_bars_blocks(out, mode, filters); + read_cloth(out, mode, filters); + read_coins(out, mode, filters); + read_finished_goods(out, mode, filters); + read_food(out, mode, filters); + read_furniture(out, mode, filters); + read_gems(out, mode, filters); + read_leather(out, mode, filters); // support for old versions before corpses had a set if (mBuffer.has_corpses()) { @@ -913,7 +913,7 @@ void StockpileSerializer::read_general(color_ostream& out, DeserializeMode mode) void StockpileSerializer::write_features(color_ostream& out) { DEBUG(log, out).print("writing feature settings\n"); - if (!call_stockpiles_lua(&out, "get_stockpile_features", 1, 3, + if (!call_stockpiles_lua(&out, "get_stockpile_features", 1, 4, [&](lua_State* L) { Lua::Push(L, mPile->stockpile_number); }, @@ -921,6 +921,7 @@ void StockpileSerializer::write_features(color_ostream& out) { mBuffer.set_melt(0 != lua_toboolean(L, -1)); mBuffer.set_trade(0 != lua_toboolean(L, -2)); mBuffer.set_dump(0 != lua_toboolean(L, -3)); + mBuffer.set_train(0 != lua_toboolean(L, -4)); })) { WARN(log, out).print("failed to get logistics features of stockpile number %d\n", mPile->stockpile_number); @@ -928,7 +929,7 @@ void StockpileSerializer::write_features(color_ostream& out) { } void StockpileSerializer::read_features(color_ostream &out, DeserializeMode mode) { - int32_t melt = -1, trade = -1, dump = -1; + int32_t melt = -1, trade = -1, dump = -1, train = -1; read_elem(out, "melt", mode, std::bind(&StockpileSettings::has_melt, mBuffer), std::bind(&StockpileSettings::melt, mBuffer), @@ -941,14 +942,19 @@ void StockpileSerializer::read_features(color_ostream &out, DeserializeMode mode std::bind(&StockpileSettings::has_dump, mBuffer), std::bind(&StockpileSettings::dump, mBuffer), dump); + read_elem(out, "train", mode, + std::bind(&StockpileSettings::has_train, mBuffer), + std::bind(&StockpileSettings::train, mBuffer), + train); - if (melt != -1 || trade != -1 || dump != -1) { + if (melt != -1 || trade != -1 || dump != -1 || train != -1) { if (!call_stockpiles_lua(&out, "set_stockpile_features", 4, 0, [&](lua_State* L) { Lua::Push(L, mPile->stockpile_number); Lua::Push(L, melt == 1); Lua::Push(L, trade == 1); Lua::Push(L, dump == 1); + Lua::Push(L, train == 1); })) { WARN(log, out).print("failed to set logistics features of stockpile number %d\n", mPile->stockpile_number); } @@ -973,7 +979,7 @@ bool StockpileSettingsSerializer::write_ammo(color_ostream& out, StockpileSettin if (mSettings->ammo.other_mats.size() > 2) { WARN(log, out).print("ammo other materials > 2: %zd\n", - mPile->settings.ammo.other_mats.size()); + mSettings->ammo.other_mats.size()); } size_t num_other_mats = std::min(size_t(2), @@ -1339,7 +1345,6 @@ bool StockpileSettingsSerializer::write_cloth(color_ostream& out, StockpileSetti void StockpileSettingsSerializer::read_cloth(color_ostream& out, DeserializeMode mode, const vector& filters) { auto & pcloth = mSettings->cloth; read_category(out, "cloth", mode, ->>>>>>> 7a1aacdca (import and export logistics features) std::bind(&StockpileSettings::has_cloth, mBuffer), std::bind(&StockpileSettings::cloth, mBuffer), mSettings->flags.whole, @@ -1473,10 +1478,12 @@ bool StockpileSettingsSerializer::write_finished_goods(color_ostream& out, Stock mOtherMatsFinishedGoods.mats, [&](const string& token) { finished_goods->add_other_mats(token); }, mSettings->finished_goods.other_mats) && all; - all = serialize_list_quality([&](out, const string& token) { finished_goods->add_quality_core(token); }, + all = serialize_list_quality(out, + [&](const string& token) { finished_goods->add_quality_core(token); }, mSettings->finished_goods.quality_core) && all; - all = serialize_list_quality([&](out, const string& token) { finished_goods->add_quality_total(token); }, + all = serialize_list_quality(out, + [&](const string& token) { finished_goods->add_quality_total(token); }, mSettings->finished_goods.quality_total) && all; return all; diff --git a/plugins/stockpiles/StockpileSerializer.h b/plugins/stockpiles/StockpileSerializer.h index 115b21c9f..c707eab85 100644 --- a/plugins/stockpiles/StockpileSerializer.h +++ b/plugins/stockpiles/StockpileSerializer.h @@ -97,10 +97,10 @@ protected: virtual void write(DFHack::color_ostream& out, uint32_t includedElements); // parse serialized data into ui indices - virtual void read(DeserializeMode mode, const std::vector& filters); + virtual void read(DFHack::color_ostream& out, DeserializeMode mode, const std::vector& filters); - virtual void write_general(); - virtual void read_general(DeserializeMode mode); + virtual void write_general(DFHack::color_ostream& out); + virtual void read_general(DFHack::color_ostream& out, DeserializeMode mode); private: df::stockpile_settings *mSettings; @@ -156,19 +156,19 @@ public: protected: // read memory structures and serialize to protobuf - virtual void write(uint32_t includedElements); + virtual void write(DFHack::color_ostream& out, uint32_t includedElements); // parse serialized data into ui indices - virtual void read(DeserializeMode mode, const std::vector& filters); + virtual void read(DFHack::color_ostream& out, DeserializeMode mode, const std::vector& filters); - virtual void write_general(); - virtual void read_general(DeserializeMode mode); + virtual void write_general(DFHack::color_ostream& out); + virtual void read_general(DFHack::color_ostream& out, DeserializeMode mode); private: df::building_stockpilest* mPile; - void write_containers(); - void read_containers(DeserializeMode mode); + void write_containers(DFHack::color_ostream& out); + void read_containers(DFHack::color_ostream& out, DeserializeMode mode); void write_features(DFHack::color_ostream& out); void read_features(DFHack::color_ostream &out, DeserializeMode mode); }; diff --git a/plugins/stockpiles/proto/stockpiles.proto b/plugins/stockpiles/proto/stockpiles.proto index 0ad89e143..4030de0cd 100644 --- a/plugins/stockpiles/proto/stockpiles.proto +++ b/plugins/stockpiles/proto/stockpiles.proto @@ -187,6 +187,7 @@ message StockpileSettings { optional bool melt = 27; optional bool trade = 28; optional bool dump = 29; + optional bool train = 30; // deprecated optional bool corpses = 24; // not marked as deprecated since we still read it diff --git a/plugins/stockpiles/stockpiles.cpp b/plugins/stockpiles/stockpiles.cpp index b9d6e9d37..6e3caa61d 100644 --- a/plugins/stockpiles/stockpiles.cpp +++ b/plugins/stockpiles/stockpiles.cpp @@ -178,7 +178,7 @@ static bool stockpiles_route_import(color_ostream& out, string fname, int route_ try { StockpileSettingsSerializer cereal(&stop->settings); - if (!cereal.unserialize_from_file(fname, mode, filters)) { + if (!cereal.unserialize_from_file(out, fname, mode, filters)) { out.printerr("deserialization failed: '%s'\n", fname.c_str()); return false; }