Tidy production exits, cnc only
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<Exit>
|
||||
{
|
||||
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<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
|
||||
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<IMove>();
|
||||
var facing = newUnit.TraitOrDefault<IFacing>();
|
||||
|
||||
@@ -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
|
||||
@@ -98,13 +97,12 @@ namespace OpenRA.Traits
|
||||
|
||||
// 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<ExitInfo>())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ExitInfo>().First();
|
||||
|
||||
var rb = self.Trait<RenderBuilding>();
|
||||
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());
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (res != null)
|
||||
self.Trait<Helicopter>().reservation = res.Reserve(self);
|
||||
|
||||
var pi = dest.Trait<Production>();
|
||||
var offset = pi != null ? pi.Spawns.First().First : float2.Zero;
|
||||
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new HeliFly(dest.CenterLocation + offset),
|
||||
|
||||
@@ -104,8 +104,8 @@ namespace OpenRA.Mods.RA
|
||||
if (res != null)
|
||||
reservation = res.Reserve(self);
|
||||
|
||||
var pi = order.TargetActor.Trait<Production>();
|
||||
var offset = pi != null ? pi.Spawns.First().First : float2.Zero;
|
||||
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w =>
|
||||
|
||||
@@ -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<ExitInfo>())
|
||||
{
|
||||
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<UnitInfluence>().GetUnitsAt( exit ).Any())
|
||||
{
|
||||
var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary
|
||||
|
||||
@@ -179,11 +179,15 @@ PYLE:
|
||||
Range: 5
|
||||
Bib:
|
||||
RallyPoint:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user