Name | Type | is_array | initial_value |
TunnelAbil | abilcode | No | A000 |
TunnelAllowFlying | boolean | No | |
TunnelDelay | real | No | 1.00 |
TunnelHashtable | hashtable | No | |
TunnelRange | real | No | 72.00 |
TunnelSfx | string | No | Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdx |
// REMOVE EXIT DATA FROM ENTRANCE
function RemoveExit takes integer entranceId, boolean kill returns nothing
local trigger trg = null
// Kill exit
if kill and HaveSavedHandle(udg_TunnelHashtable, entranceId, 0) then
call KillUnit(LoadUnitHandle(udg_TunnelHashtable, entranceId, 0))
endif
if HaveSavedHandle(udg_TunnelHashtable, entranceId, 1) then
// Destroy unit in range trigger
set trg = LoadTriggerHandle(udg_TunnelHashtable, entranceId, 1)
call FlushChildHashtable(udg_TunnelHashtable, GetHandleId(trg))
call DestroyTrigger(trg)
set trg = null
endif
call FlushChildHashtable(udg_TunnelHashtable, entranceId)
endfunction
// SHOW UNIT AT EXIT
function Tunnel__ExitUnit_Conditions takes nothing returns boolean
local trigger trg = GetTriggeringTrigger()
local integer trgId = GetHandleId(trg)
local unit trgUnit = LoadUnitHandle(udg_TunnelHashtable, trgId, 0)
local effect sfx = null
// Create sfx
if StringLength(udg_TunnelSfx) > 0 then
set sfx = AddSpecialEffectTarget(udg_TunnelSfx, trgUnit, "origin")
call DestroyEffect(sfx)
set sfx = null
endif
call DestroyTrigger(trg)
call FlushChildHashtable(udg_TunnelHashtable, trgId)
set trg = null
// Show unit
call ShowUnit(trgUnit, true)
set trgUnit = null
return false
endfunction
// FILTER FOR UNIT IN RANGE OF ENTRANCE
function Tunnel__EntranceEnter_Filter takes nothing returns boolean
// Filter flying units
return udg_TunnelAllowFlying or not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)
endfunction
// UNIT IN RANGE OF ENTRANCE
function Tunnel__EntranceEnter_Conditions takes nothing returns boolean
local unit trgUnit = GetTriggerUnit()
local unit entrance = LoadUnitHandle(udg_TunnelHashtable, GetHandleId(GetTriggeringTrigger()), 0)
local integer entranceId = GetHandleId(entrance)
local unit exit = null
local trigger trg = null
local effect sfx = null
if GetOwningPlayer(trgUnit) == GetOwningPlayer(entrance) and HaveSavedHandle(udg_TunnelHashtable, entranceId, 0) then
// Create sfx
if StringLength(udg_TunnelSfx) > 0 then
set sfx = AddSpecialEffect(udg_TunnelSfx, GetUnitX(trgUnit), GetUnitY(trgUnit))
call DestroyEffect(sfx)
set sfx = null
endif
// Hide unit and move
set exit = LoadUnitHandle(udg_TunnelHashtable, entranceId, 0)
call ShowUnit(trgUnit, false)
call SetUnitPosition(trgUnit, GetUnitX(exit), GetUnitY(exit))
set exit = null
// Timeout trigger for unit show
set trg = CreateTrigger()
call SaveUnitHandle(udg_TunnelHashtable, GetHandleId(trg), 0, trgUnit)
call TriggerRegisterTimerEvent(trg, udg_TunnelDelay, false)
call TriggerAddCondition(trg, Condition(function Tunnel__ExitUnit_Conditions))
set trg = null
endif
set trgUnit = null
set entrance = null
return false
endfunction
// ENTRANCE DEAD
function Tunnel__EntranceDeath_Conditions takes nothing returns boolean
// Remove exit data
call RemoveExit(GetHandleId(GetDyingUnit()), true)
call DestroyTrigger(GetTriggeringTrigger())
return false
endfunction
// EXIT FINISHED, DEAD, OR CANCELLED
function Tunnel__Exit_Conditions takes nothing returns boolean
local unit exit = GetConstructedStructure()
local unit entrance = null
local integer exitId
local trigger trg = null
// Construction finished
if exit != null then
set exitId = GetHandleId(exit)
if HaveSavedHandle(udg_TunnelHashtable, exitId, 0) then
set entrance = LoadUnitHandle(udg_TunnelHashtable, exitId, 0)
// Create unit in range trigger
set trg = CreateTrigger()
call SaveTriggerHandle(udg_TunnelHashtable, GetHandleId(entrance), 1, trg)
call SaveUnitHandle(udg_TunnelHashtable, GetHandleId(trg), 0, entrance)
call TriggerRegisterUnitInRange(trg, entrance, udg_TunnelRange, Filter(function Tunnel__EntranceEnter_Filter))
call TriggerAddCondition(trg, Condition(function Tunnel__EntranceEnter_Conditions))
set entrance = null
set trg = null
endif
// Exit dead or cancelled
else
set exit = GetDyingUnit()
if exit == null then
set exit = GetCancelledStructure()
endif
set exitId = GetHandleId(exit)
call DestroyTrigger(GetTriggeringTrigger())
if HaveSavedHandle(udg_TunnelHashtable, exitId, 0) then
set entrance = LoadUnitHandle(udg_TunnelHashtable, exitId, 0)
// Remove exit data from entrance and add ability back
call RemoveExit(GetHandleId(entrance), false)
call UnitAddAbility(entrance, udg_TunnelAbil)
set entrance = null
endif
call FlushChildHashtable(udg_TunnelHashtable, exitId)
endif
set exit = null
return false
endfunction
// BUILD EXIT TIMEOUT
function Tunnel__ExitTimeout_Conditions takes nothing returns boolean
local trigger trg = GetTriggeringTrigger()
local integer trgId = GetHandleId(trg)
local group grp = CreateGroup()
local unit entrance = null
local unit exit = null
call DestroyTrigger(trg)
set trg = null
// Get Exit
call GroupEnumUnitsInRangeCounted(grp, LoadReal(udg_TunnelHashtable, trgId, 0), LoadReal(udg_TunnelHashtable, trgId, 1), 0, null, 1)
set exit = FirstOfGroup(grp)
call DestroyGroup(grp)
set grp = null
if exit != null then
set entrance = LoadUnitHandle(udg_TunnelHashtable, trgId, 2)
if GetOwningPlayer(entrance) == GetOwningPlayer(exit) then
// Save unit ids
call SaveUnitHandle(udg_TunnelHashtable, GetHandleId(entrance), 0, exit)
call SaveUnitHandle(udg_TunnelHashtable, GetHandleId(exit), 0, entrance)
// Remove Tunnel ability and add death triggers
call UnitRemoveAbility(entrance, udg_TunnelAbil)
set trg = CreateTrigger()
call TriggerRegisterUnitEvent(trg, entrance, EVENT_UNIT_DEATH)
call TriggerAddCondition(trg, Condition(function Tunnel__EntranceDeath_Conditions))
set trg = CreateTrigger()
call TriggerRegisterUnitEvent(trg, exit, EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(trg, exit, EVENT_UNIT_CONSTRUCT_CANCEL)
call TriggerRegisterUnitEvent(trg, exit, EVENT_UNIT_CONSTRUCT_FINISH)
call TriggerAddCondition(trg, Condition(function Tunnel__Exit_Conditions))
set trg = null
endif
set entrance = null
set exit = null
endif
call FlushChildHashtable(udg_TunnelHashtable, trgId)
return false
endfunction
// FILTER TO UNITS WITH TUNNEL ABIL
function Trig_Tunnel_Filter takes nothing returns boolean
return GetUnitAbilityLevel(GetFilterUnit(), udg_TunnelAbil) > 0
endfunction
// BUILD EXIT SPELL CAST
function Trig_Tunnel_Conditions takes nothing returns boolean
local trigger trg = null
local integer trgId
if GetSpellAbilityId() == udg_TunnelAbil then
set trg = CreateTrigger()
set trgId = GetHandleId(trg)
// Save coordinates and entrance unit
call SaveReal(udg_TunnelHashtable, trgId, 0, GetSpellTargetX())
call SaveReal(udg_TunnelHashtable, trgId, 1, GetSpellTargetY())
call SaveUnitHandle(udg_TunnelHashtable, trgId, 2, GetSpellAbilityUnit())
// Timeout for exit construction to start
call TriggerRegisterTimerEvent(trg, 0, false)
call TriggerAddCondition(trg, Condition(function Tunnel__ExitTimeout_Conditions))
set trg = null
endif
return false
endfunction
//===========================================================================
function InitTrig_Tunnel takes nothing returns nothing
local integer i = 0
set gg_trg_Tunnel = CreateTrigger()
set udg_TunnelHashtable = InitHashtable()
loop
call TriggerRegisterPlayerUnitEvent(gg_trg_Tunnel, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Filter(function Trig_Tunnel_Filter))
set i = i+1
exitwhen i == bj_MAX_PLAYERS
endloop
call TriggerAddCondition(gg_trg_Tunnel, Condition(function Trig_Tunnel_Conditions))
endfunction