Various harvesting fixes.

This commit is contained in:
Bob
2009-11-12 11:38:28 +13:00
parent 39a7b01f4a
commit efb200c16c
4 changed files with 56 additions and 55 deletions

View File

@@ -12,6 +12,8 @@ namespace OpenRa.Game.Traits.Activities
bool isDone;
Actor refinery;
public DeliverOre() { }
public DeliverOre( Actor refinery )
{
this.refinery = refinery;
@@ -21,14 +23,44 @@ namespace OpenRa.Game.Traits.Activities
public void Tick(Actor self, Mobile mobile)
{
if( self.Location != refinery.Location + refineryDeliverOffset )
if( isDone )
{
var move = new Move( refinery.Location + refineryDeliverOffset, 0 );
mobile.InternalSetActivity( move );
mobile.QueueActivity( this );
move.Tick( self, mobile );
var harv = self.traits.Get<Harvester>();
harv.Deliver( self );
if( NextActivity == null )
NextActivity = new Harvest();
mobile.InternalSetActivity( NextActivity );
return;
}
else if( refinery == null || refinery.IsDead )
{
var search = new PathSearch
{
heuristic = PathSearch.DefaultEstimator( self.Location ),
umt = mobile.GetMovementType(),
checkForBlocked = false,
};
var refineries = Game.world.Actors.Where( x => x.unitInfo == Rules.UnitInfo[ "proc" ] ).ToList();
foreach( var r in refineries )
search.AddInitialCell( r.Location + refineryDeliverOffset );
var path = Game.PathFinder.FindPath( search );
path.Reverse();
if( path.Count != 0 )
{
refinery = refineries.FirstOrDefault( x => x.Location + refineryDeliverOffset == path[ 0 ] );
var move = new Move( () => path );
mobile.InternalSetActivity( move );
mobile.QueueActivity( this );
move.Tick( self, mobile );
return;
}
else
// no refineries reachable?
return;
}
else if( mobile.facing != 64 )
{
var turn = new Turn( 64 );
@@ -37,22 +69,11 @@ namespace OpenRa.Game.Traits.Activities
turn.Tick( self, mobile );
return;
}
else if (isDone)
{
var harv = self.traits.Get<Harvester>();
harv.Deliver(self);
if( NextActivity == null )
NextActivity = new Harvest();
mobile.InternalSetActivity(NextActivity);
return;
}
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
if (renderUnit.anim.CurrentSequence.Name != "empty")
renderUnit.PlayCustomAnimation(self, "empty",
() => isDone = true);
if( renderUnit.anim.CurrentSequence.Name != "empty" )
renderUnit.PlayCustomAnimation( self, "empty",
() => isDone = true );
}
public void Cancel(Actor self, Mobile mobile)