Skip to content

Commit fc848c8

Browse files
authored
Merge pull request #14 from LoireLab/3zaa1h-codex
Summarize non-artifact item creation
2 parents 5a1278e + 9a12910 commit fc848c8

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

chronicle.lua

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local function get_default_state()
1212
entries = {},
1313
last_artifact_id = -1,
1414
known_invasions = {},
15+
item_counts = {}, -- item creation summary per year
1516
}
1617
end
1718

@@ -70,6 +71,40 @@ local function add_entry(text)
7071
persist_state()
7172
end
7273

74+
local CATEGORY_MAP = {
75+
-- food and food-related
76+
DRINK='food', DRINK2='food', FOOD='food', MEAT='food', FISH='food',
77+
FISH_RAW='food', PLANT='food', PLANT_GROWTH='food', SEEDS='food',
78+
EGG='food', CHEESE='food', POWDER_MISC='food', LIQUID_MISC='food',
79+
GLOB='food',
80+
-- weapons and defense
81+
WEAPON='weapons', TRAPCOMP='weapons',
82+
AMMO='ammo', SIEGEAMMO='ammo',
83+
ARMOR='armor', PANTS='armor', HELM='armor', GLOVES='armor',
84+
SHOES='armor', SHIELD='armor', QUIVER='armor',
85+
-- materials
86+
WOOD='wood', BOULDER='stone', ROCK='stone', ROUGH='gems', SMALLGEM='gems',
87+
BAR='bars_blocks', BLOCKS='bars_blocks',
88+
-- misc
89+
COIN='coins',
90+
-- finished goods and furniture
91+
FIGURINE='finished_goods', AMULET='finished_goods', SCEPTER='finished_goods',
92+
CROWN='finished_goods', RING='finished_goods', EARRING='finished_goods',
93+
BRACELET='finished_goods', CRAFTS='finished_goods', TOY='finished_goods',
94+
TOOL='finished_goods', GOBLET='finished_goods', FLASK='finished_goods',
95+
BOX='furniture', BARREL='furniture', BED='furniture', CHAIR='furniture',
96+
TABLE='furniture', DOOR='furniture', WINDOW='furniture', BIN='furniture',
97+
}
98+
99+
local IGNORE_TYPES = {
100+
CORPSE=true, CORPSEPIECE=true, REMAINS=true,
101+
}
102+
103+
local function get_category(item)
104+
local t = df.item_type[item:getType()]
105+
return CATEGORY_MAP[t] or 'other'
106+
end
107+
73108
local function on_unit_death(unit_id)
74109
local unit = df.unit.find(unit_id)
75110
if not unit then return end
@@ -92,10 +127,17 @@ local function on_item_created(item_id)
92127
state.last_artifact_id = rec.id
93128
end
94129
add_entry(string.format('%s: Artifact "%s" created', date, name))
95-
else
96-
local desc = dfhack.items.getDescription(item, 0, true)
97-
add_entry(string.format('%s: Item "%s" created', date, desc))
130+
return
98131
end
132+
133+
local type_name = df.item_type[item:getType()]
134+
if IGNORE_TYPES[type_name] then return end
135+
136+
local year = df.global.cur_year
137+
local category = get_category(item)
138+
state.item_counts[year] = state.item_counts[year] or {}
139+
state.item_counts[year][category] = (state.item_counts[year][category] or 0) + 1
140+
persist_state()
99141
end
100142

101143
local function on_invasion(invasion_id)
@@ -184,6 +226,23 @@ elseif cmd == 'print' then
184226
print(state.entries[i])
185227
end
186228
end
229+
elseif cmd == 'summary' then
230+
local years = {}
231+
for year in pairs(state.item_counts) do table.insert(years, year) end
232+
table.sort(years)
233+
if #years == 0 then
234+
print('No item creation records.')
235+
return
236+
end
237+
for _,year in ipairs(years) do
238+
local counts = state.item_counts[year]
239+
local parts = {}
240+
for cat,count in pairs(counts) do
241+
table.insert(parts, string.format('%d %s', count, cat))
242+
end
243+
table.sort(parts)
244+
print(string.format('Year %d: %s', year, table.concat(parts, ', ')))
245+
end
187246
else
188247
print(dfhack.script_help())
189248
end

docs/chronicle.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ chronicle
66
:tags: fort gameplay
77

88
This tool automatically records notable events in a chronicle that is stored
9-
with your save. Unit deaths, all item creation events, and invasions are
10-
recorded.
9+
with your save. Unit deaths, artifact creation events, invasions, and yearly
10+
totals of crafted items are recorded.
1111

1212
Usage
1313
-----
@@ -17,6 +17,7 @@ Usage
1717
chronicle enable
1818
chronicle disable
1919
chronicle print [count]
20+
chronicle summary
2021
chronicle clear
2122

2223
``chronicle enable``
@@ -27,5 +28,7 @@ Usage
2728
Print the most recent recorded events. Takes an optional ``count``
2829
argument (default ``25``) that specifies how many events to show. Prints
2930
a notice if the chronicle is empty.
31+
``chronicle summary``
32+
Show yearly totals of created items by category (non-artifact items only).
3033
``chronicle clear``
3134
Delete the chronicle.

0 commit comments

Comments
 (0)