From 9a12910301bc264fa3757771797979ae1bf15978 Mon Sep 17 00:00:00 2001 From: LOIRELAB <66545056+LoireLab@users.noreply.github.com> Date: Sat, 19 Jul 2025 21:53:14 +0200 Subject: [PATCH] Summarize non-artifact item creation --- chronicle.lua | 65 +++++++++++++++++++++++++++++++++++++++++++--- docs/chronicle.rst | 7 +++-- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/chronicle.lua b/chronicle.lua index 40f0dd533..54d02e0b4 100644 --- a/chronicle.lua +++ b/chronicle.lua @@ -12,6 +12,7 @@ local function get_default_state() entries = {}, last_artifact_id = -1, known_invasions = {}, + item_counts = {}, -- item creation summary per year } end @@ -70,6 +71,40 @@ local function add_entry(text) persist_state() end +local CATEGORY_MAP = { + -- food and food-related + DRINK='food', DRINK2='food', FOOD='food', MEAT='food', FISH='food', + FISH_RAW='food', PLANT='food', PLANT_GROWTH='food', SEEDS='food', + EGG='food', CHEESE='food', POWDER_MISC='food', LIQUID_MISC='food', + GLOB='food', + -- weapons and defense + WEAPON='weapons', TRAPCOMP='weapons', + AMMO='ammo', SIEGEAMMO='ammo', + ARMOR='armor', PANTS='armor', HELM='armor', GLOVES='armor', + SHOES='armor', SHIELD='armor', QUIVER='armor', + -- materials + WOOD='wood', BOULDER='stone', ROCK='stone', ROUGH='gems', SMALLGEM='gems', + BAR='bars_blocks', BLOCKS='bars_blocks', + -- misc + COIN='coins', + -- finished goods and furniture + FIGURINE='finished_goods', AMULET='finished_goods', SCEPTER='finished_goods', + CROWN='finished_goods', RING='finished_goods', EARRING='finished_goods', + BRACELET='finished_goods', CRAFTS='finished_goods', TOY='finished_goods', + TOOL='finished_goods', GOBLET='finished_goods', FLASK='finished_goods', + BOX='furniture', BARREL='furniture', BED='furniture', CHAIR='furniture', + TABLE='furniture', DOOR='furniture', WINDOW='furniture', BIN='furniture', +} + +local IGNORE_TYPES = { + CORPSE=true, CORPSEPIECE=true, REMAINS=true, +} + +local function get_category(item) + local t = df.item_type[item:getType()] + return CATEGORY_MAP[t] or 'other' +end + local function on_unit_death(unit_id) local unit = df.unit.find(unit_id) if not unit then return end @@ -92,10 +127,17 @@ local function on_item_created(item_id) state.last_artifact_id = rec.id end add_entry(string.format('%s: Artifact "%s" created', date, name)) - else - local desc = dfhack.items.getDescription(item, 0, true) - add_entry(string.format('%s: Item "%s" created', date, desc)) + return end + + local type_name = df.item_type[item:getType()] + if IGNORE_TYPES[type_name] then return end + + local year = df.global.cur_year + local category = get_category(item) + state.item_counts[year] = state.item_counts[year] or {} + state.item_counts[year][category] = (state.item_counts[year][category] or 0) + 1 + persist_state() end local function on_invasion(invasion_id) @@ -184,6 +226,23 @@ elseif cmd == 'print' then print(state.entries[i]) end end +elseif cmd == 'summary' then + local years = {} + for year in pairs(state.item_counts) do table.insert(years, year) end + table.sort(years) + if #years == 0 then + print('No item creation records.') + return + end + for _,year in ipairs(years) do + local counts = state.item_counts[year] + local parts = {} + for cat,count in pairs(counts) do + table.insert(parts, string.format('%d %s', count, cat)) + end + table.sort(parts) + print(string.format('Year %d: %s', year, table.concat(parts, ', '))) + end else print(dfhack.script_help()) end diff --git a/docs/chronicle.rst b/docs/chronicle.rst index 0c5b039ef..d59b6e42b 100644 --- a/docs/chronicle.rst +++ b/docs/chronicle.rst @@ -6,8 +6,8 @@ chronicle :tags: fort gameplay This tool automatically records notable events in a chronicle that is stored -with your save. Unit deaths, all item creation events, and invasions are -recorded. +with your save. Unit deaths, artifact creation events, invasions, and yearly +totals of crafted items are recorded. Usage ----- @@ -17,6 +17,7 @@ Usage chronicle enable chronicle disable chronicle print [count] + chronicle summary chronicle clear ``chronicle enable`` @@ -27,5 +28,7 @@ Usage Print the most recent recorded events. Takes an optional ``count`` argument (default ``25``) that specifies how many events to show. Prints a notice if the chronicle is empty. +``chronicle summary`` + Show yearly totals of created items by category (non-artifact items only). ``chronicle clear`` Delete the chronicle.