library SPS
globals
constant real INTERVAL = 0.03
constant real PHeight = 50.
constant real CollisionSize = 96.
string ATTACH = "origin"
constant integer PARTICLE_ID = 'e000'
//boolexpr UnitDmg = Condition( function FilterUnit )
timer sps = CreateTimer()
integer SPSIndex = 0
SPS array temp_SPS
endglobals
//function FilterUnit takes nothing returns boolean
//return GetWidgetLife(GetFilterUnit()) > .405 and IsUnitEnemy(GetFilterUnit(),dat.p) and not ConvertUnitType(2)
//endfunction
struct SPS
unit u
unit u2
real s
real x
real y
real x2
real y2
real a
real dx
real dy
real z1
string sfxs2
effect sfx
effect sfx2
real dmg
boolean DamageDestructible
player p
attacktype atk
method onDestroy takes nothing returns nothing
call DestroyEffect( .sfx )
call DestroyEffect( .sfx2 )
set .sfx = null
set .sfx2 = null
call RemoveUnit( .u )
set .u = null
call UnitApplyTimedLife( .u2, 'BTLF', 1.0 )
set .u2 = null
if SPSIndex == 0 then
call PauseTimer( sps )
endif
endmethod
endstruct
function GetMoveX takes real s, real a returns real
return Cos(a)*s
endfunction
function GetMoveY takes real s, real a returns real
return Sin(a)*s
endfunction
//===============================================================
function move takes nothing returns nothing
local SPS dat
local real fh
local integer i = 0
loop
exitwhen i >= SPSIndex
set dat = temp_SPS[i]
call SetUnitPosition( dat.u, dat.x + dat.dx, dat.y + dat.dy )
set dat.x = GetUnitX( dat.u )
set dat.y = GetUnitY( dat.u )
call SetUnitFlyHeight( dat.u, GetUnitFlyHeight( dat.u ) + (dat.z1 - GetLocationZ(Location(dat.x, dat.y))), 0. )
if fh <= GetLocationZ(Location(dat.x, dat.y)) or IsTerrainPathable( dat.x, dat.y, ConvertPathingType(2) ) == false then
set dat.u2 = CreateUnit( GetOwningPlayer(dat.u), PARTICLE_ID, dat.x, dat.y, 0. )
set fh = GetUnitFlyHeight( dat.u )
call SetUnitFlyHeight( dat.u2, fh, 0 )
call AddSpecialEffectTarget( dat.sfxs2, dat.u2, ATTACH )
set SPSIndex = SPSIndex - 1
set temp_SPS[i] = temp_SPS[SPSIndex]
call DisplayTextToForce( GetPlayersAll(), "test" )
call dat.destroy()
endif
set i = i + 1
endloop
endfunction
function InitSPS takes player p, real d, real s, string sfx, string sfx2, real x, real y, real x2, real y2, boolean DD, attacktype atk returns SPS
local SPS dat = SPS.create()
set temp_SPS[SPSIndex] = dat
set dat.x = x
set dat.x2 = x2
set dat.y = y
set dat.y2 = y2
set dat.a = Atan2( dat.y2 - dat.y, dat.x2 - dat.x )
set dat.p = p
set dat.u = CreateUnit( dat.p, PARTICLE_ID, dat.x, dat.y, dat.a )
call SetUnitX( dat.u, dat.x )
call SetUnitY( dat.u, dat.y )
set dat.z1 = GetLocationZ(Location(x, y))
set dat.dx = GetMoveX( s*INTERVAL, dat.a )
set dat.dy = GetMoveY( s*INTERVAL, dat.a )
set dat.sfx = AddSpecialEffectTarget( sfx, dat.u, ATTACH )
set dat.sfxs2 = sfx2
set dat.dmg = d
set dat.DamageDestructible = DD
set dat.atk = atk
call UnitAddAbility( dat.u, 'Amrf' )
call UnitRemoveAbility( dat.u, 'Amrf' )
call SetUnitFlyHeight( dat.u, PHeight + dat.z1, 0. )
if SPSIndex == 0 then
call TimerStart( sps, INTERVAL, true, function move )
endif
set SPSIndex = SPSIndex + 1
return dat
endfunction
endlibrary