summaryrefslogtreecommitdiffstats
path: root/src/vehicles/Transmission.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-17 23:58:06 +0200
committeraap <aap@papnet.eu>2019-07-17 23:58:06 +0200
commitba242bcf584d885167a9499e53f5bcaf6c9cc866 (patch)
tree29477a626a36462ec3280081388ff1b965be860f /src/vehicles/Transmission.cpp
parentMerge pull request #145 from guard3/master (diff)
downloadre3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar.gz
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar.bz2
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar.lz
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar.xz
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.tar.zst
re3-ba242bcf584d885167a9499e53f5bcaf6c9cc866.zip
Diffstat (limited to 'src/vehicles/Transmission.cpp')
-rw-r--r--src/vehicles/Transmission.cpp93
1 files changed, 92 insertions, 1 deletions
diff --git a/src/vehicles/Transmission.cpp b/src/vehicles/Transmission.cpp
index f8c345f1..d500d004 100644
--- a/src/vehicles/Transmission.cpp
+++ b/src/vehicles/Transmission.cpp
@@ -1,5 +1,7 @@
#include "common.h"
#include "patcher.h"
+#include "Timer.h"
+#include "HandlingMgr.h"
#include "Transmission.h"
void
@@ -39,7 +41,9 @@ cTransmission::InitGearRatios(void)
void
cTransmission::CalculateGearForSimpleCar(float speed, uint8 &gear)
{
- static tGear *pGearRatio = &Gears[gear];
+ static tGear *pGearRatio;
+
+ pGearRatio = &Gears[gear];
fCurVelocity = speed;
if(speed > pGearRatio->fShiftUpVelocity)
gear++;
@@ -50,3 +54,90 @@ cTransmission::CalculateGearForSimpleCar(float speed, uint8 &gear)
gear--;
}
}
+
+float
+cTransmission::CalculateDriveAcceleration(const float &gasPedal, uint8 &gear, float &time, const float &velocity, bool cheat)
+{
+ static float fAcceleration = 0.0f;
+ static float fVelocity;
+ static float fCheat;
+ static tGear *pGearRatio;
+
+ fVelocity = velocity;
+ if(fVelocity < fMaxReverseVelocity){
+ fVelocity = fMaxReverseVelocity;
+ return 0.0f;
+ }
+ if(fVelocity > fMaxVelocity){
+ fVelocity = fMaxVelocity;
+ return 0.0f;
+ }
+ fCurVelocity = fVelocity;
+
+ assert(gear <= nNumberOfGears);
+
+ pGearRatio = &Gears[gear];
+ if(fVelocity > pGearRatio->fShiftUpVelocity){
+ if(gear != 0 || gasPedal > 0.0f){
+ gear++;
+ time = 0.0f;
+ return CalculateDriveAcceleration(gasPedal, gear, time, fVelocity, false);
+ }
+ }else if(fVelocity < pGearRatio->fShiftDownVelocity && gear != 0){
+ if(gear != 1 || gasPedal < 0.0f){
+ gear--;
+ time = 0.0f;
+ return CalculateDriveAcceleration(gasPedal, gear, time, fVelocity, false);
+ }
+ }
+
+ if(time > 0.0f){
+ // changing gears currently, can't accelerate
+ fAcceleration = 0.0f;
+ time -= CTimer::GetTimeStepInSeconds();
+ }else{
+ float speedMul, accelMul;
+
+ if(gear < 1){
+ // going reverse
+ accelMul = (Flags & HANDLING_2G_BOOST) ? 2.0f : 1.0f;
+ speedMul = -1.0f;
+ }else if(nNumberOfGears == 1){
+ accelMul = 1.0f;
+ speedMul = 1.0f;
+ }else{
+ // BUG or not? this is 1.0 normally but 0.0 in the highest gear
+ float f = 1.0f - (gear-1)/(nNumberOfGears-1);
+ speedMul = 3.0f*sq(f) + 1.0f;
+ // This is pretty ugly, could be written more clearly
+ if(Flags & HANDLING_2G_BOOST){
+ if(gear == 1)
+ accelMul = (Flags & HANDLING_1G_BOOST) ? 3.0f : 2.0f;
+ else if(gear == 2)
+ accelMul = 1.3f;
+ else
+ accelMul = 1.0f;
+ }else if(Flags & HANDLING_1G_BOOST && gear == 1){
+ accelMul = 3.0f;
+ }else
+ accelMul = 1.0f;
+ }
+
+ if(cheat)
+ fCheat = 1.2f;
+ else
+ fCheat = 1.0f;
+ float targetVelocity = Gears[gear].fMaxVelocity*speedMul*fCheat;
+ float accel = fEngineAcceleration*accelMul * (targetVelocity - fVelocity)/Abs(targetVelocity);
+ if(Abs(fVelocity) < Abs(Gears[gear].fMaxVelocity*fCheat))
+ fAcceleration = gasPedal * accel * CTimer::GetTimeStep();
+ else
+ fAcceleration = 0.0f;
+ }
+ return fAcceleration;
+}
+
+STARTPATCHES
+ InjectHook(0x550A00, &cTransmission::CalculateGearForSimpleCar, PATCH_JUMP);
+ InjectHook(0x5506B0, &cTransmission::CalculateDriveAcceleration, PATCH_JUMP);
+ENDPATCHES