summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control/CarCtrl.cpp8
-rw-r--r--src/control/CarCtrl.h1
-rw-r--r--src/control/Replay.cpp2
-rw-r--r--src/core/Pad.h3
-rw-r--r--src/core/Streaming.cpp2
-rw-r--r--src/modelinfo/ModelIndices.h5
-rw-r--r--src/render/Rubbish.cpp1
-rw-r--r--src/render/Rubbish.h3
-rw-r--r--src/vehicles/Automobile.cpp472
-rw-r--r--src/vehicles/Automobile.h37
-rw-r--r--src/vehicles/DamageManager.h2
-rw-r--r--src/vehicles/HandlingMgr.cpp2
-rw-r--r--src/vehicles/HandlingMgr.h4
-rw-r--r--src/vehicles/Transmission.cpp93
-rw-r--r--src/vehicles/Transmission.h1
-rw-r--r--src/vehicles/Vehicle.cpp4
-rw-r--r--src/vehicles/Vehicle.h2
17 files changed, 605 insertions, 37 deletions
diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp
index 7acfa64a..edf4d1ae 100644
--- a/src/control/CarCtrl.cpp
+++ b/src/control/CarCtrl.cpp
@@ -16,3 +16,11 @@ WRAPPER bool CCarCtrl::JoinCarWithRoadSystemGotoCoors(CVehicle*, CVector, bool)
WRAPPER void CCarCtrl::JoinCarWithRoadSystem(CVehicle*) { EAXJMP(0x41F820); }
WRAPPER void CCarCtrl::SteerAICarWithPhysics(CVehicle*) { EAXJMP(0x41DA60); }
WRAPPER void CCarCtrl::UpdateCarOnRails(CVehicle*) { EAXJMP(0x418880); }
+
+bool
+CCarCtrl::MapCouldMoveInThisArea(float x, float y)
+{
+ // bridge moves up and down
+ return x > -342.0f && x < -219.0f &&
+ y > -677.0f && y < -580.0f;
+}
diff --git a/src/control/CarCtrl.h b/src/control/CarCtrl.h
index a15279d3..7e3f70a9 100644
--- a/src/control/CarCtrl.h
+++ b/src/control/CarCtrl.h
@@ -13,6 +13,7 @@ public:
static void JoinCarWithRoadSystem(CVehicle*);
static void SteerAICarWithPhysics(CVehicle*);
static void UpdateCarOnRails(CVehicle*);
+ static bool MapCouldMoveInThisArea(float x, float y);
static int32 &NumLawEnforcerCars;
static int32 &NumAmbulancesOnDuty;
diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp
index 3ce9085f..29bdacd7 100644
--- a/src/control/Replay.cpp
+++ b/src/control/Replay.cpp
@@ -718,7 +718,7 @@ void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressI
}
vehicle->bEngineOn = true;
if (vehicle->IsCar())
- ((CAutomobile*)vehicle)->m_nWheelsOnGround = 4;
+ ((CAutomobile*)vehicle)->m_nDriveWheelsOnGround = 4;
CWorld::Remove(vehicle);
CWorld::Add(vehicle);
if (vehicle->IsBoat())
diff --git a/src/core/Pad.h b/src/core/Pad.h
index f853a8cd..f84ca742 100644
--- a/src/core/Pad.h
+++ b/src/core/Pad.h
@@ -197,7 +197,7 @@ public:
int16 Mode;
int16 ShakeDur;
uint8 ShakeFreq;
- int8 bHornHistory[5];
+ bool bHornHistory[5];
uint8 iCurrHornHistory;
uint8 DisablePlayerControls;
int8 bApplyBrakes;
@@ -377,6 +377,7 @@ public:
bool ArePlayerControlsDisabled(void) { return DisablePlayerControls != PLAYERCONTROL_ENABLED; }
};
VALIDATE_SIZE(CPad, 0xFC);
+extern CPad *Pads; //[2]
#define IsButtonJustDown(pad, btn) \
(!(pad)->OldState.btn && (pad)->NewState.btn)
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp
index a23e35be..9d9241e4 100644
--- a/src/core/Streaming.cpp
+++ b/src/core/Streaming.cpp
@@ -1048,8 +1048,6 @@ CStreaming::RemoveReferencedTxds(int32 mem)
return false;
}
-// TODO: RemoveCurrentZonesModels
-
void
CStreaming::RemoveUnusedModelsInLoadedList(void)
{
diff --git a/src/modelinfo/ModelIndices.h b/src/modelinfo/ModelIndices.h
index 135f3424..a0d3f70c 100644
--- a/src/modelinfo/ModelIndices.h
+++ b/src/modelinfo/ModelIndices.h
@@ -315,6 +315,11 @@ enum
MI_TOYZ,
MI_GHOST,
+ // leftovers on PC
+ MI_MIAMI_RCBARON = 154,
+ MI_MIAMI_RCRAIDER = 155,
+ MI_MIAMI_SPARROW = 159,
+
MI_GRENADE = 170,
MI_AK47,
MI_BASEBALL_BAT,
diff --git a/src/render/Rubbish.cpp b/src/render/Rubbish.cpp
index 975f2554..c925df1c 100644
--- a/src/render/Rubbish.cpp
+++ b/src/render/Rubbish.cpp
@@ -3,3 +3,4 @@
#include "Rubbish.h"
WRAPPER void CRubbish::Render(void) { EAXJMP(0x512190); }
+WRAPPER void CRubbish::StirUp(CVehicle *veh) { EAXJMP(0x512690); }
diff --git a/src/render/Rubbish.h b/src/render/Rubbish.h
index f4f976e9..9f946dc2 100644
--- a/src/render/Rubbish.h
+++ b/src/render/Rubbish.h
@@ -1,7 +1,10 @@
#pragma once
+class CVehicle;
+
class CRubbish
{
public:
static void Render(void);
+ static void StirUp(CVehicle *veh); // CAutomobile on PS2
};
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index 0cfe31cc..5580ee6d 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -7,6 +7,7 @@
#include "DMAudio.h"
#include "Camera.h"
#include "Darkel.h"
+#include "Rubbish.h"
#include "Fire.h"
#include "Explosion.h"
#include "World.h"
@@ -24,6 +25,8 @@
#include "Object.h"
#include "Automobile.h"
+bool bAllCarCheat; // unused
+
RwObject *GetCurrentAtomicObjectCB(RwObject *object, void *data);
bool &CAutomobile::m_sAllTaxiLights = *(bool*)0x95CD21;
@@ -102,7 +105,7 @@ CAutomobile::ProcessControl(void)
// Process driver
if(pDriver){
- if(!bHadDriver && m_bombType == 5){
+ if(!bHadDriver && m_bombType == CARBOMB_ONIGNITIONACTIVE){
// If someone enters the car and there is a bomb, detonate
m_nBombTimer = 1000;
m_pBlowUpEntity = field_4DC;
@@ -131,7 +134,7 @@ CAutomobile::ProcessControl(void)
pPassengers[i]->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this);
}
- // CRubbish::StirUp
+ CRubbish::StirUp(this);
// blend in clump
int clumpAlpha = CVisibilityPlugins::GetClumpAlpha((RpClump*)m_rwObject);
@@ -200,9 +203,9 @@ CAutomobile::ProcessControl(void)
CPhysical::ProcessControl();
CCarCtrl::UpdateCarOnRails(this);
- m_nWheelsOnGround_2 = 4;
- m_nWheelsOnGroundPrev = m_nWheelsOnGround;
m_nWheelsOnGround = 4;
+ m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround;
+ m_nDriveWheelsOnGround = 4;
pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear);
@@ -252,13 +255,55 @@ CAutomobile::ProcessControl(void)
break;
}
- if(GetPosition().z < -0.6f){
- assert(0);
- }
+ // what's going on here?
+ if(GetPosition().z < -0.6f &&
+ Abs(m_vecMoveSpeed.x) < 0.05f &&
+ Abs(m_vecMoveSpeed.y) < 0.05f)
+ m_vecTurnSpeed *= Pow(0.95f, CTimer::GetTimeStep());
+ // Skip physics if object is found to have been static recently
bool skipPhysics = false;
- if(!bIsStuck){
- assert(0);
+ if(!bIsStuck && (m_status == STATUS_ABANDONED || m_status == STATUS_WRECKED)){
+ bool makeStatic = false;
+ float moveSpeedLimit, turnSpeedLimit, distanceLimit;
+
+ if(!bVehicleColProcessed &&
+ m_vecMoveSpeed.IsZero() &&
+ // BUG? m_aSuspensionSpringRatioPrev[3] is checked twice in the game. also, why 3?
+ m_aSuspensionSpringRatioPrev[3] != 1.0f)
+ makeStatic = true;
+
+ if(m_status == STATUS_WRECKED){
+ moveSpeedLimit = 0.006f;
+ turnSpeedLimit = 0.0015f;
+ distanceLimit = 0.015f;
+ }else{
+ moveSpeedLimit = 0.003f;
+ turnSpeedLimit = 0.0009f;
+ distanceLimit = 0.005f;
+ }
+
+ m_vecMoveSpeedAvg = (m_vecMoveSpeedAvg + m_vecMoveSpeed)/2.0f;
+ m_vecTurnSpeedAvg = (m_vecTurnSpeedAvg + m_vecTurnSpeed)/2.0f;
+
+ if(m_vecMoveSpeedAvg.MagnitudeSqr() <= sq(moveSpeedLimit*CTimer::GetTimeStep()) &&
+ m_vecTurnSpeedAvg.MagnitudeSqr() <= sq(turnSpeedLimit*CTimer::GetTimeStep()) &&
+ m_fDistanceTravelled < distanceLimit ||
+ makeStatic){
+ m_nStaticFrames++;
+
+ if(m_nStaticFrames > 10 || makeStatic)
+ if(!CCarCtrl::MapCouldMoveInThisArea(GetPosition().x, GetPosition().y)){
+ if(!makeStatic || m_nStaticFrames > 10)
+ m_nStaticFrames = 10;
+
+ skipPhysics = true;
+
+ m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
+ }
+ }else
+ m_nStaticFrames = 0;
}
// Postpone
@@ -268,15 +313,27 @@ CAutomobile::ProcessControl(void)
return;
}
- // VehicleDamage
+ VehicleDamage(1.0f, 0);
// special control
switch(GetModelIndex()){
case MI_FIRETRUCK:
+ FireTruckControl();
+ break;
case MI_RHINO:
+ TankControl();
+ BlowUpCarsInPath();
+ break;
case MI_YARDIE:
+ // beta also had esperanto here it seems
+ HydraulicControl();
+ break;
default:
- assert(0);
+ if(CVehicle::bCheat3){
+ // strong grip cheat
+ // TODO: make cars jump when horn key is pressed
+ }
+ break;
}
if(skipPhysics){
@@ -402,7 +459,369 @@ CAutomobile::ProcessControl(void)
}
}
- assert(0);
+
+ bool gripCheat = true;
+ fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
+ if(!strongGrip1 && !CVehicle::bCheat3)
+ gripCheat = false;
+ float acceleration = pHandling->Transmission.CalculateDriveAcceleration(m_fGasPedal, m_nCurrentGear, m_fChangeGearTime, fwdSpeed, gripCheat);
+ acceleration /= fForceMultiplier;
+
+ // unused
+ if(GetModelIndex() == MI_MIAMI_RCBARON ||
+ GetModelIndex() == MI_MIAMI_RCRAIDER ||
+ GetModelIndex() == MI_MIAMI_SPARROW)
+ acceleration = 0.0f;
+
+ float brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep();
+ bool neutralHandling = !!(pHandling->Flags & HANDLING_NEUTRALHANDLING);
+ float brakeBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias;
+ float brakeBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fBrakeBias);
+ float tractionBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias;
+ float tractionBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fTractionBias);
+
+ // Count how many wheels are touching the ground
+
+ m_nWheelsOnGround = 0;
+ m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround;
+ m_nDriveWheelsOnGround = 0;
+
+ for(i = 0; i < 4; i++){
+ if(m_aSuspensionSpringRatio[i] < 1.0f)
+ m_aWheelTimer[i] = 4.0f;
+ else
+ m_aWheelTimer[i] = max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f);
+
+ if(m_aWheelTimer[i] > 0.0f){
+ m_nWheelsOnGround++;
+ switch(pHandling->Transmission.nDriveType){
+ case '4':
+ m_nDriveWheelsOnGround++;
+ break;
+ case 'F':
+ if(i == CARWHEEL_FRONT_LEFT || i == CARWHEEL_FRONT_RIGHT)
+ m_nDriveWheelsOnGround++;
+ break;
+ case 'R':
+ if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT)
+ m_nDriveWheelsOnGround++;
+ break;
+ }
+ }
+ }
+
+ float traction;
+ if(m_status == STATUS_PHYSICS)
+ traction = 0.004f * m_fTraction;
+ else
+ traction = 0.004f;
+ traction *= pHandling->fTractionMultiplier / 4.0f;
+ traction /= fForceMultiplier;
+ if(CVehicle::bCheat3)
+ traction *= 4.0f;
+
+ if(FindPlayerVehicle() && FindPlayerVehicle() == this){
+ if(CPad::GetPad(0)->WeaponJustDown()){
+ if(m_bombType == CARBOMB_TIMED){
+ m_bombType = CARBOMB_TIMEDACTIVE;
+ m_nBombTimer = 7000;
+ m_pBlowUpEntity = FindPlayerPed();
+ CGarages::TriggerMessage("GA_12", -1, 3000, -1);
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TIMED_ACTIVATED, 1.0f);
+ }else{
+ m_bombType = CARBOMB_ONIGNITIONACTIVE;
+ CGarages::TriggerMessage("GA_12", -1, 3000, -1);
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_ONIGNITION_ACTIVATED, 1.0f);
+ }
+ }
+ }else if(strongGrip1 || CVehicle::bCheat3){
+ traction *= 1.2f;
+ acceleration *= 1.4f;
+ if(strongGrip2 || CVehicle::bCheat3){
+ traction *= 1.3f;
+ acceleration *= 1.4f;
+ }
+ }
+
+ static float fThrust;
+ static tWheelState WheelState[4];
+
+ // Process front wheels on ground
+
+ if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){
+ float s = Sin(m_fSteerAngle);
+ float c = Cos(m_fSteerAngle);
+ CVector wheelFwd = Multiply3x3(GetMatrix(), CVector(-s, c, 0.0f));
+ CVector wheelRight = Multiply3x3(GetMatrix(), CVector(c, s, 0.0f));
+
+ if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f){
+ if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier))
+ fThrust = 0.0f;
+ else
+ fThrust = acceleration;
+
+ m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceA = SURFACE_RUBBER29;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_LEFT])*traction;
+ if(m_status == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB);
+ WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT];
+
+ if(Damage.GetWheelStatus(VEHWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect,
+ CARWHEEL_FRONT_LEFT,
+ &m_aWheelSpeed[CARWHEEL_FRONT_LEFT],
+ &WheelState[CARWHEEL_FRONT_LEFT],
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront,
+ CARWHEEL_FRONT_LEFT,
+ &m_aWheelSpeed[CARWHEEL_FRONT_LEFT],
+ &WheelState[CARWHEEL_FRONT_LEFT],
+ WHEEL_STATUS_OK);
+ }
+
+ if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f){
+ if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier))
+ fThrust = 0.0f;
+ else
+ fThrust = acceleration;
+
+ m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceA = SURFACE_RUBBER29;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT])*traction;
+ if(m_status == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB);
+ WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT];
+
+ if(Damage.GetWheelStatus(VEHWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront*Damage.m_fWheelDamageEffect,
+ CARWHEEL_FRONT_RIGHT,
+ &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT],
+ &WheelState[CARWHEEL_FRONT_RIGHT],
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront,
+ CARWHEEL_FRONT_RIGHT,
+ &m_aWheelSpeed[CARWHEEL_FRONT_RIGHT],
+ &WheelState[CARWHEEL_FRONT_RIGHT],
+ WHEEL_STATUS_OK);
+ }
+ }
+
+ // Process front wheels off ground
+
+ if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] <= 0.0f){
+ if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_LEFT] *= 0.95f;
+ else{
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] < 2.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_LEFT] -= 0.2f;
+ }else{
+ if(m_aWheelSpeed[CARWHEEL_FRONT_LEFT] > -2.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_LEFT] += 0.1f;
+ }
+ }
+ m_aWheelRotation[CARWHEEL_FRONT_LEFT] += m_aWheelSpeed[CARWHEEL_FRONT_LEFT];
+ }
+ if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] <= 0.0f){
+ if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] *= 0.95f;
+ else{
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] < 2.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] -= 0.2f;
+ }else{
+ if(m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] > -2.0f)
+ m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] += 0.1f;
+ }
+ }
+ m_aWheelRotation[CARWHEEL_FRONT_RIGHT] += m_aWheelSpeed[CARWHEEL_FRONT_RIGHT];
+ }
+
+ // Process rear wheels
+
+ if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){
+ CVector wheelFwd = GetForward();
+ CVector wheelRight = GetRight();
+
+ if(bIsHandbrakeOn)
+ brake = 20000.0f;
+
+ if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f){
+ if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier))
+ fThrust = 0.0f;
+ else
+ fThrust = acceleration;
+
+ m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceA = SURFACE_RUBBER29;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_LEFT])*traction;
+ if(m_status == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB);
+ WheelState[CARWHEEL_REAR_LEFT] = m_aWheelState[CARWHEEL_REAR_LEFT];
+
+ if(Damage.GetWheelStatus(VEHWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasRear,
+ adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect,
+ CARWHEEL_REAR_LEFT,
+ &m_aWheelSpeed[CARWHEEL_REAR_LEFT],
+ &WheelState[CARWHEEL_REAR_LEFT],
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasRear,
+ adhesion*tractionBiasRear,
+ CARWHEEL_REAR_LEFT,
+ &m_aWheelSpeed[CARWHEEL_REAR_LEFT],
+ &WheelState[CARWHEEL_REAR_LEFT],
+ WHEEL_STATUS_OK);
+ }
+
+ if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){
+ if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier))
+ fThrust = 0.0f;
+ else
+ fThrust = acceleration;
+
+ m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceA = SURFACE_RUBBER29;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_RIGHT])*traction;
+ if(m_status == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB);
+ WheelState[CARWHEEL_REAR_RIGHT] = m_aWheelState[CARWHEEL_REAR_RIGHT];
+
+ if(Damage.GetWheelStatus(VEHWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasRear,
+ adhesion*tractionBiasRear*Damage.m_fWheelDamageEffect,
+ CARWHEEL_REAR_RIGHT,
+ &m_aWheelSpeed[CARWHEEL_REAR_RIGHT],
+ &WheelState[CARWHEEL_REAR_RIGHT],
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBiasRear,
+ adhesion*tractionBiasRear,
+ CARWHEEL_REAR_RIGHT,
+ &m_aWheelSpeed[CARWHEEL_REAR_RIGHT],
+ &WheelState[CARWHEEL_REAR_RIGHT],
+ WHEEL_STATUS_OK);
+ }
+ }
+
+ // Process rear wheels off ground
+
+ if(m_aWheelTimer[CARWHEEL_REAR_LEFT] <= 0.0f){
+ if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_LEFT] *= 0.95f;
+ else{
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] < 2.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_LEFT] -= 0.2f;
+ }else{
+ if(m_aWheelSpeed[CARWHEEL_REAR_LEFT] > -2.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_LEFT] += 0.1f;
+ }
+ }
+ m_aWheelRotation[CARWHEEL_REAR_LEFT] += m_aWheelSpeed[CARWHEEL_REAR_LEFT];
+ }
+ if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] <= 0.0f){
+ if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_RIGHT] *= 0.95f;
+ else{
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] < 2.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_RIGHT] -= 0.2f;
+ }else{
+ if(m_aWheelSpeed[CARWHEEL_REAR_RIGHT] > -2.0f)
+ m_aWheelSpeed[CARWHEEL_REAR_RIGHT] += 0.1f;
+ }
+ }
+ m_aWheelRotation[CARWHEEL_REAR_RIGHT] += m_aWheelSpeed[CARWHEEL_REAR_RIGHT];
+ }
+
+ for(i = 0; i < 4; i++){
+ float wheelPos = colModel->lines[i].p0.z;
+ if(m_aSuspensionSpringRatio[i] > 0.0f)
+ wheelPos -= m_aSuspensionSpringRatio[i]*m_aSuspensionLineLength[i];
+ m_aWheelPosition[i] += (wheelPos - m_aWheelPosition[i])*0.75f;
+ }
+ for(i = 0; i < 4; i++)
+ m_aWheelState[i] = WheelState[i];
+
+ // Process horn
+
+ if(m_status != STATUS_PLAYER){
+ ReduceHornCounter();
+ }else{
+ if(GetModelIndex() == MI_MRWHOOP){
+ if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory] &&
+ !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5]){
+ m_bSirenOrAlarm = !m_bSirenOrAlarm;
+ printf("m_bSirenOrAlarm toggled to %d\n", m_bSirenOrAlarm);
+ }
+ }else if(UsesSiren(GetModelIndex())){
+ if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory]){
+ if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] &&
+ Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+3) % 5])
+ m_nCarHornTimer = 1;
+ else
+ m_nCarHornTimer = 0;
+ }else if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] &&
+ !Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+1) % 5]){
+ m_nCarHornTimer = 0;
+ m_bSirenOrAlarm = !m_bSirenOrAlarm;
+ }else
+ m_nCarHornTimer = 0;
+ }else if(GetModelIndex() != MI_YARDIE && !CVehicle::bCheat3){
+ if(Pads[0].GetHorn())
+ m_nCarHornTimer = 1;
+ else
+ m_nCarHornTimer = 0;
+ }
+ }
+
+ // Flying
+
+ if(m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE && m_status != STATUS_PHYSICS){
+ if(GetModelIndex() == MI_MIAMI_RCRAIDER || GetModelIndex() == MI_MIAMI_SPARROW)
+ 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);
+ }else if(GetModelIndex() == MI_MIAMI_RCBARON){
+ FlyingControl(FLIGHT_MODEL_HELI);
+ }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)
+ FlyingControl(FLIGHT_MODEL_HELI);
+ }
}
assert(0 && "misc stuff");
@@ -640,6 +1059,27 @@ CAutomobile::ProcessControlInputs(uint8 pad)
}
WRAPPER void
+CAutomobile::FireTruckControl(void)
+{ EAXJMP(0x522590);
+}
+
+WRAPPER void
+CAutomobile::TankControl(void)
+{ EAXJMP(0x53D530);
+}
+
+WRAPPER void
+CAutomobile::HydraulicControl(void)
+{ EAXJMP(0x52D4E0);
+}
+
+WRAPPER void
+CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece)
+{ EAXJMP(0x52F390);
+}
+
+
+WRAPPER void
CAutomobile::ProcessBuoyancy(void)
{ EAXJMP(0x5308D0);
}
@@ -908,7 +1348,7 @@ CAutomobile::BlowUpCar(CEntity *culprit)
m_fHealth = 0.0f;
m_nBombTimer = 0;
- m_bombType = 0;
+ m_bombType = CARBOMB_NONE;
TheCamera.CamShake(0.7f, GetPosition().x, GetPosition().y, GetPosition().z);
@@ -1057,9 +1497,9 @@ CAutomobile::ResetSuspension(void)
int i;
for(i = 0; i < 4; i++){
m_aSuspensionSpringRatio[i] = 1.0f;
- m_aWheelSkidThing[i] = 0.0f;
+ m_aWheelTimer[i] = 0.0f;
m_aWheelRotation[i] = 0.0f;
- m_aWheelState[i] = 0; // TODO: enum?
+ m_aWheelState[i] = WHEEL_STATE_0;
}
}
@@ -1562,7 +2002,7 @@ CAutomobile::SetTaxiLight(bool light)
bool
CAutomobile::GetAllWheelsOffGround(void)
{
- return m_nWheelsOnGround == 0;
+ return m_nDriveWheelsOnGround == 0;
}
void
diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h
index 6ed5e154..69df9bb3 100644
--- a/src/vehicles/Automobile.h
+++ b/src/vehicles/Automobile.h
@@ -6,11 +6,24 @@
class CObject;
-// Wheels are in order:
-// FRONT LEFT
-// REAR LEFT
-// FRONT RIGHT
-// REAR RIGHT
+// These are used for all the wheel arrays
+// DON'T confuse with VEHWHEEL, which are vehicle components
+enum {
+ CARWHEEL_FRONT_LEFT,
+ CARWHEEL_REAR_LEFT,
+ CARWHEEL_FRONT_RIGHT,
+ CARWHEEL_REAR_RIGHT
+};
+
+enum eBombType
+{
+ CARBOMB_NONE,
+ CARBOMB_TIMED,
+ CARBOMB_ONIGNITION,
+ CARBOMB_REMOTE,
+ CARBOMB_TIMEDACTIVE,
+ CARBOMB_ONIGNITIONACTIVE,
+};
class CAutomobile : public CVehicle
{
@@ -22,7 +35,7 @@ public:
CColPoint m_aWheelColPoints[4];
float m_aSuspensionSpringRatio[4];
float m_aSuspensionSpringRatioPrev[4];
- float m_aWheelSkidThing[4];
+ float m_aWheelTimer[4]; // set to 4.0 when wheel is touching ground, then decremented
float field_49C;
bool m_aWheelSkidmarkMuddy[4];
bool m_aWheelSkidmarkBloody[4];
@@ -44,7 +57,7 @@ public:
float m_aSuspensionSpringLength[4];
float m_aSuspensionLineLength[4];
float m_fHeightAboveRoad;
- float m_fImprovedHandling;
+ float m_fTraction;
uint8 stuff6[28];
float field_530;
CPhysical *m_aGroundPhysical[4]; // physicals touching wheels
@@ -56,11 +69,11 @@ public:
float m_fCarGunUD;
float m_fWindScreenRotation;
uint8 stuff4[4];
- uint8 m_nWheelsOnGround_2;
uint8 m_nWheelsOnGround;
- uint8 m_nWheelsOnGroundPrev;
+ uint8 m_nDriveWheelsOnGround;
+ uint8 m_nDriveWheelsOnGroundPrev;
uint8 stuff5[5];
- int32 m_aWheelState[4];
+ tWheelState m_aWheelState[4];
static bool &m_sAllTaxiLights;
@@ -95,6 +108,10 @@ public:
float GetHeightAboveRoad(void);
void PlayCarHorn(void);
+ void FireTruckControl(void);
+ void TankControl(void);
+ void HydraulicControl(void);
+ void VehicleDamage(float impulse, uint16 damagedPiece);
void ProcessBuoyancy(void);
void DoDriveByShootings(void);
int32 RcbanditCheckHitWheels(void);
diff --git a/src/vehicles/DamageManager.h b/src/vehicles/DamageManager.h
index f2044ec2..ee1297d9 100644
--- a/src/vehicles/DamageManager.h
+++ b/src/vehicles/DamageManager.h
@@ -66,7 +66,7 @@ class CDamageManager
{
public:
- float field_0;
+ float m_fWheelDamageEffect;
uint8 m_engineStatus;
uint8 m_wheelStatus[4];
uint8 m_doorStatus[6];
diff --git a/src/vehicles/HandlingMgr.cpp b/src/vehicles/HandlingMgr.cpp
index 9bcaaf81..4d3a94a8 100644
--- a/src/vehicles/HandlingMgr.cpp
+++ b/src/vehicles/HandlingMgr.cpp
@@ -127,7 +127,7 @@ cHandlingDataMgr::LoadHandlingData(void)
handlingId = FindExactWord(word, (const char*)VehicleNames, 14, NUMHANDLINGS);
assert(handlingId >= 0 && handlingId < NUMHANDLINGS);
handling = &HandlingData[handlingId];
- handling->nIdentifier = handlingId;
+ handling->nIdentifier = (eHandlingId)handlingId;
break;
case 1: handling->fMass = strtod(word, nil); break;
case 2: handling->Dimension.x = strtod(word, nil); break;
diff --git a/src/vehicles/HandlingMgr.h b/src/vehicles/HandlingMgr.h
index 7d8613da..70f1c005 100644
--- a/src/vehicles/HandlingMgr.h
+++ b/src/vehicles/HandlingMgr.h
@@ -85,7 +85,7 @@ enum
struct tHandlingData
{
- int32 nIdentifier;
+ eHandlingId nIdentifier;
float fMass;
float fInvMass;
float fTurnMass;
@@ -136,6 +136,8 @@ public:
void ConvertDataToGameUnits(tHandlingData *handling);
int32 GetHandlingId(const char *name);
tHandlingData *GetHandlingData(eHandlingId id) { return &HandlingData[id]; }
+ bool HasRearWheelDrive(eHandlingId id) { return HandlingData[id].Transmission.nDriveType == 'R'; }
+ bool HasFrontWheelDrive(eHandlingId id) { return HandlingData[id].Transmission.nDriveType == 'F'; }
};
VALIDATE_SIZE(cHandlingDataMgr, 0x3030);
extern cHandlingDataMgr &mod_HandlingManager;
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
diff --git a/src/vehicles/Transmission.h b/src/vehicles/Transmission.h
index ea67b62c..8eeef1e8 100644
--- a/src/vehicles/Transmission.h
+++ b/src/vehicles/Transmission.h
@@ -24,4 +24,5 @@ public:
void InitGearRatios(void);
void CalculateGearForSimpleCar(float speed, uint8 &gear);
+ float CalculateDriveAcceleration(const float &gasPedal, uint8 &gear, float &time, const float &velocity, bool cheat);
};
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index f3a8f785..316de7ac 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -35,7 +35,7 @@ CVehicle::CVehicle(uint8 CreatedBy)
int i;
m_nCurrentGear = 0;
- field_208 = 0;
+ m_fChangeGearTime = 0;
m_fSteerRatio = 0.0f;
m_type = ENTITY_TYPE_VEHICLE;
VehicleCreatedBy = CreatedBy;
@@ -380,7 +380,7 @@ CVehicle::ProcessDelayedExplosion(void)
else
m_nBombTimer -= tick;
- if(IsCar() && ((CAutomobile*)this)->m_bombType == 4 && (m_nBombTimer & 0xFE00) != 0xFE00)
+ if(IsCar() && ((CAutomobile*)this)->m_bombType == CARBOMB_TIMEDACTIVE && (m_nBombTimer & 0xFE00) != 0xFE00)
DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_BOMB_TICK, 0.0f);
if (m_nBombTimer != 0)
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index b37ea84d..de74264b 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -191,7 +191,7 @@ public:
float m_fHealth; // 1000.0f = full health. 0 -> explode
uint8 m_nCurrentGear;
int8 field_205[3];
- int field_208;
+ float m_fChangeGearTime;
uint32 m_nGunFiringTime; // last time when gun on vehicle was fired (used on boats)
uint32 m_nTimeOfDeath;
int16 field_214;