Make the ICrushable implementation explicit

This commit is contained in:
abcdefg30
2016-01-22 11:01:26 +01:00
parent 8b59ce4dc2
commit f21d1f52e7
3 changed files with 15 additions and 8 deletions

View File

@@ -61,7 +61,8 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
{ {
if (!CrushableBy(crushClasses, crusher.Owner)) // Crate can only be crushed if it is not in the air.
if (!self.IsAtGroundLevel() || !crushClasses.Contains(info.CrushClass))
return; return;
OnCrushInner(crusher); OnCrushInner(crusher);
@@ -84,7 +85,8 @@ namespace OpenRA.Mods.Common.Traits
return false; return false;
// Make sure that the actor can collect this crate type // Make sure that the actor can collect this crate type
return CrushableBy(mi.Crushes, a.Owner); // Crate can only be crushed if it is not in the air.
return self.IsAtGroundLevel() && mi.Crushes.Contains(info.CrushClass);
}); });
// Destroy the crate if none of the units in the cell are valid collectors // Destroy the crate if none of the units in the cell are valid collectors
@@ -196,7 +198,7 @@ namespace OpenRA.Mods.Common.Traits
return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid; return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid;
} }
public bool CrushableBy(HashSet<string> crushClasses, Player owner) bool ICrushable.CrushableBy(HashSet<string> crushClasses, Player owner)
{ {
// Crate can only be crushed if it is not in the air. // Crate can only be crushed if it is not in the air.
return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass); return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass);

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
{ {
if (!CrushableBy(crushClasses, crusher.Owner)) if (!CrushableInner(crushClasses, crusher.Owner))
return; return;
var mobile = self.TraitOrDefault<Mobile>(); var mobile = self.TraitOrDefault<Mobile>();
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
{ {
if (!CrushableBy(crushClasses, crusher.Owner)) if (!CrushableInner(crushClasses, crusher.Owner))
return; return;
Game.Sound.Play(info.CrushSound, crusher.CenterPosition); Game.Sound.Play(info.CrushSound, crusher.CenterPosition);
@@ -71,7 +71,12 @@ namespace OpenRA.Mods.Common.Traits
self.Kill(crusher); self.Kill(crusher);
} }
public bool CrushableBy(HashSet<string> crushClasses, Player crushOwner) bool ICrushable.CrushableBy(HashSet<string> crushClasses, Player crushOwner)
{
return CrushableInner(crushClasses, crushOwner);
}
bool CrushableInner(HashSet<string> crushClasses, Player crushOwner)
{ {
// Only make actor crushable if it is on the ground. // Only make actor crushable if it is on the ground.
if (!self.IsAtGroundLevel()) if (!self.IsAtGroundLevel())

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Traits
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
{ {
if (!CrushableBy(crushClasses, crusher.Owner)) if (!info.CrushClasses.Overlaps(crushClasses))
return; return;
if (crusher.Info.HasTraitInfo<MineImmuneInfo>() || (self.Owner.Stances[crusher.Owner] == Stance.Ally && info.AvoidFriendly)) if (crusher.Info.HasTraitInfo<MineImmuneInfo>() || (self.Owner.Stances[crusher.Owner] == Stance.Ally && info.AvoidFriendly))
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Traits
self.Kill(crusher); self.Kill(crusher);
} }
public bool CrushableBy(HashSet<string> crushClasses, Player owner) bool ICrushable.CrushableBy(HashSet<string> crushClasses, Player owner)
{ {
return info.CrushClasses.Overlaps(crushClasses); return info.CrushClasses.Overlaps(crushClasses);
} }