1
0
forked from 0ad/0ad

ai: remove some unneeded parentheses

This was SVN commit r18186.
This commit is contained in:
mimo 2016-05-16 10:48:52 +00:00
parent 7ddfc89c18
commit 0b6c7ca1b0
5 changed files with 53 additions and 46 deletions

View File

@ -85,7 +85,7 @@ m.Template = m.Class({
if (!this._classes)
this._classes = this.classes();
var classes = this._classes;
return (classes && classes.indexOf(name) != -1);
return classes && classes.indexOf(name) !== -1;
},
hasClasses: function(array) {
@ -505,7 +505,7 @@ m.Template = m.Class({
hasBuildTerritory: function(territory) {
var territories = this.buildTerritories();
return (territories && territories.indexOf(territory) != -1);
return territories && territories.indexOf(territory) !== -1;
},
hasTerritoryInfluence: function() {
@ -531,15 +531,15 @@ m.Template = m.Class({
},
territoryDecayRate: function() {
return (this.get("TerritoryDecay") ? +this.get("TerritoryDecay/DecayRate") : 0);
return this.get("TerritoryDecay") ? +this.get("TerritoryDecay/DecayRate") : 0;
},
defaultRegenRate: function() {
return (this.get("Capturable") ? +this.get("Capturable/RegenRate") : 0);
return this.get("Capturable") ? +this.get("Capturable/RegenRate") : 0;
},
garrisonRegenRate: function() {
return (this.get("Capturable") ? +this.get("Capturable/GarrisonRegenRate") : 0);
return this.get("Capturable") ? +this.get("Capturable/GarrisonRegenRate") : 0;
},
visionRange: function() {
@ -616,32 +616,32 @@ 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); },
isHurt: function() { return (this.hitpoints() < this.maxHitpoints()); },
healthLevel: function() { return (this.hitpoints() / this.maxHitpoints()); },
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
* [ { "id": 0, "template": "...", "count": 1, "progress": 0.5, "metadata": ... }, ... ]
*/
trainingQueue: function() {
var queue = this._entity.trainingQueue;
let queue = this._entity.trainingQueue;
return queue;
},
trainingQueueTime: function() {
var queue = this._entity.trainingQueue;
let queue = this._entity.trainingQueue;
if (!queue)
return undefined;
var time = 0;
for (var item of queue)
let time = 0;
for (let item of queue)
time += item.timeRemaining;
return time/1000;
},
@ -679,7 +679,7 @@ m.Entity = m.Class({
},
resourceSupplyAmount: function() {
if(this._entity.resourceSupplyAmount === undefined)
if (this._entity.resourceSupplyAmount === undefined)
return undefined;
return this._entity.resourceSupplyAmount;
},
@ -694,13 +694,13 @@ m.Entity = m.Class({
isFull: function()
{
if (this._entity.resourceSupplyNumGatherers !== undefined)
return (this.maxGatherers() === this._entity.resourceSupplyNumGatherers);
return this.maxGatherers() === this._entity.resourceSupplyNumGatherers;
return undefined;
},
resourceCarrying: function() {
if(this._entity.resourceCarrying === undefined)
if (this._entity.resourceCarrying === undefined)
return undefined;
return this._entity.resourceCarrying;
},
@ -806,8 +806,8 @@ m.Entity = m.Class({
// moveApart from a point in the opposite direction with a distance dist
moveApart: function(point, dist) {
if (this.position() !== undefined) {
var direction = [this.position()[0] - point[0], this.position()[1] - point[1]];
var norm = m.VectorDistance(point, this.position());
let direction = [this.position()[0] - point[0], this.position()[1] - point[1]];
let norm = m.VectorDistance(point, this.position());
if (norm === 0)
direction = [1, 0];
else
@ -823,8 +823,9 @@ m.Entity = m.Class({
// Flees from a unit in the opposite direction.
flee: function(unitToFleeFrom) {
if (this.position() !== undefined && unitToFleeFrom.position() !== undefined) {
var FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0],this.position()[1] - unitToFleeFrom.position()[1]];
var dist = m.VectorDistance(unitToFleeFrom.position(), this.position() );
let FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0],
this.position()[1] - unitToFleeFrom.position()[1]];
let dist = m.VectorDistance(unitToFleeFrom.position(), this.position() );
FleeDirection[0] = (FleeDirection[0]/dist) * 8;
FleeDirection[1] = (FleeDirection[1]/dist) * 8;
@ -929,10 +930,10 @@ m.Entity = m.Class({
},
stopAllProduction: function(percentToStopAt) {
var queue = this._entity.trainingQueue;
let queue = this._entity.trainingQueue;
if (!queue)
return true; // no queue, so technically we stopped all production.
for (var item of queue)
for (let item of queue)
if (item.progress < percentToStopAt)
Engine.PostCommand(PlayerID,{ "type": "stop-production", "entity": this.id(), "id": item.id });
return this;

View File

@ -38,7 +38,7 @@ m.Filters = {
byMetadata: function(player, key, value){
return {"func" : function(ent){
return (ent.getMetadata(player, key) == value);
return ent.getMetadata(player, key) == value;
},
"dynamicProperties": ['metadata.' + key]};
},
@ -46,14 +46,14 @@ m.Filters = {
// can be used for stuffs which won't change once entities are created.
byStaticMetadata: function(player, key, value){
return {"func" : function(ent){
return (ent.getMetadata(player, key) == value);
return ent.getMetadata(player, key) == value;
},
"dynamicProperties": []};
},
byHasMetadata: function(player, key){
return {"func" : function(ent){
return (ent.getMetadata(player, key) != undefined);
return ent.getMetadata(player, key) != undefined;
},
"dynamicProperties": ['metadata.' + key]};
},
@ -81,14 +81,14 @@ m.Filters = {
byOwner: function(owner){
return {"func" : function(ent){
return (ent.owner() === owner);
return ent.owner() === owner;
},
"dynamicProperties": ['owner']};
},
byNotOwner: function(owner){
return {"func" : function(ent){
return (ent.owner() !== owner);
return ent.owner() !== owner;
},
"dynamicProperties": ['owner']};
},
@ -123,7 +123,7 @@ m.Filters = {
},
byTargetedEntity: function(targetID){
return {"func": function(ent) {
return (ent.unitAIOrderData().length && ent.unitAIOrderData()[0].target && ent.unitAIOrderData()[0].target == targetID);
return ent.unitAIOrderData().length && ent.unitAIOrderData()[0].target && ent.unitAIOrderData()[0].target == targetID;
},
"dynamicProperties": ['unitAIOrderData']};
},
@ -181,7 +181,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": ['position']};
},
@ -205,7 +205,7 @@ m.Filters = {
isDropsite: function(resourceType){
return {"func": function(ent){
return (ent.resourceDropsiteTypes() && (resourceType === undefined || ent.resourceDropsiteTypes().indexOf(resourceType) !== -1));
return ent.resourceDropsiteTypes() && (resourceType === undefined || ent.resourceDropsiteTypes().indexOf(resourceType) !== -1);
},
"dynamicProperties": []};
},
@ -233,7 +233,7 @@ m.Filters = {
return false;
if (type.generic == "treasure")
return (resourceType == type.specific);
return resourceType == type.specific;
return resourceType == type.generic;
},

View File

@ -188,7 +188,8 @@ m.GameState.prototype.isResearched = function(template)
// true if started or queued
m.GameState.prototype.isResearching = function(template)
{
return (this.playerData.researchStarted[template] !== undefined || this.playerData.researchQueued[template] !== undefined);
return this.playerData.researchStarted[template] !== undefined ||
this.playerData.researchQueued[template] !== undefined;
};
// this is an "in-absolute" check that doesn't check if we have a building to research from.
@ -199,7 +200,9 @@ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementChec
return false;
// researching or already researched: NOO.
if (this.playerData.researchQueued[techTemplateName] || this.playerData.researchStarted[techTemplateName] || this.playerData.researchedTechs[techTemplateName])
if (this.playerData.researchQueued[techTemplateName] ||
this.playerData.researchStarted[techTemplateName] ||
this.playerData.researchedTechs[techTemplateName])
return false;
if (noRequirementCheck === true)
@ -217,7 +220,9 @@ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementChec
if (template.pair())
{
let other = template.pairedWith();
if (this.playerData.researchQueued[other] || this.playerData.researchStarted[other] || this.playerData.researchedTechs[other])
if (this.playerData.researchQueued[other] ||
this.playerData.researchStarted[other] ||
this.playerData.researchedTechs[other])
return false;
}
@ -790,9 +795,10 @@ m.GameState.prototype.isDisabledTemplates = function(template)
// Checks whether the maximum number of buildings have been cnstructed for a certain catergory
m.GameState.prototype.isEntityLimitReached = function(category)
{
if(this.playerData.entityLimits[category] === undefined || this.playerData.entityCounts[category] === undefined)
if (this.playerData.entityLimits[category] === undefined ||
this.playerData.entityCounts[category] === undefined)
return false;
return (this.playerData.entityCounts[category] >= this.playerData.entityLimits[category]);
return this.playerData.entityCounts[category] >= this.playerData.entityLimits[category];
};
m.GameState.prototype.getTraderTemplatesGains = function()

View File

@ -281,8 +281,8 @@ m.Map.prototype.sumInfluence = function(cx, cy, radius)
*/
m.Map.prototype.expandInfluences = function(maximum, map)
{
maximum = (maximum !== undefined) ? maximum : this.maxVal;
let grid = (map !== undefined) ? map : this.map;
maximum = maximum !== undefined ? maximum : this.maxVal;
let grid = map !== undefined ? map : this.map;
let w = this.width;
let h = this.height;
@ -402,7 +402,7 @@ m.Map.prototype.getNonObstructedTile = function(i, radius, obstruction)
continue;
if (obstruction.isObstructedTile(kx, ky, radius))
continue;
return (kx + ky*w);
return kx + ky*w;
}
}
return -1;
@ -416,7 +416,7 @@ m.Map.prototype.isObstructedTile = function(kx, ky, radius)
return true;
for (let dy = 0; dy <= radius; ++dy)
{
let dxmax = (dy == 0) ? radius : Math.ceil(Math.sqrt(radius*radius - (dy-0.5)*(dy-0.5)));
let dxmax = dy === 0 ? radius : Math.ceil(Math.sqrt(radius*radius - (dy-0.5)*(dy-0.5)));
let xp = kx + (ky + dy)*w;
let xm = kx + (ky - dy)*w;
for (let dx = -dxmax; dx <= dxmax; ++dx)
@ -433,7 +433,7 @@ m.Map.prototype.findNearestObstructed = function(k, radius)
var w = this.width;
var ix = k % w;
var iy = Math.floor(k / w);
var n = (this.cellSize > 8) ? 1 : Math.floor(8 / this.cellSize);
var n = this.cellSize > 8 ? 1 : Math.floor(8 / this.cellSize);
for (let i = 1; i <= n; ++i)
{
let kx = ix - i;
@ -458,7 +458,7 @@ m.Map.prototype.findNearestObstructed = function(k, radius)
else
++ky;
}
return (kx + w*ky);
return kx + w*ky;
}
if (j < 2*i+1)
++kx;

View File

@ -6,7 +6,7 @@ m.Resources = function(amounts = {}, population = 0)
for (let key of this.types)
this[key] = amounts[key] || 0;
this.population = (population > 0) ? population : 0;
this.population = population > 0 ? population : 0;
};
m.Resources.prototype.types = [ "food", "wood", "stone", "metal" ];