Nestharus
o-o
- Reaction score
- 83
Is Point Pathable
Not to be confused with IsTerrainPathable, this script will check to see if a point is currently pathable given a pathing type. For example, it will be able to detect if a building is at that point, unlike IsTerrainPathable, which only checks the terrains pathability (including doodads and what not).
This takes advantage of SetUnitPosition in order to determine whether a point is pathable or not. However, SetUnitPosition may bug in cases where the closest pathable point is at least 1024 units away (in which case the unit is just placed at the original point regardless as to whether it was pathable or not). This avoid that bug with a special algorithm that no other is pathable resource has.
Installation Script
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
//! runtextmacro LUA_FILE_HEADER()
//! i dofile("GetVarObject")
//! i local function create(id,pt)
//! i createobject("hwtw", id)
//! i makechange(current, "unsf", "( " .. pt .. " )")
//! i makechange(current, "upat", "")
//! i makechange(current, "ushb", "")
//! i makechange(current, "uubs", "")
//! i makechange(current, "uabr", "0")
//! i makechange(current, "uabt", "")
//! i makechange(current, "ucol", "16")
//! i makechange(current, "usid", "")
//! i makechange(current, "usin", "")
//! i if (pt~="blighted") then
//! i makechange(current, "upap", pt)
//! i else
//! i makechange(current, "upar", pt)
//! i makechange(current, "upap", "")
//! i end
//! i if (pt=="unflyable") then
//! i makechange(current, "umvt", "fly")
//! i elseif (pt=="unamph") then
//! i makechange(current, "umvt", "amph")
//! i elseif (pt=="unfloat") then
//! i makechange(current, "umvt", "float")
//! i else
//! i makechange(current, "umvt", "foot")
//! i end
//! i end
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unflyable", true),"unflyable")
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unamph", true),"unamph")
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unbuildable", true),"unbuildable")
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unwalkable", true),"unwalkable")
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unfloat", true),"unfloat")
//! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "blighted", true),"blighted")
//! i updateobjects()
//! endexternalblock
Script
JASS:
library IsPathable /* v1.0.1.2
*************************************************************************************
*
* The IsTerrainPathable native does not work.
*
* This library will also check if a point is currently pathable. Will even be
* able to detect buildings and large clusters of units (avoids the 1024 warcraft
* limit to pathing by checking via a loop).
*
************************************************************************************
*
* */uses/*
*
* */ WorldBounds /* hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
*
************************************************************************************
*
* constant integer PATH_TYPE_AMPHIBIOUS
* constant integer PATH_TYPE_BLIGHT
* constant integer PATH_TYPE_BUILDABILITY
* constant integer PATH_TYPE_FLOATABILITY
* constant integer PATH_TYPE_FLYABILITY
* constant integer PATH_TYPE_WALKABILITY
*
* function IsPathable takes integer x, integer y, integer pathingType returns boolean
* - i.e. call IsPathable(0,0,PATH_TYPE_AMPHIBIOUS)
*
************************************************************************************/
globals
//pathing types
constant integer PATH_TYPE_AMPHIBIOUS=0
constant integer PATH_TYPE_BLIGHT=1
constant integer PATH_TYPE_BUILDABILITY=2
constant integer PATH_TYPE_FLOATABILITY=3
constant integer PATH_TYPE_FLYABILITY=4
constant integer PATH_TYPE_WALKABILITY=5
private pathingtype array pt
private unit array u //unit pathability checkers array
endglobals
function IsPathable takes integer x, integer y, integer p returns boolean
local boolean b //was point pathable?
if (not IsTerrainPathable(x,y,pt[p])) then
call SetUnitPosition(u[p],x,y) //use SetUnitPosition to determine if point is pathable
set b=GetWidgetX(u[p])==x and GetWidgetY(u[p])==y //if coordinates are identical, coordinate *may* be
//pathable
if (b) then
//if the point was found as pathable, it may not be pathable
//units are placed at the original coordinates if the closest pathable point is
//at least 1024 units out
set x=x+64 //go out by 64
call SetUnitPosition(u[p],x,y) //set unit to new position
set b=GetWidgetX(u[p])<x //check to see if unit shifted towards original position
//if unit didn't shift towards original position, check second position with another unit
//where all points are not pathable, place a unit at an arbitrary point
//it will stay at that point even though it isn't pathable
/*
* * * *
* * * *
* U * *
* * * *
*/
//shift the unit over by 1 and see if it doesn't shift
//if it did shift, then the original position was pathable
//if it didn't shift, then both positions may or may not be pathable
/*
* * * *
* * * *
* * U *
* * * *
*/
//place a second unit on top of the first unit
//if it didn't shift left, then the first position was not pathable
/*
* * * *
* * * *
* * <-UU *
* * * *
--------------------------
* * * *
* * * *
* U U *
* * * *
*/
//the reason it will shift left is because 64 is only half a square, meaning it
//will still be closest to the first position
//the reason why two units are required
/*
* * * *
* * * *
* *
* * * *
*/
//in this case, both positions are pathable, meaning the unit will not shift
//it would be identical to this case
/*
* * * *
* * * *
* * * *
* * * *
*/
//and the reason for moving right is due to this case
/*
* * * *
* * * *
* * *
* * * *
*/
//in this case, a unit placed on top of the original unit will not shift anywhere
//and nothing is known
if (not b) then
call SetUnitPosition(u[p+6],x-32,y)
set b=GetWidgetX(u[p+6])<x
call SetUnitX(u[p+6],WorldBounds.minX)
call SetUnitY(u[p+6],WorldBounds.minY)
endif
endif
call SetUnitX(u[p],WorldBounds.minX)
call SetUnitY(u[p],WorldBounds.minY)
return b
endif
return false
endfunction
private module N
private static method onInit takes nothing returns nothing
local player p=Player(15)
set pt[PATH_TYPE_FLYABILITY]=PATHING_TYPE_FLYABILITY
set pt[PATH_TYPE_AMPHIBIOUS]=PATHING_TYPE_AMPHIBIOUSPATHING
set pt[PATH_TYPE_BUILDABILITY]=PATHING_TYPE_BUILDABILITY
set pt[PATH_TYPE_WALKABILITY]=PATHING_TYPE_WALKABILITY
set pt[PATH_TYPE_FLOATABILITY]=PATHING_TYPE_FLOATABILITY
set pt[PATH_TYPE_BLIGHT]=PATHING_TYPE_BLIGHTPATHING
set u[PATH_TYPE_FLYABILITY]=CreateUnit(p,UNITS_PATH_unflyable,0,0,0)
set u[PATH_TYPE_AMPHIBIOUS]=CreateUnit(p,UNITS_PATH_unamph,0,0,0)
set u[PATH_TYPE_BUILDABILITY]=CreateUnit(p,UNITS_PATH_unbuildable,0,0,0)
set u[PATH_TYPE_WALKABILITY]=CreateUnit(p,UNITS_PATH_unwalkable,0,0,0)
set u[PATH_TYPE_FLOATABILITY]=CreateUnit(p,UNITS_PATH_unfloat,0,0,0)
set u[PATH_TYPE_BLIGHT]=CreateUnit(p,UNITS_PATH_blighted,0,0,0)
set u[PATH_TYPE_FLYABILITY+6]=CreateUnit(p,UNITS_PATH_unflyable,0,0,0)
set u[PATH_TYPE_AMPHIBIOUS+6]=CreateUnit(p,UNITS_PATH_unamph,0,0,0)
set u[PATH_TYPE_BUILDABILITY+6]=CreateUnit(p,UNITS_PATH_unbuildable,0,0,0)
set u[PATH_TYPE_WALKABILITY+6]=CreateUnit(p,UNITS_PATH_unwalkable,0,0,0)
set u[PATH_TYPE_FLOATABILITY+6]=CreateUnit(p,UNITS_PATH_unfloat,0,0,0)
set u[PATH_TYPE_BLIGHT+6]=CreateUnit(p,UNITS_PATH_blighted,0,0,0)
call SetUnitX(u[PATH_TYPE_FLYABILITY],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_FLYABILITY],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_AMPHIBIOUS],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_AMPHIBIOUS],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_BUILDABILITY],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_BUILDABILITY],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_WALKABILITY],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_WALKABILITY],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_FLOATABILITY],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_FLOATABILITY],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_BLIGHT],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_BLIGHT],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_FLYABILITY+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_FLYABILITY+6],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_AMPHIBIOUS+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_AMPHIBIOUS+6],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_BUILDABILITY+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_BUILDABILITY+6],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_WALKABILITY+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_WALKABILITY+6],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_FLOATABILITY+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_FLOATABILITY+6],WorldBounds.minY)
call SetUnitX(u[PATH_TYPE_BLIGHT+6],WorldBounds.minX)
call SetUnitY(u[PATH_TYPE_BLIGHT+6],WorldBounds.minY)
set p=null
endmethod
endmodule
private struct I extends array
implement N
endstruct
endlibrary