Update Manipulator to display stress level instead of happiness

develop
Quietust 2014-10-31 13:33:35 -05:00
parent ed225de365
commit f08a32f4e2
1 changed files with 34 additions and 31 deletions

@ -270,7 +270,7 @@ struct UnitInfo
enum altsort_mode { enum altsort_mode {
ALTSORT_NAME, ALTSORT_NAME,
ALTSORT_PROFESSION_OR_SQUAD, ALTSORT_PROFESSION_OR_SQUAD,
ALTSORT_HAPPINESS, ALTSORT_STRESS,
ALTSORT_ARRIVAL, ALTSORT_ARRIVAL,
ALTSORT_MAX ALTSORT_MAX
}; };
@ -311,13 +311,17 @@ bool sortBySquad (const UnitInfo *d1, const UnitInfo *d2)
return descending ? gt : !gt; return descending ? gt : !gt;
} }
bool sortByHappiness (const UnitInfo *d1, const UnitInfo *d2) bool sortByStress (const UnitInfo *d1, const UnitInfo *d2)
{ {
return sortByName(d1, d2); if (!d1->unit->status.current_soul)
/*if (descending) return !descending;
return (d1->unit->status.happiness > d2->unit->status.happiness); if (!d2->unit->status.current_soul)
return descending;
if (descending)
return (d1->unit->status.current_soul->personality.stress_level > d2->unit->status.current_soul->personality.stress_level);
else else
return (d1->unit->status.happiness < d2->unit->status.happiness);*/ return (d1->unit->status.current_soul->personality.stress_level < d2->unit->status.current_soul->personality.stress_level);
} }
bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2) bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2)
@ -368,7 +372,7 @@ bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2)
} }
enum display_columns { enum display_columns {
DISP_COLUMN_HAPPINESS, DISP_COLUMN_STRESS,
DISP_COLUMN_NAME, DISP_COLUMN_NAME,
DISP_COLUMN_PROFESSION_OR_SQUAD, DISP_COLUMN_PROFESSION_OR_SQUAD,
DISP_COLUMN_LABORS, DISP_COLUMN_LABORS,
@ -510,8 +514,8 @@ void viewscreen_unitlaborsst::calcSize()
// min/max width of columns // min/max width of columns
int col_minwidth[DISP_COLUMN_MAX]; int col_minwidth[DISP_COLUMN_MAX];
int col_maxwidth[DISP_COLUMN_MAX]; int col_maxwidth[DISP_COLUMN_MAX];
col_minwidth[DISP_COLUMN_HAPPINESS] = 4; col_minwidth[DISP_COLUMN_STRESS] = 6;
col_maxwidth[DISP_COLUMN_HAPPINESS] = 4; col_maxwidth[DISP_COLUMN_STRESS] = 6;
col_minwidth[DISP_COLUMN_NAME] = 16; col_minwidth[DISP_COLUMN_NAME] = 16;
col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below
col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10;
@ -779,10 +783,10 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
switch (click_header) switch (click_header)
{ {
case DISP_COLUMN_HAPPINESS: case DISP_COLUMN_STRESS:
if (enabler->mouse_lbut || enabler->mouse_rbut) if (enabler->mouse_lbut || enabler->mouse_rbut)
{ {
input_sort = ALTSORT_HAPPINESS; input_sort = ALTSORT_STRESS;
if (enabler->mouse_lbut) if (enabler->mouse_lbut)
events->insert(interface_key::SECONDSCROLL_PAGEUP); events->insert(interface_key::SECONDSCROLL_PAGEUP);
if (enabler->mouse_rbut) if (enabler->mouse_rbut)
@ -826,7 +830,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
switch (click_body) switch (click_body)
{ {
case DISP_COLUMN_HAPPINESS: case DISP_COLUMN_STRESS:
// do nothing // do nothing
break; break;
@ -932,8 +936,8 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
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_STRESS:
std::sort(units.begin(), units.end(), sortByHappiness); std::sort(units.begin(), units.end(), sortByStress);
break; break;
case ALTSORT_ARRIVAL: case ALTSORT_ARRIVAL:
std::sort(units.begin(), units.end(), sortByArrival); std::sort(units.begin(), units.end(), sortByArrival);
@ -948,9 +952,9 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
altsort = ALTSORT_PROFESSION_OR_SQUAD; altsort = ALTSORT_PROFESSION_OR_SQUAD;
break; break;
case ALTSORT_PROFESSION_OR_SQUAD: case ALTSORT_PROFESSION_OR_SQUAD:
altsort = ALTSORT_HAPPINESS; altsort = ALTSORT_STRESS;
break; break;
case ALTSORT_HAPPINESS: case ALTSORT_STRESS:
altsort = ALTSORT_ARRIVAL; altsort = ALTSORT_ARRIVAL;
break; break;
case ALTSORT_ARRIVAL: case ALTSORT_ARRIVAL:
@ -1001,7 +1005,7 @@ void viewscreen_unitlaborsst::render()
Screen::clear(); Screen::clear();
Screen::drawBorder(" Dwarf Manipulator - Manage Labors "); Screen::drawBorder(" Dwarf Manipulator - Manage Labors ");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_HAPPINESS], 2, "Hap."); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_STRESS], 2, "Stress");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name"); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 2, show_squad ? "Squad" : "Profession"); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 2, show_squad ? "Squad" : "Profession");
@ -1044,23 +1048,22 @@ void viewscreen_unitlaborsst::render()
df::unit *unit = cur->unit; df::unit *unit = cur->unit;
int8_t fg = 15, bg = 0; int8_t fg = 15, bg = 0;
int happy = 100;//cur->unit->status.happiness; int stress_lvl = unit->status.current_soul ? unit->status.current_soul->personality.stress_level : 0;
string happiness = stl_sprintf("%4i", happy); // cap at 6 digits
if (happy == 0) // miserable if (stress_lvl < -99999) stress_lvl = -99999;
if (stress_lvl > 999999) stress_lvl = 999999;
string stress = stl_sprintf("%6i", stress_lvl);
if (stress_lvl >= 500000)
fg = 13; // 5:1 fg = 13; // 5:1
else if (happy <= 25) // very unhappy else if (stress_lvl >= 250000)
fg = 12; // 4:1 fg = 12; // 4:1
else if (happy <= 50) // unhappy else if (stress_lvl >= 100000)
fg = 4; // 4:0
else if (happy < 75) // fine
fg = 14; // 6:1 fg = 14; // 6:1
else if (happy < 125) // quite content else if (stress_lvl >= 0)
fg = 6; // 6:0
else if (happy < 150) // happy
fg = 2; // 2:0 fg = 2; // 2:0
else // ecstatic else
fg = 10; // 2:1 fg = 10; // 2:1
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_HAPPINESS], 4 + row, happiness); Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_STRESS], 4 + row, stress);
fg = 15; fg = 15;
if (row_offset == sel_row) if (row_offset == sel_row)
@ -1233,8 +1236,8 @@ void viewscreen_unitlaborsst::render()
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_STRESS:
OutputString(15, x, y, "Happiness"); OutputString(15, x, y, "Stress Level");
break; break;
case ALTSORT_ARRIVAL: case ALTSORT_ARRIVAL:
OutputString(15, x, y, "Arrival"); OutputString(15, x, y, "Arrival");