mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 21:34:08 -07:00
fix incoherent UnitAI state when changing ownership of a cheering or garrisoned unit
This was SVN commit r16908.
This commit is contained in:
parent
591771a0be
commit
b3f7b8633a
1 changed files with 13 additions and 7 deletions
|
|
@ -3287,20 +3287,26 @@ UnitAI.prototype.OnOwnershipChanged = function(msg)
|
|||
{
|
||||
this.SetupRangeQueries();
|
||||
|
||||
// If the unit isn't being created or dying, reset stance and clear orders (if not garrisoned).
|
||||
// If the unit isn't being created or dying, reset stance and clear orders
|
||||
if (msg.to != -1 && msg.from != -1)
|
||||
{
|
||||
// Switch to a virgin state to let states execute their leave handlers.
|
||||
var index = this.GetCurrentState().indexOf(".");
|
||||
if (index != -1)
|
||||
this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index));
|
||||
// except if garrisoned or cheering, in which case we only clear the order queue
|
||||
if (this.isGarrisoned || (this.orderQueue[0] && this.orderQueue[0].type == "Cheering"))
|
||||
this.orderQueue.length = Math.min(this.orderQueue.length, 1);
|
||||
else
|
||||
{
|
||||
let index = this.GetCurrentState().indexOf(".");
|
||||
if (index != -1)
|
||||
this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index));
|
||||
this.Stop(false);
|
||||
}
|
||||
|
||||
this.SetStance(this.template.DefaultStance);
|
||||
if(!this.isGarrisoned)
|
||||
this.Stop(false);
|
||||
if (this.IsTurret())
|
||||
this.SetTurretStance();
|
||||
}
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnDestroy = function()
|
||||
{
|
||||
// Switch to an empty state to let states execute their leave handlers.
|
||||
|
|
|
|||
Loading…
Reference in a new issue