Static helper that manages playing a map-specific "power motif" sound when the game power turns on. It reads the cue from ActiveConfig.Current.Gameplay.PowerSound, allows session-level enable/disable, plays the cue via NZSound.PlayUi, and exposes a console command nz_power_motif to toggle or play it.
using Sandbox;
namespace NZombies;
/// <summary>
/// THE MAP'S MOTIF AS THE POWER COMES ON — `Gameplay.PowerSound`, played over the game's own power-on sound: *"when the power turns on
/// I also want the map's motif to play, something ancient a small melody with ancient instruments that sound powerfull"* (2026-09-28).
/// Basalt's (`nz.basalt.power`) is the box's figure on two bronze war horns over war drums, a lyre and a low chant, made by
/// `Tools/basalt_power_motif.py`.
///
/// ⚠️ EACH MACHINE, NOTHING SENT, AND ONCE. `Power` calls it beside `PowerTremor.Play`: `ApplyPowered` on the host (and solo),
/// `TurnOnFromHost` on a client, on the host's word. Not for each lever of several, and not on a map with no switch.
/// ⚠️ A MAP THAT NAMES NONE PLAYS NOTHING MORE: the game's own `nz.power.on` plays either way.
/// ⚠️ THE SWITCH IS NULLABLE-BACKED (INSTRUCTIONS §1).
/// </summary>
public static class PowerMotif
{
/// <summary>`nz_power_motif 0` silences it (this session).</summary>
public static bool Enabled
{
get => _enabled ?? true;
set => _enabled = value;
}
static bool? _enabled;
static SoundHandle _playing;
/// <summary>This map's motif: its config's `Gameplay.PowerSound`, blank for none.</summary>
public static string Cue => ActiveConfig.Current?.Gameplay?.PowerSound?.Trim() ?? "";
/// <summary>The motif, now, on this machine. A second start cuts the first rather than playing over it.</summary>
public static void Play()
{
if ( !Enabled ) return;
var cue = Cue;
if ( cue.Length == 0 ) return;
if ( _playing.IsValid() ) _playing.Stop();
// ⚠️ PlayUi: a cue with no asset is named once in a warning, rather than the engine's quiet "couldn't find"
_playing = NZSound.PlayUi( cue );
Log.Info( $"[nz-power] the map's motif: {cue}" );
}
/// <summary>
/// `nz_power_motif [0|1]` — this map's power motif, played now to hear it. `0` silences it and `1` brings it back (this session).
/// </summary>
[ConCmd( "nz_power_motif" )]
public static void Cmd( string what = "" )
{
if ( what == "0" )
{
Enabled = false;
if ( _playing.IsValid() ) _playing.Stop();
Log.Info( "[nz-power] the power's motif is OFF — nz_power_motif 1 for it back" );
return;
}
if ( what == "1" ) Enabled = true;
if ( Cue.Length == 0 )
{
Log.Info( "[nz-power] this map names no power motif (Gameplay.PowerSound) — basalt's is nz.basalt.power" );
return;
}
Play();
}
}