diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index bdc0e3ea20..f80c09acdb 100644 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -144,6 +144,18 @@ namespace OpenRA.FileFormats var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return new int2(int.Parse(parts[0]), int.Parse(parts[1])); } + else if (fieldType == typeof(float2)) + { + var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + float xx = 0; + float yy = 0; + float res; + if (float.TryParse(parts[0].Replace("%",""), out res)) + xx = res * (parts[0].Contains( '%' ) ? 0.01f : 1f); + if (float.TryParse(parts[1].Replace("%",""), out res)) + yy = res * (parts[1].Contains( '%' ) ? 0.01f : 1f); + return new float2(xx,yy); + } UnknownFieldAction("[Type] {0}".F(x),fieldType); return null; diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index 97dccecb79..830b2d841f 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -16,33 +16,32 @@ namespace OpenRA.Traits { public class ProductionInfo : ITraitInfo { - public readonly float[] SpawnOffsets; // in px relative to CenterLocation - public readonly int[] ExitCells; // in cells relative to TopLeft, supports a list for multiple exits public readonly string[] Produces = { }; public virtual object Create(ActorInitializer init) { return new Production(this); } } + public class ExitInfo : TraitInfo + { + public readonly float2 SpawnOffset = float2.Zero; // in px relative to CenterLocation + public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft + public readonly int Facing = -1; + } + public class Exit {} + public class Production - { - public readonly List> Spawns = new List>(); + { public ProductionInfo Info; public Production(ProductionInfo info) { Info = info; - - if (info.SpawnOffsets == null || info.ExitCells == null) - return; - - if (info.SpawnOffsets.Length != info.ExitCells.Length) - throw new System.InvalidOperationException("SpawnOffset, ExitCells length mismatch"); - - for (int i = 0; i < info.ExitCells.Length; i+=2) - 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) + public void DoProduction(Actor self, Actor newUnit, ExitInfo exitinfo) { + var exit = self.Location + exitinfo.ExitCell; + var spawn = self.CenterLocation + exitinfo.SpawnOffset; + var move = newUnit.Trait(); var facing = newUnit.TraitOrDefault(); @@ -51,7 +50,7 @@ namespace OpenRA.Traits var to = Util.CenterOfCell(exit); newUnit.CenterLocation = spawn; if (facing != null) - facing.Facing = Util.GetFacing(to - spawn, facing.Facing); + facing.Facing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, facing.Facing) : exitinfo.Facing; self.World.Add(newUnit); // Animate the spawn -> exit transition @@ -95,16 +94,15 @@ namespace OpenRA.Traits // Todo: remove assumption on Mobile; // required for 3-arg CanEnterCell var mobile = newUnit.Trait(); - + // Pick a spawn/exit point pair // Todo: Reorder in a synced random way - foreach (var s in Spawns) + foreach (var s in self.Info.Traits.WithInterface()) { - var exit = self.Location + s.Second; - var spawn = self.CenterLocation + s.First; - if (mobile.CanEnterCell(exit,self,true)) + System.Console.WriteLine("here"); + if (mobile.CanEnterCell(self.Location + s.ExitCell,self,true)) { - DoProduction(self, newUnit, exit, spawn); + DoProduction(self, newUnit, s); return true; } } diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index f5c77fe254..1378dd24f2 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -37,8 +37,7 @@ namespace OpenRA.Mods.Cnc // Assume a single exit point for simplicity - var spawn = self.CenterLocation + Spawns.First().First; - var exit = self.Location + Spawns.First().Second; + var exit = self.Info.Traits.WithInterface().First(); var rb = self.Trait(); rb.PlayCustomAnimRepeating(self, "active"); @@ -65,7 +64,7 @@ namespace OpenRA.Mods.Cnc if (self.IsDead()) return; rb.PlayCustomAnimRepeating(self, "idle"); - self.World.AddFrameEndTask(ww => DoProduction(self, cargo.Unload(self), exit, spawn)); + self.World.AddFrameEndTask(ww => DoProduction(self, cargo.Unload(self), exit)); })); a.QueueActivity(new Fly(endPos)); a.QueueActivity(new RemoveSelf()); diff --git a/OpenRA.Mods.RA/Activities/HeliReturn.cs b/OpenRA.Mods.RA/Activities/HeliReturn.cs index 2362a1a111..8eeaad0af6 100644 --- a/OpenRA.Mods.RA/Activities/HeliReturn.cs +++ b/OpenRA.Mods.RA/Activities/HeliReturn.cs @@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA.Activities if (res != null) self.Trait().reservation = res.Reserve(self); - var pi = dest.Trait(); - var offset = pi != null ? pi.Spawns.First().First : float2.Zero; + var exit = dest.Info.Traits.WithInterface().FirstOrDefault(); + var offset = exit != null ? exit.SpawnOffset : float2.Zero; return Util.SequenceActivities( new HeliFly(dest.CenterLocation + offset), diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index 3b63a868b1..c23c466a48 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -104,8 +104,8 @@ namespace OpenRA.Mods.RA if (res != null) reservation = res.Reserve(self); - var pi = order.TargetActor.Trait(); - var offset = pi != null ? pi.Spawns.First().First : float2.Zero; + var exit = order.TargetActor.Info.Traits.WithInterface().FirstOrDefault(); + var offset = exit != null ? exit.SpawnOffset : float2.Zero; if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.RA/ReservableProduction.cs b/OpenRA.Mods.RA/ReservableProduction.cs index 8be9bd9af6..cb9f00c774 100644 --- a/OpenRA.Mods.RA/ReservableProduction.cs +++ b/OpenRA.Mods.RA/ReservableProduction.cs @@ -32,10 +32,10 @@ namespace OpenRA.Mods.RA // Pick a spawn/exit point // Todo: Reorder in a synced random way - foreach (var s in Spawns) + foreach (var s in self.Info.Traits.WithInterface()) { - var exit = self.Location + s.Second; - var spawn = self.CenterLocation + s.First; + var exit = self.Location + s.ExitCell; + var spawn = self.CenterLocation + s.SpawnOffset; if (!self.World.WorldActor.Trait().GetUnitsAt( exit ).Any()) { var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index ec5f7c75e5..4a7a077185 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -179,11 +179,15 @@ PYLE: Range: 5 Bib: RallyPoint: - Production: + Exit@1: + SpawnOffset: -10,2 + ExitCell: 0,1 + Exit@2: + SpawnOffset: 7,7 + ExitCell: 1,1 + Production: Produces: Infantry - SpawnOffsets: -10,2, 7,7 - ExitCells: 0,1, 1,1 - ProductionQueue@Vehicle: + ProductionQueue: Type: Infantry BuildSpeed: .4 LowPowerSlowdown: 3 @@ -212,10 +216,11 @@ HAND: Range: 5 Bib: RallyPoint: + Exit@1: + SpawnOffset: 12,24 + ExitCell: 1,2 Production: Produces: Infantry - SpawnOffsets: 12,24 - ExitCells:1,2 ProductionQueue@Infantry: Type: Infantry BuildSpeed: .4 @@ -247,10 +252,11 @@ AFLD: RallyPoint: RallyPoint: 4,2 BelowUnits: + Exit@1: + SpawnOffset: -24,0 + ExitCell: 3,1 ProductionAirdrop: Produces: Vehicle - SpawnOffsets: -24,0 - ExitCells:3,1 ProductionQueue@Vehicle: Type: Vehicle BuildSpeed: .4 @@ -283,10 +289,11 @@ WEAP: RenderWarFactory: RallyPoint: RallyPoint: 0,3 + Exit@1: + SpawnOffset: -8,-8 + ExitCell: 0,2 Production: Produces: Vehicle - SpawnOffsets: -8,-8 - ExitCells: 0,2 ProductionQueue@Vehicle: Type: Vehicle BuildSpeed: .4 @@ -396,9 +403,9 @@ HPAD: RevealsShroud: Range: 5 Bib: + Exit@1: + SpawnOffset: 0,-6 ReservableProduction: - SpawnOffsets: 0,-6 - ExitCells: 0,0 Produces: Plane BelowUnits: Reservable: