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; if (transport == null || !transport.IsInWorld) return NextActivity;
var cargo = transport.Trait<Cargo>(); var cargo = transport.Trait<Cargo>();
if (cargo.IsFull(transport)) if (!cargo.HasSpace(1))
return NextActivity; return NextActivity;

View File

@@ -17,7 +17,8 @@ namespace OpenRA.Mods.RA
{ {
public class CargoInfo : ITraitInfo 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 string[] Types = { };
public readonly int UnloadFacing = 0; public readonly int UnloadFacing = 0;
@@ -28,7 +29,8 @@ namespace OpenRA.Mods.RA
{ {
readonly Actor self; readonly Actor self;
readonly CargoInfo info; readonly CargoInfo info;
int totalWeight = 0;
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; } }
@@ -101,8 +103,8 @@ namespace OpenRA.Mods.RA
if (order.OrderString != "Unload" || IsEmpty(self)) return null; if (order.OrderString != "Unload" || IsEmpty(self)) return null;
return "Move"; 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 bool IsEmpty(Actor self) { return cargo.Count == 0; }
public Actor Peek(Actor self) { return cargo[0]; } public Actor Peek(Actor self) { return cargo[0]; }
@@ -111,22 +113,42 @@ namespace OpenRA.Mods.RA
{ {
var a = cargo[0]; var a = cargo[0];
cargo.RemoveAt(0); cargo.RemoveAt(0);
var pi = a.Info.Traits.GetOrDefault<PassengerInfo>();
totalWeight -= pi != null ? pi.Weight : 1;
return a; return a;
} }
public IEnumerable<PipType> GetPips( Actor self ) public IEnumerable<PipType> GetPips(Actor self)
{ {
var numPips = info.Passengers; int numPips = info.PipCount;
for (var i = 0; i < numPips; i++)
if (i >= cargo.Count) for (int i = 0; i < numPips; i++)
yield return PipType.Transparent; 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 else
yield return cargo[i].Trait<Passenger>().ColorOfCargoPip(); n -= pi.Weight;
}
return PipType.Transparent;
} }
public void Load(Actor self, Actor a) public void Load(Actor self, Actor a)
{ {
cargo.Add(a); cargo.Add(a);
var pi = a.Info.Traits.GetOrDefault<PassengerInfo>();
totalWeight += pi != null ? pi.Weight : 1;
} }
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)

View File

@@ -21,6 +21,7 @@ namespace OpenRA.Mods.RA
{ {
public readonly string CargoType = null; public readonly string CargoType = null;
public readonly PipType PipType = PipType.Green; public readonly PipType PipType = PipType.Green;
public int Weight = 1;
public object Create( ActorInitializer init ) { return new Passenger( this ); } public object Create( ActorInitializer init ) { return new Passenger( this ); }
} }
@@ -56,7 +57,7 @@ namespace OpenRA.Mods.RA
bool CanEnter( Actor target ) bool CanEnter( Actor target )
{ {
var cargo = target.TraitOrDefault<Cargo>(); 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) public string VoicePhraseForOrder(Actor self, Order order)
@@ -81,7 +82,5 @@ namespace OpenRA.Mods.RA
self.QueueActivity(new EnterTransport(self, order.TargetActor)); self.QueueActivity(new EnterTransport(self, order.TargetActor));
} }
} }
public PipType ColorOfCargoPip() { return info.PipType; }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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