Add 'Max Quality' setting to buildingplan

develop
Phillip Spiess 2018-05-20 14:25:59 -07:00
parent 8cb5e7fa88
commit 385ac3f9f5
4 changed files with 40 additions and 7 deletions

@ -131,6 +131,7 @@ Tim Walberg twalberg
Timothy Collett danaris Timothy Collett danaris
Tom Jobbins TheBloke Tom Jobbins TheBloke
Tom Prince Tom Prince
TotallyGatsby TotallyGatsby
Travis Hoppe thoppe orthographic-pedant Travis Hoppe thoppe orthographic-pedant
txtsd txtsd txtsd txtsd
U-glouglou\\simon U-glouglou\\simon

@ -39,7 +39,7 @@ bool ItemFilter::matches(DFHack::MaterialInfo &material) const
bool ItemFilter::matches(df::item *item) bool ItemFilter::matches(df::item *item)
{ {
if (item->getQuality() < min_quality) if (item->getQuality() < min_quality || item->getQuality() > max_quality)
return false; return false;
if (decorated_only && !item->hasImprovements()) if (decorated_only && !item->hasImprovements())
@ -120,6 +120,11 @@ std::string ItemFilter::getMinQuality()
return ENUM_KEY_STR(item_quality, min_quality); return ENUM_KEY_STR(item_quality, min_quality);
} }
std::string ItemFilter::getMaxQuality()
{
return ENUM_KEY_STR(item_quality, max_quality);
}
bool ItemFilter::isValid() bool ItemFilter::isValid()
{ {
return valid; return valid;
@ -400,6 +405,7 @@ PlannedBuilding::PlannedBuilding(df::building *building, ItemFilter *filter)
config.ival(1) = building->id; config.ival(1) = building->id;
config.ival(2) = filter->min_quality + 1; config.ival(2) = filter->min_quality + 1;
config.ival(3) = static_cast<int>(filter->decorated_only) + 1; config.ival(3) = static_cast<int>(filter->decorated_only) + 1;
config.ival(4) = filter->max_quality + 1;
} }
PlannedBuilding::PlannedBuilding(PersistentDataItem &config, color_ostream &out) PlannedBuilding::PlannedBuilding(PersistentDataItem &config, color_ostream &out)
@ -418,6 +424,7 @@ PlannedBuilding::PlannedBuilding(PersistentDataItem &config, color_ostream &out)
pos = df::coord(building->centerx, building->centery, building->z); pos = df::coord(building->centerx, building->centery, building->z);
filter.min_quality = static_cast<df::item_quality>(config.ival(2) - 1); filter.min_quality = static_cast<df::item_quality>(config.ival(2) - 1);
filter.max_quality = static_cast<df::item_quality>(config.ival(4) - 1);
filter.decorated_only = config.ival(3) - 1; filter.decorated_only = config.ival(3) - 1;
} }
@ -647,11 +654,20 @@ PlannedBuilding *Planner::getSelectedPlannedBuilding()
return nullptr; return nullptr;
} }
void Planner::cycleDefaultQuality(df::building_type type) void Planner::cycleMinQuality(df::building_type type)
{ {
auto quality = &getDefaultItemFilterForType(type)->min_quality; cycleItemQuality(&getDefaultItemFilterForType(type)->min_quality);
}
void Planner::cycleMaxQuality(df::building_type type)
{
cycleItemQuality(&getDefaultItemFilterForType(type)->max_quality);
}
void Planner::cycleItemQuality(item_quality::item_quality *quality) {
*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;
} }

