notifications (formerly EVAalerts) centralized and race specific
outsourced into notifications.yaml triggered with PlayNotification(...) (v2: less redundant code for PlayVoice/Notifications) added harvester under attack and battlecontrol terminated
This commit is contained in:
committed by
Chris Forbes
parent
5fee165692
commit
7a578a0679
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2012 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,
|
||||
@@ -17,9 +17,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class BaseAttackNotifierInfo : ITraitInfo
|
||||
{
|
||||
public readonly int NotifyInterval = 30; /* seconds */
|
||||
public readonly string Audio = "baseatk1.aud";
|
||||
public readonly string Race = null;
|
||||
public readonly int NotifyInterval = 30; // seconds
|
||||
|
||||
public object Create(ActorInitializer init) { return new BaseAttackNotifier(this); }
|
||||
}
|
||||
@@ -35,17 +33,16 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (info.Race != null && info.Race != self.Owner.Country.Race) return;
|
||||
/* only track last hit against our base */
|
||||
// only track last hit against our base
|
||||
if (!self.HasTrait<Building>())
|
||||
return;
|
||||
|
||||
/* don't track self-damage */
|
||||
// don't track self-damage
|
||||
if (e.Attacker != null && e.Attacker.Owner == self.Owner)
|
||||
return;
|
||||
|
||||
if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25)
|
||||
Sound.PlayToPlayer(self.Owner, info.Audio);
|
||||
Sound.PlayNotification(self.Owner, "Speech", "BaseAttack", self.Owner.Country.Race);
|
||||
|
||||
lastAttackLocation = self.CenterLocation.ToCPos();
|
||||
lastAttackTime = self.World.FrameNumber;
|
||||
|
||||
52
OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs
Normal file
52
OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2012 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 HarvesterAttackNotifierInfo : ITraitInfo
|
||||
{
|
||||
public readonly int NotifyInterval = 30; // seconds
|
||||
|
||||
public object Create(ActorInitializer init) { return new HarvesterAttackNotifier(this); }
|
||||
}
|
||||
|
||||
public class HarvesterAttackNotifier : INotifyDamage
|
||||
{
|
||||
HarvesterAttackNotifierInfo info;
|
||||
|
||||
public int lastAttackTime = -1;
|
||||
public CPos lastAttackLocation;
|
||||
|
||||
public HarvesterAttackNotifier(HarvesterAttackNotifierInfo info) { this.info = info; }
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
// only track last hit against our base
|
||||
if (!self.HasTrait<Harvester>())
|
||||
return;
|
||||
|
||||
// don't track self-damage
|
||||
if (e.Attacker != null && e.Attacker.Owner == self.Owner)
|
||||
return;
|
||||
|
||||
if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25)
|
||||
Sound.PlayNotification(self.Owner, "Speech", "HarvesterAttack", self.Owner.Country.Race);
|
||||
|
||||
lastAttackLocation = self.CenterLocation.ToCPos();
|
||||
lastAttackTime = self.World.FrameNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
if (GetNumBuildables(self.Owner) > prevItems)
|
||||
w.Add(new DelayedAction(10,
|
||||
() => Sound.PlayToPlayer(order.Player,
|
||||
w.WorldActor.Info.Traits.Get<EvaAlertsInfo>().NewOptions)));
|
||||
() => Sound.PlayNotification(order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user