1
0
forked from mirrors/0ad

check that the target can be built or repaired inside the canRepair function

This was SVN commit r17685.
This commit is contained in:
mimo
2016-01-21 20:49:57 +00:00
parent edb16dafbb
commit fdf7dabe18
@@ -1395,14 +1395,14 @@ UnitAI.prototype.UnitFsmSpec = {
{
if (this.CanHeal(this.isGuardOf))
this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false });
else if (this.CanRepair(this.isGuardOf) && cmpHealth.IsRepairable())
else if (this.CanRepair(this.isGuardOf))
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false });
return;
}
// if the attacker is a building and we can repair the guarded, repair it rather than attacking
var cmpBuildingAI = Engine.QueryInterface(msg.data.attacker, IID_BuildingAI);
if (cmpBuildingAI && this.CanRepair(this.isGuardOf) && cmpHealth.IsRepairable())
if (cmpBuildingAI && this.CanRepair(this.isGuardOf))
{
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false });
return;
@@ -1642,7 +1642,7 @@ UnitAI.prototype.UnitFsmSpec = {
{
if (this.CanHeal(this.isGuardOf))
this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false });
else if (this.CanRepair(this.isGuardOf) && cmpHealth.IsRepairable())
else if (this.CanRepair(this.isGuardOf))
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false });
}
}
@@ -5783,6 +5783,12 @@ UnitAI.prototype.CanRepair = function(target)
if (!cmpBuilder)
return false;
// Verify that the target can be either built or repaired
var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);
var cmpRepairable = Engine.QueryInterface(target, IID_Repairable);
if (!cmpFoundation && !cmpRepairable)
return false;
// Verify that the target is owned by an ally of this entity's player
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
return cmpOwnership && IsOwnedByAllyOfPlayer(cmpOwnership.GetOwner(), target);