tailor: add inventory sanity check debug mode

enable with "tailor debugging on" disable with "tailor debugging off"

this setting is not persisted
develop
Kelly Kinkade 2023-03-25 14:56:04 -05:00
parent 95f6e6e5be
commit c8c0040678
2 changed files with 57 additions and 8 deletions

@ -32,6 +32,11 @@ function setMaterials(names)
idxs.adamantine or -1) idxs.adamantine or -1)
end end
function setDebugMode(opt)
local fl = (opt[1] == "true" or opt[1] == "on")
tailor_setDebugFlag(fl)
end
function parse_commandline(...) function parse_commandline(...)
local args, opts = {...}, {} local args, opts = {...}, {}
local positionals = process_args(opts, args) local positionals = process_args(opts, args)
@ -47,6 +52,8 @@ function parse_commandline(...)
tailor_doCycle() tailor_doCycle()
elseif command == 'materials' then elseif command == 'materials' then
setMaterials(positionals) setMaterials(positionals)
elseif command == 'debugging' then
setDebugMode(positionals)
else else
return false return false
end end

@ -157,7 +157,14 @@ private:
int default_reserve = 10; int default_reserve = 10;
bool inventory_sanity_checking = false;
public: public:
void set_debug_flag(bool f)
{
inventory_sanity_checking = f;
}
void reset() void reset()
{ {
available.clear(); available.clear();
@ -170,16 +177,42 @@ public:
void scan_clothing() 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) for (auto i : world->items.other[df::items_other_id::ANY_GENERIC37]) // GENERIC37 is "clothing"
continue; {
if (i->getWear() >= 1) if (i->flags.whole & badFlags.whole)
continue; continue;
df::item_type t = i->getType(); if (i->getWear() >= 1)
int size = world->raws.creatures.all[i->getMakerRace()]->adultsize; 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; 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_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(tailor_doCycle), DFHACK_LUA_FUNCTION(tailor_doCycle),
DFHACK_LUA_FUNCTION(tailor_setMaterialPreferences), DFHACK_LUA_FUNCTION(tailor_setMaterialPreferences),
DFHACK_LUA_FUNCTION(tailor_setDebugFlag),
DFHACK_LUA_END DFHACK_LUA_END
}; };