From d8665adf4235be42411ec96512a72378c083e032 Mon Sep 17 00:00:00 2001 From: elexis Date: Fri, 28 Oct 2016 16:01:02 +0000 Subject: [PATCH] Random map script cleanup. Remove many unneeded parenthesis when assigning variables. Use min and max to avoid ternaries. Simplify ternaries that return booleans. Remove == true from checks. This was SVN commit r18881. --- .../data/mods/public/maps/random/fortress.js | 7 +- .../mods/public/maps/random/rmgen/placer.js | 54 +++--- .../maps/random/rmgen/utilityfunctions.js | 21 ++- .../public/maps/random/rmgen/wall_builder.js | 175 +++++++++--------- 4 files changed, 131 insertions(+), 126 deletions(-) diff --git a/binaries/data/mods/public/maps/random/fortress.js b/binaries/data/mods/public/maps/random/fortress.js index 3f07d018c2..402ef8eb63 100644 --- a/binaries/data/mods/public/maps/random/fortress.js +++ b/binaries/data/mods/public/maps/random/fortress.js @@ -103,7 +103,8 @@ for (var i=0; i < numPlayers; i++) placeObject(ux, uz, startEntities[j].Template, i+1, uAngle); } } - // create resources + + // Create treasure var bbAngle = BUILDING_ORIENTATION; var bbDist = 10; var bbX = round(playerX[i] + bbDist * cos(bbAngle)); @@ -143,7 +144,7 @@ for (var i=0; i < numPlayers; i++) // Base texture var civ = getCivCode(i); - var tilesSize = (civ == "cart" ? 27 : 22); + var tilesSize = civ == "cart" ? 27 : 22; const minBoundX = (playerX[i] > tilesSize ? playerX[i] - tilesSize : 0); const minBoundY = (playerZ[i] > tilesSize ? playerZ[i] - tilesSize : 0); @@ -151,7 +152,6 @@ for (var i=0; i < numPlayers; i++) const maxBoundY = (playerZ[i] < mapSize - tilesSize ? playerZ[i] + tilesSize : mapSize); for (var tx = minBoundX; tx < maxBoundX; ++tx) - { for (var ty = minBoundY; ty < maxBoundY; ++ty) { var unboundSumOfXY = tx + ty - minBoundX - minBoundY; @@ -161,7 +161,6 @@ for (var i=0; i < numPlayers; i++) addToClass(floor(tx), floor(ty), clPlayer); } } - } // Place custom fortress if (civ == "brit" || civ == "gaul" || civ == "iber") diff --git a/binaries/data/mods/public/maps/random/rmgen/placer.js b/binaries/data/mods/public/maps/random/rmgen/placer.js index 636be06aa2..06f943db3f 100644 --- a/binaries/data/mods/public/maps/random/rmgen/placer.js +++ b/binaries/data/mods/public/maps/random/rmgen/placer.js @@ -16,9 +16,9 @@ function ClumpPlacer(size, coherence, smoothness, failFraction, x, z) this.size = size; this.coherence = coherence; this.smoothness = smoothness; - this.failFraction = (failFraction !== undefined ? failFraction : 0); - this.x = (x !== undefined ? x : -1); - this.z = (z !== undefined ? z : -1); + this.failFraction = failFraction !== undefined ? failFraction : 0; + this.x = x !== undefined ? x : -1; + this.z = z !== undefined ? z : -1; } ClumpPlacer.prototype.place = function(constraint) @@ -69,7 +69,7 @@ ClumpPlacer.prototype.place = function(constraint) var v2 = ctrlVals[(c+1)%ctrlPts]; var v3 = ctrlVals[(c+2)%ctrlPts]; var P = (v3 - v2) - (v0 - v1); - var Q = (v0 - v1) - P; + var Q = v0 - v1 - P; var R = v2 - v0; var S = v1; @@ -130,11 +130,11 @@ function ChainPlacer(minRadius, maxRadius, numCircles, failFraction, x, z, fcc, this.minRadius = minRadius; this.maxRadius = maxRadius; this.numCircles = numCircles; - this.failFraction = (failFraction !== undefined ? failFraction : 0); - this.x = (x !== undefined ? x : -1); - this.z = (z !== undefined ? z : -1); - this.fcc = (fcc !== undefined ? fcc : 0); - this.q = (q !== undefined ? q : []); + this.failFraction = failFraction !== undefined ? failFraction : 0; + this.x = x !== undefined ? x : -1; + this.z = z !== undefined ? z : -1; + this.fcc = fcc !== undefined ? fcc : 0; + this.q = q !== undefined ? q : []; } ChainPlacer.prototype.place = function(constraint) @@ -146,7 +146,7 @@ ChainPlacer.prototype.place = function(constraint) var retVec = []; var size = getMapSize(); var failed = 0, count = 0; - var queueEmpty = (this.q.length ? false : true); + var queueEmpty = !this.q.length; var gotRet = new Array(size).fill(0).map(p => new Array(size).fill(-1)); --size; @@ -164,16 +164,16 @@ ChainPlacer.prototype.place = function(constraint) else { var radius = this.q.pop(); - queueEmpty = (this.q.length ? false : true); + queueEmpty = !this.q.length; } var sx = cx - radius, lx = cx + radius; var sz = cz - radius, lz = cz + radius; - sx = (sx < 0 ? 0 : sx); - sz = (sz < 0 ? 0 : sz); - lx = (lx > size ? size : lx); - lz = (lz > size ? size : lz); + sx = Math.max(0, sx); + sz = Math.max(0, sz); + lx = Math.min(lx, size); + lz = Math.min(lz, size); var radius2 = radius * radius; var dx, dz; @@ -330,8 +330,8 @@ function SimpleObject(type, minCount, maxCount, minDistance, maxDistance, minAng this.maxCount = maxCount; this.minDistance = minDistance; this.maxDistance = maxDistance; - this.minAngle = (minAngle !== undefined ? minAngle : 0); - this.maxAngle = (maxAngle !== undefined ? maxAngle : 2*PI); + this.minAngle = minAngle !== undefined ? minAngle : 0; + this.maxAngle = maxAngle !== undefined ? maxAngle : 2*PI; if (minCount > maxCount) warn("SimpleObject: minCount should be less than or equal to maxCount"); @@ -421,8 +421,8 @@ function RandomObject(types, minCount, maxCount, minDistance, maxDistance, minAn this.maxCount = maxCount; this.minDistance = minDistance; this.maxDistance = maxDistance; - this.minAngle = (minAngle !== undefined ? minAngle : 0); - this.maxAngle = (maxAngle !== undefined ? maxAngle : 2*PI); + this.minAngle = minAngle !== undefined ? minAngle : 0; + this.maxAngle = maxAngle !== undefined ? maxAngle : 2*PI; if (minCount > maxCount) warn("RandomObject: minCount should be less than or equal to maxCount"); @@ -511,10 +511,10 @@ RandomObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, m function SimpleGroup(elements, avoidSelf, tileClass, x, z) { this.elements = elements; - this.tileClass = (tileClass !== undefined ? getTileClass(tileClass) : undefined); - this.avoidSelf = (avoidSelf !== undefined ? avoidSelf : false); - this.x = (x !== undefined ? x : -1); - this.z = (z !== undefined ? z : -1); + this.tileClass = tileClass !== undefined ? getTileClass(tileClass) : undefined; + this.avoidSelf = avoidSelf !== undefined ? avoidSelf : false; + this.x = x !== undefined ? x : -1; + this.z = z !== undefined ? z : -1; } SimpleGroup.prototype.place = function(player, constraint) @@ -561,10 +561,10 @@ SimpleGroup.prototype.place = function(player, constraint) function RandomGroup(elements, avoidSelf, tileClass, x, z) { this.elements = elements; - this.tileClass = (tileClass !== undefined ? getTileClass(tileClass) : undefined); - this.avoidSelf = (avoidSelf !== undefined ? avoidSelf : false); - this.x = (x !== undefined ? x : -1); - this.z = (z !== undefined ? z : -1); + this.tileClass = tileClass !== undefined ? getTileClass(tileClass) : undefined; + this.avoidSelf = avoidSelf !== undefined ? avoidSelf : false; + this.x = x !== undefined ? x : -1; + this.z = z !== undefined ? z : -1; } RandomGroup.prototype.place = function(player, constraint) diff --git a/binaries/data/mods/public/maps/random/rmgen/utilityfunctions.js b/binaries/data/mods/public/maps/random/rmgen/utilityfunctions.js index 76ed9841e3..d960553383 100644 --- a/binaries/data/mods/public/maps/random/rmgen/utilityfunctions.js +++ b/binaries/data/mods/public/maps/random/rmgen/utilityfunctions.js @@ -53,13 +53,13 @@ function createMountains(terrain, constraint, tileclass, count, maxHeight, minRa { log("Creating mountains..."); - tileclass = (tileclass !== undefined ? tileclass : clHill); - constraint = (constraint !== undefined ? constraint : avoidClasses(clPlayer, 20, clHill, 15)); - count = (count !== undefined ? count : scaleByMapSize(1, 4) * getNumPlayers()); - maxHeight = (maxHeight !== undefined ? maxHeight : floor(scaleByMapSize(30, 50))); - minRadius = (minRadius !== undefined ? minRadius : floor(scaleByMapSize(3, 4))); - maxRadius = (maxRadius !== undefined ? maxRadius : floor(scaleByMapSize(6, 12))); - numCircles = (numCircles !== undefined ? numCircles : floor(scaleByMapSize(4, 10))); + tileclass = tileclass !== undefined ? tileclass : clHill; + constraint = constraint !== undefined ? constraint : avoidClasses(clPlayer, 20, clHill, 15); + count = count !== undefined ? count : scaleByMapSize(1, 4) * getNumPlayers(); + maxHeight = maxHeight !== undefined ? maxHeight : floor(scaleByMapSize(30, 50)); + minRadius = minRadius !== undefined ? minRadius : floor(scaleByMapSize(3, 4)); + maxRadius = maxRadius !== undefined ? maxRadius : floor(scaleByMapSize(6, 12)); + numCircles = numCircles !== undefined ? numCircles : floor(scaleByMapSize(4, 10)); var numHills = count; for (var i = 0; i < numHills; ++i) @@ -236,8 +236,11 @@ function createStragglerTrees(types, constraint, tileclass) { log("Creating straggler trees..."); - constraint = (constraint !== undefined ? constraint : avoidClasses(clForest, 8, clHill, 1, clPlayer, 12, clMetal, 1, clRock, 1)); - tileclass = (tileclass !== undefined ? tileclass : clForest); + constraint = constraint !== undefined ? + constraint : + avoidClasses(clForest, 8, clHill, 1, clPlayer, 12, clMetal, 1, clRock, 1); + + tileclass = tileclass !== undefined ? tileclass : clForest; var num = floor(g_numStragglerTrees / types.length); for (var i = 0; i < types.length; ++i) diff --git a/binaries/data/mods/public/maps/random/rmgen/wall_builder.js b/binaries/data/mods/public/maps/random/rmgen/wall_builder.js index c006f8ce40..d757c234fd 100644 --- a/binaries/data/mods/public/maps/random/rmgen/wall_builder.js +++ b/binaries/data/mods/public/maps/random/rmgen/wall_builder.js @@ -73,10 +73,10 @@ function WallElement(type, entity, angle, width, indent, bending) // "house" A zero-length wall element without bending far indented so it stands inside the wall that grants population bonus, example: house, hut, longhouse // "barracks" A zero-length wall element without bending far indented so it stands inside the wall that grants unit production, example: barracks, tavern, ... this.entity = entity; - this.angle = (angle !== undefined) ? angle : 0*PI; - this.width = (width !== undefined) ? width : 0; - this.indent = (indent !== undefined) ? indent : 0; - this.bending = (bending !== undefined) ? bending : 0*PI; + this.angle = angle !== undefined ? angle : 0; + this.width = width !== undefined ? width : 0; + this.indent = indent !== undefined ? indent : 0; + this.bending = bending !== undefined ? bending : 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -93,11 +93,10 @@ function WallElement(type, entity, angle, width, indent, bending) function Fortress(type, wall, centerToFirstElement) { this.type = type; // Only usefull to get the type of the actual fortress - this.wall = (wall !== undefined) ? wall : []; + this.wall = wall !== undefined ? wall : []; this.centerToFirstElement = undefined; } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // wallStyles data structure for default wall styles // @@ -330,7 +329,7 @@ function getWallAlignment(startX, startY, wall, style, orientation) warn("Function getWallAlignment: Unknown style: " + style + ' (falling back to "athen")'); style = "athen"; } - orientation = (orientation || 0); + orientation = orientation || 0; var alignment = []; var wallX = startX; @@ -340,11 +339,19 @@ function getWallAlignment(startX, startY, wall, style, orientation) var element = wallStyles[style][wall[i]]; if (element === undefined && i == 0) warn("No valid wall element: " + wall[i]); + // Indentation var placeX = wallX - element.indent * cos(orientation); var placeY = wallY - element.indent * sin(orientation); + // Add wall elements entity placement arguments to the alignment - alignment.push({"x": placeX, "y": placeY, "entity": element.entity, "angle":orientation + element.angle}); + alignment.push({ + "x": placeX, + "y": placeY, + "entity": element.entity, + "angle": orientation + element.angle + }); + // Preset vars for the next wall element if (i+1 < wall.length) { @@ -410,9 +417,8 @@ function getWallLength(wall, style) var length = 0; for (var i = 0; i < wall.length; i++) - { length += wallStyles[style][wall[i]].width; - } + return length; } @@ -440,15 +446,15 @@ function placeWall(startX, startY, wall, style, playerId, orientation) // Graciously handle arguments if (wall === undefined) wall = []; - playerId = (playerId || 0); + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } - orientation = (orientation || 0); + orientation = orientation || 0; // Get wall alignment var AM = getWallAlignment(startX, startY, wall, style, orientation); @@ -475,13 +481,13 @@ function placeWall(startX, startY, wall, style, playerId, orientation) function placeCustomFortress(centerX, centerY, fortress, style, playerId = 0, orientation = BUILDING_ORIENTATION) { // Graciously handle arguments - fortress = (fortress || fortressTypes["medium"]); + fortress = fortress || fortressTypes.medium; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } // Calculate center if fortress.centerToFirstElement is undefined (default) @@ -502,16 +508,16 @@ function placeCustomFortress(centerX, centerY, fortress, style, playerId = 0, or function placeFortress(centerX, centerY, type, style, playerId, orientation) { // Graciously handle arguments - type = (type || "medium"); - playerId = (playerId || 0); + type = type || "medium"; + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } - orientation = (orientation || 0); + orientation = orientation || 0; // Call placeCustomFortress with the given arguments placeCustomFortress(centerX, centerY, fortressTypes[type], style, playerId, orientation); @@ -534,14 +540,14 @@ function placeFortress(centerX, centerY, type, style, playerId, orientation) function placeLinearWall(startX, startY, targetX, targetY, wallPart, style, playerId, endWithFirst) { // Setup optional arguments to the default - wallPart = (wallPart || ["tower", "wallLong"]); - playerId = (playerId || 0); + wallPart = wallPart || ["tower", "wallLong"]; + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } endWithFirst = typeof endWithFirst == "undefined" ? true : endWithFirst; @@ -558,13 +564,13 @@ function placeLinearWall(startX, startY, targetX, targetY, wallPart, style, play for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++) wallPartLength += wallStyles[style][wallPart[elementIndex]].width; var numParts = 0; - if (endWithFirst == true) + if (endWithFirst) numParts = ceil((totalLength - wallStyles[style][wallPart[0]].width) / wallPartLength); else numParts = ceil(totalLength / wallPartLength); // Setup scale factor var scaleFactor = 1; - if (endWithFirst == true) + if (endWithFirst) scaleFactor = totalLength / (numParts * wallPartLength + wallStyles[style][wallPart[0]].width); else scaleFactor = totalLength / (numParts * wallPartLength); @@ -593,7 +599,7 @@ function placeLinearWall(startX, startY, targetX, targetY, wallPart, style, play y += scaleFactor * wallEle.width/2 * sin(wallAngle); } } - if (endWithFirst == true) + if (endWithFirst) { var wallEle = wallStyles[style][wallPart[0]]; x += scaleFactor * wallEle.width/2 * cos(wallAngle); @@ -628,25 +634,22 @@ function placeLinearWall(startX, startY, targetX, targetY, wallPart, style, play function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, orientation, maxAngle, endWithFirst, maxBendOff) { // Setup optional arguments to the default - wallPart = (wallPart || ["tower", "wallLong"]); - playerId = (playerId || 0); + wallPart = wallPart || ["tower", "wallLong"]; + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } - orientation = (orientation || 0); - maxAngle = (maxAngle || 2*PI); + orientation = orientation || 0; + maxAngle = maxAngle || 2*PI; + if (endWithFirst === undefined) - { - if (maxAngle >= 2*PI - 0.001) // Can this be done better? - endWithFirst = false; - else - endWithFirst = true; - } - maxBendOff = (maxBendOff || 0); + endWithFirst = maxAngle < 2*PI - 0.001; // Can this be done better? + + maxBendOff = maxBendOff || 0; // Check arguments if (maxBendOff > PI/2 || maxBendOff < 0) @@ -663,26 +666,23 @@ function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++) wallPartLength += wallStyles[style][wallPart[elementIndex]].width; var numParts = 0; - if (endWithFirst == true) - { + if (endWithFirst) numParts = ceil((totalLength - wallStyles[style][wallPart[0]].width) / wallPartLength); - } else - { numParts = ceil(totalLength / wallPartLength); - } + // Setup scale factor var scaleFactor = 1; - if (endWithFirst == true) + if (endWithFirst) scaleFactor = totalLength / (numParts * wallPartLength + wallStyles[style][wallPart[0]].width); else scaleFactor = totalLength / (numParts * wallPartLength); + // Place wall entities var actualAngle = orientation + (2*PI - maxAngle) / 2; var x = centerX + radius*cos(actualAngle); var y = centerY + radius*sin(actualAngle); for (var partIndex = 0; partIndex < numParts; partIndex++) - { for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++) { var wallEle = wallStyles[style][wallPart[elementIndex]]; @@ -705,8 +705,8 @@ function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, x = centerX + radius*cos(actualAngle); y = centerY + radius*sin(actualAngle); } - } - if (endWithFirst == true) + + if (endWithFirst) { var wallEle = wallStyles[style][wallPart[0]]; var addAngle = scaleFactor * wallEle.width / radius; @@ -742,19 +742,20 @@ function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, function placePolygonalWall(centerX, centerY, radius, wallPart, cornerWallElement, style, playerId, orientation, numCorners, skipFirstWall) { // Setup optional arguments to the default - wallPart = (wallPart || ["wallLong", "tower"]); - cornerWallElement = (cornerWallElement || "tower"); // Don't use wide elements for this. Not supported well... - playerId = (playerId || 0); + wallPart = wallPart || ["wallLong", "tower"]; + cornerWallElement = cornerWallElement || "tower"; // Don't use wide elements for this. Not supported well... + playerId = playerId || 0; + if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } - orientation = (orientation || 0); - numCorners = (numCorners || 8); - skipFirstWall = (skipFirstWall || true); + orientation = orientation || 0; + numCorners = numCorners || 8; + skipFirstWall = skipFirstWall || true; // Setup angles var angleAdd = 2*PI/numCorners; @@ -768,8 +769,7 @@ function placePolygonalWall(centerX, centerY, radius, wallPart, cornerWallElemen { var angleToCorner = getAngle(corners[i][0], corners[i][1], centerX, centerY); placeObject(corners[i][0], corners[i][1], wallStyles[style][cornerWallElement].entity, playerId, angleToCorner); - if (!(skipFirstWall && i == 0)) - { + if (!skipFirstWall || i != 0) placeLinearWall( // Adjustment to the corner element width (approximately) corners[i][0] + wallStyles[style][cornerWallElement].width/2 * sin(angleToCorner + angleAdd/2), // startX @@ -777,7 +777,6 @@ function placePolygonalWall(centerX, centerY, radius, wallPart, cornerWallElemen corners[(i+1)%numCorners][0] - wallStyles[style][cornerWallElement].width/2 * sin(angleToCorner + angleAdd/2), // targetX corners[(i+1)%numCorners][1] + wallStyles[style][cornerWallElement].width/2 * cos(angleToCorner + angleAdd/2), // targetY wallPart, style, playerId); - } } } @@ -806,13 +805,13 @@ function placePolygonalWall(centerX, centerY, radius, wallPart, cornerWallElemen function placeIrregularPolygonalWall(centerX, centerY, radius, cornerWallElement, style, playerId, orientation, numCorners, irregularity, skipFirstWall, wallPartsAssortment) { // Setup optional arguments - playerId = (playerId || 0); + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId-1); } // Generating a generic wall part assortment with each wall part including 1 gate lengthened by walls and towers @@ -838,14 +837,15 @@ function placeIrregularPolygonalWall(centerX, centerY, radius, cornerWallElement } } // Setup optional arguments to the default - wallPartsAssortment = (wallPartsAssortment || defaultWallPartsAssortment); - cornerWallElement = (cornerWallElement || "tower"); // Don't use wide elements for this. Not supported well... - style = (style || "palisades"); - playerId = (playerId || 0); - orientation = (orientation || 0); - numCorners = (numCorners || randInt(5, 7)); - irregularity = (irregularity || 0.5); - skipFirstWall = (skipFirstWall || false); + wallPartsAssortment = wallPartsAssortment || defaultWallPartsAssortment; + cornerWallElement = cornerWallElement || "tower"; // Don't use wide elements for this. Not supported well... + style = style || "palisades"; + playerId = playerId || 0; + orientation = orientation || 0; + numCorners = numCorners || randInt(5, 7); + irregularity = irregularity || 0.5; + skipFirstWall = skipFirstWall || false; + // Setup angles var angleToCover = 2*PI; var angleAddList = []; @@ -898,8 +898,7 @@ function placeIrregularPolygonalWall(centerX, centerY, radius, cornerWallElement { var angleToCorner = getAngle(corners[i][0], corners[i][1], centerX, centerY); placeObject(corners[i][0], corners[i][1], wallStyles[style][cornerWallElement].entity, playerId, angleToCorner); - if (!(skipFirstWall && i == 0)) - { + if (!skipFirstWall || i != 0) placeLinearWall( // Adjustment to the corner element width (approximately) corners[i][0] + wallStyles[style][cornerWallElement].width/2 * sin(angleToCorner + angleAddList[i]/2), // startX @@ -907,7 +906,6 @@ function placeIrregularPolygonalWall(centerX, centerY, radius, cornerWallElement corners[(i+1)%numCorners][0] - wallStyles[style][cornerWallElement].width/2 * sin(angleToCorner + angleAddList[(i+1)%numCorners]/2), // targetX corners[(i+1)%numCorners][1] + wallStyles[style][cornerWallElement].width/2 * cos(angleToCorner + angleAddList[(i+1)%numCorners]/2), // targetY wallPartList[i], style, playerId, false); - } } } @@ -928,31 +926,31 @@ function placeIrregularPolygonalWall(centerX, centerY, radius, cornerWallElement function placeGenericFortress(centerX, centerY, radius, playerId, style, irregularity, gateOccurence, maxTrys) { // Setup optional arguments - radius = (radius || 20); - playerId = (playerId || 0); + radius = radius || 20; + playerId = playerId || 0; if (!wallStyles.hasOwnProperty(style)) { if (playerId == 0) - style = (style || "palisades"); + style = style || "palisades"; else - style = (getCivCode(playerId-1)); + style = getCivCode(playerId - 1); } - irregularity = (irregularity || 1/2); - gateOccurence = (gateOccurence || 3); - maxTrys = (maxTrys || 100); + irregularity = irregularity || 1/2; + gateOccurence = gateOccurence || 3; + maxTrys = maxTrys || 100; // Setup some vars var startAngle = randFloat(0, 2*PI); var actualOffX = radius*cos(startAngle); var actualOffY = radius*sin(startAngle); var actualAngle = startAngle; - var pointDistance = wallStyles[style]["wallLong"].width + wallStyles[style]["tower"].width; + var pointDistance = wallStyles[style].wallLong.width + wallStyles[style].tower.width; // Searching for a well fitting point derivation var tries = 0; var bestPointDerivation = undefined; var minOverlap = 1000; var overlap = undefined; - while (tries < maxTrys && minOverlap > wallStyles[style]["tower"].width / 10) + while (tries < maxTrys && minOverlap > wallStyles[style].tower.width / 10) { var pointDerivation = []; var distanceToTarget = 1000; @@ -1005,6 +1003,11 @@ function placeGenericFortress(centerX, centerY, radius, playerId, style, irregul var startX = centerX + bestPointDerivation[(pointIndex + bestPointDerivation.length - 1) % bestPointDerivation.length][0]; var startY = centerY + bestPointDerivation[(pointIndex + bestPointDerivation.length - 1) % bestPointDerivation.length][1]; var angle = getAngle(startX, startY, targetX, targetY); - placeObject(centerX + bestPointDerivation[pointIndex][0], centerY + bestPointDerivation[pointIndex][1], wallStyles[style]["tower"].entity, playerId, angle - PI/2 + wallStyles[style]["tower"].angle); + placeObject( + centerX + bestPointDerivation[pointIndex][0], + centerY + bestPointDerivation[pointIndex][1], + wallStyles[style].tower.entity, + playerId, + angle - PI/2 + wallStyles[style].tower.angle); } }