calculate and display global stats

develop
Myk Taylor 2023-04-22 15:05:25 -07:00
parent 8eb6226336
commit 2b2d03b9b1
No known key found for this signature in database
2 changed files with 57 additions and 16 deletions

@ -663,6 +663,38 @@ static void logistics_clearAllStockpileConfigs(color_ostream &out) {
watched_stockpiles.clear();
}
static int logistics_getGlobalCounts(lua_State *L) {
color_ostream *out = Lua::GetOutput(L);
if (!out)
out = &Core::getInstance().getConsole();
DEBUG(status,*out).print("entering logistics_getGlobalCounts\n");
size_t num_melt = df::global::world->items.other.ANY_MELT_DESIGNATED.size();
size_t num_trade = 0;
for (auto link = world->jobs.list.next; link; link = link->next) {
df::job *job = link->item;
if (job->job_type == df::job_type::BringItemToDepot)
++num_trade;
}
size_t num_dump = 0;
for (auto item : world->items.other.IN_PLAY) {
if (item->flags.bits.dump)
++num_dump;
}
unordered_map<string, size_t> results;
results.emplace("total_melt", num_melt);
results.emplace("total_trade", num_trade);
results.emplace("total_dump", num_dump);
Lua::Push(L, results);
TRACE(cycle, *out).print("exit logistics_getGlobalCounts\n");
return 1;
}
DFHACK_PLUGIN_LUA_FUNCTIONS{
DFHACK_LUA_FUNCTION(logistics_cycle),
DFHACK_LUA_FUNCTION(logistics_setStockpileConfig),
@ -673,4 +705,5 @@ DFHACK_PLUGIN_LUA_COMMANDS{
DFHACK_LUA_COMMAND(logistics_getStockpileData),
DFHACK_LUA_COMMAND(logistics_getStockpileConfigs),
DFHACK_LUA_COMMAND(logistics_clearStockpileConfig),
DFHACK_LUA_COMMAND(logistics_getGlobalCounts),
DFHACK_LUA_END};

@ -34,22 +34,7 @@ function getStockpileData()
return data
end
local function print_status()
print(('logistics is %sactively monitoring stockpiles and marking items')
:format(isEnabled() and '' or 'not '))
if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then
return
end
local data = getStockpileData()
print()
if not data[1] then
print 'No stockpiles defined -- go make some!'
return
end
local function print_stockpile_data(data)
local name_len = 12
for _,sp in ipairs(data) do
name_len = math.min(40, math.max(name_len, #sp.name))
@ -69,6 +54,29 @@ local function print_status()
end
end
local function print_status()
print(('logistics is %sactively monitoring stockpiles and marking items')
:format(isEnabled() and '' or 'not '))
if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then
return
end
local data = getStockpileData()
print()
if not data[1] then
print 'No stockpiles defined -- go make some!'
else
print_stockpile_data(data)
end
local global_stats = logistics_getGlobalCounts()
print()
print(('Total items marked for melting: %5d'):format(global_stats.total_melt))
print(('Total items marked for trading: %5d'):format(global_stats.total_trade))
print(('Total items marked for dumping: %5d'):format(global_stats.total_dump))
end
local function for_stockpiles(opts, fn)
if not opts.sp then
local selected_sp = dfhack.gui.getSelectedStockpile()