From 66f86add059778c16a96096ff9a4918656808357 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 7 Nov 2011 00:31:17 +0000 Subject: [PATCH] - Fixed: Starting in a sector with a musinfo thing would not trigger the thing. SVN r3313 (trunk) --- src/g_level.cpp | 6 ++++++ src/g_level.h | 1 + src/s_advsound.cpp | 54 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/g_level.cpp b/src/g_level.cpp index 95b11f4a9..d552a3140 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -665,6 +665,7 @@ void G_DoCompleted (void) else { + level_info_t *nextinfo = FindLevelInfo (nextlevel); wminfo.next = nextinfo->mapname; wminfo.LName1 = TexMan[TexMan.CheckForTexture(nextinfo->pname, FTexture::TEX_MiscPatch)]; @@ -1366,6 +1367,11 @@ void G_SerializeLevel (FArchive &arc, bool hubLoad) << level.maptime << i; + if (SaveVersion >= 3313) + { + arc << level.nextmusic; + } + // Hub transitions must keep the current total time if (!hubLoad) level.totaltime = i; diff --git a/src/g_level.h b/src/g_level.h index 336b47105..4b70f595a 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -401,6 +401,7 @@ struct FLevelLocals int musicorder; int cdtrack; unsigned int cdid; + int nextmusic; // For MUSINFO purposes char skypic1[9]; char skypic2[9]; diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 2dd815f1b..58102ce4c 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -293,6 +293,7 @@ float S_GetMusicVolume (const char *music) } //========================================================================== + // // S_HashSounds // @@ -2248,6 +2249,8 @@ class AMusicChanger : public ASectorAction DECLARE_CLASS (AMusicChanger, ASectorAction) public: virtual bool TriggerAction (AActor *triggerer, int activationType); + virtual void Tick(); + virtual void PostBeginPlay(); }; IMPLEMENT_CLASS(AMusicChanger) @@ -2256,19 +2259,46 @@ bool AMusicChanger::TriggerAction (AActor *triggerer, int activationType) { if (activationType & SECSPAC_Enter) { - if (args[0] != 0) - { - FName *music = level.info->MusicMap.CheckKey(args[0]); - - if (music != NULL) - { - S_ChangeMusic(music->GetChars(), args[1]); - } - } - else - { - S_ChangeMusic("*"); + if (args[0] == 0 || level.info->MusicMap.CheckKey(args[0])) + { + level.nextmusic = args[0]; + reactiontime = 30; } } return Super::TriggerAction (triggerer, activationType); } + +void AMusicChanger::Tick() +{ + Super::Tick(); + if (reactiontime > -1 && --reactiontime == 0) + { + // Is it our music that's queued for being played? + if (level.nextmusic == args[0]) + { + if (args[0] != 0) + { + FName *music = level.info->MusicMap.CheckKey(args[0]); + + if (music != NULL) + { + S_ChangeMusic(music->GetChars(), args[1]); + } + } + else + { + S_ChangeMusic("*"); + } + } + } + } + +void AMusicChanger::PostBeginPlay() +{ + // The music changer should consider itself activated if the player + // spawns in its sector as well as if it enters the sector during a P_TryMove. + if (players[consoleplayer].mo && players[consoleplayer].mo->Sector == this->Sector) + { + TriggerAction(players[consoleplayer].mo, SECSPAC_Enter); + } +}