Fix AI using SharedRandom values

The AI code runs on only one hosts, so by having the AI use SharedRandom values, the host's random gets out of sync with the other players' and crashes the game.
This commit is contained in:
Oliver Brakmann
2015-08-01 15:59:12 +02:00
parent 1e96e7720d
commit c539b9fcb4
2 changed files with 10 additions and 10 deletions

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.AI
// Add a random factor so not every AI produces at the same tick early in the game.
// Minimum should not be negative as delays in HackyAI could be zero.
var randomFactor = world.SharedRandom.Next(0, ai.Info.StructureProductionRandomBonusDelay);
var randomFactor = ai.Random.Next(0, ai.Info.StructureProductionRandomBonusDelay);
waitTicks = active ? ai.Info.StructureProductionActiveDelay + randomFactor
: ai.Info.StructureProductionInactiveDelay + randomFactor;
}

View File

@@ -230,15 +230,6 @@ namespace OpenRA.Mods.Common.AI
Info = info;
World = init.World;
// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
var smallFractionOfRushInterval = Info.RushInterval / 20;
rushTicks = World.SharedRandom.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);
// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
assignRolesTicks = World.SharedRandom.Next(0, Info.AssignRolesInterval);
attackForceTicks = World.SharedRandom.Next(0, Info.AttackForceInterval);
minAttackForceDelayTicks = World.SharedRandom.Next(0, Info.MinimumAttackForceDelay);
foreach (var decision in info.PowerDecisions)
powerDecisions.Add(decision.OrderName, decision);
}
@@ -265,6 +256,15 @@ namespace OpenRA.Mods.Common.AI
Random = new MersenneTwister((int)p.PlayerActor.ActorID);
// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
var smallFractionOfRushInterval = Info.RushInterval / 20;
rushTicks = Random.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);
// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
assignRolesTicks = Random.Next(0, Info.AssignRolesInterval);
attackForceTicks = Random.Next(0, Info.AttackForceInterval);
minAttackForceDelayTicks = Random.Next(0, Info.MinimumAttackForceDelay);
resourceTypeIndices = new BitArray(World.TileSet.TerrainInfo.Length); // Big enough
foreach (var t in Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>())
resourceTypeIndices.Set(World.TileSet.GetTerrainIndex(t.TerrainType), true);