Updated teleport for new args system.

Also updated the teleport function to properly check for units at
destination.
develop
Putnam3145 2014-11-06 22:15:21 -08:00
parent ba56f369e5
commit 6b2b13b186
4 changed files with 34 additions and 31 deletions

@ -2,6 +2,7 @@ DFHack Future
Internals:
- EventManager: deals with frame_counter getting reset properly now.
- modtools/item-trigger: fixed equip/unequip bug and corrected minor documentation error
- teleport: Updated with proper argument handling and proper unit-at-destination handling.
DFHack 0.40.14-r1
Internals:

@ -3158,12 +3158,10 @@ stripcaged weapons 25321 34228
<p>Teleports a unit to given coordinates.</p>
<p>Examples:</p>
<pre class="literal-block">
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
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
</pre>
<p>One or both of <tt class="docutils literal">unit</tt> and <tt class="docutils literal">x</tt>/<tt class="docutils literal">y</tt>/<tt class="docutils literal">z</tt> coordinate positions must be
specified. If one is omitted, the unit or position beneath the cursor is used.</p>
</div>
<div class="section" id="undump-buildings">
<h2><a class="toc-backref" href="#id155">undump-buildings</a></h2>

@ -2425,12 +2425,9 @@ 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
One or both of ``unit`` and ``x``/``y``/``z`` coordinate positions must be
specified. If one is omitted, the unit or position beneath the cursor is used.
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
undump-buildings
================

@ -5,32 +5,39 @@
local function teleport(unit,pos)
local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16]
local newoccupancy = dfhack.maps.getTileBlock(pos).occupancy[pos.x%16][pos.y%16]
if newoccupancy.unit then
unit.flags1.on_ground=true
end
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
local function getArgsTogether(args)
local settings={pos={}}
for k,v in ipairs(args) do
v=string.lower(v)
if v=="unit" then settings.unitID=tonumber(args[k+1]) end
if v=="x" then settings.pos['x']=tonumber(args[k+1]) end
if v=="y" then settings.pos['y']=tonumber(args[k+1]) end
if v=="z" then settings.pos['z']=tonumber(args[k+1]) end
if v=="showunitid" then print(dfhack.gui.getSelectedUnit(true).id) end
if v=="showpos" then printall(df.global.cursor) end
end
if not settings.pos.x or not settings.pos.y or not settings.pos.z then settings.pos=nil end
if not settings.unitID and not settings.pos.x then qerror("Needs a position, a unit ID or both, but not neither!") end
return settings
end
utils = require('utils')
validArgs = validArgs or utils.invert({
'unit',
'x',
'y',
'z',
'showunitid',
'showpos'
})
local args = {...}
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 teleportSettings=getArgsTogether(args)
local unit = teleportSettings.unitID and df.unit.find(teleportSettings.unitID) or dfhack.gui.getSelectedUnit(true)
local pos = teleportSettings.pos and teleportSettings.pos or df.global.cursor
local unit = args.unit and df.unit.find(args.unit) or dfhack.gui.getSelectedUnit(true)
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 df.global.cursor
teleport(unit,pos)
end