Merge pull request #2911 from chrisforbes/mcv-crate-bugfix

fix MCV crate not being given if normal SelectionShares was zero
This commit is contained in:
Matthias Mailänder
2013-04-01 03:26:35 -07:00
2 changed files with 10 additions and 4 deletions

View File

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

View File

@@ -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<BuildableInfo>();
// 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);
}