summaryrefslogtreecommitdiffstats
path: root/src/audio/MusicManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/MusicManager.cpp')
-rw-r--r--src/audio/MusicManager.cpp1797
1 files changed, 1097 insertions, 700 deletions
diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp
index 0752a5d8..59cec9b3 100644
--- a/src/audio/MusicManager.cpp
+++ b/src/audio/MusicManager.cpp
@@ -14,231 +14,127 @@
#include "Timer.h"
#include "World.h"
#include "sampman.h"
+#include "Stats.h"
+#include "Script.h"
+#include "ZoneCull.h"
+#include "Weather.h"
+#include "DMAudio.h"
+#include "GenericGameStorage.h"
#if !defined FIX_BUGS && (defined RADIO_SCROLL_TO_PREV_STATION || defined RADIO_OFF_TEXT)
-static_assert(false, "RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work correctly without FIX_BUGS");
+static_assert(false, "R*'s radio implementation is quite buggy, RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work without FIX_BUGS");
#endif
cMusicManager MusicManager;
int32 gNumRetunePresses;
int32 gRetuneCounter;
-bool8 bHasStarted;
+bool8 g_bAnnouncementReadPosAlready;
+uint8 RadioStaticCounter = 5;
+uint32 RadioStaticTimer;
+
+CVector vecRiotPosition(300.7f, -322.0f, 12.0f);
+
+uint32 NewGameRadioTimers[10] =
+{
+ 948160,
+ 452150,
+ 2438150,
+ 3538230,
+ 3513100,
+ 4246050,
+ 1418050,
+ 3178240,
+ 471210,
+ 0
+};
cMusicManager::cMusicManager()
{
m_bIsInitialised = FALSE;
m_bDisabled = FALSE;
- m_nMusicMode = MUSICMODE_DISABLED;
- m_nNextTrack = NO_TRACK;
+ m_nFrontendTrack = NO_TRACK;
m_nPlayingTrack = NO_TRACK;
- m_bFrontendTrackFinished = FALSE;
- m_bPlayInFrontend = FALSE;
+ m_nUpcomingMusicMode = MUSICMODE_DISABLED;
+ m_nMusicMode = MUSICMODE_DISABLED;
m_bSetNextStation = FALSE;
- m_nAnnouncement = NO_TRACK;
- m_bPreviousPlayerInCar = FALSE;
- m_bPlayerInCar = FALSE;
- m_bAnnouncementInProgress = FALSE;
- m_bVerifyAmbienceTrackStartedToPlay = FALSE;
- bHasStarted = FALSE;
-}
-bool8
-cMusicManager::PlayerInCar()
-{
- if(!FindPlayerVehicle())
- return FALSE;
-
- int32 State = FindPlayerPed()->m_nPedState;
-
- if(State == PED_DRAG_FROM_CAR || State == PED_EXIT_CAR || State == PED_ARRESTED)
- return FALSE;
+ for (int i = 0; i < NUM_RADIOS; i++)
+ aListenTimeArray[i] = 0.0f;
- if (!FindPlayerVehicle())
- return TRUE;
-
- if (FindPlayerVehicle()->GetStatus() == STATUS_WRECKED)
- return FALSE;
-
- switch (FindPlayerVehicle()->GetModelIndex()) {
- case MI_FIRETRUCK:
- case MI_AMBULAN:
- case MI_MRWHOOP:
- case MI_PREDATOR:
- case MI_TRAIN:
- case MI_SPEEDER:
- case MI_REEFER:
- case MI_GHOST: return FALSE;
- default: return TRUE;
- }
+ m_nLastTrackServiceTime = 0.0f;
+ m_nVolumeLatency = 0;
+ m_nCurrentVolume = 0;
+ m_nMaxVolume = 0;
+ m_nAnnouncement = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
}
void
-cMusicManager::DisplayRadioStationName()
+cMusicManager::ResetMusicAfterReload()
{
- int8 pRetune;
- int8 gStreamedSound;
- int8 gRetuneCounter;
- static wchar *pCurrentStation = nil;
- static uint8 cDisplay = 0;
-
- if(!CTimer::GetIsPaused() && !TheCamera.m_WideScreenOn && PlayerInCar() &&
- !CReplay::IsPlayingBack()) {
- if(m_bPlayerInCar && !m_bPreviousPlayerInCar)
- pCurrentStation = nil;
-
-#ifdef FIX_BUGS
- const int curRadio = GetCarTuning();
-#else
- const int curRadio = m_nNextTrack;
-#endif
-
-#ifdef RADIO_SCROLL_TO_PREV_STATION
- if(gNumRetunePresses < 0) {
- gStreamedSound = curRadio;
-
- gRetuneCounter = gNumRetunePresses;
- pRetune = gStreamedSound;
-
- while(gRetuneCounter < 0) {
- if(pRetune == HEAD_RADIO) {
- pRetune = RADIO_OFF;
- } else if(pRetune == RADIO_OFF || pRetune == NUM_RADIOS) {
- pRetune = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1;
- } else
- pRetune--;
+ float afRadioTime[NUM_RADIOS];
- ++gRetuneCounter;
- }
- } else
-#endif
- if(SampleManager.IsMP3RadioChannelAvailable()) {
- gStreamedSound = curRadio;
-
- if(gStreamedSound == STREAMED_SOUND_CITY_AMBIENT ||
- gStreamedSound == STREAMED_SOUND_WATER_AMBIENT) { // which means OFF
- gStreamedSound = NUM_RADIOS;
- } else if(gStreamedSound > STREAMED_SOUND_RADIO_MP3_PLAYER)
- return;
-
- pRetune = gNumRetunePresses + gStreamedSound;
-
-#ifdef FIX_BUGS
- while(pRetune > NUM_RADIOS)
- pRetune -= (NUM_RADIOS + 1);
-#endif
- if(pRetune == NUM_RADIOS) {
- pRetune = RADIO_OFF;
- }
-#ifndef FIX_BUGS
- else if(pRetune > NUM_RADIOS) {
- pRetune = pRetune - (NUM_RADIOS + 1);
- }
-#endif
- } else {
- gStreamedSound = curRadio;
- pRetune = gNumRetunePresses + gStreamedSound;
-
- if(pRetune >= USERTRACK) {
- gRetuneCounter = gNumRetunePresses;
- pRetune = curRadio;
-
- if(gStreamedSound == STREAMED_SOUND_WATER_AMBIENT)
- pRetune = STREAMED_SOUND_CITY_AMBIENT; // which is RADIO_OFF
-
- while(gRetuneCounter) {
- if(pRetune == RADIO_OFF) {
- pRetune = HEAD_RADIO;
- } else if(pRetune < USERTRACK) {
- pRetune = pRetune + 1;
- }
- if(pRetune == USERTRACK) pRetune = RADIO_OFF;
-
- --gRetuneCounter;
- }
- }
- }
+ m_bRadioSetByScript = FALSE;
+ m_nRadioStationScript = WILDSTYLE;
+ m_nRadioPosition = -1;
+ m_nAnnouncement = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
+ m_bSetNextStation = FALSE;
+ RadioStaticTimer = 0;
+ gNumRetunePresses = 0;
+ gRetuneCounter = 0;
+ m_nFrontendTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ m_FrontendLoopFlag = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = FALSE;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_bGameplayAllowsRadio = FALSE;
+ m_bRadioStreamReady = FALSE;
+ nFramesSinceCutsceneEnded = -1;
+ m_bUserResumedGame = FALSE;
+ m_bMusicModeChangeStarted = FALSE;
+ m_bEarlyFrontendTrack = FALSE;
+ m_nVolumeLatency = 0;
+ m_nCurrentVolume = 0;
+ m_nMaxVolume = 0;
+
+ bool8 bRadioWasEverListened = FALSE;
+
+ for (int i = 0; i < NUM_RADIOS; i++) {
+ afRadioTime[i] = CStats::GetFavoriteRadioStationList(i);
+ if (!bRadioWasEverListened && afRadioTime[i] != 0.0f)
+ bRadioWasEverListened = TRUE;
+ }
- wchar *string;
-
- switch(pRetune) {
- case HEAD_RADIO: string = TheText.Get("FEA_FM0"); break;
- case DOUBLE_CLEF: string = TheText.Get("FEA_FM1"); break;
- case JAH_RADIO: string = TheText.Get("FEA_FM2"); break;
- case RISE_FM: string = TheText.Get("FEA_FM3"); break;
- case LIPS_106: string = TheText.Get("FEA_FM4"); break;
- case GAME_FM: string = TheText.Get("FEA_FM5"); break;
- case MSX_FM: string = TheText.Get("FEA_FM6"); break;
- case FLASHBACK: string = TheText.Get("FEA_FM7"); break;
- case CHATTERBOX: string = TheText.Get("FEA_FM8"); break;
- case USERTRACK:
- if (!SampleManager.IsMP3RadioChannelAvailable())
- return;
- string = TheText.Get("FEA_FM9"); break;
-#ifdef RADIO_OFF_TEXT
- case RADIO_OFF: {
- extern wchar WideErrorString[];
+ if (!bRadioWasEverListened) return;
- string = TheText.Get("FEA_FMN");
- if(string == WideErrorString) {
- pCurrentStation = nil;
- return;
+ for (int i = 0; i < NUM_RADIOS; i++) {
+ aListenTimeArray[i] = afRadioTime[i];
+ int32 trackPos = GetSavedRadioStationPosition(i);
+ if (trackPos != -1) {
+ if (trackPos > m_aTracks[i].m_nLength) {
+ debug("Radio Track %d saved position is %d, Length is only %d\n", i, trackPos, m_aTracks[i].m_nLength);
+ trackPos %= m_aTracks[i].m_nLength;
}
- break;
- }
-#endif
- default: return;
- };
-
- if(pCurrentStation != string ||
- m_nNextTrack == STREAMED_SOUND_RADIO_MP3_PLAYER && m_nPlayingTrack != STREAMED_SOUND_RADIO_MP3_PLAYER) {
- pCurrentStation = string;
- cDisplay = 60;
- } else {
- if(cDisplay == 0) return;
-#ifdef FIX_BUGS
- cDisplay -= CTimer::GetLogicalFramesPassed();
-#else
- cDisplay--;
-#endif
+ m_aTracks[i].m_nPosition = trackPos;
+ m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
-
- CFont::SetJustifyOff();
- CFont::SetBackgroundOff();
- CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f));
- CFont::SetPropOn();
- CFont::SetFontStyle(FONT_HEADING);
- CFont::SetCentreOn();
- // Reminder: Game doesn't have "scaling" at all, it just stretches, and it's team's decision here to not let centered text occupy all the screen.
- // Disable ASPECT_RATIO_SCALE and it'll go back to default behaviour; stretching.
- CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH));
- CFont::SetColor(CRGBA(0, 0, 0, 255));
-#ifdef FIX_BUGS
- CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(22.0f) + SCREEN_SCALE_Y(2.0f), pCurrentStation);
-#else
- CFont::PrintString(SCREEN_WIDTH / 2 + 2.0f, SCREEN_SCALE_Y(22.0f) + 2.0f, pCurrentStation);
-#endif
-
- if(gNumRetunePresses)
- CFont::SetColor(CRGBA(102, 133, 143, 255));
- else
- CFont::SetColor(CRGBA(147, 196, 211, 255));
-
- CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_Y(22.0f), pCurrentStation);
- CFont::DrawFonts();
}
}
-bool8
-cMusicManager::Initialise()
+void
+cMusicManager::SetStartingTrackPositions(bool8 isNewGameTimer)
{
int pos;
- if (!IsInitialised()) {
+ if (IsInitialised()) {
time_t timevalue = time(0);
if (timevalue == -1) {
pos = AudioManager.m_anRandomTable[0];
} else {
- tm *pTm = localtime(&timevalue);
+ tm* pTm = localtime(&timevalue);
if (pTm->tm_sec == 0)
pTm->tm_sec = AudioManager.m_anRandomTable[0];
if (pTm->tm_min == 0)
@@ -265,22 +161,52 @@ cMusicManager::Initialise()
for (int i = 0; i < TOTAL_STREAMED_SOUNDS; i++) {
m_aTracks[i].m_nLength = SampleManager.GetStreamedFileLength(i);
- m_aTracks[i].m_nPosition = pos * AudioManager.m_anRandomTable[i % 5] % m_aTracks[i].m_nLength;
+
+ if (i < STREAMED_SOUND_CITY_AMBIENT && isNewGameTimer)
+ m_aTracks[i].m_nPosition = NewGameRadioTimers[i];
+ else if (i < STREAMED_SOUND_ANNOUNCE_BRIDGE_CLOSED)
+ m_aTracks[i].m_nPosition = (pos * AudioManager.m_anRandomTable[i % 5]) % m_aTracks[i].m_nLength;
+ else
+ m_aTracks[i].m_nPosition = 0;
+
m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
+ }
+}
+bool8
+cMusicManager::Initialise()
+{
+ if (!IsInitialised()) {
+ m_bIsInitialised = TRUE;
+ SetStartingTrackPositions(FALSE);
m_bResetTimers = FALSE;
m_nResetTime = 0;
- m_nTimer = m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
- m_bDoTrackService = FALSE;
- m_bIgnoreTimeDelay = FALSE;
m_bRadioSetByScript = FALSE;
- m_nRadioStationScript = HEAD_RADIO;
+ m_nRadioStationScript = WILDSTYLE;
m_nRadioPosition = -1;
m_nRadioInCar = NO_TRACK;
- gNumRetunePresses = 0;
gRetuneCounter = 0;
- m_bIsInitialised = TRUE;
+ gNumRetunePresses = 0;
+ m_nFrontendTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ m_nUpcomingMusicMode = MUSICMODE_DISABLED;
+ m_nMusicMode = MUSICMODE_DISABLED;
+ m_FrontendLoopFlag = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = FALSE;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_bGameplayAllowsRadio = FALSE;
+ m_bRadioStreamReady = FALSE;
+ nFramesSinceCutsceneEnded = -1;
+ m_bUserResumedGame = FALSE;
+ m_bMusicModeChangeStarted = FALSE;
+ m_nMusicModeToBeSet = MUSICMODE_DISABLED;
+ m_bEarlyFrontendTrack = FALSE;
+ m_nVolumeLatency = 0;
+ m_nCurrentVolume = 0;
+ m_nMaxVolume = 0;
}
return m_bIsInitialised;
}
@@ -292,81 +218,56 @@ cMusicManager::Terminate()
if (SampleManager.IsStreamPlaying()) {
SampleManager.StopStreamedFile();
- m_nNextTrack = NO_TRACK;
m_nPlayingTrack = NO_TRACK;
}
m_bIsInitialised = FALSE;
}
void
-cMusicManager::ChangeMusicMode(uint8 mode)
+cMusicManager::SetRadioChannelByScript(uint32 station, int32 pos)
{
- if (!IsInitialised()) return;
-
- uint8 mode2;
- switch (mode)
- {
- case MUSICMODE_FRONTEND:
- mode2 = MUSICMODE_FRONTEND;
-#ifdef PAUSE_RADIO_IN_FRONTEND
- // rewind those streams we weren't listening right now
- for (uint32 i = STREAMED_SOUND_RADIO_HEAD; i < STREAMED_SOUND_CUTSCENE_LUIGI1_LG; i++) {
- m_aTracks[i].m_nPosition = GetTrackStartPos(i);
- m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_bIsInitialised) {
+ if (station == STREAMED_SOUND_RADIO_MP3_PLAYER)
+ station = STREAMED_SOUND_CITY_AMBIENT;
+ if (station <= STREAMED_SOUND_RADIO_POLICE) {
+ m_bRadioSetByScript = TRUE;
+ m_nRadioStationScript = station;
+ m_nRadioPosition = pos == -1 ? -1 : pos % m_aTracks[station].m_nLength;
}
-#endif
- break;
- case MUSICMODE_GAME: mode2 = MUSICMODE_GAME; break;
- case MUSICMODE_CUTSCENE: mode2 = MUSICMODE_CUTSCENE; break;
- case MUSICMODE_DISABLE: mode2 = MUSICMODE_DISABLED; break;
- default: return;
}
+}
- if (mode2 != m_nMusicMode || mode == MUSICMODE_FRONTEND && mode2 == MUSICMODE_FRONTEND) {
- switch (mode)
- {
- case MUSICMODE_FRONTEND:
- case MUSICMODE_GAME:
- case MUSICMODE_CUTSCENE:
- case MUSICMODE_DISABLED:
- if (SampleManager.IsStreamPlaying()) {
- if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- }
- SampleManager.StopStreamedFile();
- }
- m_nNextTrack = NO_TRACK;
- m_nPlayingTrack = NO_TRACK;
- m_bFrontendTrackFinished = FALSE;
- m_bPlayInFrontend = FALSE;
- m_bSetNextStation = FALSE;
- m_bPreviousPlayerInCar = FALSE;
- m_bPlayerInCar = FALSE;
- m_bAnnouncementInProgress = FALSE;
- m_nTimer = m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
- m_bDoTrackService = FALSE;
- m_bIgnoreTimeDelay = TRUE;
- m_bVerifyAmbienceTrackStartedToPlay = FALSE;
- m_nMusicMode = mode2;
- break;
- default: return;
- }
- }
+bool8
+cMusicManager::PlayerInCar()
+{
+ CVehicle *vehicle = AudioManager.FindVehicleOfPlayer();
+ if(!vehicle)
+ return FALSE;
+
+ int32 State = FindPlayerPed()->m_nPedState;
+
+ if(State == PED_DRAG_FROM_CAR || State == PED_EXIT_CAR || State == PED_ARRESTED)
+ return FALSE;
+
+ if (vehicle->GetStatus() == STATUS_WRECKED)
+ return FALSE;
+
+ return TRUE;
}
-uint8
+uint32
cMusicManager::GetRadioInCar(void)
{
- if (!m_bIsInitialised) return HEAD_RADIO;
+ if (!m_bIsInitialised) return WILDSTYLE;
if (PlayerInCar()) {
- CVehicle *veh = FindPlayerVehicle();
- if (veh != nil){
- if (UsesPoliceRadio(veh)) {
+ CVehicle* veh = AudioManager.FindVehicleOfPlayer();
+ if (veh != nil) {
+ if (UsesPoliceRadio(veh) || UsesTaxiRadio(veh)) {
if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && !AudioManager.m_nUserPause))
- return POLICE_RADIO;
+ return STREAMED_SOUND_RADIO_POLICE;
return m_nRadioInCar;
- } else return veh->m_nRadioStation;
+ }
+ else return veh->m_nRadioStation;
}
}
@@ -383,9 +284,9 @@ cMusicManager::SetRadioInCar(uint32 station)
m_nRadioInCar = station;
return;
}
- CVehicle *veh = FindPlayerVehicle();
+ CVehicle* veh = AudioManager.FindVehicleOfPlayer();
if (veh == nil) return;
- if (UsesPoliceRadio(veh))
+ if (UsesPoliceRadio(veh) || UsesTaxiRadio(veh))
m_nRadioInCar = station;
else
veh->m_nRadioStation = station;
@@ -393,29 +294,63 @@ cMusicManager::SetRadioInCar(uint32 station)
}
void
-cMusicManager::SetRadioChannelByScript(uint8 station, int32 pos)
+cMusicManager::RecordRadioStats()
{
- if (m_bIsInitialised && station < RADIO_OFF) {
- m_bRadioSetByScript = TRUE;
- m_nRadioStationScript = station;
- m_nRadioPosition = pos == -1 ? -1 : pos % m_aTracks[station].m_nLength;
+ if (m_nPlayingTrack < NUM_RADIOS) {
+ double time /*Rusty*/ = CTimer::GetTimeInMillisecondsPauseMode();
+ if (time > m_nLastTrackServiceTime)
+ aListenTimeArray[m_nPlayingTrack] += time - m_nLastTrackServiceTime;
}
}
-
void
-cMusicManager::ResetMusicAfterReload()
+cMusicManager::ChangeMusicMode(uint8 mode)
{
- m_bRadioSetByScript = FALSE;
- m_nRadioStationScript = 0;
- m_nRadioPosition = -1;
- m_nAnnouncement = NO_TRACK;
- m_bAnnouncementInProgress = FALSE;
- m_bSetNextStation = FALSE;
- gRetuneCounter = 0;
- gNumRetunePresses = 0;
-}
+ if (!IsInitialised()) return;
+
+ switch (mode)
+ {
+ case MUSICMODE_FRONTEND:
+ m_nUpcomingMusicMode = MUSICMODE_FRONTEND;
+#ifdef PAUSE_RADIO_IN_FRONTEND
+ // rewind those streams we weren't listening right now
+ for( uint32 i = STREAMED_SOUND_RADIO_WILD; i < STREAMED_SOUND_CUTSCENE_ASS_1; i++ ) {
+ m_aTracks[i].m_nPosition = GetTrackStartPos(i);
+ m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+#endif
+
+ break;
+ case MUSICMODE_GAME: m_nUpcomingMusicMode = MUSICMODE_GAME; break;
+ case MUSICMODE_CUTSCENE:
+ m_nUpcomingMusicMode = MUSICMODE_CUTSCENE;
+ if (SampleManager.IsStreamPlaying()) {
+ if (m_nPlayingTrack != NO_TRACK) {
+ RecordRadioStats();
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+ }
+ SampleManager.StopStreamedFile();
+ while (SampleManager.IsStreamPlaying())
+ SampleManager.StopStreamedFile();
+ m_nMusicMode = m_nUpcomingMusicMode;
+ m_bMusicModeChangeStarted = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = FALSE;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_nPlayingTrack = NO_TRACK;
+ m_nFrontendTrack = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
+ m_nAnnouncement = NO_TRACK;
+ g_bAnnouncementReadPosAlready = FALSE;
+ break;
+ case MUSICMODE_DISABLE: m_nUpcomingMusicMode = MUSICMODE_DISABLED; break;
+ default: return;
+ }
+}
void
cMusicManager::ResetTimers(int32 time)
@@ -432,338 +367,724 @@ cMusicManager::Service()
m_nLastTrackServiceTime = m_nResetTime;
}
- if (!m_bIsInitialised || m_bDisabled) return;
-
- if (m_nMusicMode == MUSICMODE_CUTSCENE) {
- SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE);
- return;
- }
+ static bool8 bRadioStatsRecorded = FALSE;
- m_nTimer = CTimer::GetTimeInMillisecondsPauseMode();
- if (m_nTimer > (m_nLastTrackServiceTime + 2000) || m_bIgnoreTimeDelay) {
- m_bIgnoreTimeDelay = FALSE;
- m_bDoTrackService = TRUE;
- m_nLastTrackServiceTime = m_nTimer;
- } else m_bDoTrackService = FALSE;
+ if (!m_bIsInitialised || m_bDisabled) return;
- if (m_nNextTrack == NO_TRACK && SampleManager.IsStreamPlaying())
- SampleManager.StopStreamedFile();
- else switch (m_nMusicMode) {
- case MUSICMODE_FRONTEND: ServiceFrontEndMode(); break;
- case MUSICMODE_GAME: ServiceGameMode(); break;
+ if (!m_bMusicModeChangeStarted)
+ m_nMusicModeToBeSet = m_nUpcomingMusicMode;
+ if (m_nMusicModeToBeSet == m_nMusicMode) {
+ if (!AudioManager.m_nUserPause || AudioManager.m_nPreviousUserPause || m_nMusicMode != MUSICMODE_FRONTEND)
+ {
+ switch (m_nMusicMode)
+ {
+ case MUSICMODE_FRONTEND: ServiceFrontEndMode(); break;
+ case MUSICMODE_GAME: ServiceGameMode(); break;
+ case MUSICMODE_CUTSCENE: SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE); break;
+ }
}
+ else
+ m_nMusicMode = MUSICMODE_DISABLED;
+ } else {
+ m_bMusicModeChangeStarted = TRUE;
+ if (!m_bUserResumedGame && !AudioManager.m_nUserPause && AudioManager.m_nPreviousUserPause)
+ m_bUserResumedGame = TRUE;
+ if (AudioManager.m_FrameCounter % 4 == 0) {
+ gNumRetunePresses = 0;
+ gRetuneCounter = 0;
+ m_bSetNextStation = FALSE;
+ if (SampleManager.IsStreamPlaying()) {
+ if (m_nPlayingTrack != NO_TRACK && !bRadioStatsRecorded)
+ {
+ RecordRadioStats();
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ bRadioStatsRecorded = TRUE;
+ }
+ SampleManager.StopStreamedFile();
+ } else {
+ bRadioStatsRecorded = FALSE;
+ m_nMusicMode = m_nMusicModeToBeSet;
+ m_bMusicModeChangeStarted = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = FALSE;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_nPlayingTrack = NO_TRACK;
+ if (m_bEarlyFrontendTrack)
+ m_bEarlyFrontendTrack = FALSE;
+ else
+ m_nFrontendTrack = NO_TRACK;
+ }
+ }
+ }
}
void
cMusicManager::ServiceFrontEndMode()
{
+ static bool8 bRadioStatsRecorded = FALSE;
+
#ifdef PAUSE_RADIO_IN_FRONTEND
// pause radio
- for (uint32 i = STREAMED_SOUND_RADIO_HEAD; i < STREAMED_SOUND_CUTSCENE_LUIGI1_LG; i++)
+ for (uint32 i = STREAMED_SOUND_RADIO_WILD; i < STREAMED_SOUND_CUTSCENE_ASS_1; i++)
m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
#endif
- if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) {
- if (m_bFrontendTrackFinished) {
- if (!SampleManager.IsStreamPlaying()) {
- switch (m_nNextTrack)
- {
- case STREAMED_SOUND_MISSION_COMPLETED:
- if (!AudioManager.m_nUserPause)
- ChangeMusicMode(MUSICMODE_GAME);
- break;
- case STREAMED_SOUND_GAME_COMPLETED:
- ChangeMusicMode(MUSICMODE_GAME);
- break;
- default:
- break;
+ if (m_bAnnouncementInProgress) {
+ SampleManager.StopStreamedFile();
+ if (SampleManager.IsStreamPlaying())
+ return;
+ g_bAnnouncementReadPosAlready = FALSE;
+ m_nAnnouncement = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nFrontendTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ }
+
+ if (AudioManager.m_FrameCounter % 4 != 0) return;
+
+ if (!m_bTrackChangeStarted && !m_bVerifyNextTrackStartedToPlay) {
+ m_nNextTrack = m_nFrontendTrack;
+ m_nNextLoopFlag = m_FrontendLoopFlag;
+ }
+
+ if (m_nNextTrack == m_nPlayingTrack) {
+ if (SampleManager.IsStreamPlaying()) {
+ if (m_nVolumeLatency > 0) m_nVolumeLatency--;
+ else {
+ if (m_nCurrentVolume < m_nMaxVolume)
+ m_nCurrentVolume = Min(m_nMaxVolume, m_nCurrentVolume + 6);
+ SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, FALSE);
+ }
+ } else {
+ if (m_nPlayingTrack == STREAMED_SOUND_RADIO_MP3_PLAYER)
+ SampleManager.StartStreamedFile(STREAMED_SOUND_RADIO_MP3_PLAYER, 0);
+ else if (m_nPlayingTrack == STREAMED_SOUND_MISSION_COMPLETED && !AudioManager.m_nUserPause)
+ ChangeMusicMode(MUSICMODE_GAME);
+ }
+ } else {
+ m_bTrackChangeStarted = TRUE;
+ if (m_bVerifyNextTrackStartedToPlay || !SampleManager.IsStreamPlaying()) {
+ bRadioStatsRecorded = FALSE;
+ if (SampleManager.IsStreamPlaying() || m_nNextTrack == NO_TRACK) {
+ m_nPlayingTrack = m_nNextTrack;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ } else {
+ uint32 trackStartPos = (m_nNextTrack > STREAMED_SOUND_RADIO_POLICE) ? 0 : GetTrackStartPos(m_nNextTrack);
+ if (m_nNextTrack != NO_TRACK) {
+ SampleManager.SetStreamedFileLoopFlag(m_nNextLoopFlag);
+ SampleManager.StartStreamedFile(m_nNextTrack, trackStartPos);
+ m_nVolumeLatency = 3;
+ m_nCurrentVolume = 0;
+ m_nMaxVolume = 100;
+ SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, FALSE);
+ if (m_nNextTrack < STREAMED_SOUND_CITY_AMBIENT)
+ m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
+ m_bVerifyNextTrackStartedToPlay = TRUE;
}
- m_nNextTrack = NO_TRACK;
- m_nPlayingTrack = NO_TRACK;
}
- } else if (bHasStarted) {
- if (!SampleManager.IsStreamPlaying())
- SampleManager.StartStreamedFile(m_nNextTrack, 0);
} else {
+ if (m_nPlayingTrack != NO_TRACK && !bRadioStatsRecorded) {
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ RecordRadioStats();
+ bRadioStatsRecorded = TRUE;
+ }
SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
- if (!SampleManager.StartStreamedFile(m_nNextTrack, m_nNextTrack < NUM_RADIOS ? GetTrackStartPos(m_nNextTrack) : 0))
- return;
- SampleManager.SetStreamedVolumeAndPan(100, 63, FALSE);
- if (m_bPlayInFrontend) bHasStarted = TRUE;
- else m_bFrontendTrackFinished = TRUE;
+ SampleManager.StopStreamedFile();
}
}
- if (SampleManager.IsStreamPlaying())
- SampleManager.SetStreamedVolumeAndPan((CPad::GetPad(0)->bDisplayNoControllerMessage || CPad::GetPad(0)->bObsoleteControllerMessage) ? 0 : 100, 63, FALSE);
}
void
cMusicManager::ServiceGameMode()
{
- bool8 bRadioOff = FALSE;
- static int8 nFramesSinceCutsceneEnded = -1;
- uint8 volume;
+ CPed *ped = FindPlayerPed();
+ CVehicle *vehicle = AudioManager.FindVehicleOfPlayer();
+ m_bRadioStreamReady = m_bGameplayAllowsRadio;
+ m_bGameplayAllowsRadio = FALSE;
- m_bPreviousPlayerInCar = m_bPlayerInCar;
- m_bPlayerInCar = PlayerInCar();
- m_nPlayingTrack = m_nNextTrack;
- if (m_bPlayerInCar) {
- if (FindPlayerPed() != nil
- && !FindPlayerPed()->DyingOrDead()
- && !CReplay::IsPlayingBack()
- && FindPlayerVehicle() != nil
- && !UsesPoliceRadio(FindPlayerVehicle())) {
-
- if (CPad::GetPad(0)->ChangeStationJustDown()) {
- gRetuneCounter = 30;
- gNumRetunePresses++;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
- // This needs loop, and this is not the right place. Now done elsewhere.
-#ifndef FIX_BUGS
- if (SampleManager.IsMP3RadioChannelAvailable()) {
- if (gNumRetunePresses > RADIO_OFF)
- gNumRetunePresses -= RADIO_OFF;
+ switch (CGame::currArea)
+ {
+ case AREA_HOTEL:
+ case AREA_MALL:
+ case AREA_STRIP_CLUB:
+ case AREA_DIRT:
+ case AREA_BLOOD:
+ case AREA_OVALRING:
+ case AREA_MALIBU_CLUB:
+ m_bGameplayAllowsRadio = FALSE;
+ break;
+ default:
+ if (SampleManager.GetMusicVolume()) {
+ if (PlayerInCar())
+ m_bGameplayAllowsRadio = TRUE;
+ } else
+ m_bGameplayAllowsRadio = FALSE;
+ break;
+ }
+
+ if (!m_bGameplayAllowsRadio) {
+ nFramesSinceCutsceneEnded = -1;
+ gNumRetunePresses = 0;
+ gRetuneCounter = 0;
+ m_bSetNextStation = FALSE;
+ } else if (ped) {
+ if(!ped->DyingOrDead() && vehicle) {
+#ifdef GTA_PC
+ if (SampleManager.IsMP3RadioChannelAvailable()
+ && vehicle->m_nRadioStation < USERTRACK
+ && ControlsManager.GetIsKeyboardKeyJustDown(rsF9))
+ {
+ if (!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
+ gNumRetunePresses = 0;
+ gRetuneCounter = 20;
+ RadioStaticCounter = 0;
+ if (vehicle->m_nRadioStation < USERTRACK)
+ {
+ do
+ ++gNumRetunePresses;
+ while (gNumRetunePresses + vehicle->m_nRadioStation < USERTRACK);
}
+ }
+ }
#endif
+ if (CPad::GetPad(0)->ChangeStationJustDown())
+ {
+ if (!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
+ gNumRetunePresses++;
+ gRetuneCounter = 20;
+ RadioStaticCounter = 0;
}
+ }
#ifdef RADIO_SCROLL_TO_PREV_STATION
- else if(!CPad::GetPad(0)->ArePlayerControlsDisabled() && (CPad::GetPad(0)->GetMouseWheelDownJustDown() || CPad::GetPad(0)->GetMouseWheelUpJustDown())) {
+ else if(!CPad::GetPad(0)->ArePlayerControlsDisabled() && (CPad::GetPad(0)->GetMouseWheelDownJustDown() || CPad::GetPad(0)->GetMouseWheelUpJustDown())) {
+ if(!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
int scrollNext = ControlsManager.GetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, MOUSE);
- int scrollPrev = scrollNext == rsMOUSEWHEELUPBUTTON ? rsMOUSEWHEELDOWNBUTTON : scrollNext == rsMOUSEWHEELDOWNBUTTON ? rsMOUSEWHEELUPBUTTON : -1;
+ int scrollPrev = scrollNext == rsMOUSEWHEELUPBUTTON ? rsMOUSEWHEELDOWNBUTTON
+ : scrollNext == rsMOUSEWHEELDOWNBUTTON ? rsMOUSEWHEELUPBUTTON : -1;
- if (scrollPrev != -1 && !ControlsManager.IsAnyVehicleActionAssignedToMouseKey(scrollPrev)) {
- gRetuneCounter = 30;
+ if(scrollPrev != -1 && !ControlsManager.IsAnyVehicleActionAssignedToMouseKey(scrollPrev)) {
gNumRetunePresses--;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
+ gRetuneCounter = 20;
+ RadioStaticCounter = 0;
+ int track = gNumRetunePresses + vehicle->m_nRadioStation;
+ while(track < 0) track += NUM_RADIOS + 1;
+ while(track >= NUM_RADIOS + 1) track -= NUM_RADIOS + 1;
+ if(!DMAudio.IsMP3RadioChannelAvailable() && track == USERTRACK) gNumRetunePresses--;
}
}
+ }
#endif
}
- } else {
- nFramesSinceCutsceneEnded = -1;
}
- if (AudioManager.m_nPreviousUserPause)
- m_bPreviousPlayerInCar = FALSE;
- if (!m_bPlayerInCar) {
- if (m_bPreviousPlayerInCar) {
- if (m_nNextTrack != STREAMED_SOUND_RADIO_POLICE)
- m_nRadioInCar = m_nNextTrack;
- }
- ServiceAmbience();
- return;
+ if (m_bUserResumedGame)
+ {
+ m_bRadioStreamReady = FALSE;
+ m_bUserResumedGame = FALSE;
}
+ if (m_nPlayingTrack == NO_TRACK && m_nFrontendTrack == NO_TRACK)
+ m_bRadioStreamReady = FALSE;
- if (m_bPreviousPlayerInCar) {
- if (m_nAnnouncement < TOTAL_STREAMED_SOUNDS
- && (m_nNextTrack < RADIO_OFF || m_bAnnouncementInProgress)
- && ServiceAnnouncement())
+ if (m_bGameplayAllowsRadio)
+ {
+ if (!m_bRadioStreamReady)
{
- if (m_bAnnouncementInProgress) {
- m_bSetNextStation = FALSE;
+ if(vehicle == nil) {
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_WAVE; // huh?
return;
}
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = GetCarTuning();
+ if(m_bRadioSetByScript) {
+ if(UsesPoliceRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
+ else if(UsesTaxiRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
+ else {
+ m_nFrontendTrack = m_nRadioStationScript;
+ vehicle->m_nRadioStation = m_nRadioStationScript;
+ }
+ if(m_nRadioPosition != -1) {
+ m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
+ m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+ m_bRadioSetByScript = FALSE;
+ return;
+ }
+
+ // This starts the radio when you enter the car.
+ m_nFrontendTrack = GetCarTuning();
+ return;
+ }
+ if (m_nAnnouncement < NO_TRACK) {
+ if ((m_bAnnouncementInProgress || m_nFrontendTrack == m_nPlayingTrack) && ServiceAnnouncement()) {
+ if (m_bAnnouncementInProgress) {
+ m_bSetNextStation = FALSE;
+ gNumRetunePresses = 0;
+ gRetuneCounter = 0;
+ return;
+ }
+ if(m_nAnnouncement == NO_TRACK) {
+ m_nNextTrack = NO_TRACK;
+ m_nFrontendTrack = GetCarTuning();
+ m_bSetNextStation = FALSE;
+ gRetuneCounter = 0;
+ gNumRetunePresses = 0;
+ }
+ }
}
- if (SampleManager.IsMP3RadioChannelAvailable()
- && m_nNextTrack != STREAMED_SOUND_RADIO_MP3_PLAYER
- && ControlsManager.GetIsKeyboardKeyJustDown(rsF9))
+ if (!m_bAnnouncementInProgress
+ && m_nAnnouncement == NO_TRACK
+ && m_nPlayingTrack == STREAMED_SOUND_RADIO_MP3_PLAYER
+ && !SampleManager.IsStreamPlaying())
{
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = STREAMED_SOUND_RADIO_MP3_PLAYER;
- if (FindPlayerVehicle() != nil)
- FindPlayerVehicle()->m_nRadioStation = STREAMED_SOUND_RADIO_MP3_PLAYER;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
- gRetuneCounter = 0;
- gNumRetunePresses = 0;
- m_bSetNextStation = FALSE;
+ SampleManager.StartStreamedFile(STREAMED_SOUND_RADIO_MP3_PLAYER, 0);
}
- // Because when you switch radio back and forth, gNumRetunePresses will be 0 but gRetuneCounter won't.
+
+ if (!m_bRadioSetByScript)
+ {
+ // Because when you switch radio back and forth, gNumRetunePresses will be 0 but gRetuneCounter won't.
#ifdef RADIO_SCROLL_TO_PREV_STATION
- if (gRetuneCounter != 0) {
- if (gRetuneCounter > 1) gRetuneCounter--;
- else if (gRetuneCounter == 1) gRetuneCounter = -1;
- else if (gRetuneCounter == -1) {
- m_bSetNextStation = TRUE;
- gRetuneCounter = 0;
+ if(gRetuneCounter != 0) {
+ if(gRetuneCounter > 1)
+ gRetuneCounter--;
+ else if(gRetuneCounter == 1) {
+ m_bSetNextStation = TRUE;
+ gRetuneCounter = 0;
+ }
}
- }
#else
- if (gNumRetunePresses) {
- if (gRetuneCounter != 0) gRetuneCounter--;
- else m_bSetNextStation = TRUE;
- }
+ if (gNumRetunePresses != 0)
+ {
+ if (--gRetuneCounter == 0)
+ {
+ m_bSetNextStation = TRUE;
+ gRetuneCounter = 0;
+ }
+ }
#endif
- if (gRetuneCounter)
- AudioManager.DoPoliceRadioCrackle();
- if (m_bSetNextStation) {
- m_bSetNextStation = FALSE;
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = GetNextCarTuning();
- if (m_nNextTrack == STREAMED_SOUND_CITY_AMBIENT || m_nNextTrack == STREAMED_SOUND_WATER_AMBIENT)
- bRadioOff = TRUE;
+ if (gRetuneCounter)
+ {
+ int32 station = gNumRetunePresses + vehicle->m_nRadioStation;
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ while (station < 0) station += NUM_RADIOS + 1;
+#endif
+ while (station >= NUM_RADIOS + 1) station -= NUM_RADIOS + 1;
- if (m_nPlayingTrack == STREAMED_SOUND_CITY_AMBIENT || m_nPlayingTrack == STREAMED_SOUND_WATER_AMBIENT)
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 0.0f);
- }
- if (m_nNextTrack < RADIO_OFF) {
- if (ChangeRadioChannel()) {
- ServiceTrack();
- } else {
- m_bPlayerInCar = FALSE;
- if (FindPlayerVehicle())
- FindPlayerVehicle()->m_nRadioStation = m_nNextTrack;
- m_nNextTrack = NO_TRACK;
- }
- if (CTimer::GetIsSlowMotionActive()) {
- if (TheCamera.pTargetEntity != nil) {
- float DistToTargetSq = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr();
- if (DistToTargetSq >= SQR(55.0f)) {
- SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
- } else if (DistToTargetSq >= SQR(10.0f)) {
- volume = ((45.0f - (Sqrt(DistToTargetSq) - 10.0f)) / 45.0f * 100.0f);
- uint8 pan;
- if (AudioManager.ShouldDuckMissionAudio())
- volume /= 4;
- if (volume > 0) {
- CVector panVec;
- AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &panVec);
- pan = AudioManager.ComputePan(55.0f, &panVec);
- } else {
- pan = 0;
- }
- if (gRetuneCounter)
- volume /= 4;
- SampleManager.SetStreamedVolumeAndPan(volume, pan, FALSE);
- } else if (AudioManager.ShouldDuckMissionAudio()) {
- SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE);
- } else if (gRetuneCounter) {
- SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE);
- } else {
- SampleManager.SetStreamedVolumeAndPan(100, 63, FALSE);
+ // Scrolling back won't hit here, so increasing isn't problem
+ if (!DMAudio.IsMP3RadioChannelAvailable() && station == USERTRACK)
+ {
+ ++gNumRetunePresses;
+ station = RADIO_OFF;
+ }
+ if (station == RADIO_OFF)
+ {
+ if (gRetuneCounter == 19) // One less then what switching radio sets, so runs right after turning off radio
+ {
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_OFF, 0.0f);
+ RadioStaticCounter = 5;
}
}
- } else if (AudioManager.ShouldDuckMissionAudio()) {
- SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE);
- nFramesSinceCutsceneEnded = 0;
- } else {
- if (nFramesSinceCutsceneEnded == -1) {
- volume = 100;
- } else if (nFramesSinceCutsceneEnded < 20) {
- nFramesSinceCutsceneEnded++;
- volume = 25;
- } else if (nFramesSinceCutsceneEnded < 40) {
- volume = 3 * (nFramesSinceCutsceneEnded - 20) + 25;
- nFramesSinceCutsceneEnded++;
- } else {
- nFramesSinceCutsceneEnded = -1;
- volume = 100;
+ else
+ {
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ if (vehicle->m_nRadioStation == RADIO_OFF && gRetuneCounter == 19) // Right after turning on the radio
+#else
+ if (station == 0 && gRetuneCounter == 19) // Right after turning on the radio
+#endif
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_ON, 0.0f);
+ AudioManager.DoPoliceRadioCrackle();
}
- if (gRetuneCounter != 0)
- volume /= 4;
- SampleManager.SetStreamedVolumeAndPan(volume, 63, FALSE);
}
+ if (RadioStaticCounter < 2 && CTimer::GetTimeInMilliseconds() > RadioStaticTimer + 800)
+ {
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_RADIO_CHANGE, 0.0f);
+ RadioStaticCounter++;
+ RadioStaticTimer = CTimer::GetTimeInMilliseconds();
+ }
+ if (m_bSetNextStation)
+ m_nFrontendTrack = GetNextCarTuning();
+ if (m_nFrontendTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nFrontendTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ SetUpCorrectAmbienceTrack();
+ ServiceTrack(vehicle, ped);
+ if (m_bSetNextStation)
+ m_bSetNextStation = FALSE;
return;
}
- if (bRadioOff) {
- m_nNextTrack = m_nPlayingTrack;
- if (FindPlayerVehicle() != nil)
- FindPlayerVehicle()->m_nRadioStation = RADIO_OFF;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_OFF, 0.0f);
+ if (UsesPoliceRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
+ else if (UsesTaxiRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
+ else {
+ m_nFrontendTrack = m_nRadioStationScript;
+ vehicle->m_nRadioStation = m_nRadioStationScript;
}
- ServiceAmbience();
+
+ if (m_nRadioPosition != -1) {
+ m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
+ m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+
+ gRetuneCounter = 0;
+ gNumRetunePresses = 0;
+ m_bSetNextStation = FALSE;
+ m_bRadioSetByScript = FALSE;
+ if (m_nFrontendTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nFrontendTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ SetUpCorrectAmbienceTrack();
+ ServiceTrack(vehicle, ped);
+ if (m_bSetNextStation)
+ m_bSetNextStation = FALSE;
return;
}
- if (m_bRadioSetByScript) {
- if (UsesPoliceRadio(FindPlayerVehicle())) {
- m_nNextTrack = STREAMED_SOUND_RADIO_POLICE;
- } else {
- m_nNextTrack = m_nRadioStationScript;
- if (FindPlayerVehicle()->m_nRadioStation == m_nNextTrack) {
- m_nPlayingTrack = NO_TRACK;
- SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
- SampleManager.StopStreamedFile();
- }
- if (m_nRadioPosition != -1) {
- m_aTracks[m_nNextTrack].m_nPosition = m_nRadioPosition;
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+
+ if (m_bAnnouncementInProgress)
+ {
+ SampleManager.StopStreamedFile();
+ if (SampleManager.IsStreamPlaying())
+ return;
+ g_bAnnouncementReadPosAlready = FALSE;
+ m_nAnnouncement = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
+ m_nNextTrack = NO_TRACK;
+ m_nFrontendTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ }
+ SetUpCorrectAmbienceTrack();
+ ServiceTrack(nil, ped);
+}
+
+void
+cMusicManager::SetUpCorrectAmbienceTrack()
+{
+ switch (CGame::currArea)
+ {
+ case AREA_MAIN_MAP:
+ case AREA_EVERYWHERE:
+ if (CTheScripts::RiotIntensity != 0 && ((TheCamera.GetPosition() - vecRiotPosition).MagnitudeSqr() < SQR(65.0f)))
+ m_nFrontendTrack = STREAMED_SOUND_LAW4RIOT_AMBIENT;
+ else if (TheCamera.DistanceToWater <= 90.0f) {
+ if (CCullZones::bAtBeachForAudio) {
+ if (CWeather::OldWeatherType != WEATHER_HURRICANE && CWeather::NewWeatherType != WEATHER_HURRICANE || CWeather::Wind <= 1.0f)
+ m_nFrontendTrack = STREAMED_SOUND_BEACH_AMBIENT;
+ else
+ m_nFrontendTrack = STREAMED_SOUND_HAVANA_BEACH_AMBIENT;
}
+ else if (CWeather::OldWeatherType != WEATHER_HURRICANE && CWeather::NewWeatherType != WEATHER_HURRICANE || CWeather::Wind <= 1.0f)
+ m_nFrontendTrack = STREAMED_SOUND_WATER_AMBIENT;
+ else
+ m_nFrontendTrack = STREAMED_SOUND_HAVANA_WATER_AMBIENT;
}
- } else {
- m_nNextTrack = GetCarTuning();
+ else if (CWeather::OldWeatherType != WEATHER_HURRICANE && CWeather::NewWeatherType != WEATHER_HURRICANE || CWeather::Wind <= 1.0f)
+ m_nFrontendTrack = STREAMED_SOUND_CITY_AMBIENT;
+ else
+ m_nFrontendTrack = STREAMED_SOUND_HAVANA_CITY_AMBIENT;
+ break;
+ case AREA_HOTEL:
+ m_nFrontendTrack = STREAMED_SOUND_HOTEL_AMBIENT;
+ break;
+ case AREA_MALL:
+ m_nFrontendTrack = STREAMED_SOUND_MALL_AMBIENT;
+ break;
+ case AREA_STRIP_CLUB:
+ m_nFrontendTrack = STREAMED_SOUND_STRIPCLUB_AMBIENT;
+ break;
+ case AREA_DIRT:
+ case AREA_BLOOD:
+ case AREA_OVALRING:
+ m_nFrontendTrack = STREAMED_SOUND_DIRTRING_AMBIENT;
+ break;
+ case AREA_MALIBU_CLUB:
+ m_nFrontendTrack = STREAMED_SOUND_MALIBU_AMBIENT;
+ break;
+ case AREA_MANSION:
+ case AREA_BANK:
+ case AREA_LAWYERS:
+ case AREA_COFFEE_SHOP:
+ case AREA_CONCERT_HALL:
+ case AREA_STUDIO:
+ case AREA_RIFLE_RANGE:
+ case AREA_BIKER_BAR:
+ case AREA_POLICE_STATION:
+ m_nFrontendTrack = STREAMED_SOUND_AMBSIL_AMBIENT;
+ break;
}
- if (m_nNextTrack >= RADIO_OFF) {
- ServiceAmbience();
+}
+
+float
+GetHeightScale()
+{
+ if (TheCamera.GetPosition().z > 20.0f) {
+ if (TheCamera.GetPosition().z < 50.0f)
+ return 1.0f - (TheCamera.GetPosition().z - 20.0f) / 30.0f;
+ return 0.0f;
+ }
+ return 1.0f;
+}
+
+void
+cMusicManager::ComputeAmbienceVol(bool8 reset, uint8& outVolume)
+{
+ static float fVol = 0.0f;
+
+ float fHeightScale = GetHeightScale();
+
+ if (CTheScripts::RiotIntensity > 0) {
+ float distToRiotSq = (TheCamera.GetPosition() - vecRiotPosition).MagnitudeSqr();
+ if (distToRiotSq < SQR(100.0f)) {
+ if (distToRiotSq >= SQR(65.0f))
+ outVolume = (Sqrt(distToRiotSq) - 65.0f) / 35.0f * (127.0f * fHeightScale);
+ else if (distToRiotSq >= SQR(20.0f))
+ outVolume = (CTheScripts::RiotIntensity * (1.0f - (Sqrt(distToRiotSq) - 20.0f) / 45.0f) * (127.0f * fHeightScale)) / MAX_VOLUME;
+ else
+ outVolume = (CTheScripts::RiotIntensity * (127.0f * fHeightScale)) / MAX_VOLUME;
+ return;
+ }
+ }
+
+ if (reset)
+ fVol = 0.0f;
+ else if (fVol < 60.0f) {
+ if ((m_nPlayingTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT) && (m_nPlayingTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT))
+ fVol += 20.0f;
+ else
+ fVol += 1.0f;
+ fVol = Min(fVol, 60.0f);
+ }
+
+ if ((m_nPlayingTrack >= STREAMED_SOUND_MALL_AMBIENT) && (m_nPlayingTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)) {
+ outVolume = fVol;
return;
}
- if (ChangeRadioChannel()) {
- if (m_bRadioSetByScript) {
- m_bRadioSetByScript = FALSE;
- FindPlayerVehicle()->m_nRadioStation = m_nNextTrack;
+
+ if (CWeather::OldWeatherType == WEATHER_HURRICANE || CWeather::NewWeatherType == WEATHER_HURRICANE) {
+ if (CWeather::Wind > 1.0f) {
+ outVolume = (CWeather::Wind - 1.0f) * fVol;
+ return;
}
- } else {
- m_bPlayerInCar = FALSE;
- m_nNextTrack = NO_TRACK;
+ fVol = (1.0f - CWeather::Wind) * fVol;
+ }
+
+ if (TheCamera.DistanceToWater > 140.0f) {
+ outVolume = fVol;
+ return;
+ }
+
+ if (TheCamera.DistanceToWater > 90.0f) {
+ outVolume = ((TheCamera.DistanceToWater - 90.0f) / 50.0f * fVol * fHeightScale);
+ return;
}
+
+ if (TheCamera.DistanceToWater > 40.0f) {
+ outVolume = fVol;
+ return;
+ }
+
+ outVolume = (90.0f - fHeightScale) / 50.0f * fVol;
}
-void
-cMusicManager::StopFrontEndTrack()
+bool8
+cMusicManager::ServiceAnnouncement()
{
- if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nNextTrack != NO_TRACK) {
- m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_bAnnouncementInProgress) {
+ if (SampleManager.IsStreamPlaying())
+ m_nPlayingTrack = m_nNextTrack;
+ else if (m_nPlayingTrack != NO_TRACK) {
+ m_nAnnouncement = NO_TRACK;
+ m_bAnnouncementInProgress = FALSE;
+ m_nPlayingTrack = NO_TRACK;
+ }
+ return TRUE;
+ } else if (SampleManager.IsStreamPlaying()) {
+ if (m_nPlayingTrack != NO_TRACK && !g_bAnnouncementReadPosAlready) {
+ RecordRadioStats();
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ g_bAnnouncementReadPosAlready = TRUE;
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
SampleManager.StopStreamedFile();
+ } else {
+ g_bAnnouncementReadPosAlready = FALSE;
m_nPlayingTrack = NO_TRACK;
- m_nNextTrack = NO_TRACK;
+ m_nNextTrack = m_nAnnouncement;
+ SampleManager.SetStreamedFileLoopFlag(FALSE);
+ SampleManager.StartStreamedFile(m_nNextTrack, 0);
+ SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, FALSE);
+ m_bAnnouncementInProgress = TRUE;
}
-}
-void
-cMusicManager::PlayAnnouncement(uint8 announcement)
-{
- if (IsInitialised() && !m_bDisabled && !m_bAnnouncementInProgress)
- m_nAnnouncement = announcement;
+ return TRUE;
}
void
-cMusicManager::PlayFrontEndTrack(uint8 track, bool8 bPlayInFrontend)
+cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped)
{
- if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS) {
- if (m_nMusicMode == MUSICMODE_GAME) {
- if (m_nNextTrack != NO_TRACK) {
- if (m_bAnnouncementInProgress) {
- m_nAnnouncement = NO_TRACK;
- m_bAnnouncementInProgress = FALSE;
- }
- m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ static bool8 bRadioStatsRecorded = FALSE;
+ static bool8 bRadioStatsRecorded2 = FALSE;
+ uint8 volume;
+ if (!m_bTrackChangeStarted)
+ m_nNextTrack = m_nFrontendTrack;
+ if (gRetuneCounter != 0 || m_bSetNextStation) {
+ if (SampleManager.IsStreamPlaying()) {
+ if (m_nPlayingTrack != NO_TRACK && !bRadioStatsRecorded) {
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ RecordRadioStats();
+ bRadioStatsRecorded = TRUE;
}
+ SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
SampleManager.StopStreamedFile();
- } else if (m_nMusicMode == MUSICMODE_FRONTEND) {
- if (m_nNextTrack != NO_TRACK) {
- m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+ return;
+ }
+
+ if (bRadioStatsRecorded) {
+ bRadioStatsRecorded = FALSE;
+ m_nPlayingTrack = NO_TRACK;
+ }
+
+ if (m_nNextTrack != m_nPlayingTrack)
+ {
+ m_bTrackChangeStarted = TRUE;
+ SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
+ if (!(AudioManager.m_FrameCounter & 1)) {
+ if (m_bVerifyNextTrackStartedToPlay || !SampleManager.IsStreamPlaying()) {
+ bRadioStatsRecorded2 = FALSE;
+ if (SampleManager.IsStreamPlaying()) {
+ m_nPlayingTrack = m_nNextTrack;
+ m_bVerifyNextTrackStartedToPlay = FALSE;
+ m_bTrackChangeStarted = FALSE;
+ if (veh) {
+#ifdef FIX_BUGS
+ if (m_nPlayingTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ veh->m_nRadioStation = RADIO_OFF;
+ else if (m_nPlayingTrack < STREAMED_SOUND_CITY_AMBIENT)
+ veh->m_nRadioStation = m_nPlayingTrack;
+#else
+ if (veh->m_nRadioStation >= STREAMED_SOUND_CITY_AMBIENT && veh->m_nRadioStation <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ veh->m_nRadioStation = RADIO_OFF;
+ else
+ veh->m_nRadioStation = m_nPlayingTrack;
+#endif
+ }
+ } else {
+ uint32 pos = GetTrackStartPos(m_nNextTrack);
+ if (m_nNextTrack != NO_TRACK) {
+ SampleManager.SetStreamedFileLoopFlag(TRUE);
+ SampleManager.StartStreamedFile(m_nNextTrack, pos);
+ if (m_nFrontendTrack < STREAMED_SOUND_CITY_AMBIENT || m_nFrontendTrack > STREAMED_SOUND_AMBSIL_AMBIENT)
+ {
+ m_nVolumeLatency = 10;
+ m_nCurrentVolume = 0;
+ m_nMaxVolume = 100;
+ SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, FALSE);
+ }
+ else
+ {
+ ComputeAmbienceVol(TRUE, volume);
+ SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE);
+ }
+ if (m_nNextTrack < STREAMED_SOUND_CITY_AMBIENT)
+ m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
+ m_bVerifyNextTrackStartedToPlay = TRUE;
+ }
+ }
+ } else {
+ if (m_nPlayingTrack == NO_TRACK)
+ debug("m_nPlayingTrack == NO_TRACK, yet track playing - tidying up\n");
+ else if (!bRadioStatsRecorded2)
+ {
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ bRadioStatsRecorded2 = TRUE;
+ RecordRadioStats();
+ if (m_nPlayingTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT)
+ {
+ if (m_nNextTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT && m_nNextTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT)
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_HURRICANE, 0.0);
+ }
+ }
+ SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
+ SampleManager.StopStreamedFile();
}
- SampleManager.StopStreamedFile();
}
+ return;
+ }
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = track;
- m_bPlayInFrontend = bPlayInFrontend;
- m_bFrontendTrackFinished = FALSE;
- m_bDoTrackService = TRUE;
- bHasStarted = FALSE;
- if (m_nNextTrack < NUM_RADIOS) {
- gRetuneCounter = 0;
- gNumRetunePresses = 0;
+ if (m_nPlayingTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ {
+ ComputeAmbienceVol(FALSE, volume);
+ SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE);
+ return;
+ }
+ if (CTimer::GetIsSlowMotionActive())
+ {
+ if (TheCamera.pTargetEntity)
+ {
+ float DistToTargetSq = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr();
+ if (DistToTargetSq >= SQR(55.0f))
+ {
+ SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
+ }
+ else if (DistToTargetSq >= SQR(10.0f))
+ {
+ volume = (45.0f - (Sqrt(DistToTargetSq) - 10.0f)) / 45.0f * m_nCurrentVolume;
+ if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1))
+ volume /= 4;
+
+ uint8 pan = 0;
+ if (volume > 0)
+ {
+ CVector panVec;
+ AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &panVec);
+ pan = AudioManager.ComputePan(55.0f, &panVec);
+ }
+ if (gRetuneCounter != 0)
+ volume = 0;
+ SampleManager.SetStreamedVolumeAndPan(volume, pan, FALSE);
+ }
+ else if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1))
+ SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, FALSE);
+ else if (gRetuneCounter != 0)
+ SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
+ else
+ SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, FALSE);
+ }
+ } else if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1)) {
+ SampleManager.SetStreamedVolumeAndPan(Min(m_nCurrentVolume, 25), 63, FALSE);
+ nFramesSinceCutsceneEnded = 0;
+ } else {
+ if (nFramesSinceCutsceneEnded == -1)
+ volume = m_nCurrentVolume;
+ else if (nFramesSinceCutsceneEnded < 20)
+ {
+ volume = Min(m_nCurrentVolume, 25);
+ nFramesSinceCutsceneEnded++;
}
+ else if (nFramesSinceCutsceneEnded < 40)
+ {
+ volume = Min(m_nCurrentVolume, 3 * (nFramesSinceCutsceneEnded - 20) + 25);
+ nFramesSinceCutsceneEnded++;
+ }
+ else
+ {
+ volume = m_nCurrentVolume;
+ nFramesSinceCutsceneEnded = -1;
+ }
+ if (gRetuneCounter != 0)
+ volume = 0;
+ SampleManager.SetStreamedVolumeAndPan(volume, 63, FALSE);
}
+ if (m_nVolumeLatency > 0)
+ m_nVolumeLatency--;
+ else if (m_nCurrentVolume < m_nMaxVolume)
+ m_nCurrentVolume = Min(m_nMaxVolume, m_nCurrentVolume + 6);
}
void
-cMusicManager::PreloadCutSceneMusic(uint8 track)
+cMusicManager::PreloadCutSceneMusic(uint32 track)
{
if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS && m_nMusicMode == MUSICMODE_CUTSCENE) {
AudioManager.ResetPoliceRadio();
@@ -771,7 +1092,7 @@ cMusicManager::PreloadCutSceneMusic(uint8 track)
SampleManager.StopStreamedFile();
SampleManager.PreloadStreamedFile(track);
SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE);
- m_nNextTrack = track;
+ m_nPlayingTrack = track;
}
}
@@ -787,16 +1108,87 @@ cMusicManager::StopCutSceneMusic(void)
{
if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_CUTSCENE) {
SampleManager.StopStreamedFile();
- m_nNextTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ }
+}
+
+void
+cMusicManager::PlayFrontEndTrack(uint32 track, bool8 loopFlag)
+{
+ if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS && (m_nUpcomingMusicMode == MUSICMODE_FRONTEND || m_nMusicMode == MUSICMODE_FRONTEND))
+ {
+ m_nFrontendTrack = track;
+ m_FrontendLoopFlag = loopFlag;
+ if (m_nMusicMode != MUSICMODE_FRONTEND)
+ m_bEarlyFrontendTrack = TRUE;
+ }
+}
+
+void
+cMusicManager::StopFrontEndTrack()
+{
+ if (m_nUpcomingMusicMode == MUSICMODE_FRONTEND || m_nMusicMode == MUSICMODE_FRONTEND)
+ m_nFrontendTrack = NO_TRACK;
+}
+
+void
+cMusicManager::PlayAnnouncement(uint32 announcement)
+{
+ if (IsInitialised() && !m_bDisabled && !m_bAnnouncementInProgress)
+ m_nAnnouncement = announcement;
+}
+
+uint32
+cMusicManager::GetNextCarTuning()
+{
+ CVehicle *veh = AudioManager.FindVehicleOfPlayer();
+ if (veh == nil) return STREAMED_SOUND_CITY_AMBIENT;
+ if (UsesPoliceRadio(veh)) return STREAMED_SOUND_RADIO_POLICE;
+ if (UsesTaxiRadio(veh)) return STREAMED_SOUND_RADIO_TAXI;
+ if (gNumRetunePresses != 0) {
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ // m_nRadioStation is unsigned, so...
+ int station = veh->m_nRadioStation + gNumRetunePresses;
+ while(station < 0) station += NUM_RADIOS + 1;
+ while(station >= NUM_RADIOS + 1) station -= NUM_RADIOS + 1;
+ veh->m_nRadioStation = station;
+#else
+ veh->m_nRadioStation += gNumRetunePresses;
+ while(veh->m_nRadioStation >= NUM_RADIOS + 1)
+ veh->m_nRadioStation -= NUM_RADIOS + 1;
+#endif
+ DMAudio.IsMP3RadioChannelAvailable(); // woof, just call and do nothing =P they manipulate gNumRetunePresses on DisplayRadioStationName in this case
+ gNumRetunePresses = 0;
}
+ return veh->m_nRadioStation;
}
uint32
-cMusicManager::GetTrackStartPos(uint8 track)
+cMusicManager::GetCarTuning()
{
+ CVehicle* veh = AudioManager.FindVehicleOfPlayer();
+ if (veh == nil) return STREAMED_SOUND_CITY_AMBIENT;
+ if (UsesPoliceRadio(veh)) return STREAMED_SOUND_RADIO_POLICE;
+ if (UsesTaxiRadio(veh)) return STREAMED_SOUND_RADIO_TAXI;
+ if (veh->m_nRadioStation == USERTRACK && !SampleManager.IsMP3RadioChannelAvailable())
+ veh->m_nRadioStation = AudioManager.m_anRandomTable[2] % USERTRACK;
+ return veh->m_nRadioStation;
+}
+
+float*
+cMusicManager::GetListenTimeArray()
+{
+ return aListenTimeArray;
+}
+
+uint32
+cMusicManager::GetTrackStartPos(uint32 track)
+{
+ if (!IsInitialised()) return 0;
+
uint32 pos = m_aTracks[track].m_nPosition;
if (CTimer::GetTimeInMillisecondsPauseMode() > m_aTracks[track].m_nLastPosCheckTimer)
- pos += Min(CTimer::GetTimeInMillisecondsPauseMode() - m_aTracks[track].m_nLastPosCheckTimer, 90000);
+ pos += Min(CTimer::GetTimeInMillisecondsPauseMode() - m_aTracks[track].m_nLastPosCheckTimer, 270000);
else
m_aTracks[track].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
@@ -805,222 +1197,227 @@ cMusicManager::GetTrackStartPos(uint8 track)
return pos;
}
-
-bool8
-cMusicManager::UsesPoliceRadio(CVehicle *veh)
+uint32
+cMusicManager::GetRadioPosition(uint32 station)
{
- switch (veh->GetModelIndex())
- {
- case MI_FBICAR:
- case MI_POLICE:
- case MI_ENFORCER:
- case MI_PREDATOR:
- case MI_RHINO:
- case MI_BARRACKS:
- return TRUE;
- }
- return FALSE;
+ if (station < NUM_RADIOS)
+ return GetTrackStartPos(station);
+ return 0;
}
-void
-cMusicManager::ServiceAmbience()
+uint32
+cMusicManager::GetFavouriteRadioStation()
{
- uint8 volume;
+ uint32 favstation = 0;
- if (m_bAnnouncementInProgress) {
- m_nAnnouncement = NO_TRACK;
- m_bAnnouncementInProgress = FALSE;
- }
- if (m_nNextTrack < RADIO_OFF) {
- if (SampleManager.IsStreamPlaying()) {
- m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- SampleManager.StopStreamedFile();
- m_nNextTrack = NO_TRACK;
- return;
- }
- m_nNextTrack = RADIO_OFF;
+ for (int i = 1; i < NUM_RADIOS; i++) {
+ if (aListenTimeArray[i] > aListenTimeArray[favstation])
+ favstation = i;
}
- if (CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING && !SampleManager.IsStreamPlaying()) {
- m_nNextTrack = NO_TRACK;
- return;
- }
-
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = TheCamera.DistanceToWater <= 45.0f ? STREAMED_SOUND_WATER_AMBIENT : STREAMED_SOUND_CITY_AMBIENT;
- if (m_nNextTrack == m_nPlayingTrack) {
- ComputeAmbienceVol(FALSE, volume);
- SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE);
- if (m_bVerifyAmbienceTrackStartedToPlay) {
- if (SampleManager.IsStreamPlaying())
- m_bVerifyAmbienceTrackStartedToPlay = FALSE;
- } else ServiceTrack();
- } else {
- if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- SampleManager.StopStreamedFile();
- }
- uint32 pos = GetTrackStartPos(m_nNextTrack);
- SampleManager.SetStreamedVolumeAndPan(0, 63, TRUE);
- if (SampleManager.StartStreamedFile(m_nNextTrack, pos)) {
- ComputeAmbienceVol(TRUE, volume);
- SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE);
- m_bVerifyAmbienceTrackStartedToPlay = TRUE;
- } else
- m_nNextTrack = NO_TRACK;
- }
+ return favstation;
}
-void
-cMusicManager::ComputeAmbienceVol(bool8 reset, uint8 &outVolume)
+bool8
+cMusicManager::CheckForMusicInterruptions()
{
- static float fVol = 0.0f;
-
- if (reset)
- fVol = 0.0f;
- else if (fVol < 60.0f)
- fVol += 1.0f;
-
- if (TheCamera.DistanceToWater > 70.0f)
- outVolume = fVol;
- else if (TheCamera.DistanceToWater > 45.0f)
- outVolume = (TheCamera.DistanceToWater - 45.0f) / 25.0f * fVol;
- else if (TheCamera.DistanceToWater > 20.0f)
- outVolume = (45.0f - TheCamera.DistanceToWater) / 25.0f * fVol;
- else
- outVolume = fVol;
+ return (m_nPlayingTrack == STREAMED_SOUND_MISSION_COMPLETED) || (m_nPlayingTrack == STREAMED_SOUND_CUTSCENE_FINALE);
}
void
-cMusicManager::ServiceTrack()
+cMusicManager::SetMalibuClubTrackPos(uint8 scriptObject)
{
- if (m_bDoTrackService) {
- if (!SampleManager.IsStreamPlaying())
- SampleManager.StartStreamedFile(m_nNextTrack, 0);
+ if (!IsInitialised())
+ m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nPosition = 8640;
+ if (m_nNextTrack != STREAMED_SOUND_MALIBU_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_MALIBU_AMBIENT) {
+ switch (scriptObject)
+ {
+ case SCRIPT_SOUND_NEW_BUILDING_MALIBU_1:
+ m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nPosition = (AudioManager.m_anRandomTable[0] % 128) + 8640;
+ break;
+ case SCRIPT_SOUND_NEW_BUILDING_MALIBU_2:
+ m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nPosition = (AudioManager.m_anRandomTable[0] % 128) + 286720;
+ break;
+ case SCRIPT_SOUND_NEW_BUILDING_MALIBU_3:
+ m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nPosition = (AudioManager.m_anRandomTable[0] % 128) + 509120;
+ break;
+ }
+ m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
}
-bool8
-cMusicManager::ServiceAnnouncement()
+void
+cMusicManager::SetStripClubTrackPos(uint8 scriptObject)
{
- static int8 cCheck = 0;
- if (m_bAnnouncementInProgress) {
- if (!SampleManager.IsStreamPlaying()) {
- m_nAnnouncement = NO_TRACK;
- m_bAnnouncementInProgress = FALSE;
+ if (!IsInitialised())
+ m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nPosition = 0;
+ if (m_nNextTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT)
+ {
+ switch (scriptObject)
+ {
+ case SCRIPT_SOUND_NEW_BUILDING_STRIP_1:
+ m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nPosition = AudioManager.m_anRandomTable[0] % 128;
+ break;
+ case SCRIPT_SOUND_NEW_BUILDING_STRIP_2:
+ m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nPosition = (AudioManager.m_anRandomTable[0] % 128) + 320200;
+ break;
+ case SCRIPT_SOUND_NEW_BUILDING_STRIP_3:
+ m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nPosition = (AudioManager.m_anRandomTable[0] % 128) + 672000;
+ break;
}
- return TRUE;
+ m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
+}
- if (++cCheck >= 30) {
- cCheck = 0;
- int pos = SampleManager.GetStreamedFilePosition();
- if (SampleManager.IsStreamPlaying()) {
- if (m_nNextTrack != NO_TRACK) {
- m_aTracks[m_nNextTrack].m_nPosition = pos;
- m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- SampleManager.StopStreamedFile();
+void
+cMusicManager::DisplayRadioStationName()
+{
+ uint8 gStreamedSound;
+ static wchar *pCurrentStation = nil;
+ static uint8 cDisplay = 0;
+
+ if(!CTimer::GetIsPaused() && !TheCamera.m_WideScreenOn && PlayerInCar() &&
+ !CReplay::IsPlayingBack()) {
+ CVehicle *vehicle = AudioManager.FindVehicleOfPlayer();
+
+ if (vehicle)
+ {
+ // Prev scroll needs it to be signed, and m_nFrontendTrack can be NO_TRACK thus FIX_BUGS
+#if defined RADIO_SCROLL_TO_PREV_STATION || defined FIX_BUGS
+ int track;
+#else
+ uint8 track;
+#endif
+ gStreamedSound = vehicle->m_nRadioStation;
+ if (gStreamedSound >= STREAMED_SOUND_CITY_AMBIENT && gStreamedSound <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ gStreamedSound = RADIO_OFF;
+ if (gNumRetunePresses != 0)
+ {
+ track = gNumRetunePresses + gStreamedSound;
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ while (track < 0) track += NUM_RADIOS + 1;
+#endif
+ while (track >= NUM_RADIOS + 1) track -= NUM_RADIOS + 1;
+
+ // On scrolling back we handle this condition on key press. No need to change this.
+ if (!DMAudio.IsMP3RadioChannelAvailable() && track == USERTRACK)
+ gNumRetunePresses++;
}
- }
+ else
+#ifdef RADIO_OFF_TEXT
+ track = GetCarTuning(); // gStreamedSound or veh->m_nRadioStation would also work, but these don't cover police/taxi radios
+#else
+ track = m_nFrontendTrack;
+#endif
+ wchar* string = nil;
+ switch (track) {
+ case WILDSTYLE: string = TheText.Get("FEA_FM0"); break;
+ case FLASH_FM: string = TheText.Get("FEA_FM1"); break;
+ case KCHAT: string = TheText.Get("FEA_FM2"); break;
+ case FEVER: string = TheText.Get("FEA_FM3"); break;
+ case V_ROCK: string = TheText.Get("FEA_FM4"); break;
+ case VCPR: string = TheText.Get("FEA_FM5"); break;
+ case RADIO_ESPANTOSO: string = TheText.Get("FEA_FM6"); break;
+ case EMOTION: string = TheText.Get("FEA_FM7"); break;
+ case WAVE: string = TheText.Get("FEA_FM8"); break;
+ case USERTRACK:
+ if (!SampleManager.IsMP3RadioChannelAvailable())
+ return;
+ string = TheText.Get("FEA_MP3"); break;
+#ifdef RADIO_OFF_TEXT
+ case RADIO_OFF: {
+ // Otherwise RADIO OFF will be seen after pausing-resuming game and Mission Complete text
+ if (!m_bRadioStreamReady || !m_bGameplayAllowsRadio)
+ return;
- SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
- if (SampleManager.StartStreamedFile(m_nAnnouncement, 0)) {
- SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, FALSE);
- m_bAnnouncementInProgress = TRUE;
- m_nPlayingTrack = m_nNextTrack;
- m_nNextTrack = m_nAnnouncement;
- return TRUE;
+ extern wchar WideErrorString[];
+
+ string = TheText.Get("FEA_NON");
+ if (string == WideErrorString) {
+ pCurrentStation = nil;
+ return;
+ }
+ break;
+ }
+#endif
+ default: return;
+ };
+
+ if (pCurrentStation != string) {
+ pCurrentStation = string;
+ cDisplay = 60;
+ }
+ else {
+ if (cDisplay == 0) return;
+#ifdef FIX_BUGS
+ cDisplay -= CTimer::GetLogicalFramesPassed();
+#else
+ cDisplay--;
+#endif
+ }
+
+ CFont::SetJustifyOff();
+ CFont::SetBackgroundOff();
+ CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f));
+ CFont::SetPropOn();
+ CFont::SetFontStyle(FONT_STANDARD);
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH));
+ CFont::SetColor(CRGBA(0, 0, 0, 255));
+ CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(22.0f) + SCREEN_SCALE_Y(2.0f), pCurrentStation);
+
+ if (gNumRetunePresses)
+ CFont::SetColor(CRGBA(102, 133, 143, 255));
+ else
+ CFont::SetColor(CRGBA(147, 196, 211, 255));
+
+ CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_Y(22.0f), pCurrentStation);
+ CFont::DrawFonts();
}
+ }
+ // Always show station text after entering car. Same behaviour as III and SA.
+#ifdef FIX_BUGS
+ else
+ pCurrentStation = nil;
+#endif
+}
- if (cCheck != 0) cCheck--;
- else cCheck = 30;
+bool8
+cMusicManager::UsesPoliceRadio(CVehicle *veh)
+{
+ switch (veh->GetModelIndex())
+ {
+ case MI_VCNMAV:
+ case MI_POLMAV:
+ case MI_COASTG:
+ case MI_RHINO:
+ case MI_BARRACKS:
+ return TRUE;
+ case MI_MRWHOOP:
+ case MI_HUNTER:
return FALSE;
}
-
- return FALSE;
+ return veh->UsesSiren();
}
-uint8
-cMusicManager::GetCarTuning()
+bool8
+cMusicManager::UsesTaxiRadio(CVehicle *veh)
{
- CVehicle *veh = FindPlayerVehicle();
- if (veh == nil) return RADIO_OFF;
- if (UsesPoliceRadio(veh)) return POLICE_RADIO;
- if (veh->m_nRadioStation == USERTRACK && !SampleManager.IsMP3RadioChannelAvailable())
- veh->m_nRadioStation = AudioManager.m_anRandomTable[2] % USERTRACK;
- return veh->m_nRadioStation;
+ if (veh->GetModelIndex() != MI_KAUFMAN) return FALSE;
+ return CTheScripts::bPlayerHasMetDebbieHarry;
}
-uint8
-cMusicManager::GetNextCarTuning()
+void
+cMusicManager::ServiceAmbience()
{
- CVehicle *veh = FindPlayerVehicle();
- if (veh == nil) return RADIO_OFF;
- if (UsesPoliceRadio(veh)) return POLICE_RADIO;
- if (gNumRetunePresses != 0) {
-#ifdef RADIO_SCROLL_TO_PREV_STATION
- if (gNumRetunePresses < 0) {
- while (gNumRetunePresses < 0) {
- if(veh->m_nRadioStation == HEAD_RADIO) {
- veh->m_nRadioStation = RADIO_OFF;
- } else if(veh->m_nRadioStation == RADIO_OFF || veh->m_nRadioStation == NUM_RADIOS) {
- veh->m_nRadioStation = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1;
- } else
- veh->m_nRadioStation--;
-
- ++gNumRetunePresses;
- }
- } else
-#endif
- if (SampleManager.IsMP3RadioChannelAvailable()) {
- if (veh->m_nRadioStation == RADIO_OFF)
- veh->m_nRadioStation = NUM_RADIOS;
- veh->m_nRadioStation += gNumRetunePresses;
-#ifdef FIX_BUGS
- while (veh->m_nRadioStation > NUM_RADIOS)
- veh->m_nRadioStation -= (NUM_RADIOS + 1);
-#endif
- if (veh->m_nRadioStation == NUM_RADIOS)
- veh->m_nRadioStation = RADIO_OFF;
-#ifndef FIX_BUGS
- else if (veh->m_nRadioStation > NUM_RADIOS)
- veh->m_nRadioStation -= (NUM_RADIOS + 1);
-#endif
- } else if (gNumRetunePresses + veh->m_nRadioStation >= USERTRACK) {
- while (gNumRetunePresses) {
- if (veh->m_nRadioStation == RADIO_OFF)
- veh->m_nRadioStation = HEAD_RADIO;
- else if (veh->m_nRadioStation < USERTRACK)
- ++veh->m_nRadioStation;
-
- if (veh->m_nRadioStation == USERTRACK)
- veh->m_nRadioStation = RADIO_OFF;
- --gNumRetunePresses;
- }
- } else
- veh->m_nRadioStation += gNumRetunePresses;
- gNumRetunePresses = 0;
- }
- return veh->m_nRadioStation;
}
bool8
cMusicManager::ChangeRadioChannel()
{
- if (m_nNextTrack != m_nPlayingTrack) {
- if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition();
- m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE);
- SampleManager.StopStreamedFile();
- }
- if (SampleManager.IsStreamPlaying())
- return FALSE;
- if (!SampleManager.StartStreamedFile(m_nNextTrack, GetTrackStartPos(m_nNextTrack)))
- return FALSE;
- SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, FALSE);
- }
return TRUE;
}
+
+// these two are empty
+void cMusicManager::Enable() {}
+void cMusicManager::Disable() {}