From 9e65eb34ec834de082154ee7559cd1c418f02ae6 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sun, 19 Apr 2020 17:38:10 +0300 Subject: [PATCH 01/10] 1.1 patch stuff --- src/core/Cam.cpp | 13 +++++++++++++ src/core/Camera.cpp | 20 +++++++++++++++++++- src/core/Camera.h | 1 + src/core/Frontend.cpp | 23 ++++++++++++++++++++++- src/core/Frontend.h | 1 + src/entities/Physical.cpp | 4 ++++ src/modelinfo/VehicleModelInfo.cpp | 2 ++ src/peds/CopPed.cpp | 2 ++ src/render/2dEffect.h | 6 ++++++ src/render/Clouds.cpp | 15 +++++++++++++++ src/render/Rubbish.cpp | 12 ++++++++++++ src/render/Skidmarks.cpp | 9 +++++++++ src/weapons/WeaponEffects.cpp | 3 +++ 13 files changed, 109 insertions(+), 2 deletions(-) diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 07dc2051..505f838f 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -2545,11 +2545,13 @@ CCam::Process_M16_1stPerson(const CVector &CameraTarget, float, float, float) ResetStatics = false; } +#ifndef GTA3_1_1_PATCH ((CPed*)CamTargetEntity)->m_pedIK.GetComponentPosition(&HeadPos, PED_HEAD); Source = HeadPos; Source.z += 0.1f; Source.x -= 0.19f*Cos(m_fInitialPlayerOrientation); Source.y -= 0.19f*Sin(m_fInitialPlayerOrientation); +#endif // Look around bool UseMouse = false; @@ -2578,6 +2580,17 @@ CCam::Process_M16_1stPerson(const CVector &CameraTarget, float, float, float) if(Alpha > DEGTORAD(60.0f)) Alpha = DEGTORAD(60.0f); if(Alpha < -DEGTORAD(89.5f)) Alpha = -DEGTORAD(89.5f); +#ifdef GTA3_1_1_PATCH + HeadPos.x = 0.0f; + HeadPos.y = 0.0f; + HeadPos.z = 0.0f; + ((CPed*)CamTargetEntity)->m_pedIK.GetComponentPosition(&HeadPos, PED_HEAD); + Source = HeadPos; + Source.z += 0.1f; + Source.x -= 0.19f * Cos(m_fInitialPlayerOrientation); + Source.y -= 0.19f * Sin(m_fInitialPlayerOrientation); +#endif + TargetCoors.x = 3.0f * Cos(Alpha) * Cos(Beta) + Source.x; TargetCoors.y = 3.0f * Cos(Alpha) * Sin(Beta) + Source.y; TargetCoors.z = 3.0f * Sin(Alpha) + Source.z; diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 6747ebf5..202d481d 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -71,11 +71,27 @@ bool bDidWeProcessAnyCinemaCam; #define CTRLDOWN(key) ((KEYDOWN(rsLCTRL) || KEYDOWN(rsRCTRL)) && KEYDOWN((RsKeyCodes)key)) #endif +CCamera::CCamera(void) +{ +#ifdef GTA3_1_1_PATCH + m_fMouseAccelHorzntl = 0.0025f; + m_fMouseAccelVertical = 0.003f; +#endif + Init(); +} + void CCamera::Init(void) { +#ifdef GTA3_1_1_PATCH + float fMouseAccelHorzntl = m_fMouseAccelHorzntl; + float fMouseAccelVertical = m_fMouseAccelVertical; +#endif memset(this, 0, sizeof(CCamera)); // getting rid of vtable, eh? - +#ifdef GTA3_1_1_PATCH + m_fMouseAccelHorzntl = fMouseAccelHorzntl; + m_fMouseAccelVertical = fMouseAccelVertical; +#endif m_pRwCamera = nil; m_1rstPersonRunCloseToAWall = false; m_fPositionAlongSpline = 0.0f; @@ -191,8 +207,10 @@ CCamera::Init(void) m_uiTransitionState = 0; m_uiTimeTransitionStart = 0; m_bLookingAtPlayer = true; +#ifndef GTA3_1_1_PATCH m_fMouseAccelHorzntl = 0.0025f; m_fMouseAccelVertical = 0.003f; +#endif m_f3rdPersonCHairMultX = 0.53f; m_f3rdPersonCHairMultY = 0.4f; } diff --git a/src/core/Camera.h b/src/core/Camera.h index d1c8ec03..6d53f417 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -546,6 +546,7 @@ uint32 unknown; // some counter having to do with music #endif // High level and misc + CCamera(void); void Init(void); void Process(void); void CamControl(void); diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 6fe06d96..0a2903b7 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -2954,8 +2954,10 @@ CMenuManager::LoadAllTextures() CTxdStore::LoadTxd(frontendTxdSlot, "MODELS/FRONTEND.TXD"); CTxdStore::AddRef(frontendTxdSlot); CTxdStore::SetCurrentTxd(frontendTxdSlot); +#ifndef GTA3_1_1_PATCH CStreaming::IHaveUsedStreamingMemory(); CTimer::Update(); +#endif for (int i = 0; i < ARRAY_SIZE(FrontendFilenames); i++) { m_aFrontEndSprites[i].SetTexture(FrontendFilenames[i][0], FrontendFilenames[i][1]); @@ -2981,6 +2983,10 @@ CMenuManager::LoadAllTextures() m_aMapSprites[i].SetTexture(MapFilenames[i][0], MapFilenames[i][1]); m_aMapSprites[i].SetAddressing(rwTEXTUREADDRESSBORDER); } +#endif +#ifdef GTA3_1_1_PATCH + CStreaming::IHaveUsedStreamingMemory(); + CTimer::Update(); #endif m_bSpritesLoaded = true; CTxdStore::PopCurrentTxd(); @@ -2993,7 +2999,11 @@ CMenuManager::LoadSettings() int fileHandle = CFileMgr::OpenFile("gta3.set", "r"); int32 prevLang = m_PrefsLanguage; +#ifdef GTA3_1_1_PATCH + CMBlur::BlurOn = (_dwOperatingSystemVersion != OS_WIN98); +#else CMBlur::BlurOn = true; +#endif MousePointerStateHelper.bInvertVertically = true; // 50 is silly @@ -4456,7 +4466,18 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsUseWideScreen = false; m_PrefsShowSubtitles = true; m_nDisplayVideoMode = m_nPrefsVideoMode; +#ifdef GTA3_1_1_PATCH + if (_dwOperatingSystemVersion == OS_WIN98) { + CMBlur::BlurOn = false; + CMBlur::MotionBlurClose(); + } + else { + CMBlur::BlurOn = true; + CMBlur::MotionBlurOpen(Scene.camera); + } +#else CMBlur::BlurOn = true; +#endif SaveSettings(); } else if ((m_nCurrScreen != MENUPAGE_SKIN_SELECT_OLD) && (m_nCurrScreen == MENUPAGE_CONTROLLER_PC)) { ControlsManager.MakeControllerActionsBlank(); @@ -4986,7 +5007,7 @@ CMenuManager::WaitForUserCD() CSprite2d *splash; char *splashscreen = nil; -#ifndef RANDOMSPLASH +#if (!(defined RANDOMSPLASH) && !(defined GTA3_1_1_PATCH)) if (CGame::frenchGame || CGame::germanGame || !CGame::nastyGame) splashscreen = "mainsc2"; else diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 71aac605..9fb0756f 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -644,3 +644,4 @@ public: static_assert(sizeof(CMenuManager) == 0x564, "CMenuManager: error"); extern CMenuManager FrontEndMenuManager; +extern DWORD _dwOperatingSystemVersion; \ No newline at end of file diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index 445cd83f..e2099945 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -814,7 +814,11 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV normalSpeed = DotProduct(speed, colpoint.normal); if(normalSpeed < 0.0f){ float minspeed = 0.0104f * CTimer::GetTimeStep(); +#ifdef GTA3_1_1_PATCH + if ((IsObject() || IsVehicle() && (GetUp().z < -0.3f || ((CVehicle*)this)->IsBike() && (m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED))) && +#else if((IsObject() || IsVehicle() && GetUp().z < -0.3f) && +#endif !bHasContacted && Abs(m_vecMoveSpeed.x) < minspeed && Abs(m_vecMoveSpeed.y) < minspeed && diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp index 0c3a7720..098400cc 100644 --- a/src/modelinfo/VehicleModelInfo.cpp +++ b/src/modelinfo/VehicleModelInfo.cpp @@ -960,7 +960,9 @@ CVehicleModelInfo::DeleteVehicleColourTextures(void) for(i = 0; i < 256; i++){ if(ms_colourTextureTable[i]){ RwTextureDestroy(ms_colourTextureTable[i]); +#ifdef GTA3_1_1_PATCH ms_colourTextureTable[i] = nil; +#endif } } } diff --git a/src/peds/CopPed.cpp b/src/peds/CopPed.cpp index e62743de..63811eae 100644 --- a/src/peds/CopPed.cpp +++ b/src/peds/CopPed.cpp @@ -668,11 +668,13 @@ CCopPed::ProcessControl(void) } if (bDuckAndCover) { +#ifndef GTA3_1_1_PATCH if (!bNotAllowedToDuck && Seek()) { SetMoveState(PEDMOVE_STILL); SetMoveAnim(); SetPointGunAt(m_pedInObjective); } +#endif } else if (Seek()) { CVehicle *playerVeh = FindPlayerVehicle(); if (!playerVeh && player && player->EnteringCar()) { diff --git a/src/render/2dEffect.h b/src/render/2dEffect.h index 62216bca..b0615e4d 100644 --- a/src/render/2dEffect.h +++ b/src/render/2dEffect.h @@ -76,8 +76,14 @@ public: if(type == EFFECT_LIGHT){ if(light.corona) RwTextureDestroy(light.corona); +#ifdef GTA3_1_1_PATCH + light.corona = nil; +#endif if(light.shadow) RwTextureDestroy(light.shadow); +#ifdef GTA3_1_1_PATCH + light.shadow = nil; +#endif } } }; diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index 58dc3f93..d4246a15 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -44,10 +44,25 @@ void CClouds::Shutdown(void) { RwTextureDestroy(gpCloudTex[0]); +#ifdef GTA3_1_1_PATCH + gpCloudTex[0] = nil; +#endif RwTextureDestroy(gpCloudTex[1]); +#ifdef GTA3_1_1_PATCH + gpCloudTex[1] = nil; +#endif RwTextureDestroy(gpCloudTex[2]); +#ifdef GTA3_1_1_PATCH + gpCloudTex[2] = nil; +#endif RwTextureDestroy(gpCloudTex[3]); +#ifdef GTA3_1_1_PATCH + gpCloudTex[3] = nil; +#endif RwTextureDestroy(gpCloudTex[4]); +#ifdef GTA3_1_1_PATCH + gpCloudTex[4] = nil; +#endif } void diff --git a/src/render/Rubbish.cpp b/src/render/Rubbish.cpp index 31110046..8a0b80e8 100644 --- a/src/render/Rubbish.cpp +++ b/src/render/Rubbish.cpp @@ -414,7 +414,19 @@ void CRubbish::Shutdown(void) { RwTextureDestroy(gpRubbishTexture[0]); +#ifdef GTA3_1_1_PATCH + gpRubbishTexture[0] = nil; +#endif RwTextureDestroy(gpRubbishTexture[1]); +#ifdef GTA3_1_1_PATCH + gpRubbishTexture[1] = nil; +#endif RwTextureDestroy(gpRubbishTexture[2]); +#ifdef GTA3_1_1_PATCH + gpRubbishTexture[2] = nil; +#endif RwTextureDestroy(gpRubbishTexture[3]); +#ifdef GTA3_1_1_PATCH + gpRubbishTexture[3] = nil; +#endif } diff --git a/src/render/Skidmarks.cpp b/src/render/Skidmarks.cpp index f3479536..5d521041 100644 --- a/src/render/Skidmarks.cpp +++ b/src/render/Skidmarks.cpp @@ -54,8 +54,17 @@ void CSkidmarks::Shutdown(void) { RwTextureDestroy(gpSkidTex); +#ifdef GTA3_1_1_PATCH + gpSkidTex = nil; +#endif RwTextureDestroy(gpSkidBloodTex); +#ifdef GTA3_1_1_PATCH + gpSkidBloodTex = nil; +#endif RwTextureDestroy(gpSkidMudTex); +#ifdef GTA3_1_1_PATCH + gpSkidMudTex = nil; +#endif } void diff --git a/src/weapons/WeaponEffects.cpp b/src/weapons/WeaponEffects.cpp index f7e50f78..46195d2c 100644 --- a/src/weapons/WeaponEffects.cpp +++ b/src/weapons/WeaponEffects.cpp @@ -46,6 +46,9 @@ void CWeaponEffects::Shutdown(void) { RwTextureDestroy(gpCrossHairTex); +#ifdef GTA3_1_1_PATCH + gpCrossHairTex = nil; +#endif } void From 7e4c68382416229cf0a58637bd9f308a6def1caa Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Mon, 20 Apr 2020 01:04:57 +0300 Subject: [PATCH 02/10] fixes --- librw | 2 +- src/control/Pickups.cpp | 2 +- src/control/Script.cpp | 6 ------ src/core/Frontend.h | 2 +- src/core/templates.h | 4 ++++ 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/librw b/librw index e6c7d910..4541fe86 160000 --- a/librw +++ b/librw @@ -1 +1 @@ -Subproject commit e6c7d910ffc32bc059c4e750a797fde51ee29fd9 +Subproject commit 4541fe86f7ecb119c6fcb4fde7d08121341ce189 diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index f9605ca6..1bf6d9ce 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -491,7 +491,7 @@ CPickups::GenerateNewOne(CVector pos, uint32 modelIndex, uint8 type, uint32 quan int32 slot = 0; if (type == PICKUP_FLOATINGPACKAGE || type == PICKUP_NAUTICAL_MINE_INACTIVE) { - for (slot = NUMPICKUPS; slot >= 0; slot--) { + for (slot = NUMPICKUPS-1; slot >= 0; slot--) { if (aPickUps[slot].m_eType == PICKUP_NONE) { bFreeFound = true; break; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index bfe2de34..4707042d 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1675,13 +1675,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) return 0; } case COMMAND_GENERATE_RANDOM_INT: -#ifdef FIX_BUGS - // Not a very good fix but before switching to PS2 rand, it sort of works - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) = CGeneral::GetRandomNumberInRange(0, 65535); -#else - /* On PC between 0 and 32767, even though script expects values between 0 and 65536 */ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) = CGeneral::GetRandomNumber(); -#endif return 0; case COMMAND_CREATE_CHAR: { diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 9fb0756f..ce9861c8 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -644,4 +644,4 @@ public: static_assert(sizeof(CMenuManager) == 0x564, "CMenuManager: error"); extern CMenuManager FrontEndMenuManager; -extern DWORD _dwOperatingSystemVersion; \ No newline at end of file +extern unsigned long _dwOperatingSystemVersion; \ No newline at end of file diff --git a/src/core/templates.h b/src/core/templates.h index a1627357..51a24e4c 100644 --- a/src/core/templates.h +++ b/src/core/templates.h @@ -104,6 +104,10 @@ public: return m_flags[i].free ? nil : (T*)&m_entries[i]; } T *GetAt(int handle){ +#ifdef FIX_BUGS + if (handle == -1) + return nil; +#endif return m_flags[handle>>8].u == (handle & 0xFF) ? (T*)&m_entries[handle >> 8] : nil; } From 0b12cacf15baea97414d401eb2684cfc4cec8d0d Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Fri, 24 Apr 2020 01:01:41 +0300 Subject: [PATCH 03/10] more 1.1 patch --- librw | 2 +- src/control/Script.cpp | 10 ++++++++++ src/control/ScriptCommands.h | 3 +++ src/skel/win/win.cpp | 9 +++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/librw b/librw index 752fceb1..374f951d 160000 --- a/librw +++ b/librw @@ -1 +1 @@ -Subproject commit 752fceb1e3c4ce06b6f20b9c4471927821469bf2 +Subproject commit 374f951d7cee353914059d8ddf9c5aff7d764984 diff --git a/src/control/Script.cpp b/src/control/Script.cpp index c7c762d2..0445922a 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -9649,6 +9649,16 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) CPed::nEnterCarRangeMultiplier = (float)ScriptParams[0]; #endif return 0; +#endif +#ifndef GTA3_1_1_PATCH + case COMMAND_SET_THREAT_REACTION_RANGE_MULTIPLIER: + CollectParameters(&m_nIp, 1); +#ifdef FIX_BUGS + CPed::nThreatReactionRangeMultiplier = *(float*)&ScriptParams[0]; +#else + CPed::nThreatReactionRangeMultiplier = (float)ScriptParams[0]; +#endif + return 0; #endif default: assert(0); diff --git a/src/control/ScriptCommands.h b/src/control/ScriptCommands.h index dafe2418..77cf3f0f 100644 --- a/src/control/ScriptCommands.h +++ b/src/control/ScriptCommands.h @@ -1156,5 +1156,8 @@ enum { COMMAND_IS_CHAR_LYING_DOWN, COMMAND_CAN_CHAR_SEE_DEAD_CHAR, COMMAND_SET_ENTER_CAR_RANGE_MULTIPLIER, +#ifndef GTA3_1_1_PATCH + COMMAND_SET_THREAT_REACTION_RANGE_MULTIPLIER +#endif #endif }; \ No newline at end of file diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index d13d3c52..8697c19c 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -594,8 +594,9 @@ psInitialise(void) C_PcSave::SetSaveDirectory(_psGetUserFilesFolder()); InitialiseLanguage(); - +#ifndef GTA3_1_1_PATCH FrontEndMenuManager.LoadSettings(); +#endif gGameState = GS_START_UP; TRACE("gGameState = GS_START_UP"); @@ -640,7 +641,11 @@ psInitialise(void) _dwOperatingSystemVersion = OS_WIN95; } } - + +#ifdef GTA3_1_1_PATCH + FrontEndMenuManager.LoadSettings(); +#endif + dwDXVersion = GetDXVersion(); debug("DirectX version 0x%x\n", dwDXVersion); From 0fc505926fe40c4366dbb5fe365b4ea7d2381ddf Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Fri, 24 Apr 2020 01:32:17 +0300 Subject: [PATCH 04/10] fix annoying bug --- src/control/CarCtrl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index ae38b68f..f347b2c9 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -1868,6 +1868,9 @@ void CCarCtrl::Init(void) NumFiretrucksOnDuty = 0; LastTimeFireTruckCreated = 0; LastTimeAmbulanceCreated = 0; +#ifdef FIX_BUGS + LastTimeLawEnforcerCreated = 0; +#endif bCarsGeneratedAroundCamera = false; CountDownToCarsAtStart = 2; CarDensityMultiplier = 1.0f; @@ -1890,6 +1893,11 @@ void CCarCtrl::ReInit(void) NumPermanentCars = 0; NumAmbulancesOnDuty = 0; NumFiretrucksOnDuty = 0; +#ifdef FIX_BUGS + LastTimeFireTruckCreated = 0; + LastTimeAmbulanceCreated = 0; + LastTimeLawEnforcerCreated = 0; +#endif CountDownToCarsAtStart = 2; CarDensityMultiplier = 1.0f; for (int i = 0; i < MAX_CARS_TO_KEEP; i++) From bed41e1bec7969535099b8aaaf035288c12e7bfb Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Fri, 24 Apr 2020 01:40:12 +0300 Subject: [PATCH 05/10] removed redundant checks --- src/control/Script.cpp | 50 +++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 0445922a..a4ad15a9 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -256,10 +256,6 @@ void CUpsideDownCarCheck::UpdateTimers() { uint32 timeStep = CTimer::GetTimeStepInMilliseconds(); for (int i = 0; i < MAX_UPSIDEDOWN_CAR_CHECKS; i++){ -#ifdef FIX_BUGS - if (m_sCars[i].m_nVehicleIndex == -1) - continue; -#endif CVehicle* v = CPools::GetVehiclePool()->GetAt(m_sCars[i].m_nVehicleIndex); if (v){ if (IsCarUpsideDown(m_sCars[i].m_nVehicleIndex)) @@ -2308,20 +2304,15 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) assert(pCurrent); // GetIndex(0) doesn't look good int handle = CPools::GetVehiclePool()->GetIndex(pCurrent); if (handle != CTheScripts::StoreVehicleIndex && m_bIsMissionScript){ -#ifdef FIX_BUGS - if (CTheScripts::StoreVehicleIndex != -1) -#endif - { - CVehicle* pOld = CPools::GetVehiclePool()->GetAt(CTheScripts::StoreVehicleIndex); - if (pOld){ - CCarCtrl::RemoveFromInterestingVehicleList(pOld); - if (pOld->VehicleCreatedBy == MISSION_VEHICLE && CTheScripts::StoreVehicleWasRandom){ - pOld->VehicleCreatedBy = RANDOM_VEHICLE; - pOld->bIsLocked = false; - CCarCtrl::NumRandomCars++; - CCarCtrl::NumMissionCars--; - CTheScripts::MissionCleanup.RemoveEntityFromList(CTheScripts::StoreVehicleIndex, CLEANUP_CAR); - } + CVehicle* pOld = CPools::GetVehiclePool()->GetAt(CTheScripts::StoreVehicleIndex); + if (pOld){ + CCarCtrl::RemoveFromInterestingVehicleList(pOld); + if (pOld->VehicleCreatedBy == MISSION_VEHICLE && CTheScripts::StoreVehicleWasRandom){ + pOld->VehicleCreatedBy = RANDOM_VEHICLE; + pOld->bIsLocked = false; + CCarCtrl::NumRandomCars++; + CCarCtrl::NumMissionCars--; + CTheScripts::MissionCleanup.RemoveEntityFromList(CTheScripts::StoreVehicleIndex, CLEANUP_CAR); } } @@ -2364,20 +2355,15 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) assert(pCurrent); // Here pCurrent shouldn't be NULL anyway int handle = CPools::GetVehiclePool()->GetIndex(pCurrent); if (handle != CTheScripts::StoreVehicleIndex && m_bIsMissionScript) { -#ifdef FIX_BUGS - if (CTheScripts::StoreVehicleIndex != -1) -#endif - { - CVehicle* pOld = CPools::GetVehiclePool()->GetAt(CTheScripts::StoreVehicleIndex); - if (pOld){ - CCarCtrl::RemoveFromInterestingVehicleList(pOld); - if (pOld->VehicleCreatedBy == MISSION_VEHICLE && CTheScripts::StoreVehicleWasRandom){ - pOld->VehicleCreatedBy = RANDOM_VEHICLE; - pOld->bIsLocked = false; - CCarCtrl::NumRandomCars++; - CCarCtrl::NumMissionCars--; - CTheScripts::MissionCleanup.RemoveEntityFromList(CTheScripts::StoreVehicleIndex, CLEANUP_CAR); - } + CVehicle* pOld = CPools::GetVehiclePool()->GetAt(CTheScripts::StoreVehicleIndex); + if (pOld){ + CCarCtrl::RemoveFromInterestingVehicleList(pOld); + if (pOld->VehicleCreatedBy == MISSION_VEHICLE && CTheScripts::StoreVehicleWasRandom){ + pOld->VehicleCreatedBy = RANDOM_VEHICLE; + pOld->bIsLocked = false; + CCarCtrl::NumRandomCars++; + CCarCtrl::NumMissionCars--; + CTheScripts::MissionCleanup.RemoveEntityFromList(CTheScripts::StoreVehicleIndex, CLEANUP_CAR); } } From c8fd0385cfa18f6a0d051cb2ebaed01d00ead90f Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 25 Apr 2020 12:14:21 +0300 Subject: [PATCH 06/10] flying control --- src/vehicles/Automobile.cpp | 2 +- src/vehicles/Vehicle.cpp | 129 +++++++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 74609e15..008d50f7 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1013,7 +1013,7 @@ CAutomobile::ProcessControl(void) 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); + FlyingControl(FLIGHT_MODEL_RCPLANE); }else if(GetModelIndex() == MI_MIAMI_RCBARON){ FlyingControl(FLIGHT_MODEL_RCPLANE); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 57c5f3af..7de8bb21 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -185,6 +185,35 @@ CVehicle::GetHeightAboveRoad(void) return -1.0f * GetColModel()->boundingBox.min.z; } +const float fRCPropFallOff = 3.0f; +const float fRCAeroThrust = 0.003f; +const float fRCSideSlipMult = 0.1f; +const float fRCRudderMult = 0.2f; +const float fRCYawMult = -0.01f; +const float fRCRollMult = 0.02f; +const float fRCRollStabilise = -0.08f; +const float fRCPitchMult = 0.005f; +const float fRCTailMult = 0.3f; +const float fRCFormLiftMult = 0.02f; +const float fRCAttackLiftMult = 0.25f; +const CVector vecRCAeroResistance(0.998f, 0.998f, 0.9f); + +const float fSeaPropFallOff = 2.3f; +const float fSeaThrust = 0.002f; +const float fSeaSideSlipMult = 0.1f; +const float fSeaRudderMult = 0.01f; +const float fSeaYawMult = 0.0003f; +const float fSeaRollMult = 0.0015f; +const float fSeaRollStabilise = -0.01f; +const float fSeaPitchMult = 0.0002f; +const float fSeaTailMult = 0.01f; +const float fSeaFormLiftMult = 0.012f; +const float fSeaAttackLiftMult = 0.1f; +const CVector vecSeaAeroResistance(0.995f, 0.995f, 0.85f); + +const float fSpeedResistanceY = 500.0f; +const float fSpeedResistanceZ = 500.0f; + void CVehicle::FlyingControl(eFlightModel flightModel) { @@ -229,18 +258,112 @@ CVehicle::FlyingControl(eFlightModel flightModel) m_vecTurnSpeed.y *= Pow(0.9f, CTimer::GetTimeStep()); moveSpeed = m_vecMoveSpeed.MagnitudeSqr(); - if(moveSpeed > 2.25f) + if(moveSpeed > SQR(1.5f)) m_vecMoveSpeed *= 1.5f/Sqrt(moveSpeed); float turnSpeed = m_vecTurnSpeed.MagnitudeSqr(); - if(turnSpeed > 0.04f) + if(turnSpeed > SQR(0.2f)) m_vecTurnSpeed *= 0.2f/Sqrt(turnSpeed); } break; case FLIGHT_MODEL_RCPLANE: case FLIGHT_MODEL_SEAPLANE: - assert(0 && "Plane flight model not implemented"); + { + // thrust + float fForwSpeed = DotProduct(GetMoveSpeed(), GetForward()); + CVector vecWidthForward = GetColModel()->boundingBox.min.y * GetForward(); + float fThrust = (CPad::GetPad(0)->GetAccelerate() - CPad::GetPad(0)->GetBrake()) / 255.0f; + if (fForwSpeed > 0.1f || (flightModel == FLIGHT_MODEL_RCPLANE && fForwSpeed > 0.02f)) + fThrust += 1.0f; + else if (fForwSpeed > 0.0f && fThrust < 0.0f) + fThrust = 0.0f; + float fThrustImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fThrustImpulse = (fThrust - fRCPropFallOff * fForwSpeed) * fRCAeroThrust; + else + fThrustImpulse = (fThrust - fSeaPropFallOff * fForwSpeed) * fSeaThrust; + ApplyMoveForce(fThrustImpulse * GetForward() * m_fMass * CTimer::GetTimeStep()); + + // left/right + float fSideSpeed = -DotProduct(GetMoveSpeed(), GetRight()); + float fSteerLR = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f; + float fSideSlipImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fSideSlipImpulse = Abs(fSideSpeed) * fSideSpeed * fRCSideSlipMult; + else + fSideSlipImpulse = Abs(fSideSpeed) * fSideSpeed * fSeaSideSlipMult; + ApplyMoveForce(m_fMass * GetRight() * fSideSlipImpulse * CTimer::GetTimeStep()); + + float fYaw = -DotProduct(CrossProduct(m_vecTurnSpeed + m_vecTurnFriction, vecWidthForward) + m_vecMoveSpeed + m_vecMoveFriction, GetRight()); + float fYawImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fYawImpulse = fRCRudderMult * fYaw * Abs(fYaw) + fRCYawMult * fSteerLR * fForwSpeed; + else + fYawImpulse = fSeaRudderMult * fYaw * Abs(fYaw) + fSeaYawMult * fSteerLR * fForwSpeed; + ApplyTurnForce(fYawImpulse * GetRight() * m_fTurnMass * CTimer::GetTimeStep(), vecWidthForward); + + float fRollImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) { + float fDirectionMultiplier = CPad::GetPad(0)->GetLookRight(); + if (CPad::GetPad(0)->GetLookLeft()) + fDirectionMultiplier = -1; + fRollImpulse = (0.5f * fDirectionMultiplier + fSteerLR) * fRCRollMult; + } + else + fRollImpulse = fSteerLR * fSeaRollMult; + ApplyTurnForce(GetRight() * fRollImpulse * fForwSpeed * m_fTurnMass * CTimer::GetTimeStep(), GetUp()); + + CVector vecFRight = CrossProduct(GetForward(), CVector(0.0f, 0.0f, 1.0f)); + CVector vecStabilise = (GetUp().z > 0.0f) ? vecFRight : -vecFRight; + float fStabiliseDirection = (GetUp().z > 0.0f) ? -1.0f : 1.0f; + float fStabiliseImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fStabiliseImpulse = fRCRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z)); + else + fStabiliseImpulse = fSeaRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z)); + ApplyTurnForce(fStabiliseImpulse * m_fTurnMass * GetRight(), GetUp()); // no CTimer::GetTimeStep(), is it right? VC doesn't have it too + + // up/down + float fTail = -DotProduct(CrossProduct(m_vecTurnSpeed + m_vecTurnFriction, vecWidthForward) + m_vecMoveSpeed + m_vecMoveFriction, GetUp()); + float fSteerUD = -CPad::GetPad(0)->GetSteeringUpDown() / 128.0f; + float fPitchImpulse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fPitchImpulse = fRCTailMult * fTail * Abs(fTail) + fRCPitchMult * fSteerUD * fForwSpeed; + else + fPitchImpulse = fSeaTailMult * fTail * Abs(fTail) + fSeaPitchMult * fSteerUD * fForwSpeed; + ApplyTurnForce(fPitchImpulse* m_fTurnMass* GetRight()* CTimer::GetTimeStep(), vecWidthForward); + + float fLift = -DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude()); + float fLiftImpluse; + if (flightModel == FLIGHT_MODEL_RCPLANE) + fLiftImpluse = (fRCAttackLiftMult * fLift + fRCFormLiftMult) * fForwSpeed * fForwSpeed; + else + fLiftImpluse = fSeaAttackLiftMult * fLift + fSeaFormLiftMult * fForwSpeed * fForwSpeed; + float fLiftForce = fLiftImpluse * m_fMass * CTimer::GetTimeStep(); + if (GRAVITY * CTimer::GetTimeStep() * m_fMass < fLiftImpluse) { + if (flightModel == FLIGHT_MODEL_RCPLANE && GetPosition().z > 50.0f) + fLiftForce = CTimer::GetTimeStep() * 0.0072 * m_fMass; + else if (flightModel == FLIGHT_MODEL_SEAPLANE && GetPosition().z > 80.0f) + fLiftForce = CTimer::GetTimeStep() * 0.0072 * m_fMass; + } + ApplyMoveForce(fLiftForce * GetUp()); + CVector vecResistance; + if (flightModel == FLIGHT_MODEL_RCPLANE) + vecResistance = vecRCAeroResistance; + else + vecResistance = vecSeaAeroResistance; + float rX = Pow(vecResistance.x, CTimer::GetTimeStep()); + float rY = Pow(vecResistance.y, CTimer::GetTimeStep()); + float rZ = Pow(vecResistance.z, CTimer::GetTimeStep()); + CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix()); + vecTurnSpeed.x *= rX; + float fResistance = vecTurnSpeed.y * (1.0f / (fSpeedResistanceY * SQR(vecTurnSpeed.y) + 1.0f)) * rY - vecTurnSpeed.y; + vecTurnSpeed.z *= rZ; + m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed); + ApplyTurnForce(-GetUp() * fResistance * m_fTurnMass, GetRight() + Multiply3x3(GetMatrix(), m_vecCentreOfMass)); + break; + } case FLIGHT_MODEL_HELI: assert(0 && "Heli flight model not implemented"); } From f3ae4fa1844f8656c661591b34e7e875e689b92d Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 25 Apr 2020 12:14:51 +0300 Subject: [PATCH 07/10] undo --- src/vehicles/Automobile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 008d50f7..74609e15 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1013,7 +1013,7 @@ CAutomobile::ProcessControl(void) 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_RCPLANE); + FlyingControl(FLIGHT_MODEL_DODO); }else if(GetModelIndex() == MI_MIAMI_RCBARON){ FlyingControl(FLIGHT_MODEL_RCPLANE); }else if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW || bAllCarCheat){ From d9bd6342dddf0dd33918dd3a52b62933837a3ce1 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 25 Apr 2020 12:15:58 +0300 Subject: [PATCH 08/10] librw update --- librw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librw b/librw index 374f951d..5ffbde38 160000 --- a/librw +++ b/librw @@ -1 +1 @@ -Subproject commit 374f951d7cee353914059d8ddf9c5aff7d764984 +Subproject commit 5ffbde3890d1f959490c3ce16721c2a263415d8d From 40ec6362917ece931e8b00dd71e42c523ef53256 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 25 Apr 2020 16:47:39 +0300 Subject: [PATCH 09/10] fixed flight control code --- src/vehicles/Vehicle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index ef706f11..a3bb705a 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -202,7 +202,7 @@ const float fSeaPropFallOff = 2.3f; const float fSeaThrust = 0.002f; const float fSeaSideSlipMult = 0.1f; const float fSeaRudderMult = 0.01f; -const float fSeaYawMult = 0.0003f; +const float fSeaYawMult = -0.0003f; const float fSeaRollMult = 0.0015f; const float fSeaRollStabilise = -0.01f; const float fSeaPitchMult = 0.0002f; @@ -316,7 +316,7 @@ CVehicle::FlyingControl(eFlightModel flightModel) CVector vecFRight = CrossProduct(GetForward(), CVector(0.0f, 0.0f, 1.0f)); CVector vecStabilise = (GetUp().z > 0.0f) ? vecFRight : -vecFRight; - float fStabiliseDirection = (GetUp().z > 0.0f) ? -1.0f : 1.0f; + float fStabiliseDirection = (GetRight().z > 0.0f) ? -1.0f : 1.0f; float fStabiliseImpulse; if (flightModel == FLIGHT_MODEL_RCPLANE) fStabiliseImpulse = fRCRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z)); @@ -332,14 +332,14 @@ CVehicle::FlyingControl(eFlightModel flightModel) fPitchImpulse = fRCTailMult * fTail * Abs(fTail) + fRCPitchMult * fSteerUD * fForwSpeed; else fPitchImpulse = fSeaTailMult * fTail * Abs(fTail) + fSeaPitchMult * fSteerUD * fForwSpeed; - ApplyTurnForce(fPitchImpulse* m_fTurnMass* GetRight()* CTimer::GetTimeStep(), vecWidthForward); + ApplyTurnForce(fPitchImpulse* m_fTurnMass* GetUp()* CTimer::GetTimeStep(), vecWidthForward); float fLift = -DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude()); float fLiftImpluse; if (flightModel == FLIGHT_MODEL_RCPLANE) fLiftImpluse = (fRCAttackLiftMult * fLift + fRCFormLiftMult) * fForwSpeed * fForwSpeed; else - fLiftImpluse = fSeaAttackLiftMult * fLift + fSeaFormLiftMult * fForwSpeed * fForwSpeed; + fLiftImpluse = (fSeaAttackLiftMult * fLift + fSeaFormLiftMult) * fForwSpeed * fForwSpeed; float fLiftForce = fLiftImpluse * m_fMass * CTimer::GetTimeStep(); if (GRAVITY * CTimer::GetTimeStep() * m_fMass < fLiftImpluse) { if (flightModel == FLIGHT_MODEL_RCPLANE && GetPosition().z > 50.0f) From ae8deff1315f8535ebed4ae4a22d1dd7e808f3d0 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 25 Apr 2020 21:25:14 +0300 Subject: [PATCH 10/10] helis done + cheats --- src/core/Pad.cpp | 44 ++++++++++++++++++ src/core/Pad.h | 4 ++ src/core/config.h | 2 + src/vehicles/Automobile.cpp | 24 +++++++--- src/vehicles/Vehicle.cpp | 89 ++++++++++++++++++++++++++++++++++++- src/vehicles/Vehicle.h | 3 ++ 6 files changed, 158 insertions(+), 8 deletions(-) diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 8a3fc7cb..44b22d6d 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -291,6 +291,38 @@ void KangarooCheat() } #endif +#ifdef ALLCARSHELI_CHEAT +void AllCarsHeliCheat(void) +{ + wchar* string; + if (bAllCarCheat) { + string = TheText.Get("CHEATOF"); + bAllCarCheat = false; + } + else { + string = TheText.Get("CHEAT1"); + bAllCarCheat = true; + } + CHud::SetHelpMessage(string, true); +} +#endif + +#ifdef ALT_DODO_CHEAT +void AltDodoCheat(void) +{ + wchar* string; + if (CVehicle::bAltDodoCheat) { + string = TheText.Get("CHEATOF"); + CVehicle::bAltDodoCheat = false; + } + else { + string = TheText.Get("CHEAT1"); + CVehicle::bAltDodoCheat = true; + } + CHud::SetHelpMessage(string, true); +} +#endif + void CControllerState::Clear(void) { @@ -861,6 +893,18 @@ void CPad::AddToPCCheatString(char c) if (!_CHEATCMP("GUBEDDEP")) CPed::SwitchDebugDisplay(); #endif + +#ifdef ALLCARSHELI_CHEAT + // "CARSAREHELI" + if (!_CHEATCMP("ILEHERASRAC")) + AllCarsHeliCheat(); +#endif + +#ifdef ALT_DODO_CHEAT + // "IWANTTOMASTERDODO" + if (!_CHEATCMP("ODODRETSAMOTTNAWI")) + AltDodoCheat(); +#endif #undef _CHEATCMP } diff --git a/src/core/Pad.h b/src/core/Pad.h index b3b0849b..b8228444 100644 --- a/src/core/Pad.h +++ b/src/core/Pad.h @@ -450,3 +450,7 @@ public: VALIDATE_SIZE(CPad, 0xFC); extern CPad Pads[MAX_PADS]; + +#ifdef ALLCARSHELI_CHEAT +extern bool bAllCarCheat; +#endif diff --git a/src/core/config.h b/src/core/config.h index 84712af3..a6876ab0 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -202,6 +202,8 @@ enum Config { // Pad #define XINPUT #define KANGAROO_CHEAT +#define ALLCARSHELI_CHEAT +#define ALT_DODO_CHEAT #define REGISTER_START_BUTTON // Hud, frontend and radar diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 74609e15..bfb215d2 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1013,16 +1013,28 @@ CAutomobile::ProcessControl(void) 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); +#ifdef ALT_DODO_CHEAT + if (bAltDodoCheat) + FlyingControl(FLIGHT_MODEL_SEAPLANE); + else +#endif + FlyingControl(FLIGHT_MODEL_DODO); }else if(GetModelIndex() == MI_MIAMI_RCBARON){ FlyingControl(FLIGHT_MODEL_RCPLANE); }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) +#ifdef ALLCARSHELI_CHEAT + if (bAllCarCheat) FlyingControl(FLIGHT_MODEL_HELI); + else +#endif + { + 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); + } } } diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index a3bb705a..d0ccd31b 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -24,6 +24,9 @@ bool CVehicle::bAllDodosCheat; bool CVehicle::bCheat3; bool CVehicle::bCheat4; bool CVehicle::bCheat5; +#ifdef ALT_DODO_CHEAT +bool CVehicle::bAltDodoCheat; +#endif bool CVehicle::m_bDisableMouseSteering = true; void *CVehicle::operator new(size_t sz) { return CPools::GetVehiclePool()->New(); } @@ -214,6 +217,19 @@ const CVector vecSeaAeroResistance(0.995f, 0.995f, 0.85f); const float fSpeedResistanceY = 500.0f; const float fSpeedResistanceZ = 500.0f; +const CVector vecHeliMoveRes(0.995f, 0.995f, 0.99f); +const CVector vecRCHeliMoveRes(0.99f, 0.99f, 0.99f); +const float fThrustVar = 0.3f; +const float fRotorFallOff = 0.75f; +const float fStabiliseVar = 0.015f; +const float fPitchBrake = 10.0f; +const float fPitchVar = 0.006f; +const float fRollVar = 0.006f; +const float fYawVar = -0.001f; +const CVector vecHeliResistance(0.81f, 0.85f, 0.99f); +const CVector vecRCHeliResistance(0.92f, 0.92f, 0.998f); +const float fSpinSpeedRes = 20.0f; + void CVehicle::FlyingControl(eFlightModel flightModel) { @@ -332,7 +348,7 @@ CVehicle::FlyingControl(eFlightModel flightModel) fPitchImpulse = fRCTailMult * fTail * Abs(fTail) + fRCPitchMult * fSteerUD * fForwSpeed; else fPitchImpulse = fSeaTailMult * fTail * Abs(fTail) + fSeaPitchMult * fSteerUD * fForwSpeed; - ApplyTurnForce(fPitchImpulse* m_fTurnMass* GetUp()* CTimer::GetTimeStep(), vecWidthForward); + ApplyTurnForce(fPitchImpulse * m_fTurnMass * GetUp() * CTimer::GetTimeStep(), vecWidthForward); float fLift = -DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude()); float fLiftImpluse; @@ -365,7 +381,76 @@ CVehicle::FlyingControl(eFlightModel flightModel) break; } case FLIGHT_MODEL_HELI: - assert(0 && "Heli flight model not implemented"); + { + CVector vecMoveResistance; + if (GetModelIndex() == MI_MIAMI_SPARROW) + vecMoveResistance = vecHeliMoveRes; + else + vecMoveResistance = vecRCHeliMoveRes; + float rmX = Pow(vecMoveResistance.x, CTimer::GetTimeStep()); + float rmY = Pow(vecMoveResistance.y, CTimer::GetTimeStep()); + float rmZ = Pow(vecMoveResistance.z, CTimer::GetTimeStep()); + m_vecMoveSpeed.x *= rmX; + m_vecMoveSpeed.y *= rmY; + m_vecMoveSpeed.z *= rmZ; + if (m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE) + return; + float fThrust; + if (bCheat5) + fThrust = CPad::GetPad(0)->GetSteeringUpDown() * fThrustVar / 128.0f + 0.95f; + else + fThrust = fThrustVar * (CPad::GetPad(0)->GetAccelerate() - 2 * CPad::GetPad(0)->GetBrake()) / 255.0f + 0.95f; + fThrust -= fRotorFallOff * DotProduct(m_vecMoveSpeed, GetUp()); +#ifdef GTA3_1_1_PATCH + if (fThrust > 0.9f && GetPosition().z > 80.0f) + fThrust = 0.9f; +#endif + ApplyMoveForce(GRAVITY * GetUp() * fThrust * m_fMass * CTimer::GetTimeStep()); + + if (GetUp().z > 0.0f) + ApplyTurnForce(-CVector(GetUp().x, GetUp().y, 0.0f) * fStabiliseVar * m_fTurnMass * CTimer::GetTimeStep(), GetUp()); + + float fRoll, fPitch, fYaw; + if (bCheat5) { + fPitch = CPad::GetPad(0)->GetCarGunUpDown() / 128.0f; + fRoll = -CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f; + fYaw = CPad::GetPad(0)->GetCarGunLeftRight() / 128.0f; + } + else { + fPitch = CPad::GetPad(0)->GetSteeringUpDown() / 128.0f; + fRoll = CPad::GetPad(0)->GetLookLeft(); + if (CPad::GetPad(0)->GetLookRight()) + fRoll = -1.0f; + fYaw = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f; + } + if (CPad::GetPad(0)->GetHorn()) { + fYaw = 0.0f; + fPitch = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetUp()), -200.0f, 1.3f); + fRoll = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f); + } + debug("fPitch: %f\n", fPitch); + ApplyTurnForce(fPitch * GetUp() * fPitchVar * m_fTurnMass * CTimer::GetTimeStep(), GetForward()); + ApplyTurnForce(fRoll * GetUp() * fRollVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight()); + ApplyTurnForce(fYaw * GetForward() * fYawVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight()); + + CVector vecResistance; + if (GetModelIndex() == MI_MIAMI_SPARROW) + vecResistance = vecHeliResistance; + else + vecResistance = vecRCHeliResistance; + float rX = Pow(vecResistance.x, CTimer::GetTimeStep()); + float rY = Pow(vecResistance.y, CTimer::GetTimeStep()); + float rZ = Pow(vecResistance.z, CTimer::GetTimeStep()); + CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix()); + float fResistanceMultiplier = Pow(1.0f / (fSpinSpeedRes * SQR(vecTurnSpeed.z) + 1.0f), CTimer::GetTimeStep()); + float fResistance = vecTurnSpeed.z * fResistanceMultiplier - vecTurnSpeed.z; + vecTurnSpeed.x *= rX; + vecTurnSpeed.y *= rY; + vecTurnSpeed.z *= rZ; + m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed); + ApplyTurnForce(-GetRight() * fResistance * m_fTurnMass, GetForward() + Multiply3x3(GetMatrix(), m_vecCentreOfMass)); + break; + } } } diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index 2ae78829..f9ff1037 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -280,6 +280,9 @@ public: static bool bCheat3; static bool bCheat4; static bool bCheat5; +#ifdef ALT_DODO_CHEAT + static bool bAltDodoCheat; +#endif static bool m_bDisableMouseSteering; };