Skip to content

Commit

Permalink
Add support for superweapon detected sounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender authored and reaperrr committed Dec 5, 2021
1 parent c51327c commit c9022bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions OpenRA.Game/Player.cs
Expand Up @@ -253,6 +253,7 @@ public PlayerRelationship RelationshipWith(Player other)
return PlayerRelationship.Neutral;
}

/// <summary> returns true if player is null </summary>
public bool IsAlliedWith(Player p)
{
return RelationshipWith(p) == PlayerRelationship.Ally;
Expand Down
18 changes: 17 additions & 1 deletion OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs
Expand Up @@ -47,6 +47,11 @@ public abstract class SupportPowerInfo : PausableConditionalTraitInfo
public readonly bool StartFullyCharged = false;
public readonly string[] Prerequisites = { };

public readonly string DetectedSound = null;

[NotificationReference("Speech")]
public readonly string DetectedSpeechNotification = null;

public readonly string BeginChargeSound = null;

[NotificationReference("Speech")]
Expand Down Expand Up @@ -137,6 +142,18 @@ public SupportPower(Actor self, SupportPowerInfo info)
this.info = info;
}

protected override void Created(Actor self)
{
base.Created(self);

var renderPlayer = self.World.RenderPlayer;
if (renderPlayer != null && renderPlayer != self.Owner)
{
Game.Sound.Play(SoundType.UI, Info.DetectedSound);
Game.Sound.PlayNotification(self.World.Map.Rules, renderPlayer, "Speech", info.DetectedSpeechNotification, renderPlayer.Faction.InternalName);
}
}

public virtual SupportPowerInstance CreateInstance(string key, SupportPowerManager manager)
{
return new SupportPowerInstance(key, info, manager);
Expand Down Expand Up @@ -185,7 +202,6 @@ public virtual void PlayLaunchSounds()
var isAllied = Self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(SoundType.UI, isAllied ? Info.LaunchSound : Info.IncomingSound);

// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? Self.Owner : renderPlayer;
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(Self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
Expand Down

0 comments on commit c9022bc

Please sign in to comment.