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);
|
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
return new int2(int.Parse(parts[0]), int.Parse(parts[1]));
|
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);
|
UnknownFieldAction("[Type] {0}".F(x),fieldType);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -16,33 +16,32 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public class ProductionInfo : ITraitInfo
|
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 readonly string[] Produces = { };
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Production(this); }
|
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 class Production
|
||||||
{
|
{
|
||||||
public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
|
|
||||||
public ProductionInfo Info;
|
public ProductionInfo Info;
|
||||||
public Production(ProductionInfo info)
|
public Production(ProductionInfo info)
|
||||||
{
|
{
|
||||||
Info = 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 move = newUnit.Trait<IMove>();
|
||||||
var facing = newUnit.TraitOrDefault<IFacing>();
|
var facing = newUnit.TraitOrDefault<IFacing>();
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ namespace OpenRA.Traits
|
|||||||
var to = Util.CenterOfCell(exit);
|
var to = Util.CenterOfCell(exit);
|
||||||
newUnit.CenterLocation = spawn;
|
newUnit.CenterLocation = spawn;
|
||||||
if (facing != null)
|
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);
|
self.World.Add(newUnit);
|
||||||
|
|
||||||
// Animate the spawn -> exit transition
|
// Animate the spawn -> exit transition
|
||||||
@@ -95,16 +94,15 @@ namespace OpenRA.Traits
|
|||||||
// Todo: remove assumption on Mobile;
|
// Todo: remove assumption on Mobile;
|
||||||
// required for 3-arg CanEnterCell
|
// required for 3-arg CanEnterCell
|
||||||
var mobile = newUnit.Trait<Mobile>();
|
var mobile = newUnit.Trait<Mobile>();
|
||||||
|
|
||||||
// Pick a spawn/exit point pair
|
// Pick a spawn/exit point pair
|
||||||
// Todo: Reorder in a synced random way
|
// 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;
|
System.Console.WriteLine("here");
|
||||||
var spawn = self.CenterLocation + s.First;
|
if (mobile.CanEnterCell(self.Location + s.ExitCell,self,true))
|
||||||
if (mobile.CanEnterCell(exit,self,true))
|
|
||||||
{
|
{
|
||||||
DoProduction(self, newUnit, exit, spawn);
|
DoProduction(self, newUnit, s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
|
|
||||||
|
|
||||||
// Assume a single exit point for simplicity
|
// Assume a single exit point for simplicity
|
||||||
var spawn = self.CenterLocation + Spawns.First().First;
|
var exit = self.Info.Traits.WithInterface<ExitInfo>().First();
|
||||||
var exit = self.Location + Spawns.First().Second;
|
|
||||||
|
|
||||||
var rb = self.Trait<RenderBuilding>();
|
var rb = self.Trait<RenderBuilding>();
|
||||||
rb.PlayCustomAnimRepeating(self, "active");
|
rb.PlayCustomAnimRepeating(self, "active");
|
||||||
@@ -65,7 +64,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
if (self.IsDead())
|
if (self.IsDead())
|
||||||
return;
|
return;
|
||||||
rb.PlayCustomAnimRepeating(self, "idle");
|
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 Fly(endPos));
|
||||||
a.QueueActivity(new RemoveSelf());
|
a.QueueActivity(new RemoveSelf());
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
if (res != null)
|
if (res != null)
|
||||||
self.Trait<Helicopter>().reservation = res.Reserve(self);
|
self.Trait<Helicopter>().reservation = res.Reserve(self);
|
||||||
|
|
||||||
var pi = dest.Trait<Production>();
|
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||||
var offset = pi != null ? pi.Spawns.First().First : float2.Zero;
|
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
||||||
|
|
||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new HeliFly(dest.CenterLocation + offset),
|
new HeliFly(dest.CenterLocation + offset),
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ namespace OpenRA.Mods.RA
|
|||||||
if (res != null)
|
if (res != null)
|
||||||
reservation = res.Reserve(self);
|
reservation = res.Reserve(self);
|
||||||
|
|
||||||
var pi = order.TargetActor.Trait<Production>();
|
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||||
var offset = pi != null ? pi.Spawns.First().First : float2.Zero;
|
var offset = exit != null ? exit.SpawnOffset : float2.Zero;
|
||||||
|
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
// Pick a spawn/exit point
|
// Pick a spawn/exit point
|
||||||
// Todo: Reorder in a synced random way
|
// 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 exit = self.Location + s.ExitCell;
|
||||||
var spawn = self.CenterLocation + s.First;
|
var spawn = self.CenterLocation + s.SpawnOffset;
|
||||||
if (!self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt( exit ).Any())
|
if (!self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt( exit ).Any())
|
||||||
{
|
{
|
||||||
var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary
|
var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary
|
||||||
|
|||||||
@@ -179,11 +179,15 @@ PYLE:
|
|||||||
Range: 5
|
Range: 5
|
||||||
Bib:
|
Bib:
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
Production:
|
Exit@1:
|
||||||
|
SpawnOffset: -10,2
|
||||||
|
ExitCell: 0,1
|
||||||
|
Exit@2:
|
||||||
|
SpawnOffset: 7,7
|
||||||
|
ExitCell: 1,1
|
||||||
|
Production:
|
||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
SpawnOffsets: -10,2, 7,7
|
ProductionQueue:
|
||||||
ExitCells: 0,1, 1,1
|
|
||||||
ProductionQueue@Vehicle:
|
|
||||||
Type: Infantry
|
Type: Infantry
|
||||||
BuildSpeed: .4
|
BuildSpeed: .4
|
||||||
LowPowerSlowdown: 3
|
LowPowerSlowdown: 3
|
||||||
@@ -212,10 +216,11 @@ HAND:
|
|||||||
Range: 5
|
Range: 5
|
||||||
Bib:
|
Bib:
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
|
Exit@1:
|
||||||
|
SpawnOffset: 12,24
|
||||||
|
ExitCell: 1,2
|
||||||
Production:
|
Production:
|
||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
SpawnOffsets: 12,24
|
|
||||||
ExitCells:1,2
|
|
||||||
ProductionQueue@Infantry:
|
ProductionQueue@Infantry:
|
||||||
Type: Infantry
|
Type: Infantry
|
||||||
BuildSpeed: .4
|
BuildSpeed: .4
|
||||||
@@ -247,10 +252,11 @@ AFLD:
|
|||||||
RallyPoint:
|
RallyPoint:
|
||||||
RallyPoint: 4,2
|
RallyPoint: 4,2
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
|
Exit@1:
|
||||||
|
SpawnOffset: -24,0
|
||||||
|
ExitCell: 3,1
|
||||||
ProductionAirdrop:
|
ProductionAirdrop:
|
||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
SpawnOffsets: -24,0
|
|
||||||
ExitCells:3,1
|
|
||||||
ProductionQueue@Vehicle:
|
ProductionQueue@Vehicle:
|
||||||
Type: Vehicle
|
Type: Vehicle
|
||||||
BuildSpeed: .4
|
BuildSpeed: .4
|
||||||
@@ -283,10 +289,11 @@ WEAP:
|
|||||||
RenderWarFactory:
|
RenderWarFactory:
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
RallyPoint: 0,3
|
RallyPoint: 0,3
|
||||||
|
Exit@1:
|
||||||
|
SpawnOffset: -8,-8
|
||||||
|
ExitCell: 0,2
|
||||||
Production:
|
Production:
|
||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
SpawnOffsets: -8,-8
|
|
||||||
ExitCells: 0,2
|
|
||||||
ProductionQueue@Vehicle:
|
ProductionQueue@Vehicle:
|
||||||
Type: Vehicle
|
Type: Vehicle
|
||||||
BuildSpeed: .4
|
BuildSpeed: .4
|
||||||
@@ -396,9 +403,9 @@ HPAD:
|
|||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 5
|
Range: 5
|
||||||
Bib:
|
Bib:
|
||||||
|
Exit@1:
|
||||||
|
SpawnOffset: 0,-6
|
||||||
ReservableProduction:
|
ReservableProduction:
|
||||||
SpawnOffsets: 0,-6
|
|
||||||
ExitCells: 0,0
|
|
||||||
Produces: Plane
|
Produces: Plane
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
Reservable:
|
Reservable:
|
||||||
|
|||||||
Reference in New Issue
Block a user