Do not allow to override formation animation variants chosen when walking and define remaining combat variants

Fixing oversight from e7ab2c9b3f. Switching to columnar formation,
adding or removing formation members does not reset animation variant
passed by last order.

Also adding remaining combat variants for formationwalk.

Differential Revision: https://code.wildfiregames.com/D2556
This was SVN commit r23359.
This commit is contained in:
Angen 2020-01-10 10:03:15 +00:00
parent 900573e01c
commit d12e5a9df0
2 changed files with 26 additions and 15 deletions

View File

@ -109,6 +109,8 @@ Formation.prototype.Init = function()
}
}
this.lastOrderVariant = undefined;
this.members = []; // entity IDs currently belonging to this formation
this.memberPositions = {};
this.maxRowsUsed = 0;
@ -347,7 +349,7 @@ Formation.prototype.RemoveMembers = function(ents)
return;
// Rearrange the remaining members
this.MoveMembersIntoFormation(true, true);
this.MoveMembersIntoFormation(true, true, this.lastOrderVariant);
};
Formation.prototype.AddMembers = function(ents)
@ -377,7 +379,7 @@ Formation.prototype.AddMembers = function(ents)
}
this.ComputeMotionParameters();
this.MoveMembersIntoFormation(true, true);
this.MoveMembersIntoFormation(true, true, this.lastOrderVariant);
};
/**
@ -470,6 +472,7 @@ Formation.prototype.MoveMembersIntoFormation = function(moveCenter, force, varia
}
}
this.lastOrderVariant = variant;
// Switch between column and box if necessary
var cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
var walkingDistance = cmpUnitAI.ComputeWalkingDistance();
@ -906,12 +909,17 @@ Formation.prototype.ShapeUpdate = function()
{
this.offsets = undefined;
this.columnar = columnar;
this.MoveMembersIntoFormation(false, true);
this.MoveMembersIntoFormation(false, true, this.lastOrderVariant);
// (disable moveCenter so we can't get stuck in a loop of switching
// shape causing center to change causing shape to switch back)
}
};
Formation.prototype.ResetOrderVariant = function()
{
this.lastOrderVariant = undefined;
};
Formation.prototype.OnGlobalOwnershipChanged = function(msg)
{
// When an entity is captured or destroyed, it should no longer be

View File

@ -734,6 +734,8 @@ UnitAI.prototype.UnitFsmSpec = {
},
"Order.Stop": function(msg) {
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
cmpFormation.ResetOrderVariant();
if (!this.IsAttackingAsFormation())
this.CallMemberFunction("Stop", [false]);
this.StopMoving();
@ -968,7 +970,7 @@ UnitAI.prototype.UnitFsmSpec = {
this.StartTimer(0, 1000);
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
cmpFormation.SetRearrange(true);
cmpFormation.MoveMembersIntoFormation(true, true);
cmpFormation.MoveMembersIntoFormation(true, true, "combat");
return false;
},
@ -1016,7 +1018,7 @@ UnitAI.prototype.UnitFsmSpec = {
let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
cmpFormation.SetRearrange(true);
cmpFormation.MoveMembersIntoFormation(true, true);
cmpFormation.MoveMembersIntoFormation(true, true, "combat");
return false;
},
@ -1311,6 +1313,7 @@ UnitAI.prototype.UnitFsmSpec = {
"leave": function() {
this.SetDefaultAnimationVariant();
this.formationAnimationVariant = undefined;
},
"IDLE": "INDIVIDUAL.IDLE",
@ -1815,6 +1818,11 @@ UnitAI.prototype.UnitFsmSpec = {
this.RespondToTargetedEntities([msg.data.attacker]);
},
"leave": function() {
if (!this.formationAnimationVariant)
this.SetDefaultAnimationVariant();
},
"APPROACHING": {
"enter": function() {
if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType))
@ -1823,16 +1831,14 @@ UnitAI.prototype.UnitFsmSpec = {
return true;
}
// Show weapons rather than carried resources.
this.SetAnimationVariant("combat");
if (!this.formationAnimationVariant)
this.SetAnimationVariant("combat");
this.StartTimer(1000, 1000);
return false;
},
"leave": function() {
// Show carried resources when walking.
this.SetDefaultAnimationVariant();
this.StopMoving();
this.StopTimer();
},
@ -1939,7 +1945,7 @@ UnitAI.prototype.UnitFsmSpec = {
prepare = Math.max(prepare, repeatLeft);
}
if (!this.IsFormationMember())
if (!this.formationAnimationVariant)
this.SetAnimationVariant("combat");
this.oldAttackType = this.order.data.attackType;
@ -1965,7 +1971,6 @@ UnitAI.prototype.UnitFsmSpec = {
if (cmpBuildingAI)
cmpBuildingAI.SetUnitAITarget(0);
this.StopTimer();
this.SetDefaultAnimationVariant();
this.ResetAnimation();
},
@ -2080,8 +2085,8 @@ UnitAI.prototype.UnitFsmSpec = {
return true;
}
// Show weapons rather than carried resources.
this.SetAnimationVariant("combat");
if (!this.formationAnimationVariant)
this.SetAnimationVariant("combat");
var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI);
if (cmpUnitAI && cmpUnitAI.IsFleeing())
@ -2096,8 +2101,6 @@ UnitAI.prototype.UnitFsmSpec = {
"leave": function() {
this.ResetSpeedMultiplier();
// Show carried resources when walking.
this.SetDefaultAnimationVariant();
this.StopMoving();
this.StopTimer();
},