petra: prevent UnitAI to give a useless capture attack

This was SVN commit r19088.
This commit is contained in:
mimo 2016-12-31 11:22:48 +00:00
parent 11ce52f8c5
commit 86cf621def

View file

@ -52,10 +52,24 @@ m.Worker.prototype.update = function(gameState, ent)
let unitAIStateOrder = unitAIState.split(".")[1];
// If we're fighting or hunting, let's not start gathering
// but for fishers where UnitAI must have made us target a moving whale.
// Also, if we are attacking, do not capture
if (unitAIStateOrder === "COMBAT")
{
if (subrole === "fisher")
this.startFishing(gameState);
else if (unitAIState === "INDIVIDUAL.COMBAT.ATTACKING" && ent.unitAIOrderData().length &&
!ent.getMetadata(PlayerID, "PartOfArmy"))
{
let orderData = ent.unitAIOrderData()[0];
if (orderData && orderData.target && orderData.attackType && orderData.attackType === "Capture")
{
// If we are here, an enemy structure must have targeted one of our workers
// and UnitAI sent it fight back with allowCapture=true
let target = gameState.getEntityById(orderData.target);
if (target && target.owner() > 0 && !gameState.isPlayerAlly(target.owner()))
ent.attack(orderData.target, false);
}
}
return;
}