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

[General] How to get the highest Z-values in the map ?

Status
Not open for further replies.
Level 45
Joined
Feb 27, 2007
Messages
5,578
Only way to get that I can think of is to define a mesh width W and then check points in a grid W on a side throughout the map. A search with higher fidelity (say mesh of W/10) can then be performed around the N highest points found in step 1. This would likely never give you the true maximum z but it would be very close to it if W is sufficiently small. With W too small or a map of large enough size you'll hit the op limit so you'd have to break the search into multiple threads.

Instead of defining W you could define S as the maximum slope angle you think your map has and then W = K*Cos(S) where K is some constant. The editor might have a default maximum slope angle in it? However a custom MiscData.txt would be able to change that to allow unnaturally steep terrain.

Would be willing to try writing this but I'm not convinced it would ultimately be super accurate without a very small W. What do you need it for? Maybe there's a better thing to search for.
 
Last edited:
This library will sample the height of every terrain mesh vertex and return the absolute highest terrain height.
Since it resets the operation counter as it advances along the X-axis, it should not reach the operation limit. Even on a 480x480 map. The game will freeze for a second on very large maps though.
JASS:
//! zinc
library TerrainSampler {
    constant real GridSize = 128; // Size of a terrain mesh quad.
   
    location samplePoint = Location(0,0);
    real x, y, z, minX, minY, maxX, maxY, sampleZ;
    rect bounds = null;
   
    function InitBounds() {
        bounds = GetWorldBounds();
        minX = GetRectMinX(bounds);
        minY = GetRectMinY(bounds);
        maxX = GetRectMaxX(bounds);
        maxY = GetRectMaxY(bounds);
    }
   
    function SampleYAxis() {
        y = minY;
        while (y <= maxY) {
            MoveLocation(samplePoint, x, y);
            sampleZ = GetLocationZ(samplePoint);
            if (sampleZ > z) z = sampleZ;
            y += GridSize;
        }
    }
   
    function SampleXAxis() {
        if (bounds == null) InitBounds();
        z = -10000000;
        x = minX;
        while (x <= maxX) {
            ForForce(bj_FORCE_PLAYER[0], function SampleYAxis);
            x += GridSize;
        }
    }
   
    public function SampleTerrainMaxZ() -> real {
        ForForce(bj_FORCE_PLAYER[0], function SampleXAxis);
        return z;
    }
}
//! endzinc
Since GetLocationZ() is an asynchronous function, the returned value is not guaranteed synchronous between clients.
 
Status
Not open for further replies.
Top