• 🏆 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!

Map generation fail

Status
Not open for further replies.
Level 1
Joined
Jul 31, 2020
Messages
1
So im generating units for my map to make it more dynamic.
But it fails mid loop and I don't understand why.

WC3ScrnShot_073120_174254_001.png
Code:
setup
    Events
        Time - Elapsed game time is 3.00 seconds
    Conditions
    Actions
        Set VariableSet temp_playergroup = (All players controlled by a User player)
        Set VariableSet MaxSize = (5 + (Number of players in temp_playergroup))
        Custom script:   call DestroyForce (udg_temp_playergroup)
        Set VariableSet mapsize_max = (100.00 x (Real(MaxSize)))
        Set VariableSet mapsize_min = (mapsize_max - mapsize_max)
        Set VariableSet playareaX = mapsize_max
        Set VariableSet playareaY = mapsize_max
        For each (Integer A) from 1 to ((MaxSize x MaxSize) + MaxSize), do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        playareaXcounter Not equal to MaxSize
                    Then - Actions
                        Set VariableSet temp_point = ((Center of (Playable map area)) offset by (playareaX, playareaY))
                        Unit - Create 1 Wall for Player 1 (Red) at temp_point facing Default building facing degrees
                        Custom script:   call RemoveLocation(udg_temp_point)
                        Set VariableSet playareaX = (playareaX + -200.00)
                        Set VariableSet playareaXcounter = (playareaXcounter + 1)
                    Else - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                playareaYcounter Not equal to MaxSize
                            Then - Actions
                                Set VariableSet playareaXcounter = 0
                                Set VariableSet playareaY = (playareaY - 200.00)
                                Set VariableSet playareaYcounter = (playareaYcounter + 1)
                                Set VariableSet playareaX = mapsize_max
                            Else - Actions
                                Game - Display to (All players) the text: TURNED OFF
                                Trigger - Turn off (This trigger)

Basically the code starts 100 units * (5 * number of players). To give it an increased size depending on how many players are playing.

Then the loop subtracts 200 units(distance) each loop. but it gives me strange patterns.
See below picture

Can someone explain why the patterns are wierd?

If you need, I can explain it more.


The outcome:
WC3ScrnShot_073120_174254_001.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
1) "Reals are 32 bit software emulated floating point numbers. They are subject to floating point errors like all floating point numbers." -Someone smarter than me

In other words, you should work with Integers instead of Reals for your arithmetic.

So make playareaX/Y an Integer, and subtract 200 from them. You can then convert those values to a Real when setting the offset.

2) You can't place a building just anywhere like you could with a unit, it needs to snap to the grid. So assuming your Walls are buildings, you need to make them follow the rules for pathing. A Farm for example uses a 128x128 pathing texture so in that case you'd want to offset your Walls by a multiple of 128. I think your Walls use this same exact pathing texture as well.

So in your case you probably want to subtract 256 when calculating the Wall offset.

Also, the Turn Off trigger thing is pointless as HerlySQR mentioned, you don't need to do anything there.
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
2) You can't place a building just anywhere like you could with a unit, it needs to snap to the grid. So assuming your Walls are buildings, you need to make them follow the rules for pathing. A Farm for example uses a 128x128 pathing texture, which it looks like your Walls use as well. So you'd want to offset your Walls by a multiple of 128.

In your case you probably want to subtract 256 when calculating the Wall offset.
Oh the position of buildings, how can I forget that?
 
Last edited:
Status
Not open for further replies.
Top