From 09db76f89fe6fd9ebc89c9ac1e755e25cb002fc9 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 12 Oct 2010 02:06:05 +1300 Subject: [PATCH] remove ref to Game.world in Move --- OpenRA.Game/Traits/Activities/Move.cs | 29 +++++++++------------------ OpenRA.Game/Traits/Mobile.cs | 6 ++++++ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index 4b7136fddb..6fd761a956 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -23,21 +23,9 @@ namespace OpenRA.Traits.Activities Func> getPath; public Actor ignoreBuilding; - int ticksBeforePathing; - - const int avgTicksBeforePathing = 5; - const int spreadTicksBeforePathing = 5; - - Move() - { - ticksBeforePathing = avgTicksBeforePathing + - Game.world.SharedRandom.Next(-spreadTicksBeforePathing, spreadTicksBeforePathing); - } - // Scriptable move order // Ignores lane bias and nearby units - public Move( int2 destination ) - : this() + public Move( int2 destination ) { this.getPath = (self,mobile) => self.World.PathFinder.FindPath( @@ -48,7 +36,6 @@ namespace OpenRA.Traits.Activities } public Move( int2 destination, int nearEnough ) - : this() { this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self ); this.destination = destination; @@ -56,7 +43,6 @@ namespace OpenRA.Traits.Activities } public Move(int2 destination, Actor ignoreBuilding) - : this() { this.getPath = (self,mobile) => self.World.PathFinder.FindPath( @@ -70,7 +56,6 @@ namespace OpenRA.Traits.Activities } public Move( Actor target, int range ) - : this() { this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange( mobile.toCell, target.Location, @@ -80,7 +65,6 @@ namespace OpenRA.Traits.Activities } public Move(Target target, int range) - : this() { this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange( mobile.toCell, Util.CellContaining(target.CenterLocation), @@ -90,7 +74,6 @@ namespace OpenRA.Traits.Activities } public Move(Func> getPath) - : this() { this.getPath = (_1,_2) => getPath(); this.destination = null; @@ -125,9 +108,9 @@ namespace OpenRA.Traits.Activities if( path == null ) { - if (ticksBeforePathing > 0) + if (mobile.ticksBeforePathing > 0) { - --ticksBeforePathing; + --mobile.ticksBeforePathing; return this; } @@ -224,6 +207,12 @@ namespace OpenRA.Traits.Activities if (--waitTicksRemaining >= 0) return null; + if (mobile.ticksBeforePathing > 0) + { + --mobile.ticksBeforePathing; + return null; + } + mobile.RemoveInfluence(); var newPath = EvalPath(self, mobile); mobile.AddInfluence(); diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index a5f256f81b..83b613fbe9 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -101,6 +101,10 @@ namespace OpenRA.Traits } UnitInfluence uim; + + const int avgTicksBeforePathing = 5; + const int spreadTicksBeforePathing = 5; + internal int ticksBeforePathing = 0; public Mobile(ActorInitializer init, MobileInfo info) { @@ -185,6 +189,8 @@ namespace OpenRA.Traits if (line != null) line.SetTarget(self, Target.FromCell(currentLocation), Color.Green); }); + ticksBeforePathing = avgTicksBeforePathing + + self.World.SharedRandom.Next( -spreadTicksBeforePathing, spreadTicksBeforePathing ); } }