Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js
Show First 20 Lines • Show All 1,407 Lines • ▼ Show 20 Lines | function GetFormationUnitAIs(ents, player, formationTemplate) | ||||
if (ents.length == 1) | if (ents.length == 1) | ||||
{ | { | ||||
// Skip unit if it has no UnitAI | // Skip unit if it has no UnitAI | ||||
var cmpUnitAI = Engine.QueryInterface(ents[0], IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ents[0], IID_UnitAI); | ||||
if (!cmpUnitAI) | if (!cmpUnitAI) | ||||
return []; | return []; | ||||
RemoveFromFormation(ents); | RemoveFromFormation(ents); | ||||
cmpUnitAI.SetLastFormationTemplate("formations/null"); | |||||
return [ cmpUnitAI ]; | return [ cmpUnitAI ]; | ||||
} | } | ||||
// Separate out the units that don't support the chosen formation | // Separate out the units that don't support the chosen formation | ||||
var formedEnts = []; | var formedEnts = []; | ||||
var nonformedUnitAIs = []; | var nonformedUnitAIs = []; | ||||
for (let ent of ents) | for (let ent of ents) | ||||
Show All 9 Lines | for (let ent of ents) | ||||
// if we move them to it. We should check if we can use formations | // if we move them to it. We should check if we can use formations | ||||
// for the other cases. | // for the other cases. | ||||
var nullFormation = (formationTemplate || cmpUnitAI.GetLastFormationTemplate()) == "formations/null"; | var nullFormation = (formationTemplate || cmpUnitAI.GetLastFormationTemplate()) == "formations/null"; | ||||
if (!nullFormation && cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "formations/null")) | if (!nullFormation && cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "formations/null")) | ||||
formedEnts.push(ent); | formedEnts.push(ent); | ||||
else | else | ||||
{ | { | ||||
if (nullFormation) | if (nullFormation) | ||||
{ | |||||
RemoveFromFormation([ent]); | |||||
cmpUnitAI.SetLastFormationTemplate("formations/null"); | cmpUnitAI.SetLastFormationTemplate("formations/null"); | ||||
} | |||||
nonformedUnitAIs.push(cmpUnitAI); | nonformedUnitAIs.push(cmpUnitAI); | ||||
} | } | ||||
} | } | ||||
if (formedEnts.length == 0) | if (formedEnts.length == 0) | ||||
{ | { | ||||
// No units support the foundation - return all the others | // No units support the foundation - return all the others | ||||
return nonformedUnitAIs; | return nonformedUnitAIs; | ||||
▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator