Fix and polish all ra production structures; remove some obsoleted Production subclasses

This commit is contained in:
Paul Chote
2010-08-03 18:29:32 +12:00
parent 8e82f6fa1a
commit 40b16e33ba
11 changed files with 62 additions and 142 deletions

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Traits
public class Production : IIssueOrder, IResolveOrder, ITags, IOrderCursor
{
public readonly Dictionary<float2, int2> Spawns = new Dictionary<float2, int2>();
public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
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);

View File

@@ -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 =>
{

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities
self.traits.Get<Helicopter>().reservation = res.Reserve(self);
var pi = dest.traits.Get<Production>();
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),

View File

@@ -41,7 +41,9 @@ namespace OpenRA.Mods.RA
public Aircraft( ActorInitializer init , AircraftInfo info)
{
this.Location = init.Get<LocationInit,int2>();
if (init.Contains<LocationInit>())
this.Location = init.Get<LocationInit,int2>();
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
Info = info;

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA
reservation = res.Reserve(self);
var pi = order.TargetActor.traits.Get<Production>();
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 =>

View File

@@ -162,7 +162,6 @@
<Compile Include="SupportPowers\ParatroopersPower.cs" />
<Compile Include="Passenger.cs" />
<Compile Include="Plane.cs" />
<Compile Include="ProductionSurround.cs" />
<Compile Include="Render\RenderBuildingCharge.cs" />
<Compile Include="Render\RenderBuildingOre.cs" />
<Compile Include="Render\RenderBuildingWall.cs" />
@@ -215,7 +214,6 @@
<Compile Include="Invulnerable.cs" />
<Compile Include="ReplaceWithActor.cs" />
<Compile Include="OreRefineryDockAction.cs" />
<Compile Include="ProducesHelicopters.cs" />
<Compile Include="StoresOre.cs" />
<Compile Include="PaletteFromCurrentTheatre.cs" />
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />

View File

@@ -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<UnitInfluence>().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<RallyPoint>();
if( rp != null )
{
newUnit.QueueActivity( new Activities.HeliFly( Util.CenterOfCell(rp.rallyPoint)) );
}
foreach (var t in self.traits.WithInterface<INotifyProduction>())
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;
}
}
}

View File

@@ -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<BuildingInfo>().WaterBound);
}
public override int CreationFacing(Actor self, Actor newUnit)
{
return Util.GetFacing(newUnit.CenterLocation - self.CenterLocation, 128);
}
*/
}
}

View File

@@ -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<UnitInfluence>().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<RallyPoint>();
if( rp != null )
{
newUnit.QueueActivity( new Activities.HeliFly( Util.CenterOfCell(rp.rallyPoint)) );
}
foreach (var t in self.traits.WithInterface<INotifyProduction>())
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;
}
}
}

View File

@@ -342,8 +342,8 @@ HPAD:
RevealsShroud:
Range: 5
Bib:
ProducesHelicopters:
SpawnOffsets: 0,-4
ReservableProduction:
SpawnOffsets: 0,-6
ExitCells: 0,0
Produces: Plane
BelowUnits:

View File

@@ -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: