Remove cMissionAudio, move cAMCrime array outside of cPoliceRadioQueue (R* vision)

This commit is contained in:
Sergeanur 2021-08-21 12:18:11 +03:00
parent 7d5b1e6c2e
commit b683c047dc
4 changed files with 141 additions and 133 deletions

View File

@ -154,13 +154,13 @@ cAudioManager::PostInitialiseGameSpecificSetup()
if (m_nBridgeEntity >= 0) if (m_nBridgeEntity >= 0)
SetEntityStatus(m_nBridgeEntity, TRUE); SetEntityStatus(m_nBridgeEntity, TRUE);
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; m_nMissionAudioSampleIndex = NO_SAMPLE;
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
m_sMissionAudio.m_bIsPlaying = FALSE; m_bIsMissionAudioPlaying = FALSE;
m_sMissionAudio.m_bIsPlayed = FALSE; m_bIsMissionAudioAllowedToPlay = FALSE;
m_sMissionAudio.m_bPredefinedProperties = TRUE; m_bIsMissionAudio2D = TRUE;
m_sMissionAudio.m_nMissionAudioCounter = 0; m_nMissionAudioFramesToPlay = 0;
ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds()); ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds());
} }
@ -8479,14 +8479,14 @@ cAudioManager::PreloadMissionAudio(Const char *name)
if (m_bIsInitialised) { if (m_bIsInitialised) {
int32 missionAudioSfx = FindMissionAudioSfx(name); int32 missionAudioSfx = FindMissionAudioSfx(name);
if (missionAudioSfx != NO_SAMPLE) { if (missionAudioSfx != NO_SAMPLE) {
m_sMissionAudio.m_nSampleIndex = missionAudioSfx; m_nMissionAudioSampleIndex = missionAudioSfx;
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
m_sMissionAudio.m_bIsPlaying = FALSE; m_bIsMissionAudioPlaying = FALSE;
m_sMissionAudio.m_nMissionAudioCounter = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000; m_nMissionAudioFramesToPlay = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000;
m_sMissionAudio.m_nMissionAudioCounter *= 4; m_nMissionAudioFramesToPlay *= 4;
m_sMissionAudio.m_bIsPlayed = FALSE; m_bIsMissionAudioAllowedToPlay = FALSE;
m_sMissionAudio.m_bPredefinedProperties = TRUE; m_bIsMissionAudio2D = TRUE;
g_bMissionAudioLoadFailed = FALSE; g_bMissionAudioLoadFailed = FALSE;
} }
} }
@ -8496,7 +8496,7 @@ uint8
cAudioManager::GetMissionAudioLoadingStatus() cAudioManager::GetMissionAudioLoadingStatus()
{ {
if (m_bIsInitialised) if (m_bIsInitialised)
return m_sMissionAudio.m_nLoadingStatus; return m_nMissionAudioLoadingStatus;
return LOADING_STATUS_LOADED; return LOADING_STATUS_LOADED;
} }
@ -8505,24 +8505,24 @@ void
cAudioManager::SetMissionAudioLocation(float x, float y, float z) cAudioManager::SetMissionAudioLocation(float x, float y, float z)
{ {
if (m_bIsInitialised) { if (m_bIsInitialised) {
m_sMissionAudio.m_bPredefinedProperties = FALSE; m_bIsMissionAudio2D = FALSE;
m_sMissionAudio.m_vecPos = CVector(x, y, z); m_vecMissionAudioPosition = CVector(x, y, z);
} }
} }
void void
cAudioManager::PlayLoadedMissionAudio() cAudioManager::PlayLoadedMissionAudio()
{ {
if (m_bIsInitialised && m_sMissionAudio.m_nSampleIndex != NO_SAMPLE && m_sMissionAudio.m_nLoadingStatus == LOADING_STATUS_LOADED && if (m_bIsInitialised && m_nMissionAudioSampleIndex != NO_SAMPLE && m_nMissionAudioLoadingStatus == LOADING_STATUS_LOADED &&
m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_STOPPED) m_nMissionAudioPlayStatus == PLAY_STATUS_STOPPED)
m_sMissionAudio.m_bIsPlayed = TRUE; m_bIsMissionAudioAllowedToPlay = TRUE;
} }
bool8 bool8
cAudioManager::IsMissionAudioSampleFinished() cAudioManager::IsMissionAudioSampleFinished()
{ {
if (m_bIsInitialised) if (m_bIsInitialised)
return m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_FINISHED; return m_nMissionAudioPlayStatus == PLAY_STATUS_FINISHED;
static int32 cPretendFrame = 1; static int32 cPretendFrame = 1;
@ -8533,13 +8533,13 @@ void
cAudioManager::ClearMissionAudio() cAudioManager::ClearMissionAudio()
{ {
if (m_bIsInitialised) { if (m_bIsInitialised) {
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; m_nMissionAudioSampleIndex = NO_SAMPLE;
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
m_sMissionAudio.m_bIsPlaying = FALSE; m_bIsMissionAudioPlaying = FALSE;
m_sMissionAudio.m_bIsPlayed = FALSE; m_bIsMissionAudioAllowedToPlay = FALSE;
m_sMissionAudio.m_bPredefinedProperties = TRUE; m_bIsMissionAudio2D = TRUE;
m_sMissionAudio.m_nMissionAudioCounter = 0; m_nMissionAudioFramesToPlay = 0;
} }
} }
@ -8557,16 +8557,16 @@ cAudioManager::ProcessMissionAudio()
static uint8 nFramesForPretendPlaying = 0; static uint8 nFramesForPretendPlaying = 0;
if (!m_bIsInitialised) return; if (!m_bIsInitialised) return;
if (m_sMissionAudio.m_nSampleIndex == NO_SAMPLE) return; if (m_nMissionAudioSampleIndex == NO_SAMPLE) return;
switch (m_sMissionAudio.m_nLoadingStatus) { switch (m_nMissionAudioLoadingStatus) {
case LOADING_STATUS_NOT_LOADED: case LOADING_STATUS_NOT_LOADED:
SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex, 1); SampleManager.PreloadStreamedFile(m_nMissionAudioSampleIndex, 1);
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED; m_nMissionAudioLoadingStatus = LOADING_STATUS_LOADED;
nFramesUntilFailedLoad = 0; nFramesUntilFailedLoad = 0;
break; break;
case LOADING_STATUS_LOADED: case LOADING_STATUS_LOADED:
if (!m_sMissionAudio.m_bIsPlayed) if (!m_bIsMissionAudioAllowedToPlay)
return; return;
if (g_bMissionAudioLoadFailed) { if (g_bMissionAudioLoadFailed) {
if (m_bTimerJustReset) { if (m_bTimerJustReset) {
@ -8577,39 +8577,39 @@ cAudioManager::ProcessMissionAudio()
nFramesUntilFailedLoad = 0; nFramesUntilFailedLoad = 0;
} else if (!m_nUserPause) { } else if (!m_nUserPause) {
if (++nFramesForPretendPlaying < 120) { if (++nFramesForPretendPlaying < 120) {
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING; m_nMissionAudioPlayStatus = PLAY_STATUS_PLAYING;
} else { } else {
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; m_nMissionAudioSampleIndex = NO_SAMPLE;
} }
} }
break; break;
} }
switch (m_sMissionAudio.m_nPlayStatus) { switch (m_nMissionAudioPlayStatus) {
case PLAY_STATUS_STOPPED: case PLAY_STATUS_STOPPED:
if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) { if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex)) {
SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex); SetMissionScriptPoliceAudio(m_nMissionAudioSampleIndex);
} else { } else {
if (m_nUserPause) if (m_nUserPause)
SampleManager.PauseStream(TRUE, 1); SampleManager.PauseStream(TRUE, 1);
if (m_sMissionAudio.m_bPredefinedProperties) { if (m_bIsMissionAudio2D) {
SampleManager.SetStreamedVolumeAndPan(80, 63, TRUE, 1); SampleManager.SetStreamedVolumeAndPan(80, 63, TRUE, 1);
} else { } else {
distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos); distSquared = GetDistanceSquared(m_vecMissionAudioPosition);
if (distSquared >= SQR(50.0f)) { if (distSquared >= SQR(50.0f)) {
emittingVol = 0; emittingVol = 0;
pan = 63; pan = 63;
} else { } else {
dist = Sqrt(distSquared); dist = Sqrt(distSquared);
emittingVol = ComputeVolume(80, 50.0f, dist); emittingVol = ComputeVolume(80, 50.0f, dist);
TranslateEntity(&m_sMissionAudio.m_vecPos, &vec); TranslateEntity(&m_vecMissionAudioPosition, &vec);
pan = ComputePan(50.f, &vec); pan = ComputePan(50.f, &vec);
} }
SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, 1); SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, 1);
} }
SampleManager.StartPreloadedStreamedFile(1); SampleManager.StartPreloadedStreamedFile(1);
} }
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING; m_nMissionAudioPlayStatus = PLAY_STATUS_PLAYING;
nCheckPlayingDelay = 30; nCheckPlayingDelay = 30;
break; break;
case PLAY_STATUS_PLAYING: case PLAY_STATUS_PLAYING:
@ -8618,28 +8618,28 @@ cAudioManager::ProcessMissionAudio()
SampleManager.StopStreamedFile(1); SampleManager.StopStreamedFile(1);
break; break;
} }
if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) { if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex)) {
if (!m_nUserPause) { if (!m_nUserPause) {
if (nCheckPlayingDelay) { if (nCheckPlayingDelay) {
--nCheckPlayingDelay; --nCheckPlayingDelay;
} else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_sMissionAudio.m_nMissionAudioCounter-- == 0) { } else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_nMissionAudioFramesToPlay-- == 0) {
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; m_nMissionAudioSampleIndex = NO_SAMPLE;
SampleManager.StopStreamedFile(1); SampleManager.StopStreamedFile(1);
m_sMissionAudio.m_nMissionAudioCounter = 0; m_nMissionAudioFramesToPlay = 0;
} }
} }
} else if (m_sMissionAudio.m_bIsPlaying) { } else if (m_bIsMissionAudioPlaying) {
if (SampleManager.IsStreamPlaying(1) || m_nUserPause || m_nPreviousUserPause) { if (SampleManager.IsStreamPlaying(1) || m_nUserPause || m_nPreviousUserPause) {
if (m_nUserPause) if (m_nUserPause)
SampleManager.PauseStream(TRUE, 1); SampleManager.PauseStream(TRUE, 1);
else else
SampleManager.PauseStream(FALSE, 1); SampleManager.PauseStream(FALSE, 1);
} else { } else {
m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; m_nMissionAudioSampleIndex = NO_SAMPLE;
SampleManager.StopStreamedFile(1); SampleManager.StopStreamedFile(1);
m_sMissionAudio.m_nMissionAudioCounter = 0; m_nMissionAudioFramesToPlay = 0;
} }
} else { } else {
if (m_nUserPause) if (m_nUserPause)
@ -8649,7 +8649,7 @@ cAudioManager::ProcessMissionAudio()
break; break;
nCheckPlayingDelay = 0; nCheckPlayingDelay = 0;
} }
m_sMissionAudio.m_bIsPlaying = TRUE; m_bIsMissionAudioPlaying = TRUE;
} }
break; break;
default: default:
@ -8661,7 +8661,7 @@ cAudioManager::ProcessMissionAudio()
nFramesForPretendPlaying = 0; nFramesForPretendPlaying = 0;
g_bMissionAudioLoadFailed = TRUE; g_bMissionAudioLoadFailed = TRUE;
nFramesUntilFailedLoad = 0; nFramesUntilFailedLoad = 0;
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED; m_nMissionAudioLoadingStatus = LOADING_STATUS_LOADED;
} }
break; break;
default: default:

