2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2011-12-24 03:51:58 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
2014-11-19 01:09:44 -07:00
|
|
|
#include "df/world_data.h"
|
|
|
|
#include "df/inorganic_raw.h"
|
|
|
|
#include "df/organic_mat_category.h"
|
|
|
|
#include "df/furniture_type.h"
|
|
|
|
#include "df/item_quality.h"
|
|
|
|
#include "df/item_type.h"
|
|
|
|
#include "df/creature_raw.h"
|
|
|
|
#include "df/caste_raw.h"
|
|
|
|
#include "df/material.h"
|
|
|
|
#include "df/inorganic_raw.h"
|
|
|
|
#include "df/plant_raw.h"
|
|
|
|
#include "df/stockpile_group_set.h"
|
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/building_stockpilest.h"
|
2014-11-21 06:37:37 -07:00
|
|
|
#include "df/stockpile_settings.h"
|
2012-02-20 03:42:40 -07:00
|
|
|
#include "df/global_objects.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
2014-11-19 01:09:44 -07:00
|
|
|
#include <df/itemdef_ammost.h>
|
2014-11-19 11:53:53 -07:00
|
|
|
#include <df/itemdef_weaponst.h>
|
|
|
|
#include <df/itemdef_ammost.h>
|
|
|
|
#include <df/itemdef_trapcompst.h>
|
|
|
|
#include <df/itemdef_armorst.h>
|
|
|
|
#include <df/itemdef_helmst.h>
|
|
|
|
#include <df/itemdef_shoesst.h>
|
|
|
|
#include <df/itemdef_glovesst.h>
|
|
|
|
#include <df/itemdef_pantsst.h>
|
|
|
|
#include <df/itemdef_shieldst.h>
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
// protobuf
|
|
|
|
#include "proto/stockpiles.pb.h"
|
2014-11-19 01:09:44 -07:00
|
|
|
#include <google/protobuf/text_format.h>
|
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
// os
|
2014-11-20 02:33:09 -07:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
// stl
|
2014-11-19 01:09:44 -07:00
|
|
|
#include <functional>
|
2014-11-21 06:37:37 -07:00
|
|
|
#include <vector>
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
2014-11-19 01:09:44 -07:00
|
|
|
using namespace google::protobuf;
|
|
|
|
using namespace dfstockpiles;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui;
|
2011-12-29 05:40:26 -07:00
|
|
|
using df::global::selection_rect;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
using df::building_stockpilest;
|
2014-11-19 06:14:46 -07:00
|
|
|
using std::placeholders::_1;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
static command_result copystock ( color_ostream &out, vector <string> & parameters );
|
|
|
|
static bool copystock_guard ( df::viewscreen *top );
|
|
|
|
|
|
|
|
static command_result savestock ( color_ostream &out, vector <string> & parameters );
|
|
|
|
static bool savestock_guard ( df::viewscreen *top );
|
2011-12-24 03:51:58 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
static command_result loadstock ( color_ostream &out, vector <string> & parameters );
|
2014-11-20 02:33:09 -07:00
|
|
|
static bool loadstock_guard ( df::viewscreen *top );
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
DFHACK_PLUGIN ( "stockpiles" );
|
2011-12-24 03:51:58 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands )
|
2011-12-24 03:51:58 -07:00
|
|
|
{
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( world && ui )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
commands.push_back (
|
|
|
|
PluginCommand (
|
2011-12-31 02:25:46 -07:00
|
|
|
"copystock", "Copy stockpile under cursor.",
|
|
|
|
copystock, copystock_guard,
|
|
|
|
" - In 'q' or 't' mode: select a stockpile and invoke in order\n"
|
|
|
|
" to switch to the 'p' stockpile creation mode, and initialize\n"
|
|
|
|
" the custom settings from the selected stockpile.\n"
|
|
|
|
" - In 'p': invoke in order to switch back to 'q'.\n"
|
2011-12-30 12:25:50 -07:00
|
|
|
)
|
|
|
|
);
|
2014-11-19 01:09:44 -07:00
|
|
|
commands.push_back (
|
|
|
|
PluginCommand (
|
|
|
|
"savestock", "Export the stockpile under cursor.",
|
|
|
|
savestock, savestock_guard,
|
2014-11-20 03:53:33 -07:00
|
|
|
" -d, --debug: enable debug output\n"
|
|
|
|
" <name> : filename to save stockpile settings to (will overwrite!)\n"
|
2014-11-19 01:09:44 -07:00
|
|
|
)
|
|
|
|
);
|
2014-11-20 02:33:09 -07:00
|
|
|
commands.push_back (
|
|
|
|
PluginCommand (
|
|
|
|
"loadstock", "Import stockpile settings and aplply them to the stockpile under cursor.",
|
|
|
|
loadstock, loadstock_guard,
|
2014-11-20 03:53:33 -07:00
|
|
|
" -d, --debug: enable debug output\n"
|
|
|
|
" <name> : filename to load stockpile settings from\n"
|
2014-11-20 03:18:01 -07:00
|
|
|
)
|
|
|
|
);
|
2011-12-24 03:51:58 -07:00
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
std::cerr << "world: " << sizeof ( df::world ) << " ui: " << sizeof ( df::ui )
|
|
|
|
<< " b_stock: " << sizeof ( building_stockpilest ) << endl;
|
2011-12-24 03:51:58 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-12-24 03:51:58 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
static bool copystock_guard ( df::viewscreen *top )
|
2011-12-30 12:25:50 -07:00
|
|
|
{
|
2011-12-24 03:51:58 -07:00
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
if ( !Gui::dwarfmode_hotkey ( top ) )
|
2011-12-31 02:25:46 -07:00
|
|
|
return false;
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
switch ( ui->main.mode )
|
|
|
|
{
|
2011-12-30 12:25:50 -07:00
|
|
|
case Stockpiles:
|
|
|
|
return true;
|
2011-12-24 03:51:58 -07:00
|
|
|
case BuildingItems:
|
|
|
|
case QueryBuilding:
|
2014-11-19 01:09:44 -07:00
|
|
|
return !!virtual_cast<building_stockpilest> ( world->selected_building );
|
2011-12-24 03:51:58 -07:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
static command_result copystock ( color_ostream &out, vector <string> & parameters )
|
2011-12-24 03:51:58 -07:00
|
|
|
{
|
2011-12-31 02:25:46 -07:00
|
|
|
// HOTKEY COMMAND: CORE ALREADY SUSPENDED
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
// For convenience: when used in the stockpiles mode, switch to 'q'
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( ui->main.mode == ui_sidebar_mode::Stockpiles )
|
|
|
|
{
|
2011-12-24 03:51:58 -07:00
|
|
|
world->selected_building = NULL; // just in case it contains some kind of garbage
|
|
|
|
ui->main.mode = ui_sidebar_mode::QueryBuilding;
|
2011-12-29 05:40:26 -07:00
|
|
|
selection_rect->start_x = -30000;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "Switched back to query building." << endl;
|
2011-12-24 03:51:58 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
building_stockpilest *sp = virtual_cast<building_stockpilest> ( world->selected_building );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( !sp )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
out.printerr ( "Selected building isn't a stockpile.\n" );
|
2011-12-31 02:25:46 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-24 03:51:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->stockpile.custom_settings = sp->settings;
|
|
|
|
ui->main.mode = ui_sidebar_mode::Stockpiles;
|
|
|
|
world->selected_stockpile_type = stockpile_category::Custom;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "Stockpile options copied." << endl;
|
2011-12-24 03:51:58 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
static bool savestock_guard ( df::viewscreen *top )
|
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
|
|
|
|
if ( !Gui::dwarfmode_hotkey ( top ) )
|
|
|
|
return false;
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
switch ( ui->main.mode )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
case Stockpiles:
|
|
|
|
return true;
|
|
|
|
case BuildingItems:
|
|
|
|
case QueryBuilding:
|
|
|
|
return !!virtual_cast<building_stockpilest> ( world->selected_building );
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
static bool loadstock_guard ( df::viewscreen *top )
|
|
|
|
{
|
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
|
|
|
|
if ( !Gui::dwarfmode_hotkey ( top ) )
|
2014-11-20 03:18:01 -07:00
|
|
|
return false;
|
2014-11-20 02:33:09 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
switch ( ui->main.mode )
|
|
|
|
{
|
|
|
|
case Stockpiles:
|
2014-11-20 02:33:09 -07:00
|
|
|
return true;
|
2014-11-20 03:18:01 -07:00
|
|
|
case BuildingItems:
|
|
|
|
case QueryBuilding:
|
2014-11-20 02:33:09 -07:00
|
|
|
return !!virtual_cast<building_stockpilest> ( world->selected_building );
|
2014-11-20 03:18:01 -07:00
|
|
|
default:
|
2014-11-20 02:33:09 -07:00
|
|
|
return false;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
2014-11-20 02:33:09 -07:00
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
// Utility Functions {{{
|
|
|
|
// A set of convenience functions for doing common lookups
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve creature raw from index
|
|
|
|
*/
|
|
|
|
static df::creature_raw* find_creature ( int32_t idx )
|
|
|
|
{
|
|
|
|
return world->raws.creatures.all[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve creature index from id string
|
2014-11-21 06:37:37 -07:00
|
|
|
* @return -1 if not found
|
2014-11-19 01:09:44 -07:00
|
|
|
*/
|
|
|
|
static int16_t find_creature ( const std::string &creature_id )
|
|
|
|
{
|
|
|
|
return linear_index ( world->raws.creatures.all, &df::creature_raw::creature_id, creature_id );
|
|
|
|
}
|
|
|
|
|
2014-11-19 11:53:53 -07:00
|
|
|
/**
|
|
|
|
* Retrieve plant raw from index
|
2014-11-21 08:07:08 -07:00
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
static df::plant_raw* find_plant ( size_t idx )
|
|
|
|
{
|
|
|
|
return world->raws.plants.all[idx];
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve plant index from id string
|
2014-11-21 06:37:37 -07:00
|
|
|
* @return -1 if not found
|
2014-11-19 11:53:53 -07:00
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
static size_t find_plant ( const std::string &plant_id )
|
2014-11-19 11:53:53 -07:00
|
|
|
{
|
2014-11-20 03:18:01 -07:00
|
|
|
return linear_index ( world->raws.plants.all, &df::plant_raw::id, plant_id );
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
// }}} utility Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
/**
|
2014-11-20 03:14:27 -07:00
|
|
|
* Helper class for mapping the various organic mats between their material indices
|
|
|
|
* and their index in the stockpile_settings structures.
|
2014-11-19 01:09:44 -07:00
|
|
|
*/
|
2014-11-19 10:38:03 -07:00
|
|
|
class OrganicMatLookup
|
2014-11-19 01:09:44 -07:00
|
|
|
{
|
2014-11-20 03:14:27 -07:00
|
|
|
|
|
|
|
// pair of material type and index
|
2014-11-20 03:18:01 -07:00
|
|
|
typedef std::pair<int16_t, int32_t> FoodMatPair;
|
2014-11-20 03:14:27 -07:00
|
|
|
// map for using type,index pairs to find the food index
|
2014-11-20 03:18:01 -07:00
|
|
|
typedef std::map<FoodMatPair, size_t> FoodMatMap;
|
2014-11-20 03:14:27 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
public:
|
2014-11-20 03:18:01 -07:00
|
|
|
struct FoodMat
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
MaterialInfo material;
|
|
|
|
df::creature_raw *creature;
|
|
|
|
df::caste_raw * caste;
|
|
|
|
FoodMat() : material ( -1 ), creature ( 0 ), caste ( 0 ) {}
|
|
|
|
};
|
2014-11-20 03:53:33 -07:00
|
|
|
static void food_mat_by_idx ( std::ostream &out, organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat & food_mat )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
out << "food_lookup: food_idx(" << 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];
|
|
|
|
int16_t type = table.organic_types[mat_category][food_idx];
|
|
|
|
if ( mat_category == organic_mat_category::Fish ||
|
|
|
|
mat_category == organic_mat_category::UnpreparedFish ||
|
2014-11-20 03:18:01 -07:00
|
|
|
mat_category == organic_mat_category::Eggs )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
food_mat.creature = raws.creatures.all[type];
|
|
|
|
food_mat.caste = food_mat.creature->caste[main_idx];
|
|
|
|
out << " special creature type(" << type << ") caste("<< main_idx <<")" <<endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
food_mat.material.decode ( type, main_idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
out << " type(" << type << ") index("<< main_idx <<") token(" << food_mat.material.getToken() << ")" << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:53:33 -07:00
|
|
|
static std::string food_token_by_idx ( std::ostream &out, organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
FoodMat food_mat;
|
|
|
|
food_mat_by_idx ( out, mat_category, idx, food_mat );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( food_mat.material.isValid() )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return food_mat.material.getToken();
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else if ( food_mat.creature )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return food_mat.creature->creature_id + ":" + food_mat.caste->caste_id;
|
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
static size_t food_max_size ( organic_mat_category::organic_mat_category mat_category )
|
|
|
|
{
|
|
|
|
return world->raws.mat_table.organic_types[mat_category].size();
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
static void food_build_map ( std::ostream &out )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
if ( index_built )
|
|
|
|
return;
|
|
|
|
df::world_raws &raws = world->raws;
|
|
|
|
df::special_mat_table table = raws.mat_table;
|
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
|
|
|
df::enum_traits<organic_mat_category> traits;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( int32_t mat_category = traits.first_item_value; mat_category <= traits.last_item_value; ++mat_category )
|
|
|
|
{
|
|
|
|
for ( size_t i = 0; i < table.organic_indexes[mat_category].size(); ++i )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
int16_t type = table.organic_types[mat_category].at ( i );
|
|
|
|
int32_t index = table.organic_indexes[mat_category].at ( i );
|
|
|
|
food_index[mat_category].insert ( std::make_pair ( std::make_pair ( type,index ), i ) ); // wtf.. only in c++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
index_built = true;
|
|
|
|
}
|
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
static int16_t food_idx_by_token ( std::ostream &out, organic_mat_category::organic_mat_category mat_category, const std::string & token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
int16_t food_idx = -1;
|
|
|
|
df::world_raws &raws = world->raws;
|
|
|
|
df::special_mat_table table = raws.mat_table;
|
|
|
|
out << "food_idx_by_token: ";
|
|
|
|
if ( mat_category == organic_mat_category::Fish ||
|
|
|
|
mat_category == organic_mat_category::UnpreparedFish ||
|
2014-11-20 03:18:01 -07:00
|
|
|
mat_category == organic_mat_category::Eggs )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
std::vector<string> tokens;
|
|
|
|
split_string ( &tokens, token, ":" );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( tokens.size() != 2 )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
out << "creature " << "invalid CREATURE:CASTE token: " << token << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
int16_t creature_idx = find_creature ( tokens[0] );
|
2014-11-21 08:07:08 -07:00
|
|
|
if ( creature_idx < 0 )
|
|
|
|
{
|
|
|
|
out << " creature invalid token " << tokens[0];
|
|
|
|
}
|
|
|
|
else
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
food_idx = linear_index ( table.organic_types[mat_category], creature_idx );
|
2014-11-21 08:07:08 -07:00
|
|
|
if ( tokens[1] == "MALE" )
|
|
|
|
food_idx += 1;
|
|
|
|
if (table.organic_types[mat_category][food_idx] == creature_idx )
|
|
|
|
out << "creature " << token << " caste " << tokens[1] << " creature_idx(" << creature_idx << ") food_idx("<< food_idx << ")" << endl;
|
|
|
|
else {
|
|
|
|
out << "ERROR creature caste not found: " << token << " caste " << tokens[1] << " creature_idx(" << creature_idx << ") food_idx("<< food_idx << ")" << endl;
|
|
|
|
food_idx = -1;
|
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !index_built )
|
2014-11-19 01:09:44 -07:00
|
|
|
food_build_map ( out );
|
2014-11-19 10:38:03 -07:00
|
|
|
MaterialInfo mat_info = food_mat_by_token ( out, token );
|
2014-11-19 01:09:44 -07:00
|
|
|
int16_t type = mat_info.type;
|
|
|
|
int32_t index = mat_info.index;
|
|
|
|
int16_t food_idx2 = -1;
|
|
|
|
auto it = food_index[mat_category].find ( std::make_pair ( type, index ) );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( it != food_index[mat_category].end() )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
out << "matinfo: " << token << " type(" << mat_info.type << ") idx(" << mat_info.index << ") food_idx(" << it->second << ")" << endl;
|
2014-11-19 10:38:03 -07:00
|
|
|
food_idx = it->second;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-19 10:38:03 -07:00
|
|
|
out << "matinfo: " << token << " type(" << mat_info.type << ") idx(" << mat_info.index << ") food_idx not found :(" << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return food_idx;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
static MaterialInfo food_mat_by_token ( std::ostream &out, const std::string & token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
MaterialInfo mat_info;
|
|
|
|
mat_info.find ( token );
|
|
|
|
return mat_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool index_built;
|
|
|
|
static std::vector<FoodMatMap> food_index;
|
|
|
|
private:
|
2014-11-19 10:38:03 -07:00
|
|
|
OrganicMatLookup() {}
|
2014-11-19 01:09:44 -07:00
|
|
|
};
|
|
|
|
|
2014-11-19 10:38:03 -07:00
|
|
|
bool OrganicMatLookup::index_built = false;
|
2014-11-20 03:14:27 -07:00
|
|
|
std::vector<OrganicMatLookup::FoodMatMap> OrganicMatLookup::food_index = std::vector<OrganicMatLookup::FoodMatMap> ( 37 );
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Null buffer that acts like /dev/null for when debug is disabled
|
|
|
|
*/
|
|
|
|
class NullBuffer : public std::streambuf
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int overflow ( int c )
|
|
|
|
{
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NullStream : public std::ostream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NullStream() : std::ostream ( &m_sb ) {}
|
|
|
|
private:
|
|
|
|
NullBuffer m_sb;
|
|
|
|
};
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* Class for serializing the stockpile_settings structure into a Google protobuf
|
|
|
|
*/
|
2014-11-19 01:09:44 -07:00
|
|
|
class StockpileSerializer
|
|
|
|
{
|
|
|
|
public:
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @param out for debugging
|
|
|
|
* @param stockpile stockpile to read or write settings to
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
StockpileSerializer ( building_stockpilest * stockpile )
|
2014-11-20 03:53:33 -07:00
|
|
|
: mDebug ( false )
|
|
|
|
, mOut ( 0 )
|
|
|
|
, mNull()
|
2014-11-20 03:18:01 -07:00
|
|
|
, mPile ( stockpile )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// build other_mats indices
|
2014-11-19 01:09:44 -07:00
|
|
|
furniture_setup_other_mats();
|
2014-11-19 06:14:46 -07:00
|
|
|
bars_blocks_setup_other_mats();
|
2014-11-19 09:46:52 -07:00
|
|
|
finished_goods_setup_other_mats();
|
2014-11-19 11:53:53 -07:00
|
|
|
weapons_armor_setup_other_mats();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-19 11:53:53 -07:00
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
~StockpileSerializer() {}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
void enable_debug ( color_ostream&out )
|
|
|
|
{
|
|
|
|
mDebug = true;
|
|
|
|
mOut = &out;
|
|
|
|
}
|
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
/**
|
|
|
|
* Will serialize stockpile settings to a file (overwrites existing files)
|
|
|
|
* @return success/failure
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
bool serialize_to_file ( const std::string & file )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
mBuffer.Clear();
|
|
|
|
write();
|
|
|
|
std::fstream output ( file, std::ios::out | std::ios::binary );
|
|
|
|
return mBuffer.SerializeToOstream ( &output );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serializes the stockpile settings to a string.
|
|
|
|
* @return empty string on error
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
std::string serialize_to_string()
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
mBuffer.Clear();
|
|
|
|
write();
|
|
|
|
std::string str;
|
|
|
|
if ( !TextFormat::PrintToString ( mBuffer, &str ) )
|
|
|
|
return std::string();
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* Read stockpile settings from file
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
bool unserialize_from_file ( const std::string & file )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
mBuffer.Clear();
|
2014-11-20 03:18:01 -07:00
|
|
|
std::fstream input ( file, std::ios::in | std::ios::binary );
|
|
|
|
const bool res = mBuffer.ParseFromIstream ( &input );
|
2014-11-20 02:33:09 -07:00
|
|
|
read();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* Read text_format stockpile settings from string
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
bool unserialize_from_string ( const std::string & data )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
mBuffer.Clear();
|
2014-11-20 03:14:27 -07:00
|
|
|
return TextFormat::ParseFromString ( data, &mBuffer );
|
2014-11-20 02:33:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-11-20 03:14:27 -07:00
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
bool mDebug;
|
|
|
|
std::ostream * mOut;
|
|
|
|
NullStream mNull;
|
2014-11-21 06:37:37 -07:00
|
|
|
building_stockpilest * mPile;
|
2014-11-20 03:53:33 -07:00
|
|
|
StockpileSettings mBuffer;
|
|
|
|
std::map<int, std::string> mOtherMatsFurniture;
|
|
|
|
std::map<int, std::string> mOtherMatsFinishedGoods;
|
|
|
|
std::map<int, std::string> mOtherMatsBars;
|
|
|
|
std::map<int, std::string> mOtherMatsBlocks;
|
|
|
|
std::map<int, std::string> mOtherMatsWeaponsArmor;
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream & debug()
|
|
|
|
{
|
|
|
|
if ( mDebug )
|
|
|
|
return *mOut;
|
|
|
|
return mNull;
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
/**
|
|
|
|
read memory structures and serialize to protobuf
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
void write()
|
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
// debug() << "GROUP SET " << bitfield_to_string(mPile->settings.flags) << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
write_general();
|
|
|
|
if ( mPile->settings.flags.bits.animals )
|
|
|
|
write_animals();
|
|
|
|
if ( mPile->settings.flags.bits.food )
|
|
|
|
write_food();
|
|
|
|
if ( mPile->settings.flags.bits.furniture )
|
|
|
|
write_furniture();
|
|
|
|
if ( mPile->settings.flags.bits.refuse )
|
|
|
|
write_refuse();
|
|
|
|
if ( mPile->settings.flags.bits.stone )
|
|
|
|
write_stone();
|
|
|
|
if ( mPile->settings.flags.bits.ammo )
|
|
|
|
write_ammo();
|
2014-11-19 02:20:54 -07:00
|
|
|
if ( mPile->settings.flags.bits.coins )
|
|
|
|
write_coins();
|
2014-11-19 06:14:46 -07:00
|
|
|
if ( mPile->settings.flags.bits.bars_blocks )
|
|
|
|
write_bars_blocks();
|
|
|
|
if ( mPile->settings.flags.bits.gems )
|
|
|
|
write_gems();
|
|
|
|
if ( mPile->settings.flags.bits.finished_goods )
|
|
|
|
write_finished_goods();
|
|
|
|
if ( mPile->settings.flags.bits.leather )
|
|
|
|
write_leather();
|
|
|
|
if ( mPile->settings.flags.bits.cloth )
|
|
|
|
write_cloth();
|
|
|
|
if ( mPile->settings.flags.bits.wood )
|
|
|
|
write_wood();
|
|
|
|
if ( mPile->settings.flags.bits.weapons )
|
|
|
|
write_weapons();
|
|
|
|
if ( mPile->settings.flags.bits.armor )
|
|
|
|
write_armor();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
// parse serialized data into ui indices
|
2014-11-20 03:18:01 -07:00
|
|
|
void read ()
|
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << endl << "==READ==" << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
read_general();
|
|
|
|
read_animals();
|
|
|
|
read_food();
|
|
|
|
read_furniture();
|
|
|
|
read_refuse();
|
|
|
|
read_stone();
|
|
|
|
read_ammo();
|
2014-11-19 02:20:54 -07:00
|
|
|
read_coins();
|
2014-11-19 06:14:46 -07:00
|
|
|
read_bars_blocks();
|
|
|
|
read_gems();
|
|
|
|
read_finished_goods();
|
|
|
|
read_leather();
|
|
|
|
read_cloth();
|
|
|
|
read_wood();
|
|
|
|
read_weapons();
|
|
|
|
read_armor();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an enum's value based off the string label.
|
|
|
|
* @param traits the enum's trait struct
|
|
|
|
* @param token the string value in key_table
|
2014-11-21 06:37:37 -07:00
|
|
|
* @return the enum's value, -1 if not found
|
2014-11-19 01:09:44 -07:00
|
|
|
*/
|
|
|
|
template<typename E>
|
2014-11-20 03:53:33 -07:00
|
|
|
static typename df::enum_traits<E>::base_type linear_index ( std::ostream & out, df::enum_traits<E> traits, const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
auto j = traits.first_item_value;
|
|
|
|
auto limit = traits.last_item_value;
|
|
|
|
// sometimes enums start at -1, which is bad news for array indexing
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( j < 0 )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
j += abs ( traits.first_item_value );
|
|
|
|
limit += abs ( traits.first_item_value );
|
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( ; j <= limit; ++j )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
// out << " linear_index("<< token <<") = table["<<j<<"/"<<limit<<"]: " <<traits.key_table[j] << endl;
|
|
|
|
if ( token.compare ( traits.key_table[j] ) == 0 )
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
// read the token from the serailized list during import
|
|
|
|
typedef std::function<std::string ( const size_t& ) > FuncReadImport;
|
|
|
|
// add the token to the serialized list during export
|
|
|
|
typedef std::function<void ( const string & ) > FuncWriteExport;
|
|
|
|
// are item's of item_type allowed?
|
|
|
|
typedef std::function<bool ( item_type::item_type ) > FuncItemAllowed;
|
2014-11-19 09:46:52 -07:00
|
|
|
// is this material allowed?
|
2014-11-20 02:33:09 -07:00
|
|
|
typedef std::function<bool ( const MaterialInfo & ) > FuncMaterialAllowed;
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
// convenient struct for parsing food stockpile items
|
2014-11-20 03:18:01 -07:00
|
|
|
struct food_pair
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
// exporting
|
|
|
|
FuncWriteExport set_value;
|
2014-11-21 06:37:37 -07:00
|
|
|
std::vector<char> * stockpile_values;
|
2014-11-19 06:14:46 -07:00
|
|
|
// importing
|
|
|
|
FuncReadImport get_value;
|
|
|
|
size_t serialized_count;
|
2014-11-21 06:37:37 -07:00
|
|
|
bool valid = false;
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
food_pair ( FuncWriteExport s, std::vector<char>* sp_v, FuncReadImport g, size_t count )
|
2014-11-19 06:14:46 -07:00
|
|
|
: set_value ( s )
|
|
|
|
, stockpile_values ( sp_v )
|
|
|
|
, get_value ( g )
|
2014-11-21 06:37:37 -07:00
|
|
|
, serialized_count ( count )
|
|
|
|
, valid ( true )
|
2014-11-19 06:14:46 -07:00
|
|
|
{}
|
|
|
|
food_pair() {}
|
|
|
|
};
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* There are many repeated (un)serialization cases throughout the stockpile_settings structure,
|
|
|
|
* so the most common cases have been generalized into generic functions using lambdas.
|
|
|
|
*
|
|
|
|
* The basic process to serialize a stockpile_settings structure is:
|
|
|
|
* 1. loop through the list
|
|
|
|
* 2. for every element that is TRUE:
|
|
|
|
* 3. map the specific stockpile_settings index into a general material, creature, etc index
|
|
|
|
* 4. verify that type is allowed in the list (e.g., no stone in gems stockpiles)
|
|
|
|
* 5. add it to the protobuf using FuncWriteExport
|
|
|
|
*
|
|
|
|
* The unserialization process is the same in reverse.
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void serialize_list_organic_mat ( FuncWriteExport add_value, const std::vector<char> * list, organic_mat_category::organic_mat_category cat )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( !list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
debug() << "serialize_list_organic_mat: list null" << endl;
|
|
|
|
}
|
|
|
|
for ( size_t i = 0; i < list->size(); ++i )
|
|
|
|
{
|
|
|
|
if ( list->at ( i ) )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
std::string token = OrganicMatLookup::food_token_by_idx ( debug(), cat, i );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( !token.empty() )
|
|
|
|
{
|
2014-11-19 10:38:03 -07:00
|
|
|
add_value ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
debug() << " organic_material " << i << " is " << token << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "food mat invalid :(" << endl;
|
2014-11-19 10:38:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void unserialize_list_organic_mat ( FuncReadImport get_value, size_t list_size, std::vector<char> *pile_list, organic_mat_category::organic_mat_category cat )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
|
|
|
if ( list_size > 0 )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
pile_list->resize ( OrganicMatLookup::food_max_size ( cat ), '\0' );
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < list_size; ++i )
|
|
|
|
{
|
2014-11-19 10:38:03 -07:00
|
|
|
std::string token = get_value ( i );
|
2014-11-21 06:37:37 -07:00
|
|
|
int16_t idx = OrganicMatLookup::food_idx_by_token ( debug(), cat, token );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " organic_material " << idx << " is " << token << endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( idx >= pile_list->size() )
|
|
|
|
{
|
|
|
|
debug() << "error organic mat index too large! idx[" << idx << "] max_size[" << pile_list->size() << "]" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pile_list->at ( idx ) = 1;
|
2014-11-19 10:38:03 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
|
|
|
}
|
2014-11-19 10:38:03 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void serialize_list_item_type ( FuncItemAllowed is_allowed, FuncWriteExport add_value, const std::vector<char> &list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
using df::enums::item_type::item_type;
|
|
|
|
df::enum_traits<item_type> type_traits;
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "item_type size = " << list.size() << " size limit = " << type_traits.last_item_value << " typecasted: " << ( size_t ) type_traits.last_item_value << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i <= ( size_t ) type_traits.last_item_value; ++i )
|
|
|
|
{
|
|
|
|
if ( list.at ( i ) )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
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 );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "item_type key_table[" << i+1 << "] type[" << ( int16_t ) type << "] is " << r_type <<endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void unserialize_list_item_type ( FuncItemAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char> *pile_list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( list_size > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
using df::enums::item_type::item_type;
|
|
|
|
df::enum_traits<item_type> type_traits;
|
|
|
|
pile_list->resize ( 112, '\0' ); // TODO remove hardcoded list size value
|
|
|
|
for ( int32_t i = 0; i < list_size; ++i )
|
|
|
|
{
|
|
|
|
const std::string token = read_value ( i );
|
|
|
|
// subtract one because item_type starts at -1
|
|
|
|
const df::enum_traits<item_type>::base_type idx = linear_index ( debug(), type_traits, token ) - 1;
|
|
|
|
const item_type type = ( item_type ) idx;
|
|
|
|
if ( !is_allowed ( type ) ) continue;
|
|
|
|
debug() << " item_type " << idx << " is " << token << endl;
|
|
|
|
if ( idx >= pile_list->size() )
|
|
|
|
{
|
|
|
|
debug() << "error item_type index too large! idx[" << idx << "] max_size[" << pile_list->size() << "]" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pile_list->at ( idx ) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void serialize_list_material ( FuncMaterialAllowed is_allowed, FuncWriteExport add_value, const std::vector<char> &list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
MaterialInfo mi;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < list.size(); ++i )
|
|
|
|
{
|
|
|
|
if ( list.at ( i ) )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
mi.decode ( 0, i );
|
2014-11-20 02:33:09 -07:00
|
|
|
if ( !is_allowed ( mi ) ) continue;
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " material" << i << " is " << mi.getToken() << endl;
|
2014-11-20 02:33:09 -07:00
|
|
|
add_value ( mi.getToken() );
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void unserialize_list_material ( FuncMaterialAllowed is_allowed, FuncReadImport read_value, int32_t list_size, std::vector<char> *pile_list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( list_size > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
std::set<int32_t> idx_set;
|
|
|
|
pile_list->resize ( world->raws.inorganics.size(), '\0' );
|
|
|
|
for ( int i = 0; i < list_size; ++i )
|
|
|
|
{
|
|
|
|
const std::string token = read_value ( i );
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.find ( token );
|
|
|
|
if ( !is_allowed ( mi ) ) continue;
|
|
|
|
debug() << " material " << mi.index << " is " << token << endl;
|
|
|
|
if ( mi.index >= pile_list->size() )
|
|
|
|
{
|
|
|
|
debug() << "error material index too large! idx[" << mi.index << "] max_size[" << pile_list->size() << "]" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pile_list->at ( mi.index ) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
void serialize_list_quality ( FuncWriteExport add_value, const bool ( &quality_list ) [7] )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
using df::enums::item_quality::item_quality;
|
|
|
|
df::enum_traits<item_quality> quality_traits;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < 7; ++i )
|
|
|
|
{
|
|
|
|
if ( quality_list[i] )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
const std::string f_type ( quality_traits.key_table[i] );
|
2014-11-20 02:33:09 -07:00
|
|
|
add_value ( f_type );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " quality: " << i << " is " << f_type <<endl;
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
/**
|
|
|
|
* Set all values in a bool[7] to false
|
|
|
|
*/
|
|
|
|
void quality_clear ( bool ( &pile_list ) [7] )
|
|
|
|
{
|
|
|
|
std::fill ( pile_list, pile_list+7, false );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void unserialize_list_quality ( FuncReadImport read_value, int32_t list_size, bool ( &pile_list ) [7] )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 09:29:15 -07:00
|
|
|
if ( list_size > 0 && list_size <= 7 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
using df::enums::item_quality::item_quality;
|
|
|
|
df::enum_traits<item_quality> quality_traits;
|
|
|
|
for ( int i = 0; i < list_size; ++i )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
const std::string quality = read_value ( i );
|
|
|
|
df::enum_traits<item_quality>::base_type idx = linear_index ( debug(), quality_traits, quality );
|
|
|
|
if ( idx < 0 )
|
|
|
|
{
|
|
|
|
debug() << " invalid quality token " << quality << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug() << " quality: " << idx << " is " << quality << endl;
|
|
|
|
pile_list[idx] = true;
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quality_clear ( pile_list );
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
void 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 ) )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
const std::string token = other_mats_index ( other_mats, i );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( token.empty() )
|
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " invalid other material with index " << i << endl;
|
2014-11-19 09:46:52 -07:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 02:33:09 -07:00
|
|
|
add_value ( token );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " other mats " << i << " is " << token << endl;
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void 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-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( list_size > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
pile_list->resize ( other_mats.size(), '\0' );
|
|
|
|
for ( int i = 0; i < list_size; ++i )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
const std::string token = read_value ( i );
|
|
|
|
size_t idx = other_mats_token ( other_mats, token );
|
|
|
|
if ( idx < 0 )
|
|
|
|
{
|
|
|
|
debug() << "invalid other mat with token " << token;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug() << " other_mats " << idx << " is " << token << endl;
|
|
|
|
if ( idx >= pile_list->size() )
|
|
|
|
{
|
|
|
|
debug() << "error other_mats index too large! idx[" << idx << "] max_size[" << pile_list->size() << "]" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pile_list->at ( idx ) = 1;
|
2014-11-20 02:33:09 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
2014-11-20 02:33:09 -07:00
|
|
|
}
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
void 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 ) )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
const df::itemdef *a = items.at ( i );
|
|
|
|
// skip procedurally generated items
|
|
|
|
if ( a->base_flags.is_set ( 0 ) ) continue;
|
|
|
|
ItemTypeInfo ii;
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( !ii.decode ( type, i ) ) continue;
|
2014-11-19 11:53:53 -07:00
|
|
|
add_value ( ii.getToken() );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " itemdef type" << i << " is " << ii.getToken() << endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* @see serialize_list_organic_mat
|
|
|
|
*/
|
2014-11-21 06:37:37 -07:00
|
|
|
void unserialize_list_itemdef ( FuncReadImport read_value, int32_t list_size, std::vector<char> *pile_list, item_type::item_type type )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( list_size > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
pile_list->resize ( Items::getSubtypeCount ( type ), '\0' );
|
|
|
|
for ( int i = 0; i < list_size; ++i )
|
|
|
|
{
|
|
|
|
std::string token = read_value ( i );
|
|
|
|
ItemTypeInfo ii;
|
|
|
|
if ( !ii.find ( token ) ) continue;
|
|
|
|
debug() << " itemdef " << ii.subtype << " is " << token << endl;
|
|
|
|
if ( ii.subtype >= pile_list->size() )
|
|
|
|
{
|
|
|
|
debug() << "error itemdef index too large! idx[" << ii.subtype << "] max_size[" << pile_list->size() << "]" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pile_list->at ( ii.subtype ) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* Given a list of other_materials and an index, return its corresponding token
|
|
|
|
* @return empty string if not found
|
|
|
|
* @see other_mats_token
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
std::string other_mats_index ( const std::map<int, std::string> other_mats, int idx )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
auto it = other_mats.find ( idx );
|
|
|
|
if ( it == other_mats.end() )
|
|
|
|
return std::string();
|
|
|
|
return it->second;
|
|
|
|
}
|
2014-11-20 03:14:27 -07:00
|
|
|
/**
|
|
|
|
* Given a list of other_materials and a token, return its corresponding index
|
|
|
|
* @return -1 if not found
|
|
|
|
* @see other_mats_index
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
int 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 )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
if ( it->second == token )
|
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_general()
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.set_max_bins ( mPile->max_barrels );
|
|
|
|
mBuffer.set_max_wheelbarrows ( mPile->max_wheelbarrows );
|
|
|
|
mBuffer.set_use_links_only ( mPile->use_links_only );
|
|
|
|
mBuffer.set_unknown1 ( mPile->settings.unk1 );
|
2014-11-20 02:33:09 -07:00
|
|
|
mBuffer.set_allow_inorganic ( mPile->settings.allow_inorganic );
|
|
|
|
mBuffer.set_allow_organic ( mPile->settings.allow_organic );
|
2014-11-21 06:37:37 -07:00
|
|
|
mBuffer.set_corpses ( mPile->settings.flags.bits.corpses );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 02:33:09 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_general()
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( mBuffer.has_max_bins() )
|
|
|
|
mPile->max_bins = mBuffer.max_bins();
|
|
|
|
if ( mBuffer.has_max_wheelbarrows() )
|
|
|
|
mPile->max_wheelbarrows = mBuffer.max_wheelbarrows();
|
|
|
|
if ( mBuffer.has_max_barrels() )
|
|
|
|
mPile->max_barrels = mBuffer.max_barrels();
|
|
|
|
if ( mBuffer.has_use_links_only() )
|
|
|
|
mPile->use_links_only = mBuffer.use_links_only();
|
|
|
|
if ( mBuffer.has_unknown1() )
|
|
|
|
mPile->settings.unk1 = mBuffer.unknown1();
|
|
|
|
if ( mBuffer.has_allow_inorganic() )
|
|
|
|
mPile->settings.allow_inorganic = mBuffer.allow_inorganic();
|
|
|
|
if ( mBuffer.has_allow_organic() )
|
|
|
|
mPile->settings.allow_organic = mBuffer.allow_organic();
|
|
|
|
if ( mBuffer.has_corpses() )
|
|
|
|
mPile->settings.flags.bits.corpses = mBuffer.corpses();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 02:33:09 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_animals()
|
|
|
|
{
|
2014-11-21 10:09:07 -07:00
|
|
|
StockpileSettings::AnimalsSet *animals= mBuffer.mutable_animals();
|
|
|
|
animals->set_empty_cages ( mPile->settings.animals.empty_cages );
|
|
|
|
animals->set_empty_traps ( mPile->settings.animals.empty_traps );
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < mPile->settings.animals.enabled.size(); ++i )
|
|
|
|
{
|
|
|
|
if ( mPile->settings.animals.enabled.at ( i ) == 1 )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
df::creature_raw* r = find_creature ( i );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "creature "<< r->creature_id << " " << i << endl;
|
2014-11-21 10:09:07 -07:00
|
|
|
animals->add_enabled ( r->creature_id );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_animals()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_animals() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.animals = 1;
|
|
|
|
debug() << "animals:" << endl;
|
|
|
|
mPile->settings.animals.empty_cages = mBuffer.animals().empty_cages();
|
|
|
|
mPile->settings.animals.empty_traps = mBuffer.animals().empty_traps();
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( mBuffer.animals().enabled_size() > 0 )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.animals.enabled.resize ( world->raws.creatures.all.size(), '\0' );
|
|
|
|
debug() << " pile has " << mPile->settings.animals.enabled.size() << endl;
|
|
|
|
for ( auto i = 0; i < mBuffer.animals().enabled_size(); ++i )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
std::string id = mBuffer.animals().enabled ( i );
|
|
|
|
int idx = find_creature ( id );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << id << " " << idx << endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( idx < 0 || idx >= mPile->settings.animals.enabled.size() )
|
|
|
|
{
|
|
|
|
debug() << "WARNING: animal index invalid: " << idx << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mPile->settings.animals.enabled.at ( idx ) = ( char ) 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.animals.enabled.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.animals.enabled.clear();
|
|
|
|
mPile->settings.flags.bits.animals = 0;
|
2014-11-21 10:09:07 -07:00
|
|
|
mPile->settings.animals.empty_cages = false;
|
|
|
|
mPile->settings.animals.empty_traps = false;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
food_pair food_map ( organic_mat_category::organic_mat_category cat )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
|
|
|
using namespace std::placeholders;
|
2014-11-20 03:18:01 -07:00
|
|
|
switch ( cat )
|
|
|
|
{
|
|
|
|
case organic_mat_category::Meat:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_meat ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().meat ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.meat, getter, mBuffer.food().meat_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Fish:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_fish ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().fish ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.fish, getter, mBuffer.food().fish_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::UnpreparedFish:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_unprepared_fish ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().unprepared_fish ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.unprepared_fish, getter, mBuffer.food().unprepared_fish_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Eggs:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_egg ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().egg ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.egg, getter, mBuffer.food().egg_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Plants:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_plants ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().plants ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.plants, getter, mBuffer.food().plants_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::PlantDrink:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_drink_plant ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().drink_plant ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.drink_plant, getter, mBuffer.food().drink_plant_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::CreatureDrink:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_drink_animal ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().drink_animal ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.drink_animal, getter, mBuffer.food().drink_animal_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::PlantCheese:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_cheese_plant ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().cheese_plant ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.cheese_plant, getter, mBuffer.food().cheese_plant_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::CreatureCheese:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_cheese_animal ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().cheese_animal ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.cheese_animal, getter, mBuffer.food().cheese_animal_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Seed:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_seeds ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().seeds ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.seeds, getter, mBuffer.food().seeds_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Leaf:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_leaves ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().leaves ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.leaves, getter, mBuffer.food().leaves_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::PlantPowder:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_powder_plant ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().powder_plant ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.powder_plant, getter, mBuffer.food().powder_plant_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::CreaturePowder:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_powder_creature ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().powder_creature ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.powder_creature, getter, mBuffer.food().powder_creature_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Glob:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_glob ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().glob ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.glob, getter, mBuffer.food().glob_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::PlantLiquid:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_liquid_plant ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().liquid_plant ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.liquid_plant, getter, mBuffer.food().liquid_plant_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::CreatureLiquid:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_liquid_animal ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().liquid_animal ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.liquid_animal, getter, mBuffer.food().liquid_animal_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::MiscLiquid:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_liquid_misc ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().liquid_misc ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.liquid_misc, getter, mBuffer.food().liquid_misc_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Paste:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_glob_paste ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().glob_paste ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.glob_paste, getter, mBuffer.food().glob_paste_size() );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
case organic_mat_category::Pressed:
|
|
|
|
{
|
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
mBuffer.mutable_food()->add_glob_pressed ( id );
|
|
|
|
};
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncReadImport getter = [=] ( size_t idx ) -> std::string { return mBuffer.food().glob_pressed ( idx ); };
|
2014-11-21 06:37:37 -07:00
|
|
|
return food_pair ( setter, &mPile->settings.food.glob_pressed, getter, mBuffer.food().glob_pressed_size() );
|
2014-11-19 01:09:44 -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:
|
2014-11-21 06:37:37 -07:00
|
|
|
default:
|
2014-11-19 01:09:44 -07:00
|
|
|
// not used in stockpile food menu
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return food_pair();
|
|
|
|
}
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_food()
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
StockpileSettings::FoodSet *food = mBuffer.mutable_food();
|
2014-11-21 06:37:37 -07:00
|
|
|
debug() << " food: " << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
food->set_prepared_meals ( mPile->settings.food.prepared_meals );
|
|
|
|
|
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
|
|
|
df::enum_traits<organic_mat_category> traits;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( int32_t mat_category = traits.first_item_value; mat_category <traits.last_item_value; ++mat_category )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
food_pair p = food_map ( ( organic_mat_category ) mat_category );
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( !p.valid ) continue;
|
|
|
|
debug() << " food: " << traits.key_table[mat_category] << endl;
|
2014-11-19 10:38:03 -07:00
|
|
|
serialize_list_organic_mat ( p.set_value, p.stockpile_values, ( organic_mat_category ) mat_category );
|
2014-11-21 06:37:37 -07:00
|
|
|
debug() << " finished food : " << traits.key_table[mat_category] << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_food()
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
using df::enums::organic_mat_category::organic_mat_category;
|
|
|
|
df::enum_traits<organic_mat_category> traits;
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( mBuffer.has_food() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.food = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
const StockpileSettings::FoodSet food = mBuffer.food();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "food:" <<endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( food.has_prepared_meals() )
|
|
|
|
mPile->settings.food.prepared_meals = food.prepared_meals();
|
|
|
|
else
|
|
|
|
mPile->settings.food.prepared_meals = true;
|
|
|
|
|
2014-11-21 10:09:07 -07:00
|
|
|
debug() << " prepared_meals: " << mPile->settings.food.prepared_meals << endl;
|
|
|
|
|
2014-11-21 06:37:37 -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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( int32_t mat_category = traits.first_item_value; mat_category <traits.last_item_value; ++mat_category )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
food_pair p = food_map ( ( organic_mat_category ) mat_category );
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( !p.valid ) continue;
|
|
|
|
p.stockpile_values->clear();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.food = 0;
|
2014-11-21 10:09:07 -07:00
|
|
|
mPile->settings.food.prepared_meals = false;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void furniture_setup_other_mats()
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
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-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_furniture()
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
StockpileSettings::FurnitureSet *furniture= mBuffer.mutable_furniture();
|
|
|
|
furniture->set_sand_bags ( mPile->settings.furniture.sand_bags );
|
|
|
|
|
|
|
|
// FURNITURE type
|
|
|
|
using df::enums::furniture_type::furniture_type;
|
|
|
|
df::enum_traits<furniture_type> type_traits;
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < mPile->settings.furniture.type.size(); ++i )
|
|
|
|
{
|
|
|
|
if ( mPile->settings.furniture.type.at ( i ) )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
std::string f_type ( type_traits.key_table[i] );
|
|
|
|
furniture->add_type ( f_type );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "furniture_type " << i << " is " << f_type <<endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// metal, stone/clay materials
|
2014-11-21 06:37:37 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::furniture_mat_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
furniture->add_mats ( token );
|
|
|
|
}, mPile->settings.furniture.mats );
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsFurniture, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
furniture->add_other_mats ( token );
|
|
|
|
}, mPile->settings.furniture.other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
furniture->add_quality_core ( token );
|
|
|
|
}, mPile->settings.furniture.quality_core );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
furniture->add_quality_total ( token );
|
|
|
|
}, mPile->settings.furniture.quality_total );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* skip gems and non hard things
|
|
|
|
should be roughly (<range>:<step): 32-158:1,242-262:1,264-282:2,283-310:1
|
|
|
|
*/
|
2014-11-20 03:18:01 -07:00
|
|
|
bool furniture_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
if ( !mi.isValid() ) return false;
|
|
|
|
return !mi.material->flags.is_set ( material_flags::IS_GEM ) && mi.material->flags.is_set ( material_flags::ITEMS_HARD );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_furniture()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_furniture() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.furniture = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
const StockpileSettings::FurnitureSet furniture = mBuffer.furniture();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "furniture:" <<endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
|
2014-11-21 09:42:38 -07:00
|
|
|
if (mBuffer.furniture().has_sand_bags())
|
|
|
|
mPile->settings.furniture.sand_bags = mBuffer.furniture().sand_bags();
|
|
|
|
else
|
|
|
|
mPile->settings.furniture.sand_bags = false;
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// type
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( furniture.type_size() > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
using df::enums::furniture_type::furniture_type;
|
|
|
|
df::enum_traits<furniture_type> type_traits;
|
|
|
|
mPile->settings.furniture.type.resize ( type_traits.last_item_value+1, '\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 ( debug(), type_traits, type );
|
|
|
|
debug() << " type " << idx << " is " << type << endl;
|
|
|
|
if ( idx < 0 || idx >= mPile->settings.furniture.type.size() )
|
|
|
|
{
|
|
|
|
debug() << "WARNING: furniture type index invalid " << type << ", idx=" << idx << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mPile->settings.furniture.type.at ( idx ) = 1;
|
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
mPile->settings.furniture.type.clear();
|
|
|
|
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::furniture_mat_is_allowed, this, _1 );
|
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
return furniture.mats ( idx );
|
|
|
|
}, furniture.mats_size(), &mPile->settings.furniture.mats );
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// other materials
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsFurniture, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return furniture.other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, furniture.other_mats_size(), &mPile->settings.furniture.other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// core quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return furniture.quality_core ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, furniture.quality_core_size(), mPile->settings.furniture.quality_core );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// total quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return furniture.quality_total ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, furniture.quality_total_size(), mPile->settings.furniture.quality_total );
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.furniture = 0;
|
|
|
|
mPile->settings.furniture.type.clear();
|
|
|
|
mPile->settings.furniture.other_mats.clear();
|
|
|
|
mPile->settings.furniture.mats.clear();
|
|
|
|
quality_clear ( mPile->settings.furniture.quality_core );
|
|
|
|
quality_clear ( mPile->settings.furniture.quality_total );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool refuse_creature_is_allowed ( const df::creature_raw *raw )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
if ( !raw ) return false;
|
|
|
|
// wagon and generated creatures not allowed, except angels
|
|
|
|
const bool is_wagon = raw->creature_id == "EQUIPMENT_WAGON";
|
|
|
|
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-11-20 03:18:01 -07:00
|
|
|
void 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 )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
df::creature_raw* r = find_creature ( i );
|
|
|
|
// skip forgotten beasts, titans, demons, and night creatures
|
|
|
|
if ( !refuse_creature_is_allowed ( r ) ) continue;
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "creature "<< r->creature_id << " " << i << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
add_value ( r->creature_id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool refuse_type_is_allowed ( item_type::item_type type )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
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;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_refuse()
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// type
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncItemAllowed filter = std::bind ( &StockpileSerializer::refuse_type_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_item_type ( filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
refuse->add_type ( token );
|
|
|
|
}, mPile->settings.refuse.type );
|
|
|
|
|
2014-11-19 01:09:44 -07:00
|
|
|
// corpses
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_corpses ( id );
|
|
|
|
}, mPile->settings.refuse.corpses );
|
|
|
|
// body_parts
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_body_parts ( id );
|
|
|
|
}, mPile->settings.refuse.body_parts );
|
|
|
|
// skulls
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_skulls ( id );
|
|
|
|
}, mPile->settings.refuse.skulls );
|
|
|
|
// bones
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_bones ( id );
|
|
|
|
}, mPile->settings.refuse.bones );
|
|
|
|
// hair
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_hair ( id );
|
|
|
|
}, mPile->settings.refuse.hair );
|
|
|
|
// shells
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_shells ( id );
|
|
|
|
}, mPile->settings.refuse.shells );
|
|
|
|
// teeth
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_teeth ( id );
|
|
|
|
}, mPile->settings.refuse.teeth );
|
|
|
|
// horns
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_write_helper ( [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
refuse->add_horns ( id );
|
|
|
|
}, mPile->settings.refuse.horns );
|
|
|
|
}
|
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
void refuse_read_helper ( std::function<std::string ( const size_t& ) > get_value, size_t list_size, std::vector<char>* pile_list )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
|
|
|
if ( list_size > 0 )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
pile_list->resize ( world->raws.creatures.all.size(), '\0' );
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < list_size; ++i )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
const std::string creature_id = get_value ( i );
|
|
|
|
const int idx = find_creature ( creature_id );
|
|
|
|
const df::creature_raw* creature = find_creature ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( idx < 0 || !refuse_creature_is_allowed ( creature ) || idx >= pile_list->size() )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
debug() << "WARNING invalid refuse creature " << creature_id << ", idx=" << idx << endl;
|
2014-11-19 01:09:44 -07:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " creature " << idx << " is " << creature_id << endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
pile_list->at ( idx ) = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pile_list->clear();
|
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_refuse()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_refuse() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.refuse = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
const StockpileSettings::RefuseSet refuse = mBuffer.refuse();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "refuse: " <<endl;
|
|
|
|
debug() << " fresh hide " << refuse.fresh_raw_hide() << endl;
|
|
|
|
debug() << " rotten hide " << refuse.rotten_raw_hide() << endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.refuse.fresh_raw_hide = refuse.fresh_raw_hide();
|
|
|
|
mPile->settings.refuse.rotten_raw_hide = refuse.rotten_raw_hide();
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
// type
|
2014-11-19 06:14:46 -07:00
|
|
|
FuncItemAllowed filter = std::bind ( &StockpileSerializer::refuse_type_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_item_type ( filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return refuse.type ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.type_size(), &mPile->settings.refuse.type );
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
// corpses
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " corpses" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.corpses ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.corpses_size(), &mPile->settings.refuse.corpses );
|
2014-11-19 01:09:44 -07:00
|
|
|
// body_parts
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " body_parts" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.body_parts ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.body_parts_size(), &mPile->settings.refuse.body_parts );
|
2014-11-19 01:09:44 -07:00
|
|
|
// skulls
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " skulls" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.skulls ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.skulls_size(), &mPile->settings.refuse.skulls );
|
2014-11-19 01:09:44 -07:00
|
|
|
// bones
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " bones" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.bones ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.bones_size(), &mPile->settings.refuse.bones );
|
2014-11-19 01:09:44 -07:00
|
|
|
// hair
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " hair" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.hair ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.hair_size(), &mPile->settings.refuse.hair );
|
2014-11-19 01:09:44 -07:00
|
|
|
// shells
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " shells" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.shells ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.shells_size(), &mPile->settings.refuse.shells );
|
2014-11-19 01:09:44 -07:00
|
|
|
// teeth
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " teeth" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.teeth ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.teeth_size(), &mPile->settings.refuse.teeth );
|
2014-11-19 01:09:44 -07:00
|
|
|
// horns
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " horns" << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
refuse_read_helper ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
return refuse.horns ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, refuse.horns_size(), &mPile->settings.refuse.horns );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool stone_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
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-11-20 03:18:01 -07:00
|
|
|
void write_stone()
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
StockpileSettings::StoneSet *stone= mBuffer.mutable_stone();
|
2014-11-21 06:37:37 -07:00
|
|
|
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::stone_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
stone->add_mats ( token );
|
|
|
|
}, mPile->settings.stone.mats );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_stone()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_stone() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.stone = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
const StockpileSettings::StoneSet stone = mBuffer.stone();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "stone: " <<endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::stone_is_allowed, this, _1 );
|
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
return stone.mats ( idx );
|
|
|
|
}, stone.mats_size(), &mPile->settings.stone.mats );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.stone = 0;
|
|
|
|
mPile->settings.stone.mats.clear();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool ammo_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 02:20:54 -07:00
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set ( material_flags::IS_METAL );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_ammo()
|
|
|
|
{
|
2014-11-19 02:20:54 -07:00
|
|
|
StockpileSettings::AmmoSet *ammo = mBuffer.mutable_ammo();
|
|
|
|
|
2014-11-19 11:53:53 -07:00
|
|
|
// ammo type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
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-11-19 02:20:54 -07:00
|
|
|
// metal
|
2014-11-21 06:37:37 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::ammo_mat_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
ammo->add_mats ( token );
|
|
|
|
}, mPile->settings.ammo.mats );
|
|
|
|
|
|
|
|
// other mats - only wood and bone
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( mPile->settings.ammo.other_mats.size() > 2 )
|
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "WARNING: ammo other materials > 2! " << mPile->settings.ammo.other_mats.size() << endl;
|
2014-11-19 02:20:54 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < std::min ( size_t ( 2 ), mPile->settings.ammo.other_mats.size() ); ++i )
|
|
|
|
{
|
2014-11-19 02:20:54 -07:00
|
|
|
if ( !mPile->settings.ammo.other_mats.at ( i ) )
|
|
|
|
continue;
|
|
|
|
const std::string token = i == 0 ? "WOOD" : "BONE";
|
|
|
|
ammo->add_other_mats ( token );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " other mats " << i << " is " << token << endl;
|
2014-11-19 02:20:54 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
|
2014-11-19 02:20:54 -07:00
|
|
|
// quality core
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
ammo->add_quality_core ( token );
|
|
|
|
}, mPile->settings.ammo.quality_core );
|
2014-11-21 06:37:37 -07:00
|
|
|
|
2014-11-19 02:20:54 -07:00
|
|
|
// quality total
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
ammo->add_quality_total ( token );
|
|
|
|
}, mPile->settings.ammo.quality_total );
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_ammo()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_ammo() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.ammo = 1;
|
2014-11-19 01:09:44 -07:00
|
|
|
const StockpileSettings::AmmoSet ammo = mBuffer.ammo();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "ammo: " <<endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
|
|
|
|
// ammo type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return ammo.type ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, ammo.type_size(), &mPile->settings.ammo.type, item_type::AMMO );
|
2014-11-19 11:53:53 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
// materials metals
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::ammo_mat_is_allowed, this, _1 );
|
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
return ammo.mats ( idx );
|
|
|
|
}, ammo.mats_size(), &mPile->settings.ammo.mats );
|
2014-11-19 02:20:54 -07:00
|
|
|
|
|
|
|
// others
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( ammo.other_mats_size() > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
// TODO remove hardcoded value
|
|
|
|
mPile->settings.ammo.other_mats.resize ( 2, '\0' );
|
|
|
|
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() << " other mats " << idx << " is " << token << endl;
|
|
|
|
if ( idx != -1 )
|
|
|
|
mPile->settings.ammo.other_mats.at ( idx ) = 1;
|
|
|
|
}
|
2014-11-19 02:20:54 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
mPile->settings.ammo.other_mats.clear();
|
|
|
|
|
2014-11-19 02:20:54 -07:00
|
|
|
// core quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return ammo.quality_core ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, ammo.quality_core_size(), mPile->settings.ammo.quality_core );
|
|
|
|
|
2014-11-19 02:20:54 -07:00
|
|
|
// total quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return ammo.quality_total ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, ammo.quality_total_size(), mPile->settings.ammo.quality_total );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.ammo = 0;
|
|
|
|
mPile->settings.ammo.type.clear();
|
|
|
|
mPile->settings.ammo.mats.clear();
|
|
|
|
mPile->settings.ammo.other_mats.clear();
|
|
|
|
quality_clear ( mPile->settings.ammo.quality_core );
|
|
|
|
quality_clear ( mPile->settings.ammo.quality_total );
|
2014-11-19 02:20:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool coins_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 02:20:54 -07:00
|
|
|
return mi.isValid();
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_coins()
|
|
|
|
{
|
2014-11-19 02:20:54 -07:00
|
|
|
StockpileSettings::CoinSet *coins = mBuffer.mutable_coin();
|
2014-11-21 06:37:37 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::coins_mat_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
coins->add_mats ( token );
|
|
|
|
}, mPile->settings.coins.mats );
|
2014-11-19 02:20:54 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_coins()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_coin() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.coins = 1;
|
2014-11-19 02:20:54 -07:00
|
|
|
const StockpileSettings::CoinSet coins = mBuffer.coin();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "coins: " <<endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::coins_mat_is_allowed, this, _1 );
|
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
return coins.mats ( idx );
|
|
|
|
}, coins.mats_size(), &mPile->settings.coins.mats );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.coins = 0;
|
|
|
|
mPile->settings.coins.mats.clear();
|
2014-11-19 01:09:44 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void bars_blocks_setup_other_mats()
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
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" ) );
|
|
|
|
|
|
|
|
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-11-20 03:18:01 -07:00
|
|
|
bool bars_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set ( material_flags::IS_METAL );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool blocks_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return mi.isValid() && mi.material && !mi.material->flags.is_set ( material_flags::IS_GEM ) && mi.material->flags.is_set ( material_flags::ITEMS_HARD );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_bars_blocks()
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
StockpileSettings::BarsBlocksSet *bars_blocks = mBuffer.mutable_barsblocks();
|
|
|
|
MaterialInfo mi;
|
2014-11-19 09:46:52 -07:00
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::bars_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
bars_blocks->add_bars_mats ( token );
|
2014-11-19 11:53:53 -07:00
|
|
|
}, mPile->settings.bars_blocks.bars_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
// blocks mats
|
2014-11-19 09:46:52 -07:00
|
|
|
filter = std::bind ( &StockpileSerializer::blocks_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_material ( filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
bars_blocks->add_blocks_mats ( token );
|
2014-11-19 11:53:53 -07:00
|
|
|
}, mPile->settings.bars_blocks.blocks_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
// bars other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsBars, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
bars_blocks->add_bars_other_mats ( token );
|
2014-11-19 09:46:52 -07:00
|
|
|
}, mPile->settings.bars_blocks.bars_other_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// blocks other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsBlocks, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
bars_blocks->add_blocks_other_mats ( token );
|
2014-11-19 09:46:52 -07:00
|
|
|
}, mPile->settings.bars_blocks.blocks_other_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_bars_blocks()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_barsblocks() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.bars_blocks = 1;
|
2014-11-19 06:14:46 -07:00
|
|
|
const StockpileSettings::BarsBlocksSet bars_blocks = mBuffer.barsblocks();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "bars_blocks: " <<endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
// bars
|
|
|
|
FuncMaterialAllowed filter = std::bind ( &StockpileSerializer::bars_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return bars_blocks.bars_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, bars_blocks.bars_mats_size(), &mPile->settings.bars_blocks.bars_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
// blocks
|
|
|
|
filter = std::bind ( &StockpileSerializer::blocks_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_material ( filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return bars_blocks.blocks_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, bars_blocks.blocks_mats_size(), &mPile->settings.bars_blocks.blocks_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
// bars other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsBars, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return bars_blocks.bars_other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, bars_blocks.bars_other_mats_size(), &mPile->settings.bars_blocks.bars_other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
// blocks other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsBlocks, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return bars_blocks.blocks_other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, bars_blocks.blocks_other_mats_size(), &mPile->settings.bars_blocks.blocks_other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool gem_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set ( material_flags::IS_GEM );
|
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
bool gem_cut_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return mi.isValid() && mi.material && ( mi.material->flags.is_set ( material_flags::IS_GEM ) || mi.material->flags.is_set ( material_flags::IS_STONE ) ) ;
|
|
|
|
}
|
2014-11-21 09:57:18 -07:00
|
|
|
bool gem_other_mat_is_allowed(MaterialInfo &mi ) {
|
|
|
|
return mi.isValid() && (mi.getToken() == "GLASS_GREEN" || mi.getToken() == "GLASS_CLEAR" || mi.getToken() == "GLASS_CRYSTAL");
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_gems()
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
StockpileSettings::GemsSet *gems = mBuffer.mutable_gems();
|
|
|
|
MaterialInfo mi;
|
|
|
|
// rough mats
|
2014-11-21 09:57:18 -07:00
|
|
|
FuncMaterialAllowed filter_rough = std::bind ( &StockpileSerializer::gem_mat_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter_rough, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
gems->add_rough_mats ( token );
|
2014-11-19 09:46:52 -07:00
|
|
|
}, mPile->settings.gems.rough_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
// cut mats
|
2014-11-21 09:57:18 -07:00
|
|
|
FuncMaterialAllowed filter_cut = std::bind ( &StockpileSerializer::gem_cut_mat_is_allowed, this, _1 );
|
|
|
|
serialize_list_material ( filter_cut, [=] ( const std::string &token )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
gems->add_cut_mats ( token );
|
|
|
|
}, mPile->settings.gems.cut_mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
// rough other
|
2014-11-20 03:18:01 -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 ) )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
mi.decode ( i, -1 );
|
2014-11-21 09:57:18 -07:00
|
|
|
if ( !gem_other_mat_is_allowed(mi) ) continue;
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " gem rough_other mat" << i << " is " << mi.getToken() << endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
gems->add_rough_other_mats ( mi.getToken() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cut other
|
2014-11-20 03:18:01 -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 ) )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
mi.decode ( i, -1 );
|
|
|
|
if ( !mi.isValid() ) mi.decode ( 0, i );
|
2014-11-21 09:57:18 -07:00
|
|
|
if ( !gem_other_mat_is_allowed(mi) ) continue;
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " gem cut_other mat" << i << " is " << mi.getToken() << endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
gems->add_cut_other_mats ( mi.getToken() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_gems()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_gems() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.gems = 1;
|
2014-11-19 06:14:46 -07:00
|
|
|
const StockpileSettings::GemsSet gems = mBuffer.gems();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "gems: " <<endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
// rough
|
2014-11-21 09:57:18 -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&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return gems.rough_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, gems.rough_mats_size(), &mPile->settings.gems.rough_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
// cut
|
2014-11-21 09:57:18 -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&
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return gems.cut_mats ( idx );
|
2014-11-21 09:57:18 -07:00
|
|
|
}, gems.cut_mats_size(), &mPile->settings.gems.cut_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
const size_t builtin_size = std::extent<decltype ( world->raws.mat_table.builtin ) >::value;
|
2014-11-19 06:14:46 -07:00
|
|
|
// rough other
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( gems.rough_other_mats_size() > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -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 );
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.find ( token );
|
|
|
|
if ( !mi.isValid() || mi.type >= builtin_size )
|
|
|
|
{
|
|
|
|
debug() << "WARNING: invalid gem mat " << token << ". idx=" << mi.type << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug() << " rough_other mats " << mi.type << " is " << token << endl;
|
|
|
|
mPile->settings.gems.rough_other_mats.at ( mi.type ) = 1;
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
mPile->settings.gems.rough_other_mats.clear();
|
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
// cut other
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( gems.cut_other_mats_size() > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -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 );
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.find ( token );
|
|
|
|
if ( !mi.isValid() || mi.type >= builtin_size )
|
|
|
|
{
|
|
|
|
debug() << "WARNING: invalid gem mat " << token << ". idx=" << mi.type << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug() << " cut_other mats " << mi.type << " is " << token << endl;
|
|
|
|
mPile->settings.gems.cut_other_mats.at ( mi.type ) = 1;
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
mPile->settings.gems.cut_other_mats.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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();
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool finished_goods_type_is_allowed ( item_type::item_type type )
|
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
2014-11-19 06:14:46 -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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void finished_goods_setup_other_mats()
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
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-11-20 03:18:01 -07:00
|
|
|
bool finished_goods_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
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-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_finished_goods()
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
StockpileSettings::FinishedGoodsSet *finished_goods = mBuffer.mutable_finished_goods();
|
|
|
|
|
|
|
|
// type
|
|
|
|
FuncItemAllowed filter = std::bind ( &StockpileSerializer::finished_goods_type_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_item_type ( filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
finished_goods->add_type ( token );
|
|
|
|
}, mPile->settings.finished_goods.type );
|
|
|
|
|
|
|
|
// materials
|
2014-11-19 09:46:52 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::finished_goods_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_material ( mat_filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
finished_goods->add_mats ( token );
|
|
|
|
}, mPile->settings.finished_goods.mats );
|
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsFinishedGoods, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
finished_goods->add_other_mats ( token );
|
2014-11-19 09:46:52 -07:00
|
|
|
}, mPile->settings.finished_goods.other_mats );
|
|
|
|
|
|
|
|
// quality core
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
finished_goods->add_quality_core ( token );
|
|
|
|
}, mPile->settings.finished_goods.quality_core );
|
2014-11-21 09:57:18 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// quality total
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
finished_goods->add_quality_total ( token );
|
|
|
|
}, mPile->settings.finished_goods.quality_total );
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_finished_goods()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_finished_goods() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.finished_goods = 1;
|
2014-11-19 06:14:46 -07:00
|
|
|
const StockpileSettings::FinishedGoodsSet finished_goods = mBuffer.finished_goods();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "finished_goods: " <<endl;
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
// type
|
|
|
|
FuncItemAllowed filter = std::bind ( &StockpileSerializer::finished_goods_type_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_item_type ( filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 06:14:46 -07:00
|
|
|
return finished_goods.type ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, finished_goods.type_size(), &mPile->settings.finished_goods.type );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
|
|
|
// materials
|
2014-11-19 09:46:52 -07:00
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::finished_goods_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_material ( mat_filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return finished_goods.mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, finished_goods.mats_size(), &mPile->settings.finished_goods.mats );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsFinishedGoods, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return finished_goods.other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, finished_goods.other_mats_size(), &mPile->settings.finished_goods.other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
|
|
|
// core quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return finished_goods.quality_core ( idx );
|
2014-11-21 09:43:21 -07:00
|
|
|
}, finished_goods.quality_core_size(), mPile->settings.finished_goods.quality_core );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
|
|
|
// total quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return finished_goods.quality_total ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, finished_goods.quality_total_size(), mPile->settings.finished_goods.quality_total );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
quality_clear ( mPile->settings.finished_goods.quality_core );
|
|
|
|
quality_clear ( mPile->settings.finished_goods.quality_total );
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_leather()
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
StockpileSettings::LeatherSet *leather = mBuffer.mutable_leather();
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
FuncWriteExport setter = [=] ( const std::string &id )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
leather->add_mats ( id );
|
2014-11-19 09:46:52 -07:00
|
|
|
};
|
2014-11-21 06:37:37 -07:00
|
|
|
serialize_list_organic_mat ( setter, &mPile->settings.leather.mats, organic_mat_category::Leather );
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_leather()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_leather() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.leather = 1;
|
2014-11-19 09:46:52 -07:00
|
|
|
const StockpileSettings::LeatherSet leather = mBuffer.leather();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "leather: " <<endl;
|
2014-11-21 06:37:37 -07:00
|
|
|
|
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return leather.mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, leather.mats_size(), &mPile->settings.leather.mats, organic_mat_category::Leather );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.leather = 0;
|
|
|
|
mPile->settings.leather.mats.clear();
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_cloth()
|
|
|
|
{
|
2014-11-19 10:38:03 -07:00
|
|
|
StockpileSettings::ClothSet * cloth = mBuffer.mutable_cloth();
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_thread_silk ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.thread_silk, organic_mat_category::Silk );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_thread_plant ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.thread_plant, organic_mat_category::PlantFiber );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_thread_yarn ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.thread_yarn, organic_mat_category::Yarn );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_thread_metal ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.thread_metal, organic_mat_category::MetalThread );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_cloth_silk ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.cloth_silk, organic_mat_category::Silk );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_cloth_plant ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.cloth_plant, organic_mat_category::PlantFiber );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_cloth_yarn ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.cloth_yarn, organic_mat_category::Yarn );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_organic_mat ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
cloth->add_cloth_metal ( token );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, &mPile->settings.cloth.cloth_metal, organic_mat_category::MetalThread );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_cloth()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_cloth() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.cloth = 1;
|
2014-11-19 10:38:03 -07:00
|
|
|
const StockpileSettings::ClothSet cloth = mBuffer.cloth();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "cloth: " <<endl;
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.thread_silk ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.thread_silk_size(), &mPile->settings.cloth.thread_silk, organic_mat_category::Silk );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.thread_plant ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.thread_plant_size(), &mPile->settings.cloth.thread_plant, organic_mat_category::PlantFiber );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.thread_yarn ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.thread_yarn_size(), &mPile->settings.cloth.thread_yarn, organic_mat_category::Yarn );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.thread_metal ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.thread_metal_size(), &mPile->settings.cloth.thread_metal, organic_mat_category::MetalThread );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.cloth_silk ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.cloth_silk_size(), &mPile->settings.cloth.cloth_silk, organic_mat_category::Silk );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.cloth_plant ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.cloth_plant_size(), &mPile->settings.cloth.cloth_plant, organic_mat_category::PlantFiber );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.cloth_yarn ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.cloth_yarn_size(), &mPile->settings.cloth.cloth_yarn, organic_mat_category::Yarn );
|
2014-11-19 10:38:03 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_organic_mat ( [=] ( size_t idx ) -> std::string
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return cloth.cloth_metal ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, cloth.cloth_metal_size(), &mPile->settings.cloth.cloth_metal, organic_mat_category::MetalThread );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
2014-11-19 10:38:03 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool wood_mat_is_allowed ( const df::plant_raw * plant )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return plant && plant->flags.is_set ( plant_raw_flags::TREE );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_wood()
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
StockpileSettings::WoodSet * wood = mBuffer.mutable_wood();
|
2014-11-20 03:18:01 -07:00
|
|
|
for ( size_t i = 0; i < mPile->settings.wood.mats.size(); ++i )
|
|
|
|
{
|
|
|
|
if ( mPile->settings.wood.mats.at ( i ) )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
const df::plant_raw * plant = find_plant ( i );
|
|
|
|
if ( !wood_mat_is_allowed ( plant ) ) continue;
|
|
|
|
wood->add_mats ( plant->id );
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << " plant " << i << " is " << plant->id << endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_wood()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_wood() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.wood = 1;
|
2014-11-19 11:53:53 -07:00
|
|
|
const StockpileSettings::WoodSet wood = mBuffer.wood();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "wood: " <<endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
|
2014-11-21 06:37:37 -07:00
|
|
|
if ( wood.mats_size() > 0 )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-21 06:37:37 -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() )
|
|
|
|
{
|
|
|
|
debug() << "WARNING wood mat index invalid " << token << ", idx=" << idx << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
debug() << " plant " << idx << " is " << token << endl;
|
|
|
|
mPile->settings.wood.mats.at ( idx ) = 1;
|
|
|
|
}
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
2014-11-21 06:37:37 -07:00
|
|
|
else
|
|
|
|
mPile->settings.wood.mats.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPile->settings.flags.bits.wood = 0;
|
|
|
|
mPile->settings.wood.mats.clear();
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
bool weapons_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return mi.isValid() && mi.material && (
|
|
|
|
mi.material->flags.is_set ( material_flags::IS_METAL ) ||
|
|
|
|
mi.material->flags.is_set ( material_flags::IS_STONE ) );
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_weapons()
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
StockpileSettings::WeaponsSet * weapons = mBuffer.mutable_weapons();
|
|
|
|
|
|
|
|
weapons->set_unusable ( mPile->settings.weapons.unusable );
|
|
|
|
weapons->set_usable ( mPile->settings.weapons.usable );
|
|
|
|
|
|
|
|
// weapon type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// trapcomp type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// materials
|
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::weapons_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_material ( mat_filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
weapons->add_mats ( token );
|
|
|
|
}, mPile->settings.weapons.mats );
|
|
|
|
|
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsWeaponsArmor, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
weapons->add_other_mats ( token );
|
|
|
|
}, mPile->settings.weapons.other_mats );
|
|
|
|
|
|
|
|
// quality core
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
weapons->add_quality_core ( token );
|
|
|
|
}, mPile->settings.weapons.quality_core );
|
|
|
|
|
|
|
|
// quality total
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
weapons->add_quality_total ( token );
|
|
|
|
}, mPile->settings.weapons.quality_total );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_weapons()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_weapons() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.weapons = 1;
|
2014-11-19 09:46:52 -07:00
|
|
|
const StockpileSettings::WeaponsSet weapons = mBuffer.weapons();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "weapons: " <<endl;
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 11:53:53 -07:00
|
|
|
bool unusable = weapons.unusable();
|
|
|
|
bool usable = weapons.usable();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "unusable " << unusable << endl;
|
|
|
|
debug() << "usable " << usable << endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
|
|
|
|
// weapon type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return weapons.weapon_type ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.weapon_type_size(), &mPile->settings.weapons.weapon_type, item_type::WEAPON );
|
2014-11-19 11:53:53 -07:00
|
|
|
|
|
|
|
// trapcomp type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return weapons.trapcomp_type ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.trapcomp_type_size(), &mPile->settings.weapons.trapcomp_type, item_type::TRAPCOMP );
|
2014-11-19 11:53:53 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// materials
|
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::weapons_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_material ( mat_filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return weapons.mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.mats_size(), &mPile->settings.weapons.mats );
|
2014-11-19 11:53:53 -07:00
|
|
|
|
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsWeaponsArmor, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return weapons.other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.other_mats_size(), &mPile->settings.weapons.other_mats );
|
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
|
|
|
|
// core quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return weapons.quality_core ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.quality_core_size(), mPile->settings.weapons.quality_core );
|
2014-11-19 09:46:52 -07:00
|
|
|
// total quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return weapons.quality_total ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, weapons.quality_total_size(), mPile->settings.weapons.quality_total );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
quality_clear ( mPile->settings.weapons.quality_core );
|
|
|
|
quality_clear ( mPile->settings.weapons.quality_total );
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
2014-11-19 06:14:46 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void weapons_armor_setup_other_mats()
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
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-11-20 03:18:01 -07:00
|
|
|
bool armor_mat_is_allowed ( const MaterialInfo &mi )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return mi.isValid() && mi.material && mi.material->flags.is_set ( material_flags::IS_METAL );
|
2014-11-19 11:53:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void write_armor()
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
StockpileSettings::ArmorSet * armor = mBuffer.mutable_armor();
|
|
|
|
|
|
|
|
armor->set_unusable ( mPile->settings.armor.unusable );
|
|
|
|
armor->set_usable ( mPile->settings.armor.usable );
|
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
// armor type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// helm type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// shoes type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// gloves type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// pant type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// shield type
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_itemdef ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
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-11-19 11:53:53 -07:00
|
|
|
// materials
|
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::armor_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_material ( mat_filter, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
armor->add_mats ( token );
|
|
|
|
}, mPile->settings.armor.mats );
|
|
|
|
|
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_other_mats ( mOtherMatsWeaponsArmor, [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
armor->add_other_mats ( token );
|
|
|
|
}, mPile->settings.armor.other_mats );
|
|
|
|
|
|
|
|
// quality core
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
armor->add_quality_core ( token );
|
|
|
|
}, mPile->settings.armor.quality_core );
|
|
|
|
|
|
|
|
// quality total
|
2014-11-20 03:18:01 -07:00
|
|
|
serialize_list_quality ( [=] ( const std::string &token )
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
armor->add_quality_total ( token );
|
|
|
|
}, mPile->settings.armor.quality_total );
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
void read_armor()
|
|
|
|
{
|
|
|
|
if ( mBuffer.has_armor() )
|
|
|
|
{
|
2014-11-21 06:37:37 -07:00
|
|
|
mPile->settings.flags.bits.armor = 1;
|
2014-11-19 09:46:52 -07:00
|
|
|
const StockpileSettings::ArmorSet armor = mBuffer.armor();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "armor: " <<endl;
|
2014-11-19 09:46:52 -07:00
|
|
|
|
2014-11-19 11:53:53 -07:00
|
|
|
bool unusable = armor.unusable();
|
|
|
|
bool usable = armor.usable();
|
2014-11-20 03:53:33 -07:00
|
|
|
debug() << "unusable " << unusable << endl;
|
|
|
|
debug() << "usable " << usable << endl;
|
2014-11-19 11:53:53 -07:00
|
|
|
|
2014-11-20 02:33:09 -07:00
|
|
|
// body type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.body ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.body_size(), &mPile->settings.armor.body, item_type::ARMOR );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// head type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.head ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.head_size(), &mPile->settings.armor.head, item_type::HELM );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// feet type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.feet ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.feet_size(), &mPile->settings.armor.feet, item_type::SHOES );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// hands type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.hands ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.hands_size(), &mPile->settings.armor.hands, item_type::GLOVES );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// legs type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.legs ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.legs_size(), &mPile->settings.armor.legs, item_type::PANTS );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
|
|
|
// shield type
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_itemdef ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return armor.shield ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.shield_size(), &mPile->settings.armor.shield, item_type::SHIELD );
|
2014-11-20 02:33:09 -07:00
|
|
|
|
2014-11-19 09:46:52 -07:00
|
|
|
// materials
|
|
|
|
FuncMaterialAllowed mat_filter = std::bind ( &StockpileSerializer::armor_mat_is_allowed, this, _1 );
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_material ( mat_filter, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return armor.mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.mats_size(), &mPile->settings.armor.mats );
|
2014-11-19 11:53:53 -07:00
|
|
|
|
|
|
|
// other mats
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_other_mats ( mOtherMatsWeaponsArmor, [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 11:53:53 -07:00
|
|
|
return armor.other_mats ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.other_mats_size(), &mPile->settings.armor.other_mats );
|
2014-11-19 09:46:52 -07:00
|
|
|
|
|
|
|
// core quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return armor.quality_core ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.quality_core_size(), mPile->settings.armor.quality_core );
|
2014-11-19 09:46:52 -07:00
|
|
|
// total quality
|
2014-11-20 03:18:01 -07:00
|
|
|
unserialize_list_quality ( [=] ( const size_t & idx ) -> const std::string&
|
|
|
|
{
|
2014-11-19 09:46:52 -07:00
|
|
|
return armor.quality_total ( idx );
|
2014-11-21 06:37:37 -07:00
|
|
|
}, armor.quality_total_size(), mPile->settings.armor.quality_total );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
quality_clear ( mPile->settings.armor.quality_core );
|
|
|
|
quality_clear ( mPile->settings.armor.quality_total );
|
2014-11-19 09:46:52 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
};
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
static bool file_exists ( const std::string& filename )
|
2014-11-20 02:33:09 -07:00
|
|
|
{
|
|
|
|
struct stat buf;
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( stat ( filename.c_str(), &buf ) != -1 )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:18:01 -07:00
|
|
|
static bool is_dfstockfile ( const std::string& filename )
|
|
|
|
{
|
|
|
|
return filename.rfind ( ".dfstock" ) != std::string::npos;
|
2014-11-20 02:33:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// exporting
|
2014-11-19 01:09:44 -07:00
|
|
|
static command_result savestock ( color_ostream &out, vector <string> & parameters )
|
|
|
|
{
|
|
|
|
building_stockpilest *sp = virtual_cast<building_stockpilest> ( world->selected_building );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( !sp )
|
|
|
|
{
|
2014-11-19 01:09:44 -07:00
|
|
|
out.printerr ( "Selected building isn't a stockpile.\n" );
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
if ( parameters.size() > 2 )
|
|
|
|
{
|
|
|
|
out.printerr ( "Invalid parameters\n" );
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool debug = false;
|
|
|
|
std::string file;
|
|
|
|
for ( std::string o : parameters )
|
|
|
|
{
|
|
|
|
if ( o == "--debug" || o == "-d" )
|
|
|
|
debug = true;
|
|
|
|
else if ( !o.empty() && o[0] != '-' )
|
|
|
|
{
|
|
|
|
file = o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StockpileSerializer cereal ( sp );
|
|
|
|
if ( debug )
|
|
|
|
cereal.enable_debug ( out );
|
|
|
|
if ( file.empty() )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
std::string data = cereal.serialize_to_string();
|
|
|
|
out << data << endl;
|
2014-11-20 03:18:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
if ( !is_dfstockfile ( file ) ) file += ".dfstock";
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( !cereal.serialize_to_file ( file ) )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
out << "serialize failed" << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// importing
|
|
|
|
static command_result loadstock ( color_ostream &out, vector <string> & parameters )
|
|
|
|
{
|
|
|
|
building_stockpilest *sp = virtual_cast<building_stockpilest> ( world->selected_building );
|
2014-11-20 03:18:01 -07:00
|
|
|
if ( !sp )
|
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
out.printerr ( "Selected building isn't a stockpile.\n" );
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
if ( parameters.size() < 1 || parameters.size() > 2 )
|
|
|
|
{
|
|
|
|
out.printerr ( "Invalid parameters\n" );
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool debug = false;
|
|
|
|
std::string file;
|
|
|
|
for ( std::string o : parameters )
|
|
|
|
{
|
|
|
|
if ( o == "--debug" || o == "-d" )
|
|
|
|
debug = true;
|
|
|
|
else if ( !o.empty() && o[0] != '-' )
|
|
|
|
{
|
|
|
|
file = o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 08:51:45 -07:00
|
|
|
if ( !is_dfstockfile ( file ) ) file += ".dfstock";
|
|
|
|
if ( file.empty() || !file_exists ( file ) )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-20 03:53:33 -07:00
|
|
|
out.printerr ( "loadstock: a .dfstock file is required to import\n" );
|
2014-11-20 02:33:09 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:53:33 -07:00
|
|
|
StockpileSerializer cereal ( sp );
|
|
|
|
if ( debug )
|
|
|
|
cereal.enable_debug ( out );
|
2014-11-20 05:37:14 -07:00
|
|
|
if ( !cereal.unserialize_from_file ( file ) )
|
2014-11-20 03:18:01 -07:00
|
|
|
{
|
2014-11-20 02:33:09 -07:00
|
|
|
out << "unserialize failed" << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2014-11-19 01:09:44 -07:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-21 08:07:08 -07:00
|
|
|
|