Make INotifyIdle and INotifyBecomingIdle require explicit implementation

This commit is contained in:
reaperrr
2017-09-07 17:39:47 +02:00
committed by Matthias Mailänder
parent ddfed13db4
commit 761a4f29ab
7 changed files with 20 additions and 7 deletions

View File

@@ -318,7 +318,10 @@ namespace OpenRA.Traits
} }
public interface IRenderOverlay { void Render(WorldRenderer wr); } public interface IRenderOverlay { void Render(WorldRenderer wr); }
[RequireExplicitImplementation]
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); } public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
[RequireExplicitImplementation]
public interface INotifyIdle { void TickIdle(Actor self); } public interface INotifyIdle { void TickIdle(Actor self); }
public interface IRenderAboveWorld { void RenderAboveWorld(Actor self, WorldRenderer wr); } public interface IRenderAboveWorld { void RenderAboveWorld(Actor self, WorldRenderer wr); }

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Scripting
return Triggerables(trigger).Count > 0; return Triggerables(trigger).Count > 0;
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
if (world.Disposing) if (world.Disposing)
return; return;

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
class FlyAwayOnIdle : INotifyIdle class FlyAwayOnIdle : INotifyIdle
{ {
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
self.QueueActivity(new FlyOffMap(self)); self.QueueActivity(new FlyOffMap(self));
self.QueueActivity(new RemoveSelf()); self.QueueActivity(new RemoveSelf());

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
aircraftInfo = self.Info.TraitInfo<AircraftInfo>(); aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
// We're on the ground, let's stay there. // We're on the ground, let's stay there.
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude) if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude)

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(TargetLocation.Value, 1))); self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(TargetLocation.Value, 1)));
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
// This might cause the actor to be stuck if the target location is unreachable // This might cause the actor to be stuck if the target location is unreachable
if (TargetLocation.HasValue && self.Location != TargetLocation.Value) if (TargetLocation.HasValue && self.Location != TargetLocation.Value)

View File

@@ -188,7 +188,7 @@ namespace OpenRA.Mods.Common.Traits
Attack(self, Aggressor, allowMove); Attack(self, Aggressor, allowMove);
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
if (IsTraitDisabled || Stance < UnitStance.Defend) if (IsTraitDisabled || Stance < UnitStance.Defend)
return; return;

View File

@@ -57,12 +57,17 @@ namespace OpenRA.Mods.Common.Traits
base.Created(self); base.Created(self);
} }
public virtual void OnBecomingIdle(Actor self) protected virtual void OnBecomingIdle(Actor self)
{ {
countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay); countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay);
} }
public virtual void TickIdle(Actor self) void INotifyBecomingIdle.OnBecomingIdle(Actor self)
{
OnBecomingIdle(self);
}
protected virtual void TickIdle(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;
@@ -83,6 +88,11 @@ namespace OpenRA.Mods.Common.Traits
DoAction(self, targetCell); DoAction(self, targetCell);
} }
void INotifyIdle.TickIdle(Actor self)
{
TickIdle(self);
}
CPos PickTargetLocation() CPos PickTargetLocation()
{ {
var target = self.CenterPosition + new WVec(0, -1024 * effectiveMoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255))); var target = self.CenterPosition + new WVec(0, -1024 * effectiveMoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255)));