From 40b16e33baddb63324b0c80632e17a2cfa262e0f Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 3 Aug 2010 18:29:32 +1200 Subject: [PATCH] Fix and polish all ra production structures; remove some obsoleted Production subclasses --- OpenRA.Game/Traits/Production.cs | 8 +-- OpenRA.Mods.Cnc/ProductionAirdrop.cs | 4 +- OpenRA.Mods.RA/Activities/HeliReturn.cs | 2 +- OpenRA.Mods.RA/Aircraft.cs | 4 +- OpenRA.Mods.RA/Helicopter.cs | 2 +- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 2 - OpenRA.Mods.RA/ProducesHelicopters.cs | 74 ------------------------- OpenRA.Mods.RA/ProductionSurround.cs | 51 ----------------- OpenRA.Mods.RA/ReservableProduction.cs | 32 ++++++++++- mods/cnc/structures.yaml | 4 +- mods/ra/structures.yaml | 21 ++++++- 11 files changed, 62 insertions(+), 142 deletions(-) delete mode 100644 OpenRA.Mods.RA/ProducesHelicopters.cs delete mode 100644 OpenRA.Mods.RA/ProductionSurround.cs diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index efce2a5753..21d77d4623 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -28,7 +28,7 @@ namespace OpenRA.Traits public class Production : IIssueOrder, IResolveOrder, ITags, IOrderCursor { - public readonly Dictionary Spawns = new Dictionary(); + public readonly List> Spawns = new List>(); public Production(ProductionInfo info) { if (info.SpawnOffsets == null || info.ExitCells == null) @@ -38,7 +38,7 @@ namespace OpenRA.Traits throw new System.InvalidOperationException("SpawnOffset, ExitCells length mismatch"); for (int i = 0; i < info.ExitCells.Length; i+=2) - Spawns.Add(new float2(info.SpawnOffsets[i],info.SpawnOffsets[i+1]), new int2(info.ExitCells[i], info.ExitCells[i+1])); + Spawns.Add(Pair.New(new float2(info.SpawnOffsets[i],info.SpawnOffsets[i+1]), new int2(info.ExitCells[i], info.ExitCells[i+1]))); } public void DoProduction(Actor self, Actor newUnit, int2 exit, float2 spawn) @@ -100,8 +100,8 @@ namespace OpenRA.Traits // Todo: Reorder in a synced random way foreach (var s in Spawns) { - var exit = self.Location + s.Value; - var spawn = self.CenterLocation + s.Key; + var exit = self.Location + s.Second; + var spawn = self.CenterLocation + s.First; if (mobile.CanEnterCell(exit,self,true)) { DoProduction(self, newUnit, exit, spawn); diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 2745cea0f9..3dd5cb5d69 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -38,8 +38,8 @@ namespace OpenRA.Mods.Cnc // Assume a single exit point for simplicity - var spawn = self.CenterLocation + Spawns.First().Key; - var exit = self.Location + Spawns.First().Value; + var spawn = self.CenterLocation + Spawns.First().First; + var exit = self.Location + Spawns.First().Second; owner.World.AddFrameEndTask(w => { diff --git a/OpenRA.Mods.RA/Activities/HeliReturn.cs b/OpenRA.Mods.RA/Activities/HeliReturn.cs index c60cf4b5ed..ea283eb8a9 100644 --- a/OpenRA.Mods.RA/Activities/HeliReturn.cs +++ b/OpenRA.Mods.RA/Activities/HeliReturn.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities self.traits.Get().reservation = res.Reserve(self); var pi = dest.traits.Get(); - var offset = pi != null ? pi.Spawns.First().Key : float2.Zero; + var offset = pi != null ? pi.Spawns.First().First : float2.Zero; return Util.SequenceActivities( new HeliFly(dest.CenterLocation + offset), diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index 9dc5821131..8b977031d5 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -41,7 +41,9 @@ namespace OpenRA.Mods.RA public Aircraft( ActorInitializer init , AircraftInfo info) { - this.Location = init.Get(); + if (init.Contains()) + this.Location = init.Get(); + this.Facing = init.Contains() ? init.Get() : info.InitialFacing; this.Altitude = init.Contains() ? init.Get() : 0; Info = info; diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index 8bf81537df..d22087fda4 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA reservation = res.Reserve(self); var pi = order.TargetActor.traits.Get(); - var offset = pi != null ? pi.Spawns.First().Key : float2.Zero; + var offset = pi != null ? pi.Spawns.First().First : float2.Zero; if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 46fee83fe5..cd6fd9a037 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -162,7 +162,6 @@ - @@ -215,7 +214,6 @@ - diff --git a/OpenRA.Mods.RA/ProducesHelicopters.cs b/OpenRA.Mods.RA/ProducesHelicopters.cs deleted file mode 100644 index ebb887acbe..0000000000 --- a/OpenRA.Mods.RA/ProducesHelicopters.cs +++ /dev/null @@ -1,74 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using System.Linq; -using OpenRA.GameRules; -using OpenRA.Traits; -using OpenRA.FileFormats; - -namespace OpenRA.Mods.RA -{ - public class ProducesHelicoptersInfo : ProductionInfo - { - public override object Create(ActorInitializer init) { return new ProducesHelicopters(this); } - } - - class ProducesHelicopters : Production - { - public ProducesHelicopters(ProducesHelicoptersInfo info) : base(info) {} - - - // Hack around visibility bullshit in Production - public override bool Produce( Actor self, ActorInfo producee ) - { - // Pick an exit that we can move to - var exit = int2.Zero; - var spawn = float2.Zero; - var success = false; - - // Pick a spawn/exit point - // Todo: Reorder in a synced random way - foreach (var s in Spawns) - { - exit = self.Location + s.Value; - spawn = self.CenterLocation + s.Key; - if (!self.World.WorldActor.traits.Get().GetUnitsAt( exit ).Any()) - { - success = true; - break; - } - } - - if (!success) - return false; - - // Todo: Once Helicopter supports it, update UIM if its docked/landed - var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary - { - new LocationInit( exit ), - new OwnerInit( self.Owner ), - }); - newUnit.CenterLocation = spawn; - - var rp = self.traits.GetOrDefault(); - if( rp != null ) - { - newUnit.QueueActivity( new Activities.HeliFly( Util.CenterOfCell(rp.rallyPoint)) ); - } - - foreach (var t in self.traits.WithInterface()) - t.UnitProduced(self, newUnit, exit); - - Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID); - - return true; - } - } -} diff --git a/OpenRA.Mods.RA/ProductionSurround.cs b/OpenRA.Mods.RA/ProductionSurround.cs deleted file mode 100644 index cec3ec40f0..0000000000 --- a/OpenRA.Mods.RA/ProductionSurround.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using System.Linq; -using OpenRA.GameRules; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - class ProductionSurroundInfo : ProductionInfo - { - public override object Create(ActorInitializer init) { return new ProductionSurround(this); } - } - - class ProductionSurround : Production - { - public ProductionSurround(ProductionSurroundInfo info) : base(info) {} - - static int2? FindAdjacentTile(Actor self, bool waterBound) - { - var tiles = Footprint.Tiles(self); - var min = tiles.Aggregate(int2.Min) - new int2(1, 1); - var max = tiles.Aggregate(int2.Max) + new int2(1, 1); - - for (var j = min.Y; j <= max.Y; j++) - for (var i = min.X; i <= max.X; i++) - if (self.World.IsCellBuildable(new int2(i, j), waterBound)) - return new int2(i, j); - - return null; - } - /* - public override int2? CreationLocation(Actor self, ActorInfo producee) - { - return FindAdjacentTile(self, self.Info.Traits.Get().WaterBound); - } - - public override int CreationFacing(Actor self, Actor newUnit) - { - return Util.GetFacing(newUnit.CenterLocation - self.CenterLocation, 128); - } - */ - } -} diff --git a/OpenRA.Mods.RA/ReservableProduction.cs b/OpenRA.Mods.RA/ReservableProduction.cs index 6a7aaf26b8..9febe368ed 100644 --- a/OpenRA.Mods.RA/ReservableProduction.cs +++ b/OpenRA.Mods.RA/ReservableProduction.cs @@ -10,6 +10,8 @@ using OpenRA.Traits; +using System.Linq; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -29,7 +31,35 @@ namespace OpenRA.Mods.RA if (Reservable.IsReserved(self)) return false; - return base.Produce(self, producee); + // Pick a spawn/exit point + // Todo: Reorder in a synced random way + foreach (var s in Spawns) + { + var exit = self.Location + s.Second; + var spawn = self.CenterLocation + s.First; + if (!self.World.WorldActor.traits.Get().GetUnitsAt( exit ).Any()) + { + var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary + { + new LocationInit( exit ), + new OwnerInit( self.Owner ), + }); + newUnit.CenterLocation = spawn; + + var rp = self.traits.GetOrDefault(); + if( rp != null ) + { + newUnit.QueueActivity( new Activities.HeliFly( Util.CenterOfCell(rp.rallyPoint)) ); + } + + foreach (var t in self.traits.WithInterface()) + t.UnitProduced(self, newUnit, exit); + + Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID); + return true; + } + } + return false; } } } diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index 334613025f..054906adf7 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -342,8 +342,8 @@ HPAD: RevealsShroud: Range: 5 Bib: - ProducesHelicopters: - SpawnOffsets: 0,-4 + ReservableProduction: + SpawnOffsets: 0,-6 ExitCells: 0,0 Produces: Plane BelowUnits: diff --git a/mods/ra/structures.yaml b/mods/ra/structures.yaml index 905211acf7..abf5023f72 100644 --- a/mods/ra/structures.yaml +++ b/mods/ra/structures.yaml @@ -77,7 +77,9 @@ SPEN: Armor: light RevealsShroud: Range: 4 - ProductionSurround: + Production: + SpawnOffsets: 0,-5, 0,-5, 0,0, 0,0 + ExitCells: -1,2, 3,2, 0,0, 2,0 Produces: Ship IronCurtainable: -EmitInfantryOnSell: @@ -109,8 +111,10 @@ SYRD: Armor: light RevealsShroud: Range: 4 - ProductionSurround: + Production: Produces: Ship + SpawnOffsets: -25,23, 26,23, -22,-25, 23,-25 + ExitCells: 0,2, 2,2, 0,0, 2,0 IronCurtainable: -EmitInfantryOnSell: RepairsUnits: @@ -444,6 +448,8 @@ WEAP: RenderWarFactory: RallyPoint: Production: + SpawnOffsets: 5,0 + ExitCells: 1,1 Produces: Vehicle IronCurtainable: @@ -558,7 +564,8 @@ HPAD: Range: 5 Bib: ReservableProduction: - SpawnOffset: 0,-4 + SpawnOffsets: 0,-6 + ExitCells: 0,0 Produces: Plane BelowUnits: Reservable: @@ -586,6 +593,8 @@ AFLD: Range: 7 ReservableProduction: Produces: Plane + SpawnOffsets: 0,4 + ExitCells: 1,1 BelowUnits: Reservable: IronCurtainable: @@ -685,6 +694,8 @@ BARR: Bib: RallyPoint: Production: + SpawnOffsets: -4,19, -17,15 + ExitCells: 0,2, 0,2 Produces: Infantry IronCurtainable: @@ -713,6 +724,8 @@ TENT: RallyPoint: Production: Produces: Infantry + SpawnOffsets: -1,19, -17,15 + ExitCells: 0,2, 0,2 IronCurtainable: KENN: @@ -734,6 +747,8 @@ KENN: Range: 4 RallyPoint: Production: + SpawnOffsets: 0,0 + ExitCells: 0,0 Produces: Infantry IronCurtainable: -EmitInfantryOnSell: