Skip to content

Commit

Permalink
More fixes for df-luacheck. Mostly annotations, but there are a few t…
Browse files Browse the repository at this point in the history
…ypos fixed as well.
  • Loading branch information
BenLubar committed Jun 9, 2018
1 parent 69500d4 commit 1d1c4fb
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 86 deletions.
26 changes: 12 additions & 14 deletions add-thought.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
if not (tonumber(emotion)) then
emotion=df.emotion_type[emotion]
end
local properThought=nil
if not (tonumber(thought)) then
properThought=df.unit_thought_type[tonumber(thought)]
if not properThought then
for k,syn in ipairs(df.global.world.raws.syndromes.all) do
if syn.syn_name==thought then
properThought=df.unit_thought_type['Syndrome']
subthought=syn.id
break
end
local properThought = tonumber(thought) --as:df.unit_thought_type
local properSubthought = tonumber(subthought)
if not properThought or not df.unit_thought_type[properThought] then
for k,syn in ipairs(df.global.world.raws.syndromes.all) do
if syn.syn_name==thought then
properThought = df.unit_thought_type.Syndrome
properSubthought = syn.id
break
end
end
end
emotions:insert('#',{new=df.unit_personality.T_emotions,
type=tonumber(emotion),
unk2=1,
strength=tonumber(strength),
thought=tonumber(thought),
subthought=tonumber(subthought),
thought=properThought,
subthought=properSubthought,
severity=tonumber(severity),
unk7=0,
year=df.global.cur_year,
Expand All @@ -47,7 +45,7 @@ function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
end
end

validArgs = utils.invert({
local validArgs = utils.invert({
'unit',
'thought',
'emotion',
Expand All @@ -58,7 +56,7 @@ validArgs = utils.invert({
})

function tablify(iterableObject)
t={}
local t={}
for k,v in ipairs(iterableObject) do
t[k] = v~=nil and v or 'nil'
end
Expand Down
21 changes: 8 additions & 13 deletions armoks-blessing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Without arguments, all attributes, age & personalities are adjusted.
Arguments allow for skills to be adjusted as well.
]====]
local utils = require 'utils'
function rejuvenate(unit)
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
Expand Down Expand Up @@ -51,18 +52,14 @@ function elevate_attributes(unit)
return
end

local ok,f,t,k = pcall(pairs,unit.status.current_soul.mental_attrs)
if ok then
for k,v in f,t,k do
if unit.status.current_soul then
for k,v in pairs(unit.status.current_soul.mental_attrs) do
v.value=v.max_value
end
end

local ok,f,t,k = pcall(pairs,unit.body.physical_attrs)
if ok then
for k,v in f,t,k do
v.value=v.max_value
end
for k,v in pairs(unit.body.physical_attrs) do
v.value=v.max_value
end
end
-- ---------------------------------------------------------------------------
Expand Down Expand Up @@ -95,7 +92,6 @@ function make_legendary(skillname,unit)
end

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

local count_max = count_this(df.job_skill)
utils = require 'utils'
for i=0, count_max do
utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id')
end
print ("The breath of Armok has engulfed "..unit.name.first_name)
end
-- ---------------------------------------------------------------------------
function LegendaryByClass(skilltype,v)
unit=v
local unit=v
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
end

utils = require 'utils'
local i
local skillclass
local count_max = count_this(df.job_skill)
Expand Down Expand Up @@ -182,7 +176,8 @@ end
-- ---------------------------------------------------------------------------
-- main script operation starts here
-- ---------------------------------------------------------------------------
local opt = ...
local args = {...}
local opt = args[1]
local skillname

if opt then
Expand Down
4 changes: 2 additions & 2 deletions cannibalism.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ end

local scrn = dfhack.gui.getCurViewscreen()
if df.viewscreen_itemst:is_instance(scrn) then
scrn.item.flags.dead_dwarf = false
scrn.item.flags.dead_dwarf = false --hint:df.viewscreen_itemst
elseif df.viewscreen_dungeon_monsterstatusst:is_instance(scrn) then
unmark_inventory(scrn.inventory)
unmark_inventory(scrn.inventory) --hint:df.viewscreen_dungeon_monsterstatusst
elseif df.global.ui_advmode.menu == df.ui_advmode_menu.Inventory then
unmark_inventory(df.global.world.units.active[0].inventory)
else
Expand Down
20 changes: 10 additions & 10 deletions catsplosion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Animals will give birth within two in-game hours (100 ticks or fewer).
]====]

world = df.global.world
local world = df.global.world

if not dfhack.isWorldLoaded() then
qerror('World not loaded.')
end

args = {...}
list_only = false
creatures = {}
local args = {...}
local list_only = false
local creatures = {}

if #args > 0 then
for _, arg in pairs(args) do
Expand All @@ -38,12 +38,12 @@ else
creatures.CAT = true
end

total = 0
total_changed = 0
total_created = 0
local total = 0
local total_changed = 0
local total_created = 0

males = {}
females = {}
local males = {} --as:df.unit[][]
local females = {} --as:df.unit[][]

for _, unit in pairs(world.units.all) do
local id = world.raws.creatures.all[unit.race].creature_id
Expand All @@ -55,7 +55,7 @@ end
if list_only then
print("Type Male # Female #")
-- sort IDs alphabetically
local ids = {}
local ids = {} --as:string[]
for id in pairs(males) do
table.insert(ids, id)
end
Expand Down
10 changes: 5 additions & 5 deletions combine-drinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Merge stacks of drinks in the selected stockpile.
]====]
local utils = require 'utils'

