Add a WarnCrush method to ICrushable which is called when a crusher begins to enter the cell.

This commit is contained in:
Paul Chote
2011-06-26 15:31:07 +12:00
parent 74d13286a8
commit 19ead53223
6 changed files with 20 additions and 1 deletions

View File

@@ -142,6 +142,7 @@ namespace OpenRA.Traits
public interface ICrushable public interface ICrushable
{ {
void OnCrush(Actor crusher); void OnCrush(Actor crusher);
void WarnCrush(Actor crusher);
bool CrushableBy(string[] crushClasses, Player owner); bool CrushableBy(string[] crushClasses, Player owner);
} }

View File

@@ -31,7 +31,9 @@ namespace OpenRA.Mods.RA.Buildings
this.self = self; this.self = self;
this.info = info; this.info = info;
} }
public void WarnCrush(Actor crusher) {}
public bool CrushableBy(string[] crushClasses, Player crushOwner) public bool CrushableBy(string[] crushClasses, Player crushOwner)
{ {
if (crushOwner.Stances[self.Owner] == Stance.Ally) if (crushOwner.Stances[self.Owner] == Stance.Ally)

View File

@@ -56,6 +56,8 @@ namespace OpenRA.Mods.RA
this.Info = info; this.Info = info;
} }
public void WarnCrush(Actor crusher) {}
public void OnCrush(Actor crusher) public void OnCrush(Actor crusher)
{ {
var shares = self.TraitsImplementing<CrateAction>().Select( var shares = self.TraitsImplementing<CrateAction>().Select(

View File

@@ -40,6 +40,8 @@ namespace OpenRA.Mods.RA
this.location = init.Get<LocationInit,int2>(); this.location = init.Get<LocationInit,int2>();
} }
public void WarnCrush(Actor crusher) {}
public void OnCrush(Actor crusher) public void OnCrush(Actor crusher)
{ {
if (crusher.HasTrait<MineImmune>() || self.Owner.Stances[crusher.Owner] == Stance.Ally) if (crusher.HasTrait<MineImmune>() || self.Owner.Stances[crusher.Owner] == Stance.Ally)

View File

@@ -329,6 +329,17 @@ namespace OpenRA.Mods.RA.Move
return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors); return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors);
} }
public void EnteringCell(Actor self)
{
var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());
foreach (var a in crushable)
{
var crushActions = a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner));
foreach (var b in crushActions)
b.WarnCrush(self);
}
}
public void FinishedMoving(Actor self) public void FinishedMoving(Actor self)
{ {
var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>()); var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());

View File

@@ -349,6 +349,7 @@ namespace OpenRA.Mods.RA.Move
mobile.Facing, mobile.Facing,
moveFraction - moveFractionTotal ); moveFraction - moveFractionTotal );
mobile.EnteringCell(self);
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell ); mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
return ret2; return ret2;
} }