From a68d38f5d55a9dd02c41f16caa4baa88a6f24aa7 Mon Sep 17 00:00:00 2001 From: temple Date: Sat, 17 Feb 2018 17:54:24 +0000 Subject: [PATCH] Remove lastFormationTemplate from UnitAI Differential Revision: https://code.wildfiregames.com/D1255 Reviewed by: bb This was SVN commit r21243. --- .../public/simulation/components/Formation.js | 4 ---- .../simulation/components/GuiInterface.js | 11 +++------- .../public/simulation/components/UnitAI.js | 11 ++-------- .../public/simulation/helpers/Commands.js | 21 ++++++------------- 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Formation.js b/binaries/data/mods/public/simulation/components/Formation.js index c6b2524936..b2b7679e89 100644 --- a/binaries/data/mods/public/simulation/components/Formation.js +++ b/binaries/data/mods/public/simulation/components/Formation.js @@ -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()) diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 3bf8e3009f..5f664971a3 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -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) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 88925799fd..c6b90ed510 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -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) diff --git a/binaries/data/mods/public/simulation/helpers/Commands.js b/binaries/data/mods/public/simulation/helpers/Commands.js index cfc5300614..15ad214617 100644 --- a/binaries/data/mods/public/simulation/helpers/Commands.js +++ b/binaries/data/mods/public/simulation/helpers/Commands.js @@ -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);