@ -111,9 +111,11 @@ struct ItemFilter
df::dfhack_material_category mat_mask; df::dfhack_material_category mat_mask;
std::vector<DFHack::MaterialInfo> materials; std::vector<DFHack::MaterialInfo> materials;
df::item_quality min_quality; df::item_quality min_quality;
df::item_quality max_quality;
bool decorated_only; bool decorated_only;
ItemFilter() : min_quality(df::item_quality::Ordinary), decorated_only(false), valid(true) ItemFilter() : min_quality(df::item_quality::Ordinary), max_quality(df::item_quality::Artifact), decorated_only(false), valid(true)
{ {
clear(); // mat_mask is not cleared by default (see issue #1047) clear(); // mat_mask is not cleared by default (see issue #1047)
} }
@ -133,6 +135,7 @@ struct ItemFilter
bool parseSerializedMaterialTokens(std::string str); bool parseSerializedMaterialTokens(std::string str);
std::string getMinQuality(); std::string getMinQuality();
std::string getMaxQuality();
bool isValid(); bool isValid();
@ -414,7 +417,8 @@ public:
ItemFilter *getDefaultItemFilterForType(df::building_type type) { return &default_item_filters[type]; } ItemFilter *getDefaultItemFilterForType(df::building_type type) { return &default_item_filters[type]; }
void cycleDefaultQuality(df::building_type type); void cycleMinQuality(df::building_type type);
void cycleMaxQuality(df::building_type type);
void enableQuickfortMode() void enableQuickfortMode()
{ {
@ -441,6 +445,8 @@ private:
std::vector<PlannedBuilding> planned_buildings; std::vector<PlannedBuilding> planned_buildings;
void cycleItemQuality(item_quality::item_quality *quality);
void gather_available_items() void gather_available_items()
{ {
debug("Gather available items"); debug("Gather available items");

@ -163,7 +163,11 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
} }
else if (input->count(interface_key::CUSTOM_SHIFT_Q)) else if (input->count(interface_key::CUSTOM_SHIFT_Q))
{ {
planner.cycleDefaultQuality(type); planner.cycleMinQuality(type);
}
else if (input->count(interface_key::CUSTOM_SHIFT_W))
{
planner.cycleMaxQuality(type);
} }
else if (input->count(interface_key::CUSTOM_SHIFT_D)) else if (input->count(interface_key::CUSTOM_SHIFT_D))
{ {
@ -274,6 +278,9 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
OutputHotkeyString(x, y, "Min Quality: ", "Q"); OutputHotkeyString(x, y, "Min Quality: ", "Q");
OutputString(COLOR_BROWN, x, y, filter->getMinQuality(), true, left_margin); OutputString(COLOR_BROWN, x, y, filter->getMinQuality(), true, left_margin);
OutputHotkeyString(x, y, "Max Quality: ", "W");
OutputString(COLOR_BROWN, x, y, filter->getMaxQuality(), true, left_margin);
OutputToggleString(x, y, "Decorated Only: ", "D", filter->decorated_only, true, left_margin); OutputToggleString(x, y, "Decorated Only: ", "D", filter->decorated_only, true, left_margin);
OutputHotkeyString(x, y, "Material Filter:", "M", true, left_margin); OutputHotkeyString(x, y, "Material Filter:", "M", true, left_margin);
@ -299,7 +306,10 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
auto filter = planner.getSelectedPlannedBuilding()->getFilter(); auto filter = planner.getSelectedPlannedBuilding()->getFilter();
y = 24; y = 24;
OutputString(COLOR_BROWN, x, y, "Planned Building Filter:", true, left_margin); OutputString(COLOR_BROWN, x, y, "Planned Building Filter:", true, left_margin);
OutputString(COLOR_BROWN, x, y, "Min Quality: ", false, left_margin);
OutputString(COLOR_BLUE, x, y, filter->getMinQuality(), true, left_margin); OutputString(COLOR_BLUE, x, y, filter->getMinQuality(), true, left_margin);
OutputString(COLOR_BROWN, x, y, "Max Quality: ", false, left_margin);
OutputString(COLOR_BLUE, x, y, filter->getMaxQuality(), true, left_margin);
if (filter->decorated_only) if (filter->decorated_only)
OutputString(COLOR_BLUE, x, y, "Decorated Only", true, left_margin); OutputString(COLOR_BLUE, x, y, "Decorated Only", true, left_margin);