Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43fbd89

Browse files
committed
first step at saving features
1 parent c8786b2 commit 43fbd89

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

docs/plugins/logistics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ logistics
33

44
.. dfhack-tool::
55
:summary: Automatically mark and route items in monitored stockpiles.
6-
:tags: fort productivity items stockpiles
6+
:tags: fort auto items stockpiles
77

88
Commands act upon the stockpile selected in the UI unless another stockpile
99
identifier is specified on the commandline.

plugins/stockpiles/StockpileSerializer.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,26 @@ bool StockpileSettingsSerializer::serialize_to_file(const string& file, uint32_t
185185
return serialize_to_ostream(&output, includedElements);
186186
}
187187

188-
bool StockpileSettingsSerializer::parse_from_istream(std::istream* input, DeserializeMode mode, const vector<string>& filters) {
188+
bool StockpileSettingsSerializer::parse_from_istream(color_ostream &out, std::istream* input, DeserializeMode mode, const vector<string>& filters) {
189189
if (input->fail())
190190
return false;
191191
mBuffer.Clear();
192192
io::IstreamInputStream zero_copy_input(input);
193193
const bool res = mBuffer.ParseFromZeroCopyStream(&zero_copy_input)
194194
&& input->eof();
195195
if (res)
196-
read(mode, filters);
196+
read(out, mode, filters);
197197
return res;
198198
}
199199

200-
bool StockpileSettingsSerializer::unserialize_from_file(const string& file, DeserializeMode mode, const vector<string>& filters) {
200+
bool StockpileSettingsSerializer::unserialize_from_file(color_ostream &out, const string& file, DeserializeMode mode, const vector<string>& filters) {
201201
std::fstream input(file, std::ios::in | std::ios::binary);
202202
if (input.fail()) {
203203
WARN(log).print("failed to open file for reading: '%s'\n",
204204
file.c_str());
205205
return false;
206206
}
207-
return parse_from_istream(&input, mode, filters);
207+
return parse_from_istream(out, &input, mode, filters);
208208
}
209209

210210
/**
@@ -768,13 +768,15 @@ void StockpileSettingsSerializer::write(uint32_t includedElements) {
768768
}
769769

770770
void StockpileSerializer::write(uint32_t includedElements) {
771+
if (includedElements & INCLUDED_ELEMENTS_FEATURES)
772+
write_features();
771773
if (includedElements & INCLUDED_ELEMENTS_CONTAINERS)
772774
write_containers();
773775

774776
StockpileSettingsSerializer::write(includedElements);
775777
}
776778

777-
void StockpileSettingsSerializer::read(DeserializeMode mode, const vector<string>& filters) {
779+
void StockpileSettingsSerializer::read(color_ostream &out, DeserializeMode mode, const vector<string>& filters) {
778780
DEBUG(log).print("==READ==\n");
779781
read_general(mode);
780782
read_ammo(mode, filters);
@@ -803,7 +805,8 @@ void StockpileSettingsSerializer::read(DeserializeMode mode, const vector<string
803805
read_wood(mode, filters);
804806
}
805807

806-
void StockpileSerializer::read(DeserializeMode mode, const vector<string>& filters) {
808+
void StockpileSerializer::read(color_ostream &out, DeserializeMode mode, const vector<string>& filters) {
809+
read_features(out, mode);
807810
read_containers(mode);
808811
StockpileSettingsSerializer::read(mode, filters);
809812
}
@@ -913,19 +916,25 @@ void StockpileSerializer::write_features() {
913916
mBuffer.set_dump(mPile->settings.allow_organic);
914917
}
915918

916-
void StockpileSerializer::read_features(DeserializeMode mode) {
917-
read_elem<int32_t, bool>("use_links_only", mode,
918-
std::bind(&StockpileSettings::has_use_links_only, mBuffer),
919-
std::bind(&StockpileSettings::use_links_only, mBuffer),
920-
mPile->use_links_only);
921-
read_elem<bool, bool>("allow_inorganic", mode,
922-
std::bind(&StockpileSettings::has_allow_inorganic, mBuffer),
923-
std::bind(&StockpileSettings::allow_inorganic, mBuffer),
924-
mPile->settings.allow_inorganic);
925-
read_elem<bool, bool>("allow_organic", mode,
926-
std::bind(&StockpileSettings::has_allow_organic, mBuffer),
927-
std::bind(&StockpileSettings::allow_organic, mBuffer),
928-
mPile->settings.allow_organic);
919+
void StockpileSerializer::read_features(color_ostream &out, DeserializeMode mode) {
920+
int32_t melt = -1, trade = -1, dump = -1;
921+
read_elem<int32_t, bool>("melt", mode,
922+
std::bind(&StockpileSettings::has_melt, mBuffer),
923+
std::bind(&StockpileSettings::melt, mBuffer),
924+
melt);
925+
read_elem<int32_t, bool>("trade", mode,
926+
std::bind(&StockpileSettings::has_trade, mBuffer),
927+
std::bind(&StockpileSettings::trade, mBuffer),
928+
trade);
929+
read_elem<int32_t, bool>("dump", mode,
930+
std::bind(&StockpileSettings::has_dump, mBuffer),
931+
std::bind(&StockpileSettings::dump, mBuffer),
932+
dump);
933+
934+
if (melt != -1 || trade != -1 || dump != -1) {
935+
auto &core = Core::getInstance();
936+
core.runCommand(out, "logistics clear -s " + int_to_string(mPile->stockpile_number));
937+
}
929938
}
930939

931940
static bool ammo_mat_is_allowed(const MaterialInfo& mi) {

plugins/stockpiles/StockpileSerializer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum IncludedElements {
2121
INCLUDED_ELEMENTS_GENERAL = 0x02,
2222
INCLUDED_ELEMENTS_CATEGORIES = 0x04,
2323
INCLUDED_ELEMENTS_TYPES = 0x08,
24+
INCLUDED_ELEMENTS_FEATURES = 0x10,
2425
};
2526

2627
enum DeserializeMode {
@@ -82,12 +83,12 @@ class StockpileSettingsSerializer {
8283
/**
8384
* Again, copied from message.cc
8485
*/
85-
bool parse_from_istream(std::istream* input, DeserializeMode mode, const std::vector<std::string>& filters);
86+
bool parse_from_istream(DFHack::color_ostream &out, std::istream* input, DeserializeMode mode, const std::vector<std::string>& filters);
8687

8788
/**
8889
* Read stockpile settings from file
8990
*/
90-
bool unserialize_from_file(const std::string& file, DeserializeMode mode, const std::vector<std::string>& filters);
91+
bool unserialize_from_file(DFHack::color_ostream &out, const std::string& file, DeserializeMode mode, const std::vector<std::string>& filters);
9192

9293
protected:
9394
dfstockpiles::StockpileSettings mBuffer;

plugins/stockpiles/stockpiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static bool stockpiles_import(color_ostream& out, string fname, int id, string m
134134

135135
try {
136136
StockpileSerializer cereal(sp);
137-
if (!cereal.unserialize_from_file(fname, mode, filters)) {
137+
if (!cereal.unserialize_from_file(out, fname, mode, filters)) {
138138
out.printerr("deserialization failed: '%s'\n", fname.c_str());
139139
return false;
140140
}

0 commit comments

Comments
 (0)