LeaveFoundation should put formation members into a discrete state to avoid prematurely disbanding.

This was SVN commit r12636.
This commit is contained in:
Deiz 2012-09-04 23:27:06 +00:00
parent b3d85df2fd
commit ef2c9e338d
2 changed files with 36 additions and 2 deletions

View File

@ -54,6 +54,16 @@ Formation.prototype.SetInPosition = function(ent)
this.Disband();
};
/**
* Called by formation members upon entering non-walking states.
*/
Formation.prototype.UnsetInPosition = function(ent)
{
var ind = this.inPosition.indexOf(ent);
if (ind != -1)
this.inPosition.splice(ind, 1);
}
/**
* Set whether we should rearrange formation members if
* units are removed from the formation.
@ -125,8 +135,13 @@ Formation.prototype.FindInPosition = function()
{
var cmpUnitMotion = Engine.QueryInterface(this.members[i], IID_UnitMotion);
if (!cmpUnitMotion.IsMoving())
{
// Verify that members are stopped in FORMATIONMEMBER.WALKING
var cmpUnitAI = Engine.QueryInterface(this.members[i], IID_UnitAI);
if (cmpUnitAI.IsWalking())
this.SetInPosition(this.members[i]);
}
}
}
/**

View File

@ -654,7 +654,7 @@ var UnitFsmSpec = {
if (ok)
{
// We've started walking to the given point
this.SetNextState("WALKING");
this.SetNextState("WALKINGTOPOINT");
}
else
{
@ -683,6 +683,19 @@ var UnitFsmSpec = {
cmpFormation.SetInPosition(this.entity);
},
},
// Special case used by Order.LeaveFoundation
"WALKINGTOPOINT": {
"enter": function() {
var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
cmpFormation.UnsetInPosition(this.entity);
this.SelectAnimation("move");
},
"MoveCompleted": function() {
this.FinishOrder();
},
},
},
@ -1876,6 +1889,12 @@ UnitAI.prototype.IsGarrisoned = function()
return this.isGarrisoned;
};
UnitAI.prototype.IsWalking = function()
{
var state = this.GetCurrentState().split(".").pop();
return (state == "WALKING");
};
UnitAI.prototype.CanAttackGaia = function()
{
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);