remove ref to Game.world in Move

This commit is contained in:
Bob
2010-10-12 02:06:05 +13:00
parent 6bbf878314
commit 09db76f89f
2 changed files with 15 additions and 20 deletions

View File

@@ -23,21 +23,9 @@ namespace OpenRA.Traits.Activities
Func<Actor, Mobile, List<int2>> getPath; Func<Actor, Mobile, List<int2>> getPath;
public Actor ignoreBuilding; 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 // Scriptable move order
// Ignores lane bias and nearby units // Ignores lane bias and nearby units
public Move( int2 destination ) public Move( int2 destination )
: this()
{ {
this.getPath = (self,mobile) => this.getPath = (self,mobile) =>
self.World.PathFinder.FindPath( self.World.PathFinder.FindPath(
@@ -48,7 +36,6 @@ namespace OpenRA.Traits.Activities
} }
public Move( int2 destination, int nearEnough ) public Move( int2 destination, int nearEnough )
: this()
{ {
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self ); this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self );
this.destination = destination; this.destination = destination;
@@ -56,7 +43,6 @@ namespace OpenRA.Traits.Activities
} }
public Move(int2 destination, Actor ignoreBuilding) public Move(int2 destination, Actor ignoreBuilding)
: this()
{ {
this.getPath = (self,mobile) => this.getPath = (self,mobile) =>
self.World.PathFinder.FindPath( self.World.PathFinder.FindPath(
@@ -70,7 +56,6 @@ namespace OpenRA.Traits.Activities
} }
public Move( Actor target, int range ) public Move( Actor target, int range )
: this()
{ {
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange( this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange(
mobile.toCell, target.Location, mobile.toCell, target.Location,
@@ -80,7 +65,6 @@ namespace OpenRA.Traits.Activities
} }
public Move(Target target, int range) public Move(Target target, int range)
: this()
{ {
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange( this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange(
mobile.toCell, Util.CellContaining(target.CenterLocation), mobile.toCell, Util.CellContaining(target.CenterLocation),
@@ -90,7 +74,6 @@ namespace OpenRA.Traits.Activities
} }
public Move(Func<List<int2>> getPath) public Move(Func<List<int2>> getPath)
: this()
{ {
this.getPath = (_1,_2) => getPath(); this.getPath = (_1,_2) => getPath();
this.destination = null; this.destination = null;
@@ -125,9 +108,9 @@ namespace OpenRA.Traits.Activities
if( path == null ) if( path == null )
{ {
if (ticksBeforePathing > 0) if (mobile.ticksBeforePathing > 0)
{ {
--ticksBeforePathing; --mobile.ticksBeforePathing;
return this; return this;
} }
@@ -224,6 +207,12 @@ namespace OpenRA.Traits.Activities
if (--waitTicksRemaining >= 0) if (--waitTicksRemaining >= 0)
return null; return null;
if (mobile.ticksBeforePathing > 0)
{
--mobile.ticksBeforePathing;
return null;
}
mobile.RemoveInfluence(); mobile.RemoveInfluence();
var newPath = EvalPath(self, mobile); var newPath = EvalPath(self, mobile);
mobile.AddInfluence(); mobile.AddInfluence();

View File

@@ -101,6 +101,10 @@ namespace OpenRA.Traits
} }
UnitInfluence uim; UnitInfluence uim;
const int avgTicksBeforePathing = 5;
const int spreadTicksBeforePathing = 5;
internal int ticksBeforePathing = 0;
public Mobile(ActorInitializer init, MobileInfo info) public Mobile(ActorInitializer init, MobileInfo info)
{ {
@@ -185,6 +189,8 @@ namespace OpenRA.Traits
if (line != null) if (line != null)
line.SetTarget(self, Target.FromCell(currentLocation), Color.Green); line.SetTarget(self, Target.FromCell(currentLocation), Color.Green);
}); });
ticksBeforePathing = avgTicksBeforePathing +
self.World.SharedRandom.Next( -spreadTicksBeforePathing, spreadTicksBeforePathing );
} }
} }