diff --git a/OpenRA.Mods.RA/Crates/GiveMcvCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveMcvCrateAction.cs index 164580ed83..47622bfeac 100644 --- a/OpenRA.Mods.RA/Crates/GiveMcvCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveMcvCrateAction.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Crates public override int GetSelectionShares(Actor collector) { - if (base.GetSelectionShares(collector) == 0) + if (!CanGiveTo(collector)) return 0; // there's some other really good reason why we shouldn't give this. var hasBase = self.World.ActorsWithTrait() diff --git a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs index e9d04e8afe..d00e62e8ac 100644 --- a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs @@ -32,17 +32,23 @@ namespace OpenRA.Mods.RA.Crates public GiveUnitCrateAction(Actor self, GiveUnitCrateActionInfo info) : base(self, info) { Info = info; } - public override int GetSelectionShares(Actor collector) + public bool CanGiveTo(Actor collector) { var bi = Rules.Info[Info.Unit].Traits.GetOrDefault(); // this unit is not buildable by the collector's country, so // don't give them free ones either. - if (Info.Owner == null && bi != null && !bi.Owner.Contains(collector.Owner.Country.Race)) return 0; + if (Info.Owner == null && bi != null && !bi.Owner.Contains(collector.Owner.Country.Race)) return false; // avoid dumping tanks in the sea, and ships on dry land. - if (!GetSuitableCells(collector.Location).Any()) return 0; + if (!GetSuitableCells(collector.Location).Any()) return false; + return true; + } + + public override int GetSelectionShares(Actor collector) + { + if (!CanGiveTo(collector)) return 0; return base.GetSelectionShares(collector); }