Merge pull request #5696 from Mailaender/emit-cargo-on-sell

Finished EmitCargoOnSell
This commit is contained in:
Paul Chote
2014-07-05 12:30:29 +12:00
4 changed files with 25 additions and 40 deletions

View File

@@ -23,11 +23,12 @@ namespace OpenRA.Mods.RA
public readonly int PipCount = 0;
public readonly string[] Types = { };
public readonly string[] InitialUnits = { };
public readonly bool EjectOnSell = true;
public object Create(ActorInitializer init) { return new Cargo(init, this); }
}
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled, INotifyCapture, ITick
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled, INotifyCapture, ITick, INotifySold
{
readonly Actor self;
public readonly CargoInfo Info;
@@ -190,6 +191,26 @@ namespace OpenRA.Mods.RA
cargo.Clear();
}
public void Selling(Actor self) { }
public void Sold(Actor self)
{
if (!Info.EjectOnSell || cargo == null)
return;
while (!IsEmpty(self))
SpawnPassenger(Unload(self));
}
void SpawnPassenger(Actor passenger)
{
self.World.AddFrameEndTask(w =>
{
w.Add(passenger);
passenger.Trait<IPositionable>().SetPosition(passenger, self.Location);
// TODO: this won't work well for >1 actor as they should move towards the next enterable (sub) cell instead
});
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
if (cargo == null)

View File

@@ -1,30 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
// for some reason I get yelled at for pbox.e1 not having Cargo, but that's a lie?
class EmitCargoOnSellInfo : TraitInfo<EmitCargoOnSell>//, Requires<Cargo>
{
}
class EmitCargoOnSell : INotifySold
{
static void Emit(Actor self)
{
// TODO: would like to spill all actors out similar to how we call Unload
}
public void Selling(Actor self) { Emit(self); }
public void Sold(Actor self) { }
}
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
public readonly string[] ActorTypes = { "e1" };
}
class EmitInfantryOnSell : INotifySold, INotifyKilled
class EmitInfantryOnSell : INotifySold
{
public void Selling(Actor self) { }
@@ -61,10 +61,5 @@ namespace OpenRA.Mods.RA
}
public void Sold(Actor self) { Emit(self); }
public void Killed(Actor self, AttackInfo e)
{
Emit(self);
}
}
}

View File

@@ -229,7 +229,6 @@
<Compile Include="Effects\SatelliteLaunch.cs" />
<Compile Include="Effects\Smoke.cs" />
<Compile Include="Effects\TeslaZap.cs" />
<Compile Include="EmitCargoOnSell.cs" />
<Compile Include="EmitInfantryOnSell.cs" />
<Compile Include="EngineerRepair.cs" />
<Compile Include="Explodes.cs" />