mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 13:04:10 +00:00
Implement rmgen SlopeConstraint which is met if the elevation difference is within the given range, fixes #5004.
Add NearTileClassesConstraint that is satisfied when there is a tile marked with the given class in the given range. Use it for the grass and mountain terrain painting on Pyrenean Sierra. This was SVN commit r21085.
This commit is contained in:
@@ -54,10 +54,13 @@ const pForestLandVeryLight = [ tGrassLandForest2 + TERRAIN_SEPARATOR + oPine,tGr
|
||||
|
||||
const heightInit = -100;
|
||||
const heightOcean = -22;
|
||||
const heightWaterTerrain = -14;
|
||||
const heightBase = -6;
|
||||
const heightSand = -2;
|
||||
const heightSandTransition = 0;
|
||||
const heightGrass = 6;
|
||||
const heightWaterLevel = 8;
|
||||
const heightPyreneans = 15;
|
||||
const heightGrass = 6;
|
||||
const heightGrassMidRange = 18;
|
||||
const heightGrassHighRange = 30;
|
||||
const heightPassage = scaleByMapSize(25, 40);
|
||||
@@ -352,7 +355,20 @@ var num = scaleByMapSize(80,400);
|
||||
var group = new SimpleGroup([new SimpleObject(oPine, 1,2, 1,3),new SimpleObject(oBeech, 1,2, 1,3)], true, clForest);
|
||||
createObjectGroupsDeprecated(group, 0, avoidClasses(clWater, 3, clForest, 1, clPlayer, 8,clPyrenneans, 1), num, 20 );
|
||||
|
||||
g_Map.log("Painting the map");
|
||||
g_Map.log("Painting terrain by height and slope");
|
||||
for (let i = 0; i < terrainPerHeight.length; ++i)
|
||||
for (let steep of [false, true])
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new TerrainPainter(steep ? terrainPerHeight[i].terrainSteep : terrainPerHeight[i].terrainGround),
|
||||
[
|
||||
new NearTileClassConstraint(clPyrenneans, 2),
|
||||
new HeightConstraint(terrainPerHeight[i - 1] ? terrainPerHeight[i - 1].maxHeight : -Infinity, terrainPerHeight[i].maxHeight),
|
||||
steep ?
|
||||
new SlopeConstraint(terrainPerHeight[i].steepness, Infinity) :
|
||||
new SlopeConstraint(-Infinity, terrainPerHeight[i].steepness),
|
||||
]);
|
||||
|
||||
for (let x = 0; x < mapSize; ++x)
|
||||
for (let z = 0; z < mapSize; ++z)
|
||||
{
|
||||
@@ -360,12 +376,6 @@ for (let x = 0; x < mapSize; ++x)
|
||||
let height = g_Map.getHeight(position);
|
||||
let heightDiff = g_Map.getSlope(position);
|
||||
|
||||
if (clPyrenneans.countMembersInRadius(position, 2))
|
||||
{
|
||||
let layer = terrainPerHeight.find(layer => height < layer.maxHeight);
|
||||
createTerrain(heightDiff > layer.steepness ? layer.terrainSteep : layer.terrainGround).place(position);
|
||||
}
|
||||
|
||||
let terrainShore = getShoreTerrain(position, height, heightDiff);
|
||||
if (terrainShore)
|
||||
createTerrain(terrainShore).place(position);
|
||||
@@ -373,13 +383,14 @@ for (let x = 0; x < mapSize; ++x)
|
||||
|
||||
function getShoreTerrain(position, height, heightDiff)
|
||||
{
|
||||
if (height <= -14)
|
||||
if (height <= heightWaterTerrain)
|
||||
return tWater;
|
||||
|
||||
if (height <= -2 && clWater.countMembersInRadius(position, 2))
|
||||
if (height <= heightSand && new NearTileClassConstraint(clWater, 2).allows(position))
|
||||
return heightDiff < 2.5 ? tSand : tMidRangeCliffs;
|
||||
|
||||
if (height <= 0 && clWater.countMembersInRadius(position, 3))
|
||||
// Notice the sand transition is also be painted below height -2
|
||||
if (height <= heightSandTransition && new NearTileClassConstraint(clWater, 3).allows(position))
|
||||
return heightDiff < 2.5 ? tSandTransition : tMidRangeCliffs;
|
||||
|
||||
return undefined;
|
||||
|
||||
@@ -84,6 +84,20 @@ StayInTileClassConstraint.prototype.allows = function(position)
|
||||
return this.tileClass.countNonMembersInRadius(position, this.distance) == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* The NearTileClassConstraint is met if at least one tile within the given radius of the tile is marked with the given TileClass.
|
||||
*/
|
||||
function NearTileClassConstraint(tileClass, distance)
|
||||
{
|
||||
this.tileClass = tileClass;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
NearTileClassConstraint.prototype.allows = function(position)
|
||||
{
|
||||
return this.tileClass.countMembersInRadius(position, this.distance) > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* The BorderTileClassConstraint is met if there are
|
||||
* tiles not marked with the given TileClass within distanceInside of the tile and
|
||||
@@ -116,3 +130,17 @@ HeightConstraint.prototype.allows = function(position)
|
||||
{
|
||||
return this.minHeight <= g_Map.getHeight(position) && g_Map.getHeight(position) <= this.maxHeight;
|
||||
};
|
||||
|
||||
/**
|
||||
* The SlopeConstraint is met if the steepness of the terrain is within the given range.
|
||||
*/
|
||||
function SlopeConstraint(minSlope, maxSlope)
|
||||
{
|
||||
this.minSlope = minSlope;
|
||||
this.maxSlope = maxSlope;
|
||||
}
|
||||
|
||||
SlopeConstraint.prototype.allows = function(position)
|
||||
{
|
||||
return this.minSlope <= g_Map.getSlope(position) && g_Map.getSlope(position) <= this.maxSlope;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user