mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 14:43:52 +00:00
Implement MapBoundsPlacer that returns all points on the tilemap.
Use it to replace the hacky resetTerrain rmgen2 function from6d52a71d4aand initHeight from280a797620. Highlights that createArea is the primary tool of rmgen, rather than nested for-loops over the mapsize. Neglect that the heightmap grid is one tile larger than the tilemap grid for now. This was SVN commit r20894.
This commit is contained in:
@@ -7,7 +7,13 @@ InitMap();
|
||||
setSelectedBiome();
|
||||
initTileClasses();
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight());
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
|
||||
Engine.SetProgress(10);
|
||||
|
||||
const pos = randomStartingPositionPattern(getTeamsArray());
|
||||
|
||||
@@ -7,7 +7,13 @@ InitMap();
|
||||
setSelectedBiome();
|
||||
initTileClasses();
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight());
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
|
||||
Engine.SetProgress(10);
|
||||
|
||||
const teamsArray = getTeamsArray();
|
||||
|
||||
@@ -8,12 +8,18 @@ setSelectedBiome();
|
||||
initTileClasses();
|
||||
Engine.SetProgress(10);
|
||||
|
||||
// Pick a random elevation with a bias towards lower elevations
|
||||
log("Picking a random elevation with a bias towards lower elevations...");
|
||||
var randElevation = randIntInclusive(0, 29);
|
||||
if (randElevation < 25)
|
||||
randElevation = randIntInclusive(1, 4);
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, randElevation);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
new ElevationPainter(randElevation),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
Engine.SetProgress(20);
|
||||
|
||||
const startPositions = randomStartingPositionPattern(getTeamsArray());
|
||||
|
||||
@@ -9,7 +9,12 @@ initTileClasses();
|
||||
|
||||
setFogFactor(0.04);
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight());
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
Engine.SetProgress(10);
|
||||
|
||||
const mapSize = getMapSize();
|
||||
|
||||
@@ -7,7 +7,12 @@ InitMap();
|
||||
setSelectedBiome();
|
||||
initTileClasses();
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight());
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
Engine.SetProgress(10);
|
||||
|
||||
const teamsArray = getTeamsArray();
|
||||
|
||||
@@ -19,7 +19,13 @@ const mapCenter = getMapCenter();
|
||||
const numPlayers = getNumPlayers();
|
||||
const startAngle = randomAngle();
|
||||
|
||||
resetTerrain(topTerrain, g_TileClasses.land, hillHeight);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(topTerrain),
|
||||
new ElevationPainter(hillHeight),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
Engine.SetProgress(10);
|
||||
|
||||
addBases("radial", fractionToTiles(0.4), fractionToTiles(randFloat(0.05, 0.1)), startAngle);
|
||||
|
||||
@@ -367,11 +367,6 @@ function setHeight(x, z, height)
|
||||
g_Map.setHeight(x, z, height);
|
||||
}
|
||||
|
||||
function initHeight(height)
|
||||
{
|
||||
g_Map.initHeight(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility functions for classes
|
||||
*/
|
||||
|
||||
@@ -58,16 +58,6 @@ function Map(size, baseHeight)
|
||||
this.entityCount = 150;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the elevation of the entire heightmap grid to the given value.
|
||||
*/
|
||||
Map.prototype.initHeight = function(height)
|
||||
{
|
||||
for (let i = 0; i < this.size; ++i)
|
||||
for (let j = 0; j < this.size; ++j)
|
||||
this.height[i][j] = height;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the ID of a texture name.
|
||||
* Creates a new ID if there isn't one assigned yet.
|
||||
|
||||
@@ -30,6 +30,20 @@ RectPlacer.prototype.place = function(constraint)
|
||||
return points;
|
||||
};
|
||||
|
||||
/**
|
||||
* The MapBoundsPlacer returns all points on the tilemap that meet the constraint.
|
||||
*/
|
||||
function MapBoundsPlacer()
|
||||
{
|
||||
let mapBounds = getMapBounds();
|
||||
this.rectPlacer = new RectPlacer(mapBounds.left, mapBounds.top, mapBounds.right, mapBounds.bottom);
|
||||
}
|
||||
|
||||
MapBoundsPlacer.prototype.place = function(constraint)
|
||||
{
|
||||
return this.rectPlacer.place(constraint);
|
||||
};
|
||||
|
||||
/**
|
||||
* HeightPlacer constants determining whether the extrema should be included by the placer too.
|
||||
*/
|
||||
|
||||
@@ -110,22 +110,6 @@ function pickSize(sizes)
|
||||
return g_Sizes.normal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the entire map with the given terrain texture, tileclass and elevation.
|
||||
*/
|
||||
function resetTerrain(terrain, tileClass, elevation)
|
||||
{
|
||||
let mapCenter = getMapCenter();
|
||||
createArea(
|
||||
new ClumpPlacer(getMapArea(), 1, 1, 1, mapCenter.x, mapCenter.y),
|
||||
[
|
||||
new LayeredPainter([terrain], []),
|
||||
new SmoothElevationPainter(ELEVATION_SET, elevation, 1),
|
||||
paintClass(tileClass)
|
||||
],
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose starting locations for all players.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,12 @@ InitMap();
|
||||
setSelectedBiome();
|
||||
initTileClasses();
|
||||
|
||||
resetTerrain(g_Terrains.mainTerrain, g_TileClasses.land, getMapBaseHeight());
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
[
|
||||
new TerrainPainter(g_Terrains.mainTerrain),
|
||||
paintClass(g_TileClasses.land)
|
||||
]);
|
||||
Engine.SetProgress(20);
|
||||
|
||||
addBases("stronghold", fractionToTiles(randFloat(0.2, 0.35)), fractionToTiles(randFloat(0.05, 0.1)), randomAngle());
|
||||
|
||||
@@ -337,7 +337,10 @@ function unknownCentralRiver()
|
||||
{
|
||||
let waterHeight = -4;
|
||||
let shallowHeight = -2;
|
||||
initHeight(landHeight);
|
||||
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
let horizontal = randBool();
|
||||
let riverAngle = horizontal ? 0 : Math.PI / 2;
|
||||
@@ -401,7 +404,9 @@ function unknownCentralRiver()
|
||||
function unknownRiversAndLake()
|
||||
{
|
||||
let waterHeight = -4;
|
||||
initHeight(landHeight);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
let startAngle;
|
||||
if (!isNomad())
|
||||
@@ -475,7 +480,10 @@ function unknownRiversAndLake()
|
||||
function unknownEdgeSeas()
|
||||
{
|
||||
let waterHeight = -4;
|
||||
initHeight(landHeight);
|
||||
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
let horizontal = randBool();
|
||||
if (!isNomad())
|
||||
@@ -513,7 +521,10 @@ function unknownEdgeSeas()
|
||||
function unknownGulf()
|
||||
{
|
||||
let waterHeight = -3;
|
||||
initHeight(landHeight);
|
||||
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
let startAngle = randomAngle();
|
||||
if (!isNomad())
|
||||
@@ -554,7 +565,9 @@ function unknownLakes()
|
||||
{
|
||||
let waterHeight = -5;
|
||||
|
||||
initHeight(landHeight);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
if (!isNomad())
|
||||
{
|
||||
@@ -580,7 +593,10 @@ function unknownPasses()
|
||||
{
|
||||
let mountainHeight = 24;
|
||||
let waterHeight = -4;
|
||||
initHeight(landHeight);
|
||||
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(landHeight));
|
||||
|
||||
let playerAngle;
|
||||
let startAngle;
|
||||
@@ -659,7 +675,9 @@ function unknownLowlands()
|
||||
let mountainHeight = 30;
|
||||
|
||||
log("Creating mountain that is going to separate players...");
|
||||
initHeight(mountainHeight);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(mountainHeight));
|
||||
|
||||
let playerAngle;
|
||||
let startAngle;
|
||||
@@ -713,7 +731,9 @@ function unknownLowlands()
|
||||
*/
|
||||
function unknownMainland()
|
||||
{
|
||||
initHeight(3);
|
||||
createArea(
|
||||
new MapBoundsPlacer(),
|
||||
new ElevationPainter(3));
|
||||
|
||||
if (!isNomad())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user