1
0
forked from 0ad/0ad

Fix missing animation variant reset after committing resources in UnitAI.

Causing units to not show the gathering animation when close to a
dropsite.
We might want to move this stuff to their respective components.

Differential revision: https://code.wildfiregames.com/D4937
Comments by: @Stan
Fixes #6566

This was SVN commit r27550.
This commit is contained in:
Freagarach 2023-02-17 13:43:06 +00:00
parent 189fc18251
commit d28145a61a

View File

@ -2419,6 +2419,11 @@ UnitAI.prototype.UnitFsmSpec = {
"APPROACHING": { "APPROACHING": {
"enter": function() { "enter": function() {
this.gatheringTarget = this.order.data.target; // temporary, deleted in "leave". this.gatheringTarget = this.order.data.target; // temporary, deleted in "leave".
if (this.CheckRange(this.order.data, IID_ResourceGatherer))
{
this.SetNextState("GATHERING");
return true;
}
// If we can't move, assume we'll fail any subsequent order // If we can't move, assume we'll fail any subsequent order
// and finish the order entirely to avoid an infinite loop. // and finish the order entirely to avoid an infinite loop.
@ -2449,11 +2454,6 @@ UnitAI.prototype.UnitFsmSpec = {
this.SetNextState("FINDINGNEWTARGET"); this.SetNextState("FINDINGNEWTARGET");
return true; return true;
} }
if (this.CheckRange(this.order.data, IID_ResourceGatherer))
{
this.SetNextState("GATHERING");
return true;
}
this.SetAnimationVariant("approach_" + this.order.data.type.specific); this.SetAnimationVariant("approach_" + this.order.data.type.specific);
return false; return false;
}, },
@ -2468,6 +2468,7 @@ UnitAI.prototype.UnitFsmSpec = {
"leave": function() { "leave": function() {
this.StopMoving(); this.StopMoving();
this.SetDefaultAnimationVariant();
if (!this.gatheringTarget) if (!this.gatheringTarget)
return; return;
@ -2494,6 +2495,7 @@ UnitAI.prototype.UnitFsmSpec = {
"leave": function() { "leave": function() {
this.StopMoving(); this.StopMoving();
this.SetDefaultAnimationVariant();
}, },
"MovementUpdate": function(msg) { "MovementUpdate": function(msg) {
@ -2523,13 +2525,13 @@ UnitAI.prototype.UnitFsmSpec = {
this.order.data.force = false; this.order.data.force = false;
this.order.data.autoharvest = true; this.order.data.autoharvest = true;
this.FaceTowardsTarget(this.order.data.target);
if (!cmpResourceGatherer.StartGathering(this.order.data.target, IID_UnitAI)) if (!cmpResourceGatherer.StartGathering(this.order.data.target, IID_UnitAI))
{ {
this.ProcessMessage("TargetInvalidated"); this.ProcessMessage("TargetInvalidated");
return true; return true;
} }
this.FaceTowardsTarget(this.order.data.target);
return false; return false;
}, },
@ -2666,7 +2668,6 @@ UnitAI.prototype.UnitFsmSpec = {
this.SetNextState("DROPPINGRESOURCES"); this.SetNextState("DROPPINGRESOURCES");
return true; return true;
} }
this.SetDefaultAnimationVariant();
this.SetNextState("APPROACHING"); this.SetNextState("APPROACHING");
return true; return true;
}, },
@ -2683,6 +2684,8 @@ UnitAI.prototype.UnitFsmSpec = {
cmpResourceGatherer.IsTargetInRange(this.order.data.target)) cmpResourceGatherer.IsTargetInRange(this.order.data.target))
{ {
cmpResourceGatherer.CommitResources(this.order.data.target); cmpResourceGatherer.CommitResources(this.order.data.target);
// Stop showing the carried resource animation.
this.SetDefaultAnimationVariant();
this.SetNextState("GATHER.APPROACHING"); this.SetNextState("GATHER.APPROACHING");
} }
else else
@ -2803,11 +2806,19 @@ UnitAI.prototype.UnitFsmSpec = {
"RETURNRESOURCE": { "RETURNRESOURCE": {
"APPROACHING": { "APPROACHING": {
"enter": function() { "enter": function() {
if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer))
{
this.SetNextState("DROPPINGRESOURCES");
return true;
}
if (!this.MoveTo(this.order.data, IID_ResourceGatherer)) if (!this.MoveTo(this.order.data, IID_ResourceGatherer))
{ {
this.FinishOrder(); this.FinishOrder();
return true; return true;
} }
this.SetDefaultAnimationVariant();
return false; return false;
}, },