- Joined
- May 24, 2005
- Messages
- 609
Hey everyone,
this is a small library that provides a function that checks if there is a pathing blocker (default ground) between 2 coordinate points (x1,y1) and (x2,y2).
This detection function requires a library for pathability detection. I'm using Rising Dusk's TerrainPathability here, but you could also use any other library.
I've attached a small testmap.
If you know ways to improve the script, i.e. some way of performance optimization or better approaches for the detection algorithm, please let me know and I will update it.
this is a small library that provides a function that checks if there is a pathing blocker (default ground) between 2 coordinate points (x1,y1) and (x2,y2).
This detection function requires a library for pathability detection. I'm using Rising Dusk's TerrainPathability here, but you could also use any other library.
JASS:
library IsPathBlockerInBetween initializer Init requires TerrainPathability
//**************************************************************************
//* ============================
//* IsPathBlockerInBetween 1.00 (by MoCo)
//* ============================
//*
//* This library provides a function to check if there is a pathing blocker (default ground) between 2 coordinate points, given by x and y.
//*
//* This system requires a library for pathability detection.
//* I'm using Rising Dusk's library here, but you could also use any other library.
//* Using another library means that you might need to change the call of the IsTerrainWalkable function
//* to the name of whatever function the other pathability library is providing.
//* You could also change the IsTerrainWalkable function call to something like IsTerrainFlyable if you need.
//*
//* Setup:
//* ======
//*
//* 1. Copy this library and the TerrainPathability library to your map.
//*
//* 2. Adjust the MAX_DISTANCE constant
//*
//* Set this constant to the maximum distance between 2 points, you need to detect a pathing blocker in between within your map
//*
//* - A higher value means higher accuracy of detection;
//* the higher the distance between the 2 points, the higher the accuracy needed by the function to return proper results
//*
//* - A higher value means lower performance;
//* if you only need the detection function for low distances,
//* like for line of sight systems where sight range is limited and, for example, you won't need the function for longer distances anyway,
//* you should use a lower value to improve performance
//*
//* - Note that performance usually won't be an issue at all.
//* So if you plan to use this function only a few times, you wouldn't need to bother about performance.
//* However, for exmaple, if you are using this function with an AI system and need to call it multiple times a second for about 50-100 units,
//* you probably want to optimize performance.
//*
//* - Technically, a higher values means more checkup steps in the line between the 2 points
//* If you know what you're doing, you can also manually set the number of these steps
//* by setting the Steps variable to the number of steps you would like to have
//*
//* - If you find that in some situations the function doesn't deliver proper results, increase the MAX_DISTANCE variable or set Steps to a higher number
//*
//* Usage:
//* ======
//*
//* Call the function PathBlockerInBetween(real x1, real y1, real x2, real y2)
//*
//* The function returns true, if a pathing blocker (default ground) is between the two coordinates, and false if not.
//*
//**************************************************************************
globals
private constant real MAX_DISTANCE = 1024 // Do set this value to the maximum distance (or slightly higher),
// you need the path detection function to work properly
private integer Steps = 0 // If you know what you're doing, you can manually define
// the number of the checkup steps in the line between the 2 points.
// Else just leave this value as it is
endglobals
function PathBlockerInBetween takes real x1, real y1, real x2, real y2 returns boolean
local real incX = (x2-x1)/Steps
local real incY = (y2-y1)/Steps
local real x = x1
local real y = y1
local integer i = 0
local boolean check = false
loop
exitwhen i > Steps or check
if IsTerrainWalkable(x,y) == false then // You may want to change this function,
set check = true // if you are using a different library for pathability checking
endif
set x = x + incX
set y = y + incY
set i = i + 1
endloop
return check
endfunction
private function Init takes nothing returns nothing
if Steps == 0 then // if no manual override of steps count, calculate number based on given MAX_DISTANCE
set Steps = R2I(MAX_DISTANCE / 32.)
endif
endfunction
endlibrary
I've attached a small testmap.
If you know ways to improve the script, i.e. some way of performance optimization or better approaches for the detection algorithm, please let me know and I will update it.
Attachments
Last edited: