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 /src/vehicles | |
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 |
Diffstat (limited to 'src/vehicles')
-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 |
8 files changed, 176 insertions, 43 deletions
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; |