@@ -97,7 +97,7 @@ function reverseRaceLookup(id)
97
97
end
98
98
function deon_filter (name ,type_id ,subtype_id ,custom_id , parent )
99
99
-- print(name)
100
- local adv = df . global . world .units . active [ 0 ]
100
+ local adv = dfhack . world .getAdventurer ()
101
101
local race_filter = build_filter [reverseRaceLookup (adv .race )]
102
102
if race_filter then
103
103
if race_filter .forbid_all then
195
195
function advGlobalPos ()
196
196
local map = df .global .world .map
197
197
local wd = df .global .world .world_data
198
- local adv = df . global . world .units . active [ 0 ]
198
+ local adv = dfhack . world .getAdventurer ()
199
199
-- 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
200
200
-- 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
201
201
-- 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)
1178
1178
usetool .focus_path = ' advfort'
1179
1179
-- luacheck: out=string
1180
1180
function usetool :getModeName ()
1181
- local adv = df . global . world .units . active [ 0 ]
1181
+ local adv = dfhack . world .getAdventurer ()
1182
1182
local ret
1183
1183
if adv .job .current_job then
1184
1184
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)
1232
1232
}
1233
1233
}
1234
1234
}
1235
- local labors = df . global . world .units . active [ 0 ] .status .labors
1235
+ local labors = dfhack . world .getAdventurer () .status .labors
1236
1236
for i ,v in ipairs (labors ) do
1237
1237
labors [i ]= true
1238
1238
end
@@ -1302,7 +1302,7 @@ function siegeWeaponActionChosen(args,actionid)
1302
1302
args .pre_actions = {dfhack .curry (setFiltersUp ,{items = {{quantity = 1 ,item_type = df .SIEGEAMMO }}}),AssignJobItems }
1303
1303
end
1304
1304
args .job_type = action
1305
- args .unit = df . global . world .units . active [ 0 ]
1305
+ args .unit = dfhack . world .getAdventurer ()
1306
1306
local from_pos = {x = args .unit .pos .x ,y = args .unit .pos .y , z = args .unit .pos .z }
1307
1307
args .from_pos = from_pos
1308
1308
args .pos = from_pos
@@ -1312,7 +1312,7 @@ function siegeWeaponActionChosen(args,actionid)
1312
1312
action = df .job_type .FireCatapult
1313
1313
end
1314
1314
args .job_type = action
1315
- args .unit = df . global . world .units . active [ 0 ]
1315
+ args .unit = dfhack . world .getAdventurer ()
1316
1316
local from_pos = {x = args .unit .pos .x ,y = args .unit .pos .y , z = args .unit .pos .z }
1317
1317
args .from_pos = from_pos
1318
1318
args .pos = from_pos
@@ -1329,7 +1329,7 @@ function putItemToBuilding(building,item)
1329
1329
end
1330
1330
end
1331
1331
function usetool :openPutWindow (building )
1332
- local adv = df . global . world .units . active [ 0 ]
1332
+ local adv = dfhack . world .getAdventurer ()
1333
1333
local items = EnumItems {pos = adv .pos ,unit = adv ,
1334
1334
inv = {[df .unit_inventory_item .T_mode .Hauled ]= true ,-- [df.unit_inventory_item.T_mode.Worn]=true,
1335
1335
[df .unit_inventory_item .T_mode .Weapon ]= true ,},deep = true }
@@ -1345,7 +1345,7 @@ function usetool:openSiegeWindow(building)
1345
1345
dfhack .curry (siegeWeaponActionChosen ,args ))
1346
1346
end
1347
1347
function usetool :onWorkShopButtonClicked (building ,index ,choice )
1348
- local adv = df . global . world .units . active [ 0 ]
1348
+ local adv = dfhack . world .getAdventurer ()
1349
1349
local args = {unit = adv ,building = building }
1350
1350
if df .interface_button_building_new_jobst :is_instance (choice .button ) then
1351
1351
choice .button :click ()
@@ -1393,7 +1393,7 @@ function usetool:openShopWindowButtoned(building,no_reset)
1393
1393
,nil , nil ,true )
1394
1394
end
1395
1395
function usetool :openShopWindow (building )
1396
- local adv = df . global . world .units . active [ 0 ]
1396
+ local adv = dfhack . world .getAdventurer ()
1397
1397
1398
1398
local filter_pile = workshopJobs .getJobs (building :getType (),building :getSubtype (),building :getCustomType ())
1399
1399
if filter_pile then
@@ -1441,7 +1441,7 @@ function track_stop_configure(bld) --TODO: dedicated widget with nice interface
1441
1441
dialog .showListPrompt (" Track stop configure" , " Choose what to change:" ,COLOR_WHITE ,choices ,chosen )
1442
1442
end
1443
1443
function usetool :armCleanTrap (building )
1444
- local adv = df . global . world .units . active [ 0 ]
1444
+ local adv = dfhack . world .getAdventurer ()
1445
1445
--[[
1446
1446
Lever,
1447
1447
PressurePlate,
@@ -1487,7 +1487,7 @@ function usetool:armCleanTrap(building)
1487
1487
end
1488
1488
-- luacheck: in=df.building_hivest out=none
1489
1489
function usetool :hiveActions (building )
1490
- local adv = df . global . world .units . active [ 0 ]
1490
+ local adv = dfhack . world .getAdventurer ()
1491
1491
local args = {unit = adv ,post_actions = {AssignBuildingRef },pos = adv .pos ,
1492
1492
from_pos = adv .pos ,job_type = df .job_type .InstallColonyInHive ,building = building ,screen = self }
1493
1493
local job_filter = {items = {{quantity = 1 ,item_type = df .item_type .VERMIN }} }
@@ -1498,14 +1498,14 @@ function usetool:hiveActions(building)
1498
1498
end
1499
1499
function usetool :operatePump (building )
1500
1500
-- 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 ()
1502
1502
local set_operate = function ( args )
1503
1503
args .building .pump_manually = true
1504
1504
end
1505
1505
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 }
1506
1506
end
1507
1507
function usetool :farmPlot (building )
1508
- local adv = df . global . world .units . active [ 0 ]
1508
+ local adv = dfhack . world .getAdventurer ()
1509
1509
local do_harvest = false
1510
1510
for id , con_item in pairs (building .contained_items ) do
1511
1511
if con_item .use_mode == 2 and con_item .item :getType ()== df .item_type .PLANT then
@@ -1531,14 +1531,14 @@ function usetool:farmPlot(building)
1531
1531
end
1532
1532
-- luacheck: in=df.building_bedst out=none
1533
1533
function usetool :bedActions (building )
1534
- local adv = df . global . world .units . active [ 0 ]
1534
+ local adv = dfhack . world .getAdventurer ()
1535
1535
local args = {unit = adv ,pos = adv .pos ,from_pos = adv .pos ,screen = self ,building = building ,
1536
1536
job_type = df .job_type .Sleep ,post_actions = {AssignBuildingRef }}
1537
1537
makeJob (args )
1538
1538
end
1539
1539
-- luacheck: in=df.building_chairst out=none
1540
1540
function usetool :chairActions (building )
1541
- local adv = df . global . world .units . active [ 0 ]
1541
+ local adv = dfhack . world .getAdventurer ()
1542
1542
local eatjob = {items = {{quantity = 1 ,item_type = df .item_type .FOOD }}}
1543
1543
local args = {unit = adv ,pos = adv .pos ,from_pos = adv .pos ,screen = self ,job_type = df .job_type .Eat ,building = building ,
1544
1544
pre_actions = {dfhack .curry (setFiltersUp ,eatjob ),AssignJobItems },post_actions = {AssignBuildingRef }}
@@ -1640,7 +1640,7 @@ end
1640
1640
function usetool :setupFields ()
1641
1641
local ui = df .global .plotinfo
1642
1642
1643
- local adv = df . global . world .units . active [ 0 ]
1643
+ local adv = dfhack . world .getAdventurer ()
1644
1644
if settings .set_civ == true then
1645
1645
ui .civ_id = adv .civ_id
1646
1646
ui .race_id = adv .race
@@ -1676,7 +1676,7 @@ function usetool:siteCheck()
1676
1676
end
1677
1677
-- movement and co... Also passes on allowed keys
1678
1678
function usetool :fieldInput (keys )
1679
- local adv = df . global . world .units . active [ 0 ]
1679
+ local adv = dfhack . world .getAdventurer ()
1680
1680
local cur_mode = actions [(mode or 0 )+ 1 ]
1681
1681
local failed = false
1682
1682
for code ,_ in pairs (keys ) do
@@ -1744,7 +1744,7 @@ function usetool:onInput(keys)
1744
1744
1745
1745
self :update_site ()
1746
1746
1747
- local adv = df . global . world .units . active [ 0 ]
1747
+ local adv = dfhack . world .getAdventurer ()
1748
1748
1749
1749
if keys .LEAVESCREEN then
1750
1750
if df .global .cursor .x ~=- 30000 then -- if not poiting at anything
@@ -1786,7 +1786,7 @@ function usetool:cancel_wait()
1786
1786
self .long_wait = false
1787
1787
end
1788
1788
function usetool :onIdle ()
1789
- local adv = df . global . world .units . active [ 0 ]
1789
+ local adv = dfhack . world .getAdventurer ()
1790
1790
local job_ptr = adv .job .current_job
1791
1791
local job_action = findAction (adv ,df .unit_action_type .Job )
1792
1792
@@ -1825,7 +1825,7 @@ function usetool:onIdle()
1825
1825
self ._native .parent :logic ()
1826
1826
end
1827
1827
function usetool :isOnBuilding ()
1828
- local adv = df . global . world .units . active [ 0 ]
1828
+ local adv = dfhack . world .getAdventurer ()
1829
1829
local bld = dfhack .buildings .findAtTile (adv .pos )
1830
1830
if bld and MODES [bld :getType ()]~= nil and bld :getBuildStage ()== bld :getMaxBuildStage () then
1831
1831
return true ,MODES [bld :getType ()],bld
@@ -1837,7 +1837,7 @@ function usetool:onRenderBody(dc)
1837
1837
self :shopMode (self :isOnBuilding ())
1838
1838
self :renderParent ()
1839
1839
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
1841
1841
qerror (" This script requires an adventurer mode with (l)ook or default mode." )
1842
1842
end
1843
1843
usetool ():show ()
0 commit comments