1
0
forked from mirrors/0ad

Fix rmgen2 SimpleObject and RandomObject ignoring the 3 invalid map border tiles.

Let validT take the responsability to account for the actually valid
region of map tiles instead of each caller.

Fixes #4814, refs #4636, #4796

This was SVN commit r20283.
This commit is contained in:
elexis
2017-10-11 01:48:12 +00:00
parent 13b2858259
commit 3a1c5669f8
7 changed files with 13 additions and 11 deletions
@@ -362,8 +362,8 @@ for (var ix = 0; ix < mapSize; ix++)
explorableArea.points.push(pt);
}
if (h > 35 && g_Map.validT(ix, iz) && randBool(0.1) ||
h < 15 && g_Map.validT(ix, iz) && randBool(0.05) && hillDecoClass.countMembersInRadius(ix, iz, 1) == 0)
if (h > 35 && randBool(0.1) ||
h < 15 && randBool(0.05) && hillDecoClass.countMembersInRadius(ix, iz, 1) == 0)
placeObject(ix + randFloat(0, 1), iz + randFloat(0, 1), pickRandom(aTrees), 0, randFloat(0, 2 * PI));
}
}
@@ -226,7 +226,7 @@ function createObjectGroups(placer, player, constraint, amount, retryFactor = 10
"placer": placer,
"player": player,
"constraint": constraint,
"halfMapSize": g_Map.size / 2 - 3
"halfMapSize": getMapSize() / 2 - MAP_BORDER_WIDTH
};
return retryPlacing(placeFunc, args, retryFactor, amount, false, behaveDeprecated);
@@ -280,7 +280,7 @@ function createSimpleTerrain(terrain)
function placeObject(x, z, type, player, angle)
{
if (g_Map.validT(x, z, MAP_BORDER_WIDTH))
if (g_Map.validT(x, z))
g_Map.addObject(new Entity(type, player, x, z, angle));
}
@@ -86,6 +86,8 @@ Map.prototype.getEntityID = function()
// Check bounds on tile map
Map.prototype.validT = function(x, z, distance = 0)
{
distance += MAP_BORDER_WIDTH;
if (g_MapSettings.CircularMap)
{
let halfSize = Math.floor(this.size / 2);
@@ -159,7 +161,7 @@ Map.prototype.getTerrainObjects = function(x, z)
Map.prototype.setTerrainObject = function(x, z, object)
{
if (!this.validT(x, z, 2))
if (!this.validT(x, z))
throw "setTerrainObject: invalid tile position (" + x + ", " + z + ")";
this.terrainObjects[x][z] = object;
@@ -523,7 +523,7 @@ SimpleGroup.prototype.place = function(player, constraint)
// Add placed objects to map
for (let obj of resultObjs)
{
if (g_Map.validT(obj.position.x / CELL_SIZE, obj.position.z / CELL_SIZE, MAP_BORDER_WIDTH))
if (g_Map.validT(obj.position.x / CELL_SIZE, obj.position.z / CELL_SIZE))
g_Map.addObject(obj);
// Convert position to integer number of tiles
@@ -41,7 +41,7 @@ SimpleTerrain.prototype = new Terrain();
SimpleTerrain.prototype.constructor = SimpleTerrain;
SimpleTerrain.prototype.placeNew = function(x, z)
{
if (this.treeType !== undefined && g_Map.validT(round(x), round(z), MAP_BORDER_WIDTH))
if (this.treeType !== undefined && g_Map.validT(Math.round(x), Math.round(z)))
g_Map.terrainObjects[x][z] = new Entity(this.treeType, 0, x + 0.5, z + 0.5, randFloat(0, 2 * PI));
g_Map.texture[x][z] = g_Map.getTextureID(this.texture);
@@ -875,7 +875,7 @@ function addStragglerTrees(constraint, size, deviation, fill)
var trees = [g_Gaia.tree1, g_Gaia.tree2, g_Gaia.tree3, g_Gaia.tree4];
var treesPerPlayer = 40;
var playerBonus = Math.max(1, (getNumPlayers() - 3) / 2);
var playerBonus = Math.max(1, (getNumPlayers() - MAP_BORDER_WIDTH) / 2);
var offset = getRandomDeviation(size, deviation);
var treeCount = treesPerPlayer * playerBonus * fill;
@@ -1170,7 +1170,7 @@ function smoothElevation(x, z)
{
var thisX = x + xOffset;
var thisZ = z + zOffset;
if (!g_Map.validT(thisX, thisZ))
if (!g_Map.validH(thisX, thisZ))
continue;
var height = g_Map.getHeight(thisX, thisZ);
@@ -1069,7 +1069,7 @@ for (var i = 0; i < numPlayers; i++)
{
for (var mz = 0; mz < mapSize; mz++)
{
if (!g_Map.validT(mx, mz, 6))
if (!g_Map.validT(mx, mz, 3))
continue;
var placable = true;
@@ -1090,7 +1090,7 @@ for (var i = 0; i < numPlayers; i++)
{
for (var mz = 0; mz < mapSize; mz++)
{
if (!g_Map.validT(mx, mz, 6))
if (!g_Map.validT(mx, mz, 3))
continue;
var placable = true;