Autolabor: more tweaks to hauling labor decoding, fix heap corruption due to array underflow

develop
Kelly Martin 2012-12-08 03:51:07 -06:00
parent e7d3fbe97b
commit 6ae82187d2
1 changed files with 23 additions and 13 deletions

@ -710,16 +710,20 @@ private:
public: public:
df::unit_labor get_labor(df::job* j) df::unit_labor get_labor(df::job* j)
{ {
df::item* item = 0;
if (j->job_type == df::job_type::StoreItemInStockpile && j->item_subtype != -1) if (j->job_type == df::job_type::StoreItemInStockpile && j->item_subtype != -1)
return (df::unit_labor) j->item_subtype; return (df::unit_labor) j->item_subtype;
df::item* item; for (auto i = j->items.begin(); i != j->items.end(); i++)
// if (j->job_type == df::job_type::StoreItemInBarrel) {
// item = j->items[1]->item; if ((*i)->role == 7)
// else {
item = j->items[0]->item; item = (*i)->item;
break;
}
}
if (item->flags.bits.container && item->getType() != df::item_type::BIN) if (item && item->flags.bits.container)
{ {
for (auto a = item->general_refs.begin(); a != item->general_refs.end(); a++) for (auto a = item->general_refs.begin(); a != item->general_refs.end(); a++)
{ {
@ -731,8 +735,9 @@ private:
} }
} }
} }
df::unit_labor l = hauling_labor_map[item->getType()];
if (l == df::unit_labor::HAUL_REFUSE && item->flags.bits.dead_dwarf) df::unit_labor l = item ? hauling_labor_map[item->getType()] : df::unit_labor::HAUL_ITEM;
if (item && l == df::unit_labor::HAUL_REFUSE && item->flags.bits.dead_dwarf)
l = df::unit_labor::HAUL_BODY; l = df::unit_labor::HAUL_BODY;
return l; return l;
} }
@ -1751,7 +1756,7 @@ private:
if (labor != df::unit_labor::NONE) if (labor != df::unit_labor::NONE)
{ {
labor_needed[labor]--; labor_needed[labor]--;
if (!dwarf->dwarf->status.labors[labor]) if (!dwarf->dwarf->status.labors[labor] && print_debug)
{ {
out.print("AUTOLABOR: dwarf %s (id %d) is doing job %s(%d) but is not enabled for labor %s(%d).\n", out.print("AUTOLABOR: dwarf %s (id %d) is doing job %s(%d) but is not enabled for labor %s(%d).\n",
dwarf->dwarf->name.first_name.c_str(), dwarf->dwarf->id, dwarf->dwarf->name.first_name.c_str(), dwarf->dwarf->id,
@ -2073,8 +2078,13 @@ public:
if (best_labor >= df::unit_labor::HAUL_STONE && best_labor <= df::unit_labor::HAUL_ANIMAL) if (best_labor >= df::unit_labor::HAUL_STONE && best_labor <= df::unit_labor::HAUL_ANIMAL)
canary &= ~(1 << best_labor); canary &= ~(1 << best_labor);
if (best_labor != df::unit_labor::NONE)
{
labor_infos[best_labor].active_dwarfs++; labor_infos[best_labor].active_dwarfs++;
to_assign[best_labor]--; to_assign[best_labor]--;
}
available_dwarfs.erase(bestdwarf); available_dwarfs.erase(bestdwarf);
} }