ai cleanup, mainly trailing spaces

This was SVN commit r18163.
This commit is contained in:
mimo 2016-05-12 17:38:58 +00:00
parent 7eea4bd81a
commit a4cb84c8e0
14 changed files with 62 additions and 65 deletions

View file

@ -721,9 +721,8 @@ m.GameState.prototype.hasResearchers = function(templateName, noRequirementCheck
if (!this.canResearch(templateName, noRequirementCheck))
return false;
var template = this.getTemplate(templateName);
var civ = this.playerData.civ;
for (let ent of this.getOwnResearchFacilities().values())
{
let techs = ent.researchableTechs(civ);
@ -750,10 +749,9 @@ m.GameState.prototype.findResearchers = function(templateName, noRequirementChec
if (!this.canResearch(templateName, noRequirementCheck))
return [];
var template = this.getTemplate(templateName);
var self = this;
var civ = this.playerData.civ;
return this.getOwnResearchFacilities().filter(function(ent) {
let techs = ent.researchableTechs(civ);
for (let tech of techs)

View file

@ -12,14 +12,14 @@ m.Map = function Map(sharedScript, type, originalMap, actualCopy)
let map = (type === "territory" || type === "resource") ? sharedScript.territoryMap : sharedScript.passabilityMap;
this.width = map.width;
this.height = map.height;
this.cellSize = map.cellSize;
this.cellSize = map.cellSize;
this.length = this.width * this.height;
this.maxVal = 255;
// sanity check
if (originalMap && originalMap.length !== this.length)
warn("AI map size incompatibility with type " + type + ": original " + originalMap.length + " new " + this.length);
warn("AI map size incompatibility with type " + type + ": original " + originalMap.length + " new " + this.length);
if (originalMap && actualCopy)
{
@ -54,13 +54,13 @@ m.Map.prototype.point = function(p)
m.Map.prototype.addInfluence = function(cx, cy, maxDist, strength, type = "linear")
{
strength = strength ? strength : maxDist;
var x0 = Math.floor(Math.max(0, cx - maxDist));
var y0 = Math.floor(Math.max(0, cy - maxDist));
var x1 = Math.floor(Math.min(this.width-1, cx + maxDist));
var y1 = Math.floor(Math.min(this.height-1, cy + maxDist));
var maxDist2 = maxDist * maxDist;
// code duplicating for speed
if (type === 'linear' || type === "linear")
{
@ -138,13 +138,13 @@ m.Map.prototype.multiplyInfluence = function(cx, cy, maxDist, strength, type)
{
strength = strength ? +strength : +maxDist;
type = type ? type : 'constant';
var x0 = Math.max(0, cx - maxDist);
var y0 = Math.max(0, cy - maxDist);
var x1 = Math.min(this.width, cx + maxDist);
var y1 = Math.min(this.height, cy + maxDist);
var maxDist2 = maxDist * maxDist;
var str = 0.0;
switch (type)
{
@ -158,7 +158,7 @@ m.Map.prototype.multiplyInfluence = function(cx, cy, maxDist, strength, type)
str = strength;
break;
}
if (type === 'linear' || type === "linear")
{
for (let y = y0; y < y1; ++y)
@ -259,9 +259,9 @@ m.Map.prototype.sumInfluence = function(cx, cy, radius)
var x1 = Math.min(this.width, cx + radius);
var y1 = Math.min(this.height, cy + radius);
var radius2 = radius * radius;
var sum = 0;
for (let y = y0; y < y1; ++y)
{
for (let x = x0; x < x1; ++x)
@ -314,7 +314,7 @@ m.Map.prototype.expandInfluences = function(maximum, map)
min = maximum;
}
}
for (let x = 0; x < w; ++x)
{
let min = maximum;
@ -329,7 +329,7 @@ m.Map.prototype.expandInfluences = function(maximum, map)
if (min > maximum)
min = maximum;
}
for (let y = h - 2; y >= 0; --y)
{
let g = grid[x + y * w];

View file

@ -177,7 +177,7 @@ m.SharedScript.prototype.init = function(state, deserialization)
this.createResourceMaps(this);
this.gameState = {};
for (var i in this._players)
for (let i in this._players)
{
this.gameState[this._players[i]] = new m.GameState();
this.gameState[this._players[i]].init(this,state, this._players[i]);
@ -212,7 +212,7 @@ m.SharedScript.prototype.onUpdate = function(state)
this.territoryMap = state.territoryMap;
this.territoryMap.cellSize = this.mapSize / this.territoryMap.width;
for (var i in this.gameState)
for (let i in this.gameState)
this.gameState[i].update(this,state);
// TODO: merge this with "ApplyEntitiesDelta" since after all they do the same.
@ -398,7 +398,7 @@ m.SharedScript.prototype.setMetadata = function(player, ent, key, value)
if (!metadata)
metadata = this._entityMetadata[player][ent.id()] = {};
metadata[key] = value;
this.updateEntityCollections('metadata', ent);
this.updateEntityCollections('metadata.' + key, ent);
};
@ -406,7 +406,7 @@ m.SharedScript.prototype.setMetadata = function(player, ent, key, value)
m.SharedScript.prototype.getMetadata = function(player, ent, key)
{
var metadata = this._entityMetadata[player][ent.id()];
if (!metadata || !(key in metadata))
return undefined;
return metadata[key];
@ -415,7 +415,7 @@ m.SharedScript.prototype.getMetadata = function(player, ent, key)
m.SharedScript.prototype.deleteMetadata = function(player, ent, key)
{
var metadata = this._entityMetadata[player][ent.id()];
if (!metadata || !(key in metadata))
return true;
metadata[key] = undefined;

View file

@ -7,7 +7,7 @@ m.Technology = function(allTemplates, templateName)
{
this._templateName = templateName;
var template = allTemplates[templateName];
// check if this is one of two paired technologies.
this._isPair = template.pair !== undefined;
if (this._isPair)
@ -44,10 +44,10 @@ m.Technology.prototype.getPairedTechs = function()
{
if (!this._definesPair)
return undefined;
var techOne = new m.Technology(this._techTemplates, this._template.top);
var techTwo = new m.Technology(this._techTemplates, this._template.bottom);
return [techOne,techTwo];
};

View file

@ -288,7 +288,7 @@ m.Accessibility.prototype.floodFill = function(startIndex, value, onWater)
var y = 0;
// Get x and y from index
var IndexArray = [startIndex];
var newIndex = 0;
var newIndex;
while(IndexArray.length)
{
newIndex = IndexArray.pop();

View file

@ -30,7 +30,7 @@ m.inRange = function(a, b, range)// checks for X distance
// will avoid unnecessary checking for position in some rare cases... I'm lazy
if (a === undefined || b === undefined || range === undefined)
return undefined;
var dx = a[0] - b[0];
var dz = a[1] - b[1];
return ((dx*dx + dz*dz ) < range);
@ -61,7 +61,7 @@ m.PickRandom = function(list)
// Utility functions for conversions of maps of different sizes
// It expects that cell size of map 1 is a multiple of cell size of map 2
// return the index of map2 with max content from indices contained inside the cell i of map1
// return the index of map2 with max content from indices contained inside the cell i of map1
m.getMaxMapIndex = function(i, map1, map2)
{
var ratio = map1.cellSize / map2.cellSize;
@ -75,7 +75,7 @@ m.getMaxMapIndex = function(i, map1, map2)
return index;
};
// return the list of indices of map2 contained inside the cell i of map1
// return the list of indices of map2 contained inside the cell i of map1
// map1.cellSize must be a multiple of map2.cellSize
m.getMapIndices = function(i, map1, map2)
{

View file

@ -77,7 +77,7 @@ m.PetraBot.prototype.CustomInit = function(gameState, sharedScript)
// this.queues can only be modified by the queue manager or things will go awry.
this.queues = {};
for (var i in this.Config.priorities)
for (let i in this.Config.priorities)
this.queues[i] = new m.Queue();
this.queueManager = new m.QueueManager(this.Config, this.queues);
@ -109,7 +109,7 @@ m.PetraBot.prototype.OnUpdate = function(sharedScript)
// Run the update every n turns, offset depending on player ID to balance the load
this.elapsedTime = this.gameState.getTimeElapsed() / 1000;
if (!this.playedTurn || (this.turn + this.player) % 8 == 5)
{
{
Engine.ProfileStart("PetraBot bot (player " + this.player +")");
this.playedTurn++;
@ -117,19 +117,19 @@ m.PetraBot.prototype.OnUpdate = function(sharedScript)
if (this.gameState.getOwnEntities().length === 0)
{
Engine.ProfileStop();
return; // With no entities to control the AI cannot do anything
return; // With no entities to control the AI cannot do anything
}
this.HQ.update(this.gameState, this.queues, this.savedEvents);
this.queueManager.update(this.gameState);
for (let i in this.savedEvents)
this.savedEvents[i] = [];
Engine.ProfileStop();
}
this.turn++;
};

View file

@ -17,7 +17,7 @@ m.Army = function(gameState, ownEntities, foeEntities)
this.defenseRatio = this.Config.Defense.defenseRatio;
this.compactSize = this.Config.Defense.armyCompactSize;
this.breakawaySize = this.Config.Defense.armyBreakawaySize;
// average
this.foePosition = [0,0];
this.positionLastUpdate = gameState.ai.elapsedTime;
@ -28,19 +28,19 @@ m.Army = function(gameState, ownEntities, foeEntities)
this.assignedAgainst = {};
// who we assigned against, for quick removal.
this.assignedTo = {};
this.foeEntities = [];
this.foeStrength = 0;
this.ownEntities = [];
this.ownStrength = 0;
// actually add units
for (let id of foeEntities)
this.addFoe(gameState, id, true);
for (let id of ownEntities)
this.addOwn(gameState, id);
this.recalculatePosition(gameState, true);
return true;
@ -79,7 +79,7 @@ m.Army.prototype.recalculateStrengths = function (gameState)
{
this.ownStrength = 0;
this.foeStrength = 0;
// todo: deal with specifics.
for (let id of this.foeEntities)
@ -127,11 +127,11 @@ m.Army.prototype.addFoe = function (gameState, enemyId, force)
let ent = gameState.getEntityById(enemyId);
if (!ent || !ent.position())
return false;
// check distance
if (!force && API3.SquareVectorDistance(ent.position(), this.foePosition) > this.compactSize)
return false;
this.foeEntities.push(enemyId);
this.assignedAgainst[enemyId] = [];
this.positionLastUpdate = 0;
@ -150,7 +150,7 @@ m.Army.prototype.removeFoe = function (gameState, enemyId, enemyEntity)
return false;
this.foeEntities.splice(idx, 1);
this.assignedAgainst[enemyId] = undefined;
for (let to in this.assignedTo)
if (this.assignedTo[to] == enemyId)

View file

@ -374,9 +374,9 @@ m.AttackManager.prototype.getEnemyPlayer = function(gameState, attack)
if (enemyDefense > 6)
veto[i] = true;
}
}
}
// then if not a huge attack, continue attacking our previous target as long as it has some entities,
// then if not a huge attack, continue attacking our previous target as long as it has some entities,
// otherwise target the most accessible one
if (attack.type !== "HugeAttack")
{

View file

@ -11,7 +11,7 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, data)
{
this.Config = Config;
this.name = uniqueID;
this.type = type || "Attack";
this.type = type || "Attack";
this.state = "unexecuted";
if (data && data.target)
@ -187,7 +187,7 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, data)
gameState.ai.queueManager.addQueue("plan_" + this.name, priority);
gameState.ai.queueManager.addQueue("plan_" + this.name +"_champ", priority+1);
gameState.ai.queueManager.addQueue("plan_" + this.name +"_siege", priority);
// each array is [ratio, [associated classes], associated EntityColl, associated unitStat, name ]
this.buildOrder = [];
this.canBuildUnits = gameState.ai.HQ.canBuildUnits;
@ -211,7 +211,7 @@ m.AttackPlan.prototype.init = function(gameState)
this.unitCollection = gameState.getOwnUnits().filter(API3.Filters.byMetadata(PlayerID, "plan", this.name));
this.unitCollection.registerUpdates();
this.unit = {};
// defining the entity collections. Will look for units I own, that are part of this plan.
@ -254,7 +254,7 @@ m.AttackPlan.prototype.setPaused = function(boolValue)
// Returns true if the attack can be executed at the current time
// Basically it checks we have enough units.
m.AttackPlan.prototype.canStart = function()
{
{
if (!this.canBuildUnits)
return true;
@ -529,7 +529,7 @@ m.AttackPlan.prototype.trainMoreUnits = function(gameState)
let queue2 = this.queueChamp.countQueuedUnitsWithMetadata("special", specialData);
let queue3 = this.queueSiege.countQueuedUnitsWithMetadata("special", specialData);
API3.warn(" >>> " + order[4] + " done " + order[2].length + " training " + inTraining +
" queue " + queue1 + " champ " + queue2 + " siege " + queue3 + " >> need " + order[3].targetSize);
" queue " + queue1 + " champ " + queue2 + " siege " + queue3 + " >> need " + order[3].targetSize);
}
API3.warn("====================================");
}
@ -993,7 +993,7 @@ m.AttackPlan.prototype.StartAttack = function(gameState)
gameState.ai.queueManager.removeQueue("plan_" + this.name);
gameState.ai.queueManager.removeQueue("plan_" + this.name + "_champ");
gameState.ai.queueManager.removeQueue("plan_" + this.name + "_siege");
for (let ent of this.unitCollection.values())
ent.setMetadata(PlayerID, "subrole", "walking");
this.unitCollection.setStance("aggressive");
@ -1091,7 +1091,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
// we're marching towards the target
// Let's check if any of our unit has been attacked.
// In case yes, we'll determine if we're simply off against an enemy army, a lone unit/building
// or if we reached the enemy base. Different plans may react differently.
// or if we reached the enemy base. Different plans may react differently.
var attackedNB = 0;
var attackedUnitNB = 0;
for (let evt of events.Attacked)
@ -1141,7 +1141,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
if (gameState.ai.playedTurn % 5 === 0)
this.position5TurnsAgo = this.position;
if (this.lastPosition && API3.SquareVectorDistance(this.position, this.lastPosition) < 20 && this.path.length > 0)
{
if (!this.path[0][0] || !this.path[0][1])
@ -1214,7 +1214,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
}
}
// basic state of attacking.
if (this.state === "")
{
@ -1270,7 +1270,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
continue;
if (accessIndex !== gameState.ai.accessibility.getAccessValue(attack.targetPos))
continue;
if (attack.target.owner() === 0 && attack.targetPlayer !== 0) // looks like it has resigned
if (attack.target.owner() === 0 && attack.targetPlayer !== 0) // looks like it has resigned
continue;
this.target = attack.target;
this.targetPlayer = attack.targetPlayer;
@ -1303,7 +1303,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
{
if (IDs.indexOf(evt.target) == -1)
continue;
var attacker = gameState.getEntityById(evt.attacker);
let attacker = gameState.getEntityById(evt.attacker);
if (!attacker || !attacker.position() || !attacker.hasClass("Unit"))
continue;
var ourUnit = gameState.getEntityById(evt.target);
@ -1338,7 +1338,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
else
{ // if units are attacked, abandon their target (if it was a structure or a support) and retaliate
// also if our unit is attacking a range unit and the attacker is a melee unit, retaliate
var orderData = ourUnit.unitAIOrderData();
let orderData = ourUnit.unitAIOrderData();
if (orderData && orderData.length && orderData[0].target)
{
if (orderData[0].target === attacker.id())
@ -1355,7 +1355,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
}
}
var enemyUnits = gameState.getEnemyUnits(this.targetPlayer);
var enemyStructures = gameState.getEnemyStructures(this.targetPlayer);
@ -1428,7 +1428,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
let orderData = ent.unitAIOrderData();
if (orderData && orderData.length && orderData[0].target)
targetId = orderData[0].target;
// update the order if needed
let needsUpdate = false;
let maybeUpdate = false;
@ -1668,7 +1668,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
this.lastPosition = this.position;
Engine.ProfileStop();
return this.unitCollection.length;
};
@ -1894,7 +1894,7 @@ m.AttackPlan.prototype.Serialize = function()
"targetPlayer": this.targetPlayer,
"target": ((this.target !== undefined) ? this.target.id() : undefined),
"targetPos": this.targetPos,
"path": this.path
"path": this.path
};
return { "properties": properties};

View file

@ -27,7 +27,7 @@ m.BaseManager = function(gameState, Config)
this.maxDistResourceSquare = 360*360;
this.constructing = false;
// Defenders to train in this cc when its construction is finished
// Defenders to train in this cc when its construction is finished
this.neededDefenders = ((this.Config.difficulty > 2) ? 3 + 2*(this.Config.difficulty - 3) : 0);
// vector for iterating, to check one use the HQ map.

View file

@ -32,7 +32,7 @@ m.DefenseManager.prototype.makeIntoArmy = function(gameState, entityID)
return; // over
// Create a new army for it.
var army = new m.DefenseArmy(gameState, [], [entityID]);
let army = new m.DefenseArmy(gameState, [], [entityID]);
this.armies.push(army);
};

View file

@ -483,7 +483,7 @@ m.NavalManager.prototype.maintainFleet = function(gameState, queues)
!gameState.getOwnEntitiesByClass("Shipyard", true).filter(API3.Filters.isBuilt()).hasEntities())
return;
// check if we have enough transport ships per region.
for (var sea = 0; sea < this.seaShips.length; ++sea)
for (let sea = 0; sea < this.seaShips.length; ++sea)
{
if (this.seaShips[sea] === undefined)
continue;
@ -492,7 +492,7 @@ m.NavalManager.prototype.maintainFleet = function(gameState, queues)
if (this.seaTransportShips[sea].length < this.wantedTransportShips[sea])
{
var template = this.getBestShip(gameState, sea, "transport");
let template = this.getBestShip(gameState, sea, "transport");
if (template)
{
queues.ships.addPlan(new m.TrainingPlan(gameState, template, { "sea": sea }, 1, 1));

View file

@ -155,7 +155,6 @@ m.QueueManager.prototype.printQueues = function(gameState)
API3.warn("---------- QUEUES ------------ with pop " + gameState.getPopulation() + " and workers " + numWorkers);
for (let i in this.queues)
{
let qStr = "";
let q = this.queues[i];
if (q.hasQueuedUnits())
{
@ -164,7 +163,7 @@ m.QueueManager.prototype.printQueues = function(gameState)
}
for (let plan of q.plans)
{
qStr = " " + plan.type + " ";
let qStr = " " + plan.type + " ";
if (plan.number)
qStr += "x" + plan.number;
qStr += " isGo " + plan.isGo(gameState);