cleanup cargo, remove some traitcalls

This commit is contained in:
Chris Forbes
2011-04-23 10:58:46 +12:45
parent 24798adf72
commit 60ce83e696
3 changed files with 16 additions and 35 deletions

View File

@@ -21,19 +21,18 @@ namespace OpenRA.Mods.RA
public readonly string[] Types = { }; public readonly string[] Types = { };
public readonly int UnloadFacing = 0; public readonly int UnloadFacing = 0;
public object Create( ActorInitializer init ) { return new Cargo( init.self ); } public object Create( ActorInitializer init ) { return new Cargo( init.self, this ); }
} }
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled
{ {
readonly Actor self; readonly Actor self;
readonly CargoInfo info;
List<Actor> cargo = new List<Actor>(); List<Actor> cargo = new List<Actor>();
public IEnumerable<Actor> Passengers { get { return cargo; } } public IEnumerable<Actor> Passengers { get { return cargo; } }
public Cargo( Actor self ) public Cargo( Actor self, CargoInfo info ) { this.self = self; this.info = info; }
{
this.self = self;
}
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
{ {
@@ -103,20 +102,10 @@ namespace OpenRA.Mods.RA
return "Move"; return "Move";
} }
public bool IsFull(Actor self) public bool IsFull(Actor self) { return cargo.Count == info.Passengers; }
{ public bool IsEmpty(Actor self) { return cargo.Count == 0; }
return cargo.Count == self.Info.Traits.Get<CargoInfo>().Passengers;
}
public bool IsEmpty(Actor self) public Actor Peek(Actor self) { return cargo[0]; }
{
return cargo.Count == 0;
}
public Actor Peek(Actor self)
{
return cargo[0];
}
public Actor Unload(Actor self) public Actor Unload(Actor self)
{ {
@@ -127,17 +116,12 @@ namespace OpenRA.Mods.RA
public IEnumerable<PipType> GetPips( Actor self ) public IEnumerable<PipType> GetPips( Actor self )
{ {
var numPips = self.Info.Traits.Get<CargoInfo>().Passengers; var numPips = info.Passengers;
for (var i = 0; i < numPips; i++) for (var i = 0; i < numPips; i++)
if (i >= cargo.Count) if (i >= cargo.Count)
yield return PipType.Transparent; yield return PipType.Transparent;
else else
yield return GetPipForPassenger(cargo[i]); yield return cargo[i].Trait<Passenger>().ColorOfCargoPip();
}
static PipType GetPipForPassenger(Actor a)
{
return a.Trait<Passenger>().ColorOfCargoPip( a );
} }
public void Load(Actor self, Actor a) public void Load(Actor self, Actor a)

View File

@@ -13,26 +13,25 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Orders; using OpenRA.Mods.RA.Orders;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class PassengerInfo : ITraitInfo public class PassengerInfo : ITraitInfo
{ {
public readonly string CargoType = null; public readonly string CargoType = null;
public readonly PipType PipType = PipType.Green; public readonly PipType PipType = PipType.Green;
public object Create( ActorInitializer init ) { return new Passenger( init.self, this ); } public object Create( ActorInitializer init ) { return new Passenger( this ); }
} }
public class Passenger : IIssueOrder, IResolveOrder, IOrderVoice public class Passenger : IIssueOrder, IResolveOrder, IOrderVoice
{ {
readonly Actor self;
readonly PassengerInfo info; readonly PassengerInfo info;
public Passenger( Actor self, PassengerInfo info ) { this.self = self; this.info = info; } public Passenger( PassengerInfo info ) { this.info = info; }
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
{ {
@@ -80,13 +79,12 @@ namespace OpenRA.Mods.RA
self.SetTargetLine(Target.FromOrder(order), Color.Green); self.SetTargetLine(Target.FromOrder(order), Color.Green);
var mobile = self.Trait<Mobile>();
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new MoveAdjacentTo(order.TargetActor)); self.QueueActivity(new MoveAdjacentTo(order.TargetActor));
self.QueueActivity(new EnterTransport(self, order.TargetActor)); self.QueueActivity(new EnterTransport(self, order.TargetActor));
} }
} }
public PipType ColorOfCargoPip( Actor self ) { return info.PipType; } public PipType ColorOfCargoPip() { return info.PipType; }
} }
} }

View File

@@ -11,10 +11,9 @@
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {