Skip to content

Commit

Permalink
Game crash bugfix McvManagerBotModule.cs
Browse files Browse the repository at this point in the history
Bugfix in McvManagerBotModule.cs. Game can crash at start if you play against lot of AI

Exception of type `System.NullReferenceException`: Object reference not set to an instance of an object.
  • Loading branch information
ottelo9 committed Oct 27, 2024
1 parent 1b54f5d commit fffc252
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public CPos GetBaseCenter(bool random = false)
var randomBotCYard = constructionYards.Actors.
RandomOrDefault(world.LocalRandom);

//important! Otherwise game can crash at the beginning of a skirmish vs lot of AI

Check failure on line 61 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Check failure on line 61 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

if (randomBotCYard == null)
return CPos.Zero;

var newBaseCenterLocation = world.Map.FindTilesInAnnulus(randomBotCYard.Location,
Info.MaxBaseRadius, world.Map.Grid.MaximumTileSearchRange)
.Where(a => resourceLayer.GetResource(a).Type != null)
Expand All @@ -76,7 +80,7 @@ public CPos GetBaseCenter(bool random = false)
IBotRequestUnitProduction[] requestUnitProduction;
IResourceLayer resourceLayer;
CPos initialBaseCenter;
int scanInterval;
int scanInterval=20;

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Check failure on line 83 in OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

bool firstTick = true;

public McvManagerBotModule(Actor self, McvManagerBotModuleInfo info)
Expand Down Expand Up @@ -116,8 +120,7 @@ void IBotTick.BotTick(IBot bot)
DeployMcvs(bot, false);
firstTick = false;
}

if (--scanInterval <= 0)
else if (--scanInterval <= 0)
{
scanInterval = Info.ScanForNewMcvInterval;
DeployMcvs(bot, true);
Expand Down

0 comments on commit fffc252

Please sign in to comment.