- Joined
- Apr 24, 2012
- Messages
- 5,113
I found out Vexorian's Bound Sentinel somewhat slow and use TriggerAddAction.
So i coded my own version from it.
Credits to Vexorian.
Vexorian's original BoundSentinel ( see comparison)
So i coded my own version from it.
Credits to Vexorian.
JASS:
/************************************************************************
*
*
* Bound Sentinel
*
* by: Almia
*
* - Keeps all units exceeding the map bounds
* inside the playable map area.
*
* - Not guaranteed to keep units that are created
* outside the map bounds.
*
*
************************************************************************
*
* Credits
*
* Vexorian for the Bound Sentinel Lib.
*
************************************************************************/
library BoundSentinelEx
globals
private real minX
private real minY
private real maxX
private real maxY
endglobals
/**************************************************
*
* On Leave
*
* - this function maintains the units
* inside the map.
*
* - Run via TriggerRegisterLeaveRegion event.
*
**************************************************/
private function OnLeave takes nothing returns boolean
local unit u = GetTriggerUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
if x > maxX then
set x = maxX
elseif x < minX then
set x = minX
endif
if y > maxY then
set y = maxY
elseif y < minY then
set y = minY
endif
call SetUnitX(u, x)
call SetUnitY(u, y)
set u = null
return false
endfunction
private module Init
static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
/**************************************************
*
* BSInit
*
* - struct for initialization
*
* - the init method initializes the
* the LeaveRegion event and the
* map bounds.
*
**************************************************/
private struct BSInit extends array
static method init takes nothing returns nothing
local trigger t = CreateTrigger()
local region r = CreateRegion()
set minX = GetRectMinX(bj_mapInitialPlayableArea)
set minY = GetRectMinY(bj_mapInitialPlayableArea)
set maxX = GetRectMaxX(bj_mapInitialPlayableArea)
set maxY = GetRectMaxY(bj_mapInitialPlayableArea)
call RegionAddRect(r, bj_mapInitialPlayableArea)
call TriggerRegisterLeaveRegion(t, r, null)
call TriggerAddCondition(t, Filter(function OnLeave))
set t = null
set r = null
endmethod
implement Init
endstruct
endlibrary
Vexorian's original BoundSentinel ( see comparison)
JASS:
library BoundSentinel initializer init
//*************************************************
//* BoundSentinel
//* -------------
//* Don't leave your units unsupervised, naughty
//* them may try to get out of the map bounds and
//* crash your game.
//*
//* To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//*************************************************
//==================================================
globals
// High enough so the unit is no longer visible, low enough so the
// game doesn't crash...
//
// I think you need 0.0 or soemthing negative prior to patch 1.22
//
private constant real EXTRA = 500.0
endglobals
//=========================================================================================
globals
private real maxx
private real maxy
private real minx
private real miny
endglobals
//=======================================================================
private function dis takes nothing returns nothing
local unit u=GetTriggerUnit()
local real x=GetUnitX(u)
local real y=GetUnitY(u)
if(x>maxx) then
set x=maxx
elseif(x<minx) then
set x=minx
endif
if(y>maxy) then
set y=maxy
elseif(y<miny) then
set y=miny
endif
call SetUnitX(u,x)
call SetUnitY(u,y)
set u=null
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local region r=CreateRegion()
local rect rc
set minx=GetCameraBoundMinX() - EXTRA
set miny=GetCameraBoundMinY() - EXTRA
set maxx=GetCameraBoundMaxX() + EXTRA
set maxy=GetCameraBoundMaxY() + EXTRA
set rc=Rect(minx,miny,maxx,maxy)
call RegionAddRect(r, rc)
call RemoveRect(rc)
call TriggerRegisterLeaveRegion(t,r, null)
call TriggerAddAction(t, function dis)
//this is not necessary but I'll do it anyway:
set t=null
set r=null
set rc=null
endfunction
endlibrary