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,427 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"); | cmpUnitAI.SetLastFormationTemplate("special/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) | ||||
{ | { | ||||
// Skip units with no UnitAI or no position | // Skip units with no UnitAI or no position | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
var cmpPosition = Engine.QueryInterface(ent, IID_Position); | var cmpPosition = Engine.QueryInterface(ent, IID_Position); | ||||
if (!cmpUnitAI || !cmpPosition || !cmpPosition.IsInWorld()) | if (!cmpUnitAI || !cmpPosition || !cmpPosition.IsInWorld()) | ||||
continue; | continue; | ||||
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); | var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); | ||||
// TODO: We only check if the formation is usable by some units | // TODO: We only check if the formation is usable by some units | ||||
// 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()) == "special/formations/null"; | ||||
if (!nullFormation && cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "formations/null")) | if (!nullFormation && cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "special/formations/null")) | ||||
formedEnts.push(ent); | formedEnts.push(ent); | ||||
else | else | ||||
{ | { | ||||
if (nullFormation) | if (nullFormation) | ||||
{ | { | ||||
RemoveFromFormation([ent]); | RemoveFromFormation([ent]); | ||||
cmpUnitAI.SetLastFormationTemplate("formations/null"); | cmpUnitAI.SetLastFormationTemplate("special/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 | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | for (let cluster of clusters) | ||||
lastFormationTemplate = undefined; | lastFormationTemplate = undefined; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (lastFormationTemplate && CanMoveEntsIntoFormation(cluster, lastFormationTemplate)) | if (lastFormationTemplate && CanMoveEntsIntoFormation(cluster, lastFormationTemplate)) | ||||
formationTemplate = lastFormationTemplate; | formationTemplate = lastFormationTemplate; | ||||
else | else | ||||
formationTemplate = "formations/null"; | formationTemplate = "special/formations/null"; | ||||
} | } | ||||
// Create the new controller | // Create the new controller | ||||
var formationEnt = Engine.AddEntity(formationTemplate); | var formationEnt = Engine.AddEntity(formationTemplate); | ||||
var cmpFormation = Engine.QueryInterface(formationEnt, IID_Formation); | var cmpFormation = Engine.QueryInterface(formationEnt, IID_Formation); | ||||
formationUnitAIs.push(Engine.QueryInterface(formationEnt, IID_UnitAI)); | formationUnitAIs.push(Engine.QueryInterface(formationEnt, IID_UnitAI)); | ||||
cmpFormation.SetFormationSeparation(formationSeparation); | cmpFormation.SetFormationSeparation(formationSeparation); | ||||
cmpFormation.SetMembers(cluster); | cmpFormation.SetMembers(cluster); | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator