scope submerge initializer i
private struct submergeDat
unit caster
integer steps
endstruct
globals
private constant integer SPELCODE='A05H' //Spellcode of submerge
private constant integer BIRDCODE='Amrf' //Abilitycode of Crow form
private constant integer STARTVEC=25 //Starting vector amount for steps. Higher makes the ship shoot higher out of the water, and takes longer before becoming invisible
private constant integer DUMMCODE='h00S' //Unitcode of Sunken Heavy
private constant real FIDELITY=1./30.
private submergeDat array submergeDB
private integer dbIndex=-1
private timer time=CreateTimer()
endglobals
private function movesC takes nothing returns boolean
local unit dummy=GetTriggerUnit()
local unit caster=Units_playerBoat[GetPlayerId(GetOwningPlayer(dummy))+1]
call SetUnitFlyHeight(caster,0.,0.)
call SetUnitInvulnerable(caster,false)
call PauseUnit(caster,false)
if GetLocalPlayer()==GetOwningPlayer(caster) then
call ClearSelection() //Instead of call SelectUnit(dummy,false)
call SelectUnit(caster,true)
endif
call SetUnitVertexColor(caster,255,255,255,255)
call RemoveUnit(dummy)
call DestroyTrigger(GetTriggeringTrigger())
return false
endfunction
private function after takes unit caster returns nothing
local trigger moves=CreateTrigger()
local unit sunkenDummy=CreateUnit(GetOwningPlayer(caster),DUMMCODE,0.,0.,GetUnitFacing(caster))
call SetUnitX(sunkenDummy,GetUnitX(caster))
call SetUnitY(sunkenDummy,GetUnitY(caster))
call PauseUnit(caster,true)
call SetUnitInvulnerable(caster,true)
call SetUnitFlyHeight(caster,3000.,0)
if GetLocalPlayer()==GetOwningPlayer(caster) then
call ClearSelection() //Using this instead of SelectUnit(caster,false)
call SelectUnit(sunkenDummy,true)
endif
call SetUnitVertexColor(caster,0,0,0,0)
call TriggerRegisterUnitEvent(moves,sunkenDummy,EVENT_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterUnitEvent(moves,sunkenDummy,EVENT_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterUnitEvent(moves,sunkenDummy,EVENT_UNIT_ISSUED_ORDER)
call TriggerAddCondition(moves,Condition(function movesC)) //Need a way to move caster through triggers..
set sunkenDummy=null
set moves=null
endfunction
private function p takes nothing returns nothing
local integer iLoop=0
local submergeDat tempDat
loop
exitwhen iLoop>dbIndex
set tempDat=submergeDB[iLoop]
call SetUnitFlyHeight(tempDat.caster,GetUnitFlyHeight(tempDat.caster)+tempDat.steps,0.)
set tempDat.steps=tempDat.steps-1
if tempDat.steps<-1*STARTVEC then
call after(tempDat.caster)
call tempDat.destroy()
set submergeDB[iLoop]=submergeDB[dbIndex]
set dbIndex=dbIndex-1
set iLoop=iLoop-1
if dbIndex==-1 then
call PauseTimer(time)
endif
endif
set iLoop=iLoop+1
endloop
endfunction
private function c takes nothing returns boolean
local submergeDat tempDat
local unit tU
if GetSpellAbilityId()==SPELCODE then
set tU=GetTriggerUnit()
if IsTerrainPathable(GetUnitX(tU),GetUnitY(tU),PATHING_TYPE_FLOATABILITY)==false then
set tempDat=submergeDat.create()
set tempDat.caster=tU
set tempDat.steps=STARTVEC-GetHeroLevel(tempDat.caster)/4
call UnitAddAbility(tempDat.caster,BIRDCODE)
call UnitRemoveAbility(tempDat.caster,BIRDCODE)
if dbIndex==-1 then
call TimerStart(time,FIDELITY,true,function p)
endif
set dbIndex=dbIndex+1
set submergeDB[dbIndex]=tempDat
else
call DisplayTextToPlayer(GetOwningPlayer(tU),0,0,"The water is not deep enough here!")
call UnitRemoveAbility(tU,SPELCODE)
call UnitAddAbility(tU,SPELCODE)
endif
set tU=null
endif
return false
endfunction
private function i takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function c))
set t=null
endfunction
endscope