mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Remove lastFormationTemplate from UnitAI
Differential Revision: https://code.wildfiregames.com/D1255 Reviewed by: bb This was SVN commit r21243.
This commit is contained in:
parent
01f581e813
commit
a68d38f5d5
4 changed files with 11 additions and 36 deletions
|
|
@ -294,14 +294,10 @@ Formation.prototype.SetMembers = function(ents)
|
|||
{
|
||||
this.members = ents;
|
||||
|
||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
||||
var templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity);
|
||||
|
||||
for (var ent of this.members)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
cmpUnitAI.SetFormationController(this.entity);
|
||||
cmpUnitAI.SetLastFormationTemplate(templateName);
|
||||
|
||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras);
|
||||
if (cmpAuras && cmpAuras.HasFormationAura())
|
||||
|
|
|
|||
|
|
@ -729,15 +729,10 @@ GuiInterface.prototype.GetFormationInfoFromTemplate = function(player, data)
|
|||
|
||||
GuiInterface.prototype.IsFormationSelected = function(player, data)
|
||||
{
|
||||
for (let ent of data.ents)
|
||||
{
|
||||
return data.ents.some(ent => {
|
||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
// GetLastFormationName is named in a strange way as it (also) is
|
||||
// the value of the current formation (see Formation.js LoadFormation)
|
||||
if (cmpUnitAI && cmpUnitAI.GetLastFormationTemplate() == data.formationTemplate)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return cmpUnitAI && cmpUnitAI.GetFormationTemplate() == data.formationTemplate;
|
||||
});
|
||||
};
|
||||
|
||||
GuiInterface.prototype.IsStanceSelected = function(player, data)
|
||||
|
|
|
|||
|
|
@ -3228,8 +3228,6 @@ UnitAI.prototype.Init = function()
|
|||
this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to
|
||||
this.isGarrisoned = false;
|
||||
this.isIdle = false;
|
||||
// For A19, keep no formations as a default to help pathfinding.
|
||||
this.lastFormationTemplate = "special/formations/null";
|
||||
this.finishedOrder = false; // used to find if all formation members finished the order
|
||||
|
||||
this.heldPosition = undefined;
|
||||
|
|
@ -4746,14 +4744,9 @@ UnitAI.prototype.GetFormationController = function()
|
|||
return this.formationController;
|
||||
};
|
||||
|
||||
UnitAI.prototype.SetLastFormationTemplate = function(template)
|
||||
UnitAI.prototype.GetFormationTemplate = function()
|
||||
{
|
||||
this.lastFormationTemplate = template;
|
||||
};
|
||||
|
||||
UnitAI.prototype.GetLastFormationTemplate = function()
|
||||
{
|
||||
return this.lastFormationTemplate;
|
||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetCurrentTemplateName(this.formationController) || "special/formations/null";
|
||||
};
|
||||
|
||||
UnitAI.prototype.MoveIntoFormation = function(cmd)
|
||||
|
|
|
|||
|
|
@ -1429,7 +1429,6 @@ function GetFormationUnitAIs(ents, player, formationTemplate)
|
|||
return [];
|
||||
|
||||
RemoveFromFormation(ents);
|
||||
cmpUnitAI.SetLastFormationTemplate("special/formations/null");
|
||||
|
||||
return [ cmpUnitAI ];
|
||||
}
|
||||
|
|
@ -1449,16 +1448,14 @@ function GetFormationUnitAIs(ents, player, formationTemplate)
|
|||
// 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
|
||||
// for the other cases.
|
||||
var nullFormation = (formationTemplate || cmpUnitAI.GetLastFormationTemplate()) == "special/formations/null";
|
||||
var nullFormation = (formationTemplate || cmpUnitAI.GetFormationTemplate()) == "special/formations/null";
|
||||
if (!nullFormation && cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "special/formations/null"))
|
||||
formedEnts.push(ent);
|
||||
else
|
||||
{
|
||||
if (nullFormation)
|
||||
{
|
||||
RemoveFromFormation([ent]);
|
||||
cmpUnitAI.SetLastFormationTemplate("special/formations/null");
|
||||
}
|
||||
|
||||
nonformedUnitAIs.push(cmpUnitAI);
|
||||
}
|
||||
}
|
||||
|
|
@ -1494,14 +1491,6 @@ function GetFormationUnitAIs(ents, player, formationTemplate)
|
|||
{
|
||||
// We need to give the selected units a new formation controller
|
||||
|
||||
// Remove selected units from their current formation
|
||||
for (var fid in formation.members)
|
||||
{
|
||||
var cmpFormation = Engine.QueryInterface(+fid, IID_Formation);
|
||||
if (cmpFormation)
|
||||
cmpFormation.RemoveMembers(formation.members[fid]);
|
||||
}
|
||||
|
||||
// TODO replace the fixed 60 with something sensible, based on vision range f.e.
|
||||
var formationSeparation = 60;
|
||||
var clusters = ClusterEntities(formation.entities, formationSeparation);
|
||||
|
|
@ -1510,14 +1499,14 @@ function GetFormationUnitAIs(ents, player, formationTemplate)
|
|||
{
|
||||
if (!formationTemplate || !CanMoveEntsIntoFormation(cluster, formationTemplate))
|
||||
{
|
||||
// get the most recently used formation, or default to line closed
|
||||
// Use the last formation template if everyone was using it
|
||||
var lastFormationTemplate = undefined;
|
||||
for (let ent of cluster)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
if (cmpUnitAI)
|
||||
{
|
||||
var template = cmpUnitAI.GetLastFormationTemplate();
|
||||
var template = cmpUnitAI.GetFormationTemplate();
|
||||
if (lastFormationTemplate === undefined)
|
||||
{
|
||||
lastFormationTemplate = template;
|
||||
|
|
@ -1535,6 +1524,8 @@ function GetFormationUnitAIs(ents, player, formationTemplate)
|
|||
formationTemplate = "special/formations/null";
|
||||
}
|
||||
|
||||
RemoveFromFormation(cluster);
|
||||
|
||||
// Create the new controller
|
||||
var formationEnt = Engine.AddEntity(formationTemplate);
|
||||
var cmpFormation = Engine.QueryInterface(formationEnt, IID_Formation);
|
||||
|
|
|
|||
Loading…
Reference in a new issue