mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
check that the target can be built or repaired inside the canRepair function
This was SVN commit r17685.
This commit is contained in:
parent
edb16dafbb
commit
fdf7dabe18
1 changed files with 9 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue