2014-12-23 14:56:15 -07:00
|
|
|
#pragma once
|
|
|
|
|
2013-02-15 16:10:47 -07:00
|
|
|
#include <algorithm>
|
2014-05-03 03:19:46 -06:00
|
|
|
#include <cctype>
|
2015-02-14 20:53:06 -07:00
|
|
|
#include <functional>
|
2014-05-03 03:19:46 -06:00
|
|
|
#include <locale>
|
2013-02-15 16:10:47 -07:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include "Core.h"
|
2013-03-01 01:29:16 -07:00
|
|
|
#include "MiscUtils.h"
|
2013-02-15 16:10:47 -07:00
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <VTableInterpose.h>
|
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
#include "modules/Items.h"
|
2013-02-15 16:10:47 -07:00
|
|
|
#include "modules/Screen.h"
|
2014-05-03 03:19:46 -06:00
|
|
|
#include "modules/World.h"
|
2013-02-15 16:10:47 -07:00
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
#include "df/building_stockpilest.h"
|
|
|
|
#include "df/caravan_state.h"
|
|
|
|
#include "df/dfhack_material_category.h"
|
2013-02-15 16:10:47 -07:00
|
|
|
#include "df/enabler.h"
|
2014-05-03 03:19:46 -06:00
|
|
|
#include "df/item_quality.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/world.h"
|
2013-02-15 16:10:47 -07:00
|
|
|
|
2013-10-08 07:41:49 -06:00
|
|
|
using namespace std;
|
2013-02-15 16:10:47 -07:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using std::map;
|
|
|
|
using std::ostringstream;
|
|
|
|
using std::set;
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
#define COLOR_TITLE COLOR_BROWN
|
2013-02-15 16:10:47 -07:00
|
|
|
#define COLOR_UNSELECTED COLOR_GREY
|
|
|
|
#define COLOR_SELECTED COLOR_WHITE
|
|
|
|
#define COLOR_HIGHLIGHTED COLOR_GREEN
|
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
struct coord32_t
|
|
|
|
{
|
|
|
|
int32_t x, y, z;
|
|
|
|
|
|
|
|
coord32_t()
|
|
|
|
{
|
|
|
|
x = -30000;
|
|
|
|
y = -30000;
|
|
|
|
z = -30000;
|
|
|
|
}
|
|
|
|
|
|
|
|
coord32_t(df::coord& other)
|
|
|
|
{
|
|
|
|
x = other.x;
|
|
|
|
y = other.y;
|
|
|
|
z = other.z;
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
df::coord get_coord16() const
|
|
|
|
{
|
|
|
|
return df::coord(x, y, z);
|
|
|
|
}
|
|
|
|
};
|
2013-02-15 16:10:47 -07:00
|
|
|
|
|
|
|
template <class T, typename Fn>
|
|
|
|
static void for_each_(vector<T> &v, Fn func)
|
|
|
|
{
|
|
|
|
for_each(v.begin(), v.end(), func);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class V, typename Fn>
|
|
|
|
static void for_each_(map<T, V> &v, Fn func)
|
|
|
|
{
|
|
|
|
for_each(v.begin(), v.end(), func);
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:53:06 -07:00
|
|
|
template <class T, class V, typename Fn>
|
2013-02-15 16:10:47 -07:00
|
|
|
static void transform_(vector<T> &src, vector<V> &dst, Fn func)
|
|
|
|
{
|
|
|
|
transform(src.begin(), src.end(), back_inserter(dst), func);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int8_t UIColor;
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputString(UIColor color, int &x, int &y, const std::string &text,
|
2015-12-22 09:42:51 -07:00
|
|
|
bool newline = false, int left_margin = 0, const UIColor bg_color = 0, bool map = false)
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
Screen::paintString(Screen::Pen(' ', color, bg_color), x, y, text, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
if (newline)
|
|
|
|
{
|
|
|
|
++y;
|
|
|
|
x = left_margin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
x += text.length();
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputHotkeyString(int &x, int &y, const char *text, const char *hotkey, bool newline = false,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
string display(": ");
|
|
|
|
display.append(text);
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(text_color, x, y, display, newline, left_margin, 0, map);
|
2013-04-12 19:26:39 -06:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputHotkeyString(int &x, int &y, const char *text, df::interface_key hotkey,
|
2015-12-22 09:42:51 -07:00
|
|
|
bool newline = false, int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN,
|
|
|
|
bool map = false)
|
2015-07-29 11:44:32 -06:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputHotkeyString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), newline, left_margin, text_color, hotkey_color, map);
|
2015-07-29 11:44:32 -06:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputLabelString(int &x, int &y, const char *text, const char *hotkey, const string &label, bool newline = false,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map);
|
2014-05-03 03:19:46 -06:00
|
|
|
string display(": ");
|
|
|
|
display.append(text);
|
|
|
|
display.append(": ");
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(text_color, x, y, display, false, 0, 0, map);
|
|
|
|
OutputString(hotkey_color, x, y, label, newline, left_margin, 0, map);
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputLabelString(int &x, int &y, const char *text, df::interface_key hotkey, const string &label, bool newline = false,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
|
|
|
{
|
|
|
|
OutputLabelString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), label, newline,
|
|
|
|
left_margin, text_color, hotkey_color, map);
|
2014-05-03 03:19:46 -06:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputFilterString(int &x, int &y, const char *text, const char *hotkey, bool state, bool newline = false,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
2013-04-12 19:26:39 -06:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map);
|
|
|
|
OutputString(COLOR_WHITE, x, y, ": ", false, 0, 0, map);
|
|
|
|
OutputString((state) ? COLOR_WHITE : COLOR_GREY, x, y, text, newline, left_margin, 0, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputToggleString(int &x, int &y, const char *text, const char *hotkey, bool state, bool newline = true,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputHotkeyString(x, y, text, hotkey, false, 0, color, hotkey_color, map);
|
|
|
|
OutputString(color, x, y, ": ", false, 0, 0, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
if (state)
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(COLOR_GREEN, x, y, "On", newline, left_margin, 0, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
else
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputString(COLOR_GREY, x, y, "Off", newline, left_margin, 0, map);
|
2013-02-15 16:10:47 -07:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void OutputToggleString(int &x, int &y, const char *text, df::interface_key hotkey, bool state, bool newline = true,
|
2015-12-22 09:42:51 -07:00
|
|
|
int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false)
|
2015-07-29 11:44:32 -06:00
|
|
|
{
|
2015-12-22 09:42:51 -07:00
|
|
|
OutputToggleString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), state, newline, left_margin, color, hotkey_color, map);
|
2015-07-29 11:44:32 -06:00
|
|
|
}
|
|
|
|
|
2013-02-15 16:10:47 -07:00
|
|
|
inline string int_to_string(const int n)
|
|
|
|
{
|
|
|
|
return static_cast<ostringstream*>( &(ostringstream() << n) )->str();
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline void set_to_limit(int &value, const int maximum, const int min = 0)
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
|
|
|
if (value < min)
|
|
|
|
value = min;
|
|
|
|
else if (value > maximum)
|
|
|
|
value = maximum;
|
|
|
|
}
|
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
// trim from start
|
|
|
|
static inline std::string <rim(std::string &s) {
|
|
|
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim from end
|
|
|
|
static inline std::string &rtrim(std::string &s) {
|
|
|
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim from both ends
|
|
|
|
static inline std::string &trim(std::string &s) {
|
|
|
|
return ltrim(rtrim(s));
|
|
|
|
}
|
2013-02-15 16:10:47 -07:00
|
|
|
|
|
|
|
inline void paint_text(const UIColor color, const int &x, const int &y, const std::string &text, const UIColor background = 0)
|
|
|
|
{
|
|
|
|
Screen::paintString(Screen::Pen(' ', color, background), x, y, text);
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline string pad_string(string text, const int size, const bool front = true, const bool trim = false)
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
if (text.length() > size_t(size))
|
2013-02-15 16:10:47 -07:00
|
|
|
{
|
|
|
|
if (trim && size > 10)
|
|
|
|
{
|
|
|
|
text = text.substr(0, size-3);
|
|
|
|
text.append("...");
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
string aligned(size - text.length(), ' ');
|
|
|
|
if (front)
|
|
|
|
{
|
|
|
|
aligned.append(text);
|
|
|
|
return aligned;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text.append(aligned);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline df::interface_key get_string_key(const std::set<df::interface_key> *input)
|
2015-07-28 16:34:29 -06:00
|
|
|
{
|
|
|
|
for (auto it = input->begin(); it != input->end(); ++it)
|
|
|
|
{
|
|
|
|
if (DFHack::Screen::keyToChar(*it) >= 0)
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return df::interface_key::NONE;
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline char get_string_input(const std::set<df::interface_key> *input)
|
2015-07-28 16:34:29 -06:00
|
|
|
{
|
|
|
|
return DFHack::Screen::keyToChar(get_string_key(input));
|
|
|
|
}
|
2013-02-15 16:10:47 -07:00
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
/*
|
|
|
|
* Utility Functions
|
|
|
|
*/
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline df::building_stockpilest *get_selected_stockpile()
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
if (!Gui::dwarfmode_hotkey(Core::getTopViewscreen()) ||
|
|
|
|
df::global::ui->main.mode != ui_sidebar_mode::QueryBuilding)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return virtual_cast<df::building_stockpilest>(df::global::world->selected_building);
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline bool can_trade()
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
if (df::global::ui->caravans.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (auto it = df::global::ui->caravans.begin(); it != df::global::ui->caravans.end(); it++)
|
|
|
|
{
|
2016-04-13 07:44:57 -06:00
|
|
|
typedef df::caravan_state::T_trade_state state;
|
2014-05-03 03:19:46 -06:00
|
|
|
auto caravan = *it;
|
|
|
|
auto trade_state = caravan->trade_state;
|
|
|
|
auto time_remaining = caravan->time_remaining;
|
2016-04-16 15:13:00 -06:00
|
|
|
if ((trade_state == state::Approaching || trade_state == state::AtDepot) && time_remaining != 0)
|
|
|
|
return true;
|
2014-05-03 03:19:46 -06:00
|
|
|
}
|
|
|
|
|
2016-04-16 15:13:00 -06:00
|
|
|
return false;
|
2014-05-03 03:19:46 -06:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline bool is_metal_item(df::item *item)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
MaterialInfo mat(item);
|
|
|
|
return (mat.getCraftClass() == craft_material_class::Metal);
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline bool is_set_to_melt(df::item* item)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
return item->flags.bits.melt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copied from Kelly Martin's code
|
2018-04-05 15:51:10 -06:00
|
|
|
static inline bool can_melt(df::item* item)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
df::item_flags bad_flags;
|
|
|
|
bad_flags.whole = 0;
|
|
|
|
|
|
|
|
#define F(x) bad_flags.bits.x = true;
|
|
|
|
F(dump); F(forbid); F(garbage_collect); F(in_job);
|
|
|
|
F(hostile); F(on_fire); F(rotten); F(trader);
|
|
|
|
F(in_building); F(construction); F(artifact); F(melt);
|
|
|
|
#undef F
|
|
|
|
|
|
|
|
if (item->flags.whole & bad_flags.whole)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::item_type t = item->getType();
|
|
|
|
|
|
|
|
if (t == df::enums::item_type::BOX || t == df::enums::item_type::BAR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!is_metal_item(item)) return false;
|
|
|
|
|
2015-02-14 20:53:06 -07:00
|
|
|
for (auto g = item->general_refs.begin(); g != item->general_refs.end(); g++)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
2015-02-14 20:53:06 -07:00
|
|
|
switch ((*g)->getType())
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
case general_ref_type::CONTAINS_ITEM:
|
|
|
|
case general_ref_type::UNIT_HOLDER:
|
|
|
|
case general_ref_type::CONTAINS_UNIT:
|
|
|
|
return false;
|
|
|
|
case general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
{
|
|
|
|
df::item* c = (*g)->getItem();
|
|
|
|
for (auto gg = c->general_refs.begin(); gg != c->general_refs.end(); gg++)
|
|
|
|
{
|
|
|
|
if ((*gg)->getType() == general_ref_type::UNIT_HOLDER)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-04-06 00:18:15 -06:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-03 03:19:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->getQuality() >= item_quality::Masterful)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stockpile Access
|
|
|
|
*/
|
|
|
|
|
|
|
|
class StockpileInfo {
|
|
|
|
public:
|
2018-04-06 00:18:15 -06:00
|
|
|
StockpileInfo() : id(0), sp(nullptr), x1(-30000), x2(-30000), y1(-30000), y2(-30000), z(-30000)
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
StockpileInfo(df::building_stockpilest *sp_) : StockpileInfo()
|
2014-05-03 03:19:46 -06:00
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
sp = sp_;
|
2014-05-03 03:19:46 -06:00
|
|
|
readBuilding();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inStockpile(df::item *i)
|
|
|
|
{
|
|
|
|
df::item *container = Items::getContainer(i);
|
|
|
|
if (container)
|
|
|
|
return inStockpile(container);
|
|
|
|
|
|
|
|
if (i->pos.z != z) return false;
|
|
|
|
if (i->pos.x < x1 || i->pos.x >= x2 ||
|
|
|
|
i->pos.y < y1 || i->pos.y >= y2) return false;
|
|
|
|
int e = (i->pos.x - x1) + (i->pos.y - y1) * sp->room.width;
|
|
|
|
return sp->room.extents[e] == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid()
|
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto found = df::building::find(id);
|
|
|
|
return found && found == sp && found->getType() == building_type::Stockpile;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t getId()
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool matches(df::building_stockpilest* sp)
|
|
|
|
{
|
|
|
|
return this->sp == sp;
|
|
|
|
}
|
|
|
|
|
2014-09-07 14:03:51 -06:00
|
|
|
df::building_stockpilest* getStockpile()
|
|
|
|
{
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
2014-05-03 03:19:46 -06:00
|
|
|
protected:
|
|
|
|
int32_t id;
|
|
|
|
df::building_stockpilest* sp;
|
|
|
|
|
|
|
|
void readBuilding()
|
|
|
|
{
|
|
|
|
if (!sp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
id = sp->id;
|
|
|
|
z = sp->z;
|
|
|
|
x1 = sp->room.x;
|
|
|
|
x2 = sp->room.x + sp->room.width;
|
|
|
|
y1 = sp->room.y;
|
|
|
|
y2 = sp->room.y + sp->room.height;
|
|
|
|
}
|
|
|
|
|
2015-07-28 16:34:29 -06:00
|
|
|
protected:
|
2014-05-03 03:19:46 -06:00
|
|
|
int x1, x2, y1, y2, z;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PersistentStockpileInfo : public StockpileInfo {
|
|
|
|
public:
|
2015-02-14 20:53:06 -07:00
|
|
|
PersistentStockpileInfo(df::building_stockpilest *sp, string persistence_key) :
|
2014-05-03 03:19:46 -06:00
|
|
|
StockpileInfo(sp), persistence_key(persistence_key)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:53:06 -07:00
|
|
|
PersistentStockpileInfo(PersistentDataItem &config, string persistence_key) :
|
2014-05-03 03:19:46 -06:00
|
|
|
config(config), persistence_key(persistence_key)
|
|
|
|
{
|
|
|
|
id = config.ival(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool load()
|
|
|
|
{
|
|
|
|
auto found = df::building::find(id);
|
|
|
|
if (!found || found->getType() != building_type::Stockpile)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sp = virtual_cast<df::building_stockpilest>(found);
|
|
|
|
if (!sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
readBuilding();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void save()
|
|
|
|
{
|
|
|
|
config = DFHack::World::AddPersistentData(persistence_key);
|
|
|
|
config.ival(1) = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove()
|
|
|
|
{
|
|
|
|
DFHack::World::DeletePersistentData(config);
|
|
|
|
}
|
|
|
|
|
2015-07-28 16:34:29 -06:00
|
|
|
protected:
|
2014-05-03 03:19:46 -06:00
|
|
|
PersistentDataItem config;
|
|
|
|
string persistence_key;
|
|
|
|
};
|