diff --git a/plugins/lua/tailor.lua b/plugins/lua/tailor.lua index e9a88bfe1..46b3526d9 100644 --- a/plugins/lua/tailor.lua +++ b/plugins/lua/tailor.lua @@ -32,6 +32,11 @@ function setMaterials(names) idxs.adamantine or -1) end +function setDebugMode(opt) + local fl = (opt[1] == "true" or opt[1] == "on") + tailor_setDebugFlag(fl) +end + function parse_commandline(...) local args, opts = {...}, {} local positionals = process_args(opts, args) @@ -47,6 +52,8 @@ function parse_commandline(...) tailor_doCycle() elseif command == 'materials' then setMaterials(positionals) + elseif command == 'debugging' then + setDebugMode(positionals) else return false end diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 2c5a1a027..3ba6744bb 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -157,7 +157,14 @@ private: int default_reserve = 10; + bool inventory_sanity_checking = false; + public: + void set_debug_flag(bool f) + { + inventory_sanity_checking = f; + } + void reset() { available.clear(); @@ -170,16 +177,42 @@ public: void scan_clothing() { - for (auto i : world->items.other[df::items_other_id::ANY_GENERIC37]) // GENERIC37 is "clothing" + if (!inventory_sanity_checking) { - if (i->flags.whole & badFlags.whole) - continue; - if (i->getWear() >= 1) - continue; - df::item_type t = i->getType(); - int size = world->raws.creatures.all[i->getMakerRace()]->adultsize; + for (auto i : world->items.other[df::items_other_id::ANY_GENERIC37]) // GENERIC37 is "clothing" + { + if (i->flags.whole & badFlags.whole) + continue; + if (i->getWear() >= 1) + continue; + df::item_type t = i->getType(); + int size = world->raws.creatures.all[i->getMakerRace()]->adultsize; + + available[std::make_pair(t, size)] += 1; + } + } + else + { + auto& l = world->items.other[df::items_other_id::ANY_GENERIC37]; + + for (auto i : world->items.other[df::items_other_id::IN_PLAY]) + { + if (i->flags.whole & badFlags.whole) + continue; + if (!i->isClothing()) + continue; + if (std::find(std::begin(l), std::end(l), i) == std::end(l)) + { + DEBUG(cycle).print("tailor: clothing item %d missing from GENERIC37 list\n", i->id); + } + if (i->getWear() >= 1) + continue; + df::item_type t = i->getType(); + int size = world->raws.creatures.all[i->getMakerRace()]->adultsize; + + available[std::make_pair(t, size)] += 1; + } - available[std::make_pair(t, size)] += 1; } } @@ -748,9 +781,18 @@ static int tailor_getMaterialPreferences(lua_State *L) { return 1; } +static void tailor_setDebugFlag(color_ostream& out, bool enable) +{ + DEBUG(config, out).print("entering tailor_setDebugFlag\n"); + + tailor_instance->set_debug_flag(enable); + +} + DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_LUA_FUNCTION(tailor_doCycle), DFHACK_LUA_FUNCTION(tailor_setMaterialPreferences), + DFHACK_LUA_FUNCTION(tailor_setDebugFlag), DFHACK_LUA_END };