add base attack notification

This commit is contained in:
Chris Forbes
2011-12-23 16:30:38 +13:00
parent fdafb9d411
commit 480c35ab58
3 changed files with 51 additions and 0 deletions

View File

@@ -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<Building>())
return;
if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25)
Sound.PlayToPlayer(self.Owner, info.Audio);
lastAttackLocation = self.Location;
lastAttackTime = self.World.FrameNumber;
}
}
}