Skip to content

Commit 1d1c4fb

Browse files
committed
More fixes for df-luacheck. Mostly annotations, but there are a few typos fixed as well.
1 parent 69500d4 commit 1d1c4fb

18 files changed

Lines changed: 88 additions & 86 deletions

add-thought.lua

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@ function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
1717
if not (tonumber(emotion)) then
1818
emotion=df.emotion_type[emotion]
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

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

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

catsplosion.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Animals will give birth within two in-game hours (100 ticks or fewer).
1616
1717
]====]
1818

19-
world = df.global.world
19+
local world = df.global.world
2020

2121
if not dfhack.isWorldLoaded() then
2222
qerror('World not loaded.')
2323
end
2424

25-
args = {...}
26-
list_only = false
27-
creatures = {}
25+
local args = {...}
26+
local list_only = false
27+
local creatures = {}
2828

2929
if #args > 0 then
3030
for _, arg in pairs(args) do
@@ -38,12 +38,12 @@ else
3838
creatures.CAT = true
3939
end
4040

41-
total = 0
42-
total_changed = 0
43-
total_created = 0
41+
local total = 0
42+
local total_changed = 0
43+
local total_created = 0
4444

45-
males = {}
46-
females = {}
45+
local males = {} --as:df.unit[][]
46+
local females = {} --as:df.unit[][]
4747

4848
for _, unit in pairs(world.units.all) do
4949
local id = world.raws.creatures.all[unit.race].creature_id
@@ -55,7 +55,7 @@ end
5555
if list_only then
5656
print("Type Male # Female #")
5757
-- sort IDs alphabetically
58-
local ids = {}
58+
local ids = {} --as:string[]
5959
for id in pairs(males) do
6060
table.insert(ids, id)
6161
end

combine-drinks.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Merge stacks of drinks in the selected stockpile.
88
]====]
99
local utils = require 'utils'
1010

11-
validArgs = utils.invert({ 'max', 'stockpile' })
11+
local validArgs = utils.invert({ 'max', 'stockpile' })
1212
local args = utils.processArgs({...}, validArgs)
1313

1414
local max = 30;
@@ -30,7 +30,7 @@ local function getDrinks(items, drinks, index)
3030
-- Skip items currently tasked
3131
if #d.specific_refs == 0 then
3232

33-
if d:getType() == 68 then
33+
if d:getType() == df.item_type.DRINK then
3434
foundDrink = d
3535
else
3636
--print(d.id)
@@ -39,7 +39,7 @@ local function getDrinks(items, drinks, index)
3939
if #containedItems == 1 then
4040
local possibleDrink = containedItems[1]
4141

42-
if #possibleDrink.specific_refs == 0 and possibleDrink:getType() == 68 then
42+
if #possibleDrink.specific_refs == 0 and possibleDrink:getType() == df.item_type.DRINK then
4343
foundDrink = possibleDrink
4444
end
4545
end
@@ -68,14 +68,14 @@ else
6868
error("Select a non-empty stockpile")
6969

7070
else
71-
local drinks = { }
71+
local drinks = { } --as:df.item_drinkst[]
7272
local drinkCount = getDrinks(rootItems, drinks, 0)
7373

7474
--for i,p in ipairs(drinks) do
7575
-- print(i .. ': ' .. dfhack.items.getDescription(p, p:getType()))
7676
--end
7777

78-
local removedDrinks = { }
78+
local removedDrinks = {} --as:bool[]
7979

8080
for i=0,(drinkCount-2) do
8181
local currentDrink = drinks[i]

devel/inspect-screen.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function InspectScreen:onRenderBody(dc)
5050
local info = self.cursor_pen
5151
dc:string('CH: '):char(info.ch, FG_PEN):char(info.ch, BG_PEN):string(' '):string(''..info.ch,TXT_PEN):newline()
5252
local fgcolor = info.fg
53-
local fgstr = info.fg
53+
local fgstr = tostring(info.fg)
5454
if info.bold then
5555
fgcolor = (fgcolor+8)%16
5656
fgstr = fgstr..'+8'

