Skip to content

Commit 028cead

Browse files
authored
Merge branch 'master' into create-unit
2 parents 89ddb81 + 7099794 commit 028cead

112 files changed

Lines changed: 1131 additions & 1132 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.

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 = utils.invert({
48+
local validArgs = utils.invert({
5149
'unit',
5250
'thought',
5351
'emotion',
@@ -58,7 +56,7 @@ validArgs = 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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Improves the "Bring up specific incident or rumor" menu in Adventure mode.
2828
-- shortenString = will further shorten the line to = slew "XYZ" ( "n time" ago in " Region")
2929
--=======================
3030

31-
utils = require "utils"
31+
local utils = require "utils"
3232

33-
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"}
3434

3535
function condenseChoiceTitle(choice)
3636
while #choice.title > 1 do
@@ -46,10 +46,10 @@ function addKeyword(choice, keyword)
4646
end
4747

4848
function rumorUpdate()
49-
improveReadability = true
50-
addKeywordSlew = true
51-
shortenString = true
52-
addKeywordNames = true
49+
local improveReadability = true
50+
local addKeywordSlew = true
51+
local shortenString = true
52+
local addKeywordNames = true
5353

5454
for i, choice in ipairs(df.global.ui_advmode.conversation.choices) do
5555
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

ban-cooking.rb

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# Just create a shorthand reference to the kitchen object
1717
kitchen = df.ui.kitchen
1818

19-
# Store our list of banned items in the dictionary/hash table, along with their index number
20-
# -- index number storage was added from the original script so as to assist in addressing
21-
# the specific kitchen array entry directly later in the script, rather than search through it again.
19+
# Store our list of banned items in the dictionary/hash table
2220
kitchen.item_types.length.times { |i|
23-
already_banned[[kitchen.mat_types[i], kitchen.mat_indices[i], kitchen.item_types[i], kitchen.item_subtypes[i]]] = [ kitchen.exc_types[i] & 1, i ]
21+
if kitchen.exc_types[i] == :Cook
22+
already_banned[[kitchen.mat_types[i], kitchen.mat_indices[i], kitchen.item_types[i], kitchen.item_subtypes[i]]] = true
23+
end
2424
}
2525

2626
# The function for actually banning cooking of an item.
@@ -35,20 +35,6 @@
3535
key = [mat_type, mat_index, type, subtype]
3636
# Skip adding a new entry further below, if the item is already banned.
3737
if already_banned[key]
38-
# Get our stored index kitchen arrays' index value
39-
index = already_banned[key][1]
40-
# Check that the banned flag is set.
41-
return if already_banned[key][0] == 1
42-
# Added a check here to ensure that the exc_types array entry had something at the index entry
43-
# as the original script didn't check for :EDIBLE_COOKED before banning certain plants, so that
44-
# lead to mismatched array lengths, and a crash possibly due to memory corruption.
45-
if kitchen.exc_types[index]
46-
# Or's the value of the exc_type to turn the first bit of the byte on.
47-
puts(print_name + ' has been banned!')
48-
kitchen.exc_types[index] |= 1
49-
end
50-
# Record in the dictionary/hash table that the item is now cooking banned.
51-
already_banned[key][0] = 1
5238
return
5339
end
5440
# The item hasn't already been banned, so we do that here by appending its values to the various arrays
@@ -59,8 +45,8 @@
5945
df.ui.kitchen.mat_indices << mat_index
6046
df.ui.kitchen.item_types << type
6147
df.ui.kitchen.item_subtypes << subtype
62-
df.ui.kitchen.exc_types << 1
63-
already_banned[key] = [ 1, length ]
48+
df.ui.kitchen.exc_types << :Cook
49+
already_banned[key] = true
6450
}
6551

6652
$script_args.each do |arg|
@@ -354,51 +340,8 @@
354340
# There's no entry for this item in our calculated list of cookable items. So, it's not a plant, alcohol, tallow, or milk. It's likely that it's a meat that has been banned.
355341
output += '|"' + key.inspect + ' unknown banned material type (meat?) " ' + '|item type: "' + b[0][2].inspect + '"|item subtype: "' + b[0][3].inspect
356342
end
357-
output += '|exc type: "' + kitchen.exc_types[b[1][1]].inspect + '"'
358343
puts output
359344
end
360-
361-
# prints out the data structures for several different plants and one animal so that their data structure can be examined/understood
362-
when 'potato'
363-
df.world.raws.plants.all.each_with_index do |p, i|
364-
if p.name.include?('potato')
365-
puts(p.inspect)
366-
end
367-
end
368-
369-
when 'pig'
370-
df.world.raws.plants.all.each_with_index do |p, i|
371-
if p.name.include?('pig tail')
372-
puts(p.inspect)
373-
end
374-
end
375-
376-
when 'cherry'
377-
df.world.raws.plants.all.each_with_index do |p, i|
378-
if p.name.include?('cherry')
379-
puts(p.inspect)
380-
end
381-
end
382-
383-
# an example of both milling and thread in one plant
384-
when 'hemp'
385-
df.world.raws.plants.all.each_with_index do |p, i|
386-
if p.name.include?('hemp')
387-
puts(p.inspect)
388-
end
389-
end
390-
391-
when 'cow'
392-
df.world.raws.creatures.all.each_with_index do |c, i|
393-
# can't just do "cow", as that would print reindeer cow, yak cow, and cow
394-
if c.name.include?('yak')
395-
# c.inspect truncates output too early to get to the materials we want to view
396-
c.material.each_with_index do |m, j|
397-
puts(m.inspect)
398-
end
399-
end
400-
end
401-
402345
else
403346
puts "ban-cooking booze - bans cooking of drinks"
404347
puts "ban-cooking honey - bans cooking of honey bee honey"

bodyswap.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
--@ module = true
77

88
local utils = require 'utils'
9-
validArgs = utils.invert({
9+
local validArgs = utils.invert({
1010
'unit',
1111
'help'
1212
})
@@ -94,15 +94,15 @@ function swapAdvUnit(newUnit)
9494
if activeUnits[0] == oldUnit then
9595
oldUnitIndex = 0
9696
else -- unlikely; this is just in case
97-
for i,u in pairs(activeUnits) do
97+
for i,u in ipairs(activeUnits) do
9898
if u == oldUnit then
9999
oldUnitIndex = i
100100
break
101101
end
102102
end
103103
end
104104
local newUnitIndex
105-
for i,u in pairs(activeUnits) do
105+
for i,u in ipairs(activeUnits) do
106106
if u == newUnit then
107107
newUnitIndex = i
108108
break

brainwash.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Usage: ``brainwash <type>``, with one of the following types:
2121
function brainwash_unit(profile)
2222
local i,unit_name
2323

24-
unit=dfhack.gui.getSelectedUnit()
24+
local unit=dfhack.gui.getSelectedUnit()
2525
if unit==nil then
2626
print ("No unit under cursor! Aborting.")
2727
return

burial.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ of pets.
1111

1212
local utils=require('utils')
1313

14-
validArgs = utils.invert({
14+
local validArgs = utils.invert({
1515
'pets'
1616
})
1717

1818
local args = utils.processArgs({...}, validArgs)
1919

20-
for k,v in ipairs(df.global.world.buildings.other.COFFIN) do
20+
for k,v in ipairs(df.global.world.buildings.other.COFFIN) do --as:df.building_coffinst
2121
if v.owner_id==-1 then
2222
v.burial_mode.allow_burial=true
2323
if not args.pets then

cannibalism.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ end
1616

1717
local scrn = dfhack.gui.getCurViewscreen()
1818
if df.viewscreen_itemst:is_instance(scrn) then
19-
scrn.item.flags.dead_dwarf = false
19+
scrn.item.flags.dead_dwarf = false --hint:df.viewscreen_itemst
2020
elseif df.viewscreen_dungeon_monsterstatusst:is_instance(scrn) then
21-
unmark_inventory(scrn.inventory)
21+
unmark_inventory(scrn.inventory) --hint:df.viewscreen_dungeon_monsterstatusst
2222
elseif df.global.ui_advmode.menu == df.ui_advmode_menu.Inventory then
2323
unmark_inventory(df.global.world.units.active[0].inventory)
2424
else

0 commit comments

Comments
 (0)