• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] trigger optimization

Status
Not open for further replies.
hello i bring another minigame to be optimized. basically i always liked the shooting minigames in ryoko td were the creeps wlked in a straight line and u shot at them w a missile. it is based a little off of tht but i wanted to make a circle. since the terrain editor did not allow perfect circular shapes i turned to this style ( will show a pic). the units go around perfectly and it looks really cool imo. ill show some pics of it working.

note: it is only set up to run for 2 ppl atm. dw about tht part

JASS:
scope circleRandom initializer Circle

globals
    trigger trg_Circle
    private trigger trg_start
    private trigger trg_timer
    private trigger trg_deaths
    private unit array circleUnits
    private real array minX // ( smallest)
    private real array minY // ( smallest)
    private real array midX
    private real array midY
    private real array maxX
    private real array maxY
    private real circleX
    private real circleY
    private integer array Int
    private unit array playerUnit
    private group circleMinG
    private group circleMidG
    private group circleMaxG
    private integer array playerPoints
    private integer unitToCreate = 'h05R'
endglobals

private function winner takes integer p returns nothing
    call pauseall( false)
    call textall( "the winner is Player " + I2S(p+1), p)
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer p = GetPlayerId( GetOwningPlayer(GetKillingUnit()))
    if IsUnitInGroup( u, circleMinG) then
        set playerPoints = playerPoints + 1
        call GroupRemoveUnit( circleMinG, u)
    elseif IsUnitInGroup( u, circleMidG) then
        set playerPoints = playerPoints + 2
        call GroupRemoveUnit( circleMidG, u)
    elseif IsUnitInGroup( u, circleMaxG) then
        set playerPoints = playerPoints + 3
        call GroupRemoveUnit( circleMaxG, u)
    endif
    if playerPoints == 10 then
        call winner( p)
    endif
    set u = null
endfunction

private function Timer takes nothing returns nothing
    local integer L1 = 0
    local integer L2 = 16
    local integer L3 = 32
    loop
        exitwhen L1 > 15       // 28                           // 44                     // 60
        if Int[L1] == 448 then // use 448 for the lower circle // use 704 for mid circle // 960 for max circle
            set Int[L1] = 0
        else
            set Int[L1] = Int[L1] + 1
        endif
        call SetUnitX( circleUnits[L1], minX[Int[L1]])
        call SetUnitY( circleUnits[L1], minY[Int[L1]])
        set L1 = L1 + 1
    endloop
    loop
        exitwhen L2 > 31       // 28                           // 44                     // 60
        if Int[L2] == 0 then // use 448 for the lower circle // use 704 for mid circle // 960 for max circle
            set Int[L2] = 704
        else
            set Int[L2] = Int[L2] - 1
        endif
        call SetUnitX( circleUnits[L2], midX[Int[L2]])
        call SetUnitY( circleUnits[L2], midY[Int[L2]])
        set L2 = L2 + 1
    endloop
    loop
        exitwhen L3 > 47       // 28                           // 44                     // 60
        if Int[L3] == 960 then // use 448 for the lower circle // use 704 for mid circle // 960 for max circle
            set Int[L3] = 0
        else
            set Int[L3] = Int[L3] + 1
        endif
        call SetUnitX( circleUnits[L3], maxX[Int[L3]])
        call SetUnitY( circleUnits[L3], maxY[Int[L3]])
        set L3 = L3 + 1
    endloop
endfunction

private function setup takes nothing returns nothing
    local integer L = 0
    local integer L1 = 0
    local integer L2 = 16
    local integer L3 = 32
    call pauseall( true)
    loop
        exitwhen L1 > 15
        set circleUnits[L1] = CreateUnit( Player(11), unitToCreate, minX[L], minY[L], 0)
        call GroupAddUnit( circleMinG, circleUnits[L1])
        set Int[L1] = L
        set L1 = L1 + 1
        set L = L + 28
    endloop
    set L = 0
    loop
        exitwhen L2 > 31
        set circleUnits[L2] = CreateUnit( Player(11), unitToCreate, midX[L], midY[L], 0)
        call GroupAddUnit( circleMidG, circleUnits[L2])
        set Int[L2] = L
        set L2 = L2 + 1
        set L = L + 44
    endloop
    set L = 0
    loop
        exitwhen L3 > 47
        set circleUnits[L3] = CreateUnit( Player(11), unitToCreate, maxX[L], maxY[L], 0)
        call GroupAddUnit( circleMaxG, circleUnits[L3])
        set Int[L3] = L
        set L3 = L3 + 1
        set L = L + 60
    endloop
    set L = 0
    loop
        exitwhen L > 5
        call PauseUnit( playerUnit[L], false)
        set playerPoints[L] = 0
        set L = L + 1
    endloop
    call EnableTrigger( trg_timer)
    call EnableTrigger( trg_deaths)
endfunction

private function minC takes nothing returns nothing
    local integer c = 1
    local integer c1
    local integer L = 1
    local integer i1
    local integer i2
    loop
        exitwhen c > 97
        if c == 1 or c == 33 then
            set i1 = 8
            set i2 = 0
        elseif c == 17 or c == 49 or c == 81 then
            set i1 = 8
            set i2 = 8
        elseif c == 65 or c == 97 then
            set i1 = 0
            set i2 = 8
        endif
        loop
            exitwhen L > 16  // this one is for the low circle ( smallest)
            set minX[c] = minX[(c-1)] + i1 //64
            set minY[c] = minY[(c-1)] + i2 //0
            set c = c + 1
            set L = L + 1
        endloop
        set L = 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set minX[c] = minX[c1]
        set minY[c] = circleY+(circleY-minY[c1])
        set c = c + 1
        set c1 = c1 - 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set minX[c] = circleX+(circleX-minX[c1])
        set minY[c] = minY[c1]
        set c = c + 1
        set c1 = c1 - 1
    endloop
    call texti( c)
