diff --git a/binaries/data/mods/public/simulation/components/Formation.js b/binaries/data/mods/public/simulation/components/Formation.js index 32e42c103b..758d5e47c0 100644 --- a/binaries/data/mods/public/simulation/components/Formation.js +++ b/binaries/data/mods/public/simulation/components/Formation.js @@ -200,13 +200,13 @@ Formation.prototype.GetPrimaryMember = function() * Get the formation animation for a certain member of this formation * @param entity The entity ID to get the animation for * @return The name of the transformed animation as defined in the template - * E.g. "testudo_row1" + * E.g. "testudo_row1" or undefined if does not exist */ Formation.prototype.GetFormationAnimation = function(entity) { var animationGroup = this.animations; if (!animationGroup.length || this.columnar || !this.memberPositions[entity]) - return "formation"; + return undefined; var row = this.memberPositions[entity].row; var column = this.memberPositions[entity].column; for (var i = 0; i < animationGroup.length; ++i) @@ -237,7 +237,7 @@ Formation.prototype.GetFormationAnimation = function(entity) return animationGroup[i].animation; } - return "formation"; + return undefined; }; /** @@ -427,12 +427,13 @@ Formation.prototype.Disband = function() /** * Set all members to form up into the formation shape. - * If moveCenter is true, the formation center will be reinitialised + * @param {boolean} moveCenter - The formation center will be reinitialised * to the center of the units. - * If force is true, all individual orders of the formation units are replaced, + * @param {boolean} force - All individual orders of the formation units are replaced, * otherwise the order to walk into formation is just pushed to the front. + * @param {string | undefined} variant - Variant to be passed as order parameter. */ -Formation.prototype.MoveMembersIntoFormation = function(moveCenter, force) +Formation.prototype.MoveMembersIntoFormation = function(moveCenter, force, variant) { if (!this.members.length) return; @@ -510,7 +511,8 @@ Formation.prototype.MoveMembersIntoFormation = function(moveCenter, force) "target": this.entity, "x": offset.x, "z": offset.y, - "offsetsChanged": offsetsChanged + "offsetsChanged": offsetsChanged, + "variant": variant }; cmpUnitAI.AddOrder("FormationWalk", data, !force); xMax = Math.max(xMax, offset.x); diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index fa3fb1f2e2..2804b20fa2 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -1142,7 +1142,7 @@ UnitAI.prototype.UnitFsmSpec = { } let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true); + cmpFormation.MoveMembersIntoFormation(true, true, "combat"); return false; }, @@ -1181,7 +1181,7 @@ UnitAI.prototype.UnitFsmSpec = { var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); // TODO fix the rearranging while attacking as formation cmpFormation.SetRearrange(!this.IsAttackingAsFormation()); - cmpFormation.MoveMembersIntoFormation(false, false); + cmpFormation.MoveMembersIntoFormation(false, false, "combat"); this.StartTimer(200, 200); return false; }, @@ -1268,6 +1268,7 @@ UnitAI.prototype.UnitFsmSpec = { } // No orders left, we're an individual now + this.formationAnimationVariant = undefined; this.SetNextState("INDIVIDUAL.IDLE"); }, @@ -1298,7 +1299,13 @@ UnitAI.prototype.UnitFsmSpec = { let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); if (cmpFormation) - this.SetAnimationVariant(cmpFormation.GetFormationAnimation(this.entity)); + { + this.formationAnimationVariant = cmpFormation.GetFormationAnimation(this.entity); + if (this.formationAnimationVariant) + this.SetAnimationVariant(this.formationAnimationVariant); + else + this.SetDefaultAnimationVariant(); + } return false; }, @@ -1321,8 +1328,14 @@ UnitAI.prototype.UnitFsmSpec = { { let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); if (cmpFormation) - this.SetAnimationVariant(cmpFormation.GetFormationAnimation(this.entity)); + this.formationAnimationVariant = cmpFormation.GetFormationAnimation(this.entity); } + if (this.formationAnimationVariant) + this.SetAnimationVariant(this.formationAnimationVariant); + else if (this.order.data.variant) + this.SetAnimationVariant(this.order.data.variant); + else + this.SetDefaultAnimationVariant(); return false; }, @@ -1368,8 +1381,6 @@ UnitAI.prototype.UnitFsmSpec = { this.FinishOrder(); return true; } - if (cmpFormation && this.order.data.offsetsChanged) - this.SetAnimationVariant(cmpFormation.GetFormationAnimation(this.entity)); return false; }, @@ -3048,6 +3059,10 @@ UnitAI.prototype.UnitFsmSpec = { "leave": function() { this.StopTimer(); this.ResetAnimation(); + if (this.formationAnimationVariant) + this.SetAnimationVariant(this.formationAnimationVariant) + else + this.SetDefaultAnimationVariant(); var cmpResistance = Engine.QueryInterface(this.entity, IID_Resistance); cmpResistance.SetInvulnerability(false); }, @@ -3295,6 +3310,8 @@ UnitAI.prototype.Init = function() this.lastAttacked = undefined; this.lastHealed = undefined; + this.formationAnimationVariant = undefined; + this.SetStance(this.template.DefaultStance); }; @@ -4302,30 +4319,27 @@ UnitAI.prototype.SetAnimationVariant = function(type) }; /* - * Reset the animation variant to default behavior + * Reset the animation variant to default behavior. * Default behavior is to pick a resource-carrying variant if resources are being carried. * Otherwise pick nothing in particular. */ UnitAI.prototype.SetDefaultAnimationVariant = function() { let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - if (!cmpResourceGatherer) + if (cmpResourceGatherer) { - this.SetAnimationVariant(""); - return; - } + let type = cmpResourceGatherer.GetLastCarriedType(); + if (type) + { + let typename = "carry_" + type.generic; - let type = cmpResourceGatherer.GetLastCarriedType(); - if (type) - { - let typename = "carry_" + type.generic; + // Special case for meat. + if (type.specific == "meat") + typename = "carry_" + type.specific; - // Special case for meat - if (type.specific == "meat") - typename = "carry_" + type.specific; - - this.SetAnimationVariant(typename); - return; + this.SetAnimationVariant(typename); + return; + } } this.SetAnimationVariant("");