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

Random terrain geometry

Level 5
Joined
May 23, 2008
Messages
148
Alright, so we want some more randomness in our map. Well, there's a way to make your terrain be shaped a bit randomly at every instance of the game. The idea is simple: execute multiple random permanent terrain deformations. We will need a region to have the changes applied and that would be pretty much everything if it were to be a one-shot map.

Variables:
TheRegion <gen> - the region to be deformed

  • TerrainGenerationSimple
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 459, do (Actions)
        • Loop - Actions
          • Environment - Create a 0.01 second Permanent crater deformation at (Random point in TheRegion <gen>) with radius (Random real number between 500.00 and 1100.00) and depth (Random real number between -40.00 and 40.00)

Note 1: Radii and depths are also random. Obviosly you might use different ranges for them. My advise is not to exaggerate them as it might result in unnatural looks of the generated terrain ('spikes', sharp edges, too deep depressions, etc). You might want to have some deep valley (it looks cool if custom fog kicks in and you can really feel the distance) apart from the general terrain. In that case just copy the trigger and give few tries to other parameters (e.g. only negative depths with high values).

Note 2: The number of deformations totally depends on the size of the region and the extent of randomness we want to achieve (I would advise 300+ in a general case).

Note 3: The trigger is executed at Map Initialization, so it will affect the loading time (in some cases even greatly). On my few maps I made it fire during the game-time periodically for a certain number of iterations and with random deformation time (not 0.01 seconds ^^) . Players had the chance to actually see how the terrain is formed over time (along with trees slowly growing from the ground, patches of grass popping out as well as debris, flowers, shells and other stuff :wink:). So consider it as an option as well.

Note 4: Outer part of the region (approximately the average radius length away from edges) will be less affected than the other parts of the region.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Okay, now we've got a nice terrain. Unfortunately, when we save the game and load it later on, all the deformations are 'forgotten'. If we want to be more professional, we have to handle this problem. Once again, the concept is simple: we will save all the parameters in variables (arrays of them).

We have to change the terrain generator to:

Variables:
NumberOfDeformations - (integer) self explanatory
TheRegion <gen> - the region to be deformed
RandomPoint - (point) - position of currently applied deformation
RandomRadius - (real) - radius of current deformation
RandomDepth - (real) - depth of current deformation
Points - (array of points) - saving all positions here
Radii - (array of reals) - saving all radii here
Depths - (array of reals) - saving all depths here


  • TerrainGeneration
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set NumberOfDeformations = 460
      • For each (Integer A) from 0 to (NumberOfDeformations - 1), do (Actions)
        • Loop - Actions
          • Set RandomPoint = (Random point in TheRegion <gen>)
          • Set RandomRadius = (Random real number between 500.00 and 1100.00)
          • Set RandomDepth = (Random real number between -40.00 and 40.00)
          • Set Points[(Integer A)] = RandomPoint
          • Set Radii[(Integer A)] = RandomRadius
          • Set Depths[(Integer A)] = RandomDepth
          • Environment - Create a 0.01 second Permanent crater deformation at RandomPoint with radius RandomRadius and depth RandomDepth
          • Custom script: call RemoveLocation(udg_RandomPoint)

Note 5: You don't have to predict the size of arrays, they might the size of 4 and even if you need access to 4735th position, Warcraft will handle this. However, the arrays have a limit of 8192 capacity, so don't set the NumberOfDeformations over 8192 :grin:.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, the trigger regenerating the original terrain after loading the saved game:

  • TerrainReGeneration
    • Events
      • Game - A saved game is loaded
    • Conditions
    • Actions
      • For each (Integer A) from 0 to (NumberOfDeformations - 1), do (Actions)
        • Loop - Actions
          • Environment - Create a 0.01 second Permanent crater deformation at Points[(Integer A)] with radius Radii[(Integer A)] and depth Depths[(Integer A)]

Should work just fine. That's all.
Have fun with your custom randomized maps.

Jees, this forum surely could use some 'horizontal line' thingie.
 
Last edited:
Level 5
Joined
May 23, 2008
Messages
148
Malfunctions

Important (an overgrown note 6): when a terrain deformation is applied, it doesn't affect buildings nor some units. They will behave as if the terrain was not changed, what can result in e.g. siege tanks driving in the air (and leaving trackprints in the air), flying units hovering under the ground, buildings hanging in the air etc.

Q: Which units particularily are effected?
A: All flying units, all buildings that were created before the deformation, all units with Art - Elevation Sample Points value different than 0 (this parameter determines how well the unit's animation is handling the curves of the terrain).

Q: What can be done about it?
A:
  • Generally: Don't exaggerate the deformation's heights. Anything above 100 is much as for my opinion.
  • About buildings: Well, you can remove it by triggers and instantly recreate it. It shall correct its position.
  • About units with Elevation Sample Points: You can set this paramerer to 0 in the Object Editor. However, it will affect the unit's animation on uneven terrain (like having Siege Tanks' model all the time rotated horizontally in the opposition to default slope.
  • About flying units: nothing helpful can be done. At your best you might try to manually change flyers flying height so that it doesn't collide with the ground (e.g. defalt flying height + maximum expected peak), but it is a half-measure.

You might also notice, that in extreme cases, you might see black areas far away when having your camera slided down. It's just like the World Editor's view distance limit, which can be adjusted by CTRL+MOUSEWHEEL. You can fix that in-game by changing the camera's Far Z parameter.
  • FarZ
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Camera - Set (Picked player)'s camera Far Z to 9000.00 over 0.00 seconds

To be 100% sure you will not see black areas, lets assume the most pessimistic case. That is: you are looking through the map's diagonal. Then set the Far Z to (MapWidth2 + MapHeight2)0.5. On the other hand, the higher value Far Z has, the worse is the performance (I wouldn't care much about it, though... unless you are playing on Commodore64 or a really unoptimized map).


Oh and you can save more than 8192 deformations by using extra arrays, but what is the point... :eekani:
 
Top