Fix crash in autolabor that happens when all dorfs decide to tipple at the same time

develop
unknown 2012-03-28 10:39:06 +08:00 committed by Petr Mrázek
parent 13d7beda4b
commit 9604be2701
1 changed files with 5 additions and 3 deletions

@ -802,7 +802,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
} }
// Idle dwarves come first, then we sort from least-skilled to most-skilled. // Idle dwarves come first, then we sort from least-skilled to most-skilled.
std::sort(hauler_ids.begin(), hauler_ids.end(), [&dwarf_info] (int i, int j) -> bool std::sort(hauler_ids.begin(), hauler_ids.end(), [&dwarf_info] (int i, int j) -> bool
{ {
if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE) if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE)
@ -812,6 +811,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty; return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty;
}); });
// don't set any haulers if everyone is off drinking or something
if (hauler_ids.size() == 0) {
num_haulers = 0;
}
FOR_ENUM_ITEMS(unit_labor, labor) FOR_ENUM_ITEMS(unit_labor, labor)
{ {
if (labor == df::enums::unit_labor::NONE) if (labor == df::enums::unit_labor::NONE)
@ -831,7 +835,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
assert(dwarf >= 0); assert(dwarf >= 0);
assert(dwarf < n_dwarfs); assert(dwarf < n_dwarfs);
dwarfs[dwarf]->status.labors[labor] = true; dwarfs[dwarf]->status.labors[labor] = true;
dwarf_info[dwarf].assigned_jobs++; dwarf_info[dwarf].assigned_jobs++;
} }
@ -848,7 +851,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
dwarfs[dwarf]->status.labors[labor] = false; dwarfs[dwarf]->status.labors[labor] = false;
} }
} }
return CR_OK; return CR_OK;
} }