diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index 77d9656bff..bfbeed797e 100644 --- a/OpenRA.Mods.RA/Activities/Transform.cs +++ b/OpenRA.Mods.RA/Activities/Transform.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA.Activities var cargo = self.TraitOrDefault(); if (cargo != null) - init.Add( new CargoInit( cargo.Passengers.ToArray() ) ); + init.Add( new RuntimeCargoInit( cargo.Passengers.ToArray() ) ); var a = w.CreateActor( ToActor, init ); diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 49b1fef38a..8df6a3270b 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -44,9 +44,21 @@ namespace OpenRA.Mods.RA self = init.self; Info = info; - if (init.Contains()) + if (init.Contains()) { - cargo = init.Get().ToList(); + cargo = init.Get().ToList(); + totalWeight = cargo.Sum(c => GetWeight(c)); + } + else if (init.Contains()) + { + foreach (var u in init.Get()) + { + var unit = self.World.CreateActor(false, u.ToLowerInvariant(), + new TypeDictionary { new OwnerInit(self.Owner) }); + + cargo.Add(unit); + } + totalWeight = cargo.Sum(c => GetWeight(c)); } else @@ -56,9 +68,10 @@ namespace OpenRA.Mods.RA var unit = self.World.CreateActor(false, u.ToLowerInvariant(), new TypeDictionary { new OwnerInit(self.Owner) }); - if (CanLoad(self, unit)) - Load(self, unit); + cargo.Add(unit); } + + totalWeight = cargo.Sum(c => GetWeight(c)); } } @@ -186,8 +199,19 @@ namespace OpenRA.Mods.RA }); } + bool initialized; public void Tick(Actor self) { + // Notify initial cargo load + if (!initialized) + { + foreach (var npe in self.TraitsImplementing()) + foreach (var c in cargo) + npe.PassengerEntered(self, c); + + initialized = true; + } + var cell = self.CenterPosition.ToCPos(); if (currentCell != cell) { @@ -200,12 +224,21 @@ namespace OpenRA.Mods.RA public interface INotifyPassengerEntered { void PassengerEntered(Actor self, Actor passenger); } public interface INotifyPassengerExited { void PassengerExited(Actor self, Actor passenger); } - public class CargoInit : IActorInit + public class RuntimeCargoInit : IActorInit { [FieldFromYamlKey] public readonly Actor[] value = { }; - public CargoInit() { } - public CargoInit(Actor[] init) { value = init; } + public RuntimeCargoInit() { } + public RuntimeCargoInit(Actor[] init) { value = init; } public Actor[] Value(World world) { return value; } } + + public class CargoInit : IActorInit + { + [FieldFromYamlKey] + public readonly string[] value = { }; + public CargoInit() { } + public CargoInit(string[] init) { value = init; } + public string[] Value(World world) { return value; } + } }