diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index 07bb3b5cef..3f9ff05acf 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("This actor can transport Passenger actors.")] - public class CargoInfo : ITraitInfo, Requires + public class CargoInfo : ITraitInfo, Requires, Requires { [Desc("The maximum sum of Passenger.Weight that this actor can support.")] public readonly int MaxWeight = 0; @@ -51,6 +51,10 @@ namespace OpenRA.Mods.Common.Traits [Desc("Cursor to display when unable to unload the passengers.")] public readonly string UnloadBlockedCursor = "deploy-blocked"; + [UpgradeGrantedReference] + [Desc("The upgrades to grant to self while loading cargo.")] + public readonly string[] LoadingUpgrades = { }; + public object Create(ActorInitializer init) { return new Cargo(init, this); } } @@ -59,6 +63,7 @@ namespace OpenRA.Mods.Common.Traits { public readonly CargoInfo Info; readonly Actor self; + readonly UpgradeManager upgradeManager; readonly Stack cargo = new Stack(); readonly HashSet reserves = new HashSet(); readonly Lazy facing; @@ -80,6 +85,7 @@ namespace OpenRA.Mods.Common.Traits Info = info; Unloading = false; checkTerrainType = info.UnloadTerrainTypes.Count > 0; + upgradeManager = self.Trait(); if (init.Contains()) { @@ -183,6 +189,10 @@ namespace OpenRA.Mods.Common.Traits if (!HasSpace(w)) return false; + if (reserves.Count == 0) + foreach (var u in Info.LoadingUpgrades) + upgradeManager.GrantUpgrade(self, u, this); + reserves.Add(a); reservedWeight += w; @@ -196,6 +206,10 @@ namespace OpenRA.Mods.Common.Traits reservedWeight -= GetWeight(a); reserves.Remove(a); + + if (reserves.Count == 0) + foreach (var u in Info.LoadingUpgrades) + upgradeManager.RevokeUpgrade(self, u, this); } public string CursorForOrder(Actor self, Order order) @@ -235,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits p.Transport = null; foreach (var u in p.Info.GrantUpgrades) - self.Trait().RevokeUpgrade(self, u, p); + upgradeManager.RevokeUpgrade(self, u, p); return a; } @@ -287,6 +301,10 @@ namespace OpenRA.Mods.Common.Traits { reservedWeight -= w; reserves.Remove(a); + + if (reserves.Count == 0) + foreach (var u in Info.LoadingUpgrades) + upgradeManager.RevokeUpgrade(self, u, this); } foreach (var npe in self.TraitsImplementing()) @@ -295,7 +313,7 @@ namespace OpenRA.Mods.Common.Traits var p = a.Trait(); p.Transport = self; foreach (var u in p.Info.GrantUpgrades) - self.Trait().GrantUpgrade(self, u, p); + upgradeManager.GrantUpgrade(self, u, p); } public void Killed(Actor self, AttackInfo e)