diff --git a/binaries/data/mods/public/maps/random/rmgen/library.js b/binaries/data/mods/public/maps/random/rmgen/library.js index 30fbff4dd2..cccd8d80ea 100644 --- a/binaries/data/mods/public/maps/random/rmgen/library.js +++ b/binaries/data/mods/public/maps/random/rmgen/library.js @@ -6,6 +6,7 @@ const CELL_SIZE = 4; const HEIGHT_UNITS_PER_METRE = 92; const MIN_MAP_SIZE = 128; const MAX_MAP_SIZE = 512; +const MAP_BORDER_WIDTH = 3; const FALLBACK_CIV = "athen"; /** * Constants needed for heightmap_manipulation.js @@ -283,7 +284,7 @@ function createSimpleTerrain(terrain) function placeObject(x, z, type, player, angle) { - if (g_Map.validT(x, z, 3)) + if (g_Map.validT(x, z, MAP_BORDER_WIDTH)) g_Map.addObject(new Entity(type, player, x, z, angle)); } diff --git a/binaries/data/mods/public/maps/random/rmgen/placer.js b/binaries/data/mods/public/maps/random/rmgen/placer.js index 656863b6de..48573c6a20 100644 --- a/binaries/data/mods/public/maps/random/rmgen/placer.js +++ b/binaries/data/mods/public/maps/random/rmgen/placer.js @@ -453,9 +453,7 @@ SimpleObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, m { failCount++; if (failCount > maxFailCount) - { return undefined; - } } } } @@ -555,9 +553,7 @@ RandomObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, m { failCount++; if (failCount > maxFailCount) - { return undefined; - } } } } @@ -602,9 +598,7 @@ SimpleGroup.prototype.place = function(player, constraint) else { for (var j = 0; j < objs.length; ++j) - { resultObjs.push(objs[j]); - } } } @@ -612,13 +606,12 @@ SimpleGroup.prototype.place = function(player, constraint) length = resultObjs.length; for (var i=0; i < length; i++) { - if (g_Map.validT(round(resultObjs[i].position.x/CELL_SIZE), round(resultObjs[i].position.z/CELL_SIZE), 3)) + if (g_Map.validT(resultObjs[i].position.x / CELL_SIZE, resultObjs[i].position.z / CELL_SIZE, MAP_BORDER_WIDTH)) g_Map.addObject(resultObjs[i]); + // Convert position to integer number of tiles if (this.tileClass !== undefined) - { // Convert position to integer number of tiles this.tileClass.add(Math.floor(resultObjs[i].position.x/CELL_SIZE), Math.floor(resultObjs[i].position.z/CELL_SIZE)); - } } return true; @@ -653,16 +646,15 @@ RandomGroup.prototype.place = function(player, constraint) var placer = this.elements[randInt(this.elements.length)]; var objs = placer.place(this.x, this.z, player, this.avoidSelf, constraint); + // Failure if (objs === undefined) - { // Failure + { return false; } else { for (var j = 0; j < objs.length; ++j) - { resultObjs.push(objs[j]); - } } // Add placed objects to map @@ -671,10 +663,9 @@ RandomGroup.prototype.place = function(player, constraint) { g_Map.addObject(resultObjs[i]); + // Convert position to integer number of tiles if (this.tileClass !== undefined) - { // Convert position to integer number of tiles this.tileClass.add(Math.floor(resultObjs[i].position.x/CELL_SIZE), Math.floor(resultObjs[i].position.z/CELL_SIZE)); - } } return true; diff --git a/binaries/data/mods/public/maps/random/rmgen/terrain.js b/binaries/data/mods/public/maps/random/rmgen/terrain.js index 201868781e..1b61b8c640 100644 --- a/binaries/data/mods/public/maps/random/rmgen/terrain.js +++ b/binaries/data/mods/public/maps/random/rmgen/terrain.js @@ -31,9 +31,7 @@ Terrain.prototype.placeNew = function() {}; function SimpleTerrain(texture, treeType) { if (texture === undefined) - { throw("SimpleTerrain: texture not defined"); - } this.texture = texture; this.treeType = treeType; @@ -43,10 +41,8 @@ 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), 3)) - { + if (this.treeType !== undefined && g_Map.validT(round(x), round(z), MAP_BORDER_WIDTH)) g_Map.terrainObjects[x][z] = new Entity(this.treeType, 0, x+0.5, z+0.5, randFloat()*TWO_PI); - } g_Map.texture[x][z] = g_Map.getTextureID(this.texture); }; @@ -63,9 +59,7 @@ SimpleTerrain.prototype.placeNew = function(x, z) function RandomTerrain(terrains) { if (!(terrains instanceof Array) || !terrains.length) - { throw("RandomTerrain: Invalid terrains array"); - } this.terrains = terrains; }