Skip to content

Commit 766c6b2

Browse files
authored
Update advfort.lua (#1394)
use new API to get adventurer and focus strings
1 parent 9f3246d commit 766c6b2

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

gui/advfort.lua

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function reverseRaceLookup(id)
9797
end
9898
function deon_filter(name,type_id,subtype_id,custom_id, parent)
9999
--print(name)
100-
local adv=df.global.world.units.active[0]
100+
local adv=dfhack.world.getAdventurer()
101101
local race_filter=build_filter[reverseRaceLookup(adv.race)]
102102
if race_filter then
103103
if race_filter.forbid_all then
@@ -195,7 +195,7 @@ end
195195
function advGlobalPos()
196196
local map=df.global.world.map
197197
local wd=df.global.world.world_data
198-
local adv=df.global.world.units.active[0]
198+
local adv=dfhack.world.getAdventurer()
199199
--wd.midmap_data.adv_region_x*16+wd.midmap_data.adv_emb_x,wd.midmap_data.adv_region_y*16+wd.midmap_data.adv_emb_y
200200
--return wd.midmap_data.adv_region_x*16+wd.midmap_data.adv_emb_x,wd.midmap_data.adv_region_y*16+wd.midmap_data.adv_emb_y
201201
--return wd.midmap_data.adv_region_x*16+wd.midmap_data.adv_emb_x+adv.pos.x/16,wd.midmap_data.adv_region_y*16+wd.midmap_data.adv_emb_y+adv.pos.y/16
@@ -1178,7 +1178,7 @@ usetool=defclass(usetool,gui.Screen)
11781178
usetool.focus_path = 'advfort'
11791179
--luacheck: out=string
11801180
function usetool:getModeName()
1181-
local adv=df.global.world.units.active[0]
1181+
local adv=dfhack.world.getAdventurer()
11821182
local ret
11831183
if adv.job.current_job then
11841184
ret= string.format("%s working(%d) ",(actions[(mode or 0)+1][1] or ""),adv.job.current_job.completion_timer)
@@ -1232,7 +1232,7 @@ function usetool:init(args)
12321232
}
12331233
}
12341234
}
1235-
local labors=df.global.world.units.active[0].status.labors
1235+
local labors=dfhack.world.getAdventurer().status.labors
12361236
for i,v in ipairs(labors) do
12371237
labors[i]=true
12381238
end
@@ -1302,7 +1302,7 @@ function siegeWeaponActionChosen(args,actionid)
13021302
args.pre_actions={dfhack.curry(setFiltersUp,{items={{quantity=1,item_type=df.SIEGEAMMO}}}),AssignJobItems}
13031303
end
13041304
args.job_type=action
1305-
args.unit=df.global.world.units.active[0]
1305+
args.unit=dfhack.world.getAdventurer()
13061306
local from_pos={x=args.unit.pos.x,y=args.unit.pos.y, z=args.unit.pos.z}
13071307
args.from_pos=from_pos
13081308
args.pos=from_pos
@@ -1312,7 +1312,7 @@ function siegeWeaponActionChosen(args,actionid)
13121312
action=df.job_type.FireCatapult
13131313
end
13141314
args.job_type=action
1315-
args.unit=df.global.world.units.active[0]
1315+
args.unit=dfhack.world.getAdventurer()
13161316
local from_pos={x=args.unit.pos.x,y=args.unit.pos.y, z=args.unit.pos.z}
13171317
args.from_pos=from_pos
13181318
args.pos=from_pos
@@ -1329,7 +1329,7 @@ function putItemToBuilding(building,item)
13291329
end
13301330
end
13311331
function usetool:openPutWindow(building)
1332-
local adv=df.global.world.units.active[0]
1332+
local adv=dfhack.world.getAdventurer()
13331333
local items=EnumItems{pos=adv.pos,unit=adv,
13341334
inv={[df.unit_inventory_item.T_mode.Hauled]=true,--[df.unit_inventory_item.T_mode.Worn]=true,
13351335
[df.unit_inventory_item.T_mode.Weapon]=true,},deep=true}
@@ -1345,7 +1345,7 @@ function usetool:openSiegeWindow(building)
13451345
dfhack.curry(siegeWeaponActionChosen,args))
13461346
end
13471347
function usetool:onWorkShopButtonClicked(building,index,choice)
1348-
local adv=df.global.world.units.active[0]
1348+
local adv=dfhack.world.getAdventurer()
13491349
local args={unit=adv,building=building}
13501350
if df.interface_button_building_new_jobst:is_instance(choice.button) then
13511351
choice.button:click()
@@ -1393,7 +1393,7 @@ function usetool:openShopWindowButtoned(building,no_reset)
13931393
,nil, nil,true)
13941394
end
13951395
function usetool:openShopWindow(building)
1396-
local adv=df.global.world.units.active[0]
1396+
local adv=dfhack.world.getAdventurer()
13971397

