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.
This commit is contained in:
Angen 2020-01-08 21:37:19 +00:00
parent 46ea62f717
commit ed54ad3486
3 changed files with 13 additions and 17 deletions

View file

@ -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);
};

View file

@ -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 });
}

View file

@ -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"
});