From e42e02d4fea2da43d2626dca63e9e7b449cbf574 Mon Sep 17 00:00:00 2001 From: mimo Date: Sat, 19 Sep 2015 12:41:21 +0000 Subject: [PATCH] bunch of cleanup (mainly missing semicolon) signaled by jshint This was SVN commit r17044. --- .../public/simulation/ai/common-api/baseAI.js | 2 +- .../public/simulation/ai/common-api/class.js | 2 +- .../public/simulation/ai/common-api/entity.js | 2 +- .../ai/common-api/entitycollection.js | 4 ++-- .../simulation/ai/common-api/gamestate.js | 2 +- .../public/simulation/ai/common-api/shared.js | 10 ++++++---- .../ai/common-api/terrain-analysis.js | 6 +++--- .../public/simulation/ai/common-api/utils.js | 14 ++++++++------ .../simulation/ai/petra/attackManager.js | 18 +++++++++--------- .../public/simulation/ai/petra/attackPlan.js | 2 +- .../public/simulation/ai/petra/baseManager.js | 6 +++--- .../public/simulation/ai/petra/defenseArmy.js | 6 +++--- .../simulation/ai/petra/defenseManager.js | 10 +++++----- .../simulation/ai/petra/diplomacyManager.js | 2 +- .../public/simulation/ai/petra/headquarters.js | 4 ++-- .../public/simulation/ai/petra/navalManager.js | 6 +++--- .../mods/public/simulation/ai/petra/queue.js | 2 +- .../public/simulation/ai/petra/queueManager.js | 6 +++--- .../public/simulation/ai/petra/queueplan--.js | 2 +- .../simulation/ai/petra/queueplan-building.js | 2 +- .../simulation/ai/petra/queueplan-training.js | 2 +- .../simulation/ai/petra/researchManager.js | 4 ++-- .../simulation/ai/petra/startingStrategy.js | 16 ++++++++-------- .../public/simulation/ai/petra/tradeManager.js | 10 +++++----- .../simulation/ai/petra/transportPlan.js | 2 +- .../mods/public/simulation/ai/petra/worker.js | 11 ++++++----- 26 files changed, 79 insertions(+), 74 deletions(-) diff --git a/binaries/data/mods/public/simulation/ai/common-api/baseAI.js b/binaries/data/mods/public/simulation/ai/common-api/baseAI.js index 10887152b5..ace108a4bf 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/baseAI.js +++ b/binaries/data/mods/public/simulation/ai/common-api/baseAI.js @@ -60,7 +60,7 @@ m.BaseAI.prototype.Init = function(state, playerID, sharedAI) this.barterPrices = sharedAI.barterPrices; this.CustomInit(this.gameState, this.sharedScript); -} +}; m.BaseAI.prototype.CustomInit = function() { // AIs override this function diff --git a/binaries/data/mods/public/simulation/ai/common-api/class.js b/binaries/data/mods/public/simulation/ai/common-api/class.js index 2767debace..97bea98d7a 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/class.js +++ b/binaries/data/mods/public/simulation/ai/common-api/class.js @@ -23,7 +23,7 @@ m.Class = function(data) } return ctor; -} +}; /* Test inheritance: var A = Class({foo:1, bar:10}); diff --git a/binaries/data/mods/public/simulation/ai/common-api/entity.js b/binaries/data/mods/public/simulation/ai/common-api/entity.js index 178a654799..e80ae0c473 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/entity.js +++ b/binaries/data/mods/public/simulation/ai/common-api/entity.js @@ -738,7 +738,7 @@ m.Entity = m.Class({ return undefined; }, - isGarrisonHolder: function() { return this.get("GarrisonHolder") }, + isGarrisonHolder: function() { return this.get("GarrisonHolder"); }, garrisoned: function() { return this._entity.garrisoned; }, diff --git a/binaries/data/mods/public/simulation/ai/common-api/entitycollection.js b/binaries/data/mods/public/simulation/ai/common-api/entitycollection.js index 16b4d6f954..86df56582e 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/entitycollection.js +++ b/binaries/data/mods/public/simulation/ai/common-api/entitycollection.js @@ -41,9 +41,9 @@ m.EntityCollection.prototype.Deserialize = function(data, sharedAI) this._filters.push(eval(f)); if (data.frozen) - this.freeze; + this.freeze(); else - this.defreeze; + this.defreeze(); }; // If an entitycollection is frozen, it will never automatically add a unit. diff --git a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js index 363defe449..a049733a68 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js +++ b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js @@ -212,7 +212,7 @@ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementChec } return this.checkTechRequirements(template.requirements()); -} +}; // Private function for checking a set of requirements is met // basically copies TechnologyManager's diff --git a/binaries/data/mods/public/simulation/ai/common-api/shared.js b/binaries/data/mods/public/simulation/ai/common-api/shared.js index d0a026b196..ed297e7e31 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/shared.js +++ b/binaries/data/mods/public/simulation/ai/common-api/shared.js @@ -257,7 +257,7 @@ m.SharedScript.prototype.ApplyEntitiesDelta = function(state) { // Apply metadata stored in training queues for (let entId of evt.entities) for (let key in evt.metadata) - this.setMetadata(evt.owner, this._entities.get(entId), key, evt.metadata[key]) + this.setMetadata(evt.owner, this._entities.get(entId), key, evt.metadata[key]); } for (let evt of state.events["ConstructionFinished"]) @@ -268,7 +268,7 @@ m.SharedScript.prototype.ApplyEntitiesDelta = function(state) let newEnt = this._entities.get(evt.newentity); if (this._entityMetadata[ent.owner()] && this._entityMetadata[ent.owner()][evt.entity] !== undefined) for (let key in this._entityMetadata[ent.owner()][evt.entity]) - this.setMetadata(ent.owner(), newEnt, key, this._entityMetadata[ent.owner()][evt.entity][key]) + this.setMetadata(ent.owner(), newEnt, key, this._entityMetadata[ent.owner()][evt.entity][key]); foundationFinished[evt.entity] = true; } @@ -278,7 +278,7 @@ m.SharedScript.prototype.ApplyEntitiesDelta = function(state) continue; // might happen in some rare cases of foundations getting destroyed, perhaps. // Apply metadata (here for buildings for example) for (let key in evt.metadata) - this.setMetadata(evt.owner, this._entities.get(evt.id), key, evt.metadata[key]) + this.setMetadata(evt.owner, this._entities.get(evt.id), key, evt.metadata[key]); } var DestroyEvents = state.events["Destroy"]; @@ -388,7 +388,7 @@ m.SharedScript.prototype.updateEntityCollections = function(property, ent) for (let entCol of this._entityCollectionsByDynProp[property].values()) entCol.updateEnt(ent); -} +}; m.SharedScript.prototype.setMetadata = function(player, ent, key, value) { @@ -400,6 +400,7 @@ m.SharedScript.prototype.setMetadata = function(player, ent, key, value) this.updateEntityCollections('metadata', ent); this.updateEntityCollections('metadata.' + key, ent); }; + m.SharedScript.prototype.getMetadata = function(player, ent, key) { var metadata = this._entityMetadata[player][ent.id()]; @@ -408,6 +409,7 @@ m.SharedScript.prototype.getMetadata = function(player, ent, key) return undefined; return metadata[key]; }; + m.SharedScript.prototype.deleteMetadata = function(player, ent, key) { var metadata = this._entityMetadata[player][ent.id()]; diff --git a/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js b/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js index 7e40cb4115..44b2255698 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js +++ b/binaries/data/mods/public/simulation/ai/common-api/terrain-analysis.js @@ -151,7 +151,7 @@ m.Accessibility.prototype.getAccessValue = function(position, onWater) if (ret === 1) { // quick spiral search. - var indx = [ [-1,-1],[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1]] + var indx = [ [-1,-1],[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1]]; for (let i of indx) { let id0 = gamePos[0] + i[0]; @@ -312,7 +312,7 @@ m.Accessibility.prototype.floodFill = function(startIndex, value, onWater) loop = true; else break; - } while (loop === true) // should actually break + } while (loop === true); // should actually break ++y; var reachLeft = false; var reachRight = false; @@ -376,7 +376,7 @@ m.Accessibility.prototype.floodFill = function(startIndex, value, onWater) reachRight = false; } ++y; - } while (index/w < h-1) // should actually break + } while (index/w < h-1); // should actually break } return true; }; diff --git a/binaries/data/mods/public/simulation/ai/common-api/utils.js b/binaries/data/mods/public/simulation/ai/common-api/utils.js index ad137c7e55..c78039d26c 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/utils.js +++ b/binaries/data/mods/public/simulation/ai/common-api/utils.js @@ -14,14 +14,15 @@ m.VectorDistance = function(a, b) var dx = a[0] - b[0]; var dz = a[1] - b[1]; return Math.sqrt(dx*dx + dz*dz); -} +}; m.SquareVectorDistance = function(a, b) { var dx = a[0] - b[0]; var dz = a[1] - b[1]; return (dx*dx + dz*dz); -} +}; + // A is the reference, B must be in "range" of A // this supposes the range is already squared m.inRange = function(a, b, range)// checks for X distance @@ -33,14 +34,15 @@ m.inRange = function(a, b, range)// checks for X distance var dx = a[0] - b[0]; var dz = a[1] - b[1]; return ((dx*dx + dz*dz ) < range); -} +}; + // slower than SquareVectorDistance, faster than VectorDistance but not exactly accurate. m.ManhattanDistance = function(a, b) { var dx = a[0] - b[0]; var dz = a[1] - b[1]; return Math.abs(dx) + Math.abs(dz); -} +}; m.AssocArraytoArray = function(assocArray) { var endArray = []; @@ -55,7 +57,7 @@ m.ShallowClone = function(obj) for (var k in obj) ret[k] = obj[k]; return ret; -} +}; // Picks a random element from an array m.PickRandom = function(list) @@ -76,7 +78,7 @@ m.getMaxMapIndex = function(i, map1, map2) var ratio = map1.cellSize / map2.cellSize; var ix = (i % map1.width) * ratio; var iy = Math.floor(i / map1.width) * ratio; - var index = undefined; + var index; for (var kx = 0; kx < ratio; ++kx) for (var ky = 0; ky < ratio; ++ky) if (!index || map2.map[ix+kx+(iy+ky)*map2.width] > map2.map[index]) diff --git a/binaries/data/mods/public/simulation/ai/petra/attackManager.js b/binaries/data/mods/public/simulation/ai/petra/attackManager.js index 15854ed001..a0af2183d3 100644 --- a/binaries/data/mods/public/simulation/ai/petra/attackManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/attackManager.js @@ -32,7 +32,7 @@ m.AttackManager.prototype.setRushes = function(allowed) { if (this.Config.personality.aggressive > 0.8 && allowed > 2) { - this.maxRushes = 3 + this.maxRushes = 3; this.rushSize = [ 16, 20, 24 ]; } else if (this.Config.personality.aggressive > 0.6 && allowed > 1) @@ -53,8 +53,8 @@ m.AttackManager.prototype.checkEvents = function(gameState, events) this.defeated[evt.playerId] = true; let answer = false; - let other = undefined; - let targetPlayer = undefined; + let other; + let targetPlayer; for (let evt of events["AttackRequest"]) { if (evt.source === PlayerID || !gameState.isPlayerAlly(evt.source) || !gameState.isPlayerEnemy(evt.target)) @@ -383,8 +383,8 @@ m.AttackManager.prototype.getEnemyPlayer = function(gameState, attack) && gameState.getEnemyEntities(this.currentEnemyPlayer) > 0) return this.currentEnemyPlayer; - let distmin = undefined; - let ccmin = undefined; + let distmin; + let ccmin; let ccEnts = gameState.updatingGlobalCollection("allCCs", API3.Filters.byClass("CivCentre")); for (let ourcc of ccEnts.values()) { @@ -466,7 +466,7 @@ m.AttackManager.prototype.Serialize = function() upcomingAttacks[key] = []; for (let attack of this.upcomingAttacks[key]) upcomingAttacks[key].push(attack.Serialize()); - }; + } let startedAttacks = {}; for (let key in this.startedAttacks) @@ -474,7 +474,7 @@ m.AttackManager.prototype.Serialize = function() startedAttacks[key] = []; for (let attack of this.startedAttacks[key]) startedAttacks[key].push(attack.Serialize()); - }; + } return { "properties": properties, "upcomingAttacks": upcomingAttacks, "startedAttacks": startedAttacks }; }; @@ -495,7 +495,7 @@ m.AttackManager.prototype.Deserialize = function(gameState, data) attack.init(gameState); this.upcomingAttacks[key].push(attack); } - }; + } this.startedAttacks = {}; for (let key in data.startedAttacks) @@ -508,7 +508,7 @@ m.AttackManager.prototype.Deserialize = function(gameState, data) attack.init(gameState); this.startedAttacks[key].push(attack); } - }; + } }; return m; diff --git a/binaries/data/mods/public/simulation/ai/petra/attackPlan.js b/binaries/data/mods/public/simulation/ai/petra/attackPlan.js index ecbeee1df8..5d796d3f88 100644 --- a/binaries/data/mods/public/simulation/ai/petra/attackPlan.js +++ b/binaries/data/mods/public/simulation/ai/petra/attackPlan.js @@ -354,7 +354,7 @@ m.AttackPlan.prototype.updatePreparation = function(gameState) // if our target was destroyed, go back to "unexecuted" state if (!this.targetPlayer || !this.target || !gameState.getEntityById(this.target.id())) { - this.state === "unexecuted"; + this.state = "unexecuted"; this.target = undefined; } else diff --git a/binaries/data/mods/public/simulation/ai/petra/baseManager.js b/binaries/data/mods/public/simulation/ai/petra/baseManager.js index 7189b4affc..a9f78ebd8a 100644 --- a/binaries/data/mods/public/simulation/ai/petra/baseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/baseManager.js @@ -75,7 +75,7 @@ m.BaseManager.prototype.setAnchor = function(gameState, anchorEntity) { if (!anchorEntity.hasClass("Structure") || !anchorEntity.hasTerritoryInfluence()) { - warn("Error: Petra base " + this.ID + " has been assigned an anchor building that has no territorial influence. Please report this on the forum.") + warn("Error: Petra base " + this.ID + " has been assigned an anchor building that has no territorial influence. Please report this on the forum."); return false; } this.anchor = anchorEntity; @@ -580,7 +580,7 @@ m.BaseManager.prototype.setWorkersIdleByPriority = function(gameState) // but we require a bit more to avoid too frequent changes if ((scale*moreNeed.wanted - moreNeed.current) - (scale*lessNeed.wanted - lessNeed.current) > 1.5) { - let only = undefined; + let only; // in average, females are less efficient for stone and metal, and citizenSoldiers for food let gatherers = this.gatherersByType(gameState, lessNeed.type); if (lessNeed.type === "food" && gatherers.filter(API3.Filters.byClass("CitizenSoldier")).length) @@ -851,7 +851,7 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair) ent.stopMoving(); ent.setMetadata(PlayerID, "subrole", "builder"); ent.setMetadata(PlayerID, "target-foundation", target.id()); - }; + } } } } diff --git a/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js b/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js index f1fc8ef66f..3a6246e235 100644 --- a/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js +++ b/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js @@ -81,7 +81,7 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID) }; // TODO: this should return cleverer results ("needs anti-elephant"…) -m.DefenseArmy.prototype.needsDefenders = function (gameState, events) +m.DefenseArmy.prototype.needsDefenders = function (gameState) { // some preliminary checks because we don't update for tech so entStrength removed can be > entStrength added if (this.foeStrength <= 0 || this.ownStrength <= 0) @@ -92,7 +92,7 @@ m.DefenseArmy.prototype.needsDefenders = function (gameState, events) return this.foeStrength * this.defenseRatio - this.ownStrength; }; -m.DefenseArmy.prototype.getState = function (gameState) +m.DefenseArmy.prototype.getState = function () { if (this.foeEntities.length == 0) return 0; @@ -138,7 +138,7 @@ m.DefenseArmy.prototype.Serialize = function() m.DefenseArmy.prototype.Deserialize = function(data) { for (let key in data) - this[key] = data[key] + this[key] = data[key]; }; return m; diff --git a/binaries/data/mods/public/simulation/ai/petra/defenseManager.js b/binaries/data/mods/public/simulation/ai/petra/defenseManager.js index 2b44304a4b..41bb38763e 100644 --- a/binaries/data/mods/public/simulation/ai/petra/defenseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/defenseManager.js @@ -7,7 +7,7 @@ m.DefenseManager = function(Config) this.Config = Config; this.targetList = []; this.armyMergeSize = this.Config.Defense.armyMergeSize; -} +}; m.DefenseManager.prototype.update = function(gameState, events) { @@ -194,7 +194,7 @@ m.DefenseManager.prototype.checkEnemyUnits = function(gameState) continue; if (!ent.capturePoints() && !ent.hasDefensiveFire()) continue; - let owner = this.territoryMap.getOwner(ent.position());; + let owner = this.territoryMap.getOwner(ent.position()); if (owner === PlayerID) this.makeIntoArmy(gameState, ent.id()); } @@ -210,7 +210,7 @@ m.DefenseManager.prototype.checkEnemyArmies = function(gameState, events) for (let breaker of breakaways) this.makeIntoArmy(gameState, breaker); // assume dangerosity - if (army.getState(gameState) === 0) + if (army.getState() === 0) { army.clear(gameState); this.armies.splice(i--,1); @@ -515,7 +515,7 @@ m.DefenseManager.prototype.garrisonRangedUnitsInside = function(gameState, targe m.DefenseManager.prototype.garrisonSiegeUnit = function(gameState, unit) { let distmin = Math.min(); - let nearest = undefined; + let nearest; let unitAccess = gameState.ai.accessibility.getAccessValue(unit.position()); let garrisonManager = gameState.ai.HQ.garrisonManager; gameState.getAllyStructures().forEach(function(ent) { @@ -547,7 +547,7 @@ m.DefenseManager.prototype.garrisonSiegeUnit = function(gameState, unit) m.DefenseManager.prototype.garrisonUnitForHealing = function(gameState, unit) { let distmin = Math.min(); - let nearest = undefined; + let nearest; let unitAccess = gameState.ai.accessibility.getAccessValue(unit.position()); let garrisonManager = gameState.ai.HQ.garrisonManager; gameState.getAllyStructures().forEach(function(ent) { diff --git a/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js b/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js index 5ca9e7f826..3dcac435fe 100644 --- a/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js @@ -22,7 +22,7 @@ m.DiplomacyManager.prototype.tributes = function(gameState) this.nextTributeUpdate = gameState.ai.elapsedTime + 30; var totalResources = gameState.getResources(); var availableResources = gameState.ai.queueManager.getAvailableResources(gameState); - var mostNeeded = undefined; + var mostNeeded; for (let i = 1; i < gameState.sharedScript.playersData.length; ++i) { if (i === PlayerID || !gameState.isPlayerAlly(i)) diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js index 264af51fad..5680e77f83 100644 --- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -761,14 +761,14 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource, let dist = API3.SquareVectorDistance(cc.pos, pos); if (dist < 14000) // Reject if too near from any cc { - norm = 0 + norm = 0; break; } if (!cc.ally) continue; if (dist < 40000) // Reject if too near from an allied cc { - norm = 0 + norm = 0; break; } if (dist < 62000) // Disfavor if quite near an allied cc diff --git a/binaries/data/mods/public/simulation/ai/petra/navalManager.js b/binaries/data/mods/public/simulation/ai/petra/navalManager.js index 858388ec46..3e222fcf3a 100644 --- a/binaries/data/mods/public/simulation/ai/petra/navalManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/navalManager.js @@ -351,9 +351,9 @@ m.NavalManager.prototype.requireTransport = function(gameState, entity, startInd for (let plan of this.transportPlans) { if (plan.startIndex !== startIndex || plan.endIndex !== endIndex) - continue + continue; if (plan.state !== "boarding") - continue + continue; plan.addUnit(entity, endPos); return true; } @@ -646,7 +646,7 @@ m.NavalManager.prototype.getBestShip = function(gameState, sea, goal) }); var best = 0; - var bestShip = undefined; + var bestShip; var limits = gameState.getEntityLimits(); var current = gameState.getEntityCounts(); for (let trainable of trainableShips) diff --git a/binaries/data/mods/public/simulation/ai/petra/queue.js b/binaries/data/mods/public/simulation/ai/petra/queue.js index be1c122d9e..dff3fbc910 100644 --- a/binaries/data/mods/public/simulation/ai/petra/queue.js +++ b/binaries/data/mods/public/simulation/ai/petra/queue.js @@ -25,7 +25,7 @@ m.Queue.prototype.addItem = function(plan) { if (plan.category === "unit" && q.type == plan.type && q.number + plan.number <= q.maxMerge) { - q.addItem(plan.number) + q.addItem(plan.number); return; } else if (plan.category === "technology" && q.type === plan.type) diff --git a/binaries/data/mods/public/simulation/ai/petra/queueManager.js b/binaries/data/mods/public/simulation/ai/petra/queueManager.js index 45ee5af767..bb3d908267 100644 --- a/binaries/data/mods/public/simulation/ai/petra/queueManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/queueManager.js @@ -37,7 +37,7 @@ m.QueueManager = function(Config, queues) this.queueArrays.push([p, this.queues[p]]); } var priorities = this.priorities; - this.queueArrays.sort(function (a,b) { return (priorities[b[0]] - priorities[a[0]]) }); + this.queueArrays.sort(function (a,b) { return (priorities[b[0]] - priorities[a[0]]); }); }; m.QueueManager.prototype.getAvailableResources = function(gameState) @@ -606,7 +606,7 @@ m.QueueManager.prototype.Serialize = function() "queues": queues, "accounts": accounts }; -} +}; m.QueueManager.prototype.Deserialize = function(gameState, data) { @@ -624,7 +624,7 @@ m.QueueManager.prototype.Deserialize = function(gameState, data) this.accounts[p].Deserialize(data.accounts[p]); this.queueArrays.push([p, this.queues[p]]); } - this.queueArrays.sort(function (a,b) { return (data.priorities[b[0]] - data.priorities[a[0]]) }); + this.queueArrays.sort(function (a,b) { return (data.priorities[b[0]] - data.priorities[a[0]]); }); }; return m; diff --git a/binaries/data/mods/public/simulation/ai/petra/queueplan--.js b/binaries/data/mods/public/simulation/ai/petra/queueplan--.js index 3f33788170..a38e878fbd 100644 --- a/binaries/data/mods/public/simulation/ai/petra/queueplan--.js +++ b/binaries/data/mods/public/simulation/ai/petra/queueplan--.js @@ -13,7 +13,7 @@ m.QueuePlan = function(gameState, type, metadata) this.template = gameState.getTemplate(this.type); if (!this.template) { - warn("Tried to add the inexisting template " + this.type + " to Petra. Please report this on the forums") + API3.warn("Tried to add the inexisting template " + this.type + " to Petra. Please report this on the forums"); return false; } this.ID = gameState.ai.uniqueIDs.plans++; diff --git a/binaries/data/mods/public/simulation/ai/petra/queueplan-building.js b/binaries/data/mods/public/simulation/ai/petra/queueplan-building.js index 8b4f2ec3f8..ba289d0d37 100644 --- a/binaries/data/mods/public/simulation/ai/petra/queueplan-building.js +++ b/binaries/data/mods/public/simulation/ai/petra/queueplan-building.js @@ -434,7 +434,7 @@ m.ConstructionPlan.prototype.findDockPosition = function(gameState) dist = m.getFrontierProximity(gameState, j); if (dist > 4) continue; - dist += 0.4 * (maxres - res) + dist += 0.4 * (maxres - res); } // Add a penalty if on the map border as ship movement will be difficult if (gameState.ai.HQ.borderMap.map[j] > 0) diff --git a/binaries/data/mods/public/simulation/ai/petra/queueplan-training.js b/binaries/data/mods/public/simulation/ai/petra/queueplan-training.js index 7386d3e0aa..ca6a6579b0 100644 --- a/binaries/data/mods/public/simulation/ai/petra/queueplan-training.js +++ b/binaries/data/mods/public/simulation/ai/petra/queueplan-training.js @@ -5,7 +5,7 @@ m.TrainingPlan = function(gameState, type, metadata, number = 1, maxMerge = 5) { if (!m.QueuePlan.call(this, gameState, type, metadata)) { - warn(" Plan training " + type + " canceled"); + API3.warn(" Plan training " + type + " canceled"); return false; } diff --git a/binaries/data/mods/public/simulation/ai/petra/researchManager.js b/binaries/data/mods/public/simulation/ai/petra/researchManager.js index b51e9e130e..642b415dce 100644 --- a/binaries/data/mods/public/simulation/ai/petra/researchManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/researchManager.js @@ -26,7 +26,7 @@ m.ResearchManager.prototype.checkPhase = function(gameState, queues) { var plan = new m.ResearchPlan(gameState, townPhase, true); plan.lastIsGo = false; - plan.onStart = function (gameState) { gameState.ai.HQ.econState = "growth"; gameState.ai.HQ.OnTownPhase(gameState) }; + plan.onStart = function (gameState) { gameState.ai.HQ.econState = "growth"; gameState.ai.HQ.OnTownPhase(gameState); }; plan.isGo = function (gameState) { var ret = gameState.getPopulation() >= gameState.ai.Config.Economy.popForTown; if (ret && !this.lastIsGo) @@ -47,7 +47,7 @@ m.ResearchManager.prototype.checkPhase = function(gameState, queues) && queues.civilCentre.length() === 0) { var plan = new m.ResearchPlan(gameState, cityPhase, true); - plan.onStart = function (gameState) { gameState.ai.HQ.OnCityPhase(gameState) }; + plan.onStart = function (gameState) { gameState.ai.HQ.OnCityPhase(gameState); }; queues.majorTech.addItem(plan); } }; diff --git a/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js b/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js index 9795e3f222..37b5b3421e 100644 --- a/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js +++ b/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js @@ -95,12 +95,12 @@ m.HQ.prototype.assignStartingEntities = function(gameState) ent.unload(id); ent.setMetadata(PlayerID, "access", gameState.ai.accessibility.getAccessValue(pos)); - var bestbase = undefined; + var bestbase; var territorypos = this.territoryMap.gamePosToMapPos(pos); var territoryIndex = territorypos[0] + territorypos[1]*this.territoryMap.width; - for (var i = 1; i < this.baseManagers.length; ++i) + for (let i = 1; i < this.baseManagers.length; ++i) { - var base = this.baseManagers[i]; + let base = this.baseManagers[i]; if (base.territoryIndices.indexOf(territoryIndex) === -1) continue; base.assignEntity(gameState, ent); @@ -119,11 +119,11 @@ m.HQ.prototype.assignStartingEntities = function(gameState) // and find something useful to do if we already have a base if (pos && bestbase.ID !== this.baseManagers[0].ID) { - base.assignRolelessUnits(gameState, [ent]); + bestbase.assignRolelessUnits(gameState, [ent]); if (ent.getMetadata(PlayerID, "role") === "worker") { - base.reassignIdleWorkers(gameState, [ent]); - base.workerObject.update(gameState, ent); + bestbase.reassignIdleWorkers(gameState, [ent]); + bestbase.workerObject.update(gameState, ent); } } } @@ -136,8 +136,8 @@ m.HQ.prototype.assignStartingEntities = function(gameState) m.HQ.prototype.regionAnalysis = function(gameState) { var accessibility = gameState.ai.accessibility; - let landIndex = undefined; - let seaIndex = undefined; + let landIndex; + let seaIndex; var ccEnts = gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")); for (let cc of ccEnts.values()) { diff --git a/binaries/data/mods/public/simulation/ai/petra/tradeManager.js b/binaries/data/mods/public/simulation/ai/petra/tradeManager.js index b36ed736c1..a2ab001990 100644 --- a/binaries/data/mods/public/simulation/ai/petra/tradeManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/tradeManager.js @@ -65,7 +65,7 @@ m.TradeManager.prototype.trainMoreTraders = function(gameState, queues) // May-be, there were produced at an early stage when no other ship were available // and the naval manager will train now more appropriate ships. var already = false; - var shipToSwitch = undefined; + var shipToSwitch; gameState.ai.HQ.navalManager.seaTransportShips[this.tradeRoute.sea].forEach(function(ship) { if (already || !ship.hasClass("Trader")) return; @@ -186,7 +186,7 @@ m.TradeManager.prototype.setTradingGoods = function(gameState) // then add what is needed now - var mainNeed = Math.floor(remaining * 70 / 100) + var mainNeed = Math.floor(remaining * 70 / 100); var nextNeed = remaining - mainNeed; tradingGoods[mostNeeded[0].type] += mainNeed; @@ -224,7 +224,7 @@ m.TradeManager.prototype.performBarter = function(gameState) continue; // pick the best resource to barter. - var bestToSell = undefined; + var bestToSell; var bestRate = 0; for (var sell of needs.types) { @@ -626,7 +626,7 @@ m.TradeManager.prototype.Serialize = function() "targetNumTraders": this.targetNumTraders, "warnedAllies": this.warnedAllies }; -} +}; m.TradeManager.prototype.Deserialize = function(gameState, data) { @@ -635,7 +635,7 @@ m.TradeManager.prototype.Deserialize = function(gameState, data) this.routeProspection = data.routeProspection; this.targetNumTraders = data.targetNumTraders; this.warnedAllies = data.warnedAllies; -} +}; return m; }(PETRA); diff --git a/binaries/data/mods/public/simulation/ai/petra/transportPlan.js b/binaries/data/mods/public/simulation/ai/petra/transportPlan.js index 3d834549a5..67532124aa 100644 --- a/binaries/data/mods/public/simulation/ai/petra/transportPlan.js +++ b/binaries/data/mods/public/simulation/ai/petra/transportPlan.js @@ -30,7 +30,7 @@ m.TransportPlan = function(gameState, units, startIndex, endIndex, endPos, ship) this.flotilla = false; // when false, only one ship per transport ... not yet tested when true this.endPos = endPos; - this.endIndex = endIndex + this.endIndex = endIndex; this.startIndex = startIndex; // TODO only cases with land-sea-land are allowed for the moment // we could also have land-sea-land-sea-land diff --git a/binaries/data/mods/public/simulation/ai/petra/worker.js b/binaries/data/mods/public/simulation/ai/petra/worker.js index 763ad86359..66d06a24a9 100644 --- a/binaries/data/mods/public/simulation/ai/petra/worker.js +++ b/binaries/data/mods/public/simulation/ai/petra/worker.js @@ -8,7 +8,7 @@ var PETRA = function(m) m.Worker = function(base) { this.ent = undefined; - this.base = base + this.base = base; this.baseID = base.ID; }; @@ -513,7 +513,7 @@ m.Worker.prototype.startHunting = function(gameState, position) var entPosition = this.ent.position(); var nearestSupplyDist = Math.min(); - var nearestSupply = undefined; + var nearestSupply; var isCavalry = this.ent.hasClass("Cavalry"); var isRanged = this.ent.hasClass("Ranged"); @@ -612,7 +612,7 @@ m.Worker.prototype.startFishing = function(gameState) } var nearestSupplyDist = Math.min(); - var nearestSupply = undefined; + var nearestSupply; var entPosition = this.ent.position(); var fisherSea = this.ent.getMetadata(PlayerID, "sea"); @@ -746,7 +746,7 @@ m.Worker.prototype.gatherTreasure = function(gameState) var rates = this.ent.resourceGatherRates(); if (!rates || !rates["treasure"] || rates["treasure"] <= 0) return false; - var treasureFound = undefined; + var treasureFound; var distmin = Math.min(); var access = gameState.ai.accessibility.getAccessValue(this.ent.position()); for (var treasure of gameState.ai.HQ.treasures.values()) @@ -835,6 +835,7 @@ m.Worker.prototype.isInaccessibleSupply = function(gameState) } } return false; -} +}; + return m; }(PETRA);