0ad/binaries/data/mods/public/simulation/ai/qbot/entitycollection-extend.js
quantumstate 167cd7151e Bug fixes and dead code removal
Fixed Filters.byOwners, before it was using indexOf() which caused
problems with number/string inequality.
Fixed the countUnassignedUnits and getAvailablenits functions to work
with the new filters.
Removed old updating entity collection code since it has been replaced
by the common-api-v2

This was SVN commit r11545.
2012-04-18 10:46:24 +00:00

40 lines
878 B
JavaScript

EntityCollection.prototype.attack = function(unit)
{
var unitId;
if (typeOf(unit) === "Entity"){
unitId = unit.id();
}else{
unitId = unit;
}
Engine.PostCommand({"type": "attack", "entities": this.toIdArray(), "target": unitId, "queued": false});
return this;
};
function EntityCollectionFromIds(gameState, idList){
var ents = {};
for (var i in idList){
var id = idList[i];
if (gameState.entities._entities[id]) {
ents[id] = gameState.entities._entities[id];
}
}
return new EntityCollection(gameState.ai, ents);
}
EntityCollection.prototype.getCentrePosition = function(){
var sumPos = [0, 0];
var count = 0;
this.forEach(function(ent){
if (ent.position()){
sumPos[0] += ent.position()[0];
sumPos[1] += ent.position()[1];
count ++;
}
});
if (count === 0){
return undefined;
}else{
return [sumPos[0]/count, sumPos[1]/count];
}
};