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

Algorithm to test every terrain tile around a point

Status
Not open for further replies.
Each cell is 32x32, right?

Untested, so there might be an error, but you can do:
JASS:
// actions to apply over a rectangle
local real maxX = 96 // 3 * 32 = 96
local real maxY = 96 // 3 * 32 = 96
local real xLooper = 0 // start X, bottom left corner of rectangle
local real yLooper = 0 // start Y, bottom left corner of rectangle
loop
    exitwhen xLooper >= maxX
    loop
        exitwhen yLooper >= maxY
        // actions, using xLooper and yLooper
        set yLooper = yLooper + 32 // 32 units shift y-axis
    endloop
    set yLooper = 0
    set xLooper = xLooper + 32 // 32 units shift x-axis
endloop

That performs the action over a rectangle. However, that is kind of complex for your situation. I usually use it for bigger rects. You can probably just use offsets since there are only 8 tiles to check. Or you could make some variant, like two loops. It is really up to you. It depends on how often you use it.

The easiest way to do this is to create a JASS function, then just call it via GUI so you only have to use one-line. But idk.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Right, I forgot to mention that I'm checking in a circle.

My current workaround is:
  • For each (Integer A) from 1 to 9, do (Actions)
    • Loop - Actions
      • Set i = (i + 4)
      • Set i = (i + (Integer A))
      • For each (Integer B) from 1 to i, do (Actions)
        • Loop - Actions
          • Set l[1] = (l[0] offset by (115.00 x (Real((Integer A)))) towards ((360.00 / (Real(i))) x (Real((Integer B)))) degrees)
          • Set x = (X of l[1])
          • Set y = (Y of l[1])
          • Custom script: call RemoveLocation(udg_l[1])
          • -------- convert positions in a circle to snap to nearest terrain tile position --------
          • Set x = ((Real(((Integer(x)) / 128))) x 128.00)
          • Set y = ((Real(((Integer(y)) / 128))) x 128.00)
          • Set l[1] = (Point(x, y))
          • For each (Integer C) from 1 to hsTerrainTypeId, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain type at l[1]) Equal to hsTerrainTypeTile[C]
                • Then - Actions
                  • -------- found tile --------
                  • Unit - Order (Triggering unit) to Neutral Beastmaster - Stampede l[1]
                  • Custom script: call RemoveLocation(udg_l[0])
                  • Custom script: call RemoveLocation(udg_l[1])
                  • Skip remaining actions
                • Else - Actions
          • Custom script: call RemoveLocation(udg_l[1])
It works, but very inefficiently.

Anybody know how worldedit fills terrain using the "circle" brush?

To clarify (my apologies for not including this image in the OP):
attachment.php

Where each square is a terrain tile (128x128).

The purpose is to see if the terrain tile is one of a list of "harvestable" terrain tiles (for the spells & systems contest).
 

Attachments

  • algorithm.png
    algorithm.png
    4 KB · Views: 221
Status
Not open for further replies.
Top