Recover gracefully if proc goes away while harv is docking

This commit is contained in:
Paul Chote
2010-06-16 20:21:47 +12:00
parent 5f58379f5b
commit f3dc3b1da0

View File

@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Cnc
class TiberiumRefineryDockAction : IAcceptOreDockAction, INotifyDamage, INotifySold, INotifyCapture, ITraitPrerequisite<IAcceptOre> class TiberiumRefineryDockAction : IAcceptOreDockAction, INotifyDamage, INotifySold, INotifyCapture, ITraitPrerequisite<IAcceptOre>
{ {
Actor dockedHarv = null; Actor dockedHarv = null;
bool preventDock = false;
public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) public void OnDock(Actor self, Actor harv, DeliverResources dockOrder)
{ {
float2 startDock = harv.CenterLocation; float2 startDock = harv.CenterLocation;
@@ -42,31 +43,40 @@ namespace OpenRA.Mods.Cnc
harv.QueueActivity( new Turn(112) ); harv.QueueActivity( new Turn(112) );
harv.QueueActivity( new CallFunc( () => harv.QueueActivity( new CallFunc( () =>
{ {
dockedHarv = harv; if (!preventDock)
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
harv.QueueActivity( new Drag(startDock, endDock, 12) );
harv.QueueActivity( new CallFunc( () =>
{ {
self.World.AddFrameEndTask( w1 => dockedHarv = harv;
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
harv.QueueActivity( new Drag(startDock, endDock, 12) );
harv.QueueActivity( new CallFunc( () =>
{ {
harvester.Visible = false; self.World.AddFrameEndTask( w1 =>
harvester.Deliver(harv, self); {
}); if (!preventDock)
}, false ) ); harvester.Visible = false;
harv.QueueActivity( new Wait(18, false ) ); harvester.Deliver(harv, self);
harv.QueueActivity( new CallFunc( () => harvester.Visible = true, false ) ); });
harv.QueueActivity( new Drag(endDock, startDock, 12) ); }, false ) );
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) ); harv.QueueActivity( new Wait(18, false ) );
if (harvester.LastHarvestedCell != int2.Zero) harv.QueueActivity( new CallFunc( () => harvester.Visible = true, false ) );
harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) ); harv.QueueActivity( new Drag(endDock, startDock, 12) );
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
if (harvester.LastHarvestedCell != int2.Zero)
harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) );
}
harv.QueueActivity( new Harvest() ); harv.QueueActivity( new Harvest() );
}) ); }) );
} }
void CancelDock(Actor self, Actor harv) void CancelDock(Actor self, Actor harv)
{ {
// Todo: Cancel the above activities that are non-cancelable preventDock = true;
if (dockedHarv == null)
return;
// invisible harvester makes ceiling cat cry
harv.traits.Get<Harvester>().Visible = true;
} }
public void Selling (Actor self) { CancelDock(self, dockedHarv); } public void Selling (Actor self) { CancelDock(self, dockedHarv); }