From af5bd951aeb43c341d5126bc4141992169e46d57 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Wed, 31 Jul 2019 17:54:18 +0200 Subject: More audio ped --- src/animation/AnimBlendAssociation.cpp | 4 +- src/animation/AnimBlendHierarchy.cpp | 2 +- src/audio/AudioManager.cpp | 1329 +++++++++- src/audio/AudioManager.h | 66 +- src/audio/DMAudio.h | 3 + src/control/PathFind.cpp | 10 +- src/control/Population.h | 3 +- src/control/Replay.cpp | 38 +- src/control/Script.cpp | 6 +- src/core/Camera.cpp | 10 +- src/core/Camera.h | 2 +- src/core/CdStream.cpp | 4 +- src/core/Collision.cpp | 8 +- src/core/EventList.cpp | 2 +- src/core/Explosion.cpp | 24 + src/core/Explosion.h | 9 +- src/core/Frontend.cpp | 2 +- src/core/Game.cpp | 2 +- src/core/Instance.h | 1 + src/core/Pad.cpp | 4 +- src/core/Placeable.cpp | 2 +- src/core/Streaming.cpp | 42 +- src/core/Wanted.cpp | 2 +- src/core/common.h | 9 +- src/core/main.cpp | 2 +- src/core/re3.cpp | 26 + src/core/re3.cpp.autosave | 483 ++++ src/entities/Physical.cpp | 40 +- src/peds/Ped.cpp | 12 +- src/peds/Ped.h | 9 + src/peds/PedPlacement.cpp | 4 +- src/peds/PlayerPed.cpp | 8 + src/peds/PlayerPed.cpp.autosave | 110 + src/render/Clouds.cpp | 8 +- src/render/Coronas.cpp | 20 +- src/render/Lights.cpp | 28 +- src/render/ParticleMgr.cpp | 2 +- src/render/PointLights.cpp | 2 +- src/render/Shadows.cpp | 28 +- src/render/Timecycle.cpp | 6 +- src/render/WaterLevel.cpp | 12 +- src/vehicles/Automobile.cpp | 46 +- src/vehicles/Automobile.cpp.autosave | 4560 ++++++++++++++++++++++++++++++++ src/vehicles/Boat.cpp | 2 +- src/vehicles/Heli.cpp | 8 + src/vehicles/Heli.cpp.autosave | 1055 ++++++++ src/vehicles/Plane.cpp | 8 + src/vehicles/Plane.cpp.autosave | 985 +++++++ src/vehicles/Vehicle.cpp | 8 +- 49 files changed, 8804 insertions(+), 252 deletions(-) create mode 100644 src/core/re3.cpp.autosave create mode 100644 src/peds/PlayerPed.cpp.autosave create mode 100644 src/vehicles/Automobile.cpp.autosave create mode 100644 src/vehicles/Heli.cpp.autosave create mode 100644 src/vehicles/Plane.cpp.autosave (limited to 'src') diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index d94fe2c1..7273c846 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -185,7 +185,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount <= 0.0f && blendDelta < 0.0f){ // We're faded out and are not fading in blendAmount = 0.0f; - blendDelta = max(0.0, blendDelta); + blendDelta = Max(0.0, blendDelta); if(flags & ASSOC_DELETEFADEDOUT){ if(callbackType == CB_FINISH || callbackType == CB_DELETE) callback(this, callbackArg); @@ -197,7 +197,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount > 1.0f){ // Maximally faded in, clamp values blendAmount = 1.0f; - blendDelta = min(0.0, blendDelta); + blendDelta = Min(0.0, blendDelta); } return true; diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp index e4bcdc69..e594e5d8 100644 --- a/src/animation/AnimBlendHierarchy.cpp +++ b/src/animation/AnimBlendHierarchy.cpp @@ -36,7 +36,7 @@ CAnimBlendHierarchy::CalcTotalTime(void) float seqTime = 0.0f; for(j = 0; j < sequences[i].numFrames; j++) seqTime += sequences[i].GetKeyFrame(j)->deltaTime; - totalTime = max(totalTime, seqTime); + totalTime = Max(totalTime, seqTime); } totalLength = totalTime; } diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index e586366d..76bfb793 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -6,6 +6,7 @@ #include "Automobile.h" #include "Camera.h" #include "DMAudio.h" +#include "Explosion.h" #include "Garages.h" #include "ModelIndices.h" #include "MusicManager.h" @@ -16,6 +17,7 @@ #include "Pools.h" #include "sampman.h" #include "Stats.h" +#include "SurfaceTable.h" #include "Vehicle.h" #include "Plane.h" #include "World.h" @@ -96,10 +98,54 @@ enum eVehicleModel { CAR159, }; -void *cAudioScriptObject::operator new(size_t sz) { return CPools::GetAudioScriptObjectPool()->New(); } -void *cAudioScriptObject::operator new(size_t sz, int handle) { return CPools::GetAudioScriptObjectPool()->New(handle); } -void cAudioScriptObject::operator delete(void *p, size_t sz) { CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject*)p); } -void cAudioScriptObject::operator delete(void *p, int handle) { CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject*)p); } +void +cPedComments::Add(tPedComment *com) +{ + uint8 index; + + if(nrOfCommentsInBank[activeBank] >= 20u) { + index = field_1120[activeBank][19]; + if(m_asPedComments[activeBank][index].m_bVolume > com->m_bVolume) return; + } else { + index = nrOfCommentsInBank[activeBank]++; + } + m_asPedComments[activeBank][index] = *com; + + uint32 i = 0; + if(index != 0) { + for(i = 0; i < index; i++) { + if(m_asPedComments[activeBank][field_1120[activeBank][i]].m_bVolume < + m_asPedComments[activeBank][index].m_bVolume) { + memmove(&field_1120[activeBank][i + 1], &field_1120[activeBank][i], + 19 - i); + break; + } + } + } + + field_1120[activeBank][i] = index; +} + +void * +cAudioScriptObject::operator new(size_t sz) +{ + return CPools::GetAudioScriptObjectPool()->New(); +} +void * +cAudioScriptObject::operator new(size_t sz, int handle) +{ + return CPools::GetAudioScriptObjectPool()->New(handle); +} +void +cAudioScriptObject::operator delete(void *p, size_t sz) +{ + CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); +} +void +cAudioScriptObject::operator delete(void *p, int handle) +{ + CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); +} cAudioManager &AudioManager = *(cAudioManager *)0x880FC0; @@ -407,9 +453,9 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float speedOfSource = (dist / field_19195) * speedMultiplier; if(speedOfSound > fabsf(speedOfSource)) { if(speedOfSource < 0.0f) { - speedOfSource = max(speedOfSource, -1.5f); + speedOfSource = Max(speedOfSource, -1.5f); } else { - speedOfSource = min(speedOfSource, 1.5f); + speedOfSource = Min(speedOfSource, 1.5f); } newFreq = (oldFreq * speedOfSound) / (speedOfSource + speedOfSound); } @@ -830,7 +876,7 @@ cAudioManager::SetupJumboFlySound(uint8 emittingVol) SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_fSoundIntensity = 440.0f; m_sQueueSample.field_56 = 0; - m_sQueueSample.field_48 = 4.0; + m_sQueueSample.field_48 = 4.0f; m_sQueueSample.m_bReverbFlag = 1; m_sQueueSample.field_76 = 5; m_sQueueSample.m_nLoopEnd = @@ -861,8 +907,8 @@ cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 4.0; - m_sQueueSample.m_fSoundIntensity = 240.0; + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 240.0f; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 12; m_sQueueSample.m_bOffset = 0; @@ -3729,7 +3775,6 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params) void cAudioManager::ProcessAirportScriptObject(uint8 sound) { - float dist; float distSquared; float maxDist; @@ -4002,68 +4047,68 @@ cAudioManager::ProcessEntity(int32 id) case AUDIOTYPE_PHYSICAL: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessPhysical(id); + ProcessPhysical(id); } break; case AUDIOTYPE_EXPLOSION: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessExplosions(id); + ProcessExplosions(id); } break; case AUDIOTYPE_FIRE: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessFires(id); + ProcessFires(id); } break; case AUDIOTYPE_WEATHER: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessWeather(id); + ProcessWeather(id); } break; case AUDIOTYPE_CRANE: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessCrane(); + ProcessCrane(); } break; case AUDIOTYPE_SCRIPTOBJECT: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessScriptObject(id); + ProcessScriptObject(id); } break; case AUDIOTYPE_BRIDGE: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessBridge(); + ProcessBridge(); } break; case AUDIOTYPE_FRONTEND: m_sQueueSample.m_bReverbFlag = 0; - cAudioManager::ProcessFrontEnd(); + ProcessFrontEnd(); break; case AUDIOTYPE_PROJECTILE: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessProjectiles(); + ProcessProjectiles(); } break; case AUDIOTYPE_GARAGE: - if(!m_bUserPause) cAudioManager::ProcessGarages(); + if(!m_bUserPause) ProcessGarages(); break; case AUDIOTYPE_FIREHYDRANT: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessFireHydrant(); + ProcessFireHydrant(); } break; case AUDIOTYPE_WATERCANNON: if(!m_bUserPause) { m_sQueueSample.m_bReverbFlag = 1; - cAudioManager::ProcessWaterCannon(id); + ProcessWaterCannon(id); } break; default: return; @@ -4071,11 +4116,88 @@ cAudioManager::ProcessEntity(int32 id) } } -WRAPPER void cAudioManager::ProcessExplosions(int32 explosion) { - EAXJMP(0x575AC0); + uint8 type; + CVector *pos; + float maxDist; + float distSquared; + + for(uint8 i = 0; i < 48u; i++) { + if(CExplosion::GetExplosionActiveCounter(i) == 1) { + CExplosion::ResetExplosionActiveCounter(i); + type = CExplosion::GetExplosionType(i); + switch(type) { + case EXPLOSION_GRENADE: + case EXPLOSION_ROCKET: + case EXPLOSION_BARREL: + case EXPLOSION_TANK_GRENADE: + maxDist = 160000.f; + m_sQueueSample.m_fSoundIntensity = 400.0f; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_WEAPON_GRENADE_EXPLOSION; + m_sQueueSample.m_nFrequency = RandomDisplacement(2000u) + 38000; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bBankIndex = 0; + break; + case EXPLOSION_MOLOTOV: + maxDist = 40000.f; + m_sQueueSample.m_fSoundIntensity = 200.0f; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_WEAPON_MOLOTOV_EXPLOSION; + m_sQueueSample.m_nFrequency = RandomDisplacement(1000u) + 19000; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bBankIndex = 0; + break; + case EXPLOSION_MINE: + case EXPLOSION_HELI_BOMB: + maxDist = 90000.f; + m_sQueueSample.m_fSoundIntensity = 300.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_SHOT; + m_sQueueSample.m_nFrequency = RandomDisplacement(1000u) + 12347; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bBankIndex = 0; + break; + default: + maxDist = 160000.f; + m_sQueueSample.m_fSoundIntensity = 400.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_EXPLOSION_CAR; + m_sQueueSample.m_nFrequency = RandomDisplacement(2000u) + 38000; + if(type == EXPLOSION_HELI) + m_sQueueSample.m_nFrequency = + 8 * m_sQueueSample.m_nFrequency / 10u; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bBankIndex = 0; + break; + } + pos = CExplosion::GetExplosionPosition(i); + m_sQueueSample.m_vecPos.x = pos->x; + m_sQueueSample.m_vecPos.y = pos->y; + m_sQueueSample.m_vecPos.z = pos->z; + distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(distSquared < maxDist) { + m_sQueueSample.m_fDistance = Sqrt(distSquared); + m_sQueueSample.m_bVolume = + ComputeVolume(maxVolume, m_sQueueSample.m_fSoundIntensity, + m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = i; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bEmittingVolume = maxVolume; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 1; + AddSampleToRequestedQueue(); + } + } + } + } } void @@ -5220,11 +5342,1001 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) } } -WRAPPER void -cAudioManager::ProcessPed(CPhysical *) +cAudioManager::ProcessOneShotScriptObject(uint8 sound) +{ + CPlayerPed *playerPed; + uint8 emittingVolume; + float maxDist; + float distSquared; + + cPedParams male; + cPedParams female; + + static uint8 iSound = 0; + + switch(sound) { + case SCRIPT_SOUND_INJURED_PED_MALE_OUCH_S: + case SCRIPT_SOUND_INJURED_PED_MALE_OUCH_L: + male.m_pPed = nil; + male.m_bDistanceCalculated = 0; + male.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); + cAudioManager::SetupPedComments(&male, SOUND_INJURED_PED_MALE_OUCH); + return; + case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_S: + case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_L: + female.m_pPed = nil; + female.m_bDistanceCalculated = 0; + female.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); + cAudioManager::SetupPedComments(&female, SOUND_INJURED_PED_FEMALE); + return; + case SCRIPT_SOUND_GATE_START_CLUNK: + case SCRIPT_SOUND_GATE_STOP_CLUNK: + maxDist = 1600.f; + m_sQueueSample.m_fSoundIntensity = 40.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_GATE; + m_sQueueSample.m_bBankIndex = 0; + if(sound == SCRIPT_SOUND_GATE_START_CLUNK) + m_sQueueSample.m_nFrequency = 10600; + else + m_sQueueSample.m_nFrequency = 9000; + m_sQueueSample.field_16 = 1; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + emittingVolume = RandomDisplacement(10u) + 50; + break; + case SCRIPT_SOUND_BULLET_HIT_GROUND_1: + case SCRIPT_SOUND_BULLET_HIT_GROUND_2: + case SCRIPT_SOUND_BULLET_HIT_GROUND_3: + maxDist = 2500.f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.m_nSampleIndex = + m_anRandomTable[iSound % 5] % 3u + AUDIO_SAMPLE_BULLET_HIT_GROUND_1; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 9; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + emittingVolume = m_anRandomTable[2] % 20 + 90; + break; + case SCRIPT_SOUND_110: + case SCRIPT_SOUND_111: + if(cSampleManager.IsSampleBankLoaded(0) != 1) return; + maxDist = 6400.f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_389; + m_sQueueSample.m_bBankIndex = 0; + emittingVolume = 127; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_389); + m_sQueueSample.field_16 = 0; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_bIsDistant = 0; + break; + case SCRIPT_SOUND_PAYPHONE_RINGING: + maxDist = 6400.f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PAYPHONE_RINGING; + m_sQueueSample.m_bBankIndex = 0; + emittingVolume = 80; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PAYPHONE_RINGING); + m_sQueueSample.field_16 = 1; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 0; + break; + case SCRIPT_SOUND_GLASS_BREAK_L: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_GLASS_GENERIC_BREAK; + m_sQueueSample.m_bBankIndex = 0; + emittingVolume = 70; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + break; + case SCRIPT_SOUND_GLASS_BREAK_S: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_GLASS_GENERIC_BREAK; + m_sQueueSample.m_bBankIndex = 0; + emittingVolume = 60; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + break; + case SCRIPT_SOUND_GLASS_CRACK: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_GLASS_WINDSHIELD_CRACK; + m_sQueueSample.m_bBankIndex = 0; + emittingVolume = 70; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_WINDSHIELD_CRACK); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SCRIPT_SOUND_GLASS_LIGHT_BREAK: + maxDist = 3025.f; + m_sQueueSample.m_fSoundIntensity = 55.0f; + m_sQueueSample.m_nSampleIndex = + (m_anRandomTable[4] & 3) + AUDIO_SAMPLE_GLASS_LIGHT_BREAK_1; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = RandomDisplacement(2000u) + 19000; + m_sQueueSample.field_16 = 9; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + emittingVolume = RandomDisplacement(11u) + 25; + break; + case SCRIPT_SOUND_BOX_DESTROYED_1: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOX_DESTROYED_1; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = RandomDisplacement(1500u) + 18600; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + emittingVolume = m_anRandomTable[2] % 20 + 80; + break; + case SCRIPT_SOUND_BOX_DESTROYED_2: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOX_DESTROYED_2; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = RandomDisplacement(1500u) + 18600; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + emittingVolume = m_anRandomTable[2] % 20 + 80; + break; + case SCRIPT_SOUND_METAL_COLLISION: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = + m_anRandomTable[3] % 5u + AUDIO_SAMPLE_COLLISION_METAL; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + emittingVolume = m_anRandomTable[2] % 30 + 70; + break; + case SCRIPT_SOUND_TIRE_COLLISION: + maxDist = 3600.f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_RUBBER; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_bRequireReflection = 1; + emittingVolume = m_anRandomTable[2] % 30 + 60; + break; + case SCRIPT_SOUND_GUNSHELL_DROP: + playerPed = FindPlayerPed(); + if(playerPed) { + switch(playerPed->m_nSurfaceTouched) { + case SURFACE_GRASS: + case SURFACE_DIRT: + case SURFACE_DIRTTRACK: + case SURFACE_SCAFFOLD: + case SURFACE_FLESH: + case SURFACE_SAND: + case SURFACE_TIRE: + case SURFACE_HEDGE: + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_BULLET_GUNSHELL_SOFT_DROP; + m_sQueueSample.m_nFrequency = RandomDisplacement(500u) + 11000; + m_sQueueSample.field_16 = 18; + maxDist = 400.f; + m_sQueueSample.m_fSoundIntensity = 20.0f; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + emittingVolume = m_anRandomTable[2] % 20 + 30; + distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(distSquared < maxDist) { + m_sQueueSample.m_fDistance = Sqrt(distSquared); + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVolume, m_sQueueSample.m_fSoundIntensity, + m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bEmittingVolume = emittingVolume; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bReverbFlag = 1; + AddSampleToRequestedQueue(); + } + } + return; + case SURFACE_PUDDLE: return; + default: break; + } + } + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BULLET_GUNSHELL_HARD_DROP; + m_sQueueSample.m_nFrequency = RandomDisplacement(750u) + 18000; + m_sQueueSample.field_16 = 15; + maxDist = 400.f; + m_sQueueSample.m_fSoundIntensity = 20.0f; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + emittingVolume = m_anRandomTable[2] % 20 + 30; + break; + case SCRIPT_SOUND_GUNSHELL_DROP_SOFT: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BULLET_GUNSHELL_SOFT_DROP; + m_sQueueSample.m_nFrequency = RandomDisplacement(500u) + 11000; + m_sQueueSample.field_16 = 18; + maxDist = 400.f; + m_sQueueSample.m_fSoundIntensity = 20.0f; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_bIsDistant = 0; + emittingVolume = m_anRandomTable[2] % 20 + 30; + break; + default: return; + } + + distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(distSquared < maxDist) { + m_sQueueSample.m_fDistance = Sqrt(distSquared); + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bEmittingVolume = emittingVolume; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bReverbFlag = 1; + AddSampleToRequestedQueue(); + } + } +} + +void +cAudioManager::ProcessPed(CPhysical *ped) { - EAXJMP(0x56F450); + cPedParams params; + + params.m_pPed = 0; + params.m_bDistanceCalculated = 0; + params.m_fDistance = 0.0f; + + m_sQueueSample.m_vecPos = ped->GetPosition(); + + params.m_bDistanceCalculated = 0; + params.m_pPed = (CPed *)ped; + params.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(ped->m_modelIndex == MI_FATMALE02) ProcessPedHeadphones(¶ms); + ProcessPedOneShots(¶ms); +} + +void +cAudioManager::ProcessPedHeadphones(cPedParams *params) +{ + CPed *ped; + CVehicle *veh; + uint8 emittingVol; + + if(params->m_fDistance < 49.f) { + ped = params->m_pPed; + if(!(ped->m_ped_flagA20) || ped->m_bodyPartBleeding != 2) { + CalculateDistance((bool *)params, params->m_fDistance); + if(ped->bInVehicle && ped->m_nPedState == PED_DRIVING) { + emittingVol = 10; + veh = ped->m_pMyVehicle; + if(veh && veh->m_type == 0) { + for(int32 i = 2; i < 6; i++) { + if(!veh->IsDoorClosed((eDoors)i) || + veh->IsDoorMissing((eDoors)i)) { + emittingVol = 42; + break; + } + } + } + } else { + emittingVol = 42; + } + + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 7.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 64; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HEADPHONES; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_PED_HEADPHONES); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + cSampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = cSampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 7.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 5; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + return; + } + } +} + +void +cAudioManager::ProcessPedOneShots(cPedParams *params) +{ + uint8 emittingVol; + int32 sampleIndex; + + CPed *ped = params->m_pPed; + + char processed; + int16 sound; + char noReflection; + CWeapon *weapon; + uint16 i; + float maxDist; + + static uint8 iSound = 21; + + i = 0; + weapon = nil; + while(i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].field_24) { + noReflection = 0; + processed = 0; + m_sQueueSample.m_bRequireReflection = 0; + sound = m_asAudioEntities[0].m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex]; + switch(sound) { + case SOUND_STEP_START: + case SOUND_STEP_END: + if(!params->m_pPed->bIsLooking) { + emittingVol = m_anRandomTable[3] % 15u + 45; + if(FindPlayerPed() != + m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity) + emittingVol >>= 1; + maxDist = 400.f; + switch(params->m_pPed->m_nSurfaceTouched) { + case SURFACE_GRASS: + sampleIndex = + m_anRandomTable[1] % 5u + AUDIO_SAMPLE_PED_FALL_GRASS_1; + break; + case SURFACE_DIRT: + case SURFACE_DIRTTRACK: + sampleIndex = + m_anRandomTable[4] % 5u + AUDIO_SAMPLE_PED_FALL_DIRT_1; + break; + case SURFACE_METAL6: + case SURFACE_METAL_DOOR: + case SURFACE_BILLBOARD: + case SURFACE_STEEL: + case SURFACE_METAL_POLE: + case SURFACE_STREET_LIGHT: + case SURFACE_METAL14: + case SURFACE_METAL15: + case SURFACE_METAL_FENCE: + case SURFACE_METAL27: + case SURFACE_METAL28: + sampleIndex = + m_anRandomTable[0] % 5u + AUDIO_SAMPLE_PED_FALL_METAL_1; + break; + case SURFACE_SAND: + sampleIndex = + (m_anRandomTable[4] & 3) + AUDIO_SAMPLE_PED_FALL_SAND_1; + break; + case SURFACE_PUDDLE: + sampleIndex = (m_anRandomTable[3] & 3) + + AUDIO_SAMPLE_PED_FALL_IN_WATER_1; + break; + case SURFACE_WOOD: + case SURFACE_WOOD_BOX: + case SURFACE_WOOD_PLANK: + sampleIndex = + m_anRandomTable[2] % 5u + AUDIO_SAMPLE_PED_FALL_WOOD_1; + break; + case SURFACE_HEDGE: + sampleIndex = + m_anRandomTable[2] % 5u + AUDIO_SAMPLE_COLLISION_HEDGE; + break; + default: + sampleIndex = m_anRandomTable[2] % 5u + + AUDIO_SAMPLE_PED_FALL_PAVEMENT_1; + break; + } + m_sQueueSample.m_nSampleIndex = sampleIndex; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = + m_asAudioEntities[0] + .m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex] - + 28; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency / 17u); + switch(params->m_pPed->m_nMoveState) { + case 2: + emittingVol >>= 2; + m_sQueueSample.m_nFrequency = + 9 * m_sQueueSample.m_nFrequency / 10u; + break; + case 3: + emittingVol >>= 1; + m_sQueueSample.m_nFrequency = + 11 * m_sQueueSample.m_nFrequency / 10u; + break; + case 4: + m_sQueueSample.m_nFrequency = + 12 * m_sQueueSample.m_nFrequency / 10u; + break; + default: break; + } + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 20.0f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + goto LABEL_84; + } + break; + case SOUND_FALL_LAND: + case SOUND_FALL_COLLAPSE: + if(!ped->bIsLooking) { + maxDist = 900.f; + emittingVol = m_anRandomTable[3] % 20 + 80; + if(ped->m_nSurfaceTouched == SURFACE_PUDDLE) { + m_sQueueSample.m_nSampleIndex = + (m_anRandomTable[3] & 3) + + AUDIO_SAMPLE_PED_FALL_IN_WATER_1; + } else if(sound == SOUND_FALL_LAND) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_FALL_LAND; + } else { + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_PED_FALL_COLLAPSE; + } + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency / 17u); + m_sQueueSample.field_16 = 2; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + goto LABEL_84; + } + break; + case SOUND_21: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; + m_sQueueSample.m_nFrequency = 18000; + goto LABEL_81; + case SOUND_22: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; + m_sQueueSample.m_nFrequency = 16500; + goto LABEL_81; + case SOUND_23: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; + goto LABEL_80; + case SOUND_24: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; + m_sQueueSample.m_nFrequency = 18000; + goto LABEL_81; + case SOUND_25: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; + m_sQueueSample.m_nFrequency = 16500; + goto LABEL_81; + case SOUND_26: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; + goto LABEL_80; + case SOUND_WEAPON_PUNCH_ATTACK: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; + m_sQueueSample.m_nFrequency = 18000; + goto LABEL_81; + case SOUND_28: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; + m_sQueueSample.m_nFrequency = 16500; + goto LABEL_81; + case SOUND_29: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; + goto LABEL_80; + case SOUND_2A: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; + m_sQueueSample.m_nFrequency = 18000; + goto LABEL_81; + case SOUND_2B: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; + m_sQueueSample.m_nFrequency = 16500; + goto LABEL_81; + case SOUND_2C: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; + LABEL_80: + m_sQueueSample.m_nFrequency = 20000; + LABEL_81: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + goto LABEL_84; + case SOUND_WEAPON_BAT_ATTACK: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_BY_BAT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = RandomDisplacement(2000u) + 22000; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[2] % 20 + 100; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case SOUND_WEAPON_SHOT_FIRED: + weapon = &ped->m_weapons[ped->m_currentWeapon]; + switch(weapon->m_eWeaponType) { + case WEAPONTYPE_COLT45: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_PISTOL_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_PISTOL_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + maxDist = 2500.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[1] % 10 + 90; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case WEAPONTYPE_UZI: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_UZI_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + maxDist = 6400.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 15 + 70; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + goto LABEL_84; + case WEAPONTYPE_SHOTGUN: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + maxDist = 3600.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[2] % 10 + 100; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case WEAPONTYPE_AK47: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + maxDist = 6400.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[1] % 15 + 70; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + goto LABEL_84; + case WEAPONTYPE_M16: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_M16_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_M16_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + maxDist = 6400.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[4] % 15 + 70; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + goto LABEL_84; + case WEAPONTYPE_SNIPERRIFLE: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_SNIPER_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + maxDist = 3600.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[4] % 10 + 110; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case WEAPONTYPE_ROCKETLAUNCHER: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_ROCKET_SHOT); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); + m_sQueueSample.field_16 = 1; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 90.0f; + maxDist = 8100.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[0] % 20 + 80; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case WEAPONTYPE_FLAMETHROWER: + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_WEAPON_FLAMETHROWER_SHOT; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = 9; + emittingVol = 90; + m_sQueueSample.m_nFrequency = + (10 * m_sQueueSample.m_nEntityIndex & 2047) + + cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_FLAMETHROWER_SHOT); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + maxDist = 3600.f; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_nLoopStart = + cSampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = cSampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_bEmittingVolume = 90; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 6; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + default: goto LABEL_100; + } + + break; + case SOUND_WEAPON_RELOAD: + weapon = &ped->m_weapons[ped->m_currentWeapon]; + switch(weapon->m_eWeaponType) { + case WEAPONTYPE_COLT45: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_PISTOL_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_PISTOL_RELOAD) + + RandomDisplacement(300u); + goto LABEL_63; + case WEAPONTYPE_UZI: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = 39243; + goto LABEL_63; + case WEAPONTYPE_SHOTGUN: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = 30290; + goto LABEL_63; + case WEAPONTYPE_AK47: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD); + goto LABEL_62; + case WEAPONTYPE_M16: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_UZI_RELOAD); + goto LABEL_62; + case WEAPONTYPE_SNIPERRIFLE: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD); + goto LABEL_62; + case WEAPONTYPE_ROCKETLAUNCHER: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD; + emittingVol = 75; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD); + LABEL_62: + LABEL_63: + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + goto LABEL_84; + default: goto LABEL_100; + } + + break; + case SOUND_WEAPON_AK47_BULLET_ECHO: + case SOUND_WEAPON_UZI_BULLET_ECHO: + case SOUND_WEAPON_M16_BULLET_ECHO: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_75; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_75); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 80.0f; + maxDist = 6400.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = m_anRandomTable[4] % 10 + 40; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + if(m_bDynamicAcousticModelingStatus) + m_sQueueSample.m_bRequireReflection = 1; + else + noReflection = 1; + goto LABEL_84; + case SOUND_WEAPON_FLAMETHROWER_FIRE: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 60.0f; + maxDist = 3600.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + emittingVol = 70; + m_sQueueSample.m_bEmittingVolume = 70; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + goto LABEL_84; + case SOUND_WEAPON_HIT_PED: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BULLET_HIT_PED; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = + cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_BULLET_HIT_PED); + m_sQueueSample.m_nFrequency += + RandomDisplacement(m_sQueueSample.m_nFrequency >> 3); + m_sQueueSample.field_16 = 7; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[0] % 20 + 90; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + goto LABEL_84; + case SOUND_SPLASH: + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_WATER; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound++; + processed = 1; + m_sQueueSample.m_nFrequency = RandomDisplacement(1400u) + 20000; + m_sQueueSample.field_16 = 1; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 40.0f; + maxDist = 1600.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[2] % 30 + 70; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + LABEL_84: + if(processed && iSound > 60u) iSound = 21; + if(params->m_fDistance < maxDist) { + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, m_sQueueSample.m_fSoundIntensity, + m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + if(noReflection) { + if(0.2f * m_sQueueSample.m_fSoundIntensity > + m_sQueueSample.m_fDistance) { + noReflection = 0; + } else { + m_sQueueSample.m_bIsDistant = 1; + m_sQueueSample.m_bOffset = 0; + } + } + m_sQueueSample.m_bReverbFlag = 1; + AddSampleToRequestedQueue(); + if(noReflection) { + m_sQueueSample.m_bOffset = 127; + ++m_sQueueSample.m_nSampleIndex; + if(m_asAudioEntities[0].m_awAudioEvent + [i + + 20 * m_sQueueSample.m_nEntityIndex] != + 47 || + weapon->m_eWeaponType != + WEAPONTYPE_FLAMETHROWER) { + m_sQueueSample.field_4 = iSound++; + if(iSound > 60u) iSound = 21; + } else { + ++m_sQueueSample.field_4; + } + AddSampleToRequestedQueue(); + } + } + } + break; + default: SetupPedComments(params, sound); break; + } + LABEL_100: + ++i; + } } void @@ -5396,8 +6508,8 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); if(distSquared < maxDist) { m_sQueueSample.m_fDistance = sqrt(distSquared); - m_sQueueSample.m_bVolume = cAudioManager::ComputeVolume( - 30u, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); + m_sQueueSample.m_bVolume = ComputeVolume(30u, m_sQueueSample.m_fSoundIntensity, + m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_SAWMILL_1; m_sQueueSample.m_bBankIndex = 0; @@ -5420,7 +6532,7 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) } time = CTimer::GetTimeInMilliseconds(); if(time > audioLogicTimers[1]) { - m_sQueueSample.m_bVolume = cAudioManager::ComputeVolume( + m_sQueueSample.m_bVolume = ComputeVolume( 70u, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_SAWMILL_2; @@ -5444,11 +6556,19 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) } } -WRAPPER void cAudioManager::ProcessScriptObject(int32 id) { - EAXJMP(0x576070); + cAudioScriptObject *entity = (cAudioScriptObject *)m_asAudioEntities[id].m_pEntity; + if(entity) { + m_sQueueSample.m_vecPos.x = entity->m_vecPos.x; + m_sQueueSample.m_vecPos.y = entity->m_vecPos.y; + m_sQueueSample.m_vecPos.z = entity->m_vecPos.z; + if(m_asAudioEntities[id].field_24 == 1) + ProcessOneShotScriptObject(m_asAudioEntities[id].m_awAudioEvent[0]); + else + ProcessLoopingScriptObject(entity->m_wSound); + } } void @@ -5490,7 +6610,7 @@ cAudioManager::ProcessShopScriptObject(uint8 sound) SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_bReverbFlag = 1; m_sQueueSample.m_bRequireReflection = 0; - cAudioManager::AddSampleToRequestedQueue(); + AddSampleToRequestedQueue(); } time = CTimer::GetTimeInMilliseconds(); if(time > audioLogicTimers[2]) { @@ -5579,7 +6699,7 @@ cAudioManager::ProcessWorkShopScriptObject(uint8 sound) case SCRIPT_SOUND_WORK_SHOP_LOOP_S: case SCRIPT_SOUND_WORK_SHOP_LOOP_L: maxDist = 400.f; - m_sQueueSample.m_fSoundIntensity = 20.0; + m_sQueueSample.m_fSoundIntensity = 20.0f; break; default: break; } @@ -5598,7 +6718,7 @@ cAudioManager::ProcessWorkShopScriptObject(uint8 sound) m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; m_sQueueSample.field_16 = 5; - m_sQueueSample.field_48 = 2.0; + m_sQueueSample.field_48 = 2.0f; m_sQueueSample.m_bEmittingVolume = 30; m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); @@ -5611,6 +6731,136 @@ cAudioManager::ProcessWorkShopScriptObject(uint8 sound) } } +void +cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) +{ + CPed *ped = params->m_pPed; + uint8 emittingVol; + float maxDist; + float soundIntensity; + tPedComment pedComment; + + if(ped) { + switch(sound) { + case SOUND_AMMUNATION_WELCOME_1: + pedComment.m_nSampleIndex = AUDIO_SAMPLE_AMMUNATION_WELCOME_1; + break; + case SOUND_AMMUNATION_WELCOME_2: + pedComment.m_nSampleIndex = AUDIO_SAMPLE_AMMUNATION_WELCOME_2; + break; + case SOUND_AMMUNATION_WELCOME_3: + pedComment.m_nSampleIndex = AUDIO_SAMPLE_AMMUNATION_WELCOME_3; + break; + default: + pedComment.m_nSampleIndex = GetPedCommentSfx(ped, sound); + if(pedComment.m_nSampleIndex == NO_SAMPLE) return; + break; + } + + maxDist = 2500.f; + soundIntensity = 50.f; + + if(params->m_fDistance < maxDist) { + CalculateDistance((bool *)params, params->m_fDistance); + if(sound != SOUND_PAGER) { + switch(sound) { + case SOUND_AMMUNATION_WELCOME_1: + case SOUND_AMMUNATION_WELCOME_2: + case SOUND_AMMUNATION_WELCOME_3: emittingVol = maxVolume; break; + default: + if(CWorld::GetIsLineOfSightClear( + TheCamera.GetGameCamPosition(), + m_sQueueSample.m_vecPos, 1, 0, 0, 0, 0, 0, 0)) { + emittingVol = maxVolume; + } else { + emittingVol = 31; + } + break; + } + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVol, soundIntensity, m_sQueueSample.m_fDistance); + pedComment.field_25 = 10; + if(m_sQueueSample.m_bVolume) { + pedComment.field_4 = m_sQueueSample.m_nEntityIndex; + pedComment.m_vecPos.x = m_sQueueSample.m_vecPos.x; + pedComment.m_vecPos.y = m_sQueueSample.m_vecPos.y; + pedComment.m_vecPos.z = m_sQueueSample.m_vecPos.z; + pedComment.m_fDistance = m_sQueueSample.m_fDistance; + pedComment.m_bVolume = m_sQueueSample.m_bVolume; + m_sPedComments.Add(&pedComment); + } + } + } + } else { + switch(sound) { + case SOUND_PED_HELI_PLAYER_FOUND: + maxDist = 160000.f; + soundIntensity = 400.f; + pedComment.m_nSampleIndex = + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % 29u + + AUDIO_SAMPLE_POLICE_HELI_FOUND_PLAYER_1; + break; + case SOUND_PED_BODYCAST_HIT: + if(CTimer::GetTimeInMilliseconds() <= audioLogicTimers[8]) return; + maxDist = 2500.f; + soundIntensity = 50.f; + audioLogicTimers[8] = CTimer::GetTimeInMilliseconds() + 500; + pedComment.m_nSampleIndex = + (m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] & 3) + + AUDIO_SAMPLE_PED_BODYCAST_HIT_1; + break; + case SOUND_INJURED_PED_MALE_OUCH: + case SOUND_8A: + maxDist = 2500.f; + soundIntensity = 50.f; + pedComment.m_nSampleIndex = + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % 15u + + AUDIO_SAMPLE_INJURED_PED_MALE_OUCH_1; + break; + case SOUND_INJURED_PED_FEMALE: + maxDist = 2500.f; + soundIntensity = 50.f; + pedComment.m_nSampleIndex = + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % 11u + + AUDIO_SAMPLE_INJURED_PED_FEMALE_OUCH_1; + break; + default: return; + } + + if(params->m_fDistance < maxDist) { + CalculateDistance((bool *)params, params->m_fDistance); + if(sound != SOUND_PAGER) { + switch(sound) { + case SOUND_AMMUNATION_WELCOME_1: + case SOUND_AMMUNATION_WELCOME_2: + case SOUND_AMMUNATION_WELCOME_3: emittingVol = maxVolume; break; + default: + if(CWorld::GetIsLineOfSightClear( + TheCamera.GetGameCamPosition(), + m_sQueueSample.m_vecPos, 1, 0, 0, 0, 0, 0, 0)) { + emittingVol = maxVolume; + } else { + emittingVol = 31; + } + break; + } + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVol, soundIntensity, m_sQueueSample.m_fDistance); + pedComment.field_25 = 10; + if(m_sQueueSample.m_bVolume) { + pedComment.field_4 = m_sQueueSample.m_nEntityIndex; + pedComment.m_vecPos.x = m_sQueueSample.m_vecPos.x; + pedComment.m_vecPos.y = m_sQueueSample.m_vecPos.y; + pedComment.m_vecPos.z = m_sQueueSample.m_vecPos.z; + pedComment.m_fDistance = m_sQueueSample.m_fDistance; + pedComment.m_bVolume = m_sQueueSample.m_bVolume; + m_sPedComments.Add(&pedComment); + } + } + } + } +} + WRAPPER void cAudioManager::Service() { @@ -5663,6 +6913,8 @@ WRAPPER void cAudioManager::PreloadMissionAudio(char *) } STARTPATCHES +InjectHook(0x5755C0, &cPedComments::Add, PATCH_JUMP); + InjectHook(0x57B210, &cAudioManager::AddDetailsToRequestedOrderList, PATCH_JUMP); InjectHook(0x56AD30, &cAudioManager::AddPlayerCarSample, PATCH_JUMP); InjectHook(0x57B300, &cAudioManager::AddReflectionsToRequestedQueue, PATCH_JUMP); @@ -5842,6 +7094,7 @@ InjectHook(0x579170, &cAudioManager::ProcessBridgeWarning, PATCH_JUMP); InjectHook(0x577CA0, &cAudioManager::ProcessCinemaScriptObject, PATCH_JUMP); InjectHook(0x577E50, &cAudioManager::ProcessDocksScriptObject, PATCH_JUMP); InjectHook(0x569870, &cAudioManager::ProcessEntity, PATCH_JUMP); +InjectHook(0x575AC0, &cAudioManager::ProcessExplosions, PATCH_JUMP); InjectHook(0x578FD0, &cAudioManager::ProcessFireHydrant, PATCH_JUMP); InjectHook(0x5785E0, &cAudioManager::ProcessFrontEnd, PATCH_JUMP); InjectHook(0x577FE0, &cAudioManager::ProcessHomeScriptObject, PATCH_JUMP); @@ -5854,10 +7107,16 @@ InjectHook(0x56EC00, &cAudioManager::ProcessJumboTakeOff, PATCH_JUMP); InjectHook(0x56EA10, &cAudioManager::ProcessJumboTaxi, PATCH_JUMP); InjectHook(0x5777E0, &cAudioManager::ProcessLaunderetteScriptObject, PATCH_JUMP); InjectHook(0x576770, &cAudioManager::ProcessLoopingScriptObject, PATCH_JUMP); +InjectHook(0x5760C0, &cAudioManager::ProcessOneShotScriptObject, PATCH_JUMP); +InjectHook(0x56F450, &cAudioManager::ProcessPed, PATCH_JUMP); +InjectHook(0x56F4D0, &cAudioManager::ProcessPedHeadphones, PATCH_JUMP); +InjectHook(0x56F650, &cAudioManager::ProcessPedOneShots, PATCH_JUMP); InjectHook(0x5699C0, &cAudioManager::ProcessPhysical, PATCH_JUMP); InjectHook(0x577280, &cAudioManager::ProcessPornCinema, PATCH_JUMP); InjectHook(0x577630, &cAudioManager::ProcessSawMillScriptObject, PATCH_JUMP); +InjectHook(0x576070, &cAudioManager::ProcessScriptObject, PATCH_JUMP); InjectHook(0x577970, &cAudioManager::ProcessShopScriptObject, PATCH_JUMP); InjectHook(0x5697D0, &cAudioManager::ProcessSpecial, PATCH_JUMP); InjectHook(0x577530, &cAudioManager::ProcessWorkShopScriptObject, PATCH_JUMP); +InjectHook(0x570690, &cAudioManager::SetupPedComments, PATCH_JUMP); ENDPATCHES diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 0d4a6f30..5b74cc16 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -51,7 +51,7 @@ public: uint8 field_91; }; -static_assert(sizeof(tActiveSample) == 0x5c, "tActiveSample: error"); +static_assert(sizeof(tActiveSample) == 92, "tActiveSample: error"); enum eAudioType : int32 { AUDIOTYPE_PHYSICAL = 0, @@ -83,11 +83,11 @@ public: int16 m_awAudioEvent[4]; uint8 gap_18[2]; float m_afVolume[4]; - uint8 field_24; + uint8 field_24; // is looping uint8 field_25[3]; }; -static_assert(sizeof(tAudioEntity) == 0x28, "tAudioEntity: error"); +static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); class tPedComment { @@ -101,19 +101,21 @@ public: uint8 gap_26[2]; }; -static_assert(sizeof(tPedComment) == 0x1c, "tPedComment: error"); +static_assert(sizeof(tPedComment) == 28, "tPedComment: error"); class cPedComments { public: - tPedComment m_asPedComments[40]; - uint8 field_1120[40]; - uint8 field_1160[2]; - uint8 field_1162; + tPedComment m_asPedComments[2][20]; + uint8 field_1120[2][20]; + uint8 nrOfCommentsInBank[2]; + uint8 activeBank; uint8 gap_1163[1]; + + void Add(tPedComment *com); // test }; -static_assert(sizeof(cPedComments) == 0x48c, "cPedComments: error"); +static_assert(sizeof(cPedComments) == 1164, "cPedComments: error"); class CEntity; @@ -133,7 +135,7 @@ public: int32 m_nBaseVolume; }; -static_assert(sizeof(cAudioCollision) == 0x28, "cAudioCollision: error"); +static_assert(sizeof(cAudioCollision) == 40, "cAudioCollision: error"); class cAudioCollisionManager { @@ -146,7 +148,7 @@ public: cAudioCollision m_sQueue; }; -static_assert(sizeof(cAudioCollisionManager) == 0x354, "cAudioCollisionManager: error"); +static_assert(sizeof(cAudioCollisionManager) == 852, "cAudioCollisionManager: error"); class cMissionAudio { @@ -166,12 +168,13 @@ public: uint8 field_31; }; -static_assert(sizeof(cMissionAudio) == 0x20, "cMissionAudio: error"); +static_assert(sizeof(cMissionAudio) == 32, "cMissionAudio: error"); class cVehicleParams; class CPlane; class CVehicle; class CPed; +class cPedParams; class cAudioScriptObject { public: @@ -182,11 +185,11 @@ public: static void *operator new(size_t); static void *operator new(size_t, int); - static void operator delete(void*, size_t); - static void operator delete(void*, int); + static void operator delete(void *, size_t); + static void operator delete(void *, int); }; -static_assert(sizeof(cAudioScriptObject) == 0x14, "cAudioScriptObject: error"); +static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error"); enum { @@ -334,7 +337,7 @@ public: bool MissionScriptAudioUsesPoliceChannel(int32 soundMission); - char* Get3DProviderName(uint8 id); + char *Get3DProviderName(uint8 id); bool SetupJumboFlySound(uint8 emittingVol); /// ok bool SetupJumboRumbleSound(uint8 emittingVol); /// ok @@ -474,7 +477,7 @@ public: void ProcessDocksScriptObject(uint8 sound); /// ok // bool ProcessEngineDamage(void *); //todo requires CVehicle void ProcessEntity(int32 sound); /// ok - void ProcessExplosions(int32 explosion); // todo requires CExplosion + void ProcessExplosions(int32 explosion); // test void ProcessFireHydrant(); /// ok void ProcessFires(int32 entity); // todo requires gFireManager void ProcessFrontEnd(); /// ok @@ -492,12 +495,12 @@ public: void ProcessLoopingScriptObject(uint8 sound); /// ok // void ProcessMissionAudio(); // void ProcessModelVehicle(void *); - // void ProcessOneShotScriptObject(uint8 sound); - void ProcessPed(CPhysical *p); // todo - // void ProcessPedHeadphones(void *); - // void ProcessPedOneShots(void *); - void ProcessPhysical(int32 id); /// ok - void ProcessPlane(void *); // todo + void ProcessOneShotScriptObject(uint8 sound); // test + void ProcessPed(CPhysical *ped); // test + void ProcessPedHeadphones(cPedParams *params); // test + void ProcessPedOneShots(cPedParams *params); // test, remove goto + void ProcessPhysical(int32 id); /// ok + void ProcessPlane(void *); // todo // void ProcessPlayersVehicleEngine(void *, void *); void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo void ProcessPornCinema(uint8 sound); /// ok @@ -506,7 +509,7 @@ public: // void ProcessReverb(); // bool ProcessReverseGear(void *); void ProcessSawMillScriptObject(uint8 sound); /// ok - void ProcessScriptObject(int32 id); // todo + void ProcessScriptObject(int32 id); // test void ProcessShopScriptObject(uint8 sound); /// ok void ProcessSpecial(); /// ok // bool ProcessTrainNoise(void *); @@ -523,19 +526,10 @@ public: void ProcessWeather(int32 id); // todo // bool ProcessWetRoadNoise(void *); void ProcessWorkShopScriptObject(uint8 sound); /// ok - - - void PlayOneShot(int, unsigned short, float); - void SetEffectsFadeVol(unsigned char); - void SetMusicFadeVol(unsigned char); - int8 SetCurrent3DProvider(unsigned char); - void ReportCrime(eCrimeType, CVector const &); - void PlaySuspectLastSeen(float, float, float); - void ReportCollision(CEntity *, CEntity *, unsigned char, unsigned char, float, float); - void ResetTimers(unsigned int); - void PreloadMissionAudio(char *); + + void SetupPedComments(cPedParams *params, uint32 sound); // todo hook }; -static_assert(sizeof(cAudioManager) == 0x4B14, "cAudioManager: error"); +static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); extern cAudioManager &AudioManager; diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h index 318b9947..0932e581 100644 --- a/src/audio/DMAudio.h +++ b/src/audio/DMAudio.h @@ -1,4 +1,7 @@ #pragma once + +#include "Wanted.h" + enum eSound : int16 { SOUND_CAR_DOOR_CLOSE_BONNET = 0, diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index e9b33395..87ce4476 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -207,8 +207,8 @@ CPathFind::PreparePathData(void) numExtern++; if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes) numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes; - maxX = max(maxX, Abs(InfoForTileCars[k].x)); - maxY = max(maxY, Abs(InfoForTileCars[k].y)); + maxX = Max(maxX, Abs(InfoForTileCars[k].x)); + maxY = Max(maxY, Abs(InfoForTileCars[k].y)); }else if(InfoForTileCars[k].type == NodeTypeIntern) numIntern++; } @@ -392,7 +392,7 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor if(Abs(dx) < nearestDist){ dy = tempnodes[k].pos.y - CoorsXFormed.y; if(Abs(dy) < nearestDist){ - nearestDist = max(Abs(dx), Abs(dy)); + nearestDist = Max(Abs(dx), Abs(dy)); nearestId = k; } } @@ -501,13 +501,13 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor // Find i inside path segment iseg = 0; - for(j = max(oldNumPathNodes, i-12); j < i; j++) + for(j = Max(oldNumPathNodes, i-12); j < i; j++) if(m_pathNodes[j].objectIndex == m_pathNodes[i].objectIndex) iseg++; istart = 12*m_mapObjects[m_pathNodes[i].objectIndex]->m_modelIndex; // Add links to other internal nodes - for(j = max(oldNumPathNodes, i-12); j < min(m_numPathNodes, i+12); j++){ + for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){ if(m_pathNodes[i].objectIndex != m_pathNodes[j].objectIndex || i == j) continue; // N.B.: in every path segment, the externals have to be at the end diff --git a/src/control/Population.h b/src/control/Population.h index 7e4b40d8..3582ccef 100644 --- a/src/control/Population.h +++ b/src/control/Population.h @@ -1,8 +1,9 @@ #pragma once +#include "Game.h" + class CPed; class CVehicle; -enum eLevelName; struct PedGroup { diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index 12636d32..207845b9 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -366,8 +366,8 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* main = RpAnimBlendClumpGetMainAssociation((RpClump*)ped->m_rwObject, &second, &blend_amount); if (main){ state->animId = main->animId; - state->time = 255.0f / 4.0f * max(0.0f, min(4.0f, main->currentTime)); - state->speed = 255.0f / 3.0f * max(0.0f, min(3.0f, main->speed)); + state->time = 255.0f / 4.0f * Max(0.0f, Min(4.0f, main->currentTime)); + state->speed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, main->speed)); }else{ state->animId = 3; state->time = 0; @@ -375,9 +375,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) } if (second) { state->secAnimId = second->animId; - state->secTime = 255.0f / 4.0f * max(0.0f, min(4.0f, second->currentTime)); - state->secSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, second->speed)); - state->blendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, blend_amount)); + state->secTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, second->currentTime)); + state->secSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, second->speed)); + state->blendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, blend_amount)); }else{ state->secAnimId = 0; state->secTime = 0; @@ -387,9 +387,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* partial = RpAnimBlendClumpGetMainPartialAssociation((RpClump*)ped->m_rwObject); if (partial) { state->partAnimId = partial->animId; - state->partAnimTime = 255.0f / 4.0f * max(0.0f, min(4.0f, partial->currentTime)); - state->partAnimSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, partial->speed)); - state->partBlendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, partial->blendAmount)); + state->partAnimTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, partial->currentTime)); + state->partAnimSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, partial->speed)); + state->partBlendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, partial->blendAmount)); }else{ state->partAnimId = 0; state->partAnimTime = 0; @@ -408,9 +408,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc){ state->aAnimId[i] = assoc->animId; - state->aCurTime[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); - state->aSpeed[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); - state->aBlendAmount[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); + state->aCurTime[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); + state->aSpeed[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); + state->aBlendAmount[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); state->aFlags[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID[i] = FindCBFunctionID(assoc->callback); @@ -431,9 +431,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainPartialAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc) { state->aAnimId2[i] = assoc->animId; - state->aCurTime2[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); - state->aSpeed2[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); - state->aBlendAmount2[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); + state->aCurTime2[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); + state->aSpeed2[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); + state->aBlendAmount2[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); state->aFlags2[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID2[i] = FindCBFunctionID(assoc->callback); @@ -625,9 +625,9 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) vp->health = vehicle->m_fHealth / 4.0f; /* Not anticipated that health can be > 1000. */ vp->acceleration = vehicle->m_fGasPedal * 100.0f; vp->panels = vehicle->IsCar() ? ((CAutomobile*)vehicle)->Damage.m_panelStatus : 0; - vp->velocityX = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ - vp->velocityY = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().y)); - vp->velocityZ = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().z)); + vp->velocityX = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ + vp->velocityY = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().y)); + vp->velocityZ = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().z)); vp->mi = vehicle->GetModelIndex(); vp->primary_color = vehicle->m_currentColour1; vp->secondary_color = vehicle->m_currentColour2; @@ -1501,9 +1501,9 @@ void CReplay::ProcessLookAroundCam(void) --FramesActiveLookAroundCam; fBetaAngleLookAroundCam += x_moved; if (CPad::NewMouseControllerState.LMB && CPad::NewMouseControllerState.RMB) - fDistanceLookAroundCam = max(3.0f, min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); + fDistanceLookAroundCam = Max(3.0f, Min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); else - fAlphaAngleLookAroundCam = max(0.1f, min(1.5f, fAlphaAngleLookAroundCam + y_moved)); + fAlphaAngleLookAroundCam = Max(0.1f, Min(1.5f, fAlphaAngleLookAroundCam + y_moved)); CVector camera_pt( fDistanceLookAroundCam * Sin(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), fDistanceLookAroundCam * Cos(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), diff --git a/src/control/Script.cpp b/src/control/Script.cpp index c81cd050..7e87fc6e 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1987,7 +1987,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; car->m_status = STATUS_PHYSICS; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -1999,7 +1999,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CCarCtrl::JoinCarWithRoadSystem(car); car->AutoPilot.m_nCarMission = MISSION_CRUISE; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2083,7 +2083,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CollectParameters(&m_nIp, 2); CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(car); - car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); + car->AutoPilot.m_nCruiseSpeed = Min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); return 0; } case COMMAND_SET_CAR_DRIVING_STYLE: diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index cb16c3ad..f15232f3 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -209,7 +209,7 @@ WellBufferMe(float Target, float *CurrentValue, float *CurrentSpeed, float MaxSp else if(TargetSpeed > 0.0f && *CurrentSpeed > TargetSpeed) *CurrentSpeed = TargetSpeed; - *CurrentValue += *CurrentSpeed * min(10.0f, CTimer::GetTimeStep()); + *CurrentValue += *CurrentSpeed * Min(10.0f, CTimer::GetTimeStep()); } void @@ -697,7 +697,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl // Process height offset to avoid peds and cars float TargetZOffSet = m_fUnknownZOffSet + m_fDimensionOfHighestNearCar; - TargetZOffSet = max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); + TargetZOffSet = Max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); float TargetHeight = CameraTarget.z + TargetZOffSet - Source.z; if(TargetHeight > m_fCamBufferedHeight){ @@ -753,7 +753,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl } } - TargetCoors.z += min(1.0f, m_fCamBufferedHeight/2.0f); + TargetCoors.z += Min(1.0f, m_fCamBufferedHeight/2.0f); m_cvecTargetCoorsForFudgeInter = TargetCoors; Front = TargetCoors - Source; @@ -991,7 +991,7 @@ CCam::WorkOutCamHeight(const CVector &TargetCoors, float TargetOrientation, floa } if(FoundCamRoof){ // Camera is under something - float roof = FoundRoofCenter ? min(CamRoof, CarRoof) : CamRoof; + float roof = FoundRoofCenter ? Min(CamRoof, CarRoof) : CamRoof; // Same weirdness again? TargetAlpha = CGeneral::GetATanOfXY(CA_MAX_DISTANCE, roof - CamTargetZ - 1.5f); CamClear = false; @@ -1249,7 +1249,7 @@ void CCam::Cam_On_A_String_Unobscured(const CVector &TargetCoors, float BaseDist) { CA_MAX_DISTANCE = BaseDist + 0.1f + TheCamera.CarZoomValueSmooth; - CA_MIN_DISTANCE = min(BaseDist*0.6f, 3.5f); + CA_MIN_DISTANCE = Min(BaseDist*0.6f, 3.5f); CVector Dist = Source - TargetCoors; diff --git a/src/core/Camera.h b/src/core/Camera.h index c617c3d7..1f38963b 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -442,7 +442,7 @@ int m_iModeObbeCamIsInForCar; static bool &m_bUseMouse3rdPerson; bool Get_Just_Switched_Status() { return m_bJust_Switched; } - inline const CMatrix GetCameraMatrix(void) { return m_cameraMatrix; } + inline const CMatrix& GetCameraMatrix(void) { return m_cameraMatrix; } CVector &GetGameCamPosition(void) { return m_vecGameCamPos; } bool IsPointVisible(const CVector ¢er, const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat); diff --git a/src/core/CdStream.cpp b/src/core/CdStream.cpp index 255e46bb..57b1cbe2 100644 --- a/src/core/CdStream.cpp +++ b/src/core/CdStream.cpp @@ -5,8 +5,8 @@ #include "rwcore.h" #include "RwHelper.h" -#define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", __VA_ARGS__) -#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", __VA_ARGS__) +#define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) +#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) struct CdReadInfo { diff --git a/src/core/Collision.cpp b/src/core/Collision.cpp index 66b29d9f..538bcae6 100644 --- a/src/core/Collision.cpp +++ b/src/core/Collision.cpp @@ -153,10 +153,10 @@ CCollision::LoadCollisionWhenINeedIt(bool forceChange) // on water we expect to be between levels multipleLevels = true; }else{ - xmin = max(sx - 1, 0); - xmax = min(sx + 1, NUMSECTORS_X-1); - ymin = max(sy - 1, 0); - ymax = min(sy + 1, NUMSECTORS_Y-1); + xmin = Max(sx - 1, 0); + xmax = Min(sx + 1, NUMSECTORS_X-1); + ymin = Max(sy - 1, 0); + ymax = Min(sy + 1, NUMSECTORS_Y-1); for(x = xmin; x <= xmax; x++) for(y = ymin; y <= ymax; y++){ diff --git a/src/core/EventList.cpp b/src/core/EventList.cpp index a833cc8e..caf0cb3f 100644 --- a/src/core/EventList.cpp +++ b/src/core/EventList.cpp @@ -4,7 +4,7 @@ #include "ModelIndices.h" #include "World.h" #include "Wanted.h" -#include "Eventlist.h" +#include "EventList.h" int32 CEventList::ms_nFirstFreeSlotIndex; //CEvent gaEvent[NUMEVENTS]; diff --git a/src/core/Explosion.cpp b/src/core/Explosion.cpp index f55cbcd6..9ccd6e81 100644 --- a/src/core/Explosion.cpp +++ b/src/core/Explosion.cpp @@ -3,3 +3,27 @@ #include "Explosion.h" WRAPPER void CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionType type, const CVector &pos, uint32) { EAXJMP(0x5591C0); } + +WRAPPER +int8 CExplosion::GetExplosionActiveCounter(uint8 id) +{ + EAXJMP(0x559140); +} + +WRAPPER +CVector *CExplosion::GetExplosionPosition(uint8 id) +{ + EAXJMP(0x5591A0); +} + +WRAPPER +uint8 CExplosion::GetExplosionType(uint8 id) +{ + EAXJMP(0x559180); +} + +WRAPPER +void CExplosion::ResetExplosionActiveCounter(uint8 id) +{ + EAXJMP(0x559160); +} diff --git a/src/core/Explosion.h b/src/core/Explosion.h index 93d60ab3..fde4ad7f 100644 --- a/src/core/Explosion.h +++ b/src/core/Explosion.h @@ -1,6 +1,7 @@ #pragma once class CEntity; +class CVector; enum eExplosionType { @@ -19,5 +20,11 @@ enum eExplosionType class CExplosion { public: - static void AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionType type, const CVector &pos, uint32); + static void AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionType type, + const CVector &pos, uint32); + + static int8 GetExplosionActiveCounter(uint8 id); + static CVector *GetExplosionPosition(uint8 id); + static uint8 GetExplosionType(uint8 id); + static void ResetExplosionActiveCounter(uint8 id); }; diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 1de5c94f..c8a00744 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -1030,7 +1030,7 @@ int CMenuManager::FadeIn(int alpha) m_nCurrScreen == MENUPAGE_SAVING_IN_PROGRESS || m_nCurrScreen == MENUPAGE_DELETING) return alpha; - return min(m_nMenuFadeAlpha, alpha); + return Min(m_nMenuFadeAlpha, alpha); } #endif diff --git a/src/core/Game.cpp b/src/core/Game.cpp index e07106ce..b488a217 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -1,7 +1,7 @@ #include "common.h" #include "patcher.h" #include "Game.h" -#include "Main.h" +#include "main.h" #include "CdStream.h" #include "FileMgr.h" diff --git a/src/core/Instance.h b/src/core/Instance.h index 1038c005..bb74ea84 100644 --- a/src/core/Instance.h +++ b/src/core/Instance.h @@ -7,4 +7,5 @@ class CInstance : CPlaceable { public: + ~CInstance() = default; }; diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index f334a255..b5086d64 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -299,10 +299,10 @@ CControllerState CPad::ReconcileTwoControllersInput(CControllerState const &Stat { if ( State1.button || State2.button ) ReconState.button = 255; } #define _RECONCILE_AXIS_POSITIVE(axis) \ - { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = max(State1.axis, State2.axis); } + { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = Max(State1.axis, State2.axis); } #define _RECONCILE_AXIS_NEGATIVE(axis) \ - { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = min(State1.axis, State2.axis); } + { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = Min(State1.axis, State2.axis); } #define _RECONCILE_AXIS(axis) \ { _RECONCILE_AXIS_POSITIVE(axis); _RECONCILE_AXIS_NEGATIVE(axis); } diff --git a/src/core/Placeable.cpp b/src/core/Placeable.cpp index c1fe705e..d2cec82b 100644 --- a/src/core/Placeable.cpp +++ b/src/core/Placeable.cpp @@ -7,7 +7,7 @@ CPlaceable::CPlaceable(void) m_matrix.SetScale(1.0f); } -CPlaceable::~CPlaceable(void) { } +CPlaceable::~CPlaceable(void) = default; void CPlaceable::SetHeading(float angle) diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index a7bde91e..8158cd1d 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1940,7 +1940,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())){ lodDistSq = sq(mi->GetLargestLodDistance()); - lodDistSq = min(lodDistSq, sq(STREAM_DIST)); + lodDistSq = Min(lodDistSq, sq(STREAM_DIST)); pos = CVector2D(e->GetPosition()); if(xmin < pos.x && pos.x < xmax && ymin < pos.y && pos.y < ymax && @@ -2160,20 +2160,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) if(Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y)){ // looking west/east - ymin = max(iy - 10, 0); - ymax = min(iy + 10, NUMSECTORS_Y); + ymin = Max(iy - 10, 0); + ymax = Min(iy + 10, NUMSECTORS_Y); assert(ymin <= ymax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().x > 0){ // looking east - xmax = max(ix - 2, 0); - xmin = max(ix - 10, 0); + xmax = Max(ix - 2, 0); + xmin = Max(ix - 10, 0); inc = 1; }else{ // looking west - xmax = min(ix + 2, NUMSECTORS_X); - xmin = min(ix + 10, NUMSECTORS_X); + xmax = Min(ix + 2, NUMSECTORS_X); + xmin = Min(ix + 10, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2189,13 +2189,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().x > 0){ // looking east - xmax = max(ix + 10, 0); - xmin = max(ix - 2, 0); + xmax = Max(ix + 10, 0); + xmin = Max(ix - 2, 0); inc = 1; }else{ // looking west - xmax = min(ix - 10, NUMSECTORS_X); - xmin = min(ix + 2, NUMSECTORS_X); + xmax = Min(ix - 10, NUMSECTORS_X); + xmin = Min(ix + 2, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2224,20 +2224,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) }else{ // looking north/south - xmin = max(ix - 10, 0); - xmax = min(ix + 10, NUMSECTORS_X); + xmin = Max(ix - 10, 0); + xmax = Min(ix + 10, NUMSECTORS_X); assert(xmin <= xmax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().y > 0){ // looking north - ymax = max(iy - 2, 0); - ymin = max(iy - 10, 0); + ymax = Max(iy - 2, 0); + ymin = Max(iy - 10, 0); inc = 1; }else{ // looking south - ymax = min(iy + 2, NUMSECTORS_Y); - ymin = min(iy + 10, NUMSECTORS_Y); + ymax = Min(iy + 2, NUMSECTORS_Y); + ymin = Min(iy + 10, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ @@ -2253,13 +2253,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().y > 0){ // looking north - ymax = max(iy + 10, 0); - ymin = max(iy - 2, 0); + ymax = Max(iy + 10, 0); + ymin = Max(iy - 2, 0); inc = 1; }else{ // looking south - ymax = min(iy - 10, NUMSECTORS_Y); - ymin = min(iy + 2, NUMSECTORS_Y); + ymax = Min(iy - 10, NUMSECTORS_Y); + ymin = Min(iy + 2, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ diff --git a/src/core/Wanted.cpp b/src/core/Wanted.cpp index 26b115e3..daed9155 100644 --- a/src/core/Wanted.cpp +++ b/src/core/Wanted.cpp @@ -209,7 +209,7 @@ CWanted::ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesnt else sensitivity = m_fCrimeSensitivity; - wantedLevelDrop = min(CCullZones::GetWantedLevelDrop(), 100); + wantedLevelDrop = Min(CCullZones::GetWantedLevelDrop(), 100); chaos = (1.0f - wantedLevelDrop/100.0f) * sensitivity; if (policeDoesntCare) diff --git a/src/core/common.h b/src/core/common.h index 36f67bfa..73e57c21 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -177,10 +177,10 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con #define DEBUGBREAK() __debugbreak(); -#define debug(f, ...) re3_debug("[DBG]: " f, __VA_ARGS__) -#define DEV(f, ...) re3_debug("[DEV]: " f, __VA_ARGS__) -#define TRACE(f, ...) re3_trace(__FILE__, __LINE__, __FUNCTION__, f, __VA_ARGS__) -#define Error(f, ...) re3_debug("[ERROR]: " f, __VA_ARGS__) +#define debug(f, ...) re3_debug("[DBG]: " f, ## __VA_ARGS__) +#define DEV(f, ...) re3_debug("[DEV]: " f, ## __VA_ARGS__) +#define TRACE(f, ...) re3_trace(__FILE__, __LINE__, __FUNCTION__, f, ## __VA_ARGS__) +#define Error(f, ...) re3_debug("[ERROR]: " f, ## __VA_ARGS__) #define assert(_Expression) (void)( (!!(_Expression)) || (re3_assert(#_Expression, __FILE__, __LINE__, __FUNCTION__), 0) ) #define ASSERT assert @@ -200,7 +200,6 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con #define ABS(a) (((a) < 0) ? (-(a)) : (a)) #define norm(value, min, max) (((value) < (min)) ? 0 : (((value) > (max)) ? 1 : (((value) - (min)) / ((max) - (min))))) - #define STRINGIFY(x) #x #define STR(x) STRINGIFY(x) #define CONCAT_(x,y) x##y diff --git a/src/core/main.cpp b/src/core/main.cpp index 50494ef3..a82a2ab8 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -453,7 +453,7 @@ DoFade(void) CRGBA fadeColor; CRect rect; int fadeValue = CDraw::FadeValue; - float brightness = min(CMenuManager::m_PrefsBrightness, 256); + float brightness = Min(CMenuManager::m_PrefsBrightness, 256); if(brightness <= 50) brightness = 50; if(FrontEndMenuManager.m_bMenuActive) diff --git a/src/core/re3.cpp b/src/core/re3.cpp index ad3838bd..0ce5ee3c 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -374,6 +374,32 @@ delayedPatches10(int a, int b) } */ +<<<<<<< HEAD +======= +void __declspec(naked) HeadlightsFix() +{ + static const float fMinusOne = -1.0f; + _asm + { + fld [esp+708h-690h] + fcomp fMinusOne + fnstsw ax + and ah, 5 + cmp ah, 1 + jnz HeadlightsFix_DontLimit + fld fMinusOne + fstp [esp+708h-690h] + +HeadlightsFix_DontLimit: + fld [esp+708h-690h] + fabs + fld st + push 0x5382F2 + retn + } +} + +>>>>>>> More audio ped const int re3_buffsize = 1024; static char re3_buff[re3_buffsize]; diff --git a/src/core/re3.cpp.autosave b/src/core/re3.cpp.autosave new file mode 100644 index 00000000..ad3838bd --- /dev/null +++ b/src/core/re3.cpp.autosave @@ -0,0 +1,483 @@ +#include +#include +#include +#include "common.h" +#include "patcher.h" +#include "Renderer.h" +#include "Credits.h" +#include "Camera.h" +#include "Weather.h" +#include "Clock.h" +#include "World.h" +#include "Vehicle.h" +#include "ModelIndices.h" +#include "Streaming.h" +#include "PathFind.h" +#include "Boat.h" +#include "Heli.h" +#include "Automobile.h" +#include "Ped.h" +#include "debugmenu_public.h" + +#include +#include + +std::vector usedAddresses; + +void **rwengine = *(void***)0x5A10E1; + +DebugMenuAPI gDebugMenuAPI; + +WRAPPER void *gtanew(uint32 sz) { EAXJMP(0x5A0690); } +WRAPPER void gtadelete(void *p) { EAXJMP(0x5A07E0); } + +// overload our own new/delete with GTA's functions +void *operator new(size_t sz) { return gtanew(sz); } +void operator delete(void *ptr) noexcept { gtadelete(ptr); } + +#ifdef USE_PS2_RAND +unsigned __int64 myrand_seed = 1; +#else +unsigned long int myrand_seed = 1; +#endif + +int +myrand(void) +{ +#ifdef USE_PS2_RAND + // Use our own implementation of rand, stolen from PS2 + myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1; + return ((myrand_seed >> 32) & 0x7FFFFFFF); +#else + // or original codewarrior rand + myrand_seed = myrand_seed * 1103515245 + 12345; + return((myrand_seed >> 16) & 0x7FFF); +#endif +} + +void +mysrand(unsigned int seed) +{ + myrand_seed = seed; +} + +void (*DebugMenuProcess)(void); +void (*DebugMenuRender)(void); +static void stub(void) { } + +void +DebugMenuInit(void) +{ + if(DebugMenuLoad()){ + DebugMenuProcess = (void(*)(void))GetProcAddress(gDebugMenuAPI.module, "DebugMenuProcess"); + DebugMenuRender = (void(*)(void))GetProcAddress(gDebugMenuAPI.module, "DebugMenuRender"); + } + if(DebugMenuProcess == nil || DebugMenuRender == nil){ + DebugMenuProcess = stub; + DebugMenuRender = stub; + } + +} + +void WeaponCheat(); +void HealthCheat(); +void TankCheat(); +void BlowUpCarsCheat(); +void ChangePlayerCheat(); +void MayhemCheat(); +void EverybodyAttacksPlayerCheat(); +void WeaponsForAllCheat(); +void FastTimeCheat(); +void SlowTimeCheat(); +void MoneyCheat(); +void ArmourCheat(); +void WantedLevelUpCheat(); +void WantedLevelDownCheat(); +void SunnyWeatherCheat(); +void CloudyWeatherCheat(); +void RainyWeatherCheat(); +void FoggyWeatherCheat(); +void FastWeatherCheat(); +void OnlyRenderWheelsCheat(); +void ChittyChittyBangBangCheat(); +void StrongGripCheat(); +void NastyLimbsCheat(); + +DebugMenuEntry *carCol1; +DebugMenuEntry *carCol2; + +void +SpawnCar(int id) +{ + CVector playerpos; + CStreaming::RequestModel(id, 0); + CStreaming::LoadAllRequestedModels(false); + if(CStreaming::HasModelLoaded(id)){ + playerpos = FindPlayerCoors(); + int node = ThePaths.FindNodeClosestToCoors(playerpos, 0, 100.0f, false, false); + if(node < 0) + return; + + CVehicle *v; + if(CModelInfo::IsBoatModel(id)) + return; + else + v = new CAutomobile(id, RANDOM_VEHICLE); + + v->bHasBeenOwnedByPlayer = true; + if(carCol1) + DebugMenuEntrySetAddress(carCol1, &v->m_currentColour1); + if(carCol2) + DebugMenuEntrySetAddress(carCol2, &v->m_currentColour2); + + v->GetPosition() = ThePaths.m_pathNodes[node].pos; + v->GetPosition().z += 4.0f; + v->SetOrientation(0.0f, 0.0f, 3.49f); + v->m_status = STATUS_ABANDONED; + v->m_nDoorLock = CARLOCK_UNLOCKED; + CWorld::Add(v); + } +} + +static void +LetThemFollowYou(void) { + CPed* player = (CPed*) FindPlayerPed(); + for (int i = 0; i < player->m_numNearPeds; i++) { + + CPed* nearPed = player->m_nearPeds[i]; + if (nearPed && !nearPed->IsPlayer()) { + nearPed->SetObjective(OBJECTIVE_FOLLOW_PED_IN_FORMATION, (void*)player); + nearPed->m_pedFormation = rand() & 7; + nearPed->bScriptObjectiveCompleted = false; + } + } +} + +static void +FixCar(void) +{ + CVehicle *veh = FindPlayerVehicle(); + if(veh == nil) + return; + veh->m_fHealth = 1000.0f; + if(!veh->IsCar()) + return; + ((CAutomobile*)veh)->Damage.SetEngineStatus(0); + ((CAutomobile*)veh)->Fix(); +} + +static int engineStatus; +static void +SetEngineStatus(void) +{ + CVehicle *veh = FindPlayerVehicle(); + if(veh == nil) + return; + if(!veh->IsCar()) + return; + ((CAutomobile*)veh)->Damage.SetEngineStatus(engineStatus); +} + +static void +ToggleComedy(void) +{ + CVehicle *veh = FindPlayerVehicle(); + if(veh == nil) + return; + veh->bComedyControls = !veh->bComedyControls; +} + +static void +PlaceOnRoad(void) +{ + CVehicle *veh = FindPlayerVehicle(); + if(veh == nil) + return; + + if(veh->IsCar()) + ((CAutomobile*)veh)->PlaceOnRoadProperly(); +} + +static const char *carnames[] = { + "landstal", "idaho", "stinger", "linerun", "peren", "sentinel", "patriot", "firetruk", "trash", "stretch", "manana", "infernus", "blista", "pony", + "mule", "cheetah", "ambulan", "fbicar", "moonbeam", "esperant", "taxi", "kuruma", "bobcat", "mrwhoop", "bfinject", "corpse", "police", "enforcer", + "securica", "banshee", "predator", "bus", "rhino", "barracks", "train", "chopper", "dodo", "coach", "cabbie", "stallion", "rumpo", "rcbandit", + "bellyup", "mrwongs", "mafia", "yardie", "yakuza", "diablos", "columb", "hoods", "airtrain", "deaddodo", "speeder", "reefer", "panlant", "flatbed", + "yankee", "escape", "borgnine", "toyz", "ghost", +}; + +static std::list TweakVarsList; +static bool bAddTweakVarsNow = false; +static const char *pTweakVarsDefaultPath = NULL; + +void CTweakVars::Add(CTweakVar *var) +{ + TweakVarsList.push_back(var); + + if ( bAddTweakVarsNow ) + var->AddDBG(pTweakVarsDefaultPath); +} + +void CTweakVars::AddDBG(const char *path) +{ + pTweakVarsDefaultPath = path; + + for(auto i = TweakVarsList.begin(); i != TweakVarsList.end(); ++i) + (*i)->AddDBG(pTweakVarsDefaultPath); + + bAddTweakVarsNow = true; +} + +void CTweakSwitch::AddDBG(const char *path) +{ + DebugMenuEntry *e = DebugMenuAddVar(m_pPath == NULL ? path : m_pPath, m_pVarName, (int32_t *)m_pIntVar, m_pFunc, 1, m_nMin, m_nMax, m_aStr); + DebugMenuEntrySetWrap(e, true); +} + +void CTweakFunc::AddDBG (const char *path) { DebugMenuAddCmd (m_pPath == NULL ? path : m_pPath, m_pVarName, m_pFunc); } +void CTweakBool::AddDBG (const char *path) { DebugMenuAddVarBool8(m_pPath == NULL ? path : m_pPath, m_pVarName, (int8_t *)m_pBoolVar, NULL); } +void CTweakInt8::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int8_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakUInt8::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint8_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakInt16::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int16_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakUInt16::AddDBG(const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint16_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakInt32::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int32_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakUInt32::AddDBG(const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint32_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } +void CTweakFloat::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (float *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound); } + +/* +static const char *wt[] = { + "Sunny", "Cloudy", "Rainy", "Foggy" + }; + +SETTWEAKPATH("TEST"); +TWEAKSWITCH(CWeather::NewWeatherType, 0, 3, wt, NULL); +*/ + +void +DebugMenuPopulate(void) +{ + if(DebugMenuLoad()){ + static const char *weathers[] = { + "Sunny", "Cloudy", "Rainy", "Foggy" + }; + DebugMenuEntry *e; + e = DebugMenuAddVar("Time & Weather", "Current Hour", &CClock::GetHoursRef(), nil, 1, 0, 23, nil); + DebugMenuEntrySetWrap(e, true); + e = DebugMenuAddVar("Time & Weather", "Current Minute", &CClock::GetMinutesRef(), + [](){ CWeather::InterpolationValue = CClock::GetMinutes()/60.0f; }, 1, 0, 59, nil); + DebugMenuEntrySetWrap(e, true); + e = DebugMenuAddVar("Time & Weather", "Old Weather", (int16*)&CWeather::OldWeatherType, nil, 1, 0, 3, weathers); + DebugMenuEntrySetWrap(e, true); + e = DebugMenuAddVar("Time & Weather", "New Weather", (int16*)&CWeather::NewWeatherType, nil, 1, 0, 3, weathers); + DebugMenuEntrySetWrap(e, true); + DebugMenuAddVar("Time & Weather", "Wind", (float*)&CWeather::Wind, nil, 0.1f, 0.0f, 1.0f); + DebugMenuAddVar("Time & Weather", "Time scale", (float*)0x8F2C20, nil, 0.1f, 0.0f, 10.0f); + + DebugMenuAddCmd("Cheats", "Weapons", WeaponCheat); + DebugMenuAddCmd("Cheats", "Money", MoneyCheat); + DebugMenuAddCmd("Cheats", "Health", HealthCheat); + DebugMenuAddCmd("Cheats", "Wanted level up", WantedLevelUpCheat); + DebugMenuAddCmd("Cheats", "Wanted level down", WantedLevelDownCheat); + DebugMenuAddCmd("Cheats", "Tank", TankCheat); + DebugMenuAddCmd("Cheats", "Blow up cars", BlowUpCarsCheat); + DebugMenuAddCmd("Cheats", "Change player", ChangePlayerCheat); + DebugMenuAddCmd("Cheats", "Mayhem", MayhemCheat); + DebugMenuAddCmd("Cheats", "Everybody attacks player", EverybodyAttacksPlayerCheat); + DebugMenuAddCmd("Cheats", "Weapons for all", WeaponsForAllCheat); + DebugMenuAddCmd("Cheats", "Fast time", FastTimeCheat); + DebugMenuAddCmd("Cheats", "Slow time", SlowTimeCheat); + DebugMenuAddCmd("Cheats", "Armour", ArmourCheat); + DebugMenuAddCmd("Cheats", "Sunny weather", SunnyWeatherCheat); + DebugMenuAddCmd("Cheats", "Cloudy weather", CloudyWeatherCheat); + DebugMenuAddCmd("Cheats", "Rainy weather", RainyWeatherCheat); + DebugMenuAddCmd("Cheats", "Foggy weather", FoggyWeatherCheat); + DebugMenuAddCmd("Cheats", "Fast weather", FastWeatherCheat); + DebugMenuAddCmd("Cheats", "Only render wheels", OnlyRenderWheelsCheat); + DebugMenuAddCmd("Cheats", "Chitty chitty bang bang", ChittyChittyBangBangCheat); + DebugMenuAddCmd("Cheats", "Strong grip", StrongGripCheat); + DebugMenuAddCmd("Cheats", "Nasty limbs", NastyLimbsCheat); + + static int spawnCarId = MI_LANDSTAL; + e = DebugMenuAddVar("Spawn", "Spawn Car ID", &spawnCarId, nil, 1, MI_LANDSTAL, MI_GHOST, carnames); + DebugMenuEntrySetWrap(e, true); + DebugMenuAddCmd("Spawn", "Spawn Car", [](){ + if(spawnCarId == MI_TRAIN || + spawnCarId == MI_CHOPPER || + spawnCarId == MI_AIRTRAIN || + spawnCarId == MI_DEADDODO || + spawnCarId == MI_ESCAPE) + return; + SpawnCar(spawnCarId); + }); + static uint8 dummy; + carCol1 = DebugMenuAddVar("Spawn", "First colour", &dummy, nil, 1, 0, 255, nil); + carCol2 = DebugMenuAddVar("Spawn", "Second colour", &dummy, nil, 1, 0, 255, nil); + DebugMenuAddCmd("Spawn", "Spawn Stinger", [](){ SpawnCar(MI_STINGER); }); + DebugMenuAddCmd("Spawn", "Spawn Infernus", [](){ SpawnCar(MI_INFERNUS); }); + DebugMenuAddCmd("Spawn", "Spawn Cheetah", [](){ SpawnCar(MI_CHEETAH); }); + DebugMenuAddCmd("Spawn", "Spawn Esperanto", [](){ SpawnCar(MI_ESPERANT); }); + DebugMenuAddCmd("Spawn", "Spawn Stallion", [](){ SpawnCar(MI_STALLION); }); + DebugMenuAddCmd("Spawn", "Spawn Kuruma", [](){ SpawnCar(MI_KURUMA); }); + DebugMenuAddCmd("Spawn", "Spawn Taxi", [](){ SpawnCar(MI_TAXI); }); + DebugMenuAddCmd("Spawn", "Spawn Police", [](){ SpawnCar(MI_POLICE); }); + DebugMenuAddCmd("Spawn", "Spawn Enforcer", [](){ SpawnCar(MI_ENFORCER); }); + DebugMenuAddCmd("Spawn", "Spawn Banshee", [](){ SpawnCar(MI_BANSHEE); }); + DebugMenuAddCmd("Spawn", "Spawn Yakuza", [](){ SpawnCar(MI_YAKUZA); }); + DebugMenuAddCmd("Spawn", "Spawn Yardie", [](){ SpawnCar(MI_YARDIE); }); + DebugMenuAddCmd("Spawn", "Spawn Dodo", [](){ SpawnCar(MI_DODO); }); + DebugMenuAddCmd("Spawn", "Spawn Rhino", [](){ SpawnCar(MI_RHINO); }); + DebugMenuAddCmd("Spawn", "Spawn Firetruck", [](){ SpawnCar(MI_FIRETRUCK); }); + + DebugMenuAddVar("Debug", "Engine Status", &engineStatus, nil, 1, 0, 226, nil); + DebugMenuAddCmd("Debug", "Set Engine Status", SetEngineStatus); + DebugMenuAddCmd("Debug", "Fix Car", FixCar); + DebugMenuAddCmd("Debug", "Toggle Comedy Controls", ToggleComedy); + DebugMenuAddCmd("Debug", "Place Car on Road", PlaceOnRoad); + + DebugMenuAddVarBool8("Debug", "Catalina Heli On", (int8*)&CHeli::CatalinaHeliOn, nil); + DebugMenuAddCmd("Debug", "Catalina Fly By", CHeli::StartCatalinaFlyBy); + DebugMenuAddCmd("Debug", "Catalina Take Off", CHeli::CatalinaTakeOff); + DebugMenuAddCmd("Debug", "Catalina Fly Away", CHeli::MakeCatalinaHeliFlyAway); + DebugMenuAddVarBool8("Debug", "Script Heli On", (int8*)0x95CD43, nil); + + DebugMenuAddVarBool8("Debug", "Show Ped Road Groups", (int8*)&gbShowPedRoadGroups, nil); + DebugMenuAddVarBool8("Debug", "Show Car Road Groups", (int8*)&gbShowCarRoadGroups, nil); + DebugMenuAddVarBool8("Debug", "Show Collision Lines", (int8*)&gbShowCollisionLines, nil); + DebugMenuAddVarBool8("Debug", "Show Collision Polys", (int8*)&gbShowCollisionPolys, nil); + DebugMenuAddVarBool8("Debug", "Don't render Buildings", (int8*)&gbDontRenderBuildings, nil); + DebugMenuAddVarBool8("Debug", "Don't render Big Buildings", (int8*)&gbDontRenderBigBuildings, nil); + DebugMenuAddVarBool8("Debug", "Don't render Peds", (int8*)&gbDontRenderPeds, nil); + DebugMenuAddVarBool8("Debug", "Don't render Vehicles", (int8*)&gbDontRenderVehicles, nil); + DebugMenuAddVarBool8("Debug", "Don't render Objects", (int8*)&gbDontRenderObjects, nil); + + DebugMenuAddCmd("Debug", "Make peds around you follow you", LetThemFollowYou); +#ifndef MASTER + DebugMenuAddVarBool8("Debug", "Toggle unused fight feature", (int8*)&CPed::bUnusedFightThingOnPlayer, nil); +#endif + + DebugMenuAddCmd("Debug", "Start Credits", CCredits::Start); + DebugMenuAddCmd("Debug", "Stop Credits", CCredits::Stop); + + CTweakVars::AddDBG("Debug"); + } +} + +/* +int (*RsEventHandler_orig)(int a, int b); +int +delayedPatches10(int a, int b) +{ + DebugMenuInit(); + DebugMenuPopulate(); + + return RsEventHandler_orig(a, b); +} +*/ + +const int re3_buffsize = 1024; +static char re3_buff[re3_buffsize]; + +void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func) +{ + int nCode; + + strcpy_s(re3_buff, re3_buffsize, "Assertion failed!" ); + strcat_s(re3_buff, re3_buffsize, "\n" ); + + strcat_s(re3_buff, re3_buffsize, "File: "); + strcat_s(re3_buff, re3_buffsize, filename ); + strcat_s(re3_buff, re3_buffsize, "\n" ); + + strcat_s(re3_buff, re3_buffsize, "Line: " ); + _itoa_s( lineno, re3_buff + strlen(re3_buff), re3_buffsize - strlen(re3_buff), 10 ); + strcat_s(re3_buff, re3_buffsize, "\n"); + + strcat_s(re3_buff, re3_buffsize, "Function: "); + strcat_s(re3_buff, re3_buffsize, func ); + strcat_s(re3_buff, re3_buffsize, "\n" ); + + strcat_s(re3_buff, re3_buffsize, "Expression: "); + strcat_s(re3_buff, re3_buffsize, expr); + strcat_s(re3_buff, re3_buffsize, "\n"); + + strcat_s(re3_buff, re3_buffsize, "\n" ); + strcat_s(re3_buff, re3_buffsize, "(Press Retry to debug the application)"); + + + nCode = ::MessageBoxA(nil, re3_buff, "RE3 Assertion Failed!", + MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SETFOREGROUND|MB_TASKMODAL); + + if (nCode == IDABORT) + { + raise(SIGABRT); + _exit(3); + } + + if (nCode == IDRETRY) + { + __debugbreak(); + return; + } + + if (nCode == IDIGNORE) + return; + + abort(); +} + +void re3_debug(char *format, ...) +{ + va_list va; + va_start(va, format); + vsprintf_s(re3_buff, re3_buffsize, format, va); + va_end(va); + + printf("%s", re3_buff); +} + +void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...) +{ + char buff[re3_buffsize *2]; + va_list va; + va_start(va, format); + vsprintf_s(re3_buff, re3_buffsize, format, va); + va_end(va); + + sprintf_s(buff, re3_buffsize * 2, "[%s.%s:%d]: %s", filename, func, lineno, re3_buff); + + OutputDebugStringA(buff); +} + +void +patch() +{ + StaticPatcher::Apply(); + +// Patch(0x46BC61+6, 1.0f); // car distance + InjectHook(0x59E460, printf, PATCH_JUMP); + InjectHook(0x475E00, printf, PATCH_JUMP); // _Error + + +// InterceptCall(&open_script_orig, open_script, 0x438869); + +// InterceptCall(&RsEventHandler_orig, delayedPatches10, 0x58275E); +} + +BOOL WINAPI +DllMain(HINSTANCE hInst, DWORD reason, LPVOID) +{ + if(reason == DLL_PROCESS_ATTACH){ + + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + + if (*(DWORD*)0x5C1E75 == 0xB85548EC) // 1.0 + patch(); + else + return FALSE; + } + + return TRUE; +} diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index fbd1322d..d59e6c59 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -457,7 +457,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector & { float compression = 1.0f - springRatio; if(compression > 0.0f){ - float step = min(CTimer::GetTimeStep(), 3.0f); + float step = Min(CTimer::GetTimeStep(), 3.0f); float impulse = -GRAVITY*m_fMass*step * springConst * compression * bias*2.0f; ApplyMoveForce(springDir*impulse); ApplyTurnForce(springDir*impulse, point); @@ -471,12 +471,12 @@ CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &poin { float speedA = DotProduct(speed, springDir); float speedB = DotProduct(GetSpeed(point), springDir); - float step = min(CTimer::GetTimeStep(), 3.0f); + float step = Min(CTimer::GetTimeStep(), 3.0f); float impulse = -damping * (speedA + speedB)/2.0f * m_fMass * step * 0.53f; // what is this? float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass); - a = min(a, 1.0f); + a = Min(a, 1.0f); float b = Abs(impulse / (speedB * m_fMass)); if(a < b) impulse *= a/b; @@ -646,7 +646,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl // positive if B is moving towards A // not interested in how much B moves into A apparently? // only interested in cases where A collided into B - speedB = max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); + speedB = Max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); // A has moved into B if(speedA < speedB){ if(!A->bHasHitWall) @@ -1147,18 +1147,18 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) CVector dir = A->GetPosition() - B->GetPosition(); dir.Normalise(); if(dir.z < 0.0f && dir.z < A->GetForward().z && dir.z < A->GetRight().z) - dir.z = min(0.0f, min(A->GetForward().z, A->GetRight().z)); + dir.z = Min(0.0f, Min(A->GetForward().z, A->GetRight().z)); shift += dir * colpoints[mostColliding].depth * 0.5f; }else if(A->IsPed() && B->IsVehicle() && ((CVehicle*)B)->IsBoat()){ CVector dir = colpoints[mostColliding].normal; - float f = min(Abs(dir.z), 0.9f); + float f = Min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); shift += dir * colpoints[mostColliding].depth / (1.0f - f); boat = B; }else if(B->IsPed() && A->IsVehicle() && ((CVehicle*)A)->IsBoat()){ CVector dir = colpoints[mostColliding].normal * -1.0f; - float f = min(Abs(dir.z), 0.9f); + float f = Min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); B->GetPosition() += dir * colpoints[mostColliding].depth / (1.0f - f); @@ -1246,7 +1246,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1268,7 +1268,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1301,7 +1301,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1328,7 +1328,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1506,7 +1506,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); } }else{ for(i = 0; i < numCollisions; i++){ @@ -1527,7 +1527,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions; @@ -1545,7 +1545,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) else if(A->GetUp().z > 0.3f) adhesion = 0.0f; else - adhesion *= min(5.0f, 0.03f*impulseA + 1.0f); + adhesion *= Min(5.0f, 0.03f*impulseA + 1.0f); } if(A->ApplyFriction(adhesion, aColPoints[i])) @@ -1594,7 +1594,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1619,7 +1619,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1655,7 +1655,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1685,7 +1685,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1831,7 +1831,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && (distSq >= sq(0.2f) || ped->IsPlayer())){ if(ped->IsPlayer()) - n = max(NUMSTEPS(0.2f), 2.0); + n = Max(NUMSTEPS(0.2f), 2.0); else n = NUMSTEPS(0.3f); step = savedTimeStep / n; @@ -1852,7 +1852,7 @@ CPhysical::ProcessCollision(void) speedDown = Multiply3x3(GetMatrix(), speedDown); speedUp = GetSpeed(speedUp); speedDown = GetSpeed(speedDown); - distSq = max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); + distSq = Max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); if(distSq >= sq(0.3f)){ n = NUMSTEPS(0.3f); step = savedTimeStep / n; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 53d94d86..59395d94 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1792,7 +1792,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) neededPos.z = autoZPos.z; m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); @@ -1807,12 +1807,12 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) { - neededPos.z = max(currentZ, autoZPos.z); + neededPos.z = Max(currentZ, autoZPos.z); } } } @@ -3172,7 +3172,7 @@ CPed::CheckIfInTheAir(void) CEntity *foundEntity; float startZ = pos.z - 1.54f; - bool foundGround = CWorld::ProcessVerticalLine(pos, startZ, foundColPoint, foundEntity, true, true, false, true, false, false, false); + bool foundGround = CWorld::ProcessVerticalLine(pos, startZ, foundColPoint, foundEntity, true, true, false, true, false, false, nil); if (!foundGround && m_nPedState != PED_JUMP) { pos.z -= 1.04f; @@ -4771,12 +4771,12 @@ CPed::FightStrike(CVector &touchedNodePos) float moveMult; if (m_lastFightMove == FIGHTMOVE_GROUNDKICK) { - moveMult = min(damageMult * 0.6f, 4.0f); + moveMult = Min(damageMult * 0.6f, 4.0f); } else { if (nearPed->m_nPedState != PED_DIE || damageMult >= 20) { moveMult = damageMult; } else { - moveMult = min(damageMult * 2.0f, 14.0f); + moveMult = Min(damageMult * 2.0f, 14.0f); } } diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 5922e0e7..ff581150 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -718,6 +718,15 @@ public: #endif }; +class cPedParams +{ +public: + char m_bDistanceCalculated; + char gap_1[3]; + float m_fDistance; + CPed *m_pPed; +}; + void FinishFuckUCB(CAnimBlendAssociation *assoc, void *arg); static_assert(offsetof(CPed, m_nPedState) == 0x224, "CPed: error"); diff --git a/src/peds/PedPlacement.cpp b/src/peds/PedPlacement.cpp index f292f4fa..d7b7ec75 100644 --- a/src/peds/PedPlacement.cpp +++ b/src/peds/PedPlacement.cpp @@ -29,7 +29,7 @@ CPedPlacement::FindZCoorForPed(CVector* pos) if (CWorld::ProcessVerticalLine(vec, startZ, foundCol, foundEnt, true, false, false, false, true, false, nil)) foundColZ2 = foundCol.point.z; - zForPed = max(foundColZ, foundColZ2); + zForPed = Max(foundColZ, foundColZ2); if (zForPed > -99.0f) pos->z = 1.04f + zForPed; @@ -38,7 +38,7 @@ CPedPlacement::FindZCoorForPed(CVector* pos) CEntity* CPedPlacement::IsPositionClearOfCars(CVector* pos) { - return CWorld::TestSphereAgainstWorld(*pos, 0.25f, false, true, true, false, false, false, false); + return CWorld::TestSphereAgainstWorld(*pos, 0.25f, nil, true, true, false, false, false, false); } STARTPATCHES diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index 5ae8c4be..1dcbdf46 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -97,8 +97,16 @@ CPlayerPed::AnnoyPlayerPed(bool annoyedByPassingEntity) class CPlayerPed_ : public CPlayerPed { public: +<<<<<<< HEAD +<<<<<<< HEAD CPlayerPed* ctor(void) { return ::new (this) CPlayerPed(); } void dtor(void) { CPlayerPed::~CPlayerPed(); } +======= + void dtor(void) { this->~CPlayerPed(); } +>>>>>>> More audio ped +======= + void dtor(void) { CPlayerPed::~CPlayerPed(); } +>>>>>>> fix }; STARTPATCHES diff --git a/src/peds/PlayerPed.cpp.autosave b/src/peds/PlayerPed.cpp.autosave new file mode 100644 index 00000000..1bf1c7fc --- /dev/null +++ b/src/peds/PlayerPed.cpp.autosave @@ -0,0 +1,110 @@ +#include "common.h" +#include "patcher.h" +#include "PlayerPed.h" +#include "Camera.h" +#include "WeaponEffects.h" +#include "ModelIndices.h" + +CPlayerPed::~CPlayerPed() +{ + delete m_pWanted; +} + +WRAPPER void CPlayerPed::ReApplyMoveAnims(void) { EAXJMP(0x4F07C0); } +WRAPPER void CPlayerPed::SetupPlayerPed(int32) { EAXJMP(0x4EFB60); } +WRAPPER void CPlayerPed::DeactivatePlayerPed(int32) { EAXJMP(0x4EFC00); } +WRAPPER void CPlayerPed::ReactivatePlayerPed(int32) { EAXJMP(0x4EFC20); } +WRAPPER void CPlayerPed::KeepAreaAroundPlayerClear(void) { EAXJMP(0x4F3460); } +WRAPPER void CPlayerPed::MakeChangesForNewWeapon(int8) { EAXJMP(0x4F2560); } +WRAPPER void CPlayerPed::SetInitialState(void) { EAXJMP(0x4EFC40); } +WRAPPER void CPlayerPed::SetMoveAnim(void) { EAXJMP(0x4F3760); } +WRAPPER void CPlayerPed::ProcessControl(void) { EAXJMP(0x4EFD90); } + +CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1) +{ + m_fMoveSpeed = 0.0f; + SetModelIndex(MI_PLAYER); + SetInitialState(); + + m_pWanted = new CWanted(); + m_pWanted->Initialise(); + m_pArrestingCop = nil; + m_currentWeapon = WEAPONTYPE_UNARMED; + m_nSelectedWepSlot = 0; + m_nSpeedTimer = 0; + m_bSpeedTimerFlag = 0; + m_pPointGunAt = nil; + m_nPedState = PED_IDLE; + m_fMaxStamina = 150.0f; + m_fCurrentStamina = m_fMaxStamina; + m_fStaminaProgress = 0.0f; + m_bShouldEvade = 0; + field_1367 = 0; + m_nShotDelay = 0; + field_1376 = 0.0f; + field_1380 = 0; + m_bHasLockOnTarget = false; + m_bCanBeDamaged = true; + m_fWalkAngle = 0.0f; + m_fFPSMoveHeading = 0.0f; + m_nTargettableObjects[0] = m_nTargettableObjects[1] = m_nTargettableObjects[2] = m_nTargettableObjects[3] = -1; + field_1413 = 0; + for (int i = 0; i < 6; i++) { + m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f); + field_1488[i] = 0; + } +} + +void CPlayerPed::ClearWeaponTarget() +{ + if (m_nPedType == PEDTYPE_PLAYER1) { + m_pPointGunAt = nil; + TheCamera.ClearPlayerWeaponMode(); + CWeaponEffects::ClearCrosshair(); + } + ClearPointGunAt(); +} + +void +CPlayerPed::SetWantedLevel(int32 level) +{ + m_pWanted->SetWantedLevel(level); +} + +void +CPlayerPed::SetWantedLevelNoDrop(int32 level) +{ + m_pWanted->SetWantedLevelNoDrop(level); +} + +// I don't know the actual purpose of parameter +void +CPlayerPed::AnnoyPlayerPed(bool annoyedByPassingEntity) +{ + if (m_pedStats->m_temper < 52) { + m_pedStats->m_temper++; + } else { + if (annoyedByPassingEntity) { + if (m_pedStats->m_temper < 55) { + m_pedStats->m_temper++; + } else { + m_pedStats->m_temper = 46; + } + } + } +} + +class CPlayerPed_ : public CPlayerPed +{ +public: + + CPlayerPed* ctor(void) { return ::new (this) CPlayerPed(); } + void dtor(void) { CPlayerPed::~CPlayerPed(); } +}; + +STARTPATCHES + InjectHook(0x4EF7E0, &CPlayerPed_::ctor, PATCH_JUMP); + InjectHook(0x4EFB30, &CPlayerPed_::dtor, PATCH_JUMP); + InjectHook(0x4F28A0, &CPlayerPed::ClearWeaponTarget, PATCH_JUMP); + InjectHook(0x4F3700, &CPlayerPed::AnnoyPlayerPed, PATCH_JUMP); +ENDPATCHES diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index 2884894c..a461301c 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -388,7 +388,7 @@ CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, ms_colourBottom.b = topblue; ms_colourBottom.a = alpha; - botpos = min(SCREEN_HEIGHT, topedge); + botpos = Min(SCREEN_HEIGHT, topedge); CSprite2d::DrawRect(CRect(0, 0, SCREEN_WIDTH, botpos), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } @@ -415,18 +415,18 @@ CClouds::RenderHorizon(void) if(ms_horizonZ > SCREEN_HEIGHT) return; - float z1 = min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); + float z1 = Min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); CSprite2d::DrawRectXLU(CRect(0, ms_horizonZ, SCREEN_WIDTH, z1), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); // This is just weird float a = SCREEN_HEIGHT/400.0f * HORIZSTRIPHEIGHT + - SCREEN_HEIGHT/300.0f * max(TheCamera.GetPosition().z, 0.0f); + SCREEN_HEIGHT/300.0f * Max(TheCamera.GetPosition().z, 0.0f); float b = TheCamera.GetUp().z < 0.0f ? SCREEN_HEIGHT : SCREEN_HEIGHT * Abs(TheCamera.GetRight().z); float z2 = z1 + (a + b)*TheCamera.LODDistMultiplier; - z2 = min(z2, SCREEN_HEIGHT); + z2 = Min(z2, SCREEN_HEIGHT); CSprite2d::DrawRect(CRect(0, z1, SCREEN_WIDTH, z2), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 1a6cfea3..9881e764 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -109,7 +109,7 @@ CCoronas::Update(void) int i; static int LastCamLook = 0; - LightsMult = min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); + LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); int CamLook = 0; if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; @@ -121,7 +121,7 @@ CCoronas::Update(void) if(LastCamLook != CamLook) bChangeBrightnessImmediately = 3; else - bChangeBrightnessImmediately = max(bChangeBrightnessImmediately-1, 0); + bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); LastCamLook = CamLook; for(i = 0; i < NUMCORONAS; i++) @@ -309,7 +309,7 @@ CCoronas::Render(void) // render corona itself if(aCoronas[i].texture){ - float fogscale = CWeather::Foggyness*min(spriteCoors.z, 40.0f)/40.0f + 1.0f; + float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; if(CCoronas::aCoronas[i].id == SUN_CORE) spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); @@ -320,7 +320,7 @@ CCoronas::Render(void) float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; float hscale = 0.35f - (wscale - 0.5f) * 0.06f; - hscale = max(hscale, 0.15f); + hscale = Max(hscale, 0.15f); CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, spritew * aCoronas[i].size * wscale, @@ -467,7 +467,7 @@ CCoronas::RenderReflections(void) float spritew, spriteh; if(CSprite::CalcScreenCoors(coors, spriteCoors, &spritew, &spriteh, true)){ float drawDist = 0.75f * aCoronas[i].drawDist; - drawDist = min(drawDist, 50.0f); + drawDist = Min(drawDist, 50.0f); if(spriteCoors.z < drawDist){ float fadeDistance = drawDist / 2.0f; float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; @@ -546,25 +546,25 @@ CRegisteredCorona::Update(void) (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ // Corona is blocked, fade out - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else if(offScreen){ // Same when off screen - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else{ // Visible if(alpha > fadeAlpha){ // fade in - fadeAlpha = min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); if(CCoronas::bChangeBrightnessImmediately) fadeAlpha = alpha; }else if(alpha < fadeAlpha){ // too visible, decrease alpha but not below alpha - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); } // darken scene when the sun is visible if(id == CCoronas::SUN_CORONA) - CCoronas::LightsMult = max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); + CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); } // remove if invisible diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp index cd83a898..85d7ba13 100644 --- a/src/render/Lights.cpp +++ b/src/render/Lights.cpp @@ -37,9 +37,9 @@ SetLightsWithTimeOfDayColour(RpWorld *) AmbientLightColourForFrame.green = 1.0f; AmbientLightColourForFrame.blue = 1.0f; } - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame.red*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame.green*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame.blue*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame.red*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame.green*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame.blue*1.3f); RpLightSetColor(pAmbient, &AmbientLightColourForFrame); } @@ -70,16 +70,16 @@ SetLightsWithTimeOfDayColour(RpWorld *) float f1 = 2.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; float f2 = 3.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - AmbientLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f2); - AmbientLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f2); - AmbientLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f2); - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); + AmbientLightColourForFrame.red = Min(1.0f, AmbientLightColourForFrame.red * f2); + AmbientLightColourForFrame.green = Min(1.0f, AmbientLightColourForFrame.green * f2); + AmbientLightColourForFrame.blue = Min(1.0f, AmbientLightColourForFrame.blue * f2); + AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); #ifdef FIX_BUGS - DirectionalLightColourForFrame.red = min(1.0f, DirectionalLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = min(1.0f, DirectionalLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = min(1.0f, DirectionalLightColourForFrame.blue * f1); + DirectionalLightColourForFrame.red = Min(1.0f, DirectionalLightColourForFrame.red * f1); + DirectionalLightColourForFrame.green = Min(1.0f, DirectionalLightColourForFrame.green * f1); + DirectionalLightColourForFrame.blue = Min(1.0f, DirectionalLightColourForFrame.blue * f1); #else DirectionalLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f1); DirectionalLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f1); @@ -193,7 +193,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwRGBAReal color; RwV3d *dir; - strength = max(max(red, green), blue); + strength = Max(Max(red, green), blue); n = -1; if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) n = NumExtraDirLightsInWorld; @@ -221,7 +221,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); LightStrengths[n] = strength; - NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); + NumExtraDirLightsInWorld = Min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); } void diff --git a/src/render/ParticleMgr.cpp b/src/render/ParticleMgr.cpp index 7a1804de..9381787c 100644 --- a/src/render/ParticleMgr.cpp +++ b/src/render/ParticleMgr.cpp @@ -91,7 +91,7 @@ void cParticleSystemMgr::LoadParticleData() break; case CFG_PARAM_INITIAL_COLOR_VARIATION: - entry->m_InitialColorVariation = min(atoi(value), 100); + entry->m_InitialColorVariation = Min(atoi(value), 100); break; case CFG_PARAM_FADE_DESTINATION_COLOR_R: diff --git a/src/render/PointLights.cpp b/src/render/PointLights.cpp index a015ec54..8e942ce6 100644 --- a/src/render/PointLights.cpp +++ b/src/render/PointLights.cpp @@ -98,7 +98,7 @@ CPointLights::GenerateLightsAffectingObject(CVector *objCoors) if(aLights[i].type == LIGHT_DIRECTIONAL){ float dot = -DotProduct(dir, aLights[i].dir); - intensity *= max((dot-0.5f)*2.0f, 0.0f); + intensity *= Max((dot-0.5f)*2.0f, 0.0f); } if(intensity > 0.0f) diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index ccdc457c..b5147f02 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -4,7 +4,7 @@ #include "TxdStore.h" #include "Timer.h" #include "Camera.h" -#include "TimeCycle.h" +#include "Timecycle.h" #include "CutsceneMgr.h" #include "Automobile.h" #include "Ped.h" @@ -727,10 +727,10 @@ CShadows::RenderStoredShadows(void) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -873,10 +873,10 @@ CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -1016,11 +1016,11 @@ CShadows::CastShadowEntity(CEntity *pEntity, float fStartX, float fStartY, floa Points[3].x = (fLengthRight - fFrontRight) - fSideRight; Points[3].y = (fLengthForward - fFrontForward) - fSideForward; - float MinX = min(min(Points[0].x, Points[1].x), min(Points[2].x, Points[3].x)); - float MaxX = max(max(Points[0].x, Points[1].x), max(Points[2].x, Points[3].x)); + float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); + float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); - float MinY = min(min(Points[0].y, Points[1].y), min(Points[2].y, Points[3].y)); - float MaxY = max(max(Points[0].y, Points[1].y), max(Points[2].y, Points[3].y)); + float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); + float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); float MaxZ = pPosn->z - pEntity->GetPosition().z; float MinZ = MaxZ - fZDistance; @@ -1767,7 +1767,7 @@ CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTextur { ASSERT(pPosn != NULL); - C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, max(fFrontX, -fSideY), + C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, Max(fFrontX, -fSideY), 0, 128, 255, 128, 2048, 0.2f, 0); } diff --git a/src/render/Timecycle.cpp b/src/render/Timecycle.cpp index 7ab3e91e..0113c001 100644 --- a/src/render/Timecycle.cpp +++ b/src/render/Timecycle.cpp @@ -290,7 +290,7 @@ CTimeCycle::Update(void) TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL); if(m_FogReduction != 0) - m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); + m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; @@ -311,9 +311,9 @@ CTimeCycle::Update(void) if(TheCamera.GetForward().z < -0.9f || !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) - m_FogReduction = min(m_FogReduction+1, 64); + m_FogReduction = Min(m_FogReduction+1, 64); else - m_FogReduction = max(m_FogReduction-1, 0); + m_FogReduction = Max(m_FogReduction-1, 0); } STARTPATCHES diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index 48e8f83b..c711c8c8 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -9,7 +9,7 @@ #include "Boat.h" #include "World.h" #include "General.h" -#include "TimeCycle.h" +#include "Timecycle.h" #include "ZoneCull.h" #include "Clock.h" #include "Particle.h" @@ -979,7 +979,7 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col SMALL_SECTOR_SIZE / 2, apBoatList) ) { - float fWakeColor = fAdd1 - max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); + float fWakeColor = fAdd1 - Max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); RpGeometry *geom = apGeomArray[nGeomUsed++]; @@ -1035,9 +1035,9 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col RwRGBAAssign(&wakeColor, &color); - wakeColor.red = min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); - wakeColor.green = min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); - wakeColor.blue = min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); + wakeColor.red = Min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); + wakeColor.green = Min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); + wakeColor.blue = Min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); RwRGBAAssign(&geomPreLights[9*i+j], &wakeColor); @@ -1114,7 +1114,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) fSectorY + SMALL_SECTOR_SIZE - fY ); - fDistSqr = min(vecDist.MagnitudeSqr(), fDistSqr); + fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); } } } diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 581b5815..0fe59cd0 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -7,9 +7,13 @@ #include "ModelIndices.h" #include "VisibilityPlugins.h" #include "DMAudio.h" +<<<<<<< HEAD #include "Clock.h" #include "TimeCycle.h" #include "ZoneCull.h" +======= +#include "Timecycle.h" +>>>>>>> More audio ped #include "Camera.h" #include "Darkel.h" #include "Rubbish.h" @@ -691,7 +695,7 @@ CAutomobile::ProcessControl(void) if(m_aSuspensionSpringRatio[i] < 1.0f) m_aWheelTimer[i] = 4.0f; else - m_aWheelTimer[i] = max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); + m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); if(m_aWheelTimer[i] > 0.0f){ m_nWheelsOnGround++; @@ -1009,7 +1013,7 @@ CAutomobile::ProcessControl(void) if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) - m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.0005f, 0.0f); + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ FlyingControl(FLIGHT_MODEL_DODO); @@ -1017,7 +1021,7 @@ CAutomobile::ProcessControl(void) FlyingControl(FLIGHT_MODEL_HELI); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ if(CPad::GetPad(0)->GetCircleJustDown()) - m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.03f, 0.0f); + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); if(m_aWheelSpeed[0] < 0.22f) m_aWheelSpeed[0] += 0.0001f; if(m_aWheelSpeed[0] > 0.15f) @@ -1129,10 +1133,10 @@ CAutomobile::ProcessControl(void) if(speed > sq(0.1f)){ speed = Sqrt(speed); if(suspShake > 0.0f){ - uint8 freq = min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); }else{ - uint8 freq = min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); + uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); } } @@ -2586,7 +2590,7 @@ CAutomobile::HydraulicControl(void) float minz = pos.z + extendedLowerLimit - wheelRadius; if(minz < specialColModel->boundingBox.min.z) specialColModel->boundingBox.min.z = minz; - float radius = max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); + float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); if(specialColModel->boundingSphere.radius < radius) specialColModel->boundingSphere.radius = radius; @@ -2685,10 +2689,10 @@ CAutomobile::HydraulicControl(void) float front = -rear; float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; float left = -right; - suspChange[CARWHEEL_FRONT_LEFT] = max(front+left, 0.0f); - suspChange[CARWHEEL_REAR_LEFT] = max(rear+left, 0.0f); - suspChange[CARWHEEL_FRONT_RIGHT] = max(front+right, 0.0f); - suspChange[CARWHEEL_REAR_RIGHT] = max(rear+right, 0.0f); + suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); + suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); + suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); + suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); if(m_hydraulicState < 100){ // Lowered, move wheels up @@ -2804,7 +2808,7 @@ CAutomobile::ProcessBuoyancy(void) ApplyTurnForce(impulse, point); CVector initialSpeed = m_vecMoveSpeed; - float timeStep = max(CTimer::GetTimeStep(), 0.01f); + float timeStep = Max(CTimer::GetTimeStep(), 0.01f); float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); m_vecMoveSpeed *= waterResistance; @@ -2897,7 +2901,7 @@ CAutomobile::ProcessBuoyancy(void) float fSpeed = vSpeed.MagnitudeSqr(); if(fSpeed > sq(0.05f)){ fSpeed = Sqrt(fSpeed); - float size = min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); + float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; CParticle::AddParticle(PARTICLE_PED_SPLASH, @@ -2979,11 +2983,11 @@ CAutomobile::DoDriveByShootings(void) // TODO: what is this? if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ - m_weaponDoorTimerLeft = max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); } if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ - m_weaponDoorTimerRight = max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); } } @@ -3131,7 +3135,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) FindPlayerPed()->SetWantedLevelNoDrop(1); if(m_status == STATUS_PLAYER && impulse > 50.0f){ - uint8 freq = min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(40000/freq, freq); } @@ -3284,7 +3288,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; - money = min(money, 40); + money = Min(money, 40); if(money > 2){ sprintf(gString, "$%d", money); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; @@ -3987,7 +3991,7 @@ CAutomobile::SetupSuspensionLines(void) // adjust col model to include suspension lines if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) colModel->boundingBox.min.z = colModel->lines[0].p1.z; - float radius = max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); + float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); if(colModel->boundingSphere.radius < radius) colModel->boundingSphere.radius = radius; @@ -4479,8 +4483,16 @@ CAutomobile::SetAllTaxiLights(bool set) class CAutomobile_ : public CAutomobile { public: +<<<<<<< HEAD +<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CAutomobile(id, CreatedBy); } void dtor() { CAutomobile::~CAutomobile(); } +======= + void dtor() { this->~CAutomobile(); } +>>>>>>> More audio ped +======= + void dtor() { CAutomobile::~CAutomobile(); } +>>>>>>> fix void SetModelIndex_(uint32 id) { CAutomobile::SetModelIndex(id); } void ProcessControl_(void) { CAutomobile::ProcessControl(); } void Teleport_(CVector v) { CAutomobile::Teleport(v); } diff --git a/src/vehicles/Automobile.cpp.autosave b/src/vehicles/Automobile.cpp.autosave new file mode 100644 index 00000000..140633b8 --- /dev/null +++ b/src/vehicles/Automobile.cpp.autosave @@ -0,0 +1,4560 @@ +#include "common.h" +#include "main.h" +#include "patcher.h" +#include "General.h" +#include "RwHelper.h" +#include "Pad.h" +#include "ModelIndices.h" +#include "VisibilityPlugins.h" +#include "DMAudio.h" +#include "Clock.h" +#include "Timecycle.h" +#include "ZoneCull.h" +#include "Camera.h" +#include "Darkel.h" +#include "Rubbish.h" +#include "Fire.h" +#include "Explosion.h" +#include "Particle.h" +#include "ParticleObject.h" +#include "Antennas.h" +#include "Skidmarks.h" +#include "Shadows.h" +#include "PointLights.h" +#include "Coronas.h" +#include "SpecialFX.h" +#include "WaterCannon.h" +#include "WaterLevel.h" +#include "Floater.h" +#include "World.h" +#include "SurfaceTable.h" +#include "Weather.h" +#include "HandlingMgr.h" +#include "Record.h" +#include "Remote.h" +#include "Population.h" +#include "CarCtrl.h" +#include "CarAI.h" +#include "Garages.h" +#include "PathFind.h" +#include "AnimManager.h" +#include "RpAnimBlend.h" +#include "Ped.h" +#include "PlayerPed.h" +#include "Object.h" +#include "Automobile.h" + +bool bAllCarCheat; // unused + +RwObject *GetCurrentAtomicObjectCB(RwObject *object, void *data); + +bool &CAutomobile::m_sAllTaxiLights = *(bool*)0x95CD21; + +CAutomobile::CAutomobile(int32 id, uint8 CreatedBy) + : CVehicle(CreatedBy) +{ + int i; + + m_vehType = VEHICLE_TYPE_CAR; + + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); + m_fFireBlowUpTimer = 0.0f; + field_4E0 = 0; + bTaxiLight = m_sAllTaxiLights; + m_auto_flagA20 = false; + m_auto_flagA40 = false; + bWaterTight = false; + + SetModelIndex(id); + + pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + + field_49C = 20.0f; + field_4D8 = 0; + + mi->ChooseVehicleColour(m_currentColour1, m_currentColour2); + + bIsVan = !!(pHandling->Flags & HANDLING_IS_VAN); + bIsBig = !!(pHandling->Flags & HANDLING_IS_BIG); + bIsBus = !!(pHandling->Flags & HANDLING_IS_BUS); + bLowVehicle = !!(pHandling->Flags & HANDLING_IS_LOW); + + // Doors + if(bIsBus){ + Doors[DOOR_FRONT_LEFT].Init(-HALFPI, 0.0f, 0, 2); + Doors[DOOR_FRONT_RIGHT].Init(0.0f, HALFPI, 1, 2); + }else{ + Doors[DOOR_FRONT_LEFT].Init(-PI*0.4f, 0.0f, 0, 2); + Doors[DOOR_FRONT_RIGHT].Init(0.0f, PI*0.4f, 1, 2); + } + if(bIsVan){ + Doors[DOOR_REAR_LEFT].Init(-HALFPI, 0.0f, 1, 2); + Doors[DOOR_REAR_RIGHT].Init(0.0f, HALFPI, 0, 2); + }else{ + Doors[DOOR_REAR_LEFT].Init(-PI*0.4f, 0.0f, 0, 2); + Doors[DOOR_REAR_RIGHT].Init(0.0f, PI*0.4f, 1, 2); + } + if(pHandling->Flags & HANDLING_REV_BONNET) + Doors[DOOR_BONNET].Init(-PI*0.3f, 0.0f, 1, 0); + else + Doors[DOOR_BONNET].Init(0.0f, PI*0.3f, 1, 0); + if(pHandling->Flags & HANDLING_HANGING_BOOT) + Doors[DOOR_BOOT].Init(PI*0.4f, 0.0f, 0, 0); + else if(pHandling->Flags & HANDLING_TAILGATE_BOOT) + Doors[DOOR_BOOT].Init(0.0, HALFPI, 1, 0); + else + Doors[DOOR_BOOT].Init(-PI*0.3f, 0.0f, 1, 0); + if(pHandling->Flags & HANDLING_NO_DOORS){ + Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_REAR_LEFT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_REAR_RIGHT, DOOR_STATUS_MISSING); + } + + for(i = 0; i < 6; i++) + m_randomValues[i] = CGeneral::GetRandomNumberInRange(-0.15f, 0.15f); + + m_fMass = pHandling->fMass; + m_fTurnMass = pHandling->fTurnMass; + m_vecCentreOfMass = pHandling->CentreOfMass; + m_fAirResistance = pHandling->Dimension.x*pHandling->Dimension.z/m_fMass; + m_fElasticity = 0.05f; + m_fBuoyancy = pHandling->fBuoyancy; + + m_nBusDoorTimerEnd = 0; + m_nBusDoorTimerStart = 0; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_fBrakePedal = 0.0f; + m_pSetOnFireEntity = nil; + field_594 = 0; + bNotDamagedUpsideDown = false; + bMoreResistantToDamage = false; + m_fVelocityChangeForAudio = 0.0f; + m_hydraulicState = 0; + + for(i = 0; i < 4; i++){ + m_aGroundPhysical[i] = nil; + m_aGroundOffset[i] = CVector(0.0f, 0.0f, 0.0f); + m_aSuspensionSpringRatio[i] = 1.0f; + m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i]; + m_aWheelTimer[i] = 0.0f; + m_aWheelRotation[i] = 0.0f; + m_aWheelSpeed[i] = 0.0f; + m_aWheelState[i] = WHEEL_STATE_NORMAL; + m_aWheelSkidmarkMuddy[i] = false; + m_aWheelSkidmarkBloody[i] = false; + } + + m_nWheelsOnGround = 0; + m_nDriveWheelsOnGround = 0; + m_nDriveWheelsOnGroundPrev = 0; + m_fHeightAboveRoad = 0.0f; + m_fTraction = 1.0f; + + CColModel *colModel = mi->GetColModel(); + if(colModel->lines == nil){ + colModel->lines = (CColLine*)RwMalloc(4*sizeof(CColLine)); + colModel->numLines = 4; + } + + SetupSuspensionLines(); + + m_status = STATUS_SIMPLE; + bUseCollisionRecords = true; + + m_nNumPassengers = 0; + + m_bombType = CARBOMB_NONE; + bHadDriver = false; + m_pBombRigger = nil; + + if(m_nDoorLock == CARLOCK_UNLOCKED && + (id == MI_POLICE || id == MI_ENFORCER || id == MI_RHINO)) + m_nDoorLock = CARLOCK_LOCKED_INITIALLY; + + m_fCarGunLR = 0.0f; + m_fCarGunUD = 0.05f; + m_fPropellerRotation = 0.0f; + m_weaponDoorTimerLeft = 0.0f; + m_weaponDoorTimerRight = m_weaponDoorTimerLeft; + + if(GetModelIndex() == MI_DODO){ + RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LF]), 0); + CMatrix mat1; + mat1.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + CMatrix mat2(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); + mat1.GetPosition() += CVector(mat2.GetPosition().x + 0.1f, 0.0f, mat2.GetPosition().z); + mat1.UpdateRW(); + }else if(GetModelIndex() == MI_MIAMI_SPARROW || GetModelIndex() == MI_MIAMI_RCRAIDER){ + RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LF]), 0); + RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_RF]), 0); + RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LB]), 0); + RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_RB]), 0); + }else if(GetModelIndex() == MI_RHINO){ + bExplosionProof = true; + bBulletProof = true; + } +} + + +void +CAutomobile::SetModelIndex(uint32 id) +{ + CVehicle::SetModelIndex(id); + SetupModelNodes(); +} + +CVector vecDAMAGE_ENGINE_POS_SMALL(-0.1f, -0.1f, 0.0f); +CVector vecDAMAGE_ENGINE_POS_BIG(-0.5f, -0.3f, 0.0f); + +void +CAutomobile::ProcessControl(void) +{ + int i; + CColModel *colModel; + + if(bUsingSpecialColModel) + colModel = &CWorld::Players[CWorld::PlayerInFocus].m_ColModel; + else + colModel = GetColModel(); + bWarnedPeds = false; + + // skip if the collision isn't for the current level + if(colModel->level > LEVEL_NONE && colModel->level != CCollision::ms_collisionInMemory) + return; + + // Improve grip of vehicles in certain cases + bool strongGrip1 = false; + bool strongGrip2 = false; + if(FindPlayerVehicle() && this != FindPlayerVehicle()){ + switch(AutoPilot.m_nCarMission){ + case MISSION_RAMPLAYER_FARAWAY: + case MISSION_RAMPLAYER_CLOSE: + case MISSION_BLOCKPLAYER_FARAWAY: + case MISSION_BLOCKPLAYER_CLOSE: + if(FindPlayerSpeed().Magnitude() > 0.3f){ + strongGrip1 = true; + if(FindPlayerSpeed().Magnitude() > 0.4f){ + if(m_vecMoveSpeed.Magnitude() < 0.3f) + strongGrip2 = true; + }else{ + if((GetPosition() - FindPlayerCoors()).Magnitude() > 50.0f) + strongGrip2 = true; + } + } + } + } + + if(bIsBus) + ProcessAutoBusDoors(); + + ProcessCarAlarm(); + + // Scan if this car is committing a crime that the police can see + if(m_status != STATUS_ABANDONED && m_status != STATUS_WRECKED && + m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PLAYER_DISABLED){ + switch(GetModelIndex()) + case MI_FBICAR: + case MI_POLICE: + case MI_ENFORCER: + case MI_SECURICA: + case MI_RHINO: + case MI_BARRACKS: + ScanForCrimes(); + } + + // Process driver + if(pDriver){ + if(!bHadDriver && m_bombType == CARBOMB_ONIGNITIONACTIVE){ + // If someone enters the car and there is a bomb, detonate + m_nBombTimer = 1000; + m_pBlowUpEntity = m_pBombRigger; + if(m_pBlowUpEntity) + m_pBlowUpEntity->RegisterReference((CEntity**)&m_pBlowUpEntity); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TICK, 1.0f); + } + bHadDriver = true; + + if(IsUpsideDown() && CanPedEnterCar()){ + if(!pDriver->IsPlayer() && + !(pDriver->m_leader && pDriver->m_leader->bInVehicle) && + pDriver->CharCreatedBy != MISSION_CHAR) + pDriver->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); + } + }else + bHadDriver = false; + + // Process passengers + if(m_nNumPassengers != 0 && IsUpsideDown() && CanPedEnterCar()){ + for(i = 0; i < m_nNumMaxPassengers; i++) + if(pPassengers[i]) + if(!pPassengers[i]->IsPlayer() && + !(pPassengers[i]->m_leader && pPassengers[i]->m_leader->bInVehicle) && + pPassengers[i]->CharCreatedBy != MISSION_CHAR) + pPassengers[i]->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); + } + + CRubbish::StirUp(this); + + // blend in clump + int clumpAlpha = CVisibilityPlugins::GetClumpAlpha((RpClump*)m_rwObject); + if(bFadeOut){ + clumpAlpha -= 8; + if(clumpAlpha < 0) + clumpAlpha = 0; + }else if(clumpAlpha < 255){ + clumpAlpha += 16; + if(clumpAlpha > 255) + clumpAlpha = 255; + } + CVisibilityPlugins::SetClumpAlpha((RpClump*)m_rwObject, clumpAlpha); + + AutoPilot.m_bSlowedDownBecauseOfCars = false; + AutoPilot.m_bSlowedDownBecauseOfPeds = false; + + // Set Center of Mass to make car more stable + if(strongGrip1 || bCheat3) + m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0*m_fHeightAboveRoad; + else if(pHandling->Flags & HANDLING_NONPLAYER_STABILISER && m_status == STATUS_PHYSICS) + m_vecCentreOfMass.z = pHandling->CentreOfMass.z - 0.2f*pHandling->Dimension.z; + else + m_vecCentreOfMass.z = pHandling->CentreOfMass.z; + + // Process depending on status + + bool playerRemote = false; + switch(m_status){ + case STATUS_PLAYER_REMOTE: + if(CPad::GetPad(0)->WeaponJustDown()){ + BlowUpCar(FindPlayerPed()); + CRemote::TakeRemoteControlledCarFromPlayer(); + } + + if(GetModelIndex() == MI_RCBANDIT){ + CVector pos = GetPosition(); + // FindPlayerCoors unused + if(RcbanditCheckHitWheels() || bIsInWater || CPopulation::IsPointInSafeZone(&pos)){ + if(CPopulation::IsPointInSafeZone(&pos)) + CGarages::TriggerMessage("HM2_5", -1, 5000, -1); + CRemote::TakeRemoteControlledCarFromPlayer(); + BlowUpCar(FindPlayerPed()); + } + } + + if(CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle == this) + playerRemote = true; + // fall through + case STATUS_PLAYER: + if(playerRemote || + pDriver && pDriver->GetPedState() != PED_EXIT_CAR && pDriver->GetPedState() != PED_DRAG_FROM_CAR){ + // process control input if controlled by player + if(playerRemote || pDriver->m_nPedType == PEDTYPE_PLAYER1) + ProcessControlInputs(0); + + PruneReferences(); + + if(m_status == STATUS_PLAYER && CRecordDataForChase::Status != RECORDSTATE_1) + DoDriveByShootings(); + } + break; + + case STATUS_SIMPLE: + CCarAI::UpdateCarAI(this); + CPhysical::ProcessControl(); + CCarCtrl::UpdateCarOnRails(this); + + m_nWheelsOnGround = 4; + m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround; + m_nDriveWheelsOnGround = 4; + + pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear); + + { + float wheelRot = ProcessWheelRotation(WHEEL_STATE_NORMAL, GetForward(), m_vecMoveSpeed, 0.35f); + for(i = 0; i < 4; i++) + m_aWheelRotation[i] += wheelRot; + } + + PlayHornIfNecessary(); + ReduceHornCounter(); + bVehicleColProcessed = false; + // that's all we do for simple vehicles + return; + + case STATUS_PHYSICS: + CCarAI::UpdateCarAI(this); + CCarCtrl::SteerAICarWithPhysics(this); + PlayHornIfNecessary(); + break; + + case STATUS_ABANDONED: + m_fBrakePedal = 0.2f; + bIsHandbrakeOn = false; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_nCarHornTimer = 0; + break; + + case STATUS_WRECKED: + m_fBrakePedal = 0.05f; + bIsHandbrakeOn = true; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_nCarHornTimer = 0; + break; + + case STATUS_PLAYER_DISABLED: + m_fBrakePedal = 1.0f; + bIsHandbrakeOn = true; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_nCarHornTimer = 0; + break; + } + + // what's going on here? + if(GetPosition().z < -0.6f && + Abs(m_vecMoveSpeed.x) < 0.05f && + Abs(m_vecMoveSpeed.y) < 0.05f) + m_vecTurnSpeed *= Pow(0.95f, CTimer::GetTimeStep()); + + // Skip physics if object is found to have been static recently + bool skipPhysics = false; + if(!bIsStuck && (m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED)){ + bool makeStatic = false; + float moveSpeedLimit, turnSpeedLimit, distanceLimit; + + if(!bVehicleColProcessed && + m_vecMoveSpeed.IsZero() && + // BUG? m_aSuspensionSpringRatioPrev[3] is checked twice in the game. also, why 3? + m_aSuspensionSpringRatioPrev[3] != 1.0f) + makeStatic = true; + + if(m_status == STATUS_WRECKED){ + moveSpeedLimit = 0.006f; + turnSpeedLimit = 0.0015f; + distanceLimit = 0.015f; + }else{ + moveSpeedLimit = 0.003f; + turnSpeedLimit = 0.0009f; + distanceLimit = 0.005f; + } + + m_vecMoveSpeedAvg = (m_vecMoveSpeedAvg + m_vecMoveSpeed)/2.0f; + m_vecTurnSpeedAvg = (m_vecTurnSpeedAvg + m_vecTurnSpeed)/2.0f; + + if(m_vecMoveSpeedAvg.MagnitudeSqr() <= sq(moveSpeedLimit*CTimer::GetTimeStep()) && + m_vecTurnSpeedAvg.MagnitudeSqr() <= sq(turnSpeedLimit*CTimer::GetTimeStep()) && + m_fDistanceTravelled < distanceLimit || + makeStatic){ + m_nStaticFrames++; + + if(m_nStaticFrames > 10 || makeStatic) + if(!CCarCtrl::MapCouldMoveInThisArea(GetPosition().x, GetPosition().y)){ + if(!makeStatic || m_nStaticFrames > 10) + m_nStaticFrames = 10; + + skipPhysics = true; + + m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + } + }else + m_nStaticFrames = 0; + } + + // Postpone + for(i = 0; i < 4; i++) + if(m_aGroundPhysical[i] && !CWorld::bForceProcessControl && m_aGroundPhysical[i]->bIsInSafePosition){ + bWasPostponed = true; + return; + } + + VehicleDamage(0.0f, 0); + + // special control + switch(GetModelIndex()){ + case MI_FIRETRUCK: + FireTruckControl(); + break; + case MI_RHINO: + TankControl(); + BlowUpCarsInPath(); + break; + case MI_YARDIE: + // beta also had esperanto here it seems + HydraulicControl(); + break; + default: + if(CVehicle::bCheat3){ + // Make vehicle jump when horn is sounded + if(m_status == STATUS_PLAYER && m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f) && + // BUG: game checks [0] four times, instead of all wheels + m_aSuspensionSpringRatio[0] < 1.0f && + CPad::GetPad(0)->HornJustDown()){ + + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, 1.0f); + + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, + m_aWheelColPoints[0].point + 0.5f*GetUp(), + 1.3f*m_vecMoveSpeed, nil, 2.5f); + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, + m_aWheelColPoints[0].point + 0.5f*GetUp(), + 1.2f*m_vecMoveSpeed, nil, 2.0f); + + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, + m_aWheelColPoints[2].point + 0.5f*GetUp(), + 1.3f*m_vecMoveSpeed, nil, 2.5f); + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, + m_aWheelColPoints[2].point + 0.5f*GetUp(), + 1.2f*m_vecMoveSpeed, nil, 2.0f); + + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, + m_aWheelColPoints[0].point + 0.5f*GetUp() - GetForward(), + 1.3f*m_vecMoveSpeed, nil, 2.5f); + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, + m_aWheelColPoints[0].point + 0.5f*GetUp() - GetForward(), + 1.2f*m_vecMoveSpeed, nil, 2.0f); + + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, + m_aWheelColPoints[2].point + 0.5f*GetUp() - GetForward(), + 1.3f*m_vecMoveSpeed, nil, 2.5f); + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, + m_aWheelColPoints[2].point + 0.5f*GetUp() - GetForward(), + 1.2f*m_vecMoveSpeed, nil, 2.0f); + + ApplyMoveForce(CVector(0.0f, 0.0f, 1.0f)*m_fMass*0.4f); + ApplyTurnForce(GetUp()*m_fMass*0.035f, GetForward()*1.0f); + } + } + break; + } + + float brake; + if(skipPhysics){ + bHasContacted = false; + bIsInSafePosition = false; + bWasPostponed = false; + bHasHitWall = false; + m_nCollisionRecords = 0; + bHasCollided = false; + bVehicleColProcessed = false; + m_nDamagePieceType = 0; + m_fDamageImpulse = 0.0f; + m_pDamageEntity = nil; + m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); + m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); + }else{ + + // This has to be done if ProcessEntityCollision wasn't called + if(!bVehicleColProcessed){ + CMatrix mat(GetMatrix()); + bIsStuck = false; + bHasContacted = false; + bIsInSafePosition = false; + bWasPostponed = false; + bHasHitWall = false; + m_fDistanceTravelled = 0.0f; + field_EF = false; + m_phy_flagA80 = false; + ApplyMoveSpeed(); + ApplyTurnSpeed(); + for(i = 0; CheckCollision() && i < 5; i++){ + GetMatrix() = mat; + ApplyMoveSpeed(); + ApplyTurnSpeed(); + } + bIsInSafePosition = true; + bIsStuck = false; + } + + CPhysical::ProcessControl(); + + ProcessBuoyancy(); + + // Rescale spring ratios, i.e. subtract wheel radius + for(i = 0; i < 4; i++){ + // wheel radius in relation to suspension line + float wheelRadius = 1.0f - m_aSuspensionSpringLength[i]/m_aSuspensionLineLength[i]; + // rescale such that 0.0 is fully compressed and 1.0 is fully extended + m_aSuspensionSpringRatio[i] = (m_aSuspensionSpringRatio[i]-wheelRadius)/(1.0f-wheelRadius); + } + + float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()); + CVector contactPoints[4]; // relative to model + CVector contactSpeeds[4]; // speed at contact points + CVector springDirections[4]; // normalized, in model space + + for(i = 0; i < 4; i++){ + // Set spring under certain circumstances + if(Damage.GetWheelStatus(i) == WHEEL_STATUS_MISSING) + m_aSuspensionSpringRatio[i] = 1.0f; + else if(Damage.GetWheelStatus(i) == WHEEL_STATUS_BURST){ + // wheel more bumpy the faster we are + if(CGeneral::GetRandomNumberInRange(0, (uint16)(40*fwdSpeed) + 98) < 100){ + m_aSuspensionSpringRatio[i] += 0.3f*(m_aSuspensionLineLength[i]-m_aSuspensionSpringLength[i])/m_aSuspensionSpringLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + } + + // get points and directions if spring is compressed + if(m_aSuspensionSpringRatio[i] < 1.0f){ + contactPoints[i] = m_aWheelColPoints[i].point - GetPosition(); + springDirections[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1 - colModel->lines[i].p0); + springDirections[i].Normalise(); + } + } + + // Make springs push up vehicle + for(i = 0; i < 4; i++){ + if(m_aSuspensionSpringRatio[i] < 1.0f){ + float bias = pHandling->fSuspensionBias; + if(i == 1 || i == 3) // rear + bias = 1.0f - bias; + + ApplySpringCollision(pHandling->fSuspensionForceLevel, + springDirections[i], contactPoints[i], + m_aSuspensionSpringRatio[i], bias); + m_aWheelSkidmarkMuddy[i] = + m_aWheelColPoints[i].surfaceB == SURFACE_GRASS || + m_aWheelColPoints[i].surfaceB == SURFACE_DIRTTRACK || + m_aWheelColPoints[i].surfaceB == SURFACE_SAND; + }else{ + contactPoints[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1); + } + } + + // Get speed at contact points + for(i = 0; i < 4; i++){ + contactSpeeds[i] = GetSpeed(contactPoints[i]); + if(m_aGroundPhysical[i]){ + // subtract movement of physical we're standing on + contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]); +#ifndef FIX_BUGS + // this shouldn't be reset because we still need it below + m_aGroundPhysical[i] = nil; +#endif + } + } + + // dampen springs + for(i = 0; i < 4; i++) + if(m_aSuspensionSpringRatio[i] < 1.0f) + ApplySpringDampening(pHandling->fSuspensionDampingLevel, + springDirections[i], contactPoints[i], contactSpeeds[i]); + + // Get speed at contact points again + for(i = 0; i < 4; i++){ + contactSpeeds[i] = GetSpeed(contactPoints[i]); + if(m_aGroundPhysical[i]){ + // subtract movement of physical we're standing on + contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]); + m_aGroundPhysical[i] = nil; + } + } + + + bool gripCheat = true; + fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()); + if(!strongGrip1 && !CVehicle::bCheat3) + gripCheat = false; + float acceleration = pHandling->Transmission.CalculateDriveAcceleration(m_fGasPedal, m_nCurrentGear, m_fChangeGearTime, fwdSpeed, gripCheat); + acceleration /= fForceMultiplier; + + // unused + if(GetModelIndex() == MI_MIAMI_RCBARON || + GetModelIndex() == MI_MIAMI_RCRAIDER || + GetModelIndex() == MI_MIAMI_SPARROW) + acceleration = 0.0f; + + brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep(); + bool neutralHandling = !!(pHandling->Flags & HANDLING_NEUTRALHANDLING); + float brakeBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias; + float brakeBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fBrakeBias); + float tractionBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias; + float tractionBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fTractionBias); + + // Count how many wheels are touching the ground + + m_nWheelsOnGround = 0; + m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround; + m_nDriveWheelsOnGround = 0; + + for(i = 0; i < 4; i++){ + if(m_aSuspensionSpringRatio[i] < 1.0f) + m_aWheelTimer[i] = 4.0f; + else + m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); + + if(m_aWheelTimer[i] > 0.0f){ + m_nWheelsOnGround++; + switch(pHandling->Transmission.nDriveType){ + case '4': + m_nDriveWheelsOnGround++; + break; + case 'F': + if(i == CARWHEEL_FRONT_LEFT || i == CARWHEEL_FRONT_RIGHT) + m_nDriveWheelsOnGround++; + break; + case 'R': + if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT) + m_nDriveWheelsOnGround++; + break; + } + } + } + + float traction; + if(m_status == STATUS_PHYSICS) + traction = 0.004f * m_fTraction; + else + traction = 0.004f; + traction *= pHandling->fTractionMultiplier / 4.0f; + traction /= fForceMultiplier; + if(CVehicle::bCheat3) + traction *= 4.0f; + + if(FindPlayerVehicle() && FindPlayerVehicle() == this){ + if(CPad::GetPad(0)->WeaponJustDown()){ + if(m_bombType == CARBOMB_TIMED){ + m_bombType = CARBOMB_TIMEDACTIVE; + m_nBombTimer = 7000; + m_pBlowUpEntity = FindPlayerPed(); + CGarages::TriggerMessage("GA_12", -1, 3000, -1); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TIMED_ACTIVATED, 1.0f); + }else if(m_bombType == CARBOMB_ONIGNITION){ + m_bombType = CARBOMB_ONIGNITIONACTIVE; + CGarages::TriggerMessage("GA_12", -1, 3000, -1); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_ONIGNITION_ACTIVATED, 1.0f); + } + } + }else if(strongGrip1 || CVehicle::bCheat3){ + traction *= 1.2f; + acceleration *= 1.4f; + if(strongGrip2 || CVehicle::bCheat3){ + traction *= 1.3f; + acceleration *= 1.4f; + } + } + + static float fThrust; + static tWheelState WheelState[4]; + + // Process front wheels on ground + + if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){ + float s = Sin(m_fSteerAngle); + float c = Cos(m_fSteerAngle); + CVector wheelFwd = Multiply3x3(GetMatrix(), CVector(-s, c, 0.0f)); + CVector wheelRight = Multiply3x3(GetMatrix(), CVector(c, s, 0.0f)); + + if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f){ + if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)) + fThrust = 0.0f; + else + fThrust = acceleration; + + m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceA = SURFACE_RUBBER29; + float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_LEFT])*traction; + if(m_status == STATUS_PLAYER) + adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB); + WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT]; + + if(Damage.GetWheelStatus(VEHWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasFront, + adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect, + CARWHEEL_FRONT_LEFT, + &m_aWheelSpeed[CARWHEEL_FRONT_LEFT], + &WheelState[CARWHEEL_FRONT_LEFT], + WHEEL_STATUS_BURST); + else + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasFront, + adhesion*tractionBiasFront, + CARWHEEL_FRONT_LEFT, + &m_aWheelSpeed[CARWHEEL_FRONT_LEFT], + &WheelState[CARWHEEL_FRONT_LEFT], + WHEEL_STATUS_OK); + } + + if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){ + if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)) + fThrust = 0.0f; + else + fThrust = acceleration; + + m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceA = SURFACE_RUBBER29; + float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT])*traction; + if(m_status == STATUS_PLAYER) + adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB); + WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT]; + + if(Damage.GetWheelStatus(VEHWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasFront, + adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect, + CARWHEEL_FRONT_RIGHT, + &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT], + &WheelState[CARWHEEL_FRONT_RIGHT], + WHEEL_STATUS_BURST); + else + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasFront, + adhesion*tractionBiasFront, + CARWHEEL_FRONT_RIGHT, + &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT], + &WheelState[CARWHEEL_FRONT_RIGHT], + WHEEL_STATUS_OK); + } + } + + // Process front wheels off ground + + if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] <= 0.0f){ + if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + m_aWheelSpeed[CARWHEEL_FRONT_LEFT] *= 0.95f; + else{ + if(acceleration > 0.0f){ + if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] < 2.0f) + m_aWheelSpeed[CARWHEEL_FRONT_LEFT] -= 0.2f; + }else{ + if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] > -2.0f) + m_aWheelSpeed[CARWHEEL_FRONT_LEFT] += 0.1f; + } + } + m_aWheelRotation[CARWHEEL_FRONT_LEFT] += m_aWheelSpeed[CARWHEEL_FRONT_LEFT]; + } + if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] <= 0.0f){ + if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] *= 0.95f; + else{ + if(acceleration > 0.0f){ + if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] < 2.0f) + m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] -= 0.2f; + }else{ + if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] > -2.0f) + m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] += 0.1f; + } + } + m_aWheelRotation[CARWHEEL_FRONT_RIGHT] += m_aWheelSpeed[CARWHEEL_FRONT_RIGHT]; + } + + // Process rear wheels + + if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ + CVector wheelFwd = GetForward(); + CVector wheelRight = GetRight(); + + if(bIsHandbrakeOn) + brake = 20000.0f; + + if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f){ + if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier)) + fThrust = 0.0f; + else + fThrust = acceleration; + + m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceA = SURFACE_RUBBER29; + float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_LEFT])*traction; + if(m_status == STATUS_PLAYER) + adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB); + WheelState[CARWHEEL_REAR_LEFT] = m_aWheelState[CARWHEEL_REAR_LEFT]; + + if(Damage.GetWheelStatus(VEHWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasRear, + adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect, + CARWHEEL_REAR_LEFT, + &m_aWheelSpeed[CARWHEEL_REAR_LEFT], + &WheelState[CARWHEEL_REAR_LEFT], + WHEEL_STATUS_BURST); + else + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasRear, + adhesion*tractionBiasRear, + CARWHEEL_REAR_LEFT, + &m_aWheelSpeed[CARWHEEL_REAR_LEFT], + &WheelState[CARWHEEL_REAR_LEFT], + WHEEL_STATUS_OK); + } + + if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ + if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier)) + fThrust = 0.0f; + else + fThrust = acceleration; + + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceA = SURFACE_RUBBER29; + float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_RIGHT])*traction; + if(m_status == STATUS_PLAYER) + adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB); + WheelState[CARWHEEL_REAR_RIGHT] = m_aWheelState[CARWHEEL_REAR_RIGHT]; + + if(Damage.GetWheelStatus(VEHWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasRear, + adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect, + CARWHEEL_REAR_RIGHT, + &m_aWheelSpeed[CARWHEEL_REAR_RIGHT], + &WheelState[CARWHEEL_REAR_RIGHT], + WHEEL_STATUS_BURST); + else + ProcessWheel(wheelFwd, wheelRight, + contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT], + m_nWheelsOnGround, fThrust, + brake*brakeBiasRear, + adhesion*tractionBiasRear, + CARWHEEL_REAR_RIGHT, + &m_aWheelSpeed[CARWHEEL_REAR_RIGHT], + &WheelState[CARWHEEL_REAR_RIGHT], + WHEEL_STATUS_OK); + } + } + + // Process rear wheels off ground + + if(m_aWheelTimer[CARWHEEL_REAR_LEFT] <= 0.0f){ + if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + m_aWheelSpeed[CARWHEEL_REAR_LEFT] *= 0.95f; + else{ + if(acceleration > 0.0f){ + if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] < 2.0f) + m_aWheelSpeed[CARWHEEL_REAR_LEFT] -= 0.2f; + }else{ + if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] > -2.0f) + m_aWheelSpeed[CARWHEEL_REAR_LEFT] += 0.1f; + } + } + m_aWheelRotation[CARWHEEL_REAR_LEFT] += m_aWheelSpeed[CARWHEEL_REAR_LEFT]; + } + if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] <= 0.0f){ + if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + m_aWheelSpeed[CARWHEEL_REAR_RIGHT] *= 0.95f; + else{ + if(acceleration > 0.0f){ + if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] < 2.0f) + m_aWheelSpeed[CARWHEEL_REAR_RIGHT] -= 0.2f; + }else{ + if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] > -2.0f) + m_aWheelSpeed[CARWHEEL_REAR_RIGHT] += 0.1f; + } + } + m_aWheelRotation[CARWHEEL_REAR_RIGHT] += m_aWheelSpeed[CARWHEEL_REAR_RIGHT]; + } + + for(i = 0; i < 4; i++){ + float wheelPos = colModel->lines[i].p0.z; + if(m_aSuspensionSpringRatio[i] > 0.0f) + wheelPos -= m_aSuspensionSpringRatio[i]*m_aSuspensionSpringLength[i]; + m_aWheelPosition[i] += (wheelPos - m_aWheelPosition[i])*0.75f; + } + for(i = 0; i < 4; i++) + m_aWheelState[i] = WheelState[i]; + + // Process horn + + if(m_status != STATUS_PLAYER){ + ReduceHornCounter(); + }else{ + if(GetModelIndex() == MI_MRWHOOP){ + if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory] && + !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5]){ + m_bSirenOrAlarm = !m_bSirenOrAlarm; + printf("m_bSirenOrAlarm toggled to %d\n", m_bSirenOrAlarm); + } + }else if(UsesSiren(GetModelIndex())){ + if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory]){ + if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] && + Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+3) % 5]) + m_nCarHornTimer = 1; + else + m_nCarHornTimer = 0; + }else if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] && + !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+1) % 5]){ + m_nCarHornTimer = 0; + m_bSirenOrAlarm = !m_bSirenOrAlarm; + }else + m_nCarHornTimer = 0; + }else if(GetModelIndex() != MI_YARDIE && !CVehicle::bCheat3){ + if(Pads[0].GetHorn()) + m_nCarHornTimer = 1; + else + m_nCarHornTimer = 0; + } + } + + // Flying + + if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ + if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); + }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && + m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ + FlyingControl(FLIGHT_MODEL_DODO); + }else if(GetModelIndex() == MI_MIAMI_RCBARON){ + FlyingControl(FLIGHT_MODEL_HELI); + }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ + if(CPad::GetPad(0)->GetCircleJustDown()) + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); + if(m_aWheelSpeed[0] < 0.22f) + m_aWheelSpeed[0] += 0.0001f; + if(m_aWheelSpeed[0] > 0.15f) + FlyingControl(FLIGHT_MODEL_HELI); + } + } + + + + // Process car on fire + // A similar calculation of damagePos is done elsewhere for smoke + + uint8 engineStatus = Damage.GetEngineStatus(); + CVector damagePos = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_positions[CAR_POS_HEADLIGHTS]; + + switch(Damage.GetDoorStatus(DOOR_BONNET)){ + case DOOR_STATUS_OK: + case DOOR_STATUS_SMASHED: + // Bonnet is still there, smoke comes out at the edge + damagePos += vecDAMAGE_ENGINE_POS_SMALL; + break; + case DOOR_STATUS_SWINGING: + case DOOR_STATUS_MISSING: + // Bonnet is gone, smoke comes out at the engine + damagePos += vecDAMAGE_ENGINE_POS_BIG; + break; + } + + // move fire forward if in first person + if(this == FindPlayerVehicle() && TheCamera.GetLookingForwardFirstPerson()) + if(m_fHealth < 250.0f && m_status != STATUS_WRECKED){ + if(GetModelIndex() == MI_FIRETRUCK) + damagePos += CVector(0.0f, 3.0f, -0.2f); + else + damagePos += CVector(0.0f, 1.2f, -0.8f); + } + + damagePos = GetMatrix()*damagePos; + damagePos.z += 0.15f; + + if(m_fHealth < 250.0f && m_status != STATUS_WRECKED){ + // Car is on fire + + CParticle::AddParticle(PARTICLE_CARFLAME, damagePos, + CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.01125f, 0.09f)), + nil, 0.9f); + + CVector coors = damagePos; + coors.x += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f), + coors.y += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f), + coors.z += CGeneral::GetRandomNumberInRange(0.5625f, 2.25f); + CParticle::AddParticle(PARTICLE_CARFLAME_SMOKE, coors, CVector(0.0f, 0.0f, 0.0f)); + + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE2, damagePos, CVector(0.0f, 0.0f, 0.0f), nil, 0.5f); + + // Blow up car after 5 seconds + m_fFireBlowUpTimer += CTimer::GetTimeStepInMilliseconds(); + if(m_fFireBlowUpTimer > 5000.0f){ + CWorld::Players[CWorld::PlayerInFocus].AwardMoneyForExplosion(this); + BlowUpCar(m_pSetOnFireEntity); + } + }else + m_fFireBlowUpTimer = 0.0f; + + // Decrease car health if engine is damaged badly + if(engineStatus > ENGINE_STATUS_ON_FIRE && m_fHealth > 250.0f) + m_fHealth -= 2.0f; + + ProcessDelayedExplosion(); + + + if(m_bSirenOrAlarm && (CTimer::GetFrameCounter()&7) == 5 && + UsesSiren(GetModelIndex()) && GetModelIndex() != MI_RCBANDIT) + CCarAI::MakeWayForCarWithSiren(this); + + + // Find out how much to shake the pad depending on suspension and ground surface + + float suspShake = 0.0f; + float surfShake = 0.0f; + for(i = 0; i < 4; i++){ + float suspChange = m_aSuspensionSpringRatioPrev[i] - m_aSuspensionSpringRatio[i]; + if(suspChange > 0.3f){ + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, suspChange); + if(suspChange > suspShake) + suspShake = suspChange; + } + + uint8 surf = m_aWheelColPoints[i].surfaceB; + if(surf == SURFACE_DIRT || surf == SURFACE_PUDDLE || surf == SURFACE_HEDGE){ + if(surfShake < 0.2f) + surfShake = 0.3f; + }else if(surf == SURFACE_DIRTTRACK || surf == SURFACE_SAND){ + if(surfShake < 0.1f) + surfShake = 0.2f; + }else if(surf == SURFACE_GRASS){ + if(surfShake < 0.05f) + surfShake = 0.1f; + } + + m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i]; + m_aSuspensionSpringRatio[i] = 1.0f; + } + + // Shake pad + + if((suspShake > 0.0f || surfShake > 0.0f) && m_status == STATUS_PLAYER){ + float speed = m_vecMoveSpeed.MagnitudeSqr(); + if(speed > sq(0.1f)){ + speed = Sqrt(speed); + if(suspShake > 0.0f){ + uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); + CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); + }else{ + uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); + CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); + } + } + } + + bVehicleColProcessed = false; + + if(!bWarnedPeds) + CCarCtrl::ScanForPedDanger(this); + + + // Turn around at the edge of the world + // TODO: make the numbers defines + + float heading; + if(GetPosition().x > 1900.0f){ + if(m_vecMoveSpeed.x > 0.0f) + m_vecMoveSpeed.x *= -1.0f; + heading = GetForward().Heading(); + if(heading > 0.0f) // going west + SetHeading(-heading); + }else if(GetPosition().x < -1900.0f){ + if(m_vecMoveSpeed.x < 0.0f) + m_vecMoveSpeed.x *= -1.0f; + heading = GetForward().Heading(); + if(heading < 0.0f) // going east + SetHeading(-heading); + } + if(GetPosition().y > 1900.0f){ + if(m_vecMoveSpeed.y > 0.0f) + m_vecMoveSpeed.y *= -1.0f; + heading = GetForward().Heading(); + if(heading < HALFPI && heading > 0.0f) + SetHeading(PI-heading); + else if(heading > -HALFPI && heading < 0.0f) + SetHeading(-PI-heading); + }else if(GetPosition().y < -1900.0f){ + if(m_vecMoveSpeed.y < 0.0f) + m_vecMoveSpeed.y *= -1.0f; + heading = GetForward().Heading(); + if(heading > HALFPI) + SetHeading(PI-heading); + else if(heading < -HALFPI) + SetHeading(-PI-heading); + } + + if(bInfiniteMass){ + m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); + m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); + }else if(!skipPhysics && + (m_fGasPedal == 0.0f && brake == 0.0f || m_status == STATUS_WRECKED)){ + if(Abs(m_vecMoveSpeed.x) < 0.005f && + Abs(m_vecMoveSpeed.y) < 0.005f && + Abs(m_vecMoveSpeed.z) < 0.005f){ + m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + m_vecTurnSpeed.z = 0.0f; + } + } +} + +void +CAutomobile::Teleport(CVector pos) +{ + CWorld::Remove(this); + + GetPosition() = pos; + SetOrientation(0.0f, 0.0f, 0.0f); + SetMoveSpeed(0.0f, 0.0f, 0.0f); + SetTurnSpeed(0.0f, 0.0f, 0.0f); + + ResetSuspension(); + + CWorld::Add(this); +} + +void +CAutomobile::PreRender(void) +{ + int i, j, n; + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + + if(GetModelIndex() == MI_RCBANDIT){ + CVector pos = GetMatrix() * CVector(0.218f, -0.444f, 0.391f); + CAntennas::RegisterOne((uintptr)this, GetUp(), pos, 1.0f); + } + + float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward())*180.0f; + + + // Wheel particles + + if(GetModelIndex() == MI_DODO){ + ; // nothing + }else if(GetModelIndex() == MI_RCBANDIT){ + for(i = 0; i < 4; i++){ + // Game has same code three times here + switch(m_aWheelState[i]){ + case WHEEL_STATE_SPINNING: + case WHEEL_STATE_SKIDDING: + case WHEEL_STATE_FIXED: + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.05f), + CVector(0.0f, 0.0f, 0.0f), nil, 0.1f); + break; + } + } + }else{ + if(m_status == STATUS_SIMPLE){ + CMatrix mat; + CVector pos; + + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); + pos = mat.GetPosition(); + pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_RIGHT]; + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB = SURFACE_DEFAULT; + + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); + pos = mat.GetPosition(); + pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_LEFT]; + m_aWheelColPoints[CARWHEEL_REAR_LEFT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB = SURFACE_DEFAULT; + + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + pos = mat.GetPosition(); + pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; + m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB = SURFACE_DEFAULT; + + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); + pos = mat.GetPosition(); + pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_LEFT]; + m_aWheelColPoints[CARWHEEL_FRONT_LEFT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB = SURFACE_DEFAULT; + } + + int drawParticles = Abs(fwdSpeed) < 90.0f; + if(m_status == STATUS_SIMPLE || m_status == STATUS_PHYSICS || + m_status == STATUS_PLAYER || m_status == STATUS_PLAYER_PLAYBACKFROMBUFFER){ + bool rearSkidding = false; + if(m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SKIDDING || + m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SKIDDING) + rearSkidding = true; + + for(i = 0; i < 4; i++){ + switch(m_aWheelState[i]){ + case WHEEL_STATE_SPINNING: + if(AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles)){ + CParticle::AddParticle(PARTICLE_BURNINGRUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), + CVector(0.0f, 0.0f, 0.0f)); + + CParticle::AddParticle(PARTICLE_BURNINGRUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), + CVector(0.0f, 0.0f, 0.05f)); + } + + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), + CVector(0.0f, 0.0f, 0.0f)); + + if(m_aWheelTimer[i] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); + break; + + case WHEEL_STATE_SKIDDING: + if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT || rearSkidding){ + // same as below + + AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); + + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), + CVector(0.0f, 0.0f, 0.0f)); + + if(m_aWheelTimer[i] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); + } + break; + + case WHEEL_STATE_FIXED: + AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); + + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), + CVector(0.0f, 0.0f, 0.0f)); + + if(m_aWheelTimer[i] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); + break; + + default: + if(Abs(fwdSpeed) > 0.5f) + AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); + if(m_aWheelSkidmarkBloody[i] && m_aWheelTimer[i] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); + } + } + } + } + + if(m_aCarNodes[CAR_WHEEL_RM]){ + // assume middle wheels are two units before rear ones + CVector offset = GetForward()*2.0f; + + switch(m_aWheelState[CARWHEEL_REAR_LEFT]){ + // Game has same code three times here + case WHEEL_STATE_SPINNING: + case WHEEL_STATE_SKIDDING: + case WHEEL_STATE_FIXED: + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[CARWHEEL_REAR_LEFT].point + CVector(0.0f, 0.0f, 0.25f) + offset, + CVector(0.0f, 0.0f, 0.0f)); + + if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + CARWHEEL_REAR_LEFT, + m_aWheelColPoints[CARWHEEL_REAR_LEFT].point + offset, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_LEFT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_LEFT]); + break; + } + + switch(m_aWheelState[CARWHEEL_REAR_RIGHT]){ + // Game has same code three times here + case WHEEL_STATE_SPINNING: + case WHEEL_STATE_SKIDDING: + case WHEEL_STATE_FIXED: + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point + CVector(0.0f, 0.0f, 0.25f) + offset, + CVector(0.0f, 0.0f, 0.0f)); + + if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f) + CSkidmarks::RegisterOne((uintptr)this + CARWHEEL_REAR_RIGHT, + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point + offset, + GetForward().x, GetForward().y, + &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_RIGHT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_RIGHT]); + break; + } + } + + + // Rain on roof + if(!CCullZones::CamNoRain() && !CCullZones::PlayerNoRain() && + Abs(fwdSpeed) < 20.0f && CWeather::Rain > 0.02f){ + CColModel *colModel = GetColModel(); + + for(i = 0; i < colModel->numTriangles; i++){ + CVector p1, p2, p3, c; + + colModel->GetTrianglePoint(p1, colModel->triangles[i].a); + p1 = GetMatrix() * p1; + colModel->GetTrianglePoint(p2, colModel->triangles[i].b); + p2 = GetMatrix() * p2; + colModel->GetTrianglePoint(p3, colModel->triangles[i].c); + p3 = GetMatrix() * p3; + c = (p1 + p2 + p3)/3.0f; + + n = 6.0f*CWeather::Rain; + for(j = 0; j <= n; j++) + CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, + c + CVector(CGeneral::GetRandomNumberInRange(-.04f, 0.4f), CGeneral::GetRandomNumberInRange(-.04f, 0.4f), 0.0f), + CVector(0.0f, 0.0f, 0.0f), + nil, 0.0f, 0, 0, CGeneral::GetRandomNumber() & 1); + } + } + + AddDamagedVehicleParticles(); + + // Exhaust smoke + if(bEngineOn && fwdSpeed < 90.0f){ + CVector exhaustPos = mi->m_positions[CAR_POS_EXHAUST]; + CVector pos1, pos2, dir; + + if(exhaustPos != CVector(0.0f, 0.0f, 0.0f)){ + dir.z = 0.0f; + if(fwdSpeed < 10.0f){ + CVector steerFwd(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f); + steerFwd = Multiply3x3(GetMatrix(), steerFwd); + float r = CGeneral::GetRandomNumberInRange(-0.06f, -0.03f); + dir.x = steerFwd.x * r; + dir.y = steerFwd.y * r; + }else{ + dir.x = m_vecMoveSpeed.x; + dir.y = m_vecMoveSpeed.y; + } + + bool dblExhaust = false; + pos1 = GetMatrix() * exhaustPos; + if(pHandling->Flags & HANDLING_DBL_EXHAUST){ + dblExhaust = true; + pos2 = exhaustPos; + pos2.x = -pos2.x; + pos2 = GetMatrix() * pos2; + } + + n = 4.0f*m_fGasPedal; + if(dblExhaust) + for(i = 0; i <= n; i++){ + CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos1, dir); + CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos2, dir); + } + else + for(i = 0; i <= n; i++) + CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos1, dir); + } + } + + + // Siren and taxi lights + switch(GetModelIndex()){ + case MI_FIRETRUCK: + case MI_AMBULAN: + case MI_POLICE: + case MI_ENFORCER: + if(m_bSirenOrAlarm){ + CVector pos1, pos2; + uint8 r1, g1, b1; + uint8 r2, g2, b2; + uint8 r, g, b; + + switch(GetModelIndex()){ + case MI_FIRETRUCK: + pos1 = CVector(1.1f, 1.7f, 2.0f); + pos2 = CVector(-1.1f, 1.7f, 2.0f); + r1 = 255; g1 = 0; b1 = 0; + r2 = 255; g2 = 255; b2 = 0; + break; + case MI_AMBULAN: + pos1 = CVector(1.1f, 0.9f, 1.6f); + pos2 = CVector(-1.1f, 0.9f, 1.6f); + r1 = 255; g1 = 0; b1 = 0; + r2 = 255; g2 = 255; b2 = 255; + break; + case MI_POLICE: + pos1 = CVector(0.7f, -0.4f, 1.0f); + pos2 = CVector(-0.7f, -0.4f, 1.0f); + r1 = 255; g1 = 0; b1 = 0; + r2 = 0; g2 = 0; b2 = 255; + break; + case MI_ENFORCER: + pos1 = CVector(1.1f, 0.8f, 1.2f); + pos2 = CVector(-1.1f, 0.8f, 1.2f); + r1 = 255; g1 = 0; b1 = 0; + r2 = 0; g2 = 0; b2 = 255; + break; + } + + uint32 t = CTimer::GetTimeInMilliseconds() & 0x3FF; // 1023 + if(t < 512){ + r = r1/6; + g = g1/6; + b = b1/6; + }else{ + r = r2/6; + g = g2/6; + b = b2/6; + } + + t = CTimer::GetTimeInMilliseconds() & 0x1FF; // 511 + if(t < 100){ + float f = t/100.0f; + r *= f; + g *= f; + b *= f; + }else if(t > 412){ + float f = (512-t)/100.0f; + r *= f; + g *= f; + b *= f; + } + + CVector pos = GetPosition(); + float angle = (CTimer::GetTimeInMilliseconds() & 0x3FF)*TWOPI/0x3FF; + float s = 8.0f*Sin(angle); + float c = 8.0f*Cos(angle); + CShadows::StoreCarLightShadow(this, (uintptr)this + 21, gpShadowHeadLightsTex, + &pos, c, s, s, -c, r, g, b, 8.0f); + + CPointLights::AddLight(CPointLights::LIGHT_POINT, + pos + GetUp()*2.0f, CVector(0.0f, 0.0f, 0.0f), 12.0f, + r*0.02f, g*0.02f, b*0.02f, CPointLights::FOG_NONE, true); + + pos1 = GetMatrix() * pos1; + pos2 = GetMatrix() * pos2; + + for(i = 0; i < 4; i++){ + uint8 sirenTimer = ((CTimer::GetTimeInMilliseconds() + (i<<6))>>8) & 3; + pos = (pos1*i + pos2*(3.0f-i))/3.0f; + + switch(sirenTimer){ + case 0: + CCoronas::RegisterCorona((uintptr)this + 21 + i, + r1, g1, b1, 255, + pos, 0.4f, 50.0f, + CCoronas::TYPE_STAR, + i == 1 ? CCoronas::FLARE_HEADLIGHTS : CCoronas::FLARE_NONE, + CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + break; + case 2: + CCoronas::RegisterCorona((uintptr)this + 21 + i, + r2, g2, b2, 255, + pos, 0.4f, 50.0f, + CCoronas::TYPE_STAR, + CCoronas::FLARE_NONE, + CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + break; + default: + CCoronas::UpdateCoronaCoors((uintptr)this + 21 + i, pos, 50.0f, 0.0f); + break; + } + } + } + break; + + case MI_FBICAR: + if(m_bSirenOrAlarm){ + CVector pos = GetMatrix() * CVector(0.4f, 0.6f, 0.3f); + if(CTimer::GetTimeInMilliseconds() & 0x100 && + DotProduct(GetForward(), GetPosition() - TheCamera.GetPosition()) < 0.0f) + CCoronas::RegisterCorona((uintptr)this + 21, + 0, 0, 255, 255, + pos, 0.4f, 50.0f, + CCoronas::TYPE_STAR, + CCoronas::FLARE_NONE, + CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::UpdateCoronaCoors((uintptr)this + 21, pos, 50.0f, 0.0f); + } + break; + + case MI_TAXI: + case MI_CABBIE: + case MI_BORGNINE: + if(bTaxiLight){ + CVector pos = GetPosition() + GetUp()*0.95f; + CCoronas::RegisterCorona((uintptr)this + 21, + 128, 128, 0, 255, + pos, 0.8f, 50.0f, + CCoronas::TYPE_NORMAL, + CCoronas::FLARE_NONE, + CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + CPointLights::AddLight(CPointLights::LIGHT_POINT, + pos, CVector(0.0f, 0.0f, 0.0f), 10.0f, + 1.0f, 1.0f, 0.5f, CPointLights::FOG_NONE, true); + } + break; + } + + if(GetModelIndex() == MI_RCBANDIT || + GetModelIndex() == MI_DODO || + GetModelIndex() == MI_RHINO) + goto nolights; + + // Turn lights on/off + bool shouldLightsBeOn = + CClock::GetHours() > 20 || + CClock::GetHours() > 19 && CClock::GetMinutes() > (m_randomSeed & 0x3F) || + CClock::GetHours() < 7 || + CClock::GetHours() < 8 && CClock::GetMinutes() < (m_randomSeed & 0x3F) || + m_randomSeed/50000.0f < CWeather::Foggyness || + m_randomSeed/50000.0f < CWeather::WetRoads; + if(shouldLightsBeOn != bLightsOn && m_status != STATUS_WRECKED){ + if(m_status == STATUS_ABANDONED){ + // Turn off lights on abandoned vehicles only when we they're far away + if(bLightsOn && + Abs(TheCamera.GetPosition().x - GetPosition().x) + Abs(TheCamera.GetPosition().y - GetPosition().y) > 100.0f) + bLightsOn = false; + }else + bLightsOn = shouldLightsBeOn; + } + + // Actually render the lights + bool alarmOn = false; + bool alarmOff = false; + if(IsAlarmOn()){ + if(CTimer::GetTimeInMilliseconds() & 0x100) + alarmOn = true; + else + alarmOff = true; + } + if(bEngineOn && bLightsOn || alarmOn || alarmOff){ + CVector lookVector = GetPosition() - TheCamera.GetPosition(); + float camDist = lookVector.Magnitude(); + if(camDist != 0.0f) + lookVector *= 1.0f/camDist; + else + lookVector = CVector(1.0f, 0.0f, 0.0f); + + // 1.0 if directly behind car, -1.0 if in front + // BUG on PC: Abs of DotProduct is taken + float behindness = DotProduct(lookVector, GetForward()); + behindness = clamp(behindness, -1.0f, 1.0f); // shouldn't be necessary + // 0.0 if behind car, PI if in front + // Abs not necessary + float angle = Abs(Acos(behindness)); + + // Headlights + + CVector headLightPos = mi->m_positions[CAR_POS_HEADLIGHTS]; + CVector lightR = GetMatrix() * headLightPos; + CVector lightL = lightR; + lightL -= GetRight()*2.0f*headLightPos.x; + + // Headlight coronas + if(behindness < 0.0f){ + // In front of car + float intensity = -0.5f*behindness + 0.3f; + float size = 1.0f - behindness; + + if(behindness < -0.97f && camDist < 30.0f){ + // Directly in front and not too far away + if(pHandling->Flags & HANDLING_HALOGEN_LIGHTS){ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 6, 150, 150, 195, 255, + lightL, 1.2f, 45.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 7, 150, 150, 195, 255, + lightR, 1.2f, 45.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); + }else{ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 6, 160, 160, 140, 255, + lightL, 1.2f, 45.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 7, 160, 160, 140, 255, + lightR, 1.2f, 45.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); + } + } + + if(alarmOff){ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this, 0, 0, 0, 0, + lightL, size, 0.0f, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 1, 0, 0, 0, 0, + lightR, size, 0.0f, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + }else{ + if(pHandling->Flags & HANDLING_HALOGEN_LIGHTS){ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this, 190*intensity, 190*intensity, 255*intensity, 255, + lightL, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 1, 190*intensity, 190*intensity, 255*intensity, 255, + lightR, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + }else{ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this, 210*intensity, 210*intensity, 195*intensity, 255, + lightL, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 1, 210*intensity, 210*intensity, 195*intensity, 255, + lightR, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + } + } + }else{ + // Behind car + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this, lightL, 50.0f*TheCamera.LODDistMultiplier, angle); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 1, lightR, 50.0f*TheCamera.LODDistMultiplier, angle); + } + + // bright lights + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK && !bNoBrightHeadLights) + CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->FrontLights + 4); + if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK && !bNoBrightHeadLights) + CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->FrontLights + 4); + + // Taillights + + CVector tailLightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; + lightR = GetMatrix() * tailLightPos; + lightL = lightR; + lightL -= GetRight()*2.0f*tailLightPos.x; + + // Taillight coronas + if(behindness > 0.0f){ + // Behind car + float intensity = 0.4f*behindness + 0.4; + float size = (behindness + 1.0f)/2.0f; + + if(m_fGasPedal < 0.0f){ + // reversing + intensity += 0.4f; + size += 0.3f; + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 2, 128*intensity, 128*intensity, 128*intensity, 255, + lightL, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 3, 128*intensity, 128*intensity, 128*intensity, 255, + lightR, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + }else{ + if(m_fBrakePedal > 0.0){ + intensity += 0.4f; + size += 0.3f; + } + + if(alarmOff){ + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 2, 0, 0, 0, 0, + lightL, size, 0.0f, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 3, 0, 0, 0, 0, + lightR, size, 0.0f, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + }else{ + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 2, 128*intensity, 0, 0, 255, + lightL, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 3, 128*intensity, 0, 0, 255, + lightR, size, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); + } + } + }else{ + // In front of car + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, angle); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, angle); + } + + // bright lights + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); + + // Light shadows + if(!alarmOff){ + CVector pos = GetPosition(); + CVector2D fwd(GetForward()); + fwd.Normalise(); + float f = headLightPos.y + 6.0f; + pos += CVector(f*fwd.x, f*fwd.y, 2.0f); + + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK || + Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CShadows::StoreCarLightShadow(this, (uintptr)this + 22, gpShadowHeadLightsTex, &pos, + 7.0f*fwd.x, 7.0f*fwd.y, 7.0f*fwd.y, -7.0f*fwd.x, 45, 45, 45, 7.0f); + + f = (tailLightPos.y - 2.5f) - (headLightPos.y + 6.0f); + pos += CVector(f*fwd.x, f*fwd.y, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK || + Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CShadows::StoreCarLightShadow(this, (uintptr)this + 25, gpShadowExplosionTex, &pos, + 3.0f, 0.0f, 0.0f, -3.0f, 35, 0, 0, 4.0f); + } + + if(this == FindPlayerVehicle() && !alarmOff){ + if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK || + Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) + CPointLights::AddLight(CPointLights::LIGHT_DIRECTIONAL, GetPosition(), GetForward(), + 20.0f, 1.0f, 1.0f, 1.0f, + FindPlayerVehicle()->m_vecMoveSpeed.MagnitudeSqr2D() < sq(0.45f) ? CPointLights::FOG_NORMAL : CPointLights::FOG_NONE, + false); + CVector pos = GetPosition() - 4.0f*GetForward(); + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK || + Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + if(m_fBrakePedal > 0.0f) + CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), + 10.0f, 1.0f, 0.0f, 0.0f, + CPointLights::FOG_NONE, false); + else + CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), + 7.0f, 0.6f, 0.0f, 0.0f, + CPointLights::FOG_NONE, false); + } + }else{ + // Lights off + + if(m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED) + goto nolights; + + CVector lightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; + CVector lightR = GetMatrix() * lightPos; + CVector lightL = lightR; + lightL -= GetRight()*2.0f*lightPos.x; + + if(m_fBrakePedal > 0.0f || m_fGasPedal < 0.0f){ + CVector lookVector = GetPosition() - TheCamera.GetPosition(); + lookVector.Normalise(); + float behindness = DotProduct(lookVector, GetForward()); + if(behindness > 0.0f){ + if(m_fGasPedal < 0.0f){ + // reversing + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 2, 120, 120, 120, 255, + lightL, 1.2f, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 3, 120, 120, 120, 255, + lightR, 1.2f, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 4); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 4); + }else{ + // braking + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 2, 120, 0, 0, 255, + lightL, 1.2f, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::RegisterCorona((uintptr)this + 3, 120, 0, 0, 255, + lightR, 1.2f, 50.0f*TheCamera.LODDistMultiplier, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); + } + }else{ + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, 0.0f); + } + }else{ + if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, 0.0f); + if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, 0.0f); + } + } + +nolights: + CShadows::StoreShadowForCar(this); +} + +void +CAutomobile::Render(void) +{ + int i; + CMatrix mat; + CVector pos; + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + + if(GetModelIndex() == MI_RHINO && m_aCarNodes[CAR_BONNET]){ + // Rhino has no bonnet...what are we doing here? + CMatrix m; + CVector p; + m.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BONNET])); + p = m.GetPosition(); + m.SetRotateZ(m_fCarGunLR); + m.Translate(p); + m.UpdateRW(); + } + + CVector contactPoints[4]; // relative to model + CVector contactSpeeds[4]; // speed at contact points + CVector frontWheelFwd = Multiply3x3(GetMatrix(), CVector(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f)); + CVector rearWheelFwd = GetForward(); + for(i = 0; i < 4; i++){ + contactPoints[i] = m_aWheelColPoints[i].point - GetPosition(); + contactSpeeds[i] = GetSpeed(contactPoints[i]); + if(i == CARWHEEL_FRONT_LEFT || i == CARWHEEL_FRONT_RIGHT) + m_aWheelSpeed[i] = ProcessWheelRotation(m_aWheelState[i], frontWheelFwd, contactSpeeds[i], 0.5f*mi->m_wheelScale); + else + m_aWheelSpeed[i] = ProcessWheelRotation(m_aWheelState[i], rearWheelFwd, contactSpeeds[i], 0.5f*mi->m_wheelScale); + m_aWheelRotation[i] += m_aWheelSpeed[i]; + } + + // Rear right wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_REAR_RIGHT]; + if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) + mat.SetRotate(m_aWheelRotation[CARWHEEL_REAR_RIGHT], 0.0f, 0.3f*Sin(m_aWheelRotation[CARWHEEL_REAR_RIGHT])); + else + mat.SetRotateX(m_aWheelRotation[CARWHEEL_REAR_RIGHT]); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RB])); + + // Rear left wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_REAR_LEFT]; + if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) + mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI+0.3f*Sin(-m_aWheelRotation[CARWHEEL_REAR_LEFT])); + else + mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LB])); + + // Mid right wheel + if(m_aCarNodes[CAR_WHEEL_RM]){ + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_REAR_RIGHT]; + if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) + mat.SetRotate(m_aWheelRotation[CARWHEEL_REAR_RIGHT], 0.0f, 0.3f*Sin(m_aWheelRotation[CARWHEEL_REAR_RIGHT])); + else + mat.SetRotateX(m_aWheelRotation[CARWHEEL_REAR_RIGHT]); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RM])); + } + + // Mid left wheel + if(m_aCarNodes[CAR_WHEEL_LM]){ + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_REAR_LEFT]; + if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) + mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI+0.3f*Sin(-m_aWheelRotation[CARWHEEL_REAR_LEFT])); + else + mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LM])); + } + + if(GetModelIndex() == MI_DODO){ + // Front wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; + if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) + mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle+0.3f*Sin(m_aWheelRotation[CARWHEEL_FRONT_RIGHT])); + else + mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); + + // Rotate propeller + if(m_aCarNodes[CAR_WINDSCREEN]){ + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WINDSCREEN])); + pos = mat.GetPosition(); + mat.SetRotateY(m_fPropellerRotation); + mat.Translate(pos); + mat.UpdateRW(); + + m_fPropellerRotation += m_fGasPedal != 0.0f ? TWOPI/13.0f : TWOPI/26.0f; + if(m_fPropellerRotation > TWOPI) + m_fPropellerRotation -= TWOPI; + } + + // Rudder + if(Damage.GetDoorStatus(DOOR_BOOT) != DOOR_STATUS_MISSING && m_aCarNodes[CAR_BOOT]){ + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BOOT])); + pos = mat.GetPosition(); + mat.SetRotate(0.0f, 0.0f, -m_fSteerAngle); + mat.Rotate(0.0f, Sin(m_fSteerAngle)*DEGTORAD(22.0f), 0.0f); + mat.Translate(pos); + mat.UpdateRW(); + } + + ProcessSwingingDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT); + ProcessSwingingDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT); + }else if(GetModelIndex() == MI_RHINO){ + // Front right wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; + // no damaged wheels or steering + mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, 0.0f); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); + + // Front left wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_FRONT_LEFT]; + // no damaged wheels or steering + mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LF])); + }else{ + // Front right wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; + if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) + mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle+0.3f*Sin(m_aWheelRotation[CARWHEEL_FRONT_RIGHT])); + else + mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); + + // Front left wheel + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); + pos.x = mat.GetPosition().x; + pos.y = mat.GetPosition().y; + pos.z = m_aWheelPosition[CARWHEEL_FRONT_LEFT]; + if(Damage.GetWheelStatus(CARWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) + mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI+m_fSteerAngle+0.3f*Sin(-m_aWheelRotation[CARWHEEL_FRONT_LEFT])); + else + mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI+m_fSteerAngle); + mat.Scale(mi->m_wheelScale); + mat.Translate(pos); + mat.UpdateRW(); + if(CVehicle::bWheelsOnlyCheat) + RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LF])); + + ProcessSwingingDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT); + ProcessSwingingDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT); + ProcessSwingingDoor(CAR_DOOR_LR, DOOR_REAR_LEFT); + ProcessSwingingDoor(CAR_DOOR_RR, DOOR_REAR_RIGHT); + ProcessSwingingDoor(CAR_BONNET, DOOR_BONNET); + ProcessSwingingDoor(CAR_BOOT, DOOR_BOOT); + + mi->SetVehicleColour(m_currentColour1, m_currentColour2); + } + + if(!CVehicle::bWheelsOnlyCheat) + CEntity::Render(); +} + +int32 +CAutomobile::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints) +{ + int i; + CColModel *colModel; + + if(m_status != STATUS_SIMPLE) + bVehicleColProcessed = true; + + if(bUsingSpecialColModel) + colModel = &CWorld::Players[CWorld::PlayerInFocus].m_ColModel; + else + colModel = GetColModel(); + + int numWheelCollisions = 0; + float prevRatios[4] = { 0.0f, 0.0f, 0.0f, 0.0f}; + for(i = 0; i < 4; i++) + prevRatios[i] = m_aSuspensionSpringRatio[i]; + + int numCollisions = CCollision::ProcessColModels(GetMatrix(), *colModel, + ent->GetMatrix(), *ent->GetColModel(), + colpoints, + m_aWheelColPoints, m_aSuspensionSpringRatio); + + // m_aSuspensionSpringRatio are now set to the point where the tyre touches ground. + // In ProcessControl these will be re-normalized to ignore the tyre radius. + + if(field_EF || m_phy_flagA80 || + GetModelIndex() == MI_DODO && (ent->IsPed() || ent->IsVehicle())){ + // don't do line collision + for(i = 0; i < 4; i++) + m_aSuspensionSpringRatio[i] = prevRatios[i]; + }else{ + for(i = 0; i < 4; i++) + if(m_aSuspensionSpringRatio[i] < 1.0f && m_aSuspensionSpringRatio[i] < prevRatios[i]){ + numWheelCollisions++; + + // wheel is touching a physical + if(ent->IsVehicle() || ent->IsObject()){ + CPhysical *phys = (CPhysical*)ent; + + m_aGroundPhysical[i] = phys; + phys->RegisterReference((CEntity**)&m_aGroundPhysical[i]); + m_aGroundOffset[i] = m_aWheelColPoints[i].point - phys->GetPosition(); + + if(phys->GetModelIndex() == MI_BODYCAST && m_status == STATUS_PLAYER){ + // damage body cast + float speed = m_vecMoveSpeed.MagnitudeSqr(); + if(speed > 0.1f){ + CObject::nBodyCastHealth -= 0.1f*m_fMass*speed; + DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_BODYCAST_HIT, 0.0f); + } + + // move body cast + if(phys->bIsStatic){ + phys->bIsStatic = false; + phys->m_nStaticFrames = 0; + phys->ApplyMoveForce(m_vecMoveSpeed / speed); + phys->AddToMovingList(); + } + } + } + + m_nSurfaceTouched = m_aWheelColPoints[i].surfaceB; + if(ent->IsBuilding()) + m_pCurGroundEntity = ent; + } + } + + if(numCollisions > 0 || numWheelCollisions > 0){ + AddCollisionRecord(ent); + if(!ent->IsBuilding()) + ((CPhysical*)ent)->AddCollisionRecord(this); + + if(numCollisions > 0) + if(ent->IsBuilding() || + ent->IsObject() && ((CPhysical*)ent)->bInfiniteMass) + bHasHitWall = true; + } + + return numCollisions; +} + +static int16 nLastControlInput; +static float fMouseCentreRange = 0.35f; +static float fMouseSteerSens = -0.0035f; +static float fMouseCentreMult = 0.975f; + +void +CAutomobile::ProcessControlInputs(uint8 pad) +{ + float speed = DotProduct(m_vecMoveSpeed, GetForward()); + + if(CPad::GetPad(pad)->GetExitVehicle()) + bIsHandbrakeOn = true; + else + bIsHandbrakeOn = !!CPad::GetPad(pad)->GetHandBrake(); + + // Steer left/right + if(CCamera::m_bUseMouse3rdPerson && !CVehicle::m_bDisableMouseSteering){ + if(CPad::GetPad(pad)->GetMouseX() != 0.0f){ + m_fSteerRatio += fMouseSteerSens*CPad::GetPad(pad)->GetMouseX(); + nLastControlInput = 2; + if(Abs(m_fSteerRatio) < fMouseCentreRange) + m_fSteerRatio *= Pow(fMouseCentreMult, CTimer::GetTimeStep()); + }else if(CPad::GetPad(pad)->GetSteeringLeftRight() || nLastControlInput != 2){ + // mouse hasn't move, steer with pad like below + m_fSteerRatio += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteerRatio)* + 0.2f*CTimer::GetTimeStep(); + nLastControlInput = 0; + } + }else{ + m_fSteerRatio += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteerRatio)* + 0.2f*CTimer::GetTimeStep(); + nLastControlInput = 0; + } + m_fSteerRatio = clamp(m_fSteerRatio, -1.0f, 1.0f); + + // Accelerate/Brake + float acceleration = (CPad::GetPad(pad)->GetAccelerate() - CPad::GetPad(pad)->GetBrake())/255.0f; + if(GetModelIndex() == MI_DODO && acceleration < 0.0f) + acceleration *= 0.3f; + if(Abs(speed) < 0.01f){ + // standing still, go into direction we want + m_fGasPedal = acceleration; + m_fBrakePedal = 0.0f; + }else{ +#if 1 + // simpler than the code below + if(speed * acceleration < 0.0f){ + // if opposite directions, have to brake first + m_fGasPedal = 0.0f; + m_fBrakePedal = Abs(acceleration); + }else{ + // accelerating in same direction we were already going + m_fGasPedal = acceleration; + m_fBrakePedal = 0.0f; + } +#else + if(speed < 0.0f){ + // moving backwards currently + if(acceleration < 0.0f){ + // still go backwards + m_fGasPedal = acceleration; + m_fBrakePedal = 0.0f; + }else{ + // want to go forwards, so brake + m_fGasPedal = 0.0f; + m_fBrakePedal = acceleration; + } + }else{ + // moving forwards currently + if(acceleration < 0.0f){ + // want to go backwards, so brake + m_fGasPedal = 0.0f; + m_fBrakePedal = -acceleration; + }else{ + // still go forwards + m_fGasPedal = acceleration; + m_fBrakePedal = 0.0f; + } + } +#endif + } + + // Actually turn wheels + static float fValue; // why static? + if(m_fSteerRatio < 0.0f) + fValue = -sq(m_fSteerRatio); + else + fValue = sq(m_fSteerRatio); + m_fSteerAngle = DEGTORAD(pHandling->fSteeringLock) * fValue; + + if(bComedyControls){ + int rnd = CGeneral::GetRandomNumber() % 10; + switch(m_comedyControlState){ + case 0: + if(rnd < 2) + m_comedyControlState = 1; + else if(rnd < 4) + m_comedyControlState = 2; + break; + case 1: + m_fSteerAngle += 0.05f; + if(rnd < 2) + m_comedyControlState = 0; + break; + case 2: + m_fSteerAngle -= 0.05f; + if(rnd < 2) + m_comedyControlState = 0; + break; + } + }else + m_comedyControlState = 0; + + // Brake if player isn't in control + // BUG: game always uses pad 0 here + if(CPad::GetPad(pad)->DisablePlayerControls){ + m_fBrakePedal = 1.0f; + bIsHandbrakeOn = true; + m_fGasPedal = 0.0f; + + FindPlayerPed()->KeepAreaAroundPlayerClear(); + + // slow down car immediately + speed = m_vecMoveSpeed.Magnitude(); + if(speed > 0.28f) + m_vecMoveSpeed *= 0.28f/speed; + } +} + +void +CAutomobile::FireTruckControl(void) +{ + if(this == FindPlayerVehicle()){ + if(!CPad::GetPad(0)->GetWeapon()) + return; + m_fCarGunLR += CPad::GetPad(0)->GetCarGunLeftRight()*0.00025f*CTimer::GetTimeStep(); + m_fCarGunUD += CPad::GetPad(0)->GetCarGunUpDown()*0.0001f*CTimer::GetTimeStep(); + m_fCarGunUD = clamp(m_fCarGunUD, 0.05f, 0.3f); + + CVector cannonPos(0.0f, 1.5f, 1.9f); + cannonPos = GetMatrix() * cannonPos; + CVector cannonDir( + Sin(m_fCarGunLR) * Cos(m_fCarGunUD), + Cos(m_fCarGunLR) * Cos(m_fCarGunUD), + Sin(m_fCarGunUD)); + cannonDir = Multiply3x3(GetMatrix(), cannonDir); + cannonDir.z += (CGeneral::GetRandomNumber()&0xF)/1000.0f; + CWaterCannons::UpdateOne((uintptr)this, &cannonPos, &cannonDir); + }else if(m_status == STATUS_PHYSICS){ + CFire *fire = gFireManager.FindFurthestFire_NeverMindFireMen(GetPosition(), 10.0f, 35.0f); + if(fire == nil) + return; + + // Target cannon onto fire + float targetAngle = CGeneral::GetATanOfXY(fire->m_vecPos.x-GetPosition().x, fire->m_vecPos.y-GetPosition().y); + float fwdAngle = CGeneral::GetATanOfXY(GetForward().x, GetForward().y); + float targetCannonAngle = fwdAngle - targetAngle; + float angleDelta = CTimer::GetTimeStep()*0.01f; + float cannonDelta = targetCannonAngle - m_fCarGunLR; + while(cannonDelta < PI) cannonDelta += TWOPI; + while(cannonDelta > PI) cannonDelta -= TWOPI; + if(Abs(cannonDelta) < angleDelta) + m_fCarGunLR = targetCannonAngle; + else if(cannonDelta > 0.0f) + m_fCarGunLR += angleDelta; + else + m_fCarGunLR -= angleDelta; + + // Go up and down a bit + float upDown = Sin((float)(CTimer::GetTimeInMilliseconds() & 0xFFF)/0x1000 * TWOPI); + m_fCarGunUD = 0.2f + 0.2f*upDown; + + // Spray water every once in a while + if((CTimer::GetTimeInMilliseconds()>>10) & 3){ + CVector cannonPos(0.0f, 0.0f, 2.2f); // different position than player's firetruck! + cannonPos = GetMatrix() * cannonPos; + CVector cannonDir( + Sin(m_fCarGunLR) * Cos(m_fCarGunUD), + Cos(m_fCarGunLR) * Cos(m_fCarGunUD), + Sin(m_fCarGunUD)); + cannonDir = Multiply3x3(GetMatrix(), cannonDir); + cannonDir.z += (CGeneral::GetRandomNumber()&0xF)/1000.0f; + CWaterCannons::UpdateOne((uintptr)this, &cannonPos, &cannonDir); + } + } +} + +void +CAutomobile::TankControl(void) +{ + int i; + + // These coords are 1 unit higher then they should be relative to model center + CVector turrentBase(0.0f, -1.394f, 2.296f); + CVector gunEnd(0.0f, 1.813f, 2.979f); + CVector baseToEnd = gunEnd - turrentBase; + + if(this != FindPlayerVehicle()) + return; + if(CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING) + return; + + // Rotate turret + float prevAngle = m_fCarGunLR; + m_fCarGunLR -= CPad::GetPad(0)->GetCarGunLeftRight() * 0.00015f * CTimer::GetTimeStep(); + if(m_fCarGunLR < 0.0f) + m_fCarGunLR += TWOPI; + if(m_fCarGunLR > TWOPI) + m_fCarGunLR -= TWOPI; + if(m_fCarGunLR != prevAngle) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_TANK_TURRET_ROTATE, Abs(m_fCarGunLR - prevAngle)); + + // Shoot + if(CPad::GetPad(0)->CarGunJustDown() && + CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeTankShotGun + 800){ + CWorld::Players[CWorld::PlayerInFocus].m_nTimeTankShotGun = CTimer::GetTimeInMilliseconds(); + + // more like -sin(angle), cos(angle), i.e. rotated (0,1,0) + CVector turretDir = CVector(Sin(-m_fCarGunLR), Cos(-m_fCarGunLR), 0.0f); + turretDir = Multiply3x3(GetMatrix(), turretDir); + + float c = Cos(m_fCarGunLR); + float s = Sin(m_fCarGunLR); + CVector rotatedEnd( + c*baseToEnd.x - s*baseToEnd.y, + s*baseToEnd.x + c*baseToEnd.y, + baseToEnd.z - 1.0f); // correct offset here + rotatedEnd += turrentBase; + + CVector point1 = GetMatrix() * rotatedEnd; + CVector point2 = point1 + 60.0f*turretDir; + m_vecMoveSpeed -= 0.06f*turretDir; + m_vecMoveSpeed.z += 0.05f; + + CWeapon::DoTankDoomAiming(FindPlayerVehicle(), FindPlayerPed(), &point1, &point2); + CColPoint colpoint; + CEntity *entity = nil; + CWorld::ProcessLineOfSight(point1, point2, colpoint, entity, true, true, true, true, true, true, false); + if(entity) + point2 = colpoint.point - 0.04f*(colpoint.point - point1); + + CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_TANK_GRENADE, point2, 0); + + // Add particles on the way to the explosion; + float shotDist = (point2 - point1).Magnitude(); + int n = shotDist/4.0f; + RwRGBA black = { 0, 0, 0, 0 }; + for(i = 0; i < n; i++){ + float f = (float)i/n; + CParticle::AddParticle(PARTICLE_HELI_DUST, + point1 + f*(point2 - point1), + CVector(0.0f, 0.0f, 0.0f), + nil, 0.1f, black); + } + + // More particles + CVector shotDir = point2 - point1; + shotDir.Normalise(); + for(i = 0; i < 15; i++){ + float f = i/15.0f; + CParticle::AddParticle(PARTICLE_GUNSMOKE2, point1, + shotDir*CGeneral::GetRandomNumberInRange(0.3f, 1.0f)*f, + nil, CGeneral::GetRandomNumberInRange(0.5f, 1.0f)*f, black); + } + + // And some gun flashes near the gun + CVector flashPos = point1; + CVector nullDir(0.0f, 0.0f, 0.0f); + int lifeSpan = 250; + if(m_vecMoveSpeed.Magnitude() > 0.08f){ + lifeSpan = 125; + flashPos.x += 0.5f*m_vecMoveSpeed.x; + flashPos.y += 0.5f*m_vecMoveSpeed.y; + } + CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.4f, black, 0, 0, 0, lifeSpan); + flashPos += 0.3f*shotDir; + CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.2f, black, 0, 0, 0, lifeSpan); + flashPos += 0.1f*shotDir; + CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.15f, black, 0, 0, 0, lifeSpan); + } + + // Actually update turret node + if(m_aCarNodes[CAR_WINDSCREEN]){ + CMatrix mat; + CVector pos; + + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WINDSCREEN])); + pos = mat.GetPosition(); + mat.SetRotateZ(m_fCarGunLR); + mat.Translate(pos); + mat.UpdateRW(); + } +} + +void +CAutomobile::HydraulicControl(void) +{ + int i; + float wheelPositions[4]; + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + CColModel *normalColModel = mi->GetColModel(); + float wheelRadius = 0.5f*mi->m_wheelScale; + CPlayerInfo *playerInfo = &CWorld::Players[CWorld::PlayerInFocus]; + CColModel *specialColModel = &playerInfo->m_ColModel; + + if(m_status != STATUS_PLAYER){ + // reset hydraulics for non-player cars + + if(!bUsingSpecialColModel) + return; + if(specialColModel != nil) // this is always true + for(i = 0; i < 4; i++) + wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + for(i = 0; i < 4; i++){ + m_aSuspensionSpringLength[i] = pHandling->fSuspensionUpperLimit - pHandling->fSuspensionLowerLimit; + m_aSuspensionLineLength[i] = normalColModel->lines[i].p0.z - normalColModel->lines[i].p1.z; + m_aSuspensionSpringRatio[i] = (normalColModel->lines[i].p0.z - wheelPositions[i]) / m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + + if(m_hydraulicState == 0) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); + else if(m_hydraulicState >= 100) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + + if(playerInfo->m_pVehicleEx == this) + playerInfo->m_pVehicleEx = nil; + bUsingSpecialColModel = false; + m_hydraulicState = 0; + return; + } + + // Player car + + float normalUpperLimit = pHandling->fSuspensionUpperLimit; + float normalLowerLimit = pHandling->fSuspensionLowerLimit; + float normalSpringLength = normalUpperLimit - normalLowerLimit; + float extendedUpperLimit = normalUpperLimit - 0.2f; + float extendedLowerLimit = normalLowerLimit - 0.2f; + float extendedSpringLength = extendedUpperLimit - extendedLowerLimit; + + if(!bUsingSpecialColModel){ + // Init special col model + + if(playerInfo->m_pVehicleEx && playerInfo->m_pVehicleEx == this) + playerInfo->m_pVehicleEx->bUsingSpecialColModel = false; + playerInfo->m_pVehicleEx = this; + playerInfo->m_ColModel = *normalColModel; + bUsingSpecialColModel = true; + specialColModel = &playerInfo->m_ColModel; + + if(m_fVelocityChangeForAudio > 0.1f) + m_hydraulicState = 20; + else{ + m_hydraulicState = 0; + normalUpperLimit += -0.12f; + normalSpringLength = normalUpperLimit - (normalLowerLimit+0.14f); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + } + + // Setup suspension + float normalLineLength = normalSpringLength + wheelRadius; + CVector pos; + for(i = 0; i < 4; i++){ + wheelPositions[i] = normalColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + mi->GetWheelPosn(i, pos); + pos.z += normalUpperLimit; + specialColModel->lines[i].p0 = pos; + pos.z -= normalLineLength; + specialColModel->lines[i].p1 = pos; + m_aSuspensionSpringLength[i] = normalSpringLength; + m_aSuspensionLineLength[i] = normalLineLength; + + if(m_aSuspensionSpringRatio[i] < 1.0f){ + m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + } + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + + // Adjust col model + mi->GetWheelPosn(0, pos); + float minz = pos.z + extendedLowerLimit - wheelRadius; + if(minz < specialColModel->boundingBox.min.z) + specialColModel->boundingBox.min.z = minz; + float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); + if(specialColModel->boundingSphere.radius < radius) + specialColModel->boundingSphere.radius = radius; + + } + + if(playerInfo->m_WBState != WBSTATE_PLAYING) + return; + + bool setPrevRatio = false; + if(m_hydraulicState < 20 && m_fVelocityChangeForAudio > 0.2f){ + if(m_hydraulicState == 0){ + m_hydraulicState = 20; + for(i = 0; i < 4; i++) + m_aWheelPosition[i] -= 0.06f; + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); + setPrevRatio = true; + }else{ + m_hydraulicState++; + } + }else if(m_hydraulicState != 0){ // must always be true + if(m_hydraulicState < 21 && m_fVelocityChangeForAudio < 0.1f){ + m_hydraulicState--; + if(m_hydraulicState == 0) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + } + } + + if(CPad::GetPad(0)->HornJustDown()){ + // Switch between normal and extended + + if(m_hydraulicState < 100) + m_hydraulicState = 100; + else{ + if(m_fVelocityChangeForAudio > 0.1f) + m_hydraulicState = 20; + else + m_hydraulicState = 0; + } + + if(m_hydraulicState < 100){ + if(m_hydraulicState == 0){ + normalUpperLimit += -0.12f; + normalLowerLimit += 0.14f; + normalSpringLength = normalUpperLimit - normalLowerLimit; + } + + // Reset suspension to normal + float normalLineLength = normalSpringLength + wheelRadius; + CVector pos; + for(i = 0; i < 4; i++){ + wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + mi->GetWheelPosn(i, pos); + pos.z += normalUpperLimit; + specialColModel->lines[i].p0 = pos; + pos.z -= normalLineLength; + specialColModel->lines[i].p1 = pos; + m_aSuspensionSpringLength[i] = normalSpringLength; + m_aSuspensionLineLength[i] = normalLineLength; + + if(m_aSuspensionSpringRatio[i] < 1.0f){ + m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + } + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + }else{ + // Reset suspension to extended + float extendedLineLength = extendedSpringLength + wheelRadius; + CVector pos; + for(i = 0; i < 4; i++){ + wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + mi->GetWheelPosn(i, pos); + pos.z += extendedUpperLimit; + specialColModel->lines[i].p0 = pos; + pos.z -= extendedLineLength; + specialColModel->lines[i].p1 = pos; + m_aSuspensionSpringLength[i] = extendedSpringLength; + m_aSuspensionLineLength[i] = extendedLineLength; + + if(m_aSuspensionSpringRatio[i] < 1.0f){ + m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + + setPrevRatio = true; + m_aWheelPosition[i] -= 0.05f; + } + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + } + }else{ + float suspChange[4]; + float maxDelta = 0.0f; + float rear = CPad::GetPad(0)->GetCarGunUpDown()/128.0f; + float front = -rear; + float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; + float left = -right; + suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); + suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); + suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); + suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); + + if(m_hydraulicState < 100){ + // Lowered, move wheels up + + if(m_hydraulicState == 0){ + normalUpperLimit += -0.12f; + normalLowerLimit += 0.14f; + normalSpringLength = normalUpperLimit - normalLowerLimit; + } + + // Set suspension + CVector pos; + for(i = 0; i < 4; i++){ + if(suspChange[i] > 1.0f) + suspChange[i] = 1.0f; + + float oldZ = specialColModel->lines[i].p1.z; + float upperLimit = suspChange[i]*(extendedUpperLimit-normalUpperLimit) + normalUpperLimit; + float springLength = suspChange[i]*(extendedSpringLength-normalSpringLength) + normalSpringLength; + float lineLength = springLength + wheelRadius; + + wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + mi->GetWheelPosn(i, pos); + pos.z += upperLimit; + specialColModel->lines[i].p0 = pos; + pos.z -= lineLength; + if(Abs(pos.z - specialColModel->lines[i].p1.z) > Abs(maxDelta)) + maxDelta = pos.z - specialColModel->lines[i].p1.z; + specialColModel->lines[i].p1 = pos; + m_aSuspensionSpringLength[i] = springLength; + m_aSuspensionLineLength[i] = lineLength; + + if(m_aSuspensionSpringRatio[i] < 1.0f){ + m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + m_aWheelPosition[i] -= (oldZ - specialColModel->lines[i].p1.z)*0.3f; + } + } + }else{ + if(m_hydraulicState < 104){ + m_hydraulicState++; + for(i = 0; i < 4; i++) + m_aWheelPosition[i] -= 0.1f; + } + + if(m_fVelocityChangeForAudio < 0.1f){ + normalUpperLimit += -0.12f; + normalLowerLimit += 0.14f; + normalSpringLength = normalUpperLimit - normalLowerLimit; + } + + // Set suspension + CVector pos; + for(i = 0; i < 4; i++){ + if(suspChange[i] > 1.0f) + suspChange[i] = 1.0f; + + float upperLimit = suspChange[i]*(normalUpperLimit-extendedUpperLimit) + extendedUpperLimit; + float springLength = suspChange[i]*(normalSpringLength-extendedSpringLength) + extendedSpringLength; + float lineLength = springLength + wheelRadius; + + wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; + mi->GetWheelPosn(i, pos); + pos.z += upperLimit; + specialColModel->lines[i].p0 = pos; + pos.z -= lineLength; + if(Abs(pos.z - specialColModel->lines[i].p1.z) > Abs(maxDelta)) + maxDelta = pos.z - specialColModel->lines[i].p1.z; + specialColModel->lines[i].p1 = pos; + m_aSuspensionSpringLength[i] = springLength; + m_aSuspensionLineLength[i] = lineLength; + + if(m_aSuspensionSpringRatio[i] < 1.0f){ + m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; + if(m_aSuspensionSpringRatio[i] > 1.0f) + m_aSuspensionSpringRatio[i] = 1.0f; + } + } + } + + float limitDiff = extendedLowerLimit - normalLowerLimit; + if(limitDiff != 0.0f && Abs(maxDelta/limitDiff) > 0.01f){ + float f = (maxDelta + limitDiff)/2.0f/limitDiff; + f = clamp(f, 0.0f, 1.0f); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_3, f); + if(f < 0.4f || f > 0.6f) + setPrevRatio = true; + if(f < 0.25f) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); + else if(f > 0.75f) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); + } + } + + if(setPrevRatio) + for(i = 0; i < 4; i++){ + // wheel radius in relation to suspension line + float wheelRadius = 1.0f - m_aSuspensionSpringLength[i]/m_aSuspensionLineLength[i]; + m_aSuspensionSpringRatioPrev[i] = (m_aSuspensionSpringRatio[i]-wheelRadius)/(1.0f-wheelRadius); + } +} + +void +CAutomobile::ProcessBuoyancy(void) +{ + int i; + CVector impulse, point; + + if(mod_Buoyancy.ProcessBuoyancy(this, m_fBuoyancy, &point, &impulse)){ + m_flagD8 = true; + ApplyMoveForce(impulse); + ApplyTurnForce(impulse, point); + + CVector initialSpeed = m_vecMoveSpeed; + float timeStep = Max(CTimer::GetTimeStep(), 0.01f); + float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); + float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); + m_vecMoveSpeed *= waterResistance; + m_vecTurnSpeed *= waterResistance; + + if(impulseRatio > 0.5f){ + bIsInWater = true; + if(m_vecMoveSpeed.z < -0.1f) + m_vecMoveSpeed.z = -0.1f; + + if(pDriver){ + pDriver->bIsInWater = true; + if(pDriver->IsPlayer() || !bWaterTight) + pDriver->InflictDamage(nil, WEAPONTYPE_WATER, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); + } + for(i = 0; i < m_nNumMaxPassengers; i++) + if(pPassengers[i]){ + pPassengers[i]->bIsInWater = true; + if(pPassengers[i]->IsPlayer() || !bWaterTight) + pPassengers[i]->InflictDamage(nil, WEAPONTYPE_WATER, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); + } + }else + bIsInWater = false; + + static uint32 nGenerateRaindrops = 0; + static uint32 nGenerateWaterCircles = 0; + + if(initialSpeed.z < -0.3f && impulse.z > 0.3f){ + RwRGBA color; + color.red = (0.5f * CTimeCycle::GetDirectionalRed() + CTimeCycle::GetAmbientRed())*0.45f*255; + color.green = (0.5f * CTimeCycle::GetDirectionalGreen() + CTimeCycle::GetAmbientGreen())*0.45f*255; + color.blue = (0.5f * CTimeCycle::GetDirectionalBlue() + CTimeCycle::GetAmbientBlue())*0.45f*255; + color.alpha = CGeneral::GetRandomNumberInRange(0, 32) + 128; + CParticleObject::AddObject(POBJECT_CAR_WATER_SPLASH, GetPosition(), + CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.15f, 0.3f)), + 0.0f, 75, color, true); + + nGenerateRaindrops = CTimer::GetTimeInMilliseconds() + 300; + nGenerateWaterCircles = CTimer::GetTimeInMilliseconds() + 60; + if(m_vecMoveSpeed.z < -0.2f) + m_vecMoveSpeed.z = -0.2f; + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WATER_FALL, 0.0f); + } + + if(nGenerateWaterCircles > 0 && nGenerateWaterCircles < CTimer::GetTimeInMilliseconds()){ + CVector pos = GetPosition(); + float waterLevel = 0.0f; + if(CWaterLevel::GetWaterLevel(pos.x, pos.y, pos.z, &waterLevel, false)) + pos.z = waterLevel; + static RwRGBA black; + if(pos.z != 0.0f){ + nGenerateWaterCircles = 0; + pos.z += 1.0f; + for(i = 0; i < 4; i++){ + CVector p = pos; + p.x += CGeneral::GetRandomNumberInRange(-2.5f, 2.5f); + p.y += CGeneral::GetRandomNumberInRange(-2.5f, 2.5f); + CParticle::AddParticle(PARTICLE_RAIN_SPLASH_BIGGROW, + p, CVector(0.0f, 0.0f, 0.0f), + nil, 0.0f, black, 0, 0, 0, 0); + } + } + } + + if(nGenerateRaindrops > 0 && nGenerateRaindrops < CTimer::GetTimeInMilliseconds()){ + CVector pos = GetPosition(); + float waterLevel = 0.0f; + if(CWaterLevel::GetWaterLevel(pos.x, pos.y, pos.z, &waterLevel, false)) + pos.z = waterLevel; + static RwRGBA black; + if(pos.z >= 0.0f){ + nGenerateRaindrops = 0; + pos.z += 0.5; + CParticleObject::AddObject(POBJECT_SPLASHES_AROUND, + pos, CVector(0.0f, 0.0f, 0.0f), 6.5f, 2500, black, true); + } + } + }else{ + bIsInWater = false; + m_flagD8 = false; + + static RwRGBA splashCol = {155, 155, 185, 196}; + static RwRGBA smokeCol = {255, 255, 255, 255}; + + for(i = 0; i < 4; i++){ + if(m_aSuspensionSpringRatio[i] < 1.0f && m_aWheelColPoints[i].surfaceB == SURFACE_PUDDLE){ + CVector pos = m_aWheelColPoints[i].point + 0.3f*GetUp() - GetPosition(); + CVector vSpeed = GetSpeed(pos); + vSpeed.z = 0.0f; + float fSpeed = vSpeed.MagnitudeSqr(); + if(fSpeed > sq(0.05f)){ + fSpeed = Sqrt(fSpeed); + float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); + CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; + + CParticle::AddParticle(PARTICLE_PED_SPLASH, + pos + GetPosition(), -0.5f*right, + nil, size, splashCol, + CGeneral::GetRandomNumberInRange(0.0f, 10.0f), + CGeneral::GetRandomNumberInRange(0.0f, 90.0f), 1, 0); + + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, + pos + GetPosition(), -0.6f*right, + nil, size, smokeCol, 0, 0, 0, 0); + + if((CTimer::GetFrameCounter() & 0xF) == 0) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_SPLASH, 2000.0f*fSpeed); + } + } + } + } +} + +void +CAutomobile::DoDriveByShootings(void) +{ + CAnimBlendAssociation *anim; + CWeapon *weapon = pDriver->GetWeapon(); + if(weapon->m_eWeaponType != WEAPONTYPE_UZI) + return; + + weapon->Update(pDriver->m_audioEntityId); + + bool lookingLeft = false; + bool lookingRight = false; + if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1){ + if(CPad::GetPad(0)->GetLookLeft()) + lookingLeft = true; + if(CPad::GetPad(0)->GetLookRight()) + lookingRight = true; + }else{ + if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) + lookingLeft = true; + if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) + lookingRight = true; + } + + if(lookingLeft || lookingRight){ + if(lookingLeft){ + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim == nil || anim->blendDelta < 0.0f) + CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_L); + else + anim->SetRun(); + }else if(pDriver->m_pMyVehicle->pPassengers[0] == nil || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FIRSTPERSON){ + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim == nil || anim->blendDelta < 0.0f) + CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_R); + else + anim->SetRun(); + } + + if(CPad::GetPad(0)->GetCarGunFired() && CTimer::GetTimeInMilliseconds() > weapon->m_nTimer){ + weapon->FireFromCar(this, lookingLeft); + weapon->m_nTimer = CTimer::GetTimeInMilliseconds() + 70; + } + }else{ + weapon->Reload(); + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim) + anim->blendDelta = -1000.0f; + } + + // TODO: what is this? + if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ + m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); + ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); + } + if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ + m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); + ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); + } +} + +int32 +CAutomobile::RcbanditCheckHitWheels(void) +{ + int x, xmin, xmax; + int y, ymin, ymax; + + xmin = CWorld::GetSectorIndexX(GetPosition().x - 2.0f); + if(xmin < 0) xmin = 0; + xmax = CWorld::GetSectorIndexX(GetPosition().x + 2.0f); + if(xmax > NUMSECTORS_X-1) xmax = NUMSECTORS_X-1; + ymin = CWorld::GetSectorIndexX(GetPosition().y - 2.0f); + if(ymin < 0) ymin = 0; + ymax = CWorld::GetSectorIndexX(GetPosition().y + 2.0f); + if(ymax > NUMSECTORS_Y-1) ymax = NUMSECTORS_X-1; + + CWorld::AdvanceCurrentScanCode(); + + for(y = ymin; y <= ymax; y++) + for(x = xmin; x <= xmax; x++){ + CSector *s = CWorld::GetSector(x, y); + if(RcbanditCheck1CarWheels(s->m_lists[ENTITYLIST_VEHICLES]) || + RcbanditCheck1CarWheels(s->m_lists[ENTITYLIST_VEHICLES_OVERLAP])) + return 1; + } + return 0; +} + +int32 +CAutomobile::RcbanditCheck1CarWheels(CPtrList &list) +{ + static CMatrix matW2B; + int i; + CPtrNode *node; + CAutomobile *car; + CColModel *colModel = GetColModel(); + CVehicleModelInfo *mi; + + for(node = list.first; node; node = node->next){ + car = (CAutomobile*)node->item; + if(this != car && car->IsCar() && car->m_scanCode != CWorld::GetCurrentScanCode()){ + car->m_scanCode = CWorld::GetCurrentScanCode(); + + if(Abs(this->GetPosition().x - car->GetPosition().x) < 10.0f && + Abs(this->GetPosition().y - car->GetPosition().y) < 10.0f){ + mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(car->GetModelIndex()); + + for(i = 0; i < 4; i++){ + if(car->m_aSuspensionSpringRatioPrev[i] < 1.0f || car->m_status == STATUS_SIMPLE){ + CVector wheelPos; + CColSphere sph; + mi->GetWheelPosn(i, wheelPos); + matW2B = Invert(GetMatrix()); + sph.center = matW2B * (car->GetMatrix() * wheelPos); + sph.radius = mi->m_wheelScale*0.25f; + if(CCollision::TestSphereBox(sph, colModel->boundingBox)) + return 1; + } + } + } + } + } + return 0; +} + +void +CAutomobile::PlaceOnRoadProperly(void) +{ + CColPoint point; + CEntity *entity; + CColModel *colModel = GetColModel(); + float lenFwd, lenBack; + float frontZ, rearZ; + + lenFwd = colModel->boundingBox.max.y; + lenBack = -colModel->boundingBox.min.y; + + CVector front(GetPosition().x + GetForward().x*lenFwd, + GetPosition().y + GetForward().y*lenFwd, + GetPosition().z + 5.0f); + if(CWorld::ProcessVerticalLine(front, GetPosition().z - 5.0f, point, entity, + true, false, false, false, false, false, nil)){ + frontZ = point.point.z; + m_pCurGroundEntity = entity; + }else{ + frontZ = field_21C; + } + + CVector rear(GetPosition().x - GetForward().x*lenBack, + GetPosition().y - GetForward().y*lenBack, + GetPosition().z + 5.0f); + if(CWorld::ProcessVerticalLine(rear, GetPosition().z - 5.0f, point, entity, + true, false, false, false, false, false, nil)){ + rearZ = point.point.z; + m_pCurGroundEntity = entity; + }else{ + rearZ = field_220; + } + + float len = lenFwd + lenBack; + float angle = Atan((frontZ - rearZ)/len); + float c = Cos(angle); + float s = Sin(angle); + + GetRight() = CVector((front.y - rear.y)/len, -(front.x - rear.x)/len, 0.0f); + GetForward() = CVector(-c*GetRight().y, c*GetRight().x, s); + GetUp() = CrossProduct(GetRight(), GetForward()); + GetPosition() = CVector((front.x + rear.x)/2.0f, (front.y + rear.y)/2.0f, (frontZ + rearZ)/2.0f + GetHeightAboveRoad()); +} + +void +CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) +{ + int i; + float damageMultiplier = 0.2f; + bool doubleMoney = false; + + if(impulse == 0.0f){ + impulse = m_fDamageImpulse; + damagedPiece = m_nDamagePieceType; + damageMultiplier = 1.0f; + } + + CVector pos(0.0f, 0.0f, 0.0f); + + if(!bCanBeDamaged) + return; + + // damage flipped over car + if(GetUp().z < 0.0f && this != FindPlayerVehicle()){ + if(bNotDamagedUpsideDown || m_status == STATUS_PLAYER_REMOTE || bIsInWater) + return; + m_fHealth -= 4.0f*CTimer::GetTimeStep(); + } + + if(impulse > 25.0f && m_status != STATUS_WRECKED){ + if(bIsLawEnforcer && + FindPlayerVehicle() && FindPlayerVehicle() == m_pDamageEntity && + m_status != STATUS_ABANDONED && + FindPlayerVehicle()->m_vecMoveSpeed.Magnitude() >= m_vecMoveSpeed.Magnitude() && + FindPlayerVehicle()->m_vecMoveSpeed.Magnitude() > 0.1f) + FindPlayerPed()->SetWantedLevelNoDrop(1); + + if(m_status == STATUS_PLAYER && impulse > 50.0f){ + uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); + CPad::GetPad(0)->StartShake(40000/freq, freq); + } + + if(bOnlyDamagedByPlayer){ + if(m_pDamageEntity != FindPlayerPed() && + m_pDamageEntity != FindPlayerVehicle()) + return; + } + + if(bCollisionProof) + return; + + if(m_pDamageEntity){ + if(m_pDamageEntity->IsBuilding() && + DotProduct(m_vecDamageNormal, GetUp()) > 0.6f) + return; + } + + int oldLightStatus[4]; + for(i = 0; i < 4; i++) + oldLightStatus[i] = Damage.GetLightStatus((eLights)i); + + if(GetUp().z > 0.0f || m_vecMoveSpeed.MagnitudeSqr() > 0.1f){ + float impulseMult = bMoreResistantToDamage ? 0.5f : 4.0f; + + switch(damagedPiece){ + case CAR_PIECE_BUMP_FRONT: + GetComponentWorldPosition(CAR_BUMP_FRONT, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_BUMPER_FRONT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); + doubleMoney = true; + } + if(m_aCarNodes[CAR_BONNET] && Damage.GetPanelStatus(VEHBUMPER_FRONT) == PANEL_STATUS_MISSING){ + case CAR_PIECE_BONNET: + GetComponentWorldPosition(CAR_BONNET, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_DOOR_BONNET, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_BONNET, DOOR_BONNET); + doubleMoney = true; + } + } + break; + + case CAR_PIECE_BUMP_REAR: + GetComponentWorldPosition(CAR_BUMP_REAR, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_BUMPER_FRONT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); + doubleMoney = true; + } + if(m_aCarNodes[CAR_BOOT] && Damage.GetPanelStatus(VEHBUMPER_REAR) == PANEL_STATUS_MISSING){ + case CAR_PIECE_BOOT: + GetComponentWorldPosition(CAR_BOOT, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_DOOR_BOOT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_BOOT, DOOR_BOOT); + doubleMoney = true; + } + } + break; + + case CAR_PIECE_DOOR_LF: + GetComponentWorldPosition(CAR_DOOR_LF, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && + Damage.ApplyDamage(COMPONENT_DOOR_FRONT_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); + doubleMoney = true; + } + break; + case CAR_PIECE_DOOR_RF: + GetComponentWorldPosition(CAR_DOOR_RF, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && + Damage.ApplyDamage(COMPONENT_DOOR_FRONT_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); + doubleMoney = true; + } + break; + case CAR_PIECE_DOOR_LR: + GetComponentWorldPosition(CAR_DOOR_LR, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && + Damage.ApplyDamage(COMPONENT_DOOR_REAR_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); + doubleMoney = true; + } + break; + case CAR_PIECE_DOOR_RR: + GetComponentWorldPosition(CAR_DOOR_RR, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && + Damage.ApplyDamage(COMPONENT_DOOR_REAR_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); + doubleMoney = true; + } + break; + + case CAR_PIECE_WING_LF: + GetComponentWorldPosition(CAR_WING_LF, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_PANEL_FRONT_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetPanelDamage(CAR_WING_LF, VEHPANEL_FRONT_LEFT); + doubleMoney = true; + } + break; + case CAR_PIECE_WING_RF: + GetComponentWorldPosition(CAR_WING_RF, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_PANEL_FRONT_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetPanelDamage(CAR_WING_RF, VEHPANEL_FRONT_RIGHT); + doubleMoney = true; + } + break; + case CAR_PIECE_WING_LR: + GetComponentWorldPosition(CAR_WING_LR, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_PANEL_REAR_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetPanelDamage(CAR_WING_LR, VEHPANEL_REAR_LEFT); + doubleMoney = true; + } + break; + case CAR_PIECE_WING_RR: + GetComponentWorldPosition(CAR_WING_RR, pos); + dmgDrawCarCollidingParticles(pos, impulse); + if(Damage.ApplyDamage(COMPONENT_PANEL_REAR_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + SetPanelDamage(CAR_WING_RR, VEHPANEL_REAR_RIGHT); + doubleMoney = true; + } + break; + + case CAR_PIECE_WHEEL_LF: + case CAR_PIECE_WHEEL_LR: + case CAR_PIECE_WHEEL_RF: + case CAR_PIECE_WHEEL_RR: + break; + + case CAR_PIECE_WINDSCREEN: + if(Damage.ApplyDamage(COMPONENT_PANEL_WINDSCREEN, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ + uint8 oldStatus = Damage.GetPanelStatus(VEHPANEL_WINDSCREEN); + SetPanelDamage(CAR_WINDSCREEN, VEHPANEL_WINDSCREEN); + if(oldStatus != Damage.GetPanelStatus(VEHPANEL_WINDSCREEN)){ + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_WINDSHIELD_CRACK, 0.0f); + doubleMoney = true; + } + } + break; + } + + if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ + int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; + money = Min(money, 40); + if(money > 2){ + sprintf(gString, "$%d", money); + CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; + } + } + } + + float damage = (impulse-25.0f)*pHandling->fCollisionDamageMultiplier*0.6f*damageMultiplier; + + if(GetModelIndex() == MI_SECURICA && m_pDamageEntity && m_pDamageEntity->m_status == STATUS_PLAYER) + damage *= 7.0f; + + if(damage > 0.0f){ + int oldHealth = m_fHealth; + if(this == FindPlayerVehicle()){ + m_fHealth -= bTakeLessDamage ? damage/6.0f : damage/2.0f; + }else{ + if(damage > 35.0f && pDriver) + pDriver->Say(SOUND_PED_CAR_COLLISION); + m_fHealth -= bTakeLessDamage ? damage/12.0f : damage/4.0f; + } + if(m_fHealth <= 0.0f && oldHealth > 0) + m_fHealth = 1.0f; + } + + // play sound if a light broke + for(i = 0; i < 4; i++) + if(oldLightStatus[i] != 1 && Damage.GetLightStatus((eLights)i) == 1){ + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_LIGHT_BREAK, i); // BUG? i? + break; + } + } + + if(m_fHealth < 250.0f){ + // Car is on fire + if(Damage.GetEngineStatus() < ENGINE_STATUS_ON_FIRE){ + // Set engine on fire and remember who did this + Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE); + m_fFireBlowUpTimer = 0.0f; + m_pSetOnFireEntity = m_pDamageEntity; + if(m_pSetOnFireEntity) + m_pSetOnFireEntity->RegisterReference(&m_pSetOnFireEntity); + } + }else{ + if(GetModelIndex() == MI_BFINJECT){ + if(m_fHealth < 400.0f) + Damage.SetEngineStatus(200); + else if(m_fHealth < 600.0f) + Damage.SetEngineStatus(100); + } + } +} + +void +CAutomobile::dmgDrawCarCollidingParticles(const CVector &pos, float amount) +{ + int i, n; + + if(!GetIsOnScreen()) + return; + + // FindPlayerSpeed() unused + + n = (int)amount/20; + + for(i = 0; i < ((n+4)&0x1F); i++) + CParticle::AddParticle(PARTICLE_SPARK_SMALL, pos, + CVector(CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), + CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), + 0.006f)); + + for(i = 0; i < n+2; i++) + CParticle::AddParticle(PARTICLE_CARCOLLISION_DUST, + CVector(CGeneral::GetRandomNumberInRange(-1.2f, 1.2f) + pos.x, + CGeneral::GetRandomNumberInRange(-1.2f, 1.2f) + pos.y, + pos.z), + CVector(0.0f, 0.0f, 0.0f), nil, 0.5f); + + n = (int)amount/50 + 1; + for(i = 0; i < n; i++) + CParticle::AddParticle(PARTICLE_CAR_DEBRIS, pos, + CVector(CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), + CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), + CGeneral::GetRandomNumberInRange(0.1f, 0.25f)), + nil, + CGeneral::GetRandomNumberInRange(0.02f, 0.08f), + CVehicleModelInfo::ms_vehicleColourTable[m_currentColour1], + CGeneral::GetRandomNumberInRange(-40.0f, 40.0f), + 0, + CGeneral::GetRandomNumberInRange(0.0f, 4.0f)); +} + +void +CAutomobile::AddDamagedVehicleParticles(void) +{ + if(this == FindPlayerVehicle() && TheCamera.GetLookingForwardFirstPerson()) + return; + + uint8 engineStatus = Damage.GetEngineStatus(); + if(engineStatus < ENGINE_STATUS_STEAM1) + return; + + float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()) * 180.0f; + CVector direction = 0.5f*m_vecMoveSpeed; + CVector damagePos = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_positions[CAR_POS_HEADLIGHTS]; + + switch(Damage.GetDoorStatus(DOOR_BONNET)){ + case DOOR_STATUS_OK: + case DOOR_STATUS_SMASHED: + // Bonnet is still there, smoke comes out at the edge + damagePos += vecDAMAGE_ENGINE_POS_SMALL; + break; + case DOOR_STATUS_SWINGING: + case DOOR_STATUS_MISSING: + // Bonnet is gone, smoke comes out at the engine + damagePos += vecDAMAGE_ENGINE_POS_BIG; + break; + } + + if(GetModelIndex() == MI_BFINJECT) + damagePos = CVector(0.3f, -1.5f, -0.1f); + + damagePos = GetMatrix()*damagePos; + damagePos.z += 0.15f; + + if(engineStatus < ENGINE_STATUS_STEAM2){ + if(fwdSpeed < 90.0f){ + direction.z += 0.05f; + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.1f); + } + }else if(engineStatus < ENGINE_STATUS_SMOKE){ + if(fwdSpeed < 90.0f) + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.0f); + }else if(engineStatus < ENGINE_STATUS_ON_FIRE){ + if(fwdSpeed < 90.0f){ + CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.0f); + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, damagePos, 0.3f*direction, nil, 0.0f); + } + }else if(m_fHealth > 250.0f){ + if(fwdSpeed < 90.0f) + CParticle::AddParticle(PARTICLE_ENGINE_SMOKE2, damagePos, 0.2f*direction, nil, 0.0f); + } +} + +int32 +CAutomobile::AddWheelDirtAndWater(CColPoint *colpoint, uint32 belowEffectSpeed) +{ + int i; + CVector dir; + static RwRGBA grassCol = { 8, 24, 8, 255 }; + static RwRGBA dirtCol = { 64, 64, 64, 255 }; + static RwRGBA dirttrackCol = { 64, 32, 16, 255 }; + static RwRGBA waterCol = { 48, 48, 64, 0 }; + + if(!belowEffectSpeed) + return 0; + + switch(colpoint->surfaceB){ + case SURFACE_GRASS: + dir.x = -0.05f*m_vecMoveSpeed.x; + dir.y = -0.05f*m_vecMoveSpeed.y; + for(i = 0; i < 4; i++){ + dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); + CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, + CGeneral::GetRandomNumberInRange(0.02f, 0.1f), grassCol); + } + return 0; + case SURFACE_DIRT: + dir.x = -0.05f*m_vecMoveSpeed.x; + dir.y = -0.05f*m_vecMoveSpeed.y; + for(i = 0; i < 4; i++){ + dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); + CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, + CGeneral::GetRandomNumberInRange(0.02f, 0.06f), dirtCol); + } + return 1; + case SURFACE_DIRTTRACK: + dir.x = -0.05f*m_vecMoveSpeed.x; + dir.y = -0.05f*m_vecMoveSpeed.y; + for(i = 0; i < 4; i++){ + dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); + CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, + CGeneral::GetRandomNumberInRange(0.02f, 0.06f), dirttrackCol); + } + return 0; + default: + // Is this even visible? + if(CWeather::WetRoads > 0.01f && CTimer::GetFrameCounter() & 1){ + CParticle::AddParticle(PARTICLE_WATERSPRAY, + colpoint->point + CVector(0.0f, 0.0f, 0.25f+0.25f), + CVector(0.0f, 0.0f, 1.0f), nil, + CGeneral::GetRandomNumberInRange(0.1f, 0.5f), waterCol); + return 0; + } + return 1; + } +} + +void +CAutomobile::GetComponentWorldPosition(int32 component, CVector &pos) +{ + if(m_aCarNodes[component] == nil){ + printf("CarNode missing: %d %d\n", GetModelIndex(), component); + return; + } + RwMatrix *ltm = RwFrameGetLTM(m_aCarNodes[component]); + pos = *RwMatrixGetPos(ltm); +} + +bool +CAutomobile::IsComponentPresent(int32 comp) +{ + return m_aCarNodes[comp] != nil; +} + +void +CAutomobile::SetComponentRotation(int32 component, CVector rotation) +{ + CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); + CVector pos = mat.GetPosition(); + // BUG: all these set the whole matrix + mat.SetRotateX(DEGTORAD(rotation.x)); + mat.SetRotateY(DEGTORAD(rotation.y)); + mat.SetRotateZ(DEGTORAD(rotation.z)); + mat.Translate(pos); + mat.UpdateRW(); +} + +void +CAutomobile::OpenDoor(int32 component, eDoors door, float openRatio) +{ + CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); + CVector pos = mat.GetPosition(); + float axes[3] = { 0.0f, 0.0f, 0.0f }; + float wasClosed = false; + + if(Doors[door].IsClosed()){ + // enable angle cull for closed doors + RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::ClearAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); + wasClosed = true; + } + + Doors[door].Open(openRatio); + + if(wasClosed && Doors[door].RetAngleWhenClosed() != Doors[door].m_fAngle){ + // door opened + HideAllComps(); + // turn off angle cull for swinging door + RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_OPEN_BONNET + door, 0.0f); + } + + if(!wasClosed && openRatio == 0.0f){ + // door closed + if(Damage.GetDoorStatus(door) == DOOR_STATUS_SWINGING) + Damage.SetDoorStatus(door, DOOR_STATUS_OK); // huh? + ShowAllComps(); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_CLOSE_BONNET + door, 0.0f); + } + + axes[Doors[door].m_nAxis] = Doors[door].m_fAngle; + mat.SetRotate(axes[0], axes[1], axes[2]); + mat.Translate(pos); + mat.UpdateRW(); +} + +inline void ProcessDoorOpenAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end) +{ + if(time > start && time < end){ + float ratio = (time - start)/(end - start); + if(car->Doors[door].GetAngleOpenRatio() < ratio) + car->OpenDoor(component, door, ratio); + }else if(time > end){ + car->OpenDoor(component, door, 1.0f); + } +} + +inline void ProcessDoorCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end) +{ + if(time > start && time < end){ + float ratio = 1.0f - (time - start)/(end - start); + if(car->Doors[door].GetAngleOpenRatio() > ratio) + car->OpenDoor(component, door, ratio); + }else if(time > end){ + car->OpenDoor(component, door, 0.0f); + } +} + +inline void ProcessDoorOpenCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float mid, float end) +{ + if(time > start && time < mid){ + // open + float ratio = (time - start)/(mid - start); + if(car->Doors[door].GetAngleOpenRatio() < ratio) + car->OpenDoor(component, door, ratio); + }else if(time > mid && time < end){ + // close + float ratio = 1.0f - (time - mid)/(end - mid); + if(car->Doors[door].GetAngleOpenRatio() > ratio) + car->OpenDoor(component, door, ratio); + }else if(time > end){ + car->OpenDoor(component, door, 0.0f); + } +} +void +CAutomobile::ProcessOpenDoor(uint32 component, uint32 anim, float time) +{ + eDoors door; + + switch(component){ + case CAR_DOOR_RF: door = DOOR_FRONT_RIGHT; break; + case CAR_DOOR_RR: door = DOOR_REAR_RIGHT; break; + case CAR_DOOR_LF: door = DOOR_FRONT_LEFT; break; + case CAR_DOOR_LR: door = DOOR_REAR_LEFT; break; + default: assert(0); + } + + if(IsDoorMissing(door)) + return; + + switch(anim){ + case ANIM_CAR_QJACK: + case ANIM_CAR_OPEN_LHS: + case ANIM_CAR_OPEN_RHS: + ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f); + break; + case ANIM_CAR_CLOSEDOOR_LHS: + case ANIM_CAR_CLOSEDOOR_LOW_LHS: + case ANIM_CAR_CLOSEDOOR_RHS: + case ANIM_CAR_CLOSEDOOR_LOW_RHS: + ProcessDoorCloseAnimation(this, component, door, time, 0.2f, 0.63f); + break; + case ANIM_CAR_ROLLDOOR: + case ANIM_CAR_ROLLDOOR_LOW: + ProcessDoorOpenCloseAnimation(this, component, door, time, 0.1f, 0.6f, 0.95f); + break; + break; + case ANIM_CAR_GETOUT_LHS: + case ANIM_CAR_GETOUT_LOW_LHS: + case ANIM_CAR_GETOUT_RHS: + case ANIM_CAR_GETOUT_LOW_RHS: + ProcessDoorOpenAnimation(this, component, door, time, 0.06f, 0.43f); + break; + case ANIM_CAR_CLOSE_LHS: + case ANIM_CAR_CLOSE_RHS: + ProcessDoorCloseAnimation(this, component, door, time, 0.1f, 0.23f); + break; + case ANIM_CAR_PULLOUT_RHS: + case ANIM_CAR_PULLOUT_LOW_RHS: + OpenDoor(component, door, 1.0f); + case ANIM_COACH_OPEN_L: + case ANIM_COACH_OPEN_R: + ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f); + break; + case ANIM_COACH_OUT_L: + ProcessDoorOpenAnimation(this, component, door, time, 0.0f, 0.3f); + break; + case ANIM_VAN_OPEN_L: + case ANIM_VAN_OPEN: + ProcessDoorOpenAnimation(this, component, door, time, 0.37f, 0.55f); + break; + case ANIM_VAN_CLOSE_L: + case ANIM_VAN_CLOSE: + ProcessDoorCloseAnimation(this, component, door, time, 0.5f, 0.8f); + break; + case ANIM_VAN_GETOUT_L: + case ANIM_VAN_GETOUT: + ProcessDoorOpenAnimation(this, component, door, time, 0.5f, 0.6f); + break; + case NUM_ANIMS: + OpenDoor(component, door, time); + break; + } +} + +bool +CAutomobile::IsDoorReady(eDoors door) +{ + if(Doors[door].IsClosed() || IsDoorMissing(door)) + return true; + int doorflag = 0; + // TODO: enum? + switch(door){ + case DOOR_FRONT_LEFT: doorflag = 1; break; + case DOOR_FRONT_RIGHT: doorflag = 4; break; + case DOOR_REAR_LEFT: doorflag = 2; break; + case DOOR_REAR_RIGHT: doorflag = 8; break; + } + return (doorflag & m_nGettingInFlags) == 0; +} + +bool +CAutomobile::IsDoorFullyOpen(eDoors door) +{ + return Doors[door].IsFullyOpen() || IsDoorMissing(door); +} + +bool +CAutomobile::IsDoorClosed(eDoors door) +{ + return !!Doors[door].IsClosed(); +} + +bool +CAutomobile::IsDoorMissing(eDoors door) +{ + return Damage.GetDoorStatus(door) == DOOR_STATUS_MISSING; +} + +void +CAutomobile::RemoveRefsToVehicle(CEntity *ent) +{ + int i; + for(i = 0; i < 4; i++) + if(m_aGroundPhysical[i] == ent) + m_aGroundPhysical[i] = nil; +} + +void +CAutomobile::BlowUpCar(CEntity *culprit) +{ + int i; + RpAtomic *atomic; + + if(!bCanBeDamaged) + return; + + // explosion pushes vehicle up + m_vecMoveSpeed.z += 0.13f; + m_status = STATUS_WRECKED; + bRenderScorched = true; + m_nTimeOfDeath = CTimer::GetTimeInMilliseconds(); + Damage.FuckCarCompletely(); + + if(GetModelIndex() != MI_RCBANDIT){ + SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); + SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); + SetDoorDamage(CAR_BONNET, DOOR_BONNET); + SetDoorDamage(CAR_BOOT, DOOR_BOOT); + SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); + SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); + SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); + SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); + SpawnFlyingComponent(CAR_WHEEL_LF, COMPGROUP_WHEEL); + atomic = nil; + RwFrameForAllObjects(m_aCarNodes[CAR_WHEEL_LF], GetCurrentAtomicObjectCB, &atomic); + if(atomic) + RpAtomicSetFlags(atomic, 0); + } + + m_fHealth = 0.0f; + m_nBombTimer = 0; + m_bombType = CARBOMB_NONE; + + TheCamera.CamShake(0.7f, GetPosition().x, GetPosition().y, GetPosition().z); + + // kill driver and passengers + if(pDriver){ + CDarkel::RegisterKillByPlayer(pDriver, WEAPONTYPE_EXPLOSION); + if(pDriver->GetPedState() == PED_DRIVING){ + pDriver->SetDead(); + if(!pDriver->IsPlayer()) + pDriver->FlagToDestroyWhenNextProcessed(); + }else + pDriver->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + } + for(i = 0; i < m_nNumMaxPassengers; i++){ + if(pPassengers[i]){ + CDarkel::RegisterKillByPlayer(pPassengers[i], WEAPONTYPE_EXPLOSION); + if(pPassengers[i]->GetPedState() == PED_DRIVING){ + pPassengers[i]->SetDead(); + if(!pPassengers[i]->IsPlayer()) + pPassengers[i]->FlagToDestroyWhenNextProcessed(); + }else + pPassengers[i]->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + } + } + + bEngineOn = false; + bLightsOn = false; + m_bSirenOrAlarm = false; + bTaxiLight = false; + if(bIsAmbulanceOnDuty){ + bIsAmbulanceOnDuty = false; + CCarCtrl::NumAmbulancesOnDuty--; + } + if(bIsFireTruckOnDuty){ + bIsFireTruckOnDuty = false; + CCarCtrl::NumFiretrucksOnDuty--; + } + ChangeLawEnforcerState(false); + + gFireManager.StartFire(this, culprit, 0.8f, 1); // TODO + CDarkel::RegisterCarBlownUpByPlayer(this); + if(GetModelIndex() == MI_RCBANDIT) + CExplosion::AddExplosion(this, culprit, EXPLOSION_CAR_QUICK, GetPosition(), 0); + else + CExplosion::AddExplosion(this, culprit, EXPLOSION_CAR, GetPosition(), 0); +} + +bool +CAutomobile::SetUpWheelColModel(CColModel *colModel) +{ + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + CColModel *vehColModel = mi->GetColModel(); + + colModel->boundingSphere = vehColModel->boundingSphere; + colModel->boundingBox = vehColModel->boundingBox; + + CMatrix mat; + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); + colModel->spheres[0].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LF); + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); + colModel->spheres[1].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LR); + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); + colModel->spheres[2].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF); + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); + colModel->spheres[3].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR); + + if(m_aCarNodes[CAR_WHEEL_LM] != nil && m_aCarNodes[CAR_WHEEL_RM] != nil){ + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM])); + colModel->spheres[4].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF); + mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM])); + colModel->spheres[5].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR); + colModel->numSpheres = 6; + }else + colModel->numSpheres = 4; + + return true; +} + +// this probably isn't used in III yet +void +CAutomobile::BurstTyre(uint8 wheel) +{ + switch(wheel){ + case CAR_PIECE_WHEEL_LF: wheel = VEHWHEEL_FRONT_LEFT; break; + case CAR_PIECE_WHEEL_LR: wheel = VEHWHEEL_REAR_LEFT; break; + case CAR_PIECE_WHEEL_RF: wheel = VEHWHEEL_FRONT_RIGHT; break; + case CAR_PIECE_WHEEL_RR: wheel = VEHWHEEL_REAR_RIGHT; break; + } + + int status = Damage.GetWheelStatus(wheel); + if(status == WHEEL_STATUS_OK){ + Damage.SetWheelStatus(wheel, WHEEL_STATUS_BURST); + + if(m_status == STATUS_SIMPLE){ + m_status = STATUS_PHYSICS; + CCarCtrl::SwitchVehicleToRealPhysics(this); + } + + ApplyMoveForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f)); + ApplyTurnForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f), GetForward()); + } +} + +bool +CAutomobile::IsRoomForPedToLeaveCar(uint32 component, CVector *doorOffset) +{ + CColPoint colpoint; + CEntity *ent; + colpoint.point = CVector(0.0f, 0.0f, 0.0f); + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + + CVector seatPos; + switch(component){ + case CAR_DOOR_RF: + seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; + break; + case CAR_DOOR_LF: + seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; + seatPos.x = -seatPos.x; + break; + case CAR_DOOR_RR: + seatPos = mi->m_positions[CAR_POS_BACKSEAT]; + break; + case CAR_DOOR_LR: + seatPos = mi->m_positions[CAR_POS_BACKSEAT]; + seatPos.x = -seatPos.x; + break; + } + seatPos = GetMatrix() * seatPos; + + CVector doorPos = CPed::GetPositionToOpenCarDoor(this, component); + if(doorOffset){ + CVector off = *doorOffset; + if(component == CAR_DOOR_RF || component == CAR_DOOR_RR) + off.x = -off.x; + doorPos += Multiply3x3(GetMatrix(), off); + } + + if(GetUp().z < 0.0f){ + seatPos.z += 0.5f; + doorPos.z += 0.5f; + } + + CVector dist = doorPos - seatPos; + float length = dist.Magnitude(); + CVector pedPos = seatPos + dist*((length+0.6f)/length); + + if(!CWorld::GetIsLineOfSightClear(seatPos, pedPos, true, false, false, true, false, false)) + return false; + if(CWorld::TestSphereAgainstWorld(doorPos, 0.6f, this, true, true, false, true, false, false)) + return false; + if(CWorld::ProcessVerticalLine(doorPos, 1000.0f, colpoint, ent, true, false, false, true, false, false, nil)) + if(colpoint.point.z > doorPos.z && colpoint.point.z < doorPos.z + 0.6f) + return false; + float upperZ = colpoint.point.z; + if(!CWorld::ProcessVerticalLine(doorPos, -1000.0f, colpoint, ent, true, false, false, true, false, false, nil)) + return false; + if(upperZ != 0.0f && upperZ < colpoint.point.z) + return false; + return true; +} + +float +CAutomobile::GetHeightAboveRoad(void) +{ + return m_fHeightAboveRoad; +} + +void +CAutomobile::PlayCarHorn(void) +{ + int r; + + if(m_nCarHornTimer != 0) + return; + + r = CGeneral::GetRandomNumber() & 7; + if(r < 2){ + m_nCarHornTimer = 45; + }else if(r < 4){ + if(pDriver) + pDriver->Say(SOUND_PED_CAR_COLLISION); + m_nCarHornTimer = 45; + }else{ + if(pDriver) + pDriver->Say(SOUND_PED_CAR_COLLISION); + } +} + +void +CAutomobile::PlayHornIfNecessary(void) +{ + if(AutoPilot.m_bSlowedDownBecauseOfPeds || + AutoPilot.m_bSlowedDownBecauseOfCars) + if(!HasCarStoppedBecauseOfLight()) + PlayCarHorn(); +} + + +void +CAutomobile::ResetSuspension(void) +{ + int i; + for(i = 0; i < 4; i++){ + m_aSuspensionSpringRatio[i] = 1.0f; + m_aWheelTimer[i] = 0.0f; + m_aWheelRotation[i] = 0.0f; + m_aWheelState[i] = WHEEL_STATE_NORMAL; + } +} + +void +CAutomobile::SetupSuspensionLines(void) +{ + int i; + CVector posn; + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + CColModel *colModel = mi->GetColModel(); + + // Each suspension line starts at the uppermost wheel position + // and extends down to the lowermost point on the tyre + for(i = 0; i < 4; i++){ + mi->GetWheelPosn(i, posn); + m_aWheelPosition[i] = posn.z; + + // uppermost wheel position + posn.z += pHandling->fSuspensionUpperLimit; + colModel->lines[i].p0 = posn; + + // lowermost wheel position + posn.z += pHandling->fSuspensionLowerLimit - pHandling->fSuspensionUpperLimit; + // lowest point on tyre + posn.z -= mi->m_wheelScale*0.5f; + colModel->lines[i].p1 = posn; + + // this is length of the spring at rest + m_aSuspensionSpringLength[i] = pHandling->fSuspensionUpperLimit - pHandling->fSuspensionLowerLimit; + m_aSuspensionLineLength[i] = colModel->lines[i].p0.z - colModel->lines[i].p1.z; + } + + // Compress spring somewhat to get normal height on road + m_fHeightAboveRoad = -(colModel->lines[0].p0.z + (colModel->lines[0].p1.z - colModel->lines[0].p0.z)* + (1.0f - 1.0f/(8.0f*pHandling->fSuspensionForceLevel))); + for(i = 0; i < 4; i++) + m_aWheelPosition[i] = mi->m_wheelScale*0.5f - m_fHeightAboveRoad; + + // adjust col model to include suspension lines + if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) + colModel->boundingBox.min.z = colModel->lines[0].p1.z; + float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); + if(colModel->boundingSphere.radius < radius) + colModel->boundingSphere.radius = radius; + + if(GetModelIndex() == MI_RCBANDIT){ + colModel->boundingSphere.radius = 2.0f; + for(i = 0; i < colModel->numSpheres; i++) + colModel->spheres[i].radius = 0.3f; + } +} + +// called on police cars +void +CAutomobile::ScanForCrimes(void) +{ + if(FindPlayerVehicle() && FindPlayerVehicle()->IsCar()) + if(FindPlayerVehicle()->IsAlarmOn()) + // if player's alarm is on, increase wanted level + if((FindPlayerVehicle()->GetPosition() - GetPosition()).MagnitudeSqr() < sq(20.0f)) + CWorld::Players[CWorld::PlayerInFocus].m_pPed->SetWantedLevelNoDrop(1); +} + +void +CAutomobile::BlowUpCarsInPath(void) +{ + int i; + + if(m_vecMoveSpeed.Magnitude() > 0.1f) + for(i = 0; i < m_nCollisionRecords; i++) + if(m_aCollisionRecords[i] && + m_aCollisionRecords[i]->IsVehicle() && + m_aCollisionRecords[i]->GetModelIndex() != MI_RHINO && + !m_aCollisionRecords[i]->bRenderScorched) + ((CVehicle*)m_aCollisionRecords[i])->BlowUpCar(this); +} + +bool +CAutomobile::HasCarStoppedBecauseOfLight(void) +{ + int i; + + if(m_status != STATUS_SIMPLE && m_status != STATUS_PHYSICS) + return false; + + if(AutoPilot.m_nCurrentRouteNode && AutoPilot.m_nNextRouteNode){ + CPathNode *curnode = &ThePaths.m_pathNodes[AutoPilot.m_nCurrentRouteNode]; + for(i = 0; i < curnode->numLinks; i++) + if(ThePaths.m_connections[curnode->firstLink + i] == AutoPilot.m_nNextRouteNode) + break; + if(i < curnode->numLinks && + ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO + return true; + } + + if(AutoPilot.m_nCurrentRouteNode && AutoPilot.m_nPrevRouteNode){ + CPathNode *curnode = &ThePaths.m_pathNodes[AutoPilot.m_nCurrentRouteNode]; + for(i = 0; i < curnode->numLinks; i++) + if(ThePaths.m_connections[curnode->firstLink + i] == AutoPilot.m_nPrevRouteNode) + break; + if(i < curnode->numLinks && + ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO + return true; + } + + return false; +} + +void +CAutomobile::SetBusDoorTimer(uint32 timer, uint8 type) +{ + if(timer < 1000) + timer = 1000; + if(type == 0) + // open and close + m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds(); + else + // only close + m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds() - 500; + m_nBusDoorTimerEnd = m_nBusDoorTimerStart + timer; +} + +void +CAutomobile::ProcessAutoBusDoors(void) +{ + if(CTimer::GetTimeInMilliseconds() < m_nBusDoorTimerEnd){ + if(m_nBusDoorTimerEnd != 0 && CTimer::GetTimeInMilliseconds() > m_nBusDoorTimerEnd-500){ + // close door + if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0){ + if(IsDoorClosed(DOOR_FRONT_LEFT)){ + m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds(); + OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f); + }else{ + OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, + 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f); + } + } + + if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0){ + if(IsDoorClosed(DOOR_FRONT_RIGHT)){ + m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds(); + OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f); + }else{ + OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, + 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f); + } + } + } + }else{ + // ended + if(m_nBusDoorTimerStart){ + if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0) + OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f); + if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0) + OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f); + m_nBusDoorTimerStart = 0; + m_nBusDoorTimerEnd = 0; + } + } +} + +void +CAutomobile::ProcessSwingingDoor(int32 component, eDoors door) +{ + if(Damage.GetDoorStatus(door) != DOOR_STATUS_SWINGING) + return; + + CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); + CVector pos = mat.GetPosition(); + float axes[3] = { 0.0f, 0.0f, 0.0f }; + + Doors[door].Process(this); + axes[Doors[door].m_nAxis] = Doors[door].m_fAngle; + mat.SetRotate(axes[0], axes[1], axes[2]); + mat.Translate(pos); + mat.UpdateRW(); +} + +void +CAutomobile::Fix(void) +{ + int component; + + Damage.ResetDamageStatus(); + + if(pHandling->Flags & HANDLING_NO_DOORS){ + Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_REAR_LEFT, DOOR_STATUS_MISSING); + Damage.SetDoorStatus(DOOR_REAR_RIGHT, DOOR_STATUS_MISSING); + } + + bIsDamaged = false; + RpClumpForAllAtomics((RpClump*)m_rwObject, CVehicleModelInfo::HideAllComponentsAtomicCB, (void*)ATOMIC_FLAG_DAM); + + for(component = CAR_BUMP_FRONT; component < NUM_CAR_NODES; component++){ + if(m_aCarNodes[component]){ + CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); + mat.SetTranslate(mat.GetPosition()); + mat.UpdateRW(); + } + } +} + +void +CAutomobile::SetupDamageAfterLoad(void) +{ + if(m_aCarNodes[CAR_BUMP_FRONT]) + SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); + if(m_aCarNodes[CAR_BONNET]) + SetDoorDamage(CAR_BONNET, DOOR_BONNET); + if(m_aCarNodes[CAR_BUMP_REAR]) + SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); + if(m_aCarNodes[CAR_BOOT]) + SetDoorDamage(CAR_BOOT, DOOR_BOOT); + if(m_aCarNodes[CAR_DOOR_LF]) + SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); + if(m_aCarNodes[CAR_DOOR_RF]) + SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); + if(m_aCarNodes[CAR_DOOR_LR]) + SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); + if(m_aCarNodes[CAR_DOOR_RR]) + SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); + if(m_aCarNodes[CAR_WING_LF]) + SetPanelDamage(CAR_WING_LF, VEHPANEL_FRONT_LEFT); + if(m_aCarNodes[CAR_WING_RF]) + SetPanelDamage(CAR_WING_RF, VEHPANEL_FRONT_RIGHT); + if(m_aCarNodes[CAR_WING_LR]) + SetPanelDamage(CAR_WING_LR, VEHPANEL_REAR_LEFT); + if(m_aCarNodes[CAR_WING_RR]) + SetPanelDamage(CAR_WING_RR, VEHPANEL_REAR_RIGHT); +} + +RwObject* +GetCurrentAtomicObjectCB(RwObject *object, void *data) +{ + RpAtomic *atomic = (RpAtomic*)object; + assert(RwObjectGetType(object) == rpATOMIC); + if(RpAtomicGetFlags(atomic) & rpATOMICRENDER) + *(RpAtomic**)data = atomic; + return object; +} + +CColPoint aTempPedColPts[32]; // this name doesn't make any sense + +CObject* +CAutomobile::SpawnFlyingComponent(int32 component, uint32 type) +{ + RpAtomic *atomic; + RwFrame *frame; + RwMatrix *matrix; + CObject *obj; + + if(CObject::nNoTempObjects >= NUMTEMPOBJECTS) + return nil; + + atomic = nil; + RwFrameForAllObjects(m_aCarNodes[component], GetCurrentAtomicObjectCB, &atomic); + if(atomic == nil) + return nil; + + obj = new CObject; + if(obj == nil) + return nil; + + if(component == CAR_WINDSCREEN){ + obj->SetModelIndexNoCreate(MI_CAR_BONNET); + }else switch(type){ + case COMPGROUP_BUMPER: + obj->SetModelIndexNoCreate(MI_CAR_BUMPER); + break; + case COMPGROUP_WHEEL: + obj->SetModelIndexNoCreate(MI_CAR_WHEEL); + break; + case COMPGROUP_DOOR: + obj->SetModelIndexNoCreate(MI_CAR_DOOR); + obj->SetCenterOfMass(0.0f, -0.5f, 0.0f); + break; + case COMPGROUP_BONNET: + obj->SetModelIndexNoCreate(MI_CAR_BONNET); + obj->SetCenterOfMass(0.0f, 0.4f, 0.0f); + break; + case COMPGROUP_BOOT: + obj->SetModelIndexNoCreate(MI_CAR_BOOT); + obj->SetCenterOfMass(0.0f, -0.3f, 0.0f); + break; + case COMPGROUP_PANEL: + default: + obj->SetModelIndexNoCreate(MI_CAR_PANEL); + break; + } + + // object needs base model + obj->RefModelInfo(GetModelIndex()); + + // create new atomic + matrix = RwFrameGetLTM(m_aCarNodes[component]); + frame = RwFrameCreate(); + atomic = RpAtomicClone(atomic); + *RwFrameGetMatrix(frame) = *matrix; + RpAtomicSetFrame(atomic, frame); + CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); + obj->AttachToRwObject((RwObject*)atomic); + + // init object + obj->m_fMass = 10.0f; + obj->m_fTurnMass = 25.0f; + obj->m_fAirResistance = 0.97f; + obj->m_fElasticity = 0.1f; + obj->m_fBuoyancy = obj->m_fMass*GRAVITY/0.75f; + obj->ObjectCreatedBy = TEMP_OBJECT; + obj->bIsStatic = false; + obj->bIsPickup = false; + obj->bUseVehicleColours = true; + obj->m_colour1 = m_currentColour1; + obj->m_colour2 = m_currentColour2; + + // life time - the more objects the are, the shorter this one will live + CObject::nNoTempObjects++; + if(CObject::nNoTempObjects > 20) + obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/5.0f; + else if(CObject::nNoTempObjects > 10) + obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/2.0f; + else + obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000; + + obj->m_vecMoveSpeed = m_vecMoveSpeed; + if(obj->m_vecMoveSpeed.z > 0.0f){ + obj->m_vecMoveSpeed.z *= 1.5f; + }else if(GetUp().z > 0.0f && + (component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN)){ + obj->m_vecMoveSpeed.z *= -1.5f; + obj->m_vecMoveSpeed.z += 0.04f; + }else{ + obj->m_vecMoveSpeed.z *= 0.25f; + } + obj->m_vecMoveSpeed.x *= 0.75f; + obj->m_vecMoveSpeed.y *= 0.75f; + + obj->m_vecTurnSpeed = m_vecTurnSpeed*2.0f; + + // push component away from car + CVector dist = obj->GetPosition() - GetPosition(); + dist.Normalise(); + if(component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN){ + // push these up some + dist += GetUp(); + if(GetUp().z > 0.0f){ + // simulate fast upward movement if going fast + float speed = CVector2D(m_vecMoveSpeed).MagnitudeSqr(); + obj->GetPosition() += GetUp()*speed; + } + } + obj->ApplyMoveForce(dist); + + if(type == COMPGROUP_WHEEL){ + obj->m_fTurnMass = 5.0f; + obj->m_vecTurnSpeed.x = 0.5f; + obj->m_fAirResistance = 0.99f; + } + + if(CCollision::ProcessColModels(obj->GetMatrix(), *obj->GetColModel(), + this->GetMatrix(), *this->GetColModel(), + aTempPedColPts, nil, nil) > 0) + obj->m_pCollidingEntity = this; + + if(bRenderScorched) + obj->bRenderScorched = true; + + CWorld::Add(obj); + + return obj; +} + +CObject* +CAutomobile::RemoveBonnetInPedCollision(void) +{ + CObject *obj; + + if(Damage.GetDoorStatus(DOOR_BONNET) != DOOR_STATUS_SWINGING && + Doors[DOOR_BONNET].RetAngleWhenOpen()*0.4f < Doors[DOOR_BONNET].m_fAngle){ + // BUG? why not COMPGROUP_BONNET? + obj = SpawnFlyingComponent(CAR_BONNET, COMPGROUP_DOOR); + // make both doors invisible on car + SetComponentVisibility(m_aCarNodes[CAR_BONNET], ATOMIC_FLAG_NONE); + Damage.SetDoorStatus(DOOR_BONNET, DOOR_STATUS_MISSING); + return obj; + } + return nil; +} + +void +CAutomobile::SetPanelDamage(int32 component, ePanels panel, bool noFlyingComponents) +{ + int status = Damage.GetPanelStatus(panel); + if(m_aCarNodes[component] == nil) + return; + if(status == PANEL_STATUS_SMASHED1){ + // show damaged part + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); + }else if(status == PANEL_STATUS_MISSING){ + if(!noFlyingComponents) + SpawnFlyingComponent(component, COMPGROUP_PANEL); + // hide both + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); + } +} + +void +CAutomobile::SetBumperDamage(int32 component, ePanels panel, bool noFlyingComponents) +{ + int status = Damage.GetPanelStatus(panel); + if(m_aCarNodes[component] == nil){ + printf("Trying to damage component %d of %s\n", + component, CModelInfo::GetModelInfo(GetModelIndex())->GetName()); + return; + } + if(status == PANEL_STATUS_SMASHED1){ + // show damaged part + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); + }else if(status == PANEL_STATUS_MISSING){ + if(!noFlyingComponents) + SpawnFlyingComponent(component, COMPGROUP_BUMPER); + // hide both + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); + } +} + +void +CAutomobile::SetDoorDamage(int32 component, eDoors door, bool noFlyingComponents) +{ + int status = Damage.GetDoorStatus(door); + if(m_aCarNodes[component] == nil){ + printf("Trying to damage component %d of %s\n", + component, CModelInfo::GetModelInfo(GetModelIndex())->GetName()); + return; + } + + if(door == DOOR_BOOT && status == DOOR_STATUS_SWINGING && pHandling->Flags & HANDLING_NOSWING_BOOT){ + Damage.SetDoorStatus(DOOR_BOOT, DOOR_STATUS_MISSING); + status = DOOR_STATUS_MISSING; + } + + if(status == DOOR_STATUS_SMASHED){ + // show damaged part + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); + }else if(status == DOOR_STATUS_SWINGING){ + // turn off angle cull for swinging doors + RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); + }else if(status == DOOR_STATUS_MISSING){ + if(!noFlyingComponents){ + if(door == DOOR_BONNET) + SpawnFlyingComponent(component, COMPGROUP_BONNET); + else if(door == DOOR_BOOT) + SpawnFlyingComponent(component, COMPGROUP_BOOT); + else + SpawnFlyingComponent(component, COMPGROUP_DOOR); + } + // hide both + SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); + } +} + + +static RwObject* +SetVehicleAtomicVisibilityCB(RwObject *object, void *data) +{ + uint32 flags = (uint32)(uintptr)data; + RpAtomic *atomic = (RpAtomic*)object; + if((CVisibilityPlugins::GetAtomicId(atomic) & (ATOMIC_FLAG_OK|ATOMIC_FLAG_DAM)) == flags) + RpAtomicSetFlags(atomic, rpATOMICRENDER); + else + RpAtomicSetFlags(atomic, 0); + return object; +} + +void +CAutomobile::SetComponentVisibility(RwFrame *frame, uint32 flags) +{ + HideAllComps(); + bIsDamaged = true; + RwFrameForAllObjects(frame, SetVehicleAtomicVisibilityCB, (void*)flags); +} + +void +CAutomobile::SetupModelNodes(void) +{ + int i; + for(i = 0; i < NUM_CAR_NODES; i++) + m_aCarNodes[i] = nil; + CClumpModelInfo::FillFrameArray((RpClump*)m_rwObject, m_aCarNodes); +} + +void +CAutomobile::SetTaxiLight(bool light) +{ + bTaxiLight = light; +} + +bool +CAutomobile::GetAllWheelsOffGround(void) +{ + return m_nDriveWheelsOnGround == 0; +} + +void +CAutomobile::HideAllComps(void) +{ + // empty +} + +void +CAutomobile::ShowAllComps(void) +{ + // empty +} + +void +CAutomobile::ReduceHornCounter(void) +{ + if(m_nCarHornTimer != 0) + m_nCarHornTimer--; +} + +void +CAutomobile::SetAllTaxiLights(bool set) +{ + m_sAllTaxiLights = set; +} + +class CAutomobile_ : public CAutomobile +{ +public: + void ctor(int32 id, uint8 CreatedBy) { ::new (this) CAutomobile(id, CreatedBy); } + void dtor() { CAutomobile::~CAutomobile(); } + void SetModelIndex_(uint32 id) { CAutomobile::SetModelIndex(id); } + void ProcessControl_(void) { CAutomobile::ProcessControl(); } + void Teleport_(CVector v) { CAutomobile::Teleport(v); } + void PreRender_(void) { CAutomobile::PreRender(); } + void Render_(void) { CAutomobile::Render(); } + + int32 ProcessEntityCollision_(CEntity *ent, CColPoint *colpoints){ return CAutomobile::ProcessEntityCollision(ent, colpoints); } + + void ProcessControlInputs_(uint8 pad) { CAutomobile::ProcessControlInputs(pad); } + void GetComponentWorldPosition_(int32 component, CVector &pos) { CAutomobile::GetComponentWorldPosition(component, pos); } + bool IsComponentPresent_(int32 component) { return CAutomobile::IsComponentPresent(component); } + void SetComponentRotation_(int32 component, CVector rotation) { CAutomobile::SetComponentRotation(component, rotation); } + void OpenDoor_(int32 component, eDoors door, float ratio) { CAutomobile::OpenDoor(component, door, ratio); } + void ProcessOpenDoor_(uint32 component, uint32 anim, float time) { CAutomobile::ProcessOpenDoor(component, anim, time); } + bool IsDoorReady_(eDoors door) { return CAutomobile::IsDoorReady(door); } + bool IsDoorFullyOpen_(eDoors door) { return CAutomobile::IsDoorFullyOpen(door); } + bool IsDoorClosed_(eDoors door) { return CAutomobile::IsDoorClosed(door); } + bool IsDoorMissing_(eDoors door) { return CAutomobile::IsDoorMissing(door); } + void RemoveRefsToVehicle_(CEntity *ent) { CAutomobile::RemoveRefsToVehicle(ent); } + void BlowUpCar_(CEntity *ent) { CAutomobile::BlowUpCar(ent); } + bool SetUpWheelColModel_(CColModel *colModel) { return CAutomobile::SetUpWheelColModel(colModel); } + void BurstTyre_(uint8 tyre) { CAutomobile::BurstTyre(tyre); } + bool IsRoomForPedToLeaveCar_(uint32 door, CVector *pos) { return CAutomobile::IsRoomForPedToLeaveCar(door, pos); } + float GetHeightAboveRoad_(void) { return CAutomobile::GetHeightAboveRoad(); } + void PlayCarHorn_(void) { CAutomobile::PlayCarHorn(); } +}; + +STARTPATCHES + InjectHook(0x52C6B0, &CAutomobile_::ctor, PATCH_JUMP); + InjectHook(0x52D170, &CAutomobile_::dtor, PATCH_JUMP); + InjectHook(0x52D190, &CAutomobile_::SetModelIndex_, PATCH_JUMP); + InjectHook(0x531470, &CAutomobile_::ProcessControl_, PATCH_JUMP); + InjectHook(0x535180, &CAutomobile_::Teleport_, PATCH_JUMP); + InjectHook(0x539EA0, &CAutomobile_::Render_, PATCH_JUMP); + InjectHook(0x535B40, &CAutomobile_::PreRender_, PATCH_JUMP); + InjectHook(0x53B270, &CAutomobile_::ProcessEntityCollision_, PATCH_JUMP); + InjectHook(0x53B660, &CAutomobile_::ProcessControlInputs_, PATCH_JUMP); + InjectHook(0x52E5F0, &CAutomobile_::GetComponentWorldPosition_, PATCH_JUMP); + InjectHook(0x52E660, &CAutomobile_::IsComponentPresent_, PATCH_JUMP); + InjectHook(0x52E680, &CAutomobile_::SetComponentRotation_, PATCH_JUMP); + InjectHook(0x52E750, &CAutomobile_::OpenDoor_, PATCH_JUMP); + InjectHook(0x52EF10, &CAutomobile_::IsDoorReady_, PATCH_JUMP); + InjectHook(0x52EF90, &CAutomobile_::IsDoorFullyOpen_, PATCH_JUMP); + InjectHook(0x52EFD0, &CAutomobile_::IsDoorClosed_, PATCH_JUMP); + InjectHook(0x52F000, &CAutomobile_::IsDoorMissing_, PATCH_JUMP); + InjectHook(0x53BF40, &CAutomobile_::RemoveRefsToVehicle_, PATCH_JUMP); + InjectHook(0x53BC60, &CAutomobile_::BlowUpCar_, PATCH_JUMP); + InjectHook(0x53BF70, &CAutomobile_::SetUpWheelColModel_, PATCH_JUMP); + InjectHook(0x53C0E0, &CAutomobile_::BurstTyre_, PATCH_JUMP); + InjectHook(0x53C5B0, &CAutomobile_::IsRoomForPedToLeaveCar_, PATCH_JUMP); + InjectHook(0x437690, &CAutomobile_::GetHeightAboveRoad_, PATCH_JUMP); + InjectHook(0x53C450, &CAutomobile_::PlayCarHorn_, PATCH_JUMP); + InjectHook(0x53E090, &CAutomobile::PlaceOnRoadProperly, PATCH_JUMP); + InjectHook(0x52F030, &CAutomobile::dmgDrawCarCollidingParticles, PATCH_JUMP); + InjectHook(0x535450, &CAutomobile::AddDamagedVehicleParticles, PATCH_JUMP); + InjectHook(0x5357D0, &CAutomobile::AddWheelDirtAndWater, PATCH_JUMP); + InjectHook(0x5353A0, &CAutomobile::ResetSuspension, PATCH_JUMP); + InjectHook(0x52D210, &CAutomobile::SetupSuspensionLines, PATCH_JUMP); + InjectHook(0x53E000, &CAutomobile::BlowUpCarsInPath, PATCH_JUMP); + InjectHook(0x42E220, &CAutomobile::HasCarStoppedBecauseOfLight, PATCH_JUMP); + InjectHook(0x53D320, &CAutomobile::SetBusDoorTimer, PATCH_JUMP); + InjectHook(0x53D370, &CAutomobile::ProcessAutoBusDoors, PATCH_JUMP); + InjectHook(0x535250, &CAutomobile::ProcessSwingingDoor, PATCH_JUMP); + InjectHook(0x53C240, &CAutomobile::Fix, PATCH_JUMP); + InjectHook(0x53C310, &CAutomobile::SetupDamageAfterLoad, PATCH_JUMP); + InjectHook(0x530300, &CAutomobile::SpawnFlyingComponent, PATCH_JUMP); + InjectHook(0x535320, &CAutomobile::RemoveBonnetInPedCollision, PATCH_JUMP); + InjectHook(0x5301A0, &CAutomobile::SetPanelDamage, PATCH_JUMP); + InjectHook(0x530120, &CAutomobile::SetBumperDamage, PATCH_JUMP); + InjectHook(0x530200, &CAutomobile::SetDoorDamage, PATCH_JUMP); + InjectHook(0x5300E0, &CAutomobile::SetComponentVisibility, PATCH_JUMP); + InjectHook(0x52D1B0, &CAutomobile::SetupModelNodes, PATCH_JUMP); + InjectHook(0x53C420, &CAutomobile::SetTaxiLight, PATCH_JUMP); + InjectHook(0x53BC40, &CAutomobile::GetAllWheelsOffGround, PATCH_JUMP); + InjectHook(0x5308C0, &CAutomobile::ReduceHornCounter, PATCH_JUMP); + InjectHook(0x53C440, &CAutomobile::SetAllTaxiLights, PATCH_JUMP); +ENDPATCHES diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index f614b78f..2b5ff567 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -61,7 +61,7 @@ float CBoat::IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat) float fDist = vecDist.MagnitudeSqr(); if ( fDist < SQR(fMaxDist) ) - return 1.0f - min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); + return 1.0f - Min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); } return 0.0f; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index 9b1a651d..1c242f0e 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -1038,8 +1038,16 @@ void CHeli::ActivateHeli(bool activate) { ScriptHeliOn = activate; } class CHeli_ : public CHeli { public: +<<<<<<< HEAD +<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CHeli(id, CreatedBy); } void dtor(void) { CHeli::~CHeli(); } +======= + void dtor(void) { this->~CHeli(); } +>>>>>>> More audio ped +======= + void dtor(void) { CHeli::~CHeli(); } +>>>>>>> fix }; STARTPATCHES diff --git a/src/vehicles/Heli.cpp.autosave b/src/vehicles/Heli.cpp.autosave new file mode 100644 index 00000000..9b1a651d --- /dev/null +++ b/src/vehicles/Heli.cpp.autosave @@ -0,0 +1,1055 @@ +#include "common.h" +#include "main.h" +#include "patcher.h" +#include "General.h" +#include "Darkel.h" +#include "Stats.h" +#include "SurfaceTable.h" +#include "ModelIndices.h" +#include "Streaming.h" +#include "Camera.h" +#include "VisibilityPlugins.h" +#include "ZoneCull.h" +#include "Particle.h" +#include "Shadows.h" +#include "Coronas.h" +#include "Explosion.h" +#include "TimeCycle.h" +#include "TempColModels.h" +#include "World.h" +#include "WaterLevel.h" +#include "PlayerPed.h" +#include "Object.h" +#include "HandlingMgr.h" +#include "Heli.h" + +enum +{ + HELI_STATUS_HOVER, + HELI_STATUS_CHASE_PLAYER, + HELI_STATUS_FLY_AWAY, + HELI_STATUS_SHOT_DOWN, + HELI_STATUS_HOVER2, +}; + +CHeli **CHeli::pHelis = (CHeli**)0x72CF50; +int16 &CHeli::NumRandomHelis = *(int16*)0x95CCAA; +uint32 &CHeli::TestForNewRandomHelisTimer = *(uint32*)0x8F1A7C; +int16 CHeli::NumScriptHelis; // unused +bool &CHeli::CatalinaHeliOn = *(bool*)0x95CD85; +bool &CHeli::CatalinaHasBeenShotDown = *(bool*)0x95CD56; +bool &CHeli::ScriptHeliOn = *(bool*)0x95CD43; + +CHeli::CHeli(int32 id, uint8 CreatedBy) + : CVehicle(CreatedBy) +{ + int i; + + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); + m_vehType = VEHICLE_TYPE_HELI; + pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + SetModelIndex(id); + m_heliStatus = HELI_STATUS_HOVER; + m_pathState = 0; + + m_fMass = 100000000.0f; + m_fTurnMass = 100000000.0f; + m_fAirResistance = 0.9994f; + m_fElasticity = 0.05f; + + m_nHeliId = 0; + m_fRotorRotation = 0.0f; + m_nBulletDamage = 0; + m_fAngularSpeed = 0.0f; + m_fRotation = 0.0f; + m_nSearchLightTimer = CTimer::GetTimeInMilliseconds(); + for(i = 0; i < 6; i++){ + m_aSearchLightHistoryX[i] = 0.0f; + m_aSearchLightHistoryY[i] = 0.0f; + } + + for(i = 0; i < 8; i++) + m_fHeliDustZ[i] = -50.0f; + + m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds(); + m_status = STATUS_HELI; + m_bTestRight = true; + m_fTargetOffset = 0.0f; + m_fSearchLightX = m_fSearchLightY = 0.0f; +} + +void +CHeli::SetModelIndex(uint32 id) +{ + int i; + + CVehicle::SetModelIndex(id); + for(i = 0; i < NUM_HELI_NODES; i++) + m_aHeliNodes[i] = nil; + CClumpModelInfo::FillFrameArray(GetClump(), m_aHeliNodes); +} + +static float CatalinaTargetX[7] = { -478.0, -677.0, -907.0, -1095.0, -1152.0, -1161.0, -1161.0 }; +static float CatalinaTargetY[7] = { 227.0, 206.0, 210.0, 242.0, 278.0, 341.0, 341.0 }; +static float CatalinaTargetZ[7] = { 77.0, 66.0, 60.0, 53.0, 51.0, 46.0, 30.0 }; +static float DamPathX[6] = { -1191.0, -1176.0, -1128.0, -1072.0, -1007.0, -971.0 }; +static float DamPathY[6] = { 350.0, 388.0, 429.0, 447.0, 449.0, 416.0 }; +static float DamPathZ[6] = { 42.0, 37.0, 28.0, 28.0, 31.0, 33.0 }; +static float ShortPathX[4] = { -974.0, -1036.0, -1112.0, -1173.0 }; +static float ShortPathY[4] = { 340.0, 312.0, 317.0, 294.0 }; +static float ShortPathZ[4] = { 41.0, 38.0, 32.0, 39.0 }; +static float LongPathX[7] = { -934.0, -905.0, -906.0, -1063.0, -1204.0, -1233.0, -1207.0 }; +static float LongPathY[7] = { 371.0, 362.0, 488.0, 548.0, 451.0, 346.0, 308.0 }; +static float LongPathZ[7] = { 57.0, 90.0, 105.0, 100.0, 81.0, 79.0, 70.0 }; + +static int PathPoint; + +void +CHeli::ProcessControl(void) +{ + int i; + + if(gbModelViewer) + return; + + // Find target + CVector target(0.0f, 0.0f, 0.0f); + CVector2D vTargetDist; + if(m_heliType == HELI_TYPE_CATALINA && m_heliStatus != HELI_STATUS_SHOT_DOWN){ + switch(m_pathState){ + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + target.x = CatalinaTargetX[m_pathState]; + target.y = CatalinaTargetY[m_pathState]; + target.z = CatalinaTargetZ[m_pathState]; + if((target - GetPosition()).Magnitude() < 9.0f) + m_pathState++; + break; + case 6: + target.x = CatalinaTargetX[m_pathState]; + target.y = CatalinaTargetY[m_pathState]; + target.z = CatalinaTargetZ[m_pathState]; + if(GetPosition().z > 31.55f) + break; + m_pathState = 7; + GetPosition().z = 31.55f; + m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + break; + case 7: + GetPosition().z = 31.55f; + target = GetPosition(); + break; + + + // Take off + case 8: + target.x = GetPosition().x; + target.y = GetPosition().y; + target.z = 74.0f; + if(GetPosition().z < 40.0f) + break; + PathPoint = 2; + m_pathState = 9; + break; + // Circle around dam + case 9: + target.x = DamPathX[PathPoint]; + target.y = DamPathY[PathPoint]; + target.z = DamPathZ[PathPoint]; + if((target - GetPosition()).Magnitude() < 9.0f){ + PathPoint++; + if(PathPoint >= 6){ + m_pathState = 10; + PathPoint = 0; + } + } + break; + case 10: + target.x = ShortPathX[PathPoint]; + target.y = ShortPathY[PathPoint]; + target.z = ShortPathZ[PathPoint]; + if((target - GetPosition()).Magnitude() < 9.0f){ + PathPoint++; + if(PathPoint >= 3){ + m_pathState = 9; + PathPoint = 1; + } + } + break; + // how do we get here? + case 11: + target.x = LongPathX[PathPoint]; + target.y = LongPathY[PathPoint]; + target.z = LongPathZ[PathPoint]; + if((target - GetPosition()).Magnitude() < 9.0f){ + PathPoint++; + if(PathPoint >= 7){ + m_pathState = 9; + PathPoint = 0; + } + } + break; + + + // Fly away + case 12: + target.x = GetPosition().x; + target.y = GetPosition().y; + target.z = 200.0f; + break; + } + + vTargetDist = target - GetPosition(); + m_fTargetZ = target.z; + if(m_pathState == 6){ + GetPosition().x = GetPosition().x*0.99f + target.x*0.01f; + GetPosition().y = GetPosition().y*0.99f + target.y*0.01f; + } + }else{ + vTargetDist = FindPlayerCoors() - GetPosition(); + m_fTargetZ = FindPlayerCoors().z; + + // Heli flies away to (0, 0) + if(m_heliStatus == HELI_STATUS_FLY_AWAY && GetPosition().z > 20.0f){ + vTargetDist.x = 0.0f - GetPosition().x; + vTargetDist.y = 0.0f - GetPosition().y; + } + + float groundZ; + switch(m_heliStatus){ + case HELI_STATUS_HOVER: + groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f; + break; + case HELI_STATUS_SHOT_DOWN: + groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + break; + case HELI_STATUS_HOVER2: + groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + break; + default: + groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); + m_fTargetZ = max(groundZ, m_fTargetZ) + 12.0f; + break; + } + + // Move up if too low + if(GetPosition().z - 2.0f < groundZ && m_heliStatus != HELI_STATUS_SHOT_DOWN) + m_vecMoveSpeed.z += CTimer::GetTimeStep()*0.01f; + m_vecMoveSpeed.z = clamp(m_vecMoveSpeed.z, -0.3f, 0.3f); + } + + float fTargetDist = vTargetDist.Magnitude(); + + switch(m_heliStatus){ + case HELI_STATUS_HOVER: + case HELI_STATUS_HOVER2:{ + float targetHeight; + if(m_heliType == HELI_TYPE_CATALINA) + targetHeight = 8.0f; + else + targetHeight = 40.0f - m_nHeliId*10.0f; + if(fTargetDist > targetHeight) + m_heliStatus = HELI_STATUS_CHASE_PLAYER; + } + // fall through, BUG? + case HELI_STATUS_CHASE_PLAYER:{ + float targetHeight; + if(m_heliType == HELI_TYPE_CATALINA) + targetHeight = 4.0f; + else + targetHeight = 30.0f - m_nHeliId*7.5f; + if(fTargetDist < 1.0f || + fTargetDist < targetHeight && CWorld::GetIsLineOfSightClear(GetPosition(), FindPlayerCoors(), true, false, false, false, false, false)) + m_heliStatus = HELI_STATUS_HOVER; + } + } + + // Find xy speed + float speed; + if(fTargetDist > 100.0f) + speed = 1.0f; + else if(fTargetDist > 75.0f) + speed = 0.7f; + else + speed = 0.4f; + if(m_heliStatus == HELI_STATUS_HOVER || m_heliStatus == HELI_STATUS_HOVER2 || m_heliStatus == HELI_STATUS_SHOT_DOWN) + speed = 0.0f; + + if(fTargetDist != 0.0f) + vTargetDist /= fTargetDist; + else + vTargetDist.x = 1.0f; + CVector2D targetSpeed = vTargetDist * speed; + + if(m_heliStatus == HELI_STATUS_HOVER2 || m_heliStatus == HELI_STATUS_SHOT_DOWN){ + bool force = !!((CTimer::GetFrameCounter() + m_randomSeed) & 8); + if(m_bTestRight){ + if(force || CWorld::TestSphereAgainstWorld(GetPosition() + 4.0f*GetRight(), 2.0f, this, true, false, false, false, false, false) == nil){ + if(m_heliStatus == HELI_STATUS_SHOT_DOWN){ + m_fTargetOffset -= CTimer::GetTimeStep()*0.05f; + targetSpeed.x -= -vTargetDist.x*0.15f; + targetSpeed.y -= vTargetDist.y*0.15f; + }else{ + targetSpeed.x -= -vTargetDist.x*0.05f; + targetSpeed.y -= vTargetDist.y*0.05f; + } + }else{ + m_bTestRight = false; + if(m_heliStatus == HELI_STATUS_HOVER2) + m_fTargetOffset += 5.0f; + else + m_fTargetOffset -= 5.0f; + } + }else{ + if(force || CWorld::TestSphereAgainstWorld(GetPosition() - 4.0f*GetRight(), 2.0f, this, true, false, false, false, false, false) == nil){ + if(m_heliStatus == HELI_STATUS_SHOT_DOWN){ + m_fTargetOffset -= CTimer::GetTimeStep()*0.05f; + targetSpeed.x += -vTargetDist.x*0.15f; + targetSpeed.y += vTargetDist.y*0.15f; + }else{ + targetSpeed.x += -vTargetDist.x*0.05f; + targetSpeed.y += vTargetDist.y*0.05f; + } + }else{ + m_bTestRight = true; + if(m_heliStatus == HELI_STATUS_HOVER2) + m_fTargetOffset += 5.0f; + else + m_fTargetOffset -= 5.0f; + } + } + + if(m_fTargetOffset > 30.0f) + m_fTargetOffset = 30.0f; + + if(m_heliStatus == HELI_STATUS_SHOT_DOWN && force){ + if(CWorld::TestSphereAgainstWorld(GetPosition() + 1.5f*GetForward(), 2.0f, this, true, false, false, false, false, false) || + CWorld::TestSphereAgainstWorld(GetPosition() - 1.5f*GetForward(), 2.0f, this, true, false, false, false, false, false)) + m_nExplosionTimer = CTimer::GetPreviousTimeInMilliseconds(); + } + }else + if(m_fTargetOffset >= 2.0f) + m_fTargetOffset -= 2.0f; + + if(m_heliType == HELI_TYPE_CATALINA) + if(m_pathState == 9 || m_pathState == 11 || m_pathState == 10){ + float f = Pow(0.997f, CTimer::GetTimeStep()); + m_vecMoveSpeed.x *= f; + m_vecMoveSpeed.y *= f; + } + + CVector2D speedDir = targetSpeed - m_vecMoveSpeed; + float speedDiff = speedDir.Magnitude(); + if(speedDiff != 0.0f) + speedDir /= speedDiff; + else + speedDir.x = 1.0f; + float speedInc = CTimer::GetTimeStep()*0.002f; + if(speedDiff < speedInc){ + m_vecMoveSpeed.x = targetSpeed.x; + m_vecMoveSpeed.y = targetSpeed.y; + }else{ + m_vecMoveSpeed.x += speedDir.x*speedInc; + m_vecMoveSpeed.y += speedDir.y*speedInc; + } + GetPosition().x += m_vecMoveSpeed.x*CTimer::GetTimeStep(); + GetPosition().y += m_vecMoveSpeed.y*CTimer::GetTimeStep(); + + // Find z target + if(m_heliStatus == HELI_STATUS_FLY_AWAY) + m_fTargetZ = 1000.0f; + if((CTimer::GetTimeInMilliseconds() + 800*m_nHeliId) & 0x800) + m_fTargetZ += 2.0f; + m_fTargetZ += m_nHeliId*5.0f; + + // Find z speed + float targetSpeedZ = (m_fTargetZ - GetPosition().z)*0.01f; + float speedDiffZ = targetSpeedZ - m_vecMoveSpeed.z; + float speedIncZ = CTimer::GetTimeStep()*0.001f; + if(m_heliStatus == HELI_STATUS_FLY_AWAY) + speedIncZ *= 1.5f; + if(Abs(speedDiffZ) < speedIncZ) + m_vecMoveSpeed.z = targetSpeedZ; + else if(speedDiffZ < 0.0f) + m_vecMoveSpeed.z -= speedIncZ; + else + m_vecMoveSpeed.z += speedIncZ*1.5f; + GetPosition().z += m_vecMoveSpeed.z*CTimer::GetTimeStep(); + + // Find angular speed + float targetAngularSpeed; + m_fAngularSpeed *= Pow(0.995f, CTimer::GetTimeStep()); + if(fTargetDist < 8.0f) + targetAngularSpeed = 0.0f; + else{ + float rotationDiff = CGeneral::GetATanOfXY(vTargetDist.x, vTargetDist.y) - m_fRotation; + while(rotationDiff < -3.14f) rotationDiff += 6.28f; + while(rotationDiff > 3.14f) rotationDiff -= 6.28f; + if(Abs(rotationDiff) > 0.4f){ + if(rotationDiff < 0.0f) + targetAngularSpeed = -0.2f; + else + targetAngularSpeed = 0.2f; + }else + targetAngularSpeed = 0.0f; + } + float angularSpeedDiff = targetAngularSpeed - m_fAngularSpeed; + float angularSpeedInc = CTimer::GetTimeStep()*0.0001f; + if(Abs(angularSpeedDiff) < angularSpeedInc) + m_fAngularSpeed = targetAngularSpeed; + else if(angularSpeedDiff < 0.0f) + m_fAngularSpeed -= angularSpeedInc; + else + m_fAngularSpeed += angularSpeedInc; + m_fRotation += m_fAngularSpeed * CTimer::GetTimeStep(); + + // Set matrix + CVector up(3.0f*m_vecMoveSpeed.x, 3.0f*m_vecMoveSpeed.y, 1.0f); + up.Normalise(); + CVector fwd(-Cos(m_fRotation), -Sin(m_fRotation), 0.0f); // not really forward + CVector right = CrossProduct(up, fwd); + fwd = CrossProduct(up, right); + GetRight() = right; + GetForward() = fwd; + GetUp() = up; + + // Search light and shooting + if(m_heliStatus == HELI_STATUS_FLY_AWAY || m_heliType == HELI_TYPE_CATALINA || CCullZones::PlayerNoRain()) + m_fSearchLightIntensity = 0.0f; + else{ + // Update search light history once every 1000ms + int timeDiff = CTimer::GetTimeInMilliseconds() - m_nSearchLightTimer; + while(timeDiff > 1000){ + for(i = 5; i > 0; i--){ + m_aSearchLightHistoryX[i] = m_aSearchLightHistoryX[i-1]; + m_aSearchLightHistoryY[i] = m_aSearchLightHistoryY[i-1]; + } + m_aSearchLightHistoryX[0] = FindPlayerCoors().x + FindPlayerSpeed().x*50.0f*(m_nHeliId+2); + m_aSearchLightHistoryY[0] = FindPlayerCoors().y + FindPlayerSpeed().y*50.0f*(m_nHeliId+2); + + timeDiff -= 1000; + m_nSearchLightTimer += 1000; + } + assert(timeDiff <= 1000); + float f1 = timeDiff/1000.0f; + float f2 = 1.0f - f1; + m_fSearchLightX = m_aSearchLightHistoryX[m_nHeliId+2]*f2 + m_aSearchLightHistoryX[m_nHeliId+2-1]*f1; + m_fSearchLightY = m_aSearchLightHistoryY[m_nHeliId+2]*f2 + m_aSearchLightHistoryY[m_nHeliId+2-1]*f1; + + float searchLightDist = (CVector2D(m_fSearchLightX, m_fSearchLightY) - GetPosition()).Magnitude(); + if(searchLightDist > 60.0f) + m_fSearchLightIntensity = 0.0f; + else if(searchLightDist < 40.0f) + m_fSearchLightIntensity = 1.0f; + else + m_fSearchLightIntensity = 1.0f - (40.0f-searchLightDist)/40.0f; + + if(m_fSearchLightIntensity < 0.9f || sq(FindPlayerCoors().x-m_fSearchLightX) + sq(FindPlayerCoors().y-m_fSearchLightY) > sq(7.0f)) + m_nShootTimer = CTimer::GetTimeInMilliseconds(); + else if(CTimer::GetTimeInMilliseconds() > m_nPoliceShoutTimer){ + DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_HELI_PLAYER_FOUND, 0.0f); + m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds() + 4500 + (CGeneral::GetRandomNumber()&0xFFF); + } + + // Shoot + int shootTimeout; + if(m_heliType == HELI_TYPE_RANDOM){ + switch(FindPlayerPed()->m_pWanted->m_nWantedLevel){ + case 0: + case 1: + case 2: shootTimeout = 999999; break; + case 3: shootTimeout = 10000; break; + case 4: shootTimeout = 5000; break; + case 5: shootTimeout = 3500; break; + case 6: shootTimeout = 2000; break; + } + if(CCullZones::NoPolice()) + shootTimeout /= 2; + }else + shootTimeout = 1500; + + if(FindPlayerPed()->m_pWanted->IsIgnored()) + m_nShootTimer = CTimer::GetTimeInMilliseconds(); + else{ + // Check if line of sight is clear + if(CTimer::GetTimeInMilliseconds() > m_nShootTimer + shootTimeout && + CTimer::GetPreviousTimeInMilliseconds() <= m_nShootTimer + shootTimeout){ + if(CWorld::GetIsLineOfSightClear(GetPosition(), FindPlayerCoors(), true, false, false, false, false, false)){ + if(m_heliStatus == HELI_STATUS_HOVER2) + m_heliStatus = HELI_STATUS_HOVER; + }else{ + m_nShootTimer = CTimer::GetTimeInMilliseconds(); + if(m_heliStatus == HELI_STATUS_HOVER) + m_heliStatus = HELI_STATUS_HOVER2; + } + } + + // Shoot! + if(CTimer::GetTimeInMilliseconds() > m_nShootTimer + shootTimeout && + CTimer::GetTimeInMilliseconds() > m_nLastShotTime + 200){ + CVector shotTarget = FindPlayerCoors(); + // some inaccuracy + shotTarget.x += ((CGeneral::GetRandomNumber()&0xFF)-128)/50.0f; + shotTarget.y += ((CGeneral::GetRandomNumber()&0xFF)-128)/50.0f; + CVector direction = FindPlayerCoors() - GetPosition(); + direction.Normalise(); + shotTarget += 3.0f*direction; + CVector shotSource = GetPosition(); + shotSource += 3.0f*direction; + FireOneInstantHitRound(&shotSource, &shotTarget, 20); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_SHOT_FIRED, 0.0f); + m_nLastShotTime = CTimer::GetTimeInMilliseconds(); + } + } + } + + // Drop Catalina's bombs + if(m_heliType == HELI_TYPE_CATALINA && m_pathState > 8 && (CTimer::GetTimeInMilliseconds()>>9) != (CTimer::GetPreviousTimeInMilliseconds()>>9)){ + CVector bombPos = GetPosition() - 60.0f*m_vecMoveSpeed; + if(sq(FindPlayerCoors().x-bombPos.x) + sq(FindPlayerCoors().y-bombPos.y) < sq(35.0f)){ + bool found; + float groundZ = CWorld::FindGroundZFor3DCoord(bombPos.x, bombPos.y, bombPos.z, &found); + float waterZ; + if(!CWaterLevel::GetWaterLevelNoWaves(bombPos.x, bombPos.y, bombPos.z, &waterZ)) + waterZ = 0.0f; + if(groundZ > waterZ){ + bombPos.z = groundZ + 2.0f; + CExplosion::AddExplosion(nil, this, EXPLOSION_HELI_BOMB, bombPos, 0); + }else{ + bombPos.z = waterZ; + CVector dir; + for(i = 0; i < 16; i++){ + dir.x = ((CGeneral::GetRandomNumber()&0xFF)-127)*0.001f; + dir.y = ((CGeneral::GetRandomNumber()&0xFF)-127)*0.001f; + dir.z = 0.5f; + CParticle::AddParticle(PARTICLE_BOAT_SPLASH, bombPos, dir, nil, 0.2f); + } + } + } + } + + RemoveAndAdd(); + bIsInSafePosition = true; + GetMatrix().UpdateRW(); + UpdateRwFrame(); +} + +void +CHeli::PreRender(void) +{ + float angle; + uint8 i; + CColPoint point; + CEntity *entity; + uint8 r, g, b; + float testLowZ = FindPlayerCoors().z - 10.0f; + float radius = (GetPosition().z - FindPlayerCoors().z - 10.0f - 1.0f) * 0.3f + 10.0f; + int frm = CTimer::GetFrameCounter() & 7; + + i = 0; + for(angle = 0.0f; angle < TWOPI; angle += TWOPI/32){ + CVector pos(radius*Cos(angle), radius*Sin(angle), 0.0f); + CVector dir = pos*0.01f; + pos += GetPosition(); + + if(CWorld::ProcessVerticalLine(pos, testLowZ, point, entity, true, false, false, false, true, false, nil)) + m_fHeliDustZ[frm] = point.point.z; + else + m_fHeliDustZ[frm] = -101.0f; + + switch(point.surfaceB){ + default: + case SURFACE_TARMAC: + r = 10; + g = 10; + b = 10; + break; + case SURFACE_GRASS: + r = 10; + g = 6; + b = 3; + break; + case SURFACE_DIRT: + r = 10; + g = 8; + b = 7; + break; + case SURFACE_DIRTTRACK: + r = 10; + g = 6; + b = 3; + break; + } + RwRGBA col = { r, g, b, 32 }; + pos.z = m_fHeliDustZ[(i - (i&3))/4]; // advance every 4 iterations, why not just /4? + if(pos.z > -200.0f && GetPosition().z - pos.z < 20.0f) + CParticle::AddParticle(PARTICLE_HELI_DUST, pos, dir, nil, 0.0f, col); + i++; + } +} + +void +CHeli::Render(void) +{ + CMatrix mat; + CVector pos; + + mat.Attach(RwFrameGetMatrix(m_aHeliNodes[HELI_TOPROTOR])); + pos = mat.GetPosition(); + mat.SetRotateZ(m_fRotorRotation); + mat.Translate(pos); + mat.UpdateRW(); + + m_fRotorRotation += 3.14f/6.5f; + if(m_fRotorRotation > 6.28f) + m_fRotorRotation -= 6.28f; + + mat.Attach(RwFrameGetMatrix(m_aHeliNodes[HELI_BACKROTOR])); + pos = mat.GetPosition(); + mat.SetRotateX(m_fRotorRotation); + mat.Translate(pos); + mat.UpdateRW(); + + CEntity::Render(); +} + +void +CHeli::PreRenderAlways(void) +{ + CVector shadowPos(m_fSearchLightX, m_fSearchLightY, GetPosition().z); + if(m_fSearchLightIntensity > 0.0f){ + CShadows::StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &shadowPos, + 6.0f, 0.0f, 0.0f, -6.0f, + 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, + 50.0f, true, 1.0f); + + CVector front = GetMatrix() * CVector(0.0f, 7.0f, 0.0f); + CVector toPlayer = FindPlayerCoors() - front; + toPlayer.Normalise(); + float intensity = m_fSearchLightIntensity*sq(CTimeCycle::GetSpriteBrightness()); + if(DotProduct(toPlayer, TheCamera.GetForward()) < -0.8f) + CCoronas::RegisterCorona((uintptr)this, 255*intensity, 255*intensity, 255*intensity, 255, + front, 10.0f, 60.0f, CCoronas::TYPE_STAR, + CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::RegisterCorona((uintptr)this, 200*intensity, 200*intensity, 200*intensity, 255, + front, 8.0f, 60.0f, CCoronas::TYPE_STAR, + CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + } + + CVector back = GetMatrix() * CVector(0.0f, -9.0f, 0.0f); + if(CTimer::GetTimeInMilliseconds() & 0x100) + CCoronas::RegisterCorona((uintptr)this + 2, 255, 0, 0, 255, + back, 1.0f, 60.0f, CCoronas::TYPE_STAR, + CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::RegisterCorona((uintptr)this + 2, 0, 0, 0, 255, + back, 1.0f, 60.0f, CCoronas::TYPE_STAR, + CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); +} + +RwObject* +GetHeliAtomicObjectCB(RwObject *object, void *data) +{ + RpAtomic *atomic = (RpAtomic*)object; + assert(RwObjectGetType(object) == rpATOMIC); + if(RpAtomicGetFlags(atomic) & rpATOMICRENDER) + *(RpAtomic**)data = atomic; + return object; +} + +CObject* +CHeli::SpawnFlyingComponent(int32 component) +{ + RpAtomic *atomic; + RwFrame *frame; + RwMatrix *matrix; + CObject *obj; + + if(m_aHeliNodes[component] == nil) + return nil; + + atomic = nil; + RwFrameForAllObjects(m_aHeliNodes[component], GetHeliAtomicObjectCB, &atomic); + if(atomic == nil) + return nil; + + obj = new CObject; + if(obj == nil) + return nil; + + obj->SetModelIndexNoCreate(MI_CAR_WHEEL); + // object needs base model + obj->RefModelInfo(GetModelIndex()); + + // create new atomic + matrix = RwFrameGetLTM(m_aHeliNodes[component]); + frame = RwFrameCreate(); + atomic = RpAtomicClone(atomic); + *RwFrameGetMatrix(frame) = *matrix; + RpAtomicSetFrame(atomic, frame); + CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); + obj->AttachToRwObject((RwObject*)atomic); + + // init object + obj->m_fMass = 10.0f; + obj->m_fTurnMass = 25.0f; + obj->m_fAirResistance = 0.99f; + obj->m_fElasticity = 0.1f; + obj->m_fBuoyancy = obj->m_fMass*GRAVITY/0.75f; + obj->ObjectCreatedBy = TEMP_OBJECT; + obj->bIsStatic = false; + obj->bIsPickup = false; + + // life time + CObject::nNoTempObjects++; + if(component == HELI_TOPROTOR) + obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 1000; + else + obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 3000; + + obj->m_vecMoveSpeed = m_vecMoveSpeed; + if(obj->m_vecMoveSpeed.z > 0.0f) + obj->m_vecMoveSpeed.z = 0.3f; + else + obj->m_vecMoveSpeed.z = 0.0f; + + obj->m_vecTurnSpeed = m_vecTurnSpeed*2.0f; + + if(component == HELI_BACKROTOR) + obj->m_vecTurnSpeed.x = 0.5f; + else if(component == HELI_TOPROTOR || component == HELI_TOPKNOT) + obj->m_vecTurnSpeed.z = 0.5f; + else + obj->m_vecTurnSpeed.y = 0.5f; + + obj->bRenderScorched = true; + + CWorld::Add(obj); + + atomic = nil; + RwFrameForAllObjects(m_aHeliNodes[component], GetHeliAtomicObjectCB, &atomic); + if(atomic) + RpAtomicSetFlags(atomic, 0); + + return obj; +} + + + +void +CHeli::InitHelis(void) +{ + int i; + + NumRandomHelis = 0; + TestForNewRandomHelisTimer = 0; + NumScriptHelis = 0; + CatalinaHeliOn = false; + ScriptHeliOn = false; + for(i = 0; i < NUM_HELIS; i++) + pHelis[i] = nil; + + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_ESCAPE))->SetColModel(&CTempColModels::ms_colModelPed1); + ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&CTempColModels::ms_colModelPed1); +} + +CHeli* +GenerateHeli(bool catalina) +{ + CHeli *heli; + CVector heliPos; + int i; + + if(catalina) + heli = new CHeli(MI_ESCAPE, PERMANENT_VEHICLE); + else + heli = new CHeli(MI_CHOPPER, PERMANENT_VEHICLE); + + if(catalina) + heliPos = CVector(-224.0f, 201.0f, 83.0f); + else{ + heliPos = FindPlayerCoors(); + float angle = (float)(CGeneral::GetRandomNumber() & 0xFF)/0xFF * 6.28f; + heliPos.x += 250.0f*Sin(angle); + heliPos.y += 250.0f*Cos(angle); + if(heliPos.x < -2000.0f || heliPos.x > 2000.0f || heliPos.y < -2000.0f || heliPos.y > 2000.0f){ + // directly above player + heliPos.x -= 250.0f*Sin(angle); + heliPos.y -= 250.0f*Cos(angle); + } + heliPos.z += 50.0f; + } + heli->GetMatrix().SetTranslate(heliPos); + if(catalina) + heli->GetMatrix().SetRotateZOnly(DEGTORAD(270.0f)); // game actually uses 3.14 here + + heli->m_status = STATUS_ABANDONED; + + int id = -1; + bool found = false; + while(!found){ + id++; + found = true; + for(i = 0; i < 4; i++) + if(CHeli::pHelis[i] && CHeli::pHelis[i]->m_nHeliId == id) + found = false; + } + heli->m_nHeliId = id; + + CWorld::Add(heli); + + return heli; +} + +void +CHeli::UpdateHelis(void) +{ + int i, j; + + // Spawn new police helis + int numHelisRequired = FindPlayerPed()->m_pWanted->NumOfHelisRequired(); + if(CStreaming::HasModelLoaded(MI_CHOPPER) && CTimer::GetTimeInMilliseconds() > TestForNewRandomHelisTimer){ + // Spawn a police heli + TestForNewRandomHelisTimer = CTimer::GetTimeInMilliseconds() + 15000; + if(NumRandomHelis < numHelisRequired){ + NumRandomHelis++; + CHeli *heli = GenerateHeli(false); + heli->m_heliType = HELI_TYPE_RANDOM; + if(pHelis[HELI_RANDOM0] == nil) + pHelis[HELI_RANDOM0] = heli; + else if(pHelis[HELI_RANDOM1] == nil) + pHelis[HELI_RANDOM1] = heli; + else + assert(0 && "too many helis"); + } + } + + // Handle script heli + if(ScriptHeliOn){ + if(CStreaming::HasModelLoaded(MI_CHOPPER) && pHelis[HELI_SCRIPT] == nil){ + pHelis[HELI_SCRIPT] = GenerateHeli(false); + pHelis[HELI_SCRIPT]->m_heliType = HELI_TYPE_SCRIPT; + }else + CStreaming::RequestModel(MI_CHOPPER, 0); + }else{ + if(pHelis[HELI_SCRIPT]) + pHelis[HELI_SCRIPT]->m_heliStatus = HELI_STATUS_FLY_AWAY; + } + + // Handle Catalina's heli + if(CatalinaHeliOn){ + if(CStreaming::HasModelLoaded(MI_ESCAPE) && pHelis[HELI_CATALINA] == nil){ + pHelis[HELI_CATALINA] = GenerateHeli(true); + pHelis[HELI_CATALINA]->m_heliType = HELI_TYPE_CATALINA; + }else + CStreaming::RequestModel(MI_ESCAPE, STREAMFLAGS_DONT_REMOVE); + }else{ + if(pHelis[HELI_CATALINA]) + pHelis[HELI_CATALINA]->m_heliStatus = HELI_STATUS_FLY_AWAY; + } + + // Delete helis that we no longer need + for(i = 0; i < NUM_HELIS; i++) + if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_FLY_AWAY && pHelis[i]->GetPosition().z > 150.0f){ + CWorld::Remove(pHelis[i]); + delete pHelis[i]; + pHelis[i] = nil; + if(i != HELI_SCRIPT && i != HELI_CATALINA) + NumRandomHelis--; + } + + // Handle explosions + for(i = 0; i < NUM_HELIS; i++){ + if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_SHOT_DOWN && CTimer::GetTimeInMilliseconds() > pHelis[i]->m_nExplosionTimer){ + // Second part of explosion + static int nFrameGen; + CRGBA colors[8]; + + TheCamera.CamShake(0.7f, pHelis[i]->GetPosition().x, pHelis[i]->GetPosition().y, pHelis[i]->GetPosition().z); + + colors[0] = CRGBA(0, 0, 0, 255); + colors[1] = CRGBA(224, 230, 238, 255); + colors[2] = CRGBA(0, 0, 0, 255); + colors[3] = CRGBA(0, 0, 0, 255); + colors[4] = CRGBA(66, 162, 252, 255); + colors[5] = CRGBA(0, 0, 0, 255); + colors[6] = CRGBA(0, 0, 0, 255); + colors[7] = CRGBA(0, 0, 0, 255); + + CVector pos = pHelis[i]->GetPosition(); + CVector dir; + for(j = 0; j < 40; j++){ + dir.x = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); + dir.y = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); + dir.z = CGeneral::GetRandomNumberInRange(0.0f, 2.0f); + int rotSpeed = CGeneral::GetRandomNumberInRange(10, 30); + if(CGeneral::GetRandomNumber() & 1) + rotSpeed = -rotSpeed; + int f = ++nFrameGen & 3; + CParticle::AddParticle(PARTICLE_HELI_DEBRIS, pos, dir, + nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), + colors[nFrameGen], rotSpeed, 0, f, 0); + } + + CExplosion::AddExplosion(nil, nil, EXPLOSION_HELI, pos, 0); + + pHelis[i]->SpawnFlyingComponent(HELI_SKID_LEFT); + pHelis[i]->SpawnFlyingComponent(HELI_SKID_RIGHT); + pHelis[i]->SpawnFlyingComponent(HELI_TOPROTOR); + + CDarkel::RegisterCarBlownUpByPlayer(pHelis[i]); + CWorld::Remove(pHelis[i]); + delete pHelis[i]; + pHelis[i] = nil; + if(i != HELI_SCRIPT && i != HELI_CATALINA) + NumRandomHelis--; + if(i == HELI_CATALINA) + CatalinaHasBeenShotDown = true; + + CStats::HelisDestroyed++; + CStats::PeopleKilledByOthers += 2; + CStats::PedsKilledOfThisType[PEDTYPE_COP] += 2; + CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 250; + pos = CWorld::Players[CWorld::PlayerInFocus].m_pPed->GetPosition(); + CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->RegisterCrime_Immediately(CRIME_SHOOT_HELI, + pos, i + 19843, false); + + TestForNewRandomHelisTimer = CTimer::GetTimeInMilliseconds() + 50000; + }else if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_SHOT_DOWN && CTimer::GetTimeInMilliseconds()+7000 > pHelis[i]->m_nExplosionTimer){ + // First part of explosion + if(CTimer::GetPreviousTimeInMilliseconds()+7000 < pHelis[i]->m_nExplosionTimer){ + pHelis[i]->SpawnFlyingComponent(HELI_BACKROTOR); + pHelis[i]->SpawnFlyingComponent(HELI_TAIL); + pHelis[i]->m_fAngularSpeed *= -2.5f; + pHelis[i]->bRenderScorched = true; + + TheCamera.CamShake(0.4f, pHelis[i]->GetPosition().x, pHelis[i]->GetPosition().y, pHelis[i]->GetPosition().z); + + CVector pos = pHelis[i]->GetPosition() - 2.5f*pHelis[i]->GetUp(); + CExplosion::AddExplosion(nil, nil, EXPLOSION_HELI, pos, 0); + }else + pHelis[i]->m_fAngularSpeed *= 1.03f; + } + } + + // Find police helis to remove + for(i = 0; i < 2; i++) + if(pHelis[i] && pHelis[i]->m_heliStatus != HELI_STATUS_FLY_AWAY){ + if(numHelisRequired > 0) + numHelisRequired--; + else + pHelis[i]->m_heliStatus = HELI_STATUS_FLY_AWAY; + } + + // Remove all helis if in a tunnel + if(FindPlayerCoors().z < - 2.0f) + for(i = 0; i < NUM_HELIS; i++) + if(pHelis[i] && pHelis[i]->m_heliStatus != HELI_STATUS_SHOT_DOWN) + pHelis[i]->m_heliStatus = HELI_STATUS_FLY_AWAY; +} + +void +CHeli::SpecialHeliPreRender(void) +{ + int i; + for(i = 0; i < NUM_HELIS; i++) + if(pHelis[i]) + pHelis[i]->PreRenderAlways(); +} + +bool +CHeli::TestRocketCollision(CVector *rocketPos) +{ + int i; + bool hit = false; + + for(i = 0; i < NUM_HELIS; i++){ + if(pHelis[i] && !pHelis[i]->bExplosionProof && (*rocketPos - pHelis[i]->GetPosition()).MagnitudeSqr() < sq(8.0f)){ + pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; + pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; + pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; + hit = true; + } + } + return hit; +} + +bool +CHeli::TestBulletCollision(CVector *line0, CVector *line1, CVector *bulletPos, int32 damage) +{ + int i; + bool hit = false; + + for(i = 0; i < NUM_HELIS; i++) + if(pHelis[i] && !pHelis[i]->bBulletProof && CCollision::DistToLine(line0, line1, &pHelis[i]->GetPosition()) < 5.0f){ + // Find bullet position + float distToHeli = (pHelis[i]->GetPosition() - *line0).Magnitude(); + CVector line = (*line1 - *line0); + float lineLength = line.Magnitude(); + *bulletPos = *line0 + line*max(1.0f, distToHeli-5.0f); + + pHelis[i]->m_nBulletDamage += damage; + + if(pHelis[i]->m_heliType == HELI_CATALINA && pHelis[i]->m_nBulletDamage > 400 || + pHelis[i]->m_heliType != HELI_CATALINA && pHelis[i]->m_nBulletDamage > 700){ + pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; + pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; + pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; + } + + hit = true; + } + return hit; +} + +void CHeli::StartCatalinaFlyBy(void) +{ + CatalinaHeliOn = true; + CatalinaHasBeenShotDown = false; +} + +void +CHeli::RemoveCatalinaHeli(void) +{ + CatalinaHeliOn = false; + if(pHelis[HELI_CATALINA]){ + CWorld::Remove(pHelis[HELI_CATALINA]); + delete pHelis[HELI_CATALINA]; + pHelis[HELI_CATALINA] = nil; + } +} + +CHeli *CHeli::FindPointerToCatalinasHeli(void) { return pHelis[HELI_CATALINA]; } +void CHeli::CatalinaTakeOff(void) { pHelis[HELI_CATALINA]->m_pathState = 8; } +void CHeli::MakeCatalinaHeliFlyAway(void) { pHelis[HELI_CATALINA]->m_pathState = 12; } +bool CHeli::HasCatalinaBeenShotDown(void) { return CatalinaHasBeenShotDown; } + +void CHeli::ActivateHeli(bool activate) { ScriptHeliOn = activate; } + + +class CHeli_ : public CHeli +{ +public: + void ctor(int32 id, uint8 CreatedBy) { ::new (this) CHeli(id, CreatedBy); } + void dtor(void) { CHeli::~CHeli(); } +}; + +STARTPATCHES + InjectHook(0x547220, &CHeli_::ctor, PATCH_JUMP); + InjectHook(0x5474A0, &CHeli_::dtor, PATCH_JUMP); + InjectHook(0x54AE50, &CHeli::SpawnFlyingComponent, PATCH_JUMP); + InjectHook(0x549970, CHeli::InitHelis, PATCH_JUMP); + InjectHook(0x5499F0, CHeli::UpdateHelis, PATCH_JUMP); + InjectHook(0x54AE10, CHeli::SpecialHeliPreRender, PATCH_JUMP); + InjectHook(0x54AA30, CHeli::TestRocketCollision, PATCH_JUMP); + InjectHook(0x54AB30, CHeli::TestBulletCollision, PATCH_JUMP); + InjectHook(0x54A640, GenerateHeli, PATCH_JUMP); +ENDPATCHES diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 775cf572..771f36e1 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -968,8 +968,16 @@ bool CPlane::HasDropOffCesnaBeenShotDown(void) { return DropOffCesnaMissionStatu class CPlane_ : public CPlane { public: +<<<<<<< HEAD +<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CPlane(id, CreatedBy); } void dtor(void) { CPlane::~CPlane(); } +======= + void dtor(void) { this->~CPlane(); } +>>>>>>> More audio ped +======= + void dtor(void) { CPlane::~CPlane(); } +>>>>>>> fix }; STARTPATCHES diff --git a/src/vehicles/Plane.cpp.autosave b/src/vehicles/Plane.cpp.autosave new file mode 100644 index 00000000..775cf572 --- /dev/null +++ b/src/vehicles/Plane.cpp.autosave @@ -0,0 +1,985 @@ +#include "common.h" +#include "main.h" +#include "patcher.h" +#include "General.h" +#include "ModelIndices.h" +#include "FileMgr.h" +#include "Streaming.h" +#include "Replay.h" +#include "Camera.h" +#include "Coronas.h" +#include "Particle.h" +#include "Explosion.h" +#include "World.h" +#include "HandlingMgr.h" +#include "Plane.h" + +CPlaneNode *&pPathNodes = *(CPlaneNode**)0x8F1B68; +CPlaneNode *&pPath2Nodes = *(CPlaneNode**)0x885B8C; +CPlaneNode *&pPath3Nodes = *(CPlaneNode**)0x885B78; +CPlaneNode *&pPath4Nodes = *(CPlaneNode**)0x885AD8; +int32 &NumPathNodes = *(int32*)0x8F2BE4; +int32 &NumPath2Nodes = *(int32*)0x941498; +int32 &NumPath3Nodes = *(int32*)0x9414D8; +int32 &NumPath4Nodes = *(int32*)0x9412C8; +float &TotalLengthOfFlightPath = *(float*)0x8F2C6C; +float &TotalLengthOfFlightPath2 = *(float*)0x64CFBC; +float &TotalLengthOfFlightPath3 = *(float*)0x64CFD0; +float &TotalLengthOfFlightPath4 = *(float*)0x64CFDC; +float &TotalDurationOfFlightPath = *(float*)0x64CFB8; +float &TotalDurationOfFlightPath2 = *(float*)0x64CFC0; +float &TotalDurationOfFlightPath3 = *(float*)0x64CFD4; +float &TotalDurationOfFlightPath4 = *(float*)0x64CFE0; +float &LandingPoint = *(float*)0x8F2C7C; +float &TakeOffPoint = *(float*)0x8E28A4; +CPlaneInterpolationLine *aPlaneLineBits = (CPlaneInterpolationLine*)0x734168; //[6] + +float *PlanePathPosition = (float*)0x8F5FC8; //[3] +float *OldPlanePathPosition = (float*)0x8F5FBC; //[3] +float *PlanePathSpeed = (float*)0x941538; //[3] +float *PlanePath2Position = (float*)0x64CFC4; //[3] +float &PlanePath3Position = *(float*)0x64CFD8; +float &PlanePath4Position = *(float*)0x64CFE4; +float *PlanePath2Speed = (float*)0x8F1A54; //[3] +float &PlanePath3Speed = *(float*)0x8F1A94; +float &PlanePath4Speed = *(float*)0x8F1AFC; + + +enum +{ + CESNA_STATUS_NONE, // doesn't even exist + CESNA_STATUS_FLYING, + CESNA_STATUS_DESTROYED, + CESNA_STATUS_LANDED, +}; + +int32 &CesnaMissionStatus = *(int32*)0x64CFE8; +int32 &CesnaMissionStartTime = *(int32*)0x64CFEC; +CPlane *&pDrugRunCesna = *(CPlane**)0x8F5F80; +int32 &DropOffCesnaMissionStatus = *(int32*)0x64CFF0; +int32 &DropOffCesnaMissionStartTime = *(int32*)0x64CFF4; +CPlane *&pDropOffCesna = *(CPlane**)0x8E2A38; + + +CPlane::CPlane(int32 id, uint8 CreatedBy) + : CVehicle(CreatedBy) +{ + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); + m_vehType = VEHICLE_TYPE_PLANE; + pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + SetModelIndex(id); + + m_fMass = 100000000.0f; + m_fTurnMass = 100000000.0f; + m_fAirResistance = 0.9994f; + m_fElasticity = 0.05f; + + bUsesCollision = false; + m_bHasBeenHit = false; + m_bIsDrugRunCesna = false; + m_bIsDropOffCesna = false; + + m_status = STATUS_PLANE; + bIsBIGBuilding = true; + m_level = LEVEL_NONE; +} + +CPlane::~CPlane() +{ + DeleteRwObject(); +} + +void +CPlane::SetModelIndex(uint32 id) +{ + CVehicle::SetModelIndex(id); +} + +void +CPlane::DeleteRwObject(void) +{ + if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ + m_matrix.Detach(); + if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check + RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); + RpAtomicDestroy((RpAtomic*)m_rwObject); + RwFrameDestroy(f); + } + m_rwObject = nil; + } + CEntity::DeleteRwObject(); +} + +// There's a LOT of copy and paste in here. Maybe this could be refactored somehow +void +CPlane::ProcessControl(void) +{ + int i; + CVector pos; + + // Explosion + if(m_bHasBeenHit){ + // BUG: since this is all based on frames, you can skip the explosion processing when you go into the menu + if(GetModelIndex() == MI_AIRTRAIN){ + int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; + if(frm == 20){ + static int nFrameGen; + CRGBA colors[8]; + + CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), 0); + + colors[0] = CRGBA(0, 0, 0, 255); + colors[1] = CRGBA(224, 230, 238, 255); + colors[2] = CRGBA(224, 230, 238, 255); + colors[3] = CRGBA(0, 0, 0, 255); + colors[4] = CRGBA(224, 230, 238, 255); + colors[5] = CRGBA(0, 0, 0, 255); + colors[6] = CRGBA(0, 0, 0, 255); + colors[7] = CRGBA(224, 230, 238, 255); + + CVector dir; + for(i = 0; i < 40; i++){ + dir.x = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); + dir.y = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); + dir.z = CGeneral::GetRandomNumberInRange(0.0f, 2.0f); + int rotSpeed = CGeneral::GetRandomNumberInRange(10, 30); + if(CGeneral::GetRandomNumber() & 1) + rotSpeed = -rotSpeed; + int f = ++nFrameGen & 3; + CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), dir, + nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), + colors[nFrameGen], rotSpeed, 0, f, 0); + } + } + if(frm >= 40 && frm <= 80 && frm & 1){ + if(frm & 1){ + pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; + pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; + pos.y = frm - 40; + pos = GetMatrix() * pos; + }else{ + pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; + pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; + pos.y = 40 - frm; + pos = GetMatrix() * pos; + } + CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, pos, 0); + } + if(frm == 60) + bRenderScorched = true; + if(frm == 82){ + TheCamera.SetFadeColour(255, 255, 255); + TheCamera.Fade(0.0f, FADE_OUT); + TheCamera.ProcessFade(); + TheCamera.Fade(1.0f, FADE_IN); + FlagToDestroyWhenNextProcessed(); + } + }else{ + int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; + if(frm == 20){ + static int nFrameGen; + CRGBA colors[8]; + + CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), 0); + + colors[0] = CRGBA(0, 0, 0, 255); + colors[1] = CRGBA(224, 230, 238, 255); + colors[2] = CRGBA(224, 230, 238, 255); + colors[3] = CRGBA(0, 0, 0, 255); + colors[4] = CRGBA(252, 66, 66, 255); + colors[5] = CRGBA(0, 0, 0, 255); + colors[6] = CRGBA(0, 0, 0, 255); + colors[7] = CRGBA(252, 66, 66, 255); + + for(i = 0; i < 40; i++){ + int rotSpeed = CGeneral::GetRandomNumberInRange(30.0f, 20.0f); + if(CGeneral::GetRandomNumber() & 1) + rotSpeed = -rotSpeed; + int f = ++nFrameGen & 3; + CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), + CVector(CGeneral::GetRandomNumberInRange(-2.0f, 2.0f), + CGeneral::GetRandomNumberInRange(-2.0f, 2.0f), + CGeneral::GetRandomNumberInRange(0.0f, 2.0f)), + nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), + colors[nFrameGen], rotSpeed, 0, f, 0); + } + } + if(frm >= 40 && frm <= 60 && frm & 1){ + if(frm & 1){ + pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; + pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; + pos.y = (frm - 40)*0.3f; + pos = GetMatrix() * pos; + }else{ + pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; + pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; + pos.y = (40 - frm)*0.3f; + pos = GetMatrix() * pos; + } + CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, pos, 0); + } + if(frm == 30) + bRenderScorched = true; + if(frm == 61){ + TheCamera.SetFadeColour(200, 200, 200); + TheCamera.Fade(0.0f, FADE_OUT); + TheCamera.ProcessFade(); + TheCamera.Fade(1.0f, FADE_IN); + if(m_bIsDrugRunCesna){ + CesnaMissionStatus = CESNA_STATUS_DESTROYED; + pDrugRunCesna = nil; + } + if(m_bIsDropOffCesna){ + DropOffCesnaMissionStatus = CESNA_STATUS_DESTROYED; + pDropOffCesna = nil; + } + FlagToDestroyWhenNextProcessed(); + } + } + } + + // Update plane position and speed + if(GetModelIndex() == MI_AIRTRAIN || !m_isFarAway || ((CTimer::GetFrameCounter() + m_randomSeed) & 7) == 0){ + if(GetModelIndex() == MI_AIRTRAIN){ + float pathPositionRear = PlanePathPosition[m_nPlaneId] - 30.0f; + if(pathPositionRear < 0.0f) + pathPositionRear += TotalLengthOfFlightPath; + float pathPosition = pathPositionRear + 30.0f; + + float pitch = 0.0f; + float distSinceTakeOff = pathPosition - TakeOffPoint; + if(distSinceTakeOff <= 0.0f && distSinceTakeOff > -70.0f){ + // shortly before take off + pitch = 1.0f - distSinceTakeOff/-70.0f; + }else if(distSinceTakeOff >= 0.0f && distSinceTakeOff < 100.0f){ + // shortly after take off + pitch = 1.0f - distSinceTakeOff/100.0f; + } + + float distSinceLanding = pathPosition - LandingPoint; + if(distSinceLanding <= 0.0f && distSinceLanding > -200.0f){ + // shortly before landing + pitch = 1.0f - distSinceLanding/-200.0f; + }else if(distSinceLanding >= 0.0f && distSinceLanding < 70.0f){ + // shortly after landing + pitch = 1.0f - distSinceLanding/70.0f; + } + + + // Advance current node to appropriate position + float pos1, pos2; + int nextTrackNode = m_nCurPathNode + 1; + pos1 = pPathNodes[m_nCurPathNode].t; + if(nextTrackNode < NumPathNodes) + pos2 = pPathNodes[nextTrackNode].t; + else{ + nextTrackNode = 0; + pos2 = TotalLengthOfFlightPath; + } + while(pathPositionRear < pos1 || pathPositionRear > pos2){ + m_nCurPathNode = (m_nCurPathNode+1) % NumPathNodes; + nextTrackNode = m_nCurPathNode + 1; + pos1 = pPathNodes[m_nCurPathNode].t; + if(nextTrackNode < NumPathNodes) + pos2 = pPathNodes[nextTrackNode].t; + else{ + nextTrackNode = 0; + pos2 = TotalLengthOfFlightPath; + } + } + bool bothOnGround = pPathNodes[m_nCurPathNode].bOnGround && pPathNodes[nextTrackNode].bOnGround; + if(PlanePathPosition[m_nPlaneId] >= LandingPoint && OldPlanePathPosition[m_nPlaneId] < LandingPoint) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_PLANE_ON_GROUND, 0.0f); + float dist = pPathNodes[nextTrackNode].t - pPathNodes[m_nCurPathNode].t; + if(dist < 0.0f) + dist += TotalLengthOfFlightPath; + float f = (pathPositionRear - pPathNodes[m_nCurPathNode].t)/dist; + CVector posRear = (1.0f - f)*pPathNodes[m_nCurPathNode].p + f*pPathNodes[nextTrackNode].p; + + // Same for the front + float pathPositionFront = pathPositionRear + 60.0f; + if(pathPositionFront > TotalLengthOfFlightPath) + pathPositionFront -= TotalLengthOfFlightPath; + int curPathNodeFront = m_nCurPathNode; + int nextPathNodeFront = curPathNodeFront + 1; + pos1 = pPathNodes[curPathNodeFront].t; + if(nextPathNodeFront < NumPathNodes) + pos2 = pPathNodes[nextPathNodeFront].t; + else{ + nextPathNodeFront = 0; + pos2 = TotalLengthOfFlightPath; + } + while(pathPositionFront < pos1 || pathPositionFront > pos2){ + curPathNodeFront = (curPathNodeFront+1) % NumPathNodes; + nextPathNodeFront = curPathNodeFront + 1; + pos1 = pPathNodes[curPathNodeFront].t; + if(nextPathNodeFront < NumPathNodes) + pos2 = pPathNodes[nextPathNodeFront].t; + else{ + nextPathNodeFront = 0; + pos2 = TotalLengthOfFlightPath; + } + } + dist = pPathNodes[nextPathNodeFront].t - pPathNodes[curPathNodeFront].t; + if(dist < 0.0f) + dist += TotalLengthOfFlightPath; + f = (pathPositionFront - pPathNodes[curPathNodeFront].t)/dist; + CVector posFront = (1.0f - f)*pPathNodes[curPathNodeFront].p + f*pPathNodes[nextPathNodeFront].p; + + // And for another point 60 units in front of the plane, used to calculate roll + float pathPositionFront2 = pathPositionFront + 60.0f; + if(pathPositionFront2 > TotalLengthOfFlightPath) + pathPositionFront2 -= TotalLengthOfFlightPath; + int curPathNodeFront2 = m_nCurPathNode; + int nextPathNodeFront2 = curPathNodeFront2 + 1; + pos1 = pPathNodes[curPathNodeFront2].t; + if(nextPathNodeFront2 < NumPathNodes) + pos2 = pPathNodes[nextPathNodeFront2].t; + else{ + nextPathNodeFront2 = 0; + pos2 = TotalLengthOfFlightPath; + } + while(pathPositionFront2 < pos1 || pathPositionFront2 > pos2){ + curPathNodeFront2 = (curPathNodeFront2+1) % NumPathNodes; + nextPathNodeFront2 = curPathNodeFront2 + 1; + pos1 = pPathNodes[curPathNodeFront2].t; + if(nextPathNodeFront2 < NumPathNodes) + pos2 = pPathNodes[nextPathNodeFront2].t; + else{ + nextPathNodeFront2 = 0; + pos2 = TotalLengthOfFlightPath; + } + } + dist = pPathNodes[nextPathNodeFront2].t - pPathNodes[curPathNodeFront2].t; + if(dist < 0.0f) + dist += TotalLengthOfFlightPath; + f = (pathPositionFront2 - pPathNodes[curPathNodeFront2].t)/dist; + CVector posFront2 = (1.0f - f)*pPathNodes[curPathNodeFront2].p + f*pPathNodes[nextPathNodeFront2].p; + + // Now set matrix + GetPosition() = (posRear + posFront)/2.0f; + GetPosition().z += 4.3f; + CVector fwd = posFront - posRear; + fwd.Normalise(); + if(pitch != 0.0f){ + fwd.z += 0.4f*pitch; + fwd.Normalise(); + } + CVector fwd2 = posFront2 - posRear; + fwd2.Normalise(); + CVector roll = CrossProduct(fwd, fwd2); + CVector right = CrossProduct(fwd, CVector(0.0f, 0.0f, 1.0f)); + if(!bothOnGround) + right.z += 3.0f*roll.z; + right.Normalise(); + CVector up = CrossProduct(right, fwd); + GetRight() = right; + GetUp() = up; + GetForward() = fwd; + + // Set speed + m_vecMoveSpeed = fwd*PlanePathSpeed[m_nPlaneId]/60.0f; + m_fSpeed = PlanePathSpeed[m_nPlaneId]/60.0f; + m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + + m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f)); + }else{ + float planePathPosition; + float totalLengthOfFlightPath; + CPlaneNode *pathNodes; + float planePathSpeed; + int numPathNodes; + + if(m_bIsDrugRunCesna){ + planePathPosition = PlanePath3Position; + totalLengthOfFlightPath = TotalLengthOfFlightPath3; + pathNodes = pPath3Nodes; + planePathSpeed = PlanePath3Speed; + numPathNodes = NumPath3Nodes; + if(CesnaMissionStatus == CESNA_STATUS_LANDED){ + pDrugRunCesna = false; + FlagToDestroyWhenNextProcessed(); + } + }else if(m_bIsDropOffCesna){ + planePathPosition = PlanePath4Position; + totalLengthOfFlightPath = TotalLengthOfFlightPath4; + pathNodes = pPath4Nodes; + planePathSpeed = PlanePath4Speed; + numPathNodes = NumPath4Nodes; + if(DropOffCesnaMissionStatus == CESNA_STATUS_LANDED){ + pDropOffCesna = false; + FlagToDestroyWhenNextProcessed(); + } + }else{ + planePathPosition = PlanePath2Position[m_nPlaneId]; + totalLengthOfFlightPath = TotalLengthOfFlightPath2; + pathNodes = pPath2Nodes; + planePathSpeed = PlanePath2Speed[m_nPlaneId]; + numPathNodes = NumPath2Nodes; + } + + // Advance current node to appropriate position + float pathPositionRear = planePathPosition - 10.0f; + if(pathPositionRear < 0.0f) + pathPositionRear += totalLengthOfFlightPath; + float pos1, pos2; + int nextTrackNode = m_nCurPathNode + 1; + pos1 = pathNodes[m_nCurPathNode].t; + if(nextTrackNode < numPathNodes) + pos2 = pathNodes[nextTrackNode].t; + else{ + nextTrackNode = 0; + pos2 = totalLengthOfFlightPath; + } + while(pathPositionRear < pos1 || pathPositionRear > pos2){ + m_nCurPathNode = (m_nCurPathNode+1) % numPathNodes; + nextTrackNode = m_nCurPathNode + 1; + pos1 = pathNodes[m_nCurPathNode].t; + if(nextTrackNode < numPathNodes) + pos2 = pathNodes[nextTrackNode].t; + else{ + nextTrackNode = 0; + pos2 = totalLengthOfFlightPath; + } + } + float dist = pathNodes[nextTrackNode].t - pathNodes[m_nCurPathNode].t; + if(dist < 0.0f) + dist += totalLengthOfFlightPath; + float f = (pathPositionRear - pathNodes[m_nCurPathNode].t)/dist; + CVector posRear = (1.0f - f)*pathNodes[m_nCurPathNode].p + f*pathNodes[nextTrackNode].p; + + // Same for the front + float pathPositionFront = pathPositionRear + 20.0f; + if(pathPositionFront > totalLengthOfFlightPath) + pathPositionFront -= totalLengthOfFlightPath; + int curPathNodeFront = m_nCurPathNode; + int nextPathNodeFront = curPathNodeFront + 1; + pos1 = pathNodes[curPathNodeFront].t; + if(nextPathNodeFront < numPathNodes) + pos2 = pathNodes[nextPathNodeFront].t; + else{ + nextPathNodeFront = 0; + pos2 = totalLengthOfFlightPath; + } + while(pathPositionFront < pos1 || pathPositionFront > pos2){ + curPathNodeFront = (curPathNodeFront+1) % numPathNodes; + nextPathNodeFront = curPathNodeFront + 1; + pos1 = pathNodes[curPathNodeFront].t; + if(nextPathNodeFront < numPathNodes) + pos2 = pathNodes[nextPathNodeFront].t; + else{ + nextPathNodeFront = 0; + pos2 = totalLengthOfFlightPath; + } + } + dist = pathNodes[nextPathNodeFront].t - pathNodes[curPathNodeFront].t; + if(dist < 0.0f) + dist += totalLengthOfFlightPath; + f = (pathPositionFront - pathNodes[curPathNodeFront].t)/dist; + CVector posFront = (1.0f - f)*pathNodes[curPathNodeFront].p + f*pathNodes[nextPathNodeFront].p; + + // And for another point 60 units in front of the plane, used to calculate roll + float pathPositionFront2 = pathPositionFront + 30.0f; + if(pathPositionFront2 > totalLengthOfFlightPath) + pathPositionFront2 -= totalLengthOfFlightPath; + int curPathNodeFront2 = m_nCurPathNode; + int nextPathNodeFront2 = curPathNodeFront2 + 1; + pos1 = pathNodes[curPathNodeFront2].t; + if(nextPathNodeFront2 < numPathNodes) + pos2 = pathNodes[nextPathNodeFront2].t; + else{ + nextPathNodeFront2 = 0; + pos2 = totalLengthOfFlightPath; + } + while(pathPositionFront2 < pos1 || pathPositionFront2 > pos2){ + curPathNodeFront2 = (curPathNodeFront2+1) % numPathNodes; + nextPathNodeFront2 = curPathNodeFront2 + 1; + pos1 = pathNodes[curPathNodeFront2].t; + if(nextPathNodeFront2 < numPathNodes) + pos2 = pathNodes[nextPathNodeFront2].t; + else{ + nextPathNodeFront2 = 0; + pos2 = totalLengthOfFlightPath; + } + } + dist = pathNodes[nextPathNodeFront2].t - pathNodes[curPathNodeFront2].t; + if(dist < 0.0f) + dist += totalLengthOfFlightPath; + f = (pathPositionFront2 - pathNodes[curPathNodeFront2].t)/dist; + CVector posFront2 = (1.0f - f)*pathNodes[curPathNodeFront2].p + f*pathNodes[nextPathNodeFront2].p; + + // Now set matrix + GetPosition() = (posRear + posFront)/2.0f; + GetPosition().z += 1.0f; + CVector fwd = posFront - posRear; + fwd.Normalise(); + CVector fwd2 = posFront2 - posRear; + fwd2.Normalise(); + CVector roll = CrossProduct(fwd, fwd2); + CVector right = CrossProduct(fwd, CVector(0.0f, 0.0f, 1.0f)); + right.z += 3.0f*roll.z; + right.Normalise(); + CVector up = CrossProduct(right, fwd); + GetRight() = right; + GetUp() = up; + GetForward() = fwd; + + // Set speed + m_vecMoveSpeed = fwd*planePathSpeed/60.0f; + m_fSpeed = planePathSpeed/60.0f; + m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + + m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f)); + } + } + + bIsInSafePosition = true; + GetMatrix().UpdateRW(); + UpdateRwFrame(); + + // Handle streaming and such + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + if(m_isFarAway){ + // Switch to LOD model + if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP){ + DeleteRwObject(); + if(mi->m_planeLodId != -1){ + m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); + if(m_rwObject) + m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); + } + } + }else if(CStreaming::HasModelLoaded(GetModelIndex())){ + if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ + // Get rid of LOD model + m_matrix.Detach(); + if(m_rwObject){ // useless check + if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check + RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); + RpAtomicDestroy((RpAtomic*)m_rwObject); + RwFrameDestroy(f); + } + m_rwObject = nil; + } + } + // Set high detail model + if(m_rwObject == nil){ + int id = GetModelIndex(); + m_modelIndex = -1; + SetModelIndex(id); + } + }else{ + CStreaming::RequestModel(GetModelIndex(), STREAMFLAGS_DEPENDENCY); + } +} + +void +CPlane::PreRender(void) +{ + CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + + CVector lookVector = GetPosition() - TheCamera.GetPosition(); + float camDist = lookVector.Magnitude(); + if(camDist != 0.0f) + lookVector *= 1.0f/camDist; + else + lookVector = CVector(1.0f, 0.0f, 0.0f); + float behindness = DotProduct(lookVector, GetForward()); + + // Wing lights + if(behindness < 0.0f){ + // in front of plane + CVector lightPos = mi->m_positions[PLANE_POS_LIGHT_RIGHT]; + CVector lightR = GetMatrix() * lightPos; + CVector lightL = lightR; + lightL -= GetRight()*2.0f*lightPos.x; + + float intensity = -0.6f*behindness + 0.4f; + float size = 1.0f - behindness; + + if(behindness < -0.9f && camDist < 50.0f){ + // directly in front + CCoronas::RegisterCorona((uintptr)this + 10, 255*intensity, 255*intensity, 255*intensity, 255, + lightL, size, 240.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + CCoronas::RegisterCorona((uintptr)this + 11, 255*intensity, 255*intensity, 255*intensity, 255, + lightR, size, 240.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + }else{ + CCoronas::RegisterCorona((uintptr)this + 10, 255*intensity, 255*intensity, 255*intensity, 255, + lightL, size, 240.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + CCoronas::RegisterCorona((uintptr)this + 11, 255*intensity, 255*intensity, 255*intensity, 255, + lightR, size, 240.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + } + } + + // Tail light + if(CTimer::GetTimeInMilliseconds() & 0x200){ + CVector pos = GetMatrix() * mi->m_positions[PLANE_POS_LIGHT_TAIL]; + + CCoronas::RegisterCorona((uintptr)this + 12, 255, 0, 0, 255, + pos, 1.0f, 120.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); + } +} + +void +CPlane::Render(void) +{ + CEntity::Render(); +} + +#define CRUISE_SPEED (50.0f) +#define TAXI_SPEED (5.0f) + +void +CPlane::InitPlanes(void) +{ + int i; + + CesnaMissionStatus = CESNA_STATUS_NONE; + + // Jumbo + if(pPathNodes == nil){ + pPathNodes = LoadPath("data\\paths\\flight.dat", NumPathNodes, TotalLengthOfFlightPath, true); + + // Figure out which nodes are on ground + CColPoint colpoint; + CEntity *entity; + for(i = 0; i < NumPathNodes; i++){ + if(CWorld::ProcessVerticalLine(pPathNodes[i].p, 1000.0f, colpoint, entity, true, false, false, false, true, false, nil)){ + pPathNodes[i].p.z = colpoint.point.z; + pPathNodes[i].bOnGround = true; + }else + pPathNodes[i].bOnGround = false; + } + + // Find lading and takeoff points + LandingPoint = -1.0f; + TakeOffPoint = -1.0f; + bool lastOnGround = pPathNodes[NumPathNodes-1].bOnGround; + for(i = 0; i < NumPathNodes; i++){ + if(pPathNodes[i].bOnGround && !lastOnGround) + LandingPoint = pPathNodes[i].t; + else if(!pPathNodes[i].bOnGround && lastOnGround) + TakeOffPoint = pPathNodes[i].t; + lastOnGround = pPathNodes[i].bOnGround; + } + + // Animation + float time = 0.0f; + float position = 0.0f; + // Start on ground with slow speed + aPlaneLineBits[0].type = 1; + aPlaneLineBits[0].time = time; + aPlaneLineBits[0].position = position; + aPlaneLineBits[0].speed = TAXI_SPEED; + aPlaneLineBits[0].acceleration = 0.0f; + float dist = (TakeOffPoint-600.0f) - position; + time += dist/TAXI_SPEED; + position += dist; + + // Accelerate to take off + aPlaneLineBits[1].type = 2; + aPlaneLineBits[1].time = time; + aPlaneLineBits[1].position = position; + aPlaneLineBits[1].speed = TAXI_SPEED; + aPlaneLineBits[1].acceleration = 33.0f/32.0f; + time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f); + position += 600.0f; + + // Fly at cruise speed + aPlaneLineBits[2].type = 1; + aPlaneLineBits[2].time = time; + aPlaneLineBits[2].position = position; + aPlaneLineBits[2].speed = CRUISE_SPEED; + aPlaneLineBits[2].acceleration = 0.0f; + dist = LandingPoint - TakeOffPoint; + time += dist/CRUISE_SPEED; + position += dist; + + // Brake after landing + aPlaneLineBits[3].type = 2; + aPlaneLineBits[3].time = time; + aPlaneLineBits[3].position = position; + aPlaneLineBits[3].speed = CRUISE_SPEED; + aPlaneLineBits[3].acceleration = -33.0f/32.0f; + time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f); + position += 600.0f; + + // Taxi + aPlaneLineBits[4].type = 1; + aPlaneLineBits[4].time = time; + aPlaneLineBits[4].position = position; + aPlaneLineBits[4].speed = TAXI_SPEED; + aPlaneLineBits[4].acceleration = 0.0f; + time += (TotalLengthOfFlightPath - position)/TAXI_SPEED; + + // end + aPlaneLineBits[5].time = time; + TotalDurationOfFlightPath = time; + } + + // Dodo + if(pPath2Nodes == nil){ + pPath2Nodes = LoadPath("data\\paths\\flight2.dat", NumPath2Nodes, TotalLengthOfFlightPath2, true); + TotalDurationOfFlightPath2 = TotalLengthOfFlightPath2/CRUISE_SPEED; + } + + // Mission Cesna + if(pPath3Nodes == nil){ + pPath3Nodes = LoadPath("data\\paths\\flight3.dat", NumPath3Nodes, TotalLengthOfFlightPath3, false); + TotalDurationOfFlightPath3 = TotalLengthOfFlightPath3/CRUISE_SPEED; + } + + // Mission Cesna + if(pPath4Nodes == nil){ + pPath4Nodes = LoadPath("data\\paths\\flight4.dat", NumPath4Nodes, TotalLengthOfFlightPath4, false); + TotalDurationOfFlightPath4 = TotalLengthOfFlightPath4/CRUISE_SPEED; + } + + CStreaming::LoadAllRequestedModels(false); + CStreaming::RequestModel(MI_AIRTRAIN, 0); + CStreaming::LoadAllRequestedModels(false); + + for(i = 0; i < 3; i++){ + CPlane *plane = new CPlane(MI_AIRTRAIN, PERMANENT_VEHICLE); + plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); + plane->m_status = STATUS_ABANDONED; + plane->bIsLocked = true; + plane->m_nPlaneId = i; + plane->m_nCurPathNode = 0; + CWorld::Add(plane); + } + + + CStreaming::RequestModel(MI_DEADDODO, 0); + CStreaming::LoadAllRequestedModels(false); + + for(i = 0; i < 3; i++){ + CPlane *plane = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); + plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); + plane->m_status = STATUS_ABANDONED; + plane->bIsLocked = true; + plane->m_nPlaneId = i; + plane->m_nCurPathNode = 0; + CWorld::Add(plane); + } +} + +void +CPlane::Shutdown(void) +{ + delete[] pPathNodes; + delete[] pPath2Nodes; + delete[] pPath3Nodes; + delete[] pPath4Nodes; + pPathNodes = nil; + pPath2Nodes = nil; + pPath3Nodes = nil; + pPath4Nodes = nil; +} + +CPlaneNode* +CPlane::LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool loop) +{ + int bp, lp; + int i; + + CFileMgr::LoadFile(filename, work_buff, sizeof(work_buff), "r"); + *gString = '\0'; + for(bp = 0, lp = 0; work_buff[bp] != '\n'; bp++, lp++) + gString[lp] = work_buff[bp]; + bp++; + gString[lp] = '\0'; + sscanf(gString, "%d", &numNodes); + CPlaneNode *nodes = new CPlaneNode[numNodes]; + + for(i = 0; i < numNodes; i++){ + *gString = '\0'; + for(lp = 0; work_buff[bp] != '\n'; bp++, lp++) + gString[lp] = work_buff[bp]; + bp++; + // BUG: game doesn't terminate string + gString[lp] = '\0'; + sscanf(gString, "%f %f %f", &nodes[i].p.x, &nodes[i].p.y, &nodes[i].p.z); + } + + // Calculate length of segments and path + totalLength = 0.0f; + for(i = 0; i < numNodes; i++){ + nodes[i].t = totalLength; + float l = (nodes[(i+1) % numNodes].p - nodes[i].p).Magnitude2D(); + if(!loop && i == numNodes-1) + l = 0.0f; + totalLength += l; + } + + return nodes; +} + +void +CPlane::UpdatePlanes(void) +{ + int i, j; + uint32 time; + float t, deltaT; + + if(CReplay::IsPlayingBack()) + return; + + // Jumbo jets + time = CTimer::GetTimeInMilliseconds(); + for(i = 0; i < 3; i++){ + t = TotalDurationOfFlightPath * (float)(time & 0x7FFFF)/0x80000; + // find current frame + for(j = 0; t > aPlaneLineBits[j+1].time; j++); + + OldPlanePathPosition[i] = PlanePathPosition[i]; + deltaT = t - aPlaneLineBits[j].time; + switch(aPlaneLineBits[j].type){ + case 0: // standing still + PlanePathPosition[i] = aPlaneLineBits[j].position; + PlanePathSpeed[i] = 0.0f; + break; + case 1: // moving with constant speed + PlanePathPosition[i] = aPlaneLineBits[j].position + aPlaneLineBits[j].speed*deltaT; + PlanePathSpeed[i] = (TotalDurationOfFlightPath*1000.0f/0x80000) * aPlaneLineBits[j].speed; + break; + case 2: // accelerating/braking + PlanePathPosition[i] = aPlaneLineBits[j].position + (aPlaneLineBits[j].speed + aPlaneLineBits[j].acceleration*deltaT)*deltaT; + PlanePathSpeed[i] = (TotalDurationOfFlightPath*1000.0f/0x80000)*aPlaneLineBits[j].speed + 2.0f*aPlaneLineBits[j].acceleration*deltaT; + break; + } + + // time offset for each plane + time += 0x80000/3; + } + + time = CTimer::GetTimeInMilliseconds(); + + t = TotalDurationOfFlightPath2/0x80000; + PlanePath2Position[0] = CRUISE_SPEED * (time & 0x7FFFF)*t; + PlanePath2Position[1] = CRUISE_SPEED * ((time + 0x80000/3) & 0x7FFFF)*t; + PlanePath2Position[2] = CRUISE_SPEED * ((time + 0x80000/3*2) & 0x7FFFF)*t; + PlanePath2Speed[0] = CRUISE_SPEED*t; + PlanePath2Speed[1] = CRUISE_SPEED*t; + PlanePath2Speed[2] = CRUISE_SPEED*t; + + if(CesnaMissionStatus == CESNA_STATUS_FLYING){ + PlanePath3Speed = CRUISE_SPEED*TotalDurationOfFlightPath3/0x20000; + PlanePath3Position = PlanePath3Speed * ((time - CesnaMissionStartTime) & 0x1FFFF); + if(time - CesnaMissionStartTime >= 128072) + CesnaMissionStatus = CESNA_STATUS_LANDED; + } + + if(DropOffCesnaMissionStatus == CESNA_STATUS_FLYING){ + PlanePath4Speed = CRUISE_SPEED*TotalDurationOfFlightPath4/0x80000; + PlanePath4Position = PlanePath4Speed * ((time - DropOffCesnaMissionStartTime) & 0x7FFFF); + if(time - DropOffCesnaMissionStartTime >= 521288) + DropOffCesnaMissionStatus = CESNA_STATUS_LANDED; + } +} + +bool +CPlane::TestRocketCollision(CVector *rocketPos) +{ + int i; + + i = CPools::GetVehiclePool()->GetSize(); + while(--i >= 0){ + CPlane *plane = (CPlane*)CPools::GetVehiclePool()->GetSlot(i); + if(plane && +#ifdef EXPLODING_AIRTRAIN + (plane->GetModelIndex() == MI_AIRTRAIN || plane->GetModelIndex() == MI_DODO) && +#else + plane->GetModelIndex() != MI_AIRTRAIN && plane->GetModelIndex() == MI_DODO && // strange check +#endif + !plane->m_bHasBeenHit && (*rocketPos - plane->GetPosition()).Magnitude() < 25.0f){ + plane->m_nFrameWhenHit = CTimer::GetFrameCounter(); + plane->m_bHasBeenHit = true; + CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->RegisterCrime_Immediately(CRIME_DESTROYED_CESSNA, + plane->GetPosition(), i+1983, false); + return true; + } + } + return false; +} + +// BUG: not in CPlane in the game +void +CPlane::CreateIncomingCesna(void) +{ + if(CesnaMissionStatus == CESNA_STATUS_FLYING){ + CWorld::Remove(pDrugRunCesna); + delete pDrugRunCesna; + pDrugRunCesna = nil; + } + pDrugRunCesna = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); + pDrugRunCesna->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); + pDrugRunCesna->m_status = STATUS_ABANDONED; + pDrugRunCesna->bIsLocked = true; + pDrugRunCesna->m_nPlaneId = 0; + pDrugRunCesna->m_nCurPathNode = 0; + pDrugRunCesna->m_bIsDrugRunCesna = true; + CWorld::Add(pDrugRunCesna); + + CesnaMissionStatus = CESNA_STATUS_FLYING; + CesnaMissionStartTime = CTimer::GetTimeInMilliseconds(); + printf("CPlane::CreateIncomingCesna(void)\n"); +} + +void +CPlane::CreateDropOffCesna(void) +{ + if(DropOffCesnaMissionStatus == CESNA_STATUS_FLYING){ + CWorld::Remove(pDropOffCesna); + delete pDropOffCesna; + pDropOffCesna = nil; + } + pDropOffCesna = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); + pDropOffCesna->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); + pDropOffCesna->m_status = STATUS_ABANDONED; + pDropOffCesna->bIsLocked = true; + pDropOffCesna->m_nPlaneId = 0; + pDropOffCesna->m_nCurPathNode = 0; + pDropOffCesna->m_bIsDropOffCesna = true; + CWorld::Add(pDropOffCesna); + + DropOffCesnaMissionStatus = CESNA_STATUS_FLYING; + DropOffCesnaMissionStartTime = CTimer::GetTimeInMilliseconds(); + printf("CPlane::CreateDropOffCesna(void)\n"); +} + +CVector CPlane::FindDrugPlaneCoordinates(void) { return pDrugRunCesna->GetPosition(); } +CVector CPlane::FindDropOffCesnaCoordinates(void) { return pDrugRunCesna->GetPosition(); } +bool CPlane::HasCesnaLanded(void) { return CesnaMissionStatus == CESNA_STATUS_LANDED; } +bool CPlane::HasCesnaBeenDestroyed(void) { return CesnaMissionStatus == CESNA_STATUS_DESTROYED; } +bool CPlane::HasDropOffCesnaBeenShotDown(void) { return DropOffCesnaMissionStatus == CESNA_STATUS_DESTROYED; } + + +class CPlane_ : public CPlane +{ +public: + void ctor(int32 id, uint8 CreatedBy) { ::new (this) CPlane(id, CreatedBy); } + void dtor(void) { CPlane::~CPlane(); } +}; + +STARTPATCHES + InjectHook(0x54B170, &CPlane_::ctor, PATCH_JUMP); + InjectHook(0x54B270, &CPlane_::dtor, PATCH_JUMP); + InjectHook(0x54B820, CPlane::InitPlanes, PATCH_JUMP); + InjectHook(0x54BCD0, CPlane::Shutdown, PATCH_JUMP); + InjectHook(0x54BD50, CPlane::LoadPath, PATCH_JUMP); + InjectHook(0x54BEC0, CPlane::UpdatePlanes, PATCH_JUMP); + InjectHook(0x54DE90, CPlane::TestRocketCollision, PATCH_JUMP); + InjectHook(0x54E000, CPlane::CreateIncomingCesna, PATCH_JUMP); + InjectHook(0x54E160, CPlane::CreateDropOffCesna, PATCH_JUMP); +ENDPATCHES diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 775689f7..dd15d910 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -273,7 +273,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon right = -contactSpeedRight/wheelsOnGround; if(wheelStatus == WHEEL_STATUS_BURST){ - float fwdspeed = min(contactSpeedFwd, 0.3f); + float fwdspeed = Min(contactSpeedFwd, 0.3f); right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); } } @@ -363,7 +363,7 @@ CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVec void CVehicle::ExtinguishCarFire(void) { - m_fHealth = max(m_fHealth, 300.0f); + m_fHealth = Max(m_fHealth, 300.0f); if(m_pCarFire) m_pCarFire->Extinguish(); if(IsCar()){ @@ -638,13 +638,13 @@ CVehicle::SetDriver(CPed *driver) if(bFreebies && driver == FindPlayerPed()){ if(GetModelIndex() == MI_AMBULAN) - FindPlayerPed()->m_fHealth = min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); + FindPlayerPed()->m_fHealth = Min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); else if(GetModelIndex() == MI_TAXI) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; else if(GetModelIndex() == MI_POLICE) driver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5); else if(GetModelIndex() == MI_ENFORCER) - driver->m_fArmour = max(driver->m_fArmour, 100.0f); + driver->m_fArmour = Max(driver->m_fArmour, 100.0f); else if(GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; bFreebies = false; -- cgit v1.2.3 From 458fc63f0196dc92362b44d5cf7ebf67bbc903e1 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Fri, 2 Aug 2019 17:43:40 +0200 Subject: Cleanup --- src/animation/AnimBlendAssociation.cpp | 4 +- src/animation/AnimBlendHierarchy.cpp | 2 +- src/audio/AudioManager.cpp | 1737 ++++++++---- src/audio/AudioManager.h | 95 +- src/audio/DMAudio.cpp | 2 + src/control/Bridge.h | 27 +- src/control/PathFind.cpp | 10 +- src/control/Replay.cpp | 38 +- src/control/Script.cpp | 6 +- src/core/Camera.cpp | 10 +- src/core/Collision.cpp | 8 +- src/core/Frontend.cpp | 2 +- src/core/Pad.cpp | 4 +- src/core/Streaming.cpp | 42 +- src/core/Wanted.cpp | 2 +- src/core/main.cpp | 2 +- src/core/re3.cpp | 26 - src/core/re3.cpp.autosave | 483 ---- src/entities/Physical.cpp | 40 +- src/peds/Ped.cpp | 10 +- src/peds/PedPlacement.cpp | 2 +- src/peds/PlayerPed.cpp | 8 - src/peds/PlayerPed.cpp.autosave | 110 - src/render/Clouds.cpp | 8 +- src/render/Coronas.cpp | 20 +- src/render/Lights.cpp | 28 +- src/render/ParticleMgr.cpp | 2 +- src/render/PointLights.cpp | 2 +- src/render/Shadows.cpp | 26 +- src/render/Timecycle.cpp | 6 +- src/render/WaterLevel.cpp | 10 +- src/vehicles/Automobile.cpp | 50 +- src/vehicles/Automobile.cpp.autosave | 4560 -------------------------------- src/vehicles/Automobile.h | 2 +- src/vehicles/Boat.cpp | 2 +- src/vehicles/Heli.cpp | 8 - src/vehicles/Heli.cpp.autosave | 1055 -------- src/vehicles/Plane.cpp | 8 - src/vehicles/Plane.cpp.autosave | 985 ------- src/vehicles/Vehicle.cpp | 12 +- src/vehicles/Vehicle.h | 4 +- 41 files changed, 1462 insertions(+), 7996 deletions(-) delete mode 100644 src/core/re3.cpp.autosave delete mode 100644 src/peds/PlayerPed.cpp.autosave delete mode 100644 src/vehicles/Automobile.cpp.autosave delete mode 100644 src/vehicles/Heli.cpp.autosave delete mode 100644 src/vehicles/Plane.cpp.autosave (limited to 'src') diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index 7273c846..d94fe2c1 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -185,7 +185,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount <= 0.0f && blendDelta < 0.0f){ // We're faded out and are not fading in blendAmount = 0.0f; - blendDelta = Max(0.0, blendDelta); + blendDelta = max(0.0, blendDelta); if(flags & ASSOC_DELETEFADEDOUT){ if(callbackType == CB_FINISH || callbackType == CB_DELETE) callback(this, callbackArg); @@ -197,7 +197,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount > 1.0f){ // Maximally faded in, clamp values blendAmount = 1.0f; - blendDelta = Min(0.0, blendDelta); + blendDelta = min(0.0, blendDelta); } return true; diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp index e594e5d8..e4bcdc69 100644 --- a/src/animation/AnimBlendHierarchy.cpp +++ b/src/animation/AnimBlendHierarchy.cpp @@ -36,7 +36,7 @@ CAnimBlendHierarchy::CalcTotalTime(void) float seqTime = 0.0f; for(j = 0; j < sequences[i].numFrames; j++) seqTime += sequences[i].GetKeyFrame(j)->deltaTime; - totalTime = Max(totalTime, seqTime); + totalTime = max(totalTime, seqTime); } totalLength = totalTime; } diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 76bfb793..e08efbc6 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -4,23 +4,30 @@ #include "AudioManager.h" #include "Automobile.h" +#include "Boat.h" +#include "Bridge.h" #include "Camera.h" #include "DMAudio.h" #include "Explosion.h" #include "Garages.h" +#include "Heli.h" #include "ModelIndices.h" #include "MusicManager.h" +#include "Pad.h" #include "Ped.h" #include "Physical.h" #include "Plane.h" #include "PlayerPed.h" #include "Pools.h" -#include "sampman.h" +#include "Replay.h" #include "Stats.h" #include "SurfaceTable.h" +#include "Transmission.h" #include "Vehicle.h" -#include "Plane.h" +#include "Weather.h" #include "World.h" +#include "ZoneCull.h" +#include "sampman.h" uint32 *audioLogicTimers = (uint32 *)0x6508A0; @@ -254,70 +261,7 @@ cAudioManager::AddReleasingSounds() EAXJMP(0x57B8D0); } #else -void -cAudioManager::AddReleasingSounds() -{ - bool isFirstSampleQueue; - int32 calculatedIndex; - tActiveSample *sample; - uint8 field_76; - uint8 field_88; - int sampleQueue; - bool toProcess[44]; - isFirstSampleQueue = m_bActiveSampleQueue == 0; - - cAudioManager *s = (this + 2484 * isFirstSampleQueue); // wtf - - for(uint32 i = 0; i < m_bSampleRequestQueuesStatus[isFirstSampleQueue]; i++) { - calculatedIndex = i + 27 * isFirstSampleQueue; - sample = &s->m_asSamples[m_abSampleQueueIndexTable[calculatedIndex]]; - if(!s->m_asSamples[m_abSampleQueueIndexTable[calculatedIndex]].m_bLoopEnded) { - toProcess[i] = 0; - sampleQueue = m_bActiveSampleQueue; - for(uint8 j = 0; j < m_bSampleRequestQueuesStatus[m_bActiveSampleQueue]; - j++) { - if(sample->m_nEntityIndex == - m_asSamples[27 * sampleQueue + - m_abSampleQueueIndexTable[27 * sampleQueue + j]] - .m_nEntityIndex && - sample->field_4 == - m_asSamples[27 * sampleQueue + - m_abSampleQueueIndexTable[27 * sampleQueue + j]] - .field_4) { - toProcess[i] = 1; - break; - } - } - if(!toProcess[i]) { - if(sample->field_4 <= 255u || !sample->m_bLoopsRemaining) { - field_76 = sample->field_76; - if(!field_76) continue; - if(!sample->m_nLoopCount) { - uint8 &vol = sample->m_bVolume; - if(sample->field_88 == -1) { - sample->field_88 = vol / field_76; - if(sample->field_88 <= 0) - sample->field_88 = 1; - } - field_88 = sample->field_88; - if(vol <= field_88) { - sample->field_76 = 0; - continue; - } - vol -= field_88; - } - --sample->field_76; - if(field_2) { - if(sample->field_16 < 20u) ++sample->field_16; - } - sample->field_56 = 0; - } - memcpy(&m_sQueueSample, sample, 92); - AddSampleToRequestedQueue(); - } - } - } -} + #endif void @@ -453,9 +397,9 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float speedOfSource = (dist / field_19195) * speedMultiplier; if(speedOfSound > fabsf(speedOfSource)) { if(speedOfSource < 0.0f) { - speedOfSource = Max(speedOfSource, -1.5f); + speedOfSource = max(speedOfSource, -1.5f); } else { - speedOfSource = Min(speedOfSource, 1.5f); + speedOfSource = min(speedOfSource, 1.5f); } newFreq = (oldFreq * speedOfSound) / (speedOfSource + speedOfSound); } @@ -3407,6 +3351,13 @@ cAudioManager::GetGenericFemaleTalkSfx(int16 sound) return sfx; } +WRAPPER +void +cAudioManager::PlayOneShot(int32 index, int16 sound, float vol) +{ + EAXJMP(0x57A500); +} + #if 1 WRAPPER @@ -3417,317 +3368,7 @@ cAudioManager::ProcessActiveQueues() } #else -void -cAudioManager::ProcessActiveQueues() -{ - int v3; // ecx - cAudioManager *v4; // edx - tActiveSample *v5; // ebx - cAudioManager *v6; // edi - tActiveSample *v7; // esi - char v8; // al - unsigned __int8 v9; // dl - double v10; // st7 - double v11; // st6 - float a4; // ST08_4 - float a3; // ST04_4 - int activeSampleFreq; // ecx - int freq; // edi - int newFreq; // ecx - int v17; // eax - char v18; // al - unsigned __int8 v19; // al - float v20; // ST0C_4 - int v21; // edx - unsigned __int8 v22; // bl - cAudioManager *v23; // ebp - int v24; // ecx - cAudioManager *v25; // edx - tActiveSample *v26; // ebx - cAudioManager *v27; // ebp - unsigned int v28; // edi - unsigned int v29; // eax - unsigned __int8 v30; // cl - double v31; // st4 - double v32; // st7 - double v33; // st6 - double v34; // st5 - float v35; // ST0C_4 - float v36; // ST08_4 - float v37; // ST04_4 - float v38; // ST0C_4 - int v39; // edx - int v40; // [esp+Ch] [ebp-58h] - int v41; // [esp+Ch] [ebp-58h] - unsigned int v42; // [esp+10h] [ebp-54h] - int v43; // [esp+10h] [ebp-54h] - char v44; // [esp+14h] [ebp-50h] - unsigned __int8 v45; // [esp+14h] [ebp-50h] - unsigned __int8 l; // [esp+24h] [ebp-40h] - unsigned __int8 j; // [esp+28h] [ebp-3Ch] - unsigned __int8 k; // [esp+34h] [ebp-30h] - unsigned __int8 i; // [esp+38h] [ebp-2Ch] - CVector a2; // [esp+48h] [ebp-1Ch] - - for(uint32 i = 0; i < m_bActiveSamples; i++) { - m_asSamples[m_bActiveSampleQueue][i].m_bIsProcessed = 0; - m_asActiveSamples[i].m_bIsProcessed = 0; - } - - for(i = 0;; ++i) { - v21 = m_bActiveSampleQueue; - if(i >= m_bSampleRequestQueuesStatus[v21]) break; - v3 = i + 27 * v21; - v4 = (this + 2484 * v21); - v5 = &v4->m_asSamples[m_abSampleQueueIndexTable[v3]]; - if(v4->m_asSamples[m_abSampleQueueIndexTable[v3]].m_nSampleIndex != NO_SAMPLE) { - v6 = this; - for(j = 0;; ++j) { - if(j >= m_bActiveSamples) goto LABEL_58; - v7 = m_asActiveSamples; - if(v5->m_nEntityIndex == m_asActiveSamples[0].m_nEntityIndex && - v5->field_4 == m_asActiveSamples[0].field_4 && - v5->m_nSampleIndex == m_asActiveSamples[0].m_nSampleIndex) { - break; - } - LABEL_56: - v6 = (v6 + 92); - } - if(v5->m_nLoopCount) { - if(m_FrameCounter & 1) { - if(!(j & 1)) { - v8 = 0; - goto LABEL_17; - } - LABEL_16: - v8 = 1; - } else { - if(!(j & 1)) goto LABEL_16; - v8 = 0; - } - LABEL_17: - if(v8 && !SampleManager.GetChannelUsedFlag(j)) { - v5->m_bLoopEnded = 1; - m_asActiveSamples[0].m_bLoopEnded = 1; - m_asActiveSamples[0].m_nSampleIndex = NO_SAMPLE; - v7->m_nEntityIndex = -5; - goto LABEL_56; - } - } - v5->m_bIsProcessed = 1; - m_asActiveSamples[0].m_bIsProcessed = 1; - v5->field_88 = -1; - if(!v5->field_56) { - if(v5->m_bIsDistant) { - if(field_4) { - v9 = v5->m_bEmittingVolume; - if(v9 >= 63u) - v42 = 63; - else - v42 = v9; - v43 = 2 * v42; - } else { - v43 = v5->m_bEmittingVolume; - } - SampleManager.SetChannelFrequency(j, v5->m_nFrequency); - SampleManager.SetChannelEmittingVolume(j, v43); - } else { - v10 = m_asActiveSamples[0].m_fDistance; - v11 = v5->m_fDistance; - m_asActiveSamples[0].m_fDistance = v5->m_fDistance; - a4 = v11; - a3 = v10; - v5->m_nFrequency = ComputeDopplerEffectedFrequency( - v5->m_nFrequency, a3, a4, v5->field_48); - activeSampleFreq = m_asActiveSamples[0].m_nFrequency; - freq = v5->m_nFrequency; - if(freq != activeSampleFreq) { - if(freq <= activeSampleFreq) { - if(activeSampleFreq - 6000 > freq) - freq = activeSampleFreq - 6000; - newFreq = freq; - } else if(activeSampleFreq + 6000 >= freq) { - newFreq = v5->m_nFrequency; - } else { - newFreq = activeSampleFreq + 6000; - } - v7->m_nFrequency = newFreq; - SampleManager.SetChannelFrequency(j, newFreq); - } - v40 = v7->m_bEmittingVolume; - v17 = v5->m_bEmittingVolume; - if(v17 != v40) { - if(v17 <= v40) { - if(v40 - 10 > v17) v17 = v40 - 10; - v41 = v17; - } else if(v40 + 10 >= v17) { - v41 = v5->m_bEmittingVolume; - } else { - v41 = v40 + 10; - } - if(field_4) { - if(v41 >= 63) - v18 = 63; - else - v18 = v41; - v19 = 2 * v18; - } else { - v19 = v41; - } - SampleManager.SetChannelEmittingVolume(j, v19); - v7->m_bEmittingVolume = v41; - } - TranslateEntity(&v5->m_vecPos, &a2); - SampleManager.SetChannel3DPosition(j, a2.x, a2.y, a2.z); - v20 = 0.25f * v5->m_fSoundIntensity; - SampleManager.SetChannel3DDistances( - j, v5->m_fSoundIntensity, v20); - } - SampleManager.SetChannelReverbFlag(j, v5->m_bReverbFlag); - continue; - } - v5->m_bIsProcessed = 0; - m_asActiveSamples[0].m_bIsProcessed = 0; - goto LABEL_56; - } - LABEL_58:; - } - v22 = 0; - v23 = this; - for(uint32 i = 0; v22 < m_bActiveSamples; i++) { - if(v23->m_asActiveSamples[0].m_nSampleIndex != NO_SAMPLE && - !v23->m_asActiveSamples[0].m_bIsProcessed) { - SampleManager.StopChannel(i); - v23->m_asActiveSamples[0].m_nSampleIndex = NO_SAMPLE; - v23->m_asActiveSamples[0].m_nEntityIndex = -5; - } - v23 = (v23 + 92); - } - for(k = 0; k < m_bSampleRequestQueuesStatus[m_bActiveSampleQueue]; ++k) { - v24 = k + 27 * v39; - v25 = (this + 2484 * v39); - v26 = &v25->m_asSamples[m_abSampleQueueIndexTable[v24]]; - if(!v25->m_asSamples[m_abSampleQueueIndexTable[v24]].m_bIsProcessed && - !v25->m_asSamples[m_abSampleQueueIndexTable[v24]].m_bLoopEnded && - m_asAudioEntities[v26->m_nEntityIndex].m_bIsUsed && - v25->m_asSamples[m_abSampleQueueIndexTable[v24]].m_nSampleIndex < NO_SAMPLE) { - if(v25->m_asSamples[m_abSampleQueueIndexTable[v24]].field_4 > 255u && - v25->m_asSamples[m_abSampleQueueIndexTable[v24]].m_nLoopCount && - v25->m_asSamples[m_abSampleQueueIndexTable[v24]].m_bLoopsRemaining) { - --v25->m_asSamples[m_abSampleQueueIndexTable[v24]] - .m_bLoopsRemaining; - v26->field_76 = 1; - } else { - v27 = this; - for(l = 0; l < m_bActiveSamples; ++l) { - if(!v27->m_asActiveSamples[0].m_bIsProcessed) { - if(!v26->m_nLoopCount) goto LABEL_80; - v28 = v26->m_nFrequency / field_19192; - v29 = v26->m_nLoopCount * - SampleManager.GetSampleLength( - v26->m_nSampleIndex); - if(v28) { - v26->field_76 = v29 / v28 + 1; - LABEL_80: - memcpy(v27->m_asActiveSamples, v26, 92); - if(!v27->m_asActiveSamples[0].m_bIsDistant) - TranslateEntity( - &v27->m_asActiveSamples[0] - .m_vecPos, - &a2); - if(field_4) { - if(v27->m_asActiveSamples[0] - .m_bEmittingVolume >= 63u) - v44 = 63; - else - v44 = - v27 - ->m_asActiveSamples - [0] - .m_bEmittingVolume; - v45 = 2 * v44; - } else { - v45 = v27->m_asActiveSamples[0] - .m_bEmittingVolume; - } - if(SampleManager.InitialiseChannel( - l, - v27->m_asActiveSamples[0] - .m_nSampleIndex, - v27->m_asActiveSamples[0] - .m_bBankIndex)) { - SampleManager.SetChannelFrequency( - l, v27->m_asActiveSamples[0] - .m_nFrequency); - cSampleManager - .SetChannelEmittingVolume(l, - v45); - SampleManager.SetChannelLoopPoints( - l, - v27->m_asActiveSamples[0] - .m_nLoopStart, - v27->m_asActiveSamples[0] - .m_nLoopEnd); - SampleManager.SetChannelLoopCount( - l, v27->m_asActiveSamples[0] - .m_nLoopCount); - SampleManager.SetChannelReverbFlag( - l, v27->m_asActiveSamples[0] - .m_bReverbFlag); - if(v27->m_asActiveSamples[0] - .m_bIsDistant) { - v30 = v27->m_asActiveSamples - [0] - .m_bOffset; - if(v30 == 63) { - v31 = 0.0f; - } else if(v30 >= 63u) { - v31 = (v30 - 63) * - 15.873f; - } else { - v31 = -((63 - v30) * - 15.873f); - } - v32 = v31; - v33 = 0.0f; - v34 = 0.0f; - v27->m_asActiveSamples[0] - .m_fSoundIntensity = - 100000.0f; - } else { - v32 = a2.x; - v33 = a2.y; - v34 = a2.z; - } - v35 = v34; - v36 = v33; - v37 = v32; - SampleManager.SetChannel3DPosition( - l, v37, v36, v35); - v38 = 0.25f * - v27->m_asActiveSamples[0] - .m_fSoundIntensity; - cSampleManager - .SetChannel3DDistances( - l, - v27->m_asActiveSamples[0] - .m_fSoundIntensity, - v38); - SampleManager.StartChannel(l); - } - v27->m_asActiveSamples[0].m_bIsProcessed = - 1; - v26->m_bIsProcessed = 1; - v26->field_88 = -1; - break; - } - } - v27 = (v27 + 92); - } - } - } - } -} + #endif bool @@ -3824,25 +3465,235 @@ cAudioManager::ProcessAirportScriptObject(uint8 sound) } } -WRAPPER bool cAudioManager::ProcessBoatEngine(cVehicleParams *params) { - EAXJMP(0x56DE80); + CBoat *boat; + float padRelativeAccerate; + float gasPedal; + int32 padAccelerate; + uint8 emittingVol; + float oneShotVol; + + static uint16 LastAccel = 0; + static uint8 LastVol = 0; + + if(params->m_fDistance < 2500.f) { + boat = (CBoat *)params->m_pVehicle; + if(params->m_nIndex == REEFER) { + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(80u, 50.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 39; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_MOTOR; + m_sQueueSample.m_nFrequency = 10386; + m_sQueueSample.m_nFrequency += + (m_sQueueSample.m_nEntityIndex << 16) % 1000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = 80; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 7; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + if(FindPlayerVehicle() == params->m_pVehicle) { + if(Pads[0].GetAccelerate() <= Pads[0].GetBrake()) + padAccelerate = Pads[0].GetBrake(); + else + padAccelerate = Pads[0].GetAccelerate(); + padRelativeAccerate = padAccelerate / 255; + emittingVol = (100.f * padRelativeAccerate) + 15; + m_sQueueSample.m_nFrequency = (3000.f * padRelativeAccerate) + 6000; + if(!boat->m_bIsAnchored) + m_sQueueSample.m_nFrequency = + 11 * m_sQueueSample.m_nFrequency / 10u; + } else { + gasPedal = Abs(boat->m_fGasPedal); + if(gasPedal > 0.0f) { + m_sQueueSample.m_nFrequency = 6000; + emittingVol = 15; + } else { + emittingVol = (100.f * gasPedal) + 15; + m_sQueueSample.m_nFrequency = (3000.f * gasPedal) + 6000; + if(!boat->m_bIsAnchored) + m_sQueueSample.m_nFrequency = + 11 * m_sQueueSample.m_nFrequency / 10u; + } + } + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance); + if(!m_sQueueSample.m_bVolume) return 1; + m_sQueueSample.field_4 = 40; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; + m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex << 16) % 1000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 7; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + } else { + if(FindPlayerVehicle() == params->m_pVehicle) { + if(Pads[0].GetAccelerate() <= Pads[0].GetBrake()) + padAccelerate = Pads[0].GetBrake(); + else + padAccelerate = Pads[0].GetAccelerate(); + if(padAccelerate <= 20) { + emittingVol = 45 - 45 * padAccelerate / 40; + m_sQueueSample.m_nFrequency = 100 * padAccelerate + 11025; + m_sQueueSample.field_4 = 39; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_BOAT_ENGINE_IDLE; + if(LastAccel > 20) { + oneShotVol = LastVol; + PlayOneShot(m_sQueueSample.m_nEntityIndex, SOUND_17, + oneShotVol); + } + } else { + emittingVol = 105 * padAccelerate / 255 + 15; + m_sQueueSample.m_nFrequency = + 4000 * padAccelerate / 255 + 8000; + if(!boat->m_bIsAnchored) + m_sQueueSample.m_nFrequency = + 11 * m_sQueueSample.m_nFrequency / 10u; + m_sQueueSample.field_4 = 40; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; + } + LastVol = emittingVol; + LastAccel = padAccelerate; + } else { + gasPedal = Abs(boat->m_fGasPedal); + if(gasPedal > 0.0f) { + m_sQueueSample.m_nFrequency = 11025; + emittingVol = 45; + m_sQueueSample.field_4 = 39; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_BOAT_ENGINE_IDLE; + } else { + emittingVol = (105.f * gasPedal) + 15; + m_sQueueSample.m_nFrequency = (4000.f * gasPedal) + 8000; + if(!boat->m_bIsAnchored) + m_sQueueSample.m_nFrequency = + 11 * m_sQueueSample.m_nFrequency / 10u; + m_sQueueSample.field_4 = 40; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; + } + } + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance); + if(!m_sQueueSample.m_bVolume) return 1; + m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex << 16) % 1000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 7; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + } + AddSampleToRequestedQueue(); + return 1; + } + return 0; } -WRAPPER bool cAudioManager::ProcessBoatMovingOverWater(cVehicleParams *params) { - EAXJMP(0x56E500); + float velocityChange; + int32 vol; + float multiplier; + + if(params->m_fDistance > 2500.f) return 0; + + velocityChange = Abs(params->m_fVelocityChange); + if(velocityChange <= 0.0005f && params->m_pVehicle->GetPosition().y) return 1; + + velocityChange = min(0.75f, velocityChange); + multiplier = (velocityChange - 0.0005f) * 1.3342f; + CalculateDistance((bool *)params, params->m_fDistance); + vol = (30.f * multiplier); + m_sQueueSample.m_bVolume = ComputeVolume(vol, 50.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 38; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_LOOPING_WATER; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + m_sQueueSample.m_nFrequency = (6050.f * multiplier) + 16000; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = vol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + + return 1; } -WRAPPER void cAudioManager::ProcessBridge() { - EAXJMP(0x5790D0); + float dist; + bool something = false; + + if(CBridge::pLiftRoad) { + m_sQueueSample.m_vecPos = CBridge::pLiftRoad->GetPosition(); + dist = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(dist < 202500.0f) { + CalculateDistance(&something, dist); + switch(CBridge::State) { + case STATE_BRIDGE_LOCKED: + case STATE_LIFT_PART_IS_UP: + case STATE_LIFT_PART_ABOUT_TO_MOVE_UP: ProcessBridgeWarning(); break; + case STATE_LIFT_PART_MOVING_DOWN: + case STATE_LIFT_PART_MOVING_UP: + ProcessBridgeWarning(); + ProcessBridgeMotor(); + break; + default: break; + } + ProcessBridgeOneShots(); + } + } } void @@ -3873,11 +3724,56 @@ cAudioManager::ProcessBridgeMotor() } } -WRAPPER void cAudioManager::ProcessBridgeOneShots() { - EAXJMP(0x579310); + float maxDist; + + if(CBridge::State != STATE_LIFT_PART_IS_UP || + CBridge::OldState != STATE_LIFT_PART_MOVING_UP) { + if(CBridge::State != STATE_LIFT_PART_IS_DOWN || + CBridge::OldState != STATE_LIFT_PART_MOVING_DOWN) { + if(CBridge::State != STATE_LIFT_PART_MOVING_UP || + CBridge::OldState != STATE_LIFT_PART_ABOUT_TO_MOVE_UP) { + if(CBridge::State != STATE_LIFT_PART_MOVING_DOWN || + CBridge::OldState != STATE_LIFT_PART_IS_UP) + return; + maxDist = 400.f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_METAL_27; + } else { + maxDist = 400.f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_METAL_27; + } + } else { + maxDist = 400.f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_METAL_27; + } + } else { + maxDist = 400.f; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_METAL_27; + } + if(m_sQueueSample.m_fDistance < maxDist) { + m_sQueueSample.m_bVolume = + ComputeVolume(maxVolume, maxDist, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 2; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_bEmittingVolume = maxVolume; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = maxDist; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bReverbFlag = 0; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } } void @@ -3910,11 +3806,40 @@ cAudioManager::ProcessBridgeWarning() } } -WRAPPER bool -cAudioManager::ProcessCarBombTick(void *) +cAudioManager::ProcessCarBombTick(cVehicleParams *params) { - EAXJMP(0x56CC20); + CAutomobile *automobile; + + if(params->m_fDistance >= 1600.f) return 0; + automobile = (CAutomobile *)params->m_pVehicle; + if(automobile->bEngineOn && automobile->m_bombType == CARBOMB_TIMEDACTIVE) { + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = ComputeVolume(60u, 40.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 35; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_CAR_BOMB_TICK; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_CAR_BOMB_TICK); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = 60; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0; + m_sQueueSample.m_fSoundIntensity = 40.0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + return 1; } WRAPPER @@ -4038,35 +3963,84 @@ cAudioManager::ProcessDocksScriptObject(uint8 sound) } } -void -cAudioManager::ProcessEntity(int32 id) +bool +cAudioManager::ProcessEngineDamage(cVehicleParams *params) { - if(m_asAudioEntities[id].m_bStatus) { - m_sQueueSample.m_nEntityIndex = id; - switch(m_asAudioEntities[id].m_nType) { - case AUDIOTYPE_PHYSICAL: - if(!m_bUserPause) { - m_sQueueSample.m_bReverbFlag = 1; - ProcessPhysical(id); - } - break; - case AUDIOTYPE_EXPLOSION: - if(!m_bUserPause) { - m_sQueueSample.m_bReverbFlag = 1; - ProcessExplosions(id); - } - break; - case AUDIOTYPE_FIRE: - if(!m_bUserPause) { - m_sQueueSample.m_bReverbFlag = 1; - ProcessFires(id); - } - break; - case AUDIOTYPE_WEATHER: - if(!m_bUserPause) { - m_sQueueSample.m_bReverbFlag = 1; - ProcessWeather(id); - } + CAutomobile *veh; + uint8 engineStatus; + uint8 emittingVolume; + + if(params->m_fDistance >= 1600.f) return 0; + veh = (CAutomobile *)params->m_pVehicle; + if(veh->bEngineOn) { + engineStatus = veh->Damage.GetEngineStatus(); + if(engineStatus > 250u || engineStatus < 100u) return 1; + if(engineStatus < 225u) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_TAXI_SOUND; + emittingVolume = 6; + m_sQueueSample.field_16 = 7; + m_sQueueSample.m_nFrequency = 40000; + } else { + emittingVolume = 60; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_FIRE_ENTITY; + m_sQueueSample.field_16 = 7; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_FIRE_ENTITY); + } + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVolume, 40.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 28; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVolume; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 2.0; + m_sQueueSample.m_fSoundIntensity = 40.0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + return 1; +} + +void +cAudioManager::ProcessEntity(int32 id) +{ + if(m_asAudioEntities[id].m_bStatus) { + m_sQueueSample.m_nEntityIndex = id; + switch(m_asAudioEntities[id].m_nType) { + case AUDIOTYPE_PHYSICAL: + if(!m_bUserPause) { + m_sQueueSample.m_bReverbFlag = 1; + ProcessPhysical(id); + } + break; + case AUDIOTYPE_EXPLOSION: + if(!m_bUserPause) { + m_sQueueSample.m_bReverbFlag = 1; + ProcessExplosions(id); + } + break; + case AUDIOTYPE_FIRE: + if(!m_bUserPause) { + m_sQueueSample.m_bReverbFlag = 1; + ProcessFires(id); + } + break; + case AUDIOTYPE_WEATHER: + if(!m_bUserPause) { + m_sQueueSample.m_bReverbFlag = 1; + ProcessWeather(id); + } break; case AUDIOTYPE_CRANE: if(!m_bUserPause) { @@ -4406,6 +4380,70 @@ cAudioManager::ProcessGarages() EAXJMP(0x578C20); } +struct tHelicopterSampleData { + float m_fMaxDistance; + float m_fBaseDistance; + char m_bBaseVolume; + char gap_9[3]; +}; + +tHelicopterSampleData *gHeliSfxRanges = (tHelicopterSampleData *)0x604784; + +bool +cAudioManager::ProcessHelicopter(cVehicleParams *params) +{ + CHeli *heli; + float MaxDist; + float dist; + float baseDist; + int32 emittingVol; + + if(gHeliSfxRanges[0].m_fMaxDistance * gHeliSfxRanges[0].m_fMaxDistance <= + params->m_fDistance) + return 0; + + CalculateDistance((bool *)params, params->m_fDistance); + heli = (CHeli *)params->m_pVehicle; + for(uint32 i = 0; i < 3; i++) { + MaxDist = gHeliSfxRanges[i].m_fMaxDistance; + dist = m_sQueueSample.m_fDistance; + if(dist >= MaxDist) return 1; + baseDist = gHeliSfxRanges[i].m_fBaseDistance; + if(dist < baseDist) + emittingVol = (gHeliSfxRanges[i].m_bBaseVolume * + ((MaxDist - dist) / (MaxDist - baseDist))); + else + emittingVol = gHeliSfxRanges[i].m_bBaseVolume; + + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVol, gHeliSfxRanges[i].m_fMaxDistance, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = i + 65; + m_sQueueSample.m_nSampleIndex = i + AUDIO_SAMPLE_HELI_FAR; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_nFrequency = + 1200 * heli->m_nHeliId + + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 6.0; + m_sQueueSample.m_fSoundIntensity = gHeliSfxRanges[i].m_fMaxDistance; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + return 1; +} + void cAudioManager::ProcessHomeScriptObject(uint8 sound) { @@ -5342,6 +5380,71 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) } } +void +cAudioManager::ProcessModelCarEngine(cVehicleParams *params) +{ + cAudioManager *v2; + CAutomobile *automobile; + float allowedVelocity; + int32 emittingVol; + float velocityChange; + + v2 = this; + if(params->m_fDistance < 900.f) { + automobile = (CAutomobile *)params->m_pVehicle; + if(automobile->bEngineOn) { + if(automobile->m_nWheelsOnGround) { + velocityChange = Abs(params->m_fVelocityChange); + } else { + if(automobile->m_nDriveWheelsOnGround) + automobile->m_fGasPedalAudio = + automobile->m_fGasPedalAudio * 0.4f; + velocityChange = automobile->m_fGasPedalAudio * + params->m_pTransmission->fMaxVelocity; + } + if(velocityChange > 0.001f) { + allowedVelocity = 0.5f * params->m_pTransmission->fMaxVelocity; + if(velocityChange < allowedVelocity) + emittingVol = (90.f * velocityChange / allowedVelocity); + else + emittingVol = 90; + if(emittingVol) { + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVol, 30.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = 2; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_MODEL_VEHICLE_ACCELERATING; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nFrequency = + (11025.f * velocityChange / + params->m_pTransmission->fMaxVelocity + + 11025.f); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 3.0; + m_sQueueSample.m_fSoundIntensity = 30.0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } + } + } +} + void cAudioManager::ProcessOneShotScriptObject(uint8 sound) { @@ -5395,7 +5498,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_anRandomTable[iSound % 5] % 3u + AUDIO_SAMPLE_BULLET_HIT_GROUND_1; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); m_sQueueSample.field_16 = 9; m_sQueueSample.field_48 = 0.0f; @@ -5404,14 +5507,14 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) break; case SCRIPT_SOUND_110: case SCRIPT_SOUND_111: - if(cSampleManager.IsSampleBankLoaded(0) != 1) return; + if(SampleManager.IsSampleBankLoaded(0) != 1) return; maxDist = 6400.f; m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_389; m_sQueueSample.m_bBankIndex = 0; emittingVolume = 127; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_389); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_389); m_sQueueSample.field_16 = 0; m_sQueueSample.field_48 = 2.0f; m_sQueueSample.m_bIsDistant = 0; @@ -5423,7 +5526,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; emittingVolume = 80; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PAYPHONE_RINGING); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PAYPHONE_RINGING); m_sQueueSample.field_16 = 1; m_sQueueSample.field_48 = 2.0f; m_sQueueSample.m_bIsDistant = 0; @@ -5436,7 +5539,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; emittingVolume = 70; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 0.0f; m_sQueueSample.m_bIsDistant = 0; @@ -5448,7 +5551,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; emittingVolume = 60; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_GENERIC_BREAK); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 0.0f; m_sQueueSample.m_bIsDistant = 0; @@ -5460,7 +5563,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; emittingVolume = 70; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_WINDSHIELD_CRACK); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_GLASS_WINDSHIELD_CRACK); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 0.0f; m_sQueueSample.m_bIsDistant = 0; @@ -5509,7 +5612,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_anRandomTable[3] % 5u + AUDIO_SAMPLE_COLLISION_METAL; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 0.0f; @@ -5523,7 +5626,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_RUBBER; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 0.0f; @@ -5670,14 +5773,14 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_16 = 5; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_PED_HEADPHONES); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_nLoopStart = - cSampleManager.GetSampleLoopStartOffset( + SampleManager.GetSampleLoopStartOffset( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = cSampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( m_sQueueSample.m_nSampleIndex); m_sQueueSample.field_48 = 4.0f; m_sQueueSample.m_fSoundIntensity = 7.0f; @@ -5704,14 +5807,12 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) int16 sound; char noReflection; CWeapon *weapon; - uint16 i; float maxDist; static uint8 iSound = 21; - i = 0; weapon = nil; - while(i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].field_24) { + for(uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].field_24; i++) { noReflection = 0; processed = 0; m_sQueueSample.m_bRequireReflection = 0; @@ -5778,7 +5879,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_asAudioEntities[0] .m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex] - 28; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17u); @@ -5809,7 +5910,6 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bRequireReflection = 1; - goto LABEL_84; } break; case SOUND_FALL_LAND: @@ -5829,7 +5929,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) } m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17u); @@ -5843,55 +5943,232 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bRequireReflection = 1; - goto LABEL_84; + break; } break; - case SOUND_21: + case SOUND_FIGHT_PUNCH_33: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; m_sQueueSample.m_nFrequency = 18000; - goto LABEL_81; - case SOUND_22: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_KICK_34: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; m_sQueueSample.m_nFrequency = 16500; - goto LABEL_81; - case SOUND_23: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_HEADBUTT_35: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; - goto LABEL_80; - case SOUND_24: + m_sQueueSample.m_nFrequency = 20000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_36: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; m_sQueueSample.m_nFrequency = 18000; - goto LABEL_81; - case SOUND_25: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_37: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; m_sQueueSample.m_nFrequency = 16500; - goto LABEL_81; - case SOUND_26: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_CLOSE_PUNCH_38: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; - goto LABEL_80; - case SOUND_WEAPON_PUNCH_ATTACK: + m_sQueueSample.m_nFrequency = 20000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_39: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; m_sQueueSample.m_nFrequency = 18000; - goto LABEL_81; - case SOUND_28: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_OR_KICK_BELOW_40: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; m_sQueueSample.m_nFrequency = 16500; - goto LABEL_81; - case SOUND_29: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_41: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; - goto LABEL_80; - case SOUND_2A: + m_sQueueSample.m_nFrequency = 20000; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_PUNCH_FROM_BEHIND_42: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; m_sQueueSample.m_nFrequency = 18000; - goto LABEL_81; - case SOUND_2B: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_KNEE_OR_KICK_43: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; m_sQueueSample.m_nFrequency = 16500; - goto LABEL_81; - case SOUND_2C: + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_4 = iSound; + processed = 1; + ++iSound; + m_sQueueSample.field_16 = 3; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + emittingVol = m_anRandomTable[3] % 26 + 100; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; + case SOUND_FIGHT_KICK_44: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; - LABEL_80: m_sQueueSample.m_nFrequency = 20000; - LABEL_81: m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound; processed = 1; @@ -5908,7 +6185,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bRequireReflection = 1; - goto LABEL_84; + break; case SOUND_WEAPON_BAT_ATTACK: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_BY_BAT; m_sQueueSample.m_bBankIndex = 0; @@ -5930,7 +6207,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case SOUND_WEAPON_SHOT_FIRED: weapon = &ped->m_weapons[ped->m_currentWeapon]; switch(weapon->m_eWeaponType) { @@ -5939,7 +6216,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_PISTOL_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -5958,13 +6235,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case WEAPONTYPE_UZI: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_UZI_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -5979,13 +6256,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; - goto LABEL_84; + break; case WEAPONTYPE_SHOTGUN: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -6004,13 +6281,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case WEAPONTYPE_AK47: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -6025,13 +6302,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; - goto LABEL_84; + break; case WEAPONTYPE_M16: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_M16_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_M16_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -6046,13 +6323,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; - goto LABEL_84; + break; case WEAPONTYPE_SNIPERRIFLE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SNIPER_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -6071,13 +6348,13 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case WEAPONTYPE_ROCKETLAUNCHER: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_SHOT; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_ROCKET_SHOT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 5); @@ -6096,7 +6373,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case WEAPONTYPE_FLAMETHROWER: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_FLAMETHROWER_SHOT; @@ -6105,7 +6382,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) emittingVol = 90; m_sQueueSample.m_nFrequency = (10 * m_sQueueSample.m_nEntityIndex & 2047) + - cSampleManager.GetSampleBaseFrequency( + SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_FLAMETHROWER_SHOT); m_sQueueSample.field_16 = 3; m_sQueueSample.field_48 = 4.0f; @@ -6113,9 +6390,9 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) maxDist = 3600.f; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nLoopStart = - cSampleManager.GetSampleLoopStartOffset( + SampleManager.GetSampleLoopStartOffset( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = cSampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_bEmittingVolume = 90; m_sQueueSample.m_bIsDistant = 0; @@ -6125,8 +6402,8 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; - default: goto LABEL_100; + break; + default: continue; } break; @@ -6139,57 +6416,133 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.field_4 = iSound++; processed = 1; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency( + SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_PISTOL_RELOAD) + RandomDisplacement(300u); - goto LABEL_63; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_UZI: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; m_sQueueSample.m_nFrequency = 39243; - goto LABEL_63; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_SHOTGUN: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; m_sQueueSample.m_nFrequency = 30290; - goto LABEL_63; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_AK47: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD); - goto LABEL_62; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_M16: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_UZI_RELOAD); - goto LABEL_62; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_SNIPERRIFLE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD); - goto LABEL_62; + m_sQueueSample.m_nFrequency += RandomDisplacement(300u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + maxDist = 900.f; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bEmittingVolume = 75; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bRequireReflection = 1; + break; case WEAPONTYPE_ROCKETLAUNCHER: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD; emittingVol = 75; m_sQueueSample.field_4 = iSound++; processed = 1; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD); - LABEL_62: - LABEL_63: m_sQueueSample.m_nFrequency += RandomDisplacement(300u); m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_16 = 5; @@ -6203,10 +6556,9 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bRequireReflection = 1; - goto LABEL_84; - default: goto LABEL_100; + break; + default: continue; } - break; case SOUND_WEAPON_AK47_BULLET_ECHO: case SOUND_WEAPON_UZI_BULLET_ECHO: @@ -6216,7 +6568,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.field_4 = iSound++; processed = 1; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_75); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_75); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); m_sQueueSample.field_16 = 3; @@ -6234,12 +6586,12 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bRequireReflection = 1; else noReflection = 1; - goto LABEL_84; + break; case SOUND_WEAPON_FLAMETHROWER_FIRE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; - m_sQueueSample.m_nFrequency = cSampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); @@ -6254,14 +6606,14 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bEmittingVolume = 70; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; - goto LABEL_84; + break; case SOUND_WEAPON_HIT_PED: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BULLET_HIT_PED; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.field_4 = iSound++; processed = 1; m_sQueueSample.m_nFrequency = - cSampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_BULLET_HIT_PED); + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_BULLET_HIT_PED); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 3); m_sQueueSample.field_16 = 7; @@ -6275,7 +6627,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; - goto LABEL_84; + break; case SOUND_SPLASH: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_WATER; m_sQueueSample.m_bBankIndex = 0; @@ -6294,7 +6646,11 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bRequireReflection = 1; - LABEL_84: + break; + default: + SetupPedComments(params, sound); + continue; + if(processed && iSound > 60u) iSound = 21; if(params->m_fDistance < maxDist) { CalculateDistance((bool *)params, params->m_fDistance); @@ -6331,11 +6687,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) } } } - break; - default: SetupPedComments(params, sound); break; } - LABEL_100: - ++i; } } @@ -6356,11 +6708,318 @@ cAudioManager::ProcessPhysical(int32 id) } } -WRAPPER void -cAudioManager::ProcessPlane(void *ptr) +cAudioManager::ProcessPlane(cVehicleParams *params) { - EAXJMP(0x56E860); + switch(params->m_nIndex) { + case AIRTRAIN: ProcessJumbo(params); break; + case DEADDODO: ProcessCesna(params); break; + default: debug("Plane Model Id is %d\n, ", params->m_pVehicle->m_modelIndex); break; + } +} + +struct tVehicleSampleData { + eAudioSamples m_nAccelerationSampleIndex; + char m_bEngineSoundType; + char gap_5[3]; + eAudioSamples m_nHornSample; + int m_nHornFrequency; + char m_nSirenOrAlarmSample; + int m_nSirenOrAlarmFrequency; + char m_bDoorType; + char gap_25[3]; +}; + +int32 *CSWTCH_554 = (int32 *)0x606A50; +tVehicleSampleData *vehicleSampleData = (tVehicleSampleData *)0x606204; + +void +cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *automobile) +{ + cTransmission *transmission; + float velocityChange; + float relativeVelocityChange; + float accelerationMultipler; + uint8 wheelInUseCounter; + uint8 i; + float time; + uint32 freq4; + int baseFreq; + uint8 vol; + unsigned int freq5; + int gearNr; + int freq; + unsigned int freq3; + unsigned int freq2; + + int freqModifier; + int soundOffset; + uint8 engineSoundType; + int32 accelerateState; + bool channelUsed; + char lostTraction; + bool processedAccelSampleStopped; + uint8 currentGear; + float gasPedalAudio; + CVector pos; + + static uint16 LastAccel = 0; + static uint16 LastBrake = 0; + static uint8 CurrentPretendGear = 1; + static bool bLostTractionLastFrame = 0; + static bool bHandbrakeOnLastFrame = 0; + static uint32 nCruising = 0; + static uint8 bAccelSampleStopped = 1; + + lostTraction = 0; + processedAccelSampleStopped = 0; + if(bPlayerJustEnteredCar) { + bAccelSampleStopped = 1; + bPlayerJustEnteredCar = 0; + nCruising = 0; + LastAccel = 0; + bLostTractionLastFrame = 0; + LastBrake = 0; + bHandbrakeOnLastFrame = 0; + CurrentPretendGear = 1; + } + if(CReplay::IsPlayingBack()) { + accelerateState = 255.f * max(0.0f, min(1.0f, automobile->m_fGasPedal)); + } else { + accelerateState = Pads->GetAccelerate(); + } + channelUsed = SampleManager.GetChannelUsedFlag(m_bActiveSamples); + transmission = params->m_pTransmission; + velocityChange = params->m_fVelocityChange; + relativeVelocityChange = 2.0f * velocityChange / transmission->fMaxVelocity; + + accelerationMultipler = 0.0f; + + if(relativeVelocityChange > 1.0f) accelerationMultipler = relativeVelocityChange; + + gasPedalAudio = accelerationMultipler; + currentGear = params->m_pVehicle->m_nCurrentGear; + if(transmission->nDriveType == '4') { + wheelInUseCounter = 0; + i = 0; + do { + if(automobile->m_aWheelState[i]) ++wheelInUseCounter; + ++i; + } while(i < 4u); + if(wheelInUseCounter > 2u) lostTraction = 1; + } else if(transmission->nDriveType == 'F') { + if((automobile->m_aWheelState[0] || automobile->m_aWheelState[2]) && + (automobile->m_aWheelState[1] || automobile->m_aWheelState[3])) { + lostTraction = 1; + } + } else if(transmission->nDriveType == 'R' && + (automobile->m_aWheelState[1] || automobile->m_aWheelState[3])) { + lostTraction = 1; + } + if(0.0f != velocityChange) { // ok + time = params->m_pVehicle->m_vecMoveSpeed.z / velocityChange; + if(time <= 0.0f) { + freqModifier = max(-0.2f, time) * -15000.f; + } else { + freqModifier = -(min(0.2f, time) * 15000.f); + } + if(params->m_fVelocityChange < -0.001f) freqModifier = -freqModifier; // ok + } else { + freqModifier = 0; + } + engineSoundType = vehicleSampleData[params->m_nIndex].m_bEngineSoundType; + soundOffset = 3 * (engineSoundType - 1); + if(accelerateState <= 0) { + if(params->m_fVelocityChange < -0.001f) { + if(channelUsed) { + SampleManager.StopChannel(m_bActiveSamples); + bAccelSampleStopped = 1; + } + if(!automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || + lostTraction) { + gasPedalAudio = automobile->m_fGasPedalAudio; + } else { + gasPedalAudio = min( + 1.0f, params->m_fVelocityChange / + params->m_pTransmission->fMaxReverseVelocity); // ok + } + gasPedalAudio = max(0.0f, gasPedalAudio); // ok + automobile->m_fGasPedalAudio = gasPedalAudio; + } else if(LastAccel > 0) { + if(channelUsed) { + SampleManager.StopChannel(m_bActiveSamples); + bAccelSampleStopped = 1; + } + nCruising = 0; + if(!automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || + lostTraction || + params->m_fVelocityChange >= 0.01f && + automobile->m_fGasPedalAudio > 0.2f) { + automobile->m_fGasPedalAudio = automobile->m_fGasPedalAudio * 0.6f; + gasPedalAudio = automobile->m_fGasPedalAudio; + } + if(gasPedalAudio > 0.05) { // ok + freq3 = (5000.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 19000; + if(engineSoundType == 6) freq3 >>= 1; + AddPlayerCarSample( + (25.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 40, freq3, + (soundOffset + AUDIO_SAMPLE_VEHICLE_ENGINE_STOPPING_GENERIC), + engineSoundType, 63u, 0); + } + } + freq2 = (10000.f * gasPedalAudio) + 22050; + if(engineSoundType == 6) freq2 >>= 1; + AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq2, + (engineSoundType + AUDIO_SAMPLE_VEHICLE_ENGINE_IDLE_NONE), 0, + 52u, 1); + + CurrentPretendGear = max(1, currentGear); + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; + return; + } + if(nCruising) { + if(accelerateState < 150 || !automobile->m_nWheelsOnGround || + automobile->bIsHandbrakeOn || lostTraction || + currentGear < 2u && + velocityChange - automobile->m_fVelocityChangeForAudio >= 0.01f) { + if(!automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || + lostTraction) { + if(!automobile->m_nWheelsOnGround && + automobile->m_nDriveWheelsOnGround || + (automobile->bIsHandbrakeOn && !bHandbrakeOnLastFrame || + lostTraction && !bLostTractionLastFrame) && + automobile->m_nWheelsOnGround) { + automobile->m_fGasPedalAudio = + automobile->m_fGasPedalAudio * 0.6f; + } + freqModifier = 0; + baseFreq = (15000.f * automobile->m_fGasPedalAudio) + 14000; + vol = (25.0f * automobile->m_fGasPedalAudio) + 60; + } else { + baseFreq = (8000.f * accelerationMultipler) + 16000; + vol = (25.0f * accelerationMultipler) + 60; + automobile->m_fGasPedalAudio = accelerationMultipler; + } + freq5 = freqModifier + baseFreq; + if(engineSoundType == 6) freq5 >>= 1; + if(channelUsed) { + SampleManager.StopChannel(m_bActiveSamples); + bAccelSampleStopped = 1; + } + AddPlayerCarSample(vol, freq5, + (engineSoundType + AUDIO_SAMPLE_PAYPHONE_RINGING), 0, 2u, + 1); + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; + return; + } + TranslateEntity(&m_sQueueSample.m_vecPos, &pos); + if(bAccelSampleStopped) { + if(CurrentPretendGear != 1 || currentGear != 2) { + gearNr = currentGear - 1; + if(gearNr < 1) gearNr = 1; + CurrentPretendGear = gearNr; + } + processedAccelSampleStopped = 1; + bAccelSampleStopped = 0; + } + if(channelUsed) { + SampleManager.SetChannelEmittingVolume(m_bActiveSamples, 85u); + SampleManager.SetChannel3DPosition(m_bActiveSamples, pos.x, pos.y, pos.z); + SampleManager.SetChannel3DDistances(m_bActiveSamples, 50.f, 12.5f); + if(engineSoundType == 6) + freq = (CSWTCH_554[CurrentPretendGear] + freqModifier + 22050) >> 1; + else + freq = CSWTCH_554[CurrentPretendGear] + freqModifier + 22050; + SampleManager.SetChannelFrequency(m_bActiveSamples, freq); + if(!channelUsed) { + SampleManager.SetChannelReverbFlag( + m_bActiveSamples, m_bDynamicAcousticModelingStatus != 0); + SampleManager.StartChannel(m_bActiveSamples); + } + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; + return; + } + if(processedAccelSampleStopped) { + if(!SampleManager.InitialiseChannel(m_bActiveSamples, soundOffset + 345, 0)) + return; + SampleManager.SetChannelLoopCount(m_bActiveSamples, 1); + SampleManager.SetChannelLoopPoints(m_bActiveSamples, 0, -1); + SampleManager.SetChannelEmittingVolume(m_bActiveSamples, 85u); + SampleManager.SetChannel3DPosition(m_bActiveSamples, pos.x, pos.y, pos.z); + SampleManager.SetChannel3DDistances(m_bActiveSamples, 50.f, 12.5f); + if(engineSoundType == 6) + freq = (CSWTCH_554[CurrentPretendGear] + freqModifier + 22050) >> 1; + else + freq = CSWTCH_554[CurrentPretendGear] + freqModifier + 22050; + SampleManager.SetChannelFrequency(m_bActiveSamples, freq); + if(!channelUsed) { + SampleManager.SetChannelReverbFlag( + m_bActiveSamples, m_bDynamicAcousticModelingStatus != 0); + SampleManager.StartChannel(m_bActiveSamples); + } + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; + return; + } + if(CurrentPretendGear < params->m_pTransmission->nNumberOfGears - 1) { + ++CurrentPretendGear; + if(!SampleManager.InitialiseChannel(m_bActiveSamples, soundOffset + 345, 0)) + return; + SampleManager.SetChannelLoopCount(m_bActiveSamples, 1); + SampleManager.SetChannelLoopPoints(m_bActiveSamples, 0, -1); + SampleManager.SetChannelEmittingVolume(m_bActiveSamples, 85u); + SampleManager.SetChannel3DPosition(m_bActiveSamples, pos.x, pos.y, pos.z); + SampleManager.SetChannel3DDistances(m_bActiveSamples, 50.f, 12.5f); + if(engineSoundType == 6) + freq = (CSWTCH_554[CurrentPretendGear] + freqModifier + 22050) >> 1; + else + freq = CSWTCH_554[CurrentPretendGear] + freqModifier + 22050; + SampleManager.SetChannelFrequency(m_bActiveSamples, freq); + if(!channelUsed) { + SampleManager.SetChannelReverbFlag( + m_bActiveSamples, m_bDynamicAcousticModelingStatus != 0); + SampleManager.StartChannel(m_bActiveSamples); + } + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; + return; + } + nCruising = 1; + } + bAccelSampleStopped = 1; + if(accelerateState < 150 || !automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || + lostTraction || currentGear < params->m_pTransmission->nNumberOfGears - 1) { + nCruising = 0; + } else { + if(accelerateState >= 220 && + 0.001f + params->m_fVelocityChange < automobile->m_fVelocityChangeForAudio) { + if(nCruising < 800) ++nCruising; + } else if(nCruising > 3) { + --nCruising; + } + freq4 = 27 * nCruising + freqModifier + 22050; + if(engineSoundType == 6) freq4 >>= 1; + AddPlayerCarSample(85u, freq4, + (soundOffset + AUDIO_SAMPLE_VEHICLE_ENGINE_CHANGE_GEAR_GENERIC), + engineSoundType, 64u, 1); + } + LastAccel = accelerateState; + + bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; + bLostTractionLastFrame = lostTraction; } WRAPPER @@ -6490,6 +7149,47 @@ cAudioManager::ProcessProjectiles() EAXJMP(0x578A80); } +void +cAudioManager::ProcessRainOnVehicle(cVehicleParams *params) +{ + float emittingVol; + CVehicle *veh; + + if(params->m_fDistance < 484.f && CWeather::Rain > 0.01f && + (!CCullZones::CamNoRain() || !CCullZones::PlayerNoRain())) { + ++params->m_pVehicle->m_bRainAudioCounter; + veh = params->m_pVehicle; + if(veh->m_bRainAudioCounter >= 2u) { + veh->m_bRainAudioCounter = 0; + CalculateDistance((bool *)params, params->m_fDistance); + emittingVol = 30.f * CWeather::Rain; + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 22.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.field_4 = veh->m_bRainSamplesCounter++; + veh = params->m_pVehicle; + if(veh->m_bRainSamplesCounter > 4u) veh->m_bRainSamplesCounter = 68; + m_sQueueSample.m_nSampleIndex = + (m_anRandomTable[1] & 3) + AUDIO_SAMPLE_RAIN_ON_VEHICLE_1; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 9; + m_sQueueSample.m_nFrequency = m_anRandomTable[1] % 4000u + 28000; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_bEmittingVolume = (uint8)emittingVol; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.field_48 = 0.0; + m_sQueueSample.m_fSoundIntensity = 22.0; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bReverbFlag = 0; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } +} + void cAudioManager::ProcessSawMillScriptObject(uint8 sound) { @@ -7089,14 +7789,21 @@ InjectHook(0x575510, &cAudioManager::GetGenericFemaleTalkSfx, PATCH_JUMP); // InjectHook(0x57BA60, &cAudioManager::ProcessActiveQueues, PATCH_JUMP); InjectHook(0x56C940, &cAudioManager::ProcessAirBrakes, PATCH_JUMP); InjectHook(0x577B30, &cAudioManager::ProcessAirportScriptObject, PATCH_JUMP); +InjectHook(0x56DE80, &cAudioManager::ProcessBoatEngine, PATCH_JUMP); +InjectHook(0x56E500, &cAudioManager::ProcessBoatMovingOverWater, PATCH_JUMP); +InjectHook(0x5790D0, &cAudioManager::ProcessBridge, PATCH_JUMP); InjectHook(0x579250, &cAudioManager::ProcessBridgeMotor, PATCH_JUMP); +InjectHook(0x579310, &cAudioManager::ProcessBridgeOneShots, PATCH_JUMP); InjectHook(0x579170, &cAudioManager::ProcessBridgeWarning, PATCH_JUMP); +InjectHook(0x56CC20, &cAudioManager::ProcessCarBombTick, PATCH_JUMP); InjectHook(0x577CA0, &cAudioManager::ProcessCinemaScriptObject, PATCH_JUMP); InjectHook(0x577E50, &cAudioManager::ProcessDocksScriptObject, PATCH_JUMP); +InjectHook(0x56CAF0, &cAudioManager::ProcessEngineDamage, PATCH_JUMP); InjectHook(0x569870, &cAudioManager::ProcessEntity, PATCH_JUMP); InjectHook(0x575AC0, &cAudioManager::ProcessExplosions, PATCH_JUMP); InjectHook(0x578FD0, &cAudioManager::ProcessFireHydrant, PATCH_JUMP); InjectHook(0x5785E0, &cAudioManager::ProcessFrontEnd, PATCH_JUMP); +InjectHook(0x56E6A0, &cAudioManager::ProcessHelicopter, PATCH_JUMP); InjectHook(0x577FE0, &cAudioManager::ProcessHomeScriptObject, PATCH_JUMP); InjectHook(0x56E8F0, &cAudioManager::ProcessJumbo, PATCH_JUMP); InjectHook(0x56EA40, &cAudioManager::ProcessJumboAccel, PATCH_JUMP); @@ -7107,12 +7814,16 @@ InjectHook(0x56EC00, &cAudioManager::ProcessJumboTakeOff, PATCH_JUMP); InjectHook(0x56EA10, &cAudioManager::ProcessJumboTaxi, PATCH_JUMP); InjectHook(0x5777E0, &cAudioManager::ProcessLaunderetteScriptObject, PATCH_JUMP); InjectHook(0x576770, &cAudioManager::ProcessLoopingScriptObject, PATCH_JUMP); +InjectHook(0x56A050, &cAudioManager::ProcessModelCarEngine, PATCH_JUMP); InjectHook(0x5760C0, &cAudioManager::ProcessOneShotScriptObject, PATCH_JUMP); InjectHook(0x56F450, &cAudioManager::ProcessPed, PATCH_JUMP); InjectHook(0x56F4D0, &cAudioManager::ProcessPedHeadphones, PATCH_JUMP); InjectHook(0x56F650, &cAudioManager::ProcessPedOneShots, PATCH_JUMP); InjectHook(0x5699C0, &cAudioManager::ProcessPhysical, PATCH_JUMP); +InjectHook(0x56E860, &cAudioManager::ProcessPlane, PATCH_JUMP); +InjectHook(0x56B0D0, &cAudioManager::ProcessPlayersVehicleEngine, PATCH_JUMP); InjectHook(0x577280, &cAudioManager::ProcessPornCinema, PATCH_JUMP); +InjectHook(0x569CC0, &cAudioManager::ProcessRainOnVehicle, PATCH_JUMP); InjectHook(0x577630, &cAudioManager::ProcessSawMillScriptObject, PATCH_JUMP); InjectHook(0x576070, &cAudioManager::ProcessScriptObject, PATCH_JUMP); InjectHook(0x577970, &cAudioManager::ProcessShopScriptObject, PATCH_JUMP); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 5b74cc16..12e823b7 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -72,6 +72,7 @@ enum eAudioType : int32 { }; class CPhysical; +class CAutomobile; class tAudioEntity { @@ -112,7 +113,7 @@ public: uint8 activeBank; uint8 gap_1163[1]; - void Add(tPedComment *com); // test + void Add(tPedComment *com); /// ok }; static_assert(sizeof(cPedComments) == 1164, "cPedComments: error"); @@ -191,8 +192,7 @@ public: static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error"); -enum -{ +enum { /* REFLECTION_YMAX = 0, top REFLECTION_YMIN = 1, bottom @@ -209,6 +209,7 @@ enum MAX_REFLECTIONS, }; +<<<<<<< HEAD enum AudioEntityHandle { AEHANDLE_NONE = -5, @@ -222,6 +223,8 @@ enum AudioEntityHandle #define AEHANDLE_IS_OK(h) ((h)>=0) +======= +>>>>>>> Cleanup class cAudioManager { public: @@ -270,10 +273,15 @@ public: uint8 m_bPreviousUserPause; uint8 field_19195; uint32 m_FrameCounter; - + inline uint32 GetFrameCounter(void) { return m_FrameCounter; } float GetReflectionsDistance(int32 idx) { return m_afReflectionsDistances[idx]; } +<<<<<<< HEAD int32 GetRandomNumber(int32 idx) { return m_anRandomTable[idx]; } +======= + int32 GetRandomTabe(int32 idx) { return m_anRandomTable[idx]; } + +>>>>>>> Cleanup // void AddDetailsToRequestedOrderList(uint8 sample); /// ok @@ -283,7 +291,7 @@ public: void AddReleasingSounds(); // todo (difficult) void AddSampleToRequestedQueue(); /// ok void AgeCrimes(); // todo - int8 GetCurrent3DProviderIndex(); /// ok + int8 GetCurrent3DProviderIndex(); /// ok void CalculateDistance(bool *ptr, float dist); /// ok bool CheckForAnAudioFileOnCD(); /// ok @@ -461,55 +469,58 @@ public: uint32 GetGenericMaleTalkSfx(int16 sound); uint32 GetGenericFemaleTalkSfx(int16 sound); + void PlayOneShot(int32 index, int16 sound, float vol); // todo + void ProcessActiveQueues(); // todo bool ProcessAirBrakes(cVehicleParams *params); /// ok void ProcessAirportScriptObject(uint8 sound); /// ok - bool ProcessBoatEngine(cVehicleParams *params); // todo requires CBoat - bool ProcessBoatMovingOverWater(cVehicleParams *params); // todo requires CBoat - void ProcessBridge(); // todo requires CBridge + bool ProcessBoatEngine(cVehicleParams *params); /// ok + bool ProcessBoatMovingOverWater(cVehicleParams *params); /// ok + void ProcessBridge(); /// ok void ProcessBridgeMotor(); /// ok - void ProcessBridgeOneShots(); // todo requires CBridge + void ProcessBridgeOneShots(); /// ok void ProcessBridgeWarning(); /// ok - bool ProcessCarBombTick(void *); // todo requires CVehicle + bool ProcessCarBombTick(cVehicleParams *params); /// ok void ProcessCesna(void *); // todo requires CPlane void ProcessCinemaScriptObject(uint8 sound); /// ok void ProcessCrane(); // todo requires CCrane void ProcessDocksScriptObject(uint8 sound); /// ok - // bool ProcessEngineDamage(void *); //todo requires CVehicle - void ProcessEntity(int32 sound); /// ok - void ProcessExplosions(int32 explosion); // test - void ProcessFireHydrant(); /// ok - void ProcessFires(int32 entity); // todo requires gFireManager - void ProcessFrontEnd(); /// ok - void ProcessGarages(); // todo requires CGarages::aGarages - // bool ProcessHelicopter(void *); // todo requires CVehicle - void ProcessHomeScriptObject(uint8 sound); /// ok - void ProcessJumbo(cVehicleParams *); /// ok - void ProcessJumboAccel(CPlane *plane); /// ok - void ProcessJumboDecel(CPlane *plane); /// ok - void ProcessJumboFlying(); /// ok - void ProcessJumboLanding(CPlane *plane); /// ok - void ProcessJumboTakeOff(CPlane *plane); /// ok - void ProcessJumboTaxi(); /// ok - void ProcessLaunderetteScriptObject(uint8 sound); /// ok - void ProcessLoopingScriptObject(uint8 sound); /// ok + bool ProcessEngineDamage(cVehicleParams *params); /// ok + void ProcessEntity(int32 sound); /// ok + void ProcessExplosions(int32 explosion); /// ok + void ProcessFireHydrant(); /// ok + void ProcessFires(int32 entity); // todo requires gFireManager + void ProcessFrontEnd(); /// ok + void ProcessGarages(); // todo requires CGarages::aGarages + bool ProcessHelicopter(cVehicleParams *params); /// ok + void ProcessHomeScriptObject(uint8 sound); /// ok + void ProcessJumbo(cVehicleParams *); /// ok + void ProcessJumboAccel(CPlane *plane); /// ok + void ProcessJumboDecel(CPlane *plane); /// ok + void ProcessJumboFlying(); /// ok + void ProcessJumboLanding(CPlane *plane); /// ok + void ProcessJumboTakeOff(CPlane *plane); /// ok + void ProcessJumboTaxi(); /// ok + void ProcessLaunderetteScriptObject(uint8 sound); /// ok + void ProcessLoopingScriptObject(uint8 sound); /// ok // void ProcessMissionAudio(); - // void ProcessModelVehicle(void *); - void ProcessOneShotScriptObject(uint8 sound); // test - void ProcessPed(CPhysical *ped); // test - void ProcessPedHeadphones(cPedParams *params); // test - void ProcessPedOneShots(cPedParams *params); // test, remove goto - void ProcessPhysical(int32 id); /// ok - void ProcessPlane(void *); // todo - // void ProcessPlayersVehicleEngine(void *, void *); - void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo - void ProcessPornCinema(uint8 sound); /// ok - void ProcessProjectiles(); // todo - // void ProcessRainOnVehicle(void *); + void ProcessModelCarEngine(cVehicleParams *params); /// (check float comparisons) + void ProcessOneShotScriptObject(uint8 sound); /// ok + void ProcessPed(CPhysical *ped); /// ok + void ProcessPedHeadphones(cPedParams *params); /// ok + void ProcessPedOneShots(cPedParams *params); /// ok + void ProcessPhysical(int32 id); /// ok + void ProcessPlane(cVehicleParams *params); /// ok + void ProcessPlayersVehicleEngine(cVehicleParams *params, + CAutomobile *automobile); /// ok (check float comparisons) + void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo + void ProcessPornCinema(uint8 sound); /// ok + void ProcessProjectiles(); // todo requires CProjectileInfo + void ProcessRainOnVehicle(cVehicleParams *params); /// ok // void ProcessReverb(); // bool ProcessReverseGear(void *); void ProcessSawMillScriptObject(uint8 sound); /// ok - void ProcessScriptObject(int32 id); // test + void ProcessScriptObject(int32 id); /// ok void ProcessShopScriptObject(uint8 sound); /// ok void ProcessSpecial(); /// ok // bool ProcessTrainNoise(void *); @@ -527,7 +538,7 @@ public: // bool ProcessWetRoadNoise(void *); void ProcessWorkShopScriptObject(uint8 sound); /// ok - void SetupPedComments(cPedParams *params, uint32 sound); // todo hook + void SetupPedComments(cPedParams *params, uint32 sound); /// ok }; static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 6fb6d1e5..076c1178 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -7,6 +7,8 @@ cDMAudio &DMAudio = *(cDMAudio*)0x95CDBE; +#define AEHANDLE_IS_FAILED(h) ((h)<0) +#define AEHANDLE_IS_OK(h) ((h)>=0) void cDMAudio::Initialise(void) diff --git a/src/control/Bridge.h b/src/control/Bridge.h index 52c85322..377c8bf8 100644 --- a/src/control/Bridge.h +++ b/src/control/Bridge.h @@ -1,27 +1,24 @@ #pragma once #include "Entity.h" +enum bridgeStates { + STATE_BRIDGE_LOCKED, + STATE_LIFT_PART_IS_UP, + STATE_LIFT_PART_MOVING_DOWN, + STATE_LIFT_PART_IS_DOWN, + STATE_LIFT_PART_ABOUT_TO_MOVE_UP, + STATE_LIFT_PART_MOVING_UP +}; + class CBridge { -private: - enum bridgeStates - { - STATE_BRIDGE_LOCKED, - STATE_LIFT_PART_IS_UP, - STATE_LIFT_PART_MOVING_DOWN, - STATE_LIFT_PART_IS_DOWN, - STATE_LIFT_PART_ABOUT_TO_MOVE_UP, - STATE_LIFT_PART_MOVING_UP - }; - - +public: static CEntity *&pLiftRoad, *&pLiftPart, *&pWeight; static int &State, &OldState; static float &DefaultZLiftPart, &DefaultZLiftRoad, &DefaultZLiftWeight; - static float& OldLift; - static uint32& TimeOfBridgeBecomingOperational; + static float &OldLift; + static uint32 &TimeOfBridgeBecomingOperational; -public: static void Init(); static void Update(); static bool ShouldLightsBeFlashing(); diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index 87ce4476..e9b33395 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -207,8 +207,8 @@ CPathFind::PreparePathData(void) numExtern++; if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes) numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes; - maxX = Max(maxX, Abs(InfoForTileCars[k].x)); - maxY = Max(maxY, Abs(InfoForTileCars[k].y)); + maxX = max(maxX, Abs(InfoForTileCars[k].x)); + maxY = max(maxY, Abs(InfoForTileCars[k].y)); }else if(InfoForTileCars[k].type == NodeTypeIntern) numIntern++; } @@ -392,7 +392,7 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor if(Abs(dx) < nearestDist){ dy = tempnodes[k].pos.y - CoorsXFormed.y; if(Abs(dy) < nearestDist){ - nearestDist = Max(Abs(dx), Abs(dy)); + nearestDist = max(Abs(dx), Abs(dy)); nearestId = k; } } @@ -501,13 +501,13 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor // Find i inside path segment iseg = 0; - for(j = Max(oldNumPathNodes, i-12); j < i; j++) + for(j = max(oldNumPathNodes, i-12); j < i; j++) if(m_pathNodes[j].objectIndex == m_pathNodes[i].objectIndex) iseg++; istart = 12*m_mapObjects[m_pathNodes[i].objectIndex]->m_modelIndex; // Add links to other internal nodes - for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){ + for(j = max(oldNumPathNodes, i-12); j < min(m_numPathNodes, i+12); j++){ if(m_pathNodes[i].objectIndex != m_pathNodes[j].objectIndex || i == j) continue; // N.B.: in every path segment, the externals have to be at the end diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index 207845b9..12636d32 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -366,8 +366,8 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* main = RpAnimBlendClumpGetMainAssociation((RpClump*)ped->m_rwObject, &second, &blend_amount); if (main){ state->animId = main->animId; - state->time = 255.0f / 4.0f * Max(0.0f, Min(4.0f, main->currentTime)); - state->speed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, main->speed)); + state->time = 255.0f / 4.0f * max(0.0f, min(4.0f, main->currentTime)); + state->speed = 255.0f / 3.0f * max(0.0f, min(3.0f, main->speed)); }else{ state->animId = 3; state->time = 0; @@ -375,9 +375,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) } if (second) { state->secAnimId = second->animId; - state->secTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, second->currentTime)); - state->secSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, second->speed)); - state->blendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, blend_amount)); + state->secTime = 255.0f / 4.0f * max(0.0f, min(4.0f, second->currentTime)); + state->secSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, second->speed)); + state->blendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, blend_amount)); }else{ state->secAnimId = 0; state->secTime = 0; @@ -387,9 +387,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* partial = RpAnimBlendClumpGetMainPartialAssociation((RpClump*)ped->m_rwObject); if (partial) { state->partAnimId = partial->animId; - state->partAnimTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, partial->currentTime)); - state->partAnimSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, partial->speed)); - state->partBlendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, partial->blendAmount)); + state->partAnimTime = 255.0f / 4.0f * max(0.0f, min(4.0f, partial->currentTime)); + state->partAnimSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, partial->speed)); + state->partBlendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, partial->blendAmount)); }else{ state->partAnimId = 0; state->partAnimTime = 0; @@ -408,9 +408,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc){ state->aAnimId[i] = assoc->animId; - state->aCurTime[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); - state->aSpeed[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); - state->aBlendAmount[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); + state->aCurTime[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); + state->aSpeed[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); + state->aBlendAmount[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); state->aFlags[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID[i] = FindCBFunctionID(assoc->callback); @@ -431,9 +431,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainPartialAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc) { state->aAnimId2[i] = assoc->animId; - state->aCurTime2[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); - state->aSpeed2[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); - state->aBlendAmount2[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); + state->aCurTime2[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); + state->aSpeed2[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); + state->aBlendAmount2[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); state->aFlags2[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID2[i] = FindCBFunctionID(assoc->callback); @@ -625,9 +625,9 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) vp->health = vehicle->m_fHealth / 4.0f; /* Not anticipated that health can be > 1000. */ vp->acceleration = vehicle->m_fGasPedal * 100.0f; vp->panels = vehicle->IsCar() ? ((CAutomobile*)vehicle)->Damage.m_panelStatus : 0; - vp->velocityX = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ - vp->velocityY = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().y)); - vp->velocityZ = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().z)); + vp->velocityX = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ + vp->velocityY = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().y)); + vp->velocityZ = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().z)); vp->mi = vehicle->GetModelIndex(); vp->primary_color = vehicle->m_currentColour1; vp->secondary_color = vehicle->m_currentColour2; @@ -1501,9 +1501,9 @@ void CReplay::ProcessLookAroundCam(void) --FramesActiveLookAroundCam; fBetaAngleLookAroundCam += x_moved; if (CPad::NewMouseControllerState.LMB && CPad::NewMouseControllerState.RMB) - fDistanceLookAroundCam = Max(3.0f, Min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); + fDistanceLookAroundCam = max(3.0f, min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); else - fAlphaAngleLookAroundCam = Max(0.1f, Min(1.5f, fAlphaAngleLookAroundCam + y_moved)); + fAlphaAngleLookAroundCam = max(0.1f, min(1.5f, fAlphaAngleLookAroundCam + y_moved)); CVector camera_pt( fDistanceLookAroundCam * Sin(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), fDistanceLookAroundCam * Cos(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 7e87fc6e..c81cd050 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1987,7 +1987,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; car->m_status = STATUS_PHYSICS; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -1999,7 +1999,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CCarCtrl::JoinCarWithRoadSystem(car); car->AutoPilot.m_nCarMission = MISSION_CRUISE; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2083,7 +2083,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CollectParameters(&m_nIp, 2); CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(car); - car->AutoPilot.m_nCruiseSpeed = Min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); + car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); return 0; } case COMMAND_SET_CAR_DRIVING_STYLE: diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index f15232f3..cb16c3ad 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -209,7 +209,7 @@ WellBufferMe(float Target, float *CurrentValue, float *CurrentSpeed, float MaxSp else if(TargetSpeed > 0.0f && *CurrentSpeed > TargetSpeed) *CurrentSpeed = TargetSpeed; - *CurrentValue += *CurrentSpeed * Min(10.0f, CTimer::GetTimeStep()); + *CurrentValue += *CurrentSpeed * min(10.0f, CTimer::GetTimeStep()); } void @@ -697,7 +697,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl // Process height offset to avoid peds and cars float TargetZOffSet = m_fUnknownZOffSet + m_fDimensionOfHighestNearCar; - TargetZOffSet = Max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); + TargetZOffSet = max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); float TargetHeight = CameraTarget.z + TargetZOffSet - Source.z; if(TargetHeight > m_fCamBufferedHeight){ @@ -753,7 +753,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl } } - TargetCoors.z += Min(1.0f, m_fCamBufferedHeight/2.0f); + TargetCoors.z += min(1.0f, m_fCamBufferedHeight/2.0f); m_cvecTargetCoorsForFudgeInter = TargetCoors; Front = TargetCoors - Source; @@ -991,7 +991,7 @@ CCam::WorkOutCamHeight(const CVector &TargetCoors, float TargetOrientation, floa } if(FoundCamRoof){ // Camera is under something - float roof = FoundRoofCenter ? Min(CamRoof, CarRoof) : CamRoof; + float roof = FoundRoofCenter ? min(CamRoof, CarRoof) : CamRoof; // Same weirdness again? TargetAlpha = CGeneral::GetATanOfXY(CA_MAX_DISTANCE, roof - CamTargetZ - 1.5f); CamClear = false; @@ -1249,7 +1249,7 @@ void CCam::Cam_On_A_String_Unobscured(const CVector &TargetCoors, float BaseDist) { CA_MAX_DISTANCE = BaseDist + 0.1f + TheCamera.CarZoomValueSmooth; - CA_MIN_DISTANCE = Min(BaseDist*0.6f, 3.5f); + CA_MIN_DISTANCE = min(BaseDist*0.6f, 3.5f); CVector Dist = Source - TargetCoors; diff --git a/src/core/Collision.cpp b/src/core/Collision.cpp index 538bcae6..66b29d9f 100644 --- a/src/core/Collision.cpp +++ b/src/core/Collision.cpp @@ -153,10 +153,10 @@ CCollision::LoadCollisionWhenINeedIt(bool forceChange) // on water we expect to be between levels multipleLevels = true; }else{ - xmin = Max(sx - 1, 0); - xmax = Min(sx + 1, NUMSECTORS_X-1); - ymin = Max(sy - 1, 0); - ymax = Min(sy + 1, NUMSECTORS_Y-1); + xmin = max(sx - 1, 0); + xmax = min(sx + 1, NUMSECTORS_X-1); + ymin = max(sy - 1, 0); + ymax = min(sy + 1, NUMSECTORS_Y-1); for(x = xmin; x <= xmax; x++) for(y = ymin; y <= ymax; y++){ diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index c8a00744..1de5c94f 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -1030,7 +1030,7 @@ int CMenuManager::FadeIn(int alpha) m_nCurrScreen == MENUPAGE_SAVING_IN_PROGRESS || m_nCurrScreen == MENUPAGE_DELETING) return alpha; - return Min(m_nMenuFadeAlpha, alpha); + return min(m_nMenuFadeAlpha, alpha); } #endif diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index b5086d64..f334a255 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -299,10 +299,10 @@ CControllerState CPad::ReconcileTwoControllersInput(CControllerState const &Stat { if ( State1.button || State2.button ) ReconState.button = 255; } #define _RECONCILE_AXIS_POSITIVE(axis) \ - { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = Max(State1.axis, State2.axis); } + { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = max(State1.axis, State2.axis); } #define _RECONCILE_AXIS_NEGATIVE(axis) \ - { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = Min(State1.axis, State2.axis); } + { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = min(State1.axis, State2.axis); } #define _RECONCILE_AXIS(axis) \ { _RECONCILE_AXIS_POSITIVE(axis); _RECONCILE_AXIS_NEGATIVE(axis); } diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 8158cd1d..a7bde91e 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1940,7 +1940,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())){ lodDistSq = sq(mi->GetLargestLodDistance()); - lodDistSq = Min(lodDistSq, sq(STREAM_DIST)); + lodDistSq = min(lodDistSq, sq(STREAM_DIST)); pos = CVector2D(e->GetPosition()); if(xmin < pos.x && pos.x < xmax && ymin < pos.y && pos.y < ymax && @@ -2160,20 +2160,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) if(Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y)){ // looking west/east - ymin = Max(iy - 10, 0); - ymax = Min(iy + 10, NUMSECTORS_Y); + ymin = max(iy - 10, 0); + ymax = min(iy + 10, NUMSECTORS_Y); assert(ymin <= ymax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().x > 0){ // looking east - xmax = Max(ix - 2, 0); - xmin = Max(ix - 10, 0); + xmax = max(ix - 2, 0); + xmin = max(ix - 10, 0); inc = 1; }else{ // looking west - xmax = Min(ix + 2, NUMSECTORS_X); - xmin = Min(ix + 10, NUMSECTORS_X); + xmax = min(ix + 2, NUMSECTORS_X); + xmin = min(ix + 10, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2189,13 +2189,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().x > 0){ // looking east - xmax = Max(ix + 10, 0); - xmin = Max(ix - 2, 0); + xmax = max(ix + 10, 0); + xmin = max(ix - 2, 0); inc = 1; }else{ // looking west - xmax = Min(ix - 10, NUMSECTORS_X); - xmin = Min(ix + 2, NUMSECTORS_X); + xmax = min(ix - 10, NUMSECTORS_X); + xmin = min(ix + 2, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2224,20 +2224,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) }else{ // looking north/south - xmin = Max(ix - 10, 0); - xmax = Min(ix + 10, NUMSECTORS_X); + xmin = max(ix - 10, 0); + xmax = min(ix + 10, NUMSECTORS_X); assert(xmin <= xmax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().y > 0){ // looking north - ymax = Max(iy - 2, 0); - ymin = Max(iy - 10, 0); + ymax = max(iy - 2, 0); + ymin = max(iy - 10, 0); inc = 1; }else{ // looking south - ymax = Min(iy + 2, NUMSECTORS_Y); - ymin = Min(iy + 10, NUMSECTORS_Y); + ymax = min(iy + 2, NUMSECTORS_Y); + ymin = min(iy + 10, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ @@ -2253,13 +2253,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().y > 0){ // looking north - ymax = Max(iy + 10, 0); - ymin = Max(iy - 2, 0); + ymax = max(iy + 10, 0); + ymin = max(iy - 2, 0); inc = 1; }else{ // looking south - ymax = Min(iy - 10, NUMSECTORS_Y); - ymin = Min(iy + 2, NUMSECTORS_Y); + ymax = min(iy - 10, NUMSECTORS_Y); + ymin = min(iy + 2, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ diff --git a/src/core/Wanted.cpp b/src/core/Wanted.cpp index daed9155..26b115e3 100644 --- a/src/core/Wanted.cpp +++ b/src/core/Wanted.cpp @@ -209,7 +209,7 @@ CWanted::ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesnt else sensitivity = m_fCrimeSensitivity; - wantedLevelDrop = Min(CCullZones::GetWantedLevelDrop(), 100); + wantedLevelDrop = min(CCullZones::GetWantedLevelDrop(), 100); chaos = (1.0f - wantedLevelDrop/100.0f) * sensitivity; if (policeDoesntCare) diff --git a/src/core/main.cpp b/src/core/main.cpp index a82a2ab8..50494ef3 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -453,7 +453,7 @@ DoFade(void) CRGBA fadeColor; CRect rect; int fadeValue = CDraw::FadeValue; - float brightness = Min(CMenuManager::m_PrefsBrightness, 256); + float brightness = min(CMenuManager::m_PrefsBrightness, 256); if(brightness <= 50) brightness = 50; if(FrontEndMenuManager.m_bMenuActive) diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 0ce5ee3c..ad3838bd 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -374,32 +374,6 @@ delayedPatches10(int a, int b) } */ -<<<<<<< HEAD -======= -void __declspec(naked) HeadlightsFix() -{ - static const float fMinusOne = -1.0f; - _asm - { - fld [esp+708h-690h] - fcomp fMinusOne - fnstsw ax - and ah, 5 - cmp ah, 1 - jnz HeadlightsFix_DontLimit - fld fMinusOne - fstp [esp+708h-690h] - -HeadlightsFix_DontLimit: - fld [esp+708h-690h] - fabs - fld st - push 0x5382F2 - retn - } -} - ->>>>>>> More audio ped const int re3_buffsize = 1024; static char re3_buff[re3_buffsize]; diff --git a/src/core/re3.cpp.autosave b/src/core/re3.cpp.autosave deleted file mode 100644 index ad3838bd..00000000 --- a/src/core/re3.cpp.autosave +++ /dev/null @@ -1,483 +0,0 @@ -#include -#include -#include -#include "common.h" -#include "patcher.h" -#include "Renderer.h" -#include "Credits.h" -#include "Camera.h" -#include "Weather.h" -#include "Clock.h" -#include "World.h" -#include "Vehicle.h" -#include "ModelIndices.h" -#include "Streaming.h" -#include "PathFind.h" -#include "Boat.h" -#include "Heli.h" -#include "Automobile.h" -#include "Ped.h" -#include "debugmenu_public.h" - -#include -#include - -std::vector usedAddresses; - -void **rwengine = *(void***)0x5A10E1; - -DebugMenuAPI gDebugMenuAPI; - -WRAPPER void *gtanew(uint32 sz) { EAXJMP(0x5A0690); } -WRAPPER void gtadelete(void *p) { EAXJMP(0x5A07E0); } - -// overload our own new/delete with GTA's functions -void *operator new(size_t sz) { return gtanew(sz); } -void operator delete(void *ptr) noexcept { gtadelete(ptr); } - -#ifdef USE_PS2_RAND -unsigned __int64 myrand_seed = 1; -#else -unsigned long int myrand_seed = 1; -#endif - -int -myrand(void) -{ -#ifdef USE_PS2_RAND - // Use our own implementation of rand, stolen from PS2 - myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1; - return ((myrand_seed >> 32) & 0x7FFFFFFF); -#else - // or original codewarrior rand - myrand_seed = myrand_seed * 1103515245 + 12345; - return((myrand_seed >> 16) & 0x7FFF); -#endif -} - -void -mysrand(unsigned int seed) -{ - myrand_seed = seed; -} - -void (*DebugMenuProcess)(void); -void (*DebugMenuRender)(void); -static void stub(void) { } - -void -DebugMenuInit(void) -{ - if(DebugMenuLoad()){ - DebugMenuProcess = (void(*)(void))GetProcAddress(gDebugMenuAPI.module, "DebugMenuProcess"); - DebugMenuRender = (void(*)(void))GetProcAddress(gDebugMenuAPI.module, "DebugMenuRender"); - } - if(DebugMenuProcess == nil || DebugMenuRender == nil){ - DebugMenuProcess = stub; - DebugMenuRender = stub; - } - -} - -void WeaponCheat(); -void HealthCheat(); -void TankCheat(); -void BlowUpCarsCheat(); -void ChangePlayerCheat(); -void MayhemCheat(); -void EverybodyAttacksPlayerCheat(); -void WeaponsForAllCheat(); -void FastTimeCheat(); -void SlowTimeCheat(); -void MoneyCheat(); -void ArmourCheat(); -void WantedLevelUpCheat(); -void WantedLevelDownCheat(); -void SunnyWeatherCheat(); -void CloudyWeatherCheat(); -void RainyWeatherCheat(); -void FoggyWeatherCheat(); -void FastWeatherCheat(); -void OnlyRenderWheelsCheat(); -void ChittyChittyBangBangCheat(); -void StrongGripCheat(); -void NastyLimbsCheat(); - -DebugMenuEntry *carCol1; -DebugMenuEntry *carCol2; - -void -SpawnCar(int id) -{ - CVector playerpos; - CStreaming::RequestModel(id, 0); - CStreaming::LoadAllRequestedModels(false); - if(CStreaming::HasModelLoaded(id)){ - playerpos = FindPlayerCoors(); - int node = ThePaths.FindNodeClosestToCoors(playerpos, 0, 100.0f, false, false); - if(node < 0) - return; - - CVehicle *v; - if(CModelInfo::IsBoatModel(id)) - return; - else - v = new CAutomobile(id, RANDOM_VEHICLE); - - v->bHasBeenOwnedByPlayer = true; - if(carCol1) - DebugMenuEntrySetAddress(carCol1, &v->m_currentColour1); - if(carCol2) - DebugMenuEntrySetAddress(carCol2, &v->m_currentColour2); - - v->GetPosition() = ThePaths.m_pathNodes[node].pos; - v->GetPosition().z += 4.0f; - v->SetOrientation(0.0f, 0.0f, 3.49f); - v->m_status = STATUS_ABANDONED; - v->m_nDoorLock = CARLOCK_UNLOCKED; - CWorld::Add(v); - } -} - -static void -LetThemFollowYou(void) { - CPed* player = (CPed*) FindPlayerPed(); - for (int i = 0; i < player->m_numNearPeds; i++) { - - CPed* nearPed = player->m_nearPeds[i]; - if (nearPed && !nearPed->IsPlayer()) { - nearPed->SetObjective(OBJECTIVE_FOLLOW_PED_IN_FORMATION, (void*)player); - nearPed->m_pedFormation = rand() & 7; - nearPed->bScriptObjectiveCompleted = false; - } - } -} - -static void -FixCar(void) -{ - CVehicle *veh = FindPlayerVehicle(); - if(veh == nil) - return; - veh->m_fHealth = 1000.0f; - if(!veh->IsCar()) - return; - ((CAutomobile*)veh)->Damage.SetEngineStatus(0); - ((CAutomobile*)veh)->Fix(); -} - -static int engineStatus; -static void -SetEngineStatus(void) -{ - CVehicle *veh = FindPlayerVehicle(); - if(veh == nil) - return; - if(!veh->IsCar()) - return; - ((CAutomobile*)veh)->Damage.SetEngineStatus(engineStatus); -} - -static void -ToggleComedy(void) -{ - CVehicle *veh = FindPlayerVehicle(); - if(veh == nil) - return; - veh->bComedyControls = !veh->bComedyControls; -} - -static void -PlaceOnRoad(void) -{ - CVehicle *veh = FindPlayerVehicle(); - if(veh == nil) - return; - - if(veh->IsCar()) - ((CAutomobile*)veh)->PlaceOnRoadProperly(); -} - -static const char *carnames[] = { - "landstal", "idaho", "stinger", "linerun", "peren", "sentinel", "patriot", "firetruk", "trash", "stretch", "manana", "infernus", "blista", "pony", - "mule", "cheetah", "ambulan", "fbicar", "moonbeam", "esperant", "taxi", "kuruma", "bobcat", "mrwhoop", "bfinject", "corpse", "police", "enforcer", - "securica", "banshee", "predator", "bus", "rhino", "barracks", "train", "chopper", "dodo", "coach", "cabbie", "stallion", "rumpo", "rcbandit", - "bellyup", "mrwongs", "mafia", "yardie", "yakuza", "diablos", "columb", "hoods", "airtrain", "deaddodo", "speeder", "reefer", "panlant", "flatbed", - "yankee", "escape", "borgnine", "toyz", "ghost", -}; - -static std::list TweakVarsList; -static bool bAddTweakVarsNow = false; -static const char *pTweakVarsDefaultPath = NULL; - -void CTweakVars::Add(CTweakVar *var) -{ - TweakVarsList.push_back(var); - - if ( bAddTweakVarsNow ) - var->AddDBG(pTweakVarsDefaultPath); -} - -void CTweakVars::AddDBG(const char *path) -{ - pTweakVarsDefaultPath = path; - - for(auto i = TweakVarsList.begin(); i != TweakVarsList.end(); ++i) - (*i)->AddDBG(pTweakVarsDefaultPath); - - bAddTweakVarsNow = true; -} - -void CTweakSwitch::AddDBG(const char *path) -{ - DebugMenuEntry *e = DebugMenuAddVar(m_pPath == NULL ? path : m_pPath, m_pVarName, (int32_t *)m_pIntVar, m_pFunc, 1, m_nMin, m_nMax, m_aStr); - DebugMenuEntrySetWrap(e, true); -} - -void CTweakFunc::AddDBG (const char *path) { DebugMenuAddCmd (m_pPath == NULL ? path : m_pPath, m_pVarName, m_pFunc); } -void CTweakBool::AddDBG (const char *path) { DebugMenuAddVarBool8(m_pPath == NULL ? path : m_pPath, m_pVarName, (int8_t *)m_pBoolVar, NULL); } -void CTweakInt8::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int8_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakUInt8::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint8_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakInt16::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int16_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakUInt16::AddDBG(const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint16_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakInt32::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (int32_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakUInt32::AddDBG(const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (uint32_t *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound, NULL); } -void CTweakFloat::AddDBG (const char *path) { DebugMenuAddVar (m_pPath == NULL ? path : m_pPath, m_pVarName, (float *)m_pIntVar, NULL, m_nStep, m_nLoawerBound, m_nUpperBound); } - -/* -static const char *wt[] = { - "Sunny", "Cloudy", "Rainy", "Foggy" - }; - -SETTWEAKPATH("TEST"); -TWEAKSWITCH(CWeather::NewWeatherType, 0, 3, wt, NULL); -*/ - -void -DebugMenuPopulate(void) -{ - if(DebugMenuLoad()){ - static const char *weathers[] = { - "Sunny", "Cloudy", "Rainy", "Foggy" - }; - DebugMenuEntry *e; - e = DebugMenuAddVar("Time & Weather", "Current Hour", &CClock::GetHoursRef(), nil, 1, 0, 23, nil); - DebugMenuEntrySetWrap(e, true); - e = DebugMenuAddVar("Time & Weather", "Current Minute", &CClock::GetMinutesRef(), - [](){ CWeather::InterpolationValue = CClock::GetMinutes()/60.0f; }, 1, 0, 59, nil); - DebugMenuEntrySetWrap(e, true); - e = DebugMenuAddVar("Time & Weather", "Old Weather", (int16*)&CWeather::OldWeatherType, nil, 1, 0, 3, weathers); - DebugMenuEntrySetWrap(e, true); - e = DebugMenuAddVar("Time & Weather", "New Weather", (int16*)&CWeather::NewWeatherType, nil, 1, 0, 3, weathers); - DebugMenuEntrySetWrap(e, true); - DebugMenuAddVar("Time & Weather", "Wind", (float*)&CWeather::Wind, nil, 0.1f, 0.0f, 1.0f); - DebugMenuAddVar("Time & Weather", "Time scale", (float*)0x8F2C20, nil, 0.1f, 0.0f, 10.0f); - - DebugMenuAddCmd("Cheats", "Weapons", WeaponCheat); - DebugMenuAddCmd("Cheats", "Money", MoneyCheat); - DebugMenuAddCmd("Cheats", "Health", HealthCheat); - DebugMenuAddCmd("Cheats", "Wanted level up", WantedLevelUpCheat); - DebugMenuAddCmd("Cheats", "Wanted level down", WantedLevelDownCheat); - DebugMenuAddCmd("Cheats", "Tank", TankCheat); - DebugMenuAddCmd("Cheats", "Blow up cars", BlowUpCarsCheat); - DebugMenuAddCmd("Cheats", "Change player", ChangePlayerCheat); - DebugMenuAddCmd("Cheats", "Mayhem", MayhemCheat); - DebugMenuAddCmd("Cheats", "Everybody attacks player", EverybodyAttacksPlayerCheat); - DebugMenuAddCmd("Cheats", "Weapons for all", WeaponsForAllCheat); - DebugMenuAddCmd("Cheats", "Fast time", FastTimeCheat); - DebugMenuAddCmd("Cheats", "Slow time", SlowTimeCheat); - DebugMenuAddCmd("Cheats", "Armour", ArmourCheat); - DebugMenuAddCmd("Cheats", "Sunny weather", SunnyWeatherCheat); - DebugMenuAddCmd("Cheats", "Cloudy weather", CloudyWeatherCheat); - DebugMenuAddCmd("Cheats", "Rainy weather", RainyWeatherCheat); - DebugMenuAddCmd("Cheats", "Foggy weather", FoggyWeatherCheat); - DebugMenuAddCmd("Cheats", "Fast weather", FastWeatherCheat); - DebugMenuAddCmd("Cheats", "Only render wheels", OnlyRenderWheelsCheat); - DebugMenuAddCmd("Cheats", "Chitty chitty bang bang", ChittyChittyBangBangCheat); - DebugMenuAddCmd("Cheats", "Strong grip", StrongGripCheat); - DebugMenuAddCmd("Cheats", "Nasty limbs", NastyLimbsCheat); - - static int spawnCarId = MI_LANDSTAL; - e = DebugMenuAddVar("Spawn", "Spawn Car ID", &spawnCarId, nil, 1, MI_LANDSTAL, MI_GHOST, carnames); - DebugMenuEntrySetWrap(e, true); - DebugMenuAddCmd("Spawn", "Spawn Car", [](){ - if(spawnCarId == MI_TRAIN || - spawnCarId == MI_CHOPPER || - spawnCarId == MI_AIRTRAIN || - spawnCarId == MI_DEADDODO || - spawnCarId == MI_ESCAPE) - return; - SpawnCar(spawnCarId); - }); - static uint8 dummy; - carCol1 = DebugMenuAddVar("Spawn", "First colour", &dummy, nil, 1, 0, 255, nil); - carCol2 = DebugMenuAddVar("Spawn", "Second colour", &dummy, nil, 1, 0, 255, nil); - DebugMenuAddCmd("Spawn", "Spawn Stinger", [](){ SpawnCar(MI_STINGER); }); - DebugMenuAddCmd("Spawn", "Spawn Infernus", [](){ SpawnCar(MI_INFERNUS); }); - DebugMenuAddCmd("Spawn", "Spawn Cheetah", [](){ SpawnCar(MI_CHEETAH); }); - DebugMenuAddCmd("Spawn", "Spawn Esperanto", [](){ SpawnCar(MI_ESPERANT); }); - DebugMenuAddCmd("Spawn", "Spawn Stallion", [](){ SpawnCar(MI_STALLION); }); - DebugMenuAddCmd("Spawn", "Spawn Kuruma", [](){ SpawnCar(MI_KURUMA); }); - DebugMenuAddCmd("Spawn", "Spawn Taxi", [](){ SpawnCar(MI_TAXI); }); - DebugMenuAddCmd("Spawn", "Spawn Police", [](){ SpawnCar(MI_POLICE); }); - DebugMenuAddCmd("Spawn", "Spawn Enforcer", [](){ SpawnCar(MI_ENFORCER); }); - DebugMenuAddCmd("Spawn", "Spawn Banshee", [](){ SpawnCar(MI_BANSHEE); }); - DebugMenuAddCmd("Spawn", "Spawn Yakuza", [](){ SpawnCar(MI_YAKUZA); }); - DebugMenuAddCmd("Spawn", "Spawn Yardie", [](){ SpawnCar(MI_YARDIE); }); - DebugMenuAddCmd("Spawn", "Spawn Dodo", [](){ SpawnCar(MI_DODO); }); - DebugMenuAddCmd("Spawn", "Spawn Rhino", [](){ SpawnCar(MI_RHINO); }); - DebugMenuAddCmd("Spawn", "Spawn Firetruck", [](){ SpawnCar(MI_FIRETRUCK); }); - - DebugMenuAddVar("Debug", "Engine Status", &engineStatus, nil, 1, 0, 226, nil); - DebugMenuAddCmd("Debug", "Set Engine Status", SetEngineStatus); - DebugMenuAddCmd("Debug", "Fix Car", FixCar); - DebugMenuAddCmd("Debug", "Toggle Comedy Controls", ToggleComedy); - DebugMenuAddCmd("Debug", "Place Car on Road", PlaceOnRoad); - - DebugMenuAddVarBool8("Debug", "Catalina Heli On", (int8*)&CHeli::CatalinaHeliOn, nil); - DebugMenuAddCmd("Debug", "Catalina Fly By", CHeli::StartCatalinaFlyBy); - DebugMenuAddCmd("Debug", "Catalina Take Off", CHeli::CatalinaTakeOff); - DebugMenuAddCmd("Debug", "Catalina Fly Away", CHeli::MakeCatalinaHeliFlyAway); - DebugMenuAddVarBool8("Debug", "Script Heli On", (int8*)0x95CD43, nil); - - DebugMenuAddVarBool8("Debug", "Show Ped Road Groups", (int8*)&gbShowPedRoadGroups, nil); - DebugMenuAddVarBool8("Debug", "Show Car Road Groups", (int8*)&gbShowCarRoadGroups, nil); - DebugMenuAddVarBool8("Debug", "Show Collision Lines", (int8*)&gbShowCollisionLines, nil); - DebugMenuAddVarBool8("Debug", "Show Collision Polys", (int8*)&gbShowCollisionPolys, nil); - DebugMenuAddVarBool8("Debug", "Don't render Buildings", (int8*)&gbDontRenderBuildings, nil); - DebugMenuAddVarBool8("Debug", "Don't render Big Buildings", (int8*)&gbDontRenderBigBuildings, nil); - DebugMenuAddVarBool8("Debug", "Don't render Peds", (int8*)&gbDontRenderPeds, nil); - DebugMenuAddVarBool8("Debug", "Don't render Vehicles", (int8*)&gbDontRenderVehicles, nil); - DebugMenuAddVarBool8("Debug", "Don't render Objects", (int8*)&gbDontRenderObjects, nil); - - DebugMenuAddCmd("Debug", "Make peds around you follow you", LetThemFollowYou); -#ifndef MASTER - DebugMenuAddVarBool8("Debug", "Toggle unused fight feature", (int8*)&CPed::bUnusedFightThingOnPlayer, nil); -#endif - - DebugMenuAddCmd("Debug", "Start Credits", CCredits::Start); - DebugMenuAddCmd("Debug", "Stop Credits", CCredits::Stop); - - CTweakVars::AddDBG("Debug"); - } -} - -/* -int (*RsEventHandler_orig)(int a, int b); -int -delayedPatches10(int a, int b) -{ - DebugMenuInit(); - DebugMenuPopulate(); - - return RsEventHandler_orig(a, b); -} -*/ - -const int re3_buffsize = 1024; -static char re3_buff[re3_buffsize]; - -void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func) -{ - int nCode; - - strcpy_s(re3_buff, re3_buffsize, "Assertion failed!" ); - strcat_s(re3_buff, re3_buffsize, "\n" ); - - strcat_s(re3_buff, re3_buffsize, "File: "); - strcat_s(re3_buff, re3_buffsize, filename ); - strcat_s(re3_buff, re3_buffsize, "\n" ); - - strcat_s(re3_buff, re3_buffsize, "Line: " ); - _itoa_s( lineno, re3_buff + strlen(re3_buff), re3_buffsize - strlen(re3_buff), 10 ); - strcat_s(re3_buff, re3_buffsize, "\n"); - - strcat_s(re3_buff, re3_buffsize, "Function: "); - strcat_s(re3_buff, re3_buffsize, func ); - strcat_s(re3_buff, re3_buffsize, "\n" ); - - strcat_s(re3_buff, re3_buffsize, "Expression: "); - strcat_s(re3_buff, re3_buffsize, expr); - strcat_s(re3_buff, re3_buffsize, "\n"); - - strcat_s(re3_buff, re3_buffsize, "\n" ); - strcat_s(re3_buff, re3_buffsize, "(Press Retry to debug the application)"); - - - nCode = ::MessageBoxA(nil, re3_buff, "RE3 Assertion Failed!", - MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SETFOREGROUND|MB_TASKMODAL); - - if (nCode == IDABORT) - { - raise(SIGABRT); - _exit(3); - } - - if (nCode == IDRETRY) - { - __debugbreak(); - return; - } - - if (nCode == IDIGNORE) - return; - - abort(); -} - -void re3_debug(char *format, ...) -{ - va_list va; - va_start(va, format); - vsprintf_s(re3_buff, re3_buffsize, format, va); - va_end(va); - - printf("%s", re3_buff); -} - -void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...) -{ - char buff[re3_buffsize *2]; - va_list va; - va_start(va, format); - vsprintf_s(re3_buff, re3_buffsize, format, va); - va_end(va); - - sprintf_s(buff, re3_buffsize * 2, "[%s.%s:%d]: %s", filename, func, lineno, re3_buff); - - OutputDebugStringA(buff); -} - -void -patch() -{ - StaticPatcher::Apply(); - -// Patch(0x46BC61+6, 1.0f); // car distance - InjectHook(0x59E460, printf, PATCH_JUMP); - InjectHook(0x475E00, printf, PATCH_JUMP); // _Error - - -// InterceptCall(&open_script_orig, open_script, 0x438869); - -// InterceptCall(&RsEventHandler_orig, delayedPatches10, 0x58275E); -} - -BOOL WINAPI -DllMain(HINSTANCE hInst, DWORD reason, LPVOID) -{ - if(reason == DLL_PROCESS_ATTACH){ - - AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - - if (*(DWORD*)0x5C1E75 == 0xB85548EC) // 1.0 - patch(); - else - return FALSE; - } - - return TRUE; -} diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index d59e6c59..fbd1322d 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -457,7 +457,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector & { float compression = 1.0f - springRatio; if(compression > 0.0f){ - float step = Min(CTimer::GetTimeStep(), 3.0f); + float step = min(CTimer::GetTimeStep(), 3.0f); float impulse = -GRAVITY*m_fMass*step * springConst * compression * bias*2.0f; ApplyMoveForce(springDir*impulse); ApplyTurnForce(springDir*impulse, point); @@ -471,12 +471,12 @@ CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &poin { float speedA = DotProduct(speed, springDir); float speedB = DotProduct(GetSpeed(point), springDir); - float step = Min(CTimer::GetTimeStep(), 3.0f); + float step = min(CTimer::GetTimeStep(), 3.0f); float impulse = -damping * (speedA + speedB)/2.0f * m_fMass * step * 0.53f; // what is this? float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass); - a = Min(a, 1.0f); + a = min(a, 1.0f); float b = Abs(impulse / (speedB * m_fMass)); if(a < b) impulse *= a/b; @@ -646,7 +646,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl // positive if B is moving towards A // not interested in how much B moves into A apparently? // only interested in cases where A collided into B - speedB = Max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); + speedB = max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); // A has moved into B if(speedA < speedB){ if(!A->bHasHitWall) @@ -1147,18 +1147,18 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) CVector dir = A->GetPosition() - B->GetPosition(); dir.Normalise(); if(dir.z < 0.0f && dir.z < A->GetForward().z && dir.z < A->GetRight().z) - dir.z = Min(0.0f, Min(A->GetForward().z, A->GetRight().z)); + dir.z = min(0.0f, min(A->GetForward().z, A->GetRight().z)); shift += dir * colpoints[mostColliding].depth * 0.5f; }else if(A->IsPed() && B->IsVehicle() && ((CVehicle*)B)->IsBoat()){ CVector dir = colpoints[mostColliding].normal; - float f = Min(Abs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); shift += dir * colpoints[mostColliding].depth / (1.0f - f); boat = B; }else if(B->IsPed() && A->IsVehicle() && ((CVehicle*)A)->IsBoat()){ CVector dir = colpoints[mostColliding].normal * -1.0f; - float f = Min(Abs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); B->GetPosition() += dir * colpoints[mostColliding].depth / (1.0f - f); @@ -1246,7 +1246,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1268,7 +1268,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1301,7 +1301,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1328,7 +1328,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1506,7 +1506,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); } }else{ for(i = 0; i < numCollisions; i++){ @@ -1527,7 +1527,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions; @@ -1545,7 +1545,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) else if(A->GetUp().z > 0.3f) adhesion = 0.0f; else - adhesion *= Min(5.0f, 0.03f*impulseA + 1.0f); + adhesion *= min(5.0f, 0.03f*impulseA + 1.0f); } if(A->ApplyFriction(adhesion, aColPoints[i])) @@ -1594,7 +1594,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1619,7 +1619,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1655,7 +1655,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1685,7 +1685,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1831,7 +1831,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && (distSq >= sq(0.2f) || ped->IsPlayer())){ if(ped->IsPlayer()) - n = Max(NUMSTEPS(0.2f), 2.0); + n = max(NUMSTEPS(0.2f), 2.0); else n = NUMSTEPS(0.3f); step = savedTimeStep / n; @@ -1852,7 +1852,7 @@ CPhysical::ProcessCollision(void) speedDown = Multiply3x3(GetMatrix(), speedDown); speedUp = GetSpeed(speedUp); speedDown = GetSpeed(speedDown); - distSq = Max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); + distSq = max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); if(distSq >= sq(0.3f)){ n = NUMSTEPS(0.3f); step = savedTimeStep / n; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 59395d94..209c4ff6 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1792,7 +1792,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) neededPos.z = autoZPos.z; m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); @@ -1807,12 +1807,12 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) { - neededPos.z = Max(currentZ, autoZPos.z); + neededPos.z = max(currentZ, autoZPos.z); } } } @@ -4771,12 +4771,12 @@ CPed::FightStrike(CVector &touchedNodePos) float moveMult; if (m_lastFightMove == FIGHTMOVE_GROUNDKICK) { - moveMult = Min(damageMult * 0.6f, 4.0f); + moveMult = min(damageMult * 0.6f, 4.0f); } else { if (nearPed->m_nPedState != PED_DIE || damageMult >= 20) { moveMult = damageMult; } else { - moveMult = Min(damageMult * 2.0f, 14.0f); + moveMult = min(damageMult * 2.0f, 14.0f); } } diff --git a/src/peds/PedPlacement.cpp b/src/peds/PedPlacement.cpp index d7b7ec75..8a40e56f 100644 --- a/src/peds/PedPlacement.cpp +++ b/src/peds/PedPlacement.cpp @@ -29,7 +29,7 @@ CPedPlacement::FindZCoorForPed(CVector* pos) if (CWorld::ProcessVerticalLine(vec, startZ, foundCol, foundEnt, true, false, false, false, true, false, nil)) foundColZ2 = foundCol.point.z; - zForPed = Max(foundColZ, foundColZ2); + zForPed = max(foundColZ, foundColZ2); if (zForPed > -99.0f) pos->z = 1.04f + zForPed; diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index 1dcbdf46..5ae8c4be 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -97,16 +97,8 @@ CPlayerPed::AnnoyPlayerPed(bool annoyedByPassingEntity) class CPlayerPed_ : public CPlayerPed { public: -<<<<<<< HEAD -<<<<<<< HEAD CPlayerPed* ctor(void) { return ::new (this) CPlayerPed(); } void dtor(void) { CPlayerPed::~CPlayerPed(); } -======= - void dtor(void) { this->~CPlayerPed(); } ->>>>>>> More audio ped -======= - void dtor(void) { CPlayerPed::~CPlayerPed(); } ->>>>>>> fix }; STARTPATCHES diff --git a/src/peds/PlayerPed.cpp.autosave b/src/peds/PlayerPed.cpp.autosave deleted file mode 100644 index 1bf1c7fc..00000000 --- a/src/peds/PlayerPed.cpp.autosave +++ /dev/null @@ -1,110 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PlayerPed.h" -#include "Camera.h" -#include "WeaponEffects.h" -#include "ModelIndices.h" - -CPlayerPed::~CPlayerPed() -{ - delete m_pWanted; -} - -WRAPPER void CPlayerPed::ReApplyMoveAnims(void) { EAXJMP(0x4F07C0); } -WRAPPER void CPlayerPed::SetupPlayerPed(int32) { EAXJMP(0x4EFB60); } -WRAPPER void CPlayerPed::DeactivatePlayerPed(int32) { EAXJMP(0x4EFC00); } -WRAPPER void CPlayerPed::ReactivatePlayerPed(int32) { EAXJMP(0x4EFC20); } -WRAPPER void CPlayerPed::KeepAreaAroundPlayerClear(void) { EAXJMP(0x4F3460); } -WRAPPER void CPlayerPed::MakeChangesForNewWeapon(int8) { EAXJMP(0x4F2560); } -WRAPPER void CPlayerPed::SetInitialState(void) { EAXJMP(0x4EFC40); } -WRAPPER void CPlayerPed::SetMoveAnim(void) { EAXJMP(0x4F3760); } -WRAPPER void CPlayerPed::ProcessControl(void) { EAXJMP(0x4EFD90); } - -CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1) -{ - m_fMoveSpeed = 0.0f; - SetModelIndex(MI_PLAYER); - SetInitialState(); - - m_pWanted = new CWanted(); - m_pWanted->Initialise(); - m_pArrestingCop = nil; - m_currentWeapon = WEAPONTYPE_UNARMED; - m_nSelectedWepSlot = 0; - m_nSpeedTimer = 0; - m_bSpeedTimerFlag = 0; - m_pPointGunAt = nil; - m_nPedState = PED_IDLE; - m_fMaxStamina = 150.0f; - m_fCurrentStamina = m_fMaxStamina; - m_fStaminaProgress = 0.0f; - m_bShouldEvade = 0; - field_1367 = 0; - m_nShotDelay = 0; - field_1376 = 0.0f; - field_1380 = 0; - m_bHasLockOnTarget = false; - m_bCanBeDamaged = true; - m_fWalkAngle = 0.0f; - m_fFPSMoveHeading = 0.0f; - m_nTargettableObjects[0] = m_nTargettableObjects[1] = m_nTargettableObjects[2] = m_nTargettableObjects[3] = -1; - field_1413 = 0; - for (int i = 0; i < 6; i++) { - m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f); - field_1488[i] = 0; - } -} - -void CPlayerPed::ClearWeaponTarget() -{ - if (m_nPedType == PEDTYPE_PLAYER1) { - m_pPointGunAt = nil; - TheCamera.ClearPlayerWeaponMode(); - CWeaponEffects::ClearCrosshair(); - } - ClearPointGunAt(); -} - -void -CPlayerPed::SetWantedLevel(int32 level) -{ - m_pWanted->SetWantedLevel(level); -} - -void -CPlayerPed::SetWantedLevelNoDrop(int32 level) -{ - m_pWanted->SetWantedLevelNoDrop(level); -} - -// I don't know the actual purpose of parameter -void -CPlayerPed::AnnoyPlayerPed(bool annoyedByPassingEntity) -{ - if (m_pedStats->m_temper < 52) { - m_pedStats->m_temper++; - } else { - if (annoyedByPassingEntity) { - if (m_pedStats->m_temper < 55) { - m_pedStats->m_temper++; - } else { - m_pedStats->m_temper = 46; - } - } - } -} - -class CPlayerPed_ : public CPlayerPed -{ -public: - - CPlayerPed* ctor(void) { return ::new (this) CPlayerPed(); } - void dtor(void) { CPlayerPed::~CPlayerPed(); } -}; - -STARTPATCHES - InjectHook(0x4EF7E0, &CPlayerPed_::ctor, PATCH_JUMP); - InjectHook(0x4EFB30, &CPlayerPed_::dtor, PATCH_JUMP); - InjectHook(0x4F28A0, &CPlayerPed::ClearWeaponTarget, PATCH_JUMP); - InjectHook(0x4F3700, &CPlayerPed::AnnoyPlayerPed, PATCH_JUMP); -ENDPATCHES diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index a461301c..2884894c 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -388,7 +388,7 @@ CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, ms_colourBottom.b = topblue; ms_colourBottom.a = alpha; - botpos = Min(SCREEN_HEIGHT, topedge); + botpos = min(SCREEN_HEIGHT, topedge); CSprite2d::DrawRect(CRect(0, 0, SCREEN_WIDTH, botpos), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } @@ -415,18 +415,18 @@ CClouds::RenderHorizon(void) if(ms_horizonZ > SCREEN_HEIGHT) return; - float z1 = Min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); + float z1 = min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); CSprite2d::DrawRectXLU(CRect(0, ms_horizonZ, SCREEN_WIDTH, z1), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); // This is just weird float a = SCREEN_HEIGHT/400.0f * HORIZSTRIPHEIGHT + - SCREEN_HEIGHT/300.0f * Max(TheCamera.GetPosition().z, 0.0f); + SCREEN_HEIGHT/300.0f * max(TheCamera.GetPosition().z, 0.0f); float b = TheCamera.GetUp().z < 0.0f ? SCREEN_HEIGHT : SCREEN_HEIGHT * Abs(TheCamera.GetRight().z); float z2 = z1 + (a + b)*TheCamera.LODDistMultiplier; - z2 = Min(z2, SCREEN_HEIGHT); + z2 = min(z2, SCREEN_HEIGHT); CSprite2d::DrawRect(CRect(0, z1, SCREEN_WIDTH, z2), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 9881e764..1a6cfea3 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -109,7 +109,7 @@ CCoronas::Update(void) int i; static int LastCamLook = 0; - LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); + LightsMult = min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); int CamLook = 0; if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; @@ -121,7 +121,7 @@ CCoronas::Update(void) if(LastCamLook != CamLook) bChangeBrightnessImmediately = 3; else - bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); + bChangeBrightnessImmediately = max(bChangeBrightnessImmediately-1, 0); LastCamLook = CamLook; for(i = 0; i < NUMCORONAS; i++) @@ -309,7 +309,7 @@ CCoronas::Render(void) // render corona itself if(aCoronas[i].texture){ - float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; + float fogscale = CWeather::Foggyness*min(spriteCoors.z, 40.0f)/40.0f + 1.0f; if(CCoronas::aCoronas[i].id == SUN_CORE) spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); @@ -320,7 +320,7 @@ CCoronas::Render(void) float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; float hscale = 0.35f - (wscale - 0.5f) * 0.06f; - hscale = Max(hscale, 0.15f); + hscale = max(hscale, 0.15f); CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, spritew * aCoronas[i].size * wscale, @@ -467,7 +467,7 @@ CCoronas::RenderReflections(void) float spritew, spriteh; if(CSprite::CalcScreenCoors(coors, spriteCoors, &spritew, &spriteh, true)){ float drawDist = 0.75f * aCoronas[i].drawDist; - drawDist = Min(drawDist, 50.0f); + drawDist = min(drawDist, 50.0f); if(spriteCoors.z < drawDist){ float fadeDistance = drawDist / 2.0f; float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; @@ -546,25 +546,25 @@ CRegisteredCorona::Update(void) (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ // Corona is blocked, fade out - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else if(offScreen){ // Same when off screen - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else{ // Visible if(alpha > fadeAlpha){ // fade in - fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); if(CCoronas::bChangeBrightnessImmediately) fadeAlpha = alpha; }else if(alpha < fadeAlpha){ // too visible, decrease alpha but not below alpha - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); } // darken scene when the sun is visible if(id == CCoronas::SUN_CORONA) - CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); + CCoronas::LightsMult = max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); } // remove if invisible diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp index 85d7ba13..cd83a898 100644 --- a/src/render/Lights.cpp +++ b/src/render/Lights.cpp @@ -37,9 +37,9 @@ SetLightsWithTimeOfDayColour(RpWorld *) AmbientLightColourForFrame.green = 1.0f; AmbientLightColourForFrame.blue = 1.0f; } - AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame.red*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame.green*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame.blue*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame.red*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame.green*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame.blue*1.3f); RpLightSetColor(pAmbient, &AmbientLightColourForFrame); } @@ -70,16 +70,16 @@ SetLightsWithTimeOfDayColour(RpWorld *) float f1 = 2.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; float f2 = 3.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - AmbientLightColourForFrame.red = Min(1.0f, AmbientLightColourForFrame.red * f2); - AmbientLightColourForFrame.green = Min(1.0f, AmbientLightColourForFrame.green * f2); - AmbientLightColourForFrame.blue = Min(1.0f, AmbientLightColourForFrame.blue * f2); - AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); + AmbientLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f2); + AmbientLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f2); + AmbientLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f2); + AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); #ifdef FIX_BUGS - DirectionalLightColourForFrame.red = Min(1.0f, DirectionalLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = Min(1.0f, DirectionalLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = Min(1.0f, DirectionalLightColourForFrame.blue * f1); + DirectionalLightColourForFrame.red = min(1.0f, DirectionalLightColourForFrame.red * f1); + DirectionalLightColourForFrame.green = min(1.0f, DirectionalLightColourForFrame.green * f1); + DirectionalLightColourForFrame.blue = min(1.0f, DirectionalLightColourForFrame.blue * f1); #else DirectionalLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f1); DirectionalLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f1); @@ -193,7 +193,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwRGBAReal color; RwV3d *dir; - strength = Max(Max(red, green), blue); + strength = max(max(red, green), blue); n = -1; if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) n = NumExtraDirLightsInWorld; @@ -221,7 +221,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); LightStrengths[n] = strength; - NumExtraDirLightsInWorld = Min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); + NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); } void diff --git a/src/render/ParticleMgr.cpp b/src/render/ParticleMgr.cpp index 9381787c..7a1804de 100644 --- a/src/render/ParticleMgr.cpp +++ b/src/render/ParticleMgr.cpp @@ -91,7 +91,7 @@ void cParticleSystemMgr::LoadParticleData() break; case CFG_PARAM_INITIAL_COLOR_VARIATION: - entry->m_InitialColorVariation = Min(atoi(value), 100); + entry->m_InitialColorVariation = min(atoi(value), 100); break; case CFG_PARAM_FADE_DESTINATION_COLOR_R: diff --git a/src/render/PointLights.cpp b/src/render/PointLights.cpp index 8e942ce6..a015ec54 100644 --- a/src/render/PointLights.cpp +++ b/src/render/PointLights.cpp @@ -98,7 +98,7 @@ CPointLights::GenerateLightsAffectingObject(CVector *objCoors) if(aLights[i].type == LIGHT_DIRECTIONAL){ float dot = -DotProduct(dir, aLights[i].dir); - intensity *= Max((dot-0.5f)*2.0f, 0.0f); + intensity *= max((dot-0.5f)*2.0f, 0.0f); } if(intensity > 0.0f) diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index b5147f02..4d2e4605 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -727,10 +727,10 @@ CShadows::RenderStoredShadows(void) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -873,10 +873,10 @@ CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -1016,11 +1016,11 @@ CShadows::CastShadowEntity(CEntity *pEntity, float fStartX, float fStartY, floa Points[3].x = (fLengthRight - fFrontRight) - fSideRight; Points[3].y = (fLengthForward - fFrontForward) - fSideForward; - float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); - float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); + float MinX = min(min(Points[0].x, Points[1].x), min(Points[2].x, Points[3].x)); + float MaxX = max(max(Points[0].x, Points[1].x), max(Points[2].x, Points[3].x)); - float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); - float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); + float MinY = min(min(Points[0].y, Points[1].y), min(Points[2].y, Points[3].y)); + float MaxY = max(max(Points[0].y, Points[1].y), max(Points[2].y, Points[3].y)); float MaxZ = pPosn->z - pEntity->GetPosition().z; float MinZ = MaxZ - fZDistance; @@ -1767,7 +1767,7 @@ CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTextur { ASSERT(pPosn != NULL); - C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, Max(fFrontX, -fSideY), + C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, max(fFrontX, -fSideY), 0, 128, 255, 128, 2048, 0.2f, 0); } diff --git a/src/render/Timecycle.cpp b/src/render/Timecycle.cpp index 0113c001..7ab3e91e 100644 --- a/src/render/Timecycle.cpp +++ b/src/render/Timecycle.cpp @@ -290,7 +290,7 @@ CTimeCycle::Update(void) TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL); if(m_FogReduction != 0) - m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); + m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; @@ -311,9 +311,9 @@ CTimeCycle::Update(void) if(TheCamera.GetForward().z < -0.9f || !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) - m_FogReduction = Min(m_FogReduction+1, 64); + m_FogReduction = min(m_FogReduction+1, 64); else - m_FogReduction = Max(m_FogReduction-1, 0); + m_FogReduction = max(m_FogReduction-1, 0); } STARTPATCHES diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index c711c8c8..a1c2af93 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -979,7 +979,7 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col SMALL_SECTOR_SIZE / 2, apBoatList) ) { - float fWakeColor = fAdd1 - Max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); + float fWakeColor = fAdd1 - max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); RpGeometry *geom = apGeomArray[nGeomUsed++]; @@ -1035,9 +1035,9 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col RwRGBAAssign(&wakeColor, &color); - wakeColor.red = Min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); - wakeColor.green = Min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); - wakeColor.blue = Min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); + wakeColor.red = min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); + wakeColor.green = min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); + wakeColor.blue = min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); RwRGBAAssign(&geomPreLights[9*i+j], &wakeColor); @@ -1114,7 +1114,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) fSectorY + SMALL_SECTOR_SIZE - fY ); - fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); + fDistSqr = min(vecDist.MagnitudeSqr(), fDistSqr); } } } diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 0fe59cd0..18c74478 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -7,13 +7,9 @@ #include "ModelIndices.h" #include "VisibilityPlugins.h" #include "DMAudio.h" -<<<<<<< HEAD #include "Clock.h" -#include "TimeCycle.h" -#include "ZoneCull.h" -======= #include "Timecycle.h" ->>>>>>> More audio ped +#include "ZoneCull.h" #include "Camera.h" #include "Darkel.h" #include "Rubbish.h" @@ -132,7 +128,7 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy) m_fGasPedal = 0.0f; m_fBrakePedal = 0.0f; m_pSetOnFireEntity = nil; - field_594 = 0; + m_fGasPedalAudio = 0; bNotDamagedUpsideDown = false; bMoreResistantToDamage = false; m_fVelocityChangeForAudio = 0.0f; @@ -695,7 +691,7 @@ CAutomobile::ProcessControl(void) if(m_aSuspensionSpringRatio[i] < 1.0f) m_aWheelTimer[i] = 4.0f; else - m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); + m_aWheelTimer[i] = max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); if(m_aWheelTimer[i] > 0.0f){ m_nWheelsOnGround++; @@ -1013,7 +1009,7 @@ CAutomobile::ProcessControl(void) if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); + m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.0005f, 0.0f); }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ FlyingControl(FLIGHT_MODEL_DODO); @@ -1021,7 +1017,7 @@ CAutomobile::ProcessControl(void) FlyingControl(FLIGHT_MODEL_HELI); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ if(CPad::GetPad(0)->GetCircleJustDown()) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); + m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.03f, 0.0f); if(m_aWheelSpeed[0] < 0.22f) m_aWheelSpeed[0] += 0.0001f; if(m_aWheelSpeed[0] > 0.15f) @@ -1133,10 +1129,10 @@ CAutomobile::ProcessControl(void) if(speed > sq(0.1f)){ speed = Sqrt(speed); if(suspShake > 0.0f){ - uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); }else{ - uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); + uint8 freq = min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); } } @@ -2590,7 +2586,7 @@ CAutomobile::HydraulicControl(void) float minz = pos.z + extendedLowerLimit - wheelRadius; if(minz < specialColModel->boundingBox.min.z) specialColModel->boundingBox.min.z = minz; - float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); + float radius = max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); if(specialColModel->boundingSphere.radius < radius) specialColModel->boundingSphere.radius = radius; @@ -2689,10 +2685,10 @@ CAutomobile::HydraulicControl(void) float front = -rear; float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; float left = -right; - suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); - suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); - suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); - suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); + suspChange[CARWHEEL_FRONT_LEFT] = max(front+left, 0.0f); + suspChange[CARWHEEL_REAR_LEFT] = max(rear+left, 0.0f); + suspChange[CARWHEEL_FRONT_RIGHT] = max(front+right, 0.0f); + suspChange[CARWHEEL_REAR_RIGHT] = max(rear+right, 0.0f); if(m_hydraulicState < 100){ // Lowered, move wheels up @@ -2808,7 +2804,7 @@ CAutomobile::ProcessBuoyancy(void) ApplyTurnForce(impulse, point); CVector initialSpeed = m_vecMoveSpeed; - float timeStep = Max(CTimer::GetTimeStep(), 0.01f); + float timeStep = max(CTimer::GetTimeStep(), 0.01f); float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); m_vecMoveSpeed *= waterResistance; @@ -2901,7 +2897,7 @@ CAutomobile::ProcessBuoyancy(void) float fSpeed = vSpeed.MagnitudeSqr(); if(fSpeed > sq(0.05f)){ fSpeed = Sqrt(fSpeed); - float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); + float size = min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; CParticle::AddParticle(PARTICLE_PED_SPLASH, @@ -2983,11 +2979,11 @@ CAutomobile::DoDriveByShootings(void) // TODO: what is this? if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ - m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerLeft = max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); } if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ - m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerRight = max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); } } @@ -3135,7 +3131,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) FindPlayerPed()->SetWantedLevelNoDrop(1); if(m_status == STATUS_PLAYER && impulse > 50.0f){ - uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(40000/freq, freq); } @@ -3288,7 +3284,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; - money = Min(money, 40); + money = min(money, 40); if(money > 2){ sprintf(gString, "$%d", money); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; @@ -3991,7 +3987,7 @@ CAutomobile::SetupSuspensionLines(void) // adjust col model to include suspension lines if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) colModel->boundingBox.min.z = colModel->lines[0].p1.z; - float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); + float radius = max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); if(colModel->boundingSphere.radius < radius) colModel->boundingSphere.radius = radius; @@ -4483,16 +4479,8 @@ CAutomobile::SetAllTaxiLights(bool set) class CAutomobile_ : public CAutomobile { public: -<<<<<<< HEAD -<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CAutomobile(id, CreatedBy); } void dtor() { CAutomobile::~CAutomobile(); } -======= - void dtor() { this->~CAutomobile(); } ->>>>>>> More audio ped -======= - void dtor() { CAutomobile::~CAutomobile(); } ->>>>>>> fix void SetModelIndex_(uint32 id) { CAutomobile::SetModelIndex(id); } void ProcessControl_(void) { CAutomobile::ProcessControl(); } void Teleport_(CVector v) { CAutomobile::Teleport(v); } diff --git a/src/vehicles/Automobile.cpp.autosave b/src/vehicles/Automobile.cpp.autosave deleted file mode 100644 index 140633b8..00000000 --- a/src/vehicles/Automobile.cpp.autosave +++ /dev/null @@ -1,4560 +0,0 @@ -#include "common.h" -#include "main.h" -#include "patcher.h" -#include "General.h" -#include "RwHelper.h" -#include "Pad.h" -#include "ModelIndices.h" -#include "VisibilityPlugins.h" -#include "DMAudio.h" -#include "Clock.h" -#include "Timecycle.h" -#include "ZoneCull.h" -#include "Camera.h" -#include "Darkel.h" -#include "Rubbish.h" -#include "Fire.h" -#include "Explosion.h" -#include "Particle.h" -#include "ParticleObject.h" -#include "Antennas.h" -#include "Skidmarks.h" -#include "Shadows.h" -#include "PointLights.h" -#include "Coronas.h" -#include "SpecialFX.h" -#include "WaterCannon.h" -#include "WaterLevel.h" -#include "Floater.h" -#include "World.h" -#include "SurfaceTable.h" -#include "Weather.h" -#include "HandlingMgr.h" -#include "Record.h" -#include "Remote.h" -#include "Population.h" -#include "CarCtrl.h" -#include "CarAI.h" -#include "Garages.h" -#include "PathFind.h" -#include "AnimManager.h" -#include "RpAnimBlend.h" -#include "Ped.h" -#include "PlayerPed.h" -#include "Object.h" -#include "Automobile.h" - -bool bAllCarCheat; // unused - -RwObject *GetCurrentAtomicObjectCB(RwObject *object, void *data); - -bool &CAutomobile::m_sAllTaxiLights = *(bool*)0x95CD21; - -CAutomobile::CAutomobile(int32 id, uint8 CreatedBy) - : CVehicle(CreatedBy) -{ - int i; - - m_vehType = VEHICLE_TYPE_CAR; - - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); - m_fFireBlowUpTimer = 0.0f; - field_4E0 = 0; - bTaxiLight = m_sAllTaxiLights; - m_auto_flagA20 = false; - m_auto_flagA40 = false; - bWaterTight = false; - - SetModelIndex(id); - - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); - - field_49C = 20.0f; - field_4D8 = 0; - - mi->ChooseVehicleColour(m_currentColour1, m_currentColour2); - - bIsVan = !!(pHandling->Flags & HANDLING_IS_VAN); - bIsBig = !!(pHandling->Flags & HANDLING_IS_BIG); - bIsBus = !!(pHandling->Flags & HANDLING_IS_BUS); - bLowVehicle = !!(pHandling->Flags & HANDLING_IS_LOW); - - // Doors - if(bIsBus){ - Doors[DOOR_FRONT_LEFT].Init(-HALFPI, 0.0f, 0, 2); - Doors[DOOR_FRONT_RIGHT].Init(0.0f, HALFPI, 1, 2); - }else{ - Doors[DOOR_FRONT_LEFT].Init(-PI*0.4f, 0.0f, 0, 2); - Doors[DOOR_FRONT_RIGHT].Init(0.0f, PI*0.4f, 1, 2); - } - if(bIsVan){ - Doors[DOOR_REAR_LEFT].Init(-HALFPI, 0.0f, 1, 2); - Doors[DOOR_REAR_RIGHT].Init(0.0f, HALFPI, 0, 2); - }else{ - Doors[DOOR_REAR_LEFT].Init(-PI*0.4f, 0.0f, 0, 2); - Doors[DOOR_REAR_RIGHT].Init(0.0f, PI*0.4f, 1, 2); - } - if(pHandling->Flags & HANDLING_REV_BONNET) - Doors[DOOR_BONNET].Init(-PI*0.3f, 0.0f, 1, 0); - else - Doors[DOOR_BONNET].Init(0.0f, PI*0.3f, 1, 0); - if(pHandling->Flags & HANDLING_HANGING_BOOT) - Doors[DOOR_BOOT].Init(PI*0.4f, 0.0f, 0, 0); - else if(pHandling->Flags & HANDLING_TAILGATE_BOOT) - Doors[DOOR_BOOT].Init(0.0, HALFPI, 1, 0); - else - Doors[DOOR_BOOT].Init(-PI*0.3f, 0.0f, 1, 0); - if(pHandling->Flags & HANDLING_NO_DOORS){ - Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_REAR_LEFT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_REAR_RIGHT, DOOR_STATUS_MISSING); - } - - for(i = 0; i < 6; i++) - m_randomValues[i] = CGeneral::GetRandomNumberInRange(-0.15f, 0.15f); - - m_fMass = pHandling->fMass; - m_fTurnMass = pHandling->fTurnMass; - m_vecCentreOfMass = pHandling->CentreOfMass; - m_fAirResistance = pHandling->Dimension.x*pHandling->Dimension.z/m_fMass; - m_fElasticity = 0.05f; - m_fBuoyancy = pHandling->fBuoyancy; - - m_nBusDoorTimerEnd = 0; - m_nBusDoorTimerStart = 0; - - m_fSteerAngle = 0.0f; - m_fGasPedal = 0.0f; - m_fBrakePedal = 0.0f; - m_pSetOnFireEntity = nil; - field_594 = 0; - bNotDamagedUpsideDown = false; - bMoreResistantToDamage = false; - m_fVelocityChangeForAudio = 0.0f; - m_hydraulicState = 0; - - for(i = 0; i < 4; i++){ - m_aGroundPhysical[i] = nil; - m_aGroundOffset[i] = CVector(0.0f, 0.0f, 0.0f); - m_aSuspensionSpringRatio[i] = 1.0f; - m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i]; - m_aWheelTimer[i] = 0.0f; - m_aWheelRotation[i] = 0.0f; - m_aWheelSpeed[i] = 0.0f; - m_aWheelState[i] = WHEEL_STATE_NORMAL; - m_aWheelSkidmarkMuddy[i] = false; - m_aWheelSkidmarkBloody[i] = false; - } - - m_nWheelsOnGround = 0; - m_nDriveWheelsOnGround = 0; - m_nDriveWheelsOnGroundPrev = 0; - m_fHeightAboveRoad = 0.0f; - m_fTraction = 1.0f; - - CColModel *colModel = mi->GetColModel(); - if(colModel->lines == nil){ - colModel->lines = (CColLine*)RwMalloc(4*sizeof(CColLine)); - colModel->numLines = 4; - } - - SetupSuspensionLines(); - - m_status = STATUS_SIMPLE; - bUseCollisionRecords = true; - - m_nNumPassengers = 0; - - m_bombType = CARBOMB_NONE; - bHadDriver = false; - m_pBombRigger = nil; - - if(m_nDoorLock == CARLOCK_UNLOCKED && - (id == MI_POLICE || id == MI_ENFORCER || id == MI_RHINO)) - m_nDoorLock = CARLOCK_LOCKED_INITIALLY; - - m_fCarGunLR = 0.0f; - m_fCarGunUD = 0.05f; - m_fPropellerRotation = 0.0f; - m_weaponDoorTimerLeft = 0.0f; - m_weaponDoorTimerRight = m_weaponDoorTimerLeft; - - if(GetModelIndex() == MI_DODO){ - RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LF]), 0); - CMatrix mat1; - mat1.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - CMatrix mat2(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); - mat1.GetPosition() += CVector(mat2.GetPosition().x + 0.1f, 0.0f, mat2.GetPosition().z); - mat1.UpdateRW(); - }else if(GetModelIndex() == MI_MIAMI_SPARROW || GetModelIndex() == MI_MIAMI_RCRAIDER){ - RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LF]), 0); - RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_RF]), 0); - RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_LB]), 0); - RpAtomicSetFlags(GetFirstObject(m_aCarNodes[CAR_WHEEL_RB]), 0); - }else if(GetModelIndex() == MI_RHINO){ - bExplosionProof = true; - bBulletProof = true; - } -} - - -void -CAutomobile::SetModelIndex(uint32 id) -{ - CVehicle::SetModelIndex(id); - SetupModelNodes(); -} - -CVector vecDAMAGE_ENGINE_POS_SMALL(-0.1f, -0.1f, 0.0f); -CVector vecDAMAGE_ENGINE_POS_BIG(-0.5f, -0.3f, 0.0f); - -void -CAutomobile::ProcessControl(void) -{ - int i; - CColModel *colModel; - - if(bUsingSpecialColModel) - colModel = &CWorld::Players[CWorld::PlayerInFocus].m_ColModel; - else - colModel = GetColModel(); - bWarnedPeds = false; - - // skip if the collision isn't for the current level - if(colModel->level > LEVEL_NONE && colModel->level != CCollision::ms_collisionInMemory) - return; - - // Improve grip of vehicles in certain cases - bool strongGrip1 = false; - bool strongGrip2 = false; - if(FindPlayerVehicle() && this != FindPlayerVehicle()){ - switch(AutoPilot.m_nCarMission){ - case MISSION_RAMPLAYER_FARAWAY: - case MISSION_RAMPLAYER_CLOSE: - case MISSION_BLOCKPLAYER_FARAWAY: - case MISSION_BLOCKPLAYER_CLOSE: - if(FindPlayerSpeed().Magnitude() > 0.3f){ - strongGrip1 = true; - if(FindPlayerSpeed().Magnitude() > 0.4f){ - if(m_vecMoveSpeed.Magnitude() < 0.3f) - strongGrip2 = true; - }else{ - if((GetPosition() - FindPlayerCoors()).Magnitude() > 50.0f) - strongGrip2 = true; - } - } - } - } - - if(bIsBus) - ProcessAutoBusDoors(); - - ProcessCarAlarm(); - - // Scan if this car is committing a crime that the police can see - if(m_status != STATUS_ABANDONED && m_status != STATUS_WRECKED && - m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PLAYER_DISABLED){ - switch(GetModelIndex()) - case MI_FBICAR: - case MI_POLICE: - case MI_ENFORCER: - case MI_SECURICA: - case MI_RHINO: - case MI_BARRACKS: - ScanForCrimes(); - } - - // Process driver - if(pDriver){ - if(!bHadDriver && m_bombType == CARBOMB_ONIGNITIONACTIVE){ - // If someone enters the car and there is a bomb, detonate - m_nBombTimer = 1000; - m_pBlowUpEntity = m_pBombRigger; - if(m_pBlowUpEntity) - m_pBlowUpEntity->RegisterReference((CEntity**)&m_pBlowUpEntity); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TICK, 1.0f); - } - bHadDriver = true; - - if(IsUpsideDown() && CanPedEnterCar()){ - if(!pDriver->IsPlayer() && - !(pDriver->m_leader && pDriver->m_leader->bInVehicle) && - pDriver->CharCreatedBy != MISSION_CHAR) - pDriver->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); - } - }else - bHadDriver = false; - - // Process passengers - if(m_nNumPassengers != 0 && IsUpsideDown() && CanPedEnterCar()){ - for(i = 0; i < m_nNumMaxPassengers; i++) - if(pPassengers[i]) - if(!pPassengers[i]->IsPlayer() && - !(pPassengers[i]->m_leader && pPassengers[i]->m_leader->bInVehicle) && - pPassengers[i]->CharCreatedBy != MISSION_CHAR) - pPassengers[i]->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); - } - - CRubbish::StirUp(this); - - // blend in clump - int clumpAlpha = CVisibilityPlugins::GetClumpAlpha((RpClump*)m_rwObject); - if(bFadeOut){ - clumpAlpha -= 8; - if(clumpAlpha < 0) - clumpAlpha = 0; - }else if(clumpAlpha < 255){ - clumpAlpha += 16; - if(clumpAlpha > 255) - clumpAlpha = 255; - } - CVisibilityPlugins::SetClumpAlpha((RpClump*)m_rwObject, clumpAlpha); - - AutoPilot.m_bSlowedDownBecauseOfCars = false; - AutoPilot.m_bSlowedDownBecauseOfPeds = false; - - // Set Center of Mass to make car more stable - if(strongGrip1 || bCheat3) - m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0*m_fHeightAboveRoad; - else if(pHandling->Flags & HANDLING_NONPLAYER_STABILISER && m_status == STATUS_PHYSICS) - m_vecCentreOfMass.z = pHandling->CentreOfMass.z - 0.2f*pHandling->Dimension.z; - else - m_vecCentreOfMass.z = pHandling->CentreOfMass.z; - - // Process depending on status - - bool playerRemote = false; - switch(m_status){ - case STATUS_PLAYER_REMOTE: - if(CPad::GetPad(0)->WeaponJustDown()){ - BlowUpCar(FindPlayerPed()); - CRemote::TakeRemoteControlledCarFromPlayer(); - } - - if(GetModelIndex() == MI_RCBANDIT){ - CVector pos = GetPosition(); - // FindPlayerCoors unused - if(RcbanditCheckHitWheels() || bIsInWater || CPopulation::IsPointInSafeZone(&pos)){ - if(CPopulation::IsPointInSafeZone(&pos)) - CGarages::TriggerMessage("HM2_5", -1, 5000, -1); - CRemote::TakeRemoteControlledCarFromPlayer(); - BlowUpCar(FindPlayerPed()); - } - } - - if(CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle == this) - playerRemote = true; - // fall through - case STATUS_PLAYER: - if(playerRemote || - pDriver && pDriver->GetPedState() != PED_EXIT_CAR && pDriver->GetPedState() != PED_DRAG_FROM_CAR){ - // process control input if controlled by player - if(playerRemote || pDriver->m_nPedType == PEDTYPE_PLAYER1) - ProcessControlInputs(0); - - PruneReferences(); - - if(m_status == STATUS_PLAYER && CRecordDataForChase::Status != RECORDSTATE_1) - DoDriveByShootings(); - } - break; - - case STATUS_SIMPLE: - CCarAI::UpdateCarAI(this); - CPhysical::ProcessControl(); - CCarCtrl::UpdateCarOnRails(this); - - m_nWheelsOnGround = 4; - m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround; - m_nDriveWheelsOnGround = 4; - - pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear); - - { - float wheelRot = ProcessWheelRotation(WHEEL_STATE_NORMAL, GetForward(), m_vecMoveSpeed, 0.35f); - for(i = 0; i < 4; i++) - m_aWheelRotation[i] += wheelRot; - } - - PlayHornIfNecessary(); - ReduceHornCounter(); - bVehicleColProcessed = false; - // that's all we do for simple vehicles - return; - - case STATUS_PHYSICS: - CCarAI::UpdateCarAI(this); - CCarCtrl::SteerAICarWithPhysics(this); - PlayHornIfNecessary(); - break; - - case STATUS_ABANDONED: - m_fBrakePedal = 0.2f; - bIsHandbrakeOn = false; - - m_fSteerAngle = 0.0f; - m_fGasPedal = 0.0f; - m_nCarHornTimer = 0; - break; - - case STATUS_WRECKED: - m_fBrakePedal = 0.05f; - bIsHandbrakeOn = true; - - m_fSteerAngle = 0.0f; - m_fGasPedal = 0.0f; - m_nCarHornTimer = 0; - break; - - case STATUS_PLAYER_DISABLED: - m_fBrakePedal = 1.0f; - bIsHandbrakeOn = true; - - m_fSteerAngle = 0.0f; - m_fGasPedal = 0.0f; - m_nCarHornTimer = 0; - break; - } - - // what's going on here? - if(GetPosition().z < -0.6f && - Abs(m_vecMoveSpeed.x) < 0.05f && - Abs(m_vecMoveSpeed.y) < 0.05f) - m_vecTurnSpeed *= Pow(0.95f, CTimer::GetTimeStep()); - - // Skip physics if object is found to have been static recently - bool skipPhysics = false; - if(!bIsStuck && (m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED)){ - bool makeStatic = false; - float moveSpeedLimit, turnSpeedLimit, distanceLimit; - - if(!bVehicleColProcessed && - m_vecMoveSpeed.IsZero() && - // BUG? m_aSuspensionSpringRatioPrev[3] is checked twice in the game. also, why 3? - m_aSuspensionSpringRatioPrev[3] != 1.0f) - makeStatic = true; - - if(m_status == STATUS_WRECKED){ - moveSpeedLimit = 0.006f; - turnSpeedLimit = 0.0015f; - distanceLimit = 0.015f; - }else{ - moveSpeedLimit = 0.003f; - turnSpeedLimit = 0.0009f; - distanceLimit = 0.005f; - } - - m_vecMoveSpeedAvg = (m_vecMoveSpeedAvg + m_vecMoveSpeed)/2.0f; - m_vecTurnSpeedAvg = (m_vecTurnSpeedAvg + m_vecTurnSpeed)/2.0f; - - if(m_vecMoveSpeedAvg.MagnitudeSqr() <= sq(moveSpeedLimit*CTimer::GetTimeStep()) && - m_vecTurnSpeedAvg.MagnitudeSqr() <= sq(turnSpeedLimit*CTimer::GetTimeStep()) && - m_fDistanceTravelled < distanceLimit || - makeStatic){ - m_nStaticFrames++; - - if(m_nStaticFrames > 10 || makeStatic) - if(!CCarCtrl::MapCouldMoveInThisArea(GetPosition().x, GetPosition().y)){ - if(!makeStatic || m_nStaticFrames > 10) - m_nStaticFrames = 10; - - skipPhysics = true; - - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); - } - }else - m_nStaticFrames = 0; - } - - // Postpone - for(i = 0; i < 4; i++) - if(m_aGroundPhysical[i] && !CWorld::bForceProcessControl && m_aGroundPhysical[i]->bIsInSafePosition){ - bWasPostponed = true; - return; - } - - VehicleDamage(0.0f, 0); - - // special control - switch(GetModelIndex()){ - case MI_FIRETRUCK: - FireTruckControl(); - break; - case MI_RHINO: - TankControl(); - BlowUpCarsInPath(); - break; - case MI_YARDIE: - // beta also had esperanto here it seems - HydraulicControl(); - break; - default: - if(CVehicle::bCheat3){ - // Make vehicle jump when horn is sounded - if(m_status == STATUS_PLAYER && m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f) && - // BUG: game checks [0] four times, instead of all wheels - m_aSuspensionSpringRatio[0] < 1.0f && - CPad::GetPad(0)->HornJustDown()){ - - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, 1.0f); - - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, - m_aWheelColPoints[0].point + 0.5f*GetUp(), - 1.3f*m_vecMoveSpeed, nil, 2.5f); - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, - m_aWheelColPoints[0].point + 0.5f*GetUp(), - 1.2f*m_vecMoveSpeed, nil, 2.0f); - - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, - m_aWheelColPoints[2].point + 0.5f*GetUp(), - 1.3f*m_vecMoveSpeed, nil, 2.5f); - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, - m_aWheelColPoints[2].point + 0.5f*GetUp(), - 1.2f*m_vecMoveSpeed, nil, 2.0f); - - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, - m_aWheelColPoints[0].point + 0.5f*GetUp() - GetForward(), - 1.3f*m_vecMoveSpeed, nil, 2.5f); - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, - m_aWheelColPoints[0].point + 0.5f*GetUp() - GetForward(), - 1.2f*m_vecMoveSpeed, nil, 2.0f); - - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, - m_aWheelColPoints[2].point + 0.5f*GetUp() - GetForward(), - 1.3f*m_vecMoveSpeed, nil, 2.5f); - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, - m_aWheelColPoints[2].point + 0.5f*GetUp() - GetForward(), - 1.2f*m_vecMoveSpeed, nil, 2.0f); - - ApplyMoveForce(CVector(0.0f, 0.0f, 1.0f)*m_fMass*0.4f); - ApplyTurnForce(GetUp()*m_fMass*0.035f, GetForward()*1.0f); - } - } - break; - } - - float brake; - if(skipPhysics){ - bHasContacted = false; - bIsInSafePosition = false; - bWasPostponed = false; - bHasHitWall = false; - m_nCollisionRecords = 0; - bHasCollided = false; - bVehicleColProcessed = false; - m_nDamagePieceType = 0; - m_fDamageImpulse = 0.0f; - m_pDamageEntity = nil; - m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); - m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); - }else{ - - // This has to be done if ProcessEntityCollision wasn't called - if(!bVehicleColProcessed){ - CMatrix mat(GetMatrix()); - bIsStuck = false; - bHasContacted = false; - bIsInSafePosition = false; - bWasPostponed = false; - bHasHitWall = false; - m_fDistanceTravelled = 0.0f; - field_EF = false; - m_phy_flagA80 = false; - ApplyMoveSpeed(); - ApplyTurnSpeed(); - for(i = 0; CheckCollision() && i < 5; i++){ - GetMatrix() = mat; - ApplyMoveSpeed(); - ApplyTurnSpeed(); - } - bIsInSafePosition = true; - bIsStuck = false; - } - - CPhysical::ProcessControl(); - - ProcessBuoyancy(); - - // Rescale spring ratios, i.e. subtract wheel radius - for(i = 0; i < 4; i++){ - // wheel radius in relation to suspension line - float wheelRadius = 1.0f - m_aSuspensionSpringLength[i]/m_aSuspensionLineLength[i]; - // rescale such that 0.0 is fully compressed and 1.0 is fully extended - m_aSuspensionSpringRatio[i] = (m_aSuspensionSpringRatio[i]-wheelRadius)/(1.0f-wheelRadius); - } - - float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()); - CVector contactPoints[4]; // relative to model - CVector contactSpeeds[4]; // speed at contact points - CVector springDirections[4]; // normalized, in model space - - for(i = 0; i < 4; i++){ - // Set spring under certain circumstances - if(Damage.GetWheelStatus(i) == WHEEL_STATUS_MISSING) - m_aSuspensionSpringRatio[i] = 1.0f; - else if(Damage.GetWheelStatus(i) == WHEEL_STATUS_BURST){ - // wheel more bumpy the faster we are - if(CGeneral::GetRandomNumberInRange(0, (uint16)(40*fwdSpeed) + 98) < 100){ - m_aSuspensionSpringRatio[i] += 0.3f*(m_aSuspensionLineLength[i]-m_aSuspensionSpringLength[i])/m_aSuspensionSpringLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - } - - // get points and directions if spring is compressed - if(m_aSuspensionSpringRatio[i] < 1.0f){ - contactPoints[i] = m_aWheelColPoints[i].point - GetPosition(); - springDirections[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1 - colModel->lines[i].p0); - springDirections[i].Normalise(); - } - } - - // Make springs push up vehicle - for(i = 0; i < 4; i++){ - if(m_aSuspensionSpringRatio[i] < 1.0f){ - float bias = pHandling->fSuspensionBias; - if(i == 1 || i == 3) // rear - bias = 1.0f - bias; - - ApplySpringCollision(pHandling->fSuspensionForceLevel, - springDirections[i], contactPoints[i], - m_aSuspensionSpringRatio[i], bias); - m_aWheelSkidmarkMuddy[i] = - m_aWheelColPoints[i].surfaceB == SURFACE_GRASS || - m_aWheelColPoints[i].surfaceB == SURFACE_DIRTTRACK || - m_aWheelColPoints[i].surfaceB == SURFACE_SAND; - }else{ - contactPoints[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1); - } - } - - // Get speed at contact points - for(i = 0; i < 4; i++){ - contactSpeeds[i] = GetSpeed(contactPoints[i]); - if(m_aGroundPhysical[i]){ - // subtract movement of physical we're standing on - contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]); -#ifndef FIX_BUGS - // this shouldn't be reset because we still need it below - m_aGroundPhysical[i] = nil; -#endif - } - } - - // dampen springs - for(i = 0; i < 4; i++) - if(m_aSuspensionSpringRatio[i] < 1.0f) - ApplySpringDampening(pHandling->fSuspensionDampingLevel, - springDirections[i], contactPoints[i], contactSpeeds[i]); - - // Get speed at contact points again - for(i = 0; i < 4; i++){ - contactSpeeds[i] = GetSpeed(contactPoints[i]); - if(m_aGroundPhysical[i]){ - // subtract movement of physical we're standing on - contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]); - m_aGroundPhysical[i] = nil; - } - } - - - bool gripCheat = true; - fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()); - if(!strongGrip1 && !CVehicle::bCheat3) - gripCheat = false; - float acceleration = pHandling->Transmission.CalculateDriveAcceleration(m_fGasPedal, m_nCurrentGear, m_fChangeGearTime, fwdSpeed, gripCheat); - acceleration /= fForceMultiplier; - - // unused - if(GetModelIndex() == MI_MIAMI_RCBARON || - GetModelIndex() == MI_MIAMI_RCRAIDER || - GetModelIndex() == MI_MIAMI_SPARROW) - acceleration = 0.0f; - - brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep(); - bool neutralHandling = !!(pHandling->Flags & HANDLING_NEUTRALHANDLING); - float brakeBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias; - float brakeBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fBrakeBias); - float tractionBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias; - float tractionBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fTractionBias); - - // Count how many wheels are touching the ground - - m_nWheelsOnGround = 0; - m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround; - m_nDriveWheelsOnGround = 0; - - for(i = 0; i < 4; i++){ - if(m_aSuspensionSpringRatio[i] < 1.0f) - m_aWheelTimer[i] = 4.0f; - else - m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); - - if(m_aWheelTimer[i] > 0.0f){ - m_nWheelsOnGround++; - switch(pHandling->Transmission.nDriveType){ - case '4': - m_nDriveWheelsOnGround++; - break; - case 'F': - if(i == CARWHEEL_FRONT_LEFT || i == CARWHEEL_FRONT_RIGHT) - m_nDriveWheelsOnGround++; - break; - case 'R': - if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT) - m_nDriveWheelsOnGround++; - break; - } - } - } - - float traction; - if(m_status == STATUS_PHYSICS) - traction = 0.004f * m_fTraction; - else - traction = 0.004f; - traction *= pHandling->fTractionMultiplier / 4.0f; - traction /= fForceMultiplier; - if(CVehicle::bCheat3) - traction *= 4.0f; - - if(FindPlayerVehicle() && FindPlayerVehicle() == this){ - if(CPad::GetPad(0)->WeaponJustDown()){ - if(m_bombType == CARBOMB_TIMED){ - m_bombType = CARBOMB_TIMEDACTIVE; - m_nBombTimer = 7000; - m_pBlowUpEntity = FindPlayerPed(); - CGarages::TriggerMessage("GA_12", -1, 3000, -1); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TIMED_ACTIVATED, 1.0f); - }else if(m_bombType == CARBOMB_ONIGNITION){ - m_bombType = CARBOMB_ONIGNITIONACTIVE; - CGarages::TriggerMessage("GA_12", -1, 3000, -1); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_ONIGNITION_ACTIVATED, 1.0f); - } - } - }else if(strongGrip1 || CVehicle::bCheat3){ - traction *= 1.2f; - acceleration *= 1.4f; - if(strongGrip2 || CVehicle::bCheat3){ - traction *= 1.3f; - acceleration *= 1.4f; - } - } - - static float fThrust; - static tWheelState WheelState[4]; - - // Process front wheels on ground - - if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){ - float s = Sin(m_fSteerAngle); - float c = Cos(m_fSteerAngle); - CVector wheelFwd = Multiply3x3(GetMatrix(), CVector(-s, c, 0.0f)); - CVector wheelRight = Multiply3x3(GetMatrix(), CVector(c, s, 0.0f)); - - if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f){ - if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)) - fThrust = 0.0f; - else - fThrust = acceleration; - - m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceA = SURFACE_RUBBER29; - float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_LEFT])*traction; - if(m_status == STATUS_PLAYER) - adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB); - WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT]; - - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasFront, - adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect, - CARWHEEL_FRONT_LEFT, - &m_aWheelSpeed[CARWHEEL_FRONT_LEFT], - &WheelState[CARWHEEL_FRONT_LEFT], - WHEEL_STATUS_BURST); - else - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasFront, - adhesion*tractionBiasFront, - CARWHEEL_FRONT_LEFT, - &m_aWheelSpeed[CARWHEEL_FRONT_LEFT], - &WheelState[CARWHEEL_FRONT_LEFT], - WHEEL_STATUS_OK); - } - - if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){ - if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)) - fThrust = 0.0f; - else - fThrust = acceleration; - - m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceA = SURFACE_RUBBER29; - float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT])*traction; - if(m_status == STATUS_PLAYER) - adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB); - WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT]; - - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasFront, - adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect, - CARWHEEL_FRONT_RIGHT, - &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT], - &WheelState[CARWHEEL_FRONT_RIGHT], - WHEEL_STATUS_BURST); - else - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasFront, - adhesion*tractionBiasFront, - CARWHEEL_FRONT_RIGHT, - &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT], - &WheelState[CARWHEEL_FRONT_RIGHT], - WHEEL_STATUS_OK); - } - } - - // Process front wheels off ground - - if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] <= 0.0f){ - if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) - m_aWheelSpeed[CARWHEEL_FRONT_LEFT] *= 0.95f; - else{ - if(acceleration > 0.0f){ - if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] < 2.0f) - m_aWheelSpeed[CARWHEEL_FRONT_LEFT] -= 0.2f; - }else{ - if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] > -2.0f) - m_aWheelSpeed[CARWHEEL_FRONT_LEFT] += 0.1f; - } - } - m_aWheelRotation[CARWHEEL_FRONT_LEFT] += m_aWheelSpeed[CARWHEEL_FRONT_LEFT]; - } - if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] <= 0.0f){ - if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) - m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] *= 0.95f; - else{ - if(acceleration > 0.0f){ - if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] < 2.0f) - m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] -= 0.2f; - }else{ - if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] > -2.0f) - m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] += 0.1f; - } - } - m_aWheelRotation[CARWHEEL_FRONT_RIGHT] += m_aWheelSpeed[CARWHEEL_FRONT_RIGHT]; - } - - // Process rear wheels - - if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ - CVector wheelFwd = GetForward(); - CVector wheelRight = GetRight(); - - if(bIsHandbrakeOn) - brake = 20000.0f; - - if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier)) - fThrust = 0.0f; - else - fThrust = acceleration; - - m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceA = SURFACE_RUBBER29; - float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_LEFT])*traction; - if(m_status == STATUS_PLAYER) - adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB); - WheelState[CARWHEEL_REAR_LEFT] = m_aWheelState[CARWHEEL_REAR_LEFT]; - - if(Damage.GetWheelStatus(VEHWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasRear, - adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect, - CARWHEEL_REAR_LEFT, - &m_aWheelSpeed[CARWHEEL_REAR_LEFT], - &WheelState[CARWHEEL_REAR_LEFT], - WHEEL_STATUS_BURST); - else - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasRear, - adhesion*tractionBiasRear, - CARWHEEL_REAR_LEFT, - &m_aWheelSpeed[CARWHEEL_REAR_LEFT], - &WheelState[CARWHEEL_REAR_LEFT], - WHEEL_STATUS_OK); - } - - if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier)) - fThrust = 0.0f; - else - fThrust = acceleration; - - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceA = SURFACE_RUBBER29; - float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_RIGHT])*traction; - if(m_status == STATUS_PLAYER) - adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB); - WheelState[CARWHEEL_REAR_RIGHT] = m_aWheelState[CARWHEEL_REAR_RIGHT]; - - if(Damage.GetWheelStatus(VEHWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasRear, - adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect, - CARWHEEL_REAR_RIGHT, - &m_aWheelSpeed[CARWHEEL_REAR_RIGHT], - &WheelState[CARWHEEL_REAR_RIGHT], - WHEEL_STATUS_BURST); - else - ProcessWheel(wheelFwd, wheelRight, - contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT], - m_nWheelsOnGround, fThrust, - brake*brakeBiasRear, - adhesion*tractionBiasRear, - CARWHEEL_REAR_RIGHT, - &m_aWheelSpeed[CARWHEEL_REAR_RIGHT], - &WheelState[CARWHEEL_REAR_RIGHT], - WHEEL_STATUS_OK); - } - } - - // Process rear wheels off ground - - if(m_aWheelTimer[CARWHEEL_REAR_LEFT] <= 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) - m_aWheelSpeed[CARWHEEL_REAR_LEFT] *= 0.95f; - else{ - if(acceleration > 0.0f){ - if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] < 2.0f) - m_aWheelSpeed[CARWHEEL_REAR_LEFT] -= 0.2f; - }else{ - if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] > -2.0f) - m_aWheelSpeed[CARWHEEL_REAR_LEFT] += 0.1f; - } - } - m_aWheelRotation[CARWHEEL_REAR_LEFT] += m_aWheelSpeed[CARWHEEL_REAR_LEFT]; - } - if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] <= 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) - m_aWheelSpeed[CARWHEEL_REAR_RIGHT] *= 0.95f; - else{ - if(acceleration > 0.0f){ - if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] < 2.0f) - m_aWheelSpeed[CARWHEEL_REAR_RIGHT] -= 0.2f; - }else{ - if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] > -2.0f) - m_aWheelSpeed[CARWHEEL_REAR_RIGHT] += 0.1f; - } - } - m_aWheelRotation[CARWHEEL_REAR_RIGHT] += m_aWheelSpeed[CARWHEEL_REAR_RIGHT]; - } - - for(i = 0; i < 4; i++){ - float wheelPos = colModel->lines[i].p0.z; - if(m_aSuspensionSpringRatio[i] > 0.0f) - wheelPos -= m_aSuspensionSpringRatio[i]*m_aSuspensionSpringLength[i]; - m_aWheelPosition[i] += (wheelPos - m_aWheelPosition[i])*0.75f; - } - for(i = 0; i < 4; i++) - m_aWheelState[i] = WheelState[i]; - - // Process horn - - if(m_status != STATUS_PLAYER){ - ReduceHornCounter(); - }else{ - if(GetModelIndex() == MI_MRWHOOP){ - if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory] && - !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5]){ - m_bSirenOrAlarm = !m_bSirenOrAlarm; - printf("m_bSirenOrAlarm toggled to %d\n", m_bSirenOrAlarm); - } - }else if(UsesSiren(GetModelIndex())){ - if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory]){ - if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] && - Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+3) % 5]) - m_nCarHornTimer = 1; - else - m_nCarHornTimer = 0; - }else if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] && - !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+1) % 5]){ - m_nCarHornTimer = 0; - m_bSirenOrAlarm = !m_bSirenOrAlarm; - }else - m_nCarHornTimer = 0; - }else if(GetModelIndex() != MI_YARDIE && !CVehicle::bCheat3){ - if(Pads[0].GetHorn()) - m_nCarHornTimer = 1; - else - m_nCarHornTimer = 0; - } - } - - // Flying - - if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ - if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); - }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && - m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ - FlyingControl(FLIGHT_MODEL_DODO); - }else if(GetModelIndex() == MI_MIAMI_RCBARON){ - FlyingControl(FLIGHT_MODEL_HELI); - }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ - if(CPad::GetPad(0)->GetCircleJustDown()) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); - if(m_aWheelSpeed[0] < 0.22f) - m_aWheelSpeed[0] += 0.0001f; - if(m_aWheelSpeed[0] > 0.15f) - FlyingControl(FLIGHT_MODEL_HELI); - } - } - - - - // Process car on fire - // A similar calculation of damagePos is done elsewhere for smoke - - uint8 engineStatus = Damage.GetEngineStatus(); - CVector damagePos = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_positions[CAR_POS_HEADLIGHTS]; - - switch(Damage.GetDoorStatus(DOOR_BONNET)){ - case DOOR_STATUS_OK: - case DOOR_STATUS_SMASHED: - // Bonnet is still there, smoke comes out at the edge - damagePos += vecDAMAGE_ENGINE_POS_SMALL; - break; - case DOOR_STATUS_SWINGING: - case DOOR_STATUS_MISSING: - // Bonnet is gone, smoke comes out at the engine - damagePos += vecDAMAGE_ENGINE_POS_BIG; - break; - } - - // move fire forward if in first person - if(this == FindPlayerVehicle() && TheCamera.GetLookingForwardFirstPerson()) - if(m_fHealth < 250.0f && m_status != STATUS_WRECKED){ - if(GetModelIndex() == MI_FIRETRUCK) - damagePos += CVector(0.0f, 3.0f, -0.2f); - else - damagePos += CVector(0.0f, 1.2f, -0.8f); - } - - damagePos = GetMatrix()*damagePos; - damagePos.z += 0.15f; - - if(m_fHealth < 250.0f && m_status != STATUS_WRECKED){ - // Car is on fire - - CParticle::AddParticle(PARTICLE_CARFLAME, damagePos, - CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.01125f, 0.09f)), - nil, 0.9f); - - CVector coors = damagePos; - coors.x += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f), - coors.y += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f), - coors.z += CGeneral::GetRandomNumberInRange(0.5625f, 2.25f); - CParticle::AddParticle(PARTICLE_CARFLAME_SMOKE, coors, CVector(0.0f, 0.0f, 0.0f)); - - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE2, damagePos, CVector(0.0f, 0.0f, 0.0f), nil, 0.5f); - - // Blow up car after 5 seconds - m_fFireBlowUpTimer += CTimer::GetTimeStepInMilliseconds(); - if(m_fFireBlowUpTimer > 5000.0f){ - CWorld::Players[CWorld::PlayerInFocus].AwardMoneyForExplosion(this); - BlowUpCar(m_pSetOnFireEntity); - } - }else - m_fFireBlowUpTimer = 0.0f; - - // Decrease car health if engine is damaged badly - if(engineStatus > ENGINE_STATUS_ON_FIRE && m_fHealth > 250.0f) - m_fHealth -= 2.0f; - - ProcessDelayedExplosion(); - - - if(m_bSirenOrAlarm && (CTimer::GetFrameCounter()&7) == 5 && - UsesSiren(GetModelIndex()) && GetModelIndex() != MI_RCBANDIT) - CCarAI::MakeWayForCarWithSiren(this); - - - // Find out how much to shake the pad depending on suspension and ground surface - - float suspShake = 0.0f; - float surfShake = 0.0f; - for(i = 0; i < 4; i++){ - float suspChange = m_aSuspensionSpringRatioPrev[i] - m_aSuspensionSpringRatio[i]; - if(suspChange > 0.3f){ - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, suspChange); - if(suspChange > suspShake) - suspShake = suspChange; - } - - uint8 surf = m_aWheelColPoints[i].surfaceB; - if(surf == SURFACE_DIRT || surf == SURFACE_PUDDLE || surf == SURFACE_HEDGE){ - if(surfShake < 0.2f) - surfShake = 0.3f; - }else if(surf == SURFACE_DIRTTRACK || surf == SURFACE_SAND){ - if(surfShake < 0.1f) - surfShake = 0.2f; - }else if(surf == SURFACE_GRASS){ - if(surfShake < 0.05f) - surfShake = 0.1f; - } - - m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i]; - m_aSuspensionSpringRatio[i] = 1.0f; - } - - // Shake pad - - if((suspShake > 0.0f || surfShake > 0.0f) && m_status == STATUS_PLAYER){ - float speed = m_vecMoveSpeed.MagnitudeSqr(); - if(speed > sq(0.1f)){ - speed = Sqrt(speed); - if(suspShake > 0.0f){ - uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); - CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); - }else{ - uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); - CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); - } - } - } - - bVehicleColProcessed = false; - - if(!bWarnedPeds) - CCarCtrl::ScanForPedDanger(this); - - - // Turn around at the edge of the world - // TODO: make the numbers defines - - float heading; - if(GetPosition().x > 1900.0f){ - if(m_vecMoveSpeed.x > 0.0f) - m_vecMoveSpeed.x *= -1.0f; - heading = GetForward().Heading(); - if(heading > 0.0f) // going west - SetHeading(-heading); - }else if(GetPosition().x < -1900.0f){ - if(m_vecMoveSpeed.x < 0.0f) - m_vecMoveSpeed.x *= -1.0f; - heading = GetForward().Heading(); - if(heading < 0.0f) // going east - SetHeading(-heading); - } - if(GetPosition().y > 1900.0f){ - if(m_vecMoveSpeed.y > 0.0f) - m_vecMoveSpeed.y *= -1.0f; - heading = GetForward().Heading(); - if(heading < HALFPI && heading > 0.0f) - SetHeading(PI-heading); - else if(heading > -HALFPI && heading < 0.0f) - SetHeading(-PI-heading); - }else if(GetPosition().y < -1900.0f){ - if(m_vecMoveSpeed.y < 0.0f) - m_vecMoveSpeed.y *= -1.0f; - heading = GetForward().Heading(); - if(heading > HALFPI) - SetHeading(PI-heading); - else if(heading < -HALFPI) - SetHeading(-PI-heading); - } - - if(bInfiniteMass){ - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); - m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); - m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); - }else if(!skipPhysics && - (m_fGasPedal == 0.0f && brake == 0.0f || m_status == STATUS_WRECKED)){ - if(Abs(m_vecMoveSpeed.x) < 0.005f && - Abs(m_vecMoveSpeed.y) < 0.005f && - Abs(m_vecMoveSpeed.z) < 0.005f){ - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - m_vecTurnSpeed.z = 0.0f; - } - } -} - -void -CAutomobile::Teleport(CVector pos) -{ - CWorld::Remove(this); - - GetPosition() = pos; - SetOrientation(0.0f, 0.0f, 0.0f); - SetMoveSpeed(0.0f, 0.0f, 0.0f); - SetTurnSpeed(0.0f, 0.0f, 0.0f); - - ResetSuspension(); - - CWorld::Add(this); -} - -void -CAutomobile::PreRender(void) -{ - int i, j, n; - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - - if(GetModelIndex() == MI_RCBANDIT){ - CVector pos = GetMatrix() * CVector(0.218f, -0.444f, 0.391f); - CAntennas::RegisterOne((uintptr)this, GetUp(), pos, 1.0f); - } - - float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward())*180.0f; - - - // Wheel particles - - if(GetModelIndex() == MI_DODO){ - ; // nothing - }else if(GetModelIndex() == MI_RCBANDIT){ - for(i = 0; i < 4; i++){ - // Game has same code three times here - switch(m_aWheelState[i]){ - case WHEEL_STATE_SPINNING: - case WHEEL_STATE_SKIDDING: - case WHEEL_STATE_FIXED: - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.05f), - CVector(0.0f, 0.0f, 0.0f), nil, 0.1f); - break; - } - } - }else{ - if(m_status == STATUS_SIMPLE){ - CMatrix mat; - CVector pos; - - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); - pos = mat.GetPosition(); - pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_RIGHT]; - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point = GetMatrix() * pos; - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB = SURFACE_DEFAULT; - - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); - pos = mat.GetPosition(); - pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_LEFT]; - m_aWheelColPoints[CARWHEEL_REAR_LEFT].point = GetMatrix() * pos; - m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB = SURFACE_DEFAULT; - - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - pos = mat.GetPosition(); - pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; - m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].point = GetMatrix() * pos; - m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB = SURFACE_DEFAULT; - - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); - pos = mat.GetPosition(); - pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_LEFT]; - m_aWheelColPoints[CARWHEEL_FRONT_LEFT].point = GetMatrix() * pos; - m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB = SURFACE_DEFAULT; - } - - int drawParticles = Abs(fwdSpeed) < 90.0f; - if(m_status == STATUS_SIMPLE || m_status == STATUS_PHYSICS || - m_status == STATUS_PLAYER || m_status == STATUS_PLAYER_PLAYBACKFROMBUFFER){ - bool rearSkidding = false; - if(m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SKIDDING || - m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SKIDDING) - rearSkidding = true; - - for(i = 0; i < 4; i++){ - switch(m_aWheelState[i]){ - case WHEEL_STATE_SPINNING: - if(AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles)){ - CParticle::AddParticle(PARTICLE_BURNINGRUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), - CVector(0.0f, 0.0f, 0.0f)); - - CParticle::AddParticle(PARTICLE_BURNINGRUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), - CVector(0.0f, 0.0f, 0.05f)); - } - - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), - CVector(0.0f, 0.0f, 0.0f)); - - if(m_aWheelTimer[i] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); - break; - - case WHEEL_STATE_SKIDDING: - if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT || rearSkidding){ - // same as below - - AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); - - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), - CVector(0.0f, 0.0f, 0.0f)); - - if(m_aWheelTimer[i] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); - } - break; - - case WHEEL_STATE_FIXED: - AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); - - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.25f), - CVector(0.0f, 0.0f, 0.0f)); - - if(m_aWheelTimer[i] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); - break; - - default: - if(Abs(fwdSpeed) > 0.5f) - AddWheelDirtAndWater(&m_aWheelColPoints[i], drawParticles); - if(m_aWheelSkidmarkBloody[i] && m_aWheelTimer[i] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + i, m_aWheelColPoints[i].point, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[i], &m_aWheelSkidmarkBloody[i]); - } - } - } - } - - if(m_aCarNodes[CAR_WHEEL_RM]){ - // assume middle wheels are two units before rear ones - CVector offset = GetForward()*2.0f; - - switch(m_aWheelState[CARWHEEL_REAR_LEFT]){ - // Game has same code three times here - case WHEEL_STATE_SPINNING: - case WHEEL_STATE_SKIDDING: - case WHEEL_STATE_FIXED: - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[CARWHEEL_REAR_LEFT].point + CVector(0.0f, 0.0f, 0.25f) + offset, - CVector(0.0f, 0.0f, 0.0f)); - - if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + CARWHEEL_REAR_LEFT, - m_aWheelColPoints[CARWHEEL_REAR_LEFT].point + offset, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_LEFT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_LEFT]); - break; - } - - switch(m_aWheelState[CARWHEEL_REAR_RIGHT]){ - // Game has same code three times here - case WHEEL_STATE_SPINNING: - case WHEEL_STATE_SKIDDING: - case WHEEL_STATE_FIXED: - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point + CVector(0.0f, 0.0f, 0.25f) + offset, - CVector(0.0f, 0.0f, 0.0f)); - - if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f) - CSkidmarks::RegisterOne((uintptr)this + CARWHEEL_REAR_RIGHT, - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point + offset, - GetForward().x, GetForward().y, - &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_RIGHT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_RIGHT]); - break; - } - } - - - // Rain on roof - if(!CCullZones::CamNoRain() && !CCullZones::PlayerNoRain() && - Abs(fwdSpeed) < 20.0f && CWeather::Rain > 0.02f){ - CColModel *colModel = GetColModel(); - - for(i = 0; i < colModel->numTriangles; i++){ - CVector p1, p2, p3, c; - - colModel->GetTrianglePoint(p1, colModel->triangles[i].a); - p1 = GetMatrix() * p1; - colModel->GetTrianglePoint(p2, colModel->triangles[i].b); - p2 = GetMatrix() * p2; - colModel->GetTrianglePoint(p3, colModel->triangles[i].c); - p3 = GetMatrix() * p3; - c = (p1 + p2 + p3)/3.0f; - - n = 6.0f*CWeather::Rain; - for(j = 0; j <= n; j++) - CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, - c + CVector(CGeneral::GetRandomNumberInRange(-.04f, 0.4f), CGeneral::GetRandomNumberInRange(-.04f, 0.4f), 0.0f), - CVector(0.0f, 0.0f, 0.0f), - nil, 0.0f, 0, 0, CGeneral::GetRandomNumber() & 1); - } - } - - AddDamagedVehicleParticles(); - - // Exhaust smoke - if(bEngineOn && fwdSpeed < 90.0f){ - CVector exhaustPos = mi->m_positions[CAR_POS_EXHAUST]; - CVector pos1, pos2, dir; - - if(exhaustPos != CVector(0.0f, 0.0f, 0.0f)){ - dir.z = 0.0f; - if(fwdSpeed < 10.0f){ - CVector steerFwd(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f); - steerFwd = Multiply3x3(GetMatrix(), steerFwd); - float r = CGeneral::GetRandomNumberInRange(-0.06f, -0.03f); - dir.x = steerFwd.x * r; - dir.y = steerFwd.y * r; - }else{ - dir.x = m_vecMoveSpeed.x; - dir.y = m_vecMoveSpeed.y; - } - - bool dblExhaust = false; - pos1 = GetMatrix() * exhaustPos; - if(pHandling->Flags & HANDLING_DBL_EXHAUST){ - dblExhaust = true; - pos2 = exhaustPos; - pos2.x = -pos2.x; - pos2 = GetMatrix() * pos2; - } - - n = 4.0f*m_fGasPedal; - if(dblExhaust) - for(i = 0; i <= n; i++){ - CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos1, dir); - CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos2, dir); - } - else - for(i = 0; i <= n; i++) - CParticle::AddParticle(PARTICLE_EXHAUST_FUMES, pos1, dir); - } - } - - - // Siren and taxi lights - switch(GetModelIndex()){ - case MI_FIRETRUCK: - case MI_AMBULAN: - case MI_POLICE: - case MI_ENFORCER: - if(m_bSirenOrAlarm){ - CVector pos1, pos2; - uint8 r1, g1, b1; - uint8 r2, g2, b2; - uint8 r, g, b; - - switch(GetModelIndex()){ - case MI_FIRETRUCK: - pos1 = CVector(1.1f, 1.7f, 2.0f); - pos2 = CVector(-1.1f, 1.7f, 2.0f); - r1 = 255; g1 = 0; b1 = 0; - r2 = 255; g2 = 255; b2 = 0; - break; - case MI_AMBULAN: - pos1 = CVector(1.1f, 0.9f, 1.6f); - pos2 = CVector(-1.1f, 0.9f, 1.6f); - r1 = 255; g1 = 0; b1 = 0; - r2 = 255; g2 = 255; b2 = 255; - break; - case MI_POLICE: - pos1 = CVector(0.7f, -0.4f, 1.0f); - pos2 = CVector(-0.7f, -0.4f, 1.0f); - r1 = 255; g1 = 0; b1 = 0; - r2 = 0; g2 = 0; b2 = 255; - break; - case MI_ENFORCER: - pos1 = CVector(1.1f, 0.8f, 1.2f); - pos2 = CVector(-1.1f, 0.8f, 1.2f); - r1 = 255; g1 = 0; b1 = 0; - r2 = 0; g2 = 0; b2 = 255; - break; - } - - uint32 t = CTimer::GetTimeInMilliseconds() & 0x3FF; // 1023 - if(t < 512){ - r = r1/6; - g = g1/6; - b = b1/6; - }else{ - r = r2/6; - g = g2/6; - b = b2/6; - } - - t = CTimer::GetTimeInMilliseconds() & 0x1FF; // 511 - if(t < 100){ - float f = t/100.0f; - r *= f; - g *= f; - b *= f; - }else if(t > 412){ - float f = (512-t)/100.0f; - r *= f; - g *= f; - b *= f; - } - - CVector pos = GetPosition(); - float angle = (CTimer::GetTimeInMilliseconds() & 0x3FF)*TWOPI/0x3FF; - float s = 8.0f*Sin(angle); - float c = 8.0f*Cos(angle); - CShadows::StoreCarLightShadow(this, (uintptr)this + 21, gpShadowHeadLightsTex, - &pos, c, s, s, -c, r, g, b, 8.0f); - - CPointLights::AddLight(CPointLights::LIGHT_POINT, - pos + GetUp()*2.0f, CVector(0.0f, 0.0f, 0.0f), 12.0f, - r*0.02f, g*0.02f, b*0.02f, CPointLights::FOG_NONE, true); - - pos1 = GetMatrix() * pos1; - pos2 = GetMatrix() * pos2; - - for(i = 0; i < 4; i++){ - uint8 sirenTimer = ((CTimer::GetTimeInMilliseconds() + (i<<6))>>8) & 3; - pos = (pos1*i + pos2*(3.0f-i))/3.0f; - - switch(sirenTimer){ - case 0: - CCoronas::RegisterCorona((uintptr)this + 21 + i, - r1, g1, b1, 255, - pos, 0.4f, 50.0f, - CCoronas::TYPE_STAR, - i == 1 ? CCoronas::FLARE_HEADLIGHTS : CCoronas::FLARE_NONE, - CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - break; - case 2: - CCoronas::RegisterCorona((uintptr)this + 21 + i, - r2, g2, b2, 255, - pos, 0.4f, 50.0f, - CCoronas::TYPE_STAR, - CCoronas::FLARE_NONE, - CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - break; - default: - CCoronas::UpdateCoronaCoors((uintptr)this + 21 + i, pos, 50.0f, 0.0f); - break; - } - } - } - break; - - case MI_FBICAR: - if(m_bSirenOrAlarm){ - CVector pos = GetMatrix() * CVector(0.4f, 0.6f, 0.3f); - if(CTimer::GetTimeInMilliseconds() & 0x100 && - DotProduct(GetForward(), GetPosition() - TheCamera.GetPosition()) < 0.0f) - CCoronas::RegisterCorona((uintptr)this + 21, - 0, 0, 255, 255, - pos, 0.4f, 50.0f, - CCoronas::TYPE_STAR, - CCoronas::FLARE_NONE, - CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::UpdateCoronaCoors((uintptr)this + 21, pos, 50.0f, 0.0f); - } - break; - - case MI_TAXI: - case MI_CABBIE: - case MI_BORGNINE: - if(bTaxiLight){ - CVector pos = GetPosition() + GetUp()*0.95f; - CCoronas::RegisterCorona((uintptr)this + 21, - 128, 128, 0, 255, - pos, 0.8f, 50.0f, - CCoronas::TYPE_NORMAL, - CCoronas::FLARE_NONE, - CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - CPointLights::AddLight(CPointLights::LIGHT_POINT, - pos, CVector(0.0f, 0.0f, 0.0f), 10.0f, - 1.0f, 1.0f, 0.5f, CPointLights::FOG_NONE, true); - } - break; - } - - if(GetModelIndex() == MI_RCBANDIT || - GetModelIndex() == MI_DODO || - GetModelIndex() == MI_RHINO) - goto nolights; - - // Turn lights on/off - bool shouldLightsBeOn = - CClock::GetHours() > 20 || - CClock::GetHours() > 19 && CClock::GetMinutes() > (m_randomSeed & 0x3F) || - CClock::GetHours() < 7 || - CClock::GetHours() < 8 && CClock::GetMinutes() < (m_randomSeed & 0x3F) || - m_randomSeed/50000.0f < CWeather::Foggyness || - m_randomSeed/50000.0f < CWeather::WetRoads; - if(shouldLightsBeOn != bLightsOn && m_status != STATUS_WRECKED){ - if(m_status == STATUS_ABANDONED){ - // Turn off lights on abandoned vehicles only when we they're far away - if(bLightsOn && - Abs(TheCamera.GetPosition().x - GetPosition().x) + Abs(TheCamera.GetPosition().y - GetPosition().y) > 100.0f) - bLightsOn = false; - }else - bLightsOn = shouldLightsBeOn; - } - - // Actually render the lights - bool alarmOn = false; - bool alarmOff = false; - if(IsAlarmOn()){ - if(CTimer::GetTimeInMilliseconds() & 0x100) - alarmOn = true; - else - alarmOff = true; - } - if(bEngineOn && bLightsOn || alarmOn || alarmOff){ - CVector lookVector = GetPosition() - TheCamera.GetPosition(); - float camDist = lookVector.Magnitude(); - if(camDist != 0.0f) - lookVector *= 1.0f/camDist; - else - lookVector = CVector(1.0f, 0.0f, 0.0f); - - // 1.0 if directly behind car, -1.0 if in front - // BUG on PC: Abs of DotProduct is taken - float behindness = DotProduct(lookVector, GetForward()); - behindness = clamp(behindness, -1.0f, 1.0f); // shouldn't be necessary - // 0.0 if behind car, PI if in front - // Abs not necessary - float angle = Abs(Acos(behindness)); - - // Headlights - - CVector headLightPos = mi->m_positions[CAR_POS_HEADLIGHTS]; - CVector lightR = GetMatrix() * headLightPos; - CVector lightL = lightR; - lightL -= GetRight()*2.0f*headLightPos.x; - - // Headlight coronas - if(behindness < 0.0f){ - // In front of car - float intensity = -0.5f*behindness + 0.3f; - float size = 1.0f - behindness; - - if(behindness < -0.97f && camDist < 30.0f){ - // Directly in front and not too far away - if(pHandling->Flags & HANDLING_HALOGEN_LIGHTS){ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 6, 150, 150, 195, 255, - lightL, 1.2f, 45.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 7, 150, 150, 195, 255, - lightR, 1.2f, 45.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); - }else{ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 6, 160, 160, 140, 255, - lightL, 1.2f, 45.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 7, 160, 160, 140, 255, - lightR, 1.2f, 45.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_HEADLIGHT, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, angle); - } - } - - if(alarmOff){ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this, 0, 0, 0, 0, - lightL, size, 0.0f, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 1, 0, 0, 0, 0, - lightR, size, 0.0f, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - }else{ - if(pHandling->Flags & HANDLING_HALOGEN_LIGHTS){ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this, 190*intensity, 190*intensity, 255*intensity, 255, - lightL, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 1, 190*intensity, 190*intensity, 255*intensity, 255, - lightR, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - }else{ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this, 210*intensity, 210*intensity, 195*intensity, 255, - lightL, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 1, 210*intensity, 210*intensity, 195*intensity, 255, - lightR, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - } - } - }else{ - // Behind car - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this, lightL, 50.0f*TheCamera.LODDistMultiplier, angle); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 1, lightR, 50.0f*TheCamera.LODDistMultiplier, angle); - } - - // bright lights - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK && !bNoBrightHeadLights) - CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->FrontLights + 4); - if(Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK && !bNoBrightHeadLights) - CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->FrontLights + 4); - - // Taillights - - CVector tailLightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; - lightR = GetMatrix() * tailLightPos; - lightL = lightR; - lightL -= GetRight()*2.0f*tailLightPos.x; - - // Taillight coronas - if(behindness > 0.0f){ - // Behind car - float intensity = 0.4f*behindness + 0.4; - float size = (behindness + 1.0f)/2.0f; - - if(m_fGasPedal < 0.0f){ - // reversing - intensity += 0.4f; - size += 0.3f; - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 2, 128*intensity, 128*intensity, 128*intensity, 255, - lightL, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 3, 128*intensity, 128*intensity, 128*intensity, 255, - lightR, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - }else{ - if(m_fBrakePedal > 0.0){ - intensity += 0.4f; - size += 0.3f; - } - - if(alarmOff){ - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 2, 0, 0, 0, 0, - lightL, size, 0.0f, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 3, 0, 0, 0, 0, - lightR, size, 0.0f, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - }else{ - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 2, 128*intensity, 0, 0, 255, - lightL, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 3, 128*intensity, 0, 0, 255, - lightR, size, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); - } - } - }else{ - // In front of car - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, angle); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, angle); - } - - // bright lights - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); - - // Light shadows - if(!alarmOff){ - CVector pos = GetPosition(); - CVector2D fwd(GetForward()); - fwd.Normalise(); - float f = headLightPos.y + 6.0f; - pos += CVector(f*fwd.x, f*fwd.y, 2.0f); - - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK || - Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CShadows::StoreCarLightShadow(this, (uintptr)this + 22, gpShadowHeadLightsTex, &pos, - 7.0f*fwd.x, 7.0f*fwd.y, 7.0f*fwd.y, -7.0f*fwd.x, 45, 45, 45, 7.0f); - - f = (tailLightPos.y - 2.5f) - (headLightPos.y + 6.0f); - pos += CVector(f*fwd.x, f*fwd.y, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK || - Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CShadows::StoreCarLightShadow(this, (uintptr)this + 25, gpShadowExplosionTex, &pos, - 3.0f, 0.0f, 0.0f, -3.0f, 35, 0, 0, 4.0f); - } - - if(this == FindPlayerVehicle() && !alarmOff){ - if(Damage.GetLightStatus(VEHLIGHT_FRONT_LEFT) == LIGHT_STATUS_OK || - Damage.GetLightStatus(VEHLIGHT_FRONT_RIGHT) == LIGHT_STATUS_OK) - CPointLights::AddLight(CPointLights::LIGHT_DIRECTIONAL, GetPosition(), GetForward(), - 20.0f, 1.0f, 1.0f, 1.0f, - FindPlayerVehicle()->m_vecMoveSpeed.MagnitudeSqr2D() < sq(0.45f) ? CPointLights::FOG_NORMAL : CPointLights::FOG_NONE, - false); - CVector pos = GetPosition() - 4.0f*GetForward(); - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK || - Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - if(m_fBrakePedal > 0.0f) - CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), - 10.0f, 1.0f, 0.0f, 0.0f, - CPointLights::FOG_NONE, false); - else - CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), - 7.0f, 0.6f, 0.0f, 0.0f, - CPointLights::FOG_NONE, false); - } - }else{ - // Lights off - - if(m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED) - goto nolights; - - CVector lightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; - CVector lightR = GetMatrix() * lightPos; - CVector lightL = lightR; - lightL -= GetRight()*2.0f*lightPos.x; - - if(m_fBrakePedal > 0.0f || m_fGasPedal < 0.0f){ - CVector lookVector = GetPosition() - TheCamera.GetPosition(); - lookVector.Normalise(); - float behindness = DotProduct(lookVector, GetForward()); - if(behindness > 0.0f){ - if(m_fGasPedal < 0.0f){ - // reversing - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 2, 120, 120, 120, 255, - lightL, 1.2f, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 3, 120, 120, 120, 255, - lightR, 1.2f, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 4); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 4); - }else{ - // braking - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 2, 120, 0, 0, 255, - lightL, 1.2f, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::RegisterCorona((uintptr)this + 3, 120, 0, 0, 255, - lightR, 1.2f, 50.0f*TheCamera.LODDistMultiplier, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightL, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CBrightLights::RegisterOne(lightR, GetUp(), GetRight(), GetForward(), pHandling->RearLights + 8); - } - }else{ - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, 0.0f); - } - }else{ - if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 2, lightL, 50.0f*TheCamera.LODDistMultiplier, 0.0f); - if(Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) - CCoronas::UpdateCoronaCoors((uintptr)this + 3, lightR, 50.0f*TheCamera.LODDistMultiplier, 0.0f); - } - } - -nolights: - CShadows::StoreShadowForCar(this); -} - -void -CAutomobile::Render(void) -{ - int i; - CMatrix mat; - CVector pos; - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - - if(GetModelIndex() == MI_RHINO && m_aCarNodes[CAR_BONNET]){ - // Rhino has no bonnet...what are we doing here? - CMatrix m; - CVector p; - m.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BONNET])); - p = m.GetPosition(); - m.SetRotateZ(m_fCarGunLR); - m.Translate(p); - m.UpdateRW(); - } - - CVector contactPoints[4]; // relative to model - CVector contactSpeeds[4]; // speed at contact points - CVector frontWheelFwd = Multiply3x3(GetMatrix(), CVector(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f)); - CVector rearWheelFwd = GetForward(); - for(i = 0; i < 4; i++){ - contactPoints[i] = m_aWheelColPoints[i].point - GetPosition(); - contactSpeeds[i] = GetSpeed(contactPoints[i]); - if(i == CARWHEEL_FRONT_LEFT || i == CARWHEEL_FRONT_RIGHT) - m_aWheelSpeed[i] = ProcessWheelRotation(m_aWheelState[i], frontWheelFwd, contactSpeeds[i], 0.5f*mi->m_wheelScale); - else - m_aWheelSpeed[i] = ProcessWheelRotation(m_aWheelState[i], rearWheelFwd, contactSpeeds[i], 0.5f*mi->m_wheelScale); - m_aWheelRotation[i] += m_aWheelSpeed[i]; - } - - // Rear right wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_REAR_RIGHT]; - if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) - mat.SetRotate(m_aWheelRotation[CARWHEEL_REAR_RIGHT], 0.0f, 0.3f*Sin(m_aWheelRotation[CARWHEEL_REAR_RIGHT])); - else - mat.SetRotateX(m_aWheelRotation[CARWHEEL_REAR_RIGHT]); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RB])); - - // Rear left wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_REAR_LEFT]; - if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) - mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI+0.3f*Sin(-m_aWheelRotation[CARWHEEL_REAR_LEFT])); - else - mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LB])); - - // Mid right wheel - if(m_aCarNodes[CAR_WHEEL_RM]){ - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_REAR_RIGHT]; - if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) - mat.SetRotate(m_aWheelRotation[CARWHEEL_REAR_RIGHT], 0.0f, 0.3f*Sin(m_aWheelRotation[CARWHEEL_REAR_RIGHT])); - else - mat.SetRotateX(m_aWheelRotation[CARWHEEL_REAR_RIGHT]); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RM])); - } - - // Mid left wheel - if(m_aCarNodes[CAR_WHEEL_LM]){ - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_REAR_LEFT]; - if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) - mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI+0.3f*Sin(-m_aWheelRotation[CARWHEEL_REAR_LEFT])); - else - mat.SetRotate(-m_aWheelRotation[CARWHEEL_REAR_LEFT], 0.0f, PI); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LM])); - } - - if(GetModelIndex() == MI_DODO){ - // Front wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; - if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) - mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle+0.3f*Sin(m_aWheelRotation[CARWHEEL_FRONT_RIGHT])); - else - mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); - - // Rotate propeller - if(m_aCarNodes[CAR_WINDSCREEN]){ - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WINDSCREEN])); - pos = mat.GetPosition(); - mat.SetRotateY(m_fPropellerRotation); - mat.Translate(pos); - mat.UpdateRW(); - - m_fPropellerRotation += m_fGasPedal != 0.0f ? TWOPI/13.0f : TWOPI/26.0f; - if(m_fPropellerRotation > TWOPI) - m_fPropellerRotation -= TWOPI; - } - - // Rudder - if(Damage.GetDoorStatus(DOOR_BOOT) != DOOR_STATUS_MISSING && m_aCarNodes[CAR_BOOT]){ - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BOOT])); - pos = mat.GetPosition(); - mat.SetRotate(0.0f, 0.0f, -m_fSteerAngle); - mat.Rotate(0.0f, Sin(m_fSteerAngle)*DEGTORAD(22.0f), 0.0f); - mat.Translate(pos); - mat.UpdateRW(); - } - - ProcessSwingingDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT); - ProcessSwingingDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT); - }else if(GetModelIndex() == MI_RHINO){ - // Front right wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; - // no damaged wheels or steering - mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, 0.0f); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); - - // Front left wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_FRONT_LEFT]; - // no damaged wheels or steering - mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LF])); - }else{ - // Front right wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; - if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) - mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle+0.3f*Sin(m_aWheelRotation[CARWHEEL_FRONT_RIGHT])); - else - mat.SetRotate(m_aWheelRotation[CARWHEEL_FRONT_RIGHT], 0.0f, m_fSteerAngle); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_RF])); - - // Front left wheel - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); - pos.x = mat.GetPosition().x; - pos.y = mat.GetPosition().y; - pos.z = m_aWheelPosition[CARWHEEL_FRONT_LEFT]; - if(Damage.GetWheelStatus(CARWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) - mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI+m_fSteerAngle+0.3f*Sin(-m_aWheelRotation[CARWHEEL_FRONT_LEFT])); - else - mat.SetRotate(-m_aWheelRotation[CARWHEEL_FRONT_LEFT], 0.0f, PI+m_fSteerAngle); - mat.Scale(mi->m_wheelScale); - mat.Translate(pos); - mat.UpdateRW(); - if(CVehicle::bWheelsOnlyCheat) - RpAtomicRender((RpAtomic*)GetFirstObject(m_aCarNodes[CAR_WHEEL_LF])); - - ProcessSwingingDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT); - ProcessSwingingDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT); - ProcessSwingingDoor(CAR_DOOR_LR, DOOR_REAR_LEFT); - ProcessSwingingDoor(CAR_DOOR_RR, DOOR_REAR_RIGHT); - ProcessSwingingDoor(CAR_BONNET, DOOR_BONNET); - ProcessSwingingDoor(CAR_BOOT, DOOR_BOOT); - - mi->SetVehicleColour(m_currentColour1, m_currentColour2); - } - - if(!CVehicle::bWheelsOnlyCheat) - CEntity::Render(); -} - -int32 -CAutomobile::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints) -{ - int i; - CColModel *colModel; - - if(m_status != STATUS_SIMPLE) - bVehicleColProcessed = true; - - if(bUsingSpecialColModel) - colModel = &CWorld::Players[CWorld::PlayerInFocus].m_ColModel; - else - colModel = GetColModel(); - - int numWheelCollisions = 0; - float prevRatios[4] = { 0.0f, 0.0f, 0.0f, 0.0f}; - for(i = 0; i < 4; i++) - prevRatios[i] = m_aSuspensionSpringRatio[i]; - - int numCollisions = CCollision::ProcessColModels(GetMatrix(), *colModel, - ent->GetMatrix(), *ent->GetColModel(), - colpoints, - m_aWheelColPoints, m_aSuspensionSpringRatio); - - // m_aSuspensionSpringRatio are now set to the point where the tyre touches ground. - // In ProcessControl these will be re-normalized to ignore the tyre radius. - - if(field_EF || m_phy_flagA80 || - GetModelIndex() == MI_DODO && (ent->IsPed() || ent->IsVehicle())){ - // don't do line collision - for(i = 0; i < 4; i++) - m_aSuspensionSpringRatio[i] = prevRatios[i]; - }else{ - for(i = 0; i < 4; i++) - if(m_aSuspensionSpringRatio[i] < 1.0f && m_aSuspensionSpringRatio[i] < prevRatios[i]){ - numWheelCollisions++; - - // wheel is touching a physical - if(ent->IsVehicle() || ent->IsObject()){ - CPhysical *phys = (CPhysical*)ent; - - m_aGroundPhysical[i] = phys; - phys->RegisterReference((CEntity**)&m_aGroundPhysical[i]); - m_aGroundOffset[i] = m_aWheelColPoints[i].point - phys->GetPosition(); - - if(phys->GetModelIndex() == MI_BODYCAST && m_status == STATUS_PLAYER){ - // damage body cast - float speed = m_vecMoveSpeed.MagnitudeSqr(); - if(speed > 0.1f){ - CObject::nBodyCastHealth -= 0.1f*m_fMass*speed; - DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_BODYCAST_HIT, 0.0f); - } - - // move body cast - if(phys->bIsStatic){ - phys->bIsStatic = false; - phys->m_nStaticFrames = 0; - phys->ApplyMoveForce(m_vecMoveSpeed / speed); - phys->AddToMovingList(); - } - } - } - - m_nSurfaceTouched = m_aWheelColPoints[i].surfaceB; - if(ent->IsBuilding()) - m_pCurGroundEntity = ent; - } - } - - if(numCollisions > 0 || numWheelCollisions > 0){ - AddCollisionRecord(ent); - if(!ent->IsBuilding()) - ((CPhysical*)ent)->AddCollisionRecord(this); - - if(numCollisions > 0) - if(ent->IsBuilding() || - ent->IsObject() && ((CPhysical*)ent)->bInfiniteMass) - bHasHitWall = true; - } - - return numCollisions; -} - -static int16 nLastControlInput; -static float fMouseCentreRange = 0.35f; -static float fMouseSteerSens = -0.0035f; -static float fMouseCentreMult = 0.975f; - -void -CAutomobile::ProcessControlInputs(uint8 pad) -{ - float speed = DotProduct(m_vecMoveSpeed, GetForward()); - - if(CPad::GetPad(pad)->GetExitVehicle()) - bIsHandbrakeOn = true; - else - bIsHandbrakeOn = !!CPad::GetPad(pad)->GetHandBrake(); - - // Steer left/right - if(CCamera::m_bUseMouse3rdPerson && !CVehicle::m_bDisableMouseSteering){ - if(CPad::GetPad(pad)->GetMouseX() != 0.0f){ - m_fSteerRatio += fMouseSteerSens*CPad::GetPad(pad)->GetMouseX(); - nLastControlInput = 2; - if(Abs(m_fSteerRatio) < fMouseCentreRange) - m_fSteerRatio *= Pow(fMouseCentreMult, CTimer::GetTimeStep()); - }else if(CPad::GetPad(pad)->GetSteeringLeftRight() || nLastControlInput != 2){ - // mouse hasn't move, steer with pad like below - m_fSteerRatio += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteerRatio)* - 0.2f*CTimer::GetTimeStep(); - nLastControlInput = 0; - } - }else{ - m_fSteerRatio += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteerRatio)* - 0.2f*CTimer::GetTimeStep(); - nLastControlInput = 0; - } - m_fSteerRatio = clamp(m_fSteerRatio, -1.0f, 1.0f); - - // Accelerate/Brake - float acceleration = (CPad::GetPad(pad)->GetAccelerate() - CPad::GetPad(pad)->GetBrake())/255.0f; - if(GetModelIndex() == MI_DODO && acceleration < 0.0f) - acceleration *= 0.3f; - if(Abs(speed) < 0.01f){ - // standing still, go into direction we want - m_fGasPedal = acceleration; - m_fBrakePedal = 0.0f; - }else{ -#if 1 - // simpler than the code below - if(speed * acceleration < 0.0f){ - // if opposite directions, have to brake first - m_fGasPedal = 0.0f; - m_fBrakePedal = Abs(acceleration); - }else{ - // accelerating in same direction we were already going - m_fGasPedal = acceleration; - m_fBrakePedal = 0.0f; - } -#else - if(speed < 0.0f){ - // moving backwards currently - if(acceleration < 0.0f){ - // still go backwards - m_fGasPedal = acceleration; - m_fBrakePedal = 0.0f; - }else{ - // want to go forwards, so brake - m_fGasPedal = 0.0f; - m_fBrakePedal = acceleration; - } - }else{ - // moving forwards currently - if(acceleration < 0.0f){ - // want to go backwards, so brake - m_fGasPedal = 0.0f; - m_fBrakePedal = -acceleration; - }else{ - // still go forwards - m_fGasPedal = acceleration; - m_fBrakePedal = 0.0f; - } - } -#endif - } - - // Actually turn wheels - static float fValue; // why static? - if(m_fSteerRatio < 0.0f) - fValue = -sq(m_fSteerRatio); - else - fValue = sq(m_fSteerRatio); - m_fSteerAngle = DEGTORAD(pHandling->fSteeringLock) * fValue; - - if(bComedyControls){ - int rnd = CGeneral::GetRandomNumber() % 10; - switch(m_comedyControlState){ - case 0: - if(rnd < 2) - m_comedyControlState = 1; - else if(rnd < 4) - m_comedyControlState = 2; - break; - case 1: - m_fSteerAngle += 0.05f; - if(rnd < 2) - m_comedyControlState = 0; - break; - case 2: - m_fSteerAngle -= 0.05f; - if(rnd < 2) - m_comedyControlState = 0; - break; - } - }else - m_comedyControlState = 0; - - // Brake if player isn't in control - // BUG: game always uses pad 0 here - if(CPad::GetPad(pad)->DisablePlayerControls){ - m_fBrakePedal = 1.0f; - bIsHandbrakeOn = true; - m_fGasPedal = 0.0f; - - FindPlayerPed()->KeepAreaAroundPlayerClear(); - - // slow down car immediately - speed = m_vecMoveSpeed.Magnitude(); - if(speed > 0.28f) - m_vecMoveSpeed *= 0.28f/speed; - } -} - -void -CAutomobile::FireTruckControl(void) -{ - if(this == FindPlayerVehicle()){ - if(!CPad::GetPad(0)->GetWeapon()) - return; - m_fCarGunLR += CPad::GetPad(0)->GetCarGunLeftRight()*0.00025f*CTimer::GetTimeStep(); - m_fCarGunUD += CPad::GetPad(0)->GetCarGunUpDown()*0.0001f*CTimer::GetTimeStep(); - m_fCarGunUD = clamp(m_fCarGunUD, 0.05f, 0.3f); - - CVector cannonPos(0.0f, 1.5f, 1.9f); - cannonPos = GetMatrix() * cannonPos; - CVector cannonDir( - Sin(m_fCarGunLR) * Cos(m_fCarGunUD), - Cos(m_fCarGunLR) * Cos(m_fCarGunUD), - Sin(m_fCarGunUD)); - cannonDir = Multiply3x3(GetMatrix(), cannonDir); - cannonDir.z += (CGeneral::GetRandomNumber()&0xF)/1000.0f; - CWaterCannons::UpdateOne((uintptr)this, &cannonPos, &cannonDir); - }else if(m_status == STATUS_PHYSICS){ - CFire *fire = gFireManager.FindFurthestFire_NeverMindFireMen(GetPosition(), 10.0f, 35.0f); - if(fire == nil) - return; - - // Target cannon onto fire - float targetAngle = CGeneral::GetATanOfXY(fire->m_vecPos.x-GetPosition().x, fire->m_vecPos.y-GetPosition().y); - float fwdAngle = CGeneral::GetATanOfXY(GetForward().x, GetForward().y); - float targetCannonAngle = fwdAngle - targetAngle; - float angleDelta = CTimer::GetTimeStep()*0.01f; - float cannonDelta = targetCannonAngle - m_fCarGunLR; - while(cannonDelta < PI) cannonDelta += TWOPI; - while(cannonDelta > PI) cannonDelta -= TWOPI; - if(Abs(cannonDelta) < angleDelta) - m_fCarGunLR = targetCannonAngle; - else if(cannonDelta > 0.0f) - m_fCarGunLR += angleDelta; - else - m_fCarGunLR -= angleDelta; - - // Go up and down a bit - float upDown = Sin((float)(CTimer::GetTimeInMilliseconds() & 0xFFF)/0x1000 * TWOPI); - m_fCarGunUD = 0.2f + 0.2f*upDown; - - // Spray water every once in a while - if((CTimer::GetTimeInMilliseconds()>>10) & 3){ - CVector cannonPos(0.0f, 0.0f, 2.2f); // different position than player's firetruck! - cannonPos = GetMatrix() * cannonPos; - CVector cannonDir( - Sin(m_fCarGunLR) * Cos(m_fCarGunUD), - Cos(m_fCarGunLR) * Cos(m_fCarGunUD), - Sin(m_fCarGunUD)); - cannonDir = Multiply3x3(GetMatrix(), cannonDir); - cannonDir.z += (CGeneral::GetRandomNumber()&0xF)/1000.0f; - CWaterCannons::UpdateOne((uintptr)this, &cannonPos, &cannonDir); - } - } -} - -void -CAutomobile::TankControl(void) -{ - int i; - - // These coords are 1 unit higher then they should be relative to model center - CVector turrentBase(0.0f, -1.394f, 2.296f); - CVector gunEnd(0.0f, 1.813f, 2.979f); - CVector baseToEnd = gunEnd - turrentBase; - - if(this != FindPlayerVehicle()) - return; - if(CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING) - return; - - // Rotate turret - float prevAngle = m_fCarGunLR; - m_fCarGunLR -= CPad::GetPad(0)->GetCarGunLeftRight() * 0.00015f * CTimer::GetTimeStep(); - if(m_fCarGunLR < 0.0f) - m_fCarGunLR += TWOPI; - if(m_fCarGunLR > TWOPI) - m_fCarGunLR -= TWOPI; - if(m_fCarGunLR != prevAngle) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_TANK_TURRET_ROTATE, Abs(m_fCarGunLR - prevAngle)); - - // Shoot - if(CPad::GetPad(0)->CarGunJustDown() && - CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeTankShotGun + 800){ - CWorld::Players[CWorld::PlayerInFocus].m_nTimeTankShotGun = CTimer::GetTimeInMilliseconds(); - - // more like -sin(angle), cos(angle), i.e. rotated (0,1,0) - CVector turretDir = CVector(Sin(-m_fCarGunLR), Cos(-m_fCarGunLR), 0.0f); - turretDir = Multiply3x3(GetMatrix(), turretDir); - - float c = Cos(m_fCarGunLR); - float s = Sin(m_fCarGunLR); - CVector rotatedEnd( - c*baseToEnd.x - s*baseToEnd.y, - s*baseToEnd.x + c*baseToEnd.y, - baseToEnd.z - 1.0f); // correct offset here - rotatedEnd += turrentBase; - - CVector point1 = GetMatrix() * rotatedEnd; - CVector point2 = point1 + 60.0f*turretDir; - m_vecMoveSpeed -= 0.06f*turretDir; - m_vecMoveSpeed.z += 0.05f; - - CWeapon::DoTankDoomAiming(FindPlayerVehicle(), FindPlayerPed(), &point1, &point2); - CColPoint colpoint; - CEntity *entity = nil; - CWorld::ProcessLineOfSight(point1, point2, colpoint, entity, true, true, true, true, true, true, false); - if(entity) - point2 = colpoint.point - 0.04f*(colpoint.point - point1); - - CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_TANK_GRENADE, point2, 0); - - // Add particles on the way to the explosion; - float shotDist = (point2 - point1).Magnitude(); - int n = shotDist/4.0f; - RwRGBA black = { 0, 0, 0, 0 }; - for(i = 0; i < n; i++){ - float f = (float)i/n; - CParticle::AddParticle(PARTICLE_HELI_DUST, - point1 + f*(point2 - point1), - CVector(0.0f, 0.0f, 0.0f), - nil, 0.1f, black); - } - - // More particles - CVector shotDir = point2 - point1; - shotDir.Normalise(); - for(i = 0; i < 15; i++){ - float f = i/15.0f; - CParticle::AddParticle(PARTICLE_GUNSMOKE2, point1, - shotDir*CGeneral::GetRandomNumberInRange(0.3f, 1.0f)*f, - nil, CGeneral::GetRandomNumberInRange(0.5f, 1.0f)*f, black); - } - - // And some gun flashes near the gun - CVector flashPos = point1; - CVector nullDir(0.0f, 0.0f, 0.0f); - int lifeSpan = 250; - if(m_vecMoveSpeed.Magnitude() > 0.08f){ - lifeSpan = 125; - flashPos.x += 0.5f*m_vecMoveSpeed.x; - flashPos.y += 0.5f*m_vecMoveSpeed.y; - } - CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.4f, black, 0, 0, 0, lifeSpan); - flashPos += 0.3f*shotDir; - CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.2f, black, 0, 0, 0, lifeSpan); - flashPos += 0.1f*shotDir; - CParticle::AddParticle(PARTICLE_GUNFLASH, flashPos, nullDir, nil, 0.15f, black, 0, 0, 0, lifeSpan); - } - - // Actually update turret node - if(m_aCarNodes[CAR_WINDSCREEN]){ - CMatrix mat; - CVector pos; - - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WINDSCREEN])); - pos = mat.GetPosition(); - mat.SetRotateZ(m_fCarGunLR); - mat.Translate(pos); - mat.UpdateRW(); - } -} - -void -CAutomobile::HydraulicControl(void) -{ - int i; - float wheelPositions[4]; - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - CColModel *normalColModel = mi->GetColModel(); - float wheelRadius = 0.5f*mi->m_wheelScale; - CPlayerInfo *playerInfo = &CWorld::Players[CWorld::PlayerInFocus]; - CColModel *specialColModel = &playerInfo->m_ColModel; - - if(m_status != STATUS_PLAYER){ - // reset hydraulics for non-player cars - - if(!bUsingSpecialColModel) - return; - if(specialColModel != nil) // this is always true - for(i = 0; i < 4; i++) - wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - for(i = 0; i < 4; i++){ - m_aSuspensionSpringLength[i] = pHandling->fSuspensionUpperLimit - pHandling->fSuspensionLowerLimit; - m_aSuspensionLineLength[i] = normalColModel->lines[i].p0.z - normalColModel->lines[i].p1.z; - m_aSuspensionSpringRatio[i] = (normalColModel->lines[i].p0.z - wheelPositions[i]) / m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - - if(m_hydraulicState == 0) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); - else if(m_hydraulicState >= 100) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - - if(playerInfo->m_pVehicleEx == this) - playerInfo->m_pVehicleEx = nil; - bUsingSpecialColModel = false; - m_hydraulicState = 0; - return; - } - - // Player car - - float normalUpperLimit = pHandling->fSuspensionUpperLimit; - float normalLowerLimit = pHandling->fSuspensionLowerLimit; - float normalSpringLength = normalUpperLimit - normalLowerLimit; - float extendedUpperLimit = normalUpperLimit - 0.2f; - float extendedLowerLimit = normalLowerLimit - 0.2f; - float extendedSpringLength = extendedUpperLimit - extendedLowerLimit; - - if(!bUsingSpecialColModel){ - // Init special col model - - if(playerInfo->m_pVehicleEx && playerInfo->m_pVehicleEx == this) - playerInfo->m_pVehicleEx->bUsingSpecialColModel = false; - playerInfo->m_pVehicleEx = this; - playerInfo->m_ColModel = *normalColModel; - bUsingSpecialColModel = true; - specialColModel = &playerInfo->m_ColModel; - - if(m_fVelocityChangeForAudio > 0.1f) - m_hydraulicState = 20; - else{ - m_hydraulicState = 0; - normalUpperLimit += -0.12f; - normalSpringLength = normalUpperLimit - (normalLowerLimit+0.14f); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - } - - // Setup suspension - float normalLineLength = normalSpringLength + wheelRadius; - CVector pos; - for(i = 0; i < 4; i++){ - wheelPositions[i] = normalColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - mi->GetWheelPosn(i, pos); - pos.z += normalUpperLimit; - specialColModel->lines[i].p0 = pos; - pos.z -= normalLineLength; - specialColModel->lines[i].p1 = pos; - m_aSuspensionSpringLength[i] = normalSpringLength; - m_aSuspensionLineLength[i] = normalLineLength; - - if(m_aSuspensionSpringRatio[i] < 1.0f){ - m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - } - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - - // Adjust col model - mi->GetWheelPosn(0, pos); - float minz = pos.z + extendedLowerLimit - wheelRadius; - if(minz < specialColModel->boundingBox.min.z) - specialColModel->boundingBox.min.z = minz; - float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); - if(specialColModel->boundingSphere.radius < radius) - specialColModel->boundingSphere.radius = radius; - - } - - if(playerInfo->m_WBState != WBSTATE_PLAYING) - return; - - bool setPrevRatio = false; - if(m_hydraulicState < 20 && m_fVelocityChangeForAudio > 0.2f){ - if(m_hydraulicState == 0){ - m_hydraulicState = 20; - for(i = 0; i < 4; i++) - m_aWheelPosition[i] -= 0.06f; - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); - setPrevRatio = true; - }else{ - m_hydraulicState++; - } - }else if(m_hydraulicState != 0){ // must always be true - if(m_hydraulicState < 21 && m_fVelocityChangeForAudio < 0.1f){ - m_hydraulicState--; - if(m_hydraulicState == 0) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - } - } - - if(CPad::GetPad(0)->HornJustDown()){ - // Switch between normal and extended - - if(m_hydraulicState < 100) - m_hydraulicState = 100; - else{ - if(m_fVelocityChangeForAudio > 0.1f) - m_hydraulicState = 20; - else - m_hydraulicState = 0; - } - - if(m_hydraulicState < 100){ - if(m_hydraulicState == 0){ - normalUpperLimit += -0.12f; - normalLowerLimit += 0.14f; - normalSpringLength = normalUpperLimit - normalLowerLimit; - } - - // Reset suspension to normal - float normalLineLength = normalSpringLength + wheelRadius; - CVector pos; - for(i = 0; i < 4; i++){ - wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - mi->GetWheelPosn(i, pos); - pos.z += normalUpperLimit; - specialColModel->lines[i].p0 = pos; - pos.z -= normalLineLength; - specialColModel->lines[i].p1 = pos; - m_aSuspensionSpringLength[i] = normalSpringLength; - m_aSuspensionLineLength[i] = normalLineLength; - - if(m_aSuspensionSpringRatio[i] < 1.0f){ - m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - } - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - }else{ - // Reset suspension to extended - float extendedLineLength = extendedSpringLength + wheelRadius; - CVector pos; - for(i = 0; i < 4; i++){ - wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - mi->GetWheelPosn(i, pos); - pos.z += extendedUpperLimit; - specialColModel->lines[i].p0 = pos; - pos.z -= extendedLineLength; - specialColModel->lines[i].p1 = pos; - m_aSuspensionSpringLength[i] = extendedSpringLength; - m_aSuspensionLineLength[i] = extendedLineLength; - - if(m_aSuspensionSpringRatio[i] < 1.0f){ - m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - - setPrevRatio = true; - m_aWheelPosition[i] -= 0.05f; - } - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - } - }else{ - float suspChange[4]; - float maxDelta = 0.0f; - float rear = CPad::GetPad(0)->GetCarGunUpDown()/128.0f; - float front = -rear; - float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; - float left = -right; - suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); - suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); - suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); - suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); - - if(m_hydraulicState < 100){ - // Lowered, move wheels up - - if(m_hydraulicState == 0){ - normalUpperLimit += -0.12f; - normalLowerLimit += 0.14f; - normalSpringLength = normalUpperLimit - normalLowerLimit; - } - - // Set suspension - CVector pos; - for(i = 0; i < 4; i++){ - if(suspChange[i] > 1.0f) - suspChange[i] = 1.0f; - - float oldZ = specialColModel->lines[i].p1.z; - float upperLimit = suspChange[i]*(extendedUpperLimit-normalUpperLimit) + normalUpperLimit; - float springLength = suspChange[i]*(extendedSpringLength-normalSpringLength) + normalSpringLength; - float lineLength = springLength + wheelRadius; - - wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - mi->GetWheelPosn(i, pos); - pos.z += upperLimit; - specialColModel->lines[i].p0 = pos; - pos.z -= lineLength; - if(Abs(pos.z - specialColModel->lines[i].p1.z) > Abs(maxDelta)) - maxDelta = pos.z - specialColModel->lines[i].p1.z; - specialColModel->lines[i].p1 = pos; - m_aSuspensionSpringLength[i] = springLength; - m_aSuspensionLineLength[i] = lineLength; - - if(m_aSuspensionSpringRatio[i] < 1.0f){ - m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - m_aWheelPosition[i] -= (oldZ - specialColModel->lines[i].p1.z)*0.3f; - } - } - }else{ - if(m_hydraulicState < 104){ - m_hydraulicState++; - for(i = 0; i < 4; i++) - m_aWheelPosition[i] -= 0.1f; - } - - if(m_fVelocityChangeForAudio < 0.1f){ - normalUpperLimit += -0.12f; - normalLowerLimit += 0.14f; - normalSpringLength = normalUpperLimit - normalLowerLimit; - } - - // Set suspension - CVector pos; - for(i = 0; i < 4; i++){ - if(suspChange[i] > 1.0f) - suspChange[i] = 1.0f; - - float upperLimit = suspChange[i]*(normalUpperLimit-extendedUpperLimit) + extendedUpperLimit; - float springLength = suspChange[i]*(normalSpringLength-extendedSpringLength) + extendedSpringLength; - float lineLength = springLength + wheelRadius; - - wheelPositions[i] = specialColModel->lines[i].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i]; - mi->GetWheelPosn(i, pos); - pos.z += upperLimit; - specialColModel->lines[i].p0 = pos; - pos.z -= lineLength; - if(Abs(pos.z - specialColModel->lines[i].p1.z) > Abs(maxDelta)) - maxDelta = pos.z - specialColModel->lines[i].p1.z; - specialColModel->lines[i].p1 = pos; - m_aSuspensionSpringLength[i] = springLength; - m_aSuspensionLineLength[i] = lineLength; - - if(m_aSuspensionSpringRatio[i] < 1.0f){ - m_aSuspensionSpringRatio[i] = (specialColModel->lines[i].p0.z - wheelPositions[i])/m_aSuspensionLineLength[i]; - if(m_aSuspensionSpringRatio[i] > 1.0f) - m_aSuspensionSpringRatio[i] = 1.0f; - } - } - } - - float limitDiff = extendedLowerLimit - normalLowerLimit; - if(limitDiff != 0.0f && Abs(maxDelta/limitDiff) > 0.01f){ - float f = (maxDelta + limitDiff)/2.0f/limitDiff; - f = clamp(f, 0.0f, 1.0f); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_3, f); - if(f < 0.4f || f > 0.6f) - setPrevRatio = true; - if(f < 0.25f) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_2, 0.0f); - else if(f > 0.75f) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_1, 0.0f); - } - } - - if(setPrevRatio) - for(i = 0; i < 4; i++){ - // wheel radius in relation to suspension line - float wheelRadius = 1.0f - m_aSuspensionSpringLength[i]/m_aSuspensionLineLength[i]; - m_aSuspensionSpringRatioPrev[i] = (m_aSuspensionSpringRatio[i]-wheelRadius)/(1.0f-wheelRadius); - } -} - -void -CAutomobile::ProcessBuoyancy(void) -{ - int i; - CVector impulse, point; - - if(mod_Buoyancy.ProcessBuoyancy(this, m_fBuoyancy, &point, &impulse)){ - m_flagD8 = true; - ApplyMoveForce(impulse); - ApplyTurnForce(impulse, point); - - CVector initialSpeed = m_vecMoveSpeed; - float timeStep = Max(CTimer::GetTimeStep(), 0.01f); - float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); - float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); - m_vecMoveSpeed *= waterResistance; - m_vecTurnSpeed *= waterResistance; - - if(impulseRatio > 0.5f){ - bIsInWater = true; - if(m_vecMoveSpeed.z < -0.1f) - m_vecMoveSpeed.z = -0.1f; - - if(pDriver){ - pDriver->bIsInWater = true; - if(pDriver->IsPlayer() || !bWaterTight) - pDriver->InflictDamage(nil, WEAPONTYPE_WATER, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); - } - for(i = 0; i < m_nNumMaxPassengers; i++) - if(pPassengers[i]){ - pPassengers[i]->bIsInWater = true; - if(pPassengers[i]->IsPlayer() || !bWaterTight) - pPassengers[i]->InflictDamage(nil, WEAPONTYPE_WATER, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); - } - }else - bIsInWater = false; - - static uint32 nGenerateRaindrops = 0; - static uint32 nGenerateWaterCircles = 0; - - if(initialSpeed.z < -0.3f && impulse.z > 0.3f){ - RwRGBA color; - color.red = (0.5f * CTimeCycle::GetDirectionalRed() + CTimeCycle::GetAmbientRed())*0.45f*255; - color.green = (0.5f * CTimeCycle::GetDirectionalGreen() + CTimeCycle::GetAmbientGreen())*0.45f*255; - color.blue = (0.5f * CTimeCycle::GetDirectionalBlue() + CTimeCycle::GetAmbientBlue())*0.45f*255; - color.alpha = CGeneral::GetRandomNumberInRange(0, 32) + 128; - CParticleObject::AddObject(POBJECT_CAR_WATER_SPLASH, GetPosition(), - CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.15f, 0.3f)), - 0.0f, 75, color, true); - - nGenerateRaindrops = CTimer::GetTimeInMilliseconds() + 300; - nGenerateWaterCircles = CTimer::GetTimeInMilliseconds() + 60; - if(m_vecMoveSpeed.z < -0.2f) - m_vecMoveSpeed.z = -0.2f; - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WATER_FALL, 0.0f); - } - - if(nGenerateWaterCircles > 0 && nGenerateWaterCircles < CTimer::GetTimeInMilliseconds()){ - CVector pos = GetPosition(); - float waterLevel = 0.0f; - if(CWaterLevel::GetWaterLevel(pos.x, pos.y, pos.z, &waterLevel, false)) - pos.z = waterLevel; - static RwRGBA black; - if(pos.z != 0.0f){ - nGenerateWaterCircles = 0; - pos.z += 1.0f; - for(i = 0; i < 4; i++){ - CVector p = pos; - p.x += CGeneral::GetRandomNumberInRange(-2.5f, 2.5f); - p.y += CGeneral::GetRandomNumberInRange(-2.5f, 2.5f); - CParticle::AddParticle(PARTICLE_RAIN_SPLASH_BIGGROW, - p, CVector(0.0f, 0.0f, 0.0f), - nil, 0.0f, black, 0, 0, 0, 0); - } - } - } - - if(nGenerateRaindrops > 0 && nGenerateRaindrops < CTimer::GetTimeInMilliseconds()){ - CVector pos = GetPosition(); - float waterLevel = 0.0f; - if(CWaterLevel::GetWaterLevel(pos.x, pos.y, pos.z, &waterLevel, false)) - pos.z = waterLevel; - static RwRGBA black; - if(pos.z >= 0.0f){ - nGenerateRaindrops = 0; - pos.z += 0.5; - CParticleObject::AddObject(POBJECT_SPLASHES_AROUND, - pos, CVector(0.0f, 0.0f, 0.0f), 6.5f, 2500, black, true); - } - } - }else{ - bIsInWater = false; - m_flagD8 = false; - - static RwRGBA splashCol = {155, 155, 185, 196}; - static RwRGBA smokeCol = {255, 255, 255, 255}; - - for(i = 0; i < 4; i++){ - if(m_aSuspensionSpringRatio[i] < 1.0f && m_aWheelColPoints[i].surfaceB == SURFACE_PUDDLE){ - CVector pos = m_aWheelColPoints[i].point + 0.3f*GetUp() - GetPosition(); - CVector vSpeed = GetSpeed(pos); - vSpeed.z = 0.0f; - float fSpeed = vSpeed.MagnitudeSqr(); - if(fSpeed > sq(0.05f)){ - fSpeed = Sqrt(fSpeed); - float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); - CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; - - CParticle::AddParticle(PARTICLE_PED_SPLASH, - pos + GetPosition(), -0.5f*right, - nil, size, splashCol, - CGeneral::GetRandomNumberInRange(0.0f, 10.0f), - CGeneral::GetRandomNumberInRange(0.0f, 90.0f), 1, 0); - - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, - pos + GetPosition(), -0.6f*right, - nil, size, smokeCol, 0, 0, 0, 0); - - if((CTimer::GetFrameCounter() & 0xF) == 0) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_SPLASH, 2000.0f*fSpeed); - } - } - } - } -} - -void -CAutomobile::DoDriveByShootings(void) -{ - CAnimBlendAssociation *anim; - CWeapon *weapon = pDriver->GetWeapon(); - if(weapon->m_eWeaponType != WEAPONTYPE_UZI) - return; - - weapon->Update(pDriver->m_audioEntityId); - - bool lookingLeft = false; - bool lookingRight = false; - if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1){ - if(CPad::GetPad(0)->GetLookLeft()) - lookingLeft = true; - if(CPad::GetPad(0)->GetLookRight()) - lookingRight = true; - }else{ - if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) - lookingLeft = true; - if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) - lookingRight = true; - } - - if(lookingLeft || lookingRight){ - if(lookingLeft){ - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); - if(anim) - anim->blendDelta = -1000.0f; - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); - if(anim == nil || anim->blendDelta < 0.0f) - CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_L); - else - anim->SetRun(); - }else if(pDriver->m_pMyVehicle->pPassengers[0] == nil || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FIRSTPERSON){ - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); - if(anim) - anim->blendDelta = -1000.0f; - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); - if(anim == nil || anim->blendDelta < 0.0f) - CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_R); - else - anim->SetRun(); - } - - if(CPad::GetPad(0)->GetCarGunFired() && CTimer::GetTimeInMilliseconds() > weapon->m_nTimer){ - weapon->FireFromCar(this, lookingLeft); - weapon->m_nTimer = CTimer::GetTimeInMilliseconds() + 70; - } - }else{ - weapon->Reload(); - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); - if(anim) - anim->blendDelta = -1000.0f; - anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); - if(anim) - anim->blendDelta = -1000.0f; - } - - // TODO: what is this? - if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ - m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); - ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); - } - if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ - m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); - ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); - } -} - -int32 -CAutomobile::RcbanditCheckHitWheels(void) -{ - int x, xmin, xmax; - int y, ymin, ymax; - - xmin = CWorld::GetSectorIndexX(GetPosition().x - 2.0f); - if(xmin < 0) xmin = 0; - xmax = CWorld::GetSectorIndexX(GetPosition().x + 2.0f); - if(xmax > NUMSECTORS_X-1) xmax = NUMSECTORS_X-1; - ymin = CWorld::GetSectorIndexX(GetPosition().y - 2.0f); - if(ymin < 0) ymin = 0; - ymax = CWorld::GetSectorIndexX(GetPosition().y + 2.0f); - if(ymax > NUMSECTORS_Y-1) ymax = NUMSECTORS_X-1; - - CWorld::AdvanceCurrentScanCode(); - - for(y = ymin; y <= ymax; y++) - for(x = xmin; x <= xmax; x++){ - CSector *s = CWorld::GetSector(x, y); - if(RcbanditCheck1CarWheels(s->m_lists[ENTITYLIST_VEHICLES]) || - RcbanditCheck1CarWheels(s->m_lists[ENTITYLIST_VEHICLES_OVERLAP])) - return 1; - } - return 0; -} - -int32 -CAutomobile::RcbanditCheck1CarWheels(CPtrList &list) -{ - static CMatrix matW2B; - int i; - CPtrNode *node; - CAutomobile *car; - CColModel *colModel = GetColModel(); - CVehicleModelInfo *mi; - - for(node = list.first; node; node = node->next){ - car = (CAutomobile*)node->item; - if(this != car && car->IsCar() && car->m_scanCode != CWorld::GetCurrentScanCode()){ - car->m_scanCode = CWorld::GetCurrentScanCode(); - - if(Abs(this->GetPosition().x - car->GetPosition().x) < 10.0f && - Abs(this->GetPosition().y - car->GetPosition().y) < 10.0f){ - mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(car->GetModelIndex()); - - for(i = 0; i < 4; i++){ - if(car->m_aSuspensionSpringRatioPrev[i] < 1.0f || car->m_status == STATUS_SIMPLE){ - CVector wheelPos; - CColSphere sph; - mi->GetWheelPosn(i, wheelPos); - matW2B = Invert(GetMatrix()); - sph.center = matW2B * (car->GetMatrix() * wheelPos); - sph.radius = mi->m_wheelScale*0.25f; - if(CCollision::TestSphereBox(sph, colModel->boundingBox)) - return 1; - } - } - } - } - } - return 0; -} - -void -CAutomobile::PlaceOnRoadProperly(void) -{ - CColPoint point; - CEntity *entity; - CColModel *colModel = GetColModel(); - float lenFwd, lenBack; - float frontZ, rearZ; - - lenFwd = colModel->boundingBox.max.y; - lenBack = -colModel->boundingBox.min.y; - - CVector front(GetPosition().x + GetForward().x*lenFwd, - GetPosition().y + GetForward().y*lenFwd, - GetPosition().z + 5.0f); - if(CWorld::ProcessVerticalLine(front, GetPosition().z - 5.0f, point, entity, - true, false, false, false, false, false, nil)){ - frontZ = point.point.z; - m_pCurGroundEntity = entity; - }else{ - frontZ = field_21C; - } - - CVector rear(GetPosition().x - GetForward().x*lenBack, - GetPosition().y - GetForward().y*lenBack, - GetPosition().z + 5.0f); - if(CWorld::ProcessVerticalLine(rear, GetPosition().z - 5.0f, point, entity, - true, false, false, false, false, false, nil)){ - rearZ = point.point.z; - m_pCurGroundEntity = entity; - }else{ - rearZ = field_220; - } - - float len = lenFwd + lenBack; - float angle = Atan((frontZ - rearZ)/len); - float c = Cos(angle); - float s = Sin(angle); - - GetRight() = CVector((front.y - rear.y)/len, -(front.x - rear.x)/len, 0.0f); - GetForward() = CVector(-c*GetRight().y, c*GetRight().x, s); - GetUp() = CrossProduct(GetRight(), GetForward()); - GetPosition() = CVector((front.x + rear.x)/2.0f, (front.y + rear.y)/2.0f, (frontZ + rearZ)/2.0f + GetHeightAboveRoad()); -} - -void -CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) -{ - int i; - float damageMultiplier = 0.2f; - bool doubleMoney = false; - - if(impulse == 0.0f){ - impulse = m_fDamageImpulse; - damagedPiece = m_nDamagePieceType; - damageMultiplier = 1.0f; - } - - CVector pos(0.0f, 0.0f, 0.0f); - - if(!bCanBeDamaged) - return; - - // damage flipped over car - if(GetUp().z < 0.0f && this != FindPlayerVehicle()){ - if(bNotDamagedUpsideDown || m_status == STATUS_PLAYER_REMOTE || bIsInWater) - return; - m_fHealth -= 4.0f*CTimer::GetTimeStep(); - } - - if(impulse > 25.0f && m_status != STATUS_WRECKED){ - if(bIsLawEnforcer && - FindPlayerVehicle() && FindPlayerVehicle() == m_pDamageEntity && - m_status != STATUS_ABANDONED && - FindPlayerVehicle()->m_vecMoveSpeed.Magnitude() >= m_vecMoveSpeed.Magnitude() && - FindPlayerVehicle()->m_vecMoveSpeed.Magnitude() > 0.1f) - FindPlayerPed()->SetWantedLevelNoDrop(1); - - if(m_status == STATUS_PLAYER && impulse > 50.0f){ - uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); - CPad::GetPad(0)->StartShake(40000/freq, freq); - } - - if(bOnlyDamagedByPlayer){ - if(m_pDamageEntity != FindPlayerPed() && - m_pDamageEntity != FindPlayerVehicle()) - return; - } - - if(bCollisionProof) - return; - - if(m_pDamageEntity){ - if(m_pDamageEntity->IsBuilding() && - DotProduct(m_vecDamageNormal, GetUp()) > 0.6f) - return; - } - - int oldLightStatus[4]; - for(i = 0; i < 4; i++) - oldLightStatus[i] = Damage.GetLightStatus((eLights)i); - - if(GetUp().z > 0.0f || m_vecMoveSpeed.MagnitudeSqr() > 0.1f){ - float impulseMult = bMoreResistantToDamage ? 0.5f : 4.0f; - - switch(damagedPiece){ - case CAR_PIECE_BUMP_FRONT: - GetComponentWorldPosition(CAR_BUMP_FRONT, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_BUMPER_FRONT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); - doubleMoney = true; - } - if(m_aCarNodes[CAR_BONNET] && Damage.GetPanelStatus(VEHBUMPER_FRONT) == PANEL_STATUS_MISSING){ - case CAR_PIECE_BONNET: - GetComponentWorldPosition(CAR_BONNET, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_DOOR_BONNET, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_BONNET, DOOR_BONNET); - doubleMoney = true; - } - } - break; - - case CAR_PIECE_BUMP_REAR: - GetComponentWorldPosition(CAR_BUMP_REAR, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_BUMPER_FRONT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); - doubleMoney = true; - } - if(m_aCarNodes[CAR_BOOT] && Damage.GetPanelStatus(VEHBUMPER_REAR) == PANEL_STATUS_MISSING){ - case CAR_PIECE_BOOT: - GetComponentWorldPosition(CAR_BOOT, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_DOOR_BOOT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_BOOT, DOOR_BOOT); - doubleMoney = true; - } - } - break; - - case CAR_PIECE_DOOR_LF: - GetComponentWorldPosition(CAR_DOOR_LF, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && - Damage.ApplyDamage(COMPONENT_DOOR_FRONT_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); - doubleMoney = true; - } - break; - case CAR_PIECE_DOOR_RF: - GetComponentWorldPosition(CAR_DOOR_RF, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && - Damage.ApplyDamage(COMPONENT_DOOR_FRONT_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); - doubleMoney = true; - } - break; - case CAR_PIECE_DOOR_LR: - GetComponentWorldPosition(CAR_DOOR_LR, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && - Damage.ApplyDamage(COMPONENT_DOOR_REAR_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); - doubleMoney = true; - } - break; - case CAR_PIECE_DOOR_RR: - GetComponentWorldPosition(CAR_DOOR_RR, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if((m_nDoorLock == CARLOCK_NOT_USED || m_nDoorLock == CARLOCK_UNLOCKED) && - Damage.ApplyDamage(COMPONENT_DOOR_REAR_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); - doubleMoney = true; - } - break; - - case CAR_PIECE_WING_LF: - GetComponentWorldPosition(CAR_WING_LF, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_PANEL_FRONT_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetPanelDamage(CAR_WING_LF, VEHPANEL_FRONT_LEFT); - doubleMoney = true; - } - break; - case CAR_PIECE_WING_RF: - GetComponentWorldPosition(CAR_WING_RF, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_PANEL_FRONT_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetPanelDamage(CAR_WING_RF, VEHPANEL_FRONT_RIGHT); - doubleMoney = true; - } - break; - case CAR_PIECE_WING_LR: - GetComponentWorldPosition(CAR_WING_LR, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_PANEL_REAR_LEFT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetPanelDamage(CAR_WING_LR, VEHPANEL_REAR_LEFT); - doubleMoney = true; - } - break; - case CAR_PIECE_WING_RR: - GetComponentWorldPosition(CAR_WING_RR, pos); - dmgDrawCarCollidingParticles(pos, impulse); - if(Damage.ApplyDamage(COMPONENT_PANEL_REAR_RIGHT, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - SetPanelDamage(CAR_WING_RR, VEHPANEL_REAR_RIGHT); - doubleMoney = true; - } - break; - - case CAR_PIECE_WHEEL_LF: - case CAR_PIECE_WHEEL_LR: - case CAR_PIECE_WHEEL_RF: - case CAR_PIECE_WHEEL_RR: - break; - - case CAR_PIECE_WINDSCREEN: - if(Damage.ApplyDamage(COMPONENT_PANEL_WINDSCREEN, impulse*impulseMult, pHandling->fCollisionDamageMultiplier)){ - uint8 oldStatus = Damage.GetPanelStatus(VEHPANEL_WINDSCREEN); - SetPanelDamage(CAR_WINDSCREEN, VEHPANEL_WINDSCREEN); - if(oldStatus != Damage.GetPanelStatus(VEHPANEL_WINDSCREEN)){ - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_WINDSHIELD_CRACK, 0.0f); - doubleMoney = true; - } - } - break; - } - - if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ - int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; - money = Min(money, 40); - if(money > 2){ - sprintf(gString, "$%d", money); - CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; - } - } - } - - float damage = (impulse-25.0f)*pHandling->fCollisionDamageMultiplier*0.6f*damageMultiplier; - - if(GetModelIndex() == MI_SECURICA && m_pDamageEntity && m_pDamageEntity->m_status == STATUS_PLAYER) - damage *= 7.0f; - - if(damage > 0.0f){ - int oldHealth = m_fHealth; - if(this == FindPlayerVehicle()){ - m_fHealth -= bTakeLessDamage ? damage/6.0f : damage/2.0f; - }else{ - if(damage > 35.0f && pDriver) - pDriver->Say(SOUND_PED_CAR_COLLISION); - m_fHealth -= bTakeLessDamage ? damage/12.0f : damage/4.0f; - } - if(m_fHealth <= 0.0f && oldHealth > 0) - m_fHealth = 1.0f; - } - - // play sound if a light broke - for(i = 0; i < 4; i++) - if(oldLightStatus[i] != 1 && Damage.GetLightStatus((eLights)i) == 1){ - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_LIGHT_BREAK, i); // BUG? i? - break; - } - } - - if(m_fHealth < 250.0f){ - // Car is on fire - if(Damage.GetEngineStatus() < ENGINE_STATUS_ON_FIRE){ - // Set engine on fire and remember who did this - Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE); - m_fFireBlowUpTimer = 0.0f; - m_pSetOnFireEntity = m_pDamageEntity; - if(m_pSetOnFireEntity) - m_pSetOnFireEntity->RegisterReference(&m_pSetOnFireEntity); - } - }else{ - if(GetModelIndex() == MI_BFINJECT){ - if(m_fHealth < 400.0f) - Damage.SetEngineStatus(200); - else if(m_fHealth < 600.0f) - Damage.SetEngineStatus(100); - } - } -} - -void -CAutomobile::dmgDrawCarCollidingParticles(const CVector &pos, float amount) -{ - int i, n; - - if(!GetIsOnScreen()) - return; - - // FindPlayerSpeed() unused - - n = (int)amount/20; - - for(i = 0; i < ((n+4)&0x1F); i++) - CParticle::AddParticle(PARTICLE_SPARK_SMALL, pos, - CVector(CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), - CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), - 0.006f)); - - for(i = 0; i < n+2; i++) - CParticle::AddParticle(PARTICLE_CARCOLLISION_DUST, - CVector(CGeneral::GetRandomNumberInRange(-1.2f, 1.2f) + pos.x, - CGeneral::GetRandomNumberInRange(-1.2f, 1.2f) + pos.y, - pos.z), - CVector(0.0f, 0.0f, 0.0f), nil, 0.5f); - - n = (int)amount/50 + 1; - for(i = 0; i < n; i++) - CParticle::AddParticle(PARTICLE_CAR_DEBRIS, pos, - CVector(CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), - CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), - CGeneral::GetRandomNumberInRange(0.1f, 0.25f)), - nil, - CGeneral::GetRandomNumberInRange(0.02f, 0.08f), - CVehicleModelInfo::ms_vehicleColourTable[m_currentColour1], - CGeneral::GetRandomNumberInRange(-40.0f, 40.0f), - 0, - CGeneral::GetRandomNumberInRange(0.0f, 4.0f)); -} - -void -CAutomobile::AddDamagedVehicleParticles(void) -{ - if(this == FindPlayerVehicle() && TheCamera.GetLookingForwardFirstPerson()) - return; - - uint8 engineStatus = Damage.GetEngineStatus(); - if(engineStatus < ENGINE_STATUS_STEAM1) - return; - - float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward()) * 180.0f; - CVector direction = 0.5f*m_vecMoveSpeed; - CVector damagePos = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_positions[CAR_POS_HEADLIGHTS]; - - switch(Damage.GetDoorStatus(DOOR_BONNET)){ - case DOOR_STATUS_OK: - case DOOR_STATUS_SMASHED: - // Bonnet is still there, smoke comes out at the edge - damagePos += vecDAMAGE_ENGINE_POS_SMALL; - break; - case DOOR_STATUS_SWINGING: - case DOOR_STATUS_MISSING: - // Bonnet is gone, smoke comes out at the engine - damagePos += vecDAMAGE_ENGINE_POS_BIG; - break; - } - - if(GetModelIndex() == MI_BFINJECT) - damagePos = CVector(0.3f, -1.5f, -0.1f); - - damagePos = GetMatrix()*damagePos; - damagePos.z += 0.15f; - - if(engineStatus < ENGINE_STATUS_STEAM2){ - if(fwdSpeed < 90.0f){ - direction.z += 0.05f; - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.1f); - } - }else if(engineStatus < ENGINE_STATUS_SMOKE){ - if(fwdSpeed < 90.0f) - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.0f); - }else if(engineStatus < ENGINE_STATUS_ON_FIRE){ - if(fwdSpeed < 90.0f){ - CParticle::AddParticle(PARTICLE_ENGINE_STEAM, damagePos, direction, nil, 0.0f); - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, damagePos, 0.3f*direction, nil, 0.0f); - } - }else if(m_fHealth > 250.0f){ - if(fwdSpeed < 90.0f) - CParticle::AddParticle(PARTICLE_ENGINE_SMOKE2, damagePos, 0.2f*direction, nil, 0.0f); - } -} - -int32 -CAutomobile::AddWheelDirtAndWater(CColPoint *colpoint, uint32 belowEffectSpeed) -{ - int i; - CVector dir; - static RwRGBA grassCol = { 8, 24, 8, 255 }; - static RwRGBA dirtCol = { 64, 64, 64, 255 }; - static RwRGBA dirttrackCol = { 64, 32, 16, 255 }; - static RwRGBA waterCol = { 48, 48, 64, 0 }; - - if(!belowEffectSpeed) - return 0; - - switch(colpoint->surfaceB){ - case SURFACE_GRASS: - dir.x = -0.05f*m_vecMoveSpeed.x; - dir.y = -0.05f*m_vecMoveSpeed.y; - for(i = 0; i < 4; i++){ - dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); - CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, - CGeneral::GetRandomNumberInRange(0.02f, 0.1f), grassCol); - } - return 0; - case SURFACE_DIRT: - dir.x = -0.05f*m_vecMoveSpeed.x; - dir.y = -0.05f*m_vecMoveSpeed.y; - for(i = 0; i < 4; i++){ - dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); - CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, - CGeneral::GetRandomNumberInRange(0.02f, 0.06f), dirtCol); - } - return 1; - case SURFACE_DIRTTRACK: - dir.x = -0.05f*m_vecMoveSpeed.x; - dir.y = -0.05f*m_vecMoveSpeed.y; - for(i = 0; i < 4; i++){ - dir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.06f); - CParticle::AddParticle(PARTICLE_WHEEL_DIRT, colpoint->point, dir, nil, - CGeneral::GetRandomNumberInRange(0.02f, 0.06f), dirttrackCol); - } - return 0; - default: - // Is this even visible? - if(CWeather::WetRoads > 0.01f && CTimer::GetFrameCounter() & 1){ - CParticle::AddParticle(PARTICLE_WATERSPRAY, - colpoint->point + CVector(0.0f, 0.0f, 0.25f+0.25f), - CVector(0.0f, 0.0f, 1.0f), nil, - CGeneral::GetRandomNumberInRange(0.1f, 0.5f), waterCol); - return 0; - } - return 1; - } -} - -void -CAutomobile::GetComponentWorldPosition(int32 component, CVector &pos) -{ - if(m_aCarNodes[component] == nil){ - printf("CarNode missing: %d %d\n", GetModelIndex(), component); - return; - } - RwMatrix *ltm = RwFrameGetLTM(m_aCarNodes[component]); - pos = *RwMatrixGetPos(ltm); -} - -bool -CAutomobile::IsComponentPresent(int32 comp) -{ - return m_aCarNodes[comp] != nil; -} - -void -CAutomobile::SetComponentRotation(int32 component, CVector rotation) -{ - CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); - CVector pos = mat.GetPosition(); - // BUG: all these set the whole matrix - mat.SetRotateX(DEGTORAD(rotation.x)); - mat.SetRotateY(DEGTORAD(rotation.y)); - mat.SetRotateZ(DEGTORAD(rotation.z)); - mat.Translate(pos); - mat.UpdateRW(); -} - -void -CAutomobile::OpenDoor(int32 component, eDoors door, float openRatio) -{ - CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); - CVector pos = mat.GetPosition(); - float axes[3] = { 0.0f, 0.0f, 0.0f }; - float wasClosed = false; - - if(Doors[door].IsClosed()){ - // enable angle cull for closed doors - RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::ClearAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); - wasClosed = true; - } - - Doors[door].Open(openRatio); - - if(wasClosed && Doors[door].RetAngleWhenClosed() != Doors[door].m_fAngle){ - // door opened - HideAllComps(); - // turn off angle cull for swinging door - RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_OPEN_BONNET + door, 0.0f); - } - - if(!wasClosed && openRatio == 0.0f){ - // door closed - if(Damage.GetDoorStatus(door) == DOOR_STATUS_SWINGING) - Damage.SetDoorStatus(door, DOOR_STATUS_OK); // huh? - ShowAllComps(); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_CLOSE_BONNET + door, 0.0f); - } - - axes[Doors[door].m_nAxis] = Doors[door].m_fAngle; - mat.SetRotate(axes[0], axes[1], axes[2]); - mat.Translate(pos); - mat.UpdateRW(); -} - -inline void ProcessDoorOpenAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end) -{ - if(time > start && time < end){ - float ratio = (time - start)/(end - start); - if(car->Doors[door].GetAngleOpenRatio() < ratio) - car->OpenDoor(component, door, ratio); - }else if(time > end){ - car->OpenDoor(component, door, 1.0f); - } -} - -inline void ProcessDoorCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end) -{ - if(time > start && time < end){ - float ratio = 1.0f - (time - start)/(end - start); - if(car->Doors[door].GetAngleOpenRatio() > ratio) - car->OpenDoor(component, door, ratio); - }else if(time > end){ - car->OpenDoor(component, door, 0.0f); - } -} - -inline void ProcessDoorOpenCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float mid, float end) -{ - if(time > start && time < mid){ - // open - float ratio = (time - start)/(mid - start); - if(car->Doors[door].GetAngleOpenRatio() < ratio) - car->OpenDoor(component, door, ratio); - }else if(time > mid && time < end){ - // close - float ratio = 1.0f - (time - mid)/(end - mid); - if(car->Doors[door].GetAngleOpenRatio() > ratio) - car->OpenDoor(component, door, ratio); - }else if(time > end){ - car->OpenDoor(component, door, 0.0f); - } -} -void -CAutomobile::ProcessOpenDoor(uint32 component, uint32 anim, float time) -{ - eDoors door; - - switch(component){ - case CAR_DOOR_RF: door = DOOR_FRONT_RIGHT; break; - case CAR_DOOR_RR: door = DOOR_REAR_RIGHT; break; - case CAR_DOOR_LF: door = DOOR_FRONT_LEFT; break; - case CAR_DOOR_LR: door = DOOR_REAR_LEFT; break; - default: assert(0); - } - - if(IsDoorMissing(door)) - return; - - switch(anim){ - case ANIM_CAR_QJACK: - case ANIM_CAR_OPEN_LHS: - case ANIM_CAR_OPEN_RHS: - ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f); - break; - case ANIM_CAR_CLOSEDOOR_LHS: - case ANIM_CAR_CLOSEDOOR_LOW_LHS: - case ANIM_CAR_CLOSEDOOR_RHS: - case ANIM_CAR_CLOSEDOOR_LOW_RHS: - ProcessDoorCloseAnimation(this, component, door, time, 0.2f, 0.63f); - break; - case ANIM_CAR_ROLLDOOR: - case ANIM_CAR_ROLLDOOR_LOW: - ProcessDoorOpenCloseAnimation(this, component, door, time, 0.1f, 0.6f, 0.95f); - break; - break; - case ANIM_CAR_GETOUT_LHS: - case ANIM_CAR_GETOUT_LOW_LHS: - case ANIM_CAR_GETOUT_RHS: - case ANIM_CAR_GETOUT_LOW_RHS: - ProcessDoorOpenAnimation(this, component, door, time, 0.06f, 0.43f); - break; - case ANIM_CAR_CLOSE_LHS: - case ANIM_CAR_CLOSE_RHS: - ProcessDoorCloseAnimation(this, component, door, time, 0.1f, 0.23f); - break; - case ANIM_CAR_PULLOUT_RHS: - case ANIM_CAR_PULLOUT_LOW_RHS: - OpenDoor(component, door, 1.0f); - case ANIM_COACH_OPEN_L: - case ANIM_COACH_OPEN_R: - ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f); - break; - case ANIM_COACH_OUT_L: - ProcessDoorOpenAnimation(this, component, door, time, 0.0f, 0.3f); - break; - case ANIM_VAN_OPEN_L: - case ANIM_VAN_OPEN: - ProcessDoorOpenAnimation(this, component, door, time, 0.37f, 0.55f); - break; - case ANIM_VAN_CLOSE_L: - case ANIM_VAN_CLOSE: - ProcessDoorCloseAnimation(this, component, door, time, 0.5f, 0.8f); - break; - case ANIM_VAN_GETOUT_L: - case ANIM_VAN_GETOUT: - ProcessDoorOpenAnimation(this, component, door, time, 0.5f, 0.6f); - break; - case NUM_ANIMS: - OpenDoor(component, door, time); - break; - } -} - -bool -CAutomobile::IsDoorReady(eDoors door) -{ - if(Doors[door].IsClosed() || IsDoorMissing(door)) - return true; - int doorflag = 0; - // TODO: enum? - switch(door){ - case DOOR_FRONT_LEFT: doorflag = 1; break; - case DOOR_FRONT_RIGHT: doorflag = 4; break; - case DOOR_REAR_LEFT: doorflag = 2; break; - case DOOR_REAR_RIGHT: doorflag = 8; break; - } - return (doorflag & m_nGettingInFlags) == 0; -} - -bool -CAutomobile::IsDoorFullyOpen(eDoors door) -{ - return Doors[door].IsFullyOpen() || IsDoorMissing(door); -} - -bool -CAutomobile::IsDoorClosed(eDoors door) -{ - return !!Doors[door].IsClosed(); -} - -bool -CAutomobile::IsDoorMissing(eDoors door) -{ - return Damage.GetDoorStatus(door) == DOOR_STATUS_MISSING; -} - -void -CAutomobile::RemoveRefsToVehicle(CEntity *ent) -{ - int i; - for(i = 0; i < 4; i++) - if(m_aGroundPhysical[i] == ent) - m_aGroundPhysical[i] = nil; -} - -void -CAutomobile::BlowUpCar(CEntity *culprit) -{ - int i; - RpAtomic *atomic; - - if(!bCanBeDamaged) - return; - - // explosion pushes vehicle up - m_vecMoveSpeed.z += 0.13f; - m_status = STATUS_WRECKED; - bRenderScorched = true; - m_nTimeOfDeath = CTimer::GetTimeInMilliseconds(); - Damage.FuckCarCompletely(); - - if(GetModelIndex() != MI_RCBANDIT){ - SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); - SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); - SetDoorDamage(CAR_BONNET, DOOR_BONNET); - SetDoorDamage(CAR_BOOT, DOOR_BOOT); - SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); - SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); - SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); - SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); - SpawnFlyingComponent(CAR_WHEEL_LF, COMPGROUP_WHEEL); - atomic = nil; - RwFrameForAllObjects(m_aCarNodes[CAR_WHEEL_LF], GetCurrentAtomicObjectCB, &atomic); - if(atomic) - RpAtomicSetFlags(atomic, 0); - } - - m_fHealth = 0.0f; - m_nBombTimer = 0; - m_bombType = CARBOMB_NONE; - - TheCamera.CamShake(0.7f, GetPosition().x, GetPosition().y, GetPosition().z); - - // kill driver and passengers - if(pDriver){ - CDarkel::RegisterKillByPlayer(pDriver, WEAPONTYPE_EXPLOSION); - if(pDriver->GetPedState() == PED_DRIVING){ - pDriver->SetDead(); - if(!pDriver->IsPlayer()) - pDriver->FlagToDestroyWhenNextProcessed(); - }else - pDriver->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); - } - for(i = 0; i < m_nNumMaxPassengers; i++){ - if(pPassengers[i]){ - CDarkel::RegisterKillByPlayer(pPassengers[i], WEAPONTYPE_EXPLOSION); - if(pPassengers[i]->GetPedState() == PED_DRIVING){ - pPassengers[i]->SetDead(); - if(!pPassengers[i]->IsPlayer()) - pPassengers[i]->FlagToDestroyWhenNextProcessed(); - }else - pPassengers[i]->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); - } - } - - bEngineOn = false; - bLightsOn = false; - m_bSirenOrAlarm = false; - bTaxiLight = false; - if(bIsAmbulanceOnDuty){ - bIsAmbulanceOnDuty = false; - CCarCtrl::NumAmbulancesOnDuty--; - } - if(bIsFireTruckOnDuty){ - bIsFireTruckOnDuty = false; - CCarCtrl::NumFiretrucksOnDuty--; - } - ChangeLawEnforcerState(false); - - gFireManager.StartFire(this, culprit, 0.8f, 1); // TODO - CDarkel::RegisterCarBlownUpByPlayer(this); - if(GetModelIndex() == MI_RCBANDIT) - CExplosion::AddExplosion(this, culprit, EXPLOSION_CAR_QUICK, GetPosition(), 0); - else - CExplosion::AddExplosion(this, culprit, EXPLOSION_CAR, GetPosition(), 0); -} - -bool -CAutomobile::SetUpWheelColModel(CColModel *colModel) -{ - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - CColModel *vehColModel = mi->GetColModel(); - - colModel->boundingSphere = vehColModel->boundingSphere; - colModel->boundingBox = vehColModel->boundingBox; - - CMatrix mat; - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); - colModel->spheres[0].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LF); - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); - colModel->spheres[1].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LR); - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); - colModel->spheres[2].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF); - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); - colModel->spheres[3].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR); - - if(m_aCarNodes[CAR_WHEEL_LM] != nil && m_aCarNodes[CAR_WHEEL_RM] != nil){ - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM])); - colModel->spheres[4].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF); - mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM])); - colModel->spheres[5].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR); - colModel->numSpheres = 6; - }else - colModel->numSpheres = 4; - - return true; -} - -// this probably isn't used in III yet -void -CAutomobile::BurstTyre(uint8 wheel) -{ - switch(wheel){ - case CAR_PIECE_WHEEL_LF: wheel = VEHWHEEL_FRONT_LEFT; break; - case CAR_PIECE_WHEEL_LR: wheel = VEHWHEEL_REAR_LEFT; break; - case CAR_PIECE_WHEEL_RF: wheel = VEHWHEEL_FRONT_RIGHT; break; - case CAR_PIECE_WHEEL_RR: wheel = VEHWHEEL_REAR_RIGHT; break; - } - - int status = Damage.GetWheelStatus(wheel); - if(status == WHEEL_STATUS_OK){ - Damage.SetWheelStatus(wheel, WHEEL_STATUS_BURST); - - if(m_status == STATUS_SIMPLE){ - m_status = STATUS_PHYSICS; - CCarCtrl::SwitchVehicleToRealPhysics(this); - } - - ApplyMoveForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f)); - ApplyTurnForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f), GetForward()); - } -} - -bool -CAutomobile::IsRoomForPedToLeaveCar(uint32 component, CVector *doorOffset) -{ - CColPoint colpoint; - CEntity *ent; - colpoint.point = CVector(0.0f, 0.0f, 0.0f); - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - - CVector seatPos; - switch(component){ - case CAR_DOOR_RF: - seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; - break; - case CAR_DOOR_LF: - seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; - seatPos.x = -seatPos.x; - break; - case CAR_DOOR_RR: - seatPos = mi->m_positions[CAR_POS_BACKSEAT]; - break; - case CAR_DOOR_LR: - seatPos = mi->m_positions[CAR_POS_BACKSEAT]; - seatPos.x = -seatPos.x; - break; - } - seatPos = GetMatrix() * seatPos; - - CVector doorPos = CPed::GetPositionToOpenCarDoor(this, component); - if(doorOffset){ - CVector off = *doorOffset; - if(component == CAR_DOOR_RF || component == CAR_DOOR_RR) - off.x = -off.x; - doorPos += Multiply3x3(GetMatrix(), off); - } - - if(GetUp().z < 0.0f){ - seatPos.z += 0.5f; - doorPos.z += 0.5f; - } - - CVector dist = doorPos - seatPos; - float length = dist.Magnitude(); - CVector pedPos = seatPos + dist*((length+0.6f)/length); - - if(!CWorld::GetIsLineOfSightClear(seatPos, pedPos, true, false, false, true, false, false)) - return false; - if(CWorld::TestSphereAgainstWorld(doorPos, 0.6f, this, true, true, false, true, false, false)) - return false; - if(CWorld::ProcessVerticalLine(doorPos, 1000.0f, colpoint, ent, true, false, false, true, false, false, nil)) - if(colpoint.point.z > doorPos.z && colpoint.point.z < doorPos.z + 0.6f) - return false; - float upperZ = colpoint.point.z; - if(!CWorld::ProcessVerticalLine(doorPos, -1000.0f, colpoint, ent, true, false, false, true, false, false, nil)) - return false; - if(upperZ != 0.0f && upperZ < colpoint.point.z) - return false; - return true; -} - -float -CAutomobile::GetHeightAboveRoad(void) -{ - return m_fHeightAboveRoad; -} - -void -CAutomobile::PlayCarHorn(void) -{ - int r; - - if(m_nCarHornTimer != 0) - return; - - r = CGeneral::GetRandomNumber() & 7; - if(r < 2){ - m_nCarHornTimer = 45; - }else if(r < 4){ - if(pDriver) - pDriver->Say(SOUND_PED_CAR_COLLISION); - m_nCarHornTimer = 45; - }else{ - if(pDriver) - pDriver->Say(SOUND_PED_CAR_COLLISION); - } -} - -void -CAutomobile::PlayHornIfNecessary(void) -{ - if(AutoPilot.m_bSlowedDownBecauseOfPeds || - AutoPilot.m_bSlowedDownBecauseOfCars) - if(!HasCarStoppedBecauseOfLight()) - PlayCarHorn(); -} - - -void -CAutomobile::ResetSuspension(void) -{ - int i; - for(i = 0; i < 4; i++){ - m_aSuspensionSpringRatio[i] = 1.0f; - m_aWheelTimer[i] = 0.0f; - m_aWheelRotation[i] = 0.0f; - m_aWheelState[i] = WHEEL_STATE_NORMAL; - } -} - -void -CAutomobile::SetupSuspensionLines(void) -{ - int i; - CVector posn; - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - CColModel *colModel = mi->GetColModel(); - - // Each suspension line starts at the uppermost wheel position - // and extends down to the lowermost point on the tyre - for(i = 0; i < 4; i++){ - mi->GetWheelPosn(i, posn); - m_aWheelPosition[i] = posn.z; - - // uppermost wheel position - posn.z += pHandling->fSuspensionUpperLimit; - colModel->lines[i].p0 = posn; - - // lowermost wheel position - posn.z += pHandling->fSuspensionLowerLimit - pHandling->fSuspensionUpperLimit; - // lowest point on tyre - posn.z -= mi->m_wheelScale*0.5f; - colModel->lines[i].p1 = posn; - - // this is length of the spring at rest - m_aSuspensionSpringLength[i] = pHandling->fSuspensionUpperLimit - pHandling->fSuspensionLowerLimit; - m_aSuspensionLineLength[i] = colModel->lines[i].p0.z - colModel->lines[i].p1.z; - } - - // Compress spring somewhat to get normal height on road - m_fHeightAboveRoad = -(colModel->lines[0].p0.z + (colModel->lines[0].p1.z - colModel->lines[0].p0.z)* - (1.0f - 1.0f/(8.0f*pHandling->fSuspensionForceLevel))); - for(i = 0; i < 4; i++) - m_aWheelPosition[i] = mi->m_wheelScale*0.5f - m_fHeightAboveRoad; - - // adjust col model to include suspension lines - if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) - colModel->boundingBox.min.z = colModel->lines[0].p1.z; - float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); - if(colModel->boundingSphere.radius < radius) - colModel->boundingSphere.radius = radius; - - if(GetModelIndex() == MI_RCBANDIT){ - colModel->boundingSphere.radius = 2.0f; - for(i = 0; i < colModel->numSpheres; i++) - colModel->spheres[i].radius = 0.3f; - } -} - -// called on police cars -void -CAutomobile::ScanForCrimes(void) -{ - if(FindPlayerVehicle() && FindPlayerVehicle()->IsCar()) - if(FindPlayerVehicle()->IsAlarmOn()) - // if player's alarm is on, increase wanted level - if((FindPlayerVehicle()->GetPosition() - GetPosition()).MagnitudeSqr() < sq(20.0f)) - CWorld::Players[CWorld::PlayerInFocus].m_pPed->SetWantedLevelNoDrop(1); -} - -void -CAutomobile::BlowUpCarsInPath(void) -{ - int i; - - if(m_vecMoveSpeed.Magnitude() > 0.1f) - for(i = 0; i < m_nCollisionRecords; i++) - if(m_aCollisionRecords[i] && - m_aCollisionRecords[i]->IsVehicle() && - m_aCollisionRecords[i]->GetModelIndex() != MI_RHINO && - !m_aCollisionRecords[i]->bRenderScorched) - ((CVehicle*)m_aCollisionRecords[i])->BlowUpCar(this); -} - -bool -CAutomobile::HasCarStoppedBecauseOfLight(void) -{ - int i; - - if(m_status != STATUS_SIMPLE && m_status != STATUS_PHYSICS) - return false; - - if(AutoPilot.m_nCurrentRouteNode && AutoPilot.m_nNextRouteNode){ - CPathNode *curnode = &ThePaths.m_pathNodes[AutoPilot.m_nCurrentRouteNode]; - for(i = 0; i < curnode->numLinks; i++) - if(ThePaths.m_connections[curnode->firstLink + i] == AutoPilot.m_nNextRouteNode) - break; - if(i < curnode->numLinks && - ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO - return true; - } - - if(AutoPilot.m_nCurrentRouteNode && AutoPilot.m_nPrevRouteNode){ - CPathNode *curnode = &ThePaths.m_pathNodes[AutoPilot.m_nCurrentRouteNode]; - for(i = 0; i < curnode->numLinks; i++) - if(ThePaths.m_connections[curnode->firstLink + i] == AutoPilot.m_nPrevRouteNode) - break; - if(i < curnode->numLinks && - ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO - return true; - } - - return false; -} - -void -CAutomobile::SetBusDoorTimer(uint32 timer, uint8 type) -{ - if(timer < 1000) - timer = 1000; - if(type == 0) - // open and close - m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds(); - else - // only close - m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds() - 500; - m_nBusDoorTimerEnd = m_nBusDoorTimerStart + timer; -} - -void -CAutomobile::ProcessAutoBusDoors(void) -{ - if(CTimer::GetTimeInMilliseconds() < m_nBusDoorTimerEnd){ - if(m_nBusDoorTimerEnd != 0 && CTimer::GetTimeInMilliseconds() > m_nBusDoorTimerEnd-500){ - // close door - if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0){ - if(IsDoorClosed(DOOR_FRONT_LEFT)){ - m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds(); - OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f); - }else{ - OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, - 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f); - } - } - - if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0){ - if(IsDoorClosed(DOOR_FRONT_RIGHT)){ - m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds(); - OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f); - }else{ - OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, - 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f); - } - } - } - }else{ - // ended - if(m_nBusDoorTimerStart){ - if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0) - OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f); - if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0) - OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f); - m_nBusDoorTimerStart = 0; - m_nBusDoorTimerEnd = 0; - } - } -} - -void -CAutomobile::ProcessSwingingDoor(int32 component, eDoors door) -{ - if(Damage.GetDoorStatus(door) != DOOR_STATUS_SWINGING) - return; - - CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); - CVector pos = mat.GetPosition(); - float axes[3] = { 0.0f, 0.0f, 0.0f }; - - Doors[door].Process(this); - axes[Doors[door].m_nAxis] = Doors[door].m_fAngle; - mat.SetRotate(axes[0], axes[1], axes[2]); - mat.Translate(pos); - mat.UpdateRW(); -} - -void -CAutomobile::Fix(void) -{ - int component; - - Damage.ResetDamageStatus(); - - if(pHandling->Flags & HANDLING_NO_DOORS){ - Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_REAR_LEFT, DOOR_STATUS_MISSING); - Damage.SetDoorStatus(DOOR_REAR_RIGHT, DOOR_STATUS_MISSING); - } - - bIsDamaged = false; - RpClumpForAllAtomics((RpClump*)m_rwObject, CVehicleModelInfo::HideAllComponentsAtomicCB, (void*)ATOMIC_FLAG_DAM); - - for(component = CAR_BUMP_FRONT; component < NUM_CAR_NODES; component++){ - if(m_aCarNodes[component]){ - CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component])); - mat.SetTranslate(mat.GetPosition()); - mat.UpdateRW(); - } - } -} - -void -CAutomobile::SetupDamageAfterLoad(void) -{ - if(m_aCarNodes[CAR_BUMP_FRONT]) - SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT); - if(m_aCarNodes[CAR_BONNET]) - SetDoorDamage(CAR_BONNET, DOOR_BONNET); - if(m_aCarNodes[CAR_BUMP_REAR]) - SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR); - if(m_aCarNodes[CAR_BOOT]) - SetDoorDamage(CAR_BOOT, DOOR_BOOT); - if(m_aCarNodes[CAR_DOOR_LF]) - SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT); - if(m_aCarNodes[CAR_DOOR_RF]) - SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT); - if(m_aCarNodes[CAR_DOOR_LR]) - SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT); - if(m_aCarNodes[CAR_DOOR_RR]) - SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT); - if(m_aCarNodes[CAR_WING_LF]) - SetPanelDamage(CAR_WING_LF, VEHPANEL_FRONT_LEFT); - if(m_aCarNodes[CAR_WING_RF]) - SetPanelDamage(CAR_WING_RF, VEHPANEL_FRONT_RIGHT); - if(m_aCarNodes[CAR_WING_LR]) - SetPanelDamage(CAR_WING_LR, VEHPANEL_REAR_LEFT); - if(m_aCarNodes[CAR_WING_RR]) - SetPanelDamage(CAR_WING_RR, VEHPANEL_REAR_RIGHT); -} - -RwObject* -GetCurrentAtomicObjectCB(RwObject *object, void *data) -{ - RpAtomic *atomic = (RpAtomic*)object; - assert(RwObjectGetType(object) == rpATOMIC); - if(RpAtomicGetFlags(atomic) & rpATOMICRENDER) - *(RpAtomic**)data = atomic; - return object; -} - -CColPoint aTempPedColPts[32]; // this name doesn't make any sense - -CObject* -CAutomobile::SpawnFlyingComponent(int32 component, uint32 type) -{ - RpAtomic *atomic; - RwFrame *frame; - RwMatrix *matrix; - CObject *obj; - - if(CObject::nNoTempObjects >= NUMTEMPOBJECTS) - return nil; - - atomic = nil; - RwFrameForAllObjects(m_aCarNodes[component], GetCurrentAtomicObjectCB, &atomic); - if(atomic == nil) - return nil; - - obj = new CObject; - if(obj == nil) - return nil; - - if(component == CAR_WINDSCREEN){ - obj->SetModelIndexNoCreate(MI_CAR_BONNET); - }else switch(type){ - case COMPGROUP_BUMPER: - obj->SetModelIndexNoCreate(MI_CAR_BUMPER); - break; - case COMPGROUP_WHEEL: - obj->SetModelIndexNoCreate(MI_CAR_WHEEL); - break; - case COMPGROUP_DOOR: - obj->SetModelIndexNoCreate(MI_CAR_DOOR); - obj->SetCenterOfMass(0.0f, -0.5f, 0.0f); - break; - case COMPGROUP_BONNET: - obj->SetModelIndexNoCreate(MI_CAR_BONNET); - obj->SetCenterOfMass(0.0f, 0.4f, 0.0f); - break; - case COMPGROUP_BOOT: - obj->SetModelIndexNoCreate(MI_CAR_BOOT); - obj->SetCenterOfMass(0.0f, -0.3f, 0.0f); - break; - case COMPGROUP_PANEL: - default: - obj->SetModelIndexNoCreate(MI_CAR_PANEL); - break; - } - - // object needs base model - obj->RefModelInfo(GetModelIndex()); - - // create new atomic - matrix = RwFrameGetLTM(m_aCarNodes[component]); - frame = RwFrameCreate(); - atomic = RpAtomicClone(atomic); - *RwFrameGetMatrix(frame) = *matrix; - RpAtomicSetFrame(atomic, frame); - CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); - obj->AttachToRwObject((RwObject*)atomic); - - // init object - obj->m_fMass = 10.0f; - obj->m_fTurnMass = 25.0f; - obj->m_fAirResistance = 0.97f; - obj->m_fElasticity = 0.1f; - obj->m_fBuoyancy = obj->m_fMass*GRAVITY/0.75f; - obj->ObjectCreatedBy = TEMP_OBJECT; - obj->bIsStatic = false; - obj->bIsPickup = false; - obj->bUseVehicleColours = true; - obj->m_colour1 = m_currentColour1; - obj->m_colour2 = m_currentColour2; - - // life time - the more objects the are, the shorter this one will live - CObject::nNoTempObjects++; - if(CObject::nNoTempObjects > 20) - obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/5.0f; - else if(CObject::nNoTempObjects > 10) - obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/2.0f; - else - obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000; - - obj->m_vecMoveSpeed = m_vecMoveSpeed; - if(obj->m_vecMoveSpeed.z > 0.0f){ - obj->m_vecMoveSpeed.z *= 1.5f; - }else if(GetUp().z > 0.0f && - (component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN)){ - obj->m_vecMoveSpeed.z *= -1.5f; - obj->m_vecMoveSpeed.z += 0.04f; - }else{ - obj->m_vecMoveSpeed.z *= 0.25f; - } - obj->m_vecMoveSpeed.x *= 0.75f; - obj->m_vecMoveSpeed.y *= 0.75f; - - obj->m_vecTurnSpeed = m_vecTurnSpeed*2.0f; - - // push component away from car - CVector dist = obj->GetPosition() - GetPosition(); - dist.Normalise(); - if(component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN){ - // push these up some - dist += GetUp(); - if(GetUp().z > 0.0f){ - // simulate fast upward movement if going fast - float speed = CVector2D(m_vecMoveSpeed).MagnitudeSqr(); - obj->GetPosition() += GetUp()*speed; - } - } - obj->ApplyMoveForce(dist); - - if(type == COMPGROUP_WHEEL){ - obj->m_fTurnMass = 5.0f; - obj->m_vecTurnSpeed.x = 0.5f; - obj->m_fAirResistance = 0.99f; - } - - if(CCollision::ProcessColModels(obj->GetMatrix(), *obj->GetColModel(), - this->GetMatrix(), *this->GetColModel(), - aTempPedColPts, nil, nil) > 0) - obj->m_pCollidingEntity = this; - - if(bRenderScorched) - obj->bRenderScorched = true; - - CWorld::Add(obj); - - return obj; -} - -CObject* -CAutomobile::RemoveBonnetInPedCollision(void) -{ - CObject *obj; - - if(Damage.GetDoorStatus(DOOR_BONNET) != DOOR_STATUS_SWINGING && - Doors[DOOR_BONNET].RetAngleWhenOpen()*0.4f < Doors[DOOR_BONNET].m_fAngle){ - // BUG? why not COMPGROUP_BONNET? - obj = SpawnFlyingComponent(CAR_BONNET, COMPGROUP_DOOR); - // make both doors invisible on car - SetComponentVisibility(m_aCarNodes[CAR_BONNET], ATOMIC_FLAG_NONE); - Damage.SetDoorStatus(DOOR_BONNET, DOOR_STATUS_MISSING); - return obj; - } - return nil; -} - -void -CAutomobile::SetPanelDamage(int32 component, ePanels panel, bool noFlyingComponents) -{ - int status = Damage.GetPanelStatus(panel); - if(m_aCarNodes[component] == nil) - return; - if(status == PANEL_STATUS_SMASHED1){ - // show damaged part - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); - }else if(status == PANEL_STATUS_MISSING){ - if(!noFlyingComponents) - SpawnFlyingComponent(component, COMPGROUP_PANEL); - // hide both - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); - } -} - -void -CAutomobile::SetBumperDamage(int32 component, ePanels panel, bool noFlyingComponents) -{ - int status = Damage.GetPanelStatus(panel); - if(m_aCarNodes[component] == nil){ - printf("Trying to damage component %d of %s\n", - component, CModelInfo::GetModelInfo(GetModelIndex())->GetName()); - return; - } - if(status == PANEL_STATUS_SMASHED1){ - // show damaged part - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); - }else if(status == PANEL_STATUS_MISSING){ - if(!noFlyingComponents) - SpawnFlyingComponent(component, COMPGROUP_BUMPER); - // hide both - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); - } -} - -void -CAutomobile::SetDoorDamage(int32 component, eDoors door, bool noFlyingComponents) -{ - int status = Damage.GetDoorStatus(door); - if(m_aCarNodes[component] == nil){ - printf("Trying to damage component %d of %s\n", - component, CModelInfo::GetModelInfo(GetModelIndex())->GetName()); - return; - } - - if(door == DOOR_BOOT && status == DOOR_STATUS_SWINGING && pHandling->Flags & HANDLING_NOSWING_BOOT){ - Damage.SetDoorStatus(DOOR_BOOT, DOOR_STATUS_MISSING); - status = DOOR_STATUS_MISSING; - } - - if(status == DOOR_STATUS_SMASHED){ - // show damaged part - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM); - }else if(status == DOOR_STATUS_SWINGING){ - // turn off angle cull for swinging doors - RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL); - }else if(status == DOOR_STATUS_MISSING){ - if(!noFlyingComponents){ - if(door == DOOR_BONNET) - SpawnFlyingComponent(component, COMPGROUP_BONNET); - else if(door == DOOR_BOOT) - SpawnFlyingComponent(component, COMPGROUP_BOOT); - else - SpawnFlyingComponent(component, COMPGROUP_DOOR); - } - // hide both - SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE); - } -} - - -static RwObject* -SetVehicleAtomicVisibilityCB(RwObject *object, void *data) -{ - uint32 flags = (uint32)(uintptr)data; - RpAtomic *atomic = (RpAtomic*)object; - if((CVisibilityPlugins::GetAtomicId(atomic) & (ATOMIC_FLAG_OK|ATOMIC_FLAG_DAM)) == flags) - RpAtomicSetFlags(atomic, rpATOMICRENDER); - else - RpAtomicSetFlags(atomic, 0); - return object; -} - -void -CAutomobile::SetComponentVisibility(RwFrame *frame, uint32 flags) -{ - HideAllComps(); - bIsDamaged = true; - RwFrameForAllObjects(frame, SetVehicleAtomicVisibilityCB, (void*)flags); -} - -void -CAutomobile::SetupModelNodes(void) -{ - int i; - for(i = 0; i < NUM_CAR_NODES; i++) - m_aCarNodes[i] = nil; - CClumpModelInfo::FillFrameArray((RpClump*)m_rwObject, m_aCarNodes); -} - -void -CAutomobile::SetTaxiLight(bool light) -{ - bTaxiLight = light; -} - -bool -CAutomobile::GetAllWheelsOffGround(void) -{ - return m_nDriveWheelsOnGround == 0; -} - -void -CAutomobile::HideAllComps(void) -{ - // empty -} - -void -CAutomobile::ShowAllComps(void) -{ - // empty -} - -void -CAutomobile::ReduceHornCounter(void) -{ - if(m_nCarHornTimer != 0) - m_nCarHornTimer--; -} - -void -CAutomobile::SetAllTaxiLights(bool set) -{ - m_sAllTaxiLights = set; -} - -class CAutomobile_ : public CAutomobile -{ -public: - void ctor(int32 id, uint8 CreatedBy) { ::new (this) CAutomobile(id, CreatedBy); } - void dtor() { CAutomobile::~CAutomobile(); } - void SetModelIndex_(uint32 id) { CAutomobile::SetModelIndex(id); } - void ProcessControl_(void) { CAutomobile::ProcessControl(); } - void Teleport_(CVector v) { CAutomobile::Teleport(v); } - void PreRender_(void) { CAutomobile::PreRender(); } - void Render_(void) { CAutomobile::Render(); } - - int32 ProcessEntityCollision_(CEntity *ent, CColPoint *colpoints){ return CAutomobile::ProcessEntityCollision(ent, colpoints); } - - void ProcessControlInputs_(uint8 pad) { CAutomobile::ProcessControlInputs(pad); } - void GetComponentWorldPosition_(int32 component, CVector &pos) { CAutomobile::GetComponentWorldPosition(component, pos); } - bool IsComponentPresent_(int32 component) { return CAutomobile::IsComponentPresent(component); } - void SetComponentRotation_(int32 component, CVector rotation) { CAutomobile::SetComponentRotation(component, rotation); } - void OpenDoor_(int32 component, eDoors door, float ratio) { CAutomobile::OpenDoor(component, door, ratio); } - void ProcessOpenDoor_(uint32 component, uint32 anim, float time) { CAutomobile::ProcessOpenDoor(component, anim, time); } - bool IsDoorReady_(eDoors door) { return CAutomobile::IsDoorReady(door); } - bool IsDoorFullyOpen_(eDoors door) { return CAutomobile::IsDoorFullyOpen(door); } - bool IsDoorClosed_(eDoors door) { return CAutomobile::IsDoorClosed(door); } - bool IsDoorMissing_(eDoors door) { return CAutomobile::IsDoorMissing(door); } - void RemoveRefsToVehicle_(CEntity *ent) { CAutomobile::RemoveRefsToVehicle(ent); } - void BlowUpCar_(CEntity *ent) { CAutomobile::BlowUpCar(ent); } - bool SetUpWheelColModel_(CColModel *colModel) { return CAutomobile::SetUpWheelColModel(colModel); } - void BurstTyre_(uint8 tyre) { CAutomobile::BurstTyre(tyre); } - bool IsRoomForPedToLeaveCar_(uint32 door, CVector *pos) { return CAutomobile::IsRoomForPedToLeaveCar(door, pos); } - float GetHeightAboveRoad_(void) { return CAutomobile::GetHeightAboveRoad(); } - void PlayCarHorn_(void) { CAutomobile::PlayCarHorn(); } -}; - -STARTPATCHES - InjectHook(0x52C6B0, &CAutomobile_::ctor, PATCH_JUMP); - InjectHook(0x52D170, &CAutomobile_::dtor, PATCH_JUMP); - InjectHook(0x52D190, &CAutomobile_::SetModelIndex_, PATCH_JUMP); - InjectHook(0x531470, &CAutomobile_::ProcessControl_, PATCH_JUMP); - InjectHook(0x535180, &CAutomobile_::Teleport_, PATCH_JUMP); - InjectHook(0x539EA0, &CAutomobile_::Render_, PATCH_JUMP); - InjectHook(0x535B40, &CAutomobile_::PreRender_, PATCH_JUMP); - InjectHook(0x53B270, &CAutomobile_::ProcessEntityCollision_, PATCH_JUMP); - InjectHook(0x53B660, &CAutomobile_::ProcessControlInputs_, PATCH_JUMP); - InjectHook(0x52E5F0, &CAutomobile_::GetComponentWorldPosition_, PATCH_JUMP); - InjectHook(0x52E660, &CAutomobile_::IsComponentPresent_, PATCH_JUMP); - InjectHook(0x52E680, &CAutomobile_::SetComponentRotation_, PATCH_JUMP); - InjectHook(0x52E750, &CAutomobile_::OpenDoor_, PATCH_JUMP); - InjectHook(0x52EF10, &CAutomobile_::IsDoorReady_, PATCH_JUMP); - InjectHook(0x52EF90, &CAutomobile_::IsDoorFullyOpen_, PATCH_JUMP); - InjectHook(0x52EFD0, &CAutomobile_::IsDoorClosed_, PATCH_JUMP); - InjectHook(0x52F000, &CAutomobile_::IsDoorMissing_, PATCH_JUMP); - InjectHook(0x53BF40, &CAutomobile_::RemoveRefsToVehicle_, PATCH_JUMP); - InjectHook(0x53BC60, &CAutomobile_::BlowUpCar_, PATCH_JUMP); - InjectHook(0x53BF70, &CAutomobile_::SetUpWheelColModel_, PATCH_JUMP); - InjectHook(0x53C0E0, &CAutomobile_::BurstTyre_, PATCH_JUMP); - InjectHook(0x53C5B0, &CAutomobile_::IsRoomForPedToLeaveCar_, PATCH_JUMP); - InjectHook(0x437690, &CAutomobile_::GetHeightAboveRoad_, PATCH_JUMP); - InjectHook(0x53C450, &CAutomobile_::PlayCarHorn_, PATCH_JUMP); - InjectHook(0x53E090, &CAutomobile::PlaceOnRoadProperly, PATCH_JUMP); - InjectHook(0x52F030, &CAutomobile::dmgDrawCarCollidingParticles, PATCH_JUMP); - InjectHook(0x535450, &CAutomobile::AddDamagedVehicleParticles, PATCH_JUMP); - InjectHook(0x5357D0, &CAutomobile::AddWheelDirtAndWater, PATCH_JUMP); - InjectHook(0x5353A0, &CAutomobile::ResetSuspension, PATCH_JUMP); - InjectHook(0x52D210, &CAutomobile::SetupSuspensionLines, PATCH_JUMP); - InjectHook(0x53E000, &CAutomobile::BlowUpCarsInPath, PATCH_JUMP); - InjectHook(0x42E220, &CAutomobile::HasCarStoppedBecauseOfLight, PATCH_JUMP); - InjectHook(0x53D320, &CAutomobile::SetBusDoorTimer, PATCH_JUMP); - InjectHook(0x53D370, &CAutomobile::ProcessAutoBusDoors, PATCH_JUMP); - InjectHook(0x535250, &CAutomobile::ProcessSwingingDoor, PATCH_JUMP); - InjectHook(0x53C240, &CAutomobile::Fix, PATCH_JUMP); - InjectHook(0x53C310, &CAutomobile::SetupDamageAfterLoad, PATCH_JUMP); - InjectHook(0x530300, &CAutomobile::SpawnFlyingComponent, PATCH_JUMP); - InjectHook(0x535320, &CAutomobile::RemoveBonnetInPedCollision, PATCH_JUMP); - InjectHook(0x5301A0, &CAutomobile::SetPanelDamage, PATCH_JUMP); - InjectHook(0x530120, &CAutomobile::SetBumperDamage, PATCH_JUMP); - InjectHook(0x530200, &CAutomobile::SetDoorDamage, PATCH_JUMP); - InjectHook(0x5300E0, &CAutomobile::SetComponentVisibility, PATCH_JUMP); - InjectHook(0x52D1B0, &CAutomobile::SetupModelNodes, PATCH_JUMP); - InjectHook(0x53C420, &CAutomobile::SetTaxiLight, PATCH_JUMP); - InjectHook(0x53BC40, &CAutomobile::GetAllWheelsOffGround, PATCH_JUMP); - InjectHook(0x5308C0, &CAutomobile::ReduceHornCounter, PATCH_JUMP); - InjectHook(0x53C440, &CAutomobile::SetAllTaxiLights, PATCH_JUMP); -ENDPATCHES diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h index 4dd3a087..6203957d 100644 --- a/src/vehicles/Automobile.h +++ b/src/vehicles/Automobile.h @@ -117,7 +117,7 @@ public: uint8 m_nWheelsOnGround; uint8 m_nDriveWheelsOnGround; uint8 m_nDriveWheelsOnGroundPrev; - int32 field_594; + int32 m_fGasPedalAudio; tWheelState m_aWheelState[4]; static bool &m_sAllTaxiLights; diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index 2b5ff567..f614b78f 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -61,7 +61,7 @@ float CBoat::IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat) float fDist = vecDist.MagnitudeSqr(); if ( fDist < SQR(fMaxDist) ) - return 1.0f - Min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); + return 1.0f - min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); } return 0.0f; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index 1c242f0e..9b1a651d 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -1038,16 +1038,8 @@ void CHeli::ActivateHeli(bool activate) { ScriptHeliOn = activate; } class CHeli_ : public CHeli { public: -<<<<<<< HEAD -<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CHeli(id, CreatedBy); } void dtor(void) { CHeli::~CHeli(); } -======= - void dtor(void) { this->~CHeli(); } ->>>>>>> More audio ped -======= - void dtor(void) { CHeli::~CHeli(); } ->>>>>>> fix }; STARTPATCHES diff --git a/src/vehicles/Heli.cpp.autosave b/src/vehicles/Heli.cpp.autosave deleted file mode 100644 index 9b1a651d..00000000 --- a/src/vehicles/Heli.cpp.autosave +++ /dev/null @@ -1,1055 +0,0 @@ -#include "common.h" -#include "main.h" -#include "patcher.h" -#include "General.h" -#include "Darkel.h" -#include "Stats.h" -#include "SurfaceTable.h" -#include "ModelIndices.h" -#include "Streaming.h" -#include "Camera.h" -#include "VisibilityPlugins.h" -#include "ZoneCull.h" -#include "Particle.h" -#include "Shadows.h" -#include "Coronas.h" -#include "Explosion.h" -#include "TimeCycle.h" -#include "TempColModels.h" -#include "World.h" -#include "WaterLevel.h" -#include "PlayerPed.h" -#include "Object.h" -#include "HandlingMgr.h" -#include "Heli.h" - -enum -{ - HELI_STATUS_HOVER, - HELI_STATUS_CHASE_PLAYER, - HELI_STATUS_FLY_AWAY, - HELI_STATUS_SHOT_DOWN, - HELI_STATUS_HOVER2, -}; - -CHeli **CHeli::pHelis = (CHeli**)0x72CF50; -int16 &CHeli::NumRandomHelis = *(int16*)0x95CCAA; -uint32 &CHeli::TestForNewRandomHelisTimer = *(uint32*)0x8F1A7C; -int16 CHeli::NumScriptHelis; // unused -bool &CHeli::CatalinaHeliOn = *(bool*)0x95CD85; -bool &CHeli::CatalinaHasBeenShotDown = *(bool*)0x95CD56; -bool &CHeli::ScriptHeliOn = *(bool*)0x95CD43; - -CHeli::CHeli(int32 id, uint8 CreatedBy) - : CVehicle(CreatedBy) -{ - int i; - - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); - m_vehType = VEHICLE_TYPE_HELI; - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); - SetModelIndex(id); - m_heliStatus = HELI_STATUS_HOVER; - m_pathState = 0; - - m_fMass = 100000000.0f; - m_fTurnMass = 100000000.0f; - m_fAirResistance = 0.9994f; - m_fElasticity = 0.05f; - - m_nHeliId = 0; - m_fRotorRotation = 0.0f; - m_nBulletDamage = 0; - m_fAngularSpeed = 0.0f; - m_fRotation = 0.0f; - m_nSearchLightTimer = CTimer::GetTimeInMilliseconds(); - for(i = 0; i < 6; i++){ - m_aSearchLightHistoryX[i] = 0.0f; - m_aSearchLightHistoryY[i] = 0.0f; - } - - for(i = 0; i < 8; i++) - m_fHeliDustZ[i] = -50.0f; - - m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds(); - m_status = STATUS_HELI; - m_bTestRight = true; - m_fTargetOffset = 0.0f; - m_fSearchLightX = m_fSearchLightY = 0.0f; -} - -void -CHeli::SetModelIndex(uint32 id) -{ - int i; - - CVehicle::SetModelIndex(id); - for(i = 0; i < NUM_HELI_NODES; i++) - m_aHeliNodes[i] = nil; - CClumpModelInfo::FillFrameArray(GetClump(), m_aHeliNodes); -} - -static float CatalinaTargetX[7] = { -478.0, -677.0, -907.0, -1095.0, -1152.0, -1161.0, -1161.0 }; -static float CatalinaTargetY[7] = { 227.0, 206.0, 210.0, 242.0, 278.0, 341.0, 341.0 }; -static float CatalinaTargetZ[7] = { 77.0, 66.0, 60.0, 53.0, 51.0, 46.0, 30.0 }; -static float DamPathX[6] = { -1191.0, -1176.0, -1128.0, -1072.0, -1007.0, -971.0 }; -static float DamPathY[6] = { 350.0, 388.0, 429.0, 447.0, 449.0, 416.0 }; -static float DamPathZ[6] = { 42.0, 37.0, 28.0, 28.0, 31.0, 33.0 }; -static float ShortPathX[4] = { -974.0, -1036.0, -1112.0, -1173.0 }; -static float ShortPathY[4] = { 340.0, 312.0, 317.0, 294.0 }; -static float ShortPathZ[4] = { 41.0, 38.0, 32.0, 39.0 }; -static float LongPathX[7] = { -934.0, -905.0, -906.0, -1063.0, -1204.0, -1233.0, -1207.0 }; -static float LongPathY[7] = { 371.0, 362.0, 488.0, 548.0, 451.0, 346.0, 308.0 }; -static float LongPathZ[7] = { 57.0, 90.0, 105.0, 100.0, 81.0, 79.0, 70.0 }; - -static int PathPoint; - -void -CHeli::ProcessControl(void) -{ - int i; - - if(gbModelViewer) - return; - - // Find target - CVector target(0.0f, 0.0f, 0.0f); - CVector2D vTargetDist; - if(m_heliType == HELI_TYPE_CATALINA && m_heliStatus != HELI_STATUS_SHOT_DOWN){ - switch(m_pathState){ - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - target.x = CatalinaTargetX[m_pathState]; - target.y = CatalinaTargetY[m_pathState]; - target.z = CatalinaTargetZ[m_pathState]; - if((target - GetPosition()).Magnitude() < 9.0f) - m_pathState++; - break; - case 6: - target.x = CatalinaTargetX[m_pathState]; - target.y = CatalinaTargetY[m_pathState]; - target.z = CatalinaTargetZ[m_pathState]; - if(GetPosition().z > 31.55f) - break; - m_pathState = 7; - GetPosition().z = 31.55f; - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - break; - case 7: - GetPosition().z = 31.55f; - target = GetPosition(); - break; - - - // Take off - case 8: - target.x = GetPosition().x; - target.y = GetPosition().y; - target.z = 74.0f; - if(GetPosition().z < 40.0f) - break; - PathPoint = 2; - m_pathState = 9; - break; - // Circle around dam - case 9: - target.x = DamPathX[PathPoint]; - target.y = DamPathY[PathPoint]; - target.z = DamPathZ[PathPoint]; - if((target - GetPosition()).Magnitude() < 9.0f){ - PathPoint++; - if(PathPoint >= 6){ - m_pathState = 10; - PathPoint = 0; - } - } - break; - case 10: - target.x = ShortPathX[PathPoint]; - target.y = ShortPathY[PathPoint]; - target.z = ShortPathZ[PathPoint]; - if((target - GetPosition()).Magnitude() < 9.0f){ - PathPoint++; - if(PathPoint >= 3){ - m_pathState = 9; - PathPoint = 1; - } - } - break; - // how do we get here? - case 11: - target.x = LongPathX[PathPoint]; - target.y = LongPathY[PathPoint]; - target.z = LongPathZ[PathPoint]; - if((target - GetPosition()).Magnitude() < 9.0f){ - PathPoint++; - if(PathPoint >= 7){ - m_pathState = 9; - PathPoint = 0; - } - } - break; - - - // Fly away - case 12: - target.x = GetPosition().x; - target.y = GetPosition().y; - target.z = 200.0f; - break; - } - - vTargetDist = target - GetPosition(); - m_fTargetZ = target.z; - if(m_pathState == 6){ - GetPosition().x = GetPosition().x*0.99f + target.x*0.01f; - GetPosition().y = GetPosition().y*0.99f + target.y*0.01f; - } - }else{ - vTargetDist = FindPlayerCoors() - GetPosition(); - m_fTargetZ = FindPlayerCoors().z; - - // Heli flies away to (0, 0) - if(m_heliStatus == HELI_STATUS_FLY_AWAY && GetPosition().z > 20.0f){ - vTargetDist.x = 0.0f - GetPosition().x; - vTargetDist.y = 0.0f - GetPosition().y; - } - - float groundZ; - switch(m_heliStatus){ - case HELI_STATUS_HOVER: - groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f; - break; - case HELI_STATUS_SHOT_DOWN: - groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; - break; - case HELI_STATUS_HOVER2: - groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; - break; - default: - groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 12.0f; - break; - } - - // Move up if too low - if(GetPosition().z - 2.0f < groundZ && m_heliStatus != HELI_STATUS_SHOT_DOWN) - m_vecMoveSpeed.z += CTimer::GetTimeStep()*0.01f; - m_vecMoveSpeed.z = clamp(m_vecMoveSpeed.z, -0.3f, 0.3f); - } - - float fTargetDist = vTargetDist.Magnitude(); - - switch(m_heliStatus){ - case HELI_STATUS_HOVER: - case HELI_STATUS_HOVER2:{ - float targetHeight; - if(m_heliType == HELI_TYPE_CATALINA) - targetHeight = 8.0f; - else - targetHeight = 40.0f - m_nHeliId*10.0f; - if(fTargetDist > targetHeight) - m_heliStatus = HELI_STATUS_CHASE_PLAYER; - } - // fall through, BUG? - case HELI_STATUS_CHASE_PLAYER:{ - float targetHeight; - if(m_heliType == HELI_TYPE_CATALINA) - targetHeight = 4.0f; - else - targetHeight = 30.0f - m_nHeliId*7.5f; - if(fTargetDist < 1.0f || - fTargetDist < targetHeight && CWorld::GetIsLineOfSightClear(GetPosition(), FindPlayerCoors(), true, false, false, false, false, false)) - m_heliStatus = HELI_STATUS_HOVER; - } - } - - // Find xy speed - float speed; - if(fTargetDist > 100.0f) - speed = 1.0f; - else if(fTargetDist > 75.0f) - speed = 0.7f; - else - speed = 0.4f; - if(m_heliStatus == HELI_STATUS_HOVER || m_heliStatus == HELI_STATUS_HOVER2 || m_heliStatus == HELI_STATUS_SHOT_DOWN) - speed = 0.0f; - - if(fTargetDist != 0.0f) - vTargetDist /= fTargetDist; - else - vTargetDist.x = 1.0f; - CVector2D targetSpeed = vTargetDist * speed; - - if(m_heliStatus == HELI_STATUS_HOVER2 || m_heliStatus == HELI_STATUS_SHOT_DOWN){ - bool force = !!((CTimer::GetFrameCounter() + m_randomSeed) & 8); - if(m_bTestRight){ - if(force || CWorld::TestSphereAgainstWorld(GetPosition() + 4.0f*GetRight(), 2.0f, this, true, false, false, false, false, false) == nil){ - if(m_heliStatus == HELI_STATUS_SHOT_DOWN){ - m_fTargetOffset -= CTimer::GetTimeStep()*0.05f; - targetSpeed.x -= -vTargetDist.x*0.15f; - targetSpeed.y -= vTargetDist.y*0.15f; - }else{ - targetSpeed.x -= -vTargetDist.x*0.05f; - targetSpeed.y -= vTargetDist.y*0.05f; - } - }else{ - m_bTestRight = false; - if(m_heliStatus == HELI_STATUS_HOVER2) - m_fTargetOffset += 5.0f; - else - m_fTargetOffset -= 5.0f; - } - }else{ - if(force || CWorld::TestSphereAgainstWorld(GetPosition() - 4.0f*GetRight(), 2.0f, this, true, false, false, false, false, false) == nil){ - if(m_heliStatus == HELI_STATUS_SHOT_DOWN){ - m_fTargetOffset -= CTimer::GetTimeStep()*0.05f; - targetSpeed.x += -vTargetDist.x*0.15f; - targetSpeed.y += vTargetDist.y*0.15f; - }else{ - targetSpeed.x += -vTargetDist.x*0.05f; - targetSpeed.y += vTargetDist.y*0.05f; - } - }else{ - m_bTestRight = true; - if(m_heliStatus == HELI_STATUS_HOVER2) - m_fTargetOffset += 5.0f; - else - m_fTargetOffset -= 5.0f; - } - } - - if(m_fTargetOffset > 30.0f) - m_fTargetOffset = 30.0f; - - if(m_heliStatus == HELI_STATUS_SHOT_DOWN && force){ - if(CWorld::TestSphereAgainstWorld(GetPosition() + 1.5f*GetForward(), 2.0f, this, true, false, false, false, false, false) || - CWorld::TestSphereAgainstWorld(GetPosition() - 1.5f*GetForward(), 2.0f, this, true, false, false, false, false, false)) - m_nExplosionTimer = CTimer::GetPreviousTimeInMilliseconds(); - } - }else - if(m_fTargetOffset >= 2.0f) - m_fTargetOffset -= 2.0f; - - if(m_heliType == HELI_TYPE_CATALINA) - if(m_pathState == 9 || m_pathState == 11 || m_pathState == 10){ - float f = Pow(0.997f, CTimer::GetTimeStep()); - m_vecMoveSpeed.x *= f; - m_vecMoveSpeed.y *= f; - } - - CVector2D speedDir = targetSpeed - m_vecMoveSpeed; - float speedDiff = speedDir.Magnitude(); - if(speedDiff != 0.0f) - speedDir /= speedDiff; - else - speedDir.x = 1.0f; - float speedInc = CTimer::GetTimeStep()*0.002f; - if(speedDiff < speedInc){ - m_vecMoveSpeed.x = targetSpeed.x; - m_vecMoveSpeed.y = targetSpeed.y; - }else{ - m_vecMoveSpeed.x += speedDir.x*speedInc; - m_vecMoveSpeed.y += speedDir.y*speedInc; - } - GetPosition().x += m_vecMoveSpeed.x*CTimer::GetTimeStep(); - GetPosition().y += m_vecMoveSpeed.y*CTimer::GetTimeStep(); - - // Find z target - if(m_heliStatus == HELI_STATUS_FLY_AWAY) - m_fTargetZ = 1000.0f; - if((CTimer::GetTimeInMilliseconds() + 800*m_nHeliId) & 0x800) - m_fTargetZ += 2.0f; - m_fTargetZ += m_nHeliId*5.0f; - - // Find z speed - float targetSpeedZ = (m_fTargetZ - GetPosition().z)*0.01f; - float speedDiffZ = targetSpeedZ - m_vecMoveSpeed.z; - float speedIncZ = CTimer::GetTimeStep()*0.001f; - if(m_heliStatus == HELI_STATUS_FLY_AWAY) - speedIncZ *= 1.5f; - if(Abs(speedDiffZ) < speedIncZ) - m_vecMoveSpeed.z = targetSpeedZ; - else if(speedDiffZ < 0.0f) - m_vecMoveSpeed.z -= speedIncZ; - else - m_vecMoveSpeed.z += speedIncZ*1.5f; - GetPosition().z += m_vecMoveSpeed.z*CTimer::GetTimeStep(); - - // Find angular speed - float targetAngularSpeed; - m_fAngularSpeed *= Pow(0.995f, CTimer::GetTimeStep()); - if(fTargetDist < 8.0f) - targetAngularSpeed = 0.0f; - else{ - float rotationDiff = CGeneral::GetATanOfXY(vTargetDist.x, vTargetDist.y) - m_fRotation; - while(rotationDiff < -3.14f) rotationDiff += 6.28f; - while(rotationDiff > 3.14f) rotationDiff -= 6.28f; - if(Abs(rotationDiff) > 0.4f){ - if(rotationDiff < 0.0f) - targetAngularSpeed = -0.2f; - else - targetAngularSpeed = 0.2f; - }else - targetAngularSpeed = 0.0f; - } - float angularSpeedDiff = targetAngularSpeed - m_fAngularSpeed; - float angularSpeedInc = CTimer::GetTimeStep()*0.0001f; - if(Abs(angularSpeedDiff) < angularSpeedInc) - m_fAngularSpeed = targetAngularSpeed; - else if(angularSpeedDiff < 0.0f) - m_fAngularSpeed -= angularSpeedInc; - else - m_fAngularSpeed += angularSpeedInc; - m_fRotation += m_fAngularSpeed * CTimer::GetTimeStep(); - - // Set matrix - CVector up(3.0f*m_vecMoveSpeed.x, 3.0f*m_vecMoveSpeed.y, 1.0f); - up.Normalise(); - CVector fwd(-Cos(m_fRotation), -Sin(m_fRotation), 0.0f); // not really forward - CVector right = CrossProduct(up, fwd); - fwd = CrossProduct(up, right); - GetRight() = right; - GetForward() = fwd; - GetUp() = up; - - // Search light and shooting - if(m_heliStatus == HELI_STATUS_FLY_AWAY || m_heliType == HELI_TYPE_CATALINA || CCullZones::PlayerNoRain()) - m_fSearchLightIntensity = 0.0f; - else{ - // Update search light history once every 1000ms - int timeDiff = CTimer::GetTimeInMilliseconds() - m_nSearchLightTimer; - while(timeDiff > 1000){ - for(i = 5; i > 0; i--){ - m_aSearchLightHistoryX[i] = m_aSearchLightHistoryX[i-1]; - m_aSearchLightHistoryY[i] = m_aSearchLightHistoryY[i-1]; - } - m_aSearchLightHistoryX[0] = FindPlayerCoors().x + FindPlayerSpeed().x*50.0f*(m_nHeliId+2); - m_aSearchLightHistoryY[0] = FindPlayerCoors().y + FindPlayerSpeed().y*50.0f*(m_nHeliId+2); - - timeDiff -= 1000; - m_nSearchLightTimer += 1000; - } - assert(timeDiff <= 1000); - float f1 = timeDiff/1000.0f; - float f2 = 1.0f - f1; - m_fSearchLightX = m_aSearchLightHistoryX[m_nHeliId+2]*f2 + m_aSearchLightHistoryX[m_nHeliId+2-1]*f1; - m_fSearchLightY = m_aSearchLightHistoryY[m_nHeliId+2]*f2 + m_aSearchLightHistoryY[m_nHeliId+2-1]*f1; - - float searchLightDist = (CVector2D(m_fSearchLightX, m_fSearchLightY) - GetPosition()).Magnitude(); - if(searchLightDist > 60.0f) - m_fSearchLightIntensity = 0.0f; - else if(searchLightDist < 40.0f) - m_fSearchLightIntensity = 1.0f; - else - m_fSearchLightIntensity = 1.0f - (40.0f-searchLightDist)/40.0f; - - if(m_fSearchLightIntensity < 0.9f || sq(FindPlayerCoors().x-m_fSearchLightX) + sq(FindPlayerCoors().y-m_fSearchLightY) > sq(7.0f)) - m_nShootTimer = CTimer::GetTimeInMilliseconds(); - else if(CTimer::GetTimeInMilliseconds() > m_nPoliceShoutTimer){ - DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_HELI_PLAYER_FOUND, 0.0f); - m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds() + 4500 + (CGeneral::GetRandomNumber()&0xFFF); - } - - // Shoot - int shootTimeout; - if(m_heliType == HELI_TYPE_RANDOM){ - switch(FindPlayerPed()->m_pWanted->m_nWantedLevel){ - case 0: - case 1: - case 2: shootTimeout = 999999; break; - case 3: shootTimeout = 10000; break; - case 4: shootTimeout = 5000; break; - case 5: shootTimeout = 3500; break; - case 6: shootTimeout = 2000; break; - } - if(CCullZones::NoPolice()) - shootTimeout /= 2; - }else - shootTimeout = 1500; - - if(FindPlayerPed()->m_pWanted->IsIgnored()) - m_nShootTimer = CTimer::GetTimeInMilliseconds(); - else{ - // Check if line of sight is clear - if(CTimer::GetTimeInMilliseconds() > m_nShootTimer + shootTimeout && - CTimer::GetPreviousTimeInMilliseconds() <= m_nShootTimer + shootTimeout){ - if(CWorld::GetIsLineOfSightClear(GetPosition(), FindPlayerCoors(), true, false, false, false, false, false)){ - if(m_heliStatus == HELI_STATUS_HOVER2) - m_heliStatus = HELI_STATUS_HOVER; - }else{ - m_nShootTimer = CTimer::GetTimeInMilliseconds(); - if(m_heliStatus == HELI_STATUS_HOVER) - m_heliStatus = HELI_STATUS_HOVER2; - } - } - - // Shoot! - if(CTimer::GetTimeInMilliseconds() > m_nShootTimer + shootTimeout && - CTimer::GetTimeInMilliseconds() > m_nLastShotTime + 200){ - CVector shotTarget = FindPlayerCoors(); - // some inaccuracy - shotTarget.x += ((CGeneral::GetRandomNumber()&0xFF)-128)/50.0f; - shotTarget.y += ((CGeneral::GetRandomNumber()&0xFF)-128)/50.0f; - CVector direction = FindPlayerCoors() - GetPosition(); - direction.Normalise(); - shotTarget += 3.0f*direction; - CVector shotSource = GetPosition(); - shotSource += 3.0f*direction; - FireOneInstantHitRound(&shotSource, &shotTarget, 20); - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_SHOT_FIRED, 0.0f); - m_nLastShotTime = CTimer::GetTimeInMilliseconds(); - } - } - } - - // Drop Catalina's bombs - if(m_heliType == HELI_TYPE_CATALINA && m_pathState > 8 && (CTimer::GetTimeInMilliseconds()>>9) != (CTimer::GetPreviousTimeInMilliseconds()>>9)){ - CVector bombPos = GetPosition() - 60.0f*m_vecMoveSpeed; - if(sq(FindPlayerCoors().x-bombPos.x) + sq(FindPlayerCoors().y-bombPos.y) < sq(35.0f)){ - bool found; - float groundZ = CWorld::FindGroundZFor3DCoord(bombPos.x, bombPos.y, bombPos.z, &found); - float waterZ; - if(!CWaterLevel::GetWaterLevelNoWaves(bombPos.x, bombPos.y, bombPos.z, &waterZ)) - waterZ = 0.0f; - if(groundZ > waterZ){ - bombPos.z = groundZ + 2.0f; - CExplosion::AddExplosion(nil, this, EXPLOSION_HELI_BOMB, bombPos, 0); - }else{ - bombPos.z = waterZ; - CVector dir; - for(i = 0; i < 16; i++){ - dir.x = ((CGeneral::GetRandomNumber()&0xFF)-127)*0.001f; - dir.y = ((CGeneral::GetRandomNumber()&0xFF)-127)*0.001f; - dir.z = 0.5f; - CParticle::AddParticle(PARTICLE_BOAT_SPLASH, bombPos, dir, nil, 0.2f); - } - } - } - } - - RemoveAndAdd(); - bIsInSafePosition = true; - GetMatrix().UpdateRW(); - UpdateRwFrame(); -} - -void -CHeli::PreRender(void) -{ - float angle; - uint8 i; - CColPoint point; - CEntity *entity; - uint8 r, g, b; - float testLowZ = FindPlayerCoors().z - 10.0f; - float radius = (GetPosition().z - FindPlayerCoors().z - 10.0f - 1.0f) * 0.3f + 10.0f; - int frm = CTimer::GetFrameCounter() & 7; - - i = 0; - for(angle = 0.0f; angle < TWOPI; angle += TWOPI/32){ - CVector pos(radius*Cos(angle), radius*Sin(angle), 0.0f); - CVector dir = pos*0.01f; - pos += GetPosition(); - - if(CWorld::ProcessVerticalLine(pos, testLowZ, point, entity, true, false, false, false, true, false, nil)) - m_fHeliDustZ[frm] = point.point.z; - else - m_fHeliDustZ[frm] = -101.0f; - - switch(point.surfaceB){ - default: - case SURFACE_TARMAC: - r = 10; - g = 10; - b = 10; - break; - case SURFACE_GRASS: - r = 10; - g = 6; - b = 3; - break; - case SURFACE_DIRT: - r = 10; - g = 8; - b = 7; - break; - case SURFACE_DIRTTRACK: - r = 10; - g = 6; - b = 3; - break; - } - RwRGBA col = { r, g, b, 32 }; - pos.z = m_fHeliDustZ[(i - (i&3))/4]; // advance every 4 iterations, why not just /4? - if(pos.z > -200.0f && GetPosition().z - pos.z < 20.0f) - CParticle::AddParticle(PARTICLE_HELI_DUST, pos, dir, nil, 0.0f, col); - i++; - } -} - -void -CHeli::Render(void) -{ - CMatrix mat; - CVector pos; - - mat.Attach(RwFrameGetMatrix(m_aHeliNodes[HELI_TOPROTOR])); - pos = mat.GetPosition(); - mat.SetRotateZ(m_fRotorRotation); - mat.Translate(pos); - mat.UpdateRW(); - - m_fRotorRotation += 3.14f/6.5f; - if(m_fRotorRotation > 6.28f) - m_fRotorRotation -= 6.28f; - - mat.Attach(RwFrameGetMatrix(m_aHeliNodes[HELI_BACKROTOR])); - pos = mat.GetPosition(); - mat.SetRotateX(m_fRotorRotation); - mat.Translate(pos); - mat.UpdateRW(); - - CEntity::Render(); -} - -void -CHeli::PreRenderAlways(void) -{ - CVector shadowPos(m_fSearchLightX, m_fSearchLightY, GetPosition().z); - if(m_fSearchLightIntensity > 0.0f){ - CShadows::StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &shadowPos, - 6.0f, 0.0f, 0.0f, -6.0f, - 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, 80*m_fSearchLightIntensity, - 50.0f, true, 1.0f); - - CVector front = GetMatrix() * CVector(0.0f, 7.0f, 0.0f); - CVector toPlayer = FindPlayerCoors() - front; - toPlayer.Normalise(); - float intensity = m_fSearchLightIntensity*sq(CTimeCycle::GetSpriteBrightness()); - if(DotProduct(toPlayer, TheCamera.GetForward()) < -0.8f) - CCoronas::RegisterCorona((uintptr)this, 255*intensity, 255*intensity, 255*intensity, 255, - front, 10.0f, 60.0f, CCoronas::TYPE_STAR, - CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::RegisterCorona((uintptr)this, 200*intensity, 200*intensity, 200*intensity, 255, - front, 8.0f, 60.0f, CCoronas::TYPE_STAR, - CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - } - - CVector back = GetMatrix() * CVector(0.0f, -9.0f, 0.0f); - if(CTimer::GetTimeInMilliseconds() & 0x100) - CCoronas::RegisterCorona((uintptr)this + 2, 255, 0, 0, 255, - back, 1.0f, 60.0f, CCoronas::TYPE_STAR, - CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::RegisterCorona((uintptr)this + 2, 0, 0, 0, 255, - back, 1.0f, 60.0f, CCoronas::TYPE_STAR, - CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); -} - -RwObject* -GetHeliAtomicObjectCB(RwObject *object, void *data) -{ - RpAtomic *atomic = (RpAtomic*)object; - assert(RwObjectGetType(object) == rpATOMIC); - if(RpAtomicGetFlags(atomic) & rpATOMICRENDER) - *(RpAtomic**)data = atomic; - return object; -} - -CObject* -CHeli::SpawnFlyingComponent(int32 component) -{ - RpAtomic *atomic; - RwFrame *frame; - RwMatrix *matrix; - CObject *obj; - - if(m_aHeliNodes[component] == nil) - return nil; - - atomic = nil; - RwFrameForAllObjects(m_aHeliNodes[component], GetHeliAtomicObjectCB, &atomic); - if(atomic == nil) - return nil; - - obj = new CObject; - if(obj == nil) - return nil; - - obj->SetModelIndexNoCreate(MI_CAR_WHEEL); - // object needs base model - obj->RefModelInfo(GetModelIndex()); - - // create new atomic - matrix = RwFrameGetLTM(m_aHeliNodes[component]); - frame = RwFrameCreate(); - atomic = RpAtomicClone(atomic); - *RwFrameGetMatrix(frame) = *matrix; - RpAtomicSetFrame(atomic, frame); - CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); - obj->AttachToRwObject((RwObject*)atomic); - - // init object - obj->m_fMass = 10.0f; - obj->m_fTurnMass = 25.0f; - obj->m_fAirResistance = 0.99f; - obj->m_fElasticity = 0.1f; - obj->m_fBuoyancy = obj->m_fMass*GRAVITY/0.75f; - obj->ObjectCreatedBy = TEMP_OBJECT; - obj->bIsStatic = false; - obj->bIsPickup = false; - - // life time - CObject::nNoTempObjects++; - if(component == HELI_TOPROTOR) - obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 1000; - else - obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 3000; - - obj->m_vecMoveSpeed = m_vecMoveSpeed; - if(obj->m_vecMoveSpeed.z > 0.0f) - obj->m_vecMoveSpeed.z = 0.3f; - else - obj->m_vecMoveSpeed.z = 0.0f; - - obj->m_vecTurnSpeed = m_vecTurnSpeed*2.0f; - - if(component == HELI_BACKROTOR) - obj->m_vecTurnSpeed.x = 0.5f; - else if(component == HELI_TOPROTOR || component == HELI_TOPKNOT) - obj->m_vecTurnSpeed.z = 0.5f; - else - obj->m_vecTurnSpeed.y = 0.5f; - - obj->bRenderScorched = true; - - CWorld::Add(obj); - - atomic = nil; - RwFrameForAllObjects(m_aHeliNodes[component], GetHeliAtomicObjectCB, &atomic); - if(atomic) - RpAtomicSetFlags(atomic, 0); - - return obj; -} - - - -void -CHeli::InitHelis(void) -{ - int i; - - NumRandomHelis = 0; - TestForNewRandomHelisTimer = 0; - NumScriptHelis = 0; - CatalinaHeliOn = false; - ScriptHeliOn = false; - for(i = 0; i < NUM_HELIS; i++) - pHelis[i] = nil; - - ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_ESCAPE))->SetColModel(&CTempColModels::ms_colModelPed1); - ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&CTempColModels::ms_colModelPed1); -} - -CHeli* -GenerateHeli(bool catalina) -{ - CHeli *heli; - CVector heliPos; - int i; - - if(catalina) - heli = new CHeli(MI_ESCAPE, PERMANENT_VEHICLE); - else - heli = new CHeli(MI_CHOPPER, PERMANENT_VEHICLE); - - if(catalina) - heliPos = CVector(-224.0f, 201.0f, 83.0f); - else{ - heliPos = FindPlayerCoors(); - float angle = (float)(CGeneral::GetRandomNumber() & 0xFF)/0xFF * 6.28f; - heliPos.x += 250.0f*Sin(angle); - heliPos.y += 250.0f*Cos(angle); - if(heliPos.x < -2000.0f || heliPos.x > 2000.0f || heliPos.y < -2000.0f || heliPos.y > 2000.0f){ - // directly above player - heliPos.x -= 250.0f*Sin(angle); - heliPos.y -= 250.0f*Cos(angle); - } - heliPos.z += 50.0f; - } - heli->GetMatrix().SetTranslate(heliPos); - if(catalina) - heli->GetMatrix().SetRotateZOnly(DEGTORAD(270.0f)); // game actually uses 3.14 here - - heli->m_status = STATUS_ABANDONED; - - int id = -1; - bool found = false; - while(!found){ - id++; - found = true; - for(i = 0; i < 4; i++) - if(CHeli::pHelis[i] && CHeli::pHelis[i]->m_nHeliId == id) - found = false; - } - heli->m_nHeliId = id; - - CWorld::Add(heli); - - return heli; -} - -void -CHeli::UpdateHelis(void) -{ - int i, j; - - // Spawn new police helis - int numHelisRequired = FindPlayerPed()->m_pWanted->NumOfHelisRequired(); - if(CStreaming::HasModelLoaded(MI_CHOPPER) && CTimer::GetTimeInMilliseconds() > TestForNewRandomHelisTimer){ - // Spawn a police heli - TestForNewRandomHelisTimer = CTimer::GetTimeInMilliseconds() + 15000; - if(NumRandomHelis < numHelisRequired){ - NumRandomHelis++; - CHeli *heli = GenerateHeli(false); - heli->m_heliType = HELI_TYPE_RANDOM; - if(pHelis[HELI_RANDOM0] == nil) - pHelis[HELI_RANDOM0] = heli; - else if(pHelis[HELI_RANDOM1] == nil) - pHelis[HELI_RANDOM1] = heli; - else - assert(0 && "too many helis"); - } - } - - // Handle script heli - if(ScriptHeliOn){ - if(CStreaming::HasModelLoaded(MI_CHOPPER) && pHelis[HELI_SCRIPT] == nil){ - pHelis[HELI_SCRIPT] = GenerateHeli(false); - pHelis[HELI_SCRIPT]->m_heliType = HELI_TYPE_SCRIPT; - }else - CStreaming::RequestModel(MI_CHOPPER, 0); - }else{ - if(pHelis[HELI_SCRIPT]) - pHelis[HELI_SCRIPT]->m_heliStatus = HELI_STATUS_FLY_AWAY; - } - - // Handle Catalina's heli - if(CatalinaHeliOn){ - if(CStreaming::HasModelLoaded(MI_ESCAPE) && pHelis[HELI_CATALINA] == nil){ - pHelis[HELI_CATALINA] = GenerateHeli(true); - pHelis[HELI_CATALINA]->m_heliType = HELI_TYPE_CATALINA; - }else - CStreaming::RequestModel(MI_ESCAPE, STREAMFLAGS_DONT_REMOVE); - }else{ - if(pHelis[HELI_CATALINA]) - pHelis[HELI_CATALINA]->m_heliStatus = HELI_STATUS_FLY_AWAY; - } - - // Delete helis that we no longer need - for(i = 0; i < NUM_HELIS; i++) - if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_FLY_AWAY && pHelis[i]->GetPosition().z > 150.0f){ - CWorld::Remove(pHelis[i]); - delete pHelis[i]; - pHelis[i] = nil; - if(i != HELI_SCRIPT && i != HELI_CATALINA) - NumRandomHelis--; - } - - // Handle explosions - for(i = 0; i < NUM_HELIS; i++){ - if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_SHOT_DOWN && CTimer::GetTimeInMilliseconds() > pHelis[i]->m_nExplosionTimer){ - // Second part of explosion - static int nFrameGen; - CRGBA colors[8]; - - TheCamera.CamShake(0.7f, pHelis[i]->GetPosition().x, pHelis[i]->GetPosition().y, pHelis[i]->GetPosition().z); - - colors[0] = CRGBA(0, 0, 0, 255); - colors[1] = CRGBA(224, 230, 238, 255); - colors[2] = CRGBA(0, 0, 0, 255); - colors[3] = CRGBA(0, 0, 0, 255); - colors[4] = CRGBA(66, 162, 252, 255); - colors[5] = CRGBA(0, 0, 0, 255); - colors[6] = CRGBA(0, 0, 0, 255); - colors[7] = CRGBA(0, 0, 0, 255); - - CVector pos = pHelis[i]->GetPosition(); - CVector dir; - for(j = 0; j < 40; j++){ - dir.x = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); - dir.y = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); - dir.z = CGeneral::GetRandomNumberInRange(0.0f, 2.0f); - int rotSpeed = CGeneral::GetRandomNumberInRange(10, 30); - if(CGeneral::GetRandomNumber() & 1) - rotSpeed = -rotSpeed; - int f = ++nFrameGen & 3; - CParticle::AddParticle(PARTICLE_HELI_DEBRIS, pos, dir, - nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), - colors[nFrameGen], rotSpeed, 0, f, 0); - } - - CExplosion::AddExplosion(nil, nil, EXPLOSION_HELI, pos, 0); - - pHelis[i]->SpawnFlyingComponent(HELI_SKID_LEFT); - pHelis[i]->SpawnFlyingComponent(HELI_SKID_RIGHT); - pHelis[i]->SpawnFlyingComponent(HELI_TOPROTOR); - - CDarkel::RegisterCarBlownUpByPlayer(pHelis[i]); - CWorld::Remove(pHelis[i]); - delete pHelis[i]; - pHelis[i] = nil; - if(i != HELI_SCRIPT && i != HELI_CATALINA) - NumRandomHelis--; - if(i == HELI_CATALINA) - CatalinaHasBeenShotDown = true; - - CStats::HelisDestroyed++; - CStats::PeopleKilledByOthers += 2; - CStats::PedsKilledOfThisType[PEDTYPE_COP] += 2; - CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 250; - pos = CWorld::Players[CWorld::PlayerInFocus].m_pPed->GetPosition(); - CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->RegisterCrime_Immediately(CRIME_SHOOT_HELI, - pos, i + 19843, false); - - TestForNewRandomHelisTimer = CTimer::GetTimeInMilliseconds() + 50000; - }else if(pHelis[i] && pHelis[i]->m_heliStatus == HELI_STATUS_SHOT_DOWN && CTimer::GetTimeInMilliseconds()+7000 > pHelis[i]->m_nExplosionTimer){ - // First part of explosion - if(CTimer::GetPreviousTimeInMilliseconds()+7000 < pHelis[i]->m_nExplosionTimer){ - pHelis[i]->SpawnFlyingComponent(HELI_BACKROTOR); - pHelis[i]->SpawnFlyingComponent(HELI_TAIL); - pHelis[i]->m_fAngularSpeed *= -2.5f; - pHelis[i]->bRenderScorched = true; - - TheCamera.CamShake(0.4f, pHelis[i]->GetPosition().x, pHelis[i]->GetPosition().y, pHelis[i]->GetPosition().z); - - CVector pos = pHelis[i]->GetPosition() - 2.5f*pHelis[i]->GetUp(); - CExplosion::AddExplosion(nil, nil, EXPLOSION_HELI, pos, 0); - }else - pHelis[i]->m_fAngularSpeed *= 1.03f; - } - } - - // Find police helis to remove - for(i = 0; i < 2; i++) - if(pHelis[i] && pHelis[i]->m_heliStatus != HELI_STATUS_FLY_AWAY){ - if(numHelisRequired > 0) - numHelisRequired--; - else - pHelis[i]->m_heliStatus = HELI_STATUS_FLY_AWAY; - } - - // Remove all helis if in a tunnel - if(FindPlayerCoors().z < - 2.0f) - for(i = 0; i < NUM_HELIS; i++) - if(pHelis[i] && pHelis[i]->m_heliStatus != HELI_STATUS_SHOT_DOWN) - pHelis[i]->m_heliStatus = HELI_STATUS_FLY_AWAY; -} - -void -CHeli::SpecialHeliPreRender(void) -{ - int i; - for(i = 0; i < NUM_HELIS; i++) - if(pHelis[i]) - pHelis[i]->PreRenderAlways(); -} - -bool -CHeli::TestRocketCollision(CVector *rocketPos) -{ - int i; - bool hit = false; - - for(i = 0; i < NUM_HELIS; i++){ - if(pHelis[i] && !pHelis[i]->bExplosionProof && (*rocketPos - pHelis[i]->GetPosition()).MagnitudeSqr() < sq(8.0f)){ - pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; - pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; - pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; - hit = true; - } - } - return hit; -} - -bool -CHeli::TestBulletCollision(CVector *line0, CVector *line1, CVector *bulletPos, int32 damage) -{ - int i; - bool hit = false; - - for(i = 0; i < NUM_HELIS; i++) - if(pHelis[i] && !pHelis[i]->bBulletProof && CCollision::DistToLine(line0, line1, &pHelis[i]->GetPosition()) < 5.0f){ - // Find bullet position - float distToHeli = (pHelis[i]->GetPosition() - *line0).Magnitude(); - CVector line = (*line1 - *line0); - float lineLength = line.Magnitude(); - *bulletPos = *line0 + line*max(1.0f, distToHeli-5.0f); - - pHelis[i]->m_nBulletDamage += damage; - - if(pHelis[i]->m_heliType == HELI_CATALINA && pHelis[i]->m_nBulletDamage > 400 || - pHelis[i]->m_heliType != HELI_CATALINA && pHelis[i]->m_nBulletDamage > 700){ - pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; - pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; - pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; - } - - hit = true; - } - return hit; -} - -void CHeli::StartCatalinaFlyBy(void) -{ - CatalinaHeliOn = true; - CatalinaHasBeenShotDown = false; -} - -void -CHeli::RemoveCatalinaHeli(void) -{ - CatalinaHeliOn = false; - if(pHelis[HELI_CATALINA]){ - CWorld::Remove(pHelis[HELI_CATALINA]); - delete pHelis[HELI_CATALINA]; - pHelis[HELI_CATALINA] = nil; - } -} - -CHeli *CHeli::FindPointerToCatalinasHeli(void) { return pHelis[HELI_CATALINA]; } -void CHeli::CatalinaTakeOff(void) { pHelis[HELI_CATALINA]->m_pathState = 8; } -void CHeli::MakeCatalinaHeliFlyAway(void) { pHelis[HELI_CATALINA]->m_pathState = 12; } -bool CHeli::HasCatalinaBeenShotDown(void) { return CatalinaHasBeenShotDown; } - -void CHeli::ActivateHeli(bool activate) { ScriptHeliOn = activate; } - - -class CHeli_ : public CHeli -{ -public: - void ctor(int32 id, uint8 CreatedBy) { ::new (this) CHeli(id, CreatedBy); } - void dtor(void) { CHeli::~CHeli(); } -}; - -STARTPATCHES - InjectHook(0x547220, &CHeli_::ctor, PATCH_JUMP); - InjectHook(0x5474A0, &CHeli_::dtor, PATCH_JUMP); - InjectHook(0x54AE50, &CHeli::SpawnFlyingComponent, PATCH_JUMP); - InjectHook(0x549970, CHeli::InitHelis, PATCH_JUMP); - InjectHook(0x5499F0, CHeli::UpdateHelis, PATCH_JUMP); - InjectHook(0x54AE10, CHeli::SpecialHeliPreRender, PATCH_JUMP); - InjectHook(0x54AA30, CHeli::TestRocketCollision, PATCH_JUMP); - InjectHook(0x54AB30, CHeli::TestBulletCollision, PATCH_JUMP); - InjectHook(0x54A640, GenerateHeli, PATCH_JUMP); -ENDPATCHES diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 771f36e1..775cf572 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -968,16 +968,8 @@ bool CPlane::HasDropOffCesnaBeenShotDown(void) { return DropOffCesnaMissionStatu class CPlane_ : public CPlane { public: -<<<<<<< HEAD -<<<<<<< HEAD void ctor(int32 id, uint8 CreatedBy) { ::new (this) CPlane(id, CreatedBy); } void dtor(void) { CPlane::~CPlane(); } -======= - void dtor(void) { this->~CPlane(); } ->>>>>>> More audio ped -======= - void dtor(void) { CPlane::~CPlane(); } ->>>>>>> fix }; STARTPATCHES diff --git a/src/vehicles/Plane.cpp.autosave b/src/vehicles/Plane.cpp.autosave deleted file mode 100644 index 775cf572..00000000 --- a/src/vehicles/Plane.cpp.autosave +++ /dev/null @@ -1,985 +0,0 @@ -#include "common.h" -#include "main.h" -#include "patcher.h" -#include "General.h" -#include "ModelIndices.h" -#include "FileMgr.h" -#include "Streaming.h" -#include "Replay.h" -#include "Camera.h" -#include "Coronas.h" -#include "Particle.h" -#include "Explosion.h" -#include "World.h" -#include "HandlingMgr.h" -#include "Plane.h" - -CPlaneNode *&pPathNodes = *(CPlaneNode**)0x8F1B68; -CPlaneNode *&pPath2Nodes = *(CPlaneNode**)0x885B8C; -CPlaneNode *&pPath3Nodes = *(CPlaneNode**)0x885B78; -CPlaneNode *&pPath4Nodes = *(CPlaneNode**)0x885AD8; -int32 &NumPathNodes = *(int32*)0x8F2BE4; -int32 &NumPath2Nodes = *(int32*)0x941498; -int32 &NumPath3Nodes = *(int32*)0x9414D8; -int32 &NumPath4Nodes = *(int32*)0x9412C8; -float &TotalLengthOfFlightPath = *(float*)0x8F2C6C; -float &TotalLengthOfFlightPath2 = *(float*)0x64CFBC; -float &TotalLengthOfFlightPath3 = *(float*)0x64CFD0; -float &TotalLengthOfFlightPath4 = *(float*)0x64CFDC; -float &TotalDurationOfFlightPath = *(float*)0x64CFB8; -float &TotalDurationOfFlightPath2 = *(float*)0x64CFC0; -float &TotalDurationOfFlightPath3 = *(float*)0x64CFD4; -float &TotalDurationOfFlightPath4 = *(float*)0x64CFE0; -float &LandingPoint = *(float*)0x8F2C7C; -float &TakeOffPoint = *(float*)0x8E28A4; -CPlaneInterpolationLine *aPlaneLineBits = (CPlaneInterpolationLine*)0x734168; //[6] - -float *PlanePathPosition = (float*)0x8F5FC8; //[3] -float *OldPlanePathPosition = (float*)0x8F5FBC; //[3] -float *PlanePathSpeed = (float*)0x941538; //[3] -float *PlanePath2Position = (float*)0x64CFC4; //[3] -float &PlanePath3Position = *(float*)0x64CFD8; -float &PlanePath4Position = *(float*)0x64CFE4; -float *PlanePath2Speed = (float*)0x8F1A54; //[3] -float &PlanePath3Speed = *(float*)0x8F1A94; -float &PlanePath4Speed = *(float*)0x8F1AFC; - - -enum -{ - CESNA_STATUS_NONE, // doesn't even exist - CESNA_STATUS_FLYING, - CESNA_STATUS_DESTROYED, - CESNA_STATUS_LANDED, -}; - -int32 &CesnaMissionStatus = *(int32*)0x64CFE8; -int32 &CesnaMissionStartTime = *(int32*)0x64CFEC; -CPlane *&pDrugRunCesna = *(CPlane**)0x8F5F80; -int32 &DropOffCesnaMissionStatus = *(int32*)0x64CFF0; -int32 &DropOffCesnaMissionStartTime = *(int32*)0x64CFF4; -CPlane *&pDropOffCesna = *(CPlane**)0x8E2A38; - - -CPlane::CPlane(int32 id, uint8 CreatedBy) - : CVehicle(CreatedBy) -{ - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); - m_vehType = VEHICLE_TYPE_PLANE; - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); - SetModelIndex(id); - - m_fMass = 100000000.0f; - m_fTurnMass = 100000000.0f; - m_fAirResistance = 0.9994f; - m_fElasticity = 0.05f; - - bUsesCollision = false; - m_bHasBeenHit = false; - m_bIsDrugRunCesna = false; - m_bIsDropOffCesna = false; - - m_status = STATUS_PLANE; - bIsBIGBuilding = true; - m_level = LEVEL_NONE; -} - -CPlane::~CPlane() -{ - DeleteRwObject(); -} - -void -CPlane::SetModelIndex(uint32 id) -{ - CVehicle::SetModelIndex(id); -} - -void -CPlane::DeleteRwObject(void) -{ - if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ - m_matrix.Detach(); - if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check - RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); - RpAtomicDestroy((RpAtomic*)m_rwObject); - RwFrameDestroy(f); - } - m_rwObject = nil; - } - CEntity::DeleteRwObject(); -} - -// There's a LOT of copy and paste in here. Maybe this could be refactored somehow -void -CPlane::ProcessControl(void) -{ - int i; - CVector pos; - - // Explosion - if(m_bHasBeenHit){ - // BUG: since this is all based on frames, you can skip the explosion processing when you go into the menu - if(GetModelIndex() == MI_AIRTRAIN){ - int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; - if(frm == 20){ - static int nFrameGen; - CRGBA colors[8]; - - CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), 0); - - colors[0] = CRGBA(0, 0, 0, 255); - colors[1] = CRGBA(224, 230, 238, 255); - colors[2] = CRGBA(224, 230, 238, 255); - colors[3] = CRGBA(0, 0, 0, 255); - colors[4] = CRGBA(224, 230, 238, 255); - colors[5] = CRGBA(0, 0, 0, 255); - colors[6] = CRGBA(0, 0, 0, 255); - colors[7] = CRGBA(224, 230, 238, 255); - - CVector dir; - for(i = 0; i < 40; i++){ - dir.x = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); - dir.y = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f); - dir.z = CGeneral::GetRandomNumberInRange(0.0f, 2.0f); - int rotSpeed = CGeneral::GetRandomNumberInRange(10, 30); - if(CGeneral::GetRandomNumber() & 1) - rotSpeed = -rotSpeed; - int f = ++nFrameGen & 3; - CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), dir, - nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), - colors[nFrameGen], rotSpeed, 0, f, 0); - } - } - if(frm >= 40 && frm <= 80 && frm & 1){ - if(frm & 1){ - pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; - pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; - pos.y = frm - 40; - pos = GetMatrix() * pos; - }else{ - pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; - pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.2f; - pos.y = 40 - frm; - pos = GetMatrix() * pos; - } - CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, pos, 0); - } - if(frm == 60) - bRenderScorched = true; - if(frm == 82){ - TheCamera.SetFadeColour(255, 255, 255); - TheCamera.Fade(0.0f, FADE_OUT); - TheCamera.ProcessFade(); - TheCamera.Fade(1.0f, FADE_IN); - FlagToDestroyWhenNextProcessed(); - } - }else{ - int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; - if(frm == 20){ - static int nFrameGen; - CRGBA colors[8]; - - CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), 0); - - colors[0] = CRGBA(0, 0, 0, 255); - colors[1] = CRGBA(224, 230, 238, 255); - colors[2] = CRGBA(224, 230, 238, 255); - colors[3] = CRGBA(0, 0, 0, 255); - colors[4] = CRGBA(252, 66, 66, 255); - colors[5] = CRGBA(0, 0, 0, 255); - colors[6] = CRGBA(0, 0, 0, 255); - colors[7] = CRGBA(252, 66, 66, 255); - - for(i = 0; i < 40; i++){ - int rotSpeed = CGeneral::GetRandomNumberInRange(30.0f, 20.0f); - if(CGeneral::GetRandomNumber() & 1) - rotSpeed = -rotSpeed; - int f = ++nFrameGen & 3; - CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), - CVector(CGeneral::GetRandomNumberInRange(-2.0f, 2.0f), - CGeneral::GetRandomNumberInRange(-2.0f, 2.0f), - CGeneral::GetRandomNumberInRange(0.0f, 2.0f)), - nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f), - colors[nFrameGen], rotSpeed, 0, f, 0); - } - } - if(frm >= 40 && frm <= 60 && frm & 1){ - if(frm & 1){ - pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; - pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; - pos.y = (frm - 40)*0.3f; - pos = GetMatrix() * pos; - }else{ - pos.x = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; - pos.z = ((CGeneral::GetRandomNumber() & 0x3F) - 32) * 0.1f; - pos.y = (40 - frm)*0.3f; - pos = GetMatrix() * pos; - } - CExplosion::AddExplosion(nil, FindPlayerPed(), EXPLOSION_HELI, pos, 0); - } - if(frm == 30) - bRenderScorched = true; - if(frm == 61){ - TheCamera.SetFadeColour(200, 200, 200); - TheCamera.Fade(0.0f, FADE_OUT); - TheCamera.ProcessFade(); - TheCamera.Fade(1.0f, FADE_IN); - if(m_bIsDrugRunCesna){ - CesnaMissionStatus = CESNA_STATUS_DESTROYED; - pDrugRunCesna = nil; - } - if(m_bIsDropOffCesna){ - DropOffCesnaMissionStatus = CESNA_STATUS_DESTROYED; - pDropOffCesna = nil; - } - FlagToDestroyWhenNextProcessed(); - } - } - } - - // Update plane position and speed - if(GetModelIndex() == MI_AIRTRAIN || !m_isFarAway || ((CTimer::GetFrameCounter() + m_randomSeed) & 7) == 0){ - if(GetModelIndex() == MI_AIRTRAIN){ - float pathPositionRear = PlanePathPosition[m_nPlaneId] - 30.0f; - if(pathPositionRear < 0.0f) - pathPositionRear += TotalLengthOfFlightPath; - float pathPosition = pathPositionRear + 30.0f; - - float pitch = 0.0f; - float distSinceTakeOff = pathPosition - TakeOffPoint; - if(distSinceTakeOff <= 0.0f && distSinceTakeOff > -70.0f){ - // shortly before take off - pitch = 1.0f - distSinceTakeOff/-70.0f; - }else if(distSinceTakeOff >= 0.0f && distSinceTakeOff < 100.0f){ - // shortly after take off - pitch = 1.0f - distSinceTakeOff/100.0f; - } - - float distSinceLanding = pathPosition - LandingPoint; - if(distSinceLanding <= 0.0f && distSinceLanding > -200.0f){ - // shortly before landing - pitch = 1.0f - distSinceLanding/-200.0f; - }else if(distSinceLanding >= 0.0f && distSinceLanding < 70.0f){ - // shortly after landing - pitch = 1.0f - distSinceLanding/70.0f; - } - - - // Advance current node to appropriate position - float pos1, pos2; - int nextTrackNode = m_nCurPathNode + 1; - pos1 = pPathNodes[m_nCurPathNode].t; - if(nextTrackNode < NumPathNodes) - pos2 = pPathNodes[nextTrackNode].t; - else{ - nextTrackNode = 0; - pos2 = TotalLengthOfFlightPath; - } - while(pathPositionRear < pos1 || pathPositionRear > pos2){ - m_nCurPathNode = (m_nCurPathNode+1) % NumPathNodes; - nextTrackNode = m_nCurPathNode + 1; - pos1 = pPathNodes[m_nCurPathNode].t; - if(nextTrackNode < NumPathNodes) - pos2 = pPathNodes[nextTrackNode].t; - else{ - nextTrackNode = 0; - pos2 = TotalLengthOfFlightPath; - } - } - bool bothOnGround = pPathNodes[m_nCurPathNode].bOnGround && pPathNodes[nextTrackNode].bOnGround; - if(PlanePathPosition[m_nPlaneId] >= LandingPoint && OldPlanePathPosition[m_nPlaneId] < LandingPoint) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_PLANE_ON_GROUND, 0.0f); - float dist = pPathNodes[nextTrackNode].t - pPathNodes[m_nCurPathNode].t; - if(dist < 0.0f) - dist += TotalLengthOfFlightPath; - float f = (pathPositionRear - pPathNodes[m_nCurPathNode].t)/dist; - CVector posRear = (1.0f - f)*pPathNodes[m_nCurPathNode].p + f*pPathNodes[nextTrackNode].p; - - // Same for the front - float pathPositionFront = pathPositionRear + 60.0f; - if(pathPositionFront > TotalLengthOfFlightPath) - pathPositionFront -= TotalLengthOfFlightPath; - int curPathNodeFront = m_nCurPathNode; - int nextPathNodeFront = curPathNodeFront + 1; - pos1 = pPathNodes[curPathNodeFront].t; - if(nextPathNodeFront < NumPathNodes) - pos2 = pPathNodes[nextPathNodeFront].t; - else{ - nextPathNodeFront = 0; - pos2 = TotalLengthOfFlightPath; - } - while(pathPositionFront < pos1 || pathPositionFront > pos2){ - curPathNodeFront = (curPathNodeFront+1) % NumPathNodes; - nextPathNodeFront = curPathNodeFront + 1; - pos1 = pPathNodes[curPathNodeFront].t; - if(nextPathNodeFront < NumPathNodes) - pos2 = pPathNodes[nextPathNodeFront].t; - else{ - nextPathNodeFront = 0; - pos2 = TotalLengthOfFlightPath; - } - } - dist = pPathNodes[nextPathNodeFront].t - pPathNodes[curPathNodeFront].t; - if(dist < 0.0f) - dist += TotalLengthOfFlightPath; - f = (pathPositionFront - pPathNodes[curPathNodeFront].t)/dist; - CVector posFront = (1.0f - f)*pPathNodes[curPathNodeFront].p + f*pPathNodes[nextPathNodeFront].p; - - // And for another point 60 units in front of the plane, used to calculate roll - float pathPositionFront2 = pathPositionFront + 60.0f; - if(pathPositionFront2 > TotalLengthOfFlightPath) - pathPositionFront2 -= TotalLengthOfFlightPath; - int curPathNodeFront2 = m_nCurPathNode; - int nextPathNodeFront2 = curPathNodeFront2 + 1; - pos1 = pPathNodes[curPathNodeFront2].t; - if(nextPathNodeFront2 < NumPathNodes) - pos2 = pPathNodes[nextPathNodeFront2].t; - else{ - nextPathNodeFront2 = 0; - pos2 = TotalLengthOfFlightPath; - } - while(pathPositionFront2 < pos1 || pathPositionFront2 > pos2){ - curPathNodeFront2 = (curPathNodeFront2+1) % NumPathNodes; - nextPathNodeFront2 = curPathNodeFront2 + 1; - pos1 = pPathNodes[curPathNodeFront2].t; - if(nextPathNodeFront2 < NumPathNodes) - pos2 = pPathNodes[nextPathNodeFront2].t; - else{ - nextPathNodeFront2 = 0; - pos2 = TotalLengthOfFlightPath; - } - } - dist = pPathNodes[nextPathNodeFront2].t - pPathNodes[curPathNodeFront2].t; - if(dist < 0.0f) - dist += TotalLengthOfFlightPath; - f = (pathPositionFront2 - pPathNodes[curPathNodeFront2].t)/dist; - CVector posFront2 = (1.0f - f)*pPathNodes[curPathNodeFront2].p + f*pPathNodes[nextPathNodeFront2].p; - - // Now set matrix - GetPosition() = (posRear + posFront)/2.0f; - GetPosition().z += 4.3f; - CVector fwd = posFront - posRear; - fwd.Normalise(); - if(pitch != 0.0f){ - fwd.z += 0.4f*pitch; - fwd.Normalise(); - } - CVector fwd2 = posFront2 - posRear; - fwd2.Normalise(); - CVector roll = CrossProduct(fwd, fwd2); - CVector right = CrossProduct(fwd, CVector(0.0f, 0.0f, 1.0f)); - if(!bothOnGround) - right.z += 3.0f*roll.z; - right.Normalise(); - CVector up = CrossProduct(right, fwd); - GetRight() = right; - GetUp() = up; - GetForward() = fwd; - - // Set speed - m_vecMoveSpeed = fwd*PlanePathSpeed[m_nPlaneId]/60.0f; - m_fSpeed = PlanePathSpeed[m_nPlaneId]/60.0f; - m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); - - m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f)); - }else{ - float planePathPosition; - float totalLengthOfFlightPath; - CPlaneNode *pathNodes; - float planePathSpeed; - int numPathNodes; - - if(m_bIsDrugRunCesna){ - planePathPosition = PlanePath3Position; - totalLengthOfFlightPath = TotalLengthOfFlightPath3; - pathNodes = pPath3Nodes; - planePathSpeed = PlanePath3Speed; - numPathNodes = NumPath3Nodes; - if(CesnaMissionStatus == CESNA_STATUS_LANDED){ - pDrugRunCesna = false; - FlagToDestroyWhenNextProcessed(); - } - }else if(m_bIsDropOffCesna){ - planePathPosition = PlanePath4Position; - totalLengthOfFlightPath = TotalLengthOfFlightPath4; - pathNodes = pPath4Nodes; - planePathSpeed = PlanePath4Speed; - numPathNodes = NumPath4Nodes; - if(DropOffCesnaMissionStatus == CESNA_STATUS_LANDED){ - pDropOffCesna = false; - FlagToDestroyWhenNextProcessed(); - } - }else{ - planePathPosition = PlanePath2Position[m_nPlaneId]; - totalLengthOfFlightPath = TotalLengthOfFlightPath2; - pathNodes = pPath2Nodes; - planePathSpeed = PlanePath2Speed[m_nPlaneId]; - numPathNodes = NumPath2Nodes; - } - - // Advance current node to appropriate position - float pathPositionRear = planePathPosition - 10.0f; - if(pathPositionRear < 0.0f) - pathPositionRear += totalLengthOfFlightPath; - float pos1, pos2; - int nextTrackNode = m_nCurPathNode + 1; - pos1 = pathNodes[m_nCurPathNode].t; - if(nextTrackNode < numPathNodes) - pos2 = pathNodes[nextTrackNode].t; - else{ - nextTrackNode = 0; - pos2 = totalLengthOfFlightPath; - } - while(pathPositionRear < pos1 || pathPositionRear > pos2){ - m_nCurPathNode = (m_nCurPathNode+1) % numPathNodes; - nextTrackNode = m_nCurPathNode + 1; - pos1 = pathNodes[m_nCurPathNode].t; - if(nextTrackNode < numPathNodes) - pos2 = pathNodes[nextTrackNode].t; - else{ - nextTrackNode = 0; - pos2 = totalLengthOfFlightPath; - } - } - float dist = pathNodes[nextTrackNode].t - pathNodes[m_nCurPathNode].t; - if(dist < 0.0f) - dist += totalLengthOfFlightPath; - float f = (pathPositionRear - pathNodes[m_nCurPathNode].t)/dist; - CVector posRear = (1.0f - f)*pathNodes[m_nCurPathNode].p + f*pathNodes[nextTrackNode].p; - - // Same for the front - float pathPositionFront = pathPositionRear + 20.0f; - if(pathPositionFront > totalLengthOfFlightPath) - pathPositionFront -= totalLengthOfFlightPath; - int curPathNodeFront = m_nCurPathNode; - int nextPathNodeFront = curPathNodeFront + 1; - pos1 = pathNodes[curPathNodeFront].t; - if(nextPathNodeFront < numPathNodes) - pos2 = pathNodes[nextPathNodeFront].t; - else{ - nextPathNodeFront = 0; - pos2 = totalLengthOfFlightPath; - } - while(pathPositionFront < pos1 || pathPositionFront > pos2){ - curPathNodeFront = (curPathNodeFront+1) % numPathNodes; - nextPathNodeFront = curPathNodeFront + 1; - pos1 = pathNodes[curPathNodeFront].t; - if(nextPathNodeFront < numPathNodes) - pos2 = pathNodes[nextPathNodeFront].t; - else{ - nextPathNodeFront = 0; - pos2 = totalLengthOfFlightPath; - } - } - dist = pathNodes[nextPathNodeFront].t - pathNodes[curPathNodeFront].t; - if(dist < 0.0f) - dist += totalLengthOfFlightPath; - f = (pathPositionFront - pathNodes[curPathNodeFront].t)/dist; - CVector posFront = (1.0f - f)*pathNodes[curPathNodeFront].p + f*pathNodes[nextPathNodeFront].p; - - // And for another point 60 units in front of the plane, used to calculate roll - float pathPositionFront2 = pathPositionFront + 30.0f; - if(pathPositionFront2 > totalLengthOfFlightPath) - pathPositionFront2 -= totalLengthOfFlightPath; - int curPathNodeFront2 = m_nCurPathNode; - int nextPathNodeFront2 = curPathNodeFront2 + 1; - pos1 = pathNodes[curPathNodeFront2].t; - if(nextPathNodeFront2 < numPathNodes) - pos2 = pathNodes[nextPathNodeFront2].t; - else{ - nextPathNodeFront2 = 0; - pos2 = totalLengthOfFlightPath; - } - while(pathPositionFront2 < pos1 || pathPositionFront2 > pos2){ - curPathNodeFront2 = (curPathNodeFront2+1) % numPathNodes; - nextPathNodeFront2 = curPathNodeFront2 + 1; - pos1 = pathNodes[curPathNodeFront2].t; - if(nextPathNodeFront2 < numPathNodes) - pos2 = pathNodes[nextPathNodeFront2].t; - else{ - nextPathNodeFront2 = 0; - pos2 = totalLengthOfFlightPath; - } - } - dist = pathNodes[nextPathNodeFront2].t - pathNodes[curPathNodeFront2].t; - if(dist < 0.0f) - dist += totalLengthOfFlightPath; - f = (pathPositionFront2 - pathNodes[curPathNodeFront2].t)/dist; - CVector posFront2 = (1.0f - f)*pathNodes[curPathNodeFront2].p + f*pathNodes[nextPathNodeFront2].p; - - // Now set matrix - GetPosition() = (posRear + posFront)/2.0f; - GetPosition().z += 1.0f; - CVector fwd = posFront - posRear; - fwd.Normalise(); - CVector fwd2 = posFront2 - posRear; - fwd2.Normalise(); - CVector roll = CrossProduct(fwd, fwd2); - CVector right = CrossProduct(fwd, CVector(0.0f, 0.0f, 1.0f)); - right.z += 3.0f*roll.z; - right.Normalise(); - CVector up = CrossProduct(right, fwd); - GetRight() = right; - GetUp() = up; - GetForward() = fwd; - - // Set speed - m_vecMoveSpeed = fwd*planePathSpeed/60.0f; - m_fSpeed = planePathSpeed/60.0f; - m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); - - m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f)); - } - } - - bIsInSafePosition = true; - GetMatrix().UpdateRW(); - UpdateRwFrame(); - - // Handle streaming and such - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - if(m_isFarAway){ - // Switch to LOD model - if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP){ - DeleteRwObject(); - if(mi->m_planeLodId != -1){ - m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); - if(m_rwObject) - m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); - } - } - }else if(CStreaming::HasModelLoaded(GetModelIndex())){ - if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ - // Get rid of LOD model - m_matrix.Detach(); - if(m_rwObject){ // useless check - if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check - RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); - RpAtomicDestroy((RpAtomic*)m_rwObject); - RwFrameDestroy(f); - } - m_rwObject = nil; - } - } - // Set high detail model - if(m_rwObject == nil){ - int id = GetModelIndex(); - m_modelIndex = -1; - SetModelIndex(id); - } - }else{ - CStreaming::RequestModel(GetModelIndex(), STREAMFLAGS_DEPENDENCY); - } -} - -void -CPlane::PreRender(void) -{ - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - - CVector lookVector = GetPosition() - TheCamera.GetPosition(); - float camDist = lookVector.Magnitude(); - if(camDist != 0.0f) - lookVector *= 1.0f/camDist; - else - lookVector = CVector(1.0f, 0.0f, 0.0f); - float behindness = DotProduct(lookVector, GetForward()); - - // Wing lights - if(behindness < 0.0f){ - // in front of plane - CVector lightPos = mi->m_positions[PLANE_POS_LIGHT_RIGHT]; - CVector lightR = GetMatrix() * lightPos; - CVector lightL = lightR; - lightL -= GetRight()*2.0f*lightPos.x; - - float intensity = -0.6f*behindness + 0.4f; - float size = 1.0f - behindness; - - if(behindness < -0.9f && camDist < 50.0f){ - // directly in front - CCoronas::RegisterCorona((uintptr)this + 10, 255*intensity, 255*intensity, 255*intensity, 255, - lightL, size, 240.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - CCoronas::RegisterCorona((uintptr)this + 11, 255*intensity, 255*intensity, 255*intensity, 255, - lightR, size, 240.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - }else{ - CCoronas::RegisterCorona((uintptr)this + 10, 255*intensity, 255*intensity, 255*intensity, 255, - lightL, size, 240.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - CCoronas::RegisterCorona((uintptr)this + 11, 255*intensity, 255*intensity, 255*intensity, 255, - lightR, size, 240.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - } - } - - // Tail light - if(CTimer::GetTimeInMilliseconds() & 0x200){ - CVector pos = GetMatrix() * mi->m_positions[PLANE_POS_LIGHT_TAIL]; - - CCoronas::RegisterCorona((uintptr)this + 12, 255, 0, 0, 255, - pos, 1.0f, 120.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f); - } -} - -void -CPlane::Render(void) -{ - CEntity::Render(); -} - -#define CRUISE_SPEED (50.0f) -#define TAXI_SPEED (5.0f) - -void -CPlane::InitPlanes(void) -{ - int i; - - CesnaMissionStatus = CESNA_STATUS_NONE; - - // Jumbo - if(pPathNodes == nil){ - pPathNodes = LoadPath("data\\paths\\flight.dat", NumPathNodes, TotalLengthOfFlightPath, true); - - // Figure out which nodes are on ground - CColPoint colpoint; - CEntity *entity; - for(i = 0; i < NumPathNodes; i++){ - if(CWorld::ProcessVerticalLine(pPathNodes[i].p, 1000.0f, colpoint, entity, true, false, false, false, true, false, nil)){ - pPathNodes[i].p.z = colpoint.point.z; - pPathNodes[i].bOnGround = true; - }else - pPathNodes[i].bOnGround = false; - } - - // Find lading and takeoff points - LandingPoint = -1.0f; - TakeOffPoint = -1.0f; - bool lastOnGround = pPathNodes[NumPathNodes-1].bOnGround; - for(i = 0; i < NumPathNodes; i++){ - if(pPathNodes[i].bOnGround && !lastOnGround) - LandingPoint = pPathNodes[i].t; - else if(!pPathNodes[i].bOnGround && lastOnGround) - TakeOffPoint = pPathNodes[i].t; - lastOnGround = pPathNodes[i].bOnGround; - } - - // Animation - float time = 0.0f; - float position = 0.0f; - // Start on ground with slow speed - aPlaneLineBits[0].type = 1; - aPlaneLineBits[0].time = time; - aPlaneLineBits[0].position = position; - aPlaneLineBits[0].speed = TAXI_SPEED; - aPlaneLineBits[0].acceleration = 0.0f; - float dist = (TakeOffPoint-600.0f) - position; - time += dist/TAXI_SPEED; - position += dist; - - // Accelerate to take off - aPlaneLineBits[1].type = 2; - aPlaneLineBits[1].time = time; - aPlaneLineBits[1].position = position; - aPlaneLineBits[1].speed = TAXI_SPEED; - aPlaneLineBits[1].acceleration = 33.0f/32.0f; - time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f); - position += 600.0f; - - // Fly at cruise speed - aPlaneLineBits[2].type = 1; - aPlaneLineBits[2].time = time; - aPlaneLineBits[2].position = position; - aPlaneLineBits[2].speed = CRUISE_SPEED; - aPlaneLineBits[2].acceleration = 0.0f; - dist = LandingPoint - TakeOffPoint; - time += dist/CRUISE_SPEED; - position += dist; - - // Brake after landing - aPlaneLineBits[3].type = 2; - aPlaneLineBits[3].time = time; - aPlaneLineBits[3].position = position; - aPlaneLineBits[3].speed = CRUISE_SPEED; - aPlaneLineBits[3].acceleration = -33.0f/32.0f; - time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f); - position += 600.0f; - - // Taxi - aPlaneLineBits[4].type = 1; - aPlaneLineBits[4].time = time; - aPlaneLineBits[4].position = position; - aPlaneLineBits[4].speed = TAXI_SPEED; - aPlaneLineBits[4].acceleration = 0.0f; - time += (TotalLengthOfFlightPath - position)/TAXI_SPEED; - - // end - aPlaneLineBits[5].time = time; - TotalDurationOfFlightPath = time; - } - - // Dodo - if(pPath2Nodes == nil){ - pPath2Nodes = LoadPath("data\\paths\\flight2.dat", NumPath2Nodes, TotalLengthOfFlightPath2, true); - TotalDurationOfFlightPath2 = TotalLengthOfFlightPath2/CRUISE_SPEED; - } - - // Mission Cesna - if(pPath3Nodes == nil){ - pPath3Nodes = LoadPath("data\\paths\\flight3.dat", NumPath3Nodes, TotalLengthOfFlightPath3, false); - TotalDurationOfFlightPath3 = TotalLengthOfFlightPath3/CRUISE_SPEED; - } - - // Mission Cesna - if(pPath4Nodes == nil){ - pPath4Nodes = LoadPath("data\\paths\\flight4.dat", NumPath4Nodes, TotalLengthOfFlightPath4, false); - TotalDurationOfFlightPath4 = TotalLengthOfFlightPath4/CRUISE_SPEED; - } - - CStreaming::LoadAllRequestedModels(false); - CStreaming::RequestModel(MI_AIRTRAIN, 0); - CStreaming::LoadAllRequestedModels(false); - - for(i = 0; i < 3; i++){ - CPlane *plane = new CPlane(MI_AIRTRAIN, PERMANENT_VEHICLE); - plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); - plane->m_status = STATUS_ABANDONED; - plane->bIsLocked = true; - plane->m_nPlaneId = i; - plane->m_nCurPathNode = 0; - CWorld::Add(plane); - } - - - CStreaming::RequestModel(MI_DEADDODO, 0); - CStreaming::LoadAllRequestedModels(false); - - for(i = 0; i < 3; i++){ - CPlane *plane = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); - plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); - plane->m_status = STATUS_ABANDONED; - plane->bIsLocked = true; - plane->m_nPlaneId = i; - plane->m_nCurPathNode = 0; - CWorld::Add(plane); - } -} - -void -CPlane::Shutdown(void) -{ - delete[] pPathNodes; - delete[] pPath2Nodes; - delete[] pPath3Nodes; - delete[] pPath4Nodes; - pPathNodes = nil; - pPath2Nodes = nil; - pPath3Nodes = nil; - pPath4Nodes = nil; -} - -CPlaneNode* -CPlane::LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool loop) -{ - int bp, lp; - int i; - - CFileMgr::LoadFile(filename, work_buff, sizeof(work_buff), "r"); - *gString = '\0'; - for(bp = 0, lp = 0; work_buff[bp] != '\n'; bp++, lp++) - gString[lp] = work_buff[bp]; - bp++; - gString[lp] = '\0'; - sscanf(gString, "%d", &numNodes); - CPlaneNode *nodes = new CPlaneNode[numNodes]; - - for(i = 0; i < numNodes; i++){ - *gString = '\0'; - for(lp = 0; work_buff[bp] != '\n'; bp++, lp++) - gString[lp] = work_buff[bp]; - bp++; - // BUG: game doesn't terminate string - gString[lp] = '\0'; - sscanf(gString, "%f %f %f", &nodes[i].p.x, &nodes[i].p.y, &nodes[i].p.z); - } - - // Calculate length of segments and path - totalLength = 0.0f; - for(i = 0; i < numNodes; i++){ - nodes[i].t = totalLength; - float l = (nodes[(i+1) % numNodes].p - nodes[i].p).Magnitude2D(); - if(!loop && i == numNodes-1) - l = 0.0f; - totalLength += l; - } - - return nodes; -} - -void -CPlane::UpdatePlanes(void) -{ - int i, j; - uint32 time; - float t, deltaT; - - if(CReplay::IsPlayingBack()) - return; - - // Jumbo jets - time = CTimer::GetTimeInMilliseconds(); - for(i = 0; i < 3; i++){ - t = TotalDurationOfFlightPath * (float)(time & 0x7FFFF)/0x80000; - // find current frame - for(j = 0; t > aPlaneLineBits[j+1].time; j++); - - OldPlanePathPosition[i] = PlanePathPosition[i]; - deltaT = t - aPlaneLineBits[j].time; - switch(aPlaneLineBits[j].type){ - case 0: // standing still - PlanePathPosition[i] = aPlaneLineBits[j].position; - PlanePathSpeed[i] = 0.0f; - break; - case 1: // moving with constant speed - PlanePathPosition[i] = aPlaneLineBits[j].position + aPlaneLineBits[j].speed*deltaT; - PlanePathSpeed[i] = (TotalDurationOfFlightPath*1000.0f/0x80000) * aPlaneLineBits[j].speed; - break; - case 2: // accelerating/braking - PlanePathPosition[i] = aPlaneLineBits[j].position + (aPlaneLineBits[j].speed + aPlaneLineBits[j].acceleration*deltaT)*deltaT; - PlanePathSpeed[i] = (TotalDurationOfFlightPath*1000.0f/0x80000)*aPlaneLineBits[j].speed + 2.0f*aPlaneLineBits[j].acceleration*deltaT; - break; - } - - // time offset for each plane - time += 0x80000/3; - } - - time = CTimer::GetTimeInMilliseconds(); - - t = TotalDurationOfFlightPath2/0x80000; - PlanePath2Position[0] = CRUISE_SPEED * (time & 0x7FFFF)*t; - PlanePath2Position[1] = CRUISE_SPEED * ((time + 0x80000/3) & 0x7FFFF)*t; - PlanePath2Position[2] = CRUISE_SPEED * ((time + 0x80000/3*2) & 0x7FFFF)*t; - PlanePath2Speed[0] = CRUISE_SPEED*t; - PlanePath2Speed[1] = CRUISE_SPEED*t; - PlanePath2Speed[2] = CRUISE_SPEED*t; - - if(CesnaMissionStatus == CESNA_STATUS_FLYING){ - PlanePath3Speed = CRUISE_SPEED*TotalDurationOfFlightPath3/0x20000; - PlanePath3Position = PlanePath3Speed * ((time - CesnaMissionStartTime) & 0x1FFFF); - if(time - CesnaMissionStartTime >= 128072) - CesnaMissionStatus = CESNA_STATUS_LANDED; - } - - if(DropOffCesnaMissionStatus == CESNA_STATUS_FLYING){ - PlanePath4Speed = CRUISE_SPEED*TotalDurationOfFlightPath4/0x80000; - PlanePath4Position = PlanePath4Speed * ((time - DropOffCesnaMissionStartTime) & 0x7FFFF); - if(time - DropOffCesnaMissionStartTime >= 521288) - DropOffCesnaMissionStatus = CESNA_STATUS_LANDED; - } -} - -bool -CPlane::TestRocketCollision(CVector *rocketPos) -{ - int i; - - i = CPools::GetVehiclePool()->GetSize(); - while(--i >= 0){ - CPlane *plane = (CPlane*)CPools::GetVehiclePool()->GetSlot(i); - if(plane && -#ifdef EXPLODING_AIRTRAIN - (plane->GetModelIndex() == MI_AIRTRAIN || plane->GetModelIndex() == MI_DODO) && -#else - plane->GetModelIndex() != MI_AIRTRAIN && plane->GetModelIndex() == MI_DODO && // strange check -#endif - !plane->m_bHasBeenHit && (*rocketPos - plane->GetPosition()).Magnitude() < 25.0f){ - plane->m_nFrameWhenHit = CTimer::GetFrameCounter(); - plane->m_bHasBeenHit = true; - CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->RegisterCrime_Immediately(CRIME_DESTROYED_CESSNA, - plane->GetPosition(), i+1983, false); - return true; - } - } - return false; -} - -// BUG: not in CPlane in the game -void -CPlane::CreateIncomingCesna(void) -{ - if(CesnaMissionStatus == CESNA_STATUS_FLYING){ - CWorld::Remove(pDrugRunCesna); - delete pDrugRunCesna; - pDrugRunCesna = nil; - } - pDrugRunCesna = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); - pDrugRunCesna->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); - pDrugRunCesna->m_status = STATUS_ABANDONED; - pDrugRunCesna->bIsLocked = true; - pDrugRunCesna->m_nPlaneId = 0; - pDrugRunCesna->m_nCurPathNode = 0; - pDrugRunCesna->m_bIsDrugRunCesna = true; - CWorld::Add(pDrugRunCesna); - - CesnaMissionStatus = CESNA_STATUS_FLYING; - CesnaMissionStartTime = CTimer::GetTimeInMilliseconds(); - printf("CPlane::CreateIncomingCesna(void)\n"); -} - -void -CPlane::CreateDropOffCesna(void) -{ - if(DropOffCesnaMissionStatus == CESNA_STATUS_FLYING){ - CWorld::Remove(pDropOffCesna); - delete pDropOffCesna; - pDropOffCesna = nil; - } - pDropOffCesna = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE); - pDropOffCesna->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f); - pDropOffCesna->m_status = STATUS_ABANDONED; - pDropOffCesna->bIsLocked = true; - pDropOffCesna->m_nPlaneId = 0; - pDropOffCesna->m_nCurPathNode = 0; - pDropOffCesna->m_bIsDropOffCesna = true; - CWorld::Add(pDropOffCesna); - - DropOffCesnaMissionStatus = CESNA_STATUS_FLYING; - DropOffCesnaMissionStartTime = CTimer::GetTimeInMilliseconds(); - printf("CPlane::CreateDropOffCesna(void)\n"); -} - -CVector CPlane::FindDrugPlaneCoordinates(void) { return pDrugRunCesna->GetPosition(); } -CVector CPlane::FindDropOffCesnaCoordinates(void) { return pDrugRunCesna->GetPosition(); } -bool CPlane::HasCesnaLanded(void) { return CesnaMissionStatus == CESNA_STATUS_LANDED; } -bool CPlane::HasCesnaBeenDestroyed(void) { return CesnaMissionStatus == CESNA_STATUS_DESTROYED; } -bool CPlane::HasDropOffCesnaBeenShotDown(void) { return DropOffCesnaMissionStatus == CESNA_STATUS_DESTROYED; } - - -class CPlane_ : public CPlane -{ -public: - void ctor(int32 id, uint8 CreatedBy) { ::new (this) CPlane(id, CreatedBy); } - void dtor(void) { CPlane::~CPlane(); } -}; - -STARTPATCHES - InjectHook(0x54B170, &CPlane_::ctor, PATCH_JUMP); - InjectHook(0x54B270, &CPlane_::dtor, PATCH_JUMP); - InjectHook(0x54B820, CPlane::InitPlanes, PATCH_JUMP); - InjectHook(0x54BCD0, CPlane::Shutdown, PATCH_JUMP); - InjectHook(0x54BD50, CPlane::LoadPath, PATCH_JUMP); - InjectHook(0x54BEC0, CPlane::UpdatePlanes, PATCH_JUMP); - InjectHook(0x54DE90, CPlane::TestRocketCollision, PATCH_JUMP); - InjectHook(0x54E000, CPlane::CreateIncomingCesna, PATCH_JUMP); - InjectHook(0x54E160, CPlane::CreateDropOffCesna, PATCH_JUMP); -ENDPATCHES diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index dd15d910..4795a29f 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -97,8 +97,8 @@ CVehicle::CVehicle(uint8 CreatedBy) DMAudio.SetEntityStatus(m_audioEntityId, true); m_nRadioStation = CGeneral::GetRandomNumber() % USERTRACK; m_pCurGroundEntity = nil; - field_22A = 0; - field_22B = 0; + m_bRainAudioCounter = 0; + m_bRainSamplesCounter = 0; m_comedyControlState = 0; m_aCollPolys[0].valid = false; m_aCollPolys[1].valid = false; @@ -273,7 +273,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon right = -contactSpeedRight/wheelsOnGround; if(wheelStatus == WHEEL_STATUS_BURST){ - float fwdspeed = Min(contactSpeedFwd, 0.3f); + float fwdspeed = min(contactSpeedFwd, 0.3f); right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); } } @@ -363,7 +363,7 @@ CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVec void CVehicle::ExtinguishCarFire(void) { - m_fHealth = Max(m_fHealth, 300.0f); + m_fHealth = max(m_fHealth, 300.0f); if(m_pCarFire) m_pCarFire->Extinguish(); if(IsCar()){ @@ -638,13 +638,13 @@ CVehicle::SetDriver(CPed *driver) if(bFreebies && driver == FindPlayerPed()){ if(GetModelIndex() == MI_AMBULAN) - FindPlayerPed()->m_fHealth = Min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); + FindPlayerPed()->m_fHealth = min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); else if(GetModelIndex() == MI_TAXI) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; else if(GetModelIndex() == MI_POLICE) driver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5); else if(GetModelIndex() == MI_ENFORCER) - driver->m_fArmour = Max(driver->m_fArmour, 100.0f); + driver->m_fArmour = max(driver->m_fArmour, 100.0f); else if(GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; bFreebies = false; diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index accc6936..96f57e06 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -191,8 +191,8 @@ public: eCarLock m_nDoorLock; int8 m_nLastWeaponDamage; // see eWeaponType, -1 if no damage int8 m_nRadioStation; - int8 field_22A; - int8 field_22B; + uint8 m_bRainAudioCounter; + uint8 m_bRainSamplesCounter; uint8 m_nCarHornTimer; int8 field_22D; bool m_bSirenOrAlarm; -- cgit v1.2.3 From 2fabbc3b4cab40220986f402569af64673cb4cd9 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Fri, 16 Aug 2019 20:17:15 +0200 Subject: More more more audio --- src/animation/AnimBlendAssocGroup.cpp | 4 +- src/animation/AnimBlendAssocGroup.h | 2 +- src/animation/AnimBlendAssociation.cpp | 4 +- src/animation/AnimBlendHierarchy.cpp | 2 +- src/animation/AnimManager.cpp | 54 +- src/animation/AnimManager.h | 8 +- src/audio/AudioManager.cpp | 1715 ++++++++++++++++++++++---------- src/audio/AudioManager.h | 208 ++-- src/audio/sampman.cpp | 35 +- src/control/CarCtrl.cpp | 22 +- src/control/CarGen.cpp | 2 +- src/control/Garages.cpp | 6 +- src/control/Garages.h | 2 +- src/control/PathFind.cpp | 67 +- src/control/Replay.cpp | 60 +- src/control/Script.cpp | 6 +- src/core/Camera.cpp | 10 +- src/core/Collision.cpp | 8 +- src/core/FileMgr.cpp | 8 +- src/core/FileMgr.h | 4 +- src/core/Frontend.cpp | 6 +- src/core/General.h | 2 +- src/core/IniFile.cpp | 4 +- src/core/Pad.cpp | 4 +- src/core/Streaming.cpp | 42 +- src/core/Wanted.cpp | 2 +- src/core/common.h | 10 +- src/core/main.cpp | 2 +- src/core/re3.cpp | 4 +- src/entities/Physical.cpp | 40 +- src/modelinfo/ClumpModelInfo.h | 4 +- src/modelinfo/VehicleModelInfo.cpp | 2 +- src/peds/Ped.cpp | 16 +- src/peds/Ped.h | 2 +- src/peds/PedPlacement.cpp | 2 +- src/render/Clouds.cpp | 8 +- src/render/Coronas.cpp | 20 +- src/render/Fluff.cpp | 2 +- src/render/Fluff.h | 2 +- src/render/Hud.cpp | 20 +- src/render/Lights.cpp | 28 +- src/render/ParticleMgr.cpp | 2 +- src/render/PointLights.cpp | 2 +- src/render/Shadows.cpp | 26 +- src/render/Timecycle.cpp | 6 +- src/render/VisibilityPlugins.cpp | 16 +- src/render/WaterLevel.cpp | 10 +- src/skel/win/win.cpp | 2 +- src/vehicles/Automobile.cpp | 58 +- src/vehicles/Boat.cpp | 2 +- src/vehicles/HandlingMgr.cpp | 8 +- src/vehicles/Heli.cpp | 12 +- src/vehicles/Plane.cpp | 4 +- src/vehicles/Vehicle.cpp | 8 +- 54 files changed, 1658 insertions(+), 947 deletions(-) (limited to 'src') diff --git a/src/animation/AnimBlendAssocGroup.cpp b/src/animation/AnimBlendAssocGroup.cpp index 05f9a06a..72c90233 100644 --- a/src/animation/AnimBlendAssocGroup.cpp +++ b/src/animation/AnimBlendAssocGroup.cpp @@ -129,7 +129,7 @@ CAnimBlendAssocGroup::CreateAssociations(const char *name) // Create associations from hierarchies for a given clump void -CAnimBlendAssocGroup::CreateAssociations(const char *blockName, RpClump *clump, char **animNames, int numAssocs) +CAnimBlendAssocGroup::CreateAssociations(const char *blockName, RpClump *clump, const char **animNames, int numAssocs) { int i; CAnimBlock *animBlock; @@ -157,5 +157,5 @@ STARTPATCHES InjectHook(0x401420, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(uint32))&CAnimBlendAssocGroup::CopyAnimation, PATCH_JUMP); InjectHook(0x4013E0, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(const char*))&CAnimBlendAssocGroup::CopyAnimation, PATCH_JUMP); InjectHook(0x401130, (void (CAnimBlendAssocGroup::*)(const char*))&CAnimBlendAssocGroup::CreateAssociations, PATCH_JUMP); - InjectHook(0x401220, (void (CAnimBlendAssocGroup::*)(const char*, RpClump*, char**, int))&CAnimBlendAssocGroup::CreateAssociations, PATCH_JUMP); + InjectHook(0x401220, (void (CAnimBlendAssocGroup::*)(const char*, RpClump*, const char**, int))&CAnimBlendAssocGroup::CreateAssociations, PATCH_JUMP); ENDPATCHES diff --git a/src/animation/AnimBlendAssocGroup.h b/src/animation/AnimBlendAssocGroup.h index 708a3cdd..aa58b0d3 100644 --- a/src/animation/AnimBlendAssocGroup.h +++ b/src/animation/AnimBlendAssocGroup.h @@ -16,5 +16,5 @@ public: CAnimBlendAssociation *CopyAnimation(uint32 id); CAnimBlendAssociation *CopyAnimation(const char *name); void CreateAssociations(const char *name); - void CreateAssociations(const char *blockName, RpClump *clump, char **animNames, int numAssocs); + void CreateAssociations(const char *blockName, RpClump *clump, const char **animNames, int numAssocs); }; diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index d94fe2c1..d2214057 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -185,7 +185,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount <= 0.0f && blendDelta < 0.0f){ // We're faded out and are not fading in blendAmount = 0.0f; - blendDelta = max(0.0, blendDelta); + blendDelta = Max(0.0f, blendDelta); if(flags & ASSOC_DELETEFADEDOUT){ if(callbackType == CB_FINISH || callbackType == CB_DELETE) callback(this, callbackArg); @@ -197,7 +197,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount > 1.0f){ // Maximally faded in, clamp values blendAmount = 1.0f; - blendDelta = min(0.0, blendDelta); + blendDelta = Min(0.0f, blendDelta); } return true; diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp index e4bcdc69..e594e5d8 100644 --- a/src/animation/AnimBlendHierarchy.cpp +++ b/src/animation/AnimBlendHierarchy.cpp @@ -36,7 +36,7 @@ CAnimBlendHierarchy::CalcTotalTime(void) float seqTime = 0.0f; for(j = 0; j < sequences[i].numFrames; j++) seqTime += sequences[i].GetKeyFrame(j)->deltaTime; - totalTime = max(totalTime, seqTime); + totalTime = Max(totalTime, seqTime); } totalLength = totalTime; } diff --git a/src/animation/AnimManager.cpp b/src/animation/AnimManager.cpp index 6ad63e49..444ae93d 100644 --- a/src/animation/AnimManager.cpp +++ b/src/animation/AnimManager.cpp @@ -198,7 +198,7 @@ AnimAssocDesc aStdAnimDescsSide[] = { { ANIM_IDLE_STANCE, ASSOC_REPEAT }, { ANIM_WALK_START, ASSOC_HAS_TRANSLATION | ASSOC_HAS_X_TRANSLATION }, }; -char *aStdAnimations[] = { +char const *aStdAnimations[] = { "walk_civi", "run_civi", "sprint_panic", @@ -373,162 +373,162 @@ char *aStdAnimations[] = { "PHONE_out", "PHONE_talk", }; -char *aPlayerAnimations[] = { +char const *aPlayerAnimations[] = { "walk_player", "run_player", "SPRINT_civi", "IDLE_STANCE", "walk_start", }; -char *aPlayerWithRocketAnimations[] = { +char const *aPlayerWithRocketAnimations[] = { "walk_rocket", "run_rocket", "run_rocket", "idle_rocket", "walk_start_rocket", }; -char *aPlayer1ArmedAnimations[] = { +char const *aPlayer1ArmedAnimations[] = { "walk_player", "run_1armed", "SPRINT_civi", "IDLE_STANCE", "walk_start", }; -char *aPlayer2ArmedAnimations[] = { +char const *aPlayer2ArmedAnimations[] = { "walk_player", "run_armed", "run_armed", "idle_stance", "walk_start", }; -char *aPlayerBBBatAnimations[] = { +char const *aPlayerBBBatAnimations[] = { "walk_player", "run_player", "run_player", "IDLE_STANCE", "walk_start", }; -char *aShuffleAnimations[] = { +char const *aShuffleAnimations[] = { "WALK_shuffle", "RUN_civi", "SPRINT_civi", "IDLE_STANCE", }; -char *aOldAnimations[] = { +char const *aOldAnimations[] = { "walk_old", "run_civi", "sprint_civi", "idle_stance", }; -char *aGang1Animations[] = { +char const *aGang1Animations[] = { "walk_gang1", "run_gang1", "sprint_civi", "idle_stance", }; -char *aGang2Animations[] = { +char const *aGang2Animations[] = { "walk_gang2", "run_gang1", "sprint_civi", "idle_stance", }; -char *aFatAnimations[] = { +char const *aFatAnimations[] = { "walk_fat", "run_civi", "woman_runpanic", "idle_stance", }; -char *aOldFatAnimations[] = { +char const *aOldFatAnimations[] = { "walk_fatold", "run_fatold", "woman_runpanic", "idle_stance", }; -char *aStdWomanAnimations[] = { +char const *aStdWomanAnimations[] = { "woman_walknorm", "woman_run", "woman_runpanic", "woman_idlestance", }; -char *aWomanShopAnimations[] = { +char const *aWomanShopAnimations[] = { "woman_walkshop", "woman_run", "woman_run", "woman_idlestance", }; -char *aBusyWomanAnimations[] = { +char const *aBusyWomanAnimations[] = { "woman_walkbusy", "woman_run", "woman_runpanic", "woman_idlestance", }; -char *aSexyWomanAnimations[] = { +char const *aSexyWomanAnimations[] = { "woman_walksexy", "woman_run", "woman_runpanic", "woman_idlestance", }; -char *aOldWomanAnimations[] = { +char const *aOldWomanAnimations[] = { "woman_walkold", "woman_run", "woman_runpanic", "woman_idlestance", }; -char *aFatWomanAnimations[] = { +char const *aFatWomanAnimations[] = { "walk_fat", "woman_run", "woman_runpanic", "woman_idlestance", }; -char *aPanicChunkyAnimations[] = { +char const *aPanicChunkyAnimations[] = { "run_fatold", "woman_runpanic", "woman_runpanic", "idle_stance", }; -char *aPlayerStrafeBackAnimations[] = { +char const *aPlayerStrafeBackAnimations[] = { "walk_player_back", "run_player_back", "run_player_back", "IDLE_STANCE", "walk_start_back", }; -char *aPlayerStrafeLeftAnimations[] = { +char const *aPlayerStrafeLeftAnimations[] = { "walk_player_left", "run_left", "run_left", "IDLE_STANCE", "walk_start_left", }; -char *aPlayerStrafeRightAnimations[] = { +char const *aPlayerStrafeRightAnimations[] = { "walk_player_right", "run_right", "run_right", "IDLE_STANCE", "walk_start_right", }; -char *aRocketStrafeBackAnimations[] = { +char const *aRocketStrafeBackAnimations[] = { "walk_rocket_back", "run_rocket_back", "run_rocket_back", "idle_rocket", "walkst_rocket_back", }; -char *aRocketStrafeLeftAnimations[] = { +char const *aRocketStrafeLeftAnimations[] = { "walk_rocket_left", "run_rocket_left", "run_rocket_left", "idle_rocket", "walkst_rocket_left", }; -char *aRocketStrafeRightAnimations[] = { +char const *aRocketStrafeRightAnimations[] = { "walk_rocket_right", "run_rocket_right", "run_rocket_right", "idle_rocket", "walkst_rocket_right", }; -AnimAssocDefinition CAnimManager::ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS] = { +const AnimAssocDefinition CAnimManager::ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS] = { { "man", "ped", MI_COP, 173, aStdAnimations, aStdAnimDescs }, { "player", "ped", MI_COP, 5, aPlayerAnimations, aStdAnimDescs }, { "playerrocket", "ped", MI_COP, 5, aPlayerWithRocketAnimations, aStdAnimDescs }, @@ -749,7 +749,7 @@ CAnimManager::LoadAnimFiles(void) RpClump *clump = (RpClump*)mi->CreateInstance(); RpAnimBlendClumpInit(clump); CAnimBlendAssocGroup *group = &CAnimManager::ms_aAnimAssocGroups[i]; - AnimAssocDefinition *def = &CAnimManager::ms_aAnimAssocDefinitions[i]; + const AnimAssocDefinition *def = &CAnimManager::ms_aAnimAssocDefinitions[i]; group->CreateAssociations(def->blockName, clump, def->animNames, def->numAnims); for(j = 0; j < group->numAssociations; j++) group->GetAnimation(j)->flags |= def->animDescs[j].flags; diff --git a/src/animation/AnimManager.h b/src/animation/AnimManager.h index 3a7c057c..d2e85c06 100644 --- a/src/animation/AnimManager.h +++ b/src/animation/AnimManager.h @@ -231,17 +231,17 @@ struct AnimAssocDesc struct AnimAssocDefinition { - char *name; - char *blockName; + char const *name; + char const *blockName; int32 modelIndex; int32 numAnims; - char **animNames; + char const **animNames; AnimAssocDesc *animDescs; }; class CAnimManager { - static AnimAssocDefinition ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS]; + static const AnimAssocDefinition ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS]; static CAnimBlock *ms_aAnimBlocks; //[2] static CAnimBlendHierarchy *ms_aAnimations; //[250] static int32 &ms_numAnimBlocks; diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index e08efbc6..e1860698 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -22,6 +22,7 @@ #include "Replay.h" #include "Stats.h" #include "SurfaceTable.h" +#include "Train.h" #include "Transmission.h" #include "Vehicle.h" #include "Weather.h" @@ -29,6 +30,11 @@ #include "ZoneCull.h" #include "sampman.h" +cAudioManager &AudioManager = *(cAudioManager *)0x880FC0; + +constexpr int totalAudioEntitiesSlots = 200; +constexpr int maxVolume = 127; + uint32 *audioLogicTimers = (uint32 *)0x6508A0; // TODO: where is this used? Is this the right file? @@ -111,26 +117,117 @@ cPedComments::Add(tPedComment *com) uint8 index; if(nrOfCommentsInBank[activeBank] >= 20u) { - index = field_1120[activeBank][19]; + index = indexMap[activeBank][19]; if(m_asPedComments[activeBank][index].m_bVolume > com->m_bVolume) return; } else { index = nrOfCommentsInBank[activeBank]++; } - m_asPedComments[activeBank][index] = *com; + + m_asPedComments[activeBank][index].m_nSampleIndex = com->m_nSampleIndex; + m_asPedComments[activeBank][index].m_entityIndex = com->m_entityIndex; + m_asPedComments[activeBank][index].m_vecPos = com->m_vecPos; + m_asPedComments[activeBank][index].m_fDistance = com->m_fDistance; + m_asPedComments[activeBank][index].m_bVolume = com->m_bVolume; uint32 i = 0; if(index != 0) { for(i = 0; i < index; i++) { - if(m_asPedComments[activeBank][field_1120[activeBank][i]].m_bVolume < + if(m_asPedComments[activeBank][indexMap[activeBank][i]].m_bVolume < m_asPedComments[activeBank][index].m_bVolume) { - memmove(&field_1120[activeBank][i + 1], &field_1120[activeBank][i], - 19 - i); break; } } + + if(i < index) + memmove(&indexMap[activeBank][i + 1], &indexMap[activeBank][i], 19 - i); } - field_1120[activeBank][i] = index; + indexMap[activeBank][i] = index; +} + +void +cPedComments::Process() +{ + int sampleIndex; + uint8 actualUsedBank; + tPedComment *comment; + + if(!AudioManager.m_bUserPause) { + if(nrOfCommentsInBank[activeBank]) { + sampleIndex = + m_asPedComments[activeBank][indexMap[activeBank][0]].m_nSampleIndex; + if(!SampleManager.IsPedCommentLoaded(sampleIndex)) + SampleManager.LoadPedComment(sampleIndex); + + AudioManager.m_sQueueSample.m_nEntityIndex = + m_asPedComments[activeBank][indexMap[activeBank][0]].m_entityIndex; + AudioManager.m_sQueueSample.m_counter = 0; + AudioManager.m_sQueueSample.m_nSampleIndex = sampleIndex; + AudioManager.m_sQueueSample.m_bBankIndex = 1; + AudioManager.m_sQueueSample.field_16 = 3; + AudioManager.m_sQueueSample.m_bVolume = + m_asPedComments[activeBank][indexMap[activeBank][0]].m_bVolume; + AudioManager.m_sQueueSample.m_fDistance = + m_asPedComments[activeBank][indexMap[activeBank][0]].m_fDistance; + AudioManager.m_sQueueSample.m_nLoopCount = 1; + AudioManager.m_sQueueSample.m_nLoopStart = 0; + AudioManager.m_sQueueSample.m_nLoopEnd = -1; + AudioManager.m_sQueueSample.m_bEmittingVolume = maxVolume; + AudioManager.m_sQueueSample.field_48 = 3.0f; + switch(sampleIndex) { + case AUDIO_SAMPLE_POLICE_HELI_FOUND_PLAYER_1: + case AUDIO_SAMPLE_POLICE_HELI_FOUND_PLAYER_2: + case AUDIO_SAMPLE_POLICE_HELI_FOUND_PLAYER_3: + AudioManager.m_sQueueSample.m_fSoundIntensity = 400.0f; + break; + default: AudioManager.m_sQueueSample.m_fSoundIntensity = 50.0f; break; + } + AudioManager.m_sQueueSample.field_56 = 1; + AudioManager.m_sQueueSample.m_vecPos = + m_asPedComments[activeBank][indexMap[activeBank][0]].m_vecPos; + + if((sampleIndex - AUDIO_SAMPLE_AMMUNATION_WELCOME_1) > 1 && + sampleIndex != AUDIO_SAMPLE_AMMUNATION_WELCOME_3) { + AudioManager.m_sQueueSample.m_bReverbFlag = 1; + AudioManager.m_sQueueSample.m_bRequireReflection = 1; + } else { + AudioManager.m_sQueueSample.m_bReverbFlag = 0; + AudioManager.m_sQueueSample.m_bRequireReflection = 0; + } + + AudioManager.m_sQueueSample.m_bIsDistant = 0; + AudioManager.m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency( + AudioManager.m_sQueueSample.m_nSampleIndex) + + AudioManager.RandomDisplacement(750u); + if(CTimer::GetIsSlowMotionActive()) + AudioManager.m_sQueueSample.m_nFrequency = + AudioManager.m_sQueueSample.m_nFrequency >> 1; + m_asPedComments[activeBank][indexMap[activeBank][0]].field_25 = -1; + AudioManager.AddSampleToRequestedQueue(); + } + + // Switch bank + if(activeBank) { + actualUsedBank = 1; + activeBank = 0; + } else { + actualUsedBank = 0; + activeBank = 1; + } + comment = m_asPedComments[actualUsedBank]; + for(uint32 i = 0; i < nrOfCommentsInBank[actualUsedBank]; i++) { + if(m_asPedComments[actualUsedBank][indexMap[actualUsedBank][i]].field_25 > + 0) { + --m_asPedComments[actualUsedBank][indexMap[actualUsedBank][i]] + .field_25; + Add(&comment[indexMap[actualUsedBank][i]]); + } + } + + for(uint32 i = 0; i < 20; i++) { indexMap[actualUsedBank][i] = 20; } + nrOfCommentsInBank[actualUsedBank] = 0; + } } void * @@ -154,11 +251,6 @@ cAudioScriptObject::operator delete(void *p, int handle) CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); } -cAudioManager &AudioManager = *(cAudioManager *)0x880FC0; - -constexpr int totalAudioEntitiesSlots = 200; -constexpr int maxVolume = 127; - char &g_nMissionAudioPlayingStatus = *(char *)0x60ED88; void @@ -184,11 +276,11 @@ cAudioManager::AddDetailsToRequestedOrderList(uint8 sample) void cAudioManager::AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 unk1, - uint8 unk2, bool notLooping) + uint8 counter, bool notLooping) { m_sQueueSample.m_bVolume = ComputeVolume(emittingVolume, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = unk2; + m_sQueueSample.m_counter = counter; m_sQueueSample.m_nSampleIndex = sample; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -234,7 +326,7 @@ cAudioManager::AddReflectionsToRequestedQueue() ComputeVolume(emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume > emittingVolume >> 4) { - m_sQueueSample.field_4 += ((i + 1) << 8); + m_sQueueSample.m_counter += ((i + 1) << 8); if(m_sQueueSample.m_nLoopCount) { noise = RandomDisplacement( m_sQueueSample.m_nFrequency >> 5); @@ -244,9 +336,7 @@ cAudioManager::AddReflectionsToRequestedQueue() m_sQueueSample.m_nFrequency -= noise; } m_sQueueSample.field_16 += 20; - m_sQueueSample.m_vecPos.x = m_avecReflectionsPos[i].x; - m_sQueueSample.m_vecPos.y = m_avecReflectionsPos[i].y; - m_sQueueSample.m_vecPos.z = m_avecReflectionsPos[i].z; + m_sQueueSample.m_vecPos = m_avecReflectionsPos[i]; AddSampleToRequestedQueue(); } } @@ -268,7 +358,6 @@ void cAudioManager::AddSampleToRequestedQueue() { int32 calculatedVolume; - tActiveSample *sample; uint8 sampleIndex; bool bReflections; @@ -300,33 +389,7 @@ cAudioManager::AddSampleToRequestedQueue() if(!m_bDynamicAcousticModelingStatus) m_sQueueSample.m_bReverbFlag = 0; - sample = &m_asSamples[m_bActiveSampleQueue][sampleIndex]; - sample->m_nEntityIndex = m_sQueueSample.m_nEntityIndex; - sample->field_4 = m_sQueueSample.field_4; - sample->m_nSampleIndex = m_sQueueSample.m_nSampleIndex; - sample->m_bBankIndex = m_sQueueSample.m_bBankIndex; - sample->m_bIsDistant = m_sQueueSample.m_bIsDistant; - sample->field_16 = m_sQueueSample.field_16; - sample->m_nFrequency = m_sQueueSample.m_nFrequency; - sample->m_bVolume = m_sQueueSample.m_bVolume; - sample->m_fDistance = m_sQueueSample.m_fDistance; - sample->m_nLoopCount = m_sQueueSample.m_nLoopCount; - sample->m_nLoopStart = m_sQueueSample.m_nLoopStart; - sample->m_nLoopEnd = m_sQueueSample.m_nLoopEnd; - sample->m_bEmittingVolume = m_sQueueSample.m_bEmittingVolume; - sample->field_48 = m_sQueueSample.field_48; - sample->m_fSoundIntensity = m_sQueueSample.m_fSoundIntensity; - sample->field_56 = m_sQueueSample.field_56; - sample->m_vecPos = m_sQueueSample.m_vecPos; - sample->m_bReverbFlag = m_sQueueSample.m_bReverbFlag; - sample->m_bLoopsRemaining = m_sQueueSample.m_bLoopsRemaining; - sample->m_bRequireReflection = m_sQueueSample.m_bRequireReflection; - sample->m_bOffset = m_sQueueSample.m_bOffset; - sample->field_76 = m_sQueueSample.field_76; - sample->m_bIsProcessed = m_sQueueSample.m_bIsProcessed; - sample->m_bLoopEnded = m_sQueueSample.m_bLoopEnded; - sample->calculatedVolume = m_sQueueSample.calculatedVolume; - sample->field_88 = m_sQueueSample.field_88; + m_asSamples[m_bActiveSampleQueue][sampleIndex] = m_sQueueSample; AddDetailsToRequestedOrderList(sampleIndex); if(bReflections) AddReflectionsToRequestedQueue(); @@ -340,14 +403,6 @@ cAudioManager::AgeCrimes() EAXJMP(0x580AF0); } -int8 -cAudioManager::GetCurrent3DProviderIndex() -{ - if(m_bIsInitialised) return SampleManager.GetCurrent3DProviderIndex(); - - return -1; -} - void cAudioManager::CalculateDistance(bool *ptr, float dist) { @@ -358,7 +413,7 @@ cAudioManager::CalculateDistance(bool *ptr, float dist) } bool -cAudioManager::CheckForAnAudioFileOnCD() +cAudioManager::CheckForAnAudioFileOnCD() const { return SampleManager.CheckForAnAudioFileOnCD(); } @@ -388,18 +443,18 @@ cAudioManager::ClearRequestedQueue() int32 cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, - float speedMultiplier) + float speedMultiplier) const { uint32 newFreq = oldFreq; if(!TheCamera.Get_Just_Switched_Status() && speedMultiplier != 0.0f) { float dist = position2 - position1; if(dist != 0.0f) { float speedOfSource = (dist / field_19195) * speedMultiplier; - if(speedOfSound > fabsf(speedOfSource)) { + if(speedOfSound > Abs(speedOfSource)) { if(speedOfSource < 0.0f) { - speedOfSource = max(speedOfSource, -1.5f); + speedOfSource = Max(speedOfSource, -1.5f); } else { - speedOfSource = min(speedOfSource, 1.5f); + speedOfSource = Min(speedOfSource, 1.5f); } newFreq = (oldFreq * speedOfSound) / (speedOfSource + speedOfSound); } @@ -416,7 +471,7 @@ cAudioManager::ComputePan(float, CVector *) } uint32 -cAudioManager::ComputeVolume(int emittingVolume, float soundIntensity, float distance) +cAudioManager::ComputeVolume(int emittingVolume, float soundIntensity, float distance) const { float newSoundIntensity; if(soundIntensity <= 0.0f) return 0; @@ -445,7 +500,7 @@ cAudioManager::CreateEntity(int32 type, void *entity) m_asAudioEntities[i].m_awAudioEvent[1] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[2] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[3] = SOUND_TOTAL_PED_SOUNDS; - m_asAudioEntities[i].field_24 = 0; + m_asAudioEntities[i].m_Loops = 0; m_anAudioEntityIndices[m_nAudioEntitiesTotal++] = i; return i; } @@ -467,7 +522,7 @@ cAudioManager::DestroyAllGameCreatedEntities() case AUDIOTYPE_WEATHER: case AUDIOTYPE_CRANE: case AUDIOTYPE_GARAGE: - case AUDIOTYPE_FIREHYDRANT: cAudioManager::DestroyEntity(i); break; + case AUDIOTYPE_FIREHYDRANT: DestroyEntity(i); break; case AUDIOTYPE_SCRIPTOBJECT: entity = (cAudioScriptObject *)m_asAudioEntities[i].m_pEntity; @@ -506,7 +561,7 @@ void cAudioManager::DoPoliceRadioCrackle() { m_sQueueSample.m_nEntityIndex = m_nPoliceChannelEntity; - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_POLICE_SCANNER_CRACKLE; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 1; @@ -532,15 +587,8 @@ cAudioManager::GenerateIntegerRandomNumberTable() for(int32 i = 0; i < 5; i++) { m_anRandomTable[i] = rand(); } } -float -cAudioManager::GetDistanceSquared(CVector *v) -{ - const CVector &c = TheCamera.GetPosition(); - return sq(v->x - c.x) + sq(v->y - c.y) + sq((v->z - c.z) * 0.2f); -} - void -cAudioManager::TranslateEntity(CVector *v1, CVector *v2) +cAudioManager::TranslateEntity(CVector *v1, CVector *v2) const { const RwMatrix &cM = TheCamera.GetMatrix().m_matrix; const CVector &cV = TheCamera.GetPosition(); @@ -555,24 +603,27 @@ cAudioManager::TranslateEntity(CVector *v1, CVector *v2) } void -cAudioManager::Initialise() +cAudioManager::ResetAudioLogicTimers(int32 timer) { - if(!m_bIsInitialised) { - PreInitialiseGameSpecificSetup(); - m_bIsInitialised = SampleManager.Initialise(); - if(m_bIsInitialised) { - m_bActiveSamples = SampleManager.GetMaximumSupportedChannels(); - if(m_bActiveSamples <= 1u) { - Terminate(); - } else { - --m_bActiveSamples; - PostInitialiseGameSpecificSetup(); - InitialisePoliceRadioZones(); - InitialisePoliceRadio(); - MusicManager.Initialise(); + audioLogicTimers[0] = timer; + audioLogicTimers[8] = timer; + audioLogicTimers[1] = timer; + audioLogicTimers[7] = timer; + audioLogicTimers[2] = timer; + audioLogicTimers[6] = timer; + audioLogicTimers[3] = timer; + audioLogicTimers[5] = timer; + audioLogicTimers[4] = timer; + for(int32 i = 0; i < m_nAudioEntitiesTotal; i++) { + if(m_asAudioEntities[m_anAudioEntityIndices[i]].m_nType == AUDIOTYPE_PHYSICAL) { + CPed *ped = (CPed *)m_asAudioEntities[m_anAudioEntityIndices[i]].m_pEntity; + if(ped->IsPed()) { + ped->m_lastSoundStart = timer; + ped->m_soundStart = timer + m_anRandomTable[0] % 3000u; } } } +<<<<<<< HEAD } void @@ -623,6 +674,10 @@ void cAudioManager::ResetAudioLogicTimers(int32 timer) { EAXJMP(0x569650); +======= + ClearMissionAudio(); + SampleManager.StopChannel(28); +>>>>>>> More more more audio } void @@ -651,29 +706,15 @@ cAudioManager::Terminate() } } -char -cAudioManager::GetMissionScriptPoliceAudioPlayingStatus() -{ - return g_nMissionAudioPlayingStatus; -} - -bool -cAudioManager::GetMissionAudioLoadingStatus() -{ - if(m_bIsInitialised) return m_sMissionAudio.m_bLoadingStatus; - - return true; -} - uint8 -cAudioManager::GetNum3DProvidersAvailable() +cAudioManager::GetNum3DProvidersAvailable() const { if(m_bIsInitialised) return SampleManager.GetNum3DProvidersAvailable(); return 0; } bool -cAudioManager::IsMP3RadioChannelAvailable() +cAudioManager::IsMP3RadioChannelAvailable() const { if(m_bIsInitialised) return SampleManager.IsMP3RadioChannelAvailable(); @@ -681,7 +722,7 @@ cAudioManager::IsMP3RadioChannelAvailable() } uint8 -cAudioManager::GetCDAudioDriveLetter() +cAudioManager::GetCDAudioDriveLetter() const { if(m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter(); @@ -689,31 +730,31 @@ cAudioManager::GetCDAudioDriveLetter() } void -cAudioManager::SetEffectsMasterVolume(uint8 volume) +cAudioManager::SetEffectsMasterVolume(uint8 volume) const { SampleManager.SetEffectsMasterVolume(volume); } void -cAudioManager::SetMusicMasterVolume(uint8 volume) +cAudioManager::SetMusicMasterVolume(uint8 volume) const { SampleManager.SetMusicMasterVolume(volume); } void -cAudioManager::SetEffectsFadeVolume(uint8 volume) +cAudioManager::SetEffectsFadeVolume(uint8 volume) const { SampleManager.SetEffectsFadeVolume(volume); } void -cAudioManager::SetMusicFadeVolume(uint8 volume) +cAudioManager::SetMusicFadeVolume(uint8 volume) const { SampleManager.SetMusicFadeVolume(volume); } void -cAudioManager::SetSpeakerConfig(int32 conf) +cAudioManager::SetSpeakerConfig(int32 conf) const { SampleManager.SetSpeakerConfig(conf); } @@ -724,7 +765,7 @@ bool cAudioManager::SetupJumboEngineSound(uint8, int32) { EAXJMP(0x56F140); } int32 *BankStartOffset = (int32 *)0x6FAB70; //[2] void -cAudioManager::PreInitialiseGameSpecificSetup() +cAudioManager::PreInitialiseGameSpecificSetup() const { BankStartOffset[0] = AUDIO_SAMPLE_VEHICLE_HORN_0; BankStartOffset[1] = AUDIO_SAMPLE_POLICE_COP_1_ARREST_1; @@ -733,7 +774,7 @@ cAudioManager::PreInitialiseGameSpecificSetup() int32 &g_nMissionAudioSfx = *(int32 *)0x60ED84; void -cAudioManager::SetMissionScriptPoliceAudio(int32 sfx) +cAudioManager::SetMissionScriptPoliceAudio(int32 sfx) const { if(m_bIsInitialised) { if(g_nMissionAudioPlayingStatus != 1) { @@ -744,7 +785,7 @@ cAudioManager::SetMissionScriptPoliceAudio(int32 sfx) } bool -cAudioManager::UsesSiren(int32 model) +cAudioManager::UsesSiren(int32 model) const { switch(model) { case FIRETRUK: @@ -758,7 +799,7 @@ cAudioManager::UsesSiren(int32 model) } bool -cAudioManager::UsesSirenSwitching(int32 model) +cAudioManager::UsesSirenSwitching(int32 model) const { switch(model) { case AMBULAN: @@ -769,28 +810,8 @@ cAudioManager::UsesSirenSwitching(int32 model) } } -bool -cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) -{ - switch(soundMission) { - case STREAMED_SOUND_MISSION_J6_D: - case STREAMED_SOUND_MISSION_T4_A: - case STREAMED_SOUND_MISSION_S1_H: - case STREAMED_SOUND_MISSION_S3_B: - case STREAMED_SOUND_MISSION_EL3_A: - case STREAMED_SOUND_MISSION_A3_A: - case STREAMED_SOUND_MISSION_A5_A: - case STREAMED_SOUND_MISSION_K1_A: - case STREAMED_SOUND_MISSION_R1_A: - case STREAMED_SOUND_MISSION_R5_A: - case STREAMED_SOUND_MISSION_LO2_A: - case STREAMED_SOUND_MISSION_LO6_A: return true; - default: return false; - } -} - char * -cAudioManager::Get3DProviderName(uint8 id) +cAudioManager::Get3DProviderName(uint8 id) const { if(!m_bIsInitialised) return 0; if(id >= SampleManager.GetNum3DProvidersAvailable()) return 0; @@ -802,13 +823,13 @@ cAudioManager::SetupJumboFlySound(uint8 emittingVol) { int32 vol; - if(m_sQueueSample.m_fDistance >= 440.0) return 0; + if(m_sQueueSample.m_fDistance >= 440.0f) return 0; vol = ComputeVolume(emittingVol, 440.0f, m_sQueueSample.m_fDistance); m_sQueueSample.m_bVolume = vol; if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_FLY_SOUND; - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_16 = 1; @@ -838,7 +859,7 @@ cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 240.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 5; + m_sQueueSample.m_counter = 5; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 1; @@ -859,10 +880,10 @@ cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) m_sQueueSample.m_bReverbFlag = 1; m_sQueueSample.m_bRequireReflection = 0; AddSampleToRequestedQueue(); - m_sQueueSample.field_4 = 6; + m_sQueueSample.m_counter = 6; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; m_sQueueSample.m_nFrequency += 200; - m_sQueueSample.m_bOffset = 127; + m_sQueueSample.m_bOffset = maxVolume; AddSampleToRequestedQueue(); } return 1; @@ -884,7 +905,7 @@ cAudioManager::SetupJumboTaxiSound(uint8 vol) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 180.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 1; + m_sQueueSample.m_counter = 1; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_TAXI_SOUND; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -915,7 +936,7 @@ cAudioManager::SetupJumboWhineSound(uint8 emittingVol, int32 freq) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 170.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 2; + m_sQueueSample.m_counter = 2; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_WHINE_SOUND; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -938,15 +959,6 @@ cAudioManager::SetupJumboWhineSound(uint8 emittingVol, int32 freq) return 1; } -void -cAudioManager::PlayLoadedMissionAudio() -{ - if(m_bIsInitialised && m_sMissionAudio.m_nSampleIndex != NO_SAMPLE && - m_sMissionAudio.m_bLoadingStatus == 1 && !m_sMissionAudio.m_bPlayStatus) { - m_sMissionAudio.m_bIsPlayed = true; - } -} - void cAudioManager::SetMissionAudioLocation(float x, float y, float z) { @@ -967,54 +979,15 @@ cAudioManager::ResetPoliceRadio() } } -void -cAudioManager::InterrogateAudioEntities() -{ - for(int32 i = 0; i < m_nAudioEntitiesTotal; i++) { - ProcessEntity(m_anAudioEntityIndices[i]); - m_asAudioEntities[m_anAudioEntityIndices[i]].field_24 = 0; - } -} - bool -cAudioManager::UsesReverseWarning(int32 model) +cAudioManager::UsesReverseWarning(int32 model) const { return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || - model == COACH; // fix -} - -bool -cAudioManager::HasAirBrakes(int32 model) -{ - return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || - model == COACH; // fix + model == COACH; } int32 -cAudioManager::GetJumboTaxiFreq() -{ - return (60.833f * m_sQueueSample.m_fDistance) + 22050; -} - -bool -cAudioManager::IsMissionAudioSampleFinished() -{ - if(m_bIsInitialised) return m_sMissionAudio.m_bPlayStatus == 2; - - static int32 cPretendFrame = 1; - - return (cPretendFrame++ & 63) == 0; -} - -WRAPPER -void -cAudioManager::InitialisePoliceRadio() -{ - EAXJMP(0x57EEC0); -} - -int32 -cAudioManager::RandomDisplacement(uint32 seed) +cAudioManager::RandomDisplacement(uint32 seed) const { int32 value; @@ -1032,13 +1005,13 @@ cAudioManager::RandomDisplacement(uint32 seed) } void -cAudioManager::ReleaseDigitalHandle() +cAudioManager::ReleaseDigitalHandle() const { if(m_bIsInitialised) { SampleManager.ReleaseDigitalHandle(); } } void -cAudioManager::ReacquireDigitalHandle() +cAudioManager::ReacquireDigitalHandle() const { if(m_bIsInitialised) { SampleManager.ReacquireDigitalHandle(); } } @@ -1064,60 +1037,7 @@ cAudioManager::SetEntityStatus(int32 id, bool status) } void -cAudioManager::PreTerminateGameSpecificShutdown() -{ - if(m_nBridgeEntity >= 0) { - DestroyEntity(m_nBridgeEntity); - m_nBridgeEntity = -5; - } - if(m_nPoliceChannelEntity >= 0) { - DestroyEntity(m_nPoliceChannelEntity); - m_nPoliceChannelEntity = -5; - } - if(m_nWaterCannonEntity >= 0) { - DestroyEntity(m_nWaterCannonEntity); - m_nWaterCannonEntity = -5; - } - if(m_nFireAudioEntity >= 0) { - DestroyEntity(m_nFireAudioEntity); - m_nFireAudioEntity = -5; - } - if(m_nCollisionEntity >= 0) { - DestroyEntity(m_nCollisionEntity); - m_nCollisionEntity = -5; - } - if(m_nFrontEndEntity >= 0) { - DestroyEntity(m_nFrontEndEntity); - m_nFrontEndEntity = -5; - } - if(m_nProjectileEntity >= 0) { - DestroyEntity(m_nProjectileEntity); - m_nProjectileEntity = -5; - } -} - -void -cAudioManager::PostTerminateGameSpecificShutdown() -{ - ; -} - -bool &bPlayerJustEnteredCar = *(bool *)0x6508C4; - -void -cAudioManager::PlayerJustGotInCar() -{ - if(m_bIsInitialised) { bPlayerJustEnteredCar = true; } -} - -void -cAudioManager::PlayerJustLeftCar(void) -{ - // UNUSED: This is a perfectly empty function. -} - -void -cAudioManager::GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) +cAudioManager::GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const { *phrase = sample + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % maxOffset; @@ -1130,7 +1050,7 @@ cAudioManager::GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint uint8 &jumboVolOffset = *(uint8 *)0x6508ED; void -cAudioManager::DoJumboVolOffset() +cAudioManager::DoJumboVolOffset() const { if(!(m_FrameCounter % (m_anRandomTable[0] % 6u + 3))) jumboVolOffset = m_anRandomTable[1] % 60u; @@ -1258,9 +1178,7 @@ cAudioManager::GetCopTalkSfx(int16 sound) if(sound == SOUND_PED_ARREST_COP) { GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_COP_1_ARREST_1, 6u); } else { - if(sound != SOUND_PED_PURSUIT_COP) { - return cAudioManager::GetGenericMaleTalkSfx(sound); - } + if(sound != SOUND_PED_PURSUIT_COP) { return GetGenericMaleTalkSfx(sound); } pedState = FindPlayerPed()->m_nPedState; if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) @@ -1281,9 +1199,7 @@ cAudioManager::GetSwatTalkSfx(int16 sound) if(sound == SOUND_PED_ARREST_SWAT) { GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_SWAT_1_PURSUIT_ARREST_1, 6u); } else { - if(sound != SOUND_PED_PURSUIT_SWAT) { - return cAudioManager::GetGenericMaleTalkSfx(sound); - } + if(sound != SOUND_PED_PURSUIT_SWAT) { return GetGenericMaleTalkSfx(sound); } pedState = FindPlayerPed()->m_nPedState; if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) @@ -1304,9 +1220,7 @@ cAudioManager::GetFBITalkSfx(int16 sound) if(sound == SOUND_PED_ARREST_FBI) { GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_FBI_1_PURSUIT_ARREST_1, 6u); } else { - if(sound != SOUND_PED_PURSUIT_FBI) { - return cAudioManager::GetGenericMaleTalkSfx(sound); - } + if(sound != SOUND_PED_PURSUIT_FBI) { return GetGenericMaleTalkSfx(sound); } pedState = FindPlayerPed()->m_nPedState; if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) @@ -1324,7 +1238,7 @@ cAudioManager::GetArmyTalkSfx(int16 sound) PedState pedState; static uint32 lastSfx = NO_SAMPLE; - if(sound != SOUND_PED_PURSUIT_ARMY) { return cAudioManager::GetGenericMaleTalkSfx(sound); } + if(sound != SOUND_PED_PURSUIT_ARMY) { return GetGenericMaleTalkSfx(sound); } pedState = FindPlayerPed()->m_nPedState; if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) @@ -1356,7 +1270,7 @@ cAudioManager::GetMedicTalkSfx(int16 sound) case SOUND_PED_FLEE_RUN: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_FLEE_RUN_1, 6u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 37 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1364,7 +1278,7 @@ cAudioManager::GetMedicTalkSfx(int16 sound) uint32 cAudioManager::GetFiremanTalkSfx(int16 sound) { - return cAudioManager::GetGenericMaleTalkSfx(sound); + return GetGenericMaleTalkSfx(sound); } uint32 @@ -1398,7 +1312,7 @@ cAudioManager::GetNormalMaleTalkSfx(int16 sound) case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_NORMAL_MALE_CHAT_1, 25u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return sfx; } @@ -1412,8 +1326,7 @@ cAudioManager::GetTaxiDriverTalkSfx(int16 sound) if(sound == SOUND_PED_CAR_JACKED) { GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_TAXI_DRIVER_1_CAR_JACKED_1, 7u); } else { - if(sound != SOUND_PED_CAR_COLLISION) - return cAudioManager::GetGenericMaleTalkSfx(sound); + if(sound != SOUND_PED_CAR_COLLISION) return GetGenericMaleTalkSfx(sound); GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_TAXI_DRIVER_1_CAR_COLLISION_1, 6u); } return 13 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; @@ -1441,7 +1354,7 @@ cAudioManager::GetPimpTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_PIMP_CHAT_EVENT_1, 2u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_PIMP_CHAT_1, 17u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return sfx; } @@ -1472,7 +1385,7 @@ cAudioManager::GetMafiaTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MAFIA_1_CHAT_SEXY_1, 3u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MAFIA_1_CHAT_1, 7u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 30 * (m_sQueueSample.m_nEntityIndex % 3) + sfx; } @@ -1506,7 +1419,7 @@ cAudioManager::GetTriadTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_TRIAD_1_CHAT_SEXY_1, 3u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_TRIAD_1_CHAT_1, 8u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return sfx; } @@ -1523,7 +1436,7 @@ cAudioManager::GetDiabloTalkSfx(int16 sound) break; case SOUND_PED_HANDS_COWER: sound = SOUND_PED_FLEE_SPRINT; - return cAudioManager::GetGenericMaleTalkSfx(sound); + return GetGenericMaleTalkSfx(sound); break; case SOUND_PED_CAR_JACKING: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_DIABLO_1_CAR_JACKING_1, 2u); @@ -1544,7 +1457,7 @@ cAudioManager::GetDiabloTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_DIABLO_1_CHAT_SEXY_1, 4u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_DIABLO_1_CHAT_1, 5u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 30 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1572,7 +1485,7 @@ cAudioManager::GetYakuzaTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_YAKUZA_1_CAR_COLLISION_1, 6u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_YAKUZA_1_CHAT_1, 5u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 24 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1602,7 +1515,7 @@ cAudioManager::GetYardieTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_YARDIE_1_CHAT_SEXY_1, 2u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_YARDIE_1_CHAT_1, 8u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 31 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1633,7 +1546,7 @@ cAudioManager::GetColumbianTalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_COLUMB_1_CHAT_SEXY_1, 2u); break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_COLUMB_1_CHAT_1, 5u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return 27 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1668,7 +1581,7 @@ cAudioManager::GetHoodTalkSfx(int16 sound) break; case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_HOODS_1_CHAT_1, 6u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); break; + default: return GetGenericMaleTalkSfx(sound); break; } return 35 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } @@ -1696,7 +1609,7 @@ cAudioManager::GetBlackCriminalTalkSfx(int16 sound) case SOUND_PED_CAR_COLLISION: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_BLACK_CRIMINAL_1_CAR_COLLISION_1, 5u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); break; + default: return GetGenericMaleTalkSfx(sound); break; } return sfx; } @@ -1724,7 +1637,7 @@ cAudioManager::GetWhiteCriminalTalkSfx(int16 sound) case SOUND_PED_CAR_COLLISION: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_WHITE_CRIMINAL_1_CAR_COLLISION_1, 4u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); break; + default: return GetGenericMaleTalkSfx(sound); break; } return sfx; } @@ -1737,8 +1650,7 @@ cAudioManager::GetMaleNo2TalkSfx(int16 sound) switch(sound) { case SOUND_PED_CAR_JACKED: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CAR_JACKED_1, - 3u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CAR_JACKED_1, 3u); break; case SOUND_PED_ROBBED: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_ROBBED_1, 4u); @@ -1750,8 +1662,7 @@ cAudioManager::GetMaleNo2TalkSfx(int16 sound) GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_EVADE_1, 4u); break; case SOUND_PED_CAR_COLLISION: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CAR_COLLISION_1, - 7u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CAR_COLLISION_1, 7u); break; case SOUND_PED_CHAT_SEXY: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CHAT_SEXY_1, 5u); @@ -1759,7 +1670,7 @@ cAudioManager::GetMaleNo2TalkSfx(int16 sound) case SOUND_PED_CHAT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MALE_NO_2_CHAT_1, 7u); break; - default: return cAudioManager::GetGenericMaleTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); } return sfx; } @@ -2122,9 +2033,8 @@ cAudioManager::GetBlackProjectFemaleOldTalkSfx(int16 sound) 6u); break; case SOUND_PED_CAR_COLLISION: - cAudioManager::GetPhrase( - &sfx, &lastSfx, AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_OLD_1_CAR_COLLISION_1, - 7u); + GetPhrase(&sfx, &lastSfx, + AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_OLD_1_CAR_COLLISION_1, 7u); break; case SOUND_PED_CHAT_EVENT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_OLD_1_CHAT_EVENT_1, @@ -2146,9 +2056,8 @@ cAudioManager::GetBlackProjectFemaleYoungTalkSfx(int16 sound) switch(sound) { case SOUND_PED_HANDS_COWER: - cAudioManager::GetPhrase( - &sfx, &lastSfx, AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_YOUNG_1_HANDS_COWER_1, - 4u); + GetPhrase(&sfx, &lastSfx, + AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_YOUNG_1_HANDS_COWER_1, 4u); break; case SOUND_PED_CAR_JACKED: sfx = AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_YOUNG_1_CAR_JACKED_1; @@ -2162,9 +2071,8 @@ cAudioManager::GetBlackProjectFemaleYoungTalkSfx(int16 sound) 5u); break; case SOUND_PED_CAR_COLLISION: - cAudioManager::GetPhrase( - &sfx, &lastSfx, AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_YOUNG_1_CAR_COLLISION_1, - 6u); + GetPhrase(&sfx, &lastSfx, + AUDIO_SAMPLE_PED_BLACK_PROJECT_FEMALE_YOUNG_1_CAR_COLLISION_1, 6u); break; case SOUND_PED_CHAT_EVENT: GetPhrase(&sfx, &lastSfx, @@ -3173,17 +3081,15 @@ cAudioManager::GetEightTalkSfx(int16 sound) switch(sound) { case SOUND_PED_HANDS_UP: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_HANDS_UP_1, 2u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_HANDS_UP_1, 2u); break; case SOUND_PED_ROBBED: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_ROBBED_1, 2u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_ROBBED_1, 2u); break; case SOUND_PED_ATTACK: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_ATTACK_1, 6u); - break; - case SOUND_PED_EVADE: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_EVADE_1, 7u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_ATTACK_1, 6u); break; + case SOUND_PED_EVADE: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_EIGHT_EVADE_1, 7u); break; default: return GetGenericMaleTalkSfx(sound); } return sfx; @@ -3333,29 +3239,302 @@ cAudioManager::GetGenericFemaleTalkSfx(int16 sound) switch(sound) { case SOUND_PED_DEATH: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_DEATH_1, 10u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_DEATH_1, 10u); break; case SOUND_PED_BULLET_HIT: case SOUND_PED_DEFEND: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_INJURED_PED_FEMALE_OUCH_1, - 11u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_INJURED_PED_FEMALE_OUCH_1, 11u); break; case SOUND_PED_BURNING: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_BURNING_1, 9u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_BURNING_1, 9u); break; case SOUND_PED_FLEE_SPRINT: - cAudioManager::GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_FLEE_SPRINT_1, 8u); + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FEMALE_FLEE_SPRINT_1, 8u); break; default: return NO_SAMPLE; } - return sfx; -} - -WRAPPER -void -cAudioManager::PlayOneShot(int32 index, int16 sound, float vol) -{ - EAXJMP(0x57A500); + return sfx; +} + +int8 +cAudioManager::GetCurrent3DProviderIndex() const +{ + if(m_bIsInitialised) return SampleManager.GetCurrent3DProviderIndex(); + + return -1; +} + +float +cAudioManager::GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const +{ + return GetCollisionRatio(c, 0.0f, 0.02f, 0.02f); +} + +float +cAudioManager::GetCollisionOneShotRatio(uint32 a, float b) const +{ + float result; + + switch(a) { + case 0u: + case 1u: + case 5u: + case 26u: + case 31u: result = GetCollisionRatio(b, 10.0, 60.0, 50.0); break; + case 2u: + case 3u: + case 4u: + case 30u: result = GetCollisionRatio(b, 0.0, 2.0, 2.0); break; + case 6u: result = GetCollisionRatio(b, 6.0, 50.0, 44.0); break; + case 7u: + case 16u: result = GetCollisionRatio(b, 0.1, 10.0, 9.9); break; + case 8u: + case 11u: result = GetCollisionRatio(b, 30.0, 130.0, 100.0); break; + case 9u: result = GetCollisionRatio(b, 20.0, 100.0, 80.0); break; + case 10u: result = GetCollisionRatio(b, 0.0, 4.0, 4.0); break; + case 12u: + case 13u: + case 32u: result = GetCollisionRatio(b, 1.0, 10.0, 9.0); break; + case 14u: result = GetCollisionRatio(b, 1.0, 15.0, 14.0); break; + case 15u: result = GetCollisionRatio(b, 8.0, 50.0, 42.0); break; + case 17u: result = GetCollisionRatio(b, 0.0, 20.0, 20.0); break; + case 18u: + case 19u: + case 23u: + case 29u: result = GetCollisionRatio(b, 0.0, 10.0, 10.0); break; + case 20u: result = GetCollisionRatio(b, 1.0, 4.0, 3.0); break; + case 21u: result = GetCollisionRatio(b, 0.1, 5.0, 4.9); break; + case 22u: result = GetCollisionRatio(b, 0.1, 40.0, 39.9); break; + case 24u: result = GetCollisionRatio(b, 0.1, 4.0, 3.9); break; + case 25u: result = GetCollisionRatio(b, 0.0, 0.5, 0.5); break; + case 27u: result = GetCollisionRatio(b, 4.0, 40.0, 36.0); break; + case 28u: result = GetCollisionRatio(b, 0.0, 5.0, 5.0); break; + default: result = 0.0; break; + } + return result; +} + +float +cAudioManager::GetCollisionRatio(float a, float b, float c, float d) const +{ + float e; + e = a; + if(a <= b) return 0.0f; + if(c <= a) e = c; + return (e - b) / d; +} + +float +cAudioManager::GetDistanceSquared(CVector *v) const +{ + const CVector &c = TheCamera.GetPosition(); + return sq(v->x - c.x) + sq(v->y - c.y) + sq((v->z - c.z) * 0.2f); +} + +int32 +cAudioManager::GetJumboTaxiFreq() const +{ + return (60.833f * m_sQueueSample.m_fDistance) + 22050; +} + +bool +cAudioManager::GetMissionAudioLoadingStatus() const +{ + if(m_bIsInitialised) return m_sMissionAudio.m_bLoadingStatus; + + return true; +} + +char +cAudioManager::GetMissionScriptPoliceAudioPlayingStatus() const +{ + return g_nMissionAudioPlayingStatus; +} + +bool +cAudioManager::HasAirBrakes(int32 model) const +{ + return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || + model == COACH; +} + +void +cAudioManager::Initialise() +{ + if(!m_bIsInitialised) { + PreInitialiseGameSpecificSetup(); + m_bIsInitialised = SampleManager.Initialise(); + if(m_bIsInitialised) { + m_bActiveSamples = SampleManager.GetMaximumSupportedChannels(); + if(m_bActiveSamples <= 1u) { + Terminate(); + } else { + --m_bActiveSamples; + PostInitialiseGameSpecificSetup(); + InitialisePoliceRadioZones(); + InitialisePoliceRadio(); + MusicManager.Initialise(); + } + } + } +} + +WRAPPER +void +cAudioManager::InitialisePoliceRadio() +{ + EAXJMP(0x57EEC0); +} + +WRAPPER +void +cAudioManager::InitialisePoliceRadioZones() +{ + EAXJMP(0x57EAC0); +} + +void +cAudioManager::InterrogateAudioEntities() +{ + for(int32 i = 0; i < m_nAudioEntitiesTotal; i++) { + ProcessEntity(m_anAudioEntityIndices[i]); + m_asAudioEntities[m_anAudioEntityIndices[i]].m_Loops = 0; + } +} + +bool +cAudioManager::IsMissionAudioSampleFinished() +{ + if(m_bIsInitialised) return m_sMissionAudio.m_bPlayStatus == 2; + + static int32 cPretendFrame = 1; + + return (cPretendFrame++ & 63) == 0; +} + +bool +cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) const +{ + switch(soundMission) { + case STREAMED_SOUND_MISSION_J6_D: + case STREAMED_SOUND_MISSION_T4_A: + case STREAMED_SOUND_MISSION_S1_H: + case STREAMED_SOUND_MISSION_S3_B: + case STREAMED_SOUND_MISSION_EL3_A: + case STREAMED_SOUND_MISSION_A3_A: + case STREAMED_SOUND_MISSION_A5_A: + case STREAMED_SOUND_MISSION_K1_A: + case STREAMED_SOUND_MISSION_R1_A: + case STREAMED_SOUND_MISSION_R5_A: + case STREAMED_SOUND_MISSION_LO2_A: + case STREAMED_SOUND_MISSION_LO6_A: return true; + default: return false; + } +} + +void +cAudioManager::PlayLoadedMissionAudio() +{ + if(m_bIsInitialised && m_sMissionAudio.m_nSampleIndex != NO_SAMPLE && + m_sMissionAudio.m_bLoadingStatus == 1 && !m_sMissionAudio.m_bPlayStatus) { + m_sMissionAudio.m_bIsPlayed = true; + } +} + +WRAPPER +void +cAudioManager::PlayOneShot(int32 index, int16 sound, float vol) +{ + EAXJMP(0x57A500); +} + +bool &bPlayerJustEnteredCar = *(bool *)0x6508C4; + +void +cAudioManager::PlayerJustGotInCar() const +{ + if(m_bIsInitialised) { bPlayerJustEnteredCar = true; } +} + +void +cAudioManager::PlayerJustLeftCar(void) const +{ + // UNUSED: This is a perfectly empty function. +} + +void +cAudioManager::PostInitialiseGameSpecificSetup() +{ + m_nFireAudioEntity = + CreateEntity(AUDIOTYPE_FIRE, + (CPhysical *)0x8F31D0); // last is addr of firemanager @todo change + if(m_nFireAudioEntity >= 0) SetEntityStatus(m_nFireAudioEntity, 1); + + m_nCollisionEntity = CreateEntity(AUDIOTYPE_COLLISION, (CPhysical *)1); + if(m_nCollisionEntity >= 0) SetEntityStatus(m_nCollisionEntity, 1); + + m_nFrontEndEntity = CreateEntity(AUDIOTYPE_FRONTEND, (CPhysical *)1); + if(m_nFrontEndEntity >= 0) SetEntityStatus(m_nFrontEndEntity, 1); + + m_nProjectileEntity = CreateEntity(AUDIOTYPE_PROJECTILE, (CPhysical *)1); + if(m_nProjectileEntity >= 0) SetEntityStatus(m_nProjectileEntity, 1); + + m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATER_CANNON, (CPhysical *)1); + if(m_nWaterCannonEntity >= 0) SetEntityStatus(m_nWaterCannonEntity, 1); + + m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_D, (CPhysical *)1); + if(m_nPoliceChannelEntity >= 0) SetEntityStatus(m_nPoliceChannelEntity, 1); + + m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (CPhysical *)1); + if(m_nBridgeEntity >= 0) SetEntityStatus(m_nBridgeEntity, 1); + + m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; + m_sMissionAudio.m_bLoadingStatus = 0; + m_sMissionAudio.m_bPlayStatus = 0; + m_sMissionAudio.field_22 = 0; + m_sMissionAudio.m_bIsPlayed = 0; + m_sMissionAudio.field_12 = 1; + m_sMissionAudio.field_24 = 0; + ResetAudioLogicTimers((int32)CTimer::GetTimeInMilliseconds); +} + +void +cAudioManager::PostTerminateGameSpecificShutdown() +{ + ; +} + +void +cAudioManager::PreTerminateGameSpecificShutdown() +{ + if(m_nBridgeEntity >= 0) { + DestroyEntity(m_nBridgeEntity); + m_nBridgeEntity = -5; + } + if(m_nPoliceChannelEntity >= 0) { + DestroyEntity(m_nPoliceChannelEntity); + m_nPoliceChannelEntity = -5; + } + if(m_nWaterCannonEntity >= 0) { + DestroyEntity(m_nWaterCannonEntity); + m_nWaterCannonEntity = -5; + } + if(m_nFireAudioEntity >= 0) { + DestroyEntity(m_nFireAudioEntity); + m_nFireAudioEntity = -5; + } + if(m_nCollisionEntity >= 0) { + DestroyEntity(m_nCollisionEntity); + m_nCollisionEntity = -5; + } + if(m_nFrontEndEntity >= 0) { + DestroyEntity(m_nFrontEndEntity); + m_nFrontEndEntity = -5; + } + if(m_nProjectileEntity >= 0) { + DestroyEntity(m_nProjectileEntity); + m_nProjectileEntity = -5; + } } #if 1 @@ -3390,7 +3569,7 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params) rand = m_anRandomTable[0] % 10u + 70; m_sQueueSample.m_bVolume = ComputeVolume(rand, 30.0f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 13; + m_sQueueSample.m_counter = 13; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_VEHICLE_AIR_BRAKES; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_VEHICLE_AIR_BRAKES); @@ -3447,7 +3626,7 @@ cAudioManager::ProcessAirportScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_4 = counter++; + m_sQueueSample.m_counter = counter++; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -3485,7 +3664,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume(80u, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 39; + m_sQueueSample.m_counter = 39; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_MOTOR; m_sQueueSample.m_nFrequency = 10386; m_sQueueSample.m_nFrequency += @@ -3535,7 +3714,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance); if(!m_sQueueSample.m_bVolume) return 1; - m_sQueueSample.field_4 = 40; + m_sQueueSample.m_counter = 40; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex << 16) % 1000; m_sQueueSample.m_bBankIndex = 0; @@ -3562,7 +3741,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) if(padAccelerate <= 20) { emittingVol = 45 - 45 * padAccelerate / 40; m_sQueueSample.m_nFrequency = 100 * padAccelerate + 11025; - m_sQueueSample.field_4 = 39; + m_sQueueSample.m_counter = 39; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE_IDLE; if(LastAccel > 20) { @@ -3577,7 +3756,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) if(!boat->m_bIsAnchored) m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10u; - m_sQueueSample.field_4 = 40; + m_sQueueSample.m_counter = 40; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; } LastVol = emittingVol; @@ -3587,7 +3766,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) if(gasPedal > 0.0f) { m_sQueueSample.m_nFrequency = 11025; emittingVol = 45; - m_sQueueSample.field_4 = 39; + m_sQueueSample.m_counter = 39; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE_IDLE; } else { @@ -3596,7 +3775,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) if(!boat->m_bIsAnchored) m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10u; - m_sQueueSample.field_4 = 40; + m_sQueueSample.m_counter = 40; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BOAT_ENGINE; } } @@ -3639,13 +3818,13 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams *params) velocityChange = Abs(params->m_fVelocityChange); if(velocityChange <= 0.0005f && params->m_pVehicle->GetPosition().y) return 1; - velocityChange = min(0.75f, velocityChange); + velocityChange = Min(0.75f, velocityChange); multiplier = (velocityChange - 0.0005f) * 1.3342f; CalculateDistance((bool *)params, params->m_fDistance); vol = (30.f * multiplier); m_sQueueSample.m_bVolume = ComputeVolume(vol, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 38; + m_sQueueSample.m_counter = 38; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_LOOPING_WATER; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -3700,16 +3879,17 @@ void cAudioManager::ProcessBridgeMotor() { if(m_sQueueSample.m_fDistance < 400.f) { - m_sQueueSample.m_bVolume = ComputeVolume(127, 400.f, m_sQueueSample.m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(maxVolume, 400.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 1; + m_sQueueSample.m_counter = 1; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_MOTOR; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_16 = 1; m_sQueueSample.m_nFrequency = 5500; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bEmittingVolume = 127; + m_sQueueSample.m_bEmittingVolume = maxVolume; m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopEnd = @@ -3756,7 +3936,7 @@ cAudioManager::ProcessBridgeOneShots() m_sQueueSample.m_bVolume = ComputeVolume(maxVolume, maxDist, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 2; + m_sQueueSample.m_counter = 2; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_16 = 1; @@ -3782,7 +3962,7 @@ cAudioManager::ProcessBridgeWarning() if(CStats::CommercialPassed && m_sQueueSample.m_fDistance < 450.f) { m_sQueueSample.m_bVolume = ComputeVolume(100u, 450.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_nSampleIndex = 457; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -3817,7 +3997,7 @@ cAudioManager::ProcessCarBombTick(cVehicleParams *params) CalculateDistance((bool *)params, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(60u, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 35; + m_sQueueSample.m_counter = 35; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_CAR_BOMB_TICK; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -3830,8 +4010,8 @@ cAudioManager::ProcessCarBombTick(cVehicleParams *params) SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 2.0; - m_sQueueSample.m_fSoundIntensity = 40.0; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 40.0f; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 3; m_sQueueSample.m_bReverbFlag = 1; @@ -3884,7 +4064,7 @@ cAudioManager::ProcessCinemaScriptObject(uint8 sound) m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 2); - m_sQueueSample.field_4 = counter++; + m_sQueueSample.m_counter = counter++; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -3945,7 +4125,7 @@ cAudioManager::ProcessDocksScriptObject(uint8 sound) SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_DOCKS); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 3); - m_sQueueSample.field_4 = counter++; + m_sQueueSample.m_counter = counter++; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -3991,7 +4171,7 @@ cAudioManager::ProcessEngineDamage(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume(emittingVolume, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 28; + m_sQueueSample.m_counter = 28; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; @@ -4000,8 +4180,8 @@ cAudioManager::ProcessEngineDamage(cVehicleParams *params) SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 2.0; - m_sQueueSample.m_fSoundIntensity = 40.0; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_fSoundIntensity = 40.0f; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 3; m_sQueueSample.m_bReverbFlag = 1; @@ -4146,9 +4326,7 @@ cAudioManager::ProcessExplosions(int32 explosion) break; } pos = CExplosion::GetExplosionPosition(i); - m_sQueueSample.m_vecPos.x = pos->x; - m_sQueueSample.m_vecPos.y = pos->y; - m_sQueueSample.m_vecPos.z = pos->z; + m_sQueueSample.m_vecPos = *pos; distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); if(distSquared < maxDist) { m_sQueueSample.m_fDistance = Sqrt(distSquared); @@ -4156,7 +4334,7 @@ cAudioManager::ProcessExplosions(int32 explosion) ComputeVolume(maxVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = i; + m_sQueueSample.m_counter = i; m_sQueueSample.field_48 = 2.0f; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; @@ -4187,7 +4365,7 @@ cAudioManager::ProcessFireHydrant() CalculateDistance(&something, distSquared); m_sQueueSample.m_bVolume = ComputeVolume(40u, 35.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_TAXI_SOUND; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -4225,7 +4403,7 @@ cAudioManager::ProcessFrontEnd() static uint32 counter = 0; - for(uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].field_24; i++) { + for(uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_Loops; i++) { processed = 0; switch( m_asAudioEntities[0].m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex]) { @@ -4348,7 +4526,7 @@ cAudioManager::ProcessFrontEnd() SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); } m_sQueueSample.m_bVolume = 110; - m_sQueueSample.field_4 = counter++; + m_sQueueSample.m_counter = counter++; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bBankIndex = 0; @@ -4366,8 +4544,8 @@ cAudioManager::ProcessFrontEnd() AddSampleToRequestedQueue(); if(processed) { ++m_sQueueSample.m_nSampleIndex; - m_sQueueSample.field_4 = counter++; - m_sQueueSample.m_bOffset = 127 - m_sQueueSample.m_bOffset; + m_sQueueSample.m_counter = counter++; + m_sQueueSample.m_bOffset = maxVolume - m_sQueueSample.m_bOffset; AddSampleToRequestedQueue(); } } @@ -4418,7 +4596,7 @@ cAudioManager::ProcessHelicopter(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume( emittingVol, gHeliSfxRanges[i].m_fMaxDistance, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = i + 65; + m_sQueueSample.m_counter = i + 65; m_sQueueSample.m_nSampleIndex = i + AUDIO_SAMPLE_HELI_FAR; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -4432,7 +4610,7 @@ cAudioManager::ProcessHelicopter(cVehicleParams *params) SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 6.0; + m_sQueueSample.field_48 = 6.0f; m_sQueueSample.m_fSoundIntensity = gHeliSfxRanges[i].m_fMaxDistance; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 3; @@ -4481,7 +4659,7 @@ cAudioManager::ProcessHomeScriptObject(uint8 sound) m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); - m_sQueueSample.field_4 = counter++; + m_sQueueSample.m_counter = counter++; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -4546,7 +4724,7 @@ cAudioManager::ProcessJumboAccel(CPlane *plane) if(SetupJumboFlySound(20u)) { modificator = (plane->m_fSpeed - 0.10334f) * 1.676f; if(modificator > 1.0f) modificator = 1.0f; - if(cAudioManager::SetupJumboRumbleSound(maxVolume * modificator) && + if(SetupJumboRumbleSound(maxVolume * modificator) && SetupJumboTaxiSound((1.0f - modificator) * 75.f)) { if(modificator < 0.2f) { whineSoundFreq = modificator * 5.f * 14600.0f + 29500; @@ -4579,7 +4757,7 @@ cAudioManager::ProcessJumboDecel(CPlane *plane) void cAudioManager::ProcessJumboFlying() { - if(SetupJumboFlySound(127u)) SetupJumboEngineSound(63u, 22050); + if(SetupJumboFlySound(maxVolume)) SetupJumboEngineSound(63u, 22050); } void @@ -4598,12 +4776,12 @@ cAudioManager::ProcessJumboLanding(CPlane *plane) void cAudioManager::ProcessJumboTakeOff(CPlane *plane) { - double modificator = (PlanePathPosition[plane->m_nPlaneId] - TakeOffPoint) * 0.0033333f; + float modificator = (PlanePathPosition[plane->m_nPlaneId] - TakeOffPoint) * 0.0033333f; - if(cAudioManager::SetupJumboFlySound((107.f * modificator) + 20) && - cAudioManager::SetupJumboRumbleSound(maxVolume * (1.f - modificator))) { - if(cAudioManager::SetupJumboEngineSound(127u, 22050)) - cAudioManager::SetupJumboWhineSound(18.f * (1.f - modificator), 44100); + if(SetupJumboFlySound((107.f * modificator) + 20) && + SetupJumboRumbleSound(maxVolume * (1.f - modificator))) { + if(SetupJumboEngineSound(maxVolume, 22050)) + SetupJumboWhineSound(18.f * (1.f - modificator), 44100); } } @@ -4639,7 +4817,7 @@ cAudioManager::ProcessLaunderetteScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_LAUNDERETTE_1); - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -4661,7 +4839,7 @@ cAudioManager::ProcessLaunderetteScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_LAUNDERETTE_2); - m_sQueueSample.field_4 = 1; + m_sQueueSample.m_counter = 1; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -4692,7 +4870,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_1); m_sQueueSample.field_16 = 3; @@ -4704,7 +4882,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_1); m_sQueueSample.field_16 = 3; @@ -4716,7 +4894,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_2); m_sQueueSample.field_16 = 3; @@ -4728,7 +4906,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_2); m_sQueueSample.field_16 = 3; @@ -4740,7 +4918,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_3; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_3); m_sQueueSample.field_16 = 3; @@ -4752,7 +4930,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_3; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_3); m_sQueueSample.field_16 = 3; @@ -4764,7 +4942,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_4; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_4); m_sQueueSample.field_16 = 3; @@ -4776,7 +4954,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_4; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_4); m_sQueueSample.field_16 = 3; @@ -4788,7 +4966,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_5; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_5); m_sQueueSample.field_16 = 3; @@ -4800,7 +4978,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_5; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_5); m_sQueueSample.field_16 = 3; @@ -4812,7 +4990,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_6; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_6); m_sQueueSample.field_16 = 3; @@ -4824,7 +5002,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_6; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_6); m_sQueueSample.field_16 = 3; @@ -4836,7 +5014,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_7; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_7); m_sQueueSample.field_16 = 3; @@ -4848,7 +5026,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_7; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_7); m_sQueueSample.field_16 = 3; @@ -4860,7 +5038,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_8; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_8); m_sQueueSample.field_16 = 3; @@ -4872,7 +5050,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_8; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_8); m_sQueueSample.field_16 = 3; @@ -4884,7 +5062,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_9; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_9); m_sQueueSample.field_16 = 3; @@ -4896,7 +5074,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_9; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_9); m_sQueueSample.field_16 = 3; @@ -4908,7 +5086,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_10; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_10); m_sQueueSample.field_16 = 3; @@ -4920,7 +5098,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_10; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_10); m_sQueueSample.field_16 = 3; @@ -4932,7 +5110,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_11; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_11); m_sQueueSample.field_16 = 3; @@ -4944,7 +5122,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_11; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_11); m_sQueueSample.field_16 = 3; @@ -4956,7 +5134,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_12; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_12); m_sQueueSample.field_16 = 3; @@ -4968,7 +5146,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_12; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_12); m_sQueueSample.field_16 = 3; @@ -4980,7 +5158,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_13; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_13); m_sQueueSample.field_16 = 3; @@ -4992,7 +5170,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_13; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_13); m_sQueueSample.field_16 = 3; @@ -5004,7 +5182,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_STRIP_CLUB_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_STRIP_CLUB_1); m_sQueueSample.field_16 = 3; @@ -5016,7 +5194,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_STRIP_CLUB_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_STRIP_CLUB_1); m_sQueueSample.field_16 = 3; @@ -5028,7 +5206,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_STRIP_CLUB_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_STRIP_CLUB_2); m_sQueueSample.field_16 = 3; @@ -5040,7 +5218,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_STRIP_CLUB_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_STRIP_CLUB_2); m_sQueueSample.field_16 = 3; @@ -5048,11 +5226,9 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.field_48 = 2.0f; break; case SCRIPT_SOUND_WORK_SHOP_LOOP_S: - case SCRIPT_SOUND_WORK_SHOP_LOOP_L: - cAudioManager::ProcessWorkShopScriptObject(sound); - return; + case SCRIPT_SOUND_WORK_SHOP_LOOP_L: ProcessWorkShopScriptObject(sound); return; case SCRIPT_SOUND_SAWMILL_LOOP_S: - case SCRIPT_SOUND_SAWMILL_LOOP_L: cAudioManager::ProcessSawMillScriptObject(sound); return; + case SCRIPT_SOUND_SAWMILL_LOOP_L: ProcessSawMillScriptObject(sound); return; case SCRIPT_SOUND_38: maxDist = 900.f; m_sQueueSample.m_fSoundIntensity = 30.0f; @@ -5182,15 +5358,15 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) case SCRIPT_SOUND_CINEMA_LOOP_S: case SCRIPT_SOUND_CINEMA_LOOP_L: ProcessCinemaScriptObject(sound); return; case SCRIPT_SOUND_DOCKS_LOOP_S: - case SCRIPT_SOUND_DOCKS_LOOP_L: cAudioManager::ProcessDocksScriptObject(sound); return; + case SCRIPT_SOUND_DOCKS_LOOP_L: ProcessDocksScriptObject(sound); return; case SCRIPT_SOUND_HOME_LOOP_S: - case SCRIPT_SOUND_HOME_LOOP_L: cAudioManager::ProcessHomeScriptObject(sound); return; + case SCRIPT_SOUND_HOME_LOOP_L: ProcessHomeScriptObject(sound); return; case SCRIPT_SOUND_FRANKIE_PIANO: maxDist = 900.f; m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_FRANKIE_PIANO; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_FRANKIE_PIANO); m_sQueueSample.field_16 = 3; @@ -5202,7 +5378,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PARTY_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_PARTY_1); m_sQueueSample.field_16 = 3; @@ -5246,7 +5422,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_POLICE_BALL; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_POLICE_BALL); m_sQueueSample.field_16 = 2; @@ -5258,7 +5434,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_POLICE_BALL; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_POLICE_BALL); m_sQueueSample.field_16 = 2; @@ -5270,7 +5446,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_INDUSTRIAL; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_RAVE_INDUSTRIAL); m_sQueueSample.field_16 = 3; @@ -5282,7 +5458,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_INDUSTRIAL; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_RAVE_INDUSTRIAL); m_sQueueSample.field_16 = 3; @@ -5291,7 +5467,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) break; case SCRIPT_SOUND_POLICE_CELL_BEATING_LOOP_S: case SCRIPT_SOUND_POLICE_CELL_BEATING_LOOP_L: - cAudioManager::ProcessPoliceCellBeatingScriptObject(sound); + ProcessPoliceCellBeatingScriptObject(sound); return; case SCRIPT_SOUND_RAVE_1_LOOP_S: case SCRIPT_SOUND_RAVE_2_LOOP_S: @@ -5299,7 +5475,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.field_16 = 3; @@ -5312,7 +5488,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_1; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.field_16 = 3; @@ -5324,7 +5500,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_RAVE_2); m_sQueueSample.field_16 = 3; @@ -5336,7 +5512,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_RAVE_2; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_RAVE_2); m_sQueueSample.field_16 = 3; @@ -5364,7 +5540,7 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_bVolume = ComputeVolume( emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -5380,6 +5556,155 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) } } +bool &g_bMissionAudioLoadFailed = *(bool *)0x95CD8E; + +void +cAudioManager::ProcessMissionAudio() +{ + float dist; + uint8 emittingVol; + uint8 pan; + float distSquared; + CVector vec; + + static uint8 nCheckPlayingDelay = 0; + static uint8 nFramesUntilFailedLoad = 0; + static uint8 nFramesForPretendPlaying = 0; + + if(this->m_bIsInitialised) { + if(m_sMissionAudio.m_nSampleIndex != 3033) { + switch(this->m_sMissionAudio.m_bLoadingStatus) { + case 0: + SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex, + 1u); + m_sMissionAudio.m_bLoadingStatus = 1; + nFramesUntilFailedLoad = 0; + return; + case 1: + if(!this->m_sMissionAudio.m_bIsPlayed) return; + if(g_bMissionAudioLoadFailed) { + if(this->m_bTimerJustReset) { + ClearMissionAudio(); + SampleManager.StopStreamedFile(1u); + nFramesForPretendPlaying = 0; + nCheckPlayingDelay = 0; + nFramesUntilFailedLoad = 0; + } else if(!m_bUserPause) { + if(++nFramesForPretendPlaying < 120u) { + this->m_sMissionAudio.m_bPlayStatus = 1; + } else { + this->m_sMissionAudio.m_bPlayStatus = 2; + this->m_sMissionAudio.m_nSampleIndex = 3033; + } + } + } else { + if(m_sMissionAudio.m_bPlayStatus) { + if(m_sMissionAudio.m_bPlayStatus != 1) return; + if(this->m_bTimerJustReset) { + ClearMissionAudio(); + SampleManager.StopStreamedFile(1u); + return; + } + if(MissionScriptAudioUsesPoliceChannel( + m_sMissionAudio.m_nSampleIndex)) { + if(!m_bUserPause) { + if(nCheckPlayingDelay) { + --nCheckPlayingDelay; + } else if( + GetMissionScriptPoliceAudioPlayingStatus() == + 2 || + --m_sMissionAudio.field_24) { + m_sMissionAudio + .m_bPlayStatus = 2; + m_sMissionAudio + .m_nSampleIndex = 3033; + SampleManager + .StopStreamedFile(1u); + m_sMissionAudio.field_24 = + 0; + } + } + } else if(m_sMissionAudio.field_22) { + if(SampleManager.IsStreamPlaying(1u) || + m_bUserPause || m_bPreviousUserPause) { + if(m_bUserPause) + SampleManager.PauseStream( + 1, 1u); + else + SampleManager.PauseStream( + 0, 1u); + } else { + m_sMissionAudio.m_bPlayStatus = 2; + m_sMissionAudio.m_nSampleIndex = + 3033; + SampleManager.StopStreamedFile(1u); + m_sMissionAudio.field_24 = 0; + } + } else { + if(m_bUserPause) return; + if(nCheckPlayingDelay--) { + if(!SampleManager.IsStreamPlaying( + 1u)) + return; + nCheckPlayingDelay = 0; + } + m_sMissionAudio.field_22 = 1; + } + } else { + if(MissionScriptAudioUsesPoliceChannel( + m_sMissionAudio.m_nSampleIndex)) { + SetMissionScriptPoliceAudio( + m_sMissionAudio.m_nSampleIndex); + } else { + if(m_bUserPause) + SampleManager.PauseStream(1, 1u); + if(m_sMissionAudio.field_12) { + SampleManager + .SetStreamedVolumeAndPan( + 80u, 63u, 1, 1u); + } else { + distSquared = GetDistanceSquared( + &m_sMissionAudio.m_vecPos); + if(distSquared >= 2500.f) { + emittingVol = 0; + pan = 63; + } else { + dist = Sqrt(distSquared); + emittingVol = ComputeVolume( + 80u, 50.0f, dist); + TranslateEntity( + &m_sMissionAudio + .m_vecPos, + &vec); + pan = + ComputePan(50.f, &vec); + } + SampleManager + .SetStreamedVolumeAndPan( + emittingVol, pan, 1, 1u); + } + SampleManager.StartPreloadedStreamedFile( + 1u); + } + m_sMissionAudio.m_bPlayStatus = 1; + nCheckPlayingDelay = 30; + } + } + break; + case 2: + if(++nFramesUntilFailedLoad >= 90u) { + nFramesForPretendPlaying = 0; + g_bMissionAudioLoadFailed = 1; + nFramesUntilFailedLoad = 0; + this->m_sMissionAudio.m_bLoadingStatus = 1; + } + return; + default: return; + } + } + } +} + void cAudioManager::ProcessModelCarEngine(cVehicleParams *params) { @@ -5413,7 +5738,7 @@ cAudioManager::ProcessModelCarEngine(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume( emittingVol, 30.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 2; + m_sQueueSample.m_counter = 2; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_MODEL_VEHICLE_ACCELERATING; m_sQueueSample.m_bBankIndex = 0; @@ -5431,8 +5756,8 @@ cAudioManager::ProcessModelCarEngine(cVehicleParams *params) m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 3.0; - m_sQueueSample.m_fSoundIntensity = 30.0; + m_sQueueSample.field_48 = 3.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 3; m_sQueueSample.m_bReverbFlag = 1; @@ -5464,14 +5789,14 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) male.m_pPed = nil; male.m_bDistanceCalculated = 0; male.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); - cAudioManager::SetupPedComments(&male, SOUND_INJURED_PED_MALE_OUCH); + SetupPedComments(&male, SOUND_INJURED_PED_MALE_OUCH); return; case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_S: case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_L: female.m_pPed = nil; female.m_bDistanceCalculated = 0; female.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); - cAudioManager::SetupPedComments(&female, SOUND_INJURED_PED_FEMALE); + SetupPedComments(&female, SOUND_INJURED_PED_FEMALE); return; case SCRIPT_SOUND_GATE_START_CLUNK: case SCRIPT_SOUND_GATE_STOP_CLUNK: @@ -5512,7 +5837,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 80.0f; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_389; m_sQueueSample.m_bBankIndex = 0; - emittingVolume = 127; + emittingVolume = maxVolume; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_389); m_sQueueSample.field_16 = 0; @@ -5663,7 +5988,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bEmittingVolume = emittingVolume; @@ -5708,7 +6033,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_bVolume = ComputeVolume( emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bEmittingVolume = emittingVolume; @@ -5768,7 +6093,7 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 7.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = 64; + m_sQueueSample.m_counter = 64; m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HEADPHONES; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; @@ -5795,6 +6120,14 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params) } } +#if 1 +WRAPPER +void +cAudioManager::ProcessPedOneShots(cPedParams *params) +{ + EAXJMP(0x56F650); +} +#else void cAudioManager::ProcessPedOneShots(cPedParams *params) { @@ -5812,11 +6145,11 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) static uint8 iSound = 21; weapon = nil; - for(uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].field_24; i++) { + for(uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_Loops; i++) { noReflection = 0; processed = 0; m_sQueueSample.m_bRequireReflection = 0; - sound = m_asAudioEntities[0].m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex]; + sound = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i]; switch(sound) { case SOUND_STEP_START: case SOUND_STEP_END: @@ -5875,9 +6208,9 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) } m_sQueueSample.m_nSampleIndex = sampleIndex; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = - m_asAudioEntities[0] - .m_awAudioEvent[i + 20 * m_sQueueSample.m_nEntityIndex] - + m_sQueueSample.m_counter = + m_asAudioEntities[m_sQueueSample.m_nEntityIndex] + .m_awAudioEvent[i] - 28; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); @@ -5928,7 +6261,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) AUDIO_SAMPLE_PED_FALL_COLLAPSE; } m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = 1; + m_sQueueSample.m_counter = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += @@ -5950,7 +6283,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; m_sQueueSample.m_nFrequency = 18000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -5970,7 +6303,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; m_sQueueSample.m_nFrequency = 16500; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -5990,7 +6323,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_1; m_sQueueSample.m_nFrequency = 20000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6010,7 +6343,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; m_sQueueSample.m_nFrequency = 18000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6030,7 +6363,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; m_sQueueSample.m_nFrequency = 16500; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6050,7 +6383,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_2; m_sQueueSample.m_nFrequency = 20000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6070,7 +6403,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; m_sQueueSample.m_nFrequency = 18000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6090,7 +6423,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; m_sQueueSample.m_nFrequency = 16500; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6110,7 +6443,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_3; m_sQueueSample.m_nFrequency = 20000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6130,7 +6463,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; m_sQueueSample.m_nFrequency = 18000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6150,7 +6483,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; m_sQueueSample.m_nFrequency = 16500; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6170,7 +6503,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_4; m_sQueueSample.m_nFrequency = 20000; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound; + m_sQueueSample.m_counter = iSound; processed = 1; ++iSound; m_sQueueSample.field_16 = 3; @@ -6189,7 +6522,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case SOUND_WEAPON_BAT_ATTACK: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_PED_HIT_BY_BAT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = RandomDisplacement(2000u) + 22000; m_sQueueSample.field_16 = 3; @@ -6214,7 +6547,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_COLT45: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_PISTOL_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_PISTOL_SHOT); @@ -6239,7 +6572,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_UZI: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_UZI_SHOT); @@ -6260,7 +6593,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_SHOTGUN: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SHOTGUN_SHOT); @@ -6285,7 +6618,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_AK47: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_CHAINGUN_SHOT); @@ -6306,7 +6639,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_M16: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_M16_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_M16_SHOT); @@ -6327,7 +6660,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_SNIPERRIFLE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SNIPER_SHOT); @@ -6352,7 +6685,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_ROCKETLAUNCHER: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_ROCKET_SHOT); @@ -6378,7 +6711,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_FLAMETHROWER_SHOT; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = 9; + m_sQueueSample.m_counter = 9; emittingVol = 90; m_sQueueSample.m_nFrequency = (10 * m_sQueueSample.m_nEntityIndex & 2047) + @@ -6413,7 +6746,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_COLT45: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_PISTOL_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( @@ -6436,7 +6769,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_UZI: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = 39243; m_sQueueSample.m_nFrequency += RandomDisplacement(300u); @@ -6456,7 +6789,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_SHOTGUN: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = 30290; m_sQueueSample.m_nFrequency += RandomDisplacement(300u); @@ -6476,7 +6809,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_AK47: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_CHAINGUN_RELOAD); @@ -6497,7 +6830,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_M16: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_UZI_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_UZI_RELOAD); @@ -6518,7 +6851,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_SNIPERRIFLE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_SNIPER_RELOAD); @@ -6539,7 +6872,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case WEAPONTYPE_ROCKETLAUNCHER: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD; emittingVol = 75; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_ROCKET_RELOAD); @@ -6565,7 +6898,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case SOUND_WEAPON_M16_BULLET_ECHO: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_75; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_75); @@ -6590,7 +6923,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case SOUND_WEAPON_FLAMETHROWER_FIRE: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( AUDIO_SAMPLE_WEAPON_FLAMETHROWER_FIRE); m_sQueueSample.m_nFrequency += @@ -6610,7 +6943,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case SOUND_WEAPON_HIT_PED: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_BULLET_HIT_PED; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_BULLET_HIT_PED); @@ -6631,7 +6964,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) case SOUND_SPLASH: m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_WATER; m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; processed = 1; m_sQueueSample.m_nFrequency = RandomDisplacement(1400u) + 20000; m_sQueueSample.field_16 = 1; @@ -6672,16 +7005,14 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) if(noReflection) { m_sQueueSample.m_bOffset = 127; ++m_sQueueSample.m_nSampleIndex; - if(m_asAudioEntities[0].m_awAudioEvent - [i + - 20 * m_sQueueSample.m_nEntityIndex] != - 47 || + if(m_asAudioEntities[m_sQueueSample.m_nEntityIndex] + .m_awAudioEvent[i] != 47 || weapon->m_eWeaponType != WEAPONTYPE_FLAMETHROWER) { - m_sQueueSample.field_4 = iSound++; + m_sQueueSample.m_counter = iSound++; if(iSound > 60u) iSound = 21; } else { - ++m_sQueueSample.field_4; + ++m_sQueueSample.m_counter; } AddSampleToRequestedQueue(); } @@ -6690,6 +7021,7 @@ cAudioManager::ProcessPedOneShots(cPedParams *params) } } } +#endif void cAudioManager::ProcessPhysical(int32 id) @@ -6723,7 +7055,7 @@ struct tVehicleSampleData { char m_bEngineSoundType; char gap_5[3]; eAudioSamples m_nHornSample; - int m_nHornFrequency; + int32 m_nHornFrequency; char m_nSirenOrAlarmSample; int m_nSirenOrAlarmFrequency; char m_bDoorType; @@ -6733,6 +7065,15 @@ struct tVehicleSampleData { int32 *CSWTCH_554 = (int32 *)0x606A50; tVehicleSampleData *vehicleSampleData = (tVehicleSampleData *)0x606204; +#if 0 +WRAPPER +void +cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *automobile) +{ + EAXJMP(0x56B0D0); +} +#else + void cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *automobile) { @@ -6743,14 +7084,10 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * uint8 wheelInUseCounter; uint8 i; float time; - uint32 freq4; int baseFreq; uint8 vol; - unsigned int freq5; int gearNr; - int freq; - unsigned int freq3; - unsigned int freq2; + int32 freq; int freqModifier; int soundOffset; @@ -6763,13 +7100,13 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * float gasPedalAudio; CVector pos; - static uint16 LastAccel = 0; - static uint16 LastBrake = 0; + static int16 LastAccel = 0; + static int16 LastBrake = 0; static uint8 CurrentPretendGear = 1; static bool bLostTractionLastFrame = 0; static bool bHandbrakeOnLastFrame = 0; - static uint32 nCruising = 0; - static uint8 bAccelSampleStopped = 1; + static int32 nCruising = 0; + static bool bAccelSampleStopped = 1; lostTraction = 0; processedAccelSampleStopped = 0; @@ -6784,7 +7121,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * CurrentPretendGear = 1; } if(CReplay::IsPlayingBack()) { - accelerateState = 255.f * max(0.0f, min(1.0f, automobile->m_fGasPedal)); + accelerateState = 255.f * Max(0.0f, Min(1.0f, automobile->m_fGasPedal)); } else { accelerateState = Pads->GetAccelerate(); } @@ -6816,14 +7153,14 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * (automobile->m_aWheelState[1] || automobile->m_aWheelState[3])) { lostTraction = 1; } - if(0.0f != velocityChange) { // ok + if(0.0f != velocityChange) { time = params->m_pVehicle->m_vecMoveSpeed.z / velocityChange; if(time <= 0.0f) { - freqModifier = max(-0.2f, time) * -15000.f; + freqModifier = Max(-0.2f, time) * -15000.f; } else { - freqModifier = -(min(0.2f, time) * 15000.f); + freqModifier = -(Min(0.2f, time) * 15000.f); } - if(params->m_fVelocityChange < -0.001f) freqModifier = -freqModifier; // ok + if(params->m_fVelocityChange < -0.001f) freqModifier = -freqModifier; } else { freqModifier = 0; } @@ -6839,11 +7176,11 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * lostTraction) { gasPedalAudio = automobile->m_fGasPedalAudio; } else { - gasPedalAudio = min( - 1.0f, params->m_fVelocityChange / - params->m_pTransmission->fMaxReverseVelocity); // ok + gasPedalAudio = + Min(1.0f, params->m_fVelocityChange / + params->m_pTransmission->fMaxReverseVelocity); } - gasPedalAudio = max(0.0f, gasPedalAudio); // ok + gasPedalAudio = Max(0.0f, gasPedalAudio); automobile->m_fGasPedalAudio = gasPedalAudio; } else if(LastAccel > 0) { if(channelUsed) { @@ -6858,29 +7195,29 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * automobile->m_fGasPedalAudio = automobile->m_fGasPedalAudio * 0.6f; gasPedalAudio = automobile->m_fGasPedalAudio; } - if(gasPedalAudio > 0.05) { // ok - freq3 = (5000.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 19000; - if(engineSoundType == 6) freq3 >>= 1; + if(gasPedalAudio > 0.05f) { + freq = (5000.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 19000; + if(engineSoundType == 6) freq >>= 1; AddPlayerCarSample( - (25.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 40, freq3, + (25.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 40, freq, (soundOffset + AUDIO_SAMPLE_VEHICLE_ENGINE_STOPPING_GENERIC), engineSoundType, 63u, 0); } } - freq2 = (10000.f * gasPedalAudio) + 22050; - if(engineSoundType == 6) freq2 >>= 1; - AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq2, + freq = (10000.f * gasPedalAudio) + 22050; + if(engineSoundType == 6) freq >>= 1; + AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq, (engineSoundType + AUDIO_SAMPLE_VEHICLE_ENGINE_IDLE_NONE), 0, 52u, 1); - CurrentPretendGear = max(1, currentGear); + CurrentPretendGear = Max(1, currentGear); LastAccel = accelerateState; bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; bLostTractionLastFrame = lostTraction; return; } - if(nCruising) { + if(!nCruising) { if(accelerateState < 150 || !automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || lostTraction || currentGear < 2u && @@ -6903,15 +7240,14 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * vol = (25.0f * accelerationMultipler) + 60; automobile->m_fGasPedalAudio = accelerationMultipler; } - freq5 = freqModifier + baseFreq; - if(engineSoundType == 6) freq5 >>= 1; + freq = freqModifier + baseFreq; + if(engineSoundType == 6) freq >>= 1; if(channelUsed) { SampleManager.StopChannel(m_bActiveSamples); bAccelSampleStopped = 1; } - AddPlayerCarSample(vol, freq5, - (engineSoundType + AUDIO_SAMPLE_PAYPHONE_RINGING), 0, 2u, - 1); + AddPlayerCarSample( + vol, freq, (engineSoundType + AUDIO_SAMPLE_PAYPHONE_RINGING), 0, 2u, 1); LastAccel = accelerateState; bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; @@ -6981,10 +7317,10 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * SampleManager.SetChannelEmittingVolume(m_bActiveSamples, 85u); SampleManager.SetChannel3DPosition(m_bActiveSamples, pos.x, pos.y, pos.z); SampleManager.SetChannel3DDistances(m_bActiveSamples, 50.f, 12.5f); - if(engineSoundType == 6) - freq = (CSWTCH_554[CurrentPretendGear] + freqModifier + 22050) >> 1; - else - freq = CSWTCH_554[CurrentPretendGear] + freqModifier + 22050; + freq = CSWTCH_554[CurrentPretendGear] + freqModifier + 22050; + + if(engineSoundType == 6) freq >>= 1; + SampleManager.SetChannelFrequency(m_bActiveSamples, freq); if(!channelUsed) { SampleManager.SetChannelReverbFlag( @@ -7010,9 +7346,9 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * } else if(nCruising > 3) { --nCruising; } - freq4 = 27 * nCruising + freqModifier + 22050; - if(engineSoundType == 6) freq4 >>= 1; - AddPlayerCarSample(85u, freq4, + freq = 27 * nCruising + freqModifier + 22050; + if(engineSoundType == 6) freq >>= 1; + AddPlayerCarSample(85u, freq, (soundOffset + AUDIO_SAMPLE_VEHICLE_ENGINE_CHANGE_GEAR_GENERIC), engineSoundType, 64u, 1); } @@ -7021,6 +7357,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; bLostTractionLastFrame = lostTraction; } +#endif WRAPPER void @@ -7096,7 +7433,7 @@ cAudioManager::ProcessPornCinema(uint8 sound) if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -7125,7 +7462,7 @@ cAudioManager::ProcessPornCinema(uint8 sound) m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency >> 4); - m_sQueueSample.field_4 = rand + 1; + m_sQueueSample.m_counter = rand + 1; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -7166,7 +7503,7 @@ cAudioManager::ProcessRainOnVehicle(cVehicleParams *params) m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 22.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.field_4 = veh->m_bRainSamplesCounter++; + m_sQueueSample.m_counter = veh->m_bRainSamplesCounter++; veh = params->m_pVehicle; if(veh->m_bRainSamplesCounter > 4u) veh->m_bRainSamplesCounter = 68; m_sQueueSample.m_nSampleIndex = @@ -7179,8 +7516,8 @@ cAudioManager::ProcessRainOnVehicle(cVehicleParams *params) m_sQueueSample.m_bEmittingVolume = (uint8)emittingVol; m_sQueueSample.m_nLoopStart = 0; m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.field_48 = 0.0; - m_sQueueSample.m_fSoundIntensity = 22.0; + m_sQueueSample.field_48 = 0.0f; + m_sQueueSample.m_fSoundIntensity = 22.0f; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bReverbFlag = 0; m_sQueueSample.m_bRequireReflection = 0; @@ -7190,6 +7527,73 @@ cAudioManager::ProcessRainOnVehicle(cVehicleParams *params) } } +void +cAudioManager::ProcessReverb() const +{ + if(SampleManager.UpdateReverb() && m_bDynamicAcousticModelingStatus) { + for(uint32 i = 0; i < 28; i++) { + if(m_asActiveSamples[i].m_bReverbFlag) + SampleManager.SetChannelReverbFlag(i, 1); + } + } +} + +bool +cAudioManager::ProcessReverseGear(cVehicleParams *params) +{ + CVehicle *veh; + CAutomobile *automobile; + int32 emittingVol; + float modificator; + + if(params->m_fDistance >= 900.f) return 0; + veh = params->m_pVehicle; + if(veh->bEngineOn && (veh->m_fGasPedal < 0.0f || !veh->m_nCurrentGear)) { + CalculateDistance((bool *)params, params->m_fDistance); + automobile = (CAutomobile *)params->m_pVehicle; + if(automobile->m_nWheelsOnGround) { + modificator = params->m_fVelocityChange / + params->m_pTransmission->fMaxReverseVelocity; + } else { + if(automobile->m_nDriveWheelsOnGround) + automobile->m_fGasPedalAudio = automobile->m_fGasPedalAudio * 0.4f; + modificator = automobile->m_fGasPedalAudio; + } + modificator = Abs(modificator); + emittingVol = (24.f * modificator); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 30.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + if(params->m_pVehicle->m_fGasPedal >= 0.0f) { + m_sQueueSample.m_counter = 62; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_REVERSE_GEAR_CONSTANT; + } else { + m_sQueueSample.m_counter = 61; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_REVERSE_GEAR_ACCELERATING; + } + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + m_sQueueSample.m_nFrequency = (6000.f * modificator) + 7000; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 3.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 5; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + return 1; +} + void cAudioManager::ProcessSawMillScriptObject(uint8 sound) { @@ -7215,7 +7619,7 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_SAWMILL_1); - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -7239,7 +7643,7 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_4 = 1; + m_sQueueSample.m_counter = 1; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -7261,10 +7665,8 @@ cAudioManager::ProcessScriptObject(int32 id) { cAudioScriptObject *entity = (cAudioScriptObject *)m_asAudioEntities[id].m_pEntity; if(entity) { - m_sQueueSample.m_vecPos.x = entity->m_vecPos.x; - m_sQueueSample.m_vecPos.y = entity->m_vecPos.y; - m_sQueueSample.m_vecPos.z = entity->m_vecPos.z; - if(m_asAudioEntities[id].field_24 == 1) + m_sQueueSample.m_vecPos = entity->m_vecPos; + if(m_asAudioEntities[id].m_Loops == 1) ProcessOneShotScriptObject(m_asAudioEntities[id].m_awAudioEvent[0]); else ProcessLoopingScriptObject(entity->m_wSound); @@ -7297,7 +7699,7 @@ cAudioManager::ProcessShopScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_SHOP_1); - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -7322,7 +7724,7 @@ cAudioManager::ProcessShopScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency( m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_4 = rand + 1; + m_sQueueSample.m_counter = rand + 1; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.field_56 = 1; @@ -7364,6 +7766,79 @@ cAudioManager::ProcessSpecial() } } +bool +cAudioManager::ProcessTrainNoise(cVehicleParams *params) +{ + CTrain *train; + int32 emittingVol; + float speedMultipler; + + if(params->m_fDistance >= 90000.f) return 0; + + if(params->m_fVelocityChange <= 0.0f) { + CalculateDistance((bool *)params, params->m_fDistance); + train = (CTrain *)params->m_pVehicle; + speedMultipler = Min(1.0f, train->m_fSpeed * 250.f / 51.f); + emittingVol = (75.f * speedMultipler); + if(train->m_fWagonPosition == 0.0f) { + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 300.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 32; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_TRAIN_FAR; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 2; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_TRAIN_FAR); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 3.0f; + m_sQueueSample.m_fSoundIntensity = 300.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + if(params->m_fDistance < 4900.f) { + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 70.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 33; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_TRAIN_CLOSE; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_TRAIN_CLOSE) + + 100 * m_sQueueSample.m_nEntityIndex % 987; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 6.0f; + m_sQueueSample.m_fSoundIntensity = 70.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } + return 1; +} + #if 1 WRAPPER void @@ -7371,6 +7846,7 @@ cAudioManager::ProcessVehicle(CVehicle *) { EAXJMP(0x569A00); } + #else void cAudioManager::ProcessVehicle(CVehicle *) @@ -7379,6 +7855,159 @@ cAudioManager::ProcessVehicle(CVehicle *) } #endif +bool +cAudioManager::ProcessVehicleDoors(cVehicleParams *params) +{ + CAutomobile *automobile; + int8 doorState; + int32 emittingVol; + float velocity; + + if(params->m_fDistance >= 1600.f) return 0; + + automobile = (CAutomobile *)params->m_pVehicle; + CalculateDistance((bool *)params, params->m_fDistance); + for(int32 i = 0; i < 6; i++) { + if(automobile->Damage.GetDoorStatus(i) == 2) { + doorState = automobile->Doors[i].m_nDoorState; + if(doorState == 1 || doorState == 2) { + velocity = Min(0.3f, Abs(automobile->Doors[i].m_fAngVel)); + if(velocity > 0.0035f) { + emittingVol = (100.f * velocity * 10.f / 3.f); + m_sQueueSample.m_bVolume = ComputeVolume( + emittingVol, 40.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = i + 6; + m_sQueueSample.m_nSampleIndex = + m_anRandomTable[1] % 6u + + AUDIO_SAMPLE_CAR_DOOR_MOVEMENT_1; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency( + m_sQueueSample.m_nSampleIndex) + + RandomDisplacement(1000u); + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 10; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.field_48 = 1.0f; + m_sQueueSample.m_fSoundIntensity = 40.0f; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 1; + AddSampleToRequestedQueue(); + } + } + } + } + } + return 1; +} + +bool +cAudioManager::ProcessVehicleReverseWarning(cVehicleParams *params) +{ + CVehicle *veh = params->m_pVehicle; + + if(params->m_fDistance >= 2500.f) return 0; + + if(veh->bEngineOn && veh->m_fGasPedal < 0.0f) { + CalculateDistance((bool *)params, params->m_fDistance); + m_sQueueSample.m_bVolume = ComputeVolume(60u, 50.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 12; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_VEHICLE_REVERSE_WARNING; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 2; + m_sQueueSample.m_nFrequency = + (100 * m_sQueueSample.m_nEntityIndex & 0x3FF) + + SampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_VEHICLE_REVERSE_WARNING); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = 60; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 3.0f; + m_sQueueSample.m_fSoundIntensity = 50.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 3; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + return 1; +} + +bool +cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) +{ + int32 emittingVol; + uint32 freq; + float modificator; + int sampleFreq; + float velocity; + + if(params->m_fDistance >= 9025.f) return 0; + if(params->m_pTransmission) { + if(params->m_pVehicle->m_vecMoveSpeed.z) { + velocity = Abs(params->m_fVelocityChange); + if(velocity > 0.0f) { + CalculateDistance((bool *)params, params->m_fDistance); + emittingVol = + 30.f * + Min(1.f, + velocity / (0.5f * params->m_pTransmission->fMaxVelocity)); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 95.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 0; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + if(params->m_pVehicle->m_nSurfaceTouched == + SURFACE_PUDDLE) { + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_LOOPING_WATER; + freq = 6050 * emittingVol / 30 + 16000; + } else { + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; + modificator = + m_sQueueSample.m_fDistance * 1.f / 95.f * 0.5f; + sampleFreq = SampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); + freq = (sampleFreq * modificator) + + ((3 * sampleFreq) >> 2); + } + m_sQueueSample.m_nFrequency = freq; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 6.0f; + m_sQueueSample.m_fSoundIntensity = 95.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 4; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } + } + return 1; +} + WRAPPER void cAudioManager::ProcessWaterCannon(int32) { EAXJMP(0x575F30); } @@ -7389,6 +8018,60 @@ cAudioManager::ProcessWeather(int32 id) EAXJMP(0x578370); } +bool +cAudioManager::ProcessWetRoadNoise(cVehicleParams *params) +{ + float relativeVelocity; + int32 emittingVol; + float modificator; + int freq; + float velChange; + + if(params->m_fDistance >= 900.f) return 0; + if(params->m_pTransmission) { + if(params->m_pVehicle->m_vecMoveSpeed.z) { + velChange = Abs(params->m_fVelocityChange); + if(velChange > 0.f) { + CalculateDistance((bool *)params, params->m_fDistance); + relativeVelocity = + Min(1.0f, + velChange / (0.5f * params->m_pTransmission->fMaxVelocity)); + emittingVol = 23.0f * relativeVelocity * CWeather::WetRoads; + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 30.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 1; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + modificator = m_sQueueSample.m_fDistance * 1.f / 3.f * 0.5f; + freq = SampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); + m_sQueueSample.m_nFrequency = freq + freq * modificator; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 6.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 4; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } + } + return 1; +} + void cAudioManager::ProcessWorkShopScriptObject(uint8 sound) { @@ -7413,7 +8096,7 @@ cAudioManager::ProcessWorkShopScriptObject(uint8 sound) m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_WORK_SHOP); - m_sQueueSample.field_4 = 0; + m_sQueueSample.m_counter = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.field_56 = 0; @@ -7481,10 +8164,8 @@ cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) emittingVol, soundIntensity, m_sQueueSample.m_fDistance); pedComment.field_25 = 10; if(m_sQueueSample.m_bVolume) { - pedComment.field_4 = m_sQueueSample.m_nEntityIndex; - pedComment.m_vecPos.x = m_sQueueSample.m_vecPos.x; - pedComment.m_vecPos.y = m_sQueueSample.m_vecPos.y; - pedComment.m_vecPos.z = m_sQueueSample.m_vecPos.z; + pedComment.m_entityIndex = m_sQueueSample.m_nEntityIndex; + pedComment.m_vecPos = m_sQueueSample.m_vecPos; pedComment.m_fDistance = m_sQueueSample.m_fDistance; pedComment.m_bVolume = m_sQueueSample.m_bVolume; m_sPedComments.Add(&pedComment); @@ -7548,10 +8229,8 @@ cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) emittingVol, soundIntensity, m_sQueueSample.m_fDistance); pedComment.field_25 = 10; if(m_sQueueSample.m_bVolume) { - pedComment.field_4 = m_sQueueSample.m_nEntityIndex; - pedComment.m_vecPos.x = m_sQueueSample.m_vecPos.x; - pedComment.m_vecPos.y = m_sQueueSample.m_vecPos.y; - pedComment.m_vecPos.z = m_sQueueSample.m_vecPos.z; + pedComment.m_entityIndex = m_sQueueSample.m_nEntityIndex; + pedComment.m_vecPos = m_sQueueSample.m_vecPos; pedComment.m_fDistance = m_sQueueSample.m_fDistance; pedComment.m_bVolume = m_sQueueSample.m_bVolume; m_sPedComments.Add(&pedComment); @@ -7614,6 +8293,7 @@ WRAPPER void cAudioManager::PreloadMissionAudio(char *) STARTPATCHES InjectHook(0x5755C0, &cPedComments::Add, PATCH_JUMP); +InjectHook(0x575730, &cPedComments::Process, PATCH_JUMP); InjectHook(0x57B210, &cAudioManager::AddDetailsToRequestedOrderList, PATCH_JUMP); InjectHook(0x56AD30, &cAudioManager::AddPlayerCarSample, PATCH_JUMP); @@ -7642,7 +8322,7 @@ InjectHook(0x57AC60, &cAudioManager::TranslateEntity, PATCH_JUMP); InjectHook(0x57A0E0, &cAudioManager::Initialise, PATCH_JUMP); InjectHook(0x569420, &cAudioManager::PostInitialiseGameSpecificSetup, PATCH_JUMP); // InjectHook(0x57EAC0, &cAudioManager::InitialisePoliceRadioZones, PATCH_JUMP); -// InjectHook(0x569650, &cAudioManager::ResetAudioLogicTimers, PATCH_JUMP); +InjectHook(0x569650, &cAudioManager::ResetAudioLogicTimers, PATCH_JUMP); InjectHook(0x57A150, &cAudioManager::Terminate, PATCH_JUMP); InjectHook(0x57F050, &cAudioManager::GetMissionScriptPoliceAudioPlayingStatus, PATCH_JUMP); @@ -7814,20 +8494,27 @@ InjectHook(0x56EC00, &cAudioManager::ProcessJumboTakeOff, PATCH_JUMP); InjectHook(0x56EA10, &cAudioManager::ProcessJumboTaxi, PATCH_JUMP); InjectHook(0x5777E0, &cAudioManager::ProcessLaunderetteScriptObject, PATCH_JUMP); InjectHook(0x576770, &cAudioManager::ProcessLoopingScriptObject, PATCH_JUMP); +InjectHook(0x5796E0, &cAudioManager::ProcessMissionAudio, PATCH_JUMP); InjectHook(0x56A050, &cAudioManager::ProcessModelCarEngine, PATCH_JUMP); InjectHook(0x5760C0, &cAudioManager::ProcessOneShotScriptObject, PATCH_JUMP); InjectHook(0x56F450, &cAudioManager::ProcessPed, PATCH_JUMP); InjectHook(0x56F4D0, &cAudioManager::ProcessPedHeadphones, PATCH_JUMP); -InjectHook(0x56F650, &cAudioManager::ProcessPedOneShots, PATCH_JUMP); +// InjectHook(0x56F650, &cAudioManager::ProcessPedOneShots, PATCH_JUMP); InjectHook(0x5699C0, &cAudioManager::ProcessPhysical, PATCH_JUMP); InjectHook(0x56E860, &cAudioManager::ProcessPlane, PATCH_JUMP); InjectHook(0x56B0D0, &cAudioManager::ProcessPlayersVehicleEngine, PATCH_JUMP); InjectHook(0x577280, &cAudioManager::ProcessPornCinema, PATCH_JUMP); InjectHook(0x569CC0, &cAudioManager::ProcessRainOnVehicle, PATCH_JUMP); +InjectHook(0x569700, &cAudioManager::ProcessReverb, PATCH_JUMP); +InjectHook(0x569E50, &cAudioManager::ProcessReverseGear, PATCH_JUMP); InjectHook(0x577630, &cAudioManager::ProcessSawMillScriptObject, PATCH_JUMP); InjectHook(0x576070, &cAudioManager::ProcessScriptObject, PATCH_JUMP); InjectHook(0x577970, &cAudioManager::ProcessShopScriptObject, PATCH_JUMP); InjectHook(0x5697D0, &cAudioManager::ProcessSpecial, PATCH_JUMP); +InjectHook(0x56DBF0, &cAudioManager::ProcessTrainNoise, PATCH_JUMP); +InjectHook(0x56C770, &cAudioManager::ProcessVehicleDoors, PATCH_JUMP); +InjectHook(0x56C640, &cAudioManager::ProcessVehicleReverseWarning, PATCH_JUMP); +InjectHook(0x56A230, &cAudioManager::ProcessVehicleRoadNoise, PATCH_JUMP); InjectHook(0x577530, &cAudioManager::ProcessWorkShopScriptObject, PATCH_JUMP); InjectHook(0x570690, &cAudioManager::SetupPedComments, PATCH_JUMP); ENDPATCHES diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 12e823b7..5ad14050 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "AudioSamples.h" #include "DMAudio.h" @@ -8,7 +8,7 @@ class tActiveSample { public: int32 m_nEntityIndex; - int32 field_4; + int32 m_counter; int32 m_nSampleIndex; uint8 m_bBankIndex; uint8 m_bIsDistant; @@ -49,6 +49,8 @@ public: uint8 field_89; uint8 field_90; uint8 field_91; + + // no methods }; static_assert(sizeof(tActiveSample) == 92, "tActiveSample: error"); @@ -84,8 +86,10 @@ public: int16 m_awAudioEvent[4]; uint8 gap_18[2]; float m_afVolume[4]; - uint8 field_24; // is looping + uint8 m_Loops; uint8 field_25[3]; + + // no methods }; static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); @@ -93,13 +97,15 @@ static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); class tPedComment { public: - int m_nSampleIndex; - int field_4; + int32 m_nSampleIndex; + int32 m_entityIndex; CVector m_vecPos; float m_fDistance; uint8 m_bVolume; - uint8 field_25; + int8 field_25; // allocated time? uint8 gap_26[2]; + + // no methods }; static_assert(sizeof(tPedComment) == 28, "tPedComment: error"); @@ -108,12 +114,14 @@ class cPedComments { public: tPedComment m_asPedComments[2][20]; - uint8 field_1120[2][20]; + uint8 indexMap[2][20]; uint8 nrOfCommentsInBank[2]; uint8 activeBank; uint8 gap_1163[1]; + // reversed all methods void Add(tPedComment *com); /// ok + void Process(); /// ok }; static_assert(sizeof(cPedComments) == 1164, "cPedComments: error"); @@ -134,6 +142,8 @@ public: CVector m_vecPosition; float m_fDistance; int32 m_nBaseVolume; + + // no methods }; static_assert(sizeof(cAudioCollision) == 40, "cAudioCollision: error"); @@ -176,6 +186,7 @@ class CPlane; class CVehicle; class CPed; class cPedParams; +class cTransmission; class cAudioScriptObject { public: @@ -271,9 +282,10 @@ public: uint8 field_19192; uint8 m_bUserPause; uint8 m_bPreviousUserPause; - uint8 field_19195; + uint8 field_19195; // time? uint32 m_FrameCounter; +<<<<<<< HEAD inline uint32 GetFrameCounter(void) { return m_FrameCounter; } float GetReflectionsDistance(int32 idx) { return m_afReflectionsDistances[idx]; } <<<<<<< HEAD @@ -283,25 +295,36 @@ public: >>>>>>> Cleanup // +======= + // getters + uint32 GetFrameCounter() const { return m_FrameCounter; } + float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } + int32 GetRandomTabe(int32 idx) const { return m_anRandomTable[idx]; } +>>>>>>> More more more audio + // "Should" be in alphabetic order, except "getXTalkSfx" void AddDetailsToRequestedOrderList(uint8 sample); /// ok void AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 unk1, - uint8 unk2, bool notLooping); /// ok - void AddReflectionsToRequestedQueue(); /// ok (check value) - void AddReleasingSounds(); // todo (difficult) - void AddSampleToRequestedQueue(); /// ok - void AgeCrimes(); // todo - int8 GetCurrent3DProviderIndex(); /// ok + uint8 counter, bool notLooping); /// ok + void AddReflectionsToRequestedQueue(); /// ok (check value) + void AddReleasingSounds(); // todo (difficult) + void AddSampleToRequestedQueue(); /// ok + void AgeCrimes(); // todo void CalculateDistance(bool *ptr, float dist); /// ok - bool CheckForAnAudioFileOnCD(); /// ok + bool CheckForAnAudioFileOnCD() const; /// ok void ClearMissionAudio(); /// ok void ClearRequestedQueue(); /// ok int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, - float speedMultiplier); /// ok + float speedMultiplier) const; /// ok int32 ComputePan(float, CVector *); // todo +<<<<<<< HEAD uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance); /// ok int32 CreateEntity(int32 type, void *entity); /// ok +======= + uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance) const; /// ok + int32 CreateEntity(int32 type, CPhysical *entity); /// ok +>>>>>>> More more more audio void DestroyAllGameCreatedEntities(); /// ok void DestroyEntity(int32 id); /// ok @@ -309,89 +332,60 @@ public: void GenerateIntegerRandomNumberTable(); /// ok - float GetDistanceSquared(CVector *v); /// ok - - void TranslateEntity(CVector *v1, CVector *v2); /// ok + void TranslateEntity(CVector *v1, CVector *v2) const ; /// ok - // done - - void Initialise(); - void PostInitialiseGameSpecificSetup(); - void InitialisePoliceRadioZones(); // todo - void ResetAudioLogicTimers(int32 timer); // todo + void ResetAudioLogicTimers(int32 timer); /// ok void Terminate(); + uint8 GetNum3DProvidersAvailable() const; + bool IsMP3RadioChannelAvailable() const; + uint8 GetCDAudioDriveLetter() const; - char GetMissionScriptPoliceAudioPlayingStatus(); - bool GetMissionAudioLoadingStatus(); - - uint8 GetNum3DProvidersAvailable(); - bool IsMP3RadioChannelAvailable(); - uint8 GetCDAudioDriveLetter(); + void SetEffectsMasterVolume(uint8 volume) const; + void SetMusicMasterVolume(uint8 volume) const; + void SetEffectsFadeVolume(uint8 volume) const; + void SetMusicFadeVolume(uint8 volume) const; - void SetEffectsMasterVolume(uint8 volume); - void SetMusicMasterVolume(uint8 volume); - void SetEffectsFadeVolume(uint8 volume); - void SetMusicFadeVolume(uint8 volume); - - void SetSpeakerConfig(int32 conf); + void SetSpeakerConfig(int32 conf) const; bool SetupJumboEngineSound(uint8, int32); // todo - void PreInitialiseGameSpecificSetup(); - void SetMissionScriptPoliceAudio(int32 sfx); - - bool UsesSiren(int32 model); - bool UsesSirenSwitching(int32 model); + void PreInitialiseGameSpecificSetup() const; + void SetMissionScriptPoliceAudio(int32 sfx) const; - bool MissionScriptAudioUsesPoliceChannel(int32 soundMission); + bool UsesSiren(int32 model) const; + bool UsesSirenSwitching(int32 model) const; - char *Get3DProviderName(uint8 id); + char *Get3DProviderName(uint8 id) const; bool SetupJumboFlySound(uint8 emittingVol); /// ok bool SetupJumboRumbleSound(uint8 emittingVol); /// ok bool SetupJumboTaxiSound(uint8 vol); /// ok bool SetupJumboWhineSound(uint8 emittingVol, int32 freq); /// ok - void PlayLoadedMissionAudio(); - void SetMissionAudioLocation(float x, float y, float z); void ResetPoliceRadio(); - void InterrogateAudioEntities(); - - bool UsesReverseWarning(int32 model); - bool HasAirBrakes(int32 model); - - int32 GetJumboTaxiFreq(); + bool UsesReverseWarning(int32 model) const; - bool IsMissionAudioSampleFinished(); + int32 RandomDisplacement(uint32 seed) const; - void InitialisePoliceRadio(); // todo - - int32 RandomDisplacement(uint32 seed); - - void ReleaseDigitalHandle(); - void ReacquireDigitalHandle(); + void ReleaseDigitalHandle() const; + void ReacquireDigitalHandle() const; void SetDynamicAcousticModelingStatus(bool status); bool IsAudioInitialised() const; void SetEntityStatus(int32 id, bool status); - void PreTerminateGameSpecificShutdown(); - void PostTerminateGameSpecificShutdown(); - - void PlayerJustGotInCar(); - void PlayerJustLeftCar(); - void Service(); - void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset); + void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const; - void DoJumboVolOffset(); + void DoJumboVolOffset() const; int32 GetPedCommentSfx(CPed *ped, int32 sound); + // order from GetPedCommentSfx uint32 GetPlayerTalkSfx(int16 sound); uint32 GetCopTalkSfx(int16 sound); uint32 GetSwatTalkSfx(int16 sound); @@ -469,8 +463,38 @@ public: uint32 GetGenericMaleTalkSfx(int16 sound); uint32 GetGenericFemaleTalkSfx(int16 sound); + int8 GetCurrent3DProviderIndex() const; /// ok + float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // todo hook + float GetCollisionOneShotRatio(uint32 a, float b) const; // todo hook + float GetCollisionRatio(float a, float b, float c, float d) const; // todo hook + float GetDistanceSquared(CVector *v) const; /// ok + int32 GetJumboTaxiFreq() const; /// ok + bool GetMissionAudioLoadingStatus() const; /// ok + char GetMissionScriptPoliceAudioPlayingStatus() const; /// ok + float GetVehicleDriveWheelSkidValue(uint8 a1, CAutomobile *a2, cTransmission *a3, + float a4); // todo + int32 GetVehicleNonDriveWheelSkidValue(float a1, int a2, int a3, int a4, float a5); // todo + + bool HasAirBrakes(int32 model) const; /// ok + + void Initialise(); /// ok + void InitialisePoliceRadio(); // todo + void InitialisePoliceRadioZones(); // todo + void InterrogateAudioEntities(); /// ok + bool IsMissionAudioSampleFinished(); /// ok + + bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; /// ok + + void PlayLoadedMissionAudio(); /// ok void PlayOneShot(int32 index, int16 sound, float vol); // todo - + uint32 PlaySuspectLastSeen(float x, float y, float z); // todo + void PlayerJustGotInCar() const; /// ok + void PlayerJustLeftCar() const; /// ok + void PostInitialiseGameSpecificSetup(); /// ok + void PostTerminateGameSpecificShutdown(); /// ok + void PreTerminateGameSpecificShutdown(); /// ok + void PreloadMissionAudio(char *); // todo + /// processX - main logic of adding new sounds void ProcessActiveQueues(); // todo bool ProcessAirBrakes(cVehicleParams *params); /// ok void ProcessAirportScriptObject(uint8 sound); /// ok @@ -503,40 +527,40 @@ public: void ProcessJumboTaxi(); /// ok void ProcessLaunderetteScriptObject(uint8 sound); /// ok void ProcessLoopingScriptObject(uint8 sound); /// ok - // void ProcessMissionAudio(); - void ProcessModelCarEngine(cVehicleParams *params); /// (check float comparisons) - void ProcessOneShotScriptObject(uint8 sound); /// ok - void ProcessPed(CPhysical *ped); /// ok - void ProcessPedHeadphones(cPedParams *params); /// ok - void ProcessPedOneShots(cPedParams *params); /// ok - void ProcessPhysical(int32 id); /// ok - void ProcessPlane(cVehicleParams *params); /// ok + void ProcessMissionAudio(); /// ok + void ProcessModelCarEngine(cVehicleParams *params); /// ok (check float comparisons) + void ProcessOneShotScriptObject(uint8 sound); /// ok + void ProcessPed(CPhysical *ped); /// ok + void ProcessPedHeadphones(cPedParams *params); /// ok + void ProcessPedOneShots(cPedParams *params); // todo later (weird) + void ProcessPhysical(int32 id); /// ok + void ProcessPlane(cVehicleParams *params); /// ok void ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *automobile); /// ok (check float comparisons) void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo void ProcessPornCinema(uint8 sound); /// ok void ProcessProjectiles(); // todo requires CProjectileInfo void ProcessRainOnVehicle(cVehicleParams *params); /// ok - // void ProcessReverb(); - // bool ProcessReverseGear(void *); - void ProcessSawMillScriptObject(uint8 sound); /// ok - void ProcessScriptObject(int32 id); /// ok - void ProcessShopScriptObject(uint8 sound); /// ok - void ProcessSpecial(); /// ok - // bool ProcessTrainNoise(void *); - void ProcessVehicle(CVehicle *); // todo - // bool ProcessVehicleDoors(void *); + void ProcessReverb() const; /// ok + bool ProcessReverseGear(cVehicleParams *a2); /// ok + void ProcessSawMillScriptObject(uint8 sound); /// ok + void ProcessScriptObject(int32 id); /// ok + void ProcessShopScriptObject(uint8 sound); /// ok + void ProcessSpecial(); /// ok + bool ProcessTrainNoise(cVehicleParams *params); /// ok + void ProcessVehicle(CVehicle *); // todo + bool ProcessVehicleDoors(cVehicleParams *params); /// ok // bool ProcessVehicleEngine(void *); - // void ProcessVehicleHorn(void *); + // void ProcessVehicleHorn(cVehicleParams *params); // void ProcessVehicleOneShots(void *); - // bool ProcessVehicleReverseWarning(void *); - // bool ProcessVehicleRoadNoise(void *); + bool ProcessVehicleReverseWarning(cVehicleParams *params); /// ok + bool ProcessVehicleRoadNoise(cVehicleParams *params); /// ok // void ProcessVehicleSirenOrAlarm(void *); // void ProcessVehicleSkidding(void *); - void ProcessWaterCannon(int32); // todo - void ProcessWeather(int32 id); // todo - // bool ProcessWetRoadNoise(void *); - void ProcessWorkShopScriptObject(uint8 sound); /// ok + void ProcessWaterCannon(int32); // todo + void ProcessWeather(int32 id); // todo + bool ProcessWetRoadNoise(cVehicleParams *params); // todo hook + void ProcessWorkShopScriptObject(uint8 sound); /// ok void SetupPedComments(cPedParams *params, uint32 sound); /// ok }; diff --git a/src/audio/sampman.cpp b/src/audio/sampman.cpp index de222493..58da6f64 100644 --- a/src/audio/sampman.cpp +++ b/src/audio/sampman.cpp @@ -158,14 +158,14 @@ release_existing() if ( opened_samples[i] ) { AIL_release_3D_sample_handle(opened_samples[i]); - opened_samples[i] = NULL; + opened_samples[i] = 0; } } if ( opened_provider ) { AIL_close_3D_provider(opened_provider); - opened_provider = NULL; + opened_provider = 0; } _fPrevEaxRatioDestination = 0.0f; @@ -879,7 +879,7 @@ cSampleManager::Initialise(void) _maxSamples = 0; - opened_provider = NULL; + opened_provider = 0; DIG = NULL; for ( int32 i = 0; i < MAXCHANNELS; i++ ) @@ -2020,10 +2020,9 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) { uint32 i = 0; - if ( !_bIsMp3Active ) goto FIND_MP3TRACK; - do { + if(_bIsMp3Active){ if ( ++_CurMP3Index >= nNumMP3s ) _CurMP3Index = 0; @@ -2059,21 +2058,15 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) AIL_pause_stream(mp3Stream[nStream], 0); return true; } - - goto NEXT_MP3TRACK; - -FIND_MP3TRACK: - if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) - position = 0; - - tMP3Entry *e; - if ( !_GetMP3PosFromStreamPos(&position, &e) ) - { - if ( e == NULL ) - { - nFile = 0; - goto PLAY_STREAMEDTRACK; - } + } + if(nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER]) position = 0; + + tMP3Entry *e; + if(!_GetMP3PosFromStreamPos(&position, &e)) { + if(e == NULL) { + nFile = 0; + goto PLAY_STREAMEDTRACK; + } } if ( e->pLinkPath != NULL ) @@ -2097,14 +2090,12 @@ FIND_MP3TRACK: return true; } -NEXT_MP3TRACK: _bIsMp3Active = false; } while ( ++i < nNumMP3s ); position = 0; nFile = 0; - goto PLAY_STREAMEDTRACK; } PLAY_STREAMEDTRACK: diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index bcf94479..677436a6 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -340,7 +340,7 @@ CCarCtrl::GenerateOneRandomCar() if (distanceBetweenNodes / 2 < carLength) positionBetweenNodes = 0.5f; else - positionBetweenNodes = min(1.0f - carLength / distanceBetweenNodes, max(carLength / distanceBetweenNodes, positionBetweenNodes)); + positionBetweenNodes = Min(1.0f - carLength / distanceBetweenNodes, Max(carLength / distanceBetweenNodes, positionBetweenNodes)); pCar->AutoPilot.m_nNextDirection = (curNodeId >= nextNodeId) ? 1 : -1; if (pCurNode->numLinks == 1){ /* Do not create vehicle if there is nowhere to go. */ @@ -793,10 +793,10 @@ CCarCtrl::FindMaximumSpeedForThisCarInTraffic(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = max(0, CWorld::GetSectorIndexX(left)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = max(0, CWorld::GetSectorIndexY(top)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -827,10 +827,10 @@ CCarCtrl::ScanForPedDanger(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = max(0, CWorld::GetSectorIndexX(left)); - int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = max(0, CWorld::GetSectorIndexY(top)); - int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -862,12 +862,12 @@ CCarCtrl::SlowCarOnRailsDownForTrafficAndLights(CVehicle* pVehicle) float curSpeed = pVehicle->AutoPilot.m_fMaxTrafficSpeed; if (maxSpeed >= curSpeed){ if (maxSpeed > curSpeed) - pVehicle->AutoPilot.ModifySpeed(min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(Min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); }else{ if (curSpeed == 0.0f) return; if (curSpeed >= 0.1f) - pVehicle->AutoPilot.ModifySpeed(max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(Max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); else if (curSpeed != 0.0f) /* no need to check */ pVehicle->AutoPilot.ModifySpeed(0.0f); } diff --git a/src/control/CarGen.cpp b/src/control/CarGen.cpp index 65a23c8c..f2b35547 100644 --- a/src/control/CarGen.cpp +++ b/src/control/CarGen.cpp @@ -157,7 +157,7 @@ void CCarGenerator::Setup(float x, float y, float z, float angle, int32 mi, int1 m_bIsBlocking = false; m_vecInf = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.min; m_vecSup = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.max; - m_fSize = max(m_vecInf.Magnitude(), m_vecSup.Magnitude()); + m_fSize = Max(m_vecInf.Magnitude(), m_vecSup.Magnitude()); } bool CCarGenerator::CheckForBlockage() diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 3c5c142c..0e9592dc 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -68,7 +68,7 @@ bool CGarages::HasCarBeenCrushed(int32 handle) return CrushedCarId == handle; } -WRAPPER void CGarages::TriggerMessage(char *text, int16, uint16 time, int16) { EAXJMP(0x426B20); } +WRAPPER void CGarages::TriggerMessage(const char *text, int16, uint16 time, int16) { EAXJMP(0x426B20); } WRAPPER bool CGarages::IsPointWithinHideOutGarage(CVector*) { EAXJMP(0x428260); } #if 0 @@ -97,7 +97,7 @@ void CGarages::PrintMessages() CMessages::InsertNumberInString(TheText.Get(MessageIDString), MessageNumberInString, -1, -1, -1, -1, -1, gUString); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f + 2.0 - 40.0f), gUString); + CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f + 2.0f - 40.0f), gUString); CFont::SetColor(CRGBA(89, 115, 150, 255)); CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f - 40.0f), gUString); @@ -107,7 +107,7 @@ void CGarages::PrintMessages() CMessages::InsertNumberInString(TheText.Get(MessageIDString), MessageNumberInString, MessageNumberInString2, -1, -1, -1, -1, gUString); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f + 2.0 - 40.0f), gUString); + CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f + 2.0f - 40.0f), gUString); CFont::SetColor(CRGBA(89, 115, 150, 255)); CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(-84.0f - 40.0f), gUString); diff --git a/src/control/Garages.h b/src/control/Garages.h index d338c71b..4c35fad1 100644 --- a/src/control/Garages.h +++ b/src/control/Garages.h @@ -22,7 +22,7 @@ public: public: static bool IsModelIndexADoor(uint32 id); - static void TriggerMessage(char *text, int16, uint16 time, int16); + static void TriggerMessage(const char *text, int16, uint16 time, int16); static void PrintMessages(void); static bool HasCarBeenCrushed(int32); static bool IsPointWithinHideOutGarage(CVector*); diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index e9b33395..025db0c9 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -207,8 +207,8 @@ CPathFind::PreparePathData(void) numExtern++; if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes) numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes; - maxX = max(maxX, Abs(InfoForTileCars[k].x)); - maxY = max(maxY, Abs(InfoForTileCars[k].y)); + maxX = Max(maxX, Abs(InfoForTileCars[k].x)); + maxY = Max(maxY, Abs(InfoForTileCars[k].y)); }else if(InfoForTileCars[k].type == NodeTypeIntern) numIntern++; } @@ -392,7 +392,7 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor if(Abs(dx) < nearestDist){ dy = tempnodes[k].pos.y - CoorsXFormed.y; if(Abs(dy) < nearestDist){ - nearestDist = max(Abs(dx), Abs(dy)); + nearestDist = Max(Abs(dx), Abs(dy)); nearestId = k; } } @@ -501,13 +501,13 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor // Find i inside path segment iseg = 0; - for(j = max(oldNumPathNodes, i-12); j < i; j++) + for(j = Max(oldNumPathNodes, i-12); j < i; j++) if(m_pathNodes[j].objectIndex == m_pathNodes[i].objectIndex) iseg++; istart = 12*m_mapObjects[m_pathNodes[i].objectIndex]->m_modelIndex; // Add links to other internal nodes - for(j = max(oldNumPathNodes, i-12); j < min(m_numPathNodes, i+12); j++){ + for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){ if(m_pathNodes[i].objectIndex != m_pathNodes[j].objectIndex || i == j) continue; // N.B.: in every path segment, the externals have to be at the end @@ -1263,7 +1263,9 @@ CPathFind::FindNextNodeWandering(uint8 type, CVector coors, CPathNode **lastNode static CPathNode *apNodesToBeCleared[4995]; void -CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector target, CPathNode **nodes, int16 *pNumNodes, int16 maxNumNodes, CVehicle *vehicle, float *pDist, float distLimit, int32 forcedTargetNode) +CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector target, + CPathNode **nodes, int16 *pNumNodes, int16 maxNumNodes, CVehicle *vehicle, + float *pDist, float distLimit, int32 forcedTargetNode) { int i, j; @@ -1273,41 +1275,51 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta targetNode = FindNodeClosestToCoors(target, type, distLimit); else targetNode = forcedTargetNode; - if(targetNode < 0) - goto fail; + if(targetNode < 0) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } // Find start int numPathsToTry; CTreadable *startObj; - if(startNodeId < 0){ + if(startNodeId < 0) { if(vehicle == nil || (startObj = vehicle->m_treadable[type]) == nil) startObj = FindRoadObjectClosestToCoors(start, type); numPathsToTry = 0; - for(i = 0; i < 12; i++){ - if(startObj->m_nodeIndices[type][i] < 0) - break; - if(m_pathNodes[startObj->m_nodeIndices[type][i]].group == m_pathNodes[targetNode].group) + for(i = 0; i < 12; i++) { + if(startObj->m_nodeIndices[type][i] < 0) break; + if(m_pathNodes[startObj->m_nodeIndices[type][i]].group == + m_pathNodes[targetNode].group) numPathsToTry++; } - }else{ + } else { numPathsToTry = 1; startObj = m_mapObjects[m_pathNodes[startNodeId].objectIndex]; } - if(numPathsToTry == 0) - goto fail; + if(numPathsToTry == 0) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + } - if(startNodeId < 0){ + if(startNodeId < 0) { // why only check node 0? - if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != m_pathNodes[targetNode].group) - goto fail; - }else{ - if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) - goto fail; + if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != + m_pathNodes[targetNode].group) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } + } else { + if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) { + *pNumNodes = 0; + if(pDist) *pDist = 100000.0f; + return; + } } - - for(i = 0; i < 512; i++) - m_searchNodes[i].next = nil; + for(i = 0; i < 512; i++) m_searchNodes[i].next = nil; AddNodeToList(&m_pathNodes[targetNode], 0); int numNodesToBeCleared = 0; apNodesToBeCleared[numNodesToBeCleared++] = &m_pathNodes[targetNode]; @@ -1383,11 +1395,6 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta for(i = 0; i < numNodesToBeCleared; i++) apNodesToBeCleared[i]->distance = MAX_DIST; return; - -fail: - *pNumNodes = 0; - if(pDist) - *pDist = 100000.0f; } static CPathNode *pNodeList[32]; diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index 12636d32..03104307 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -342,7 +342,7 @@ void CReplay::StorePedUpdate(CPed *ped, int id) tPedUpdatePacket* pp = (tPedUpdatePacket*)&Record.m_pBase[Record.m_nOffset]; pp->type = REPLAYPACKET_PED_UPDATE; pp->index = id; - pp->heading = 128.0f / M_PI * ped->m_fRotationCur; + pp->heading = 128.0f / PI * ped->m_fRotationCur; pp->matrix.CompressFromFullMatrix(ped->GetMatrix()); pp->assoc_group_id = ped->m_animGroup; /* Would be more sane to use GetJustIndex(ped->m_pMyVehicle) in following assignment */ @@ -366,8 +366,8 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* main = RpAnimBlendClumpGetMainAssociation((RpClump*)ped->m_rwObject, &second, &blend_amount); if (main){ state->animId = main->animId; - state->time = 255.0f / 4.0f * max(0.0f, min(4.0f, main->currentTime)); - state->speed = 255.0f / 3.0f * max(0.0f, min(3.0f, main->speed)); + state->time = 255.0f / 4.0f * Max(0.0f, Min(4.0f, main->currentTime)); + state->speed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, main->speed)); }else{ state->animId = 3; state->time = 0; @@ -375,9 +375,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) } if (second) { state->secAnimId = second->animId; - state->secTime = 255.0f / 4.0f * max(0.0f, min(4.0f, second->currentTime)); - state->secSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, second->speed)); - state->blendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, blend_amount)); + state->secTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, second->currentTime)); + state->secSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, second->speed)); + state->blendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, blend_amount)); }else{ state->secAnimId = 0; state->secTime = 0; @@ -387,9 +387,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* partial = RpAnimBlendClumpGetMainPartialAssociation((RpClump*)ped->m_rwObject); if (partial) { state->partAnimId = partial->animId; - state->partAnimTime = 255.0f / 4.0f * max(0.0f, min(4.0f, partial->currentTime)); - state->partAnimSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, partial->speed)); - state->partBlendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, partial->blendAmount)); + state->partAnimTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, partial->currentTime)); + state->partAnimSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, partial->speed)); + state->partBlendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, partial->blendAmount)); }else{ state->partAnimId = 0; state->partAnimTime = 0; @@ -408,9 +408,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc){ state->aAnimId[i] = assoc->animId; - state->aCurTime[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); - state->aSpeed[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); - state->aBlendAmount[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); + state->aCurTime[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); + state->aSpeed[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); + state->aBlendAmount[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); state->aFlags[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID[i] = FindCBFunctionID(assoc->callback); @@ -431,9 +431,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainPartialAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc) { state->aAnimId2[i] = assoc->animId; - state->aCurTime2[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); - state->aSpeed2[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); - state->aBlendAmount2[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); + state->aCurTime2[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); + state->aSpeed2[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); + state->aBlendAmount2[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); state->aFlags2[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID2[i] = FindCBFunctionID(assoc->callback); @@ -464,8 +464,8 @@ void CReplay::ProcessPedUpdate(CPed *ped, float interpolation, CAddressInReplayB buffer->m_nOffset += sizeof(tPedUpdatePacket); return; } - ped->m_fRotationCur = pp->heading * M_PI / 128.0f; - ped->m_fRotationDest = pp->heading * M_PI / 128.0f; + ped->m_fRotationCur = pp->heading * PI / 128.0f; + ped->m_fRotationDest = pp->heading * PI / 128.0f; CMatrix ped_matrix; pp->matrix.DecompressIntoFullMatrix(ped_matrix); ped->GetMatrix() = ped->GetMatrix() * CMatrix(1.0f - interpolation); @@ -625,24 +625,24 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) vp->health = vehicle->m_fHealth / 4.0f; /* Not anticipated that health can be > 1000. */ vp->acceleration = vehicle->m_fGasPedal * 100.0f; vp->panels = vehicle->IsCar() ? ((CAutomobile*)vehicle)->Damage.m_panelStatus : 0; - vp->velocityX = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ - vp->velocityY = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().y)); - vp->velocityZ = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().z)); + vp->velocityX = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ + vp->velocityY = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().y)); + vp->velocityZ = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().z)); vp->mi = vehicle->GetModelIndex(); vp->primary_color = vehicle->m_currentColour1; vp->secondary_color = vehicle->m_currentColour2; if (vehicle->GetModelIndex() == MI_RHINO) - vp->car_gun = 128.0f / M_PI * ((CAutomobile*)vehicle)->m_fCarGunLR; + vp->car_gun = 128.0f / PI * ((CAutomobile*)vehicle)->m_fCarGunLR; else vp->wheel_state = 50.0f * vehicle->m_fSteerAngle; if (vehicle->IsCar()){ CAutomobile* car = (CAutomobile*)vehicle; for (int i = 0; i < 4; i++){ vp->wheel_susp_dist[i] = 50.0f * car->m_aSuspensionSpringRatio[i]; - vp->wheel_rotation[i] = 128.0f / M_PI * car->m_aWheelRotation[i]; + vp->wheel_rotation[i] = 128.0f / PI * car->m_aWheelRotation[i]; } - vp->door_angles[0] = 127.0f / M_PI * car->Doors[2].m_fAngle; - vp->door_angles[1] = 127.0f / M_PI * car->Doors[3].m_fAngle; + vp->door_angles[0] = 127.0f / PI * car->Doors[2].m_fAngle; + vp->door_angles[1] = 127.0f / PI * car->Doors[3].m_fAngle; vp->door_status = 0; for (int i = 0; i < 6; i++){ if (car->Damage.GetDoorStatus(i) == 3) @@ -675,7 +675,7 @@ void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressI ApplyPanelDamageToCar(vp->panels, (CAutomobile*)vehicle, true); vehicle->m_vecMoveSpeed = CVector(vp->velocityX / 8000.0f, vp->velocityY / 8000.0f, vp->velocityZ / 8000.0f); if (vehicle->GetModelIndex() == MI_RHINO) { - ((CAutomobile*)vehicle)->m_fCarGunLR = vp->car_gun * M_PI / 128.0f; + ((CAutomobile*)vehicle)->m_fCarGunLR = vp->car_gun * PI / 128.0f; vehicle->m_fSteerAngle = 0.0f; }else{ vehicle->m_fSteerAngle = vp->wheel_state / 50.0f; @@ -684,10 +684,10 @@ void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressI CAutomobile* car = (CAutomobile*)vehicle; for (int i = 0; i < 4; i++) { car->m_aSuspensionSpringRatio[i] = vp->wheel_susp_dist[i] / 50.0f; - car->m_aWheelRotation[i] = vp->wheel_rotation[i] * M_PI / 128.0f; + car->m_aWheelRotation[i] = vp->wheel_rotation[i] * PI / 128.0f; } - car->Doors[2].m_fAngle = car->Doors[2].m_fPrevAngle = vp->door_angles[0] * M_PI / 127.0f; - car->Doors[3].m_fAngle = car->Doors[3].m_fPrevAngle = vp->door_angles[1] * M_PI / 127.0f; + car->Doors[2].m_fAngle = car->Doors[2].m_fPrevAngle = vp->door_angles[0] * PI / 127.0f; + car->Doors[3].m_fAngle = car->Doors[3].m_fPrevAngle = vp->door_angles[1] * PI / 127.0f; if (vp->door_angles[0]) car->Damage.SetDoorStatus(2, 2); if (vp->door_angles[1]) @@ -1501,9 +1501,9 @@ void CReplay::ProcessLookAroundCam(void) --FramesActiveLookAroundCam; fBetaAngleLookAroundCam += x_moved; if (CPad::NewMouseControllerState.LMB && CPad::NewMouseControllerState.RMB) - fDistanceLookAroundCam = max(3.0f, min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); + fDistanceLookAroundCam = Max(3.0f, Min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); else - fAlphaAngleLookAroundCam = max(0.1f, min(1.5f, fAlphaAngleLookAroundCam + y_moved)); + fAlphaAngleLookAroundCam = Max(0.1f, Min(1.5f, fAlphaAngleLookAroundCam + y_moved)); CVector camera_pt( fDistanceLookAroundCam * Sin(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), fDistanceLookAroundCam * Cos(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), diff --git a/src/control/Script.cpp b/src/control/Script.cpp index c81cd050..7e87fc6e 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1987,7 +1987,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; car->m_status = STATUS_PHYSICS; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -1999,7 +1999,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CCarCtrl::JoinCarWithRoadSystem(car); car->AutoPilot.m_nCarMission = MISSION_CRUISE; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2083,7 +2083,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CollectParameters(&m_nIp, 2); CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(car); - car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); + car->AutoPilot.m_nCruiseSpeed = Min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); return 0; } case COMMAND_SET_CAR_DRIVING_STYLE: diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index cb16c3ad..f15232f3 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -209,7 +209,7 @@ WellBufferMe(float Target, float *CurrentValue, float *CurrentSpeed, float MaxSp else if(TargetSpeed > 0.0f && *CurrentSpeed > TargetSpeed) *CurrentSpeed = TargetSpeed; - *CurrentValue += *CurrentSpeed * min(10.0f, CTimer::GetTimeStep()); + *CurrentValue += *CurrentSpeed * Min(10.0f, CTimer::GetTimeStep()); } void @@ -697,7 +697,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl // Process height offset to avoid peds and cars float TargetZOffSet = m_fUnknownZOffSet + m_fDimensionOfHighestNearCar; - TargetZOffSet = max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); + TargetZOffSet = Max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); float TargetHeight = CameraTarget.z + TargetZOffSet - Source.z; if(TargetHeight > m_fCamBufferedHeight){ @@ -753,7 +753,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl } } - TargetCoors.z += min(1.0f, m_fCamBufferedHeight/2.0f); + TargetCoors.z += Min(1.0f, m_fCamBufferedHeight/2.0f); m_cvecTargetCoorsForFudgeInter = TargetCoors; Front = TargetCoors - Source; @@ -991,7 +991,7 @@ CCam::WorkOutCamHeight(const CVector &TargetCoors, float TargetOrientation, floa } if(FoundCamRoof){ // Camera is under something - float roof = FoundRoofCenter ? min(CamRoof, CarRoof) : CamRoof; + float roof = FoundRoofCenter ? Min(CamRoof, CarRoof) : CamRoof; // Same weirdness again? TargetAlpha = CGeneral::GetATanOfXY(CA_MAX_DISTANCE, roof - CamTargetZ - 1.5f); CamClear = false; @@ -1249,7 +1249,7 @@ void CCam::Cam_On_A_String_Unobscured(const CVector &TargetCoors, float BaseDist) { CA_MAX_DISTANCE = BaseDist + 0.1f + TheCamera.CarZoomValueSmooth; - CA_MIN_DISTANCE = min(BaseDist*0.6f, 3.5f); + CA_MIN_DISTANCE = Min(BaseDist*0.6f, 3.5f); CVector Dist = Source - TargetCoors; diff --git a/src/core/Collision.cpp b/src/core/Collision.cpp index 66b29d9f..538bcae6 100644 --- a/src/core/Collision.cpp +++ b/src/core/Collision.cpp @@ -153,10 +153,10 @@ CCollision::LoadCollisionWhenINeedIt(bool forceChange) // on water we expect to be between levels multipleLevels = true; }else{ - xmin = max(sx - 1, 0); - xmax = min(sx + 1, NUMSECTORS_X-1); - ymin = max(sy - 1, 0); - ymax = min(sy + 1, NUMSECTORS_Y-1); + xmin = Max(sx - 1, 0); + xmax = Min(sx + 1, NUMSECTORS_X-1); + ymin = Max(sy - 1, 0); + ymax = Min(sy + 1, NUMSECTORS_Y-1); for(x = xmin; x <= xmax; x++) for(y = ymin; y <= ymax; y++){ diff --git a/src/core/FileMgr.cpp b/src/core/FileMgr.cpp index 954fcdef..2a8628b0 100644 --- a/src/core/FileMgr.cpp +++ b/src/core/FileMgr.cpp @@ -248,15 +248,15 @@ CFileMgr::OpenFileForWriting(const char *file) } int -CFileMgr::Read(int fd, char *buf, int len) +CFileMgr::Read(int fd, const char *buf, int len) { - return myfread(buf, 1, len, fd); + return myfread((void*)buf, 1, len, fd); } int -CFileMgr::Write(int fd, char *buf, int len) +CFileMgr::Write(int fd, const char *buf, int len) { - return myfwrite(buf, 1, len, fd); + return myfwrite((void*)buf, 1, len, fd); } bool diff --git a/src/core/FileMgr.h b/src/core/FileMgr.h index bab86e38..3df0c7d8 100644 --- a/src/core/FileMgr.h +++ b/src/core/FileMgr.h @@ -12,8 +12,8 @@ public: static int LoadFile(const char *file, uint8 *buf, int unused, const char *mode); static int OpenFile(const char *file, const char *mode); static int OpenFileForWriting(const char *file); - static int Read(int fd, char *buf, int len); - static int Write(int fd, char *buf, int len); + static int Read(int fd, const char *buf, int len); + static int Write(int fd, const char *buf, int len); static bool Seek(int fd, int offset, int whence); static bool ReadLine(int fd, char *buf, int len); static int CloseFile(int fd); diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 1de5c94f..f4545f7b 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -95,7 +95,7 @@ bool GetMouseMoveRight(); bool GetPadInput(); bool GetMouseInput(); -char *FrontendFilenames[] = { +const char *FrontendFilenames[] = { "fe2_mainpanel_ul", "fe2_mainpanel_ur", "fe2_mainpanel_dl", @@ -126,7 +126,7 @@ char *FrontendFilenames[] = { "fe_radio9", // CHATTERBOX }; -char *MenuFilenames[] = { +const char *MenuFilenames[] = { "connection24", "", "findgame24", "", "hostgame24", "", @@ -1030,7 +1030,7 @@ int CMenuManager::FadeIn(int alpha) m_nCurrScreen == MENUPAGE_SAVING_IN_PROGRESS || m_nCurrScreen == MENUPAGE_DELETING) return alpha; - return min(m_nMenuFadeAlpha, alpha); + return Min(m_nMenuFadeAlpha, alpha); } #endif diff --git a/src/core/General.h b/src/core/General.h index 8f9aa044..366c571c 100644 --- a/src/core/General.h +++ b/src/core/General.h @@ -97,7 +97,7 @@ public: } // should return direction in 0-8 range. fits perfectly to peds' path directions. - static int CGeneral::GetNodeHeadingFromVector(float x, float y) + static int GetNodeHeadingFromVector(float x, float y) { float angle = CGeneral::GetRadianAngleBetweenPoints(x, y, 0.0f, 0.0f); if (angle < 0.0f) diff --git a/src/core/IniFile.cpp b/src/core/IniFile.cpp index 08b30876..46dceff3 100644 --- a/src/core/IniFile.cpp +++ b/src/core/IniFile.cpp @@ -17,10 +17,10 @@ void CIniFile::LoadIniFile() if (f){ CFileMgr::ReadLine(f, gString, 200); sscanf(gString, "%f", &PedNumberMultiplier); - PedNumberMultiplier = min(3.0f, max(0.5f, PedNumberMultiplier)); + PedNumberMultiplier = Min(3.0f, Max(0.5f, PedNumberMultiplier)); CFileMgr::ReadLine(f, gString, 200); sscanf(gString, "%f", &CarNumberMultiplier); - CarNumberMultiplier = min(3.0f, max(0.5f, CarNumberMultiplier)); + CarNumberMultiplier = Min(3.0f, Max(0.5f, CarNumberMultiplier)); CFileMgr::CloseFile(f); } CPopulation::MaxNumberOfPedsInUse = 25.0f * PedNumberMultiplier; diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index f334a255..b5086d64 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -299,10 +299,10 @@ CControllerState CPad::ReconcileTwoControllersInput(CControllerState const &Stat { if ( State1.button || State2.button ) ReconState.button = 255; } #define _RECONCILE_AXIS_POSITIVE(axis) \ - { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = max(State1.axis, State2.axis); } + { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = Max(State1.axis, State2.axis); } #define _RECONCILE_AXIS_NEGATIVE(axis) \ - { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = min(State1.axis, State2.axis); } + { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = Min(State1.axis, State2.axis); } #define _RECONCILE_AXIS(axis) \ { _RECONCILE_AXIS_POSITIVE(axis); _RECONCILE_AXIS_NEGATIVE(axis); } diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index a7bde91e..8158cd1d 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1940,7 +1940,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())){ lodDistSq = sq(mi->GetLargestLodDistance()); - lodDistSq = min(lodDistSq, sq(STREAM_DIST)); + lodDistSq = Min(lodDistSq, sq(STREAM_DIST)); pos = CVector2D(e->GetPosition()); if(xmin < pos.x && pos.x < xmax && ymin < pos.y && pos.y < ymax && @@ -2160,20 +2160,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) if(Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y)){ // looking west/east - ymin = max(iy - 10, 0); - ymax = min(iy + 10, NUMSECTORS_Y); + ymin = Max(iy - 10, 0); + ymax = Min(iy + 10, NUMSECTORS_Y); assert(ymin <= ymax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().x > 0){ // looking east - xmax = max(ix - 2, 0); - xmin = max(ix - 10, 0); + xmax = Max(ix - 2, 0); + xmin = Max(ix - 10, 0); inc = 1; }else{ // looking west - xmax = min(ix + 2, NUMSECTORS_X); - xmin = min(ix + 10, NUMSECTORS_X); + xmax = Min(ix + 2, NUMSECTORS_X); + xmin = Min(ix + 10, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2189,13 +2189,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().x > 0){ // looking east - xmax = max(ix + 10, 0); - xmin = max(ix - 2, 0); + xmax = Max(ix + 10, 0); + xmin = Max(ix - 2, 0); inc = 1; }else{ // looking west - xmax = min(ix - 10, NUMSECTORS_X); - xmin = min(ix + 2, NUMSECTORS_X); + xmax = Min(ix - 10, NUMSECTORS_X); + xmin = Min(ix + 2, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2224,20 +2224,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) }else{ // looking north/south - xmin = max(ix - 10, 0); - xmax = min(ix + 10, NUMSECTORS_X); + xmin = Max(ix - 10, 0); + xmax = Min(ix + 10, NUMSECTORS_X); assert(xmin <= xmax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().y > 0){ // looking north - ymax = max(iy - 2, 0); - ymin = max(iy - 10, 0); + ymax = Max(iy - 2, 0); + ymin = Max(iy - 10, 0); inc = 1; }else{ // looking south - ymax = min(iy + 2, NUMSECTORS_Y); - ymin = min(iy + 10, NUMSECTORS_Y); + ymax = Min(iy + 2, NUMSECTORS_Y); + ymin = Min(iy + 10, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ @@ -2253,13 +2253,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().y > 0){ // looking north - ymax = max(iy + 10, 0); - ymin = max(iy - 2, 0); + ymax = Max(iy + 10, 0); + ymin = Max(iy - 2, 0); inc = 1; }else{ // looking south - ymax = min(iy - 10, NUMSECTORS_Y); - ymin = min(iy + 2, NUMSECTORS_Y); + ymax = Min(iy - 10, NUMSECTORS_Y); + ymin = Min(iy + 2, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ diff --git a/src/core/Wanted.cpp b/src/core/Wanted.cpp index 26b115e3..daed9155 100644 --- a/src/core/Wanted.cpp +++ b/src/core/Wanted.cpp @@ -209,7 +209,7 @@ CWanted::ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesnt else sensitivity = m_fCrimeSensitivity; - wantedLevelDrop = min(CCullZones::GetWantedLevelDrop(), 100); + wantedLevelDrop = Min(CCullZones::GetWantedLevelDrop(), 100); chaos = (1.0f - wantedLevelDrop/100.0f) * sensitivity; if (policeDoesntCare) diff --git a/src/core/common.h b/src/core/common.h index 73e57c21..d1f71720 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -156,7 +156,7 @@ public: inline float sq(float x) { return x*x; } #define SQR(x) ((x) * (x)) -#define PI M_PI +#define PI (float)M_PI #define TWOPI (PI*2) #define HALFPI (PI/2) #define DEGTORAD(x) ((x) * PI / 180.0f) @@ -171,8 +171,8 @@ inline float sq(float x) { return x*x; } int myrand(void); void mysrand(unsigned int seed); -void re3_debug(char *format, ...); -void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...); +void re3_debug(const char *format, ...); +void re3_trace(const char *filename, unsigned int lineno, const char *func, const char *format, ...); void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func); #define DEBUGBREAK() __debugbreak(); @@ -195,8 +195,8 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define BIT(num) (1<<(num)) -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#define min(a, b) (((a) < (b)) ? (a) : (b)) +#define Max(a, b) (((a) > (b)) ? (a) : (b)) +#define Min(a, b) (((a) < (b)) ? (a) : (b)) #define ABS(a) (((a) < 0) ? (-(a)) : (a)) #define norm(value, min, max) (((value) < (min)) ? 0 : (((value) > (max)) ? 1 : (((value) - (min)) / ((max) - (min))))) diff --git a/src/core/main.cpp b/src/core/main.cpp index 50494ef3..a82a2ab8 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -453,7 +453,7 @@ DoFade(void) CRGBA fadeColor; CRect rect; int fadeValue = CDraw::FadeValue; - float brightness = min(CMenuManager::m_PrefsBrightness, 256); + float brightness = Min(CMenuManager::m_PrefsBrightness, 256); if(brightness <= 50) brightness = 50; if(FrontEndMenuManager.m_bMenuActive) diff --git a/src/core/re3.cpp b/src/core/re3.cpp index ad3838bd..9737fddb 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -425,7 +425,7 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con abort(); } -void re3_debug(char *format, ...) +void re3_debug(const char *format, ...) { va_list va; va_start(va, format); @@ -435,7 +435,7 @@ void re3_debug(char *format, ...) printf("%s", re3_buff); } -void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...) +void re3_trace(const char *filename, unsigned int lineno, const char *func, const char *format, ...) { char buff[re3_buffsize *2]; va_list va; diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index fbd1322d..d59e6c59 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -457,7 +457,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector & { float compression = 1.0f - springRatio; if(compression > 0.0f){ - float step = min(CTimer::GetTimeStep(), 3.0f); + float step = Min(CTimer::GetTimeStep(), 3.0f); float impulse = -GRAVITY*m_fMass*step * springConst * compression * bias*2.0f; ApplyMoveForce(springDir*impulse); ApplyTurnForce(springDir*impulse, point); @@ -471,12 +471,12 @@ CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &poin { float speedA = DotProduct(speed, springDir); float speedB = DotProduct(GetSpeed(point), springDir); - float step = min(CTimer::GetTimeStep(), 3.0f); + float step = Min(CTimer::GetTimeStep(), 3.0f); float impulse = -damping * (speedA + speedB)/2.0f * m_fMass * step * 0.53f; // what is this? float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass); - a = min(a, 1.0f); + a = Min(a, 1.0f); float b = Abs(impulse / (speedB * m_fMass)); if(a < b) impulse *= a/b; @@ -646,7 +646,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl // positive if B is moving towards A // not interested in how much B moves into A apparently? // only interested in cases where A collided into B - speedB = max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); + speedB = Max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); // A has moved into B if(speedA < speedB){ if(!A->bHasHitWall) @@ -1147,18 +1147,18 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) CVector dir = A->GetPosition() - B->GetPosition(); dir.Normalise(); if(dir.z < 0.0f && dir.z < A->GetForward().z && dir.z < A->GetRight().z) - dir.z = min(0.0f, min(A->GetForward().z, A->GetRight().z)); + dir.z = Min(0.0f, Min(A->GetForward().z, A->GetRight().z)); shift += dir * colpoints[mostColliding].depth * 0.5f; }else if(A->IsPed() && B->IsVehicle() && ((CVehicle*)B)->IsBoat()){ CVector dir = colpoints[mostColliding].normal; - float f = min(Abs(dir.z), 0.9f); + float f = Min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); shift += dir * colpoints[mostColliding].depth / (1.0f - f); boat = B; }else if(B->IsPed() && A->IsVehicle() && ((CVehicle*)A)->IsBoat()){ CVector dir = colpoints[mostColliding].normal * -1.0f; - float f = min(Abs(dir.z), 0.9f); + float f = Min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); B->GetPosition() += dir * colpoints[mostColliding].depth / (1.0f - f); @@ -1246,7 +1246,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1268,7 +1268,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1301,7 +1301,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1328,7 +1328,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1506,7 +1506,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); } }else{ for(i = 0; i < numCollisions; i++){ @@ -1527,7 +1527,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions; @@ -1545,7 +1545,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) else if(A->GetUp().z > 0.3f) adhesion = 0.0f; else - adhesion *= min(5.0f, 0.03f*impulseA + 1.0f); + adhesion *= Min(5.0f, 0.03f*impulseA + 1.0f); } if(A->ApplyFriction(adhesion, aColPoints[i])) @@ -1594,7 +1594,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1619,7 +1619,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1655,7 +1655,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1685,7 +1685,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1831,7 +1831,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && (distSq >= sq(0.2f) || ped->IsPlayer())){ if(ped->IsPlayer()) - n = max(NUMSTEPS(0.2f), 2.0); + n = Max(NUMSTEPS(0.2f), 2.0); else n = NUMSTEPS(0.3f); step = savedTimeStep / n; @@ -1852,7 +1852,7 @@ CPhysical::ProcessCollision(void) speedDown = Multiply3x3(GetMatrix(), speedDown); speedUp = GetSpeed(speedUp); speedDown = GetSpeed(speedDown); - distSq = max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); + distSq = Max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); if(distSq >= sq(0.3f)){ n = NUMSTEPS(0.3f); step = savedTimeStep / n; diff --git a/src/modelinfo/ClumpModelInfo.h b/src/modelinfo/ClumpModelInfo.h index d491bdb9..100aa30b 100644 --- a/src/modelinfo/ClumpModelInfo.h +++ b/src/modelinfo/ClumpModelInfo.h @@ -4,14 +4,14 @@ struct RwObjectNameIdAssocation { - char *name; + const char *name; int32 hierId; uint32 flags; }; struct RwObjectNameAssociation { - char *name; + const char *name; RwFrame *frame; }; diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp index 19100d84..87f01177 100644 --- a/src/modelinfo/VehicleModelInfo.cpp +++ b/src/modelinfo/VehicleModelInfo.cpp @@ -1038,7 +1038,7 @@ CVehicleModelInfo::SetEnvironmentMap(void) void CVehicleModelInfo::LoadEnvironmentMaps(void) { - char *texnames[] = { + const char *texnames[] = { "reflection01", // only one used "reflection02", "reflection03", diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 209c4ff6..65bd696d 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1792,7 +1792,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) neededPos.z = autoZPos.z; m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); @@ -1807,12 +1807,12 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) { - neededPos.z = max(currentZ, autoZPos.z); + neededPos.z = Max(currentZ, autoZPos.z); } } } @@ -4622,7 +4622,7 @@ CPed::LoadFightData(void) // Actually GetLocalDirectionTo(Turn/Look) int -CPed::GetLocalDirection(CVector2D const &posOffset) +CPed::GetLocalDirection(const CVector2D &posOffset) { float direction; @@ -4771,12 +4771,12 @@ CPed::FightStrike(CVector &touchedNodePos) float moveMult; if (m_lastFightMove == FIGHTMOVE_GROUNDKICK) { - moveMult = min(damageMult * 0.6f, 4.0f); + moveMult = Min(damageMult * 0.6f, 4.0f); } else { if (nearPed->m_nPedState != PED_DIE || damageMult >= 20) { moveMult = damageMult; } else { - moveMult = min(damageMult * 2.0f, 14.0f); + moveMult = Min(damageMult * 2.0f, 14.0f); } } @@ -5434,7 +5434,7 @@ CPed::CreateDeadPedWeaponPickups(void) pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f; } if (found) - CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, min(weaponAmmo, AmmoForWeapon_OnStreet[weapon])); + CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, Min(weaponAmmo, AmmoForWeapon_OnStreet[weapon])); } ClearWeapons(); } @@ -5443,7 +5443,7 @@ void CPed::SetAttackTimer(uint32 time) { if (CTimer::GetTimeInMilliseconds() > m_attackTimer) - m_attackTimer = max(m_lastHitTime, CTimer::GetTimeInMilliseconds()) + time; + m_attackTimer = Max(m_lastHitTime, CTimer::GetTimeInMilliseconds()) + time; } void diff --git a/src/peds/Ped.h b/src/peds/Ped.h index ff581150..c1e93fdc 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -575,7 +575,7 @@ public: void StartFightAttack(uint8); void SetWaitState(eWaitState, void*); bool FightStrike(CVector&); - int GetLocalDirection(CVector2D const &); + int GetLocalDirection(const CVector2D &); void StartFightDefend(uint8, uint8, uint8); void PlayHitSound(CPed*); void SetFall(int, AnimationId, uint8); diff --git a/src/peds/PedPlacement.cpp b/src/peds/PedPlacement.cpp index 8a40e56f..d7b7ec75 100644 --- a/src/peds/PedPlacement.cpp +++ b/src/peds/PedPlacement.cpp @@ -29,7 +29,7 @@ CPedPlacement::FindZCoorForPed(CVector* pos) if (CWorld::ProcessVerticalLine(vec, startZ, foundCol, foundEnt, true, false, false, false, true, false, nil)) foundColZ2 = foundCol.point.z; - zForPed = max(foundColZ, foundColZ2); + zForPed = Max(foundColZ, foundColZ2); if (zForPed > -99.0f) pos->z = 1.04f + zForPed; diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index 2884894c..a461301c 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -388,7 +388,7 @@ CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, ms_colourBottom.b = topblue; ms_colourBottom.a = alpha; - botpos = min(SCREEN_HEIGHT, topedge); + botpos = Min(SCREEN_HEIGHT, topedge); CSprite2d::DrawRect(CRect(0, 0, SCREEN_WIDTH, botpos), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } @@ -415,18 +415,18 @@ CClouds::RenderHorizon(void) if(ms_horizonZ > SCREEN_HEIGHT) return; - float z1 = min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); + float z1 = Min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); CSprite2d::DrawRectXLU(CRect(0, ms_horizonZ, SCREEN_WIDTH, z1), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); // This is just weird float a = SCREEN_HEIGHT/400.0f * HORIZSTRIPHEIGHT + - SCREEN_HEIGHT/300.0f * max(TheCamera.GetPosition().z, 0.0f); + SCREEN_HEIGHT/300.0f * Max(TheCamera.GetPosition().z, 0.0f); float b = TheCamera.GetUp().z < 0.0f ? SCREEN_HEIGHT : SCREEN_HEIGHT * Abs(TheCamera.GetRight().z); float z2 = z1 + (a + b)*TheCamera.LODDistMultiplier; - z2 = min(z2, SCREEN_HEIGHT); + z2 = Min(z2, SCREEN_HEIGHT); CSprite2d::DrawRect(CRect(0, z1, SCREEN_WIDTH, z2), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 1a6cfea3..9881e764 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -109,7 +109,7 @@ CCoronas::Update(void) int i; static int LastCamLook = 0; - LightsMult = min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); + LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); int CamLook = 0; if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; @@ -121,7 +121,7 @@ CCoronas::Update(void) if(LastCamLook != CamLook) bChangeBrightnessImmediately = 3; else - bChangeBrightnessImmediately = max(bChangeBrightnessImmediately-1, 0); + bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); LastCamLook = CamLook; for(i = 0; i < NUMCORONAS; i++) @@ -309,7 +309,7 @@ CCoronas::Render(void) // render corona itself if(aCoronas[i].texture){ - float fogscale = CWeather::Foggyness*min(spriteCoors.z, 40.0f)/40.0f + 1.0f; + float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; if(CCoronas::aCoronas[i].id == SUN_CORE) spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); @@ -320,7 +320,7 @@ CCoronas::Render(void) float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; float hscale = 0.35f - (wscale - 0.5f) * 0.06f; - hscale = max(hscale, 0.15f); + hscale = Max(hscale, 0.15f); CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, spritew * aCoronas[i].size * wscale, @@ -467,7 +467,7 @@ CCoronas::RenderReflections(void) float spritew, spriteh; if(CSprite::CalcScreenCoors(coors, spriteCoors, &spritew, &spriteh, true)){ float drawDist = 0.75f * aCoronas[i].drawDist; - drawDist = min(drawDist, 50.0f); + drawDist = Min(drawDist, 50.0f); if(spriteCoors.z < drawDist){ float fadeDistance = drawDist / 2.0f; float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; @@ -546,25 +546,25 @@ CRegisteredCorona::Update(void) (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ // Corona is blocked, fade out - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else if(offScreen){ // Same when off screen - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else{ // Visible if(alpha > fadeAlpha){ // fade in - fadeAlpha = min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); if(CCoronas::bChangeBrightnessImmediately) fadeAlpha = alpha; }else if(alpha < fadeAlpha){ // too visible, decrease alpha but not below alpha - fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); } // darken scene when the sun is visible if(id == CCoronas::SUN_CORONA) - CCoronas::LightsMult = max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); + CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); } // remove if invisible diff --git a/src/render/Fluff.cpp b/src/render/Fluff.cpp index 7c35319f..fc68d315 100644 --- a/src/render/Fluff.cpp +++ b/src/render/Fluff.cpp @@ -10,7 +10,7 @@ #include "Clock.h" #include "Weather.h" #include "Stats.h" -#include "math/maths.h" +#include "maths.h" #include "Frontend.h" uint8 ScrollCharSet[59][5] = { diff --git a/src/render/Fluff.h b/src/render/Fluff.h index f33b016e..b189b9a2 100644 --- a/src/render/Fluff.h +++ b/src/render/Fluff.h @@ -1,6 +1,6 @@ #pragma once #include "common.h" -#include "math/Vector.h" +#include "Vector.h" class CMovingThings { diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 1db7b07c..2dae7551 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -1128,7 +1128,7 @@ void CHud::DrawAfterFade() switch (OddJob2On) { case 0: OddJob2On = 1; - OddJob2XOffset = 380.0; + OddJob2XOffset = 380.0f; break; case 1: if (OddJob2XOffset <= 2.0f) { @@ -1136,27 +1136,27 @@ void CHud::DrawAfterFade() OddJob2On = 2; } else { - fStep = 40.0; - if ((OddJob2XOffset * 0.16667) <= 40.0) - fStep = OddJob2XOffset * 0.16667; + fStep = 40.0f; + if ((OddJob2XOffset * 0.16667f) <= 40.0f) + fStep = OddJob2XOffset * 0.16667f; OddJob2XOffset = OddJob2XOffset - fStep; } break; case 2: - OddJob2Timer += (20.0 * CTimer::GetTimeStep()); + OddJob2Timer += (20.0f * CTimer::GetTimeStep()); if (OddJob2Timer > 1500) { OddJob2On = 3; } break; case 3: - fStep = 30.0; - if ((OddJob2XOffset * 0.2) >= 30.0) - fStep = OddJob2XOffset * 0.2; + fStep = 30.0f; + if ((OddJob2XOffset * 0.2f) >= 30.0f) + fStep = OddJob2XOffset * 0.2f; OddJob2XOffset = OddJob2XOffset - fStep; - if (OddJob2XOffset < -380.0) { - OddJob2OffTimer = 5000.0; + if (OddJob2XOffset < -380.0f) { + OddJob2OffTimer = 5000.0f; OddJob2On = 0; } break; diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp index cd83a898..85d7ba13 100644 --- a/src/render/Lights.cpp +++ b/src/render/Lights.cpp @@ -37,9 +37,9 @@ SetLightsWithTimeOfDayColour(RpWorld *) AmbientLightColourForFrame.green = 1.0f; AmbientLightColourForFrame.blue = 1.0f; } - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame.red*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame.green*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame.blue*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame.red*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame.green*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame.blue*1.3f); RpLightSetColor(pAmbient, &AmbientLightColourForFrame); } @@ -70,16 +70,16 @@ SetLightsWithTimeOfDayColour(RpWorld *) float f1 = 2.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; float f2 = 3.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - AmbientLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f2); - AmbientLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f2); - AmbientLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f2); - AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); + AmbientLightColourForFrame.red = Min(1.0f, AmbientLightColourForFrame.red * f2); + AmbientLightColourForFrame.green = Min(1.0f, AmbientLightColourForFrame.green * f2); + AmbientLightColourForFrame.blue = Min(1.0f, AmbientLightColourForFrame.blue * f2); + AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); #ifdef FIX_BUGS - DirectionalLightColourForFrame.red = min(1.0f, DirectionalLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = min(1.0f, DirectionalLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = min(1.0f, DirectionalLightColourForFrame.blue * f1); + DirectionalLightColourForFrame.red = Min(1.0f, DirectionalLightColourForFrame.red * f1); + DirectionalLightColourForFrame.green = Min(1.0f, DirectionalLightColourForFrame.green * f1); + DirectionalLightColourForFrame.blue = Min(1.0f, DirectionalLightColourForFrame.blue * f1); #else DirectionalLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f1); DirectionalLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f1); @@ -193,7 +193,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwRGBAReal color; RwV3d *dir; - strength = max(max(red, green), blue); + strength = Max(Max(red, green), blue); n = -1; if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) n = NumExtraDirLightsInWorld; @@ -221,7 +221,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); LightStrengths[n] = strength; - NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); + NumExtraDirLightsInWorld = Min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); } void diff --git a/src/render/ParticleMgr.cpp b/src/render/ParticleMgr.cpp index 7a1804de..9381787c 100644 --- a/src/render/ParticleMgr.cpp +++ b/src/render/ParticleMgr.cpp @@ -91,7 +91,7 @@ void cParticleSystemMgr::LoadParticleData() break; case CFG_PARAM_INITIAL_COLOR_VARIATION: - entry->m_InitialColorVariation = min(atoi(value), 100); + entry->m_InitialColorVariation = Min(atoi(value), 100); break; case CFG_PARAM_FADE_DESTINATION_COLOR_R: diff --git a/src/render/PointLights.cpp b/src/render/PointLights.cpp index a015ec54..8e942ce6 100644 --- a/src/render/PointLights.cpp +++ b/src/render/PointLights.cpp @@ -98,7 +98,7 @@ CPointLights::GenerateLightsAffectingObject(CVector *objCoors) if(aLights[i].type == LIGHT_DIRECTIONAL){ float dot = -DotProduct(dir, aLights[i].dir); - intensity *= max((dot-0.5f)*2.0f, 0.0f); + intensity *= Max((dot-0.5f)*2.0f, 0.0f); } if(intensity > 0.0f) diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index 4d2e4605..b5147f02 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -727,10 +727,10 @@ CShadows::RenderStoredShadows(void) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -873,10 +873,10 @@ CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -1016,11 +1016,11 @@ CShadows::CastShadowEntity(CEntity *pEntity, float fStartX, float fStartY, floa Points[3].x = (fLengthRight - fFrontRight) - fSideRight; Points[3].y = (fLengthForward - fFrontForward) - fSideForward; - float MinX = min(min(Points[0].x, Points[1].x), min(Points[2].x, Points[3].x)); - float MaxX = max(max(Points[0].x, Points[1].x), max(Points[2].x, Points[3].x)); + float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); + float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); - float MinY = min(min(Points[0].y, Points[1].y), min(Points[2].y, Points[3].y)); - float MaxY = max(max(Points[0].y, Points[1].y), max(Points[2].y, Points[3].y)); + float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); + float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); float MaxZ = pPosn->z - pEntity->GetPosition().z; float MinZ = MaxZ - fZDistance; @@ -1767,7 +1767,7 @@ CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTextur { ASSERT(pPosn != NULL); - C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, max(fFrontX, -fSideY), + C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, Max(fFrontX, -fSideY), 0, 128, 255, 128, 2048, 0.2f, 0); } diff --git a/src/render/Timecycle.cpp b/src/render/Timecycle.cpp index 7ab3e91e..0113c001 100644 --- a/src/render/Timecycle.cpp +++ b/src/render/Timecycle.cpp @@ -290,7 +290,7 @@ CTimeCycle::Update(void) TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL); if(m_FogReduction != 0) - m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); + m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; @@ -311,9 +311,9 @@ CTimeCycle::Update(void) if(TheCamera.GetForward().z < -0.9f || !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) - m_FogReduction = min(m_FogReduction+1, 64); + m_FogReduction = Min(m_FogReduction+1, 64); else - m_FogReduction = max(m_FogReduction-1, 0); + m_FogReduction = Max(m_FogReduction-1, 0); } STARTPATCHES diff --git a/src/render/VisibilityPlugins.cpp b/src/render/VisibilityPlugins.cpp index ca3a0195..2107813b 100644 --- a/src/render/VisibilityPlugins.cpp +++ b/src/render/VisibilityPlugins.cpp @@ -103,14 +103,14 @@ CVisibilityPlugins::SetRenderWareCamera(RwCamera *camera) else ms_cullCompsDist = sq(TheCamera.LODDistMultiplier * 20.0f); - ms_vehicleLod0Dist = sq(70.0 * TheCamera.GenerationDistMultiplier); - ms_vehicleLod1Dist = sq(90.0 * TheCamera.GenerationDistMultiplier); - ms_vehicleFadeDist = sq(100.0 * TheCamera.GenerationDistMultiplier); - ms_bigVehicleLod0Dist = sq(60.0 * TheCamera.GenerationDistMultiplier); - ms_bigVehicleLod1Dist = sq(150.0 * TheCamera.GenerationDistMultiplier); - ms_pedLod0Dist = sq(25.0 * TheCamera.LODDistMultiplier); - ms_pedLod1Dist = sq(60.0 * TheCamera.LODDistMultiplier); - ms_pedFadeDist = sq(70.0 * TheCamera.LODDistMultiplier); + ms_vehicleLod0Dist = sq(70.0f * TheCamera.GenerationDistMultiplier); + ms_vehicleLod1Dist = sq(90.0f * TheCamera.GenerationDistMultiplier); + ms_vehicleFadeDist = sq(100.0f * TheCamera.GenerationDistMultiplier); + ms_bigVehicleLod0Dist = sq(60.0f * TheCamera.GenerationDistMultiplier); + ms_bigVehicleLod1Dist = sq(150.0f * TheCamera.GenerationDistMultiplier); + ms_pedLod0Dist = sq(25.0f * TheCamera.LODDistMultiplier); + ms_pedLod1Dist = sq(60.0f * TheCamera.LODDistMultiplier); + ms_pedFadeDist = sq(70.0f * TheCamera.LODDistMultiplier); } RpMaterial* diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index a1c2af93..c711c8c8 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -979,7 +979,7 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col SMALL_SECTOR_SIZE / 2, apBoatList) ) { - float fWakeColor = fAdd1 - max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); + float fWakeColor = fAdd1 - Max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); RpGeometry *geom = apGeomArray[nGeomUsed++]; @@ -1035,9 +1035,9 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col RwRGBAAssign(&wakeColor, &color); - wakeColor.red = min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); - wakeColor.green = min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); - wakeColor.blue = min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); + wakeColor.red = Min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); + wakeColor.green = Min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); + wakeColor.blue = Min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); RwRGBAAssign(&geomPreLights[9*i+j], &wakeColor); @@ -1114,7 +1114,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) fSectorY + SMALL_SECTOR_SIZE - fY ); - fDistSqr = min(vecDist.MagnitudeSqr(), fDistSqr); + fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); } } } diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index d4eb71be..fc82e51e 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -1661,7 +1661,7 @@ void CenterVideo(void) /* ***************************************************************************** */ -void PlayMovieInWindow(int cmdShow, LPTSTR szFile) +void PlayMovieInWindow(int cmdShow, const char* szFile) { WCHAR wFileName[256]; HRESULT hr; diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 18c74478..99354d70 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -316,7 +316,7 @@ CAutomobile::ProcessControl(void) // Set Center of Mass to make car more stable if(strongGrip1 || bCheat3) - m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0*m_fHeightAboveRoad; + m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0f*m_fHeightAboveRoad; else if(pHandling->Flags & HANDLING_NONPLAYER_STABILISER && m_status == STATUS_PHYSICS) m_vecCentreOfMass.z = pHandling->CentreOfMass.z - 0.2f*pHandling->Dimension.z; else @@ -691,7 +691,7 @@ CAutomobile::ProcessControl(void) if(m_aSuspensionSpringRatio[i] < 1.0f) m_aWheelTimer[i] = 4.0f; else - m_aWheelTimer[i] = max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); + m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); if(m_aWheelTimer[i] > 0.0f){ m_nWheelsOnGround++; @@ -1009,7 +1009,7 @@ CAutomobile::ProcessControl(void) if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) - m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.0005f, 0.0f); + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ FlyingControl(FLIGHT_MODEL_DODO); @@ -1017,7 +1017,7 @@ CAutomobile::ProcessControl(void) FlyingControl(FLIGHT_MODEL_HELI); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ if(CPad::GetPad(0)->GetCircleJustDown()) - m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.03f, 0.0f); + m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); if(m_aWheelSpeed[0] < 0.22f) m_aWheelSpeed[0] += 0.0001f; if(m_aWheelSpeed[0] > 0.15f) @@ -1129,10 +1129,10 @@ CAutomobile::ProcessControl(void) if(speed > sq(0.1f)){ speed = Sqrt(speed); if(suspShake > 0.0f){ - uint8 freq = min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); }else{ - uint8 freq = min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); + uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); } } @@ -1591,10 +1591,11 @@ CAutomobile::PreRender(void) break; } - if(GetModelIndex() == MI_RCBANDIT || - GetModelIndex() == MI_DODO || - GetModelIndex() == MI_RHINO) - goto nolights; + if(GetModelIndex() == MI_RCBANDIT || GetModelIndex() == MI_DODO || + GetModelIndex() == MI_RHINO) { + CShadows::StoreShadowForCar(this); + return; + } // Turn lights on/off bool shouldLightsBeOn = @@ -1739,7 +1740,7 @@ CAutomobile::PreRender(void) // Taillight coronas if(behindness > 0.0f){ // Behind car - float intensity = 0.4f*behindness + 0.4; + float intensity = 0.4f*behindness + 0.4f; float size = (behindness + 1.0f)/2.0f; if(m_fGasPedal < 0.0f){ @@ -1757,7 +1758,7 @@ CAutomobile::PreRender(void) CCoronas::TYPE_STREAK, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, angle); }else{ - if(m_fBrakePedal > 0.0){ + if(m_fBrakePedal > 0.0f){ intensity += 0.4f; size += 0.3f; } @@ -1843,8 +1844,10 @@ CAutomobile::PreRender(void) }else{ // Lights off - if(m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED) - goto nolights; + if(m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED) { + CShadows::StoreShadowForCar(this); + return; + } CVector lightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; CVector lightR = GetMatrix() * lightPos; @@ -1903,7 +1906,6 @@ CAutomobile::PreRender(void) } } -nolights: CShadows::StoreShadowForCar(this); } @@ -2586,7 +2588,7 @@ CAutomobile::HydraulicControl(void) float minz = pos.z + extendedLowerLimit - wheelRadius; if(minz < specialColModel->boundingBox.min.z) specialColModel->boundingBox.min.z = minz; - float radius = max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); + float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); if(specialColModel->boundingSphere.radius < radius) specialColModel->boundingSphere.radius = radius; @@ -2685,10 +2687,10 @@ CAutomobile::HydraulicControl(void) float front = -rear; float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; float left = -right; - suspChange[CARWHEEL_FRONT_LEFT] = max(front+left, 0.0f); - suspChange[CARWHEEL_REAR_LEFT] = max(rear+left, 0.0f); - suspChange[CARWHEEL_FRONT_RIGHT] = max(front+right, 0.0f); - suspChange[CARWHEEL_REAR_RIGHT] = max(rear+right, 0.0f); + suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); + suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); + suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); + suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); if(m_hydraulicState < 100){ // Lowered, move wheels up @@ -2804,7 +2806,7 @@ CAutomobile::ProcessBuoyancy(void) ApplyTurnForce(impulse, point); CVector initialSpeed = m_vecMoveSpeed; - float timeStep = max(CTimer::GetTimeStep(), 0.01f); + float timeStep = Max(CTimer::GetTimeStep(), 0.01f); float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); m_vecMoveSpeed *= waterResistance; @@ -2877,7 +2879,7 @@ CAutomobile::ProcessBuoyancy(void) static RwRGBA black; if(pos.z >= 0.0f){ nGenerateRaindrops = 0; - pos.z += 0.5; + pos.z += 0.5f; CParticleObject::AddObject(POBJECT_SPLASHES_AROUND, pos, CVector(0.0f, 0.0f, 0.0f), 6.5f, 2500, black, true); } @@ -2897,7 +2899,7 @@ CAutomobile::ProcessBuoyancy(void) float fSpeed = vSpeed.MagnitudeSqr(); if(fSpeed > sq(0.05f)){ fSpeed = Sqrt(fSpeed); - float size = min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); + float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; CParticle::AddParticle(PARTICLE_PED_SPLASH, @@ -2979,11 +2981,11 @@ CAutomobile::DoDriveByShootings(void) // TODO: what is this? if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ - m_weaponDoorTimerLeft = max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); } if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ - m_weaponDoorTimerRight = max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); } } @@ -3131,7 +3133,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) FindPlayerPed()->SetWantedLevelNoDrop(1); if(m_status == STATUS_PLAYER && impulse > 50.0f){ - uint8 freq = min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(40000/freq, freq); } @@ -3284,7 +3286,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; - money = min(money, 40); + money = Min(money, 40); if(money > 2){ sprintf(gString, "$%d", money); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; @@ -3987,7 +3989,7 @@ CAutomobile::SetupSuspensionLines(void) // adjust col model to include suspension lines if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) colModel->boundingBox.min.z = colModel->lines[0].p1.z; - float radius = max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); + float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); if(colModel->boundingSphere.radius < radius) colModel->boundingSphere.radius = radius; diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index f614b78f..2b5ff567 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -61,7 +61,7 @@ float CBoat::IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat) float fDist = vecDist.MagnitudeSqr(); if ( fDist < SQR(fMaxDist) ) - return 1.0f - min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); + return 1.0f - Min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); } return 0.0f; diff --git a/src/vehicles/HandlingMgr.cpp b/src/vehicles/HandlingMgr.cpp index be96ab08..0f16401e 100644 --- a/src/vehicles/HandlingMgr.cpp +++ b/src/vehicles/HandlingMgr.cpp @@ -6,9 +6,9 @@ cHandlingDataMgr &mod_HandlingManager = *(cHandlingDataMgr*)0x728060; -char *HandlingFilename = "HANDLING.CFG"; +const char *HandlingFilename = "HANDLING.CFG"; -char VehicleNames[NUMHANDLINGS][14] = { +const char VehicleNames[NUMHANDLINGS][14] = { "LANDSTAL", "IDAHO", "STINGER", @@ -199,7 +199,7 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling) if(handling->fTurnMass < 10.0f) handling->fTurnMass *= 5.0f; handling->fInvMass = 1.0f/handling->fMass; - handling->fBuoyancy = 100.0f/handling->nPercentSubmerged * 0.008*handling->fMass; + handling->fBuoyancy = 100.0f/handling->nPercentSubmerged * 0.008f*handling->fMass; // What the hell is going on here? specificVolume = handling->Dimension.x*handling->Dimension.z*0.5f / handling->fMass; // ? @@ -207,7 +207,7 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling) b = 100.0f; velocity = handling->Transmission.fMaxVelocity; while(a < b && velocity > 0.0f){ - velocity -= 0.01; + velocity -= 0.01f; a = handling->Transmission.fEngineAcceleration/6.0f; b = -velocity * (1.0f/(specificVolume * sq(velocity) + 1.0f) - 1.0f); } diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index 9b1a651d..39fc7ec4 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -14,7 +14,7 @@ #include "Shadows.h" #include "Coronas.h" #include "Explosion.h" -#include "TimeCycle.h" +#include "Timecycle.h" #include "TempColModels.h" #include "World.h" #include "WaterLevel.h" @@ -223,19 +223,19 @@ CHeli::ProcessControl(void) switch(m_heliStatus){ case HELI_STATUS_HOVER: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f; + m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f; break; case HELI_STATUS_SHOT_DOWN: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; break; case HELI_STATUS_HOVER2: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; break; default: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = max(groundZ, m_fTargetZ) + 12.0f; + m_fTargetZ = Max(groundZ, m_fTargetZ) + 12.0f; break; } @@ -994,7 +994,7 @@ CHeli::TestBulletCollision(CVector *line0, CVector *line1, CVector *bulletPos, i float distToHeli = (pHelis[i]->GetPosition() - *line0).Magnitude(); CVector line = (*line1 - *line0); float lineLength = line.Magnitude(); - *bulletPos = *line0 + line*max(1.0f, distToHeli-5.0f); + *bulletPos = *line0 + line*Max(1.0f, distToHeli-5.0f); pHelis[i]->m_nBulletDamage += damage; diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 775cf572..40e0e5a7 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -397,7 +397,7 @@ CPlane::ProcessControl(void) planePathSpeed = PlanePath3Speed; numPathNodes = NumPath3Nodes; if(CesnaMissionStatus == CESNA_STATUS_LANDED){ - pDrugRunCesna = false; + pDrugRunCesna = nil; FlagToDestroyWhenNextProcessed(); } }else if(m_bIsDropOffCesna){ @@ -407,7 +407,7 @@ CPlane::ProcessControl(void) planePathSpeed = PlanePath4Speed; numPathNodes = NumPath4Nodes; if(DropOffCesnaMissionStatus == CESNA_STATUS_LANDED){ - pDropOffCesna = false; + pDropOffCesna = nil; FlagToDestroyWhenNextProcessed(); } }else{ diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 4795a29f..0355cba1 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -273,7 +273,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon right = -contactSpeedRight/wheelsOnGround; if(wheelStatus == WHEEL_STATUS_BURST){ - float fwdspeed = min(contactSpeedFwd, 0.3f); + float fwdspeed = Min(contactSpeedFwd, 0.3f); right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); } } @@ -363,7 +363,7 @@ CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVec void CVehicle::ExtinguishCarFire(void) { - m_fHealth = max(m_fHealth, 300.0f); + m_fHealth = Max(m_fHealth, 300.0f); if(m_pCarFire) m_pCarFire->Extinguish(); if(IsCar()){ @@ -638,13 +638,13 @@ CVehicle::SetDriver(CPed *driver) if(bFreebies && driver == FindPlayerPed()){ if(GetModelIndex() == MI_AMBULAN) - FindPlayerPed()->m_fHealth = min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); + FindPlayerPed()->m_fHealth = Min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); else if(GetModelIndex() == MI_TAXI) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; else if(GetModelIndex() == MI_POLICE) driver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5); else if(GetModelIndex() == MI_ENFORCER) - driver->m_fArmour = max(driver->m_fArmour, 100.0f); + driver->m_fArmour = Max(driver->m_fArmour, 100.0f); else if(GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; bFreebies = false; -- cgit v1.2.3 From 01ac2929cd723b579454788ffbe9579d1863d240 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 27 Aug 2019 20:50:59 +0200 Subject: Cleanup --- src/animation/AnimBlendAssociation.cpp | 4 +- src/animation/AnimBlendHierarchy.cpp | 2 +- src/audio/AudioManager.cpp | 1931 ++++++++++++++++---------------- src/audio/AudioManager.h | 206 ++-- src/audio/AudioManager.h.autosave | 549 +++++++++ src/audio/DMAudio.cpp | 12 +- src/control/CarCtrl.cpp | 22 +- src/control/CarGen.cpp | 2 +- src/control/PathFind.cpp | 10 +- src/control/Replay.cpp | 38 +- src/control/Script.cpp | 6 +- src/core/Camera.cpp | 10 +- src/core/Collision.cpp | 8 +- src/core/Frontend.cpp | 2 +- src/core/IniFile.cpp | 4 +- src/core/Pad.cpp | 4 +- src/core/Streaming.cpp | 42 +- src/core/Wanted.cpp | 2 +- src/core/common.h | 4 +- src/core/main.cpp | 2 +- src/entities/Physical.cpp | 40 +- src/peds/Ped.cpp | 14 +- src/peds/PedPlacement.cpp | 2 +- src/render/Clouds.cpp | 8 +- src/render/Coronas.cpp | 20 +- src/render/Lights.cpp | 28 +- src/render/ParticleMgr.cpp | 2 +- src/render/PointLights.cpp | 2 +- src/render/Shadows.cpp | 26 +- src/render/Timecycle.cpp | 6 +- src/render/WaterLevel.cpp | 10 +- src/vehicles/Automobile.cpp | 34 +- src/vehicles/Boat.cpp | 2 +- src/vehicles/Heli.cpp | 10 +- src/vehicles/Vehicle.cpp | 8 +- 35 files changed, 1770 insertions(+), 1302 deletions(-) create mode 100644 src/audio/AudioManager.h.autosave (limited to 'src') diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index d2214057..ec42191b 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -185,7 +185,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount <= 0.0f && blendDelta < 0.0f){ // We're faded out and are not fading in blendAmount = 0.0f; - blendDelta = Max(0.0f, blendDelta); + blendDelta = max(0.0f, blendDelta); if(flags & ASSOC_DELETEFADEDOUT){ if(callbackType == CB_FINISH || callbackType == CB_DELETE) callback(this, callbackArg); @@ -197,7 +197,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount > 1.0f){ // Maximally faded in, clamp values blendAmount = 1.0f; - blendDelta = Min(0.0f, blendDelta); + blendDelta = min(0.0f, blendDelta); } return true; diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp index e594e5d8..e4bcdc69 100644 --- a/src/animation/AnimBlendHierarchy.cpp +++ b/src/animation/AnimBlendHierarchy.cpp @@ -36,7 +36,7 @@ CAnimBlendHierarchy::CalcTotalTime(void) float seqTime = 0.0f; for(j = 0; j < sequences[i].numFrames; j++) seqTime += sequences[i].GetKeyFrame(j)->deltaTime; - totalTime = Max(totalTime, seqTime); + totalTime = max(totalTime, seqTime); } totalLength = totalTime; } diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index e1860698..1e4b9c3b 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -31,12 +31,18 @@ #include "sampman.h" cAudioManager &AudioManager = *(cAudioManager *)0x880FC0; +uint32 *audioLogicTimers = (uint32 *)0x6508A0; +uint8 &jumboVolOffset = *(uint8 *)0x6508ED; +uint8 &gJumboVolOffsetPercentage = *(uint8 *)0x6508ED; +char &g_nMissionAudioPlayingStatus = *(char *)0x60ED88; +int32 *BankStartOffset = (int32 *)0x6FAB70; //[2] +int32 &g_nMissionAudioSfx = *(int32 *)0x60ED84; +bool &bPlayerJustEnteredCar = *(bool *)0x6508C4; +bool &g_bMissionAudioLoadFailed = *(bool *)0x95CD8E; constexpr int totalAudioEntitiesSlots = 200; constexpr int maxVolume = 127; -uint32 *audioLogicTimers = (uint32 *)0x6508A0; - // TODO: where is this used? Is this the right file? enum eVehicleModel { LANDSTAL, @@ -251,8 +257,6 @@ cAudioScriptObject::operator delete(void *p, int handle) CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); } -char &g_nMissionAudioPlayingStatus = *(char *)0x60ED88; - void cAudioManager::AddDetailsToRequestedOrderList(uint8 sample) { @@ -311,8 +315,7 @@ cAudioManager::AddReflectionsToRequestedQueue() { float reflectionDistance; int32 noise; - uint8 emittingVolume = emittingVolume = - (m_sQueueSample.m_bVolume >> 1) + (m_sQueueSample.m_bVolume >> 3); + uint8 emittingVolume = (m_sQueueSample.m_bVolume >> 1) + (m_sQueueSample.m_bVolume >> 3); for(uint32 i = 0; i < 5u; i++) { reflectionDistance = m_afReflectionsDistances[i]; @@ -452,9 +455,9 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float speedOfSource = (dist / field_19195) * speedMultiplier; if(speedOfSound > Abs(speedOfSource)) { if(speedOfSource < 0.0f) { - speedOfSource = Max(speedOfSource, -1.5f); + speedOfSource = max(speedOfSource, -1.5f); } else { - speedOfSource = Min(speedOfSource, 1.5f); + speedOfSource = min(speedOfSource, 1.5f); } newFreq = (oldFreq * speedOfSound) / (speedOfSource + speedOfSound); } @@ -485,7 +488,7 @@ cAudioManager::ComputeVolume(int emittingVolume, float soundIntensity, float dis } int32 -cAudioManager::CreateEntity(int32 type, void *entity) +cAudioManager::CreateEntity(int32 type, CPhysical *entity) { if(!m_bIsInitialised) return -4; if(!entity) return -2; @@ -495,7 +498,7 @@ cAudioManager::CreateEntity(int32 type, void *entity) m_asAudioEntities[i].m_bIsUsed = true; m_asAudioEntities[i].m_bStatus = 0; m_asAudioEntities[i].m_nType = (eAudioType)type; - m_asAudioEntities[i].m_pEntity = entity; + m_asAudioEntities[i].m_pEntity = (void*)entity; m_asAudioEntities[i].m_awAudioEvent[0] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[1] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[2] = SOUND_TOTAL_PED_SOUNDS; @@ -557,6 +560,13 @@ cAudioManager::DestroyEntity(int32 id) } } +void +cAudioManager::DoJumboVolOffset() const +{ + if(!(m_FrameCounter % (m_anRandomTable[0] % 6u + 3))) + jumboVolOffset = m_anRandomTable[1] % 60u; +} + void cAudioManager::DoPoliceRadioCrackle() { @@ -581,711 +591,144 @@ cAudioManager::DoPoliceRadioCrackle() AddSampleToRequestedQueue(); } -void -cAudioManager::GenerateIntegerRandomNumberTable() +uint32 +cAudioManager::GetPlayerTalkSfx(int16 sound) { - for(int32 i = 0; i < 5; i++) { m_anRandomTable[i] = rand(); } -} + uint32 sfx; + static uint32 lastSfx = NO_SAMPLE; -void -cAudioManager::TranslateEntity(CVector *v1, CVector *v2) const -{ - const RwMatrix &cM = TheCamera.GetMatrix().m_matrix; - const CVector &cV = TheCamera.GetPosition(); + switch(sound) { + case SOUND_PED_DAMAGE: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_DAMAGE_REACTION_1, 11u); + break; - float a = v1->z - cV.z; - float b = v1->y - cV.y; - float c = v1->x - cV.x; + case SOUND_PED_HIT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_HIT_REACTION_1, 10u); break; - v2->x = cM.right.y * b + cM.right.x * c + cM.right.z * a; - v2->y = cM.up.y * b + cM.up.x * c + cM.up.z * a; - v2->z = cM.at.y * b + cM.at.x * c + cM.at.z * a; -} + case SOUND_PED_LAND: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FALL_REACTION_1, 6u); break; -void -cAudioManager::ResetAudioLogicTimers(int32 timer) -{ - audioLogicTimers[0] = timer; - audioLogicTimers[8] = timer; - audioLogicTimers[1] = timer; - audioLogicTimers[7] = timer; - audioLogicTimers[2] = timer; - audioLogicTimers[6] = timer; - audioLogicTimers[3] = timer; - audioLogicTimers[5] = timer; - audioLogicTimers[4] = timer; - for(int32 i = 0; i < m_nAudioEntitiesTotal; i++) { - if(m_asAudioEntities[m_anAudioEntityIndices[i]].m_nType == AUDIOTYPE_PHYSICAL) { - CPed *ped = (CPed *)m_asAudioEntities[m_anAudioEntityIndices[i]].m_pEntity; - if(ped->IsPed()) { - ped->m_lastSoundStart = timer; - ped->m_soundStart = timer + m_anRandomTable[0] % 3000u; - } - } + default: sfx = NO_SAMPLE; break; } -<<<<<<< HEAD + return sfx; } -void -cAudioManager::PostInitialiseGameSpecificSetup() +uint32 +cAudioManager::GetCopTalkSfx(int16 sound) { - m_nFireAudioEntity = - CreateEntity(AUDIOTYPE_FIRE, - (CPhysical *)0x8F31D0); // last is addr of firemanager @todo change - if(m_nFireAudioEntity >= 0) SetEntityStatus(m_nFireAudioEntity, 1); - - m_nCollisionEntity = CreateEntity(AUDIOTYPE_COLLISION, (CPhysical *)1); - if(m_nCollisionEntity >= 0) SetEntityStatus(m_nCollisionEntity, 1); - - m_nFrontEndEntity = CreateEntity(AUDIOTYPE_FRONTEND, (CPhysical *)1); - if(m_nFrontEndEntity >= 0) SetEntityStatus(m_nFrontEndEntity, 1); - - m_nProjectileEntity = CreateEntity(AUDIOTYPE_PROJECTILE, (CPhysical *)1); - if(m_nProjectileEntity >= 0) SetEntityStatus(m_nProjectileEntity, 1); - - m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATERCANNON, (CPhysical *)1); - if(m_nWaterCannonEntity >= 0) SetEntityStatus(m_nWaterCannonEntity, 1); - - m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (CPhysical *)1); - if(m_nPoliceChannelEntity >= 0) SetEntityStatus(m_nPoliceChannelEntity, 1); + uint32 sfx; + PedState pedState; + static uint32 lastSfx = NO_SAMPLE; - m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (CPhysical *)1); - if(m_nBridgeEntity >= 0) SetEntityStatus(m_nBridgeEntity, 1); + if(sound == SOUND_PED_ARREST_COP) { + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_COP_1_ARREST_1, 6u); + } else { + if(sound != SOUND_PED_PURSUIT_COP) { return GetGenericMaleTalkSfx(sound); } - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; - m_sMissionAudio.m_bLoadingStatus = 0; - m_sMissionAudio.m_bPlayStatus = 0; - m_sMissionAudio.field_22 = 0; - m_sMissionAudio.m_bIsPlayed = 0; - m_sMissionAudio.field_12 = 1; - m_sMissionAudio.field_24 = 0; - ResetAudioLogicTimers((int32)CTimer::GetTimeInMilliseconds); -} + pedState = FindPlayerPed()->m_nPedState; + if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) + return NO_SAMPLE; + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_COP_1_PURSUIT_1, 7u); + } -WRAPPER -void -cAudioManager::InitialisePoliceRadioZones() -{ - EAXJMP(0x57EAC0); + return 13 * (m_sQueueSample.m_nEntityIndex % 5) + sfx; } -WRAPPER -void -cAudioManager::ResetAudioLogicTimers(int32 timer) +uint32 +cAudioManager::GetSwatTalkSfx(int16 sound) { - EAXJMP(0x569650); -======= - ClearMissionAudio(); - SampleManager.StopChannel(28); ->>>>>>> More more more audio -} + uint32 sfx; + PedState pedState; + static uint32 lastSfx = NO_SAMPLE; -void -cAudioManager::Terminate() -{ - if(m_bIsInitialised) { - MusicManager.Terminate(); + if(sound == SOUND_PED_ARREST_SWAT) { + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_SWAT_1_PURSUIT_ARREST_1, 6u); + } else { + if(sound != SOUND_PED_PURSUIT_SWAT) { return GetGenericMaleTalkSfx(sound); } - for(uint32 i = 0; i < totalAudioEntitiesSlots; i++) { - m_asAudioEntities[i].m_bIsUsed = 0; - m_anAudioEntityIndices[i] = 200; - } + pedState = FindPlayerPed()->m_nPedState; + if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) + return NO_SAMPLE; + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_SWAT_1_PURSUIT_ARREST_1, 6u); + } - m_nAudioEntitiesTotal = 0; - m_nScriptObjectEntityTotal = 0; - PreTerminateGameSpecificShutdown(); + return 6 * (m_sQueueSample.m_nEntityIndex % 3) + sfx; +} - for(uint32 i = 0; i < 2; i++) { - if(SampleManager.IsSampleBankLoaded(i)) SampleManager.UnloadSampleBank(i); - } +uint32 +cAudioManager::GetFBITalkSfx(int16 sound) +{ + uint32 sfx; + PedState pedState; + static uint32 lastSfx = NO_SAMPLE; - SampleManager.Terminate(); + if(sound == SOUND_PED_ARREST_FBI) { + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_FBI_1_PURSUIT_ARREST_1, 6u); + } else { + if(sound != SOUND_PED_PURSUIT_FBI) { return GetGenericMaleTalkSfx(sound); } - m_bIsInitialised = 0; - PostTerminateGameSpecificShutdown(); + pedState = FindPlayerPed()->m_nPedState; + if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) + return NO_SAMPLE; + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_FBI_1_PURSUIT_ARREST_1, 6u); } -} -uint8 -cAudioManager::GetNum3DProvidersAvailable() const -{ - if(m_bIsInitialised) return SampleManager.GetNum3DProvidersAvailable(); - return 0; + return 6 * (m_sQueueSample.m_nEntityIndex % 3) + sfx; } -bool -cAudioManager::IsMP3RadioChannelAvailable() const +uint32 +cAudioManager::GetArmyTalkSfx(int16 sound) { - if(m_bIsInitialised) return SampleManager.IsMP3RadioChannelAvailable(); - - return 0; -} + uint32 sfx; + PedState pedState; + static uint32 lastSfx = NO_SAMPLE; -uint8 -cAudioManager::GetCDAudioDriveLetter() const -{ - if(m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter(); + if(sound != SOUND_PED_PURSUIT_ARMY) { return GetGenericMaleTalkSfx(sound); } - return 0; -} + pedState = FindPlayerPed()->m_nPedState; + if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) + return NO_SAMPLE; + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_ARMY_1_PURSUIT_1, 15u); -void -cAudioManager::SetEffectsMasterVolume(uint8 volume) const -{ - SampleManager.SetEffectsMasterVolume(volume); + return 15 * (m_sQueueSample.m_nEntityIndex % 1) + sfx; } -void -cAudioManager::SetMusicMasterVolume(uint8 volume) const +uint32 +cAudioManager::GetMedicTalkSfx(int16 sound) { - SampleManager.SetMusicMasterVolume(volume); -} + uint32 sfx; + static uint32 lastSfx = NO_SAMPLE; -void -cAudioManager::SetEffectsFadeVolume(uint8 volume) const -{ - SampleManager.SetEffectsFadeVolume(volume); + switch(sound) { + case SOUND_PED_HANDS_COWER: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_HANDS_COWER_1, 5u); + break; + case SOUND_PED_CAR_JACKED: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_CAR_JACKED_1, 5u); + break; + case SOUND_PED_HEALING: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_HEALING_1, 12u); + break; + case SOUND_PED_LEAVE_VEHICLE: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_LEAVE_VEHICLE_1, 9u); + break; + case SOUND_PED_FLEE_RUN: + GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_FLEE_RUN_1, 6u); + break; + default: return GetGenericMaleTalkSfx(sound); + } + return 37 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; } -void -cAudioManager::SetMusicFadeVolume(uint8 volume) const +uint32 +cAudioManager::GetFiremanTalkSfx(int16 sound) { - SampleManager.SetMusicFadeVolume(volume); + return GetGenericMaleTalkSfx(sound); } -void -cAudioManager::SetSpeakerConfig(int32 conf) const +uint32 +cAudioManager::GetNormalMaleTalkSfx(int16 sound) { - SampleManager.SetSpeakerConfig(conf); -} - -WRAPPER -bool cAudioManager::SetupJumboEngineSound(uint8, int32) { EAXJMP(0x56F140); } - -int32 *BankStartOffset = (int32 *)0x6FAB70; //[2] - -void -cAudioManager::PreInitialiseGameSpecificSetup() const -{ - BankStartOffset[0] = AUDIO_SAMPLE_VEHICLE_HORN_0; - BankStartOffset[1] = AUDIO_SAMPLE_POLICE_COP_1_ARREST_1; -} - -int32 &g_nMissionAudioSfx = *(int32 *)0x60ED84; - -void -cAudioManager::SetMissionScriptPoliceAudio(int32 sfx) const -{ - if(m_bIsInitialised) { - if(g_nMissionAudioPlayingStatus != 1) { - g_nMissionAudioPlayingStatus = 0; - g_nMissionAudioSfx = sfx; - } - } -} - -bool -cAudioManager::UsesSiren(int32 model) const -{ - switch(model) { - case FIRETRUK: - case AMBULAN: - case FBICAR: - case POLICE: - case ENFORCER: - case PREDATOR: return true; - default: return false; - } -} - -bool -cAudioManager::UsesSirenSwitching(int32 model) const -{ - switch(model) { - case AMBULAN: - case POLICE: - case ENFORCER: - case PREDATOR: return true; - default: return false; - } -} - -char * -cAudioManager::Get3DProviderName(uint8 id) const -{ - if(!m_bIsInitialised) return 0; - if(id >= SampleManager.GetNum3DProvidersAvailable()) return 0; - return SampleManager.Get3DProviderName(id); -} - -bool -cAudioManager::SetupJumboFlySound(uint8 emittingVol) -{ - int32 vol; - - if(m_sQueueSample.m_fDistance >= 440.0f) return 0; - - vol = ComputeVolume(emittingVol, 440.0f, m_sQueueSample.m_fDistance); - m_sQueueSample.m_bVolume = vol; - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_FLY_SOUND; - m_sQueueSample.m_counter = 0; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_bIsDistant = 0; - m_sQueueSample.field_16 = 1; - m_sQueueSample.m_bEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_nFrequency = - SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_JUMBO_FLY_SOUND); - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_fSoundIntensity = 440.0f; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.field_76 = 5; - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - AddSampleToRequestedQueue(); - } - return 1; -} - -bool -cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) -{ - if(m_sQueueSample.m_fDistance >= 240.f) return 0; - - m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 240.f, m_sQueueSample.m_fDistance); - - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_counter = 5; - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_bIsDistant = 1; - m_sQueueSample.field_16 = 1; - m_sQueueSample.m_nFrequency = - SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND); - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_fSoundIntensity = 240.0f; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_76 = 12; - m_sQueueSample.m_bOffset = 0; - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.m_bRequireReflection = 0; - AddSampleToRequestedQueue(); - m_sQueueSample.m_counter = 6; - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; - m_sQueueSample.m_nFrequency += 200; - m_sQueueSample.m_bOffset = maxVolume; - AddSampleToRequestedQueue(); - } - return 1; -} - -uint8 &gJumboVolOffsetPercentage = *(uint8 *)0x6508ED; - -bool -cAudioManager::SetupJumboTaxiSound(uint8 vol) -{ - uint8 emittingVol; - - if(m_sQueueSample.m_fDistance >= 180.f) return 0; - - emittingVol = (vol >> 1) + ((vol >> 1) * m_sQueueSample.m_fDistance * 0.0055556f); - - if(m_sQueueSample.m_fDistance * 0.0055556f < 0.7f) - emittingVol -= emittingVol * gJumboVolOffsetPercentage / 100; - m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 180.f, m_sQueueSample.m_fDistance); - - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_counter = 1; - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_TAXI_SOUND; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_bIsDistant = 0; - m_sQueueSample.field_16 = 1; - m_sQueueSample.m_nFrequency = GetJumboTaxiFreq(); - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_fSoundIntensity = 180.0f; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_76 = 4; - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.m_bRequireReflection = 0; - AddSampleToRequestedQueue(); - } - return 1; -} - -bool -cAudioManager::SetupJumboWhineSound(uint8 emittingVol, int32 freq) -{ - if(m_sQueueSample.m_fDistance >= 170.f) return 0; - - m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 170.f, m_sQueueSample.m_fDistance); - - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_counter = 2; - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_WHINE_SOUND; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_bIsDistant = 0; - m_sQueueSample.field_16 = 1; - m_sQueueSample.m_nFrequency = freq; - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_fSoundIntensity = 170.0f; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_76 = 4; - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.m_bRequireReflection = 0; - AddSampleToRequestedQueue(); - } - return 1; -} - -void -cAudioManager::SetMissionAudioLocation(float x, float y, float z) -{ - if(m_bIsInitialised) { - m_sMissionAudio.field_12 = 0; - m_sMissionAudio.m_vecPos.x = x; - m_sMissionAudio.m_vecPos.y = y; - m_sMissionAudio.m_vecPos.z = z; - } -} - -void -cAudioManager::ResetPoliceRadio() -{ - if(m_bIsInitialised) { - if(SampleManager.GetChannelUsedFlag(28)) SampleManager.StopChannel(28); - InitialisePoliceRadio(); - } -} - -bool -cAudioManager::UsesReverseWarning(int32 model) const -{ - return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || - model == COACH; -} - -int32 -cAudioManager::RandomDisplacement(uint32 seed) const -{ - int32 value; - - static bool bIsEven = true; - static uint32 base = 0; - - if(!seed) return 0; - - value = m_anRandomTable[(base + seed) % 5] % seed; - base += value; - - if(value % 2) { bIsEven = !bIsEven; } - if(!bIsEven) value = -value; - return value; -} - -void -cAudioManager::ReleaseDigitalHandle() const -{ - if(m_bIsInitialised) { SampleManager.ReleaseDigitalHandle(); } -} - -void -cAudioManager::ReacquireDigitalHandle() const -{ - if(m_bIsInitialised) { SampleManager.ReacquireDigitalHandle(); } -} - -void -cAudioManager::SetDynamicAcousticModelingStatus(bool status) -{ - m_bDynamicAcousticModelingStatus = status; -} - -bool -cAudioManager::IsAudioInitialised() const -{ - return m_bIsInitialised; -} - -void -cAudioManager::SetEntityStatus(int32 id, bool status) -{ - if(m_bIsInitialised && id >= 0 && id < totalAudioEntitiesSlots) { - if(m_asAudioEntities[id].m_bIsUsed) { m_asAudioEntities[id].m_bStatus = status; } - } -} - -void -cAudioManager::GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const -{ - *phrase = sample + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % maxOffset; - - // check if the same sfx like last time, if yes, then try use next one, - // if exceeded range, then choose first available sample - if(*phrase == *prevPhrase && ++*phrase >= sample + maxOffset) *phrase = sample; - *prevPhrase = *phrase; -} - -uint8 &jumboVolOffset = *(uint8 *)0x6508ED; - -void -cAudioManager::DoJumboVolOffset() const -{ - if(!(m_FrameCounter % (m_anRandomTable[0] % 6u + 3))) - jumboVolOffset = m_anRandomTable[1] % 60u; -} - -int32 -cAudioManager::GetPedCommentSfx(CPed *ped, int32 sound) -{ - if(ped->IsPlayer()) return GetPlayerTalkSfx(sound); - - switch(ped->m_modelIndex) { - case MI_COP: return GetCopTalkSfx(sound); - case MI_SWAT: return GetSwatTalkSfx(sound); - case MI_FBI: return GetFBITalkSfx(sound); - case MI_ARMY: return GetArmyTalkSfx(sound); - case MI_MEDIC: return GetMedicTalkSfx(sound); - case MI_FIREMAN: return GetFiremanTalkSfx(sound); - case MI_MALE01: return GetNormalMaleTalkSfx(sound); - case MI_TAXI_D: return GetTaxiDriverTalkSfx(sound); - case MI_PIMP: return GetPimpTalkSfx(sound); - case MI_GANG01: - case MI_GANG02: return GetMafiaTalkSfx(sound); - case MI_GANG03: - case MI_GANG04: return GetTriadTalkSfx(sound); - case MI_GANG05: - case MI_GANG06: return GetDiabloTalkSfx(sound); - case MI_GANG07: - case MI_GANG08: return GetYakuzaTalkSfx(sound); - case MI_GANG09: - case MI_GANG10: return GetYardieTalkSfx(sound); - case MI_GANG11: - case MI_GANG12: return GetColumbianTalkSfx(sound); - case MI_GANG13: - case MI_GANG14: return GetHoodTalkSfx(sound); - case MI_CRIMINAL01: return GetBlackCriminalTalkSfx(sound); - case MI_CRIMINAL02: return GetWhiteCriminalTalkSfx(sound); - case MI_SPECIAL01: - case MI_SPECIAL02: - case MI_SPECIAL03: - case MI_SPECIAL04: return GetSpecialCharacterTalkSfx(ped->m_modelIndex, sound); - case MI_MALE02: return GetMaleNo2TalkSfx(sound); - case MI_MALE03: - case MI_P_MAN1: - case MI_P_MAN2: return GetBlackProjectMaleTalkSfx(sound, ped->m_modelIndex); - case MI_FATMALE01: return GetWhiteFatMaleTalkSfx(sound); - case MI_FATMALE02: return GetBlackFatMaleTalkSfx(sound); - case MI_FEMALE01: return GetBlackCasualFemaleTalkSfx(sound); - case MI_FEMALE02: - case MI_CAS_WOM: return GetWhiteCasualFemaleTalkSfx(sound); - case MI_FEMALE03: return GetFemaleNo3TalkSfx(sound); - case MI_FATFEMALE01: return GetBlackFatFemaleTalkSfx(sound); - case MI_FATFEMALE02: return GetWhiteFatFemaleTalkSfx(sound); - case MI_PROSTITUTE: return GetBlackFemaleProstituteTalkSfx(sound); - case MI_PROSTITUTE2: return GetWhiteFemaleProstituteTalkSfx(sound); - case MI_P_WOM1: return GetBlackProjectFemaleOldTalkSfx(sound); - case MI_P_WOM2: return GetBlackProjectFemaleYoungTalkSfx(sound); - case MI_CT_MAN1: return GetChinatownMaleOldTalkSfx(sound); - case MI_CT_MAN2: return GetChinatownMaleYoungTalkSfx(sound); - case MI_CT_WOM1: return GetChinatownFemaleOldTalkSfx(sound); - case MI_CT_WOM2: return GetChinatownFemaleYoungTalkSfx(sound); - case MI_LI_MAN1: - case MI_LI_MAN2: return GetLittleItalyMaleTalkSfx(sound); - case MI_LI_WOM1: return GetLittleItalyFemaleOldTalkSfx(sound); - case MI_LI_WOM2: return GetLittleItalyFemaleYoungTalkSfx(sound); - case MI_DOCKER1: return GetWhiteDockerMaleTalkSfx(sound); - case MI_DOCKER2: return GetBlackDockerMaleTalkSfx(sound); - case MI_SCUM_MAN: return GetScumMaleTalkSfx(sound); - case MI_SCUM_WOM: return GetScumFemaleTalkSfx(sound); - case MI_WORKER1: return GetWhiteWorkerMaleTalkSfx(sound); - case MI_WORKER2: return GetBlackWorkerMaleTalkSfx(sound); - case MI_B_MAN1: - case MI_B_MAN3: return GetBusinessMaleYoungTalkSfx(sound, ped->m_modelIndex); - case MI_B_MAN2: return GetBusinessMaleOldTalkSfx(sound); - case MI_B_WOM1: - case MI_B_WOM2: return GetWhiteBusinessFemaleTalkSfx(sound, ped->m_modelIndex); - case MI_B_WOM3: return GetBlackBusinessFemaleTalkSfx(sound); - case MI_MOD_MAN: return GetSupermodelMaleTalkSfx(sound); - case MI_MOD_WOM: return GetSupermodelFemaleTalkSfx(sound); - case MI_ST_MAN: return GetStewardMaleTalkSfx(sound); - case MI_ST_WOM: return GetStewardFemaleTalkSfx(sound); - case MI_FAN_MAN1: - case MI_FAN_MAN2: return GetFanMaleTalkSfx(sound, ped->m_modelIndex); - case MI_FAN_WOM: return GetFanFemaleTalkSfx(sound); - case MI_HOS_MAN: return GetHospitalMaleTalkSfx(sound); - case MI_HOS_WOM: return GetHospitalFemaleTalkSfx(sound); - case MI_CONST1: return GetWhiteConstructionWorkerTalkSfx(sound); - case MI_CONST2: return GetBlackConstructionWorkerTalkSfx(sound); - case MI_SHOPPER1: - case MI_SHOPPER2: - case MI_SHOPPER3: return GetShopperFemaleTalkSfx(sound, ped->m_modelIndex); - case MI_STUD_MAN: return GetStudentMaleTalkSfx(sound); - case MI_STUD_WOM: return GetStudentFemaleTalkSfx(sound); - case MI_CAS_MAN: return GetCasualMaleOldTalkSfx(sound); - default: return GetGenericMaleTalkSfx(sound); - } -} - -uint32 -cAudioManager::GetPlayerTalkSfx(int16 sound) -{ - uint32 sfx; - static uint32 lastSfx = NO_SAMPLE; - - switch(sound) { - case SOUND_PED_DAMAGE: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_DAMAGE_REACTION_1, 11u); - break; - - case SOUND_PED_HIT: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_HIT_REACTION_1, 10u); break; - - case SOUND_PED_LAND: GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_FALL_REACTION_1, 6u); break; - - default: sfx = NO_SAMPLE; break; - } - return sfx; -} - -uint32 -cAudioManager::GetCopTalkSfx(int16 sound) -{ - uint32 sfx; - PedState pedState; - static uint32 lastSfx = NO_SAMPLE; - - if(sound == SOUND_PED_ARREST_COP) { - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_COP_1_ARREST_1, 6u); - } else { - if(sound != SOUND_PED_PURSUIT_COP) { return GetGenericMaleTalkSfx(sound); } - - pedState = FindPlayerPed()->m_nPedState; - if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) - return NO_SAMPLE; - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_COP_1_PURSUIT_1, 7u); - } - - return 13 * (m_sQueueSample.m_nEntityIndex % 5) + sfx; -} - -uint32 -cAudioManager::GetSwatTalkSfx(int16 sound) -{ - uint32 sfx; - PedState pedState; - static uint32 lastSfx = NO_SAMPLE; - - if(sound == SOUND_PED_ARREST_SWAT) { - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_SWAT_1_PURSUIT_ARREST_1, 6u); - } else { - if(sound != SOUND_PED_PURSUIT_SWAT) { return GetGenericMaleTalkSfx(sound); } - - pedState = FindPlayerPed()->m_nPedState; - if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) - return NO_SAMPLE; - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_SWAT_1_PURSUIT_ARREST_1, 6u); - } - - return 6 * (m_sQueueSample.m_nEntityIndex % 3) + sfx; -} - -uint32 -cAudioManager::GetFBITalkSfx(int16 sound) -{ - uint32 sfx; - PedState pedState; - static uint32 lastSfx = NO_SAMPLE; - - if(sound == SOUND_PED_ARREST_FBI) { - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_FBI_1_PURSUIT_ARREST_1, 6u); - } else { - if(sound != SOUND_PED_PURSUIT_FBI) { return GetGenericMaleTalkSfx(sound); } - - pedState = FindPlayerPed()->m_nPedState; - if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) - return NO_SAMPLE; - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_FBI_1_PURSUIT_ARREST_1, 6u); - } - - return 6 * (m_sQueueSample.m_nEntityIndex % 3) + sfx; -} - -uint32 -cAudioManager::GetArmyTalkSfx(int16 sound) -{ - uint32 sfx; - PedState pedState; - static uint32 lastSfx = NO_SAMPLE; - - if(sound != SOUND_PED_PURSUIT_ARMY) { return GetGenericMaleTalkSfx(sound); } - - pedState = FindPlayerPed()->m_nPedState; - if(pedState == PED_ARRESTED || pedState == PED_DEAD || pedState == PED_DIE) - return NO_SAMPLE; - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_POLICE_ARMY_1_PURSUIT_1, 15u); - - return 15 * (m_sQueueSample.m_nEntityIndex % 1) + sfx; -} - -uint32 -cAudioManager::GetMedicTalkSfx(int16 sound) -{ - uint32 sfx; - static uint32 lastSfx = NO_SAMPLE; - - switch(sound) { - case SOUND_PED_HANDS_COWER: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_HANDS_COWER_1, 5u); - break; - case SOUND_PED_CAR_JACKED: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_CAR_JACKED_1, 5u); - break; - case SOUND_PED_HEALING: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_HEALING_1, 12u); - break; - case SOUND_PED_LEAVE_VEHICLE: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_LEAVE_VEHICLE_1, 9u); - break; - case SOUND_PED_FLEE_RUN: - GetPhrase(&sfx, &lastSfx, AUDIO_SAMPLE_PED_MEDIC_1_FLEE_RUN_1, 6u); - break; - default: return GetGenericMaleTalkSfx(sound); - } - return 37 * (m_sQueueSample.m_nEntityIndex & 1) + sfx; -} - -uint32 -cAudioManager::GetFiremanTalkSfx(int16 sound) -{ - return GetGenericMaleTalkSfx(sound); -} - -uint32 -cAudioManager::GetNormalMaleTalkSfx(int16 sound) -{ - uint32 sfx; - static uint32 lastSfx = NO_SAMPLE; + uint32 sfx; + static uint32 lastSfx = NO_SAMPLE; switch(sound) { case SOUND_PED_HANDS_COWER: @@ -3256,6 +2699,28 @@ cAudioManager::GetGenericFemaleTalkSfx(int16 sound) return sfx; } +void +cAudioManager::GenerateIntegerRandomNumberTable() +{ + for(int32 i = 0; i < 5; i++) { m_anRandomTable[i] = rand(); } +} + +char * +cAudioManager::Get3DProviderName(uint8 id) const +{ + if(!m_bIsInitialised) return 0; + if(id >= SampleManager.GetNum3DProvidersAvailable()) return 0; + return SampleManager.Get3DProviderName(id); +} + +uint8 +cAudioManager::GetCDAudioDriveLetter() const +{ + if(m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter(); + + return 0; +} + int8 cAudioManager::GetCurrent3DProviderIndex() const { @@ -3351,6 +2816,117 @@ cAudioManager::GetMissionScriptPoliceAudioPlayingStatus() const return g_nMissionAudioPlayingStatus; } +uint8 +cAudioManager::GetNum3DProvidersAvailable() const +{ + if(m_bIsInitialised) return SampleManager.GetNum3DProvidersAvailable(); + return 0; +} + + +int32 +cAudioManager::GetPedCommentSfx(CPed *ped, int32 sound) +{ + if(ped->IsPlayer()) return GetPlayerTalkSfx(sound); + + switch(ped->m_modelIndex) { + case MI_COP: return GetCopTalkSfx(sound); + case MI_SWAT: return GetSwatTalkSfx(sound); + case MI_FBI: return GetFBITalkSfx(sound); + case MI_ARMY: return GetArmyTalkSfx(sound); + case MI_MEDIC: return GetMedicTalkSfx(sound); + case MI_FIREMAN: return GetFiremanTalkSfx(sound); + case MI_MALE01: return GetNormalMaleTalkSfx(sound); + case MI_TAXI_D: return GetTaxiDriverTalkSfx(sound); + case MI_PIMP: return GetPimpTalkSfx(sound); + case MI_GANG01: + case MI_GANG02: return GetMafiaTalkSfx(sound); + case MI_GANG03: + case MI_GANG04: return GetTriadTalkSfx(sound); + case MI_GANG05: + case MI_GANG06: return GetDiabloTalkSfx(sound); + case MI_GANG07: + case MI_GANG08: return GetYakuzaTalkSfx(sound); + case MI_GANG09: + case MI_GANG10: return GetYardieTalkSfx(sound); + case MI_GANG11: + case MI_GANG12: return GetColumbianTalkSfx(sound); + case MI_GANG13: + case MI_GANG14: return GetHoodTalkSfx(sound); + case MI_CRIMINAL01: return GetBlackCriminalTalkSfx(sound); + case MI_CRIMINAL02: return GetWhiteCriminalTalkSfx(sound); + case MI_SPECIAL01: + case MI_SPECIAL02: + case MI_SPECIAL03: + case MI_SPECIAL04: return GetSpecialCharacterTalkSfx(ped->m_modelIndex, sound); + case MI_MALE02: return GetMaleNo2TalkSfx(sound); + case MI_MALE03: + case MI_P_MAN1: + case MI_P_MAN2: return GetBlackProjectMaleTalkSfx(sound, ped->m_modelIndex); + case MI_FATMALE01: return GetWhiteFatMaleTalkSfx(sound); + case MI_FATMALE02: return GetBlackFatMaleTalkSfx(sound); + case MI_FEMALE01: return GetBlackCasualFemaleTalkSfx(sound); + case MI_FEMALE02: + case MI_CAS_WOM: return GetWhiteCasualFemaleTalkSfx(sound); + case MI_FEMALE03: return GetFemaleNo3TalkSfx(sound); + case MI_FATFEMALE01: return GetBlackFatFemaleTalkSfx(sound); + case MI_FATFEMALE02: return GetWhiteFatFemaleTalkSfx(sound); + case MI_PROSTITUTE: return GetBlackFemaleProstituteTalkSfx(sound); + case MI_PROSTITUTE2: return GetWhiteFemaleProstituteTalkSfx(sound); + case MI_P_WOM1: return GetBlackProjectFemaleOldTalkSfx(sound); + case MI_P_WOM2: return GetBlackProjectFemaleYoungTalkSfx(sound); + case MI_CT_MAN1: return GetChinatownMaleOldTalkSfx(sound); + case MI_CT_MAN2: return GetChinatownMaleYoungTalkSfx(sound); + case MI_CT_WOM1: return GetChinatownFemaleOldTalkSfx(sound); + case MI_CT_WOM2: return GetChinatownFemaleYoungTalkSfx(sound); + case MI_LI_MAN1: + case MI_LI_MAN2: return GetLittleItalyMaleTalkSfx(sound); + case MI_LI_WOM1: return GetLittleItalyFemaleOldTalkSfx(sound); + case MI_LI_WOM2: return GetLittleItalyFemaleYoungTalkSfx(sound); + case MI_DOCKER1: return GetWhiteDockerMaleTalkSfx(sound); + case MI_DOCKER2: return GetBlackDockerMaleTalkSfx(sound); + case MI_SCUM_MAN: return GetScumMaleTalkSfx(sound); + case MI_SCUM_WOM: return GetScumFemaleTalkSfx(sound); + case MI_WORKER1: return GetWhiteWorkerMaleTalkSfx(sound); + case MI_WORKER2: return GetBlackWorkerMaleTalkSfx(sound); + case MI_B_MAN1: + case MI_B_MAN3: return GetBusinessMaleYoungTalkSfx(sound, ped->m_modelIndex); + case MI_B_MAN2: return GetBusinessMaleOldTalkSfx(sound); + case MI_B_WOM1: + case MI_B_WOM2: return GetWhiteBusinessFemaleTalkSfx(sound, ped->m_modelIndex); + case MI_B_WOM3: return GetBlackBusinessFemaleTalkSfx(sound); + case MI_MOD_MAN: return GetSupermodelMaleTalkSfx(sound); + case MI_MOD_WOM: return GetSupermodelFemaleTalkSfx(sound); + case MI_ST_MAN: return GetStewardMaleTalkSfx(sound); + case MI_ST_WOM: return GetStewardFemaleTalkSfx(sound); + case MI_FAN_MAN1: + case MI_FAN_MAN2: return GetFanMaleTalkSfx(sound, ped->m_modelIndex); + case MI_FAN_WOM: return GetFanFemaleTalkSfx(sound); + case MI_HOS_MAN: return GetHospitalMaleTalkSfx(sound); + case MI_HOS_WOM: return GetHospitalFemaleTalkSfx(sound); + case MI_CONST1: return GetWhiteConstructionWorkerTalkSfx(sound); + case MI_CONST2: return GetBlackConstructionWorkerTalkSfx(sound); + case MI_SHOPPER1: + case MI_SHOPPER2: + case MI_SHOPPER3: return GetShopperFemaleTalkSfx(sound, ped->m_modelIndex); + case MI_STUD_MAN: return GetStudentMaleTalkSfx(sound); + case MI_STUD_WOM: return GetStudentFemaleTalkSfx(sound); + case MI_CAS_MAN: return GetCasualMaleOldTalkSfx(sound); + default: return GetGenericMaleTalkSfx(sound); + } +} + +void +cAudioManager::GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const +{ + *phrase = sample + m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] % maxOffset; + + // check if the same sfx like last time, if yes, then try use next one, + // if exceeded range, then choose first available sample + if(*phrase == *prevPhrase && ++*phrase >= sample + maxOffset) *phrase = sample; + *prevPhrase = *phrase; +} + bool cAudioManager::HasAirBrakes(int32 model) const { @@ -3402,6 +2978,12 @@ cAudioManager::InterrogateAudioEntities() } } +bool +cAudioManager::IsAudioInitialised() const +{ + return m_bIsInitialised; +} + bool cAudioManager::IsMissionAudioSampleFinished() { @@ -3412,6 +2994,14 @@ cAudioManager::IsMissionAudioSampleFinished() return (cPretendFrame++ & 63) == 0; } +bool +cAudioManager::IsMP3RadioChannelAvailable() const +{ + if(m_bIsInitialised) return SampleManager.IsMP3RadioChannelAvailable(); + + return 0; +} + bool cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) const { @@ -3448,8 +3038,6 @@ cAudioManager::PlayOneShot(int32 index, int16 sound, float vol) EAXJMP(0x57A500); } -bool &bPlayerJustEnteredCar = *(bool *)0x6508C4; - void cAudioManager::PlayerJustGotInCar() const { @@ -3479,10 +3067,10 @@ cAudioManager::PostInitialiseGameSpecificSetup() m_nProjectileEntity = CreateEntity(AUDIOTYPE_PROJECTILE, (CPhysical *)1); if(m_nProjectileEntity >= 0) SetEntityStatus(m_nProjectileEntity, 1); - m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATER_CANNON, (CPhysical *)1); + m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATERCANNON, (CPhysical *)1); if(m_nWaterCannonEntity >= 0) SetEntityStatus(m_nWaterCannonEntity, 1); - m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_D, (CPhysical *)1); + m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (CPhysical *)1); if(m_nPoliceChannelEntity >= 0) SetEntityStatus(m_nPoliceChannelEntity, 1); m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (CPhysical *)1); @@ -3504,6 +3092,14 @@ cAudioManager::PostTerminateGameSpecificShutdown() ; } + +void +cAudioManager::PreInitialiseGameSpecificSetup() const +{ + BankStartOffset[0] = AUDIO_SAMPLE_VEHICLE_HORN_0; + BankStartOffset[1] = AUDIO_SAMPLE_POLICE_COP_1_ARREST_1; +} + void cAudioManager::PreTerminateGameSpecificShutdown() { @@ -3818,7 +3414,7 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams *params) velocityChange = Abs(params->m_fVelocityChange); if(velocityChange <= 0.0005f && params->m_pVehicle->GetPosition().y) return 1; - velocityChange = Min(0.75f, velocityChange); + velocityChange = min(0.75f, velocityChange); multiplier = (velocityChange - 0.0005f) * 1.3342f; CalculateDistance((bool *)params, params->m_fDistance); vol = (30.f * multiplier); @@ -5556,8 +5152,6 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) } } -bool &g_bMissionAudioLoadFailed = *(bool *)0x95CD8E; - void cAudioManager::ProcessMissionAudio() { @@ -5571,9 +5165,9 @@ cAudioManager::ProcessMissionAudio() static uint8 nFramesUntilFailedLoad = 0; static uint8 nFramesForPretendPlaying = 0; - if(this->m_bIsInitialised) { + if(m_bIsInitialised) { if(m_sMissionAudio.m_nSampleIndex != 3033) { - switch(this->m_sMissionAudio.m_bLoadingStatus) { + switch(m_sMissionAudio.m_bLoadingStatus) { case 0: SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex, 1u); @@ -5581,9 +5175,9 @@ cAudioManager::ProcessMissionAudio() nFramesUntilFailedLoad = 0; return; case 1: - if(!this->m_sMissionAudio.m_bIsPlayed) return; + if(!m_sMissionAudio.m_bIsPlayed) return; if(g_bMissionAudioLoadFailed) { - if(this->m_bTimerJustReset) { + if(m_bTimerJustReset) { ClearMissionAudio(); SampleManager.StopStreamedFile(1u); nFramesForPretendPlaying = 0; @@ -5591,16 +5185,16 @@ cAudioManager::ProcessMissionAudio() nFramesUntilFailedLoad = 0; } else if(!m_bUserPause) { if(++nFramesForPretendPlaying < 120u) { - this->m_sMissionAudio.m_bPlayStatus = 1; + m_sMissionAudio.m_bPlayStatus = 1; } else { - this->m_sMissionAudio.m_bPlayStatus = 2; - this->m_sMissionAudio.m_nSampleIndex = 3033; + m_sMissionAudio.m_bPlayStatus = 2; + m_sMissionAudio.m_nSampleIndex = 3033; } } } else { if(m_sMissionAudio.m_bPlayStatus) { if(m_sMissionAudio.m_bPlayStatus != 1) return; - if(this->m_bTimerJustReset) { + if(m_bTimerJustReset) { ClearMissionAudio(); SampleManager.StopStreamedFile(1u); return; @@ -5696,7 +5290,7 @@ cAudioManager::ProcessMissionAudio() nFramesForPretendPlaying = 0; g_bMissionAudioLoadFailed = 1; nFramesUntilFailedLoad = 0; - this->m_sMissionAudio.m_bLoadingStatus = 1; + m_sMissionAudio.m_bLoadingStatus = 1; } return; default: return; @@ -6072,7 +5666,7 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params) if(params->m_fDistance < 49.f) { ped = params->m_pPed; - if(!(ped->m_ped_flagA20) || ped->m_bodyPartBleeding != 2) { + if(!ped->bIsAimingGun || ped->m_bodyPartBleeding != 2) { CalculateDistance((bool *)params, params->m_fDistance); if(ped->bInVehicle && ped->m_nPedState == PED_DRIVING) { emittingVol = 10; @@ -7121,7 +6715,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * CurrentPretendGear = 1; } if(CReplay::IsPlayingBack()) { - accelerateState = 255.f * Max(0.0f, Min(1.0f, automobile->m_fGasPedal)); + accelerateState = 255.f * max(0.0f, min(1.0f, automobile->m_fGasPedal)); } else { accelerateState = Pads->GetAccelerate(); } @@ -7156,9 +6750,9 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * if(0.0f != velocityChange) { time = params->m_pVehicle->m_vecMoveSpeed.z / velocityChange; if(time <= 0.0f) { - freqModifier = Max(-0.2f, time) * -15000.f; + freqModifier = max(-0.2f, time) * -15000.f; } else { - freqModifier = -(Min(0.2f, time) * 15000.f); + freqModifier = -(min(0.2f, time) * 15000.f); } if(params->m_fVelocityChange < -0.001f) freqModifier = -freqModifier; } else { @@ -7177,10 +6771,10 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * gasPedalAudio = automobile->m_fGasPedalAudio; } else { gasPedalAudio = - Min(1.0f, params->m_fVelocityChange / + min(1.0f, params->m_fVelocityChange / params->m_pTransmission->fMaxReverseVelocity); } - gasPedalAudio = Max(0.0f, gasPedalAudio); + gasPedalAudio = max(0.0f, gasPedalAudio); automobile->m_fGasPedalAudio = gasPedalAudio; } else if(LastAccel > 0) { if(channelUsed) { @@ -7210,7 +6804,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * (engineSoundType + AUDIO_SAMPLE_VEHICLE_ENGINE_IDLE_NONE), 0, 52u, 1); - CurrentPretendGear = Max(1, currentGear); + CurrentPretendGear = max(1, currentGear); LastAccel = accelerateState; bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn; @@ -7665,11 +7259,11 @@ cAudioManager::ProcessScriptObject(int32 id) { cAudioScriptObject *entity = (cAudioScriptObject *)m_asAudioEntities[id].m_pEntity; if(entity) { - m_sQueueSample.m_vecPos = entity->m_vecPos; + m_sQueueSample.m_vecPos = entity->Posn; if(m_asAudioEntities[id].m_Loops == 1) ProcessOneShotScriptObject(m_asAudioEntities[id].m_awAudioEvent[0]); else - ProcessLoopingScriptObject(entity->m_wSound); + ProcessLoopingScriptObject(entity->AudioId); } } @@ -7778,7 +7372,7 @@ cAudioManager::ProcessTrainNoise(cVehicleParams *params) if(params->m_fVelocityChange <= 0.0f) { CalculateDistance((bool *)params, params->m_fDistance); train = (CTrain *)params->m_pVehicle; - speedMultipler = Min(1.0f, train->m_fSpeed * 250.f / 51.f); + speedMultipler = min(1.0f, train->m_fSpeed * 250.f / 51.f); emittingVol = (75.f * speedMultipler); if(train->m_fWagonPosition == 0.0f) { m_sQueueSample.m_bVolume = @@ -7871,7 +7465,7 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams *params) if(automobile->Damage.GetDoorStatus(i) == 2) { doorState = automobile->Doors[i].m_nDoorState; if(doorState == 1 || doorState == 2) { - velocity = Min(0.3f, Abs(automobile->Doors[i].m_fAngVel)); + velocity = min(0.3f, Abs(automobile->Doors[i].m_fAngVel)); if(velocity > 0.0035f) { emittingVol = (100.f * velocity * 10.f / 3.f); m_sQueueSample.m_bVolume = ComputeVolume( @@ -7941,51 +7535,167 @@ cAudioManager::ProcessVehicleReverseWarning(cVehicleParams *params) AddSampleToRequestedQueue(); } } - return 1; + return 1; +} + +bool +cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) +{ + int32 emittingVol; + uint32 freq; + float modificator; + int sampleFreq; + float velocity; + + if(params->m_fDistance >= 9025.f) return 0; + if(params->m_pTransmission) { + if(params->m_pVehicle->m_vecMoveSpeed.z) { + velocity = Abs(params->m_fVelocityChange); + if(velocity > 0.0f) { + CalculateDistance((bool *)params, params->m_fDistance); + emittingVol = + 30.f * + min(1.f, + velocity / (0.5f * params->m_pTransmission->fMaxVelocity)); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, 95.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 0; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 3; + if(params->m_pVehicle->m_nSurfaceTouched == + SURFACE_PUDDLE) { + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_LOOPING_WATER; + freq = 6050 * emittingVol / 30 + 16000; + } else { + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; + modificator = + m_sQueueSample.m_fDistance * 1.f / 95.f * 0.5f; + sampleFreq = SampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); + freq = (sampleFreq * modificator) + + ((3 * sampleFreq) >> 2); + } + m_sQueueSample.m_nFrequency = freq; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset( + m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 6.0f; + m_sQueueSample.m_fSoundIntensity = 95.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 4; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } + } + } + return 1; +} + +WRAPPER +void cAudioManager::ProcessWaterCannon(int32) { EAXJMP(0x575F30); } + +void +cAudioManager::ProcessWeather(int32 id) +{ + uint8 vol; + static uint8 counter = 0; + + if(m_asAudioEntities[id].m_Loops && + m_asAudioEntities[id].m_awAudioEvent[0] == SOUND_LIGHTNING) { + if(m_asAudioEntities[id].m_afVolume[0] >= 10.f) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_EXPLOSION_CAR; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = RandomDisplacement(500u) + 4000; + vol = (m_asAudioEntities[id].m_afVolume[0] - 10.f) + 40; + } else { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WEAPON_GRENADE_EXPLOSION; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = RandomDisplacement(500u) + 4000; + vol = (m_asAudioEntities[id].m_afVolume[0]) + 35; + } + m_sQueueSample.m_bVolume = vol; + if(TheCamera.SoundDistUp < 20.f) m_sQueueSample.m_bVolume >>= 1; + if(counter == 4) counter = 0; + m_sQueueSample.m_counter = counter++; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bOffset = (m_anRandomTable[2] & 15) + 55; + m_sQueueSample.m_bIsDistant = 1; + m_sQueueSample.m_nLoopCount = 1; + m_sQueueSample.field_56 = 1; + m_sQueueSample.m_bEmittingVolume = m_sQueueSample.m_bVolume; + m_sQueueSample.m_nLoopStart = 0; + m_sQueueSample.m_nLoopEnd = -1; + m_sQueueSample.m_bReverbFlag = 0; + m_sQueueSample.m_bRequireReflection = 0; + cAudioManager::AddSampleToRequestedQueue(); + } + if(CWeather::Rain > 0.0f && (!CCullZones::CamNoRain() || !CCullZones::PlayerNoRain())) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_COLLISION_LOOPING_GRASS; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_COLLISION_LOOPING_GRASS); + m_sQueueSample.m_bVolume = (uint8)(25.f * CWeather::Rain); + m_sQueueSample.m_counter = 4; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.field_16 = 0; + m_sQueueSample.m_bOffset = 63; + m_sQueueSample.m_bIsDistant = 1; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 30; + m_sQueueSample.m_bReverbFlag = 0; + m_sQueueSample.m_bEmittingVolume = m_sQueueSample.m_bVolume; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_bRequireReflection = 0; + cAudioManager::AddSampleToRequestedQueue(); + } } bool -cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) +cAudioManager::ProcessWetRoadNoise(cVehicleParams *params) { + float relativeVelocity; int32 emittingVol; - uint32 freq; float modificator; - int sampleFreq; - float velocity; + int freq; + float velChange; - if(params->m_fDistance >= 9025.f) return 0; + if(params->m_fDistance >= 900.f) return 0; if(params->m_pTransmission) { if(params->m_pVehicle->m_vecMoveSpeed.z) { - velocity = Abs(params->m_fVelocityChange); - if(velocity > 0.0f) { + velChange = Abs(params->m_fVelocityChange); + if(velChange > 0.f) { CalculateDistance((bool *)params, params->m_fDistance); - emittingVol = - 30.f * - Min(1.f, - velocity / (0.5f * params->m_pTransmission->fMaxVelocity)); + relativeVelocity = + min(1.0f, + velChange / (0.5f * params->m_pTransmission->fMaxVelocity)); + emittingVol = 23.0f * relativeVelocity * CWeather::WetRoads; m_sQueueSample.m_bVolume = - ComputeVolume(emittingVol, 95.f, m_sQueueSample.m_fDistance); + ComputeVolume(emittingVol, 30.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_counter = 0; + m_sQueueSample.m_counter = 1; + m_sQueueSample.m_nSampleIndex = + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; m_sQueueSample.m_bBankIndex = 0; m_sQueueSample.m_bIsDistant = 0; m_sQueueSample.field_16 = 3; - if(params->m_pVehicle->m_nSurfaceTouched == - SURFACE_PUDDLE) { - m_sQueueSample.m_nSampleIndex = - AUDIO_SAMPLE_LOOPING_WATER; - freq = 6050 * emittingVol / 30 + 16000; - } else { - m_sQueueSample.m_nSampleIndex = - AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; - modificator = - m_sQueueSample.m_fDistance * 1.f / 95.f * 0.5f; - sampleFreq = SampleManager.GetSampleBaseFrequency( - AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); - freq = (sampleFreq * modificator) + - ((3 * sampleFreq) >> 2); - } - m_sQueueSample.m_nFrequency = freq; + modificator = m_sQueueSample.m_fDistance * 1.f / 3.f * 0.5f; + freq = SampleManager.GetSampleBaseFrequency( + AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); + m_sQueueSample.m_nFrequency = freq + freq * modificator; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_bEmittingVolume = emittingVol; m_sQueueSample.m_nLoopStart = @@ -7995,7 +7705,7 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) SampleManager.GetSampleLoopEndOffset( m_sQueueSample.m_nSampleIndex); m_sQueueSample.field_48 = 6.0f; - m_sQueueSample.m_fSoundIntensity = 95.0f; + m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 4; m_sQueueSample.m_bReverbFlag = 1; @@ -8008,110 +7718,326 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) return 1; } -WRAPPER -void cAudioManager::ProcessWaterCannon(int32) { EAXJMP(0x575F30); } - -WRAPPER -void -cAudioManager::ProcessWeather(int32 id) +void +cAudioManager::ProcessWorkShopScriptObject(uint8 sound) +{ + float distSquared; + float maxDist; + + switch(sound) { + case SCRIPT_SOUND_WORK_SHOP_LOOP_S: + case SCRIPT_SOUND_WORK_SHOP_LOOP_L: + maxDist = 400.f; + m_sQueueSample.m_fSoundIntensity = 20.0f; + break; + default: break; + } + distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); + if(distSquared < maxDist) { + m_sQueueSample.m_fDistance = sqrt(distSquared); + m_sQueueSample.m_bVolume = ComputeVolume(30u, m_sQueueSample.m_fSoundIntensity, + m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WORK_SHOP; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_WORK_SHOP); + m_sQueueSample.m_counter = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_16 = 5; + m_sQueueSample.field_48 = 2.0f; + m_sQueueSample.m_bEmittingVolume = 30; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + } + } +} + +int32 +cAudioManager::RandomDisplacement(uint32 seed) const +{ + int32 value; + + static bool bIsEven = true; + static uint32 base = 0; + + if(!seed) return 0; + + value = m_anRandomTable[(base + seed) % 5] % seed; + base += value; + + if(value % 2) { bIsEven = !bIsEven; } + if(!bIsEven) value = -value; + return value; +} + +void +cAudioManager::ReacquireDigitalHandle() const +{ + if(m_bIsInitialised) { SampleManager.ReacquireDigitalHandle(); } +} + +void +cAudioManager::ReleaseDigitalHandle() const +{ + if(m_bIsInitialised) { SampleManager.ReleaseDigitalHandle(); } +} + +void +cAudioManager::ResetAudioLogicTimers(int32 timer) +{ + audioLogicTimers[0] = timer; + audioLogicTimers[8] = timer; + audioLogicTimers[1] = timer; + audioLogicTimers[7] = timer; + audioLogicTimers[2] = timer; + audioLogicTimers[6] = timer; + audioLogicTimers[3] = timer; + audioLogicTimers[5] = timer; + audioLogicTimers[4] = timer; + for(int32 i = 0; i < m_nAudioEntitiesTotal; i++) { + if(m_asAudioEntities[m_anAudioEntityIndices[i]].m_nType == AUDIOTYPE_PHYSICAL) { + CPed *ped = (CPed *)m_asAudioEntities[m_anAudioEntityIndices[i]].m_pEntity; + if(ped->IsPed()) { + ped->m_lastSoundStart = timer; + ped->m_soundStart = timer + m_anRandomTable[0] % 3000u; + } + } + } + ClearMissionAudio(); + SampleManager.StopChannel(28); +} + +void +cAudioManager::ResetPoliceRadio() +{ + if(m_bIsInitialised) { + if(SampleManager.GetChannelUsedFlag(28)) SampleManager.StopChannel(28); + InitialisePoliceRadio(); + } +} + +WRAPPER void +cAudioManager::Service() +{ + EAXJMP(0x57A2A0); +} + + +void +cAudioManager::SetDynamicAcousticModelingStatus(bool status) +{ + m_bDynamicAcousticModelingStatus = status; +} + +void +cAudioManager::SetEffectsFadeVolume(uint8 volume) const +{ + SampleManager.SetEffectsFadeVolume(volume); +} + +void +cAudioManager::SetEffectsMasterVolume(uint8 volume) const +{ + SampleManager.SetEffectsMasterVolume(volume); +} + +void +cAudioManager::SetEntityStatus(int32 id, bool status) +{ + if(m_bIsInitialised && id >= 0 && id < totalAudioEntitiesSlots) { + if(m_asAudioEntities[id].m_bIsUsed) { m_asAudioEntities[id].m_bStatus = status; } + } +} + +void +cAudioManager::SetMissionAudioLocation(float x, float y, float z) +{ + if(m_bIsInitialised) { + m_sMissionAudio.field_12 = 0; + m_sMissionAudio.m_vecPos.x = x; + m_sMissionAudio.m_vecPos.y = y; + m_sMissionAudio.m_vecPos.z = z; + } +} + +void +cAudioManager::SetMissionScriptPoliceAudio(int32 sfx) const +{ + if(m_bIsInitialised) { + if(g_nMissionAudioPlayingStatus != 1) { + g_nMissionAudioPlayingStatus = 0; + g_nMissionAudioSfx = sfx; + } + } +} + +void +cAudioManager::SetMusicFadeVolume(uint8 volume) const +{ + SampleManager.SetMusicFadeVolume(volume); +} + +void +cAudioManager::SetMusicMasterVolume(uint8 volume) const +{ + SampleManager.SetMusicMasterVolume(volume); +} + + +void +cAudioManager::SetSpeakerConfig(int32 conf) const +{ + SampleManager.SetSpeakerConfig(conf); +} + +WRAPPER +bool cAudioManager::SetupJumboEngineSound(uint8, int32) { EAXJMP(0x56F140); } + +bool +cAudioManager::SetupJumboFlySound(uint8 emittingVol) +{ + int32 vol; + + if(m_sQueueSample.m_fDistance >= 440.0f) return 0; + + vol = ComputeVolume(emittingVol, 440.0f, m_sQueueSample.m_fDistance); + m_sQueueSample.m_bVolume = vol; + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_FLY_SOUND; + m_sQueueSample.m_counter = 0; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_JUMBO_FLY_SOUND); + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_fSoundIntensity = 440.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.field_76 = 5; + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + AddSampleToRequestedQueue(); + } + return 1; +} + +bool +cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) { - EAXJMP(0x578370); + if(m_sQueueSample.m_fDistance >= 240.f) return 0; + + m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 240.f, m_sQueueSample.m_fDistance); + + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 5; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 1; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 240.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 12; + m_sQueueSample.m_bOffset = 0; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + m_sQueueSample.m_counter = 6; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_RUMBLE_SOUND; + m_sQueueSample.m_nFrequency += 200; + m_sQueueSample.m_bOffset = maxVolume; + AddSampleToRequestedQueue(); + } + return 1; } bool -cAudioManager::ProcessWetRoadNoise(cVehicleParams *params) +cAudioManager::SetupJumboTaxiSound(uint8 vol) { - float relativeVelocity; - int32 emittingVol; - float modificator; - int freq; - float velChange; + uint8 emittingVol; - if(params->m_fDistance >= 900.f) return 0; - if(params->m_pTransmission) { - if(params->m_pVehicle->m_vecMoveSpeed.z) { - velChange = Abs(params->m_fVelocityChange); - if(velChange > 0.f) { - CalculateDistance((bool *)params, params->m_fDistance); - relativeVelocity = - Min(1.0f, - velChange / (0.5f * params->m_pTransmission->fMaxVelocity)); - emittingVol = 23.0f * relativeVelocity * CWeather::WetRoads; - m_sQueueSample.m_bVolume = - ComputeVolume(emittingVol, 30.f, m_sQueueSample.m_fDistance); - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_counter = 1; - m_sQueueSample.m_nSampleIndex = - AUDIO_SAMPLE_VEHICLE_ROAD_NOISE; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_bIsDistant = 0; - m_sQueueSample.field_16 = 3; - modificator = m_sQueueSample.m_fDistance * 1.f / 3.f * 0.5f; - freq = SampleManager.GetSampleBaseFrequency( - AUDIO_SAMPLE_VEHICLE_ROAD_NOISE); - m_sQueueSample.m_nFrequency = freq + freq * modificator; - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset( - m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset( - m_sQueueSample.m_nSampleIndex); - m_sQueueSample.field_48 = 6.0f; - m_sQueueSample.m_fSoundIntensity = 30.0f; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_76 = 4; - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.m_bRequireReflection = 0; - AddSampleToRequestedQueue(); - } - } - } + if(m_sQueueSample.m_fDistance >= 180.f) return 0; + + emittingVol = (vol >> 1) + ((vol >> 1) * m_sQueueSample.m_fDistance * 0.0055556f); + + if(m_sQueueSample.m_fDistance * 0.0055556f < 0.7f) + emittingVol -= emittingVol * gJumboVolOffsetPercentage / 100; + m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 180.f, m_sQueueSample.m_fDistance); + + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 1; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_TAXI_SOUND; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nFrequency = GetJumboTaxiFreq(); + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 180.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 4; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); } return 1; } -void -cAudioManager::ProcessWorkShopScriptObject(uint8 sound) +bool +cAudioManager::SetupJumboWhineSound(uint8 emittingVol, int32 freq) { - float distSquared; - float maxDist; + if(m_sQueueSample.m_fDistance >= 170.f) return 0; - switch(sound) { - case SCRIPT_SOUND_WORK_SHOP_LOOP_S: - case SCRIPT_SOUND_WORK_SHOP_LOOP_L: - maxDist = 400.f; - m_sQueueSample.m_fSoundIntensity = 20.0f; - break; - default: break; - } - distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); - if(distSquared < maxDist) { - m_sQueueSample.m_fDistance = sqrt(distSquared); - m_sQueueSample.m_bVolume = ComputeVolume(30u, m_sQueueSample.m_fSoundIntensity, - m_sQueueSample.m_fDistance); - if(m_sQueueSample.m_bVolume) { - m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_WORK_SHOP; - m_sQueueSample.m_bBankIndex = 0; - m_sQueueSample.m_nFrequency = - SampleManager.GetSampleBaseFrequency(AUDIO_SAMPLE_WORK_SHOP); - m_sQueueSample.m_counter = 0; - m_sQueueSample.m_bIsDistant = 0; - m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.field_56 = 0; - m_sQueueSample.field_16 = 5; - m_sQueueSample.field_48 = 2.0f; - m_sQueueSample.m_bEmittingVolume = 30; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = 1; - m_sQueueSample.m_bRequireReflection = 0; - AddSampleToRequestedQueue(); - } + m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 170.f, m_sQueueSample.m_fDistance); + + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 2; + m_sQueueSample.m_nSampleIndex = AUDIO_SAMPLE_JUMBO_WHINE_SOUND; + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nFrequency = freq; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = emittingVol; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = + SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 4.0f; + m_sQueueSample.m_fSoundIntensity = 170.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 4; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); } + return 1; } void @@ -8240,69 +8166,105 @@ cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) } } -WRAPPER void -cAudioManager::Service() +void +cAudioManager::Terminate() { - EAXJMP(0x57A2A0); -} + if(m_bIsInitialised) { + MusicManager.Terminate(); -WRAPPER void cAudioManager::PlayOneShot(int, unsigned short, float) -{ - EAXJMP(0x57A500); -} + for(uint32 i = 0; i < totalAudioEntitiesSlots; i++) { + m_asAudioEntities[i].m_bIsUsed = 0; + m_anAudioEntityIndices[i] = 200; + } -WRAPPER void cAudioManager::SetEffectsFadeVol(unsigned char) -{ - EAXJMP(0x57A770); -} + m_nAudioEntitiesTotal = 0; + m_nScriptObjectEntityTotal = 0; + PreTerminateGameSpecificShutdown(); -WRAPPER void cAudioManager::SetMusicFadeVol(unsigned char) -{ - EAXJMP(0x57A790); -} + for(uint32 i = 0; i < 2; i++) { + if(SampleManager.IsSampleBankLoaded(i)) SampleManager.UnloadSampleBank(i); + } -WRAPPER int8 cAudioManager::SetCurrent3DProvider(unsigned char) -{ - EAXJMP(0x57A910); + SampleManager.Terminate(); + + m_bIsInitialised = 0; + PostTerminateGameSpecificShutdown(); + } } -WRAPPER void cAudioManager::ReportCrime(eCrimeType, CVector const &) +void +cAudioManager::TranslateEntity(CVector *v1, CVector *v2) const { - EAXJMP(0x5803D0); + const RwMatrix &cM = TheCamera.GetMatrix().m_matrix; + const CVector &cV = TheCamera.GetPosition(); + + float a = v1->z - cV.z; + float b = v1->y - cV.y; + float c = v1->x - cV.x; + + v2->x = cM.right.y * b + cM.right.x * c + cM.right.z * a; + v2->y = cM.up.y * b + cM.up.x * c + cM.up.z * a; + v2->z = cM.at.y * b + cM.at.x * c + cM.at.z * a; } -WRAPPER void cAudioManager::PlaySuspectLastSeen(float, float, float) +void +cAudioManager::UpdateGasPedalAudio(CAutomobile *automobile) { - EAXJMP(0x580500); + float newGasPedalAudio; + + float gasPedal = Abs(automobile->m_fGasPedal); + float gasPedalAudio = automobile->m_fGasPedalAudio; + + if(gasPedalAudio < gasPedal) { + newGasPedalAudio = gasPedalAudio + 0.09f; + if(gasPedal <= newGasPedalAudio) newGasPedalAudio = gasPedal; + } else { + newGasPedalAudio = gasPedalAudio - 0.07f; + if(gasPedal >= newGasPedalAudio) newGasPedalAudio = gasPedal; + } + automobile->m_fGasPedalAudio = newGasPedalAudio; } -WRAPPER void cAudioManager::ReportCollision(CEntity *, CEntity *, unsigned char, unsigned char, float, float) +bool +cAudioManager::UsesReverseWarning(int32 model) const { - EAXJMP(0x568410); + return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || + model == COACH; } -WRAPPER void cAudioManager::ResetTimers(unsigned int) +bool +cAudioManager::UsesSiren(int32 model) const { - EAXJMP(0x57A7B0); + switch(model) { + case FIRETRUK: + case AMBULAN: + case FBICAR: + case POLICE: + case ENFORCER: + case PREDATOR: return true; + default: return false; + } } -WRAPPER void cAudioManager::PreloadMissionAudio(char *) +bool +cAudioManager::UsesSirenSwitching(int32 model) const { - EAXJMP(0x579550); + switch(model) { + case AMBULAN: + case POLICE: + case ENFORCER: + case PREDATOR: return true; + default: return false; + } } STARTPATCHES -InjectHook(0x5755C0, &cPedComments::Add, PATCH_JUMP); -InjectHook(0x575730, &cPedComments::Process, PATCH_JUMP); - InjectHook(0x57B210, &cAudioManager::AddDetailsToRequestedOrderList, PATCH_JUMP); InjectHook(0x56AD30, &cAudioManager::AddPlayerCarSample, PATCH_JUMP); InjectHook(0x57B300, &cAudioManager::AddReflectionsToRequestedQueue, PATCH_JUMP); // InjectHook(0x57B8D0, &cAudioManager::AddReleasingSounds, PATCH_JUMP); InjectHook(0x57B070, &cAudioManager::AddSampleToRequestedQueue, PATCH_JUMP); -InjectHook(0x57A8F0, &cAudioManager::GetCurrent3DProviderIndex, PATCH_JUMP); // InjectHook(0x580AF0, &cAudioManager::AgeCrimes, PATCH_JUMP); - InjectHook(0x5697A0, &cAudioManager::CalculateDistance, PATCH_JUMP); InjectHook(0x57AA10, &cAudioManager::CheckForAnAudioFileOnCD, PATCH_JUMP); InjectHook(0x5796A0, &cAudioManager::ClearMissionAudio, PATCH_JUMP); @@ -8310,162 +8272,111 @@ InjectHook(0x57C120, &cAudioManager::ClearRequestedQueue, PATCH_JUMP); InjectHook(0x57AE00, &cAudioManager::ComputeDopplerEffectedFrequency, PATCH_JUMP); InjectHook(0x57ABB0, &cAudioManager::ComputeVolume, PATCH_JUMP); InjectHook(0x57A310, &cAudioManager::CreateEntity, PATCH_JUMP); - InjectHook(0x57A830, &cAudioManager::DestroyAllGameCreatedEntities, PATCH_JUMP); InjectHook(0x57A400, &cAudioManager::DestroyEntity, PATCH_JUMP); InjectHook(0x57F060, &cAudioManager::DoPoliceRadioCrackle, PATCH_JUMP); - InjectHook(0x57C290, &cAudioManager::GenerateIntegerRandomNumberTable, PATCH_JUMP); -InjectHook(0x569750, &cAudioManager::GetDistanceSquared, PATCH_JUMP); -InjectHook(0x57AC60, &cAudioManager::TranslateEntity, PATCH_JUMP); - -InjectHook(0x57A0E0, &cAudioManager::Initialise, PATCH_JUMP); -InjectHook(0x569420, &cAudioManager::PostInitialiseGameSpecificSetup, PATCH_JUMP); -// InjectHook(0x57EAC0, &cAudioManager::InitialisePoliceRadioZones, PATCH_JUMP); -InjectHook(0x569650, &cAudioManager::ResetAudioLogicTimers, PATCH_JUMP); -InjectHook(0x57A150, &cAudioManager::Terminate, PATCH_JUMP); - -InjectHook(0x57F050, &cAudioManager::GetMissionScriptPoliceAudioPlayingStatus, PATCH_JUMP); -InjectHook(0x5795D0, &cAudioManager::GetMissionAudioLoadingStatus, PATCH_JUMP); - -InjectHook(0x57A8A0, &cAudioManager::GetNum3DProvidersAvailable, PATCH_JUMP); -InjectHook(0x57A9C0, &cAudioManager::IsMP3RadioChannelAvailable, PATCH_JUMP); -InjectHook(0x57AA30, &cAudioManager::GetCDAudioDriveLetter, PATCH_JUMP); - -InjectHook(0x57A730, &cAudioManager::SetEffectsMasterVolume, PATCH_JUMP); -InjectHook(0x57A750, &cAudioManager::SetMusicMasterVolume, PATCH_JUMP); -InjectHook(0x57A770, &cAudioManager::SetEffectsFadeVolume, PATCH_JUMP); -InjectHook(0x57A790, &cAudioManager::SetMusicFadeVolume, PATCH_JUMP); - -InjectHook(0x57A9A0, &cAudioManager::SetSpeakerConfig, PATCH_JUMP); - -InjectHook(0x569400, &cAudioManager::PreInitialiseGameSpecificSetup, PATCH_JUMP); - -InjectHook(0x57F020, &cAudioManager::SetMissionScriptPoliceAudio, PATCH_JUMP); - -InjectHook(0x56C3C0, &cAudioManager::UsesSiren, PATCH_JUMP); -InjectHook(0x56C3F0, &cAudioManager::UsesSirenSwitching, PATCH_JUMP); - -InjectHook(0x579520, &cAudioManager::MissionScriptAudioUsesPoliceChannel, PATCH_JUMP); - InjectHook(0x57A8C0, &cAudioManager::Get3DProviderName, PATCH_JUMP); -InjectHook(0x56F230, &cAudioManager::SetupJumboFlySound, PATCH_JUMP); -InjectHook(0x56F310, &cAudioManager::SetupJumboRumbleSound, PATCH_JUMP); -InjectHook(0x56EF20, &cAudioManager::SetupJumboTaxiSound, PATCH_JUMP); -InjectHook(0x56F070, &cAudioManager::SetupJumboWhineSound, PATCH_JUMP); - -InjectHook(0x579620, &cAudioManager::PlayLoadedMissionAudio, PATCH_JUMP); - -InjectHook(0x5795F0, &cAudioManager::SetMissionAudioLocation, PATCH_JUMP); - -InjectHook(0x57EFF0, &cAudioManager::ResetPoliceRadio, PATCH_JUMP); - -InjectHook(0x57B030, &cAudioManager::InterrogateAudioEntities, PATCH_JUMP); - -InjectHook(0x56C600, &cAudioManager::UsesReverseWarning, PATCH_JUMP); -InjectHook(0x56CAB0, &cAudioManager::HasAirBrakes, PATCH_JUMP); - -InjectHook(0x56F410, &cAudioManager::GetJumboTaxiFreq, PATCH_JUMP); - -InjectHook(0x579650, &cAudioManager::IsMissionAudioSampleFinished, PATCH_JUMP); -InjectHook(0x57AF90, &cAudioManager::RandomDisplacement, PATCH_JUMP); - -InjectHook(0x57A9E0, &cAudioManager::ReleaseDigitalHandle, PATCH_JUMP); -InjectHook(0x57A9F0, &cAudioManager::ReacquireDigitalHandle, PATCH_JUMP); -InjectHook(0x57AA00, &cAudioManager::SetDynamicAcousticModelingStatus, PATCH_JUMP); - -InjectHook(0x57AA50, &cAudioManager::IsAudioInitialised, PATCH_JUMP); - -InjectHook(0x57A4C0, &cAudioManager::SetEntityStatus, PATCH_JUMP); - -InjectHook(0x569570, &cAudioManager::PreTerminateGameSpecificShutdown, PATCH_JUMP); -InjectHook(0x569640, &cAudioManager::PostTerminateGameSpecificShutdown, PATCH_JUMP); - -InjectHook(0x56AD10, &cAudioManager::PlayerJustGotInCar, PATCH_JUMP); -InjectHook(0x56AD20, &cAudioManager::PlayerJustLeftCar, PATCH_JUMP); -InjectHook(0x570DB0, &cAudioManager::GetPhrase, PATCH_JUMP); - -// Get ped sfx stuff -InjectHook(0x570960, &cAudioManager::GetPedCommentSfx, PATCH_JUMP); - -InjectHook(0x570E00, &cAudioManager::GetPlayerTalkSfx, PATCH_JUMP); -InjectHook(0x570EA0, &cAudioManager::GetCopTalkSfx, PATCH_JUMP); -InjectHook(0x570F80, &cAudioManager::GetSwatTalkSfx, PATCH_JUMP); -InjectHook(0x571040, &cAudioManager::GetFBITalkSfx, PATCH_JUMP); InjectHook(0x571110, &cAudioManager::GetArmyTalkSfx, PATCH_JUMP); -InjectHook(0x5711C0, &cAudioManager::GetMedicTalkSfx, PATCH_JUMP); -InjectHook(0x5712B0, &cAudioManager::GetFiremanTalkSfx, PATCH_JUMP); -InjectHook(0x575340, &cAudioManager::GetNormalMaleTalkSfx, PATCH_JUMP); -InjectHook(0x575190, &cAudioManager::GetTaxiDriverTalkSfx, PATCH_JUMP); -InjectHook(0x575240, &cAudioManager::GetPimpTalkSfx, PATCH_JUMP); -InjectHook(0x571510, &cAudioManager::GetMafiaTalkSfx, PATCH_JUMP); -InjectHook(0x571650, &cAudioManager::GetTriadTalkSfx, PATCH_JUMP); -InjectHook(0x571770, &cAudioManager::GetDiabloTalkSfx, PATCH_JUMP); -InjectHook(0x5718D0, &cAudioManager::GetYakuzaTalkSfx, PATCH_JUMP); -InjectHook(0x5719E0, &cAudioManager::GetYardieTalkSfx, PATCH_JUMP); -InjectHook(0x571B00, &cAudioManager::GetColumbianTalkSfx, PATCH_JUMP); -InjectHook(0x571C30, &cAudioManager::GetHoodTalkSfx, PATCH_JUMP); -InjectHook(0x571D80, &cAudioManager::GetBlackCriminalTalkSfx, PATCH_JUMP); -InjectHook(0x571E60, &cAudioManager::GetWhiteCriminalTalkSfx, PATCH_JUMP); -InjectHook(0x571F40, &cAudioManager::GetMaleNo2TalkSfx, PATCH_JUMP); -InjectHook(0x572AF0, &cAudioManager::GetBlackProjectMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5725D0, &cAudioManager::GetWhiteFatMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5726C0, &cAudioManager::GetBlackFatMaleTalkSfx, PATCH_JUMP); +InjectHook(0x573AB0, &cAudioManager::GetBlackBusinessFemaleTalkSfx, PATCH_JUMP); InjectHook(0x572050, &cAudioManager::GetBlackCasualFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x572170, &cAudioManager::GetWhiteCasualFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x572280, &cAudioManager::GetFemaleNo3TalkSfx, PATCH_JUMP); +InjectHook(0x574380, &cAudioManager::GetBlackConstructionWorkerTalkSfx, PATCH_JUMP); +InjectHook(0x571D80, &cAudioManager::GetBlackCriminalTalkSfx, PATCH_JUMP); +InjectHook(0x5735E0, &cAudioManager::GetBlackDockerMaleTalkSfx, PATCH_JUMP); InjectHook(0x5724D0, &cAudioManager::GetBlackFatFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x5727B0, &cAudioManager::GetWhiteFatFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x5726C0, &cAudioManager::GetBlackFatMaleTalkSfx, PATCH_JUMP); InjectHook(0x5728B0, &cAudioManager::GetBlackFemaleProstituteTalkSfx, PATCH_JUMP); -InjectHook(0x5729D0, &cAudioManager::GetWhiteFemaleProstituteTalkSfx, PATCH_JUMP); InjectHook(0x572C20, &cAudioManager::GetBlackProjectFemaleOldTalkSfx, PATCH_JUMP); InjectHook(0x572D20, &cAudioManager::GetBlackProjectFemaleYoungTalkSfx, PATCH_JUMP); -InjectHook(0x572E10, &cAudioManager::GetChinatownMaleOldTalkSfx, PATCH_JUMP); -InjectHook(0x572F10, &cAudioManager::GetChinatownMaleYoungTalkSfx, PATCH_JUMP); -InjectHook(0x573010, &cAudioManager::GetChinatownFemaleOldTalkSfx, PATCH_JUMP); -InjectHook(0x5730F0, &cAudioManager::GetChinatownFemaleYoungTalkSfx, PATCH_JUMP); -InjectHook(0x5731E0, &cAudioManager::GetLittleItalyMaleTalkSfx, PATCH_JUMP); -InjectHook(0x573310, &cAudioManager::GetLittleItalyFemaleOldTalkSfx, PATCH_JUMP); -InjectHook(0x573400, &cAudioManager::GetLittleItalyFemaleYoungTalkSfx, PATCH_JUMP); -InjectHook(0x5734F0, &cAudioManager::GetWhiteDockerMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5735E0, &cAudioManager::GetBlackDockerMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5736D0, &cAudioManager::GetScumMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5737E0, &cAudioManager::GetScumFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x5738D0, &cAudioManager::GetWhiteWorkerMaleTalkSfx, PATCH_JUMP); +InjectHook(0x572AF0, &cAudioManager::GetBlackProjectMaleTalkSfx, PATCH_JUMP); InjectHook(0x5739C0, &cAudioManager::GetBlackWorkerMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5713E0, &cAudioManager::GetBusinessMaleYoungTalkSfx, PATCH_JUMP); +InjectHook(0x574FF0, &cAudioManager::GetBomberTalkSfx, PATCH_JUMP); InjectHook(0x5712C0, &cAudioManager::GetBusinessMaleOldTalkSfx, PATCH_JUMP); -InjectHook(0x5723A0, &cAudioManager::GetWhiteBusinessFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x573AB0, &cAudioManager::GetBlackBusinessFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x573BD0, &cAudioManager::GetSupermodelMaleTalkSfx, PATCH_JUMP); -InjectHook(0x573CD0, &cAudioManager::GetSupermodelFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x573DC0, &cAudioManager::GetStewardMaleTalkSfx, PATCH_JUMP); -InjectHook(0x573E90, &cAudioManager::GetStewardFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x573F60, &cAudioManager::GetFanMaleTalkSfx, PATCH_JUMP); -InjectHook(0x574040, &cAudioManager::GetFanFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x574120, &cAudioManager::GetHospitalMaleTalkSfx, PATCH_JUMP); -InjectHook(0x5741F0, &cAudioManager::GetHospitalFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x574290, &cAudioManager::GetWhiteConstructionWorkerTalkSfx, PATCH_JUMP); -InjectHook(0x574380, &cAudioManager::GetBlackConstructionWorkerTalkSfx, PATCH_JUMP); -InjectHook(0x574480, &cAudioManager::GetShopperFemaleTalkSfx, PATCH_JUMP); -InjectHook(0x574590, &cAudioManager::GetStudentMaleTalkSfx, PATCH_JUMP); -InjectHook(0x574690, &cAudioManager::GetStudentFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x5713E0, &cAudioManager::GetBusinessMaleYoungTalkSfx, PATCH_JUMP); InjectHook(0x572040, &cAudioManager::GetCasualMaleOldTalkSfx, PATCH_JUMP); - -InjectHook(0x574790, &cAudioManager::GetSpecialCharacterTalkSfx, PATCH_JUMP); +InjectHook(0x574FE0, &cAudioManager::GetCatatalinaTalkSfx, PATCH_JUMP); +InjectHook(0x57AA30, &cAudioManager::GetCDAudioDriveLetter, PATCH_JUMP); +InjectHook(0x573010, &cAudioManager::GetChinatownFemaleOldTalkSfx, PATCH_JUMP); +InjectHook(0x5730F0, &cAudioManager::GetChinatownFemaleYoungTalkSfx, PATCH_JUMP); +InjectHook(0x572E10, &cAudioManager::GetChinatownMaleOldTalkSfx, PATCH_JUMP); +InjectHook(0x572F10, &cAudioManager::GetChinatownMaleYoungTalkSfx, PATCH_JUMP); +InjectHook(0x575120, &cAudioManager::GetChunkyTalkSfx, PATCH_JUMP); +InjectHook(0x571B00, &cAudioManager::GetColumbianTalkSfx, PATCH_JUMP); +InjectHook(0x570EA0, &cAudioManager::GetCopTalkSfx, PATCH_JUMP); +InjectHook(0x57A8F0, &cAudioManager::GetCurrent3DProviderIndex, PATCH_JUMP); +InjectHook(0x569060, &cAudioManager::GetCollisionOneShotRatio, PATCH_JUMP); +InjectHook(0x5693B0, &cAudioManager::GetCollisionRatio, PATCH_JUMP); +InjectHook(0x571770, &cAudioManager::GetDiabloTalkSfx, PATCH_JUMP); +InjectHook(0x569750, &cAudioManager::GetDistanceSquared, PATCH_JUMP); InjectHook(0x574DA0, &cAudioManager::GetEightTalkSfx, PATCH_JUMP); +InjectHook(0x574040, &cAudioManager::GetFanFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x573F60, &cAudioManager::GetFanMaleTalkSfx, PATCH_JUMP); +InjectHook(0x571040, &cAudioManager::GetFBITalkSfx, PATCH_JUMP); +InjectHook(0x572280, &cAudioManager::GetFemaleNo3TalkSfx, PATCH_JUMP); +InjectHook(0x5712B0, &cAudioManager::GetFiremanTalkSfx, PATCH_JUMP); InjectHook(0x574E50, &cAudioManager::GetFrankieTalkSfx, PATCH_JUMP); +InjectHook(0x575510, &cAudioManager::GetGenericFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x575460, &cAudioManager::GetGenericMaleTalkSfx, PATCH_JUMP); +InjectHook(0x571C30, &cAudioManager::GetHoodTalkSfx, PATCH_JUMP); +InjectHook(0x5741F0, &cAudioManager::GetHospitalFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x574120, &cAudioManager::GetHospitalMaleTalkSfx, PATCH_JUMP); +InjectHook(0x56F410, &cAudioManager::GetJumboTaxiFreq, PATCH_JUMP); +InjectHook(0x573310, &cAudioManager::GetLittleItalyFemaleOldTalkSfx, PATCH_JUMP); +InjectHook(0x573400, &cAudioManager::GetLittleItalyFemaleYoungTalkSfx, PATCH_JUMP); +InjectHook(0x5731E0, &cAudioManager::GetLittleItalyMaleTalkSfx, PATCH_JUMP); +InjectHook(0x571510, &cAudioManager::GetMafiaTalkSfx, PATCH_JUMP); +InjectHook(0x571F40, &cAudioManager::GetMaleNo2TalkSfx, PATCH_JUMP); +InjectHook(0x5711C0, &cAudioManager::GetMedicTalkSfx, PATCH_JUMP); +InjectHook(0x5795D0, &cAudioManager::GetMissionAudioLoadingStatus, PATCH_JUMP); +InjectHook(0x57F050, &cAudioManager::GetMissionScriptPoliceAudioPlayingStatus, PATCH_JUMP); InjectHook(0x574F00, &cAudioManager::GetMistyTalkSfx, PATCH_JUMP); +InjectHook(0x575340, &cAudioManager::GetNormalMaleTalkSfx, PATCH_JUMP); +InjectHook(0x57A8A0, &cAudioManager::GetNum3DProvidersAvailable, PATCH_JUMP); InjectHook(0x574FD0, &cAudioManager::GetOJGTalkSfx, PATCH_JUMP); -InjectHook(0x574FE0, &cAudioManager::GetCatatalinaTalkSfx, PATCH_JUMP); -InjectHook(0x574FF0, &cAudioManager::GetBomberTalkSfx, PATCH_JUMP); +InjectHook(0x570960, &cAudioManager::GetPedCommentSfx, PATCH_JUMP); +InjectHook(0x570DB0, &cAudioManager::GetPhrase, PATCH_JUMP); +InjectHook(0x575240, &cAudioManager::GetPimpTalkSfx, PATCH_JUMP); +InjectHook(0x570E00, &cAudioManager::GetPlayerTalkSfx, PATCH_JUMP); +InjectHook(0x5737E0, &cAudioManager::GetScumFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x5736D0, &cAudioManager::GetScumMaleTalkSfx, PATCH_JUMP); InjectHook(0x575060, &cAudioManager::GetSecurityGuardTalkSfx, PATCH_JUMP); -InjectHook(0x575120, &cAudioManager::GetChunkyTalkSfx, PATCH_JUMP); - -InjectHook(0x575460, &cAudioManager::GetGenericMaleTalkSfx, PATCH_JUMP); -InjectHook(0x575510, &cAudioManager::GetGenericFemaleTalkSfx, PATCH_JUMP); - -// Process stuff +InjectHook(0x574480, &cAudioManager::GetShopperFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x574790, &cAudioManager::GetSpecialCharacterTalkSfx, PATCH_JUMP); +InjectHook(0x573E90, &cAudioManager::GetStewardFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x573DC0, &cAudioManager::GetStewardMaleTalkSfx, PATCH_JUMP); +InjectHook(0x574690, &cAudioManager::GetStudentFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x574590, &cAudioManager::GetStudentMaleTalkSfx, PATCH_JUMP); +InjectHook(0x573CD0, &cAudioManager::GetSupermodelFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x573BD0, &cAudioManager::GetSupermodelMaleTalkSfx, PATCH_JUMP); +InjectHook(0x570F80, &cAudioManager::GetSwatTalkSfx, PATCH_JUMP); +InjectHook(0x575190, &cAudioManager::GetTaxiDriverTalkSfx, PATCH_JUMP); +InjectHook(0x571650, &cAudioManager::GetTriadTalkSfx, PATCH_JUMP); +InjectHook(0x5723A0, &cAudioManager::GetWhiteBusinessFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x572170, &cAudioManager::GetWhiteCasualFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x574290, &cAudioManager::GetWhiteConstructionWorkerTalkSfx, PATCH_JUMP); +InjectHook(0x571E60, &cAudioManager::GetWhiteCriminalTalkSfx, PATCH_JUMP); +InjectHook(0x5734F0, &cAudioManager::GetWhiteDockerMaleTalkSfx, PATCH_JUMP); +InjectHook(0x5727B0, &cAudioManager::GetWhiteFatFemaleTalkSfx, PATCH_JUMP); +InjectHook(0x5725D0, &cAudioManager::GetWhiteFatMaleTalkSfx, PATCH_JUMP); +InjectHook(0x5729D0, &cAudioManager::GetWhiteFemaleProstituteTalkSfx, PATCH_JUMP); +InjectHook(0x5738D0, &cAudioManager::GetWhiteWorkerMaleTalkSfx, PATCH_JUMP); +InjectHook(0x5718D0, &cAudioManager::GetYakuzaTalkSfx, PATCH_JUMP); +InjectHook(0x5719E0, &cAudioManager::GetYardieTalkSfx, PATCH_JUMP); +InjectHook(0x56CAB0, &cAudioManager::HasAirBrakes, PATCH_JUMP); +InjectHook(0x57A0E0, &cAudioManager::Initialise, PATCH_JUMP); +// InjectHook(0x57EAC0, &cAudioManager::InitialisePoliceRadioZones, PATCH_JUMP); +InjectHook(0x57B030, &cAudioManager::InterrogateAudioEntities, PATCH_JUMP); +InjectHook(0x57AA50, &cAudioManager::IsAudioInitialised, PATCH_JUMP); +InjectHook(0x579650, &cAudioManager::IsMissionAudioSampleFinished, PATCH_JUMP); +InjectHook(0x57A9C0, &cAudioManager::IsMP3RadioChannelAvailable, PATCH_JUMP); +InjectHook(0x579520, &cAudioManager::MissionScriptAudioUsesPoliceChannel, PATCH_JUMP); +InjectHook(0x56AD10, &cAudioManager::PlayerJustGotInCar, PATCH_JUMP); +InjectHook(0x56AD20, &cAudioManager::PlayerJustLeftCar, PATCH_JUMP); +InjectHook(0x579620, &cAudioManager::PlayLoadedMissionAudio, PATCH_JUMP); +InjectHook(0x569420, &cAudioManager::PostInitialiseGameSpecificSetup, PATCH_JUMP); +InjectHook(0x569640, &cAudioManager::PostTerminateGameSpecificShutdown, PATCH_JUMP); +InjectHook(0x569400, &cAudioManager::PreInitialiseGameSpecificSetup, PATCH_JUMP); +InjectHook(0x569570, &cAudioManager::PreTerminateGameSpecificShutdown, PATCH_JUMP); // InjectHook(0x57BA60, &cAudioManager::ProcessActiveQueues, PATCH_JUMP); InjectHook(0x56C940, &cAudioManager::ProcessAirBrakes, PATCH_JUMP); InjectHook(0x577B30, &cAudioManager::ProcessAirportScriptObject, PATCH_JUMP); @@ -8515,6 +8426,34 @@ InjectHook(0x56DBF0, &cAudioManager::ProcessTrainNoise, PATCH_JUMP); InjectHook(0x56C770, &cAudioManager::ProcessVehicleDoors, PATCH_JUMP); InjectHook(0x56C640, &cAudioManager::ProcessVehicleReverseWarning, PATCH_JUMP); InjectHook(0x56A230, &cAudioManager::ProcessVehicleRoadNoise, PATCH_JUMP); +InjectHook(0x578370, &cAudioManager::ProcessWeather, PATCH_JUMP); +InjectHook(0x56A440, &cAudioManager::ProcessWetRoadNoise, PATCH_JUMP); InjectHook(0x577530, &cAudioManager::ProcessWorkShopScriptObject, PATCH_JUMP); +InjectHook(0x57AF90, &cAudioManager::RandomDisplacement, PATCH_JUMP); +InjectHook(0x57A9F0, &cAudioManager::ReacquireDigitalHandle, PATCH_JUMP); +InjectHook(0x57A9E0, &cAudioManager::ReleaseDigitalHandle, PATCH_JUMP); +InjectHook(0x569650, &cAudioManager::ResetAudioLogicTimers, PATCH_JUMP); +InjectHook(0x57EFF0, &cAudioManager::ResetPoliceRadio, PATCH_JUMP); +InjectHook(0x57AA00, &cAudioManager::SetDynamicAcousticModelingStatus, PATCH_JUMP); +InjectHook(0x57A770, &cAudioManager::SetEffectsFadeVolume, PATCH_JUMP); +InjectHook(0x57A730, &cAudioManager::SetEffectsMasterVolume, PATCH_JUMP); +InjectHook(0x57A4C0, &cAudioManager::SetEntityStatus, PATCH_JUMP); +InjectHook(0x5795F0, &cAudioManager::SetMissionAudioLocation, PATCH_JUMP); +InjectHook(0x57F020, &cAudioManager::SetMissionScriptPoliceAudio, PATCH_JUMP); +InjectHook(0x57A790, &cAudioManager::SetMusicFadeVolume, PATCH_JUMP); +InjectHook(0x57A750, &cAudioManager::SetMusicMasterVolume, PATCH_JUMP); +InjectHook(0x57A9A0, &cAudioManager::SetSpeakerConfig, PATCH_JUMP); +InjectHook(0x56F230, &cAudioManager::SetupJumboFlySound, PATCH_JUMP); +InjectHook(0x56F310, &cAudioManager::SetupJumboRumbleSound, PATCH_JUMP); +InjectHook(0x56EF20, &cAudioManager::SetupJumboTaxiSound, PATCH_JUMP); +InjectHook(0x56F070, &cAudioManager::SetupJumboWhineSound, PATCH_JUMP); InjectHook(0x570690, &cAudioManager::SetupPedComments, PATCH_JUMP); +InjectHook(0x57A150, &cAudioManager::Terminate, PATCH_JUMP); +InjectHook(0x57AC60, &cAudioManager::TranslateEntity, PATCH_JUMP); +InjectHook(0x56AC80, &cAudioManager::UpdateGasPedalAudio, PATCH_JUMP); +InjectHook(0x56C600, &cAudioManager::UsesReverseWarning, PATCH_JUMP); +InjectHook(0x56C3C0, &cAudioManager::UsesSiren, PATCH_JUMP); +InjectHook(0x56C3F0, &cAudioManager::UsesSirenSwitching, PATCH_JUMP); +InjectHook(0x5755C0, &cPedComments::Add, PATCH_JUMP); +InjectHook(0x575730, &cPedComments::Process, PATCH_JUMP); ENDPATCHES diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 5ad14050..c765bfd4 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -49,8 +49,8 @@ public: uint8 field_89; uint8 field_90; uint8 field_91; - - // no methods + + // no methods }; static_assert(sizeof(tActiveSample) == 92, "tActiveSample: error"); @@ -88,8 +88,8 @@ public: float m_afVolume[4]; uint8 m_Loops; uint8 field_25[3]; - - // no methods + + // no methods }; static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); @@ -104,8 +104,8 @@ public: uint8 m_bVolume; int8 field_25; // allocated time? uint8 gap_26[2]; - - // no methods + + // no methods }; static_assert(sizeof(tPedComment) == 28, "tPedComment: error"); @@ -119,7 +119,7 @@ public: uint8 activeBank; uint8 gap_1163[1]; - // reversed all methods + // reversed all methods void Add(tPedComment *com); /// ok void Process(); /// ok }; @@ -142,8 +142,8 @@ public: CVector m_vecPosition; float m_fDistance; int32 m_nBaseVolume; - - // no methods + + // no methods }; static_assert(sizeof(cAudioCollision) == 40, "cAudioCollision: error"); @@ -157,6 +157,8 @@ public: uint8 m_bCollisionsInQueue; uint8 gap_811; cAudioCollision m_sQueue; + + void AddCollisionToRequestedQueue(); // todo }; static_assert(sizeof(cAudioCollisionManager) == 852, "cAudioCollisionManager: error"); @@ -177,6 +179,7 @@ public: uint8 field_29; uint8 field_30; uint8 field_31; + // no methods }; static_assert(sizeof(cMissionAudio) == 32, "cMissionAudio: error"); @@ -188,7 +191,8 @@ class CPed; class cPedParams; class cTransmission; -class cAudioScriptObject { +class cAudioScriptObject +{ public: int16 AudioId; char _pad0[2]; @@ -220,22 +224,14 @@ enum { MAX_REFLECTIONS, }; -<<<<<<< HEAD -enum AudioEntityHandle -{ - AEHANDLE_NONE = -5, - AEHANDLE_ERROR_NOAUDIOSYS = -4, - AEHANDLE_ERROR_NOFREESLOT = -3, - AEHANDLE_ERROR_NOENTITY = -2, +enum AudioEntityHandle { + AEHANDLE_NONE = -5, + AEHANDLE_ERROR_NOAUDIOSYS = -4, + AEHANDLE_ERROR_NOFREESLOT = -3, + AEHANDLE_ERROR_NOENTITY = -2, AEHANDLE_ERROR_BADAUDIOTYPE = -1, }; -#define AEHANDLE_IS_FAILED(h) ((h)<0) -#define AEHANDLE_IS_OK(h) ((h)>=0) - - -======= ->>>>>>> Cleanup class cAudioManager { public: @@ -285,22 +281,10 @@ public: uint8 field_19195; // time? uint32 m_FrameCounter; -<<<<<<< HEAD - inline uint32 GetFrameCounter(void) { return m_FrameCounter; } - float GetReflectionsDistance(int32 idx) { return m_afReflectionsDistances[idx]; } -<<<<<<< HEAD - int32 GetRandomNumber(int32 idx) { return m_anRandomTable[idx]; } -======= - int32 GetRandomTabe(int32 idx) { return m_anRandomTable[idx]; } - ->>>>>>> Cleanup - // -======= // getters uint32 GetFrameCounter() const { return m_FrameCounter; } float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } - int32 GetRandomTabe(int32 idx) const { return m_anRandomTable[idx]; } ->>>>>>> More more more audio + int32 GetRandomNumber(int32 idx) const { return m_anRandomTable[idx]; } // "Should" be in alphabetic order, except "getXTalkSfx" void AddDetailsToRequestedOrderList(uint8 sample); /// ok @@ -312,80 +296,22 @@ public: void AgeCrimes(); // todo void CalculateDistance(bool *ptr, float dist); /// ok - bool CheckForAnAudioFileOnCD() const; /// ok + bool CheckForAnAudioFileOnCD() const; /// ok void ClearMissionAudio(); /// ok void ClearRequestedQueue(); /// ok int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, - float speedMultiplier) const; /// ok - int32 ComputePan(float, CVector *); // todo -<<<<<<< HEAD - uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance); /// ok - int32 CreateEntity(int32 type, void *entity); /// ok -======= + float speedMultiplier) const; /// ok + int32 ComputePan(float, CVector *); // todo uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance) const; /// ok - int32 CreateEntity(int32 type, CPhysical *entity); /// ok ->>>>>>> More more more audio + int32 CreateEntity(int32 type, CPhysical *entity); /// ok void DestroyAllGameCreatedEntities(); /// ok void DestroyEntity(int32 id); /// ok + void DoJumboVolOffset() const; /// ok void DoPoliceRadioCrackle(); /// ok - void GenerateIntegerRandomNumberTable(); /// ok - - void TranslateEntity(CVector *v1, CVector *v2) const ; /// ok - - void ResetAudioLogicTimers(int32 timer); /// ok - - void Terminate(); - uint8 GetNum3DProvidersAvailable() const; - bool IsMP3RadioChannelAvailable() const; - uint8 GetCDAudioDriveLetter() const; - - void SetEffectsMasterVolume(uint8 volume) const; - void SetMusicMasterVolume(uint8 volume) const; - void SetEffectsFadeVolume(uint8 volume) const; - void SetMusicFadeVolume(uint8 volume) const; - - void SetSpeakerConfig(int32 conf) const; - - bool SetupJumboEngineSound(uint8, int32); // todo - void PreInitialiseGameSpecificSetup() const; - void SetMissionScriptPoliceAudio(int32 sfx) const; - - bool UsesSiren(int32 model) const; - bool UsesSirenSwitching(int32 model) const; - - char *Get3DProviderName(uint8 id) const; - - bool SetupJumboFlySound(uint8 emittingVol); /// ok - bool SetupJumboRumbleSound(uint8 emittingVol); /// ok - bool SetupJumboTaxiSound(uint8 vol); /// ok - bool SetupJumboWhineSound(uint8 emittingVol, int32 freq); /// ok - - void SetMissionAudioLocation(float x, float y, float z); - - void ResetPoliceRadio(); - - bool UsesReverseWarning(int32 model) const; - - int32 RandomDisplacement(uint32 seed) const; - - void ReleaseDigitalHandle() const; - void ReacquireDigitalHandle() const; - void SetDynamicAcousticModelingStatus(bool status); - - bool IsAudioInitialised() const; - - void SetEntityStatus(int32 id, bool status); - - void Service(); - void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const; - - void DoJumboVolOffset() const; - - int32 GetPedCommentSfx(CPed *ped, int32 sound); - - // order from GetPedCommentSfx + // functions returning talk sfx, + // order from GetPedCommentSfx uint32 GetPlayerTalkSfx(int16 sound); uint32 GetCopTalkSfx(int16 sound); uint32 GetSwatTalkSfx(int16 sound); @@ -462,15 +388,22 @@ public: uint32 GetGenericMaleTalkSfx(int16 sound); uint32 GetGenericFemaleTalkSfx(int16 sound); + // end of functions returning talk sfx + void GenerateIntegerRandomNumberTable(); /// ok + char *Get3DProviderName(uint8 id) const; + uint8 GetCDAudioDriveLetter() const; int8 GetCurrent3DProviderIndex() const; /// ok - float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // todo hook - float GetCollisionOneShotRatio(uint32 a, float b) const; // todo hook - float GetCollisionRatio(float a, float b, float c, float d) const; // todo hook + float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // not used + float GetCollisionOneShotRatio(uint32 a, float b) const; /// ok + float GetCollisionRatio(float a, float b, float c, float d) const; /// ok float GetDistanceSquared(CVector *v) const; /// ok int32 GetJumboTaxiFreq() const; /// ok bool GetMissionAudioLoadingStatus() const; /// ok char GetMissionScriptPoliceAudioPlayingStatus() const; /// ok + uint8 GetNum3DProvidersAvailable() const; + int32 GetPedCommentSfx(CPed *ped, int32 sound); + void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const; float GetVehicleDriveWheelSkidValue(uint8 a1, CAutomobile *a2, cTransmission *a3, float a4); // todo int32 GetVehicleNonDriveWheelSkidValue(float a1, int a2, int a3, int a4, float a5); // todo @@ -481,19 +414,22 @@ public: void InitialisePoliceRadio(); // todo void InitialisePoliceRadioZones(); // todo void InterrogateAudioEntities(); /// ok + bool IsAudioInitialised() const; /// ok bool IsMissionAudioSampleFinished(); /// ok + bool IsMP3RadioChannelAvailable() const; bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; /// ok void PlayLoadedMissionAudio(); /// ok void PlayOneShot(int32 index, int16 sound, float vol); // todo - uint32 PlaySuspectLastSeen(float x, float y, float z); // todo - void PlayerJustGotInCar() const; /// ok - void PlayerJustLeftCar() const; /// ok + uint32 PlaySuspectLastSeen(float x, float y, float z); // todo + void PlayerJustGotInCar() const; /// ok + void PlayerJustLeftCar() const; /// ok void PostInitialiseGameSpecificSetup(); /// ok void PostTerminateGameSpecificShutdown(); /// ok - void PreTerminateGameSpecificShutdown(); /// ok - void PreloadMissionAudio(char *); // todo + void PreInitialiseGameSpecificSetup() const; + void PreloadMissionAudio(char *); // todo + void PreTerminateGameSpecificShutdown(); /// ok /// processX - main logic of adding new sounds void ProcessActiveQueues(); // todo bool ProcessAirBrakes(cVehicleParams *params); /// ok @@ -541,7 +477,7 @@ public: void ProcessPornCinema(uint8 sound); /// ok void ProcessProjectiles(); // todo requires CProjectileInfo void ProcessRainOnVehicle(cVehicleParams *params); /// ok - void ProcessReverb() const; /// ok + void ProcessReverb() const; /// ok bool ProcessReverseGear(cVehicleParams *a2); /// ok void ProcessSawMillScriptObject(uint8 sound); /// ok void ProcessScriptObject(int32 id); /// ok @@ -558,11 +494,55 @@ public: // void ProcessVehicleSirenOrAlarm(void *); // void ProcessVehicleSkidding(void *); void ProcessWaterCannon(int32); // todo - void ProcessWeather(int32 id); // todo - bool ProcessWetRoadNoise(cVehicleParams *params); // todo hook + void ProcessWeather(int32 id); /// ok + bool ProcessWetRoadNoise(cVehicleParams *params); /// ok void ProcessWorkShopScriptObject(uint8 sound); /// ok - void SetupPedComments(cPedParams *params, uint32 sound); /// ok + int32 RandomDisplacement(uint32 seed) const; + void ReacquireDigitalHandle() const; + void ReleaseDigitalHandle() const; + int32 ReportCollision(CEntity *a2, CEntity *a3, uint8 a4, uint8 a5, float a6, + float a7); // todo + int32 ReportCrime(int a2, int *a3); // todo + void ResetAudioLogicTimers(int32 timer); /// ok + void ResetPoliceRadio(); + void ResetTimers(unsigned int a2); // todo + + void Service(); // todo + void ServiceCollisions(); // todo + void ServicePoliceRadio(); // todo + void ServicePoliceRadioChannel(int a2); // todo + void ServiceSoundEffects(); // todo + void SetCurrent3DProvider(uint8); + void SetDynamicAcousticModelingStatus(bool status); + void SetEffectsFadeVolume(uint8 volume) const; + void SetEffectsMasterVolume(uint8 volume) const; + void SetEntityStatus(int32 id, bool status); + uint32 SetLoopingCollisionRequestedSfxFreqAndGetVol(int32); // todo + void SetMissionAudioLocation(float x, float y, float z); + void SetMissionScriptPoliceAudio(int32 sfx) const; + void SetMonoMode(uint8); // todo + void SetMusicFadeVolume(uint8 volume) const; + void SetMusicMasterVolume(uint8 volume) const; + void SetSpeakerConfig(int32 conf) const; + void SetUpLoopingCollisionSound(int a2, int a3); // todo + void SetUpOneShotCollisionSound(int a2); // todo + void SetupCrimeReport(); // todo + bool SetupJumboEngineSound(uint8, int32); // todo + bool SetupJumboFlySound(uint8 emittingVol); /// ok + bool SetupJumboRumbleSound(uint8 emittingVol); /// ok + bool SetupJumboTaxiSound(uint8 vol); /// ok + bool SetupJumboWhineSound(uint8 emittingVol, int32 freq); /// ok + void SetupPedComments(cPedParams *params, uint32 sound); /// ok + void SetupSuspectLastSeenReport(); // todo + + void Terminate(); + void TranslateEntity(CVector *v1, CVector *v2) const; /// ok + + void UpdateGasPedalAudio(CAutomobile *automobile); // todo hook + bool UsesReverseWarning(int32 model) const; + bool UsesSiren(int32 model) const; + bool UsesSirenSwitching(int32 model) const; }; static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); diff --git a/src/audio/AudioManager.h.autosave b/src/audio/AudioManager.h.autosave new file mode 100644 index 00000000..2ea78476 --- /dev/null +++ b/src/audio/AudioManager.h.autosave @@ -0,0 +1,549 @@ +#pragma once + +#include "AudioSamples.h" +#include "DMAudio.h" +#include "common.h" + +class tActiveSample +{ +public: + int32 m_nEntityIndex; + int32 m_counter; + int32 m_nSampleIndex; + uint8 m_bBankIndex; + uint8 m_bIsDistant; + uint8 field_14; + uint8 field_15; + int32 field_16; + int32 m_nFrequency; + uint8 m_bVolume; + uint8 field_25; + uint8 field_26; + uint8 field_27; + float m_fDistance; + int32 m_nLoopCount; + int32 m_nLoopStart; + int32 m_nLoopEnd; + uint8 m_bEmittingVolume; + uint8 field_45; + uint8 field_46; + uint8 field_47; + float field_48; + float m_fSoundIntensity; + uint8 field_56; + uint8 field_57; + uint8 field_58; + uint8 field_59; + CVector m_vecPos; + uint8 m_bReverbFlag; + uint8 m_bLoopsRemaining; + uint8 m_bRequireReflection; + uint8 m_bOffset; + int32 field_76; + uint8 m_bIsProcessed; + uint8 m_bLoopEnded; + uint8 field_82; + uint8 field_83; + int32 calculatedVolume; + uint8 field_88; + uint8 field_89; + uint8 field_90; + uint8 field_91; + + // no methods +}; + +static_assert(sizeof(tActiveSample) == 92, "tActiveSample: error"); + +enum eAudioType : int32 { + AUDIOTYPE_PHYSICAL = 0, + AUDIOTYPE_EXPLOSION = 1, + AUDIOTYPE_FIRE = 2, + AUDIOTYPE_WEATHER = 3, + AUDIOTYPE_CRANE = 4, + AUDIOTYPE_SCRIPTOBJECT = 5, + AUDIOTYPE_BRIDGE = 6, + AUDIOTYPE_COLLISION = 7, + AUDIOTYPE_FRONTEND = 8, + AUDIOTYPE_PROJECTILE = 9, + AUDIOTYPE_GARAGE = 10, + AUDIOTYPE_FIREHYDRANT = 11, + AUDIOTYPE_WATERCANNON = 12, + AUDIOTYPE_POLICERADIO = 13, + TOTAL_AUDIO_TYPES = 14, +}; + +class CPhysical; +class CAutomobile; + +class tAudioEntity +{ +public: + eAudioType m_nType; + void *m_pEntity; + bool m_bIsUsed; + uint8 m_bStatus; + int16 m_awAudioEvent[4]; + uint8 gap_18[2]; + float m_afVolume[4]; + uint8 m_Loops; + uint8 field_25[3]; + + // no methods +}; + +static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); + +class tPedComment +{ +public: + int32 m_nSampleIndex; + int32 m_entityIndex; + CVector m_vecPos; + float m_fDistance; + uint8 m_bVolume; + int8 field_25; // allocated time? + uint8 gap_26[2]; + + // no methods +}; + +static_assert(sizeof(tPedComment) == 28, "tPedComment: error"); + +class cPedComments +{ +public: + tPedComment m_asPedComments[2][20]; + uint8 indexMap[2][20]; + uint8 nrOfCommentsInBank[2]; + uint8 activeBank; + uint8 gap_1163[1]; + + // reversed all methods + void Add(tPedComment *com); /// ok + void Process(); /// ok +}; + +static_assert(sizeof(cPedComments) == 1164, "cPedComments: error"); + +class CEntity; + +class cAudioCollision +{ +public: + CEntity *m_pEntity1; + CEntity *m_pEntity2; + uint8 m_bSurface1; + uint8 m_bSurface2; + uint8 field_10; + uint8 field_11; + float m_fIntensity1; + float m_fIntensity2; + CVector m_vecPosition; + float m_fDistance; + int32 m_nBaseVolume; + + // no methods +}; + +static_assert(sizeof(cAudioCollision) == 40, "cAudioCollision: error"); + +class cAudioCollisionManager +{ +public: + cAudioCollision m_asCollisions1[10]; + cAudioCollision m_asCollisions2[10]; + uint8 m_bIndicesTable[10]; + uint8 m_bCollisionsInQueue; + uint8 gap_811; + cAudioCollision m_sQueue; + + void AddCollisionToRequestedQueue(); // todo +}; + +static_assert(sizeof(cAudioCollisionManager) == 852, "cAudioCollisionManager: error"); + +class cMissionAudio +{ +public: + CVector m_vecPos; + uint8 field_12; + uint8 gap_13[3]; + int m_nSampleIndex; + uint8 m_bLoadingStatus; + uint8 m_bPlayStatus; + uint8 field_22; + uint8 field_23; + int field_24; + bool m_bIsPlayed; + uint8 field_29; + uint8 field_30; + uint8 field_31; + // no methods +}; + +static_assert(sizeof(cMissionAudio) == 32, "cMissionAudio: error"); + +class cVehicleParams; +class CPlane; +class CVehicle; +class CPed; +class cPedParams; +class cTransmission; + +class cAudioScriptObject { +public: + int16 AudioId; + char _pad0[2]; + CVector Posn; + int32 AudioEntity; + + static void *operator new(size_t); + static void *operator new(size_t, int); + static void operator delete(void *, size_t); + static void operator delete(void *, int); +}; + +static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error"); + +enum { + /* + REFLECTION_YMAX = 0, top + REFLECTION_YMIN = 1, bottom + REFLECTION_XMIN = 2, left + REFLECTION_XMAX = 3, right + REFLECTION_ZMAX = 4, + */ + + REFLECTION_TOP = 0, + REFLECTION_BOTTOM, + REFLECTION_LEFT, + REFLECTION_RIGHT, + REFLECTION_UP, + MAX_REFLECTIONS, +}; + +enum AudioEntityHandle +{ + AEHANDLE_NONE = -5, + AEHANDLE_ERROR_NOAUDIOSYS = -4, + AEHANDLE_ERROR_NOFREESLOT = -3, + AEHANDLE_ERROR_NOENTITY = -2, + AEHANDLE_ERROR_BADAUDIOTYPE = -1, +}; + +class cAudioManager +{ +public: + bool m_bIsInitialised; + uint8 field_1; + uint8 field_2; + uint8 m_bActiveSamples; + uint8 field_4; + bool m_bDynamicAcousticModelingStatus; + uint8 field_6; + uint8 field_7; + float speedOfSound; + bool m_bTimerJustReset; + uint8 field_13; + uint8 field_14; + uint8 field_15; + int32 m_nTimer; + tActiveSample m_sQueueSample; + uint8 m_bActiveSampleQueue; + uint8 gap_109[3]; + tActiveSample m_asSamples[2][27]; + uint8 m_abSampleQueueIndexTable[2][27]; + uint8 m_bSampleRequestQueuesStatus[2]; + tActiveSample m_asActiveSamples[27]; + tAudioEntity m_asAudioEntities[200]; + int32 m_anAudioEntityIndices[200]; + int32 m_nAudioEntitiesTotal; + CVector m_avecReflectionsPos[5]; + float m_afReflectionsDistances[5]; + int32 m_anScriptObjectEntityIndices[40]; + int32 m_nScriptObjectEntityTotal; + cPedComments m_sPedComments; + int32 m_nFireAudioEntity; + int32 m_nWaterCannonEntity; + int32 m_nPoliceChannelEntity; + uint8 gap45B8[444]; + int32 m_nFrontEndEntity; + int32 m_nCollisionEntity; + cAudioCollisionManager m_sCollisionManager; + int32 m_nProjectileEntity; + int32 m_nBridgeEntity; + cMissionAudio m_sMissionAudio; + int32 m_anRandomTable[5]; + uint8 field_19192; + uint8 m_bUserPause; + uint8 m_bPreviousUserPause; + uint8 field_19195; // time? + uint32 m_FrameCounter; + + // getters + uint32 GetFrameCounter() const { return m_FrameCounter; } + float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } + int32 GetRandomTabe(int32 idx) const { return m_anRandomTable[idx]; } + + // "Should" be in alphabetic order, except "getXTalkSfx" + void AddDetailsToRequestedOrderList(uint8 sample); /// ok + void AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 unk1, + uint8 counter, bool notLooping); /// ok + void AddReflectionsToRequestedQueue(); /// ok (check value) + void AddReleasingSounds(); // todo (difficult) + void AddSampleToRequestedQueue(); /// ok + void AgeCrimes(); // todo + + void CalculateDistance(bool *ptr, float dist); /// ok + bool CheckForAnAudioFileOnCD() const; /// ok + void ClearMissionAudio(); /// ok + void ClearRequestedQueue(); /// ok + int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, + float speedMultiplier) const; /// ok + int32 ComputePan(float, CVector *); // todo + uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance) const; /// ok + int32 CreateEntity(int32 type, CPhysical *entity); /// ok + + void DestroyAllGameCreatedEntities(); /// ok + void DestroyEntity(int32 id); /// ok + void DoJumboVolOffset() const; /// ok + void DoPoliceRadioCrackle(); /// ok + + // functions returning talk sfx, + // order from GetPedCommentSfx + uint32 GetPlayerTalkSfx(int16 sound); + uint32 GetCopTalkSfx(int16 sound); + uint32 GetSwatTalkSfx(int16 sound); + uint32 GetFBITalkSfx(int16 sound); + uint32 GetArmyTalkSfx(int16 sound); + uint32 GetMedicTalkSfx(int16 sound); + uint32 GetFiremanTalkSfx(int16 sound); + uint32 GetNormalMaleTalkSfx(int16 sound); + uint32 GetTaxiDriverTalkSfx(int16 sound); + uint32 GetPimpTalkSfx(int16 sound); + uint32 GetMafiaTalkSfx(int16 sound); + uint32 GetTriadTalkSfx(int16 sound); + uint32 GetDiabloTalkSfx(int16 sound); + uint32 GetYakuzaTalkSfx(int16 sound); + uint32 GetYardieTalkSfx(int16 sound); + uint32 GetColumbianTalkSfx(int16 sound); + uint32 GetHoodTalkSfx(int16 sound); + uint32 GetBlackCriminalTalkSfx(int16 sound); + uint32 GetWhiteCriminalTalkSfx(int16 sound); + uint32 GetMaleNo2TalkSfx(int16 sound); + uint32 GetBlackProjectMaleTalkSfx(int16 sound, int32 model); + uint32 GetWhiteFatMaleTalkSfx(int16 sound); + uint32 GetBlackFatMaleTalkSfx(int16 sound); + uint32 GetBlackCasualFemaleTalkSfx(int16 sound); + uint32 GetWhiteCasualFemaleTalkSfx(int16 sound); + uint32 GetFemaleNo3TalkSfx(int16 sound); + uint32 GetBlackFatFemaleTalkSfx(int16 sound); + uint32 GetWhiteFatFemaleTalkSfx(int16 sound); + uint32 GetBlackFemaleProstituteTalkSfx(int16 sound); + uint32 GetWhiteFemaleProstituteTalkSfx(int16 sound); + uint32 GetBlackProjectFemaleOldTalkSfx(int16 sound); + uint32 GetBlackProjectFemaleYoungTalkSfx(int16 sound); + uint32 GetChinatownMaleOldTalkSfx(int16 sound); + uint32 GetChinatownMaleYoungTalkSfx(int16 sound); + uint32 GetChinatownFemaleOldTalkSfx(int16 sound); + uint32 GetChinatownFemaleYoungTalkSfx(int16 sound); + uint32 GetLittleItalyMaleTalkSfx(int16 sound); + uint32 GetLittleItalyFemaleOldTalkSfx(int16 sound); + uint32 GetLittleItalyFemaleYoungTalkSfx(int16 sound); + uint32 GetWhiteDockerMaleTalkSfx(int16 sound); + uint32 GetBlackDockerMaleTalkSfx(int16 sound); + uint32 GetScumMaleTalkSfx(int16 sound); + uint32 GetScumFemaleTalkSfx(int16 sound); + uint32 GetWhiteWorkerMaleTalkSfx(int16 sound); + uint32 GetBlackWorkerMaleTalkSfx(int16 sound); + uint32 GetBusinessMaleYoungTalkSfx(int16 sound, int32 model); + uint32 GetBusinessMaleOldTalkSfx(int16 sound); + uint32 GetWhiteBusinessFemaleTalkSfx(int16 sound, int32 model); + uint32 GetBlackBusinessFemaleTalkSfx(int16 sound); + uint32 GetSupermodelMaleTalkSfx(int16 sound); + uint32 GetSupermodelFemaleTalkSfx(int16 sound); + uint32 GetStewardMaleTalkSfx(int16 sound); + uint32 GetStewardFemaleTalkSfx(int16 sound); + uint32 GetFanMaleTalkSfx(int16 sound, int32 model); + uint32 GetFanFemaleTalkSfx(int16 sound); + uint32 GetHospitalMaleTalkSfx(int16 sound); + uint32 GetHospitalFemaleTalkSfx(int16 sound); + uint32 GetWhiteConstructionWorkerTalkSfx(int16 sound); + uint32 GetBlackConstructionWorkerTalkSfx(int16 sound); + uint32 GetShopperFemaleTalkSfx(int16 sound, int32 model); + uint32 GetStudentMaleTalkSfx(int16 sound); + uint32 GetStudentFemaleTalkSfx(int16 sound); + uint32 GetCasualMaleOldTalkSfx(int16 sound); + + uint32 GetSpecialCharacterTalkSfx(int32 modelIndex, int32 sound); + uint32 GetEightTalkSfx(int16 sound); + uint32 GetFrankieTalkSfx(int16 sound); + uint32 GetMistyTalkSfx(int16 sound); + uint32 GetOJGTalkSfx(int16 sound); + uint32 GetCatatalinaTalkSfx(int16 sound); + uint32 GetBomberTalkSfx(int16 sound); + uint32 GetSecurityGuardTalkSfx(int16 sound); + uint32 GetChunkyTalkSfx(int16 sound); + + uint32 GetGenericMaleTalkSfx(int16 sound); + uint32 GetGenericFemaleTalkSfx(int16 sound); + // end of functions returning talk sfx + + void GenerateIntegerRandomNumberTable(); /// ok + char *Get3DProviderName(uint8 id) const; + uint8 GetCDAudioDriveLetter() const; + int8 GetCurrent3DProviderIndex() const; /// ok + float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // not used + float GetCollisionOneShotRatio(uint32 a, float b) const; /// ok + float GetCollisionRatio(float a, float b, float c, float d) const; /// ok + float GetDistanceSquared(CVector *v) const; /// ok + int32 GetJumboTaxiFreq() const; /// ok + bool GetMissionAudioLoadingStatus() const; /// ok + char GetMissionScriptPoliceAudioPlayingStatus() const; /// ok + uint8 GetNum3DProvidersAvailable() const; + int32 GetPedCommentSfx(CPed *ped, int32 sound); + void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const; + float GetVehicleDriveWheelSkidValue(uint8 a1, CAutomobile *a2, cTransmission *a3, + float a4); // todo + int32 GetVehicleNonDriveWheelSkidValue(float a1, int a2, int a3, int a4, float a5); // todo + + bool HasAirBrakes(int32 model) const; /// ok + + void Initialise(); /// ok + void InitialisePoliceRadio(); // todo + void InitialisePoliceRadioZones(); // todo + void InterrogateAudioEntities(); /// ok + bool IsAudioInitialised() const; /// ok + bool IsMissionAudioSampleFinished(); /// ok + bool IsMP3RadioChannelAvailable() const; + + bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; /// ok + + void PlayLoadedMissionAudio(); /// ok + void PlayOneShot(int32 index, int16 sound, float vol); // todo + uint32 PlaySuspectLastSeen(float x, float y, float z); // todo + void PlayerJustGotInCar() const; /// ok + void PlayerJustLeftCar() const; /// ok + void PostInitialiseGameSpecificSetup(); /// ok + void PostTerminateGameSpecificShutdown(); /// ok + void PreInitialiseGameSpecificSetup() const; + void PreloadMissionAudio(char *); // todo + void PreTerminateGameSpecificShutdown(); /// ok + /// processX - main logic of adding new sounds + void ProcessActiveQueues(); // todo + bool ProcessAirBrakes(cVehicleParams *params); /// ok + void ProcessAirportScriptObject(uint8 sound); /// ok + bool ProcessBoatEngine(cVehicleParams *params); /// ok + bool ProcessBoatMovingOverWater(cVehicleParams *params); /// ok + void ProcessBridge(); /// ok + void ProcessBridgeMotor(); /// ok + void ProcessBridgeOneShots(); /// ok + void ProcessBridgeWarning(); /// ok + bool ProcessCarBombTick(cVehicleParams *params); /// ok + void ProcessCesna(void *); // todo requires CPlane + void ProcessCinemaScriptObject(uint8 sound); /// ok + void ProcessCrane(); // todo requires CCrane + void ProcessDocksScriptObject(uint8 sound); /// ok + bool ProcessEngineDamage(cVehicleParams *params); /// ok + void ProcessEntity(int32 sound); /// ok + void ProcessExplosions(int32 explosion); /// ok + void ProcessFireHydrant(); /// ok + void ProcessFires(int32 entity); // todo requires gFireManager + void ProcessFrontEnd(); /// ok + void ProcessGarages(); // todo requires CGarages::aGarages + bool ProcessHelicopter(cVehicleParams *params); /// ok + void ProcessHomeScriptObject(uint8 sound); /// ok + void ProcessJumbo(cVehicleParams *); /// ok + void ProcessJumboAccel(CPlane *plane); /// ok + void ProcessJumboDecel(CPlane *plane); /// ok + void ProcessJumboFlying(); /// ok + void ProcessJumboLanding(CPlane *plane); /// ok + void ProcessJumboTakeOff(CPlane *plane); /// ok + void ProcessJumboTaxi(); /// ok + void ProcessLaunderetteScriptObject(uint8 sound); /// ok + void ProcessLoopingScriptObject(uint8 sound); /// ok + void ProcessMissionAudio(); /// ok + void ProcessModelCarEngine(cVehicleParams *params); /// ok (check float comparisons) + void ProcessOneShotScriptObject(uint8 sound); /// ok + void ProcessPed(CPhysical *ped); /// ok + void ProcessPedHeadphones(cPedParams *params); /// ok + void ProcessPedOneShots(cPedParams *params); // todo later (weird) + void ProcessPhysical(int32 id); /// ok + void ProcessPlane(cVehicleParams *params); /// ok + void ProcessPlayersVehicleEngine(cVehicleParams *params, + CAutomobile *automobile); /// ok (check float comparisons) + void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo + void ProcessPornCinema(uint8 sound); /// ok + void ProcessProjectiles(); // todo requires CProjectileInfo + void ProcessRainOnVehicle(cVehicleParams *params); /// ok + void ProcessReverb() const; /// ok + bool ProcessReverseGear(cVehicleParams *a2); /// ok + void ProcessSawMillScriptObject(uint8 sound); /// ok + void ProcessScriptObject(int32 id); /// ok + void ProcessShopScriptObject(uint8 sound); /// ok + void ProcessSpecial(); /// ok + bool ProcessTrainNoise(cVehicleParams *params); /// ok + void ProcessVehicle(CVehicle *); // todo + bool ProcessVehicleDoors(cVehicleParams *params); /// ok + // bool ProcessVehicleEngine(void *); + // void ProcessVehicleHorn(cVehicleParams *params); + // void ProcessVehicleOneShots(void *); + bool ProcessVehicleReverseWarning(cVehicleParams *params); /// ok + bool ProcessVehicleRoadNoise(cVehicleParams *params); /// ok + // void ProcessVehicleSirenOrAlarm(void *); + // void ProcessVehicleSkidding(void *); + void ProcessWaterCannon(int32); // todo + void ProcessWeather(int32 id); /// ok + bool ProcessWetRoadNoise(cVehicleParams *params); /// ok + void ProcessWorkShopScriptObject(uint8 sound); /// ok + + int32 RandomDisplacement(uint32 seed) const; + void ReacquireDigitalHandle() const; + void ReleaseDigitalHandle() const; + int32 ReportCollision(CEntity *a2, CEntity *a3, uint8 a4, uint8 a5, float a6, + float a7); // todo + int32 ReportCrime(int a2, int *a3); // todo + void ResetAudioLogicTimers(int32 timer); /// ok + void ResetPoliceRadio(); + void ResetTimers(unsigned int a2); // todo + + void Service(); // todo + void ServiceCollisions(); // todo + void ServicePoliceRadio(); // todo + void ServicePoliceRadioChannel(int a2); // todo + void ServiceSoundEffects(); // todo + void SetDynamicAcousticModelingStatus(bool status); + void SetEffectsFadeVolume(uint8 volume) const; + void SetEffectsMasterVolume(uint8 volume) const; + void SetEntityStatus(int32 id, bool status); + uint32 SetLoopingCollisionRequestedSfxFreqAndGetVol(int32); // todo + void SetMissionAudioLocation(float x, float y, float z); + void SetMissionScriptPoliceAudio(int32 sfx) const; + void SetMonoMode(uint8); // todo + void SetMusicFadeVolume(uint8 volume) const; + void SetMusicMasterVolume(uint8 volume) const; + void SetSpeakerConfig(int32 conf) const; + void SetUpLoopingCollisionSound(int a2, int a3); // todo + void SetUpOneShotCollisionSound(int a2); // todo + void SetupCrimeReport(); // todo + bool SetupJumboEngineSound(uint8, int32); // todo + bool SetupJumboFlySound(uint8 emittingVol); /// ok + bool SetupJumboRumbleSound(uint8 emittingVol); /// ok + bool SetupJumboTaxiSound(uint8 vol); /// ok + bool SetupJumboWhineSound(uint8 emittingVol, int32 freq); /// ok + void SetupPedComments(cPedParams *params, uint32 sound); /// ok + void SetupSuspectLastSeenReport(); // todo + + void Terminate(); + void TranslateEntity(CVector *v1, CVector *v2) const; /// ok + + void UpdateGasPedalAudio(CAutomobile *automobile); // todo hook + bool UsesReverseWarning(int32 model) const; + bool UsesSiren(int32 model) const; + bool UsesSirenSwitching(int32 model) const; +}; + +static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); + +extern cAudioManager &AudioManager; diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 076c1178..08ec3bc5 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -31,7 +31,7 @@ cDMAudio::Service(void) int32 cDMAudio::CreateEntity(eAudioType type, void *UID) { - return AudioManager.CreateEntity(type, UID); + return AudioManager.CreateEntity(type, (CPhysical *)UID); } void @@ -82,7 +82,7 @@ cDMAudio::SetEffectsFadeVol(uint8 volume) uint8 vol = volume; if ( vol > MAX_VOLUME ) vol = MAX_VOLUME; - AudioManager.SetEffectsFadeVol(vol); + AudioManager.SetEffectsFadeVolume(vol); } void @@ -91,7 +91,7 @@ cDMAudio::SetMusicFadeVol(uint8 volume) uint8 vol = volume; if ( vol > MAX_VOLUME ) vol = MAX_VOLUME; - AudioManager.SetMusicFadeVol(vol); + AudioManager.SetMusicFadeVolume(vol); } uint8 @@ -169,13 +169,13 @@ cDMAudio::IsAudioInitialised(void) void cDMAudio::ReportCrime(eCrimeType crime, CVector const &pos) { - AudioManager.ReportCrime(crime, pos); + AudioManager.ReportCrime(crime, &pos); } int32 cDMAudio::CreateLoopingScriptObject(cAudioScriptObject *scriptObject) { - int32 audioEntity = AudioManager.CreateEntity(AUDIOTYPE_SCRIPTOBJECT, scriptObject); + int32 audioEntity = AudioManager.CreateEntity(AUDIOTYPE_SCRIPTOBJECT, (CPhysical *)scriptObject); if ( AEHANDLE_IS_OK(audioEntity) ) AudioManager.SetEntityStatus(audioEntity, true); @@ -192,7 +192,7 @@ cDMAudio::DestroyLoopingScriptObject(int32 audioEntity) void cDMAudio::CreateOneShotScriptObject(cAudioScriptObject *scriptObject) { - int32 audioEntity = AudioManager.CreateEntity(AUDIOTYPE_SCRIPTOBJECT, scriptObject); + int32 audioEntity = AudioManager.CreateEntity(AUDIOTYPE_SCRIPTOBJECT, (CPhysical *)scriptObject); if ( AEHANDLE_IS_OK(audioEntity) ) { diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 677436a6..bcf94479 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -340,7 +340,7 @@ CCarCtrl::GenerateOneRandomCar() if (distanceBetweenNodes / 2 < carLength) positionBetweenNodes = 0.5f; else - positionBetweenNodes = Min(1.0f - carLength / distanceBetweenNodes, Max(carLength / distanceBetweenNodes, positionBetweenNodes)); + positionBetweenNodes = min(1.0f - carLength / distanceBetweenNodes, max(carLength / distanceBetweenNodes, positionBetweenNodes)); pCar->AutoPilot.m_nNextDirection = (curNodeId >= nextNodeId) ? 1 : -1; if (pCurNode->numLinks == 1){ /* Do not create vehicle if there is nowhere to go. */ @@ -793,10 +793,10 @@ CCarCtrl::FindMaximumSpeedForThisCarInTraffic(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = Max(0, CWorld::GetSectorIndexX(left)); - int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = Max(0, CWorld::GetSectorIndexY(top)); - int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = max(0, CWorld::GetSectorIndexX(left)); + int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = max(0, CWorld::GetSectorIndexY(top)); + int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -827,10 +827,10 @@ CCarCtrl::ScanForPedDanger(CVehicle* pVehicle) float right = pVehicle->GetPosition().x + DISTANCE_TO_SCAN_FOR_DANGER; float top = pVehicle->GetPosition().y - DISTANCE_TO_SCAN_FOR_DANGER; float bottom = pVehicle->GetPosition().y + DISTANCE_TO_SCAN_FOR_DANGER; - int xstart = Max(0, CWorld::GetSectorIndexX(left)); - int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); - int ystart = Max(0, CWorld::GetSectorIndexY(top)); - int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + int xstart = max(0, CWorld::GetSectorIndexX(left)); + int xend = min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = max(0, CWorld::GetSectorIndexY(top)); + int yend = min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); assert(xstart <= xend); assert(ystart <= yend); @@ -862,12 +862,12 @@ CCarCtrl::SlowCarOnRailsDownForTrafficAndLights(CVehicle* pVehicle) float curSpeed = pVehicle->AutoPilot.m_fMaxTrafficSpeed; if (maxSpeed >= curSpeed){ if (maxSpeed > curSpeed) - pVehicle->AutoPilot.ModifySpeed(Min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(min(maxSpeed, curSpeed + 0.05f * CTimer::GetTimeStep())); }else{ if (curSpeed == 0.0f) return; if (curSpeed >= 0.1f) - pVehicle->AutoPilot.ModifySpeed(Max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); + pVehicle->AutoPilot.ModifySpeed(max(maxSpeed, curSpeed - 0.5f * CTimer::GetTimeStep())); else if (curSpeed != 0.0f) /* no need to check */ pVehicle->AutoPilot.ModifySpeed(0.0f); } diff --git a/src/control/CarGen.cpp b/src/control/CarGen.cpp index f2b35547..65a23c8c 100644 --- a/src/control/CarGen.cpp +++ b/src/control/CarGen.cpp @@ -157,7 +157,7 @@ void CCarGenerator::Setup(float x, float y, float z, float angle, int32 mi, int1 m_bIsBlocking = false; m_vecInf = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.min; m_vecSup = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.max; - m_fSize = Max(m_vecInf.Magnitude(), m_vecSup.Magnitude()); + m_fSize = max(m_vecInf.Magnitude(), m_vecSup.Magnitude()); } bool CCarGenerator::CheckForBlockage() diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index 025db0c9..eb63b0b0 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -207,8 +207,8 @@ CPathFind::PreparePathData(void) numExtern++; if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes) numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes; - maxX = Max(maxX, Abs(InfoForTileCars[k].x)); - maxY = Max(maxY, Abs(InfoForTileCars[k].y)); + maxX = max(maxX, Abs(InfoForTileCars[k].x)); + maxY = max(maxY, Abs(InfoForTileCars[k].y)); }else if(InfoForTileCars[k].type == NodeTypeIntern) numIntern++; } @@ -392,7 +392,7 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor if(Abs(dx) < nearestDist){ dy = tempnodes[k].pos.y - CoorsXFormed.y; if(Abs(dy) < nearestDist){ - nearestDist = Max(Abs(dx), Abs(dy)); + nearestDist = max(Abs(dx), Abs(dy)); nearestId = k; } } @@ -501,13 +501,13 @@ CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoFor // Find i inside path segment iseg = 0; - for(j = Max(oldNumPathNodes, i-12); j < i; j++) + for(j = max(oldNumPathNodes, i-12); j < i; j++) if(m_pathNodes[j].objectIndex == m_pathNodes[i].objectIndex) iseg++; istart = 12*m_mapObjects[m_pathNodes[i].objectIndex]->m_modelIndex; // Add links to other internal nodes - for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){ + for(j = max(oldNumPathNodes, i-12); j < min(m_numPathNodes, i+12); j++){ if(m_pathNodes[i].objectIndex != m_pathNodes[j].objectIndex || i == j) continue; // N.B.: in every path segment, the externals have to be at the end diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index 03104307..be87eb2a 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -366,8 +366,8 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* main = RpAnimBlendClumpGetMainAssociation((RpClump*)ped->m_rwObject, &second, &blend_amount); if (main){ state->animId = main->animId; - state->time = 255.0f / 4.0f * Max(0.0f, Min(4.0f, main->currentTime)); - state->speed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, main->speed)); + state->time = 255.0f / 4.0f * max(0.0f, min(4.0f, main->currentTime)); + state->speed = 255.0f / 3.0f * max(0.0f, min(3.0f, main->speed)); }else{ state->animId = 3; state->time = 0; @@ -375,9 +375,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) } if (second) { state->secAnimId = second->animId; - state->secTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, second->currentTime)); - state->secSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, second->speed)); - state->blendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, blend_amount)); + state->secTime = 255.0f / 4.0f * max(0.0f, min(4.0f, second->currentTime)); + state->secSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, second->speed)); + state->blendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, blend_amount)); }else{ state->secAnimId = 0; state->secTime = 0; @@ -387,9 +387,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* partial = RpAnimBlendClumpGetMainPartialAssociation((RpClump*)ped->m_rwObject); if (partial) { state->partAnimId = partial->animId; - state->partAnimTime = 255.0f / 4.0f * Max(0.0f, Min(4.0f, partial->currentTime)); - state->partAnimSpeed = 255.0f / 3.0f * Max(0.0f, Min(3.0f, partial->speed)); - state->partBlendAmount = 255.0f / 2.0f * Max(0.0f, Min(2.0f, partial->blendAmount)); + state->partAnimTime = 255.0f / 4.0f * max(0.0f, min(4.0f, partial->currentTime)); + state->partAnimSpeed = 255.0f / 3.0f * max(0.0f, min(3.0f, partial->speed)); + state->partBlendAmount = 255.0f / 2.0f * max(0.0f, min(2.0f, partial->blendAmount)); }else{ state->partAnimId = 0; state->partAnimTime = 0; @@ -408,9 +408,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc){ state->aAnimId[i] = assoc->animId; - state->aCurTime[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); - state->aSpeed[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); - state->aBlendAmount[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); + state->aCurTime[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); + state->aSpeed[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); + state->aBlendAmount[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); state->aFlags[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID[i] = FindCBFunctionID(assoc->callback); @@ -431,9 +431,9 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainPartialAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc) { state->aAnimId2[i] = assoc->animId; - state->aCurTime2[i] = 255.0f / 4.0f * Max(0.0f, Min(4.0f, assoc->currentTime)); - state->aSpeed2[i] = 255.0f / 3.0f * Max(0.0f, Min(3.0f, assoc->speed)); - state->aBlendAmount2[i] = 255.0f / 2.0f * Max(0.0f, Min(2.0f, assoc->blendAmount)); + state->aCurTime2[i] = 255.0f / 4.0f * max(0.0f, min(4.0f, assoc->currentTime)); + state->aSpeed2[i] = 255.0f / 3.0f * max(0.0f, min(3.0f, assoc->speed)); + state->aBlendAmount2[i] = 255.0f / 2.0f * max(0.0f, min(2.0f, assoc->blendAmount)); state->aFlags2[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { state->aFunctionCallbackID2[i] = FindCBFunctionID(assoc->callback); @@ -625,9 +625,9 @@ void CReplay::StoreCarUpdate(CVehicle *vehicle, int id) vp->health = vehicle->m_fHealth / 4.0f; /* Not anticipated that health can be > 1000. */ vp->acceleration = vehicle->m_fGasPedal * 100.0f; vp->panels = vehicle->IsCar() ? ((CAutomobile*)vehicle)->Damage.m_panelStatus : 0; - vp->velocityX = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ - vp->velocityY = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().y)); - vp->velocityZ = 8000.0f * Max(-4.0f, Min(4.0f, vehicle->GetMoveSpeed().z)); + vp->velocityX = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().x)); /* 8000!? */ + vp->velocityY = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().y)); + vp->velocityZ = 8000.0f * max(-4.0f, min(4.0f, vehicle->GetMoveSpeed().z)); vp->mi = vehicle->GetModelIndex(); vp->primary_color = vehicle->m_currentColour1; vp->secondary_color = vehicle->m_currentColour2; @@ -1501,9 +1501,9 @@ void CReplay::ProcessLookAroundCam(void) --FramesActiveLookAroundCam; fBetaAngleLookAroundCam += x_moved; if (CPad::NewMouseControllerState.LMB && CPad::NewMouseControllerState.RMB) - fDistanceLookAroundCam = Max(3.0f, Min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); + fDistanceLookAroundCam = max(3.0f, min(15.0f, fDistanceLookAroundCam + 2.0f * y_moved)); else - fAlphaAngleLookAroundCam = Max(0.1f, Min(1.5f, fAlphaAngleLookAroundCam + y_moved)); + fAlphaAngleLookAroundCam = max(0.1f, min(1.5f, fAlphaAngleLookAroundCam + y_moved)); CVector camera_pt( fDistanceLookAroundCam * Sin(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), fDistanceLookAroundCam * Cos(fBetaAngleLookAroundCam) * Cos(fAlphaAngleLookAroundCam), diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 7e87fc6e..c81cd050 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1987,7 +1987,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS; car->m_status = STATUS_PHYSICS; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -1999,7 +1999,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CCarCtrl::JoinCarWithRoadSystem(car); car->AutoPilot.m_nCarMission = MISSION_CRUISE; car->bEngineOn = true; - car->AutoPilot.m_nCruiseSpeed = Max(car->AutoPilot.m_nCruiseSpeed, 6); + car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6); car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds(); return 0; } @@ -2083,7 +2083,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) CollectParameters(&m_nIp, 2); CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(car); - car->AutoPilot.m_nCruiseSpeed = Min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); + car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity); return 0; } case COMMAND_SET_CAR_DRIVING_STYLE: diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index f15232f3..cb16c3ad 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -209,7 +209,7 @@ WellBufferMe(float Target, float *CurrentValue, float *CurrentSpeed, float MaxSp else if(TargetSpeed > 0.0f && *CurrentSpeed > TargetSpeed) *CurrentSpeed = TargetSpeed; - *CurrentValue += *CurrentSpeed * Min(10.0f, CTimer::GetTimeStep()); + *CurrentValue += *CurrentSpeed * min(10.0f, CTimer::GetTimeStep()); } void @@ -697,7 +697,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl // Process height offset to avoid peds and cars float TargetZOffSet = m_fUnknownZOffSet + m_fDimensionOfHighestNearCar; - TargetZOffSet = Max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); + TargetZOffSet = max(TargetZOffSet, m_fPedBetweenCameraHeightOffset); float TargetHeight = CameraTarget.z + TargetZOffSet - Source.z; if(TargetHeight > m_fCamBufferedHeight){ @@ -753,7 +753,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl } } - TargetCoors.z += Min(1.0f, m_fCamBufferedHeight/2.0f); + TargetCoors.z += min(1.0f, m_fCamBufferedHeight/2.0f); m_cvecTargetCoorsForFudgeInter = TargetCoors; Front = TargetCoors - Source; @@ -991,7 +991,7 @@ CCam::WorkOutCamHeight(const CVector &TargetCoors, float TargetOrientation, floa } if(FoundCamRoof){ // Camera is under something - float roof = FoundRoofCenter ? Min(CamRoof, CarRoof) : CamRoof; + float roof = FoundRoofCenter ? min(CamRoof, CarRoof) : CamRoof; // Same weirdness again? TargetAlpha = CGeneral::GetATanOfXY(CA_MAX_DISTANCE, roof - CamTargetZ - 1.5f); CamClear = false; @@ -1249,7 +1249,7 @@ void CCam::Cam_On_A_String_Unobscured(const CVector &TargetCoors, float BaseDist) { CA_MAX_DISTANCE = BaseDist + 0.1f + TheCamera.CarZoomValueSmooth; - CA_MIN_DISTANCE = Min(BaseDist*0.6f, 3.5f); + CA_MIN_DISTANCE = min(BaseDist*0.6f, 3.5f); CVector Dist = Source - TargetCoors; diff --git a/src/core/Collision.cpp b/src/core/Collision.cpp index 538bcae6..66b29d9f 100644 --- a/src/core/Collision.cpp +++ b/src/core/Collision.cpp @@ -153,10 +153,10 @@ CCollision::LoadCollisionWhenINeedIt(bool forceChange) // on water we expect to be between levels multipleLevels = true; }else{ - xmin = Max(sx - 1, 0); - xmax = Min(sx + 1, NUMSECTORS_X-1); - ymin = Max(sy - 1, 0); - ymax = Min(sy + 1, NUMSECTORS_Y-1); + xmin = max(sx - 1, 0); + xmax = min(sx + 1, NUMSECTORS_X-1); + ymin = max(sy - 1, 0); + ymax = min(sy + 1, NUMSECTORS_Y-1); for(x = xmin; x <= xmax; x++) for(y = ymin; y <= ymax; y++){ diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index f4545f7b..effcb0b4 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -1030,7 +1030,7 @@ int CMenuManager::FadeIn(int alpha) m_nCurrScreen == MENUPAGE_SAVING_IN_PROGRESS || m_nCurrScreen == MENUPAGE_DELETING) return alpha; - return Min(m_nMenuFadeAlpha, alpha); + return min(m_nMenuFadeAlpha, alpha); } #endif diff --git a/src/core/IniFile.cpp b/src/core/IniFile.cpp index 46dceff3..08b30876 100644 --- a/src/core/IniFile.cpp +++ b/src/core/IniFile.cpp @@ -17,10 +17,10 @@ void CIniFile::LoadIniFile() if (f){ CFileMgr::ReadLine(f, gString, 200); sscanf(gString, "%f", &PedNumberMultiplier); - PedNumberMultiplier = Min(3.0f, Max(0.5f, PedNumberMultiplier)); + PedNumberMultiplier = min(3.0f, max(0.5f, PedNumberMultiplier)); CFileMgr::ReadLine(f, gString, 200); sscanf(gString, "%f", &CarNumberMultiplier); - CarNumberMultiplier = Min(3.0f, Max(0.5f, CarNumberMultiplier)); + CarNumberMultiplier = min(3.0f, max(0.5f, CarNumberMultiplier)); CFileMgr::CloseFile(f); } CPopulation::MaxNumberOfPedsInUse = 25.0f * PedNumberMultiplier; diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index b5086d64..f334a255 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -299,10 +299,10 @@ CControllerState CPad::ReconcileTwoControllersInput(CControllerState const &Stat { if ( State1.button || State2.button ) ReconState.button = 255; } #define _RECONCILE_AXIS_POSITIVE(axis) \ - { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = Max(State1.axis, State2.axis); } + { if ( State1.axis >= 0 && State2.axis >= 0 ) ReconState.axis = max(State1.axis, State2.axis); } #define _RECONCILE_AXIS_NEGATIVE(axis) \ - { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = Min(State1.axis, State2.axis); } + { if ( State1.axis <= 0 && State2.axis <= 0 ) ReconState.axis = min(State1.axis, State2.axis); } #define _RECONCILE_AXIS(axis) \ { _RECONCILE_AXIS_POSITIVE(axis); _RECONCILE_AXIS_NEGATIVE(axis); } diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 8158cd1d..a7bde91e 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1940,7 +1940,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())){ lodDistSq = sq(mi->GetLargestLodDistance()); - lodDistSq = Min(lodDistSq, sq(STREAM_DIST)); + lodDistSq = min(lodDistSq, sq(STREAM_DIST)); pos = CVector2D(e->GetPosition()); if(xmin < pos.x && pos.x < xmax && ymin < pos.y && pos.y < ymax && @@ -2160,20 +2160,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) if(Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y)){ // looking west/east - ymin = Max(iy - 10, 0); - ymax = Min(iy + 10, NUMSECTORS_Y); + ymin = max(iy - 10, 0); + ymax = min(iy + 10, NUMSECTORS_Y); assert(ymin <= ymax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().x > 0){ // looking east - xmax = Max(ix - 2, 0); - xmin = Max(ix - 10, 0); + xmax = max(ix - 2, 0); + xmin = max(ix - 10, 0); inc = 1; }else{ // looking west - xmax = Min(ix + 2, NUMSECTORS_X); - xmin = Min(ix + 10, NUMSECTORS_X); + xmax = min(ix + 2, NUMSECTORS_X); + xmin = min(ix + 10, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2189,13 +2189,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().x > 0){ // looking east - xmax = Max(ix + 10, 0); - xmin = Max(ix - 2, 0); + xmax = max(ix + 10, 0); + xmin = max(ix - 2, 0); inc = 1; }else{ // looking west - xmax = Min(ix - 10, NUMSECTORS_X); - xmin = Min(ix + 2, NUMSECTORS_X); + xmax = min(ix - 10, NUMSECTORS_X); + xmin = min(ix + 2, NUMSECTORS_X); inc = -1; } for(y = ymin; y <= ymax; y++){ @@ -2224,20 +2224,20 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) }else{ // looking north/south - xmin = Max(ix - 10, 0); - xmax = Min(ix + 10, NUMSECTORS_X); + xmin = max(ix - 10, 0); + xmax = min(ix + 10, NUMSECTORS_X); assert(xmin <= xmax); // Delete a block of sectors that we know is behind the camera if(TheCamera.GetForward().y > 0){ // looking north - ymax = Max(iy - 2, 0); - ymin = Max(iy - 10, 0); + ymax = max(iy - 2, 0); + ymin = max(iy - 10, 0); inc = 1; }else{ // looking south - ymax = Min(iy + 2, NUMSECTORS_Y); - ymin = Min(iy + 10, NUMSECTORS_Y); + ymax = min(iy + 2, NUMSECTORS_Y); + ymin = min(iy + 10, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ @@ -2253,13 +2253,13 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem) // Now a block that intersects with the camera's frustum if(TheCamera.GetForward().y > 0){ // looking north - ymax = Max(iy + 10, 0); - ymin = Max(iy - 2, 0); + ymax = max(iy + 10, 0); + ymin = max(iy - 2, 0); inc = 1; }else{ // looking south - ymax = Min(iy - 10, NUMSECTORS_Y); - ymin = Min(iy + 2, NUMSECTORS_Y); + ymax = min(iy - 10, NUMSECTORS_Y); + ymin = min(iy + 2, NUMSECTORS_Y); inc = -1; } for(x = xmin; x <= xmax; x++){ diff --git a/src/core/Wanted.cpp b/src/core/Wanted.cpp index daed9155..26b115e3 100644 --- a/src/core/Wanted.cpp +++ b/src/core/Wanted.cpp @@ -209,7 +209,7 @@ CWanted::ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesnt else sensitivity = m_fCrimeSensitivity; - wantedLevelDrop = Min(CCullZones::GetWantedLevelDrop(), 100); + wantedLevelDrop = min(CCullZones::GetWantedLevelDrop(), 100); chaos = (1.0f - wantedLevelDrop/100.0f) * sensitivity; if (policeDoesntCare) diff --git a/src/core/common.h b/src/core/common.h index d1f71720..b3a271c6 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -195,8 +195,8 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define BIT(num) (1<<(num)) -#define Max(a, b) (((a) > (b)) ? (a) : (b)) -#define Min(a, b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #define ABS(a) (((a) < 0) ? (-(a)) : (a)) #define norm(value, min, max) (((value) < (min)) ? 0 : (((value) > (max)) ? 1 : (((value) - (min)) / ((max) - (min))))) diff --git a/src/core/main.cpp b/src/core/main.cpp index a82a2ab8..50494ef3 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -453,7 +453,7 @@ DoFade(void) CRGBA fadeColor; CRect rect; int fadeValue = CDraw::FadeValue; - float brightness = Min(CMenuManager::m_PrefsBrightness, 256); + float brightness = min(CMenuManager::m_PrefsBrightness, 256); if(brightness <= 50) brightness = 50; if(FrontEndMenuManager.m_bMenuActive) diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index d59e6c59..fbd1322d 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -457,7 +457,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector & { float compression = 1.0f - springRatio; if(compression > 0.0f){ - float step = Min(CTimer::GetTimeStep(), 3.0f); + float step = min(CTimer::GetTimeStep(), 3.0f); float impulse = -GRAVITY*m_fMass*step * springConst * compression * bias*2.0f; ApplyMoveForce(springDir*impulse); ApplyTurnForce(springDir*impulse, point); @@ -471,12 +471,12 @@ CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &poin { float speedA = DotProduct(speed, springDir); float speedB = DotProduct(GetSpeed(point), springDir); - float step = Min(CTimer::GetTimeStep(), 3.0f); + float step = min(CTimer::GetTimeStep(), 3.0f); float impulse = -damping * (speedA + speedB)/2.0f * m_fMass * step * 0.53f; // what is this? float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass); - a = Min(a, 1.0f); + a = min(a, 1.0f); float b = Abs(impulse / (speedB * m_fMass)); if(a < b) impulse *= a/b; @@ -646,7 +646,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl // positive if B is moving towards A // not interested in how much B moves into A apparently? // only interested in cases where A collided into B - speedB = Max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); + speedB = max(0.0f, DotProduct(B->m_vecMoveSpeed, colpoint.normal)); // A has moved into B if(speedA < speedB){ if(!A->bHasHitWall) @@ -1147,18 +1147,18 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) CVector dir = A->GetPosition() - B->GetPosition(); dir.Normalise(); if(dir.z < 0.0f && dir.z < A->GetForward().z && dir.z < A->GetRight().z) - dir.z = Min(0.0f, Min(A->GetForward().z, A->GetRight().z)); + dir.z = min(0.0f, min(A->GetForward().z, A->GetRight().z)); shift += dir * colpoints[mostColliding].depth * 0.5f; }else if(A->IsPed() && B->IsVehicle() && ((CVehicle*)B)->IsBoat()){ CVector dir = colpoints[mostColliding].normal; - float f = Min(Abs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); shift += dir * colpoints[mostColliding].depth / (1.0f - f); boat = B; }else if(B->IsPed() && A->IsVehicle() && ((CVehicle*)A)->IsBoat()){ CVector dir = colpoints[mostColliding].normal * -1.0f; - float f = Min(Abs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); B->GetPosition() += dir * colpoints[mostColliding].depth / (1.0f - f); @@ -1246,7 +1246,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1268,7 +1268,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1301,7 +1301,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1328,7 +1328,7 @@ collision: float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1506,7 +1506,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); } }else{ for(i = 0; i < numCollisions; i++){ @@ -1527,7 +1527,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); float moveSpeedDiff = A->m_vecMoveSpeed.MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, imp, max(turnSpeedDiff, moveSpeedDiff)); float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions; @@ -1545,7 +1545,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) else if(A->GetUp().z > 0.3f) adhesion = 0.0f; else - adhesion *= Min(5.0f, 0.03f*impulseA + 1.0f); + adhesion *= min(5.0f, 0.03f*impulseA + 1.0f); } if(A->ApplyFriction(adhesion, aColPoints[i])) @@ -1594,7 +1594,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); } }else if(A->bHasContacted){ CVector savedMoveFriction = A->m_vecMoveFriction; @@ -1619,7 +1619,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1655,7 +1655,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1685,7 +1685,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float turnSpeedDiff = (B->m_vecTurnSpeed - A->m_vecTurnSpeed).MagnitudeSqr(); float moveSpeedDiff = (B->m_vecMoveSpeed - A->m_vecMoveSpeed).MagnitudeSqr(); - DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, Max(turnSpeedDiff, moveSpeedDiff)); + DMAudio.ReportCollision(A, B, aColPoints[i].surfaceA, aColPoints[i].surfaceB, impulseA, max(turnSpeedDiff, moveSpeedDiff)); if(A->ApplyFriction(B, CSurfaceTable::GetAdhesiveLimit(aColPoints[i])/numCollisions, aColPoints[i])){ A->bHasContacted = true; @@ -1831,7 +1831,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && (distSq >= sq(0.2f) || ped->IsPlayer())){ if(ped->IsPlayer()) - n = Max(NUMSTEPS(0.2f), 2.0); + n = max(NUMSTEPS(0.2f), 2.0); else n = NUMSTEPS(0.3f); step = savedTimeStep / n; @@ -1852,7 +1852,7 @@ CPhysical::ProcessCollision(void) speedDown = Multiply3x3(GetMatrix(), speedDown); speedUp = GetSpeed(speedUp); speedDown = GetSpeed(speedDown); - distSq = Max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); + distSq = max(speedUp.MagnitudeSqr(), speedDown.MagnitudeSqr()) * sq(CTimer::GetTimeStep()); if(distSq >= sq(0.3f)){ n = NUMSTEPS(0.3f); step = savedTimeStep / n; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 65bd696d..a590c1ed 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1792,7 +1792,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) neededPos.z = autoZPos.z; m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); @@ -1807,12 +1807,12 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = Min(m_pVehicleAnim->timeStep, 0.1f); + adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) { - neededPos.z = Max(currentZ, autoZPos.z); + neededPos.z = max(currentZ, autoZPos.z); } } } @@ -4771,12 +4771,12 @@ CPed::FightStrike(CVector &touchedNodePos) float moveMult; if (m_lastFightMove == FIGHTMOVE_GROUNDKICK) { - moveMult = Min(damageMult * 0.6f, 4.0f); + moveMult = min(damageMult * 0.6f, 4.0f); } else { if (nearPed->m_nPedState != PED_DIE || damageMult >= 20) { moveMult = damageMult; } else { - moveMult = Min(damageMult * 2.0f, 14.0f); + moveMult = min(damageMult * 2.0f, 14.0f); } } @@ -5434,7 +5434,7 @@ CPed::CreateDeadPedWeaponPickups(void) pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f; } if (found) - CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, Min(weaponAmmo, AmmoForWeapon_OnStreet[weapon])); + CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, min(weaponAmmo, AmmoForWeapon_OnStreet[weapon])); } ClearWeapons(); } @@ -5443,7 +5443,7 @@ void CPed::SetAttackTimer(uint32 time) { if (CTimer::GetTimeInMilliseconds() > m_attackTimer) - m_attackTimer = Max(m_lastHitTime, CTimer::GetTimeInMilliseconds()) + time; + m_attackTimer = max(m_lastHitTime, CTimer::GetTimeInMilliseconds()) + time; } void diff --git a/src/peds/PedPlacement.cpp b/src/peds/PedPlacement.cpp index d7b7ec75..8a40e56f 100644 --- a/src/peds/PedPlacement.cpp +++ b/src/peds/PedPlacement.cpp @@ -29,7 +29,7 @@ CPedPlacement::FindZCoorForPed(CVector* pos) if (CWorld::ProcessVerticalLine(vec, startZ, foundCol, foundEnt, true, false, false, false, true, false, nil)) foundColZ2 = foundCol.point.z; - zForPed = Max(foundColZ, foundColZ2); + zForPed = max(foundColZ, foundColZ2); if (zForPed > -99.0f) pos->z = 1.04f + zForPed; diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index a461301c..2884894c 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -388,7 +388,7 @@ CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, ms_colourBottom.b = topblue; ms_colourBottom.a = alpha; - botpos = Min(SCREEN_HEIGHT, topedge); + botpos = min(SCREEN_HEIGHT, topedge); CSprite2d::DrawRect(CRect(0, 0, SCREEN_WIDTH, botpos), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } @@ -415,18 +415,18 @@ CClouds::RenderHorizon(void) if(ms_horizonZ > SCREEN_HEIGHT) return; - float z1 = Min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); + float z1 = min(ms_horizonZ + SMALLSTRIPHEIGHT, SCREEN_HEIGHT); CSprite2d::DrawRectXLU(CRect(0, ms_horizonZ, SCREEN_WIDTH, z1), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); // This is just weird float a = SCREEN_HEIGHT/400.0f * HORIZSTRIPHEIGHT + - SCREEN_HEIGHT/300.0f * Max(TheCamera.GetPosition().z, 0.0f); + SCREEN_HEIGHT/300.0f * max(TheCamera.GetPosition().z, 0.0f); float b = TheCamera.GetUp().z < 0.0f ? SCREEN_HEIGHT : SCREEN_HEIGHT * Abs(TheCamera.GetRight().z); float z2 = z1 + (a + b)*TheCamera.LODDistMultiplier; - z2 = Min(z2, SCREEN_HEIGHT); + z2 = min(z2, SCREEN_HEIGHT); CSprite2d::DrawRect(CRect(0, z1, SCREEN_WIDTH, z2), ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); } diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 9881e764..1a6cfea3 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -109,7 +109,7 @@ CCoronas::Update(void) int i; static int LastCamLook = 0; - LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); + LightsMult = min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); int CamLook = 0; if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; @@ -121,7 +121,7 @@ CCoronas::Update(void) if(LastCamLook != CamLook) bChangeBrightnessImmediately = 3; else - bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); + bChangeBrightnessImmediately = max(bChangeBrightnessImmediately-1, 0); LastCamLook = CamLook; for(i = 0; i < NUMCORONAS; i++) @@ -309,7 +309,7 @@ CCoronas::Render(void) // render corona itself if(aCoronas[i].texture){ - float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; + float fogscale = CWeather::Foggyness*min(spriteCoors.z, 40.0f)/40.0f + 1.0f; if(CCoronas::aCoronas[i].id == SUN_CORE) spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); @@ -320,7 +320,7 @@ CCoronas::Render(void) float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; float hscale = 0.35f - (wscale - 0.5f) * 0.06f; - hscale = Max(hscale, 0.15f); + hscale = max(hscale, 0.15f); CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, spritew * aCoronas[i].size * wscale, @@ -467,7 +467,7 @@ CCoronas::RenderReflections(void) float spritew, spriteh; if(CSprite::CalcScreenCoors(coors, spriteCoors, &spritew, &spriteh, true)){ float drawDist = 0.75f * aCoronas[i].drawDist; - drawDist = Min(drawDist, 50.0f); + drawDist = min(drawDist, 50.0f); if(spriteCoors.z < drawDist){ float fadeDistance = drawDist / 2.0f; float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; @@ -546,25 +546,25 @@ CRegisteredCorona::Update(void) (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ // Corona is blocked, fade out - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else if(offScreen){ // Same when off screen - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); }else{ // Visible if(alpha > fadeAlpha){ // fade in - fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); if(CCoronas::bChangeBrightnessImmediately) fadeAlpha = alpha; }else if(alpha < fadeAlpha){ // too visible, decrease alpha but not below alpha - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); + fadeAlpha = max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); } // darken scene when the sun is visible if(id == CCoronas::SUN_CORONA) - CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); + CCoronas::LightsMult = max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); } // remove if invisible diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp index 85d7ba13..cd83a898 100644 --- a/src/render/Lights.cpp +++ b/src/render/Lights.cpp @@ -37,9 +37,9 @@ SetLightsWithTimeOfDayColour(RpWorld *) AmbientLightColourForFrame.green = 1.0f; AmbientLightColourForFrame.blue = 1.0f; } - AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame.red*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame.green*1.3f); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame.blue*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame.red*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame.green*1.3f); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame.blue*1.3f); RpLightSetColor(pAmbient, &AmbientLightColourForFrame); } @@ -70,16 +70,16 @@ SetLightsWithTimeOfDayColour(RpWorld *) float f1 = 2.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; float f2 = 3.0f * (CMenuManager::m_PrefsBrightness/256.0f - 1.0f) * 0.6f + 1.0f; - AmbientLightColourForFrame.red = Min(1.0f, AmbientLightColourForFrame.red * f2); - AmbientLightColourForFrame.green = Min(1.0f, AmbientLightColourForFrame.green * f2); - AmbientLightColourForFrame.blue = Min(1.0f, AmbientLightColourForFrame.blue * f2); - AmbientLightColourForFrame_PedsCarsAndObjects.red = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.green = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); - AmbientLightColourForFrame_PedsCarsAndObjects.blue = Min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); + AmbientLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f2); + AmbientLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f2); + AmbientLightColourForFrame.blue = min(1.0f, AmbientLightColourForFrame.blue * f2); + AmbientLightColourForFrame_PedsCarsAndObjects.red = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.red * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.green = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.green * f1); + AmbientLightColourForFrame_PedsCarsAndObjects.blue = min(1.0f, AmbientLightColourForFrame_PedsCarsAndObjects.blue * f1); #ifdef FIX_BUGS - DirectionalLightColourForFrame.red = Min(1.0f, DirectionalLightColourForFrame.red * f1); - DirectionalLightColourForFrame.green = Min(1.0f, DirectionalLightColourForFrame.green * f1); - DirectionalLightColourForFrame.blue = Min(1.0f, DirectionalLightColourForFrame.blue * f1); + DirectionalLightColourForFrame.red = min(1.0f, DirectionalLightColourForFrame.red * f1); + DirectionalLightColourForFrame.green = min(1.0f, DirectionalLightColourForFrame.green * f1); + DirectionalLightColourForFrame.blue = min(1.0f, DirectionalLightColourForFrame.blue * f1); #else DirectionalLightColourForFrame.red = min(1.0f, AmbientLightColourForFrame.red * f1); DirectionalLightColourForFrame.green = min(1.0f, AmbientLightColourForFrame.green * f1); @@ -193,7 +193,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwRGBAReal color; RwV3d *dir; - strength = Max(Max(red, green), blue); + strength = max(max(red, green), blue); n = -1; if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) n = NumExtraDirLightsInWorld; @@ -221,7 +221,7 @@ AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, f RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); LightStrengths[n] = strength; - NumExtraDirLightsInWorld = Min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); + NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); } void diff --git a/src/render/ParticleMgr.cpp b/src/render/ParticleMgr.cpp index 9381787c..7a1804de 100644 --- a/src/render/ParticleMgr.cpp +++ b/src/render/ParticleMgr.cpp @@ -91,7 +91,7 @@ void cParticleSystemMgr::LoadParticleData() break; case CFG_PARAM_INITIAL_COLOR_VARIATION: - entry->m_InitialColorVariation = Min(atoi(value), 100); + entry->m_InitialColorVariation = min(atoi(value), 100); break; case CFG_PARAM_FADE_DESTINATION_COLOR_R: diff --git a/src/render/PointLights.cpp b/src/render/PointLights.cpp index 8e942ce6..a015ec54 100644 --- a/src/render/PointLights.cpp +++ b/src/render/PointLights.cpp @@ -98,7 +98,7 @@ CPointLights::GenerateLightsAffectingObject(CVector *objCoors) if(aLights[i].type == LIGHT_DIRECTIONAL){ float dot = -DotProduct(dir, aLights[i].dir); - intensity *= Max((dot-0.5f)*2.0f, 0.0f); + intensity *= max((dot-0.5f)*2.0f, 0.0f); } if(intensity > 0.0f) diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index b5147f02..4d2e4605 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -727,10 +727,10 @@ CShadows::RenderStoredShadows(void) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -873,10 +873,10 @@ CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) float fStartY = shadowPos.y - fHeight; float fEndY = shadowPos.y + fHeight; - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + int32 nStartX = max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); CWorld::AdvanceCurrentScanCode(); @@ -1016,11 +1016,11 @@ CShadows::CastShadowEntity(CEntity *pEntity, float fStartX, float fStartY, floa Points[3].x = (fLengthRight - fFrontRight) - fSideRight; Points[3].y = (fLengthForward - fFrontForward) - fSideForward; - float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); - float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); + float MinX = min(min(Points[0].x, Points[1].x), min(Points[2].x, Points[3].x)); + float MaxX = max(max(Points[0].x, Points[1].x), max(Points[2].x, Points[3].x)); - float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); - float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); + float MinY = min(min(Points[0].y, Points[1].y), min(Points[2].y, Points[3].y)); + float MaxY = max(max(Points[0].y, Points[1].y), max(Points[2].y, Points[3].y)); float MaxZ = pPosn->z - pEntity->GetPosition().z; float MinZ = MaxZ - fZDistance; @@ -1767,7 +1767,7 @@ CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTextur { ASSERT(pPosn != NULL); - C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, Max(fFrontX, -fSideY), + C3dMarkers::PlaceMarkerSet(nID, _TODOCONST(4), *pPosn, max(fFrontX, -fSideY), 0, 128, 255, 128, 2048, 0.2f, 0); } diff --git a/src/render/Timecycle.cpp b/src/render/Timecycle.cpp index 0113c001..7ab3e91e 100644 --- a/src/render/Timecycle.cpp +++ b/src/render/Timecycle.cpp @@ -290,7 +290,7 @@ CTimeCycle::Update(void) TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL); if(m_FogReduction != 0) - m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); + m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; @@ -311,9 +311,9 @@ CTimeCycle::Update(void) if(TheCamera.GetForward().z < -0.9f || !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) - m_FogReduction = Min(m_FogReduction+1, 64); + m_FogReduction = min(m_FogReduction+1, 64); else - m_FogReduction = Max(m_FogReduction-1, 0); + m_FogReduction = max(m_FogReduction-1, 0); } STARTPATCHES diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index c711c8c8..a1c2af93 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -979,7 +979,7 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col SMALL_SECTOR_SIZE / 2, apBoatList) ) { - float fWakeColor = fAdd1 - Max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); + float fWakeColor = fAdd1 - max(255.0f - float(color.blue + color.red + color.green) / 3, fAdd2); RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); RpGeometry *geom = apGeomArray[nGeomUsed++]; @@ -1035,9 +1035,9 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col RwRGBAAssign(&wakeColor, &color); - wakeColor.red = Min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); - wakeColor.green = Min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); - wakeColor.blue = Min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); + wakeColor.red = min(color.red + int32(fWakeColor * fRedMult * fDistMult), 255); + wakeColor.green = min(color.green + int32(fWakeColor * fGreenMult * fDistMult), 255); + wakeColor.blue = min(color.blue + int32(fWakeColor * fBlueMult * fDistMult), 255); RwRGBAAssign(&geomPreLights[9*i+j], &wakeColor); @@ -1114,7 +1114,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) fSectorY + SMALL_SECTOR_SIZE - fY ); - fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); + fDistSqr = min(vecDist.MagnitudeSqr(), fDistSqr); } } } diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 99354d70..5a788945 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -691,7 +691,7 @@ CAutomobile::ProcessControl(void) if(m_aSuspensionSpringRatio[i] < 1.0f) m_aWheelTimer[i] = 4.0f; else - m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); + m_aWheelTimer[i] = max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f); if(m_aWheelTimer[i] > 0.0f){ m_nWheelsOnGround++; @@ -1009,7 +1009,7 @@ CAutomobile::ProcessControl(void) if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){ if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.0005f, 0.0f); + m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.0005f, 0.0f); }else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) && m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){ FlyingControl(FLIGHT_MODEL_DODO); @@ -1017,7 +1017,7 @@ CAutomobile::ProcessControl(void) FlyingControl(FLIGHT_MODEL_HELI); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ if(CPad::GetPad(0)->GetCircleJustDown()) - m_aWheelSpeed[0] = Max(m_aWheelSpeed[0]-0.03f, 0.0f); + m_aWheelSpeed[0] = max(m_aWheelSpeed[0]-0.03f, 0.0f); if(m_aWheelSpeed[0] < 0.22f) m_aWheelSpeed[0] += 0.0001f; if(m_aWheelSpeed[0] > 0.15f) @@ -1129,10 +1129,10 @@ CAutomobile::ProcessControl(void) if(speed > sq(0.1f)){ speed = Sqrt(speed); if(suspShake > 0.0f){ - uint8 freq = Min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = min(200.0f*suspShake*speed*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(20000.0f*CTimer::GetTimeStep()/freq, freq); }else{ - uint8 freq = Min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); + uint8 freq = min(200.0f*surfShake*speed*2000.0f/m_fMass + 40.0f, 145.0f); CPad::GetPad(0)->StartShake(5000.0f*CTimer::GetTimeStep()/freq, freq); } } @@ -2588,7 +2588,7 @@ CAutomobile::HydraulicControl(void) float minz = pos.z + extendedLowerLimit - wheelRadius; if(minz < specialColModel->boundingBox.min.z) specialColModel->boundingBox.min.z = minz; - float radius = Max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); + float radius = max(specialColModel->boundingBox.min.Magnitude(), specialColModel->boundingBox.max.Magnitude()); if(specialColModel->boundingSphere.radius < radius) specialColModel->boundingSphere.radius = radius; @@ -2687,10 +2687,10 @@ CAutomobile::HydraulicControl(void) float front = -rear; float right = CPad::GetPad(0)->GetCarGunLeftRight()/128.0f; float left = -right; - suspChange[CARWHEEL_FRONT_LEFT] = Max(front+left, 0.0f); - suspChange[CARWHEEL_REAR_LEFT] = Max(rear+left, 0.0f); - suspChange[CARWHEEL_FRONT_RIGHT] = Max(front+right, 0.0f); - suspChange[CARWHEEL_REAR_RIGHT] = Max(rear+right, 0.0f); + suspChange[CARWHEEL_FRONT_LEFT] = max(front+left, 0.0f); + suspChange[CARWHEEL_REAR_LEFT] = max(rear+left, 0.0f); + suspChange[CARWHEEL_FRONT_RIGHT] = max(front+right, 0.0f); + suspChange[CARWHEEL_REAR_RIGHT] = max(rear+right, 0.0f); if(m_hydraulicState < 100){ // Lowered, move wheels up @@ -2806,7 +2806,7 @@ CAutomobile::ProcessBuoyancy(void) ApplyTurnForce(impulse, point); CVector initialSpeed = m_vecMoveSpeed; - float timeStep = Max(CTimer::GetTimeStep(), 0.01f); + float timeStep = max(CTimer::GetTimeStep(), 0.01f); float impulseRatio = impulse.z / (GRAVITY * m_fMass * timeStep); float waterResistance = Pow(1.0f - 0.05f*impulseRatio, CTimer::GetTimeStep()); m_vecMoveSpeed *= waterResistance; @@ -2899,7 +2899,7 @@ CAutomobile::ProcessBuoyancy(void) float fSpeed = vSpeed.MagnitudeSqr(); if(fSpeed > sq(0.05f)){ fSpeed = Sqrt(fSpeed); - float size = Min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); + float size = min((fSpeed < 0.15f ? 0.25f : 0.75f)*fSpeed, 0.6f); CVector right = 0.2f*fSpeed*GetRight() + 0.2f*vSpeed; CParticle::AddParticle(PARTICLE_PED_SPLASH, @@ -2981,11 +2981,11 @@ CAutomobile::DoDriveByShootings(void) // TODO: what is this? if(!lookingLeft && m_weaponDoorTimerLeft > 0.0f){ - m_weaponDoorTimerLeft = Max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerLeft = max(m_weaponDoorTimerLeft - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_LF, NUM_ANIMS, m_weaponDoorTimerLeft); } if(!lookingRight && m_weaponDoorTimerRight > 0.0f){ - m_weaponDoorTimerRight = Max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); + m_weaponDoorTimerRight = max(m_weaponDoorTimerRight - CTimer::GetTimeStep()*0.1f, 0.0f); ProcessOpenDoor(CAR_DOOR_RF, NUM_ANIMS, m_weaponDoorTimerRight); } } @@ -3133,7 +3133,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) FindPlayerPed()->SetWantedLevelNoDrop(1); if(m_status == STATUS_PLAYER && impulse > 50.0f){ - uint8 freq = Min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); + uint8 freq = min(0.4f*impulse*2000.0f/m_fMass + 100.0f, 250.0f); CPad::GetPad(0)->StartShake(40000/freq, freq); } @@ -3286,7 +3286,7 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece) if(m_pDamageEntity && m_pDamageEntity == FindPlayerVehicle() && impulse > 10.0f){ int money = (doubleMoney ? 2 : 1) * impulse*pHandling->nMonetaryValue/1000000.0f; - money = Min(money, 40); + money = min(money, 40); if(money > 2){ sprintf(gString, "$%d", money); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += money; @@ -3989,7 +3989,7 @@ CAutomobile::SetupSuspensionLines(void) // adjust col model to include suspension lines if(colModel->boundingBox.min.z > colModel->lines[0].p1.z) colModel->boundingBox.min.z = colModel->lines[0].p1.z; - float radius = Max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); + float radius = max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude()); if(colModel->boundingSphere.radius < radius) colModel->boundingSphere.radius = radius; diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index 2b5ff567..f614b78f 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -61,7 +61,7 @@ float CBoat::IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat) float fDist = vecDist.MagnitudeSqr(); if ( fDist < SQR(fMaxDist) ) - return 1.0f - Min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); + return 1.0f - min(fRangeMult * Sqrt(fDist / SQR(fMaxDist)) + (WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[i]) * fTimeMult, 1.0f); } return 0.0f; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index 39fc7ec4..aab9dd0d 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -223,19 +223,19 @@ CHeli::ProcessControl(void) switch(m_heliStatus){ case HELI_STATUS_HOVER: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f; + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f; break; case HELI_STATUS_SHOT_DOWN: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; break; case HELI_STATUS_HOVER2: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = Max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; + m_fTargetZ = max(groundZ, m_fTargetZ) + 8.0f + m_fTargetOffset; break; default: groundZ = CWorld::FindGroundZFor3DCoord(GetPosition().x, GetPosition().y, 1000.0f, nil); - m_fTargetZ = Max(groundZ, m_fTargetZ) + 12.0f; + m_fTargetZ = max(groundZ, m_fTargetZ) + 12.0f; break; } @@ -994,7 +994,7 @@ CHeli::TestBulletCollision(CVector *line0, CVector *line1, CVector *bulletPos, i float distToHeli = (pHelis[i]->GetPosition() - *line0).Magnitude(); CVector line = (*line1 - *line0); float lineLength = line.Magnitude(); - *bulletPos = *line0 + line*Max(1.0f, distToHeli-5.0f); + *bulletPos = *line0 + line*max(1.0f, distToHeli-5.0f); pHelis[i]->m_nBulletDamage += damage; diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 0355cba1..4795a29f 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -273,7 +273,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon right = -contactSpeedRight/wheelsOnGround; if(wheelStatus == WHEEL_STATUS_BURST){ - float fwdspeed = Min(contactSpeedFwd, 0.3f); + float fwdspeed = min(contactSpeedFwd, 0.3f); right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); } } @@ -363,7 +363,7 @@ CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVec void CVehicle::ExtinguishCarFire(void) { - m_fHealth = Max(m_fHealth, 300.0f); + m_fHealth = max(m_fHealth, 300.0f); if(m_pCarFire) m_pCarFire->Extinguish(); if(IsCar()){ @@ -638,13 +638,13 @@ CVehicle::SetDriver(CPed *driver) if(bFreebies && driver == FindPlayerPed()){ if(GetModelIndex() == MI_AMBULAN) - FindPlayerPed()->m_fHealth = Min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); + FindPlayerPed()->m_fHealth = min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); else if(GetModelIndex() == MI_TAXI) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; else if(GetModelIndex() == MI_POLICE) driver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5); else if(GetModelIndex() == MI_ENFORCER) - driver->m_fArmour = Max(driver->m_fArmour, 100.0f); + driver->m_fArmour = max(driver->m_fArmour, 100.0f); else if(GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE) CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; bFreebies = false; -- cgit v1.2.3 From 5a36d466929ac9ba5612d577904773e3bd58bfe5 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 27 Aug 2019 22:46:41 +0200 Subject: Audio fixes --- src/audio/AudioManager.cpp | 42 ++- src/audio/AudioManager.h | 12 +- src/audio/AudioManager.h.autosave | 549 -------------------------------------- src/audio/DMAudio.cpp | 5 +- src/audio/DMAudio.h | 3 + src/audio/sampman.cpp | 35 ++- src/control/PathFind.cpp | 57 ++-- 7 files changed, 95 insertions(+), 608 deletions(-) delete mode 100644 src/audio/AudioManager.h.autosave (limited to 'src') diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 1e4b9c3b..d32d4207 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -498,7 +498,7 @@ cAudioManager::CreateEntity(int32 type, CPhysical *entity) m_asAudioEntities[i].m_bIsUsed = true; m_asAudioEntities[i].m_bStatus = 0; m_asAudioEntities[i].m_nType = (eAudioType)type; - m_asAudioEntities[i].m_pEntity = (void*)entity; + m_asAudioEntities[i].m_pEntity = (void *)entity; m_asAudioEntities[i].m_awAudioEvent[0] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[1] = SOUND_TOTAL_PED_SOUNDS; m_asAudioEntities[i].m_awAudioEvent[2] = SOUND_TOTAL_PED_SOUNDS; @@ -2823,7 +2823,6 @@ cAudioManager::GetNum3DProvidersAvailable() const return 0; } - int32 cAudioManager::GetPedCommentSfx(CPed *ped, int32 sound) { @@ -3038,6 +3037,13 @@ cAudioManager::PlayOneShot(int32 index, int16 sound, float vol) EAXJMP(0x57A500); } +WRAPPER +uint32 +cAudioManager::PlaySuspectLastSeen(float x, float y, float z) +{ + EAXJMP(0x580500); +} + void cAudioManager::PlayerJustGotInCar() const { @@ -3092,7 +3098,6 @@ cAudioManager::PostTerminateGameSpecificShutdown() ; } - void cAudioManager::PreInitialiseGameSpecificSetup() const { @@ -3100,6 +3105,13 @@ cAudioManager::PreInitialiseGameSpecificSetup() const BankStartOffset[1] = AUDIO_SAMPLE_POLICE_COP_1_ARREST_1; } +WRAPPER +void +cAudioManager::PreloadMissionAudio(char *) +{ + EAXJMP(0x579550); +} + void cAudioManager::PreTerminateGameSpecificShutdown() { @@ -7790,6 +7802,20 @@ cAudioManager::ReleaseDigitalHandle() const if(m_bIsInitialised) { SampleManager.ReleaseDigitalHandle(); } } +WRAPPER +int32 +cAudioManager::ReportCollision(CEntity *a2, CEntity *a3, uint8 a4, uint8 a5, float a6, float a7) +{ + EAXJMP(0x568410); +} + +WRAPPER +int32 +cAudioManager::ReportCrime(eCrimeType crime, const CVector *pos) +{ + EAXJMP(0x5803D0); +} + void cAudioManager::ResetAudioLogicTimers(int32 timer) { @@ -7824,12 +7850,21 @@ cAudioManager::ResetPoliceRadio() } } +WRAPPER +void +cAudioManager::ResetTimers(uint32 a2) +{ + EAXJMP(0x57A7B0); +} + WRAPPER void cAudioManager::Service() { EAXJMP(0x57A2A0); } +WRAPPER +int8 cAudioManager::SetCurrent3DProvider(uint8) { EAXJMP(0x57A910); } void cAudioManager::SetDynamicAcousticModelingStatus(bool status) @@ -7891,7 +7926,6 @@ cAudioManager::SetMusicMasterVolume(uint8 volume) const SampleManager.SetMusicMasterVolume(volume); } - void cAudioManager::SetSpeakerConfig(int32 conf) const { diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index c765bfd4..fb462e94 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -502,18 +502,18 @@ public: void ReacquireDigitalHandle() const; void ReleaseDigitalHandle() const; int32 ReportCollision(CEntity *a2, CEntity *a3, uint8 a4, uint8 a5, float a6, - float a7); // todo - int32 ReportCrime(int a2, int *a3); // todo - void ResetAudioLogicTimers(int32 timer); /// ok - void ResetPoliceRadio(); - void ResetTimers(unsigned int a2); // todo + float a7); // todo + int32 ReportCrime(eCrimeType crime, const CVector *pos); // todo + void ResetAudioLogicTimers(int32 timer); /// ok + void ResetPoliceRadio(); /// ok + void ResetTimers(uint32 a2); // todo void Service(); // todo void ServiceCollisions(); // todo void ServicePoliceRadio(); // todo void ServicePoliceRadioChannel(int a2); // todo void ServiceSoundEffects(); // todo - void SetCurrent3DProvider(uint8); + int8 SetCurrent3DProvider(uint8); // todo void SetDynamicAcousticModelingStatus(bool status); void SetEffectsFadeVolume(uint8 volume) const; void SetEffectsMasterVolume(uint8 volume) const; diff --git a/src/audio/AudioManager.h.autosave b/src/audio/AudioManager.h.autosave deleted file mode 100644 index 2ea78476..00000000 --- a/src/audio/AudioManager.h.autosave +++ /dev/null @@ -1,549 +0,0 @@ -#pragma once - -#include "AudioSamples.h" -#include "DMAudio.h" -#include "common.h" - -class tActiveSample -{ -public: - int32 m_nEntityIndex; - int32 m_counter; - int32 m_nSampleIndex; - uint8 m_bBankIndex; - uint8 m_bIsDistant; - uint8 field_14; - uint8 field_15; - int32 field_16; - int32 m_nFrequency; - uint8 m_bVolume; - uint8 field_25; - uint8 field_26; - uint8 field_27; - float m_fDistance; - int32 m_nLoopCount; - int32 m_nLoopStart; - int32 m_nLoopEnd; - uint8 m_bEmittingVolume; - uint8 field_45; - uint8 field_46; - uint8 field_47; - float field_48; - float m_fSoundIntensity; - uint8 field_56; - uint8 field_57; - uint8 field_58; - uint8 field_59; - CVector m_vecPos; - uint8 m_bReverbFlag; - uint8 m_bLoopsRemaining; - uint8 m_bRequireReflection; - uint8 m_bOffset; - int32 field_76; - uint8 m_bIsProcessed; - uint8 m_bLoopEnded; - uint8 field_82; - uint8 field_83; - int32 calculatedVolume; - uint8 field_88; - uint8 field_89; - uint8 field_90; - uint8 field_91; - - // no methods -}; - -static_assert(sizeof(tActiveSample) == 92, "tActiveSample: error"); - -enum eAudioType : int32 { - AUDIOTYPE_PHYSICAL = 0, - AUDIOTYPE_EXPLOSION = 1, - AUDIOTYPE_FIRE = 2, - AUDIOTYPE_WEATHER = 3, - AUDIOTYPE_CRANE = 4, - AUDIOTYPE_SCRIPTOBJECT = 5, - AUDIOTYPE_BRIDGE = 6, - AUDIOTYPE_COLLISION = 7, - AUDIOTYPE_FRONTEND = 8, - AUDIOTYPE_PROJECTILE = 9, - AUDIOTYPE_GARAGE = 10, - AUDIOTYPE_FIREHYDRANT = 11, - AUDIOTYPE_WATERCANNON = 12, - AUDIOTYPE_POLICERADIO = 13, - TOTAL_AUDIO_TYPES = 14, -}; - -class CPhysical; -class CAutomobile; - -class tAudioEntity -{ -public: - eAudioType m_nType; - void *m_pEntity; - bool m_bIsUsed; - uint8 m_bStatus; - int16 m_awAudioEvent[4]; - uint8 gap_18[2]; - float m_afVolume[4]; - uint8 m_Loops; - uint8 field_25[3]; - - // no methods -}; - -static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error"); - -class tPedComment -{ -public: - int32 m_nSampleIndex; - int32 m_entityIndex; - CVector m_vecPos; - float m_fDistance; - uint8 m_bVolume; - int8 field_25; // allocated time? - uint8 gap_26[2]; - - // no methods -}; - -static_assert(sizeof(tPedComment) == 28, "tPedComment: error"); - -class cPedComments -{ -public: - tPedComment m_asPedComments[2][20]; - uint8 indexMap[2][20]; - uint8 nrOfCommentsInBank[2]; - uint8 activeBank; - uint8 gap_1163[1]; - - // reversed all methods - void Add(tPedComment *com); /// ok - void Process(); /// ok -}; - -static_assert(sizeof(cPedComments) == 1164, "cPedComments: error"); - -class CEntity; - -class cAudioCollision -{ -public: - CEntity *m_pEntity1; - CEntity *m_pEntity2; - uint8 m_bSurface1; - uint8 m_bSurface2; - uint8 field_10; - uint8 field_11; - float m_fIntensity1; - float m_fIntensity2; - CVector m_vecPosition; - float m_fDistance; - int32 m_nBaseVolume; - - // no methods -}; - -static_assert(sizeof(cAudioCollision) == 40, "cAudioCollision: error"); - -class cAudioCollisionManager -{ -public: - cAudioCollision m_asCollisions1[10]; - cAudioCollision m_asCollisions2[10]; - uint8 m_bIndicesTable[10]; - uint8 m_bCollisionsInQueue; - uint8 gap_811; - cAudioCollision m_sQueue; - - void AddCollisionToRequestedQueue(); // todo -}; - -static_assert(sizeof(cAudioCollisionManager) == 852, "cAudioCollisionManager: error"); - -class cMissionAudio -{ -public: - CVector m_vecPos; - uint8 field_12; - uint8 gap_13[3]; - int m_nSampleIndex; - uint8 m_bLoadingStatus; - uint8 m_bPlayStatus; - uint8 field_22; - uint8 field_23; - int field_24; - bool m_bIsPlayed; - uint8 field_29; - uint8 field_30; - uint8 field_31; - // no methods -}; - -static_assert(sizeof(cMissionAudio) == 32, "cMissionAudio: error"); - -class cVehicleParams; -class CPlane; -class CVehicle; -class CPed; -class cPedParams; -class cTransmission; - -class cAudioScriptObject { -public: - int16 AudioId; - char _pad0[2]; - CVector Posn; - int32 AudioEntity; - - static void *operator new(size_t); - static void *operator new(size_t, int); - static void operator delete(void *, size_t); - static void operator delete(void *, int); -}; - -static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error"); - -enum { - /* - REFLECTION_YMAX = 0, top - REFLECTION_YMIN = 1, bottom - REFLECTION_XMIN = 2, left - REFLECTION_XMAX = 3, right - REFLECTION_ZMAX = 4, - */ - - REFLECTION_TOP = 0, - REFLECTION_BOTTOM, - REFLECTION_LEFT, - REFLECTION_RIGHT, - REFLECTION_UP, - MAX_REFLECTIONS, -}; - -enum AudioEntityHandle -{ - AEHANDLE_NONE = -5, - AEHANDLE_ERROR_NOAUDIOSYS = -4, - AEHANDLE_ERROR_NOFREESLOT = -3, - AEHANDLE_ERROR_NOENTITY = -2, - AEHANDLE_ERROR_BADAUDIOTYPE = -1, -}; - -class cAudioManager -{ -public: - bool m_bIsInitialised; - uint8 field_1; - uint8 field_2; - uint8 m_bActiveSamples; - uint8 field_4; - bool m_bDynamicAcousticModelingStatus; - uint8 field_6; - uint8 field_7; - float speedOfSound; - bool m_bTimerJustReset; - uint8 field_13; - uint8 field_14; - uint8 field_15; - int32 m_nTimer; - tActiveSample m_sQueueSample; - uint8 m_bActiveSampleQueue; - uint8 gap_109[3]; - tActiveSample m_asSamples[2][27]; - uint8 m_abSampleQueueIndexTable[2][27]; - uint8 m_bSampleRequestQueuesStatus[2]; - tActiveSample m_asActiveSamples[27]; - tAudioEntity m_asAudioEntities[200]; - int32 m_anAudioEntityIndices[200]; - int32 m_nAudioEntitiesTotal; - CVector m_avecReflectionsPos[5]; - float m_afReflectionsDistances[5]; - int32 m_anScriptObjectEntityIndices[40]; - int32 m_nScriptObjectEntityTotal; - cPedComments m_sPedComments; - int32 m_nFireAudioEntity; - int32 m_nWaterCannonEntity; - int32 m_nPoliceChannelEntity; - uint8 gap45B8[444]; - int32 m_nFrontEndEntity; - int32 m_nCollisionEntity; - cAudioCollisionManager m_sCollisionManager; - int32 m_nProjectileEntity; - int32 m_nBridgeEntity; - cMissionAudio m_sMissionAudio; - int32 m_anRandomTable[5]; - uint8 field_19192; - uint8 m_bUserPause; - uint8 m_bPreviousUserPause; - uint8 field_19195; // time? - uint32 m_FrameCounter; - - // getters - uint32 GetFrameCounter() const { return m_FrameCounter; } - float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } - int32 GetRandomTabe(int32 idx) const { return m_anRandomTable[idx]; } - - // "Should" be in alphabetic order, except "getXTalkSfx" - void AddDetailsToRequestedOrderList(uint8 sample); /// ok - void AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 unk1, - uint8 counter, bool notLooping); /// ok - void AddReflectionsToRequestedQueue(); /// ok (check value) - void AddReleasingSounds(); // todo (difficult) - void AddSampleToRequestedQueue(); /// ok - void AgeCrimes(); // todo - - void CalculateDistance(bool *ptr, float dist); /// ok - bool CheckForAnAudioFileOnCD() const; /// ok - void ClearMissionAudio(); /// ok - void ClearRequestedQueue(); /// ok - int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, - float speedMultiplier) const; /// ok - int32 ComputePan(float, CVector *); // todo - uint32 ComputeVolume(int emittingVolume, float soundIntensity, float distance) const; /// ok - int32 CreateEntity(int32 type, CPhysical *entity); /// ok - - void DestroyAllGameCreatedEntities(); /// ok - void DestroyEntity(int32 id); /// ok - void DoJumboVolOffset() const; /// ok - void DoPoliceRadioCrackle(); /// ok - - // functions returning talk sfx, - // order from GetPedCommentSfx - uint32 GetPlayerTalkSfx(int16 sound); - uint32 GetCopTalkSfx(int16 sound); - uint32 GetSwatTalkSfx(int16 sound); - uint32 GetFBITalkSfx(int16 sound); - uint32 GetArmyTalkSfx(int16 sound); - uint32 GetMedicTalkSfx(int16 sound); - uint32 GetFiremanTalkSfx(int16 sound); - uint32 GetNormalMaleTalkSfx(int16 sound); - uint32 GetTaxiDriverTalkSfx(int16 sound); - uint32 GetPimpTalkSfx(int16 sound); - uint32 GetMafiaTalkSfx(int16 sound); - uint32 GetTriadTalkSfx(int16 sound); - uint32 GetDiabloTalkSfx(int16 sound); - uint32 GetYakuzaTalkSfx(int16 sound); - uint32 GetYardieTalkSfx(int16 sound); - uint32 GetColumbianTalkSfx(int16 sound); - uint32 GetHoodTalkSfx(int16 sound); - uint32 GetBlackCriminalTalkSfx(int16 sound); - uint32 GetWhiteCriminalTalkSfx(int16 sound); - uint32 GetMaleNo2TalkSfx(int16 sound); - uint32 GetBlackProjectMaleTalkSfx(int16 sound, int32 model); - uint32 GetWhiteFatMaleTalkSfx(int16 sound); - uint32 GetBlackFatMaleTalkSfx(int16 sound); - uint32 GetBlackCasualFemaleTalkSfx(int16 sound); - uint32 GetWhiteCasualFemaleTalkSfx(int16 sound); - uint32 GetFemaleNo3TalkSfx(int16 sound); - uint32 GetBlackFatFemaleTalkSfx(int16 sound); - uint32 GetWhiteFatFemaleTalkSfx(int16 sound); - uint32 GetBlackFemaleProstituteTalkSfx(int16 sound); - uint32 GetWhiteFemaleProstituteTalkSfx(int16 sound); - uint32 GetBlackProjectFemaleOldTalkSfx(int16 sound); - uint32 GetBlackProjectFemaleYoungTalkSfx(int16 sound); - uint32 GetChinatownMaleOldTalkSfx(int16 sound); - uint32 GetChinatownMaleYoungTalkSfx(int16 sound); - uint32 GetChinatownFemaleOldTalkSfx(int16 sound); - uint32 GetChinatownFemaleYoungTalkSfx(int16 sound); - uint32 GetLittleItalyMaleTalkSfx(int16 sound); - uint32 GetLittleItalyFemaleOldTalkSfx(int16 sound); - uint32 GetLittleItalyFemaleYoungTalkSfx(int16 sound); - uint32 GetWhiteDockerMaleTalkSfx(int16 sound); - uint32 GetBlackDockerMaleTalkSfx(int16 sound); - uint32 GetScumMaleTalkSfx(int16 sound); - uint32 GetScumFemaleTalkSfx(int16 sound); - uint32 GetWhiteWorkerMaleTalkSfx(int16 sound); - uint32 GetBlackWorkerMaleTalkSfx(int16 sound); - uint32 GetBusinessMaleYoungTalkSfx(int16 sound, int32 model); - uint32 GetBusinessMaleOldTalkSfx(int16 sound); - uint32 GetWhiteBusinessFemaleTalkSfx(int16 sound, int32 model); - uint32 GetBlackBusinessFemaleTalkSfx(int16 sound); - uint32 GetSupermodelMaleTalkSfx(int16 sound); - uint32 GetSupermodelFemaleTalkSfx(int16 sound); - uint32 GetStewardMaleTalkSfx(int16 sound); - uint32 GetStewardFemaleTalkSfx(int16 sound); - uint32 GetFanMaleTalkSfx(int16 sound, int32 model); - uint32 GetFanFemaleTalkSfx(int16 sound); - uint32 GetHospitalMaleTalkSfx(int16 sound); - uint32 GetHospitalFemaleTalkSfx(int16 sound); - uint32 GetWhiteConstructionWorkerTalkSfx(int16 sound); - uint32 GetBlackConstructionWorkerTalkSfx(int16 sound); - uint32 GetShopperFemaleTalkSfx(int16 sound, int32 model); - uint32 GetStudentMaleTalkSfx(int16 sound); - uint32 GetStudentFemaleTalkSfx(int16 sound); - uint32 GetCasualMaleOldTalkSfx(int16 sound); - - uint32 GetSpecialCharacterTalkSfx(int32 modelIndex, int32 sound); - uint32 GetEightTalkSfx(int16 sound); - uint32 GetFrankieTalkSfx(int16 sound); - uint32 GetMistyTalkSfx(int16 sound); - uint32 GetOJGTalkSfx(int16 sound); - uint32 GetCatatalinaTalkSfx(int16 sound); - uint32 GetBomberTalkSfx(int16 sound); - uint32 GetSecurityGuardTalkSfx(int16 sound); - uint32 GetChunkyTalkSfx(int16 sound); - - uint32 GetGenericMaleTalkSfx(int16 sound); - uint32 GetGenericFemaleTalkSfx(int16 sound); - // end of functions returning talk sfx - - void GenerateIntegerRandomNumberTable(); /// ok - char *Get3DProviderName(uint8 id) const; - uint8 GetCDAudioDriveLetter() const; - int8 GetCurrent3DProviderIndex() const; /// ok - float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // not used - float GetCollisionOneShotRatio(uint32 a, float b) const; /// ok - float GetCollisionRatio(float a, float b, float c, float d) const; /// ok - float GetDistanceSquared(CVector *v) const; /// ok - int32 GetJumboTaxiFreq() const; /// ok - bool GetMissionAudioLoadingStatus() const; /// ok - char GetMissionScriptPoliceAudioPlayingStatus() const; /// ok - uint8 GetNum3DProvidersAvailable() const; - int32 GetPedCommentSfx(CPed *ped, int32 sound); - void GetPhrase(uint32 *phrase, uint32 *prevPhrase, uint32 sample, uint32 maxOffset) const; - float GetVehicleDriveWheelSkidValue(uint8 a1, CAutomobile *a2, cTransmission *a3, - float a4); // todo - int32 GetVehicleNonDriveWheelSkidValue(float a1, int a2, int a3, int a4, float a5); // todo - - bool HasAirBrakes(int32 model) const; /// ok - - void Initialise(); /// ok - void InitialisePoliceRadio(); // todo - void InitialisePoliceRadioZones(); // todo - void InterrogateAudioEntities(); /// ok - bool IsAudioInitialised() const; /// ok - bool IsMissionAudioSampleFinished(); /// ok - bool IsMP3RadioChannelAvailable() const; - - bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; /// ok - - void PlayLoadedMissionAudio(); /// ok - void PlayOneShot(int32 index, int16 sound, float vol); // todo - uint32 PlaySuspectLastSeen(float x, float y, float z); // todo - void PlayerJustGotInCar() const; /// ok - void PlayerJustLeftCar() const; /// ok - void PostInitialiseGameSpecificSetup(); /// ok - void PostTerminateGameSpecificShutdown(); /// ok - void PreInitialiseGameSpecificSetup() const; - void PreloadMissionAudio(char *); // todo - void PreTerminateGameSpecificShutdown(); /// ok - /// processX - main logic of adding new sounds - void ProcessActiveQueues(); // todo - bool ProcessAirBrakes(cVehicleParams *params); /// ok - void ProcessAirportScriptObject(uint8 sound); /// ok - bool ProcessBoatEngine(cVehicleParams *params); /// ok - bool ProcessBoatMovingOverWater(cVehicleParams *params); /// ok - void ProcessBridge(); /// ok - void ProcessBridgeMotor(); /// ok - void ProcessBridgeOneShots(); /// ok - void ProcessBridgeWarning(); /// ok - bool ProcessCarBombTick(cVehicleParams *params); /// ok - void ProcessCesna(void *); // todo requires CPlane - void ProcessCinemaScriptObject(uint8 sound); /// ok - void ProcessCrane(); // todo requires CCrane - void ProcessDocksScriptObject(uint8 sound); /// ok - bool ProcessEngineDamage(cVehicleParams *params); /// ok - void ProcessEntity(int32 sound); /// ok - void ProcessExplosions(int32 explosion); /// ok - void ProcessFireHydrant(); /// ok - void ProcessFires(int32 entity); // todo requires gFireManager - void ProcessFrontEnd(); /// ok - void ProcessGarages(); // todo requires CGarages::aGarages - bool ProcessHelicopter(cVehicleParams *params); /// ok - void ProcessHomeScriptObject(uint8 sound); /// ok - void ProcessJumbo(cVehicleParams *); /// ok - void ProcessJumboAccel(CPlane *plane); /// ok - void ProcessJumboDecel(CPlane *plane); /// ok - void ProcessJumboFlying(); /// ok - void ProcessJumboLanding(CPlane *plane); /// ok - void ProcessJumboTakeOff(CPlane *plane); /// ok - void ProcessJumboTaxi(); /// ok - void ProcessLaunderetteScriptObject(uint8 sound); /// ok - void ProcessLoopingScriptObject(uint8 sound); /// ok - void ProcessMissionAudio(); /// ok - void ProcessModelCarEngine(cVehicleParams *params); /// ok (check float comparisons) - void ProcessOneShotScriptObject(uint8 sound); /// ok - void ProcessPed(CPhysical *ped); /// ok - void ProcessPedHeadphones(cPedParams *params); /// ok - void ProcessPedOneShots(cPedParams *params); // todo later (weird) - void ProcessPhysical(int32 id); /// ok - void ProcessPlane(cVehicleParams *params); /// ok - void ProcessPlayersVehicleEngine(cVehicleParams *params, - CAutomobile *automobile); /// ok (check float comparisons) - void ProcessPoliceCellBeatingScriptObject(uint8 sound); // todo - void ProcessPornCinema(uint8 sound); /// ok - void ProcessProjectiles(); // todo requires CProjectileInfo - void ProcessRainOnVehicle(cVehicleParams *params); /// ok - void ProcessReverb() const; /// ok - bool ProcessReverseGear(cVehicleParams *a2); /// ok - void ProcessSawMillScriptObject(uint8 sound); /// ok - void ProcessScriptObject(int32 id); /// ok - void ProcessShopScriptObject(uint8 sound); /// ok - void ProcessSpecial(); /// ok - bool ProcessTrainNoise(cVehicleParams *params); /// ok - void ProcessVehicle(CVehicle *); // todo - bool ProcessVehicleDoors(cVehicleParams *params); /// ok - // bool ProcessVehicleEngine(void *); - // void ProcessVehicleHorn(cVehicleParams *params); - // void ProcessVehicleOneShots(void *); - bool ProcessVehicleReverseWarning(cVehicleParams *params); /// ok - bool ProcessVehicleRoadNoise(cVehicleParams *params); /// ok - // void ProcessVehicleSirenOrAlarm(void *); - // void ProcessVehicleSkidding(void *); - void ProcessWaterCannon(int32); // todo - void ProcessWeather(int32 id); /// ok - bool ProcessWetRoadNoise(cVehicleParams *params); /// ok - void ProcessWorkShopScriptObject(uint8 sound); /// ok - - int32 RandomDisplacement(uint32 seed) const; - void ReacquireDigitalHandle() const; - void ReleaseDigitalHandle() const; - int32 ReportCollision(CEntity *a2, CEntity *a3, uint8 a4, uint8 a5, float a6, - float a7); // todo - int32 ReportCrime(int a2, int *a3); // todo - void ResetAudioLogicTimers(int32 timer); /// ok - void ResetPoliceRadio(); - void ResetTimers(unsigned int a2); // todo - - void Service(); // todo - void ServiceCollisions(); // todo - void ServicePoliceRadio(); // todo - void ServicePoliceRadioChannel(int a2); // todo - void ServiceSoundEffects(); // todo - void SetDynamicAcousticModelingStatus(bool status); - void SetEffectsFadeVolume(uint8 volume) const; - void SetEffectsMasterVolume(uint8 volume) const; - void SetEntityStatus(int32 id, bool status); - uint32 SetLoopingCollisionRequestedSfxFreqAndGetVol(int32); // todo - void SetMissionAudioLocation(float x, float y, float z); - void SetMissionScriptPoliceAudio(int32 sfx) const; - void SetMonoMode(uint8); // todo - void SetMusicFadeVolume(uint8 volume) const; - void SetMusicMasterVolume(uint8 volume) const; - void SetSpeakerConfig(int32 conf) const; - void SetUpLoopingCollisionSound(int a2, int a3); // todo - void SetUpOneShotCollisionSound(int a2); // todo - void SetupCrimeReport(); // todo - bool SetupJumboEngineSound(uint8, int32); // todo - bool SetupJumboFlySound(uint8 emittingVol); /// ok - bool SetupJumboRumbleSound(uint8 emittingVol); /// ok - bool SetupJumboTaxiSound(uint8 vol); /// ok - bool SetupJumboWhineSound(uint8 emittingVol, int32 freq); /// ok - void SetupPedComments(cPedParams *params, uint32 sound); /// ok - void SetupSuspectLastSeenReport(); // todo - - void Terminate(); - void TranslateEntity(CVector *v1, CVector *v2) const; /// ok - - void UpdateGasPedalAudio(CAutomobile *automobile); // todo hook - bool UsesReverseWarning(int32 model) const; - bool UsesSiren(int32 model) const; - bool UsesSirenSwitching(int32 model) const; -}; - -static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); - -extern cAudioManager &AudioManager; diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 08ec3bc5..82267858 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -7,9 +7,6 @@ cDMAudio &DMAudio = *(cDMAudio*)0x95CDBE; -#define AEHANDLE_IS_FAILED(h) ((h)<0) -#define AEHANDLE_IS_OK(h) ((h)>=0) - void cDMAudio::Initialise(void) { @@ -167,7 +164,7 @@ cDMAudio::IsAudioInitialised(void) } void -cDMAudio::ReportCrime(eCrimeType crime, CVector const &pos) +cDMAudio::ReportCrime(eCrimeType crime, const CVector &pos) { AudioManager.ReportCrime(crime, &pos); } diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h index 0932e581..42dd9ef4 100644 --- a/src/audio/DMAudio.h +++ b/src/audio/DMAudio.h @@ -174,6 +174,9 @@ enum eSound : int16 SOUND_TOTAL_PED_SOUNDS = 167, }; +#define AEHANDLE_IS_FAILED(h) ((h)<0) +#define AEHANDLE_IS_OK(h) ((h)>=0) + class cAudioScriptObject; class CEntity; enum eCrimeType; diff --git a/src/audio/sampman.cpp b/src/audio/sampman.cpp index 58da6f64..de222493 100644 --- a/src/audio/sampman.cpp +++ b/src/audio/sampman.cpp @@ -158,14 +158,14 @@ release_existing() if ( opened_samples[i] ) { AIL_release_3D_sample_handle(opened_samples[i]); - opened_samples[i] = 0; + opened_samples[i] = NULL; } } if ( opened_provider ) { AIL_close_3D_provider(opened_provider); - opened_provider = 0; + opened_provider = NULL; } _fPrevEaxRatioDestination = 0.0f; @@ -879,7 +879,7 @@ cSampleManager::Initialise(void) _maxSamples = 0; - opened_provider = 0; + opened_provider = NULL; DIG = NULL; for ( int32 i = 0; i < MAXCHANNELS; i++ ) @@ -2020,9 +2020,10 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) { uint32 i = 0; + if ( !_bIsMp3Active ) goto FIND_MP3TRACK; + do { - if(_bIsMp3Active){ if ( ++_CurMP3Index >= nNumMP3s ) _CurMP3Index = 0; @@ -2058,15 +2059,21 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) AIL_pause_stream(mp3Stream[nStream], 0); return true; } - } - if(nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER]) position = 0; - - tMP3Entry *e; - if(!_GetMP3PosFromStreamPos(&position, &e)) { - if(e == NULL) { - nFile = 0; - goto PLAY_STREAMEDTRACK; - } + + goto NEXT_MP3TRACK; + +FIND_MP3TRACK: + if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) + position = 0; + + tMP3Entry *e; + if ( !_GetMP3PosFromStreamPos(&position, &e) ) + { + if ( e == NULL ) + { + nFile = 0; + goto PLAY_STREAMEDTRACK; + } } if ( e->pLinkPath != NULL ) @@ -2090,12 +2097,14 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) return true; } +NEXT_MP3TRACK: _bIsMp3Active = false; } while ( ++i < nNumMP3s ); position = 0; nFile = 0; + goto PLAY_STREAMEDTRACK; } PLAY_STREAMEDTRACK: diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index eb63b0b0..e9b33395 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -1263,9 +1263,7 @@ CPathFind::FindNextNodeWandering(uint8 type, CVector coors, CPathNode **lastNode static CPathNode *apNodesToBeCleared[4995]; void -CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector target, - CPathNode **nodes, int16 *pNumNodes, int16 maxNumNodes, CVehicle *vehicle, - float *pDist, float distLimit, int32 forcedTargetNode) +CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector target, CPathNode **nodes, int16 *pNumNodes, int16 maxNumNodes, CVehicle *vehicle, float *pDist, float distLimit, int32 forcedTargetNode) { int i, j; @@ -1275,51 +1273,41 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta targetNode = FindNodeClosestToCoors(target, type, distLimit); else targetNode = forcedTargetNode; - if(targetNode < 0) { - *pNumNodes = 0; - if(pDist) *pDist = 100000.0f; - return; - } + if(targetNode < 0) + goto fail; // Find start int numPathsToTry; CTreadable *startObj; - if(startNodeId < 0) { + if(startNodeId < 0){ if(vehicle == nil || (startObj = vehicle->m_treadable[type]) == nil) startObj = FindRoadObjectClosestToCoors(start, type); numPathsToTry = 0; - for(i = 0; i < 12; i++) { - if(startObj->m_nodeIndices[type][i] < 0) break; - if(m_pathNodes[startObj->m_nodeIndices[type][i]].group == - m_pathNodes[targetNode].group) + for(i = 0; i < 12; i++){ + if(startObj->m_nodeIndices[type][i] < 0) + break; + if(m_pathNodes[startObj->m_nodeIndices[type][i]].group == m_pathNodes[targetNode].group) numPathsToTry++; } - } else { + }else{ numPathsToTry = 1; startObj = m_mapObjects[m_pathNodes[startNodeId].objectIndex]; } - if(numPathsToTry == 0) { - *pNumNodes = 0; - if(pDist) *pDist = 100000.0f; - } + if(numPathsToTry == 0) + goto fail; - if(startNodeId < 0) { + if(startNodeId < 0){ // why only check node 0? - if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != - m_pathNodes[targetNode].group) { - *pNumNodes = 0; - if(pDist) *pDist = 100000.0f; - return; - } - } else { - if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) { - *pNumNodes = 0; - if(pDist) *pDist = 100000.0f; - return; - } + if(m_pathNodes[startObj->m_nodeIndices[type][0]].group != m_pathNodes[targetNode].group) + goto fail; + }else{ + if(m_pathNodes[startNodeId].group != m_pathNodes[targetNode].group) + goto fail; } - for(i = 0; i < 512; i++) m_searchNodes[i].next = nil; + + for(i = 0; i < 512; i++) + m_searchNodes[i].next = nil; AddNodeToList(&m_pathNodes[targetNode], 0); int numNodesToBeCleared = 0; apNodesToBeCleared[numNodesToBeCleared++] = &m_pathNodes[targetNode]; @@ -1395,6 +1383,11 @@ CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector ta for(i = 0; i < numNodesToBeCleared; i++) apNodesToBeCleared[i]->distance = MAX_DIST; return; + +fail: + *pNumNodes = 0; + if(pDist) + *pDist = 100000.0f; } static CPathNode *pNodeList[32]; -- cgit v1.2.3