JASS:
/*Utility Information
//===================================================================
Name: Bounds
Version: 1.2
Author: Sevion
Settings:
*/ //===================================================================
//! textmacro BOUNDS_BUFFER
private constant real BUFFER = 0.
//! endtextmacro
/* //===================================================================
Description: World bounds and buffer safety with inline friendly functions.
Requirements: None
Installation: (N/A)
Variables:
-BUFFER
The buffer distance from the actual world bounds and safety.
Set to 0. for no difference. Can be used Directly instead.
-World
The rect containing the world. Can be used Directly instead.
-WorldReg
The region containing the world. Can be used Directly instead.
-Max_X
The real comtaining the maximum X. Can be used Direclty instead.
-Min_X
The real comtaining the minimum X. Can be used Direclty instead.
-Max_Y
The real comtaining the maximum Y. Can be used Direclty instead.
-Min_Y
The real comtaining the minimum Y. Can be used Direclty instead.
Functions:
------------------------------------------------------------------
-Bs_IsPosSafe(x, y) returns boolean
Evaluates if the given x and y coordinates are within safety
range.
if Bs_IsPosSafe(GetUnitX(u), GetUnitY(u) then
-Bs_IsLocSafe(location) returns boolean
Evaluates if the given location is within safety range.
if Bs_isLocSafe(GetUnitLoc(u)) then
-Bs_SetUnitPosSafe(unit, x, y) returns nothing
Evaluates if the given x and y coordinates is within safety
range then sets the unit's position to that or displays a
debug error.
call Bs_SetUnitPosSafe(u, 0., 0.)
-Bs_SetUnitLocSafe(unit, location) returns nothing
Evaluates if the given location is within safety range
then sets the unit's location to that or displays a debug error.
call Bs_SetUnitLocSafe(u, Location(0, 0))
------------------------------------------------------------------*/
//===================================================================
library Bounds initializer Initialization
globals
public rect World
public region WorldReg
//! runtextmacro BOUNDS_BUFFER()
public real Max_X
public real Min_X
public real Max_Y
public real Min_Y
endglobals
public function IsPosSafe takes real x, real y returns boolean
return IsPointInRegion(WorldReg, x ,y)
endfunction
public function IsLocSafe takes location loc returns boolean
return IsLocationInRegion(WorldReg, loc)
endfunction
public function SetUnitPosSafe takes unit u, real x, real y returns nothing
if IsPointInRegion(WorldReg, x, y) then
call SetUnitPosition(u, x, y)
return
endif
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, SCOPE_PREFIX + "ERROR - Unsafe Pos!")
endfunction
public function SetUnitLocSafe takes unit u, location loc returns nothing
if IsLocationInRegion(WorldReg, loc) then
call SetUnitPositionLoc(u, loc)
return
endif
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, SCOPE_PREFIX + "ERROR - Unsafe Loc!")
endfunction
private function Initialization takes nothing returns nothing
set World = GetWorldBounds()
set Max_X = GetRectMaxX(World) - BUFFER
set Min_X = GetRectMinX(World) + BUFFER
set Max_Y = GetRectMaxY(World) - BUFFER
set Min_Y = GetRectMinY(World) + BUFFER
set WorldReg = CreateRegion()
call RegionAddRect(WorldReg, World)
endfunction
endlibrary