From 83f00e5583ed0dd98dcc0416971394be361cb641 Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Thu, 5 Jul 2012 09:59:28 -0500 Subject: [PATCH] Autolabor: allow setting the nonidle hauler percentage at runtime. Stripcaged: add keeparmor option --- plugins/autolabor.cpp | 37 ++++++++++++++++++++++++++++++++---- plugins/devel/stripcaged.cpp | 14 ++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index de1a1aef6..e06e5eda8 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -383,6 +383,8 @@ struct labor_default int active_dwarfs; }; +static int hauler_pct = 33; + static std::vector labor_infos; static const struct labor_default default_labor_infos[] = { @@ -544,6 +546,16 @@ static void init_state() if (!enable_autolabor) return; + auto cfg_haulpct = pworld->GetPersistentData("autolabor/haulpct"); + if (cfg_haulpct.isValid()) + { + hauler_pct = cfg_haulpct.ival(0); + } + else + { + hauler_pct = 33; + } + // Load labors from save labor_infos.resize(ARRAY_COUNT(default_labor_infos)); @@ -956,6 +968,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) for (int dwarf = 0; dwarf < n_dwarfs; dwarf++) { + if (dwarf_info[dwarf].trader && trader_requested) + { + dwarfs[dwarf]->status.labors[labor] = false; + } + if (dwarfs[dwarf]->status.labors[labor]) { if (labor_infos[labor].is_exclusive) @@ -1041,6 +1058,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) value += 350; } + // bias by happiness + + value += dwarfs[dwarf]->status.happiness; + values[dwarf] = value; candidates.push_back(dwarf); @@ -1121,7 +1142,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) } if (print_debug) - out.print("Dwarf %i \"%s\" assigned %s: value %i\n", dwarf, dwarfs[dwarf]->name.first_name.c_str(), ENUM_KEY_STR(unit_labor, labor).c_str(), values[dwarf]); + out.print("Dwarf %i \"%s\" assigned %s: value %i\n %s", dwarf, dwarfs[dwarf]->name.first_name.c_str(), ENUM_KEY_STR(unit_labor, labor).c_str(), values[dwarf], dwarf_info[dwarf].trader ? "(trader)" : ""); if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY) labor_infos[labor].active_dwarfs++; @@ -1134,7 +1155,8 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) // Set about 1/3 of the dwarfs as haulers. The haulers have all HAULER labors enabled. Having a lot of haulers helps // make sure that hauling jobs are handled quickly rather than building up. - int num_haulers = state_count[IDLE] + state_count[BUSY] / 3; + int num_haulers = state_count[IDLE] + state_count[BUSY] * hauler_pct / 100; + if (num_haulers < 1) num_haulers = 1; @@ -1261,7 +1283,13 @@ command_result autolabor (color_ostream &out, std::vector & parame return CR_FAILURE; } - if (parameters.size() == 2 || parameters.size() == 3) { + else if (parameters.size() == 2 && parameters[0] == "haulpct") + { + int pct = atoi (parameters[1].c_str()); + hauler_pct = pct; + return CR_OK; + } + else if (parameters.size() == 2 || parameters.size() == 3) { df::enums::unit_labor::unit_labor labor = df::enums::unit_labor::NONE; FOR_ENUM_ITEMS(unit_labor, test_labor) @@ -1353,7 +1381,8 @@ command_result autolabor (color_ostream &out, std::vector & parame return CR_OK; } - else if (parameters.size() == 1 && parameters[0] == "debug") { + else if (parameters.size() == 1 && parameters[0] == "debug") + { print_debug = 1; return CR_OK; diff --git a/plugins/devel/stripcaged.cpp b/plugins/devel/stripcaged.cpp index 7e492cb01..922f220b9 100644 --- a/plugins/devel/stripcaged.cpp +++ b/plugins/devel/stripcaged.cpp @@ -77,6 +77,13 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) command_result df_stripcaged(color_ostream &out, vector & parameters) { CoreSuspender suspend; + bool keeparmor = false; + + if (parameters.size() == 1 && parameters[0] == "keeparmor") + { + out << "Not dumping armor" << endl; + keeparmor = true; + } size_t count = 0; for (size_t i=0; i < world->units.all.size(); i++) @@ -89,6 +96,13 @@ command_result df_stripcaged(color_ostream &out, vector & parameters) df::unit_inventory_item* uii = unit->inventory[j]; if (uii->item) { + if (keeparmor && (uii->item->isArmorNotClothing() || uii->item->isClothing())) + { + std::string desc; + uii->item->getItemDescription(&desc,0); + out << "Armor item " << desc << " not dumped" << endl; + continue; + } uii->item->flags.bits.forbid = 0; uii->item->flags.bits.dump = 1; count++;