Page 1 of 1

Slope

Posted: 08 Oct 2009, 00:14
by Petah
NM, I was looking at the value from modinfo.adune.nl and it seems to be inconsistent with the value you get in spring.

Using the com.springrts.ai.oo.Map.getSlopeMap() how can I check if a position is less than a unit maxslope property.

Units maxslope is normally an integer between 0-80 but the float values returned from getSlopeMap() are small decimal values.

In other words how do I tell if a position is passable by a unit.

Re: Slope

Posted: 10 Oct 2009, 21:04
by AF
Normally you can do CanBuild() on a position, and if a mobile unit can be built there, it can move there, but you could have to do a very finegrained iteration repeatedly calling it along a path or area.

Its not a very efficient approach and Id like to know how to use the slope values and the unitdef values to figure out what you get when you press f2 ingame.

Re: Slope

Posted: 10 Oct 2009, 23:23
by Peet
AF wrote:Normally you can do CanBuild() on a position, and if a mobile unit can be built there, it can move there, but you could have to do a very finegrained iteration repeatedly calling it along a path or area.
Unfortunately that only works if the unitdef's maxSlope is the same as the movetype's. Which it often isn't.


ud->maxSlope is the unit's max slope /1.5 in degrees. Presumably the decimal values given are the tangent of the angle.

Re: Slope

Posted: 10 Oct 2009, 23:29
by AF
So basically:

Code: Select all

bool CanBuildAt(float mapslope, const UnitDef* u){
    float unitslope = tan(u->maxslope/1.5);
    return unitslope < mapslope;
}