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:
Vantha 2025-10-03 10:13:46 +02:00 committed by Phosit
parent a25750f62d
commit 7b1d4426aa
2 changed files with 7 additions and 5 deletions

View file

@ -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);

View file

@ -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;
};
/**