scope Teleporters
globals
private unit array building [12] [3]
private real array X [12] [3]
private real array Y [12] [3]
private integer array count
private texttag array indicator [12] [3]
private group gr = CreateGroup()
endglobals
function SetTeleporsAvailable takes integer i returns nothing
if count[i] >= 2 then
call SetPlayerAbilityAvailable( Player(i), 'A027', true)
else
call SetPlayerAbilityAvailable( Player(i), 'A027', false)
endif
if count[i] >= 3 then
call SetPlayerAbilityAvailable( Player(i), 'A028', true)
else
call SetPlayerAbilityAvailable( Player(i), 'A028', false)
endif
endfunction
function Trig_Teleporter_Building_Conditions takes nothing returns boolean
local unit str = GetConstructedStructure()
local integer i
if GetUnitTypeId(str) == 'n00W' then
set i = GetPlayerId(GetOwningPlayer(str))
set building[i][count[i]] = str
set X[i][count[i]] = GetUnitX(str)
set Y[i][count[i]] = GetUnitY(str)
set indicator[i][count[i]] = CreateTextTag()
call SetTextTagText( indicator[i][count[i]], I2S(count[i]+1), 1.5*0.023 )
call SetTextTagPos( indicator[i][count[i]], X[i][count[i]], Y[i][count[i]], 100 )
call SetTextTagColor( indicator[i][count[i]], 75, 60, 60, 50 )
set count[i] = count[i] + 1
endif
call SetTeleporsAvailable(i)
set str = null
return false
endfunction
function Teleporter_Death takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer i
local integer j
local boolean b = false
if GetUnitTypeId(u) == 'n00W' then
set i = GetPlayerId(GetOwningPlayer(u))
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", u, "overhead"))
set j = 0
loop
exitwhen j > count[i]
if building[i][j] == u then
set b = true
call DestroyTextTag(indicator[i][j])
endif
if b then
if j != count[i] then
set building[i][j] = building[i][j+1]
set X[i][j] = X[i][j+1]
set Y[i][j] = Y[i][j+1]
set indicator[i][j] = indicator[i][j+1]
call SetTextTagText( indicator[i][j], I2S(j+1), 1.5* 0.023 )
call SetTextTagPos( indicator[i][j], X[i][j], Y[i][j], 100 )
else
set building[i][j] = null
set indicator[i][j] = null
set count[i] = count[i] - 1
endif
endif
set j = j + 1
endloop
call SetTeleporsAvailable(i)
endif
return false
endfunction
private struct TeleData
player p
unit u
integer i
group g
integer c
real x
real y
integer t
static method create takes unit u, integer abil returns TeleData
local TeleData TD = TeleData.allocate()
set TD.u = u
set TD.p = GetOwningPlayer(u)
set TD.i = GetPlayerId(TD.p)
set TD.g = CreateGroup()
set TD.x = GetUnitX(u)
set TD.y = GetUnitY(u)
set TD.c = 2
if u != building[TD.i][0] and abil == 1 then
set TD.t = 0
elseif u != building[TD.i][2] and abil == 2 then
set TD.t = 2
else
set TD.t = 1
endif
return TD
endmethod
method onDestroy takes nothing returns nothing
local unit u
loop
set u = FirstOfGroup(.g)
exitwhen u == null
call RemoveSavedBoolean(udg_Unit_Table, GetHandleId(u), 'tptd')
call GroupRemoveUnit(.g, u)
endloop
call DestroyGroup(.g)
endmethod
endstruct
function TeleLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local TeleData TD = LoadInteger(udg_Table, GetHandleId(t), 'tpst')
local unit FoG
local real x
local real y
call GroupEnumUnitsInRange(gr, TD.x, TD.y, I2R(TD.c)*100.00, null)
loop
set FoG = FirstOfGroup(gr)
exitwhen FoG == null
if IsUnitAliveBJ(FoG) and IsUnitAlly(FoG, TD.p) and not IsUnitType(FoG, UNIT_TYPE_STRUCTURE) and not LoadBoolean(udg_Unit_Table, GetHandleId(FoG), 'tptd') then
set x = GetUnitX(FoG)
set y = GetUnitY(FoG)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", x, y))
set x = X[TD.i][TD.t] + (x - TD.x)/2
set y = Y[TD.i][TD.t] + (y - TD.y)/2
call SetUnitX(FoG, x)
call SetUnitY(FoG, y)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", x, y))
call GroupAddUnit(TD.g, FoG)
call SaveBoolean(udg_Unit_Table, GetHandleId(FoG), 'tptd', true)
endif
call GroupRemoveUnit(gr, FoG)
endloop
if TD.c >= 5 then
call RecTimer(t)
call TeleData.destroy(TD)
else
set TD.c = TD.c + 1
endif
set t = null
endfunction
function Teleport_1 takes nothing returns boolean
local timer t
local unit FoG
local TeleData TD
local real x
local real y
local integer abil = GetSpellAbilityId()
if abil == 'A027' or abil == 'A028' then
if abil == 'A027' then
set TD = TD.create(GetTriggerUnit(),1)
else
set TD = TD.create(GetTriggerUnit(),2)
endif
set t = GetFreeTimer()
call SaveInteger(udg_Table, GetHandleId(t), 'tpst', TD)
call GroupEnumUnitsInRange( gr, TD.x, TD.y, 100.00, null)
loop
set FoG = FirstOfGroup(gr)
exitwhen FoG == null
if IsUnitAliveBJ(FoG) and IsUnitAlly(FoG, TD.p) and not IsUnitType(FoG, UNIT_TYPE_STRUCTURE) and not LoadBoolean(udg_Unit_Table, GetHandleId(FoG), 'tptd') then
set x = GetUnitX(FoG)
set y = GetUnitY(FoG)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", x, y))
set x = X[TD.i][TD.t] + (x - TD.x)/2
set y = Y[TD.i][TD.t] + (y - TD.y)/2
call SetUnitX(FoG, x)
call SetUnitY(FoG, y)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", x, y))
call GroupAddUnit(TD.g, FoG)
call SaveBoolean(udg_Unit_Table, GetHandleId(FoG), 'tptd', true)
endif
call GroupRemoveUnit(gr, FoG)
endloop
call TimerStart(t, 0.5, true, function TeleLoop)
set t = null
endif
return false
endfunction
//===========================================================================
function InitTrig_Teleporters takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
set gg_trg_Teleporters = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Teleporters, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition( gg_trg_Teleporters, Condition( function Trig_Teleporter_Building_Conditions ) )
call TriggerRegisterAnyUnitEventBJ( t , EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t , Condition( function Teleporter_Death ) )
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Teleport_1 ) )
loop
exitwhen i > 11
set count[i] = 0
set i = i + 1
endloop
set t = null
endfunction
endscope