bunch of cleanup (mainly missing semicolon) signaled by jshint

This was SVN commit r17044.
This commit is contained in:
mimo 2015-09-19 12:41:21 +00:00
parent e2bfba740b
commit e42e02d4fe
26 changed files with 79 additions and 74 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@ m.Class = function(data)
}
return ctor;
}
};
/* Test inheritance:
var A = Class({foo:1, bar:10});

View file

@ -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; },

View file

@ -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.

View file

@ -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

View file

@ -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()];

View file

@ -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;
};

View file

@ -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])

View file

@ -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;

View file

@ -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

View file

@ -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());
};
}
}
}
}

View file

@ -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;

View file

@ -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) {

View file

@ -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))

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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;

View file

@ -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++;

View file

@ -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)

View file

@ -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;
}

View file

@ -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);
}
};

View file

@ -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())
{

View file

@ -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);

View file

@ -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

View file

@ -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);