devel/light.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function getCursorPos()
3333
return copyall(g_cursor)
3434
end
3535
end
36+
--luacheck: skip
3637
function falloff(color,sqDist,maxdist)
3738
local v1=1/(sqDist/maxdist+1)
3839
local v2=v1-1/(1+maxdist*maxdist)
@@ -44,15 +45,16 @@ return {r=math.max(c1.r,c2.r),
4445
g=math.max(c1.g,c2.g),
4546
b=math.max(c1.b,c2.b)}
4647
end
48+
--luacheck: defclass={precalc:'{r:number,g:number,b:number}[]',lightMap:'{r:number,g:number,b:number}[]',fovs:'{_type:table,pos:{x:number,y:number},radius:number,color:{r:number,g:number,b:number}}[]'}
4749
LightOverlay=defclass(LightOverlay,guidm.DwarfOverlay)
4850
LightOverlay.ATTRS {
49-
lightMap={},
5051
dynamic=true,
5152
dirty=false,
5253
}
5354
function LightOverlay:init(args)
54-
55-
self.tick=df.global.cur_year_tick_advmode
55+
self.precalc = {}
56+
self.lightMap = {}
57+
self.tick = df.global.cur_year_tick_advmode
5658
end
5759

5860
function lightPassable(shape)
@@ -174,6 +176,7 @@ function LightOverlay:placeLightFov(pos,radius,color)
174176
self.lightMap[tile]=ncol
175177
table.insert(self.fovs,{pos=pos,radius=radius,color=color})
176178
end
179+
--luacheck: skip
177180
function LightOverlay:placeLightFov2(pos,radius,color,f,rays)
178181
f=f or falloff
179182
local raycount=rays or 25
@@ -213,6 +216,7 @@ function LightOverlay:placeLightFov2(pos,radius,color,f,rays)
213216
end
214217
end
215218
end
219+
--luacheck: skip
216220
function LightOverlay:placeLight(pos,radius,color,f)
217221
f=f or falloff
218222
local vp=self:getViewport()

devel/modstate-monitor.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Display changes in key modifier state, ie Ctrl/Alt/Shift.
1313

1414
VERSION = '0.1'
1515

16-
if active == nil then active = false end
16+
active = active or false
1717

1818
if dfhack.internal.getModstate == nil or dfhack.internal.getModifiers == nil then
1919
qerror('Required internal functions are missing')
@@ -31,6 +31,7 @@ function set_timeout()
3131
dfhack.timeout(1, 'frames', check)
3232
end
3333

34+
last_msg = last_msg or nil --as:string
3435
function log(s, color)
3536
-- prevent duplicate output
3637
if s ~= last_msg then
@@ -40,6 +41,7 @@ function log(s, color)
4041
end
4142
end
4243

44+
last_modstate = last_modstate or nil --as:number
4345
function check()
4446
local msg = ''
4547
local modstate = dfhack.internal.getModstate()
@@ -53,7 +55,7 @@ function check()
5355
if active then set_timeout() end
5456
end
5557

56-
args = {...}
58+
local args = {...}
5759
if dfhack_flags and dfhack_flags.enable then
5860
table.insert(args, dfhack_flags.enable_state and 'enable' or 'disable')
5961
end

devel/save-version.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function has_field(tbl, field)
1414
return (pcall(function() assert(tbl[field] ~= nil) end))
1515
end
1616

17+
--luacheck: global
1718
versions = {
1819
-- skipped v0.21-v0.28
1920
[1287] = "0.31.01",
@@ -103,7 +104,9 @@ versions = {
103104
[1620] = "0.44.10",
104105
}
105106

107+
--luacheck: global
106108
min_version = math.huge
109+
--luacheck: global
107110
max_version = -math.huge
108111

109112
for k in pairs(versions) do

drain-aquifer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Remove all 'aquifer' tags from the map blocks. Irreversible.
88
]====]
99

1010
local function drain()
11-
local layers = {}
11+
local layers = {} --as:bool[]
1212
local layer_count = 0
1313
local tile_count = 0
1414

0 commit comments

Comments
 (0)