IActivity no longer passed Mobiles around.

This commit is contained in:
Bob
2009-11-25 18:18:17 +13:00
parent 2aea110497
commit 5c3da9387b
9 changed files with 26 additions and 23 deletions

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
@@ -44,7 +44,7 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
public void Cancel(Actor self, Mobile mobile) public void Cancel(Actor self)
{ {
Target = null; Target = null;
} }

View File

@@ -21,9 +21,10 @@ namespace OpenRa.Game.Traits.Activities
static readonly int2 refineryDeliverOffset = new int2( 1, 2 ); static readonly int2 refineryDeliverOffset = new int2( 1, 2 );
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var mobile = self.traits.Get<Mobile>();
if( isDone ) if( isDone )
{ {
@@ -74,7 +75,7 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
public void Cancel(Actor self, Mobile mobile) public void Cancel(Actor self)
{ {
// TODO: allow canceling of deliver orders? // TODO: allow canceling of deliver orders?
} }

View File

@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits.Activities
{ {
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
public void Cancel( Actor self, Mobile mobile ) public void Cancel( Actor self )
{ {
// Cancel can't happen between this being moved to the head of the list, and it being Ticked. // Cancel can't happen between this being moved to the head of the list, and it being Ticked.
throw new InvalidOperationException( "DeployMcvAction: Cancel() should never occur." ); throw new InvalidOperationException( "DeployMcvAction: Cancel() should never occur." );

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits.Activities
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
if (Target == null || Target.IsDead) if (Target == null || Target.IsDead)
return NextActivity; return NextActivity;
@@ -29,7 +29,7 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
public void Cancel(Actor self, Mobile mobile) public void Cancel(Actor self)
{ {
Target = null; Target = null;
} }

View File

@@ -10,9 +10,10 @@ namespace OpenRa.Game.Traits.Activities
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
bool isHarvesting = false; bool isHarvesting = false;
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var mobile = self.traits.Get<Mobile>();
if( isHarvesting ) return null; if( isHarvesting ) return null;
@@ -57,6 +58,6 @@ namespace OpenRa.Game.Traits.Activities
} }
} }
public void Cancel(Actor self, Mobile mobile) { } public void Cancel(Actor self) { }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace OpenRa.Game.Traits.Activities
interface IActivity interface IActivity
{ {
IActivity NextActivity { get; set; } IActivity NextActivity { get; set; }
IActivity Tick( Actor self, Mobile mobile ); IActivity Tick( Actor self );
void Cancel( Actor self, Mobile mobile ); void Cancel( Actor self );
} }
} }

View File

@@ -49,9 +49,10 @@ namespace OpenRa.Game.Traits.Activities
return (u == null || u == self); return (u == null || u == self);
} }
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var mobile = self.traits.Get<Mobile>();
if( move != null ) if( move != null )
{ {
@@ -151,6 +152,12 @@ namespace OpenRa.Game.Traits.Activities
return 0.5f * ( CenterOfCell( from ) + CenterOfCell( to ) ); return 0.5f * ( CenterOfCell( from ) + CenterOfCell( to ) );
} }
public void Cancel( Actor self )
{
path = new List<int2>();
NextActivity = null;
}
abstract class MovePart abstract class MovePart
{ {
public readonly float2 from, to; public readonly float2 from, to;
@@ -254,11 +261,5 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
} }
public void Cancel( Actor self, Mobile mobile )
{
path = new List<int2>();
NextActivity = null;
}
} }
} }

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game.Traits.Activities
this.desiredFacing = desiredFacing; this.desiredFacing = desiredFacing;
} }
public IActivity Tick( Actor self, Mobile mobile ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
@@ -27,7 +27,7 @@ namespace OpenRa.Game.Traits.Activities
return null; return null;
} }
public void Cancel( Actor self, Mobile mobile ) public void Cancel( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();

View File

@@ -53,7 +53,7 @@ namespace OpenRa.Game.Traits
while( nextActivity != null ) while( nextActivity != null )
{ {
currentActivity = nextActivity; currentActivity = nextActivity;
nextActivity = nextActivity.Tick( self, this ); nextActivity = nextActivity.Tick( self );
} }
} }
@@ -73,7 +73,7 @@ namespace OpenRa.Game.Traits
public void Cancel(Actor self) public void Cancel(Actor self)
{ {
if (currentActivity != null) if (currentActivity != null)
currentActivity.Cancel(self, this); currentActivity.Cancel(self);
} }
public IEnumerable<int2> OccupiedCells() public IEnumerable<int2> OccupiedCells()