diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 109ea19a5b..f4e675f94a 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -13,6 +13,7 @@ using System.Drawing; using System.Linq; using OpenRA.Graphics; using OpenRA.Support; +using System.Collections.Generic; namespace OpenRA.Traits { @@ -132,5 +133,18 @@ namespace OpenRA.Traits public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } public static int2 CellContaining(float2 pos) { return (1f / Game.CellSize * pos).ToInt2(); } + + /* pretty crap */ + public static IEnumerable Shuffle(this IEnumerable ts, Thirdparty.Random random) + { + var items = ts.ToList(); + while (items.Count > 0) + { + var t = items.Random(random); + yield return t; + items.Remove(t); + } + } + } } diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 472d0410b5..b3e470609d 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -82,26 +82,21 @@ namespace OpenRA.Mods.RA //Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID); } - - public virtual bool Produce( Actor self, ActorInfo producee ) - { - // Todo: remove assumption on Mobile; - // required for 3-arg CanEnterCell - //var mobile = newUnit.Trait(); - var mobileInfo = producee.Traits.Get(); - var uim = self.World.WorldActor.Trait(); - - // Pick a spawn/exit point pair - // Todo: Reorder in a synced random way - foreach (var s in self.Info.Traits.WithInterface()) - if( mobileInfo.CanEnterCell( self.World, uim, self.Location + s.ExitCell,self,true ) ) - { - DoProduction(self, producee, s); - return true; - } - return false; - } + public virtual bool Produce(Actor self, ActorInfo producee) + { + // todo: remove Mobile requirement. + var mobileInfo = producee.Traits.Get(); + var uim = self.World.WorldActor.Trait(); + // pick a spawn/exit point pair + foreach (var s in self.Info.Traits.WithInterface().Shuffle(self.World.SharedRandom)) + if (mobileInfo.CanEnterCell(self.World, uim, self.Location + s.ExitCell, self, true)) + { + DoProduction(self, producee, s); + return true; + } + return false; + } } }