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 committed Nov 21, 2021
1 parent 98b25dd commit 29365af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions OpenRA.Game/Player.cs
Original file line number Diff line number Diff line change
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
17 changes: 15 additions & 2 deletions OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs
Original file line number Diff line number Diff line change
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 @@ -124,7 +129,7 @@ public abstract class SupportPowerInfo : PausableConditionalTraitInfo
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
}

public class SupportPower : PausableConditionalTrait<SupportPowerInfo>
public class SupportPower : PausableConditionalTrait<SupportPowerInfo>, INotifyCreated
{
public readonly Actor Self;
readonly SupportPowerInfo info;
Expand All @@ -137,6 +142,15 @@ public SupportPower(Actor self, SupportPowerInfo info)
this.info = info;
}

void INotifyCreated.Created(Actor self)
{
Game.Sound.Play(SoundType.UI, Info.DetectedSound);

var renderPlayer = self.World.RenderPlayer;
var toPlayer = self.Owner.IsAlliedWith(renderPlayer) ? renderPlayer ?? self.Owner : renderPlayer;
Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", info.DetectedSpeechNotification, toPlayer.Faction.InternalName);
}

public virtual SupportPowerInstance CreateInstance(string key, SupportPowerManager manager)
{
return new SupportPowerInstance(key, info, manager);
Expand Down Expand Up @@ -185,7 +199,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 29365af

Please sign in to comment.