Skip to content

Commit

Permalink
Merge pull request DFHack#1188 from BenLubar/labormanager-culture-crash
Browse files Browse the repository at this point in the history
Fix labormanager crash when a dwarf doesn't have a cultural identity
  • Loading branch information
lethosor authored Nov 23, 2017
2 parents c546e5e + e06644c commit c8cd2f4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/labormanager/labormanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,8 @@ class AutoLaborManager {

void collect_dwarf_list()
{
state_count.clear();
state_count.resize(NUM_STATE);

for (auto u = world->units.active.begin(); u != world->units.active.end(); ++u)
{
Expand Down Expand Up @@ -1373,6 +1375,8 @@ class AutoLaborManager {
if (print_debug)
out.print("Dwarf \"%s\": state %s %d\n", dwarf->dwarf->name.first_name.c_str(), state_names[dwarf->state], dwarf->clear_all);

state_count[dwarf->state]++;

// determine if dwarf has medical needs
if (dwarf->dwarf->health && !(
// on-duty military will not necessarily break to get minor injuries attended
Expand Down Expand Up @@ -1516,11 +1520,12 @@ class AutoLaborManager {

if (labor == df::unit_labor::CUTWOOD)
{
auto c_id = d->dwarf->cultural_identity;
auto culture = world->cultural_identities.all[c_id];
auto ethics = culture->ethic[df::ethic_type::KILL_PLANT];
if (ethics != df::ethic_response::NOT_APPLICABLE && ethics != df::ethic_response::REQUIRED)
score += 10000 * (df::ethic_response::ACCEPTABLE - ethics);
if (auto culture = df::cultural_identity::find(d->dwarf->cultural_identity))
{
auto ethics = culture->ethic[df::ethic_type::KILL_PLANT];
if (ethics != df::ethic_response::NOT_APPLICABLE && ethics != df::ethic_response::REQUIRED)
score += 10000 * (df::ethic_response::ACCEPTABLE - ethics);
}
}

score -= Units::computeMovementSpeed(d->dwarf);
Expand Down

0 comments on commit c8cd2f4

Please sign in to comment.