• 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.

[JASS] Loop limmit?

Status
Not open for further replies.
Level 4
Joined
Mar 23, 2008
Messages
87
Hi. I'm making a map and I'm having some trouble.
I have a trigger that is supposed to divide the playfield into x,y coordinates where it does a dice roll (random int(1,100)) to see if it should create an asteroid field for each 1024.00 points.
The asteroid fields are created in a circular fashion, first one random sized asteroid in center, then a random amount of others around it.
My problem is in the first loop. It makes ca 50-60 fields, then it stops. I'd like it to make 500 or so. I've attached the map so you can see for yourself. The trigger is called ARRC

oh, and:
Is it possible to remove the glowing circle around the Wagon withouth making a custom model?
 

Attachments

  • Traders_A06.w3x
    278.4 KB · Views: 42
Level 4
Joined
Mar 23, 2008
Messages
87
You should right click > copy as text trigger ARRC into here since most peopl aren't going to open your map.
I guess, you're right.
My reasons for not doing so before is because the trigger itself is working fine except it stops after x (ca 50) number of loops for some reason (so you would have to open the map to see what's happening anyway), and because the code is quite long.

And now, without further ado:
JASS:
function SpawnAsteroid takes integer xc, integer yc, integer asize returns nothing
    local location apos
    local integer array atype
    local integer dice
    local unit tmpa //temporary asteroid
    set atype[0] = 'h003'
    set atype[1] = 'h002'
    set atype[2] = 'h001'
    set atype[3] = 'h000'
    set apos = Location(I2R(xc), I2R(yc))
    set dice = GetRandomInt(1,10)
    if dice>7 and asize == 0 then
        set tmpa = CreateUnitAtLoc( Player(8), atype[0], apos, bj_UNIT_FACING )
    else
        set tmpa = CreateUnitAtLoc( Player(8), atype[asize+1], apos, bj_UNIT_FACING )
    endif
    call SetUnitUserData(tmpa, udg_UID)
    set udg_iron[udg_UID] = GetRandomInt(100,1000)
    set udg_copper[udg_UID] = GetRandomInt(50,500)
    set udg_gold[udg_UID] = GetRandomInt(10,100)
    set udg_water[udg_UID] = GetRandomInt(1,10)
    set udg_power[udg_UID] = 0
    set udg_UID = udg_UID + 1
    //call DisplayTextToForce( GetPlayersAll(),"ASteroid"+I2S(udg_UID)+": "+I2S(xc-startx())+", "+I2S(yc-starty()))
    //call TriggerSleepAction(0.10)
    //call DisplayTextToForce( GetPlayersAll(), "asteroid")
endfunction

function SetupGrid takes integer xi, integer yi returns nothing
    local integer ltimes=5//loop times
    local integer rots=0//grid x integer
    local real rot=0
    local real nring = 0.00 //next ring
    local integer next = 0 //next (distance to next)
    local integer dist
    local integer dice
    local integer dbug = 0
    set dist = R2I(DistanceBetweenPoints(Location(xi, yi), Location(0, 0))/20000)
    set dice = GetRandomInt(dist,10)
    if dice>9 then
        call SpawnAsteroid(xi,yi,0)
        set nring = 128.00
    elseif dice>7 then
        call SpawnAsteroid(xi,yi,1)
        set nring = 64.00
    else
        call SpawnAsteroid(xi,yi,2)
        set nring = 32.00
    endif
    //call DisplayTextToForce( GetPlayersAll(), "afield, dist="+I2S(dist))
    loop
        set next = next + GetRandomInt(16,256)
        set rot = I2R(360*next)/(2.00*PI()*nring)
        //call DisplayTextToForce( GetPlayersAll(), "rot="+R2S(rot)+" nring="+R2S(nring)+" x="+R2S(Cos(rot)*nring))
        //call TriggerSleepAction(0.10)
        //call DisplayTextToForce( GetPlayersAll(), "next>circle="+I2S(next)+" > "+R2S(2*nring*PI()))
        if I2R(next) > 2*nring*PI() then
            set next = next - R2I(2*nring*PI())
            set nring = nring + 128.00
            set rots=rots+1
        endif
        
        set dice = GetRandomInt(1,100)
        if dice>90 then
            call SpawnAsteroid(R2I(Cos(rot)*nring)+xi, R2I(Sin(rot)*nring)+yi, GetRandomInt(1,2))
            set next = next + 128
            set dbug = dbug + 1
        endif
        exitwhen rots>ltimes
    endloop
    //call DisplayTextToForce( GetPlayersAll(), "asteroids planted: "+I2S(dbug) )
endfunction

function Regions takes nothing returns nothing
    local integer xsi = 0 //x squares integer
    local integer ysi = 0
    local integer dice
    local integer odds = 99
    local integer reducer = 1
    local integer maxunits
    local integer array asteroid
    local integer dbug = 0
    set maxunits = udg_UID+200
    set asteroid[0] = 'h000'
    set asteroid[1] = 'h001'
    set asteroid[2] = 'h002'
    set asteroid[3] = 'h003'
    loop
        set dice = GetRandomInt(1,100)
        if dice>90 then
            call SetupGrid((xsi*grids())-startx(),(ysi*grids())-starty())
         //   set odds=99
        //elseif odds>10 then //22 - 13 = 9
         //   set odds = odds - 1
        endif
        
        if ysi>squares() then
            set ysi = 0
            set xsi=xsi+1
        endif
        set ysi=ysi+1
        exitwhen xsi>squares()
    endloop
endfunction

//===========================================================================
function InitTrig_ARRC takes nothing returns nothing
    set gg_trg_ARRC = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_ARRC, 1.00 )
    call TriggerAddAction( gg_trg_ARRC, function Regions )
endfunction
 
Level 4
Joined
Mar 23, 2008
Messages
87
ah, sorry. forgot about my definitions.
here they are:
JASS:
function startx takes nothing returns integer
    return 28160
endfunction
function starty takes nothing returns integer
    return 28160
endfunction
function grids takes nothing returns integer
    return 1024
endfunction
function square takes nothing returns integer
    return 16
endfunction
function squares takes nothing returns integer
    return 55
endfunction
function PI takes nothing returns real
    return 22.00/7.00
endfunction
 
Level 4
Joined
Mar 23, 2008
Messages
87
Resetting the count is the best option for me i think.
How would i go about doing this? What is TSA?
 
Level 4
Joined
Mar 23, 2008
Messages
87
JASS:
call TriggerSleepAction(0)

This will slow down your code dramatically if used every iteration of the loop, though, since it will wait anywhere from 0.1 to 0.5 seconds.

Haha, it works perfectly now :D
Thanks a lot. This problem has frustrated me greatly!
The loop is initzialising the asteroids, it doesn't need to be very quick, so TSA works great :D
 
Status
Not open for further replies.
Top