- Joined
- Mar 3, 2006
- Messages
- 1,564
This library will add some simple functions that will always inbound locations to the map. They are simple but may be useful.
JASS:
library BoundUtils initializer SetBoundary
/*
By: Starquizer
To implement it, simply copy the whole contents
of the library then paste it into an empty
converted-to-custom-text trigger.
To use it, use
call GetSpellTargetXBounded() instead of call GetSpellTargetX()
and
call GetSpellTargetYBounded() instead of call GetSpellTargetY()
also you have another two functions
GetBoundedX and GetBoundedY, those will inbound your x and y to the map.
*/
globals
public real MIN_X
public real MIN_Y
public real MAX_X
public real MAX_Y
public real MAP_MIN_X
public real MAP_MIN_Y
public real MAP_MAX_X
public real MAP_MAX_Y
private constant real SAFETY_OFFSET = 8.00
endglobals
private function SetBoundary takes nothing returns nothing
local rect map = GetWorldBounds()
set MIN_X = GetCameraBoundMinX() - 512.000
set MIN_Y = GetCameraBoundMinY() - 256.000
set MAX_X = GetCameraBoundMaxX() + 512.000
set MAX_Y = GetCameraBoundMaxY() + 256.000
set MAP_MIN_X = GetRectMinX(map)
set MAP_MAX_X = GetRectMaxX(map)
set MAP_MIN_Y = GetRectMinY(map)
set MAP_MAX_Y = GetRectMaxY(map)
set map = null
endfunction
function GetSpellTargetXBounded takes nothing returns real
local real x = GetSpellTargetX()
if x < MIN_X then
return MIN_X + SAFETY_OFFSET
elseif x > MAX_X then
return MAX_X - SAFETY_OFFSET
else
return x
endif
endfunction
function GetSpellTargetYBounded takes nothing returns real
local real y = GetSpellTargetY()
if y < MIN_Y then
return MIN_Y + SAFETY_OFFSET
elseif y > MAX_Y then
return MAX_Y - SAFETY_OFFSET
else
return y
endif
endfunction
function GetBoundedX takes real x returns real
if x < MAP_MIN_X then
return MAP_MIN_X + SAFETY_OFFSET
elseif x > MAP_MAX_X then
return MAP_MAX_X - SAFETY_OFFSET
else
return x
endif
endfunction
function GetBoundedY takes real y returns real
if y < MAP_MIN_Y then
return MAP_MIN_Y + SAFETY_OFFSET
elseif y > MAP_MAX_Y then
return MAP_MAX_Y - SAFETY_OFFSET
else
return y
endif
endfunction
function SetUnitXBounded takes unit u, real x returns nothing
if x < MAP_MIN_X then
call SetUnitX(u,MAP_MIN_X + SAFETY_OFFSET)
elseif x > MAP_MAX_X then
call SetUnitX(u,MAP_MAX_X - SAFETY_OFFSET)
else
call SetUnitX(u,x)
endif
endfunction
function SetUnitYBounded takes unit u, real y returns nothing
if y < MAP_MIN_Y then
call SetUnitY(u,MAP_MIN_Y + SAFETY_OFFSET)
elseif y > MAP_MAX_Y then
call SetUnitY(u,MAP_MAX_Y - SAFETY_OFFSET)
else
call SetUnitY(u,y)
endif
endfunction
endlibrary
Last edited: