• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Generate units per grid size

Status
Not open for further replies.
I'm developing a map and I need guidance on how to trigger a system that generates units on entire map per 128 grid size each.

For example I want Farms to be created from the start of the map down to the end but they must be created per one tile (128) separated each.

Any advise?

Edit: GUI is highly preferred.
 

Attachments

  • gen.png
    gen.png
    322 KB · Views: 67
Last edited:
GetWorldBounds() returns world rect.

JASS:
native GetRectMaxX takes rect whichRect returns real
native GetRectMaxY takes rect whichRect returns real
native GetRectMinX takes rect whichRect returns real
native GetRectMinY takes rect whichRect returns real
^Here you can go to the corners of the world. And when you wanna start from top left corner, for example, then:

"MinX + 64 / MaxY - 64 " are the center coordinates from the tile at the corner. And from then a simple loop might be used to add/substract "128" and to create units.
 
GetWorldBounds() returns world rect.

JASS:
native GetRectMaxX takes rect whichRect returns real
native GetRectMaxY takes rect whichRect returns real
native GetRectMinX takes rect whichRect returns real
native GetRectMinY takes rect whichRect returns real
^Here you can go to the corners of the world. And when you wanna start from top left corner, for example, then:

"MinX + 64 / MaxY - 64 " are the center coordinates from the tile at the corner. And from then a simple loop might be used to add/substract "128" and to create units.

Could you elaborate? I'm not that familiar with JASS.

this will very quickly wreck your fps. consider using destructibles instead of units.

Actually I will be using both at the same time, this is the whole concept of the map. I will have to do something about the lag though...
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
JASS:
    local real x1
    local real y1
    local real x2
    local real y2
    local real x3
    local real y3
   
    set x1=GetRectMinX(bj_mapInitialPlayableArea)
    set y1=GetRectMinY(bj_mapInitialPlayableArea)
    set x3=GetRectMaxX(bj_mapInitialPlayableArea)
    set y3=GetRectMaxY(bj_mapInitialPlayableArea)
    set x2 = x1
    set y2 = x1

    loop
        exitwhen x2>=x3
        set y2=y1
        loop
            exitwhen y2>=y3
                call CreateUnit(Player(0),'hhou',x2,y2,0)
            set y2=y2+128
        endloop
        set x2=x2+128
    endloop
I define start/end coordinates and loop through all points on the map. In this example it will be Farms for player 1.
 
  • Create Units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set X = ((Min X of (Playable map area)) + 64.00)
      • Set Y = ((Max Y of (Playable map area)) - 64.00)
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set Point = (Point(X, Y))
          • Unit - Create 1 Farm for Player 1 (Red) at Point facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_Point)
          • Set X = (X + 128.00)
 

Attachments

  • Corner Units.w3x
    16.3 KB · Views: 38
I define start/end coordinates and loop through all points on the map. In this example it will be Farms for player 1.

It lagged like hell, I couldn't even move my camera. Besides, I'd prefer a GUI version. Nevertheless I appreciate your effort.

  • Create Units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set X = ((Min X of (Playable map area)) + 64.00)
      • Set Y = ((Max Y of (Playable map area)) - 64.00)
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set Point = (Point(X, Y))
          • Unit - Create 1 Farm for Player 1 (Red) at Point facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_Point)
          • Set X = (X + 128.00)

It's small, optimized, GUI and perfect for my map! The only problem is that it doesn't fill the entire map.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
It lagged like hell, I couldn't even move my camera. Besides, I'd prefer a GUI version. Nevertheless I appreciate your effort.
The calculation is faster in JASS than in GUI, but thats only at the beginning of the map.
Once the calculation is finished the lag is because of the insane amount of units (hp bars also take a lot of fps I think).

I can make it GUI, if needed.
 
Last edited:
Oké, try it out in your map. Try to change the number "5" to something smaller in case it does break/ not entirely create farms in each row:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • LoopCounter Equal to 5
    • Then - Actions
      • Set LoopCounter = 0
      • Wait 0.00 seconds
    • Else - Actions
If bigger number works in your map then you can use bigger numbers (will create faster) -- it's just used to make a small primitive pause, for not hitting the operation limit.
 

Attachments

  • Corner Units.w3x
    17.1 KB · Views: 42

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
If bigger number works in your map then you can use bigger numbers (will create faster) -- it's just used to make a small pause, for not hitting the operation limit.
Finally I hear something about the operation limit. I never read anything about it, but experienced it myself several times.

@A Void: Use IcemanBo's solution. It is already in GUI and also considers the operation limit. You can make the screen black (fade filter) to hide the process of creating the units.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Is there something that bothered you in past? I think it's mostly only a problem in recursive functions, very big loops, or too many actions on map initialization.
I made a system to detect pathability from one side of a region to another side of the region (for maze TDs) and it did not work with bigger regions. I assumed that warcraft would just stop at some point as the function did not return a value. I was able to solve it with running the algorithm every 0.01 seconds (only if the algorithm was not finished yet).
0.00 seconds wait is obviously better. Should work with a 0.00 seconds timer as well, right? The main problem is though, that it's hard to know when to put the wait.
 
Oké, try it out in your map. Try to change the number "5" to something smaller in case it does break/ not entirely create farms in each row:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • LoopCounter Equal to 5
    • Then - Actions
      • Set LoopCounter = 0
      • Wait 0.00 seconds
    • Else - Actions
If bigger number works in your map then you can use bigger numbers (will create faster) -- it's just used to make a small primitive pause, for not hitting the operation limit.

Thank you! It's perfect. +rep
 
0.00 seconds wait is obviously better. Should work with a 0.00 seconds timer as well, right? The main problem is though, that it's hard to know when to put the wait.
Yeh, it kind of sucks, especially in GUI. "wait 0" is actually too long pause (as it's like 0.1 - 0.2 seconds), that is even visualy mentionable. ForForce or yes a "0 timeout timer" are much better/faster I think.
And yeh it's also hard to meassure where exactly a break is needed, also because different operations have a different effect on the operation counter -- like a "CreateUnit" function is very heavy, and something like "Set X = 10" is very leight weight.

The Op Limit - Wc3C.net

AVoid, you're welcome! : )
 
Yeh, it kind of sucks, especially in GUI. "wait 0" is actually too long pause (as it's like 0.1 - 0.2 seconds), that is even visualy mentionable. ForForce or yes a "0 timeout timer" are much better/faster I think.
And yeh it's also hard to meassure where exactly a break is needed, also because different operations have a different effect on the operation counter -- like a "CreateUnit" function is very heavy, and something like "Set X = 10" is very leight weight.

The Op Limit - Wc3C.net

AVoid, you're welcome! : )

I don't want to bother you too much but would it be possible to make it create single farm each time instead of drawing a line of them? Creating single unit produces less lag. I tried adding a Wait 0.00 at the end of the loop but it kept creating them in that same line, but there was no lag.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
I don't want to bother you too much but would it be possible to make it create single farm each time instead of drawing a line of them? Creating single unit produces less lag. I tried adding a Wait 0.00 at the end of the loop but it kept creating them in that same line.
As IcemanBo said:
If bigger number works in your map then you can use bigger numbers (will create faster) -- it's just used to make a small primitive pause, for not hitting the operation limit.
Bigger numbers means: faster creation, more lag. So use a smaller number than 5.
If you want each farm individually you probably need to change more, as waits do not work in loop as far as I know.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Worth noting that on large maps this will hit the single thread op limit so you will need some kind of new thread or TriggerSleepAction between to refresh the limit. Also it will cause WC3 to crash after around 60,000 such items exist, at least for destructables back in old versions of WC3.

Assuming infinite op-limit or small area the approach is as simple as starting a for style loop for X coordinates and then nesting one for Y coordinates and then creating units at the loop X and Y. The loops should increment by 128 until out of bounds. If an aligned starting point is not known it can be forcefully aligned using integer division and multiplication.
 
Status
Not open for further replies.
Top