Petra: prevent gatherers to stay blocked when UnitAI make them return resource in an inaccessible dropsite, see #2563

This was SVN commit r15325.
This commit is contained in:
mimo 2014-06-10 13:45:23 +00:00
parent 57a7bbcb90
commit 8551a799d0

View File

@ -87,6 +87,24 @@ m.Worker.prototype.update = function(baseManager, gameState)
} }
} }
} }
else if (this.ent.unitAIState() === "INDIVIDUAL.RETURNRESOURCE.APPROACHING"
&& gameState.ai.playedTurn % 10 === 0)
{
// Check from time to time that UnitAI does not send us to an inaccessible dropsite
var dropsite = gameState.getEntityById(this.ent.unitAIOrderData()[0]["target"]);
if (dropsite && dropsite.position())
{
var access = gameState.ai.accessibility.getAccessValue(this.ent.position());
var goalAccess = dropsite.getMetadata(PlayerID, "access");
if (!goalAccess || dropsite.hasClass("Elephant"))
{
goalAccess = gameState.ai.accessibility.getAccessValue(dropsite.position());
dropsite.setMetadata(PlayerID, "access", goalAccess);
}
if (access !== goalAccess)
this.returnResources(gameState);
}
}
} }
else if (subrole === "builder") else if (subrole === "builder")
{ {
@ -105,14 +123,17 @@ m.Worker.prototype.update = function(baseManager, gameState)
} }
else else
{ {
var startIndex = gameState.ai.accessibility.getAccessValue(this.ent.position()); var access = gameState.ai.accessibility.getAccessValue(this.ent.position());
var endIndex = target.getMetadata(PlayerID, "access"); var goalAccess = target.getMetadata(PlayerID, "access");
if (!endIndex) if (!goalAccess)
endIndex = gameState.ai.accessibility.getAccessValue(target.position()); {
if (startIndex === endIndex) goalAccess = gameState.ai.accessibility.getAccessValue(target.position());
target.setMetadata(PlayerID, "access", goalAccess);
}
if (access === goalAccess)
this.ent.repair(target); this.ent.repair(target);
else else
gameState.ai.HQ.navalManager.requireTransport(gameState, this.ent, startIndex, endIndex, target.position()); gameState.ai.HQ.navalManager.requireTransport(gameState, this.ent, access, goalAccess, target.position());
} }
} }
else if (subrole === "hunter") else if (subrole === "hunter")
@ -146,12 +167,33 @@ m.Worker.prototype.update = function(baseManager, gameState)
this.ent.setMetadata(PlayerID, "lastHuntSearch", gameState.ai.playedTurn); this.ent.setMetadata(PlayerID, "lastHuntSearch", gameState.ai.playedTurn);
} }
} }
else if (this.ent.unitAIState().split(".")[1] === "GATHER" || this.ent.unitAIState().split(".")[1] === "RETURNRESOURCE") else if (gameState.ai.playedTurn % 10 === 0) // Perform some checks from time to time
{
if (this.ent.unitAIState().split(".")[1] === "GATHER"
|| this.ent.unitAIState().split(".")[1] === "RETURNRESOURCE")
{ {
// we may have drifted towards ennemy territory during the hunt, if yes go home // we may have drifted towards ennemy territory during the hunt, if yes go home
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(this.ent.position()); var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(this.ent.position());
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally
this.startHunting(gameState); this.startHunting(gameState);
else if (this.ent.unitAIState() === "INDIVIDUAL.RETURNRESOURCE.APPROACHING")
{
// Check that UnitAI does not send us to an inaccessible dropsite
var dropsite = gameState.getEntityById(this.ent.unitAIOrderData()[0]["target"]);
if (dropsite && dropsite.position())
{
var access = gameState.ai.accessibility.getAccessValue(this.ent.position());
var goalAccess = dropsite.getMetadata(PlayerID, "access");
if (!goalAccess || dropsite.hasClass("Elephant"))
{
goalAccess = gameState.ai.accessibility.getAccessValue(dropsite.position());
dropsite.setMetadata(PlayerID, "access", goalAccess);
}
if (access !== goalAccess)
this.returnResources(gameState);
}
}
}
} }
} }
else if (subrole === "fisher") else if (subrole === "fisher")