petra cleanup, mainly unneeded parentheses

This was SVN commit r18196.
This commit is contained in:
mimo 2016-05-17 19:35:33 +00:00
parent 329caed9dd
commit b57a103e81
17 changed files with 96 additions and 103 deletions

View file

@ -509,13 +509,13 @@ m.Template = m.Class({
},
hasTerritoryInfluence: function() {
return (this.get("TerritoryInfluence") !== undefined);
return this.get("TerritoryInfluence") !== undefined;
},
hasDefensiveFire: function() {
if (!this.get("Attack") || !this.get("Attack/Ranged"))
return false;
return (this.getDefaultArrow() || this.getArrowMultiplier());
return this.getDefaultArrow() || this.getArrowMultiplier();
},
territoryInfluenceRadius: function() {
@ -616,16 +616,16 @@ m.Entity = m.Class({
return this._entity.idle;
},
unitAIState: function() { return (this._entity.unitAIState !== undefined) ? this._entity.unitAIState : undefined; },
unitAIOrderData: function() { return (this._entity.unitAIOrderData !== undefined) ? this._entity.unitAIOrderData : undefined; },
unitAIState: function() { return this._entity.unitAIState !== undefined ? this._entity.unitAIState : undefined; },
unitAIOrderData: function() { return this._entity.unitAIOrderData !== undefined ? this._entity.unitAIOrderData : undefined; },
hitpoints: function() { return (this._entity.hitpoints !== undefined) ? this._entity.hitpoints : undefined; },
hitpoints: function() { return this._entity.hitpoints !== undefined ? this._entity.hitpoints : undefined; },
isHurt: function() { return this.hitpoints() < this.maxHitpoints(); },
healthLevel: function() { return this.hitpoints() / this.maxHitpoints(); },
needsHeal: function() { return this.isHurt() && this.isHealable(); },
needsRepair: function() { return this.isHurt() && this.isRepairable(); },
decaying: function() { return (this._entity.decaying !== undefined) ? this._entity.decaying : undefined; },
capturePoints: function() {return (this._entity.capturePoints !== undefined) ? this._entity.capturePoints : undefined; },
decaying: function() { return this._entity.decaying !== undefined ? this._entity.decaying : undefined; },
capturePoints: function() {return this._entity.capturePoints !== undefined ? this._entity.capturePoints : undefined; },
/**
* Returns the current training queue state, of the form
@ -673,7 +673,7 @@ m.Entity = m.Class({
},
isOwn: function(player) {
if (typeof(this._entity.owner) === "undefined")
if (typeof this._entity.owner === "undefined")
return false;
return this._entity.owner === player;
},

View file

@ -191,7 +191,7 @@ m.Filters = {
return {"func": function(ent){
if (!ent.position())
return false;
return (m.SquareVectorDistance(startPoint, ent.position()) < dist*dist);
return m.SquareVectorDistance(startPoint, ent.position()) < dist*dist;
},
"dynamicProperties": []};
},

View file

@ -221,16 +221,18 @@ m.Accessibility.prototype.getTrajectToIndex = function(istart, iend)
return undefined;
};
m.Accessibility.prototype.getRegionSize = function(position, onWater){
m.Accessibility.prototype.getRegionSize = function(position, onWater)
{
var pos = this.gamePosToMapPos(position);
var index = pos[0] + pos[1]*this.width;
var ID = (onWater === true) ? this.navalPassMap[index] : this.landPassMap[index];
var ID = onWater === true ? this.navalPassMap[index] : this.landPassMap[index];
if (this.regionSize[ID] === undefined)
return 0;
return this.regionSize[ID];
};
m.Accessibility.prototype.getRegionSizei = function(index, onWater) {
m.Accessibility.prototype.getRegionSizei = function(index, onWater)
{
if (this.regionSize[this.landPassMap[index]] === undefined && (!onWater || this.regionSize[this.navalPassMap[index]] === undefined))
return 0;
if (onWater && this.regionSize[this.navalPassMap[index]] > this.regionSize[this.landPassMap[index]])

View file

@ -20,7 +20,7 @@ m.SquareVectorDistance = function(a, b)
{
var dx = a[0] - b[0];
var dz = a[1] - b[1];
return (dx*dx + dz*dz);
return dx*dx + dz*dz;
};
// A is the reference, B must be in "range" of A
@ -33,7 +33,7 @@ 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);
return dx*dx + dz*dz < range;
};
// slower than SquareVectorDistance, faster than VectorDistance but not exactly accurate.

View file

@ -238,7 +238,7 @@ m.AttackPlan.prototype.getType = function()
m.AttackPlan.prototype.isStarted = function()
{
return (this.state !== "unexecuted" && this.state !== "completing");
return this.state !== "unexecuted" && this.state !== "completing";
};
m.AttackPlan.prototype.isPaused = function()
@ -1471,7 +1471,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
{
if (!maybeUpdate && this.CheckCapture(gameState, ent))
continue;
let deltat = (ent.unitAIState() === "INDIVIDUAL.COMBAT.APPROACHING") ? 10 : 5;
let deltat = ent.unitAIState() === "INDIVIDUAL.COMBAT.APPROACHING" ? 10 : 5;
let lastAttackPlanUpdateTime = ent.getMetadata(PlayerID, "lastAttackPlanUpdateTime");
if (lastAttackPlanUpdateTime && (time - lastAttackPlanUpdateTime) < deltat &&
this.CheckCapture(gameState, ent))
@ -1518,7 +1518,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
valb += 1000;
else if (structb.hasClass("ConquestCritical"))
valb += 200;
return (valb - vala);
return valb - vala;
});
if (mStruct[0].hasClass("Gates"))
ent.attack(mStruct[0].id(), false);
@ -1542,7 +1542,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
else
{
let nearby = (!ent.hasClass("Cavalry") && !ent.hasClass("Ranged"));
let nearby = !ent.hasClass("Cavalry") && !ent.hasClass("Ranged");
let mUnit = enemyUnits.filter(function (enemy) {
if (!enemy.position())
return false;
@ -1625,7 +1625,7 @@ m.AttackPlan.prototype.update = function(gameState, events)
valb += 10000;
else if (structb.hasClass("ConquestCritical"))
valb += 100;
return (valb - vala);
return valb - vala;
});
if (mStruct[0].hasClass("Gates"))
ent.attack(mStruct[0].id(), false);
@ -1680,7 +1680,7 @@ m.AttackPlan.prototype.Abort = function(gameState)
{
// If the attack was started, and we are on the same land as the rallyPoint, go back there
var rallyPoint = this.rallyPoint;
var withdrawal = (this.isStarted() && !this.overseas);
var withdrawal = this.isStarted() && !this.overseas;
for (let ent of this.unitCollection.values())
{
if (ent.getMetadata(PlayerID, "role") === "attack")
@ -1781,7 +1781,7 @@ m.AttackPlan.prototype.hasForceOrder = function(data, value)
m.AttackPlan.prototype.isSiegeUnit = function(gameState, ent)
{
return (ent.hasClass("Siege") || (ent.hasClass("Elephant") && ent.hasClass("Champion")));
return ent.hasClass("Siege") || (ent.hasClass("Elephant") && ent.hasClass("Champion"));
};
m.AttackPlan.prototype.debugAttack = function()
@ -1892,7 +1892,7 @@ m.AttackPlan.prototype.Serialize = function()
"captureTime": this.captureTime,
"noCapture": this.noCapture,
"targetPlayer": this.targetPlayer,
"target": ((this.target !== undefined) ? this.target.id() : undefined),
"target": this.target !== undefined ? this.target.id() : undefined,
"targetPos": this.targetPos,
"path": this.path
};

View file

@ -28,7 +28,7 @@ m.BaseManager = function(gameState, Config)
this.constructing = false;
// Defenders to train in this cc when its construction is finished
this.neededDefenders = ((this.Config.difficulty > 2) ? 3 + 2*(this.Config.difficulty - 3) : 0);
this.neededDefenders = this.Config.difficulty > 2 ? 3 + 2*(this.Config.difficulty - 3) : 0;
// vector for iterating, to check one use the HQ map.
this.territoryIndices = [];
@ -618,7 +618,7 @@ m.BaseManager.prototype.setWorkersIdleByPriority = function(gameState)
gatherers.forEach( function (ent) {
if (!ent.canGather(moreNeed.type))
return;
if (nb == 0)
if (nb === 0)
return;
if (only && !ent.hasClass(only))
return;
@ -627,7 +627,7 @@ m.BaseManager.prototype.setWorkersIdleByPriority = function(gameState)
ent.setMetadata(PlayerID, "gather-type", moreNeed.type);
gameState.ai.HQ.AddTCResGatherer(moreNeed.type);
});
if (nb == 0)
if (nb === 0)
return;
}
}
@ -724,7 +724,7 @@ m.BaseManager.prototype.pickBuilders = function(gameState, workers, number)
vala = -20;
if (b.getMetadata(PlayerID, "plan") === undefined)
valb = -20;
return (vala - valb);
return vala - valb;
});
var needed = Math.min(number, availableWorkers.length - 3);
for (let i = 0; i < needed; ++i)
@ -863,7 +863,7 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
coeffB *= 0.5 * (1 + (Math.sqrt(coeffB)/150)*(30/time));
else if (workerB.getMetadata(PlayerID, "gather-type") === "food")
coeffB *= 3;
return (coeffA - coeffB);
return coeffA - coeffB;
});
let current = 0;
let nonBuilderTot = nonBuilderWorkers.length;
@ -1055,7 +1055,7 @@ m.BaseManager.prototype.Deserialize = function(gameState, data)
for (let key in data)
this[key] = data[key];
this.anchor = ((this.anchorId !== undefined) ? gameState.getEntityById(this.anchorId) : undefined);
this.anchor = this.anchorId !== undefined ? gameState.getEntityById(this.anchorId) : undefined;
};
return m;

View file

@ -23,13 +23,13 @@ m.getMaxStrength = function(ent, againstClass)
switch (str)
{
case "crush":
strength += (val * 0.085) / 3;
strength += val * 0.085 / 3;
break;
case "hack":
strength += (val * 0.075) / 3;
strength += val * 0.075 / 3;
break;
case "pierce":
strength += (val * 0.065) / 3;
strength += val * 0.065 / 3;
break;
default:
API3.warn("Petra: " + str + " unknown attackStrength in getMaxStrength");
@ -38,7 +38,7 @@ m.getMaxStrength = function(ent, againstClass)
let attackRange = ent.attackRange(type);
if (attackRange)
strength += (attackRange.max * 0.0125) ;
strength += attackRange.max * 0.0125;
let attackTimes = ent.attackTimes(type);
for (let str in attackTimes)
@ -47,10 +47,10 @@ m.getMaxStrength = function(ent, againstClass)
switch (str)
{
case "repeat":
strength += (val / 100000);
strength += val / 100000;
break;
case "prepare":
strength -= (val / 100000);
strength -= val / 100000;
break;
default:
API3.warn("Petra: " + str + " unknown attackTimes in getMaxStrength");
@ -65,13 +65,13 @@ m.getMaxStrength = function(ent, againstClass)
switch (str)
{
case "crush":
strength += (val * 0.085) / 3;
strength += val * 0.085 / 3;
break;
case "hack":
strength += (val * 0.075) / 3;
strength += val * 0.075 / 3;
break;
case "pierce":
strength += (val * 0.065) / 3;
strength += val * 0.065 / 3;
break;
default:
API3.warn("Petra: " + str + " unknown armourStrength in getMaxStrength");

View file

@ -147,7 +147,7 @@ m.GarrisonManager.prototype.numberOfGarrisonedUnits = function(holder)
if (!this.holders.has(holder.id()))
return holder.garrisoned().length;
return (holder.garrisoned().length + this.holders.get(holder.id()).length);
return holder.garrisoned().length + this.holders.get(holder.id()).length;
};
// This is just a pre-garrison state, while the entity walk to the garrison holder

View file

@ -521,7 +521,7 @@ m.HQ.prototype.findBestTrainableUnit = function(gameState, classes, requirements
else // We do not want hero when not explicitely specified
units = gameState.findTrainableUnits(classes, ["Hero"]);
if (units.length == 0)
if (units.length === 0)
return undefined;
var parameters = requirements.slice();
@ -590,7 +590,7 @@ m.HQ.prototype.findBestTrainableUnit = function(gameState, classes, requirements
bTopParam *= param[1];
}
}
return -(aTopParam/(aDivParam+1)) + (bTopParam/(bDivParam+1));
return -aTopParam/(aDivParam+1) + bTopParam/(bDivParam+1);
});
return units[0][0];
};
@ -687,8 +687,8 @@ m.HQ.prototype.pickMostNeededResources = function(gameState)
let vb = Math.max(0, b.wanted - b.current) / (b.current + 1);
// If they happen to be equal (generally this means "0" aka no need), make it fair.
if (va === vb)
return (a.current - b.current);
return (vb - va);
return a.current - b.current;
return vb - va;
});
return needed;
};
@ -787,7 +787,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
if (dist < minDist)
minDist = dist;
}
if (norm == 0)
if (norm === 0)
continue;
if (minDist > 170000 && !this.navalMap) // Reject if too far from any allied cc (not connected)
@ -819,7 +819,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
else if (dist < 6400)
norm *= 0.5;
}
if (norm == 0)
if (norm === 0)
continue;
}
@ -1355,14 +1355,14 @@ m.HQ.prototype.buildMoreHouses = function(gameState,queues)
let freeSlots = gameState.getPopulationLimit() - gameState.getPopulation();
for (let ent of gameState.getOwnFoundations().values())
freeSlots += ent.getPopulationBonus();
if (gameState.ai.HQ.saveResources)
return (freeSlots <= 10);
return freeSlots <= 10;
else if (gameState.getPopulation() > 55)
return (freeSlots <= 21);
return freeSlots <= 21;
else if (gameState.getPopulation() > 30)
return (freeSlots <= 15);
else
return (freeSlots <= 10);
return freeSlots <= 15;
return freeSlots <= 10;
};
queues.house.addPlan(plan);
}
@ -1438,7 +1438,7 @@ m.HQ.prototype.checkBaseExpansion = function(gameState, queues)
return;
// first build one cc if all have been destroyed
let activeBases = this.numActiveBase();
if (activeBases == 0)
if (activeBases === 0)
{
this.buildFirstBase(gameState);
return;
@ -1468,7 +1468,7 @@ m.HQ.prototype.buildNewBase = function(gameState, queues, resource)
return false;
if (gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() || queues.civilCentre.hasQueuedUnits())
return false;
let template = (this.numActiveBase() > 0) ? this.bBase[0] : gameState.applyCiv("structures/{civ}_civil_centre");
let template = this.numActiveBase() > 0 ? this.bBase[0] : gameState.applyCiv("structures/{civ}_civil_centre");
if (!this.canBuild(gameState, template))
return false;
@ -1596,7 +1596,7 @@ m.HQ.prototype.constructTrainingBuildings = function(gameState, queues)
}
//build advanced military buildings
if (gameState.currentPhase() > 2 && gameState.getPopulation() > 80 && !queues.militaryBuilding.hasQueuedUnits() && this.bAdvanced.length != 0)
if (gameState.currentPhase() > 2 && gameState.getPopulation() > 80 && !queues.militaryBuilding.hasQueuedUnits() && this.bAdvanced.length !== 0)
{
let nAdvanced = 0;
for (let advanced of this.bAdvanced)
@ -1709,8 +1709,8 @@ m.HQ.prototype.trainEmergencyUnits = function(gameState, positions)
nearestAnchor.stopProduction(item.id);
}
}
var autogarrison = (numGarrisoned < nearestAnchor.garrisonMax() && nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints());
var rangedWanted = (Math.random() > 0.5 && autogarrison);
var autogarrison = numGarrisoned < nearestAnchor.garrisonMax() && nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints();
var rangedWanted = Math.random() > 0.5 && autogarrison;
var total = gameState.getResources();
var templateFound;
@ -2118,7 +2118,7 @@ m.HQ.prototype.update = function(gameState, queues, events)
for (let i = 0; i < this.baseManagers.length; ++i)
{
this.baseManagers[i].checkEvents(gameState, events, queues);
if (((i + gameState.ai.playedTurn)%this.baseManagers.length) === 0)
if ((i + gameState.ai.playedTurn)%this.baseManagers.length === 0)
this.baseManagers[i].update(gameState, queues, events);
}

View file

@ -80,11 +80,10 @@ m.QueueManager.prototype.currentNeeds = function(gameState)
// TODO: many things.
m.QueueManager.prototype.wantedGatherRates = function(gameState)
{
if (gameState.ai.playedTurn == 0)
{
// default values for first turn when we have not yet set our queues.
// default values for first turn when we have not yet set our queues.
if (gameState.ai.playedTurn === 0)
return { "food": 10, "wood": 10, "stone": 0, "metal": 0 };
}
// get out current resources, not removing accounts.
var current = gameState.getResources();
// short queue is the first item of a queue, assumed to be ready in 30s
@ -107,7 +106,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState)
let cost = queue.plans[j].getCost();
if (queue.plans[j].isGo(gameState))
{
if (j == 0)
if (j === 0)
total = totalShort;
else
total = totalMedium;

View file

@ -141,8 +141,7 @@ m.ConstructionPlan.prototype.findGoodPosition = function(gameState)
if (pos)
return { "x": pos[0], "z": pos[1], "angle": 3*Math.PI/4, "base": 0 };
else
return false;
return false;
}
else if (template.hasClass("DefenseTower") || template.hasClass("Fortress") || template.hasClass("ArmyCamp"))
{
@ -241,7 +240,7 @@ m.ConstructionPlan.prototype.findGoodPosition = function(gameState)
{
for (let j = 0; j < placement.map.length; ++j)
{
let value = placement.map[j] - (gameState.sharedScript.resourceMaps.wood.map[j])/3;
let value = placement.map[j] - gameState.sharedScript.resourceMaps.wood.map[j]/3;
placement.map[j] = value >= 0 ? value : 0;
if (gameState.ai.HQ.borderMap.map[j] > 0)
placement.map[j] /= 2; // we need space around farmstead, so disfavor map border
@ -252,8 +251,8 @@ m.ConstructionPlan.prototype.findGoodPosition = function(gameState)
// requires to be inside our territory, and inside our base territory if required
// and if our first market, put it on border if possible to maximize distance with next market
var favorBorder = template.hasClass("BarterMarket");
var disfavorBorder = (gameState.currentPhase() > 1 && !template.hasDefensiveFire());
var preferredBase = (this.metadata && this.metadata.preferredBase);
var disfavorBorder = gameState.currentPhase() > 1 && !template.hasDefensiveFire();
var preferredBase = this.metadata && this.metadata.preferredBase;
if (this.metadata && this.metadata.base !== undefined)
{
let base = this.metadata.base;
@ -536,7 +535,7 @@ m.ConstructionPlan.prototype.getDockAngle = function(gameState, x, z, size)
for (let i = 0; i < length; ++i)
{
let count = 0;
for (let j = 0; j < (length-1); ++j)
for (let j = 0; j < length-1; ++j)
{
if (((waterPoints[(i + j) % length]+1) % numPoints) == waterPoints[(i + j + 1) % length])
++count;
@ -724,7 +723,7 @@ m.ConstructionPlan.prototype.getResourcesAround = function(gameState, types, i,
{
if (k === "food" || !resourceMaps[k])
continue;
let weigh0 = (k === "wood") ? 2 : 1;
let weigh0 = k === "wood" ? 2 : 1;
for (let dy = 0; dy <= size; ++dy)
{
let dxmax = size - dy;
@ -736,7 +735,7 @@ m.ConstructionPlan.prototype.getResourcesAround = function(gameState, types, i,
let kx = ix + dx;
if (kx < 0 || kx >= w)
continue;
let ddx = (dx > 0) ? dx : -dx;
let ddx = dx > 0 ? dx : -dx;
let weight = weigh0 * (dxmax - ddx) / size;
total += weight * resourceMaps[k].map[kx + w * ky];
nbcell += weight;
@ -752,7 +751,7 @@ m.ConstructionPlan.prototype.getResourcesAround = function(gameState, types, i,
let kx = ix + dx;
if (kx < 0 || kx >= w)
continue;
let ddx = (dx > 0) ? dx : -dx;
let ddx = dx > 0 ? dx : -dx;
let weight = weigh0 * (dxmax - ddx) / size;
total += weight * resourceMaps[k].map[kx + w * ky];
nbcell += weight;
@ -760,7 +759,7 @@ m.ConstructionPlan.prototype.getResourcesAround = function(gameState, types, i,
}
}
}
return (nbcell ? (total / nbcell) : 0);
return nbcell ? (total / nbcell) : 0;
};
m.ConstructionPlan.prototype.Serialize = function()

View file

@ -26,7 +26,7 @@ m.ResearchPlan.prototype.canStart = function(gameState)
m.ResearchPlan.prototype.isInvalid = function(gameState)
{
return (gameState.isResearched(this.type) || gameState.isResearching(this.type));
return gameState.isResearched(this.type) || gameState.isResearching(this.type);
};
m.ResearchPlan.prototype.start = function(gameState)
@ -38,9 +38,7 @@ m.ResearchPlan.prototype.start = function(gameState)
// plans that have already been executed this turn)
if (trainers.length > 0)
{
trainers.sort(function(a, b) {
return (a.trainingQueueTime() - b.trainingQueueTime());
});
trainers.sort((a, b) => a.trainingQueueTime() - b.trainingQueueTime());
// drop anything in the queue if we rush it.
if (this.rush)
trainers[0].stopAllProduction(0.45);

View file

@ -26,7 +26,7 @@ m.TrainingPlan.prototype.canStart = function(gameState)
if (this.metadata && this.metadata.sea)
trainers = trainers.filter(API3.Filters.byMetadata(PlayerID, "sea", this.metadata.sea));
return (trainers.length !== 0);
return trainers.length !== 0;
};
m.TrainingPlan.prototype.start = function(gameState)
@ -59,7 +59,7 @@ m.TrainingPlan.prototype.start = function(gameState)
let wantedIndex;
if (this.metadata && this.metadata.index)
wantedIndex = this.metadata.index;
let workerUnit = (this.metadata && this.metadata.role && this.metadata.role == "worker");
let workerUnit = this.metadata && this.metadata.role && this.metadata.role == "worker";
let supportUnit = this.template.hasClass("Support");
trainers.sort(function(a, b) {
let aa = a.trainingQueueTime();
@ -94,7 +94,7 @@ m.TrainingPlan.prototype.start = function(gameState)
else if (bpop > apop)
bb++;
}
return (aa - bb);
return aa - bb;
});
if (this.metadata && this.metadata.base !== undefined && this.metadata.base === 0)
this.metadata.base = trainers[0].getMetadata(PlayerID, "base");

View file

@ -88,14 +88,14 @@ m.ResearchManager.prototype.researchTradeBonus = function(gameState, queues)
// Techs to be searched for as soon as they are available
m.ResearchManager.prototype.researchWantedTechs = function(gameState, techs)
{
var available = (gameState.currentPhase() == 1 ? gameState.ai.queueManager.getAvailableResources(gameState) : null);
var numWorkers = (gameState.currentPhase() == 1 ? gameState.getOwnEntitiesByRole("worker", true).length : 0);
var available = gameState.currentPhase() === 1 ? gameState.ai.queueManager.getAvailableResources(gameState) : null;
var numWorkers = gameState.currentPhase() === 1 ? gameState.getOwnEntitiesByRole("worker", true).length : 0;
for (let tech of techs)
{
if (!tech[1]._template.modifications)
continue;
let template = tech[1]._template;
if (gameState.currentPhase() == 1)
if (gameState.currentPhase() === 1)
{
let cost = template.cost;
let costMax = 0;
@ -126,14 +126,14 @@ m.ResearchManager.prototype.researchWantedTechs = function(gameState, techs)
// Techs to be searched for as soon as they are available, but only after phase 2
m.ResearchManager.prototype.researchPreferredTechs = function(gameState, techs)
{
var available = (gameState.currentPhase() == 2 ? gameState.ai.queueManager.getAvailableResources(gameState) : null);
var numWorkers = (gameState.currentPhase() == 2 ? gameState.getOwnEntitiesByRole("worker", true).length : 0);
var available = gameState.currentPhase() === 2 ? gameState.ai.queueManager.getAvailableResources(gameState) : null;
var numWorkers = gameState.currentPhase() === 2 ? gameState.getOwnEntitiesByRole("worker", true).length : 0;
for (let tech of techs)
{
if (!tech[1]._template.modifications)
continue;
let template = tech[1]._template;
if (gameState.currentPhase() == 2)
if (gameState.currentPhase() === 2)
{
let cost = template.cost;
let costMax = 0;
@ -208,7 +208,7 @@ m.ResearchManager.prototype.update = function(gameState, queues)
if (!techs.length)
return;
// randomly pick one. No worries about pairs in that case.
var p = Math.floor((Math.random()*techs.length));
var p = Math.floor(Math.random()*techs.length);
queues.minorTech.addPlan(new m.ResearchPlan(gameState, techs[p][0]));
};

View file

@ -24,7 +24,7 @@ m.TradeManager.prototype.init = function(gameState)
m.TradeManager.prototype.hasTradeRoute = function()
{
return (this.tradeRoute !== undefined);
return this.tradeRoute !== undefined;
};
m.TradeManager.prototype.assignTrader = function(ent)
@ -166,12 +166,12 @@ m.TradeManager.prototype.setTradingGoods = function(gameState)
let wantedRate = gameState.ai.HQ.wantedRates[type];
if (stocks[type] < 200)
{
tradingGoods[type] = (wantedRate > 0) ? 20 : 10;
tradingGoods[type] = wantedRate > 0 ? 20 : 10;
targetNum += Math.min(5, 3 + Math.ceil(wantedRate/30));
}
else if (stocks[type] < 500)
{
tradingGoods[type] = (wantedRate > 0) ? 15 : 10;
tradingGoods[type] = wantedRate > 0 ? 15 : 10;
targetNum += 2;
}
else if (stocks[type] < 1000)
@ -281,7 +281,7 @@ m.TradeManager.prototype.performBarter = function(gameState)
continue;
let barterRateMin = 80;
if (available[buy] < 5000 && available.food > 5000)
barterRateMin -= (20 - Math.floor(available[buy]/250));
barterRateMin -= 20 - Math.floor(available[buy]/250);
let barterRate = getBarterRate(prices, buy, "food");
if (barterRate < barterRateMin)
continue;
@ -407,7 +407,7 @@ m.TradeManager.prototype.checkRoutes = function(gameState, accessIndex)
continue;
var access2 = gameState.ai.accessibility.getAccessValue(m2.position());
var sea2 = m2.hasClass("NavalMarket") ? gameState.ai.HQ.navalManager.getDockIndex(gameState, m2, true) : undefined;
var land = (access1 == access2) ? access1 : undefined;
var land = access1 == access2 ? access1 : undefined;
var sea = (sea1 && sea1 == sea2) ? sea1 : undefined;
if (!land && !sea)
continue;
@ -494,11 +494,9 @@ m.TradeManager.prototype.checkRoutes = function(gameState, accessIndex)
return bestIndex;
else if (gameState.ai.accessibility.regionType[accessIndex] === "land" && bestLand.gain > 0)
return bestLand;
else
return false;
return false;
}
else
return true;
return true;
};
// Called when a market was built or destroyed, and checks if trader orders should be changed
@ -610,7 +608,7 @@ m.TradeManager.prototype.routeEntToId = function(route)
return route;
let ret = {};
for (let key in route)
ret[key] = ((key == "source" || key == "target") ? route[key].id() : route[key]);
ret[key] = (key == "source" || key == "target") ? route[key].id() : route[key];
return ret;
};
@ -620,7 +618,7 @@ m.TradeManager.prototype.routeIdToEnt = function(gameState, route)
return route;
let ret = {};
for (let key in route)
ret[key] = ((key == "source" || key == "target") ? gameState.getEntityById(route[key]) : route[key]);
ret[key] = (key == "source" || key == "target") ? gameState.getEntityById(route[key]) : route[key];
return ret;
};

View file

@ -71,7 +71,7 @@ m.TransportPlan = function(gameState, units, startIndex, endIndex, endPos, ship)
this.state = "boarding";
this.boardingPos = {};
this.needTransportShips = (ship === undefined);
this.needTransportShips = ship === undefined;
this.nTry = {};
return true;
};

View file

@ -571,7 +571,7 @@ m.Worker.prototype.startHunting = function(gameState, position)
if (nbGatherers > 0 && supply.resourceSupplyAmount()/(1+nbGatherers) < 30)
return;
var canFlee = (!supply.hasClass("Domestic") && supply.templateName().indexOf("resource|") == -1);
var canFlee = !supply.hasClass("Domestic") && supply.templateName().indexOf("resource|") == -1;
// Only cavalry and range units should hunt fleeing animals
if (canFlee && !isCavalry && !isRanged)
return;
@ -710,12 +710,9 @@ m.Worker.prototype.startFishing = function(gameState)
this.ent.setMetadata(PlayerID, "target-foundation", undefined);
return true;
}
else
{
if (this.ent.getMetadata(PlayerID,"subrole") === "fisher")
this.ent.setMetadata(PlayerID, "subrole", "idle");
return false;
}
if (this.ent.getMetadata(PlayerID,"subrole") === "fisher")
this.ent.setMetadata(PlayerID, "subrole", "idle");
return false;
};
m.Worker.prototype.gatherNearestField = function(gameState, baseID)