From 9625d563849a87103d3953c8b778dfda4e30c4db Mon Sep 17 00:00:00 2001 From: Quietust Date: Tue, 24 Jun 2014 08:36:36 -0500 Subject: [PATCH] Update Manipulator to respect entity permitted_labor settings This has the effect of locking out the Alchemy labor, which is how it's supposed to work in-game (but doesn't due to bug #6511) --- plugins/manipulator.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 4f22a44be..5d36dcd5b 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -26,6 +26,8 @@ #include "df/creature_graphics_role.h" #include "df/creature_raw.h" #include "df/caste_raw.h" +#include "df/historical_entity.h" +#include "df/entity_raw.h" using std::set; using std::vector; @@ -82,6 +84,14 @@ struct SkillColumn df::job_skill skill; // displayed rating char label[3]; // column header bool special; // specified labor is mutually exclusive with all other special labors + bool isValidLabor (df::historical_entity *entity = NULL) const + { + if (labor == unit_labor::NONE) + return false; + if (entity && entity->entity_raw && !entity->entity_raw->jobs.permitted_labor[labor]) + return false; + return true; + } }; #define NUM_COLUMNS (sizeof(columns) / sizeof(SkillColumn)) @@ -851,7 +861,7 @@ void viewscreen_unitlaborsst::feed(set *events) } UnitInfo *cur = units[input_row]; - if (events->count(interface_key::SELECT) && (cur->allowEdit) && (columns[input_column].labor != unit_labor::NONE)) + if (events->count(interface_key::SELECT) && (cur->allowEdit) && columns[input_column].isValidLabor(ui->main.fortress_entity)) { df::unit *unit = cur->unit; const SkillColumn &col = columns[input_column]; @@ -870,15 +880,17 @@ void viewscreen_unitlaborsst::feed(set *events) } unit->status.labors[col.labor] = newstatus; } - if (events->count(interface_key::SELECT_ALL) && (cur->allowEdit)) + if (events->count(interface_key::SELECT_ALL) && (cur->allowEdit) && columns[input_column].isValidLabor(ui->main.fortress_entity)) { df::unit *unit = cur->unit; const SkillColumn &col = columns[input_column]; - bool newstatus = (col.labor == unit_labor::NONE) ? true : !unit->status.labors[col.labor]; + bool newstatus = !unit->status.labors[col.labor]; for (int i = 0; i < NUM_COLUMNS; i++) { if (columns[i].group != col.group) continue; + if (!columns[i].isValidLabor(ui->main.fortress_entity)) + continue; if (columns[i].special) { if (newstatus) @@ -912,7 +924,7 @@ void viewscreen_unitlaborsst::feed(set *events) std::sort(units.begin(), units.end(), sortByName); break; case ALTSORT_PROFESSION_OR_SQUAD: - std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession); + std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession); break; case ALTSORT_HAPPINESS: std::sort(units.begin(), units.end(), sortByHappiness); @@ -1175,7 +1187,7 @@ void viewscreen_unitlaborsst::render() } - canToggle = (cur->allowEdit) && (columns[sel_column].labor != unit_labor::NONE); + canToggle = (cur->allowEdit) && columns[sel_column].isValidLabor(ui->main.fortress_entity); } int x = 2, y = dim.y - 3; @@ -1213,7 +1225,7 @@ void viewscreen_unitlaborsst::render() OutputString(15, x, y, "Name"); break; case ALTSORT_PROFESSION_OR_SQUAD: - OutputString(15, x, y, show_squad ? "Squad" : "Profession"); + OutputString(15, x, y, show_squad ? "Squad" : "Profession"); break; case ALTSORT_HAPPINESS: OutputString(15, x, y, "Happiness");