summaryrefslogtreecommitdiff
path: root/plugins/autolabor.cpp
diff options
context:
space:
mode:
authorunknown2012-03-27 21:39:06 -0500
committerunknown2012-03-27 21:39:06 -0500
commit1566ae034f6832cae948fae59c600473075e01fd (patch)
treef7a5755d8696e2102220f0048d86d6fd1f310cd1 /plugins/autolabor.cpp
parentd2d16271f052cbf01a8c6e9fab5574739b3dd185 (diff)
downloaddfhack-1566ae034f6832cae948fae59c600473075e01fd.tar.gz
dfhack-1566ae034f6832cae948fae59c600473075e01fd.tar.bz2
dfhack-1566ae034f6832cae948fae59c600473075e01fd.tar.xz
Fix crash in autolabor that happens when all dorfs decide to tipple at the same time
Diffstat (limited to 'plugins/autolabor.cpp')
-rw-r--r--plugins/autolabor.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp
index 3ef0f9e5..c87d6ffb 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;
}