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

@@ -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;
}
}
}