Merge remote-tracking branch 'TotallyGatsby/buildingplanmax' into develop

develop
lethosor 2018-06-08 22:07:54 -04:00
commit c4692b1c8d
4 changed files with 65 additions and 10 deletions

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

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

@ -111,9 +111,11 @@ struct ItemFilter
df::dfhack_material_category mat_mask;
std::vector<DFHack::MaterialInfo> materials;
df::item_quality min_quality;
df::item_quality max_quality;
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)
}
@ -133,6 +135,7 @@ struct ItemFilter
bool parseSerializedMaterialTokens(std::string str);
std::string getMinQuality();
std::string getMaxQuality();
bool isValid();
@ -414,7 +417,8 @@ public:
ItemFilter *getDefaultItemFilterForType(df::building_type type) { return &default_item_filters[type]; }
void cycleDefaultQuality(df::building_type type);
void adjustMinQuality(df::building_type type, int amount);
void adjustMaxQuality(df::building_type type, int amount);
void enableQuickfortMode()
{
@ -441,6 +445,8 @@ private:
std::vector<PlannedBuilding> planned_buildings;
void boundsCheckItemQuality(item_quality::item_quality *quality);
void gather_available_items()
{
debug("Gather available items");

@ -110,7 +110,6 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
}
else if (input->count(interface_key::CUSTOM_P) ||
input->count(interface_key::CUSTOM_F) ||
input->count(interface_key::CUSTOM_Q) ||
input->count(interface_key::CUSTOM_D) ||
input->count(interface_key::CUSTOM_N))
{
@ -161,7 +160,19 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
}
else if (input->count(interface_key::CUSTOM_SHIFT_Q))
{
planner.cycleDefaultQuality(type);
planner.adjustMinQuality(type, 1);
}
else if (input->count(interface_key::CUSTOM_SHIFT_W))
{
planner.adjustMaxQuality(type, 1);
}
else if (input->count(interface_key::CUSTOM_Q))
{
planner.adjustMinQuality(type, -1);
}
else if (input->count(interface_key::CUSTOM_W))
{
planner.adjustMaxQuality(type, -1);
}
else if (input->count(interface_key::CUSTOM_SHIFT_D))
{
@ -269,9 +280,12 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
auto filter = planner.getDefaultItemFilterForType(type);
OutputHotkeyString(x, y, "Min Quality: ", "Q");
OutputHotkeyString(x, y, "Min Quality: ", "qQ");
OutputString(COLOR_BROWN, x, y, filter->getMinQuality(), true, left_margin);
OutputHotkeyString(x, y, "Max Quality: ", "wW");
OutputString(COLOR_BROWN, x, y, filter->getMaxQuality(), true, left_margin);
OutputToggleString(x, y, "Decorated Only: ", "D", filter->decorated_only, true, left_margin);
OutputHotkeyString(x, y, "Material Filter:", "M", true, left_margin);
@ -297,7 +311,10 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
auto filter = planner.getSelectedPlannedBuilding()->getFilter();
y = 24;
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_BROWN, x, y, "Max Quality: ", false, left_margin);
OutputString(COLOR_BLUE, x, y, filter->getMaxQuality(), true, left_margin);
if (filter->decorated_only)
OutputString(COLOR_BLUE, x, y, "Decorated Only", true, left_margin);