@@ -12,6 +12,7 @@ local function get_default_state()
12
12
entries = {},
13
13
last_artifact_id = - 1 ,
14
14
known_invasions = {},
15
+ item_counts = {}, -- item creation summary per year
15
16
}
16
17
end
17
18
@@ -70,6 +71,40 @@ local function add_entry(text)
70
71
persist_state ()
71
72
end
72
73
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
+
73
108
local function on_unit_death (unit_id )
74
109
local unit = df .unit .find (unit_id )
75
110
if not unit then return end
@@ -92,10 +127,17 @@ local function on_item_created(item_id)
92
127
state .last_artifact_id = rec .id
93
128
end
94
129
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
98
131
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 ()
99
141
end
100
142
101
143
local function on_invasion (invasion_id )
@@ -184,6 +226,23 @@ elseif cmd == 'print' then
184
226
print (state .entries [i ])
185
227
end
186
228
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
187
246
else
188
247
print (dfhack .script_help ())
189
248
end
0 commit comments