13981398
local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType())
13991399
if filter_pile then
@@ -1441,7 +1441,7 @@ function track_stop_configure(bld) --TODO: dedicated widget with nice interface
14411441
dialog.showListPrompt("Track stop configure", "Choose what to change:",COLOR_WHITE,choices,chosen)
14421442
end
14431443
function usetool:armCleanTrap(building)
1444-
local adv=df.global.world.units.active[0]
1444+
local adv=dfhack.world.getAdventurer()
14451445
--[[
14461446
Lever,
14471447
PressurePlate,
@@ -1487,7 +1487,7 @@ function usetool:armCleanTrap(building)
14871487
end
14881488
--luacheck: in=df.building_hivest out=none
14891489
function usetool:hiveActions(building)
1490-
local adv=df.global.world.units.active[0]
1490+
local adv=dfhack.world.getAdventurer()
14911491
local args={unit=adv,post_actions={AssignBuildingRef},pos=adv.pos,
14921492
from_pos=adv.pos,job_type=df.job_type.InstallColonyInHive,building=building,screen=self}
14931493
local job_filter={items={{quantity=1,item_type=df.item_type.VERMIN}} }
@@ -1498,14 +1498,14 @@ function usetool:hiveActions(building)
14981498
end
14991499
function usetool:operatePump(building)
15001500
--TODO: low priotity, but would be nice to have the job auto cleanup (i.e. one work would only pump and then you could press it again)
1501-
local adv=df.global.world.units.active[0]
1501+
local adv=dfhack.world.getAdventurer()
15021502
local set_operate=function ( args )
15031503
args.building.pump_manually=true
15041504
end
15051505
makeJob{unit=adv,building=building,post_actions={AssignBuildingRef,set_operate},pos=adv.pos,from_pos=adv.pos,job_type=df.job_type.OperatePump,screen=self}
15061506
end
15071507
function usetool:farmPlot(building)
1508-
local adv=df.global.world.units.active[0]
1508+
local adv=dfhack.world.getAdventurer()
15091509
local do_harvest=false
15101510
for id, con_item in pairs(building.contained_items) do
15111511
if con_item.use_mode==2 and con_item.item:getType()==df.item_type.PLANT then
@@ -1531,14 +1531,14 @@ function usetool:farmPlot(building)
15311531
end
15321532
--luacheck: in=df.building_bedst out=none
15331533
function usetool:bedActions(building)
1534-
local adv=df.global.world.units.active[0]
1534+
local adv=dfhack.world.getAdventurer()
15351535
local args={unit=adv,pos=adv.pos,from_pos=adv.pos,screen=self,building=building,
15361536
job_type=df.job_type.Sleep,post_actions={AssignBuildingRef}}
15371537
makeJob(args)
15381538
end
15391539
--luacheck: in=df.building_chairst out=none
15401540
function usetool:chairActions(building)
1541-
local adv=df.global.world.units.active[0]
1541+
local adv=dfhack.world.getAdventurer()
15421542
local eatjob={items={{quantity=1,item_type=df.item_type.FOOD}}}
15431543
local args={unit=adv,pos=adv.pos,from_pos=adv.pos,screen=self,job_type=df.job_type.Eat,building=building,
15441544
pre_actions={dfhack.curry(setFiltersUp,eatjob),AssignJobItems},post_actions={AssignBuildingRef}}
@@ -1640,7 +1640,7 @@ end
16401640
function usetool:setupFields()
16411641
local ui=df.global.plotinfo
16421642

1643-
local adv=df.global.world.units.active[0]
1643+
local adv=dfhack.world.getAdventurer()
16441644
if settings.set_civ==true then
16451645
ui.civ_id=adv.civ_id
16461646
ui.race_id=adv.race
@@ -1676,7 +1676,7 @@ function usetool:siteCheck()
16761676
end
16771677
--movement and co... Also passes on allowed keys
16781678
function usetool:fieldInput(keys)
1679-
local adv=df.global.world.units.active[0]
1679+
local adv=dfhack.world.getAdventurer()
16801680
local cur_mode=actions[(mode or 0)+1]
16811681
local failed=false
16821682
for code,_ in pairs(keys) do
@@ -1744,7 +1744,7 @@ function usetool:onInput(keys)
17441744

17451745
self:update_site()
17461746

1747-
local adv=df.global.world.units.active[0]
1747+
local adv=dfhack.world.getAdventurer()
17481748

17491749
if keys.LEAVESCREEN then
17501750
if df.global.cursor.x~=-30000 then --if not poiting at anything
@@ -1786,7 +1786,7 @@ function usetool:cancel_wait()
17861786
self.long_wait=false
17871787
end
17881788
function usetool:onIdle()
1789-
local adv=df.global.world.units.active[0]
1789+
local adv=dfhack.world.getAdventurer()
17901790
local job_ptr=adv.job.current_job
17911791
local job_action=findAction(adv,df.unit_action_type.Job)
17921792

@@ -1825,7 +1825,7 @@ function usetool:onIdle()
18251825
self._native.parent:logic()
18261826
end
18271827
function usetool:isOnBuilding()
1828-
local adv=df.global.world.units.active[0]
1828+
local adv=dfhack.world.getAdventurer()
18291829
local bld=dfhack.buildings.findAtTile(adv.pos)
18301830
if bld and MODES[bld:getType()]~=nil and bld:getBuildStage()==bld:getMaxBuildStage() then
18311831
return true,MODES[bld:getType()],bld
@@ -1837,7 +1837,7 @@ function usetool:onRenderBody(dc)
18371837
self:shopMode(self:isOnBuilding())
18381838
self:renderParent()
18391839
end
1840-
if not (dfhack.gui.getCurFocus()=="dungeonmode/Look" or dfhack.gui.getCurFocus()=="dungeonmode/Default") then
1840+
if not (dfhack.gui.matchFocusString('dungeonmode/Look') or dfhack.gui.matchFocusString('dungeonmode/Default')) then
18411841
qerror("This script requires an adventurer mode with (l)ook or default mode.")
18421842
end
18431843
usetool():show()

0 commit comments

Comments
 (0)