fixed 771 -- adds Passenger.Weight, Cargo.MaxWeight, Cargo.PipCount
This commit is contained in:
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (transport == null || !transport.IsInWorld) return NextActivity;
|
||||
|
||||
var cargo = transport.Trait<Cargo>();
|
||||
if (cargo.IsFull(transport))
|
||||
if (!cargo.HasSpace(1))
|
||||
return NextActivity;
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class CargoInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Passengers = 0;
|
||||
public readonly int MaxWeight = 0;
|
||||
public readonly int PipCount = 0;
|
||||
public readonly string[] Types = { };
|
||||
public readonly int UnloadFacing = 0;
|
||||
|
||||
@@ -28,7 +29,8 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly CargoInfo info;
|
||||
|
||||
|
||||
int totalWeight = 0;
|
||||
List<Actor> cargo = new List<Actor>();
|
||||
public IEnumerable<Actor> Passengers { get { return cargo; } }
|
||||
|
||||
@@ -101,8 +103,8 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString != "Unload" || IsEmpty(self)) return null;
|
||||
return "Move";
|
||||
}
|
||||
|
||||
public bool IsFull(Actor self) { return cargo.Count == info.Passengers; }
|
||||
|
||||
public bool HasSpace(int weight) { return totalWeight + weight <= info.MaxWeight; }
|
||||
public bool IsEmpty(Actor self) { return cargo.Count == 0; }
|
||||
|
||||
public Actor Peek(Actor self) { return cargo[0]; }
|
||||
@@ -111,22 +113,42 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var a = cargo[0];
|
||||
cargo.RemoveAt(0);
|
||||
|
||||
var pi = a.Info.Traits.GetOrDefault<PassengerInfo>();
|
||||
totalWeight -= pi != null ? pi.Weight : 1;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
public IEnumerable<PipType> GetPips( Actor self )
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
var numPips = info.Passengers;
|
||||
for (var i = 0; i < numPips; i++)
|
||||
if (i >= cargo.Count)
|
||||
yield return PipType.Transparent;
|
||||
int numPips = info.PipCount;
|
||||
|
||||
for (int i = 0; i < numPips; i++)
|
||||
yield return GetPipAt(i);
|
||||
}
|
||||
|
||||
PipType GetPipAt(int i)
|
||||
{
|
||||
var n = i * info.MaxWeight / info.PipCount;
|
||||
|
||||
foreach (var c in cargo)
|
||||
{
|
||||
var pi = c.Info.Traits.Get<PassengerInfo>();
|
||||
if (n < pi.Weight)
|
||||
return pi.PipType;
|
||||
else
|
||||
yield return cargo[i].Trait<Passenger>().ColorOfCargoPip();
|
||||
n -= pi.Weight;
|
||||
}
|
||||
|
||||
return PipType.Transparent;
|
||||
}
|
||||
|
||||
public void Load(Actor self, Actor a)
|
||||
{
|
||||
cargo.Add(a);
|
||||
var pi = a.Info.Traits.GetOrDefault<PassengerInfo>();
|
||||
totalWeight += pi != null ? pi.Weight : 1;
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public readonly string CargoType = null;
|
||||
public readonly PipType PipType = PipType.Green;
|
||||
public int Weight = 1;
|
||||
|
||||
public object Create( ActorInitializer init ) { return new Passenger( this ); }
|
||||
}
|
||||
@@ -56,7 +57,7 @@ namespace OpenRA.Mods.RA
|
||||
bool CanEnter( Actor target )
|
||||
{
|
||||
var cargo = target.TraitOrDefault<Cargo>();
|
||||
return (cargo != null && !cargo.IsFull(target));
|
||||
return cargo != null && cargo.HasSpace(info.Weight);
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
@@ -81,7 +82,5 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(new EnterTransport(self, order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
public PipType ColorOfCargoPip() { return info.PipType; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user