//===============================================
// System Configuration
//===============================================
//-----------------------------------------------
// Dummy Fly Ability for ground units
//
// This ability is needed to make ground units appear
// flying.
//-----------------------------------------------
constant function LS_DUMMY_FLY_ABILITY takes nothing returns integer
return 'A000'
endfunction
//-----------------------------------------------
// Pointer to the system hashtable
//
// Example: hashtable "udg_LevitationVars".
// Replace with desired global hashtable here.
//-----------------------------------------------
function LS_DATABASE takes nothing returns hashtable
return udg_LevitationVars
endfunction
function CreateLeviSystemTable takes nothing returns nothing
set udg_LevitationVars = InitHashtable()
endfunction
//-----------------------------------------------
// Static keys
//
// Must be UNIQUE integers and not overlap
// with other table PARENT keys.
//-----------------------------------------------
// parent keys
constant function LS_TRIGGER_KEY takes nothing returns integer
return 1
endfunction
constant function LS_REGION_KEY takes nothing returns integer
return 2
endfunction
constant function LS_REGION_E_TRIGGER_KEY takes nothing returns integer
return 3
endfunction
constant function LS_REGION_L_TRIGGER_KEY takes nothing returns integer
return 4
endfunction
constant function LS_REGION_RECT_KEY takes nothing returns integer
return 5
endfunction
constant function LS_UNIT_KEY takes nothing returns integer
return 6
endfunction
constant function LS_ELEVATION_SPEED_KEY takes nothing returns integer
return 7
endfunction
constant function LS_UTIL_VARIABLES_KEY takes nothing returns integer
return 8
endfunction
// child keys
constant function LS_GROUP_VAR_KEY takes nothing returns integer
return 1
endfunction
constant function LS_LOCATION_VAR_KEY takes nothing returns integer
return 2
endfunction
// constant dummy
constant function LS_TRUE takes nothing returns boolean
return true
endfunction
//===============================================
// System Core components
//===============================================
//-----------------------------------------------
// DB interface
//
// Do not modify or use without full understanding of the
// system's operations.
//-----------------------------------------------
// -- binds a region with 2 triggers
function LSSetRegion takes rect r,trigger t, trigger t2 returns nothing
call SaveRectHandle(LS_DATABASE(),GetHandleId(t),LS_REGION_KEY(),r)
call SaveTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_E_TRIGGER_KEY(),t)
call SaveTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_L_TRIGGER_KEY(),t2)
endfunction
// -- returns an elevation region controlled by the trigger
function LSGetRegion takes trigger t returns rect
return LoadRectHandle(LS_DATABASE(),GetHandleId(t),LS_REGION_KEY())
endfunction
// -- getters for elevation triggers attached to region
function LSGetEnterTriggerOfRegion takes rect r returns trigger
return LoadTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_E_TRIGGER_KEY())
endfunction
function LSGetLeaveTriggerOfRegion takes rect r returns trigger
return LoadTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_L_TRIGGER_KEY())
endfunction
// -- region elevation height accessors
function LSSetRegionHeightByTrigger takes trigger t, real h returns nothing
call SaveReal(LS_DATABASE(),GetHandleId(t),LS_TRIGGER_KEY(),h)
endfunction
function LSGetRegionHeightByTrigger takes trigger t returns real
return LoadReal(LS_DATABASE(),GetHandleId(t),LS_TRIGGER_KEY())
endfunction
function LSSetRegionHeight takes rect r, real h returns nothing
call LSSetRegionHeightByTrigger(LSGetEnterTriggerOfRegion(r),h)
endfunction
function LSGetRegionHeight takes rect r returns real
return LSGetRegionHeightByTrigger(LSGetEnterTriggerOfRegion(r))
endfunction
// -- region elevation speed accessors
function LSGetRegionElevationSpeedByTrigger takes trigger t returns real
return LoadReal(LS_DATABASE(),GetHandleId(t),LS_ELEVATION_SPEED_KEY())
endfunction
function LSSetRegionElevationSpeedByTrigger takes trigger t, real s returns nothing
call SaveReal(LS_DATABASE(),GetHandleId(t),LS_ELEVATION_SPEED_KEY(),s)
endfunction
function LSGetRegionRisingElevationSpeed takes rect r returns real
return LSGetRegionElevationSpeedByTrigger(LSGetEnterTriggerOfRegion(r))
endfunction
function LSSetRegionRisingElevationSpeed takes rect r, real s returns nothing
call LSSetRegionElevationSpeedByTrigger(LSGetEnterTriggerOfRegion(r),s)
endfunction
function LSGetRegionFallingElevationSpeed takes rect r returns real
return LSGetRegionElevationSpeedByTrigger(LSGetLeaveTriggerOfRegion(r))
endfunction
function LSSetRegionFallingElevationSpeed takes rect r, real s returns nothing
call LSSetRegionElevationSpeedByTrigger(LSGetLeaveTriggerOfRegion(r),s)
endfunction
// -- dummy region creation
function LSCreateRegionFromRect takes rect r,region r1 returns nothing
call RegionAddRect(r1,r)
call SaveRegionHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_RECT_KEY(),r1)
endfunction
function LSGetRegionFromRect takes rect r returns region
return LoadRegionHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_RECT_KEY())
endfunction
// -- cleanups
function LSFlushTriggerData takes trigger t returns nothing
call SaveReal(LS_DATABASE(),GetHandleId(t),LS_TRIGGER_KEY(),0)
call SaveRectHandle(LS_DATABASE(),GetHandleId(t),LS_REGION_KEY(),null)
call FlushChildHashtable(LS_DATABASE(),GetHandleId(t))
endfunction
function LSFlushRegionData takes rect r returns nothing
call SaveTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_E_TRIGGER_KEY(),null)
call SaveTriggerHandle(LS_DATABASE(),GetHandleId(r),LS_REGION_L_TRIGGER_KEY(),null)
call FlushChildHashtable(LS_DATABASE(),GetHandleId(r))
endfunction
// group recycle
function LSGroup takes nothing returns group
return LoadGroupHandle(LS_DATABASE(),LS_UTIL_VARIABLES_KEY(),LS_GROUP_VAR_KEY())
endfunction
//-----------------------------------------------
// Setting unit heights
//
// Those methods are used by the system, do not
// modify without full knowledge of the system's
// operations.
//
// Can probably apply those methods outside the
// system as well.
//-----------------------------------------------
//-----------------------------------------
// Height modification for single units
//-----------------------------------------
function LSResetUnitHeight takes unit u returns nothing
if not IsUnitType(u, UNIT_TYPE_FLYING) then
call UnitAddAbility(u, LS_DUMMY_FLY_ABILITY())
call UnitRemoveAbility(u, LS_DUMMY_FLY_ABILITY())
endif
call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u),0)
endfunction
function LSSetUnitHeight takes unit u, real h returns nothing
if not IsUnitType(u, UNIT_TYPE_FLYING) then
call UnitAddAbility(u, LS_DUMMY_FLY_ABILITY())
call UnitRemoveAbility(u, LS_DUMMY_FLY_ABILITY())
endif
call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u)+h,0)
endfunction
function LSResetUnitHeightTimed takes unit u, real speed returns nothing
if not IsUnitType(u, UNIT_TYPE_FLYING) then
call UnitAddAbility(u, LS_DUMMY_FLY_ABILITY())
call UnitRemoveAbility(u, LS_DUMMY_FLY_ABILITY())
endif
call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u),speed)
endfunction
function LSSetUnitHeightTimed takes unit u, real h, real speed returns nothing
if not IsUnitType(u, UNIT_TYPE_FLYING) then
call UnitAddAbility(u, LS_DUMMY_FLY_ABILITY())
call UnitRemoveAbility(u, LS_DUMMY_FLY_ABILITY())
endif
call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u)+h,speed)
endfunction
//-----------------------------------------
// Height modification for all units in rect
//-----------------------------------------
function LS_RESETHEIGHTENUM takes nothing returns nothing
call LSResetUnitHeight(GetEnumUnit())
endfunction
function LSResetAllUnitsHeight takes rect r returns nothing
local group g = LSGroup()
local conditionfunc LSAlwaysTrue = Condition(function LS_TRUE)
call GroupEnumUnitsInRect(g,r,LSAlwaysTrue )
call ForGroup( g, function LS_RESETHEIGHTENUM )
call DestroyBoolExpr(LSAlwaysTrue)
set LSAlwaysTrue = null
set g = null
endfunction
function LS_SETHEIGHTENUM takes nothing returns nothing
call LSSetUnitHeight(GetEnumUnit(),bj_enumDestructableRadius)
endfunction
function LSSetAllUnitsHeight takes rect r, real h returns nothing
local group g = LSGroup()
local conditionfunc LSAlwaysTrue = Condition(function LS_TRUE)
set bj_enumDestructableRadius = h
call GroupEnumUnitsInRect(g,r, LSAlwaysTrue )
call ForGroup( g, function LS_SETHEIGHTENUM )
call DestroyBoolExpr(LSAlwaysTrue)
set LSAlwaysTrue = null
set g = null
endfunction
//-----------------------------------------------
// TriggerActions for region entry/leave
//
// Used by the triggers responsible for elevation.
//-----------------------------------------------
function Unit_Enteres_LS_Region_Actions takes nothing returns nothing
call LSSetUnitHeightTimed(GetTriggerUnit(),LSGetRegionHeightByTrigger(GetTriggeringTrigger()),LSGetRegionElevationSpeedByTrigger(GetTriggeringTrigger()))
endfunction
function Unit_Leaves_LS_Region_Actions takes nothing returns nothing
call LSResetUnitHeightTimed(GetTriggerUnit(),LSGetRegionElevationSpeedByTrigger(GetTriggeringTrigger()))
endfunction
//===============================================
// System Front End Interface
//===============================================
//
// create/add/remove/destroy/enable/disable
// levitation regions
//
// Warning: must call LSAddRegion() or LSCreateRegion()
// before doing any other operations.
//
// Parameters:
//
// Region r - the region that is to be used for levitation.
// Real h - the levitation height of a region.
//
// Real x1,y1,x2,y2 - used for creating regions.
//
//-----------------------------------------------
// Toggle unit enters levitation region event on or off
function LSToggleRegionEnterEvent takes rect r, boolean b returns nothing
local trigger t = LSGetEnterTriggerOfRegion(r)
if (b) then
call EnableTrigger(t)
call LSSetAllUnitsHeight(r,LSGetRegionHeightByTrigger(t))
else
call DisableTrigger(t)
endif
set t = null
endfunction
// Toggle unit leaves levitation region event on or off
function LSToggleRegionLeaveEvent takes rect r, boolean b returns nothing
local trigger t = LSGetLeaveTriggerOfRegion(r)
if (b) then
call EnableTrigger(t)
else
call DisableTrigger(t)
endif
set t = null
endfunction
// Turn levitation region on
function LSEnableRegion takes rect r returns nothing
call EnableTrigger(LSGetEnterTriggerOfRegion(r))
call EnableTrigger(LSGetLeaveTriggerOfRegion(r))
call LSSetAllUnitsHeight(r,LSGetRegionHeight(r))
endfunction
// Turn levitation region off
function LSDisableRegion takes rect r returns nothing
call DisableTrigger(LSGetEnterTriggerOfRegion(r))
call DisableTrigger(LSGetLeaveTriggerOfRegion(r))
call LSResetAllUnitsHeight(r)
endfunction
function LSRegionIsOn takes rect r returns boolean
return IsTriggerEnabled(LSGetEnterTriggerOfRegion(r)) or IsTriggerEnabled(LSGetLeaveTriggerOfRegion(r))
endfunction
function LSRegionEnterTriggerIsOn takes rect r returns boolean
return IsTriggerEnabled(LSGetEnterTriggerOfRegion(r))
endfunction
function LSRegionLeaveTriggerIsOn takes rect r returns boolean
return IsTriggerEnabled(LSGetLeaveTriggerOfRegion(r))
endfunction
//--------------------------------------
// Set levitation region levitation height
function LSSetHeight takes rect r, real h returns nothing
call LSDisableRegion(r)
call LSSetRegionHeightByTrigger(LSGetEnterTriggerOfRegion(r),h)
call LSSetRegionHeightByTrigger(LSGetLeaveTriggerOfRegion(r),h)
call LSEnableRegion(r)
endfunction
function LSGetHeight takes rect r returns real
return LSGetRegionHeight(r)
endfunction
function LSSetRisingSpeed takes rect r, real s returns nothing
call LSSetRegionRisingElevationSpeed(r,s)
endfunction
function LSSetFallingSpeed takes rect r, real s returns nothing
call LSSetRegionFallingElevationSpeed(r,s)
endfunction
function LSGetRisingSpeed takes rect r returns real
return LSGetRegionRisingElevationSpeed(r)
endfunction
function LSGetFallingSpeed takes rect r returns real
return LSGetRegionFallingElevationSpeed(r)
endfunction
// destroys a levitation region (does not actually destroy the
// region itself)
function LSDestroyRegion takes rect r returns nothing
local trigger t = LSGetEnterTriggerOfRegion(r)
local trigger t2 = LSGetLeaveTriggerOfRegion(r)
local region r1 = LSGetRegionFromRect(r)
call LSFlushTriggerData(t)
call LSFlushTriggerData(t2)
call LSFlushRegionData(r)
call DisableTrigger(t)
call DisableTrigger(t2)
call DestroyTrigger(t)
call DestroyTrigger(t2)
call RemoveRegion(r1)
call LSResetAllUnitsHeight(r)
set r1 = null
set t = null
set t2 = null
endfunction
// adds and enables region for levitation
function LSAddRegion takes rect r, real h returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local region r1 = CreateRegion()
// events here
call LSCreateRegionFromRect(r,r1) // also defines r1 from r
call TriggerRegisterEnterRegion(t1,r1,null)
call TriggerRegisterLeaveRegion(t2,r1,null)
// conditions here
// trigger actions here
call TriggerAddAction( t1, function Unit_Enteres_LS_Region_Actions )
call TriggerAddAction( t2, function Unit_Leaves_LS_Region_Actions )
call LSSetRegion(r,t1,t2)
call LSSetRegionHeightByTrigger(t1,h)
call LSSetRegionHeightByTrigger(t2,h)
call LSSetRegionElevationSpeedByTrigger(t1,0)
call LSSetRegionElevationSpeedByTrigger(t2,0)
call LSEnableRegion(r)
set r1 = null
set t1 = null
set t2 = null
endfunction
//creates a region for levitation
function LSCreateRegion takes real x1, real y1,real x2, real y2, real h returns rect
set bj_isUnitGroupInRectRect = Rect(x1, y1, x2, y2)
call LSAddRegion(bj_isUnitGroupInRectRect,h)
return bj_isUnitGroupInRectRect
endfunction
//===========================================================================
function InitTrig_Levitation_System_JassGui takes nothing returns nothing
local group g = CreateGroup()
call CreateLeviSystemTable()
call SaveGroupHandle(LS_DATABASE(),LS_UTIL_VARIABLES_KEY(),LS_GROUP_VAR_KEY(),g)
set g = null
endfunction