buildingplan: Don't assume building and item type names match

There are a few building types (e.g. hatch covers) where this is not
the case.

Fixes #604
develop
lethosor 2015-07-27 14:05:26 -04:00
parent 46457e4c30
commit 889c76b147
2 changed files with 44 additions and 46 deletions

@ -30,6 +30,7 @@ DFHack Future
Fixed default arguments in Lua gametype detection functions Fixed default arguments in Lua gametype detection functions
Circular lua dependencies (reqscript/script_environment) fixed Circular lua dependencies (reqscript/script_environment) fixed
Prevented crash in Items::createItem() Prevented crash in Items::createItem()
buildingplan: Now supports hatch covers
gui/hack-wish now properly assigns quality to items. gui/hack-wish now properly assigns quality to items.
gui/gm-editor handles lua tables properly gui/gm-editor handles lua tables properly
search: fixed crash in unit list after cancelling a job search: fixed crash in unit list after cancelling a job

@ -9,6 +9,7 @@ void debug(const string &msg)
color_ostream_proxy out(Core::getInstance().getConsole()); color_ostream_proxy out(Core::getInstance().getConsole());
out << "DEBUG (" << PLUGIN_VERSION << "): " << msg << endl; out << "DEBUG (" << PLUGIN_VERSION << "): " << msg << endl;
} }
#define dbg Core::getInstance().getConsole()
void enable_quickfort_fn(pair<const df::building_type, bool>& pair) { pair.second = true; } void enable_quickfort_fn(pair<const df::building_type, bool>& pair) { pair.second = true; }
@ -521,51 +522,47 @@ void Planner::reset(color_ostream &out)
void Planner::initialize() void Planner::initialize()
{ {
std::vector<std::string> item_names; #define add_building_type(btype, itype) \
typedef df::enum_traits<df::item_type> item_types; item_for_building_type[df::building_type::btype] = df::item_type::itype; \
int size = item_types::last_item_value - item_types::first_item_value+1; default_item_filters[df::building_type::btype] = ItemFilter(); \
for (size_t i = 1; i < size; i++) available_item_vectors[df::item_type::itype] = std::vector<df::item *>(); \
{ is_relevant_item_type[df::item_type::itype] = true; \
is_relevant_item_type[(df::item_type) (i-1)] = false; if (planmode_enabled.find(df::building_type::btype) == planmode_enabled.end()) \
std::string item_name = toLower(item_types::key_table[i]); planmode_enabled[df::building_type::btype] = false
std::string item_name_clean;
for (auto c = item_name.begin(); c != item_name.end(); c++) FOR_ENUM_ITEMS(item_type, it)
{ is_relevant_item_type[it] = false;
if (*c == '_')
continue; add_building_type(Armorstand, ARMORSTAND);
item_name_clean += *c; add_building_type(Bed, BED);
} add_building_type(Chair, CHAIR);
item_names.push_back(item_name_clean); add_building_type(Coffin, COFFIN);
} add_building_type(Door, DOOR);
// add_building_type(Floodgate, FLOODGATE); not displayed before or after being built
typedef df::enum_traits<df::building_type> building_types; add_building_type(Hatch, HATCH_COVER);
size = building_types::last_item_value - building_types::first_item_value+1; // not displayed before or after being built:
for (size_t i = 1; i < size; i++) // add_building_type(GrateWall, GRATE);
{ // add_building_type(GrateFloor, GRATE);
auto building_type = (df::building_type) (i-1); // add_building_type(BarsVertical, BAR);
if (building_type == building_type::Weapon || building_type == building_type::Floodgate) // add_building_type(BarsFloor, BAR);
continue; add_building_type(Cabinet, CABINET);
add_building_type(Box, BOX);
std::string building_name = toLower(building_types::key_table[i]); // skip kennels, farm plot
for (size_t j = 0; j < item_names.size(); j++) add_building_type(Weaponrack, WEAPONRACK);
{ add_building_type(Statue, STATUE);
if (building_name == item_names[j]) add_building_type(Slab, SLAB);
{ add_building_type(Table, TABLE);
auto btype = (df::building_type) (i-1); // skip roads ... furnaces
auto itype = (df::item_type) j; add_building_type(WindowGlass, WINDOW);
// skip gem window ... support
item_for_building_type[btype] = itype; add_building_type(AnimalTrap, ANIMALTRAP);
default_item_filters[btype] = ItemFilter(); add_building_type(Chain, CHAIN);
available_item_vectors[itype] = std::vector<df::item *>(); add_building_type(Cage, CAGE);
is_relevant_item_type[itype] = true; // skip archery target
add_building_type(TractionBench, TRACTION_BENCH);
if (planmode_enabled.find(btype) == planmode_enabled.end()) // skip nest box, hive (tools)
{
planmode_enabled[btype] = false; #undef add_building_type
}
}
}
}
} }
void Planner::doCycle() void Planner::doCycle()
@ -657,4 +654,4 @@ void Planner::cycleDefaultQuality(df::building_type type)
*quality = static_cast<df::item_quality>(*quality + 1); *quality = static_cast<df::item_quality>(*quality + 1);
if (*quality == item_quality::Artifact) if (*quality == item_quality::Artifact)
(*quality) = item_quality::Ordinary; (*quality) = item_quality::Ordinary;
} }