diff options
author | aap <aap@papnet.eu> | 2019-07-17 13:19:20 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2019-07-17 13:19:20 +0200 |
commit | 0f1fbf5e9a7477c6fbb7645491598e87ed2e183e (patch) | |
tree | 713a8e10b3657d4c3a0d9c20c3704e0da8f9357e | |
parent | Merge pull request #139 from Nick007J/master (diff) | |
download | re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar.gz re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar.bz2 re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar.lz re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar.xz re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.tar.zst re3-0f1fbf5e9a7477c6fbb7645491598e87ed2e183e.zip |
-rw-r--r-- | src/control/CarAI.cpp | 5 | ||||
-rw-r--r-- | src/control/CarAI.h | 9 | ||||
-rw-r--r-- | src/control/CarCtrl.cpp | 2 | ||||
-rw-r--r-- | src/control/CarCtrl.h | 2 | ||||
-rw-r--r-- | src/control/Garages.cpp | 2 | ||||
-rw-r--r-- | src/control/Garages.h | 1 | ||||
-rw-r--r-- | src/control/Population.cpp | 1 | ||||
-rw-r--r-- | src/control/Population.h | 1 | ||||
-rw-r--r-- | src/control/Remote.cpp | 5 | ||||
-rw-r--r-- | src/control/Remote.h | 7 | ||||
-rw-r--r-- | src/control/Script.cpp | 2 | ||||
-rw-r--r-- | src/peds/Ped.cpp | 2 | ||||
-rw-r--r-- | src/vehicles/Automobile.cpp | 153 | ||||
-rw-r--r-- | src/vehicles/Automobile.h | 2 | ||||
-rw-r--r-- | src/vehicles/HandlingMgr.cpp | 36 | ||||
-rw-r--r-- | src/vehicles/HandlingMgr.h | 2 | ||||
-rw-r--r-- | src/vehicles/Transmission.cpp | 15 | ||||
-rw-r--r-- | src/vehicles/Transmission.h | 3 | ||||
-rw-r--r-- | src/vehicles/Vehicle.cpp | 6 | ||||
-rw-r--r-- | src/vehicles/Vehicle.h | 2 |
20 files changed, 213 insertions, 45 deletions
diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp new file mode 100644 index 00000000..92dc5ab9 --- /dev/null +++ b/src/control/CarAI.cpp @@ -0,0 +1,5 @@ +#include "common.h" +#include "patcher.h" +#include "CarAI.h" + +WRAPPER void CCarAI::UpdateCarAI(CVehicle*) { EAXJMP(0x413E50); } diff --git a/src/control/CarAI.h b/src/control/CarAI.h new file mode 100644 index 00000000..d463e1a9 --- /dev/null +++ b/src/control/CarAI.h @@ -0,0 +1,9 @@ +#pragma once + +class CVehicle; + +class CCarAI +{ +public: + static void UpdateCarAI(CVehicle*); +}; diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 8c2ee76c..7acfa64a 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -14,3 +14,5 @@ WRAPPER void CCarCtrl::UpdateCarCount(CVehicle*, bool) { EAXJMP(0x4202E0); } WRAPPER int32 CCarCtrl::ChooseCarModel(int32 vehclass) { EAXJMP(0x418110); } WRAPPER bool CCarCtrl::JoinCarWithRoadSystemGotoCoors(CVehicle*, CVector, bool) { EAXJMP(0x41FA00); } WRAPPER void CCarCtrl::JoinCarWithRoadSystem(CVehicle*) { EAXJMP(0x41F820); } +WRAPPER void CCarCtrl::SteerAICarWithPhysics(CVehicle*) { EAXJMP(0x41DA60); } +WRAPPER void CCarCtrl::UpdateCarOnRails(CVehicle*) { EAXJMP(0x418880); } diff --git a/src/control/CarCtrl.h b/src/control/CarCtrl.h index 1fe3c31e..a15279d3 100644 --- a/src/control/CarCtrl.h +++ b/src/control/CarCtrl.h @@ -11,6 +11,8 @@ public: static int32 ChooseCarModel(int32 vehclass); static bool JoinCarWithRoadSystemGotoCoors(CVehicle*, CVector, bool); static void JoinCarWithRoadSystem(CVehicle*); + static void SteerAICarWithPhysics(CVehicle*); + static void UpdateCarOnRails(CVehicle*); static int32 &NumLawEnforcerCars; static int32 &NumAmbulancesOnDuty; diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index d601db8e..acc2b459 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -63,6 +63,8 @@ CGarages::IsModelIndexADoor(uint32 id) id == MI_CRUSHERLID; } +WRAPPER void CGarages::TriggerMessage(char *text, int16, uint16 time, int16) { EAXJMP(0x426B20); } + #if 0 WRAPPER void CGarages::PrintMessages(void) { EAXJMP(0x426310); } #else diff --git a/src/control/Garages.h b/src/control/Garages.h index f018401c..69f9d256 100644 --- a/src/control/Garages.h +++ b/src/control/Garages.h @@ -22,5 +22,6 @@ public: public: static bool IsModelIndexADoor(uint32 id); + static void TriggerMessage(char *text, int16, uint16 time, int16); static void PrintMessages(void); }; diff --git a/src/control/Population.cpp b/src/control/Population.cpp index 72de300d..31c475f0 100644 --- a/src/control/Population.cpp +++ b/src/control/Population.cpp @@ -12,3 +12,4 @@ uint32 &CPopulation::ms_nTotalMissionPeds = *(uint32*)0x8F5F70; WRAPPER void CPopulation::UpdatePedCount(uint32, bool) { EAXJMP(0x4F5A60); } WRAPPER void CPopulation::DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool) { EAXJMP(0x4F6200); } WRAPPER CPed *CPopulation::AddPedInCar(CVehicle *vehicle) { EAXJMP(0x4F5800); } +WRAPPER bool CPopulation::IsPointInSafeZone(CVector *coors) { EAXJMP(0x4F60C0); } diff --git a/src/control/Population.h b/src/control/Population.h index e24ace3a..cfa9508f 100644 --- a/src/control/Population.h +++ b/src/control/Population.h @@ -20,4 +20,5 @@ public: static void UpdatePedCount(uint32, bool); static void DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool); static CPed *AddPedInCar(CVehicle *vehicle); + static bool IsPointInSafeZone(CVector *coors); }; diff --git a/src/control/Remote.cpp b/src/control/Remote.cpp new file mode 100644 index 00000000..8d8d08f2 --- /dev/null +++ b/src/control/Remote.cpp @@ -0,0 +1,5 @@ +#include "common.h" +#include "patcher.h" +#include "Remote.h" + +WRAPPER void CRemote::TakeRemoteControlledCarFromPlayer(void) { EAXJMP(0x435DA0); } diff --git a/src/control/Remote.h b/src/control/Remote.h new file mode 100644 index 00000000..f8ef96bf --- /dev/null +++ b/src/control/Remote.h @@ -0,0 +1,7 @@ +#pragma once + +class CRemote +{ +public: + static void TakeRemoteControlledCarFromPlayer(void); +}; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 5e9f51af..85e27956 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -2050,7 +2050,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->m_handling->TransmissionData.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/peds/Ped.cpp b/src/peds/Ped.cpp index dc645003..b1738465 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1460,7 +1460,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enter seatOffset = 0.0f; vehDoorOffset = offsetToOpenVanDoor; } else { - seatOffset = veh->m_handling->fSeatOffsetDistance * seatPosMult; + seatOffset = veh->pHandling->fSeatOffsetDistance * seatPosMult; if (veh->bLowVehicle) { vehDoorOffset = offsetToOpenLowCarDoor; } else { diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 9e6ec173..6e31414f 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -12,7 +12,12 @@ #include "World.h" #include "SurfaceTable.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 "Ped.h" #include "PlayerPed.h" @@ -55,9 +60,27 @@ CAutomobile::ProcessControl(void) if(colModel->level > LEVEL_NONE && colModel->level != CCollision::ms_collisionInMemory) return; - bool strongGrip = false; - - assert(0 && "some player stuff"); + // 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(); @@ -127,24 +150,106 @@ CAutomobile::ProcessControl(void) AutoPilot.m_flag2 = false; // Set Center of Mass to make car more stable - if(strongGrip || bCheat3) + if(strongGrip1 || bCheat3) m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0*m_fHeightAboveRoad; - else if(m_handling->Flags & HANDLING_NONPLAYER_STABILISER && m_status == STATUS_PHYSICS) - m_vecCentreOfMass.z = m_handling->CentreOfMass.z - 0.2f*m_handling->Dimension.z; + 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 = m_handling->CentreOfMass.z; + 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_2 = 4; + m_nWheelsOnGroundPrev = m_nWheelsOnGround; + m_nWheelsOnGround = 4; + + pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear); + + { + float wheelRot = ProcessWheelRotation(WHEEL_STATE_0, 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: - case STATUS_PLAYER_REMOTE: + m_fBrakePedal = 0.05f; + bIsHandbrakeOn = true; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_nCarHornTimer = 0; + break; + case STATUS_PLAYER_DISABLED: - assert(0); + m_fBrakePedal = 1.0f; + bIsHandbrakeOn = true; + + m_fSteerAngle = 0.0f; + m_fGasPedal = 0.0f; + m_nCarHornTimer = 0; + break; } if(GetPosition().z < -0.6f){ @@ -252,11 +357,11 @@ CAutomobile::ProcessControl(void) // Make springs push up vehicle for(i = 0; i < 4; i++){ if(m_aSuspensionSpringRatio[i] < 1.0f){ - float bias = m_handling->fSuspensionBias; + float bias = pHandling->fSuspensionBias; if(i == 1 || i == 3) // rear bias = 1.0f - bias; - ApplySpringCollision(m_handling->fSuspensionForceLevel, + ApplySpringCollision(pHandling->fSuspensionForceLevel, springDirections[i], contactPoints[i], m_aSuspensionSpringRatio[i], bias); m_aWheelSkidmarkMuddy[i] = @@ -284,7 +389,7 @@ CAutomobile::ProcessControl(void) // dampen springs for(i = 0; i < 4; i++) if(m_aSuspensionSpringRatio[i] < 1.0f) - ApplySpringDampening(m_handling->fSuspensionDampingLevel, + ApplySpringDampening(pHandling->fSuspensionDampingLevel, springDirections[i], contactPoints[i], contactSpeeds[i]); // Get speed at contact points again @@ -493,7 +598,7 @@ CAutomobile::ProcessControlInputs(uint8 pad) fValue = -sq(m_fSteerRatio); else fValue = sq(m_fSteerRatio); - m_fSteerAngle = DEGTORAD(m_handling->fSteeringLock) * fValue; + m_fSteerAngle = DEGTORAD(pHandling->fSteeringLock) * fValue; if(bComedyControls){ int rnd = CGeneral::GetRandomNumber() % 10; @@ -539,6 +644,16 @@ CAutomobile::ProcessBuoyancy(void) { EAXJMP(0x5308D0); } +WRAPPER void +CAutomobile::DoDriveByShootings(void) +{ EAXJMP(0x564000); +} + +WRAPPER int32 +CAutomobile::RcbanditCheckHitWheels(void) +{ EAXJMP(0x53C990); +} + void CAutomobile::GetComponentWorldPosition(int32 component, CVector &pos) { @@ -962,23 +1077,23 @@ CAutomobile::SetupSuspensionLines(void) m_aWheelPosition[i] = posn.z; // uppermost wheel position - posn.z += m_handling->fSuspensionUpperLimit; + posn.z += pHandling->fSuspensionUpperLimit; colModel->lines[i].p0 = posn; // lowermost wheel position - posn.z += m_handling->fSuspensionLowerLimit - m_handling->fSuspensionUpperLimit; + 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] = m_handling->fSuspensionUpperLimit - m_handling->fSuspensionLowerLimit; + 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*m_handling->fSuspensionForceLevel))); + (1.0f - 1.0f/(8.0f*pHandling->fSuspensionForceLevel))); for(i = 0; i < 4; i++) m_aWheelPosition[i] = mi->m_wheelScale*0.5f - m_fHeightAboveRoad; @@ -1129,7 +1244,7 @@ CAutomobile::Fix(void) Damage.ResetDamageStatus(); - if(m_handling->Flags & HANDLING_NO_DOORS){ + 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); @@ -1382,7 +1497,7 @@ CAutomobile::SetDoorDamage(int32 component, eDoors door, bool noFlyingComponents return; } - if(door == DOOR_BOOT && status == DOOR_STATUS_SWINGING && m_handling->Flags & HANDLING_NOSWING_BOOT){ + if(door == DOOR_BOOT && status == DOOR_STATUS_SWINGING && pHandling->Flags & HANDLING_NOSWING_BOOT){ Damage.SetDoorStatus(DOOR_BOOT, DOOR_STATUS_MISSING); status = DOOR_STATUS_MISSING; } diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h index 31042415..6ed5e154 100644 --- a/src/vehicles/Automobile.h +++ b/src/vehicles/Automobile.h @@ -96,6 +96,8 @@ public: void PlayCarHorn(void); void ProcessBuoyancy(void); + void DoDriveByShootings(void); + int32 RcbanditCheckHitWheels(void); void PlayHornIfNecessary(void); void ResetSuspension(void); void SetupSuspensionLines(void); diff --git a/src/vehicles/HandlingMgr.cpp b/src/vehicles/HandlingMgr.cpp index 47d0564c..9bcaaf81 100644 --- a/src/vehicles/HandlingMgr.cpp +++ b/src/vehicles/HandlingMgr.cpp @@ -140,11 +140,11 @@ cHandlingDataMgr::LoadHandlingData(void) case 9: handling->fTractionMultiplier = strtod(word, nil); break; case 10: handling->fTractionLoss = strtod(word, nil); break; case 11: handling->fTractionBias = strtod(word, nil); break; - case 12: handling->TransmissionData.nNumberOfGears = atoi(word); break; - case 13: handling->TransmissionData.fMaxVelocity = strtod(word, nil); break; - case 14: handling->TransmissionData.fEngineAcceleration = strtod(word, nil) * 0.4f; break; - case 15: handling->TransmissionData.nDriveType = word[0]; break; - case 16: handling->TransmissionData.nEngineType = word[0]; break; + case 12: handling->Transmission.nNumberOfGears = atoi(word); break; + case 13: handling->Transmission.fMaxVelocity = strtod(word, nil); break; + case 14: handling->Transmission.fEngineAcceleration = strtod(word, nil) * 0.4f; break; + case 15: handling->Transmission.nDriveType = word[0]; break; + case 16: handling->Transmission.nEngineType = word[0]; break; case 17: handling->fBrakeDeceleration = strtod(word, nil); break; case 18: handling->fBrakeBias = strtod(word, nil); break; case 19: handling->bABS = !!atoi(word); break; @@ -159,7 +159,7 @@ cHandlingDataMgr::LoadHandlingData(void) case 28: handling->fSuspensionBias = strtod(word, nil); break; case 29: sscanf(word, "%x", &handling->Flags); - handling->TransmissionData.Flags = handling->Flags; + handling->Transmission.Flags = handling->Flags; break; case 30: handling->FrontLights = atoi(word); break; case 31: handling->RearLights = atoi(word); break; @@ -192,8 +192,8 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling) // TODO: figure out what exactly is being converted here float velocity, a, b, specificVolume; - handling->TransmissionData.fEngineAcceleration /= 2500.0f; - handling->TransmissionData.fMaxVelocity /= 180.0f; + handling->Transmission.fEngineAcceleration /= 2500.0f; + handling->Transmission.fMaxVelocity /= 180.0f; handling->fBrakeDeceleration /= 2500.0f; handling->fTurnMass = (sq(handling->Dimension.x) + sq(handling->Dimension.y)) * handling->fMass / 12.0f; if(handling->fTurnMass < 10.0f) @@ -205,27 +205,27 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling) specificVolume = handling->Dimension.x*handling->Dimension.z*0.5f / handling->fMass; // ? a = 0.0f; b = 100.0f; - velocity = handling->TransmissionData.fMaxVelocity; + velocity = handling->Transmission.fMaxVelocity; while(a < b && velocity > 0.0f){ velocity -= 0.01; - a = handling->TransmissionData.fEngineAcceleration/6.0f; + a = handling->Transmission.fEngineAcceleration/6.0f; b = -velocity * (1.0f/(specificVolume * sq(velocity) + 1.0f) - 1.0f); } if(handling->nIdentifier == HANDLING_RCBANDIT){ - handling->TransmissionData.fUnkMaxVelocity = handling->TransmissionData.fMaxVelocity; + handling->Transmission.fUnkMaxVelocity = handling->Transmission.fMaxVelocity; }else{ - handling->TransmissionData.fUnkMaxVelocity = velocity; - handling->TransmissionData.fMaxVelocity = velocity * 1.2f; + handling->Transmission.fUnkMaxVelocity = velocity; + handling->Transmission.fMaxVelocity = velocity * 1.2f; } - handling->TransmissionData.fMaxReverseVelocity = -0.2f; + handling->Transmission.fMaxReverseVelocity = -0.2f; - if(handling->TransmissionData.nDriveType == '4') - handling->TransmissionData.fEngineAcceleration /= 4.0f; + if(handling->Transmission.nDriveType == '4') + handling->Transmission.fEngineAcceleration /= 4.0f; else - handling->TransmissionData.fEngineAcceleration /= 2.0f; + handling->Transmission.fEngineAcceleration /= 2.0f; - handling->TransmissionData.InitGearRatios(); + handling->Transmission.InitGearRatios(); } int32 diff --git a/src/vehicles/HandlingMgr.h b/src/vehicles/HandlingMgr.h index 2627fbae..7d8613da 100644 --- a/src/vehicles/HandlingMgr.h +++ b/src/vehicles/HandlingMgr.h @@ -94,7 +94,7 @@ struct tHandlingData int8 nPercentSubmerged; float fBuoyancy; float fTractionMultiplier; - cTransmission TransmissionData; + cTransmission Transmission; float fBrakeDeceleration; float fBrakeBias; int8 bABS; diff --git a/src/vehicles/Transmission.cpp b/src/vehicles/Transmission.cpp index 2be25cbb..f8c345f1 100644 --- a/src/vehicles/Transmission.cpp +++ b/src/vehicles/Transmission.cpp @@ -35,3 +35,18 @@ cTransmission::InitGearRatios(void) Gears[1].fShiftDownVelocity = -0.01f; } + +void +cTransmission::CalculateGearForSimpleCar(float speed, uint8 &gear) +{ + static tGear *pGearRatio = &Gears[gear]; + fCurVelocity = speed; + if(speed > pGearRatio->fShiftUpVelocity) + gear++; + else if(speed < pGearRatio->fShiftDownVelocity){ + if(gear - 1 < 0) + gear = 0; + else + gear--; + } +} diff --git a/src/vehicles/Transmission.h b/src/vehicles/Transmission.h index 686e0aca..ea67b62c 100644 --- a/src/vehicles/Transmission.h +++ b/src/vehicles/Transmission.h @@ -20,7 +20,8 @@ public: float fMaxVelocity; float fUnkMaxVelocity; float fMaxReverseVelocity; - float field_5C; + float fCurVelocity; void InitGearRatios(void); + void CalculateGearForSimpleCar(float speed, uint8 &gear); }; diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 3ef581a0..f3a8f785 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -259,7 +259,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon adhesion *= CTimer::GetTimeStep(); if(bAlreadySkidding) - adhesion *= m_handling->fTractionLoss; + adhesion *= pHandling->fTractionLoss; // moving sideways if(contactSpeedRight != 0.0f){ @@ -318,7 +318,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon } float l = Sqrt(sq(right) + sq(fwd)); - float tractionLoss = bAlreadySkidding ? 1.0f : m_handling->fTractionLoss; + float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss; right *= adhesion * tractionLoss / l; fwd *= adhesion * tractionLoss / l; } @@ -450,7 +450,7 @@ CVehicle::IsVehicleNormal(void) bool CVehicle::CarHasRoof(void) { - if((m_handling->Flags & HANDLING_HAS_NO_ROOF) == 0) + if((pHandling->Flags & HANDLING_HAS_NO_ROOF) == 0) return true; if(m_aExtras[0] && m_aExtras[1]) return false; diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index 1f848dc8..b37ea84d 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -125,7 +125,7 @@ class CVehicle : public CPhysical { public: // 0x128 - tHandlingData *m_handling; + tHandlingData *pHandling; CAutoPilot AutoPilot; uint8 m_currentColour1; uint8 m_currentColour2; |