mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Fix tests + improve behaviour of attacking when not in formation
This was SVN commit r14634.
This commit is contained in:
parent
04aba0e41a
commit
32844e9a16
2 changed files with 12 additions and 2 deletions
|
|
@ -799,12 +799,12 @@ var UnitFsmSpec = {
|
|||
if (cmpTargetUnitAI && cmpTargetUnitAI.IsFormationMember())
|
||||
target = cmpTargetUnitAI.GetFormationController();
|
||||
|
||||
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
||||
// Check if we are already in range, otherwise walk there
|
||||
if (!this.CheckTargetAttackRange(target, target))
|
||||
{
|
||||
if (this.TargetIsAlive(target) && this.CheckTargetVisible(target))
|
||||
{
|
||||
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
||||
var range = cmpAttack.GetRange(target);
|
||||
this.PushOrderFront("WalkToTargetRange", { "target": target, "min": range.min, "max": range.max });
|
||||
return;
|
||||
|
|
@ -813,7 +813,10 @@ var UnitFsmSpec = {
|
|||
return;
|
||||
}
|
||||
this.CallMemberFunction("Attack", [target, false]);
|
||||
this.SetNextState("ATTACKING");
|
||||
if (cmpAttack.CanAttackAsFormation())
|
||||
this.SetNextState("ATTACKING");
|
||||
else
|
||||
this.SetNextState("MEMBER");
|
||||
},
|
||||
|
||||
"Order.Garrison": function(msg) {
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ function TestFormationExiting(mode)
|
|||
AddMock(unit, IID_Position, {
|
||||
GetPosition: function() { return { "x": 0, "y": 0,"z": 0 }; },
|
||||
GetPosition2D: function() { return { "x": 0, "y": 0 }; },
|
||||
GetRotation: function() { return { "y": 0 }; },
|
||||
IsInWorld: function() { return true; },
|
||||
});
|
||||
|
||||
|
|
@ -124,6 +125,7 @@ function TestFormationExiting(mode)
|
|||
JumpTo: function(x, z) { this.x = x; this.z = z; },
|
||||
GetPosition: function() { return { "x": this.x, "z": this.z }; },
|
||||
GetPosition2D: function() { return { "x": this.x, "y": this.z }; },
|
||||
GetRotation: function() { return { "y": 0 }; },
|
||||
IsInWorld: function() { return true; },
|
||||
});
|
||||
|
||||
|
|
@ -217,6 +219,8 @@ function TestMoveIntoFormationWhileAttacking()
|
|||
|
||||
AddMock(unit + i, IID_Position, {
|
||||
GetPosition: function() { return { "x": 0, "z": 0 }; },
|
||||
GetPosition2D: function() { return { "x": 0, "y": 0 }; },
|
||||
GetRotation: function() { return { "y": 0 }; },
|
||||
IsInWorld: function() { return true; },
|
||||
});
|
||||
|
||||
|
|
@ -259,6 +263,8 @@ function TestMoveIntoFormationWhileAttacking()
|
|||
AddMock(controller, IID_Position, {
|
||||
JumpTo: function(x, z) { this.x = x; this.z = z; },
|
||||
GetPosition: function() { return { "x": this.x, "z": this.z }; },
|
||||
GetPosition2D: function() { return { "x": this.x, "y": this.z }; },
|
||||
GetRotation: function() { return { "y": 0 }; },
|
||||
IsInWorld: function() { return true; },
|
||||
});
|
||||
|
||||
|
|
@ -271,6 +277,7 @@ function TestMoveIntoFormationWhileAttacking()
|
|||
|
||||
AddMock(controller, IID_Attack, {
|
||||
GetRange: function() { return {"max":10, "min": 0}; },
|
||||
CanAttackAsFormation: function() { return false },
|
||||
});
|
||||
|
||||
controllerAI.OnCreate();
|
||||
|
|
|
|||
Loading…
Reference in a new issue