HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need Mathematical Help

07-25-2008, 05:22 AM#1
goldendercon
can you check this script for me, I'm not that good at math and neither is darkwulfv who helped me in this one(well... He's the one that said that). well anyway I'd like you to help me with looking for errors.

Collapse JASS:
struct BlazeFlightData
  unit caster = null
  unit array dummies[10]
  unit array groundies[40]
  real rotation = 0
endstruct  
   
function BlazingFlight_Callback takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local BlazeFlightData dat = GetHandleInt(t, "BlazeData")
  local unit F = dat.caster
  local unit dummy
  local integer i = 1
  local real x = GetUnitX(F)
  local real y = GetUnitY(F)
  local real x2 = 0
  local real y2 = 0
  local real angle = 0
  local real rotation = dat.rotation
  
  set dummy = dat.dummies[i]
    call SetUnitFlyHeight( F, 450.00, 75.00 )
    set angle = (Atan2(GetUnitY(dummy) - y, GetUnitX(dummy) - x)) + (bj_DEGTORAD *5.)
    set x2 = x + 200 * Cos(angle)
    set y2 = y + 200 * Sin(angle)
    call SetUnitPosition(dummy, x2, y2)
    call SetUnitFlyHeight(dummy, 450.00, 75.00 )
  set i = i + 1
    
  set dummy = dat.dummies[i]    
    set angle = (Atan2(GetUnitY(dummy) - y, GetUnitX(dummy) - x)) - (bj_DEGTORAD *5.)
    set x2 = x + 200 * Cos(angle)
    set y2 = y + 200 * Sin(angle)
    call SetUnitPosition(dummy, x2, y2 )
    call SetUnitFlyHeight(dummy, 450.00, 75.00 )
  set i = i + 1
    
  set dummy = dat.dummies[i]   
    set angle = (Atan2(GetUnitY(dummy) - y, GetUnitX(dummy) - x)) + (bj_DEGTORAD *5.)
    set x2 = x + 200 * Cos(angle)
    set y2 = y + 200 * Sin(angle)
    call SetUnitPosition(dummy, x2, y2 )
    call SetUnitFlyHeight(dummy, 450.00, 75.00 )
  set i = i + 1
    
  set dummy = dat.dummies[i]   
    set angle = (Atan2(GetUnitY(dummy) - y, GetUnitX(dummy) - x)) - (bj_DEGTORAD *5.)
    set x2 = x + 200 * Cos(angle)
    set y2 = y + 200 * Sin(angle)
    call SetUnitPosition(dummy, x2, y2 )
    call SetUnitFlyHeight(dummy, 450.00, 75.00 )

    set i = 1
    set rotation = rotation + 5. 

    loop
      exitwhen i>36
      set x2 = x + 400 * Cos(rotation + (i * 10)) * bj_DEGTORAD
      set y2 = y + 400 * Sin(rotation + (i * 10)) * bj_DEGTORAD
        call SetUnitPosition(dat.groundies[i], x2, y2)
        set i=i+1
    endloop
    
    set dat.rotation = rotation    
    
    set F = null
    set dummy = null
    set t = null
    call dat.destroy()
endfunction  

function BlazingFlight_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' 
endfunction

function BlazingFlight_Actions takes nothing returns nothing
    local integer i = 1
    local unit F= GetTriggerUnit()
    local real rotation = 0
    local real x = GetUnitX(F)
    local real y = GetUnitY(F)
    local player p = GetOwningPlayer(F)
    local unit E
    local unit G
    local real x2 = 0
    local real y2 = 0
    local timer t = CreateTimer()
    local integer Ie = 36
    local real wait = 0
    local BlazeFlightData Data = BlazeFlightData.create()
    set Data.caster = F
    
    loop
        exitwhen i > 4
        set x2 = x + 200 * Cos(90 * i) * bj_DEGTORAD
        set y2 = y + 200 * Sin(90 * i) * bj_DEGTORAD
        set E = CreateUnit(p, 'h000', x2, y2, 270.)
        set Data.dummies[i] = E
        if GetUnitAbilityLevel(F, 'A003') > 0 then
            call UnitApplyTimedLife(E, 'BTLF', 30.00)
            set wait = 30.
        else
            call UnitApplyTimedLife(E, 'BTLF', 15.00)
            set wait = 15.
        endif
        set i = i + 1
    endloop

    set i = 1
    loop
    exitwhen i > Ie
    set x2 = x + 400 * Cos(i * 10) * bj_DEGTORAD
    set y2 = y + 400 * Sin(i * 10) * bj_DEGTORAD
    set G = CreateUnit(p, 'h000', x2, y2, 270.)
    set Data.groundies[i] = G
    if GetUnitAbilityLevel(F, 'A003') > 0 then
        call UnitApplyTimedLife(G, 'BTLF', 30.)
    else
        call UnitApplyTimedLife(G, 'BTLF', 15.)
    endif
    set i = i + 1
    endloop
    
    
    call SetHandleInt(t, "BlazeData", Data)
    call TimerStart(t, .04, true, function BlazingFlight_Callback)
    
    call PolledWait(wait)
    
    call PauseTimer(t)
    call DestroyTimer(t)
    call Data.destroy()
    
    
    set F = null
    set E = null
    set G = null
    set p = null
    set t = null
endfunction

//===========================================================================
function InitTrig_BlazingFlight takes nothing returns nothing
  local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, Condition( function BlazingFlight_Conditions ) )
    call TriggerAddAction(t, function BlazingFlight_Actions )
    call Preload("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl")
  set t = null
endfunction




thanks in advance and I will give +rep
07-25-2008, 12:43 PM#2
Fireeye
In which way do you need math help?
Is there any bug or do you just want to reduce the amount of calculations needed / making the calculations simpler?

The only thing i really notice is this "ugly" part
Collapse JASS:
    set dummy = dat.dummies[i]    
    set angle = (Atan2(GetUnitY(dummy) - y, GetUnitX(dummy) - x)) - (bj_DEGTORAD *5.)
    set x2 = x + 200 * Cos(angle)
    set y2 = y + 200 * Sin(angle)
    call SetUnitPosition(dummy, x2, y2 )
    call SetUnitFlyHeight(dummy, 450.00, 75.00 )
    set i = i + 1
Why not making a loop instead of copying the same part over and over?
07-25-2008, 09:40 PM#3
goldendercon
I don't know, but darkwulfv asked me to post another thread to check his calculations, if any are wrong