View File

@ -123,22 +123,6 @@ public:
VALIDATE_SIZE(cPedComments, 1164); VALIDATE_SIZE(cPedComments, 1164);
class CEntity;
class cMissionAudio
{
public:
CVector m_vecPos;
bool8 m_bPredefinedProperties;
uint32 m_nSampleIndex;
uint8 m_nLoadingStatus;
uint8 m_nPlayStatus;
bool8 m_bIsPlaying;
int32 m_nMissionAudioCounter;
bool8 m_bIsPlayed;
};
VALIDATE_SIZE(cMissionAudio, 32);
// name made up // name made up
class cAudioScriptObjectManager class cAudioScriptObjectManager
{ {
@ -152,6 +136,7 @@ public:
class cTransmission; class cTransmission;
class CEntity;
class CPlane; class CPlane;
class CVehicle; class CVehicle;
class CPed; class CPed;
@ -247,12 +232,23 @@ public:
int32 m_nWaterCannonEntity; int32 m_nWaterCannonEntity;
int32 m_nPoliceChannelEntity; int32 m_nPoliceChannelEntity;
cPoliceRadioQueue m_sPoliceRadioQueue; cPoliceRadioQueue m_sPoliceRadioQueue;
cAMCrime m_aCrimes[10];
int32 m_nFrontEndEntity; int32 m_nFrontEndEntity;
int32 m_nCollisionEntity; int32 m_nCollisionEntity;
cAudioCollisionManager m_sCollisionManager; cAudioCollisionManager m_sCollisionManager;
int32 m_nProjectileEntity; int32 m_nProjectileEntity;
int32 m_nBridgeEntity; int32 m_nBridgeEntity;
cMissionAudio m_sMissionAudio;
// Mission audio stuff
CVector m_vecMissionAudioPosition;
bool8 m_bIsMissionAudio2D;
uint32 m_nMissionAudioSampleIndex;
uint8 m_nMissionAudioLoadingStatus;
uint8 m_nMissionAudioPlayStatus;
bool8 m_bIsMissionAudioPlaying;
int32 m_nMissionAudioFramesToPlay;
bool8 m_bIsMissionAudioAllowedToPlay;
int32 m_anRandomTable[5]; int32 m_anRandomTable[5];
uint8 m_nTimeSpent; uint8 m_nTimeSpent;
bool8 m_nUserPause; bool8 m_nUserPause;
@ -510,7 +506,7 @@ public:
void SetMissionAudioLocation(float x, float y, float z); void SetMissionAudioLocation(float x, float y, float z);
void PlayLoadedMissionAudio(); void PlayLoadedMissionAudio();
bool8 IsMissionAudioSampleFinished(); bool8 IsMissionAudioSampleFinished();
bool8 IsMissionAudioSamplePlaying() { return m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_PLAYING; } bool8 IsMissionAudioSamplePlaying() { return m_nMissionAudioPlayStatus == PLAY_STATUS_PLAYING; }
bool8 ShouldDuckMissionAudio() { return IsMissionAudioSamplePlaying(); } bool8 ShouldDuckMissionAudio() { return IsMissionAudioSamplePlaying(); }
void ClearMissionAudio(); void ClearMissionAudio();
void ProcessMissionAudio(); void ProcessMissionAudio();

View File

@ -85,11 +85,9 @@ cAudioManager::InitialisePoliceRadioZones()
void void
cAudioManager::InitialisePoliceRadio() cAudioManager::InitialisePoliceRadio()
{ {
m_sPoliceRadioQueue.policeChannelTimer = 0; m_sPoliceRadioQueue.Reset();
m_sPoliceRadioQueue.policeChannelTimerSeconds = 0; for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++)
m_sPoliceRadioQueue.policeChannelCounterSeconds = 0; m_aCrimes[i].type = CRIME_NONE;
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++)
m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE); SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE);
gSpecialSuspectLastSeenReport = FALSE; gSpecialSuspectLastSeenReport = FALSE;
@ -201,7 +199,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING) { bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING) {
SampleManager.PauseStream(FALSE, 1); SampleManager.PauseStream(FALSE, 1);
} }
if (m_sPoliceRadioQueue.policeChannelTimer == 0) bChannelOpen = FALSE; if (m_sPoliceRadioQueue.m_nSamplesInQueue == 0) bChannelOpen = FALSE;
if (cWait) { if (cWait) {
#ifdef FIX_BUGS #ifdef FIX_BUGS
cWait -= CTimer::GetLogicalFramesPassed(); cWait -= CTimer::GetLogicalFramesPassed();
@ -238,14 +236,8 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
} }
if (bChannelOpen) DoPoliceRadioCrackle(); if (bChannelOpen) DoPoliceRadioCrackle();
if ((g_nMissionAudioSfx == TOTAL_AUDIO_SAMPLES || g_nMissionAudioPlayingStatus != PLAY_STATUS_PLAYING) && if ((g_nMissionAudioSfx == TOTAL_AUDIO_SAMPLES || g_nMissionAudioPlayingStatus != PLAY_STATUS_PLAYING) &&
!SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.policeChannelTimer) { !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.m_nSamplesInQueue != 0) {
if (m_sPoliceRadioQueue.policeChannelTimer) { sample = m_sPoliceRadioQueue.Remove();
sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds];
m_sPoliceRadioQueue.policeChannelTimer--;
m_sPoliceRadioQueue.policeChannelCounterSeconds = (m_sPoliceRadioQueue.policeChannelCounterSeconds + 1) % 60;
} else {
sample = TOTAL_AUDIO_SAMPLES;
}
if (wantedLevel == 0) { if (wantedLevel == 0) {
if (gSpecialSuspectLastSeenReport) { if (gSpecialSuspectLastSeenReport) {
gSpecialSuspectLastSeenReport = FALSE; gSpecialSuspectLastSeenReport = FALSE;
@ -299,18 +291,18 @@ cAudioManager::SetupCrimeReport()
if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return FALSE; if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return FALSE;
if (60 - m_sPoliceRadioQueue.policeChannelTimer <= 9) { if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue <= 9) {
AgeCrimes(); AgeCrimes();
return TRUE; return TRUE;
} }
for (i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { for (i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) if (m_aCrimes[i].type != CRIME_NONE)
break; break;
} }
if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return FALSE; if (i == ARRAY_SIZE(m_aCrimes)) return FALSE;
audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position); audioZoneId = CTheZones::FindAudioZone(&m_aCrimes[i].position);
if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) { if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) {
zone = CTheZones::GetAudioZone(audioZoneId); zone = CTheZones::GetAudioZone(audioZoneId);
for (int j = 0; j < NUMAUDIOZONES; j++) { for (int j = 0; j < NUMAUDIOZONES; j++) {
@ -319,14 +311,14 @@ cAudioManager::SetupCrimeReport()
m_sPoliceRadioQueue.Add(m_anRandomTable[4] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(m_anRandomTable[4] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(m_anRandomTable[0] % 3 + SFX_WEVE_GOT); m_sPoliceRadioQueue.Add(m_anRandomTable[0] % 3 + SFX_WEVE_GOT);
m_sPoliceRadioQueue.Add(m_anRandomTable[1] % 2 + SFX_A_10_1); m_sPoliceRadioQueue.Add(m_anRandomTable[1] % 2 + SFX_A_10_1);
switch (m_sPoliceRadioQueue.crimes[i].type) { switch (m_aCrimes[i].type) {
case CRIME_PED_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_PED; break; case CRIME_PED_BURNED: m_aCrimes[i].type = CRIME_HIT_PED; break;
case CRIME_COP_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_COP; break; case CRIME_COP_BURNED: m_aCrimes[i].type = CRIME_HIT_COP; break;
case CRIME_VEHICLE_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_STEAL_CAR; break; case CRIME_VEHICLE_BURNED: m_aCrimes[i].type = CRIME_STEAL_CAR; break;
case CRIME_DESTROYED_CESSNA: m_sPoliceRadioQueue.crimes[i].type = CRIME_SHOOT_HELI; break; case CRIME_DESTROYED_CESSNA: m_aCrimes[i].type = CRIME_SHOOT_HELI; break;
default: break; default: break;
} }
m_sPoliceRadioQueue.Add(m_sPoliceRadioQueue.crimes[i].type + SFX_CRIME_1 - 1); m_sPoliceRadioQueue.Add(m_aCrimes[i].type + SFX_CRIME_1 - 1);
m_sPoliceRadioQueue.Add(SFX_IN); m_sPoliceRadioQueue.Add(SFX_IN);
if (sampleIndex == SFX_POLICE_RADIO_SHORESIDE_VALE && if (sampleIndex == SFX_POLICE_RADIO_SHORESIDE_VALE &&
(strcmp(zone->name, SubZo2Label) == 0 || strcmp(zone->name, SubZo3Label) == 0)) { (strcmp(zone->name, SubZo2Label) == 0 || strcmp(zone->name, SubZo3Label) == 0)) {
@ -340,17 +332,17 @@ cAudioManager::SetupCrimeReport()
quarterX = 0.25f * rangeX; quarterX = 0.25f * rangeX;
quarterY = 0.25f * rangeY; quarterY = 0.25f * rangeY;
if (m_sPoliceRadioQueue.crimes[i].position.y > halfY + quarterY) { if (m_aCrimes[i].position.y > halfY + quarterY) {
m_sPoliceRadioQueue.Add(SFX_NORTH); m_sPoliceRadioQueue.Add(SFX_NORTH);
processed = TRUE; processed = TRUE;
} else if (m_sPoliceRadioQueue.crimes[i].position.y < halfY - quarterY) { } else if (m_aCrimes[i].position.y < halfY - quarterY) {
m_sPoliceRadioQueue.Add(SFX_SOUTH); m_sPoliceRadioQueue.Add(SFX_SOUTH);
processed = TRUE; processed = TRUE;
} }
if (m_sPoliceRadioQueue.crimes[i].position.x > halfX + quarterX) if (m_aCrimes[i].position.x > halfX + quarterX)
m_sPoliceRadioQueue.Add(SFX_EAST); m_sPoliceRadioQueue.Add(SFX_EAST);
else if (m_sPoliceRadioQueue.crimes[i].position.x < halfX - quarterX) else if (m_aCrimes[i].position.x < halfX - quarterX)
m_sPoliceRadioQueue.Add(SFX_WEST); m_sPoliceRadioQueue.Add(SFX_WEST);
else if (!processed) else if (!processed)
m_sPoliceRadioQueue.Add(SFX_CENTRAL); m_sPoliceRadioQueue.Add(SFX_CENTRAL);
@ -363,7 +355,7 @@ cAudioManager::SetupCrimeReport()
} }
} }
} }
m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; m_aCrimes[i].type = CRIME_NONE;
AgeCrimes(); AgeCrimes();
return TRUE; return TRUE;
} }
@ -536,7 +528,7 @@ cAudioManager::SetupSuspectLastSeenReport()
if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE) { if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE) {
veh = FindPlayerVehicle(); veh = FindPlayerVehicle();
if (veh != nil) { if (veh != nil) {
if (60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) {
color1 = veh->m_currentColour1; color1 = veh->m_currentColour1;
if (color1 >= ARRAY_SIZE(gCarColourTable)) { if (color1 >= ARRAY_SIZE(gCarColourTable)) {
debug("\n *** UNKNOWN CAR COLOUR %d *** ", color1); debug("\n *** UNKNOWN CAR COLOUR %d *** ", color1);
@ -669,7 +661,7 @@ cAudioManager::SetupSuspectLastSeenReport()
m_sPoliceRadioQueue.Add(TOTAL_AUDIO_SAMPLES); m_sPoliceRadioQueue.Add(TOTAL_AUDIO_SAMPLES);
} }
} }
} else if (60 - m_sPoliceRadioQueue.policeChannelTimer > 4) { } else if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 4) {
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_ON_FOOT); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_ON_FOOT);
@ -682,14 +674,14 @@ cAudioManager::SetupSuspectLastSeenReport()
void void
cAudioManager::ReportCrime(eCrimeType type, const CVector &pos) cAudioManager::ReportCrime(eCrimeType type, const CVector &pos)
{ {
int32 lastCrime = ARRAY_SIZE(m_sPoliceRadioQueue.crimes); int32 lastCrime = ARRAY_SIZE(m_aCrimes);
if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->GetWantedLevel() > 0 && if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->GetWantedLevel() > 0 &&
(type > CRIME_NONE || type < NUM_CRIME_TYPES) && m_FrameCounter >= gMinTimeToNextReport[type]) { (type > CRIME_NONE || type < NUM_CRIME_TYPES) && m_FrameCounter >= gMinTimeToNextReport[type]) {
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
if (m_sPoliceRadioQueue.crimes[i].type) { if (m_aCrimes[i].type != CRIME_NONE) {
if (m_sPoliceRadioQueue.crimes[i].type == type) { if (m_aCrimes[i].type == type) {
m_sPoliceRadioQueue.crimes[i].position = pos; m_aCrimes[i].position = pos;
m_sPoliceRadioQueue.crimes[i].timer = 0; m_aCrimes[i].timer = 0;
return; return;
} }
} else { } else {
@ -697,10 +689,10 @@ cAudioManager::ReportCrime(eCrimeType type, const CVector &pos)
} }
} }
if (lastCrime < ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) { if (lastCrime < ARRAY_SIZE(m_aCrimes)) {
m_sPoliceRadioQueue.crimes[lastCrime].type = type; m_aCrimes[lastCrime].type = type;
m_sPoliceRadioQueue.crimes[lastCrime].position = pos; m_aCrimes[lastCrime].position = pos;
m_sPoliceRadioQueue.crimes[lastCrime].timer = 0; m_aCrimes[lastCrime].timer = 0;
gMinTimeToNextReport[type] = m_FrameCounter + 500; gMinTimeToNextReport[type] = m_FrameCounter + 500;
} }
} }
@ -723,7 +715,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
if (!m_bIsInitialised) return; if (!m_bIsInitialised) return;
if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && 60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) {
audioZone = CTheZones::FindAudioZone(&vec); audioZone = CTheZones::FindAudioZone(&vec);
if (audioZone >= 0 && audioZone < NUMAUDIOZONES) { if (audioZone >= 0 && audioZone < NUMAUDIOZONES) {
zone = CTheZones::GetAudioZone(audioZone); zone = CTheZones::GetAudioZone(audioZone);
@ -776,9 +768,9 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
void void
cAudioManager::AgeCrimes() cAudioManager::AgeCrimes()
{ {
for (uint8 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { for (uint8 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) { if (m_aCrimes[i].type != CRIME_NONE) {
if (++m_sPoliceRadioQueue.crimes[i].timer > 1500) m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; if (++m_aCrimes[i].timer > 1500) m_aCrimes[i].type = CRIME_NONE;
} }
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Crime.h" #include "Crime.h"
#include "AudioSamples.h"
struct cAMCrime { struct cAMCrime {
int32 type; int32 type;
@ -17,30 +18,49 @@ struct cAMCrime {
VALIDATE_SIZE(cAMCrime, 20); VALIDATE_SIZE(cAMCrime, 20);
#define POLICE_RADIO_QUEUE_MAX_SAMPLES 60
class cPoliceRadioQueue class cPoliceRadioQueue
{ {
public: public:
int32 crimesSamples[60]; int32 m_aSamples[POLICE_RADIO_QUEUE_MAX_SAMPLES];
uint8 policeChannelTimer; uint8 m_nSamplesInQueue;
uint8 policeChannelTimerSeconds; uint8 m_nAddOffset;
uint8 policeChannelCounterSeconds; uint8 m_nRemoveOffset;
cAMCrime crimes[10];
cPoliceRadioQueue() cPoliceRadioQueue()
{ {
policeChannelTimerSeconds = 0; Reset();
policeChannelCounterSeconds = 0;
policeChannelTimer = 0;
} }
void Add(uint32 sample) void Reset()
{ {
if (policeChannelTimer != 60) { m_nAddOffset = 0;
crimesSamples[policeChannelTimerSeconds] = sample; m_nRemoveOffset = 0;
policeChannelTimer++; m_nSamplesInQueue = 0;
policeChannelTimerSeconds = (policeChannelTimerSeconds + 1) % 60;
} }
bool8 Add(uint32 sample)
{
if (m_nSamplesInQueue != POLICE_RADIO_QUEUE_MAX_SAMPLES) {
m_aSamples[m_nAddOffset] = sample;
m_nSamplesInQueue++;
m_nAddOffset = (m_nAddOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
return TRUE;
}
return FALSE;
}
uint32 Remove()
{
if (m_nSamplesInQueue != 0) {
uint32 sample = m_aSamples[m_nRemoveOffset];
m_nSamplesInQueue--;
m_nRemoveOffset = (m_nRemoveOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
return sample;
}
return TOTAL_AUDIO_SAMPLES;
} }
}; };
VALIDATE_SIZE(cPoliceRadioQueue, 444); VALIDATE_SIZE(cPoliceRadioQueue, 244);