From ed54ad34865bd061520d06036283cfd6b17129e4 Mon Sep 17 00:00:00 2001 From: Angen Date: Wed, 8 Jan 2020 21:37:19 +0000 Subject: [PATCH] Do not face point after movement for formation walk After formation member ends walking, he tries to face target point. However that eliminates rotation set by SetInPosition from formation component. Partly fixed in 9d0b4db973 with setting correct rotation in idle state, but one could still notice that there is glitch when unit does quick turn to target point and then back. However that solution would be still required if logic in SetInPosition would not be changed to always set correct rotation. Another alternative would be to unset unit at position with every walking order but that would have the same effect and this is just more performance friendly to not splice member from position every time. Notice that information from inPosition is currently not used, so that change in it is not braking anything. This was SVN commit r23346. --- .../public/simulation/components/Formation.js | 11 +++++------ .../mods/public/simulation/components/UnitAI.js | 15 ++++----------- .../simulation/components/tests/test_UnitAI.js | 4 ++++ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Formation.js b/binaries/data/mods/public/simulation/components/Formation.js index 3a4177fd0d..32e42c103b 100644 --- a/binaries/data/mods/public/simulation/components/Formation.js +++ b/binaries/data/mods/public/simulation/components/Formation.js @@ -245,15 +245,14 @@ Formation.prototype.GetFormationAnimation = function(entity) */ Formation.prototype.SetInPosition = function(ent) { - if (this.inPosition.indexOf(ent) != -1) - return; - - // Rotate the entity to the right angle - var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); - var cmpEntPosition = Engine.QueryInterface(ent, IID_Position); + // Rotate the entity to the right angle. + let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); + let cmpEntPosition = Engine.QueryInterface(ent, IID_Position); if (cmpEntPosition && cmpEntPosition.IsInWorld() && cmpPosition && cmpPosition.IsInWorld()) cmpEntPosition.TurnTo(cmpPosition.GetRotation().y); + if (this.inPosition.indexOf(ent) != -1) + return; this.inPosition.push(ent); }; diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index d999945dce..fa3fb1f2e2 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -1314,6 +1314,8 @@ UnitAI.prototype.UnitFsmSpec = { "enter": function() { this.formationOffset = { "x": this.order.data.x, "z": this.order.data.z }; let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); + // Prevent unit to turn when stopmoving is called. + cmpUnitMotion.SetFacePointAfterMove(false); cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); if (this.order.data.offsetsChanged) { @@ -1326,6 +1328,7 @@ UnitAI.prototype.UnitFsmSpec = { "leave": function() { this.StopMoving(); + this.SetFacePointAfterMove(true); }, // Occurs when the unit has reached its destination and the controller @@ -1526,23 +1529,13 @@ UnitAI.prototype.UnitFsmSpec = { this.PushOrder("FormationWalk", { "target": this.formationController, "x": this.formationOffset.x, - "z": this.formationOffset.z, + "z": this.formationOffset.z }); return; } if (!this.isIdle) { - if (this.formationController) - { - let cmpFormationPosition = Engine.QueryInterface(this.formationController, IID_Position); - if (cmpFormationPosition && cmpFormationPosition.IsInWorld()) - { - let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); - if (cmpPosition && cmpPosition.IsInWorld()) - cmpPosition.TurnTo(cmpFormationPosition.GetRotation().y); - } - } this.isIdle = true; Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); } diff --git a/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js b/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js index 75a63928a6..2338f52a16 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js +++ b/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js @@ -91,6 +91,7 @@ function TestFormationExiting(mode) "MoveToFormationOffset": (target, x, z) => {}, "MoveToTargetRange": (target, min, max) => true, "StopMoving": () => {}, + "SetFacePointAfterMove": () => {}, "GetPassabilityClassName": () => "default" }); @@ -144,6 +145,7 @@ function TestFormationExiting(mode) "StopMoving": () => {}, "SetSpeedMultiplier": () => {}, "MoveToPointRange": () => true, + "SetFacePointAfterMove": () => {}, "GetPassabilityClassName": () => "default" }); @@ -248,6 +250,7 @@ function TestMoveIntoFormationWhileAttacking() "MoveToFormationOffset": (target, x, z) => {}, "MoveToTargetRange": (target, min, max) => true, "StopMoving": () => {}, + "SetFacePointAfterMove": () => {}, "GetPassabilityClassName": () => "default" }); @@ -293,6 +296,7 @@ function TestMoveIntoFormationWhileAttacking() "SetSpeedMultiplier": (speed) => {}, "MoveToPointRange": (x, z, minRange, maxRange) => {}, "StopMoving": () => {}, + "SetFacePointAfterMove": () => {}, "GetPassabilityClassName": () => "default" });