Skip to content

Commit f41c576

Browse files
committed
Merge branch 'lua-dorf-buffing' into lua-dorf-buffing-rel
2 parents 7a9dbc5 + 6b34a8b commit f41c576

130 files changed

Lines changed: 2562 additions & 1432 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adaptation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def usage(s)
5757

5858
set_adaptation_value = lambda { |u,v|
5959
next if !df.unit_iscitizen(u)
60-
next if u.flags1.dead
60+
next if u.flags2.killed
6161
u.status.misc_traits.each { |t|
6262
if t.id == :CaveAdapt
6363
# TBD: expose the color_ostream console and color values of

add-recipe.lua

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
-- Script to add unknown crafting recipes to the player's civ.
2+
--[====[
3+
add-recipe
4+
==========
5+
Adds unknown weapon and armor crafting recipes to your civ.
6+
E.g. some civilizations never learn to craft high boots. This script can
7+
help with that, and more. Only weapons and armor are currently supported;
8+
things such as instruments are not. Available options:
9+
10+
* ``add-recipe all`` adds *all* available weapons and armor, including exotic items
11+
like blowguns, two-handed swords, and capes.
12+
13+
* ``add-recipe native`` adds only native (but unknown) crafting recipes. Civilizations
14+
pick randomly from a pool of possible recipes, which means not all civs get
15+
high boots, for instance. This command gives you all the recipes your
16+
civilisation could have gotten.
17+
18+
* ``add-recipe single <item token>`` adds a single item by the given
19+
item token. For example, ``add-recipe single SHOES:ITEM_SHOES_BOOTS``.
20+
]====]
21+
22+
local itemDefs = df.global.world.raws.itemdefs
23+
local resources = df.historical_entity.find(df.global.ui.civ_id).resources
24+
local civ = df.historical_entity.find(df.global.ui.civ_id).entity_raw
25+
26+
if (resources == nil) then
27+
qerror("Could not find entity resources")
28+
elseif (itemDefs == nil) then
29+
qerror("Could not find item raws!")
30+
elseif (civ == nil) then
31+
qerror("Could not find civilization type!")
32+
end
33+
34+
--array that categorises the various containers we need to access per type
35+
--each type is represented by an array with the following elements:
36+
--1: the currently known recipes to the player civ
37+
--2: the native (non-exotic) recipes to the player civ
38+
--3: all possible recipes including exotic
39+
local categories = {
40+
weapon = {resources.weapon_type, civ.equipment.weapon_id, itemDefs.weapons },
41+
shield = {resources.shield_type, civ.equipment.shield_id, itemDefs.shields },
42+
ammo = {resources.ammo_type, civ.equipment.ammo_id, itemDefs.ammo },
43+
armor = {resources.armor_type, civ.equipment.armor_id, itemDefs.armor },
44+
gloves = {resources.gloves_type, civ.equipment.gloves_id, itemDefs.gloves },
45+
shoes = {resources.shoes_type, civ.equipment.shoes_id, itemDefs.shoes },
46+
helm = {resources.helm_type, civ.equipment.helm_id, itemDefs.helms },
47+
pants = {resources.pants_type, civ.equipment.pants_id, itemDefs.pants }
48+
}
49+
50+
local diggers = resources.digger_type
51+
52+
function checkKnown(known, itemType)
53+
--checks if the item with the given subtype is already known to the civ
54+
--params:
55+
--known: the resources field for the civ
56+
--itemType: the item subtype we're checking
57+
for _, id in ipairs(known) do
58+
if id == itemType then
59+
return true
60+
end
61+
end
62+
return false
63+
end
64+
65+
function checkNative(native, itemType)
66+
--checks if the given itemtype is native to the player's civ
67+
--params:
68+
--native: the list of native item types
69+
--itemType: the item subtype we're checking
70+
for _, id in ipairs(native) do
71+
if id == itemType then
72+
return true
73+
end
74+
end
75+
return false
76+
end
77+
78+
function addItems(category, exotic)
79+
--makes all available recipes of the given category known to the player's civ
80+
--params:
81+
--category: the category of items we're adding
82+
--exotic: whether to add exotic items
83+
--returns: list of item objects that were added
84+
known = category[1]
85+
native = category[2]
86+
all = category[3]
87+
added = {}
88+
89+
for _, item in ipairs(all) do
90+
subtype = item.subtype
91+
itemOk = false
92+
93+
--check if it's a training weapon
94+
t1, t2 = pcall(function () return item.flags.TRAINING == false end)
95+
training = not(not t1 or t2)
96+
97+
--we don't want procedural items with adjectives such as "wavy spears"
98+
--(because they don't seem to be craftable even if added)
99+
--nor do we want known items or training items (because adding training
100+
--items seems to allow them to be made out of metals)
101+
if (item.adjective == "" and not training and not checkKnown(known, subtype)) then
102+
itemOk = true
103+
end
104+
105+
if (not exotic and not checkNative(native, subtype)) then
106+
itemOk = false
107+
end
108+
109+
--check that the weapon we're adding is not already known to the civ as
110+
--a digging implement so picks don't get duplicated
111+
if (checkKnown(diggers, subtype)) then
112+
itemOk = false
113+
end
114+
115+
if (itemOk) then
116+
known:insert('#', subtype)
117+
table.insert(added, item)
118+
end
119+
end
120+
121+
return added
122+
end
123+
124+
125+
function printItems(itemList)
126+
for _, v in ipairs(added) do
127+
print("Added recipe " .. v.id .. " (" .. v.name .. ")")
128+
end
129+
end
130+
131+
function addAllItems(exotic)
132+
printItems(addItems(categories.weapon, exotic))
133+
printItems(addItems(categories.shield, exotic))
134+
printItems(addItems(categories.ammo, exotic))
135+
printItems(addItems(categories.armor, exotic))
136+
printItems(addItems(categories.gloves, exotic))
137+
printItems(addItems(categories.shoes, exotic))
138+
printItems(addItems(categories.helm, exotic))
139+
printItems(addItems(categories.pants, exotic))
140+
end
141+
142+
function addSingleItem(itemstring)
143+
itemType, itemId = string.match(itemstring, "(.*):(.*)")
144+
if (itemType == nil or itemId == nil) then return end
145+
category = categories[string.lower(itemType)]
146+
if (category == nil) then return end
147+
known = category[1]
148+
all = category[3]
149+
150+
addedItem = nil
151+
--assume the user knows what they're doing, so no need for sanity checks
152+
for _, item in ipairs(all) do
153+
if (item.id == itemId) then
154+
known:insert('#', item.subtype)
155+
addedItem = item
156+
break
157+
end
158+
end
159+
160+
if (addedItem ~= nil) then
161+
print("Added recipe " .. addedItem.id .. " (" .. addedItem.name .. ")")
162+
end
163+
end
164+
165+
local args = {...}
166+
local cmd = args[1]
167+
if (cmd == "all") then
168+
addAllItems(true)
169+
elseif (cmd == "native") then
170+
addAllItems(false)
171+
elseif (cmd == "single") then
172+
addSingleItem(args[2])
173+
else
174+
print("Available options:\n"
175+
.."all: adds all supported crafting recipes.\n"
176+
.."native: adds only unknown native recipes (eg. high boots for "
177+
.."some dwarves)\n"
178+
.."single: adds a specific item by itemstring (eg. "
179+
.."SHOES:ITEM_SHOES_BOOTS)")
180+
end

add-thought.lua

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,25 @@ local utils=require('utils')
1515
function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
1616
local emotions=unit.status.current_soul.personality.emotions
1717
if not (tonumber(emotion)) then
18-
emotion=df.emotion_type[emotion]
18+
emotion=df.emotion_type[emotion] --luacheck: retype
1919
end
20-
local properThought=nil
21-
if not (tonumber(thought)) then
22-
properThought=df.unit_thought_type[tonumber(thought)]
23-
if not properThought then
24-
for k,syn in ipairs(df.global.world.raws.syndromes.all) do
25-
if syn.syn_name==thought then
26-
properThought=df.unit_thought_type['Syndrome']
27-
subthought=syn.id
28-
break
29-
end
20+
local properThought = tonumber(thought) --as:df.unit_thought_type
21+
local properSubthought = tonumber(subthought)
22+
if not properThought or not df.unit_thought_type[properThought] then
23+
for k,syn in ipairs(df.global.world.raws.syndromes.all) do
24+
if syn.syn_name==thought then
25+
properThought = df.unit_thought_type.Syndrome
26+
properSubthought = syn.id
27+
break
3028
end
3129
end
3230
end
3331
emotions:insert('#',{new=df.unit_personality.T_emotions,
3432
type=tonumber(emotion),
3533
unk2=1,
3634
strength=tonumber(strength),
37-
thought=tonumber(thought),
38-
subthought=tonumber(subthought),
35+
thought=properThought,
36+
subthought=properSubthought,
3937
severity=tonumber(severity),
4038
unk7=0,
4139
year=df.global.cur_year,
@@ -47,7 +45,7 @@ function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
4745
end
4846
end
4947

50-
validArgs = validArgs or utils.invert({
48+
local validArgs = utils.invert({
5149
'unit',
5250
'thought',
5351
'emotion',
@@ -58,7 +56,7 @@ validArgs = validArgs or utils.invert({
5856
})
5957

6058
function tablify(iterableObject)
61-
t={}
59+
local t={}
6260
for k,v in ipairs(iterableObject) do
6361
t[k] = v~=nil and v or 'nil'
6462
end

adv-max-skills.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if dfhack.gui.getCurFocus() ~= 'setupadventure' then
1111
qerror('Must be called on adventure mode setup screen')
1212
end
1313

14-
adv = dfhack.gui.getCurViewscreen().adventurer
14+
local adv = dfhack.gui.getCurViewscreen().adventurer --hint:df.viewscreen_setupadventurest
1515
for k in pairs(adv.skills) do
1616
adv.skills[k] = df.skill_rating.Legendary5
1717
end

adv-rumors.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ adv-rumors
66
==========
77
Improves the "Bring up specific incident or rumor" menu in Adventure mode.
88
9+
- Moves entries into one line
10+
- Adds a "slew" keyword for filtering, making it easy to find your kills and not your companions'
11+
- Trims repetitive words
12+
913
]====]
1014

1115
--========================
1216
-- Author : 1337G4mer on bay12 and reddit
1317
-- Version : 0.2
1418
-- Description : A small utility based on dfhack to improve the rumor UI in adventure mode.
1519
--
16-
-- Usage: Save this code as rumors.lua file in your /hack/scripts/ folder
1720
-- In game when you want to boast about your kill to someone. Start conversation and choose
1821
-- the menu "Bring up specific incident or rumor"
1922
-- type rumors in dfhack window and hit enter. Or do the below keybind and use that directly from DF window.
20-
-- Optional One time setup : run below command at dfhack command prompt once to setup easy keybind for this
21-
-- keybinding add Ctrl-A@dungeonmode/ConversationSpeak rumors
2223
--
2324
-- Prior Configuration: (you can skip this if you want)
2425
-- Set the three boolean values below and play around with the script as to how you like
@@ -27,9 +28,9 @@ Improves the "Bring up specific incident or rumor" menu in Adventure mode.
2728
-- shortenString = will further shorten the line to = slew "XYZ" ( "n time" ago in " Region")
2829
--=======================
2930

30-
utils = require "utils"
31+
local utils = require "utils"
3132

32-
names_blacklist = utils.invert{"a", "an", "you", "attacked", "slew", "was", "slain", "by"}
33+
local names_blacklist = utils.invert{"a", "an", "you", "attacked", "slew", "was", "slain", "by"}
3334

3435
function condenseChoiceTitle(choice)
3536
while #choice.title > 1 do
@@ -45,10 +46,10 @@ function addKeyword(choice, keyword)
4546
end
4647

4748
function rumorUpdate()
48-
improveReadability = true
49-
addKeywordSlew = true
50-
shortenString = true
51-
addKeywordNames = true
49+
local improveReadability = true
50+
local addKeywordSlew = true
51+
local shortenString = true
52+
local addKeywordNames = true
5253

5354
for i, choice in ipairs(df.global.ui_advmode.conversation.choices) do
5455
if choice.choice.type == df.talk_choice_type.SummarizeConflict then

armoks-blessing.lua

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Without arguments, all attributes, age & personalities are adjusted.
1313
Arguments allow for skills to be adjusted as well.
1414
1515
]====]
16+
local utils = require 'utils'
1617
function rejuvenate(unit)
1718
if unit==nil then
1819
print ("No unit available! Aborting with extreme prejudice.")
@@ -51,18 +52,14 @@ function elevate_attributes(unit)
5152
return
5253
end
5354

54-
local ok,f,t,k = pcall(pairs,unit.status.current_soul.mental_attrs)
55-
if ok then
56-
for k,v in f,t,k do
55+
if unit.status.current_soul then
56+
for k,v in pairs(unit.status.current_soul.mental_attrs) do
5757
v.value=v.max_value
5858
end
5959
end
6060

61-
local ok,f,t,k = pcall(pairs,unit.body.physical_attrs)
62-
if ok then
63-
for k,v in f,t,k do
64-
v.value=v.max_value
65-
end
61+
for k,v in pairs(unit.body.physical_attrs) do
62+
v.value=v.max_value
6663
end
6764
end
6865
-- ---------------------------------------------------------------------------
@@ -95,7 +92,6 @@ function make_legendary(skillname,unit)
9592
end
9693

9794
if skillnamenoun ~= nil then
98-
utils = require 'utils'
9995
skillnum = df.job_skill[skillname]
10096
utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = skillnum, rating = 20 }, 'id')
10197
print (unit.name.first_name.." is now a Legendary "..skillnamenoun)
@@ -114,21 +110,19 @@ function BreathOfArmok(unit)
114110
local i
115111

116112
local count_max = count_this(df.job_skill)
117-
utils = require 'utils'
118113
for i=0, count_max do
119114
utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id')
120115
end
121116
print ("The breath of Armok has engulfed "..unit.name.first_name)
122117
end
123118
-- ---------------------------------------------------------------------------
124119
function LegendaryByClass(skilltype,v)
125-
unit=v
120+
local unit=v
126121
if unit==nil then
127122
print ("No unit available! Aborting with extreme prejudice.")
128123
return
129124
end
130125

131-
utils = require 'utils'
132126
local i
133127
local skillclass
134128
local count_max = count_this(df.job_skill)
@@ -182,7 +176,8 @@ end
182176
-- ---------------------------------------------------------------------------
183177
-- main script operation starts here
184178
-- ---------------------------------------------------------------------------
185-
local opt = ...
179+
local args = {...}
180+
local opt = args[1]
186181
local skillname
187182

188183
if opt then

autounsuspend.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def process
1818
count = 0
1919
df.world.jobs.list.each { |job|
2020
if job.job_type == :ConstructBuilding and job.flags.suspend and df.map_tile_at(job).designation.flow_size <= 1
21+
# skip planned buildings
22+
next if job.job_items.length == 1 and job.job_items[0].item_type == :NONE
2123
job.flags.suspend = false
2224
count += 1
2325
end

0 commit comments

Comments
 (0)