Add a WarnCrush method to ICrushable which is called when a crusher begins to enter the cell.
This commit is contained in:
@@ -142,6 +142,7 @@ namespace OpenRA.Traits
|
||||
public interface ICrushable
|
||||
{
|
||||
void OnCrush(Actor crusher);
|
||||
void WarnCrush(Actor crusher);
|
||||
bool CrushableBy(string[] crushClasses, Player owner);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WarnCrush(Actor crusher) {}
|
||||
|
||||
public bool CrushableBy(string[] crushClasses, Player crushOwner)
|
||||
{
|
||||
if (crushOwner.Stances[self.Owner] == Stance.Ally)
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace OpenRA.Mods.RA
|
||||
this.Info = info;
|
||||
}
|
||||
|
||||
public void WarnCrush(Actor crusher) {}
|
||||
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
var shares = self.TraitsImplementing<CrateAction>().Select(
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace OpenRA.Mods.RA
|
||||
this.location = init.Get<LocationInit,int2>();
|
||||
}
|
||||
|
||||
public void WarnCrush(Actor crusher) {}
|
||||
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
if (crusher.HasTrait<MineImmune>() || self.Owner.Stances[crusher.Owner] == Stance.Ally)
|
||||
|
||||
@@ -329,6 +329,17 @@ namespace OpenRA.Mods.RA.Move
|
||||
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)
|
||||
{
|
||||
var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());
|
||||
|
||||
@@ -349,6 +349,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
mobile.Facing,
|
||||
moveFraction - moveFractionTotal );
|
||||
|
||||
mobile.EnteringCell(self);
|
||||
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
|
||||
return ret2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user