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

develop
unknown 2012-03-27 21:39:06 -05:00
parent d2d16271f0
commit 1566ae034f
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.
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)
@ -812,6 +811,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
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)
{
if (labor == df::enums::unit_labor::NONE)
@ -831,7 +835,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
assert(dwarf >= 0);
assert(dwarf < n_dwarfs);
dwarfs[dwarf]->status.labors[labor] = true;
dwarf_info[dwarf].assigned_jobs++;
}
@ -848,7 +851,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
dwarfs[dwarf]->status.labors[labor] = false;
}
}
return CR_OK;
}