Skip to content

Commit d1285c3

Browse files
committed
convert usage of units.active[0] to getAdventurer()
1 parent c0daef1 commit d1285c3

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

break-dance.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ can't find a partner.
99
]====]
1010
local unit
1111
if dfhack.world.isAdventureMode() then
12-
unit = df.global.world.units.active[0]
12+
unit = dfhack.world.getAdventurer()
1313
else
1414
unit = dfhack.gui.getSelectedUnit(true) or qerror('No unit selected')
1515
end

cannibalism.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if df.viewscreen_itemst:is_instance(scrn) then
1010
elseif df.viewscreen_dungeon_monsterstatusst:is_instance(scrn) then
1111
unmark_inventory(scrn.inventory) --hint:df.viewscreen_dungeon_monsterstatusst
1212
elseif df.global.adventure.menu == df.ui_advmode_menu.Inventory then
13-
unmark_inventory(df.global.world.units.active[0].inventory)
13+
unmark_inventory(dfhack.world.getAdventurer().inventory)
1414
else
1515
qerror('Unsupported context')
1616
end

gui/companion-order.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ end},
346346
return true
347347
end},
348348
{name="follow",f=function (unit_list)
349-
local adv=df.global.world.units.active[0]
349+
local adv=dfhack.world.getAdventurer()
350350
for k,v in pairs(unit_list) do
351351
v.relationship_ids.GroupLeader=adv.id
352352
end
353353
return true
354354
end},
355355
{name="leave",f=function (unit_list)
356-
local adv=df.global.world.units.active[0]
356+
local adv=dfhack.world.getAdventurer()
357357
local t_nem=dfhack.units.getNemesis(adv)
358358
for k,v in pairs(unit_list) do
359359

@@ -398,7 +398,7 @@ end},
398398
if not CheckCursor(pos) then
399399
return false
400400
end
401-
adv=df.global.world.units.active[0]
401+
adv=dfhack.world.getAdventurer()
402402
item=GetItemsAtPos(df.global.cursor)[1]
403403
print(item.id)
404404
for k,v in pairs(unit_list) do
@@ -413,7 +413,7 @@ end},
413413
}
414414

415415
function getCompanions(unit)
416-
unit=unit or df.global.world.units.active[0]
416+
unit=unit or dfhack.world.getAdventurer()
417417
local t_nem=dfhack.units.getNemesis(unit)
418418
if t_nem==nil then
419419
qerror("Invalid unit! No nemesis record")

launch.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ function launch(unitSource,unitRider)
6565
proj.speed_x=resultx*10000
6666
proj.speed_y=resulty*10000
6767
proj.speed_z=resultz*15000 --higher z speed makes it easier to reach a target safely
68-
if df.global.world.units.active[0].job.hunt_target==nil then
68+
69+
local adv = dfhack.world.getAdventurer()
70+
if adv.job.hunt_target==nil then
6971
proj.flags.safe_landing=true
70-
elseif df.global.world.units.active[0].job.hunt_target then
72+
elseif adv.job.hunt_target then
7173
proj.flags.safe_landing=false
7274
end
7375
local unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16]
@@ -80,11 +82,11 @@ function launch(unitSource,unitRider)
8082
unitSource.flags1.on_ground=false
8183
end
8284

83-
local unitSource = df.global.world.units.active[0]
85+
local unitSource = dfhack.world.getAdventurer()
8486
local unitRider = nil --as:df.unit
8587
if unitSource.job.hunt_target ~= nil then
8688
unitRider = unitSource
87-
unitSource = df.global.world.units.active[0].job.hunt_target
89+
unitSource = unitSource.job.hunt_target
8890
unitSource.general_refs:insert("#",{new=df.general_ref_unit_riderst,unit_id=unitRider.id})
8991
unitRider.relationship_ids.RiderMount=unitSource.id
9092
unitRider.flags1.rider=true

0 commit comments

Comments
 (0)