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
public void Tick(Actor self, Mobile mobile)
{
if( isHarvesting ) return;
if( NextActivity != null )
{
mobile.InternalSetActivity( NextActivity );
@@ -20,10 +22,15 @@ namespace OpenRa.Game.Traits.Activities
}
var harv = self.traits.Get<Harvester>();
var isGem = false;
if (!harv.IsFull &&
Game.map.ContainsResource(self.Location) &&
if( harv.IsFull )
{
mobile.QueueActivity( new DeliverOre() );
mobile.InternalSetActivity( NextActivity );
}
var isGem = false;
if (Game.map.ContainsResource(self.Location) &&
Game.map.Harvest(self.Location, out isGem))
{
var harvestAnim = "harvest" + Util.QuantizeFacing(mobile.facing, 8);
@@ -37,37 +44,7 @@ namespace OpenRa.Game.Traits.Activities
return;
}
if (isHarvesting) return;
if (harv.IsFull)
PlanReturnToBase(self, mobile);
else
PlanMoreHarvesting(self, mobile);
}
/* maybe this doesnt really belong here, since it's the
* same as what UnitOrders has to do for an explicit return */
void PlanReturnToBase(Actor self, Mobile mobile)
{
/* find a proc */
var proc = ChooseReturnLocation(self);
if( proc != null )
mobile.QueueActivity( new DeliverOre( proc ) );
mobile.InternalSetActivity(NextActivity);
}
static Actor ChooseReturnLocation(Actor self)
{
/* todo: compute paths to possible procs, taking into account enemy presence */
/* currently, we're good at choosing close, inaccessible procs */
return Game.world.Actors.Where(
a => a.Owner == self.Owner &&
a.traits.Contains<AcceptsOre>())
.OrderBy(p => (p.Location - self.Location).LengthSquared)
.FirstOrDefault();
PlanMoreHarvesting( self, mobile );
}
void PlanMoreHarvesting(Actor self, Mobile mobile)