2013-02-15 16:10:47 -07:00
|
|
|
#include "uicommon.h"
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-02-15 16:10:47 -07:00
|
|
|
#include <functional>
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
// DF data structure definition headers
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "df/build_req_choice_genst.h"
|
|
|
|
#include "df/build_req_choice_specst.h"
|
|
|
|
#include "df/item.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/ui_build_selector.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/items_other_id.h"
|
|
|
|
#include "df/job.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/building_constructionst.h"
|
|
|
|
#include "df/building_design.h"
|
|
|
|
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "modules/Buildings.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
|
|
|
|
#include "TileTypes.h"
|
|
|
|
#include "df/job_item.h"
|
|
|
|
#include "df/dfhack_material_category.h"
|
|
|
|
#include "df/general_ref_building_holderst.h"
|
|
|
|
#include "modules/Job.h"
|
|
|
|
#include "df/building_design.h"
|
|
|
|
#include "df/buildings_other_id.h"
|
|
|
|
#include "modules/World.h"
|
2013-01-18 23:20:37 -07:00
|
|
|
#include "df/building.h"
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::ui_build_selector;
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("buildingplan");
|
2013-02-07 02:57:07 -07:00
|
|
|
#define PLUGIN_VERSION 0.5
|
2013-02-01 06:22:06 -07:00
|
|
|
|
|
|
|
#ifndef HAVE_NULLPTR
|
|
|
|
#define nullptr 0L
|
|
|
|
#endif
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
struct MaterialDescriptor
|
|
|
|
{
|
|
|
|
df::item_type item_type;
|
|
|
|
int16_t item_subtype;
|
|
|
|
int16_t type;
|
|
|
|
int32_t index;
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
bool matches(const MaterialDescriptor &a) const
|
|
|
|
{
|
|
|
|
return a.valid && valid &&
|
|
|
|
a.type == type &&
|
|
|
|
a.index == index &&
|
|
|
|
a.item_type == item_type &&
|
|
|
|
a.item_subtype == item_subtype;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct coord32_t
|
|
|
|
{
|
|
|
|
int32_t x, y, z;
|
|
|
|
|
|
|
|
df::coord get_coord16() const
|
|
|
|
{
|
|
|
|
return df::coord(x, y, z);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-15 16:10:47 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2013-01-18 23:20:37 -07:00
|
|
|
{
|
2013-02-15 16:10:47 -07:00
|
|
|
return CR_OK;
|
2013-01-18 23:20:37 -07:00
|
|
|
}
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
#define MAX_MASK 10
|
|
|
|
#define MAX_MATERIAL 21
|
|
|
|
#define SIDEBAR_WIDTH 30
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Material Choice Screen
|
|
|
|
*/
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
struct ItemFilter
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
df::dfhack_material_category mat_mask;
|
|
|
|
vector<MaterialInfo> materials;
|
|
|
|
df::item_quality min_quality;
|
|
|
|
bool decorated_only;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
ItemFilter() : min_quality(item_quality::Ordinary), decorated_only(false), valid(true)
|
|
|
|
{ }
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
bool matchesMask(MaterialInfo &mat)
|
|
|
|
{
|
|
|
|
return (mat_mask.whole) ? mat.matches(mat_mask) : true;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
bool matches(const df::dfhack_material_category mask) const
|
|
|
|
{
|
|
|
|
return mask.whole & mat_mask.whole;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
bool matches(MaterialInfo &material) const
|
|
|
|
{
|
|
|
|
return any_of(materials.begin(), materials.end(),
|
|
|
|
[&] (const MaterialInfo &m) { return material.matches(m); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool matches(df::item *item)
|
|
|
|
{
|
|
|
|
if (item->getQuality() < min_quality)
|
|
|
|
return false;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
if (decorated_only && !item->hasImprovements())
|
|
|
|
return false;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
auto imattype = item->getActualMaterial();
|
|
|
|
auto imatindex = item->getActualMaterialIndex();
|
|
|
|
auto item_mat = MaterialInfo(imattype, imatindex);
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
return (materials.size() == 0) ? matchesMask(item_mat) : matches(item_mat);
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
vector<string> getMaterialFilterAsVector()
|
|
|
|
{
|
|
|
|
vector<string> descriptions;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
transform_(materials, descriptions,
|
|
|
|
[] (MaterialInfo m) { return m.toString(); });
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
if (descriptions.size() == 0)
|
|
|
|
bitfield_to_string(&descriptions, mat_mask);
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
if (descriptions.size() == 0)
|
|
|
|
descriptions.push_back("any");
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
return descriptions;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
string getMaterialFilterAsSerial()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
string str;
|
|
|
|
|
|
|
|
str.append(bitfield_to_string(mat_mask, ","));
|
|
|
|
str.append("/");
|
|
|
|
if (materials.size() > 0)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
for_each_(materials,
|
|
|
|
[&] (MaterialInfo &m) { str.append(m.getToken() + ","); });
|
|
|
|
|
|
|
|
if (str[str.size()-1] == ',')
|
|
|
|
str.resize(str.size () - 1);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
return str;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
bool parseSerializedMaterialTokens(string str)
|
|
|
|
{
|
|
|
|
valid = false;
|
|
|
|
vector<string> tokens;
|
|
|
|
split_string(&tokens, str, "/");
|
|
|
|
|
|
|
|
if (tokens.size() > 0 && !tokens[0].empty())
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
if (!parseJobMaterialCategory(&mat_mask, tokens[0]))
|
|
|
|
return false;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
if (tokens.size() > 1 && !tokens[1].empty())
|
|
|
|
{
|
|
|
|
vector<string> mat_names;
|
|
|
|
split_string(&mat_names, tokens[1], ",");
|
|
|
|
for (auto m = mat_names.begin(); m != mat_names.end(); m++)
|
|
|
|
{
|
|
|
|
MaterialInfo material;
|
|
|
|
if (!material.find(*m) || !material.isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
materials.push_back(material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = true;
|
|
|
|
return true;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
string getMinQuality()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
return ENUM_KEY_STR(item_quality, min_quality);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
bool isValid()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
return valid;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-23 23:21:12 -07:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
mat_mask.whole = 0;
|
|
|
|
materials.clear();
|
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
private:
|
|
|
|
bool valid;
|
|
|
|
};
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
class ViewscreenChooseMaterial : public dfhack_viewscreen
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
public:
|
|
|
|
ViewscreenChooseMaterial(ItemFilter *filter)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
selected_column = 0;
|
2013-02-15 16:10:47 -07:00
|
|
|
masks_column.setTitle("Type");
|
2013-01-18 23:20:37 -07:00
|
|
|
masks_column.multiselect = true;
|
|
|
|
masks_column.allow_search = false;
|
|
|
|
masks_column.left_margin = 2;
|
|
|
|
materials_column.left_margin = MAX_MASK + 3;
|
2013-02-15 16:10:47 -07:00
|
|
|
materials_column.setTitle("Material");
|
2013-01-18 23:20:37 -07:00
|
|
|
materials_column.multiselect = true;
|
|
|
|
this->filter = filter;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
masks_column.changeHighlight(0);
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
populateMasks();
|
|
|
|
populateMaterials();
|
|
|
|
|
|
|
|
masks_column.selectDefaultEntry();
|
|
|
|
materials_column.selectDefaultEntry();
|
|
|
|
materials_column.changeHighlight(0);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
void feed(set<df::interface_key> *input)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-02-15 16:10:47 -07:00
|
|
|
bool key_processed = false;
|
2013-01-18 23:20:37 -07:00
|
|
|
switch (selected_column)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
key_processed = masks_column.feed(input);
|
|
|
|
if (input->count(interface_key::SELECT))
|
|
|
|
populateMaterials(); // Redo materials lists based on category selection
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
key_processed = materials_column.feed(input);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_processed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (input->count(interface_key::LEAVESCREEN))
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
input->clear();
|
|
|
|
Screen::dismiss(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (input->count(interface_key::CUSTOM_SHIFT_C))
|
|
|
|
{
|
2013-01-23 23:21:12 -07:00
|
|
|
filter->clear();
|
2013-02-15 16:10:47 -07:00
|
|
|
masks_column.clearSelection();
|
|
|
|
materials_column.clearSelection();
|
2013-01-23 23:21:12 -07:00
|
|
|
populateMaterials();
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
else if (input->count(interface_key::SEC_SELECT))
|
|
|
|
{
|
|
|
|
// Convert list selections to material filters
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
filter->mat_mask.whole = 0;
|
|
|
|
filter->materials.clear();
|
|
|
|
|
|
|
|
// Category masks
|
2013-01-29 00:44:56 -07:00
|
|
|
auto masks = masks_column.getSelectedElems();
|
|
|
|
for_each_(masks,
|
2013-01-18 23:20:37 -07:00
|
|
|
[&] (df::dfhack_material_category *m) { filter->mat_mask.whole |= m->whole; });
|
|
|
|
|
|
|
|
// Specific materials
|
2013-01-29 00:44:56 -07:00
|
|
|
auto materials = materials_column.getSelectedElems();
|
|
|
|
transform_(materials, filter->materials,
|
2013-01-18 23:20:37 -07:00
|
|
|
[] (MaterialInfo *m) { return *m; });
|
|
|
|
|
|
|
|
Screen::dismiss(this);
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::CURSOR_LEFT))
|
|
|
|
{
|
|
|
|
--selected_column;
|
|
|
|
validateColumn();
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::CURSOR_RIGHT))
|
|
|
|
{
|
|
|
|
selected_column++;
|
|
|
|
validateColumn();
|
|
|
|
}
|
|
|
|
else if (enabler->tracking_on && enabler->mouse_lbut)
|
|
|
|
{
|
|
|
|
if (masks_column.setHighlightByMouse())
|
|
|
|
selected_column = 0;
|
|
|
|
else if (materials_column.setHighlightByMouse())
|
|
|
|
selected_column = 1;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
enabler->mouse_lbut = enabler->mouse_rbut = 0;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
void render()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
if (Screen::isDismissed(this))
|
|
|
|
return;
|
|
|
|
|
|
|
|
dfhack_viewscreen::render();
|
|
|
|
|
|
|
|
Screen::clear();
|
|
|
|
Screen::drawBorder(" Building Material ");
|
|
|
|
|
|
|
|
masks_column.display(selected_column == 0);
|
|
|
|
materials_column.display(selected_column == 1);
|
|
|
|
|
|
|
|
int32_t y = gps->dimy - 3;
|
|
|
|
int32_t x = 2;
|
|
|
|
OutputHotkeyString(x, y, "Toggle", "Enter");
|
|
|
|
x += 3;
|
|
|
|
OutputHotkeyString(x, y, "Save", "Shift-Enter");
|
|
|
|
x += 3;
|
|
|
|
OutputHotkeyString(x, y, "Clear", "C");
|
|
|
|
x += 3;
|
|
|
|
OutputHotkeyString(x, y, "Cancel", "Esc");
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
std::string getFocusString() { return "buildingplan_choosemat"; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ListColumn<df::dfhack_material_category> masks_column;
|
|
|
|
ListColumn<MaterialInfo> materials_column;
|
|
|
|
int selected_column;
|
|
|
|
ItemFilter *filter;
|
|
|
|
|
|
|
|
df::building_type btype;
|
|
|
|
|
|
|
|
void addMaskEntry(df::dfhack_material_category &mask, const string &text)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
auto entry = ListEntry<df::dfhack_material_category>(pad_string(text, MAX_MASK, false), mask);
|
|
|
|
if (filter->matches(mask))
|
|
|
|
entry.selected = true;
|
|
|
|
|
|
|
|
masks_column.add(entry);
|
|
|
|
mask.whole = 0;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
void populateMasks()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
masks_column.clear();
|
|
|
|
df::dfhack_material_category mask;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
mask.bits.stone = true;
|
|
|
|
addMaskEntry(mask, "Stone");
|
|
|
|
mask.bits.wood = true;
|
|
|
|
addMaskEntry(mask, "Wood");
|
|
|
|
mask.bits.metal = true;
|
|
|
|
addMaskEntry(mask, "Metal");
|
|
|
|
mask.bits.soap = true;
|
|
|
|
addMaskEntry(mask, "Soap");
|
|
|
|
|
|
|
|
masks_column.filterDisplay();
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
void populateMaterials()
|
|
|
|
{
|
|
|
|
materials_column.clear();
|
|
|
|
df::dfhack_material_category selected_category;
|
|
|
|
vector<df::dfhack_material_category *> selected_masks = masks_column.getSelectedElems();
|
|
|
|
if (selected_masks.size() == 1)
|
|
|
|
selected_category = *selected_masks[0];
|
|
|
|
else if (selected_masks.size() > 1)
|
|
|
|
return;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
df::world_raws &raws = world->raws;
|
|
|
|
for (int i = 1; i < DFHack::MaterialInfo::NUM_BUILTIN; i++)
|
|
|
|
{
|
|
|
|
auto obj = raws.mat_table.builtin[i];
|
|
|
|
if (obj)
|
|
|
|
{
|
|
|
|
MaterialInfo material;
|
|
|
|
material.decode(i, -1);
|
|
|
|
addMaterialEntry(selected_category, material, material.toString());
|
|
|
|
}
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
for (size_t i = 0; i < raws.inorganics.size(); i++)
|
|
|
|
{
|
|
|
|
df::inorganic_raw *p = raws.inorganics[i];
|
|
|
|
MaterialInfo material;
|
|
|
|
material.decode(0, i);
|
|
|
|
addMaterialEntry(selected_category, material, material.toString());
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
decltype(selected_category) wood_flag;
|
|
|
|
wood_flag.bits.wood = true;
|
|
|
|
if (!selected_category.whole || selected_category.bits.wood)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < raws.plants.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::plant_raw *p = raws.plants.all[i];
|
|
|
|
//string basename = p->name;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
/*MaterialInfo material;
|
|
|
|
material.decode(p->material_defs.type_basic_mat, p->material_defs.idx_basic_mat);*/
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
//addMaterialEntry(selected_category, material, material.toString());
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
for (size_t j = 0; p->material.size() > 1 && j < p->material.size(); j++)
|
|
|
|
{
|
|
|
|
auto t = p->material[j];
|
|
|
|
if (p->material[j]->id != "WOOD")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
MaterialInfo material;
|
|
|
|
material.decode(DFHack::MaterialInfo::PLANT_BASE+j, i);
|
|
|
|
//addMaterialEntry(selected_category, material, material.toString());
|
|
|
|
auto name = material.toString();
|
|
|
|
ListEntry<MaterialInfo> entry(pad_string(name, MAX_MATERIAL, false), material);
|
|
|
|
if (filter->matches(material))
|
|
|
|
entry.selected = true;
|
|
|
|
|
|
|
|
materials_column.add(entry);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
materials_column.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void addMaterialEntry(df::dfhack_material_category &selected_category,
|
|
|
|
MaterialInfo &material, string name)
|
|
|
|
{
|
|
|
|
if (!selected_category.whole || material.matches(selected_category))
|
|
|
|
{
|
|
|
|
ListEntry<MaterialInfo> entry(pad_string(name, MAX_MATERIAL, false), material);
|
|
|
|
if (filter->matches(material))
|
|
|
|
entry.selected = true;
|
|
|
|
|
|
|
|
materials_column.add(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void validateColumn()
|
|
|
|
{
|
|
|
|
set_to_limit(selected_column, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void resize(int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
dfhack_viewscreen::resize(x, y);
|
|
|
|
masks_column.resize();
|
|
|
|
materials_column.resize();
|
|
|
|
}
|
|
|
|
};
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
// START Planning
|
|
|
|
class PlannedBuilding
|
|
|
|
{
|
|
|
|
public:
|
2013-01-18 23:20:37 -07:00
|
|
|
PlannedBuilding(df::building *building, ItemFilter *filter)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
|
|
|
this->building = building;
|
2013-01-18 23:20:37 -07:00
|
|
|
this->filter = *filter;
|
2013-01-07 01:17:38 -07:00
|
|
|
pos = df::coord(building->centerx, building->centery, building->z);
|
2013-01-18 23:20:37 -07:00
|
|
|
config = Core::getInstance().getWorld()->AddPersistentData("buildingplan/constraints");
|
|
|
|
config.val() = filter->getMaterialFilterAsSerial();
|
|
|
|
config.ival(1) = building->id;
|
|
|
|
config.ival(2) = filter->min_quality + 1;
|
|
|
|
config.ival(3) = static_cast<int>(filter->decorated_only) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlannedBuilding(PersistentDataItem &config, color_ostream &out)
|
|
|
|
{
|
|
|
|
this->config = config;
|
|
|
|
|
|
|
|
if (!filter.parseSerializedMaterialTokens(config.val()))
|
|
|
|
{
|
|
|
|
out.printerr("Buildingplan: Cannot parse filter: %s\nDiscarding.", config.val().c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
building = df::building::find(config.ival(1));
|
|
|
|
pos = df::coord(building->centerx, building->centery, building->z);
|
|
|
|
filter.min_quality = static_cast<df::item_quality>(config.ival(2) - 1);
|
|
|
|
filter.decorated_only = config.ival(3) - 1;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
df::building_type getType()
|
|
|
|
{
|
|
|
|
return building->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool assignClosestItem(vector<df::item *> *items_vector)
|
|
|
|
{
|
|
|
|
decltype(items_vector->begin()) closest_item;
|
|
|
|
int32_t closest_distance = -1;
|
|
|
|
for (auto item_iter = items_vector->begin(); item_iter != items_vector->end(); item_iter++)
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
auto item = *item_iter;
|
|
|
|
if (!filter.matches(item))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto pos = item->pos;
|
2013-01-07 01:17:38 -07:00
|
|
|
auto distance = abs(pos.x - building->centerx) +
|
|
|
|
abs(pos.y - building->centery) +
|
|
|
|
abs(pos.z - building->z) * 50;
|
|
|
|
|
|
|
|
if (closest_distance > -1 && distance >= closest_distance)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
closest_distance = distance;
|
|
|
|
closest_item = item_iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closest_distance > -1 && assignItem(*closest_item))
|
|
|
|
{
|
|
|
|
items_vector->erase(closest_item);
|
2013-01-23 23:21:12 -07:00
|
|
|
remove();
|
2013-01-07 01:17:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool assignItem(df::item *item)
|
|
|
|
{
|
|
|
|
auto ref = df::allocate<df::general_ref_building_holderst>();
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
Core::printerr("Could not allocate general_ref_building_holderst\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref->building_id = building->id;
|
|
|
|
|
|
|
|
auto job = building->jobs[0];
|
|
|
|
delete job->job_items[0];
|
|
|
|
job->job_items.clear();
|
|
|
|
job->flags.bits.suspend = false;
|
|
|
|
|
|
|
|
bool rough = false;
|
|
|
|
Job::attachJobItem(job, item, df::job_item_ref::Hauled);
|
|
|
|
if (item->getType() == item_type::BOULDER)
|
|
|
|
rough = true;
|
|
|
|
building->mat_type = item->getMaterial();
|
|
|
|
building->mat_index = item->getMaterialIndex();
|
|
|
|
|
|
|
|
job->mat_type = building->mat_type;
|
|
|
|
job->mat_index = building->mat_index;
|
|
|
|
|
|
|
|
if (building->needsDesign())
|
|
|
|
{
|
|
|
|
auto act = (df::building_actual *) building;
|
|
|
|
act->design = new df::building_design();
|
|
|
|
act->design->flags.bits.rough = rough;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid()
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
bool valid = filter.isValid() &&
|
|
|
|
building && Buildings::findAtTile(pos) == building &&
|
|
|
|
building->getBuildStage() == 0;
|
|
|
|
|
|
|
|
if (!valid)
|
|
|
|
remove();
|
|
|
|
|
|
|
|
return valid;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isCurrentlySelectedBuilding()
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
return isValid() && (building == world->selected_building);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemFilter *getFilter()
|
|
|
|
{
|
|
|
|
return &filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove()
|
|
|
|
{
|
|
|
|
Core::getInstance().getWorld()->DeletePersistentData(config);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
df::building *building;
|
|
|
|
PersistentDataItem config;
|
|
|
|
df::coord pos;
|
2013-01-18 23:20:37 -07:00
|
|
|
ItemFilter filter;
|
2013-01-07 01:17:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-08 20:49:36 -07:00
|
|
|
static map<df::building_type, bool> planmode_enabled, saved_planmodes;
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
class Planner
|
|
|
|
{
|
|
|
|
public:
|
2013-02-08 20:49:36 -07:00
|
|
|
bool in_dummmy_screen;
|
2013-02-07 02:57:07 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
Planner() : quickfort_mode(false), in_dummmy_screen(false)
|
2013-02-07 02:57:07 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
bool isPlanableBuilding(const df::building_type type) const
|
|
|
|
{
|
|
|
|
return item_for_building_type.find(type) != item_for_building_type.end();
|
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
void reset(color_ostream &out)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
|
|
|
planned_buildings.clear();
|
2013-01-18 23:20:37 -07:00
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
std::vector<PersistentDataItem> items;
|
|
|
|
pworld->GetPersistentData(&items, "buildingplan/constraints");
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
for (auto i = items.begin(); i != items.end(); i++)
|
|
|
|
{
|
|
|
|
PlannedBuilding pb(*i, out);
|
|
|
|
if (pb.isValid())
|
|
|
|
planned_buildings.push_back(pb);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialize()
|
|
|
|
{
|
|
|
|
vector<string> item_names;
|
|
|
|
typedef df::enum_traits<df::item_type> item_types;
|
|
|
|
int size = item_types::last_item_value - item_types::first_item_value+1;
|
|
|
|
for (size_t i = 1; i < size; i++)
|
|
|
|
{
|
|
|
|
is_relevant_item_type[(df::item_type) (i-1)] = false;
|
|
|
|
string item_name = toLower(item_types::key_table[i]);
|
|
|
|
string item_name_clean;
|
|
|
|
for (auto c = item_name.begin(); c != item_name.end(); c++)
|
|
|
|
{
|
|
|
|
if (*c == '_')
|
|
|
|
continue;
|
|
|
|
item_name_clean += *c;
|
|
|
|
}
|
|
|
|
item_names.push_back(item_name_clean);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef df::enum_traits<df::building_type> building_types;
|
|
|
|
size = building_types::last_item_value - building_types::first_item_value+1;
|
|
|
|
for (size_t i = 1; i < size; i++)
|
|
|
|
{
|
|
|
|
auto building_type = (df::building_type) (i-1);
|
|
|
|
if (building_type == building_type::Weapon || building_type == building_type::Floodgate)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string building_name = toLower(building_types::key_table[i]);
|
|
|
|
for (size_t j = 0; j < item_names.size(); j++)
|
|
|
|
{
|
|
|
|
if (building_name == item_names[j])
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
auto btype = (df::building_type) (i-1);
|
|
|
|
auto itype = (df::item_type) j;
|
|
|
|
|
|
|
|
item_for_building_type[btype] = itype;
|
|
|
|
default_item_filters[btype] = ItemFilter();
|
|
|
|
available_item_vectors[itype] = vector<df::item *>();
|
|
|
|
is_relevant_item_type[itype] = true;
|
2013-02-08 20:49:36 -07:00
|
|
|
|
|
|
|
if (planmode_enabled.find(btype) == planmode_enabled.end())
|
|
|
|
{
|
|
|
|
planmode_enabled[btype] = false;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addPlannedBuilding(df::building *bld)
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
PlannedBuilding pb(bld, &default_item_filters[bld->getType()]);
|
2013-01-07 01:17:38 -07:00
|
|
|
planned_buildings.push_back(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void doCycle()
|
|
|
|
{
|
|
|
|
if (planned_buildings.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gather_available_items();
|
|
|
|
for (auto building_iter = planned_buildings.begin(); building_iter != planned_buildings.end();)
|
|
|
|
{
|
|
|
|
if (building_iter->isValid())
|
|
|
|
{
|
|
|
|
auto required_item_type = item_for_building_type[building_iter->getType()];
|
|
|
|
auto items_vector = &available_item_vectors[required_item_type];
|
|
|
|
if (items_vector->size() == 0 || !building_iter->assignClosestItem(items_vector))
|
|
|
|
{
|
|
|
|
++building_iter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
building_iter = planned_buildings.erase(building_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool allocatePlannedBuilding(df::building_type type)
|
|
|
|
{
|
|
|
|
coord32_t cursor;
|
|
|
|
if (!Gui::getCursorCoords(cursor.x, cursor.y, cursor.z))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto newinst = Buildings::allocInstance(cursor.get_coord16(), type);
|
|
|
|
if (!newinst)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::job_item *filter = new df::job_item();
|
|
|
|
filter->item_type = item_type::NONE;
|
|
|
|
filter->mat_index = 0;
|
|
|
|
filter->flags2.bits.building_material = true;
|
|
|
|
std::vector<df::job_item*> filters;
|
|
|
|
filters.push_back(filter);
|
|
|
|
|
|
|
|
if (!Buildings::constructWithFilters(newinst, filters))
|
|
|
|
{
|
|
|
|
delete newinst;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto iter = newinst->jobs.begin(); iter != newinst->jobs.end(); iter++)
|
|
|
|
{
|
|
|
|
(*iter)->flags.bits.suspend = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addPlannedBuilding(newinst);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
PlannedBuilding *getSelectedPlannedBuilding()
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
|
|
|
for (auto building_iter = planned_buildings.begin(); building_iter != planned_buildings.end(); building_iter++)
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
if (building_iter->isCurrentlySelectedBuilding())
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
return &(*building_iter);
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
return nullptr;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
void removeSelectedPlannedBuilding()
|
|
|
|
{
|
|
|
|
getSelectedPlannedBuilding()->remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemFilter *getDefaultItemFilterForType(df::building_type type)
|
|
|
|
{
|
|
|
|
return &default_item_filters[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
void cycleDefaultQuality(df::building_type type)
|
|
|
|
{
|
|
|
|
auto quality = &getDefaultItemFilterForType(type)->min_quality;
|
|
|
|
*quality = static_cast<df::item_quality>(*quality + 1);
|
|
|
|
if (*quality == item_quality::Artifact)
|
|
|
|
(*quality) = item_quality::Ordinary;
|
|
|
|
}
|
|
|
|
|
2013-02-08 20:49:36 -07:00
|
|
|
void enableQuickfortMode()
|
|
|
|
{
|
|
|
|
saved_planmodes = planmode_enabled;
|
|
|
|
for_each_(planmode_enabled,
|
|
|
|
[] (pair<const df::building_type, bool>& pair) { pair.second = true; } );
|
|
|
|
|
|
|
|
quickfort_mode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void disableQuickfortMode()
|
|
|
|
{
|
|
|
|
planmode_enabled = saved_planmodes;
|
|
|
|
quickfort_mode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inQuickFortMode()
|
|
|
|
{
|
|
|
|
return quickfort_mode;
|
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
private:
|
|
|
|
map<df::building_type, df::item_type> item_for_building_type;
|
2013-01-18 23:20:37 -07:00
|
|
|
map<df::building_type, ItemFilter> default_item_filters;
|
2013-01-07 01:17:38 -07:00
|
|
|
map<df::item_type, vector<df::item *>> available_item_vectors;
|
2013-01-18 23:20:37 -07:00
|
|
|
map<df::item_type, bool> is_relevant_item_type; //Needed for fast check when looping over all items
|
2013-02-08 20:49:36 -07:00
|
|
|
bool quickfort_mode;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
|
|
|
vector<PlannedBuilding> planned_buildings;
|
|
|
|
|
|
|
|
void gather_available_items()
|
|
|
|
{
|
|
|
|
for (auto iter = available_item_vectors.begin(); iter != available_item_vectors.end(); iter++)
|
|
|
|
{
|
|
|
|
iter->second.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Precompute a bitmask with the bad flags
|
|
|
|
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(hostile); F(on_fire); F(rotten); F(trader);
|
|
|
|
F(in_building); F(construction); F(artifact1);
|
|
|
|
#undef F
|
|
|
|
|
|
|
|
std::vector<df::item*> &items = world->items.other[items_other_id::ANY_FREE];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < items.size(); i++)
|
|
|
|
{
|
|
|
|
df::item *item = items[i];
|
|
|
|
|
|
|
|
if (item->flags.whole & bad_flags.whole)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
df::item_type itype = item->getType();
|
|
|
|
if (!is_relevant_item_type[itype])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (itype == item_type::BOX && item->isBag())
|
|
|
|
continue; //Skip bags
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
if (item->flags.bits.artifact1 || item->flags.bits.artifact2)
|
|
|
|
continue;
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
if (item->flags.bits.in_job ||
|
|
|
|
item->isAssignedToStockpile() ||
|
|
|
|
item->flags.bits.owned ||
|
|
|
|
item->flags.bits.in_chest)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
available_item_vectors[itype].push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Planner planner;
|
|
|
|
|
|
|
|
|
|
|
|
static bool is_planmode_enabled(df::building_type type)
|
|
|
|
{
|
|
|
|
if (planmode_enabled.find(type) == planmode_enabled.end())
|
|
|
|
{
|
2013-02-08 20:49:36 -07:00
|
|
|
return false;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return planmode_enabled[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DAY_TICKS 1200
|
|
|
|
DFhackCExport command_result plugin_onupdate(color_ostream &out)
|
|
|
|
{
|
|
|
|
static decltype(world->frame_counter) last_frame_count = 0;
|
|
|
|
if ((world->frame_counter - last_frame_count) >= DAY_TICKS/2)
|
|
|
|
{
|
|
|
|
last_frame_count = world->frame_counter;
|
|
|
|
planner.doCycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//START Viewscreen Hook
|
|
|
|
struct buildingplan_hook : public df::viewscreen_dwarfmodest
|
|
|
|
{
|
|
|
|
//START UI Methods
|
|
|
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
|
|
|
|
|
|
|
void send_key(const df::interface_key &key)
|
|
|
|
{
|
|
|
|
set< df::interface_key > keys;
|
|
|
|
keys.insert(key);
|
|
|
|
this->feed(&keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInPlannedBuildingQueryMode()
|
|
|
|
{
|
|
|
|
return (ui->main.mode == df::ui_sidebar_mode::QueryBuilding ||
|
|
|
|
ui->main.mode == df::ui_sidebar_mode::BuildingItems) &&
|
2013-01-18 23:20:37 -07:00
|
|
|
planner.getSelectedPlannedBuilding();
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isInPlannedBuildingPlacementMode()
|
|
|
|
{
|
|
|
|
return ui->main.mode == ui_sidebar_mode::Build &&
|
|
|
|
ui_build_selector &&
|
|
|
|
ui_build_selector->stage < 2 &&
|
|
|
|
planner.isPlanableBuilding(ui_build_selector->building_type);
|
|
|
|
}
|
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
bool handleInput(set<df::interface_key> *input)
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
|
|
|
if (isInPlannedBuildingPlacementMode())
|
|
|
|
{
|
|
|
|
auto type = ui_build_selector->building_type;
|
|
|
|
if (input->count(interface_key::CUSTOM_P))
|
|
|
|
{
|
|
|
|
planmode_enabled[type] = !planmode_enabled[type];
|
|
|
|
if (!planmode_enabled[type])
|
|
|
|
{
|
|
|
|
send_key(interface_key::CURSOR_DOWN_Z);
|
|
|
|
send_key(interface_key::CURSOR_UP_Z);
|
2013-02-07 04:04:52 -07:00
|
|
|
planner.in_dummmy_screen = false;
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_planmode_enabled(type))
|
|
|
|
{
|
2013-02-08 20:49:36 -07:00
|
|
|
if (planner.inQuickFortMode() && planner.in_dummmy_screen)
|
2013-02-07 04:04:52 -07:00
|
|
|
{
|
|
|
|
if (input->count(interface_key::SELECT) || input->count(interface_key::SEC_SELECT)
|
|
|
|
|| input->count(interface_key::LEAVESCREEN))
|
|
|
|
{
|
|
|
|
planner.in_dummmy_screen = false;
|
|
|
|
send_key(interface_key::LEAVESCREEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
if (input->count(interface_key::SELECT))
|
|
|
|
{
|
|
|
|
if (ui_build_selector->errors.size() == 0 && planner.allocatePlannedBuilding(type))
|
|
|
|
{
|
|
|
|
send_key(interface_key::CURSOR_DOWN_Z);
|
|
|
|
send_key(interface_key::CURSOR_UP_Z);
|
2013-02-08 20:49:36 -07:00
|
|
|
if (planner.inQuickFortMode())
|
2013-02-07 04:04:52 -07:00
|
|
|
{
|
|
|
|
planner.in_dummmy_screen = true;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-07 04:04:52 -07:00
|
|
|
else if (input->count(interface_key::CUSTOM_F))
|
2013-02-07 02:57:07 -07:00
|
|
|
{
|
2013-02-08 20:49:36 -07:00
|
|
|
if (!planner.inQuickFortMode())
|
|
|
|
{
|
|
|
|
planner.enableQuickfortMode();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
planner.disableQuickfortMode();
|
|
|
|
}
|
2013-02-07 02:57:07 -07:00
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
else if (input->count(interface_key::CUSTOM_M))
|
|
|
|
{
|
|
|
|
Screen::show(new ViewscreenChooseMaterial(planner.getDefaultItemFilterForType(type)));
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::CUSTOM_Q))
|
|
|
|
{
|
|
|
|
planner.cycleDefaultQuality(type);
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::CUSTOM_D))
|
|
|
|
{
|
|
|
|
planner.getDefaultItemFilterForType(type)->decorated_only =
|
|
|
|
!planner.getDefaultItemFilterForType(type)->decorated_only;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
}
|
2013-01-18 23:20:37 -07:00
|
|
|
else if (isInPlannedBuildingQueryMode())
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
if (input->count(interface_key::SUSPENDBUILDING))
|
|
|
|
{
|
|
|
|
return true; // Don't unsuspend planned buildings
|
|
|
|
}
|
|
|
|
else if (input->count(interface_key::DESTROYBUILDING))
|
|
|
|
{
|
|
|
|
planner.removeSelectedPlannedBuilding(); // Remove persistent data
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
|
|
|
{
|
2013-01-18 23:20:37 -07:00
|
|
|
if (!handleInput(input))
|
2013-01-07 01:17:38 -07:00
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, render, ())
|
|
|
|
{
|
|
|
|
bool plannable = isInPlannedBuildingPlacementMode();
|
|
|
|
if (plannable && is_planmode_enabled(ui_build_selector->building_type))
|
|
|
|
{
|
|
|
|
if (ui_build_selector->stage < 1)
|
|
|
|
{
|
|
|
|
// No materials but turn on cursor
|
|
|
|
ui_build_selector->stage = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto iter = ui_build_selector->errors.begin(); iter != ui_build_selector->errors.end();)
|
|
|
|
{
|
|
|
|
//FIXME Hide bags
|
|
|
|
if (((*iter)->find("Needs") != string::npos && **iter != "Needs adjacent wall") ||
|
|
|
|
(*iter)->find("No access") != string::npos)
|
|
|
|
{
|
|
|
|
iter = ui_build_selector->errors.erase(iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(render)();
|
|
|
|
|
|
|
|
auto dims = Gui::getDwarfmodeViewDims();
|
|
|
|
int left_margin = dims.menu_x1 + 1;
|
|
|
|
int x = left_margin;
|
2013-01-18 23:20:37 -07:00
|
|
|
auto type = ui_build_selector->building_type;
|
2013-01-07 01:17:38 -07:00
|
|
|
if (plannable)
|
|
|
|
{
|
2013-02-08 20:49:36 -07:00
|
|
|
if (planner.inQuickFortMode() && planner.in_dummmy_screen)
|
2013-02-07 04:04:52 -07:00
|
|
|
{
|
|
|
|
Screen::Pen pen(' ',COLOR_BLACK);
|
|
|
|
int y = dims.y1 + 1;
|
|
|
|
Screen::fillRect(pen, x, y, dims.menu_x2, y + 20);
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
++y;
|
2013-01-07 01:17:38 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
OutputString(COLOR_BROWN, x, y, "Quickfort Placeholder", true, left_margin);
|
|
|
|
OutputString(COLOR_WHITE, x, y, "Enter, Shift-Enter or Esc", true, left_margin);
|
|
|
|
}
|
|
|
|
else
|
2013-01-07 01:17:38 -07:00
|
|
|
{
|
2013-02-07 04:04:52 -07:00
|
|
|
int y = 23;
|
2013-02-07 02:57:07 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
OutputToggleString(x, y, "Planning Mode", "p", is_planmode_enabled(type), true, left_margin);
|
2013-01-18 23:20:37 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
if (is_planmode_enabled(type))
|
|
|
|
{
|
2013-02-08 20:49:36 -07:00
|
|
|
OutputToggleString(x, y, "Quickfort Mode", "f", planner.inQuickFortMode(), true, left_margin);
|
2013-01-18 23:20:37 -07:00
|
|
|
|
2013-02-07 04:04:52 -07:00
|
|
|
auto filter = planner.getDefaultItemFilterForType(type);
|
|
|
|
|
|
|
|
OutputHotkeyString(x, y, "Min Quality: ", "q");
|
|
|
|
OutputString(COLOR_BROWN, x, y, filter->getMinQuality(), true, left_margin);
|
|
|
|
|
|
|
|
OutputHotkeyString(x, y, "Decorated Only: ", "d");
|
|
|
|
OutputString(COLOR_BROWN, x, y,
|
|
|
|
(filter->decorated_only) ? "Yes" : "No", true, left_margin);
|
|
|
|
|
|
|
|
OutputHotkeyString(x, y, "Material Filter:", "m", true, left_margin);
|
|
|
|
auto filter_descriptions = filter->getMaterialFilterAsVector();
|
|
|
|
for_each_(filter_descriptions,
|
|
|
|
[&](string d) { OutputString(COLOR_BROWN, x, y, " *" + d, true, left_margin); });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
planner.in_dummmy_screen = false;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isInPlannedBuildingQueryMode())
|
|
|
|
{
|
2013-02-07 04:04:52 -07:00
|
|
|
planner.in_dummmy_screen = false;
|
|
|
|
|
2013-01-07 01:17:38 -07:00
|
|
|
// Hide suspend toggle option
|
|
|
|
int y = 20;
|
|
|
|
Screen::Pen pen(' ', COLOR_BLACK);
|
|
|
|
Screen::fillRect(pen, x, y, dims.menu_x2, y);
|
2013-01-18 23:20:37 -07:00
|
|
|
|
|
|
|
auto filter = planner.getSelectedPlannedBuilding()->getFilter();
|
|
|
|
y = 24;
|
|
|
|
OutputString(COLOR_BROWN, x, y, "Planned Building Filter:", true, left_margin);
|
|
|
|
OutputString(COLOR_BLUE, x, y, filter->getMinQuality(), true, left_margin);
|
|
|
|
|
|
|
|
if (filter->decorated_only)
|
|
|
|
OutputString(COLOR_BLUE, x, y, "Decorated Only", true, left_margin);
|
2013-01-29 00:44:56 -07:00
|
|
|
|
2013-01-18 23:20:37 -07:00
|
|
|
OutputString(COLOR_BROWN, x, y, "Materials:", true, left_margin);
|
2013-01-29 00:44:56 -07:00
|
|
|
auto filters = filter->getMaterialFilterAsVector();
|
|
|
|
for_each_(filters,
|
2013-01-18 23:20:37 -07:00
|
|
|
[&](string d) { OutputString(COLOR_BLUE, x, y, "*" + d, true, left_margin); });
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
2013-02-07 04:04:52 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
planner.in_dummmy_screen = false;
|
|
|
|
}
|
2013-01-07 01:17:38 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(buildingplan_hook, feed);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(buildingplan_hook, render);
|
|
|
|
|
|
|
|
|
|
|
|
static command_result buildingplan_cmd(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
if (!parameters.empty())
|
|
|
|
{
|
|
|
|
out << "Building Plan" << endl << "Version: " << PLUGIN_VERSION << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
if (!gps || !INTERPOSE_HOOK(buildingplan_hook, feed).apply() || !INTERPOSE_HOOK(buildingplan_hook, render).apply())
|
|
|
|
out.printerr("Could not insert buildingplan hooks!\n");
|
|
|
|
|
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
|
|
|
"buildingplan", "Place furniture before it's built",
|
|
|
|
buildingplan_cmd, false, ""));
|
|
|
|
|
|
|
|
planner.initialize();
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case SC_MAP_LOADED:
|
2013-01-18 23:20:37 -07:00
|
|
|
planner.reset(out);
|
2013-01-07 01:17:38 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
2013-01-29 00:44:56 -07:00
|
|
|
}
|