endfunction

private function midC takes nothing returns nothing
    local integer c = 1
    local integer c1
    local integer L = 1
    local integer i1
    local integer i2
    loop
        exitwhen c > 161
        if c == 1 or c == 33 or c == 65 then
            set i1 = 8
            set i2 = 0
        elseif c == 17 or c == 49 or c == 81 or c == 113 or c == 145 then
            set i1 = 8
            set i2 = 8
        elseif c == 97 or c == 129 or c == 161 then
            set i1 = 0
            set i2 = 8
        endif
        loop
            exitwhen L > 16  // this one is for the mid circle
            set midX[c] = midX[(c-1)] + i1 //64
            set midY[c] = midY[(c-1)] + i2 //0
            set c = c + 1
            set L = L + 1
        endloop
        set L = 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set midX[c] = midX[c1]
        set midY[c] = circleY+(circleY-midY[c1])
        set c = c + 1
        set c1 = c1 - 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set midX[c] = circleX+(circleX-midX[c1])
        set midY[c] = midY[c1]
        set c = c + 1
        set c1 = c1 - 1
    endloop
endfunction

private function maxC takes nothing returns nothing
    local integer c = 1
    local integer c1
    local integer L = 1
    local integer i1
    local integer i2
    loop
        exitwhen c > 225
        if c == 1 or c == 33 or c == 65 or c == 97 then
            set i1 = 8
            set i2 = 0
        elseif c == 17 or c == 49 or c == 81 or c == 113 or c == 145 or c == 177 or c == 209 then
            set i1 = 8
            set i2 = 8
        elseif c == 129 or c == 161 or c == 193 or c == 225 then
            set i1 = 0
            set i2 = 8
        endif
        loop
            exitwhen L > 16  // this one is for the mid circle
            set maxX[c] = maxX[(c-1)] + i1 //64
            set maxY[c] = maxY[(c-1)] + i2 //0
            set c = c + 1
            set L = L + 1
        endloop
        set L = 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set maxX[c] = maxX[c1]
        set maxY[c] = circleY+(circleY-maxY[c1])
        set c = c + 1
        set c1 = c1 - 1
    endloop
    set c1 = c-2
    loop
        exitwhen c1 < 0
        set maxX[c] = circleX+(circleX-maxX[c1])
        set maxY[c] = maxY[c1]
        set c = c + 1
        set c1 = c1 - 1
    endloop
endfunction

private function startup takes nothing returns nothing
    local integer L = 0
    set circleMinG = CreateGroup()
    set circleMidG = CreateGroup()
    set circleMaxG = CreateGroup()
    set circleX = GetRectCenterX( gg_rct_CircleCenter)
    set circleY = GetRectCenterY( gg_rct_CircleCenter)
    loop
        exitwhen L > 5
        set playerUnit[L] = CreateUnit( Player(L), 'e00C', circleX, circleY, 270)
        set L = L + 1
    endloop
    call SetCameraField( CAMERA_FIELD_ZOFFSET, 2000, 0)
    set minX[0] = circleX
    set midX[0] = circleX
    set maxX[0] = circleX
    set minY[0] = circleY - 640 //7168
    set midY[0] = circleY - 1024 //6784
    set maxY[0] = circleY - 1408 //6400
    call minC()
    call midC()
    call maxC()
endfunction

private function conditions takes nothing returns boolean
    return IsUnitInGroup( GetTriggerUnit(), circleMinG) or IsUnitInGroup( GetTriggerUnit(), circleMidG) or IsUnitInGroup( GetTriggerUnit(), circleMaxG)
endfunction

//===========================================================================
private function Circle takes nothing returns nothing
    local trigger t = CreateTrigger()
    set trg_Circle = CreateTrigger()
    set trg_timer = CreateTrigger()
    set trg_deaths = CreateTrigger()
    call startup()
    call DisableTrigger( trg_Circle)
    call DisableTrigger( trg_deaths)
    call DisableTrigger( trg_timer)
    call TriggerRegisterPlayerUnitEvent( trg_deaths, Player(11), EVENT_PLAYER_UNIT_DEATH, null)
    call TriggerAddCondition( trg_deaths, function conditions)
    call TriggerAddAction( trg_deaths, function Actions)
    call TriggerAddAction( trg_Circle, function setup)
    call TriggerRegisterPlayerChatEvent( t, Player(0), "start", true)
    call TriggerAddAction( t, function setup)
    call TriggerRegisterTimerEvent( trg_timer, 0.03, true)
    call TriggerAddAction( trg_timer, function Timer)
endfunction

endscope
 

Attachments

  • the white is the path they move on.PNG
    the white is the path they move on.PNG
    1,021.4 KB · Views: 97
  • one of the units getting killed.PNG
    one of the units getting killed.PNG
    864 KB · Views: 83
Last edited:
Status
Not open for further replies.
Top