diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 2b36e821a8..b24ef66839 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -360,6 +360,7 @@ + diff --git a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs new file mode 100644 index 0000000000..7c53fa5466 --- /dev/null +++ b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs @@ -0,0 +1,49 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class BaseAttackNotifierInfo : ITraitInfo + { + public readonly int NotifyInterval = 30; /* seconds */ + public readonly string Audio = "baseatk1.aud"; + + public object Create(ActorInitializer init) { return new BaseAttackNotifier(this); } + } + + public class BaseAttackNotifier : INotifyDamage + { + BaseAttackNotifierInfo info; + + public int lastAttackTime; + public int2 lastAttackLocation; + + public BaseAttackNotifier(BaseAttackNotifierInfo info) { this.info = info; } + + public void Damaged(Actor self, AttackInfo e) + { + /* only track last hit against our base */ + if (!self.HasTrait()) + return; + + if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25) + Sound.PlayToPlayer(self.Owner, info.Audio); + + lastAttackLocation = self.Location; + lastAttackTime = self.World.FrameNumber; + } + } +} + diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 269a9e2054..e2af9b95bd 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -135,6 +135,7 @@ Player: DebugResourceOre: DebugResourceOreCapacity: GpsWatcher: + BaseAttackNotifier: World: OpenWidgetAtGameStart: