forked from 0ad/0ad
Use a filter to pick a new attack target in the same turn, while still avoiding an infinite loop
This was SVN commit r14638.
This commit is contained in:
parent
a58acb28f0
commit
1fedf11e9e
@ -155,7 +155,7 @@ Formation.prototype.GetMembers = function()
|
||||
return this.members;
|
||||
};
|
||||
|
||||
Formation.prototype.GetClosestMember = function(ent)
|
||||
Formation.prototype.GetClosestMember = function(ent, filter)
|
||||
{
|
||||
var cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
|
||||
if (!cmpEntPosition)
|
||||
@ -166,6 +166,9 @@ Formation.prototype.GetClosestMember = function(ent)
|
||||
var closestDistance = Infinity;
|
||||
for each (var member in this.members)
|
||||
{
|
||||
if (filter && !filter(ent))
|
||||
continue;
|
||||
|
||||
var cmpPosition = Engine.QueryInterface(member, IID_Position);
|
||||
var pos = cmpPosition.GetPosition2D();
|
||||
var dx = entPosition.x - pos.x;
|
||||
|
@ -1735,8 +1735,13 @@ var UnitFsmSpec = {
|
||||
}
|
||||
|
||||
// add prefix + no capital first letter for attackType
|
||||
var attackName = "attack_" + this.order.data.attackType.toLowerCase();
|
||||
this.SelectAnimation(attackName, false, 1.0, "attack");
|
||||
var animationName = "attack_" + this.order.data.attackType.toLowerCase();
|
||||
if (this.IsFormationMember())
|
||||
{
|
||||
var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
|
||||
animationName = cmpFormation.GetFormationAnimation(this.entity, animationName);
|
||||
}
|
||||
this.SelectAnimation(animationName, false, 1.0, "attack");
|
||||
this.SetAnimationSync(prepare, this.attackTimers.repeat);
|
||||
this.StartTimer(prepare, this.attackTimers.repeat);
|
||||
// TODO: we should probably only bother syncing projectile attacks, not melee
|
||||
@ -1757,8 +1762,12 @@ var UnitFsmSpec = {
|
||||
// if the target is a formation, save the attacking formation, and pick a member
|
||||
if (cmpFormation)
|
||||
{
|
||||
var thisObject = this;
|
||||
var filter = function(t) {
|
||||
return thisObject.TargetIsAlive(t) && thisObject.CanAttack(t, thisObject.order.data.forceResponse || null);
|
||||
};
|
||||
this.order.data.formationTarget = target;
|
||||
target = cmpFormation.GetClosestMember(this.entity);
|
||||
target = cmpFormation.GetClosestMember(this.entity, filter);
|
||||
this.order.data.target = target;
|
||||
}
|
||||
// Check the target is still alive and attackable
|
||||
@ -1814,7 +1823,7 @@ var UnitFsmSpec = {
|
||||
if (cmpTargetFormation)
|
||||
{
|
||||
this.order.data.target = this.order.data.formationTarget;
|
||||
//this.TimerHandler(msg.data, msg.lateness);
|
||||
this.TimerHandler(msg.data, msg.lateness);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user