Merge pull request #7170 from penev92/bleed_enemySightedNotification
Implement "Enemy unit sighted" notification
This commit is contained in:
@@ -307,6 +307,7 @@
|
|||||||
<Compile Include="Traits\Player\BaseAttackNotifier.cs" />
|
<Compile Include="Traits\Player\BaseAttackNotifier.cs" />
|
||||||
<Compile Include="Traits\Player\ClassicProductionQueue.cs" />
|
<Compile Include="Traits\Player\ClassicProductionQueue.cs" />
|
||||||
<Compile Include="Traits\Player\ConquestVictoryConditions.cs" />
|
<Compile Include="Traits\Player\ConquestVictoryConditions.cs" />
|
||||||
|
<Compile Include="Traits\Player\EnemyWatcher.cs" />
|
||||||
<Compile Include="Traits\Player\GlobalUpgradeManager.cs" />
|
<Compile Include="Traits\Player\GlobalUpgradeManager.cs" />
|
||||||
<Compile Include="Traits\Player\MissionObjectives.cs" />
|
<Compile Include="Traits\Player\MissionObjectives.cs" />
|
||||||
<Compile Include="Traits\Player\PlaceBeacon.cs" />
|
<Compile Include="Traits\Player\PlaceBeacon.cs" />
|
||||||
@@ -379,6 +380,7 @@
|
|||||||
<Compile Include="Traits\Sound\ActorLostNotification.cs" />
|
<Compile Include="Traits\Sound\ActorLostNotification.cs" />
|
||||||
<Compile Include="Traits\Sound\AnnounceOnBuild.cs" />
|
<Compile Include="Traits\Sound\AnnounceOnBuild.cs" />
|
||||||
<Compile Include="Traits\Sound\AnnounceOnKill.cs" />
|
<Compile Include="Traits\Sound\AnnounceOnKill.cs" />
|
||||||
|
<Compile Include="Traits\Sound\AnnounceOnSeen.cs" />
|
||||||
<Compile Include="Traits\Sound\DeathSounds.cs" />
|
<Compile Include="Traits\Sound\DeathSounds.cs" />
|
||||||
<Compile Include="Traits\Sound\SoundOnDamageTransition.cs" />
|
<Compile Include="Traits\Sound\SoundOnDamageTransition.cs" />
|
||||||
<Compile Include="Traits\SupportPowers\AirstrikePower.cs" />
|
<Compile Include="Traits\SupportPowers\AirstrikePower.cs" />
|
||||||
|
|||||||
115
OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs
Normal file
115
OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 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 System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("Tracks neutral and enemy actors' visibility and notifies the player.",
|
||||||
|
"Attach this to the player actor.")]
|
||||||
|
class EnemyWatcherInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("Interval in ticks between scanning for enemies.")]
|
||||||
|
public readonly int ScanInterval = 25;
|
||||||
|
|
||||||
|
[Desc("Minimal interval in ticks between notifications.")]
|
||||||
|
public readonly int NotificationInterval = 200;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new EnemyWatcher(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnemyWatcher : ITick
|
||||||
|
{
|
||||||
|
readonly EnemyWatcherInfo info;
|
||||||
|
readonly Lazy<RadarPings> radarPings;
|
||||||
|
|
||||||
|
bool announcedAny;
|
||||||
|
int rescanInterval;
|
||||||
|
int ticksBeforeNextNotification;
|
||||||
|
HashSet<uint> lastKnownActorIds;
|
||||||
|
HashSet<uint> visibleActorIds;
|
||||||
|
HashSet<string> playedNotifications;
|
||||||
|
|
||||||
|
public EnemyWatcher(Actor self, EnemyWatcherInfo info)
|
||||||
|
{
|
||||||
|
lastKnownActorIds = new HashSet<uint>();
|
||||||
|
this.info = info;
|
||||||
|
rescanInterval = info.ScanInterval;
|
||||||
|
ticksBeforeNextNotification = info.NotificationInterval;
|
||||||
|
radarPings = Exts.Lazy(() => self.World.WorldActor.Trait<RadarPings>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(Actor self)
|
||||||
|
{
|
||||||
|
// TODO: Make the AI handle such notifications and remove Owner.IsBot from this check
|
||||||
|
// Disable notifications for AI and neutral players (creeps) and for spectators
|
||||||
|
if (self.Owner.Shroud.Disabled || self.Owner.IsBot || !self.Owner.Playable || self.Owner.PlayerReference.Spectating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rescanInterval--;
|
||||||
|
ticksBeforeNextNotification--;
|
||||||
|
|
||||||
|
if (rescanInterval > 0 || ticksBeforeNextNotification > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rescanInterval = info.ScanInterval;
|
||||||
|
|
||||||
|
announcedAny = false;
|
||||||
|
visibleActorIds = new HashSet<uint>();
|
||||||
|
playedNotifications = new HashSet<string>();
|
||||||
|
|
||||||
|
foreach (var actor in self.World.ActorsWithTrait<AnnounceOnSeen>())
|
||||||
|
{
|
||||||
|
// We only care about enemy actors (creeps should be enemies)
|
||||||
|
if ((actor.Actor.EffectiveOwner != null && self.Owner.Stances[actor.Actor.EffectiveOwner.Owner] != Stance.Enemy)
|
||||||
|
|| self.Owner.Stances[actor.Actor.Owner] != Stance.Enemy)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// The actor is not currently visible
|
||||||
|
if (!self.Owner.Shroud.IsVisible(actor.Actor))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
visibleActorIds.Add(actor.Actor.ActorID);
|
||||||
|
|
||||||
|
// We already know about this actor
|
||||||
|
if (lastKnownActorIds.Contains(actor.Actor.ActorID))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// We have already played this type of notification
|
||||||
|
if (playedNotifications.Contains(actor.Trait.Info.Notification))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Announce(self, actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (announcedAny)
|
||||||
|
ticksBeforeNextNotification = info.NotificationInterval;
|
||||||
|
|
||||||
|
lastKnownActorIds = visibleActorIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Announce(Actor self, TraitPair<AnnounceOnSeen> announce)
|
||||||
|
{
|
||||||
|
// Audio notification
|
||||||
|
if (self.World.LocalPlayer != null)
|
||||||
|
Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", announce.Trait.Info.Notification, self.Owner.Country.Race);
|
||||||
|
|
||||||
|
// Radar notificaion
|
||||||
|
if (announce.Trait.Info.PingRadar && radarPings.Value != null)
|
||||||
|
radarPings.Value.Add(() => true, announce.Actor.CenterPosition, Color.Red, 50);
|
||||||
|
|
||||||
|
playedNotifications.Add(announce.Trait.Info.Notification);
|
||||||
|
announcedAny = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs
Normal file
35
OpenRA.Mods.Common/Traits/Sound/AnnounceOnSeen.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 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 OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("Players will be notified when this actor becomes visible to them.")]
|
||||||
|
public class AnnounceOnSeenInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("Should there be a radar ping on enemies' radar at the actor's location when they see him")]
|
||||||
|
public readonly bool PingRadar = false;
|
||||||
|
|
||||||
|
public readonly string Notification = "EnemyUnitSighted";
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new AnnounceOnSeen(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AnnounceOnSeen
|
||||||
|
{
|
||||||
|
public readonly AnnounceOnSeenInfo Info;
|
||||||
|
|
||||||
|
public AnnounceOnSeen(AnnounceOnSeenInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,7 +43,6 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
{
|
{
|
||||||
readonly WormManagerInfo info;
|
readonly WormManagerInfo info;
|
||||||
readonly Lazy<Actor[]> spawnPointActors;
|
readonly Lazy<Actor[]> spawnPointActors;
|
||||||
readonly Lazy<RadarPings> radarPings;
|
|
||||||
|
|
||||||
int spawnCountdown;
|
int spawnCountdown;
|
||||||
int wormsPresent;
|
int wormsPresent;
|
||||||
@@ -51,7 +50,6 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
public WormManager(Actor self, WormManagerInfo info)
|
public WormManager(Actor self, WormManagerInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
radarPings = Exts.Lazy(() => self.World.WorldActor.Trait<RadarPings>());
|
|
||||||
spawnPointActors = Exts.Lazy(() => self.World.ActorsWithTrait<WormSpawner>().Select(x => x.Actor).ToArray());
|
spawnPointActors = Exts.Lazy(() => self.World.ActorsWithTrait<WormSpawner>().Select(x => x.Actor).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +78,6 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
// more we need to reach the defined minimum count.
|
// more we need to reach the defined minimum count.
|
||||||
wormLocations.Add(SpawnWorm(self));
|
wormLocations.Add(SpawnWorm(self));
|
||||||
} while (wormsPresent < info.Minimum);
|
} while (wormsPresent < info.Minimum);
|
||||||
|
|
||||||
AnnounceWormSign(self, wormLocations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WPos SpawnWorm(Actor self)
|
WPos SpawnWorm(Actor self)
|
||||||
@@ -107,17 +103,5 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
{
|
{
|
||||||
wormsPresent--;
|
wormsPresent--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceWormSign(Actor self, IEnumerable<WPos> wormLocations)
|
|
||||||
{
|
|
||||||
if (self.World.LocalPlayer != null)
|
|
||||||
Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.WormSignNotification, self.World.LocalPlayer.Country.Race);
|
|
||||||
|
|
||||||
if (radarPings.Value == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var wormLocation in wormLocations)
|
|
||||||
radarPings.Value.Add(() => true, wormLocation, Color.Red, 50);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,3 +51,6 @@ SANDWORM:
|
|||||||
Sandworm:
|
Sandworm:
|
||||||
WanderMoveRadius: 5
|
WanderMoveRadius: 5
|
||||||
IgnoresCloak:
|
IgnoresCloak:
|
||||||
|
AnnounceOnSeen:
|
||||||
|
Notification: WormSign
|
||||||
|
PingRadar: True
|
||||||
@@ -50,6 +50,8 @@
|
|||||||
UpgradeManager:
|
UpgradeManager:
|
||||||
TemporaryOwnerManager:
|
TemporaryOwnerManager:
|
||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
|
AnnounceOnSeen:
|
||||||
|
Notification: EnemyUnitsApproaching
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -103,6 +105,8 @@
|
|||||||
UpgradeManager:
|
UpgradeManager:
|
||||||
TemporaryOwnerManager:
|
TemporaryOwnerManager:
|
||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
|
AnnounceOnSeen:
|
||||||
|
Notification: EnemyUnitsApproaching
|
||||||
|
|
||||||
^Husk:
|
^Husk:
|
||||||
Health:
|
Health:
|
||||||
@@ -227,6 +231,8 @@
|
|||||||
UpgradeMinEnabledLevel: 1
|
UpgradeMinEnabledLevel: 1
|
||||||
UpgradeManager:
|
UpgradeManager:
|
||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
|
AnnounceOnSeen:
|
||||||
|
Notification: EnemyUnitsApproaching
|
||||||
|
|
||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -260,6 +266,8 @@
|
|||||||
UpgradeTypes: selfheal
|
UpgradeTypes: selfheal
|
||||||
UpgradeMinEnabledLevel: 1
|
UpgradeMinEnabledLevel: 1
|
||||||
UpgradeManager:
|
UpgradeManager:
|
||||||
|
AnnounceOnSeen:
|
||||||
|
Notification: EnemyUnitsApproaching
|
||||||
|
|
||||||
^Helicopter:
|
^Helicopter:
|
||||||
Inherits: ^Plane
|
Inherits: ^Plane
|
||||||
|
|||||||
@@ -72,4 +72,4 @@ Player:
|
|||||||
ProvidesTechPrerequisite@all:
|
ProvidesTechPrerequisite@all:
|
||||||
Name: Unrestricted
|
Name: Unrestricted
|
||||||
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
||||||
|
EnemyWatcher:
|
||||||
|
|||||||
Reference in New Issue
Block a user