Skip to content

Commit 982f04d

Browse files
committed
Fix more luacheck stuff. Fix fixnaked being broken with the thought/emotion changes.
1 parent 0d12bd6 commit 982f04d

11 files changed

Lines changed: 183 additions & 172 deletions

devel/export-dt-ini.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local function address(name,base,field,...)
4545
_,addr = df.sizeof(ms.field_ref(base,field,...))
4646
end
4747
addr = addr - rdelta
48-
elseif base._kind == 'class-type' then --luacheck: skip
48+
elseif base._kind == 'class-type' then
4949
-- field_offset crashes with classes due to vtable problems,
5050
-- so we have to create a real temporary object here.
5151
local obj = df.new(base)

devel/find-offsets.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Arguments:
3131
3232
]====]
3333

34+
--luacheck-flags: strictsubtype
35+
3436
local utils = require 'utils'
3537
local ms = require 'memscan'
3638
local gui = require 'gui'
@@ -101,20 +103,20 @@ local function get_screen(class, prompt)
101103
if not is_known('gview') then
102104
print('Please navigate to '..prompt)
103105
if not prompt_proceed() then
104-
return nil
106+
return nil, false
105107
end
106-
return true
108+
return nil, true
107109
end
108110

109111
while true do
110-
local cs = dfhack.gui.getCurViewscreen(true) --as:class
112+
local cs = dfhack.gui.getCurViewscreen(true)
111113
if not df.is_instance(class, cs) then
112114
print('Please navigate to '..prompt)
113115
if not prompt_proceed() then
114-
return nil
116+
return nil, false
115117
end
116118
else
117-
return cs
119+
return cs, true
118120
end
119121
end
120122
end
@@ -380,7 +382,8 @@ end
380382
--
381383

382384
local function find_cursor()
383-
if not screen_title() then
385+
local _, ok = screen_title()
386+
if not ok then
384387
return false
385388
end
386389

devel/list-filters.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ local utils = require 'utils'
1313
local buildings = require 'dfhack.buildings'
1414

1515
local function name_enum(tgt,name,ename,enum)
16-
if tgt[name] ~= nil then
17-
tgt[name] = ename..'.'..enum[tgt[name]]
16+
if type(tgt[name]) == 'number' then
17+
tgt[name] = ename..'.'..enum[tgt[name]] --luacheck: retype
1818
end
1919
end
2020

devel/save-version.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ Display DF version information about the current save
1111
local function dummy() return nil end
1212

1313
function has_field(tbl, field)
14-
return (pcall(function() assert(tbl[field] ~= nil) end))
14+
for k in pairs(tbl) do
15+
if k == field then
16+
return true
17+
end
18+
end
19+
return false
1520
end
1621

1722
--luacheck: global

exportlegends.lua

Lines changed: 143 additions & 135 deletions
Large diffs are not rendered by default.

fixnaked.lua

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,29 @@ local total_fixed = 0
1212
local total_removed = 0
1313

1414
for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do
15-
if fnUnit.race == df.global.ui.race_id then
16-
local listEvents = fnUnit.status.recent_events
17-
--for lkey,lvalue in pairs(listEvents) do
18-
-- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity)
19-
--end
20-
21-
local found = 1
22-
local fixed = 0
23-
while found == 1 do
24-
local events = fnUnit.status.recent_events
25-
found = 0
26-
for k,v in pairs(events) do
27-
if v.type == df.unit_thought_type.Uncovered
28-
or v.type == df.unit_thought_type.NoShirt
29-
or v.type == df.unit_thought_type.NoShoes
30-
or v.type == df.unit_thought_type.NoCloak
31-
or v.type == df.unit_thought_type.OldClothing
32-
or v.type == df.unit_thought_type.TatteredClothing
33-
or v.type == df.unit_thought_type.RottedClothing then
34-
events:erase(k)
35-
found = 1
15+
if fnUnit.race == df.global.ui.race_id and fnUnit.status.current_soul then
16+
local found = true
17+
local fixed = false
18+
while found do
19+
local emotions = fnUnit.status.current_soul.personality.emotions
20+
found = false
21+
for k,v in pairs(emotions) do
22+
if v.thought == df.unit_thought_type.Uncovered
23+
or v.thought == df.unit_thought_type.NoShirt
24+
or v.thought == df.unit_thought_type.NoShoes
25+
or v.thought == df.unit_thought_type.NoCloak
26+
or v.thought == df.unit_thought_type.OldClothing
27+
or v.thought == df.unit_thought_type.TatteredClothing
28+
or v.thought == df.unit_thought_type.RottedClothing then
29+
emotions:erase(k)
30+
found = true
3631
total_removed = total_removed + 1
37-
fixed = 1
32+
fixed = true
3833
break
3934
end
4035
end
4136
end
42-
if fixed == 1 then
37+
if fixed then
4338
total_fixed = total_fixed + 1
4439
print(total_fixed, total_removed, dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit)))
4540
end

modtools/change-build-menu.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function ChangeBuildingAdv(typ, subtyp, custom, category, add, key)
415415
if tonumber(key) == nil then
416416
key = df.interface_key[key] --luacheck: retype
417417
else
418-
key = tonumber(key)
418+
key = tonumber(key) --luacheck: retype
419419
end
420420
end
421421
key = key or 0

modtools/create-unit.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ end
561561

562562
local u = df.unit.find(unitId)
563563
u.counters.soldier_mood_countdown = -1
564-
u.counters.death_cause = -1
565564
u.enemy.unk_450 = -1
566565
u.enemy.unk_454 = -1
567566
u.enemy.army_controller_id = -1

modtools/random-trigger.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ local function triggerEvent(outcomeListName)
104104
--print ('r = ' .. r)
105105
for i,outcome in ipairs(outcomeList.outcomes) do
106106
sum = sum + outcome.weight
107-
if sum > r then
107+
if sum > r then --luacheck: skip
108108
local temp = outcome.command
109109
--print('triggering outcome ' .. i .. ': "' .. table.concat(temp, ' ') .. '"')
110110
--dfhack.run_command(table.unpack(temp))

region-pops.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local is_plant_map = {
3939
}
4040

4141
function enum_populations()
42-
local stat_table = { --as:{plants:{_array:{_type:table,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}},creatures:{_array:{_type:table,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}},any:{_array:{_type:table,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}}}
42+
local stat_table = { --as:{plants:{_array:{_type:table,obj:df.plant_raw,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}},creatures:{_array:{_type:table,obj:df.creature_raw,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}},any:{_array:{_type:table,token:string,id:number,records:'df.local_population[]',count:number,known_count:number,known:bool,infinite:bool}}}
4343
plants = {},
4444
creatures = {},
4545
any = {}

0 commit comments

Comments
 (0)