import and export logistics features

develop
Myk Taylor 2023-05-04 01:29:07 -07:00
parent 43fbd89c23
commit b7d4b8fed6
No known key found for this signature in database
8 changed files with 411 additions and 382 deletions

@ -608,7 +608,7 @@ static int logistics_getStockpileConfigs(lua_State *L) {
color_ostream *out = Lua::GetOutput(L);
if (!out)
out = &Core::getInstance().getConsole();
DEBUG(status, *out).print("entering logistics_getStockpileConfig\n");
DEBUG(status, *out).print("entering logistics_getStockpileConfigs\n");
unordered_map<df::building_stockpilest*, PersistentDataItem> cache;
validate_stockpile_configs(*out, cache);

@ -207,6 +207,11 @@ function parse_commandline(args)
return true
end
function get_stockpile_features(stockpile_number)
local config = logistics.logistics_getStockpileConfigs(stockpile_number)[1]
return config.melt, config.trade, config.dump
end
--------------------
-- dialogs
--------------------

@ -21,8 +21,8 @@ DBG_EXTERN(stockpiles, log);
* and their index in the stockpile_settings structures.
*/
void OrganicMatLookup::food_mat_by_idx(organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat& food_mat) {
DEBUG(log).print("food_lookup: food_idx(%zd)\n", food_idx);
void OrganicMatLookup::food_mat_by_idx(color_ostream& out, organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat& food_mat) {
DEBUG(log, out).print("food_lookup: food_idx(%zd)\n", food_idx);
df::world_raws& raws = world->raws;
df::special_mat_table table = raws.mat_table;
int32_t main_idx = table.organic_indexes[mat_category][food_idx];
@ -32,16 +32,16 @@ void OrganicMatLookup::food_mat_by_idx(organic_mat_category::organic_mat_categor
mat_category == organic_mat_category::Eggs) {
food_mat.creature = raws.creatures.all[type];
food_mat.caste = food_mat.creature->caste[main_idx];
DEBUG(log).print("special creature type(%d) caste(%d)\n", type, main_idx);
DEBUG(log, out).print("special creature type(%d) caste(%d)\n", type, main_idx);
}
else {
food_mat.material.decode(type, main_idx);
DEBUG(log).print("type(%d) index(%d) token(%s)\n", type, main_idx, food_mat.material.getToken().c_str());
DEBUG(log, out).print("type(%d) index(%d) token(%s)\n", type, main_idx, food_mat.material.getToken().c_str());
}
}
std::string OrganicMatLookup::food_token_by_idx(organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx) {
std::string OrganicMatLookup::food_token_by_idx(color_ostream& out, organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx) {
FoodMat food_mat;
food_mat_by_idx(mat_category, idx, food_mat);
food_mat_by_idx(out, mat_category, idx, food_mat);
if (food_mat.material.isValid()) {
return food_mat.material.getToken();
}
@ -72,32 +72,32 @@ void OrganicMatLookup::food_build_map() {
index_built = true;
}
int16_t OrganicMatLookup::food_idx_by_token(organic_mat_category::organic_mat_category mat_category, const std::string& token) {
int16_t OrganicMatLookup::food_idx_by_token(color_ostream& out, organic_mat_category::organic_mat_category mat_category, const std::string& token) {
df::world_raws& raws = world->raws;
df::special_mat_table table = raws.mat_table;
DEBUG(log).print("food_idx_by_token:\n");
DEBUG(log, out).print("food_idx_by_token:\n");
if (mat_category == organic_mat_category::Fish ||
mat_category == organic_mat_category::UnpreparedFish ||
mat_category == organic_mat_category::Eggs) {
std::vector<std::string> tokens;
split_string(&tokens, token, ":");
if (tokens.size() != 2) {
WARN(log).print("creature invalid CREATURE:CASTE token: %s\n", token.c_str());
WARN(log, out).print("creature invalid CREATURE:CASTE token: %s\n", token.c_str());
return -1;
}
int16_t creature_idx = find_creature(tokens[0]);
if (creature_idx < 0) {
WARN(log).print("creature invalid token %s\n", tokens[0].c_str());
WARN(log, out).print("creature invalid token %s\n", tokens[0].c_str());
return -1;
}
int16_t food_idx = linear_index(table.organic_types[mat_category], creature_idx);
if (tokens[1] == "MALE")
food_idx += 1;
if (table.organic_types[mat_category][food_idx] == creature_idx) {
DEBUG(log).print("creature %s caste %s creature_idx(%d) food_idx(%d)\n", token.c_str(), tokens[1].c_str(), creature_idx, food_idx);
DEBUG(log, out).print("creature %s caste %s creature_idx(%d) food_idx(%d)\n", token.c_str(), tokens[1].c_str(), creature_idx, food_idx);
return food_idx;
}
WARN(log).print("creature caste not found: %s caste %s creature_idx(%d) food_idx(%d)\n", token.c_str(), tokens[1].c_str(), creature_idx, food_idx);
WARN(log, out).print("creature caste not found: %s caste %s creature_idx(%d) food_idx(%d)\n", token.c_str(), tokens[1].c_str(), creature_idx, food_idx);
return -1;
}
@ -108,12 +108,12 @@ int16_t OrganicMatLookup::food_idx_by_token(organic_mat_category::organic_mat_ca
int32_t index = mat_info.index;
auto it = food_index[mat_category].find(std::make_pair(type, index));
if (it != food_index[mat_category].end()) {
DEBUG(log).print("matinfo: %s type(%d) idx(%d) food_idx(%zd)\n", token.c_str(), mat_info.type, mat_info.index, it->second);
DEBUG(log, out).print("matinfo: %s type(%d) idx(%d) food_idx(%zd)\n", token.c_str(), mat_info.type, mat_info.index, it->second);
return it->second;
}
WARN(log).print("matinfo: %s type(%d) idx(%d) food_idx not found :(\n", token.c_str(), mat_info.type, mat_info.index);
WARN(log, out).print("matinfo: %s type(%d) idx(%d) food_idx not found :(\n", token.c_str(), mat_info.type, mat_info.index);
return -1;
}

@ -28,13 +28,13 @@ public:
FoodMat(): material(-1), creature(0), caste(0) { }
};
static void food_mat_by_idx(df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat& food_mat);
static std::string food_token_by_idx(df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx);
static void food_mat_by_idx(DFHack::color_ostream& out, df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat& food_mat);
static std::string food_token_by_idx(DFHack::color_ostream& out, df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx);
static size_t food_max_size(df::enums::organic_mat_category::organic_mat_category mat_category);
static void food_build_map();
static int16_t food_idx_by_token(df::enums::organic_mat_category::organic_mat_category mat_category, const std::string& token);
static int16_t food_idx_by_token(DFHack::color_ostream& out, df::enums::organic_mat_category::organic_mat_category mat_category, const std::string& token);
static DFHack::MaterialInfo food_mat_by_token(const std::string& token);

File diff suppressed because it is too large Load Diff

@ -72,13 +72,13 @@ public:
* Since we depend on protobuf-lite, not the full lib, we copy this function from
* protobuf message.cc
*/
bool serialize_to_ostream(std::ostream* output, uint32_t includedElements);
bool serialize_to_ostream(DFHack::color_ostream& out, std::ostream* output, uint32_t includedElements);
/**
* Will serialize stockpile settings to a file (overwrites existing files)
* @return success/failure
*/
bool serialize_to_file(const std::string& file, uint32_t includedElements);
bool serialize_to_file(DFHack::color_ostream& out, const std::string& file, uint32_t includedElements);
/**
* Again, copied from message.cc
@ -94,7 +94,7 @@ protected:
dfstockpiles::StockpileSettings mBuffer;
// 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<std::string>& filters);
@ -105,41 +105,41 @@ protected:
private:
df::stockpile_settings *mSettings;
bool write_ammo(dfstockpiles::StockpileSettings::AmmoSet* ammo);
void read_ammo(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_animals(dfstockpiles::StockpileSettings::AnimalsSet* animals);
void read_animals(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_armor(dfstockpiles::StockpileSettings::ArmorSet* armor);
void read_armor(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_bars_blocks(dfstockpiles::StockpileSettings::BarsBlocksSet* bars_blocks);
void read_bars_blocks(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_cloth(dfstockpiles::StockpileSettings::ClothSet* cloth);
void read_cloth(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_coins(dfstockpiles::StockpileSettings::CoinSet* coins);
void read_coins(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_finished_goods(dfstockpiles::StockpileSettings::FinishedGoodsSet* finished_goods);
void read_finished_goods(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_ammo(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::AmmoSet* ammo);
void read_ammo(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_animals(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::AnimalsSet* animals);
void read_animals(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_armor(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::ArmorSet* armor);
void read_armor(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_bars_blocks(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::BarsBlocksSet* bars_blocks);
void read_bars_blocks(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_cloth(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::ClothSet* cloth);
void read_cloth(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_coins(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::CoinSet* coins);
void read_coins(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_finished_goods(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::FinishedGoodsSet* finished_goods);
void read_finished_goods(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
food_pair food_map(df::enums::organic_mat_category::organic_mat_category cat);
bool write_food(dfstockpiles::StockpileSettings::FoodSet* food);
void read_food(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_furniture(dfstockpiles::StockpileSettings::FurnitureSet* furniture);
void read_furniture(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_gems(dfstockpiles::StockpileSettings::GemsSet* gems);
void read_gems(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_leather(dfstockpiles::StockpileSettings::LeatherSet* leather);
void read_leather(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_corpses(dfstockpiles::StockpileSettings::CorpsesSet* corpses);
void read_corpses(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_refuse(dfstockpiles::StockpileSettings::RefuseSet* refuse);
void read_refuse(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_sheet(dfstockpiles::StockpileSettings::SheetSet* sheet);
void read_sheet(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_stone(dfstockpiles::StockpileSettings::StoneSet* stone);
void read_stone(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_weapons(dfstockpiles::StockpileSettings::WeaponsSet* weapons);
void read_weapons(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_wood(dfstockpiles::StockpileSettings::WoodSet* wood);
void read_wood(DeserializeMode mode, const std::vector<std::string>& filters);
bool write_food(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::FoodSet* food);
void read_food(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_furniture(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::FurnitureSet* furniture);
void read_furniture(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_gems(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::GemsSet* gems);
void read_gems(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_leather(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::LeatherSet* leather);
void read_leather(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_corpses(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::CorpsesSet* corpses);
void read_corpses(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_refuse(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::RefuseSet* refuse);
void read_refuse(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_sheet(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::SheetSet* sheet);
void read_sheet(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_stone(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::StoneSet* stone);
void read_stone(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_weapons(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::WeaponsSet* weapons);
void read_weapons(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
bool write_wood(DFHack::color_ostream& out, dfstockpiles::StockpileSettings::WoodSet* wood);
void read_wood(DFHack::color_ostream& out, DeserializeMode mode, const std::vector<std::string>& filters);
};
/**
@ -169,6 +169,6 @@ private:
void write_containers();
void read_containers(DeserializeMode mode);
void write_features();
void read_features(DeserializeMode mode);
void write_features(DFHack::color_ostream& out);
void read_features(DFHack::color_ostream &out, DeserializeMode mode);
};

@ -1,5 +1,6 @@
#pragma once
#include "LuaTools.h"
#include "MiscUtils.h"
#include "df/world.h"
@ -9,6 +10,11 @@
// Utility Functions {{{
// A set of convenience functions for doing common lookups
bool call_stockpiles_lua(DFHack::color_ostream* out, const char* fn_name,
int nargs = 0, int nres = 0,
DFHack::Lua::LuaLambda&& args_lambda = DFHack::Lua::DEFAULT_LUA_LAMBDA,
DFHack::Lua::LuaLambda&& res_lambda = DFHack::Lua::DEFAULT_LUA_LAMBDA);
/**
* Retrieve creature raw from index
*/

@ -38,10 +38,9 @@ DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginComman
return CR_OK;
}
static bool call_stockpiles_lua(color_ostream *out, const char *fn_name,
int nargs = 0, int nres = 0,
Lua::LuaLambda && args_lambda = Lua::DEFAULT_LUA_LAMBDA,
Lua::LuaLambda && res_lambda = Lua::DEFAULT_LUA_LAMBDA) {
bool call_stockpiles_lua(color_ostream* out, const char* fn_name,
int nargs, int nres, Lua::LuaLambda&& args_lambda, Lua::LuaLambda&& res_lambda) {
DEBUG(log).print("calling stockpiles lua function: '%s'\n", fn_name);
CoreSuspender guard;
@ -95,7 +94,7 @@ static bool stockpiles_export(color_ostream& out, string fname, int id, uint32_t
try {
StockpileSerializer cereal(sp);
if (!cereal.serialize_to_file(fname, includedElements)) {
if (!cereal.serialize_to_file(out, fname, includedElements)) {
out.printerr("could not save to '%s'\n", fname.c_str());
return false;
}