From 2d3d5d67eee6e3606a5d89ff233eabe92e1f058d Mon Sep 17 00:00:00 2001 From: Roman Masanin <36927roma@gmail.com> Date: Tue, 15 Sep 2020 22:06:18 +0300 Subject: [PATCH] revisit processVehicle --- src/audio/AudioLogic.cpp | 269 +++++++++++++++++++++------------------ src/audio/AudioManager.h | 2 +- 2 files changed, 144 insertions(+), 127 deletions(-) diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index ab7c1835..a0d67d03 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -697,131 +697,148 @@ const bool hornPatternsArray[8][44] = { false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false}, }; - -void -cAudioManager::ProcessVehicle(CVehicle *veh) +void cAudioManager::ProcessVehicle(CVehicle* veh) { - tHandlingData *handling = veh->pHandling; - float velChange; + CPlayerPed* player; + CVehicle* playerVeh; + CEntity* attachedTo; cVehicleParams params; - m_sQueueSample.m_vecPos = veh->GetPosition(); + CBike* bike; + CAutomobile* automobile; + float gasPedal; - float gas; - float gasPedalAudio; - float tmp; - - params.m_bDistanceCalculated = false; - params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos); - params.m_pVehicle = veh; - params.m_pTransmission = nil; - params.m_nIndex = 0; - params.m_fVelocityChange = 0.0f; - - if (handling != nil) - params.m_pTransmission = &handling->Transmission; - - params.m_nIndex = veh->GetModelIndex() - MI_FIRST_VEHICLE; - if (params.m_pVehicle->GetStatus() == STATUS_SIMPLE) - velChange = params.m_pVehicle->AutoPilot.m_fMaxTrafficSpeed * 0.02f; - else - velChange = DotProduct(params.m_pVehicle->m_vecMoveSpeed, params.m_pVehicle->GetForward()); - params.m_fVelocityChange = velChange; - params.m_VehicleType = params.m_pVehicle->m_vehType; - switch (params.m_pVehicle->m_vehType) { - case VEHICLE_TYPE_CAR: - UpdateGasPedalAudio((CAutomobile *)veh); - if (params.m_nIndex == RCBANDIT) { - ProcessModelCarEngine(¶ms); + //44-58 + player = FindPlayerPed(); + playerVeh = FindPlayerVehicle(); + if (playerVeh == NULL && player != NULL) { + attachedTo = player->m_attachedTo; + if (attachedTo != NULL && attachedTo->GetType() == ENTITY_TYPE_VEHICLE) + playerVeh = (CVehicle*)attachedTo; + } + if (playerVeh == veh + || CGame::currArea == AREA_OVALRING + || CGame::currArea == AREA_BLOOD + || CGame::currArea == AREA_DIRT + || CGame::currArea == AREA_EVERYWHERE + || CGame::currArea == AREA_MALL + || CGame::currArea == AREA_MAIN_MAP) { + //62-84 + m_sQueueSample.m_vecPos = veh->GetPosition(); + params.m_bDistanceCalculated = false; + params.m_pVehicle = veh; + params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos); + params.m_pTransmission = veh->pHandling != NULL ? &veh->pHandling->Transmission : NULL; + params.m_nIndex = veh->m_modelIndex - MI_FIRST_VEHICLE; + if (veh->GetStatus() == STATUS_SIMPLE) + params.m_fVelocityChange = veh->AutoPilot.m_fMaxTrafficSpeed * 0.02f; + else + params.m_fVelocityChange = DotProduct(veh->m_vecMoveSpeed, veh->GetForward()); + params.m_VehicleType = veh->m_vehType; + + if (CGame::currArea == AREA_MALL && playerVeh != veh) { ProcessVehicleOneShots(¶ms); - ((CAutomobile *)veh)->m_fVelocityChangeForAudio = params.m_fVelocityChange; + ProcessVehicleSirenOrAlarm(¶ms); + ProcessEngineDamage(¶ms); + return; + } + //104- + switch (params.m_VehicleType) { + case VEHICLE_TYPE_CAR://done + automobile = (CAutomobile*)veh; + UpdateGasPedalAudio(&automobile->m_fGasPedalAudio, automobile->m_fGasPedal); + if (veh->m_modelIndex == MI_RCBANDIT || veh->m_modelIndex == MI_RCBARON) { + ProcessModelCarEngine(¶ms);//recheck + ProcessEngineDamage(¶ms); + } else if (veh->m_modelIndex == MI_RCRAIDER || veh->m_modelIndex == MI_RCGOBLIN) { + //ProcessModelHeliVehicle(this, ¶ms); + ProcessEngineDamage(¶ms); + } else { + switch (veh->GetVehicleAppearance()) { + case VEHICLE_APPEARANCE_HELI: + ProcessHelicopter(¶ms); + //ProcessVehicleFlatTyre(¶ms); + ProcessEngineDamage(¶ms); + break; + case VEHICLE_APPEARANCE_BOAT: + case VEHICLE_APPEARANCE_PLANE: + break; + default: + if (ProcessVehicleRoadNoise(¶ms)) { + ProcessReverseGear(¶ms); + if (CWeather::WetRoads > 0.0) + ProcessWetRoadNoise(¶ms); + ProcessVehicleSkidding(¶ms); + //ProcessVehicleFlatTyre(params); + ProcessVehicleHorn(¶ms); + ProcessVehicleSirenOrAlarm(¶ms); + if (UsesReverseWarning(params.m_nIndex)) + ProcessVehicleReverseWarning(¶ms); + if(HasAirBrakes(params.m_nIndex)) + ProcessAirBrakes(¶ms); + ProcessCarBombTick(¶ms); + ProcessVehicleEngine(¶ms); + ProcessEngineDamage(¶ms); + ProcessVehicleDoors(¶ms); + } + break; + } + } + ProcessVehicleOneShots(¶ms); + automobile->m_fVelocityChangeForAudio = params.m_fVelocityChange; + break; + case VEHICLE_TYPE_BOAT://done + if (veh->m_modelIndex == MI_SKIMMER) + ProcessHelicopter(¶ms); + else + ProcessBoatEngine(¶ms); + ProcessBoatMovingOverWater(¶ms); + ProcessVehicleOneShots(¶ms); + break; + case VEHICLE_TYPE_HELI: //done + ProcessHelicopter(¶ms); //TODO recheck + ProcessVehicleOneShots(¶ms); + break; + case VEHICLE_TYPE_PLANE://done + switch (params.m_nIndex) { + case AIRTRAIN: + ProcessJumbo(¶ms);//recheck + break; + case DEADDODO: + ProcessCesna(¶ms);//recheck + break; + default: + break; + } + ProcessVehicleOneShots(¶ms); + //ProcessVehicleFlatType(¶ms); + break; + case VEHICLE_TYPE_BIKE: //done + bike = (CBike*)veh; + //gasPedal = fabs(veh->m_fGasPedal); + //if (gasPedal <= bike->m_fGasPedalAudio) + // bike->m_fGasPedalAudio = Max(bike->m_fGasPedalAudio - 0.07f, gasPedal); + //else + // bike->m_fGasPedalAudio = Min(bike->m_fGasPedalAudio + 0.09f, gasPedal); + UpdateGasPedalAudio(&bike->m_fGasPedalAudio, bike->m_fGasPedal); + if (ProcessVehicleRoadNoise(¶ms)) { + if (CWeather::WetRoads > 0.0f) + ProcessWetRoadNoise(¶ms); + ProcessVehicleSkidding(¶ms); + ProcessVehicleHorn(¶ms); + ProcessVehicleSirenOrAlarm(¶ms); + ProcessCarBombTick(¶ms); + ProcessEngineDamage(¶ms); + ProcessVehicleEngine(¶ms); + //ProcessVehicleFlatTyre(); + } + ProcessVehicleOneShots(¶ms); + bike->m_fVelocityChangeForAudio = params.m_fVelocityChange; + break; + default: break; } - - if (params.m_nIndex == DODO) { - if (!ProcessVehicleRoadNoise(¶ms)) { - ProcessVehicleOneShots(¶ms); - ((CAutomobile *)veh)->m_fVelocityChangeForAudio = params.m_fVelocityChange; - break; - } - if (CWeather::WetRoads > 0.f) - ProcessWetRoadNoise(¶ms); - ProcessVehicleSkidding(¶ms); - } else { - if (!ProcessVehicleRoadNoise(¶ms)) { - ProcessVehicleOneShots(¶ms); - ((CAutomobile *)veh)->m_fVelocityChangeForAudio = params.m_fVelocityChange; - break; - } - ProcessReverseGear(¶ms); - if (CWeather::WetRoads > 0.f) - ProcessWetRoadNoise(¶ms); - ProcessVehicleSkidding(¶ms); - ProcessVehicleHorn(¶ms); - ProcessVehicleSirenOrAlarm(¶ms); - if (UsesReverseWarning(params.m_nIndex)) - ProcessVehicleReverseWarning(¶ms); - if (HasAirBrakes(params.m_nIndex)) - ProcessAirBrakes(¶ms); - } - ProcessCarBombTick(¶ms); - ProcessVehicleEngine(¶ms); - ProcessEngineDamage(¶ms); - ProcessVehicleDoors(¶ms); - - ProcessVehicleOneShots(¶ms); - ((CAutomobile *)veh)->m_fVelocityChangeForAudio = params.m_fVelocityChange; - break; - case VEHICLE_TYPE_BOAT: - ProcessBoatEngine(¶ms); - ProcessBoatMovingOverWater(¶ms); - ProcessVehicleOneShots(¶ms); - break; -#ifdef GTA_TRAIN - case VEHICLE_TYPE_TRAIN: - ProcessTrainNoise(¶ms); - ProcessVehicleOneShots(¶ms); - break; -#endif - case VEHICLE_TYPE_HELI: - ProcessHelicopter(¶ms); - ProcessVehicleOneShots(¶ms); - break; - case VEHICLE_TYPE_PLANE: - ProcessPlane(¶ms); - ProcessVehicleOneShots(¶ms); - break; - case VEHICLE_TYPE_BIKE: - gas = fabs(params.m_pVehicle->m_fGasPedal); - gasPedalAudio = ((CBike*)params.m_pVehicle)->m_fGasPedalAudio; - if (gas <= gasPedalAudio) { - tmp = gasPedalAudio = 0.07f; - if (tmp <= gas) - tmp = gas; - } else { - tmp = gasPedalAudio + 0.09f; - if (tmp < gas) - tmp = gas; - } - ((CBike*)params.m_pVehicle)->m_fGasPedalAudio = tmp; - - if (ProcessVehicleRoadNoise(¶ms)) { - if (CWeather::WetRoads > 0.0f) - ProcessWetRoadNoise(¶ms); - ProcessVehicleSkidding(¶ms); - ProcessVehicleHorn(¶ms); - ProcessVehicleSirenOrAlarm(¶ms); - ProcessCarBombTick(¶ms); - ProcessEngineDamage(¶ms); - ProcessVehicleEngine(¶ms); - //ProcessVehicleFlatTyre(); - } - ProcessVehicleOneShots(¶ms); - ((CBike*)veh)->m_fVelocityChangeForAudio = params.m_fVelocityChange; - break; - default: - break; + ProcessRainOnVehicle(¶ms); } - ProcessRainOnVehicle(¶ms); } void @@ -1227,15 +1244,14 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams *params) } void -cAudioManager::UpdateGasPedalAudio(CAutomobile *automobile) +cAudioManager::UpdateGasPedalAudio(float* gasPedalAudio, float vehGasPedal) { - float gasPedal = Abs(automobile->m_fGasPedal); - float gasPedalAudio = automobile->m_fGasPedalAudio; + float gasPedal = Abs(vehGasPedal); - if (gasPedalAudio < gasPedal) - automobile->m_fGasPedalAudio = Min(gasPedalAudio + 0.09f, gasPedal); + if (*gasPedalAudio < gasPedal) + *gasPedalAudio = Min(*gasPedalAudio + 0.09f, gasPedal); else - automobile->m_fGasPedalAudio = Max(gasPedalAudio - 0.07f, gasPedal); + *gasPedalAudio = Max(*gasPedalAudio - 0.07f, gasPedal); } void @@ -2072,7 +2088,7 @@ cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams *params) bool cAudioManager::UsesReverseWarning(int32 model) const { - return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || model == COACH; + return model == LINERUN || model == FIRETRUK || model == BUS || model == COACH || model == PACKER || model == FLATBED; } bool @@ -2204,7 +2220,8 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params) bool cAudioManager::HasAirBrakes(int32 model) const { - return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || model == COACH; + return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || model == BARRACKS + || model == COACH || model == PACKER || model == FLATBED; } bool diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index c502cad1..945dee3c 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -359,6 +359,7 @@ public: void ProcessVehicle(CVehicle *vehicle); bool ProcessVehicleDoors(cVehicleParams *params); void ProcessVehicleEngine(cVehicleParams *params); + void UpdateGasPedalAudio(float* gasPedalAudio, float vehGasPedal); void ProcessVehicleHorn(cVehicleParams *params); void ProcessVehicleOneShots(cVehicleParams *params); bool ProcessVehicleReverseWarning(cVehicleParams *params); @@ -411,7 +412,6 @@ public: void Terminate(); void TranslateEntity(Const CVector *v1, CVector *v2) const; - void UpdateGasPedalAudio(CAutomobile *automobile); void UpdateReflections(); bool UsesReverseWarning(int32 model) const; bool UsesSiren(int32 model) const;