From 249c56d82f4608f1311512fd4bf313b8e341031d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 1 Feb 2010 00:58:57 +1300 Subject: [PATCH] Start thinking about how the harv<->proc interaction is going to work --- OpenRa.Game/OpenRa.Game.csproj | 3 +- OpenRa.Game/Traits/Activities/DeliverOre.cs | 8 +++-- OpenRa.Game/Traits/Harvester.cs | 2 +- .../Traits/{AcceptsOre.cs => OreRefinery.cs} | 10 +++--- OpenRa.Game/Traits/RenderBuilding.cs | 6 ++++ OpenRa.Game/Traits/TiberiumRefinery.cs | 32 +++++++++++++++++++ OpenRa.Game/Traits/TraitsInterfaces.cs | 2 +- mods/cnc/structures.yaml | 2 +- mods/ra/rules.yaml | 2 +- 9 files changed, 56 insertions(+), 11 deletions(-) rename OpenRa.Game/Traits/{AcceptsOre.cs => OreRefinery.cs} (64%) create mode 100644 OpenRa.Game/Traits/TiberiumRefinery.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index b5a186c4b6..aa2d615897 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -117,7 +117,7 @@ - + @@ -251,6 +251,7 @@ + diff --git a/OpenRa.Game/Traits/Activities/DeliverOre.cs b/OpenRa.Game/Traits/Activities/DeliverOre.cs index a1b80d4717..677cb02556 100644 --- a/OpenRa.Game/Traits/Activities/DeliverOre.cs +++ b/OpenRa.Game/Traits/Activities/DeliverOre.cs @@ -15,7 +15,8 @@ namespace OpenRa.Traits.Activities { this.refinery = refinery; } - + + // TODO: This belongs on the refinery itself static readonly int2 refineryDeliverOffset = new int2( 1, 2 ); public IActivity Tick( Actor self ) @@ -26,6 +27,8 @@ namespace OpenRa.Traits.Activities if( isDone ) { self.traits.Get().Deliver( self, refinery ); + + refinery.traits.Get().OnDock(self); return NextActivity ?? new Harvest(); } else if( NextActivity != null ) @@ -43,7 +46,7 @@ namespace OpenRa.Traits.Activities checkForBlocked = false, }; var refineries = self.World.Queries.OwnedBy[self.Owner] - .Where( x => x.traits.Contains()) + .Where(x => x.traits.Contains()) .ToList(); if( refinery != null ) search.AddInitialCell( self.World, refinery.Location + refineryDeliverOffset ); @@ -62,6 +65,7 @@ namespace OpenRa.Traits.Activities // no refineries reachable? return this; } + // TODO: This belongs in the refinery trait else if( unit.Facing != 64 ) return new Turn( 64 ) { NextActivity = this }; diff --git a/OpenRa.Game/Traits/Harvester.cs b/OpenRa.Game/Traits/Harvester.cs index 073cc8e38e..12f98825d0 100644 --- a/OpenRa.Game/Traits/Harvester.cs +++ b/OpenRa.Game/Traits/Harvester.cs @@ -38,7 +38,7 @@ namespace OpenRa.Traits if (underCursor != null && underCursor.Owner == self.Owner - && underCursor.traits.Contains() && !IsEmpty) + && underCursor.traits.Contains() && !IsEmpty) return new Order("Deliver", self, underCursor); if (underCursor == null && self.World.Map.ContainsResource(xy)) diff --git a/OpenRa.Game/Traits/AcceptsOre.cs b/OpenRa.Game/Traits/OreRefinery.cs similarity index 64% rename from OpenRa.Game/Traits/AcceptsOre.cs rename to OpenRa.Game/Traits/OreRefinery.cs index 18145caa21..744b17a5a7 100644 --- a/OpenRa.Game/Traits/AcceptsOre.cs +++ b/OpenRa.Game/Traits/OreRefinery.cs @@ -2,14 +2,14 @@ namespace OpenRa.Traits { - class AcceptsOreInfo : ITraitInfo + class OreRefineryInfo : ITraitInfo { - public object Create(Actor self) { return new AcceptsOre(self); } + public object Create(Actor self) { return new OreRefinery(self); } } - class AcceptsOre + class OreRefinery : IAcceptOre { - public AcceptsOre(Actor self) + public OreRefinery(Actor self) { self.World.AddFrameEndTask( w => @@ -21,5 +21,7 @@ namespace OpenRa.Traits harvester.QueueActivity(new Harvest()); }); } + + public void OnDock(Actor harv) {} } } diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index b47885e261..d8e26e5f44 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -65,6 +65,12 @@ namespace OpenRa.Traits () => anim.PlayRepeating(GetPrefix(self) + "idle")); } + public void PlayCustomAnim(Actor self, string name, Action a) + { + anim.PlayThen(GetPrefix(self) + name, + () => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); }); + } + public void PlayCustomAnimBackwards(Actor self, string name, Action a) { anim.PlayBackwardsThen(GetPrefix(self) + name, diff --git a/OpenRa.Game/Traits/TiberiumRefinery.cs b/OpenRa.Game/Traits/TiberiumRefinery.cs new file mode 100644 index 0000000000..1a70cb5613 --- /dev/null +++ b/OpenRa.Game/Traits/TiberiumRefinery.cs @@ -0,0 +1,32 @@ +using OpenRa.Traits.Activities; + +namespace OpenRa.Traits +{ + class TiberiumRefineryInfo : ITraitInfo + { + public object Create(Actor self) { return new TiberiumRefinery(self); } + } + + class TiberiumRefinery : IAcceptOre + { + Actor self; + public TiberiumRefinery(Actor self) + { + this.self = self; + self.World.AddFrameEndTask( + w => + { /* create the free harvester! */ + var harvester = w.CreateActor("harv", self.Location + new int2(1, 2), self.Owner); + var unit = harvester.traits.Get(); + var mobile = harvester.traits.Get(); + unit.Facing = 64; + harvester.QueueActivity(new Harvest()); + }); + } + + public void OnDock(Actor harv) + { + self.traits.Get().PlayCustomAnim(self, "active"); + } + } +} diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index be362813bf..bb39087406 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -21,7 +21,7 @@ namespace OpenRa.Traits public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other); } - + public interface IAcceptOre { void OnDock(Actor harv); } public interface IAcceptThief { void OnSteal(Actor self, Actor thief); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index 2926c2a3b9..6597e5bee1 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -54,7 +54,7 @@ PROC: Armor: wood Crewed: yes Sight: 4 - AcceptsOre: + TiberiumRefinery: StoresOre: Pips: 17 Capacity: 1000 diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index 71cdb75245..a56bd4ddef 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -1256,7 +1256,7 @@ PROC: Armor: wood Crewed: yes Sight: 6 - AcceptsOre: + OreRefinery: StoresOre: Pips: 17 Capacity: 2000