fixed 771 -- adds Passenger.Weight, Cargo.MaxWeight, Cargo.PipCount

This commit is contained in:
Chris Forbes
2011-05-30 20:09:22 +12:00
parent faf0ea387f
commit 24586ac056
9 changed files with 51 additions and 23 deletions

View File

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

View File

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

View File

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

View File

@@ -32,7 +32,8 @@ TRAN:
WithShadow:
Cargo:
Types: Infantry
Passengers: 5
MaxWeight: 5
PipCount: 5
FallsToEarth:
HELI:
@@ -119,7 +120,8 @@ C17:
WithShadow:
Cargo:
# Types: Infantry, Vehicle
Passengers: 10
MaxWeight: 10
PipCount: 10
Invulnerable:
-Selectable:
-TargetableUnit:

View File

@@ -58,7 +58,8 @@ LST:
-Selectable:
Cargo:
Types: Infantry, Vehicle
Passengers: 5
MaxWeight: 5
PipCount: 5
AttackMove:
JustMove: true

View File

@@ -100,7 +100,7 @@ APC:
AutoTarget:
Cargo:
Types: Infantry
Passengers: 5
MaxWeight: 5
UnloadFacing: 220
LeavesHusk:
HuskActor: APC.Husk

View File

@@ -14,7 +14,7 @@ BADR:
WithShadow:
IronCurtainable:
Cargo:
Passengers: 10
MaxWeight: 10
# Types: Infantry, Vehicle
-Selectable:
-GainsExperience:
@@ -212,7 +212,8 @@ TRAN:
WithShadow:
Cargo:
Types: Infantry
Passengers: 5
MaxWeight: 5
PipCount: 5
IronCurtainable:
FallsToEarth:
Explosion: UnitExplode

View File

@@ -190,7 +190,8 @@ LST:
RenderUnit:
Cargo:
Types: Infantry, Vehicle
Passengers: 5
MaxWeight: 5
PipCount: 5
IronCurtainable:
RepairableNear:
AttackMove:

View File

@@ -293,7 +293,8 @@ JEEP:
AutoTarget:
Cargo:
Types: Infantry
Passengers: 1
MaxWeight: 1
PipCount: 1
UnloadFacing: 220
APC:
@@ -324,7 +325,8 @@ APC:
AutoTarget:
Cargo:
Types: Infantry
Passengers: 5
MaxWeight: 5
PipCount: 5
UnloadFacing: 220
MNLY.AP: