unit idle tracking via dummy activity; wasn't so bad.

This commit is contained in:
Chris Forbes
2009-12-28 08:26:13 +13:00
parent 47f4815205
commit b7bac5bd16
11 changed files with 83 additions and 48 deletions

View File

@@ -12,49 +12,62 @@ namespace OpenRa.Game.Traits.Activities
var unit = self.traits.Get<Unit>();
var mobile = self.traits.Get<Mobile>();
if( isHarvesting ) return null;
if( NextActivity != null )
return NextActivity;
if( isHarvesting ) return this;
if( NextActivity != null ) return NextActivity;
var harv = self.traits.Get<Harvester>();
if( harv.IsFull )
return new DeliverOre { NextActivity = NextActivity };
var isGem = false;
if( Rules.Map.ContainsResource( self.Location ) &&
Rules.Map.Harvest( self.Location, out isGem ) )
{
var harvestAnim = "harvest" + Util.QuantizeFacing( unit.Facing, 8 );
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
if( harvestAnim != renderUnit.anim.CurrentSequence.Name )
{
isHarvesting = true;
renderUnit.PlayCustomAnimation( self, harvestAnim, () => isHarvesting = false );
}
harv.AcceptResource( isGem );
return null;
}
if (HarvestThisTile(self))
return this;
else
{
self.QueueActivity( new Move(
() =>
{
var search = new PathSearch
{
heuristic = loc => ( Rules.Map.ContainsResource( loc ) ? 0 : 1 ),
umt = UnitMovementType.Wheel,
checkForBlocked = true
};
search.AddInitialCell( self.Location );
return Game.PathFinder.FindPath( search );
} ) );
self.QueueActivity( new Harvest() );
FindMoreOre(self);
return NextActivity;
}
}
bool HarvestThisTile(Actor self)
{
var unit = self.traits.Get<Unit>();
var harv = self.traits.Get<Harvester>();
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
var isGem = false;
if (!Rules.Map.ContainsResource(self.Location) ||
!Rules.Map.Harvest(self.Location, out isGem))
return false;
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
if (harvestAnim != renderUnit.anim.CurrentSequence.Name)
{
isHarvesting = true;
renderUnit.PlayCustomAnimation(self, harvestAnim, () => isHarvesting = false);
}
harv.AcceptResource(isGem);
return true;
}
void FindMoreOre(Actor self)
{
self.QueueActivity(new Move(
() =>
{
var search = new PathSearch
{
heuristic = loc => (Rules.Map.ContainsResource(loc) ? 0 : 1),
umt = UnitMovementType.Wheel,
checkForBlocked = true
};
search.AddInitialCell(self.Location);
return Game.PathFinder.FindPath(search);
}));
self.QueueActivity(new Harvest());
}
public void Cancel(Actor self) { }
}
}