forked from 0ad/0ad
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:
parent
57a7bbcb90
commit
8551a799d0
@ -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")
|
||||
{
|
||||
@ -105,14 +123,17 @@ m.Worker.prototype.update = function(baseManager, gameState)
|
||||
}
|
||||
else
|
||||
{
|
||||
var startIndex = gameState.ai.accessibility.getAccessValue(this.ent.position());
|
||||
var endIndex = target.getMetadata(PlayerID, "access");
|
||||
if (!endIndex)
|
||||
endIndex = gameState.ai.accessibility.getAccessValue(target.position());
|
||||
if (startIndex === endIndex)
|
||||
var access = gameState.ai.accessibility.getAccessValue(this.ent.position());
|
||||
var goalAccess = target.getMetadata(PlayerID, "access");
|
||||
if (!goalAccess)
|
||||
{
|
||||
goalAccess = gameState.ai.accessibility.getAccessValue(target.position());
|
||||
target.setMetadata(PlayerID, "access", goalAccess);
|
||||
}
|
||||
if (access === goalAccess)
|
||||
this.ent.repair(target);
|
||||
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")
|
||||
@ -146,12 +167,33 @@ m.Worker.prototype.update = function(baseManager, gameState)
|
||||
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
|
||||
{
|
||||
// we may have drifted towards ennemy territory during the hunt, if yes go home
|
||||
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(this.ent.position());
|
||||
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally
|
||||
this.startHunting(gameState);
|
||||
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
|
||||
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(this.ent.position());
|
||||
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user