Check for cmpUnitAI when extracting formations.
59d0885d68
Changed the way to get formation UnitAIs, but didn't account
for selecting entities with and without UnitAI.
This fixes that.
Differential revision: D3333
Reviewed by: @wraitii
Comments by: @Angen, @Stan
This was SVN commit r24557.
This commit is contained in:
parent
300ff96d98
commit
962c896f28
@ -887,30 +887,37 @@ function notifyOrderFailure(entity, player)
|
||||
|
||||
/**
|
||||
* Get some information about the formations used by entities.
|
||||
* The entities must have a UnitAI component.
|
||||
*/
|
||||
function ExtractFormations(ents)
|
||||
{
|
||||
let entities = []; // subset of ents that have UnitAI
|
||||
let entities = []; // Entities with UnitAI.
|
||||
let members = {}; // { formationentity: [ent, ent, ...], ... }
|
||||
let templates = {}; // { formationentity: template }
|
||||
for (let ent of ents)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
var fid = cmpUnitAI.GetFormationController();
|
||||
if (fid != INVALID_ENTITY)
|
||||
{
|
||||
if (!members[fid])
|
||||
{
|
||||
members[fid] = [];
|
||||
templates[fid] = cmpUnitAI.GetFormationTemplate();
|
||||
}
|
||||
members[fid].push(ent);
|
||||
}
|
||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
if (!cmpUnitAI)
|
||||
continue;
|
||||
|
||||
entities.push(ent);
|
||||
|
||||
let fid = cmpUnitAI.GetFormationController();
|
||||
if (fid == INVALID_ENTITY)
|
||||
continue;
|
||||
|
||||
if (!members[fid])
|
||||
{
|
||||
members[fid] = [];
|
||||
templates[fid] = cmpUnitAI.GetFormationTemplate();
|
||||
}
|
||||
members[fid].push(ent);
|
||||
}
|
||||
|
||||
return { "entities": entities, "members": members, "templates": templates };
|
||||
return {
|
||||
"entities": entities,
|
||||
"members": members,
|
||||
"templates": templates
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1419,10 +1426,10 @@ function TryConstructWall(player, cmpPlayer, controlAllUnits, cmd)
|
||||
*/
|
||||
function RemoveFromFormation(ents)
|
||||
{
|
||||
var formation = ExtractFormations(ents);
|
||||
for (var fid in formation.members)
|
||||
let formation = ExtractFormations(ents);
|
||||
for (let fid in formation.members)
|
||||
{
|
||||
var cmpFormation = Engine.QueryInterface(+fid, IID_Formation);
|
||||
let cmpFormation = Engine.QueryInterface(+fid, IID_Formation);
|
||||
if (cmpFormation)
|
||||
cmpFormation.RemoveMembers(formation.members[fid]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user