Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for super weapon detected notifications #19811

Merged
merged 1 commit into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 17 additions & 1 deletion 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 @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing this?

Copy link
Member Author

@Mailaender Mailaender Nov 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to an XML comment, so it doesn't rot when the logic changes and for it to be visible from other places calling the function.

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