Merge pull request #10564 from abcdefg30/botUnderAttack

Added support for playing a "Our ally is under attack" notification
This commit is contained in:
Oliver Brakmann
2016-01-26 23:20:41 +01:00
3 changed files with 20 additions and 9 deletions

View File

@@ -28,6 +28,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The audio notification type to play.")]
public string Notification = "BaseAttack";
[Desc("The audio notification to play to allies when under attack.",
"Won't play a notification to allies if this is null.")]
public string AllyNotification = null;
public object Create(ActorInitializer init) { return new BaseAttackNotifier(init.Self, this); }
}
@@ -47,10 +51,6 @@ namespace OpenRA.Mods.Common.Traits
public void Damaged(Actor self, AttackInfo e)
{
// only track last hit against our base
if (!self.Info.HasTraitInfo<BuildingInfo>())
return;
if (e.Attacker == null)
return;
@@ -60,12 +60,22 @@ namespace OpenRA.Mods.Common.Traits
if (e.Attacker == self.World.WorldActor)
return;
// Only track last hit against our base
if (!self.Info.HasTraitInfo<BuildingInfo>())
return;
if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0)
return;
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
{
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
var rules = self.World.Map.Rules;
Game.Sound.PlayNotification(rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
if (info.AllyNotification != null)
foreach (Player p in self.World.Players)
if (p != self.Owner && p.IsAlliedWith(self.Owner) && p != e.Attacker.Owner)
Game.Sound.PlayNotification(rules, p, "Speech", info.AllyNotification, p.Faction.InternalName);
if (radarPings != null)
radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);

View File

@@ -47,12 +47,12 @@ namespace OpenRA.Mods.Common.Traits
public void Damaged(Actor self, AttackInfo e)
{
// only track last hit against our harvesters
if (!self.Info.HasTraitInfo<HarvesterInfo>())
// Don't track self-damage
if (e.Attacker != null && e.Attacker.Owner == self.Owner)
return;
// don't track self-damage
if (e.Attacker != null && e.Attacker.Owner == self.Owner)
// Only track last hit against our harvesters
if (!self.Info.HasTraitInfo<HarvesterInfo>())
return;
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)

View File

@@ -44,6 +44,7 @@ Player:
Shroud:
FrozenActorLayer:
BaseAttackNotifier:
AllyNotification: OurAllyIsUnderAttack
HarvesterAttackNotifier:
PlayerStatistics:
PlaceBeacon: