Fixed getxyz(), getCreatureAtPos() (also returns nil/creature) and empregnate to work with look/talk

develop
Warmist 2012-03-22 21:47:33 +02:00
parent 2bec9f6711
commit 8f72a642b2
2 changed files with 14 additions and 15 deletions

@ -476,28 +476,25 @@ function getSelectedUnit()
end end
end end
function getxyz() -- this will return pointers x,y and z coordinates. function getxyz() -- this will return pointers x,y and z coordinates.
local off=VersionInfo.getGroup("Position"):getAddress("cursor_xyz") -- lets find where in memory its being held local x=df.cursor.x
-- now lets read them (they are double words (or unsigned longs or 4 bits each) and go in sucesion local y=df.cursor.y
local x=engine.peekd(off) local z=df.cursor.z
local y=engine.peekd(off+4) --next is 4 from start
local z=engine.peekd(off+8) --next is 8 from start
--print("Pointer @:"..x..","..y..","..z)
return x,y,z -- return the coords return x,y,z -- return the coords
end end
function GetCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord
--local x,y,z=getxyz() --get 'X' coords --local x,y,z=getxyz() --get 'X' coords
local vector=engine.peek(VersionInfo.getGroup("Creatures"):getAddress("vector"),ptr_vector) -- load all creatures local vector=df.world.units.all -- load all creatures
for i = 0, vector:size()-1 do -- look into all creatures offsets for i = 0, vector.size-1 do -- look into all creatures offsets
local curoff=vector:getval(i) -- get i-th creatures offset local curpos=vector[i]:deref().pos --get its coordinates
local cx=engine.peek(curoff,ptr_Creature.x) --get its coordinates local cx=curpos.x
local cy=engine.peek(curoff,ptr_Creature.y) local cy=curpos.y
local cz=engine.peek(curoff,ptr_Creature.z) local cz=curpos.z
if cx==x and cy==y and cz==z then --compare them if cx==x and cy==y and cz==z then --compare them
return i --return index return vector[i]:deref() --return index
end end
end end
print("Creature not found!") print("Creature not found!")
return -1 return nil
end end
function Allocate(size) function Allocate(size)

@ -264,6 +264,8 @@ function tools.empregnate(unit)
if unit==nil then if unit==nil then
unit=getSelectedUnit() unit=getSelectedUnit()
end end
if unit==nil then
unit=getCreatureAtPos(getxyz())
if unit==nil then if unit==nil then
error("Failed to empregnate. Unit not selected/valide") error("Failed to empregnate. Unit not selected/valide")
end end