1
0
forked from 0ad/0ad

Reset speed when stopping.

And use an explicit function for running.

Differential revision: https://code.wildfiregames.com/D4957
Comments by: @Stan
This was SVN commit r27706.
This commit is contained in:
Freagarach 2023-06-15 06:56:41 +00:00
parent 0e57957a09
commit 291f17b3c5
2 changed files with 18 additions and 18 deletions

View File

@ -1928,7 +1928,6 @@ UnitAI.prototype.UnitFsmSpec = {
"leave": function(msg) { "leave": function(msg) {
this.StopMoving(); this.StopMoving();
this.ResetSpeedMultiplier();
this.StopTimer(); this.StopTimer();
this.SetDefaultAnimationVariant(); this.SetDefaultAnimationVariant();
}, },
@ -1999,7 +1998,7 @@ UnitAI.prototype.UnitFsmSpec = {
this.PlaySound("panic"); this.PlaySound("panic");
this.SetSpeedMultiplier(this.GetRunMultiplier()); this.Run();
return false; return false;
}, },
@ -2024,7 +2023,6 @@ UnitAI.prototype.UnitFsmSpec = {
}, },
"leave": function() { "leave": function() {
this.ResetSpeedMultiplier();
this.StopMoving(); this.StopMoving();
}, },
@ -2302,16 +2300,14 @@ UnitAI.prototype.UnitFsmSpec = {
if (!this.formationAnimationVariant) if (!this.formationAnimationVariant)
this.SetAnimationVariant("combat"); this.SetAnimationVariant("combat");
var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); if (Engine.QueryInterface(this.order.data.target, IID_UnitAI)?.IsFleeing())
if (cmpUnitAI && cmpUnitAI.IsFleeing()) this.Run();
this.SetSpeedMultiplier(this.GetRunMultiplier());
this.StartTimer(1000, 1000); this.StartTimer(1000, 1000);
return false; return false;
}, },
"leave": function() { "leave": function() {
this.ResetSpeedMultiplier();
this.StopMoving(); this.StopMoving();
this.StopTimer(); this.StopTimer();
}, },
@ -4647,9 +4643,12 @@ UnitAI.prototype.SetAnimationSync = function(actiontime, repeattime)
UnitAI.prototype.StopMoving = function() UnitAI.prototype.StopMoving = function()
{ {
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); const cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
if (cmpUnitMotion) if (!cmpUnitMotion)
cmpUnitMotion.StopMoving(); return;
cmpUnitMotion.StopMoving();
cmpUnitMotion.SetSpeedMultiplier(1);
}; };
/** /**
@ -6139,20 +6138,19 @@ UnitAI.prototype.GetStanceName = function()
}; };
/* /*
* Make the unit walk at its normal pace. * Make the unit run.
*/ */
UnitAI.prototype.ResetSpeedMultiplier = function() UnitAI.prototype.Run = function()
{ {
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); this.SetSpeedMultiplier(this.GetRunMultiplier());
if (cmpUnitMotion)
cmpUnitMotion.SetSpeedMultiplier(1);
}; };
/**
* @param {number} speed - The multiplier to set the speed to.
*/
UnitAI.prototype.SetSpeedMultiplier = function(speed) UnitAI.prototype.SetSpeedMultiplier = function(speed)
{ {
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); Engine.QueryInterface(this.entity, IID_UnitMotion)?.SetSpeedMultiplier(speed);
if (cmpUnitMotion)
cmpUnitMotion.SetSpeedMultiplier(speed);
}; };
/** /**

View File

@ -171,6 +171,7 @@ function TestFormationExiting(mode)
AddMock(unit, IID_UnitMotion, { AddMock(unit, IID_UnitMotion, {
"GetWalkSpeed": () => 1, "GetWalkSpeed": () => 1,
"GetAcceleration": () => 1, "GetAcceleration": () => 1,
"SetSpeedMultiplier": () => {},
"MoveToFormationOffset": (target, x, z) => {}, "MoveToFormationOffset": (target, x, z) => {},
"MoveToTargetRange": (target, min, max) => true, "MoveToTargetRange": (target, min, max) => true,
"SetMemberOfFormation": () => {}, "SetMemberOfFormation": () => {},
@ -359,6 +360,7 @@ function TestMoveIntoFormationWhileAttacking()
AddMock(unit + i, IID_UnitMotion, { AddMock(unit + i, IID_UnitMotion, {
"GetWalkSpeed": () => 1, "GetWalkSpeed": () => 1,
"GetAcceleration": () => 1, "GetAcceleration": () => 1,
"SetSpeedMultiplier": () => {},
"MoveToFormationOffset": (target, x, z) => {}, "MoveToFormationOffset": (target, x, z) => {},
"MoveToTargetRange": (target, min, max) => true, "MoveToTargetRange": (target, min, max) => true,
"SetMemberOfFormation": () => {}, "SetMemberOfFormation": () => {},