Cleanup autolabor+cleanowned, fix depends/clsocket

develop
Quietust 2012-09-13 14:42:17 -05:00
parent 1d8c9a6a5f
commit 1325b70e41
3 changed files with 169 additions and 198 deletions

@ -1 +1 @@
Subproject commit 3808a8ac4fc1bbc0422492cb042099c47a312b58
Subproject commit d0b2d0750dc2d529a152eba4f3f519f69ff7eab0

@ -9,6 +9,7 @@
#include <vector>
#include <algorithm>
#include "modules/Units.h"
#include "modules/World.h"
// DF data structure definition headers
@ -537,7 +538,7 @@ static void cleanup_state()
labor_infos.clear();
}
static void reset_labor(df::enums::unit_labor::unit_labor labor)
static void reset_labor(df::unit_labor labor)
{
labor_infos[labor].set_minimum_dwarfs(default_labor_infos[labor].minimum_dwarfs);
labor_infos[labor].set_maximum_dwarfs(default_labor_infos[labor].maximum_dwarfs);
@ -576,7 +577,7 @@ static void init_state()
for (auto p = items.begin(); p != items.end(); p++)
{
string key = p->key();
df::enums::unit_labor::unit_labor labor = (df::enums::unit_labor::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
if (labor >= 0 && labor <= labor_infos.size())
{
labor_infos[labor].config = *p;
@ -597,7 +598,7 @@ static void init_state()
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
labor_infos[i].active_dwarfs = 0;
reset_labor((df::enums::unit_labor::unit_labor) i);
reset_labor((df::unit_labor) i);
}
generate_labor_to_skill_map();
@ -611,12 +612,12 @@ static void generate_labor_to_skill_map()
// Generate labor -> skill mapping
for (int i = 0; i <= ENUM_LAST_ITEM(unit_labor); i++)
labor_to_skill[i] = df::enums::job_skill::NONE;
labor_to_skill[i] = job_skill::NONE;
FOR_ENUM_ITEMS(job_skill, skill)
{
int labor = ENUM_ATTR(job_skill, labor, skill);
if (labor != df::enums::unit_labor::NONE)
if (labor != unit_labor::NONE)
{
/*
assert(labor >= 0);
@ -779,7 +780,7 @@ static void assign_labor(unit_labor::unit_labor labor,
int value = dwarf_info[dwarf].mastery_penalty;
if (skill != df::enums::job_skill::NONE)
if (skill != job_skill::NONE)
{
int skill_level = 0;
int skill_experience = 0;
@ -843,9 +844,9 @@ static void assign_labor(unit_labor::unit_labor labor,
int max_dwarfs = labor_infos[labor].maximum_dwarfs();
// Special - don't assign hunt without a butchers, or fish without a fishery
if (df::enums::unit_labor::HUNT == labor && !has_butchers)
if (unit_labor::HUNT == labor && !has_butchers)
min_dwarfs = max_dwarfs = 0;
if (df::enums::unit_labor::FISH == labor && !has_fishery)
if (unit_labor::FISH == labor && !has_fishery)
min_dwarfs = max_dwarfs = 0;
bool want_idle_dwarf = true;
@ -956,15 +957,15 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
df::building *build = world->buildings.all[i];
auto type = build->getType();
if (df::enums::building_type::Workshop == type)
if (building_type::Workshop == type)
{
auto subType = build->getSubtype();
if (df::enums::workshop_type::Butchers == subType)
df::workshop_type subType = (df::workshop_type)build->getSubtype();
if (workshop_type::Butchers == subType)
has_butchers = true;
if (df::enums::workshop_type::Fishery == subType)
if (workshop_type::Fishery == subType)
has_fishery = true;
}
else if (df::enums::building_type::TradeDepot == type)
else if (building_type::TradeDepot == type)
{
df::building_tradedepotst* depot = (df::building_tradedepotst*) build;
trader_requested = depot->trade_flags.bits.trader_requested;
@ -978,11 +979,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
}
}
for (int i = 0; i < world->units.all.size(); ++i)
for (int i = 0; i < world->units.active.size(); ++i)
{
df::unit* cre = world->units.all[i];
if (cre->race == race && cre->civ_id == civ && !cre->flags1.bits.marauder && !cre->flags1.bits.diplomat && !cre->flags1.bits.merchant &&
!cre->flags1.bits.dead && !cre->flags1.bits.forest)
df::unit* cre = world->units.active[i];
if (Units::isCitizen(cre))
{
if (cre->burrows.size() > 0)
continue; // dwarfs assigned to burrows are skipped entirely
@ -1003,9 +1003,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
dwarf_info[dwarf].single_labor = -1;
// assert(dwarfs[dwarf]->status.souls.size() > 0);
// assert fails can cause DF to crash, so don't do that
if (dwarfs[dwarf]->status.souls.size() <= 0)
continue;
@ -1076,7 +1073,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
// Track total & highest skill among normal/medical skills. (We don't care about personal or social skills.)
if (skill_class != df::enums::job_skill_class::Normal && skill_class != df::enums::job_skill_class::Medical)
if (skill_class != job_skill_class::Normal && skill_class != job_skill_class::Medical)
continue;
if (dwarf_info[dwarf].highest_skill < skill_level)
@ -1093,16 +1090,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
dwarf_info[dwarf].mastery_penalty -= 10 * dwarf_info[dwarf].total_skill;
dwarf_info[dwarf].mastery_penalty -= dwarf_info[dwarf].noble_penalty;
for (int labor = ENUM_FIRST_ITEM(unit_labor); labor <= ENUM_LAST_ITEM(unit_labor); labor++)
FOR_ENUM_ITEMS(unit_labor, labor)
{
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
continue;
/*
assert(labor >= 0);
assert(labor < ARRAY_COUNT(labor_infos));
*/
if (labor_infos[labor].is_exclusive && dwarfs[dwarf]->status.labors[labor])
dwarf_info[dwarf].mastery_penalty -= 100;
}
@ -1120,15 +1112,13 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
for (auto p = dwarfs[dwarf]->status.misc_traits.begin(); p < dwarfs[dwarf]->status.misc_traits.end(); p++)
{
// 7 / 0x7 = Newly arrived migrant, will not work yet
// 17 / 0x11 = On break
if ((*p)->id == 0x07 || (*p)->id == 0x11)
if ((*p)->id == misc_trait_type::Migrant || (*p)->id == misc_trait_type::OnBreak)
is_on_break = true;
}
if (dwarfs[dwarf]->profession == df::enums::profession::BABY ||
dwarfs[dwarf]->profession == df::enums::profession::CHILD ||
dwarfs[dwarf]->profession == df::enums::profession::DRUNK)
if (dwarfs[dwarf]->profession == profession::BABY ||
dwarfs[dwarf]->profession == profession::CHILD ||
dwarfs[dwarf]->profession == profession::DRUNK)
{
dwarf_info[dwarf].state = CHILD;
}
@ -1146,11 +1136,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
else
{
int job = dwarfs[dwarf]->job.current_job->job_type;
/*
assert(job >= 0);
assert(job < ARRAY_COUNT(dwarf_states));
*/
if (job >= 0 && job < ARRAY_COUNT(dwarf_states))
dwarf_info[dwarf].state = dwarf_states[job];
else
@ -1170,14 +1155,9 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
FOR_ENUM_ITEMS(unit_labor, labor)
{
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
continue;
/*
assert(labor >= 0);
assert(labor < ARRAY_COUNT(labor_infos));
*/
labor_infos[labor].active_dwarfs = 0;
labors.push_back(labor);
@ -1217,11 +1197,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
auto labor = *lp;
/*
assert(labor >= 0);
assert(labor < ARRAY_COUNT(labor_infos));
*/
assign_labor(labor, n_dwarfs, dwarf_info, trader_requested, dwarfs, has_butchers, has_fishery, out);
}
@ -1241,7 +1216,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
FOR_ENUM_ITEMS(unit_labor, labor)
{
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
continue;
if (labor_infos[labor].mode() != HAULERS)
continue;
@ -1264,14 +1239,9 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
FOR_ENUM_ITEMS(unit_labor, labor)
{
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
continue;
/*
assert(labor >= 0);
assert(labor < ARRAY_COUNT(labor_infos));
*/
if (labor_infos[labor].mode() != HAULERS)
continue;
@ -1311,7 +1281,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
return CR_OK;
}
void print_labor (df::enums::unit_labor::unit_labor labor, color_ostream &out)
void print_labor (df::unit_labor labor, color_ostream &out)
{
string labor_name = ENUM_KEY_STR(unit_labor, labor);
out << labor_name << ": ";
@ -1358,7 +1328,6 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
return CR_OK;
}
else if (parameters.size() == 2 && parameters[0] == "haulpct")
{
if (!enable_autolabor)
@ -1371,15 +1340,15 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
hauler_pct = pct;
return CR_OK;
}
else if (parameters.size() == 2 || parameters.size() == 3) {
else if (parameters.size() == 2 || parameters.size() == 3)
{
if (!enable_autolabor)
{
out << "Error: The plugin is not enabled." << endl;
return CR_FAILURE;
}
df::enums::unit_labor::unit_labor labor = df::enums::unit_labor::NONE;
df::unit_labor labor = unit_labor::NONE;
FOR_ENUM_ITEMS(unit_labor, test_labor)
{
@ -1387,7 +1356,7 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
labor = test_labor;
}
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
{
out.printerr("Could not find labor %s.\n", parameters[0].c_str());
return CR_WRONG_USAGE;
@ -1430,7 +1399,8 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
return CR_OK;
}
else if (parameters.size() == 1 && parameters[0] == "reset-all") {
else if (parameters.size() == 1 && parameters[0] == "reset-all")
{
if (!enable_autolabor)
{
out << "Error: The plugin is not enabled." << endl;
@ -1439,12 +1409,13 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
for (int i = 0; i < labor_infos.size(); i++)
{
reset_labor((df::enums::unit_labor::unit_labor) i);
reset_labor((df::unit_labor) i);
}
out << "All labors reset." << endl;
return CR_OK;
}
else if (parameters.size() == 1 && parameters[0] == "list" || parameters[0] == "status") {
else if (parameters.size() == 1 && parameters[0] == "list" || parameters[0] == "status")
{
if (!enable_autolabor)
{
out << "Error: The plugin is not enabled." << endl;
@ -1467,7 +1438,7 @@ command_result autolabor (color_ostream &out, std::vector <std::string> & parame
{
FOR_ENUM_ITEMS(unit_labor, labor)
{
if (labor == df::enums::unit_labor::NONE)
if (labor == unit_labor::NONE)
continue;
print_labor(labor, out);
@ -1571,7 +1542,7 @@ static int stockcheck(color_ostream &out, vector <string> & parameters)
{
df::building *build = world->buildings.all[i];
auto type = build->getType();
if (df::enums::building_type::Stockpile == type)
if (building_type::Stockpile == type)
{
df::building_stockpilest *sp = virtual_cast<df::building_stockpilest>(build);
StockpileInfo *spi = new StockpileInfo(sp);
@ -1580,7 +1551,7 @@ static int stockcheck(color_ostream &out, vector <string> & parameters)
}
std::vector<df::item*> &items = world->items.other[df::enums::items_other_id::ANY_FREE];
std::vector<df::item*> &items = world->items.other[items_other_id::ANY_FREE];
// Precompute a bitmask with the bad flags
df::item_flags bad_flags;
@ -1602,13 +1573,13 @@ static int stockcheck(color_ostream &out, vector <string> & parameters)
// we really only care about MEAT, FISH, FISH_RAW, PLANT, CHEESE, FOOD, and EGG
df::item_type typ = item->getType();
if (typ != df::enums::item_type::MEAT &&
typ != df::enums::item_type::FISH &&
typ != df::enums::item_type::FISH_RAW &&
typ != df::enums::item_type::PLANT &&
typ != df::enums::item_type::CHEESE &&
typ != df::enums::item_type::FOOD &&
typ != df::enums::item_type::EGG)
if (typ != item_type::MEAT &&
typ != item_type::FISH &&
typ != item_type::FISH_RAW &&
typ != item_type::PLANT &&
typ != item_type::CHEESE &&
typ != item_type::FOOD &&
typ != item_type::EGG)
continue;
df::item *container = 0;
@ -1673,11 +1644,11 @@ static int stockcheck(color_ostream &out, vector <string> & parameters)
if (building) {
df::building_type btype = building->getType();
if (btype == df::enums::building_type::TradeDepot ||
btype == df::enums::building_type::Wagon)
if (btype == building_type::TradeDepot ||
btype == building_type::Wagon)
continue; // items in trade depot or the embark wagon do not rot
if (typ == df::enums::item_type::EGG && btype ==df::enums::building_type::NestBox)
if (typ == item_type::EGG && btype ==building_type::NestBox)
continue; // eggs in nest box do not rot
}

@ -116,14 +116,14 @@ command_result df_cleanowned (color_ostream &out, vector <string> & parameters)
}
else if (item->flags.bits.on_ground)
{
int32_t type = item->getType();
if((df::enums::item_type::item_type)type == item_type::MEAT ||
(df::enums::item_type::item_type)type == item_type::FISH ||
(df::enums::item_type::item_type)type == item_type::VERMIN ||
(df::enums::item_type::item_type)type == item_type::PET ||
(df::enums::item_type::item_type)type == item_type::PLANT ||
(df::enums::item_type::item_type)type == item_type::CHEESE ||
(df::enums::item_type::item_type)type == item_type::FOOD
df::item_type type = item->getType();
if(type == item_type::MEAT ||
type == item_type::FISH ||
type == item_type::VERMIN ||
type == item_type::PET ||
type == item_type::PLANT ||
type == item_type::CHEESE ||
type == item_type::FOOD
)
{
confiscate = true;