-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpref-adjust.lua
More file actions
362 lines (341 loc) · 16.7 KB
/
pref-adjust.lua
File metadata and controls
362 lines (341 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
-- Adjust all preferences of one or all dwarves in play
-- by vjek
--[====[
pref-adjust
===========
``pref-adjust all`` removes/changes preferences from all dwarves, and
``pref-adjust one`` which works for a single currently selected dwarf.
For either, the script inserts an 'ideal' set which is easy to satisfy::
... likes iron, steel, weapons, armor, shields/bucklers and plump helmets
for their rounded tops. When possible, she prefers to consume dwarven
wine, plump helmets, and prepared meals (quarry bush). She absolutely
detests trolls, buzzards, vultures and crundles.
Additionally, ``pref-adjust goth`` will insert a less than ideal set, which
is quite challenging, for a single dwarf::
... likes dwarf skin, corpses, body parts, remains, coffins, the color
black, crosses, glumprongs for their living shadows and snow demons for
their horrifying features. When possible, she prefers to consume sewer
brew, gutter cruor and bloated tubers. She absolutely detests elves,
humans and dwarves.
To see what values can be used with each type of preference, use
``pref-adjust list``. Optionally, a single dwarf or all dwarves can have
their preferences cleared manually with the use of ``pref-adjust clear_one``
and ``pref-adjust clear_all``, respectively. Existing preferences are
automatically cleared, normally.
]====]
-- ---------------------------------------------------------------------------
function insert_preference(unit,mytype,val1)
if mytype == df.unit_preference.T_type.LikeMaterial then
unit.status.current_soul.preferences:insert("#",{new = true, type = 0 , item_type = -1 , poetic_form_id = -1, musical_form_id = -1, dance_form_id = -1, mattype = dfhack.matinfo.find(val1).type , mat_state = 0, matindex = dfhack.matinfo.find(val1).index , active = true})
-- mattype for some is non zero, those non-inorganic like creature:gazelle:hoof is 42,344
end
if mytype == df.unit_preference.T_type.LikeFood then
consumable_type=val1[1]
consumable_name=val1[2]
unit.status.current_soul.preferences:insert("#",{new = true, type = 2 , item_type = consumable_type , poetic_form_id = consumable_type, musical_form_id = df.consumable_type, dance_form_id = consumable_type, item_subtype = dfhack.matinfo.find(consumable_name).subtype , mattype = dfhack.matinfo.find(consumable_name).type , mat_state = 0, matindex = dfhack.matinfo.find(consumable_name).index , active = true})
end
if mytype == df.unit_preference.T_type.LikeCreature or (mytype >= df.unit_preference.T_type.HateCreature and mytype <= df.unit_preference.T_type.LikeDanceForm) then
unit.status.current_soul.preferences:insert("#",{new = true, type = mytype , item_type = val1 , creature_id = val1 , color_id = val1 , shape_id = val1 , plant_id = val1 , poetic_form_id = val1, musical_form_id = val1, dance_form_id = val1, item_subtype = -1 , mattype = -1 , mat_state = 0, matindex = -1 , active = true})
end
end
-- ---------------------------------------------------------------------------
function brainwash_unit(unit,profile)
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
end
if profile == "IDEAL" then
-- Type 0: Material Likes: IRON(0),STEEL(8),ADAMANTINE(25)
insert_preference(unit,df.unit_preference.T_type.LikeMaterial,"IRON")
insert_preference(unit,df.unit_preference.T_type.LikeMaterial,"STEEL")
-- insert_preference(unit,df.unit_preference.T_type.LikeMaterial,"ADAMANTINE")
-- Type 4: Item likes: (WEAPON, ARMOR, SHIELD)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.WEAPON)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.ARMOR)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.SHIELD)
-- Type 5: Plant Likes: "Likes plump helmets for their rounded tops"
insert_preference(unit,df.unit_preference.T_type.LikePlant,dfhack.matinfo.find("MUSHROOM_HELMET_PLUMP:STRUCTURAL").index)
-- insert_preference(unit,df.unit_preference.T_type.LikePlant,dfhack.matinfo.find("PEACH").index)
-- Type 2: Prefers to consume drink: (From plump helmets we get dwarven wine)
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.DRINK,"MUSHROOM_HELMET_PLUMP:DRINK"})
-- Type 2: Prefers to consume food: (plump helmets, mushrooms)
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.PLANT,"MUSHROOM_HELMET_PLUMP:MUSHROOM"})
-- Type 2: Prefers to consume prepared meals: (quarry bush)
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.FOOD,"BUSH_QUARRY"})
-- Type 3: Creature detests (TROLL, BIRD_BUZZARD, BIRD_VULTURE, CRUNDLE)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.TROLL)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.BIRD_BUZZARD)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.BIRD_VULTURE)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.CRUNDLE)
if #df.global.world.poetic_forms.all then
most_recent_poem = 0
vec=df.global.world.poetic_forms.all
for k=0,#vec-1 do
-- print("poem:"..dfhack.TranslateName(vec[k].name,true).." unit.civ_id:"..unit.civ_id.." orig_ent:"..vec[k].originating_entity)
if unit.civ_id == vec[k].originating_entity then
-- print("poem:"..dfhack.TranslateName(vec[k].name,true))
most_recent_poem = vec[k].id
end
end
insert_preference(unit,df.unit_preference.T_type.LikePoeticForm,most_recent_poem) -- this just inserts the last song out of typically many.
end
if #df.global.world.musical_forms.all then
most_recent_music = 0
vec=df.global.world.musical_forms.all
for k=0,#vec-1 do
if unit.civ_id == vec[k].originating_entity then
most_recent_music = vec[k].id
end
end
insert_preference(unit,df.unit_preference.T_type.LikeMusicalForm,most_recent_music) -- this just inserts the last song out of typically many.
end
if #df.global.world.dance_forms.all then
most_recent_dance = 0
vec=df.global.world.dance_forms.all
for k=0,#vec-1 do
if unit.civ_id == vec[k].originating_entity then
most_recent_dance = vec[k].id
end
end
insert_preference(unit,df.unit_preference.T_type.LikeDanceForm,most_recent_dance) -- this just inserts the last song out of typically many.
end
end -- end IDEAL profile
if profile == "GOTH" then
insert_preference(unit,df.unit_preference.T_type.LikeMaterial,"CREATURE:DWARF:SKIN")
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.CORPSE)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.CORPSEPIECE)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.REMAINS)
insert_preference(unit,df.unit_preference.T_type.LikeItem,df.item_type.COFFIN)
insert_preference(unit,df.unit_preference.T_type.LikeColor,list_of_colors.BLACK)
insert_preference(unit,df.unit_preference.T_type.LikeShape,list_of_shapes.CROSS)
insert_preference(unit,df.unit_preference.T_type.LikePlant,dfhack.matinfo.find("GLUMPRONG").index)
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.DRINK,"WEED_RAT:DRINK"})
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.DRINK,"SLIVER_BARB:DRINK"})
insert_preference(unit,df.unit_preference.T_type.LikeFood,{df.item_type.PLANT,"TUBER_BLOATED:STRUCTURAL"})
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.ELF)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.HUMAN)
insert_preference(unit,df.unit_preference.T_type.HateCreature,list_of_creatures.DWARF)
if list_of_creatures.DEMON_1 and df.global.world.raws.creatures.all[list_of_creatures.DEMON_1].prefstring[0] then
insert_preference(unit,df.unit_preference.T_type.LikeCreature,list_of_creatures.DEMON_1)
end
if #df.global.world.poetic_forms.all then
insert_preference(unit,df.unit_preference.T_type.LikePoeticForm,df.global.world.poetic_forms.all[#df.global.world.poetic_forms.all-1].id) -- this just inserts the last song out of typically many.
end
if #df.global.world.musical_forms.all then
insert_preference(unit,df.unit_preference.T_type.LikeMusicalForm,df.global.world.musical_forms.all[#df.global.world.musical_forms.all-1].id) -- same goes for music
end
if #df.global.world.dance_forms.all then
insert_preference(unit,df.unit_preference.T_type.LikeDanceForm,df.global.world.dance_forms.all[#df.global.world.dance_forms.all-1].id) -- and dancing
end
end -- end GOTH profile
prefcount = #(unit.status.current_soul.preferences)
print ("After adjusting, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")
end -- end of function brainwash_unit
-- ---------------------------------------------------------------------------
function clear_preferences(unit)
unit.status.current_soul.preferences:resize(0)
end
-- ---------------------------------------------------------------------------
function clearpref_all_dwarves()
for _,v in ipairs(df.global.world.units.active) do
if v.race == df.global.ui.race_id and v.status.current_soul then
print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v)))
clear_preferences(v)
end
end
end
-- ---------------------------------------------------------------------------
function adjust_all_dwarves(profile)
for _,v in ipairs(df.global.world.units.active) do
if v.race == df.global.ui.race_id and v.status.current_soul then
print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(v)))
brainwash_unit(v,profile)
end
end
end
-- ---------------------------------------------------------------------------
function build_all_lists(printflag)
list_of_inorganics={} -- Type 0 "Likes iron.."
list_of_inorganics_string=""
vec=df.global.world.raws.inorganics -- also df.global.world.raws.inorganics_subset[0].id available
for k=0,#vec-1 do
name=vec[k].id
list_of_inorganics[name]=k
list_of_inorganics_string=list_of_inorganics_string..name..","
end
if printflag==1 then
print("\nTYPE 0 INORGANICS: "..list_of_inorganics_string) -- printall(list_of_inorganics)
end
-- ------------------------------------
list_of_creatures={} --dict[name]=number, Type 1/3 "Likes them for.." / "Detests .."
vec=df.global.world.raws.creatures.all
list_of_creatures_string=""
for k=0,#vec-1 do
name=vec[k].creature_id
list_of_creatures[name]=k
list_of_creatures_string=list_of_creatures_string..name..","
end
if printflag==1 then
print("\nTYPE 1,3 CREATURES: "..list_of_creatures_string) -- printall(list_of_creatures)
end
-- ------------------------------------
list_of_plants={} -- Type 2 "Prefers to consume.." and Type 5 "Likes Plump Helmets for their rounded tops"
-- (TODO could have edible only, and/or a different list for each-all edible meat/plants/drinks)
list_of_plants_string=""
vec=df.global.world.raws.plants.all
for k=0,#vec-1 do
name=vec[k].id
list_of_plants[name]=k
list_of_plants_string=list_of_plants_string..name..","
end
if printflag==1 then
print("\nTYPE 2,5 PLANTS: "..list_of_plants_string) -- printall(list_of_plants)
end
-- ------------------------------------
list_of_items={} -- Type 4 "Likes armor.." (TODO need recursive material decode lists?)
list_of_items_string=""
-- [lua]# @dfhack.matinfo.decode(31,1)
-- <material 31:1 CREATURE:TOAD_MAN:GUT>
-- [lua]# @dfhack.matinfo.decode(0,1)
-- <material 0:1 INORGANIC:GOLD>
for k,v in ipairs(df.item_type) do
list_of_items[v]=k
list_of_items_string=list_of_items_string..v..","
end
if printflag==1 then
print("\nTYPE 4 ITEMS: "..list_of_items_string) -- printall(list_of_items)
end
-- ------------------------------------
list_of_colors={} -- Type 7 "Likes the color.."
list_of_colors_string = ""
vec=df.global.world.raws.descriptors.colors
for k=0,#vec-1 do
name=vec[k].id
list_of_colors[name]=k
list_of_colors_string=list_of_colors_string..name..","
end
if printflag==1 then
print("\nTYPE 7 COLORS: "..list_of_colors_string) -- printall(list_of_colors)
end
-- ------------------------------------
list_of_shapes={} -- Type 8 "Likes circles"
list_of_shapes_string = ""
vec=df.global.world.raws.descriptors.shapes
for k=0,#vec-1 do
name=vec[k].id
list_of_shapes[name]=k
list_of_shapes_string=list_of_shapes_string..name..","
end
if printflag==1 then
print("\nTYPE 8 SHAPES: "..list_of_shapes_string) -- printall(list_of_shapes)
end
-- ------------------------------------
list_of_poems={} -- Type 9 "likes the words of.."
list_of_poems_string = ""
vec=df.global.world.poetic_forms.all
for k=0,#vec-1 do
orig_ent=vec[k].originating_entity
name=dfhack.TranslateName(vec[k].name,true)
list_of_poems[name]=k
list_of_poems_string=list_of_poems_string..k..":"..name.."|"..orig_ent..","
end
if printflag==1 then
print("\nTYPE 9 POEMS: "..list_of_poems_string) -- printall(list_of_poems)
end
-- ------------------------------------
list_of_music={} -- Type 10 "Likes the sound of.."
list_of_music_string = ""
vec=df.global.world.musical_forms.all
for k=0,#vec-1 do
name=dfhack.TranslateName(vec[k].name,true)
list_of_music[name]=k
list_of_music_string=list_of_music_string..k..":"..name..","
end
if printflag==1 then
print("\nTYPE 10 MUSIC: "..list_of_music_string) -- printall(list_of_music)
end
-- ------------------------------------
list_of_dances={} -- Type 11
list_of_dances_string = ""
vec=df.global.world.dance_forms.all
for k=0,#vec-1 do
name=dfhack.TranslateName(vec[k].name,true)
list_of_dances[name]=k
list_of_dances_string=list_of_dances_string..k..":"..name..","
end
if printflag==1 then
print("\nTYPE 11 DANCES: "..list_of_dances_string) -- printall(list_of_dances)
end
end -- end func build_all_lists
-- ---------------------------------------------------------------------------
-- main script operation starts here
-- ---------------------------------------------------------------------------
printflag=0
build_all_lists(printflag)
local opt = ...
if opt and opt ~= "help" then
if opt=="list" then
printflag=1
build_all_lists(printflag)
return
end
if opt=="clear_one" then
local unit = dfhack.gui.getSelectedUnit()
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
end
clear_preferences(unit)
prefcount = #(unit.status.current_soul.preferences)
print ("After clearing, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")
return
end
if opt=="clear_all" then
clearpref_all_dwarves()
return
end
if opt=="goth" then
local profile="GOTH"
local unit = dfhack.gui.getSelectedUnit()
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
end
clear_preferences(unit)
brainwash_unit(unit,profile)
return
end
if opt=="one" then
local profile="IDEAL"
local unit = dfhack.gui.getSelectedUnit()
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
end
clear_preferences(unit)
brainwash_unit(unit,profile)
return
end
if opt=="all" then
local profile="IDEAL"
clearpref_all_dwarves()
adjust_all_dwarves(profile)
return
end
if opt=="goth_all" then
local profile="GOTH"
clearpref_all_dwarves()
adjust_all_dwarves(profile)
return
end
else
print ("Sets preferences of one dwarf, or of all dwarves, using profiles.")
print ("Valid options:")
print ("list -- show available preference type lists")
print ("clear_one -- clear preferences of selected unit")
print ("clear_all -- clear preferences of all units")
print ("goth -- alter current dwarf preferences to Goth")
print ("goth_all -- alter all dwarf preferences to Goth")
print ("one -- alter current dwarf preferences to Ideal")
print ("all -- alter all dwarf preferences to Ideal")
end