1
0
forked from 0ad/0ad

Remove trailing whitespace and simplify some length checks. Refs #252.

This was SVN commit r18214.
This commit is contained in:
elexis 2016-05-21 16:20:27 +00:00
parent a2bd82d171
commit 4b5f8dfca6
17 changed files with 91 additions and 92 deletions

View File

@ -30,7 +30,7 @@ function GetVisibleIdentityClasses(template)
* Check if the classes given in the identity template * Check if the classes given in the identity template
* match a list of classes * match a list of classes
* @param classes List of the classes to check against * @param classes List of the classes to check against
* @param match Either a string in the form * @param match Either a string in the form
* "Class1 Class2+Class3" * "Class1 Class2+Class3"
* where spaces are handled as OR and '+'-signs as AND, * where spaces are handled as OR and '+'-signs as AND,
* and ! is handled as NOT, thus Class1+!Class2 = Class1 AND NOT Class2 * and ! is handled as NOT, thus Class1+!Class2 = Class1 AND NOT Class2
@ -253,7 +253,7 @@ function GetTemplateDataHelper(template, player, auraTemplates)
"GainMultiplier": func("Trader/GainMultiplier", +template.Trader.GainMultiplier, player, template) "GainMultiplier": func("Trader/GainMultiplier", +template.Trader.GainMultiplier, player, template)
}; };
} }
if (template.WallSet) if (template.WallSet)
{ {
ret.wallSet = { ret.wallSet = {
@ -284,7 +284,7 @@ function GetTechnologyDataHelper(template, civ)
{ {
var ret = {}; var ret = {};
// Get specific name for this civ or else the generic specific name // Get specific name for this civ or else the generic specific name
var specific = undefined; var specific = undefined;
if (template.specificName) if (template.specificName)
{ {

View File

@ -488,7 +488,7 @@ function getPreferredEntities(ents)
for (var i = 0; i < filters.length; ++i) for (var i = 0; i < filters.length; ++i)
{ {
preferredEnts = ents.filter(filters[i]); preferredEnts = ents.filter(filters[i]);
if (preferredEnts.length > 0) if (preferredEnts.length)
break; break;
} }
return preferredEnts; return preferredEnts;

View File

@ -1,12 +1,12 @@
/** /**
* List of different actions units can execute, * List of different actions units can execute,
* this is mostly used to determine which actions can be executed * this is mostly used to determine which actions can be executed
* *
* "execute" is meant to send the command to the engine * "execute" is meant to send the command to the engine
* *
* The next functions will always return false * The next functions will always return false
* in case you have to continue to seek * in case you have to continue to seek
* (i.e. look at the next entity for getActionInfo, the next * (i.e. look at the next entity for getActionInfo, the next
* possible action for the actionCheck ...) * possible action for the actionCheck ...)
* They will return an object when the searching is finished * They will return an object when the searching is finished
* *
@ -24,10 +24,10 @@
* *
* "specificness" is used to determine how specific an action is, * "specificness" is used to determine how specific an action is,
* The lower the number, the more specific an action is, and the bigger * The lower the number, the more specific an action is, and the bigger
* the chance of selecting that action when multiple actions are possible * the chance of selecting that action when multiple actions are possible
*/ */
var unitActions = var unitActions =
{ {
"move": "move":
{ {
@ -56,7 +56,7 @@ var unitActions =
"specificness": 12, "specificness": 12,
}, },
"attack-move": "attack-move":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -87,7 +87,7 @@ var unitActions =
"specificness": 30, "specificness": 30,
}, },
"capture": "capture":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -139,7 +139,7 @@ var unitActions =
"specificness": 10, "specificness": 10,
}, },
"heal": "heal":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -159,7 +159,7 @@ var unitActions =
// Healers can't heal themselves. // Healers can't heal themselves.
if (entState.id == targetState.id) if (entState.id == targetState.id)
return false; return false;
var unhealableClasses = entState.healer.unhealableClasses; var unhealableClasses = entState.healer.unhealableClasses;
if (MatchesClassList(targetState.identity.classes, unhealableClasses)) if (MatchesClassList(targetState.identity.classes, unhealableClasses))
return false; return false;
@ -179,7 +179,7 @@ var unitActions =
"specificness": 7, "specificness": 7,
}, },
"build": "build":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -202,7 +202,7 @@ var unitActions =
"specificness": 3, "specificness": 3,
}, },
"repair": "repair":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -233,7 +233,7 @@ var unitActions =
"specificness": 11, "specificness": 11,
}, },
"gather": "gather":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -260,7 +260,7 @@ var unitActions =
"specificness": 1, "specificness": 1,
}, },
"returnresource": "returnresource":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -297,7 +297,7 @@ var unitActions =
"specificness": 2, "specificness": 2,
}, },
"setup-trade-route": "setup-trade-route":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -362,7 +362,7 @@ var unitActions =
"specificness": 0, "specificness": 0,
}, },
"garrison": "garrison":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -409,7 +409,7 @@ var unitActions =
"specificness": 20, "specificness": 20,
}, },
"guard": "guard":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -446,7 +446,7 @@ var unitActions =
"specificness": 40, "specificness": 40,
}, },
"remove-guard": "remove-guard":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -471,11 +471,11 @@ var unitActions =
"specificness": 41, "specificness": 41,
}, },
"set-rallypoint": "set-rallypoint":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
// if there is a position set in the action then use this so that when setting a // if there is a position set in the action then use this so that when setting a
// rally point on an entity it is centered on that entity // rally point on an entity it is centered on that entity
if (action.position) if (action.position)
target = action.position; target = action.position;
@ -584,7 +584,7 @@ var unitActions =
} }
return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip}; return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip};
}, },
"actionCheck": function(target, selection) "actionCheck": function(target, selection)
{ {
@ -604,7 +604,7 @@ var unitActions =
}); });
if (!haveRallyPoints) if (!haveRallyPoints)
return false; return false;
var actionInfo = getActionInfo("set-rallypoint", target); var actionInfo = getActionInfo("set-rallypoint", target);
if (!actionInfo.possible) if (!actionInfo.possible)
return false; return false;
@ -613,7 +613,7 @@ var unitActions =
"specificness": 6, "specificness": 6,
}, },
"unset-rallypoint": "unset-rallypoint":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -654,7 +654,7 @@ var unitActions =
"specificness": 11, "specificness": 11,
}, },
"none": "none":
{ {
"execute": function(target, action, selection, queued) "execute": function(target, action, selection, queued)
{ {
@ -668,7 +668,7 @@ var unitActions =
* Info and actions for the entity commands * Info and actions for the entity commands
* Currently displayed in the bottom of the central panel * Currently displayed in the bottom of the central panel
*/ */
var g_EntityCommands = var g_EntityCommands =
{ {
// Unload // Unload
"unload-all": { "unload-all": {
@ -712,7 +712,7 @@ var g_EntityCommands =
"tooltip": translate("You cannot destroy this entity as you own less than half the capture points"), "tooltip": translate("You cannot destroy this entity as you own less than half the capture points"),
"icon": "kill_small_disabled.png" "icon": "kill_small_disabled.png"
}; };
return { return {
"tooltip": translate("Delete"), "tooltip": translate("Delete"),
@ -728,7 +728,7 @@ var g_EntityCommands =
return; return;
var selection = g_Selection.toList(); var selection = g_Selection.toList();
if (selection.length < 1) if (!selection.length)
return; return;
if (!entState.resourceSupply || !entState.resourceSupply.killBeforeGather || g_DevSettings.controlAll) if (!entState.resourceSupply || !entState.resourceSupply.killBeforeGather || g_DevSettings.controlAll)
openDeleteDialog(selection); openDeleteDialog(selection);
@ -748,7 +748,7 @@ var g_EntityCommands =
"execute": function(entState) "execute": function(entState)
{ {
var selection = g_Selection.toList(); var selection = g_Selection.toList();
if (selection.length > 0) if (selection.length)
stopUnits(selection); stopUnits(selection);
}, },
}, },
@ -824,7 +824,7 @@ var g_EntityCommands =
focusTarget = entState.rallyPoint.position; focusTarget = entState.rallyPoint.position;
else if (entState.position) else if (entState.position)
focusTarget = entState.position; focusTarget = entState.position;
if (focusTarget) if (focusTarget)
Engine.CameraMoveTo(focusTarget.x, focusTarget.z); Engine.CameraMoveTo(focusTarget.x, focusTarget.z);
}, },
@ -944,13 +944,13 @@ var g_AllyEntityCommands =
{ {
var selectedEntState = GetEntityState(ent); var selectedEntState = GetEntityState(ent);
if (selectedEntState.garrisonHolder) if (selectedEntState.garrisonHolder)
{ {
var player = Engine.GetPlayerID(); var player = Engine.GetPlayerID();
for (var entity of selectedEntState.garrisonHolder.entities) for (var entity of selectedEntState.garrisonHolder.entities)
{ {
var state = GetEntityState(entity); var state = GetEntityState(entity);
if (state.player == player) if (state.player == player)
count++; ++count;
} }
} }
} }

View File

@ -111,7 +111,7 @@ function getTradingTooltip(gain)
function getEntityOrHolder(ent) function getEntityOrHolder(ent)
{ {
var entState = GetEntityState(ent); var entState = GetEntityState(ent);
if (entState && !entState.position && entState.unitAI && entState.unitAI.orders.length > 0 && if (entState && !entState.position && entState.unitAI && entState.unitAI.orders.length &&
(entState.unitAI.orders[0].type == "Garrison" || entState.unitAI.orders[0].type == "Autogarrison")) (entState.unitAI.orders[0].type == "Garrison" || entState.unitAI.orders[0].type == "Autogarrison"))
return entState.unitAI.orders[0].data.target; return entState.unitAI.orders[0].data.target;

View File

@ -208,7 +208,7 @@ function loadTechnology(techName)
break; break;
case "all": case "all":
if (req[0].length < 1) if (!req[0].length)
tech.reqs.generic = req[1]; tech.reqs.generic = req[1];
else else
for (let r of req[0]) for (let r of req[0])

View File

@ -57,7 +57,7 @@ m.Template = m.Class({
return undefined; return undefined;
return GetIdentityClasses(template); return GetIdentityClasses(template);
}, },
requiredTech: function() { requiredTech: function() {
return this.get("Identity/RequiredTechnology"); return this.get("Identity/RequiredTechnology");
}, },
@ -375,7 +375,7 @@ m.Template = m.Class({
return +this.get("ResourceSupply/MaxGatherers"); return +this.get("ResourceSupply/MaxGatherers");
return 0; return 0;
}, },
resourceGatherRates: function() { resourceGatherRates: function() {
if (!this.get("ResourceGatherer")) if (!this.get("ResourceGatherer"))
return undefined; return undefined;
@ -478,7 +478,7 @@ m.Template = m.Class({
return undefined; return undefined;
return this.get("BuildRestrictions/Category"); return this.get("BuildRestrictions/Category");
}, },
buildTime: function() { buildTime: function() {
if (!this.get("Cost") || !this.get("Cost/BuildTime")) if (!this.get("Cost") || !this.get("Cost/BuildTime"))
return undefined; return undefined;
@ -702,7 +702,7 @@ m.Entity = m.Class({
resourceCarrying: function() { resourceCarrying: function() {
if (this._entity.resourceCarrying === undefined) if (this._entity.resourceCarrying === undefined)
return undefined; return undefined;
return this._entity.resourceCarrying; return this._entity.resourceCarrying;
}, },
currentGatherRate: function() { currentGatherRate: function() {

View File

@ -10,7 +10,7 @@ m.EntityCollection = function(sharedAI, entities = new Map(), filters = [])
for (var filter of this._filters) for (var filter of this._filters)
if (filter.dynamicProperties.length) if (filter.dynamicProperties.length)
this.dynamicProp = this.dynamicProp.concat(filter.dynamicProperties); this.dynamicProp = this.dynamicProp.concat(filter.dynamicProperties);
Object.defineProperty(this, "length", { Object.defineProperty(this, "length", {
get: function () { get: function () {
return this._entities.size; return this._entities.size;
@ -83,12 +83,12 @@ m.EntityCollection.prototype.filter = function(filter, thisp)
{ {
if (typeof filter === "function") if (typeof filter === "function")
filter = {"func": filter, "dynamicProperties": []}; filter = {"func": filter, "dynamicProperties": []};
var ret = new Map(); var ret = new Map();
for (let [id, ent] of this._entities) for (let [id, ent] of this._entities)
if (filter.func.call(thisp, ent, id, this)) if (filter.func.call(thisp, ent, id, this))
ret.set(id, ent); ret.set(id, ent);
return new m.EntityCollection(this._ai, ret, this._filters.concat([filter])); return new m.EntityCollection(this._ai, ret, this._filters.concat([filter]));
}; };

View File

@ -88,7 +88,7 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, data)
} }
} }
this.paused = false; this.paused = false;
this.maxCompletingTime = 0; this.maxCompletingTime = 0;
// priority of the queues we'll create. // priority of the queues we'll create.
var priority = 70; var priority = 70;
@ -598,7 +598,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
continue; continue;
ent.setMetadata(PlayerID, "plan", plan); ent.setMetadata(PlayerID, "plan", plan);
this.unitCollection.updateEnt(ent); this.unitCollection.updateEnt(ent);
added = true; added = true;
} }
return added; return added;
} }

View File

@ -16,7 +16,7 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
{ {
// we'll assume this defender is ours already. // we'll assume this defender is ours already.
// we'll also override any previous assignment // we'll also override any previous assignment
var ent = gameState.getEntityById(entID); var ent = gameState.getEntityById(entID);
if (!ent || !ent.position()) if (!ent || !ent.position())
return false; return false;
@ -27,14 +27,14 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
var idMin; var idMin;
var distMin; var distMin;
var idMinAll; var idMinAll;
var distMinAll; var distMinAll;
for (let id of this.foeEntities) for (let id of this.foeEntities)
{ {
let eEnt = gameState.getEntityById(id); let eEnt = gameState.getEntityById(id);
if (!eEnt || !eEnt.position()) // probably can't happen. if (!eEnt || !eEnt.position()) // probably can't happen.
continue; continue;
if (eEnt.hasClass("Unit") && eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length && if (eEnt.hasClass("Unit") && eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length &&
eEnt.unitAIOrderData()[0].target && eEnt.unitAIOrderData()[0].target == entID) eEnt.unitAIOrderData()[0].target && eEnt.unitAIOrderData()[0].target == entID)
{ // being attacked >>> target the unit { // being attacked >>> target the unit
idMin = id; idMin = id;
@ -87,10 +87,10 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
// TODO: this should return cleverer results ("needs anti-elephant"…) // TODO: this should return cleverer results ("needs anti-elephant"…)
m.DefenseArmy.prototype.needsDefenders = function (gameState) m.DefenseArmy.prototype.needsDefenders = function (gameState)
{ {
// some preliminary checks because we don't update for tech so entStrength removed can be > entStrength added // some preliminary checks because we don't update for tech so entStrength removed can be > entStrength added
if (this.foeStrength <= 0 || this.ownStrength <= 0) if (this.foeStrength <= 0 || this.ownStrength <= 0)
this.recalculateStrengths(gameState); this.recalculateStrengths(gameState);
if (this.foeStrength * this.defenseRatio <= this.ownStrength) if (this.foeStrength * this.defenseRatio <= this.ownStrength)
return false; return false;
return this.foeStrength * this.defenseRatio - this.ownStrength; return this.foeStrength * this.defenseRatio - this.ownStrength;

View File

@ -108,9 +108,9 @@ m.returnResources = function(gameState, ent)
distmin = dist; distmin = dist;
closestDropsite = dropsite; closestDropsite = dropsite;
}); });
if (!closestDropsite) if (!closestDropsite)
return false; return false;
ent.returnResources(closestDropsite); ent.returnResources(closestDropsite);
return true; return true;
}; };
@ -177,7 +177,7 @@ m.getHolder = function(gameState, ent)
}; };
/** /**
* return true if it is not worth finishing this building (it would surely decay) * return true if it is not worth finishing this building (it would surely decay)
* TODO implement the other conditions * TODO implement the other conditions
*/ */
m.isNotWorthBuilding = function(gameState, ent) m.isNotWorthBuilding = function(gameState, ent)

View File

@ -36,7 +36,7 @@ m.ResearchPlan.prototype.start = function(gameState)
// Prefer training buildings with short queues // Prefer training buildings with short queues
// (TODO: this should also account for units added to the queue by // (TODO: this should also account for units added to the queue by
// plans that have already been executed this turn) // plans that have already been executed this turn)
if (trainers.length > 0) if (trainers.length)
{ {
trainers.sort((a, b) => a.trainingQueueTime() - b.trainingQueueTime()); trainers.sort((a, b) => a.trainingQueueTime() - b.trainingQueueTime());
// drop anything in the queue if we rush it. // drop anything in the queue if we rush it.

View File

@ -53,7 +53,7 @@ m.TrainingPlan.prototype.start = function(gameState)
// Prefer training buildings with short queues // Prefer training buildings with short queues
// (TODO: this should also account for units added to the queue by // (TODO: this should also account for units added to the queue by
// plans that have already been executed this turn) // plans that have already been executed this turn)
if (trainersColl.length > 0) if (trainersColl.length)
{ {
let trainers = trainersColl.toEntityArray(); let trainers = trainersColl.toEntityArray();
let wantedIndex; let wantedIndex;

View File

@ -51,9 +51,8 @@ m.TutorialAI.prototype.OnUpdate = function() {
return; return;
} }
if (this.events.length > 0){ if (this.events.length)
this.savedEvents = this.savedEvents.concat(this.events); this.savedEvents = this.savedEvents.concat(this.events);
}
Engine.ProfileStart("tutorialBot"); Engine.ProfileStart("tutorialBot");

View File

@ -1,6 +1,6 @@
function Attack() {} function Attack() {}
Attack.prototype.bonusesSchema = Attack.prototype.bonusesSchema =
"<optional>" + "<optional>" +
"<element name='Bonuses'>" + "<element name='Bonuses'>" +
"<zeroOrMore>" + "<zeroOrMore>" +
@ -253,7 +253,7 @@ Attack.prototype.CanAttack = function(target)
let heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset()); let heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset());
const cmpIdentity = Engine.QueryInterface(target, IID_Identity); const cmpIdentity = Engine.QueryInterface(target, IID_Identity);
if (!cmpIdentity) if (!cmpIdentity)
return undefined; return undefined;
const targetClasses = cmpIdentity.GetClassesList(); const targetClasses = cmpIdentity.GetClassesList();
@ -294,7 +294,7 @@ Attack.prototype.CanAttack = function(target)
Attack.prototype.GetPreference = function(target) Attack.prototype.GetPreference = function(target)
{ {
const cmpIdentity = Engine.QueryInterface(target, IID_Identity); const cmpIdentity = Engine.QueryInterface(target, IID_Identity);
if (!cmpIdentity) if (!cmpIdentity)
return undefined; return undefined;
const targetClasses = cmpIdentity.GetClassesList(); const targetClasses = cmpIdentity.GetClassesList();
@ -350,14 +350,14 @@ Attack.prototype.GetBestAttackAgainst = function(target, allowCapture)
} }
let cmpIdentity = Engine.QueryInterface(target, IID_Identity); let cmpIdentity = Engine.QueryInterface(target, IID_Identity);
if (!cmpIdentity) if (!cmpIdentity)
return undefined; return undefined;
let targetClasses = cmpIdentity.GetClassesList(); let targetClasses = cmpIdentity.GetClassesList();
let isTargetClass = function (className) { return targetClasses.indexOf(className) != -1; }; let isTargetClass = function (className) { return targetClasses.indexOf(className) != -1; };
// Always slaughter domestic animals instead of using a normal attack // Always slaughter domestic animals instead of using a normal attack
if (isTargetClass("Domestic") && this.template.Slaughter) if (isTargetClass("Domestic") && this.template.Slaughter)
return "Slaughter"; return "Slaughter";
let attack = this; let attack = this;
@ -535,9 +535,9 @@ Attack.prototype.PerformAttack = function(type, target)
let horizDistance = targetPosition.horizDistanceTo(selfPosition); let horizDistance = targetPosition.horizDistanceTo(selfPosition);
// This is an approximation of the time ot the target, it assumes that the target has a constant radial // This is an approximation of the time ot the target, it assumes that the target has a constant radial
// velocity, but since units move in straight lines this is not true. The exact value would be more // velocity, but since units move in straight lines this is not true. The exact value would be more
// difficult to calculate and I think this is sufficiently accurate. (I tested and for cavalry it was // difficult to calculate and I think this is sufficiently accurate. (I tested and for cavalry it was
// about 5% of the units radius out in the worst case) // about 5% of the units radius out in the worst case)
let timeToTarget = horizDistance / (horizSpeed - radialSpeed); let timeToTarget = horizDistance / (horizSpeed - radialSpeed);

View File

@ -54,7 +54,7 @@ GarrisonHolder.prototype.Schema =
/** /**
* Initialize GarrisonHolder Component * Initialize GarrisonHolder Component
* *
* Garrisoning when loading a map is set in the script of the map, by setting initGarrison * Garrisoning when loading a map is set in the script of the map, by setting initGarrison
* which should contain the array of garrisoned entities * which should contain the array of garrisoned entities
*/ */
GarrisonHolder.prototype.Init = function() GarrisonHolder.prototype.Init = function()
@ -111,7 +111,7 @@ GarrisonHolder.prototype.GetEntities = function()
/** /**
* Returns an array of unit classes which can be garrisoned inside this * Returns an array of unit classes which can be garrisoned inside this
* particualar entity. Obtained from the entity's template * particualar entity. Obtained from the entity's template
*/ */
GarrisonHolder.prototype.GetAllowedClasses = function() GarrisonHolder.prototype.GetAllowedClasses = function()
{ {
@ -146,7 +146,7 @@ GarrisonHolder.prototype.GetHealRate = function()
* Set this entity to allow or disallow garrisoning in * Set this entity to allow or disallow garrisoning in
* Every component calling this function should do it with its own ID, and as long as one * Every component calling this function should do it with its own ID, and as long as one
* component doesn't allow this entity to garrison, it can't be garrisoned * component doesn't allow this entity to garrison, it can't be garrisoned
* When this entity already contains garrisoned soldiers, * When this entity already contains garrisoned soldiers,
* these will not be able to ungarrison until the flag is set to true again. * these will not be able to ungarrison until the flag is set to true again.
* *
* This more useful for modern-day features. For example you can't garrison or ungarrison * This more useful for modern-day features. For example you can't garrison or ungarrison
@ -158,7 +158,7 @@ GarrisonHolder.prototype.AllowGarrisoning = function(allow, callerID)
}; };
/** /**
* Check if no component of this entity blocks garrisoning * Check if no component of this entity blocks garrisoning
* (f.e. because the vehicle is moving too fast) * (f.e. because the vehicle is moving too fast)
*/ */
GarrisonHolder.prototype.IsGarrisoningAllowed = function() GarrisonHolder.prototype.IsGarrisoningAllowed = function()
@ -389,7 +389,7 @@ GarrisonHolder.prototype.OrderWalkToRallyPoint = function(entities)
* Ejects units and orders them to move to the Rally Point. * Ejects units and orders them to move to the Rally Point.
* Returns true if successful, false if not * Returns true if successful, false if not
* If an ejection with a given obstruction radius has failed, we won't try anymore to eject * If an ejection with a given obstruction radius has failed, we won't try anymore to eject
* entities with a bigger obstruction as that is compelled to also fail * entities with a bigger obstruction as that is compelled to also fail
*/ */
GarrisonHolder.prototype.PerformEject = function(entities, forced) GarrisonHolder.prototype.PerformEject = function(entities, forced)
{ {
@ -449,7 +449,7 @@ GarrisonHolder.prototype.Unload = function(entity, forced)
* Unload one or all units that match a template and owner from * Unload one or all units that match a template and owner from
* the garrisoning entity and order them to move to the Rally Point * the garrisoning entity and order them to move to the Rally Point
* Returns true if successful, false if not * Returns true if successful, false if not
* *
* extendedTemplate has the format "p"+ownerid+"&"+template * extendedTemplate has the format "p"+ownerid+"&"+template
*/ */
GarrisonHolder.prototype.UnloadTemplate = function(extendedTemplate, all, forced) GarrisonHolder.prototype.UnloadTemplate = function(extendedTemplate, all, forced)

View File

@ -2738,7 +2738,7 @@ UnitAI.prototype.UnitFsmSpec = {
let dropsiteTypes = cmpResourceDropsite.GetTypes(); let dropsiteTypes = cmpResourceDropsite.GetTypes();
cmpResourceGatherer.CommitResources(dropsiteTypes); cmpResourceGatherer.CommitResources(dropsiteTypes);
this.SetGathererAnimationOverride(); this.SetGathererAnimationOverride();
} }
// We finished building it. // We finished building it.
// Switch to the next order (if any) // Switch to the next order (if any)
@ -3450,7 +3450,7 @@ UnitAI.prototype.UpdateRangeQueries = function()
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
if (this.losRangeQuery) if (this.losRangeQuery)
this.SetupRangeQuery(cmpRangeManager.IsActiveQueryEnabled(this.losRangeQuery)); this.SetupRangeQuery(cmpRangeManager.IsActiveQueryEnabled(this.losRangeQuery));
if (this.IsHealer() && this.losHealRangeQuery) if (this.IsHealer() && this.losHealRangeQuery)
this.SetupHealRangeQuery(cmpRangeManager.IsActiveQueryEnabled(this.losHealRangeQuery)); this.SetupHealRangeQuery(cmpRangeManager.IsActiveQueryEnabled(this.losHealRangeQuery));
}; };

View File

@ -109,7 +109,7 @@ function TestFormationExiting(mode)
unitAI.SetupRangeQuery(1); unitAI.SetupRangeQuery(1);
if (mode == 1) if (mode == 1)
{ {
AddMock(enemy, IID_Health, { AddMock(enemy, IID_Health, {
GetHitpoints: function() { return 10; }, GetHitpoints: function() { return 10; },
@ -117,7 +117,7 @@ function TestFormationExiting(mode)
AddMock(enemy, IID_UnitAI, { AddMock(enemy, IID_UnitAI, {
IsAnimal: function() { return false; } IsAnimal: function() { return false; }
}); });
} }
else if (mode == 2) else if (mode == 2)
AddMock(enemy, IID_Health, { AddMock(enemy, IID_Health, {
GetHitpoints: function() { return 0; }, GetHitpoints: function() { return 0; },
@ -210,19 +210,19 @@ function TestMoveIntoFormationWhileAttacking()
// create units // create units
for (var i = 0; i < unitCount; i++) { for (var i = 0; i < unitCount; i++) {
units.push(unit + i); units.push(unit + i);
var unitAI = ConstructComponent(unit + i, "UnitAI", { "FormationController": "false", "DefaultStance": "aggressive" }); var unitAI = ConstructComponent(unit + i, "UnitAI", { "FormationController": "false", "DefaultStance": "aggressive" });
AddMock(unit + i, IID_Identity, { AddMock(unit + i, IID_Identity, {
GetClassesList: function() { return []; }, GetClassesList: function() { return []; },
}); });
AddMock(unit + i, IID_Ownership, { AddMock(unit + i, IID_Ownership, {
GetOwner: function() { return 1; }, GetOwner: function() { return 1; },
}); });
AddMock(unit + i, IID_Position, { AddMock(unit + i, IID_Position, {
GetTurretParent: function() { return INVALID_ENTITY; }, GetTurretParent: function() { return INVALID_ENTITY; },
GetPosition: function() { return new Vector3D(); }, GetPosition: function() { return new Vector3D(); },
@ -230,7 +230,7 @@ function TestMoveIntoFormationWhileAttacking()
GetRotation: function() { return { "y": 0 }; }, GetRotation: function() { return { "y": 0 }; },
IsInWorld: function() { return true; }, IsInWorld: function() { return true; },
}); });
AddMock(unit + i, IID_UnitMotion, { AddMock(unit + i, IID_UnitMotion, {
GetWalkSpeed: function() { return 1; }, GetWalkSpeed: function() { return 1; },
MoveToFormationOffset: function(target, x, z) { }, MoveToFormationOffset: function(target, x, z) { },
@ -239,11 +239,11 @@ function TestMoveIntoFormationWhileAttacking()
StopMoving: function() { }, StopMoving: function() { },
GetPassabilityClassName: function() { return "default"; }, GetPassabilityClassName: function() { return "default"; },
}); });
AddMock(unit + i, IID_Vision, { AddMock(unit + i, IID_Vision, {
GetRange: function() { return 10; }, GetRange: function() { return 10; },
}); });
AddMock(unit + i, IID_Attack, { AddMock(unit + i, IID_Attack, {
GetRange: function() { return {"max":10, "min": 0}; }, GetRange: function() { return {"max":10, "min": 0}; },
GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, GetFullAttackRange: function() { return { "max": 40, "min": 0}; },
@ -252,14 +252,14 @@ function TestMoveIntoFormationWhileAttacking()
CanAttack: function(v) { return true; }, CanAttack: function(v) { return true; },
CompareEntitiesByPreference: function(a, b) { return 0; }, CompareEntitiesByPreference: function(a, b) { return 0; },
}); });
unitAI.OnCreate(); unitAI.OnCreate();
unitAI.SetupRangeQuery(1); unitAI.SetupRangeQuery(1);
unitAIs.push(unitAI); unitAIs.push(unitAI);
} }
// create enemy // create enemy
AddMock(enemy, IID_Health, { AddMock(enemy, IID_Health, {
GetHitpoints: function() { return 40; }, GetHitpoints: function() { return 40; },
@ -292,15 +292,15 @@ function TestMoveIntoFormationWhileAttacking()
controllerAI.OnCreate(); controllerAI.OnCreate();
controllerFormation.SetMembers(units); controllerFormation.SetMembers(units);
controllerAI.Attack(enemy, []); controllerAI.Attack(enemy, []);
for each (var ent in unitAIs) { for each (var ent in unitAIs) {
TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING"); TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING");
} }
controllerAI.MoveIntoFormation({"name": "Circle"}); controllerAI.MoveIntoFormation({"name": "Circle"});
// let all units be in position // let all units be in position
for each (var ent in unitAIs) { for each (var ent in unitAIs) {
controllerFormation.SetInPosition(ent); controllerFormation.SetInPosition(ent);
@ -309,7 +309,7 @@ function TestMoveIntoFormationWhileAttacking()
for each (var ent in unitAIs) { for each (var ent in unitAIs) {
TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING"); TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING");
} }
controllerFormation.Disband(); controllerFormation.Disband();
} }