validArgs = utils.invert({ 'max', 'stockpile' })
local validArgs = utils.invert({ 'max', 'stockpile' })
local args = utils.processArgs({...}, validArgs)

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

if d:getType() == 68 then
if d:getType() == df.item_type.DRINK then
foundDrink = d
else
--print(d.id)
Expand All @@ -39,7 +39,7 @@ local function getDrinks(items, drinks, index)
if #containedItems == 1 then
local possibleDrink = containedItems[1]

if #possibleDrink.specific_refs == 0 and possibleDrink:getType() == 68 then
if #possibleDrink.specific_refs == 0 and possibleDrink:getType() == df.item_type.DRINK then
foundDrink = possibleDrink
end
end
Expand Down Expand Up @@ -68,14 +68,14 @@ else
error("Select a non-empty stockpile")

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

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

local removedDrinks = { }
local removedDrinks = {} --as:bool[]

for i=0,(drinkCount-2) do
local currentDrink = drinks[i]
Expand Down
2 changes: 1 addition & 1 deletion devel/inspect-screen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function InspectScreen:onRenderBody(dc)
local info = self.cursor_pen
dc:string('CH: '):char(info.ch, FG_PEN):char(info.ch, BG_PEN):string(' '):string(''..info.ch,TXT_PEN):newline()
local fgcolor = info.fg
local fgstr = info.fg
local fgstr = tostring(info.fg)
if info.bold then
fgcolor = (fgcolor+8)%16
fgstr = fgstr..'+8'
Expand Down
10 changes: 7 additions & 3 deletions devel/light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function getCursorPos()
return copyall(g_cursor)
end
end
--luacheck: skip
function falloff(color,sqDist,maxdist)
local v1=1/(sqDist/maxdist+1)
local v2=v1-1/(1+maxdist*maxdist)
Expand All @@ -44,15 +45,16 @@ return {r=math.max(c1.r,c2.r),
g=math.max(c1.g,c2.g),
b=math.max(c1.b,c2.b)}
end
--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}}[]'}
LightOverlay=defclass(LightOverlay,guidm.DwarfOverlay)
LightOverlay.ATTRS {
lightMap={},
dynamic=true,
dirty=false,
}
function LightOverlay:init(args)

