diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 240498f0c9..c194d74482 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -149,6 +149,7 @@ enum SICommands SI_IfStrife, SI_Rolloff, SI_Volume, + SI_MusicAlias, }; // Blood was a cool game. If Monolith ever releases the source for it, @@ -183,6 +184,7 @@ struct FSavedPlayerSoundInfo }; // This specifies whether Timidity or Windows playback is preferred for a certain song (only useful for Windows.) +MusicAliasMap MusicAliases; MidiDeviceMap MidiDevices; // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -241,6 +243,7 @@ static const char *SICommandStrings[] = "$ifstrife", "$rolloff", "$volume", + "$musicalias", NULL }; @@ -254,6 +257,7 @@ static bool PlayerClassesIsSorted; static TArray PlayerClassLookups; static TArray PlayerSounds; + static FString DefPlayerClassName; static int DefPlayerClass; @@ -1285,6 +1289,32 @@ static void S_AddSNDINFO (int lump) } break; + case SI_MusicAlias: { + sc.MustGetString(); + int lump = Wads.CheckNumForName(sc.String, ns_music); + if (lump >= 0) + { + // do not set the alias if a later WAD defines its own music of this name + int file = Wads.GetLumpFile(lump); + int sndifile = Wads.GetLumpFile(sc.LumpNum); + if (file > sndifile) + { + sc.MustGetString(); + continue; + } + } + FName alias = sc.String; + sc.MustGetString(); + FName mapped = sc.String; + + // only set the alias if the lump it maps to exists. + if (mapped == NAME_None || Wads.CheckNumForName(sc.String, ns_music) >= 0) + { + MusicAliases[alias] = mapped; + } + } + break; + case SI_MidiDevice: { sc.MustGetString(); FName nm = sc.String; diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 95130d3090..bb85541c49 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -2386,8 +2386,16 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) int offset = 0, length = 0; int device = MDEV_DEFAULT; MusInfo *handle = NULL; + FName musicasname = musicname; - int *devp = MidiDevices.CheckKey(FName(musicname)); + FName *aliasp = MusicAliases.CheckKey(musicasname); + if (aliasp != NULL) + { + musicname = (musicasname = *aliasp).GetChars(); + if (musicasname == NAME_None) return true; + } + + int *devp = MidiDevices.CheckKey(musicasname); if (devp != NULL) device = *devp; // Strip off any leading file:// component. diff --git a/src/s_sound.h b/src/s_sound.h index 5c2796d5b3..ee831bddfa 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -382,8 +382,10 @@ enum EMidiDevice MDEV_GUS = 5, }; +typedef TMap MusicAliasMap; typedef TMap MidiDeviceMap; +extern MusicAliasMap MusicAliases; extern MidiDeviceMap MidiDevices; #endif