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)
develop
Quietust 2014-06-24 08:36:36 -05:00
parent 14697174fc
commit 9625d56384
1 changed files with 18 additions and 6 deletions

@ -26,6 +26,8 @@
#include "df/creature_graphics_role.h" #include "df/creature_graphics_role.h"
#include "df/creature_raw.h" #include "df/creature_raw.h"
#include "df/caste_raw.h" #include "df/caste_raw.h"
#include "df/historical_entity.h"
#include "df/entity_raw.h"
using std::set; using std::set;
using std::vector; using std::vector;
@ -82,6 +84,14 @@ struct SkillColumn
df::job_skill skill; // displayed rating df::job_skill skill; // displayed rating
char label[3]; // column header char label[3]; // column header
bool special; // specified labor is mutually exclusive with all other special labors 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)) #define NUM_COLUMNS (sizeof(columns) / sizeof(SkillColumn))
@ -851,7 +861,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
} }
UnitInfo *cur = units[input_row]; 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; df::unit *unit = cur->unit;
const SkillColumn &col = columns[input_column]; const SkillColumn &col = columns[input_column];
@ -870,15 +880,17 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
} }
unit->status.labors[col.labor] = newstatus; 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; df::unit *unit = cur->unit;
const SkillColumn &col = columns[input_column]; 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++) for (int i = 0; i < NUM_COLUMNS; i++)
{ {
if (columns[i].group != col.group) if (columns[i].group != col.group)
continue; continue;
if (!columns[i].isValidLabor(ui->main.fortress_entity))
continue;
if (columns[i].special) if (columns[i].special)
{ {
if (newstatus) if (newstatus)
@ -912,7 +924,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
std::sort(units.begin(), units.end(), sortByName); std::sort(units.begin(), units.end(), sortByName);
break; break;
case ALTSORT_PROFESSION_OR_SQUAD: 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; break;
case ALTSORT_HAPPINESS: case ALTSORT_HAPPINESS:
std::sort(units.begin(), units.end(), sortByHappiness); 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; int x = 2, y = dim.y - 3;
@ -1213,7 +1225,7 @@ void viewscreen_unitlaborsst::render()
OutputString(15, x, y, "Name"); OutputString(15, x, y, "Name");
break; break;
case ALTSORT_PROFESSION_OR_SQUAD: case ALTSORT_PROFESSION_OR_SQUAD:
OutputString(15, x, y, show_squad ? "Squad" : "Profession"); OutputString(15, x, y, show_squad ? "Squad" : "Profession");
break; break;
case ALTSORT_HAPPINESS: case ALTSORT_HAPPINESS:
OutputString(15, x, y, "Happiness"); OutputString(15, x, y, "Happiness");