2014-06-26 06:36:57 -06:00
-- teleport.lua
-- teleports a unit to a location
-- author Putnam
-- edited by expwnent
2015-10-23 22:10:15 -06:00
--[[=begin
teleport
========
Teleports a unit to given coordinates . Examples :
: teleport - showunitid : prints unitid beneath cursor
: teleport - showpos : prints coordinates beneath cursor
: teleport - unit 1234 - x 56 - y 115 - z 26 :
teleports unit 1234 to 56 , 115 , 26
= end ] ]
2014-06-26 06:36:57 -06:00
2015-07-27 06:46:01 -06:00
function teleport ( unit , pos )
2014-06-26 06:36:57 -06:00
local unitoccupancy = dfhack.maps . getTileBlock ( unit.pos ) . occupancy [ unit.pos . x % 16 ] [ unit.pos . y % 16 ]
2014-11-06 23:15:21 -07:00
local newoccupancy = dfhack.maps . getTileBlock ( pos ) . occupancy [ pos.x % 16 ] [ pos.y % 16 ]
if newoccupancy.unit then
unit.flags1 . on_ground = true
end
2014-06-26 06:36:57 -06:00
unit.pos . x = pos.x
unit.pos . y = pos.y
unit.pos . z = pos.z
if not unit.flags1 . on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end
end
2014-11-06 23:15:21 -07:00
utils = require ( ' utils ' )
2014-06-26 06:36:57 -06:00
2014-11-06 23:15:21 -07:00
validArgs = validArgs or utils.invert ( {
' unit ' ,
' x ' ,
' y ' ,
' z ' ,
' showunitid ' ,
' showpos '
} )
2014-06-26 06:36:57 -06:00
2015-07-27 06:46:01 -06:00
if moduleMode then
return
end
2014-11-06 23:15:21 -07:00
local args = utils.processArgs ( { ... } , validArgs )
if args.showunitid or args.showpos then
if args.showunitid then
print ( dfhack.gui . getSelectedUnit ( true ) . id )
else
printall ( df.global . cursor )
end
else
local unit = args.unit and df.unit . find ( args.unit ) or dfhack.gui . getSelectedUnit ( true )
2015-05-19 14:18:40 -06:00
local pos = not ( not args.x or not args.y or not args.z ) and { x = args.x , y = args.y , z = args.z } or { x = df.global . cursor.x , y = df.global . cursor.y , z = df.global . cursor.z }
if not unit then qerror ( ' A unit needs to be selected or specified. Use teleport -showunitid to get a unit \' s ID. ' ) end
if not pos.x or pos.x ==- 30000 then qerror ( ' A position needs to be highlighted or specified. Use teleport -showpos to get a position \' s exact xyz values. ' ) end
2014-11-06 23:15:21 -07:00
teleport ( unit , pos )
2014-12-03 03:33:05 -07:00
end