Merge pull request #8870 from obrakmann/fix-ai-using-shared-random
Fix AI using SharedRandom values
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user