self.tick=df.global.cur_year_tick_advmode
self.precalc = {}
self.lightMap = {}
self.tick = df.global.cur_year_tick_advmode
end

function lightPassable(shape)
Expand Down Expand Up @@ -174,6 +176,7 @@ function LightOverlay:placeLightFov(pos,radius,color)
self.lightMap[tile]=ncol
table.insert(self.fovs,{pos=pos,radius=radius,color=color})
end
--luacheck: skip
function LightOverlay:placeLightFov2(pos,radius,color,f,rays)
f=f or falloff
local raycount=rays or 25
Expand Down Expand Up @@ -213,6 +216,7 @@ function LightOverlay:placeLightFov2(pos,radius,color,f,rays)
end
end
end
--luacheck: skip
function LightOverlay:placeLight(pos,radius,color,f)
f=f or falloff
local vp=self:getViewport()
Expand Down
6 changes: 4 additions & 2 deletions devel/modstate-monitor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Display changes in key modifier state, ie Ctrl/Alt/Shift.

VERSION = '0.1'

if active == nil then active = false end
active = active or false

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

last_msg = last_msg or nil --as:string
function log(s, color)
-- prevent duplicate output
if s ~= last_msg then
Expand All @@ -40,6 +41,7 @@ function log(s, color)
end
end

last_modstate = last_modstate or nil --as:number
function check()
local msg = ''
local modstate = dfhack.internal.getModstate()
Expand All @@ -53,7 +55,7 @@ function check()
if active then set_timeout() end
end

args = {...}
local args = {...}
if dfhack_flags and dfhack_flags.enable then
table.insert(args, dfhack_flags.enable_state and 'enable' or 'disable')
end
Expand Down
3 changes: 3 additions & 0 deletions devel/save-version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function has_field(tbl, field)
return (pcall(function() assert(tbl[field] ~= nil) end))
end

--luacheck: global
versions = {
-- skipped v0.21-v0.28
[1287] = "0.31.01",
Expand Down Expand Up @@ -103,7 +104,9 @@ versions = {
[1620] = "0.44.10",
}

--luacheck: global
min_version = math.huge
--luacheck: global
max_version = -math.huge

for k in pairs(versions) do
Expand Down
2 changes: 1 addition & 1 deletion drain-aquifer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Remove all 'aquifer' tags from the map blocks. Irreversible.
]====]

local function drain()
local layers = {}
local layers = {} --as:bool[]
local layer_count = 0
local tile_count = 0

Expand Down
4 changes: 2 additions & 2 deletions emigration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ function checkForDeserters(method,civ_id)
end

function checkmigrationnow()
local merchant_civ_ids = {}
local diplomat_civ_ids = {}
local merchant_civ_ids = {} --as:number[]
local diplomat_civ_ids = {} --as:number[]
local allUnits = df.global.world.units.active
for i=0, #allUnits-1 do
local unit = allUnits[i]
Expand Down
2 changes: 1 addition & 1 deletion fix-ster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end

function process_args(args)
local n, v, ori, crename, crenum
local creatures = {}
local creatures = {} --as:number[]
--Checks for any arguments at all.
if args == nil or #args == 0 then
print("No arguments. Usage is: fixster <fert|ster> [all|animals|only:<creature>]")
Expand Down
2 changes: 1 addition & 1 deletion forum-dwarves.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ local colors_css = {
[15] = 'white'
}

local scrn = dfhack.gui.getCurViewscreen()
local scrn = dfhack.gui.getCurViewscreen() --as:df.viewscreen_textviewerst
local flerb = dfhack.gui.getFocusString(scrn)

local function format_for_forum(strin)
Expand Down
2 changes: 1 addition & 1 deletion gaydar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ local function nameOrSpeciesAndNumber(unit)
end
end

local orientations={}
local orientations={} --as:string[]

if args.citizens then
for k,v in ipairs(df.global.world.units.active) do
Expand Down
Loading

0 comments on commit 1d1c4fb

Please sign in to comment.