mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
PetraBot: Never play when the region analysis fails
If the region analysis at the start of the game fails, the bot can't actually play and the managers aren't initialised. And to prevent errors from the update functions, the OnUpdate at the root had an early return if the entity count was 0. However, in some edge cases the region analysis can fail even if the AI has entities. This patch fixes this potential error by storing the result of the region analysis directly and checking that instead.
This commit is contained in:
parent
a25750f62d
commit
7b1d4426aa
2 changed files with 7 additions and 5 deletions
|
|
@ -84,8 +84,8 @@ PetraBot.prototype.CustomInit = function(gameState)
|
|||
|
||||
this.HQ.init(gameState, this.queues);
|
||||
|
||||
// Analyze our starting position and set a strategy
|
||||
this.HQ.gameAnalysis(gameState);
|
||||
// Try to analyze our starting position and set a strategy.
|
||||
this.canPlay = this.HQ.gameAnalysis(gameState);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -112,10 +112,10 @@ PetraBot.prototype.OnUpdate = function(sharedScript)
|
|||
|
||||
this.playedTurn++;
|
||||
|
||||
if (this.gameState.getOwnEntities().length === 0)
|
||||
if (!this.canPlay)
|
||||
{
|
||||
Engine.ProfileStop();
|
||||
return; // With no entities to control the AI cannot do anything
|
||||
return;
|
||||
}
|
||||
|
||||
this.HQ.update(this.gameState, this.queues, this.savedEvents);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Headquarters.prototype.gameAnalysis = function(gameState)
|
|||
{
|
||||
// Analysis of the terrain and the different access regions
|
||||
if (!this.regionAnalysis(gameState))
|
||||
return;
|
||||
return false;
|
||||
|
||||
this.attackManager.init(gameState);
|
||||
this.buildManager.init(gameState);
|
||||
|
|
@ -57,6 +57,8 @@ Headquarters.prototype.gameAnalysis = function(gameState)
|
|||
// configure our first base strategy
|
||||
if (this.hasPotentialBase())
|
||||
this.configFirstBase(gameState);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue