From 9604be2701616c437a7b3a84974d761d1143dd20 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Mar 2012 10:39:06 +0800 Subject: [PATCH] Fix crash in autolabor that happens when all dorfs decide to tipple at the same time --- plugins/autolabor.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index 3ef0f9e5c..c87d6ffbf 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -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; }