summaryrefslogtreecommitdiffstats
path: root/src/vehicles
diff options
context:
space:
mode:
Diffstat (limited to 'src/vehicles')
-rw-r--r--src/vehicles/Automobile.cpp856
-rw-r--r--src/vehicles/Automobile.h3
-rw-r--r--src/vehicles/Bike.cpp9
-rw-r--r--src/vehicles/Bike.h1
-rw-r--r--src/vehicles/Boat.cpp5
-rw-r--r--src/vehicles/Cranes.cpp10
-rw-r--r--src/vehicles/DamageManager.cpp5
-rw-r--r--src/vehicles/DamageManager.h1
-rw-r--r--src/vehicles/Door.cpp55
-rw-r--r--src/vehicles/Door.h19
-rw-r--r--src/vehicles/Ferry.cpp832
-rw-r--r--src/vehicles/Ferry.h143
-rw-r--r--src/vehicles/HandlingMgr.cpp160
-rw-r--r--src/vehicles/HandlingMgr.h93
-rw-r--r--src/vehicles/Heli.cpp2
-rw-r--r--src/vehicles/Plane.cpp6
-rw-r--r--src/vehicles/Plane.h1
-rw-r--r--src/vehicles/Train.cpp88
-rw-r--r--src/vehicles/Transmission.cpp119
-rw-r--r--src/vehicles/Transmission.h2
-rw-r--r--src/vehicles/Vehicle.cpp44
-rw-r--r--src/vehicles/Vehicle.h10
22 files changed, 1715 insertions, 749 deletions
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index 5e2b0c10..2c199030 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -103,6 +103,8 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId);
pFlyingHandling = mod_HandlingManager.GetFlyingPointer((tVehicleType)mi->m_handlingId);
+ m_fEngineInertiaVar1 = 0.0f;
+ m_fEngineInertiaVar2 = 0.0f;
m_auto_unused1 = 20.0f;
m_auto_unused2 = 0;
@@ -151,7 +153,7 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
m_fMass = pHandling->fMass;
m_fTurnMass = pHandling->fTurnMass;
m_vecCentreOfMass = pHandling->CentreOfMass;
- m_fAirResistance = pHandling->Dimension.x*pHandling->Dimension.z/m_fMass;
+ m_fAirResistance = pHandling->fDragMult > 0.01f ? pHandling->fDragMult*0.0005f : pHandling->fDragMult;
m_fElasticity = 0.05f;
m_fBuoyancy = pHandling->fBuoyancy;
@@ -192,12 +194,6 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
m_fTraction = 1.0f;
m_fTireTemperature = 1.0f;
- CColModel *colModel = mi->GetColModel();
- if(colModel->lines == nil){
- colModel->lines = (CColLine*)RwMalloc(4*sizeof(CColLine));
- colModel->numLines = 4;
- }
-
SetupSuspensionLines();
SetStatus(STATUS_SIMPLE);
@@ -257,6 +253,10 @@ CVector vecDAMAGE_ENGINE_POS_BIG(-0.5f, -0.3f, 0.0f);
void
CAutomobile::ProcessControl(void)
{
+ // TODO(LCS):
+ // TheCamera can remove service vehicles
+ // some audio (?) stuff
+
int i;
float wheelRot;
CColModel *colModel;
@@ -311,7 +311,7 @@ CAutomobile::ProcessControl(void)
if(GetStatus() != STATUS_ABANDONED && GetStatus() != STATUS_WRECKED &&
GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE && GetStatus() != STATUS_PLAYER_DISABLED){
switch(GetModelIndex())
- case MI_FBIRANCH:
+ case MI_FBICAR:
case MI_POLICE:
case MI_ENFORCER:
case MI_SECURICA:
@@ -320,16 +320,18 @@ CAutomobile::ProcessControl(void)
ScanForCrimes();
}
+ // TODO(LCS): the fields used by this function are weird
+ ActivateBombWhenEntered();
+
// Process driver
- if(pDriver)
+ if(pDriver){
if(IsUpsideDown() && CanPedEnterCar()){
if(!pDriver->IsPlayer() &&
!(pDriver->m_leader && pDriver->m_leader->bInVehicle) &&
pDriver->CharCreatedBy != MISSION_CHAR)
pDriver->SetObjective(OBJECTIVE_LEAVE_CAR, this);
}
-
- ActivateBombWhenEntered();
+ }
// Process passengers
if(m_nNumPassengers != 0 && IsUpsideDown() && CanPedEnterCar()){
@@ -352,7 +354,7 @@ CAutomobile::ProcessControl(void)
if(strongGrip1 || bCheat3)
m_vecCentreOfMass.z = 0.3f*m_aSuspensionSpringLength[0] + -1.0f*m_fHeightAboveRoad;
else if(pHandling->Flags & HANDLING_NONPLAYER_STABILISER && GetStatus() == STATUS_PHYSICS)
- m_vecCentreOfMass.z = pHandling->CentreOfMass.z - 0.2f*pHandling->Dimension.z;
+ m_vecCentreOfMass.z = pHandling->CentreOfMass.z + (colModel->boundingBox.min.z - pHandling->CentreOfMass.z)*0.4f;
else
m_vecCentreOfMass = pHandling->CentreOfMass;
@@ -372,11 +374,7 @@ CAutomobile::ProcessControl(void)
bool playerRemote = false;
switch(GetStatus()){
case STATUS_PLAYER_REMOTE:
-#ifdef FIX_BUGS
if(CPad::GetPad(0)->CarGunJustDown() && !bDisableRemoteDetonation){
-#else
- if(CPad::GetPad(0)->WeaponJustDown() && !bDisableRemoteDetonation){
-#endif
BlowUpCar(FindPlayerPed());
CRemote::TakeRemoteControlledCarFromPlayer();
}
@@ -395,6 +393,7 @@ CAutomobile::ProcessControl(void)
// fall through
case STATUS_PLAYER:
if(playerRemote ||
+ // TODO(LCS): ped state 64
pDriver && pDriver->GetPedState() != PED_EXIT_CAR && pDriver->GetPedState() != PED_DRAG_FROM_CAR && pDriver->GetPedState() != PED_ARRESTED){
// process control input if controlled by player
if(playerRemote || pDriver->m_nPedType == PEDTYPE_PLAYER1)
@@ -420,6 +419,8 @@ CAutomobile::ProcessControl(void)
}else
m_vecCentreOfMass.z = pHandling->CentreOfMass.z;
+ // TODO(LCS): some in air handling?
+
if(bHoverCheat)
DoHoverSuspensionRatios();
@@ -455,8 +456,6 @@ CAutomobile::ProcessControl(void)
m_fBrakePedal = 1.0f;
m_fGasPedal = 0.0f;
}
- if(CPad::GetPad(0)->CarGunJustDown())
- ActivateBomb();
break;
case STATUS_SIMPLE:
@@ -496,7 +495,7 @@ CAutomobile::ProcessControl(void)
m_aSuspensionSpringRatio[1] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[1].surfaceB) == ADHESIVE_SAND ||
m_aSuspensionSpringRatio[2] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[2].surfaceB) == ADHESIVE_SAND ||
m_aSuspensionSpringRatio[3] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[3].surfaceB) == ADHESIVE_SAND){
- if(GetModelIndex() != MI_RCBANDIT && GetModelIndex() != MI_SANDKING && GetModelIndex() != MI_BFINJECT){
+ if(GetModelIndex() != MI_RCBANDIT /*&& GetModelIndex() != MI_SANDKING*/ && GetModelIndex() != MI_BFINJECT){
bStuckInSand = true;
if(CWeather::WetRoads > 0.0f)
ApplyMoveForce(m_vecMoveSpeed * -CTimer::GetTimeStep()*SAND_SLOWDOWN*m_fMass * (1.0f-CWeather::WetRoads));
@@ -531,8 +530,10 @@ CAutomobile::ProcessControl(void)
m_fSteerAngle = 0.0f;
m_fGasPedal = 0.0f;
- if(!IsAlarmOn())
- m_nCarHornTimer = 0;
+ m_nCarHornTimer = 0;
+ // TODO(LCS):
+ // CWeapon::::RemovePlayersRemoteDetonatorForThisVehicle
+ m_pBombRigger = nil;
break;
case STATUS_PLAYER_DISABLED:
@@ -626,14 +627,13 @@ CAutomobile::ProcessControl(void)
// special control
switch(GetModelIndex()){
- case MI_FIRETRUCK:
- FireTruckControl();
- break;
+ // FireTruckControl in PreRender now
case MI_RHINO:
TankControl();
BlowUpCarsInPath();
break;
- case MI_VOODOO:
+ // LCS: this is gone but i'm keeping it!
+ case MI_YARDIE:
HydraulicControl();
break;
default:
@@ -723,7 +723,7 @@ CAutomobile::ProcessControl(void)
ApplyTurnSpeed();
}
bIsInSafePosition = true;
- bIsStuck = false;
+ bIsStuck = false;
}
CPhysical::ProcessControl();
@@ -742,6 +742,7 @@ CAutomobile::ProcessControl(void)
CVector contactPoints[4]; // relative to model
CVector contactSpeeds[4]; // speed at contact points
CVector springDirections[4]; // normalized, in world space
+ float springForces[4];
for(i = 0; i < 4; i++){
// Set spring under certain circumstances
@@ -765,10 +766,13 @@ CAutomobile::ProcessControl(void)
}
// get points and directions if spring is compressed
+ springDirections[i] = -GetUp(); // springs are always pointing down anyway
if(m_aSuspensionSpringRatio[i] < 1.0f){
contactPoints[i] = m_aWheelColPoints[i].point - GetPosition();
- springDirections[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1 - colModel->lines[i].p0);
- springDirections[i].Normalise();
+// springDirections[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1 - colModel->lines[i].p0);
+// springDirections[i].Normalise();
+ }else{
+ contactPoints[i] = CVector(0.0f, 0.0f, 0.0f);
}
}
@@ -781,7 +785,7 @@ CAutomobile::ProcessControl(void)
ApplySpringCollisionAlt(pHandling->fSuspensionForceLevel,
springDirections[i], contactPoints[i],
- m_aSuspensionSpringRatio[i], bias, m_aWheelColPoints[i].normal);
+ m_aSuspensionSpringRatio[i], bias, m_aWheelColPoints[i].normal, springForces[i]);
m_aWheelSkidmarkUnk[i] = false;
if(m_aWheelColPoints[i].surfaceB == SURFACE_GRASS ||
@@ -793,8 +797,8 @@ CAutomobile::ProcessControl(void)
m_aWheelSkidmarkUnk[i] = true;
}else
m_aWheelSkidmarkType[i] = SKIDMARK_NORMAL;
- }else{
- contactPoints[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1);
+// }else{
+// contactPoints[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1);
}
}
@@ -816,7 +820,7 @@ CAutomobile::ProcessControl(void)
// dampen springs
for(i = 0; i < 4; i++)
if(m_aSuspensionSpringRatio[i] < 0.99999f)
- ApplySpringDampening(pHandling->fSuspensionDampingLevel,
+ ApplySpringDampening(pHandling->fSuspensionDampingLevel, springForces[i],
springDirections[i], contactPoints[i], contactSpeeds[i]);
// Get speed at contact points again
@@ -829,42 +833,6 @@ CAutomobile::ProcessControl(void)
}
}
- 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 /= m_fForceMultiplier;
-
- if(IsRealHeli() || IsRealPlane())
- acceleration = 0.0f;
-
- if(bAudioChangingGear && m_fGasPedal > 0.4f && m_fBrakePedal < 0.1f && fwdSpeed > 0.15f &&
- this == FindPlayerVehicle() && TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_1STPERSON){
- if(GetStatus() == STATUS_PLAYER && !(pHandling->Flags & HANDLING_IS_BUS)){
- if(m_nBusDoorTimerEnd == 0)
- m_nBusDoorTimerEnd = 1000;
- else {
- uint32 timeStepInMs = CTimer::GetTimeStepInMilliseconds();
- if(m_nBusDoorTimerEnd > timeStepInMs)
- m_nBusDoorTimerEnd -= timeStepInMs;
- else
- m_nBusDoorTimerEnd = 0;
- }
- }
-
- if((m_aSuspensionSpringRatio[0] < 1.0f || m_aSuspensionSpringRatio[2] < 1.0f) &&
- (m_aSuspensionSpringRatio[1] < 1.0f || m_aSuspensionSpringRatio[3] < 1.0f))
- ApplyTurnForce(-GRAVITY*Min(m_fTurnMass, 2500.0f)*GetUp(), -1.0f*GetForward());
- }
-
- brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep();
- bool neutralHandling = GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE && (pHandling->Flags & HANDLING_NEUTRALHANDLING);
- float brakeBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias;
- float brakeBiasRear = neutralHandling ? 1.0f : 2.0f-pHandling->fBrakeBias; // looks like a bug, but it was correct in III...
- float tractionBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias;
- float tractionBiasRear = neutralHandling ? 1.0f : 2.0f-tractionBiasFront;
-
// Count how many wheels are touching the ground
m_nWheelsOnGround = 0;
@@ -895,16 +863,36 @@ CAutomobile::ProcessControl(void)
}
}
+ 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,
+ &m_fEngineInertiaVar1, &m_fEngineInertiaVar2, m_nDriveWheelsOnGround, gripCheat);
+ acceleration /= m_fForceMultiplier;
+
+ if(IsRealHeli() || IsRealPlane())
+ acceleration = 0.0f;
+
+ if(Abs(acceleration) > 0.0f)
+ m_fEngineEnergy += Abs(acceleration);
+ else
+ m_fEngineEnergy = 0.0f;
+
float traction;
if(GetStatus() == STATUS_PHYSICS)
traction = 0.004f * m_fTraction;
else
traction = 0.004f;
- traction *= pHandling->fTractionMultiplier / 4.0f;
+ traction *= pHandling->GetTractionMultiplier() / 4.0f;
traction /= m_fForceMultiplier;
if(CVehicle::bCheat3)
traction *= 4.0f;
+ if(FindPlayerVehicle() && FindPlayerVehicle() == this)
+ if(CPad::GetPad(0)->CarGunJustDown())
+ ActivateBomb();
+
if(FindPlayerVehicle() != this && (strongGrip1 || CVehicle::bCheat3)){
traction *= 1.2f;
acceleration *= 1.4f;
@@ -914,448 +902,73 @@ CAutomobile::ProcessControl(void)
}
}
- static float fThrust;
- static tWheelState WheelState[4];
-
- bool rearWheelsFirst = !!(pHandling->Flags & HANDLING_REARWHEEL_1ST);
-
- // Process front wheels on ground - first try
-
- if(!rearWheelsFirst){
- 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, wheelRight, tmp;
-
- if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd = GetForward();
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal)*m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal);
- wheelRight.Normalise();
- tmp = c*wheelFwd - s*wheelRight;
- wheelRight = s*wheelFwd + c*wheelRight;
- wheelFwd = tmp;
-
- m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_LEFT])*traction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB);
- WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT];
-
- if(Damage.GetWheelStatus(CARWHEEL_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.HasFrontWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd = GetForward();
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal)*m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal);
- wheelRight.Normalise();
- tmp = c*wheelFwd - s*wheelRight;
- wheelRight = s*wheelFwd + c*wheelRight;
- wheelFwd = tmp;
-
- m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT])*traction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB);
- WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT];
-
- if(Damage.GetWheelStatus(CARWHEEL_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(!IsRealHeli()){
- if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] <= 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_FRONT_LEFT] *= 0.95f;
- }
- m_aWheelRotation[CARWHEEL_FRONT_LEFT] += m_aWheelSpeed[CARWHEEL_FRONT_LEFT];
- }
- if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] <= 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] *= 0.95f;
- }
- 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(); // overwritten for resp. wheel
-
- float rearBrake = brake;
- float rearTraction = traction;
- if(bIsHandbrakeOn){
-#ifdef FIX_BUGS
- // Not sure if this is needed, but brake usually has timestep as a factor
- rearBrake = 20000.0f * CTimer::GetTimeStepFix();
-#else
- rearBrake = 20000.0f;
-#endif
- if(fwdSpeed > 0.1f && pHandling->Flags & HANDLING_HANDBRAKE_TYRE){
- m_fTireTemperature += 0.005*CTimer::GetTimeStep();
- if(m_fTireTemperature > 2.0f)
- m_fTireTemperature = 2.0f;
- }
- }else if(m_doingBurnout && mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)){
- rearBrake = 0.0f;
- rearTraction = 0.0f;
- // BUG: missing timestep
- ApplyTurnForce(contactPoints[CARWHEEL_REAR_LEFT], -0.001f*m_fTurnMass*m_fSteerAngle*GetRight());
- }else if(m_fTireTemperature > 1.0f){
- rearTraction *= m_fTireTemperature;
- }
-
- if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f){
- if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_REAR_LEFT].normal)*m_aWheelColPoints[CARWHEEL_REAR_LEFT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_REAR_LEFT].normal);
- wheelRight.Normalise();
-
- m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_LEFT])*rearTraction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB);
- WheelState[CARWHEEL_REAR_LEFT] = m_aWheelState[CARWHEEL_REAR_LEFT];
-
- if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST)
- ProcessWheel(wheelFwd, wheelRight,
- contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT],
- m_nWheelsOnGround, fThrust,
- rearBrake*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,
- rearBrake*brakeBiasRear,
- adhesion*tractionBiasRear,
- CARWHEEL_REAR_LEFT,
- &m_aWheelSpeed[CARWHEEL_REAR_LEFT],
- &WheelState[CARWHEEL_REAR_LEFT],
- WHEEL_STATUS_OK);
- }
-
-#ifdef FIX_BUGS
- // Shouldn't we reset these after the left wheel?
- wheelFwd = GetForward();
- wheelRight = GetRight(); // actually useless
-#endif
-
- if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){
- if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_REAR_RIGHT].normal)*m_aWheelColPoints[CARWHEEL_REAR_RIGHT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_REAR_RIGHT].normal);
- wheelRight.Normalise();
-
- m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_REAR_RIGHT])*rearTraction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB);
- WheelState[CARWHEEL_REAR_RIGHT] = m_aWheelState[CARWHEEL_REAR_RIGHT];
-
- if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST)
- ProcessWheel(wheelFwd, wheelRight,
- contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT],
- m_nWheelsOnGround, fThrust,
- rearBrake*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,
- rearBrake*brakeBiasRear,
- adhesion*tractionBiasRear,
- CARWHEEL_REAR_RIGHT,
- &m_aWheelSpeed[CARWHEEL_REAR_RIGHT],
- &WheelState[CARWHEEL_REAR_RIGHT],
- WHEEL_STATUS_OK);
- }
- }
-
- if(m_doingBurnout && mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) &&
- (m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SPINNING || m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SPINNING)){
- m_fTireTemperature += 0.001f*CTimer::GetTimeStep();
- if(m_fTireTemperature > 3.0f)
- m_fTireTemperature = 3.0f;
- }else if(m_fTireTemperature > 1.0f){
- m_fTireTemperature = (m_fTireTemperature - 1.0f)*Pow(0.995f, CTimer::GetTimeStep()) + 1.0f;
- }
-
- // Process rear wheels off ground
-
- if(!IsRealHeli()){
- if(m_aWheelTimer[CARWHEEL_REAR_LEFT] <= 0.0f){
- if(bIsHandbrakeOn)
- m_aWheelSpeed[CARWHEEL_REAR_LEFT] = 0.0f;
- else if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_REAR_LEFT] *= 0.95f;
- }
- m_aWheelRotation[CARWHEEL_REAR_LEFT] += m_aWheelSpeed[CARWHEEL_REAR_LEFT];
- }
- if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] <= 0.0f){
- if(bIsHandbrakeOn)
- m_aWheelSpeed[CARWHEEL_REAR_RIGHT] = 0.0f;
- else if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_REAR_RIGHT] *= 0.95f;
+ // TODO(LCS): where did this go?
+/*
+ if(bAudioChangingGear && m_fGasPedal > 0.4f && m_fBrakePedal < 0.1f && fwdSpeed > 0.15f &&
+ this == FindPlayerVehicle() && TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_1STPERSON){
+ if(GetStatus() == STATUS_PLAYER && !(pHandling->Flags & HANDLING_IS_BUS)){
+ if(m_nBusDoorTimerEnd == 0)
+ m_nBusDoorTimerEnd = 1000;
+ else {
+ uint32 timeStepInMs = CTimer::GetTimeStepInMilliseconds();
+ if(m_nBusDoorTimerEnd > timeStepInMs)
+ m_nBusDoorTimerEnd -= timeStepInMs;
+ else
+ m_nBusDoorTimerEnd = 0;
}
- m_aWheelRotation[CARWHEEL_REAR_RIGHT] += m_aWheelSpeed[CARWHEEL_REAR_RIGHT];
}
- }
-
- // Process front wheels on ground - second try
- if(rearWheelsFirst){
- 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, wheelRight, tmp;
-
- if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd = GetForward();
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal)*m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_LEFT].normal);
- wheelRight.Normalise();
- tmp = c*wheelFwd - s*wheelRight;
- wheelRight = s*wheelFwd + c*wheelRight;
- wheelFwd = tmp;
-
- m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_LEFT])*traction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB);
- WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT];
-
- if(Damage.GetWheelStatus(CARWHEEL_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.HasFrontWheelDrive(pHandling->nIdentifier))
- fThrust = acceleration;
- else
- fThrust = 0.0f;
-
- wheelFwd = GetForward();
- wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal)*m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal;
- wheelFwd.Normalise();
- wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].normal);
- wheelRight.Normalise();
- tmp = c*wheelFwd - s*wheelRight;
- wheelRight = s*wheelFwd + c*wheelRight;
- wheelFwd = tmp;
-
- m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceA = SURFACE_WHEELBASE;
- float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT])*traction;
- if(GetStatus() == STATUS_PLAYER)
- adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB);
- WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT];
-
- if(Damage.GetWheelStatus(CARWHEEL_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);
- }
+ if((m_aSuspensionSpringRatio[0] < 1.0f || m_aSuspensionSpringRatio[2] < 1.0f) &&
+ (m_aSuspensionSpringRatio[1] < 1.0f || m_aSuspensionSpringRatio[3] < 1.0f))
+ ApplyTurnForce(-GRAVITY*Min(m_fTurnMass, 2500.0f)*GetUp(), -1.0f*GetForward());
}
+*/
+
+ float steerRange;
+ if(fwdSpeed > 0.01f && m_aWheelTimer[CARWHEEL_FRONT_LEFT] > 0.0f && m_aWheelTimer[CARWHEEL_FRONT_RIGHT] > 0.0f && GetStatus() == STATUS_PLAYER){
+ CColPoint point;
+ point.surfaceA = SURFACE_WHEELBASE;
+ point.surfaceB = SURFACE_TARMAC;
+ float rightSpeed = DotProduct(m_vecMoveSpeed, GetRight());
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(point);
+ // i have no idea what's going on here
+ float magic = traction * adhesion * 16.0f / SQR(fwdSpeed);
+ magic = Clamp(magic, -1.0f, 1.0f);
+ magic = Asin(magic);
+ if(m_fSteerAngle < 0.0f && rightSpeed > 0.05f ||
+ m_fSteerAngle > 0.0f && rightSpeed < -0.05f ||
+ bIsHandbrakeOn)
+ steerRange = 1.0f;
+ else
+ steerRange = Min(magic/DEGTORAD(pHandling->fSteeringLock), 1.0f);
+
+ }else
+ steerRange = 1.0f;
+ m_fSteerAngle *= steerRange;
- // Process front wheels off ground
+ brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep();
- if (!IsRealHeli()) {
- if(m_aWheelTimer[CARWHEEL_FRONT_LEFT] <= 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_FRONT_LEFT] *= 0.95f;
- }
- m_aWheelRotation[CARWHEEL_FRONT_LEFT] += m_aWheelSpeed[CARWHEEL_FRONT_LEFT];
- }
- if(m_aWheelTimer[CARWHEEL_FRONT_RIGHT] <= 0.0f){
- if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) && acceleration != 0.0f){
- 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;
- }
- }else{
- m_aWheelSpeed[CARWHEEL_FRONT_RIGHT] *= 0.95f;
- }
- m_aWheelRotation[CARWHEEL_FRONT_RIGHT] += m_aWheelSpeed[CARWHEEL_FRONT_RIGHT];
- }
- }
+ if(pHandling->Flags & HANDLING_REARWHEEL_1ST){
+ ProcessCarWheelPair(CARWHEEL_REAR_LEFT, CARWHEEL_REAR_RIGHT, -999.0f, contactSpeeds, contactPoints,
+ traction, acceleration, brake, false);
+ ProcessCarWheelPair(CARWHEEL_FRONT_LEFT, CARWHEEL_FRONT_RIGHT, m_fSteerAngle, contactSpeeds, contactPoints,
+ traction, acceleration, brake, true);
+ }else{
+ ProcessCarWheelPair(CARWHEEL_FRONT_LEFT, CARWHEEL_FRONT_RIGHT, m_fSteerAngle, contactSpeeds, contactPoints,
+ traction, acceleration, brake, true);
+ ProcessCarWheelPair(CARWHEEL_REAR_LEFT, CARWHEEL_REAR_RIGHT, -999.0f, contactSpeeds, contactPoints,
+ traction, acceleration, brake, false);
}
for(i = 0; i < 4; i++){
float wheelPos = colModel->lines[i].p0.z;
if(m_aSuspensionSpringRatio[i] > 0.0f)
wheelPos -= m_aSuspensionSpringRatio[i]*m_aSuspensionSpringLength[i];
- if(GetModelIndex() == MI_VOODOO && bUsingSpecialColModel)
+ if(GetModelIndex() == MI_YARDIE && bUsingSpecialColModel) // not original LCS
m_aWheelPosition[i] = wheelPos;
else
m_aWheelPosition[i] += (wheelPos - m_aWheelPosition[i])*0.75f;
}
- for(i = 0; i < 4; i++)
- m_aWheelState[i] = WheelState[i];
- if(m_fGasPedal < 0.0f){
- if(m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SPINNING)
- m_aWheelState[CARWHEEL_REAR_LEFT] = WHEEL_STATE_NORMAL;
- if(m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SPINNING)
- m_aWheelState[CARWHEEL_REAR_RIGHT] = WHEEL_STATE_NORMAL;
- }
// Process horn
@@ -1650,13 +1263,13 @@ CAutomobile::ProcessControl(void)
// TODO: make the numbers defines
float heading;
- if(GetPosition().x > 1950.0f-400.0f){
+ if(GetPosition().x > 1950.0f){
if(m_vecMoveSpeed.x > 0.0f)
m_vecMoveSpeed.x *= -1.0f;
heading = GetForward().Heading();
if(heading > 0.0f) // going west
SetHeading(-heading);
- }else if(GetPosition().x < -1950.0f-400.0f){
+ }else if(GetPosition().x < -1950.0f){
if(m_vecMoveSpeed.x < 0.0f)
m_vecMoveSpeed.x *= -1.0f;
heading = GetForward().Heading();
@@ -1719,6 +1332,207 @@ CAutomobile::ProcessControl(void)
#pragma optimize("", on)
+//--LCS: done
+void
+CAutomobile::ProcessCarWheelPair(int leftWheel, int rightWheel, float steerAngle, CVector *contactSpeeds, CVector *contactPoints, float traction, float acceleration, float brake, bool bFront)
+{
+ bool driveWheels;
+ float suspensionBias;
+
+ if(bFront){
+ driveWheels = mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier);
+ suspensionBias = 2.0f*pHandling->fSuspensionBias;
+ }else{
+ driveWheels = mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier);
+ suspensionBias = 2.0f*(1.0f-pHandling->fSuspensionBias);
+
+ float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
+ if(bIsHandbrakeOn && Abs(fwdSpeed) > 0.01f){
+#ifdef FIX_BUGS
+ // Not sure if this is needed, but brake usually has timestep as a factor
+ brake = 20000.0f * CTimer::GetTimeStepFix();
+#else
+ brake = 20000.0f;
+#endif
+/*
+ if(fwdSpeed > 0.1f && pHandling->Flags & HANDLING_HANDBRAKE_TYRE){
+ m_fTireTemperature += 0.005*CTimer::GetTimeStep();
+ if(m_fTireTemperature > 2.0f)
+ m_fTireTemperature = 2.0f;
+ }
+*/
+ }else if(driveWheels && m_doingBurnout){
+ brake = 0.0f;
+ traction = 0.0f;
+ // BUG: missing timestep
+ ApplyTurnForce(contactPoints[leftWheel], -0.003f*m_fTurnMass*Min(3000.0f/m_fTurnMass, 1.0f)*m_fSteerAngle*GetRight());
+ }else if(mod_HandlingManager.HasRearWheelDrive(pHandling->nIdentifier)){
+ traction *= m_fTireTemperature;
+ }
+ }
+
+ // Wheels on ground
+ if(m_aWheelTimer[leftWheel] > 0.0f || m_aWheelTimer[rightWheel] > 0.0f){
+ CVector wheelFwd, wheelRight;
+ float s, c;
+ bool canSteer = steerAngle > -100.0f;
+ if(canSteer){
+ s = Sin(steerAngle);
+ c = Cos(steerAngle);
+ }
+
+ bool neutralHandling = GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE && (pHandling->Flags & HANDLING_NEUTRALHANDLING);
+ float brakeBias, tractionBias;
+ if(bFront){
+ brakeBias = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias;
+ tractionBias = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias;
+ }else{
+ brakeBias = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fBrakeBias);
+ tractionBias = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fTractionBias);
+ }
+
+ if(m_aWheelTimer[leftWheel] > 0.0f){
+ float fThrust = driveWheels ? acceleration : 0.0f;
+
+ wheelFwd = GetForward();
+ wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[leftWheel].normal)*m_aWheelColPoints[leftWheel].normal;
+ wheelFwd.Normalise();
+ wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[leftWheel].normal);
+ wheelRight.Normalise();
+ if(canSteer){
+ CVector tmp = c*wheelFwd - s*wheelRight;
+ wheelRight = s*wheelFwd + c*wheelRight;
+ wheelFwd = tmp;
+ }
+
+ m_aWheelColPoints[leftWheel].surfaceA = SURFACE_WHEELBASE;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[leftWheel])*traction;
+ if(GetStatus() == STATUS_PLAYER){
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[leftWheel].surfaceB);
+ adhesion *= Min(suspensionBias*pHandling->fSuspensionForceLevel*4.0f*(1.0f-m_aSuspensionSpringRatio[leftWheel]), 2.0f);
+ }
+ tWheelState WheelState = m_aWheelState[leftWheel];
+ if(Damage.GetWheelStatus(leftWheel) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[leftWheel], contactPoints[leftWheel],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBias,
+ adhesion*tractionBias*Damage.m_fWheelDamageEffect,
+ leftWheel,
+ &m_aWheelRotation[leftWheel],
+ &WheelState,
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[leftWheel], contactPoints[leftWheel],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBias,
+ adhesion*tractionBias,
+ leftWheel,
+ &m_aWheelRotation[leftWheel],
+ &WheelState,
+ WHEEL_STATUS_OK);
+
+ if(driveWheels && m_fGasPedal < 0.0f && WheelState == WHEEL_STATE_SPINNING)
+ m_aWheelState[leftWheel] = WHEEL_STATE_NORMAL;
+ else
+ m_aWheelState[leftWheel] = WheelState;
+ }
+
+ if(m_aWheelTimer[rightWheel] > 0.0f){
+ float fThrust = driveWheels ? acceleration : 0.0f;
+
+ wheelFwd = GetForward();
+ wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[rightWheel].normal)*m_aWheelColPoints[rightWheel].normal;
+ wheelFwd.Normalise();
+ wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[rightWheel].normal);
+ wheelRight.Normalise();
+ if(canSteer){
+ CVector tmp = c*wheelFwd - s*wheelRight;
+ wheelRight = s*wheelFwd + c*wheelRight;
+ wheelFwd = tmp;
+ }
+
+ m_aWheelColPoints[rightWheel].surfaceA = SURFACE_WHEELBASE;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[rightWheel])*traction;
+ if(GetStatus() == STATUS_PLAYER){
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[rightWheel].surfaceB);
+ adhesion *= Min(suspensionBias*pHandling->fSuspensionForceLevel*4.0f*(1.0f-m_aSuspensionSpringRatio[rightWheel]), 2.0f);
+ }
+ tWheelState WheelState = m_aWheelState[rightWheel];
+ if(Damage.GetWheelStatus(rightWheel) == WHEEL_STATUS_BURST)
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[rightWheel], contactPoints[rightWheel],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBias,
+ adhesion*tractionBias*Damage.m_fWheelDamageEffect,
+ rightWheel,
+ &m_aWheelRotation[rightWheel],
+ &WheelState,
+ WHEEL_STATUS_BURST);
+ else
+ ProcessWheel(wheelFwd, wheelRight,
+ contactSpeeds[rightWheel], contactPoints[rightWheel],
+ m_nWheelsOnGround, fThrust,
+ brake*brakeBias,
+ adhesion*tractionBias,
+ rightWheel,
+ &m_aWheelRotation[rightWheel],
+ &WheelState,
+ WHEEL_STATUS_OK);
+
+ if(driveWheels && m_fGasPedal < 0.0f && WheelState == WHEEL_STATE_SPINNING)
+ m_aWheelState[rightWheel] = WHEEL_STATE_NORMAL;
+ else
+ m_aWheelState[rightWheel] = WheelState;
+ }
+ }
+
+ if(!bFront){
+ if(m_doingBurnout && driveWheels &&
+ (m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SPINNING || m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SPINNING)){
+ m_fTireTemperature += 0.001f*CTimer::GetTimeStep();
+ if(m_fTireTemperature > 3.0f)
+ m_fTireTemperature = 3.0f;
+ }else if(m_fTireTemperature > 1.0f){
+ m_fTireTemperature = (m_fTireTemperature - 1.0f)*Pow(0.995f, CTimer::GetTimeStep()) + 1.0f;
+ }
+ }
+
+ // Process wheels off ground
+
+ if(!IsRealHeli()){
+ if(m_aWheelTimer[leftWheel] <= 0.0f){
+ if(driveWheels && acceleration != 0.0f){
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[leftWheel] < 1.0f)
+ m_aWheelSpeed[leftWheel] -= 0.1f;
+ }else{
+ if(m_aWheelSpeed[leftWheel] > -1.0f)
+ m_aWheelSpeed[leftWheel] += 0.05f;
+ }
+ }else{
+ m_aWheelSpeed[leftWheel] *= 0.95f;
+ }
+ m_aWheelRotation[leftWheel] += m_aWheelSpeed[leftWheel]*CTimer::GetTimeStep();
+ }
+ if(m_aWheelTimer[rightWheel] <= 0.0f){
+ if(driveWheels && acceleration != 0.0f){
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[rightWheel] < 1.0f)
+ m_aWheelSpeed[rightWheel] -= 0.1f;
+ }else{
+ if(m_aWheelSpeed[rightWheel] > -1.0f)
+ m_aWheelSpeed[rightWheel] += 0.05f;
+ }
+ }else{
+ m_aWheelSpeed[rightWheel] *= 0.95f;
+ }
+ m_aWheelRotation[rightWheel] += m_aWheelSpeed[rightWheel]*CTimer::GetTimeStep();
+ }
+ }
+}
+
void
CAutomobile::Teleport(CVector pos)
{
@@ -1740,6 +1554,11 @@ CAutomobile::PreRender(void)
int i, j, n;
CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex());
+ if(GetModelIndex() == MI_FIRETRUCK)
+ FireTruckControl();
+
+ CVehicle::PreRender();
+
if(GetModelIndex() == MI_RHINO && m_aCarNodes[CAR_WINDSCREEN]){
// Rotate Rhino turret
CMatrix m;
@@ -2046,6 +1865,7 @@ CAutomobile::PreRender(void)
if(DotProduct(GetForward(), camDist) > 0.0f ||
TheCamera.GetLookDirection() == LOOKING_LEFT ||
TheCamera.GetLookDirection() == LOOKING_RIGHT){
+ /*
CParticle::AddParticle(PARTICLE_HEATHAZE, pos1, CVector(0.0f, 0.0f, 0.0f));
if(pHandling->Flags & HANDLING_DBL_EXHAUST)
CParticle::AddParticle(PARTICLE_HEATHAZE, pos2, CVector(0.0f, 0.0f, 0.0f));
@@ -2053,6 +1873,7 @@ CAutomobile::PreRender(void)
CParticle::AddParticle(PARTICLE_HEATHAZE, pos1, CVector(0.0f, 0.0f, 0.0f));
if(pHandling->Flags & HANDLING_DBL_EXHAUST)
CParticle::AddParticle(PARTICLE_HEATHAZE, pos2, CVector(0.0f, 0.0f, 0.0f));
+ */
}
}
@@ -2202,8 +2023,7 @@ CAutomobile::PreRender(void)
case MI_TAXI:
case MI_CABBIE:
- case MI_ZEBRA:
- case MI_KAUFMAN:
+ case MI_BORGNINE:
if(bTaxiLight){
CVector pos = GetPosition() + GetUp()*0.95f;
CCoronas::RegisterCorona((uintptr)this + 21,
@@ -3019,6 +2839,7 @@ CAutomobile::Render(void)
CEntity::Render();
}
+//--LCS: done
int32
CAutomobile::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
{
@@ -3090,9 +2911,13 @@ static float fMouseCentreRange = 0.35f;
static float fMouseSteerSens = -0.0035f;
static float fMouseCentreMult = 0.975f;
+//--LCS: done except TODO
void
CAutomobile::ProcessControlInputs(uint8 pad)
{
+ if(this == FindPlayerVehicle() && CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle)
+ return;
+
float speed = DotProduct(m_vecMoveSpeed, GetForward());
if(!CPad::GetPad(pad)->GetExitVehicle() ||
@@ -3103,6 +2928,7 @@ CAutomobile::ProcessControlInputs(uint8 pad)
bIsHandbrakeOn = true;
// Steer left/right
+#if 0 // LCS: removed, need mouse for free cam
if(CCamera::m_bUseMouse3rdPerson && !CVehicle::m_bDisableMouseSteering){
if(CPad::GetPad(pad)->GetMouseX() != 0.0f){
m_fSteerInput += fMouseSteerSens*CPad::GetPad(pad)->GetMouseX();
@@ -3115,7 +2941,9 @@ CAutomobile::ProcessControlInputs(uint8 pad)
0.2f*CTimer::GetTimeStep();
nLastControlInput = 0;
}
- }else{
+ }else
+#endif
+ {
m_fSteerInput += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteerInput)*
0.2f*CTimer::GetTimeStep();
nLastControlInput = 0;
@@ -3208,6 +3036,7 @@ CAutomobile::ProcessControlInputs(uint8 pad)
// Brake if player isn't in control
// BUG: game always uses pad 0 here
+ // TODO(LCS): more conditions here
#ifdef FIX_BUGS
if(CPad::GetPad(pad)->ArePlayerControlsDisabled()){
#else
@@ -3930,6 +3759,7 @@ CAutomobile::DoDriveByShootings(void)
}
}
+//--LCS: done
void
CAutomobile::DoHoverSuspensionRatios(void)
{
@@ -4345,7 +4175,7 @@ CAutomobile::dmgDrawCarCollidingParticles(const CVector &pos, float amount)
CGeneral::GetRandomNumberInRange(0.1f, 0.25f)),
nil,
CGeneral::GetRandomNumberInRange(0.02f, 0.08f),
- CVehicleModelInfo::ms_vehicleColourTable[m_currentColour1],
+ CVehicleModelInfo::mspInfo->ms_vehicleColourTable[m_currentColour1],
CGeneral::GetRandomNumberInRange(-40.0f, 40.0f),
0,
CGeneral::GetRandomNumberInRange(0.0f, 4.0f));
@@ -5026,6 +4856,7 @@ CAutomobile::ResetSuspension(void)
}
}
+//--LCS: done
void
CAutomobile::SetupSuspensionLines(void)
{
@@ -5034,6 +4865,14 @@ CAutomobile::SetupSuspensionLines(void)
CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex());
CColModel *colModel = mi->GetColModel();
+ bool adjustColModel;
+ if(colModel->lines == nil){
+ adjustColModel = true;
+ colModel->lines = new CColLine[4];
+ colModel->numLines = 4;
+ }else
+ adjustColModel = false;
+
// Each suspension line starts at the uppermost wheel position
// and extends down to the lowermost point on the tyre
for(i = 0; i < 4; i++){
@@ -5073,6 +4912,21 @@ CAutomobile::SetupSuspensionLines(void)
for(i = 0; i < colModel->numSpheres; i++)
colModel->spheres[i].radius = 0.3f;
}
+
+ if(pHandling->Flags & HANDLING_FORCE_GRND_CLR && adjustColModel){
+ // 0.25 is the min distance between ground and col spheres, everything above it is safe
+ float safePos = 0.25f - m_fHeightAboveRoad;
+ for(i = 0; i < colModel->numSpheres; i++){
+ CColSphere *sph = &colModel->spheres[i];
+ if(sph->center.z - sph->radius < safePos){
+ // sphere extends too far down, so move it up
+ // or decrease the radius for bigger spheres
+ if(radius > 0.4f)
+ sph->radius = Max(sph->center.z - safePos, 0.4f);
+ sph->center.z = safePos + sph->radius;
+ }
+ }
+ }
}
// called on police cars
diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h
index 16d86917..4f4ab500 100644
--- a/src/vehicles/Automobile.h
+++ b/src/vehicles/Automobile.h
@@ -26,6 +26,8 @@ public:
float m_aSuspensionSpringRatioPrev[4];
float m_aWheelTimer[4]; // set to 4.0 when wheel is touching ground, then decremented
float m_auto_unused1;
+ float m_fEngineInertiaVar1;
+ float m_fEngineInertiaVar2;
eSkidmarkType m_aWheelSkidmarkType[4];
bool m_aWheelSkidmarkBloody[4];
bool m_aWheelSkidmarkUnk[4];
@@ -114,6 +116,7 @@ public:
float GetHeightAboveRoad(void);
void PlayCarHorn(void);
+ void ProcessCarWheelPair(int leftWheel, int rightWheel, float steerAngle, CVector *contactSpeeds, CVector *contactPoints, float traction, float acceleration, float brake, bool bFront);
void FireTruckControl(void);
void TankControl(void);
void HydraulicControl(void);
diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp
index a65b64d2..39612a15 100644
--- a/src/vehicles/Bike.cpp
+++ b/src/vehicles/Bike.cpp
@@ -80,9 +80,10 @@ CBike::CBike(int32 id, uint8 CreatedBy)
m_bikeAnimType = ASSOCGRP_BIKE_STANDARD;
break;
case MI_SANCHEZ:
+ case MI_SANCHEZ2:
m_bikeAnimType = ASSOCGRP_BIKE_DIRT;
break;
- default: assert(0 && "invalid bike model ID");
+ default: m_bikeAnimType = ASSOCGRP_BIKE_STANDARD; //assert(0 && "invalid bike model ID"); // TODO
}
m_vehType = VEHICLE_TYPE_BIKE;
@@ -110,7 +111,7 @@ CBike::CBike(int32 id, uint8 CreatedBy)
m_fTurnMass = pHandling->fTurnMass;
m_vecCentreOfMass = pHandling->CentreOfMass;
m_vecCentreOfMass.z = 0.1f;
- m_fAirResistance = pHandling->Dimension.x*pHandling->Dimension.z/m_fMass;
+ m_fAirResistance = pHandling->fDragMult > 0.01f ? pHandling->fDragMult*0.0005f : pHandling->fDragMult;
m_fElasticity = 0.05f;
m_fBuoyancy = pHandling->fBuoyancy;
@@ -134,6 +135,8 @@ CBike::CBike(int32 id, uint8 CreatedBy)
bIsOnFire = false;
bWheelieCam = false;
+ bFixedColour = false; // <- figure out actual place (TODO)
+
m_fTireTemperature = 1.0f;
m_fBrakeDestabilization = 0.0f;
m_fVelocityChangeForAudio = 0;
@@ -1723,7 +1726,7 @@ CBike::PreRender(void)
TheCamera.GetLookDirection() == LOOKING_RIGHT)
pos1 -= 0.2f*GetForward();
- CParticle::AddParticle(PARTICLE_HEATHAZE, pos1, CVector(0.0f, 0.0f, 0.0f));
+ //CParticle::AddParticle(PARTICLE_HEATHAZE, pos1, CVector(0.0f, 0.0f, 0.0f));
}
}
}
diff --git a/src/vehicles/Bike.h b/src/vehicles/Bike.h
index 219d8872..611cd11d 100644
--- a/src/vehicles/Bike.h
+++ b/src/vehicles/Bike.h
@@ -75,6 +75,7 @@ public:
uint8 bExtraSpeed : 1; // leaning forward
uint8 bIsOnFire : 1;
uint8 bWheelieCam : 1;
+ uint8 bFixedColour : 1; // <- figure out its actual place (TODO)
int16 m_doingBurnout;
float m_fTireTemperature;
float m_fBrakeDestabilization;
diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp
index 73957107..a3aec041 100644
--- a/src/vehicles/Boat.cpp
+++ b/src/vehicles/Boat.cpp
@@ -72,7 +72,7 @@ CBoat::CBoat(int mi, uint8 owner) : CVehicle(owner)
m_fMass = pHandling->fMass;
m_fTurnMass = pHandling->fTurnMass / 2.0f;
m_vecCentreOfMass = pHandling->CentreOfMass;
- m_fAirResistance = pHandling->Dimension.x * pHandling->Dimension.z / m_fMass;
+ m_fAirResistance = pHandling->fDragMult > 0.01f ? pHandling->fDragMult*0.0005f : pHandling->fDragMult;
m_fElasticity = 0.1f;
m_fBuoyancy = pHandling->fBuoyancy;
m_fSteerAngle = 0.0f;
@@ -682,6 +682,7 @@ CBoat::ProcessControl(void)
}
// Spray waterdrops on screen
+ /*
if(TheCamera.GetLookingForwardFirstPerson() && FindPlayerVehicle() && FindPlayerVehicle()->IsBoat() &&
m_nDeltaVolumeUnderWater > 0 && numWaterDropOnScreen < 20){
CVector dropPos;
@@ -712,7 +713,7 @@ CBoat::ProcessControl(void)
if(CParticle::AddParticle(PARTICLE_WATERDROP, dropPos, dropDir, nil,
CGeneral::GetRandomNumberInRange(0.1f, 0.15f), dropColor, 0, 0, frm))
numWaterDropOnScreen++;
- }
+ }*/
if(m_fPrevVolumeUnderWater == 0.0f && m_fVolumeUnderWater > 0.0f && GetModelIndex() == MI_SKIMMER){
CVector splashDir(0.0f, 0.0f, 0.25f*speed);
diff --git a/src/vehicles/Cranes.cpp b/src/vehicles/Cranes.cpp
index 934ccb08..d4b58f05 100644
--- a/src/vehicles/Cranes.cpp
+++ b/src/vehicles/Cranes.cpp
@@ -13,7 +13,7 @@
#include "World.h"
#include "SaveBuf.h"
-#define MAX_DISTANCE_TO_FIND_CRANE (10.0f)
+#define MAX_DISTANCE_TO_FIND_CRANE (100.0f)
#define CRANE_UPDATE_RADIUS (300.0f)
#define CRANE_MOVEMENT_PROCESSING_RADIUS (150.0f)
#define CRUSHER_Z (-0.951f)
@@ -67,7 +67,8 @@ void CCranes::InitCranes(void)
}
}
}
- for (CPtrNode* pNode = CWorld::GetBigBuildingList(LEVEL_MAINLAND).first; pNode; pNode = pNode->next) {
+ // TODO(LCS)
+ for (CPtrNode* pNode = CWorld::GetBigBuildingList(LEVEL_INDUSTRIAL).first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (MODELID_CRANE_1 == pEntity->GetModelIndex() ||
MODELID_CRANE_2 == pEntity->GetModelIndex() ||
@@ -77,6 +78,7 @@ void CCranes::InitCranes(void)
MODELID_CRANE_6 == pEntity->GetModelIndex())
AddThisOneCrane(pEntity);
}
+
}
void CCranes::AddThisOneCrane(CEntity* pEntity)
@@ -469,7 +471,7 @@ bool CCranes::DoesMilitaryCraneHaveThisOneAlready(uint32 mi)
case MI_FIRETRUCK: return (CarsCollectedMilitaryCrane & 1);
case MI_AMBULAN: return (CarsCollectedMilitaryCrane & 2);
case MI_ENFORCER: return (CarsCollectedMilitaryCrane & 4);
- case MI_FBIRANCH: return (CarsCollectedMilitaryCrane & 8);
+ case (uint32)MI_FBIRANCH: return (CarsCollectedMilitaryCrane & 8);
case MI_RHINO: return (CarsCollectedMilitaryCrane & 0x10);
case MI_BARRACKS: return (CarsCollectedMilitaryCrane & 0x20);
case MI_POLICE: return (CarsCollectedMilitaryCrane & 0x40);
@@ -484,7 +486,7 @@ void CCranes::RegisterCarForMilitaryCrane(uint32 mi)
case MI_FIRETRUCK: CarsCollectedMilitaryCrane |= 1; break;
case MI_AMBULAN: CarsCollectedMilitaryCrane |= 2; break;
case MI_ENFORCER: CarsCollectedMilitaryCrane |= 4; break;
- case MI_FBIRANCH: CarsCollectedMilitaryCrane |= 8; break;
+ case (uint32)MI_FBIRANCH: CarsCollectedMilitaryCrane |= 8; break;
case MI_RHINO: CarsCollectedMilitaryCrane |= 0x10; break;
case MI_BARRACKS: CarsCollectedMilitaryCrane |= 0x20; break;
case MI_POLICE: CarsCollectedMilitaryCrane |= 0x40; break;
diff --git a/src/vehicles/DamageManager.cpp b/src/vehicles/DamageManager.cpp
index 8ba235b7..b74e7086 100644
--- a/src/vehicles/DamageManager.cpp
+++ b/src/vehicles/DamageManager.cpp
@@ -10,7 +10,8 @@ float G_aComponentDamage[] = { 2.5f, 1.25f, 3.2f, 1.4f, 2.5f, 2.8f, 0.5f };
CDamageManager::CDamageManager(void)
{
ResetDamageStatus();
- m_fWheelDamageEffect = 0.5f;
+ m_fWheelDamageEffect = 0.65f;
+ m_bSmashedDoorDoesntClose = false;
field_18 = 1;
}
@@ -136,6 +137,8 @@ void
CDamageManager::SetDoorStatus(int32 door, uint32 status)
{
m_doorStatus[door] = status;
+ if(m_bSmashedDoorDoesntClose && door != DOOR_BONNET && status == DOOR_STATUS_SMASHED)
+ m_doorStatus[door] = DOOR_STATUS_SWINGING;
}
int32
diff --git a/src/vehicles/DamageManager.h b/src/vehicles/DamageManager.h
index 312006e3..1f836429 100644
--- a/src/vehicles/DamageManager.h
+++ b/src/vehicles/DamageManager.h
@@ -81,6 +81,7 @@ class CDamageManager
public:
float m_fWheelDamageEffect;
+ bool m_bSmashedDoorDoesntClose;
uint8 m_engineStatus;
uint8 m_wheelStatus[4];
uint8 m_doorStatus[6];
diff --git a/src/vehicles/Door.cpp b/src/vehicles/Door.cpp
index 1b3f9e8f..6e35c951 100644
--- a/src/vehicles/Door.cpp
+++ b/src/vehicles/Door.cpp
@@ -168,3 +168,58 @@ CTrainDoor::IsClosed(void)
{
return m_fPosn == RetTranslationWhenClosed();
}
+
+bool
+CFerryDoor::IsInUse(void)
+{
+ float translationDifference = m_fPrevPosn - m_fPosn;
+ m_fPrevPosn = m_fPosn;
+ return Abs(translationDifference) > 0.002f;
+}
+
+float
+CFerryDoor::RetTranslationWhenClosed(void)
+{
+ if(Abs(m_fClosedPosn) < Abs(m_fOpenPosn))
+ return m_fClosedPosn;
+ else
+ return m_fOpenPosn;
+}
+
+bool
+CFerryDoor::IsClosed(void)
+{
+ return m_fPosn == RetTranslationWhenClosed();
+}
+
+float
+CFerryDoor::RetTranslationWhenOpen(void)
+{
+ if(Abs(m_fClosedPosn) < Abs(m_fOpenPosn))
+ return m_fOpenPosn;
+ else
+ return m_fClosedPosn;
+}
+
+bool
+CFerryDoor::IsFullyOpen(void)
+{
+ if(Abs(m_fPosn) < Abs(RetTranslationWhenOpen()) - 0.5f)
+ return false;
+ return true;
+}
+
+void
+CFerryDoor::Open(float ratio)
+{
+ float open;
+
+ m_fPrevPosn = m_fPosn;
+ open = RetTranslationWhenOpen();
+ if(ratio < 1.0f){
+ m_fPosn = open*ratio;
+ }else{
+ m_nDoorState = DOORST_OPEN;
+ m_fPosn = open;
+ }
+} \ No newline at end of file
diff --git a/src/vehicles/Door.h b/src/vehicles/Door.h
index 567d3263..da5a3de0 100644
--- a/src/vehicles/Door.h
+++ b/src/vehicles/Door.h
@@ -67,3 +67,22 @@ public:
float RetTranslationWhenOpen(void);
void Open(float ratio);
};
+
+
+class CFerryDoor {
+private:
+ float m_fClosedPosn;
+ float m_fOpenPosn;
+ int8 m_nDirn;
+ int8 m_nAxis;
+ int8 m_nDoorState;
+ float m_fPosn;
+ float m_fPrevPosn;
+public:
+ bool IsInUse(void);
+ float RetTranslationWhenClosed(void);
+ float RetTranslationWhenOpen(void);
+ bool IsClosed(void);
+ bool IsFullyOpen(void);
+ void Open(float ratio);
+}; \ No newline at end of file
diff --git a/src/vehicles/Ferry.cpp b/src/vehicles/Ferry.cpp
new file mode 100644
index 00000000..89a0de9f
--- /dev/null
+++ b/src/vehicles/Ferry.cpp
@@ -0,0 +1,832 @@
+#include "common.h"
+#include "main.h"
+#include "Ferry.h"
+
+#include "AudioManager.h"
+#include "Camera.h"
+#include "Coronas.h"
+#include "FileMgr.h"
+#include "General.h"
+#include "Leeds.h"
+#include "Particle.h"
+#include "PlayerPed.h"
+#include "Streaming.h"
+#include "TempColModels.h"
+#include "WaterLevel.h"
+#include "World.h"
+
+CFerryInst* CFerry::mspInst;
+
+#define FERRY_SPEED (0.1f)
+#define FERRY_SLOWDOWN_DISTANCE (50.0f)
+#define FERRY_TIME_STOPPED_AT_STATION (10.0f)
+
+CFerry::CFerry(int32 id, uint8 owner) : CVehicle(owner)
+{
+ m_bPlayerArrivedHorn = false;
+ m_nTimeAlongPath = 0;
+ m_vehType = VEHICLE_TYPE_FERRY;
+ CVehicleModelInfo* mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id);
+ pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId);
+ SetModelIndex(id);
+ m_doors[0].Init(DEGTORAD(90.0f), 0.0f, 1, 0);
+ m_doors[1].Init(DEGTORAD(-95.0f), 0.0f, 1, 0);
+ m_doors[2].Init(DEGTORAD(-90.0f), 0.0f, 1, 0);
+ m_doors[3].Init(DEGTORAD(95.0f), 0.0f, 1, 0);
+ m_fTurnMass = 100000000.0f;
+ m_fAirResistance = 0.9994f;
+ m_fElasticity = 0.05f;
+ m_nNumMaxPassengers = 1;
+ m_fMass = 100000000.0f;
+ bInfiniteMass = true;
+ m_phy_flagA08 = true;
+ m_bFerryDocked = false;
+ SetStatus(STATUS_FERRY_MOVING);
+ bUsesCollision = true;
+ m_nDoorTimer = CTimer::GetTimeInMilliseconds();
+ m_nDoorState = FERRY_DOOR_CLOSED;
+ m_bApproachingDock = false;
+ m_nSkipFerryStatus = 0;
+ m_nCollision = 0;
+ m_pDefaultColModel = mi->GetColModel();
+ m_level = LEVEL_GENERIC;
+}
+
+void CFerry::Init(void* pInstancePtr)
+{
+ mspInst = (CFerryInst*)pInstancePtr;
+ if (mspInst)
+ return;
+ // the following code should be wrapped in a define
+ mspInst = new CFerryInst();
+ memset(mspInst, 0, sizeof(CFerryInst));
+ for (int k = 0; k < NUM_FERRY_PATHS; k++) {
+ mspInst->pPathData[k] = new CFerryPath();
+ mspInst->pPathData[k]->aLineBits = new CFerryInterpolationLine[NUM_FERRY_STATIONS * 4 + 2];
+
+ const char* filename = "Data\\PATHS\\FERRY1.DAT"; // actually base::cStringT<char> filename; filename += k+1; filename += ".DAT"
+
+ bool readingFile = false;
+ int bp, lp;
+ int i, tmp;
+ CFerryPath* pPath = mspInst->pPathData[k];
+
+ if (pPath->aTrackNodes == nil) {
+ readingFile = true;
+
+ CFileMgr::LoadFile(filename, work_buff, sizeof(work_buff), "r");
+ *gString = '\0';
+ for (bp = 0, lp = 0; work_buff[bp] != '\n'; bp++, lp++)
+ gString[lp] = work_buff[bp];
+ bp++;
+#ifdef FIX_BUGS
+ gString[lp] = '\0';
+#endif
+ sscanf(gString, "%d", &tmp);
+ pPath->NumTrackNodes = tmp;
+ pPath->aTrackNodes = new CFerryNode[tmp];
+
+ for (i = 0; i < pPath->NumTrackNodes; i++) {
+ *gString = '\0';
+ for (lp = 0; work_buff[bp] != '\n'; bp++, lp++)
+ gString[lp] = work_buff[bp];
+ bp++;
+#ifdef FIX_BUGS
+ gString[lp] = '\0';
+#endif
+ sscanf(gString, "%f %f %f", &pPath->aTrackNodes[i].x, &pPath->aTrackNodes[i].y, &pPath->aTrackNodes[i].z);
+ pPath->aTrackNodes[i].z = 0.0f;
+ }
+ }
+
+ // Calculate length of segments and track
+ float t = 0.0f;
+ for (i = 0; i < pPath->NumTrackNodes; i++) {
+ pPath->aTrackNodes[i].t = t;
+ t += Sqrt(SQR(pPath->aTrackNodes[(i + 1) % pPath->NumTrackNodes].x - pPath->aTrackNodes[i].x) +
+ (SQR(pPath->aTrackNodes[(i + 1) % pPath->NumTrackNodes].y - pPath->aTrackNodes[i].y)));
+ }
+ pPath->TotalLengthOfTrack = t;
+
+ // Find correct z values
+ if (readingFile) {
+ CColPoint colpoint;
+ CEntity* entity;
+ for (i = 0; i < pPath->NumTrackNodes; i++) {
+ CVector p(pPath->aTrackNodes[i].x, pPath->aTrackNodes[i].y, pPath->aTrackNodes[i].z + 1.0f);
+ if (CWorld::ProcessVerticalLine(p, p.z - 0.5f, colpoint, entity, true, false, false, false, true, false, nil))
+ pPath->aTrackNodes[i].z = colpoint.point.z;
+ pPath->aTrackNodes[i].z += 0.2f;
+ }
+ }
+
+ int nStationIndices[NUM_FERRY_STATIONS];
+ for (int i = 0; i < NUM_FERRY_STATIONS; i++)
+ nStationIndices[i] = 0;
+ int nCurrentStation = 0;
+
+ for (i = 0; i < pPath->NumTrackNodes; i++) {
+ CFerryNode* pCurNode = &pPath->aTrackNodes[i];
+ CFerryNode* pNextNode = (i + 1 < pPath->NumTrackNodes) ? &pPath->aTrackNodes[i + 1] : &pPath->aTrackNodes[0];
+ CFerryNode* pPrevNode = (i - 1 >= 0) ? &pPath->aTrackNodes[i - 1] : &pPath->aTrackNodes[pPath->NumTrackNodes - 1];
+ if (pCurNode->x - pNextNode->x > 0.0f && pPrevNode->x - pCurNode->x < 0.0f)
+ nStationIndices[nCurrentStation++] = i;
+ if (pCurNode->x - pNextNode->x < 0.0f && pPrevNode->x - pCurNode->x > 0.0f)
+ nStationIndices[nCurrentStation++] = i;
+ }
+
+ float stationDists[NUM_FERRY_STATIONS];
+ for (i = 0; i < NUM_FERRY_STATIONS; i++)
+ stationDists[i] = pPath->aTrackNodes[nStationIndices[i]].t;
+
+ // Create animation for stopping at stations
+ float position = 0.0f;
+ float time = 0.0f;
+ int j = 0;
+ for (i = 0; i < NUM_FERRY_STATIONS; i++) {
+ // Start at full speed
+ pPath->aLineBits[j].type = FERRY_CRUISING;
+ pPath->aLineBits[j].time = time;
+ pPath->aLineBits[j].position = position;
+ pPath->aLineBits[j].speed = FERRY_SPEED;
+ pPath->aLineBits[j].acceleration = 0.0f;
+ j++;
+ // distance to next keyframe
+ float dist = (stationDists[i] - FERRY_SLOWDOWN_DISTANCE) - position;
+ time += dist / FERRY_SPEED;
+ position += dist;
+
+ // Now slow down 50 units before stop
+ pPath->aLineBits[j].type = FERRY_SLOWING;
+ pPath->aLineBits[j].time = time;
+ pPath->aLineBits[j].position = position;
+ pPath->aLineBits[j].speed = FERRY_SPEED;
+ pPath->aLineBits[j].acceleration = -(FERRY_SPEED * FERRY_SPEED) / (4 * FERRY_SLOWDOWN_DISTANCE);
+ j++;
+ time += 2 * FERRY_SLOWDOWN_DISTANCE / FERRY_SPEED;
+ position += FERRY_SLOWDOWN_DISTANCE; // at station
+
+ // stopping
+ pPath->aLineBits[j].type = FERRY_STOPPED;
+ pPath->aLineBits[j].time = time;
+ pPath->aLineBits[j].position = position;
+ pPath->aLineBits[j].speed = 0.0f;
+ pPath->aLineBits[j].acceleration = 0.0f;
+ j++;
+ time += FERRY_TIME_STOPPED_AT_STATION;
+
+ // accelerate again
+ pPath->aLineBits[j].type = FERRY_ACCELERATING;
+ pPath->aLineBits[j].time = time;
+ pPath->aLineBits[j].position = position;
+ pPath->aLineBits[j].speed = 0.0f;
+ pPath->aLineBits[j].acceleration = (FERRY_SPEED * FERRY_SPEED) / (4 * FERRY_SLOWDOWN_DISTANCE);
+ j++;
+ time += 2 * FERRY_SLOWDOWN_DISTANCE / FERRY_SPEED;
+ position += FERRY_SLOWDOWN_DISTANCE; // after station
+ }
+ // last keyframe
+ pPath->aLineBits[j].type = FERRY_CRUISING;
+ pPath->aLineBits[j].time = time;
+ pPath->aLineBits[j].position = position;
+ pPath->aLineBits[j].speed = FERRY_SPEED;
+ pPath->aLineBits[j].acceleration = 0.0f;
+ j++;
+ pPath->TotalDurationOfTrack = time + (pPath->TotalLengthOfTrack - position) / FERRY_SPEED;
+
+ // end
+ pPath->aLineBits[j].time = pPath->TotalDurationOfTrack;
+ }
+}
+
+void CFerry::InitFerrys(void)
+{
+ printf("init ferrys\n");
+#ifdef GTA_NETWORK
+ if (gIsMultiplayerGame)
+ SetupForMultiplayer();
+#endif
+ if (!mspInst)
+ Init(nil);
+ for (int i = 0; i < NUM_FERRIES; i++)
+ mspInst->m_apFerries[i] = nil;
+ CStreaming::LoadAllRequestedModels(false);
+ CStreaming::RequestModel(MI_FERRY, 0);
+ CStreaming::LoadAllRequestedModels(false);
+}
+
+void CFerry::SwitchFerryCollision(int type)
+{
+ for (int i = 0; i < NUM_FERRIES; i++) {
+ CFerry* pFerry = GetFerry(i);
+ if (pFerry && pFerry->m_nCollision != type) {
+ pFerry->m_nCollision = type;
+ CVehicleModelInfo* mi = pFerry->GetModelInfo();
+ if (type == 1)
+ mi->SetColModel(&CTempColModels::ms_colModelFerryDocked);
+ else
+ mi->SetColModel(pFerry->m_pDefaultColModel, true);
+ }
+ }
+}
+
+void CFerry::UpdateFerrys(void)
+{
+ int i, j;
+ float t, deltaT;
+ if (mspInst->m_bFerriesDisabled)
+ return;
+ for (i = 0; i < NUM_FERRIES; i++) {
+ CFerry* pFerry = GetFerry(i);
+ if (pFerry) {
+ pFerry->m_nTimeAlongPath += CTimer::GetTimeStepInMilliseconds();
+ t = mspInst->pPathData[i/2]->TotalDurationOfTrack * (float)((pFerry->m_nTimeAlongPath + (i & 1) * 0x20000) & 0x3FFFF) / 0x40000;
+ // find current frame
+ for (j = 0; t > mspInst->pPathData[i / 2]->aLineBits[j + 1].time; j++);
+
+ deltaT = t - mspInst->pPathData[i / 2]->aLineBits[j].time;
+ if (pFerry->m_bFerryDocked) {
+ if (mspInst->pPathData[i / 2]->aLineBits[j].type == FERRY_SLOWING) {
+ pFerry->m_nTimeAlongPath += (mspInst->pPathData[i / 2]->aLineBits[j + 1].time - mspInst->pPathData[i / 2]->aLineBits[j].time);
+ j++;
+ if (j > NUM_FERRY_STATIONS * 4 + 1)
+ j = 0;
+ pFerry->m_bApproachingDock = true;
+ if ((i & 1) == 0) {
+ GetFerry(i + 1)->m_bApproachingDock = true;
+ GetFerry(i + 1)->m_nTimeAlongPath += (mspInst->pPathData[i / 2]->aLineBits[j + 1].time - mspInst->pPathData[i / 2]->aLineBits[j].time);
+ }
+ else {
+ GetFerry(i - 1)->m_bApproachingDock = true;
+ GetFerry(i - 1)->m_nTimeAlongPath += (mspInst->pPathData[i / 2]->aLineBits[j + 1].time - mspInst->pPathData[i / 2]->aLineBits[j].time);
+ }
+ }
+ }
+ if (pFerry->m_nSkipFerryStatus == 1) {
+ float fDelta = 0.0f;
+ pFerry->m_nSkipFerryStatus = 2;
+ while (mspInst->pPathData[i / 2]->aLineBits[j].type != FERRY_STOPPED) {
+ fDelta += (mspInst->pPathData[i / 2]->aLineBits[j + 1].time - mspInst->pPathData[i / 2]->aLineBits[j].time);
+ j++;
+ if (j > NUM_FERRY_STATIONS * 4)
+ j = 0;
+ }
+ pFerry->m_nTimeAlongPath += fDelta;
+ pFerry->m_bApproachingDock = true;
+ if ((i & 1) == 0) {
+ GetFerry(i + 1)->m_bApproachingDock = true;
+ GetFerry(i + 1)->m_nTimeAlongPath += fDelta;
+ }
+ else {
+ GetFerry(i - 1)->m_bApproachingDock = true;
+ GetFerry(i - 1)->m_nTimeAlongPath += fDelta;
+ }
+ }
+ switch (mspInst->pPathData[i / 2]->aLineBits[j].type) {
+ case FERRY_STOPPED:
+ mspInst->m_afPositions[i] = mspInst->pPathData[i / 2]->aLineBits[j].position;
+ mspInst->m_afSpeeds[i] = 0.0f;
+ break;
+ case FERRY_CRUISING:
+ mspInst->m_afPositions[i] = mspInst->pPathData[i / 2]->aLineBits[j].position + mspInst->pPathData[i / 2]->aLineBits[j].speed * deltaT;
+ mspInst->m_afSpeeds[i] = (mspInst->pPathData[i / 2]->TotalDurationOfTrack * 1000.0f / 0x40000) * mspInst->pPathData[i / 2]->aLineBits[j].speed;
+ break;
+ case FERRY_SLOWING:
+ case FERRY_ACCELERATING:
+ pFerry->m_bApproachingDock = (mspInst->pPathData[i / 2]->aLineBits[j].type == FERRY_SLOWING);
+ mspInst->m_afPositions[i] = mspInst->pPathData[i / 2]->aLineBits[j].position + (mspInst->pPathData[i / 2]->aLineBits[j].speed + mspInst->pPathData[i / 2]->aLineBits[j].acceleration * deltaT) * deltaT;
+ mspInst->m_afSpeeds[i] = (mspInst->pPathData[i / 2]->TotalDurationOfTrack * 1000.0f / 0x40000) * (mspInst->pPathData[i / 2]->aLineBits[j].speed + 2 * mspInst->pPathData[i / 2]->aLineBits[j].acceleration * deltaT);
+ break;
+ }
+ }
+ }
+}
+
+void CFerry::SetModelIndex(uint32 mi)
+{
+ CVehicle::SetModelIndex(mi);
+ for (int i = 0; i < NUM_FERRY_NODES; i++)
+ m_aFerryNodes[i] = nil;
+ CClumpModelInfo::FillFrameArray(GetClump(), m_aFerryNodes);
+}
+
+void CFerry::PreRender(void)
+{
+ CVehicleModelInfo* mi = GetModelInfo();
+ if (CGeneral::GetRandomTrueFalse())
+ CParticle::AddParticle(PARTICLE_FERRY_CHIM_SMOKE, GetMatrix() * mi->m_positions[FERRY_POS_CHIM_LEFT], CVector(0.0f, 0.0f, 0.2f));
+ CVector vVectorToCamera = GetPosition() - TheCamera.GetPosition();
+ CVector vDirectionToCamera;
+ float fDistanceToCamera = vVectorToCamera.Magnitude();
+ if (fDistanceToCamera == 0.0f)
+ vVectorToCamera = vDirectionToCamera = CVector(1.0f, 0.0f, 0.0f);
+ else
+ vDirectionToCamera = vVectorToCamera / fDistanceToCamera;
+ float dp = DotProduct(GetForward(), vDirectionToCamera);
+ if (dp < 0.0f) {
+ CVector vFrontLightPosition = GetMatrix() * mi->m_positions[FERRY_POS_LIGHT_FRONT];
+ CVector vFrontLightPosition2 = vFrontLightPosition - 2 * mi->m_positions[FERRY_POS_LIGHT_FRONT].x * GetRight();
+ float size = -dp + 1.0f;
+ float fIntensity = -dp * 0.4f + 0.2f;
+ if (dp < -0.9f && fDistanceToCamera < 35.0f) {
+ uint8 intensity = fIntensity * 255.0f;
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 26, intensity, intensity, intensity, 255, vFrontLightPosition2, size, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 27, intensity, intensity, intensity, 255, vFrontLightPosition, size, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_HEADLIGHTS, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+ }
+ else {
+ uint8 intensity = fIntensity * 255.0f;
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 26, intensity, intensity, intensity, 255, vFrontLightPosition2, size, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 27, intensity, intensity, intensity, 255, vFrontLightPosition, size, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+ }
+ }
+ CVector vRearLightPosition = GetMatrix() * mi->m_positions[FERRY_POS_LIGHT_REAR];
+ CVector vRearLightPosition2 = vRearLightPosition - 2 * mi->m_positions[FERRY_POS_LIGHT_REAR].x * GetRight();
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 28, 255, 0, 0, 255, vRearLightPosition2, 1.0f, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+ CCoronas::RegisterCorona((uint32)(uintptr)this + 29, 255, 0, 0, 255, vRearLightPosition, 1.0f, 80.0f, CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f);
+}
+
+void CFerry::Render(void)
+{
+ m_bAlreadyRendered = true;
+ CEntity::Render();
+}
+
+void CFerry::RenderAllRemaning(void)
+{
+#ifdef GTA_NETWORK
+ if (gIsMultiplayerGame)
+ return;
+#endif
+ for (int i = 0; i < NUM_FERRIES; i++) {
+ CFerry* pFerry = GetFerry(i);
+ if (pFerry) {
+ if (!pFerry->m_bAlreadyRendered)
+ pFerry->Render();
+ pFerry->m_bAlreadyRendered = false;
+ }
+ }
+}
+
+void CFerry::FerryHitStuff(CPtrList& lst)
+{
+ for (CPtrNode* pNode = lst.first; pNode != nil; pNode = pNode->next) {
+ CPhysical* pEntity = (CPhysical*)pNode->item;
+ if (pEntity != this && Abs(GetPosition().x - pEntity->GetPosition().z) < 1.5f)
+ pEntity->bHitByTrain = true;
+ }
+}
+
+void CFerry::ProcessControl(void)
+{
+ if (gbModelViewer)
+ return;
+ PruneWakeTrail();
+ if (m_isFarAway && (m_nFerryId + CTimer::GetFrameCounter() & 0xF) != 0)
+ return;
+ CFerryPath* pPath = mspInst->pPathData[m_nFerryId / 2];
+ float fPosition = mspInst->m_afPositions[m_nFerryId];
+ float fSpeed = mspInst->m_afSpeeds[m_nFerryId];
+ if (fPosition < 0.0f)
+ fPosition += pPath->TotalLengthOfTrack;
+
+ CFerryNode* trackNodes = mspInst->pPathData[m_nFerryId / 2]->aTrackNodes;
+ int16 numTrackNodes = mspInst->pPathData[m_nFerryId / 2]->NumTrackNodes;
+ float totalLengthOfTrack = mspInst->pPathData[m_nFerryId / 2]->TotalLengthOfTrack;
+ float trackPosition = mspInst->m_afPositions[m_nFerryId];
+ float trackSpeed = mspInst->m_afSpeeds[m_nFerryId];
+
+ float trackPositionRear = trackPosition;
+ if (trackPositionRear < 0.0f)
+ trackPositionRear += totalLengthOfTrack;
+
+ // Advance current node to appropriate position
+ float pos1, pos2;
+ int nextTrackNode = m_nCurTrackNode + 1;
+ pos1 = trackNodes[m_nCurTrackNode].t;
+ if (nextTrackNode < numTrackNodes)
+ pos2 = trackNodes[nextTrackNode].t;
+ else {
+ nextTrackNode = 0;
+ pos2 = totalLengthOfTrack;
+ }
+ while (trackPositionRear < pos1 || trackPositionRear > pos2) {
+ m_nCurTrackNode = (m_nCurTrackNode + 1) % numTrackNodes;
+ nextTrackNode = m_nCurTrackNode + 1;
+ pos1 = trackNodes[m_nCurTrackNode].t;
+ if (nextTrackNode < numTrackNodes)
+ pos2 = trackNodes[nextTrackNode].t;
+ else {
+ nextTrackNode = 0;
+ pos2 = totalLengthOfTrack;
+ }
+ }
+ float dist = trackNodes[nextTrackNode].t - trackNodes[m_nCurTrackNode].t;
+ if (dist < 0.0f)
+ dist += totalLengthOfTrack;
+ float f = (trackPositionRear - trackNodes[m_nCurTrackNode].t) / dist;
+ CVector posRear = (1.0f - f) * CVector(trackNodes[m_nCurTrackNode].x, trackNodes[m_nCurTrackNode].y, trackNodes[m_nCurTrackNode].z) +
+ f * CVector(trackNodes[nextTrackNode].x, trackNodes[nextTrackNode].y, trackNodes[nextTrackNode].z);
+
+ // Now same again for the front
+ float trackPositionFront = trackPositionRear + 20.0f;
+ if (trackPositionFront > totalLengthOfTrack)
+ trackPositionFront -= totalLengthOfTrack;
+ int curTrackNodeFront = m_nCurTrackNode;
+ int nextTrackNodeFront = curTrackNodeFront + 1;
+ pos1 = trackNodes[curTrackNodeFront].t;
+ if (nextTrackNodeFront < numTrackNodes)
+ pos2 = trackNodes[nextTrackNodeFront].t;
+ else {
+ nextTrackNodeFront = 0;
+ pos2 = totalLengthOfTrack;
+ }
+ while (trackPositionFront < pos1 || trackPositionFront > pos2) {
+ curTrackNodeFront = (curTrackNodeFront + 1) % numTrackNodes;
+ nextTrackNodeFront = curTrackNodeFront + 1;
+ pos1 = trackNodes[curTrackNodeFront].t;
+ if (nextTrackNodeFront < numTrackNodes)
+ pos2 = trackNodes[nextTrackNodeFront].t;
+ else {
+ nextTrackNodeFront = 0;
+ pos2 = totalLengthOfTrack;
+ }
+ }
+ dist = trackNodes[nextTrackNodeFront].t - trackNodes[curTrackNodeFront].t;
+ if (dist < 0.0f)
+ dist += totalLengthOfTrack;
+ f = (trackPositionFront - trackNodes[curTrackNodeFront].t) / dist;
+ CVector posFront = (1.0f - f) * CVector(trackNodes[curTrackNodeFront].x, trackNodes[curTrackNodeFront].y, trackNodes[curTrackNodeFront].z) +
+ f * CVector(trackNodes[nextTrackNodeFront].x, trackNodes[nextTrackNodeFront].y, trackNodes[nextTrackNodeFront].z);
+
+ // Now set matrix
+ SetPosition((posRear + posFront) / 2.0f);
+ CVector fwd = posFront - posRear;
+ m_vecForwardSpeed = fwd;
+ fwd.Normalise();
+ float dp = DotProduct(fwd, GetForward());
+ if (Abs(dp) > 1.001f || Abs(dp) < 0.999f) {
+ CVector df = CrossProduct(fwd, GetForward());
+ CMatrix tmp;
+ float angle;
+ if (m_nSkipFerryStatus == 2) {
+ m_nSkipFerryStatus = 0;
+ angle = (fwd.x < 0.0f && GetForward().x < 0.0f) ? PI - Acos(dp) : Acos(dp);
+ }
+ else {
+ angle = 0.001f;
+ }
+ if (dp > 0.0f && df.z < 0.0f || dp <= 0.0f && df.z > 0.0f)
+ angle = -angle;
+ tmp.SetRotateZ(angle);
+ fwd = Multiply3x3(GetForward(), tmp);
+ }
+ else
+ fwd = GetForward();
+ CVector right = CrossProduct(fwd, CVector(0.0f, 0.0f, 1.0f));
+ right.Normalise();
+ CVector up = CrossProduct(right, fwd);
+ GetRight() = right;
+ GetUp() = up;
+ GetForward() = fwd;
+
+ // Set speed
+ m_vecMoveSpeed = fwd * trackSpeed / 60.0f;
+ m_fSpeed = trackSpeed / 60.0f;
+ m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
+
+ if (m_vecMoveSpeed.MagnitudeSqr() > 0.001f || !m_bApproachingDock) {
+ SetStatus(STATUS_FERRY_MOVING);
+ m_bFerryDocked = false;
+ m_bPlayerArrivedHorn = false;
+ m_nTimeLeftStation = CTimer::GetTimeInMilliseconds();
+ }
+ else {
+ SetStatus(STATUS_FERRY_NOT_MOVING);
+ PlayArrivedHorn();
+ m_bFerryDocked = true;
+ }
+
+ m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(1000.0f));
+
+ switch (m_nDoorState) {
+ case FERRY_DOOR_CLOSED:
+ break;
+ case FERRY_DOOR_OPENING:
+ if (CTimer::GetTimeInMilliseconds() < m_nDoorTimer) {
+ OpenFerryDoor(1.0f - (m_nDoorTimer - CTimer::GetTimeInMilliseconds()) / 1000.0f);
+ }
+ else {
+ OpenFerryDoor(1.0f);
+ m_nDoorState = FERRY_DOOR_OPEN;
+ }
+ break;
+
+ case FERRY_DOOR_OPEN:
+ break;
+
+ case FERRY_DOOR_CLOSING:
+ if (CTimer::GetTimeInMilliseconds() < m_nDoorTimer) {
+ OpenFerryDoor((m_nDoorTimer - CTimer::GetTimeInMilliseconds()) / 1000.0f);
+ }
+ else {
+ OpenFerryDoor(0.0f);
+ m_nDoorState = FERRY_DOOR_CLOSED;
+ }
+ break;
+ }
+
+ CVector wn = CWaterLevel::GetWaterNormal(GetPosition().x, GetPosition().y);
+ float fRollAngle = wn.x - GetUp().x;
+ if (fRollAngle < 0.0f)
+ fRollAngle = Max(-0.05f, fRollAngle);
+ else
+ fRollAngle = Min(0.05f, fRollAngle);
+
+ CVector oldPos = GetPosition();
+ SetPosition(-GetPosition());
+ CMatrix tmp2;
+ tmp2.SetRotateX(fRollAngle);
+ tmp2 = tmp2 * GetMatrix();
+ tmp2.SetTranslateOnly(oldPos);
+ GetMatrix() = tmp2;
+
+ GetMatrix().UpdateRW();
+ UpdateRwFrame();
+ RemoveAndAdd();
+
+ bIsStuck = false;
+ bIsInSafePosition = true;
+ bWasPostponed = false;
+
+ // request/remove model
+ if (m_isFarAway) {
+ if (m_rwObject)
+ DeleteRwObject();
+ }
+ else if (CStreaming::HasModelLoaded(MI_FERRY)) {
+ if (m_rwObject == nil) {
+ m_modelIndex = -1;
+ SetModelIndex(MI_FERRY);
+ }
+ }
+ else {
+ if (FindPlayerCoors().z * GetPosition().z >= 0.0f)
+ CStreaming::RequestModel(MI_FERRY, STREAMFLAGS_DEPENDENCY);
+ }
+
+ // Hit stuff
+ if (GetStatus() == STATUS_TRAIN_MOVING) {
+ CVector nfwd = GetForward() * GetColModel()->boundingBox.max.y;
+ if (m_vecForwardSpeed.x > 0.0f)
+ nfwd = -nfwd;
+ if ((m_nFerryId & 1) == 0)
+ nfwd = -nfwd;
+
+ int x, xmin, xmax;
+ int y, ymin, ymax;
+
+ CVector front = GetPosition() + nfwd + m_vecMoveSpeed * CTimer::GetTimeStep();
+ if (!m_isFarAway && m_vecMoveSpeed.Magnitude2D() > 0.05f)
+ AddWakePoint(nfwd * 0.85f + GetPosition());
+
+ xmin = CWorld::GetSectorIndexX(front.x - 3.0f);
+ if (xmin < 0) xmin = 0;
+ xmax = CWorld::GetSectorIndexX(front.x + 3.0f);
+ if (xmax > NUMSECTORS_X - 1) xmax = NUMSECTORS_X - 1;
+ ymin = CWorld::GetSectorIndexY(front.y - 3.0f);
+ if (ymin < 0) ymin = 0;
+ ymax = CWorld::GetSectorIndexY(front.y + 3.0f);
+ if (ymax > NUMSECTORS_Y - 1) ymax = NUMSECTORS_X - 1;
+
+ CWorld::AdvanceCurrentScanCode();
+
+ for (y = ymin; y <= ymax; y++)
+ for (x = xmin; x <= xmax; x++) {
+ CSector* s = CWorld::GetSector(x, y);
+ FerryHitStuff(s->m_lists[ENTITYLIST_VEHICLES]);
+ FerryHitStuff(s->m_lists[ENTITYLIST_VEHICLES_OVERLAP]);
+ FerryHitStuff(s->m_lists[ENTITYLIST_PEDS]);
+ FerryHitStuff(s->m_lists[ENTITYLIST_PEDS_OVERLAP]);
+ }
+ }
+}
+
+void CFerry::OpenFerryDoor(float ratio)
+{
+ if (!m_rwObject)
+ return;
+
+ int door1 = 0;
+ int door2 = 1;
+ if (!m_bUseFrontDoor) {
+ door1 = 2;
+ door2 = 3;
+ }
+ int node1 = m_bUseFrontDoor ? FERRY_DOOR_FRONT : FERRY_DOOR_BACK;
+ int node2 = m_bUseFrontDoor ? FERRY_RAMP_FRONT : FERRY_RAMP_BACK;
+ CMatrix doorL(RwFrameGetMatrix(m_aFerryNodes[node1]));
+ CMatrix doorR(RwFrameGetMatrix(m_aFerryNodes[node2]));
+ CVector posL = doorL.GetPosition();
+ CVector posR = doorR.GetPosition();
+
+ bool isClosed = m_doors[0].IsClosed(); // useless
+
+ m_doors[door1].Open(ratio);
+ m_doors[door2].Open(ratio);
+
+ doorL.SetRotateXOnly(m_doors[door1].m_fAngle);
+ doorR.SetRotateXOnly(m_doors[door2].m_fAngle);
+
+ doorL.UpdateRW();
+ doorR.UpdateRW();
+}
+
+CVector CFerry::GetBoardingSpace(CFerry::eSpaceUse use, CFerry::eSpaceStyle style, uint8 position)
+{
+ CVehicleModelInfo* pModelInfo = GetModelInfo();
+ CVector space;
+ if (m_nFerryId & 1) {
+ if (style == FERRY_SPACE_STYLE_0)
+ style = FERRY_SPACE_STYLE_1;
+ else
+ style = FERRY_SPACE_STYLE_0;
+ }
+ switch (use) {
+ case FERRY_SPACE_PED:
+ space = pModelInfo->m_positions[FERRY_POS_PED_POINT];
+ break;
+ case FERRY_SPACE_CAR:
+ space = pModelInfo->m_positions[FERRY_POS_CAR1 + position];
+ break;
+ }
+ switch (style) {
+ case FERRY_SPACE_STYLE_0:
+ space = GetMatrix() * space;
+ break;
+ case FERRY_SPACE_STYLE_1:
+ space = GetMatrix() * space - (2 * space.x) * GetRight() - (2 * space.y) * GetForward();
+ break;
+ }
+ return space;
+}
+
+CFerry* CFerry::GetClosestFerry(float x, float y)
+{
+ int closest = -1;
+ float mindist = 9999.9f;
+ for (int i = 0; i < NUM_FERRIES; i++) {
+ CFerry* pFerry = GetFerry(i);
+ if (pFerry) {
+ float dist = ((CVector2D)pFerry->GetPosition() - CVector2D(x, y)).Magnitude();
+ if (dist < 300.0f && dist < mindist) {
+ mindist = dist;
+ closest = i;
+ }
+ }
+ }
+ if (closest == -1)
+ return nil;
+ return GetFerry(closest);
+}
+
+bool CFerry::IsDocked(void)
+{
+ return m_bFerryDocked;
+}
+
+void CFerry::OpenDoor(void)
+{
+ printf("opening the ferry door\n");
+ m_nDoorState = FERRY_DOOR_OPENING;
+ m_nDoorTimer = CTimer::GetTimeInMilliseconds() + 10000;
+ CVehicleModelInfo* pModelInfo = GetModelInfo();
+ CVector2D vPlayerPos = FindPlayerPed()->GetPosition();
+ float fDistToCar4 = (vPlayerPos - GetMatrix() * pModelInfo->m_positions[FERRY_POS_CAR4]).Magnitude();
+ float fDistToCar1 = (vPlayerPos - GetMatrix() * pModelInfo->m_positions[FERRY_POS_CAR1]).Magnitude();
+ m_bUseFrontDoor = true;
+ if (fDistToCar4 < fDistToCar1)
+ m_bUseFrontDoor = false;
+ // AudioManager.DirectlyEnqueueSample(0xb8,0,0,1,0x5622,0x7f,0x14,0); // TODO
+}
+
+void CFerry::CloseDoor(void)
+{
+ printf("closing the ferry door\n");
+ m_nDoorState = FERRY_DOOR_CLOSING;
+ m_nDoorTimer = CTimer::GetTimeInMilliseconds() + 10000;
+ // AudioManager.DirectlyEnqueueSample(0xb8, 0, 0, 1, 0x5622, 0x7f, 0x14, 0); // TODO
+}
+
+bool CFerry::IsDoorOpen(void)
+{
+ return m_nDoorState == FERRY_DOOR_OPEN;
+}
+
+bool CFerry::IsDoorClosed(void)
+{
+ return m_nDoorState == FERRY_DOOR_CLOSED;
+}
+
+void CFerry::CompleteDorrMovement(void)
+{
+ m_nDoorTimer = 0;
+}
+
+void CFerry::DissableFerryPath(int)
+{
+}
+
+void CFerry::EnableFerryPath(int path)
+{
+ CStreaming::LoadAllRequestedModels(false);
+ CStreaming::RequestModel(MI_FERRY, 0);
+ CStreaming::LoadAllRequestedModels(false);
+ for (int i = path * 2; i < path * 2 + 2; i++) {
+ CFerry* pFerry = new CFerry(MI_FERRY, PERMANENT_VEHICLE);
+ bool bDirect = i & 1;
+ mspInst->m_apFerries[i] = pFerry;
+ pFerry->SetPosition(0.0f, 0.0f, 0.0f);
+ pFerry->SetStatus(STATUS_ABANDONED);
+ pFerry->bIsLocked = true;
+ pFerry->SetHeading(bDirect ? HALFPI : 3 * HALFPI);
+ pFerry->m_nFerryId = i;
+ pFerry->m_nCurTrackNode = 0;
+ CWorld::Add(pFerry);
+ }
+}
+
+void CFerry::SkipFerryToNextDock(void)
+{
+ m_nSkipFerryStatus = 1;
+}
+
+void CFerry::PruneWakeTrail(void)
+{
+ int16 num_remaining = 0;
+ for (int i = 0; i < NUM_WAKE_POINTS; i++) {
+ if (mspInst->m_afWakePointTimer[m_nFerryId][i] <= 0.0f)
+ break;
+ if (mspInst->m_afWakePointTimer[m_nFerryId][i] <= CTimer::GetTimeStep()) {
+ mspInst->m_afWakePointTimer[m_nFerryId][i] = 0.0f;
+ break;
+ }
+ mspInst->m_afWakePointTimer[m_nFerryId][i] -= CTimer::GetTimeStep();
+ num_remaining++;
+ }
+ mspInst->m_anNumWakePoints[m_nFerryId] = num_remaining;
+}
+
+void CFerry::AddWakePoint(CVector point)
+{
+ if (mspInst->m_afWakePointTimer[m_nFerryId][0] > 0.0f) {
+ int nNewWakePoints = Min(NUM_WAKE_POINTS - 1, mspInst->m_anNumWakePoints[m_nFerryId]);
+ for (int i = 0; i < nNewWakePoints; i++) {
+ mspInst->m_avWakePoints[m_nFerryId][i + 1] = mspInst->m_avWakePoints[m_nFerryId][i];
+ mspInst->m_afWakePointTimer[m_nFerryId][i + 1] = mspInst->m_afWakePointTimer[m_nFerryId][i];
+ }
+ }
+ mspInst->m_avWakePoints[m_nFerryId][0] = point;
+ mspInst->m_afWakePointTimer[m_nFerryId][0] = 900.0f; // TODO: define
+ mspInst->m_anNumWakePoints[m_nFerryId] += 1;
+}
+
+void CFerry::PlayArrivedHorn(void)
+{
+ if (m_bPlayerArrivedHorn)
+ return;
+ m_bPlayerArrivedHorn = true;
+ float fDistToCamera = (GetPosition() - TheCamera.GetPosition()).Magnitude();
+ if (fDistToCamera < 200.0f) {
+ uint8 volume = (200.0f - fDistToCamera) / 200.0f * 127;
+ // AudioManager.DirectlyEnqueueSample(0x32, 0, 0, 1, 18000, volume, 0x32, 0); // TODO
+ }
+}
+
+CVector CFerry::GetNearestDoor(CVector)
+{
+ return CVector(0.0f, 0.0f, 1.0f);
+}
+
+void CFerry::SetupForMultiplayer(void)
+{
+ for (int i = 0; i < NUM_FERRIES; i++)
+ mspInst->m_apFerries[i] = nil;
+ printf("setting up the ferrys for multiplayer\n");
+ CStreaming::SetModelIsDeletable(MI_FERRY);
+}
+
+void CFerry::Write(base::cRelocatableChunkWriter& writer)
+{
+ writer.AllocateRaw(mspInst, sizeof(*mspInst), 4);
+ if (!mspInst)
+ return;
+ for (int i = 0; i < NUM_FERRY_PATHS; i++) {
+ writer.AllocateRaw(mspInst->pPathData[i], sizeof(*mspInst->pPathData[i]), 4);
+ writer.AddPatch(&mspInst->pPathData[i]);
+ writer.AllocateRaw(mspInst->pPathData[i]->aTrackNodes, mspInst->pPathData[i]->NumTrackNodes * sizeof(CFerryNode), 4);
+ writer.AddPatch(&mspInst->pPathData[i]->aTrackNodes);
+ writer.AllocateRaw(mspInst->pPathData[i]->aLineBits, (NUM_FERRY_STATIONS * 4 + 2) * sizeof(CFerryInterpolationLine), 4);
+ writer.AddPatch(&mspInst->pPathData[i]->aTrackNodes);
+ }
+}
+
diff --git a/src/vehicles/Ferry.h b/src/vehicles/Ferry.h
new file mode 100644
index 00000000..f7936da9
--- /dev/null
+++ b/src/vehicles/Ferry.h
@@ -0,0 +1,143 @@
+#pragma once
+
+#include "Vehicle.h"
+#include "Door.h"
+
+enum eFerryNodes
+{
+ FERRY_DOOR_FRONT = 1,
+ FERRY_RAMP_FRONT,
+ FERRY_DOOR_BACK,
+ FERRY_RAMP_BACK,
+ NUM_FERRY_NODES
+};
+
+enum {
+ NUM_FERRY_STATIONS = 2,
+ NUM_FERRIES = NUM_FERRY_PATHS * 2,
+ NUM_WAKE_POINTS = 64
+};
+
+enum {
+ FERRY_STOPPED = 0,
+ FERRY_CRUISING,
+ FERRY_SLOWING,
+ FERRY_ACCELERATING
+};
+
+enum
+{
+ FERRY_DOOR_CLOSED = 0,
+ FERRY_DOOR_OPENING,
+ FERRY_DOOR_OPEN,
+ FERRY_DOOR_CLOSING
+};
+
+struct CFerryNode
+{
+ float x;
+ float y;
+ float z;
+ float t;
+};
+
+struct CFerryInterpolationLine
+{
+ uint8 type;
+ float time; // when does this keyframe start
+ // initial values at start of frame
+ float position;
+ float speed;
+ float acceleration;
+};
+
+struct CFerryPath
+{
+ float TotalLengthOfTrack;
+ float TotalDurationOfTrack;
+ int16 NumTrackNodes;
+ CFerryNode* aTrackNodes;
+ CFerryInterpolationLine* aLineBits;
+};
+
+class CFerry;
+
+class CFerryInst
+{
+public:
+ CFerryPath* pPathData[NUM_FERRY_PATHS];
+ float m_afPositions[NUM_FERRIES];
+ float m_afSpeeds[NUM_FERRIES];
+ CFerry* m_apFerries[NUM_FERRIES];
+ bool m_bFerriesDisabled;
+ uint16 m_anNumWakePoints[NUM_FERRIES];
+ CVector2D m_avWakePoints[NUM_FERRIES][NUM_WAKE_POINTS];
+ float m_afWakePointTimer[NUM_FERRIES][NUM_WAKE_POINTS];
+};
+
+class CFerry : public CVehicle
+{
+public:
+ int16 m_nFerryId;
+ uint16 m_isFarAway;
+ uint16 m_nCurTrackNode;
+ float m_fSpeed;
+ bool m_bFerryDocked;
+ uint32 m_nDoorTimer;
+ uint32 m_nTimeLeftStation;
+ int16 m_nDoorState;
+ bool m_bApproachingDock;
+ uint8 m_nSkipFerryStatus;
+ uint32 m_nTimeAlongPath;
+ bool m_bUseFrontDoor;
+ CVector m_vecForwardSpeed;
+ CColModel* m_pDefaultColModel;
+ uint8 m_nCollision;
+ CDoor m_doors[4];
+ RwFrame* m_aFerryNodes[NUM_FERRY_NODES];
+ bool m_bAlreadyRendered;
+ bool m_bPlayerArrivedHorn;
+
+ static CFerryInst* mspInst;
+
+ enum eSpaceUse {
+ FERRY_SPACE_PED = 0,
+ FERRY_SPACE_CAR
+ };
+ enum eSpaceStyle {
+ FERRY_SPACE_STYLE_0 = 0,
+ FERRY_SPACE_STYLE_1
+ };
+ void Render(void);
+ static void EnableFerryPath(int);
+ CFerry(int32, uint8);
+ void SetModelIndex(uint32);
+ static void InitFerrys(void);
+ static void Init(void*);
+ void ProcessControl(void);
+ void PlayArrivedHorn(void);
+ void AddWakePoint(CVector);
+ void PruneWakeTrail(void);
+ void SkipFerryToNextDock(void);
+ static void DissableFerryPath(int);
+ void CompleteDorrMovement(void);
+ bool IsDoorOpen(void);
+ void CloseDoor(void);
+ bool IsDocked(void);
+ static CFerry* GetClosestFerry(float, float);
+ CVector GetBoardingSpace(CFerry::eSpaceUse, CFerry::eSpaceStyle, uint8);
+ CVector GetNearestDoor(CVector);
+ void OpenFerryDoor(float);
+ void FerryHitStuff(CPtrList&);
+ static void RenderAllRemaning(void);
+ static void UpdateFerrys(void);
+ static void SwitchFerryCollision(int);
+ void SetupForMultiplayer(void);
+ void Write(base::cRelocatableChunkWriter&);
+ virtual void OpenDoor(void);
+ void PreRender(void);
+ virtual bool IsDoorClosed(void);
+
+ static CFerry* GetFerry(int i) { return mspInst ? mspInst->m_apFerries[i] : nil; }
+ static void SetFerriesDisabled(bool disabled) { mspInst->m_bFerriesDisabled = disabled; }
+};
diff --git a/src/vehicles/HandlingMgr.cpp b/src/vehicles/HandlingMgr.cpp
index 8438c5c9..b5dc7658 100644
--- a/src/vehicles/HandlingMgr.cpp
+++ b/src/vehicles/HandlingMgr.cpp
@@ -42,6 +42,7 @@ const char VehicleNames[NUMHANDLINGS][14] = {
"RHINO",
"BARRACKS",
"TRAIN",
+ "FERRY",
"HELI",
"DODO",
"COACH",
@@ -54,66 +55,40 @@ const char VehicleNames[NUMHANDLINGS][14] = {
"DEADDODO",
"FLATBED",
"YANKEE",
- "GOLFCART",
- "VOODOO",
- "WASHING",
- "CUBAN",
- "ROMERO",
- "PACKER",
- "ADMIRAL",
- "GANGBUR",
- "ZEBRA",
- "TOPFUN",
- "GLENDALE",
- "OCEANIC",
- "HERMES",
- "SABRE1",
- "SABRETUR",
- "PHEONIX",
- "WALTON",
- "REGINA",
- "COMET",
- "DELUXO",
- "BURRITO",
- "SPAND",
- "BAGGAGE",
- "KAUFMAN",
- "RANCHER",
- "FBIRANCH",
- "VIRGO",
- "GREENWOO",
- "HOTRING",
- "SANDKING",
- "BLISTAC",
- "BOXVILLE",
- "BENSON",
- "DESPERAD",
- "LOVEFIST",
- "BLOODRA",
- "BLOODRB",
+ "BLISTA",
+ "BELLYUP",
+ "MRWONGS",
+ "YARDIE",
+ "YAKUZA",
+ "DIABLOS",
+ "COLUMB",
+ "HOODS",
+ "PANLANT",
+ "BORGNINE",
+ "CAMPVAN",
+ "BALLOT",
+ "SPIDER",
+ "SHELBY",
+ "PONTIAC",
+ "ESPRIT",
+ "MINI",
+ "HOTROD",
+ "SINDACCO",
+ "FORELLI",
"BIKE",
"MOPED",
"DIRTBIKE",
"ANGEL",
+ "DIRTBIK2",
+ "ANGE2",
"FREEWAY",
"PREDATOR",
"SPEEDER",
"REEFER",
- "RIO",
- "SQUALO",
- "TROPIC",
- "COASTGRD",
- "DINGHY",
- "MARQUIS",
- "CUPBOAT",
- "SEAPLANE",
- "SPARROW",
- "SEASPAR",
"MAVERICK",
"COASTMAV",
"POLMAV",
"HUNTER",
- "RCBARON",
"RCGOBLIN",
"RCCOPTER"
};
@@ -138,18 +113,17 @@ void
cHandlingDataMgr::LoadHandlingData(void)
{
char *start, *end;
- char line[201]; // weird value
+ char line[300];
char delim[4]; // not sure
char *word;
int field, handlingId;
- int keepGoing;
tHandlingData *handling;
tFlyingHandlingData *flyingHandling;
tBoatHandlingData *boatHandling;
tBikeHandlingData *bikeHandling;
CFileMgr::SetDir("DATA");
- CFileMgr::LoadFile(HandlingFilename, work_buff, sizeof(work_buff), "r");
+ ssize_t filesz = CFileMgr::LoadFile(HandlingFilename, work_buff, sizeof(work_buff), "r");
CFileMgr::SetDir("");
start = (char*)work_buff;
@@ -158,21 +132,18 @@ cHandlingDataMgr::LoadHandlingData(void)
flyingHandling = nil;
boatHandling = nil;
bikeHandling = nil;
- keepGoing = 1;
- while(keepGoing){
+ while(start < (char*)&work_buff[filesz]){
// find end of line
while(*end != '\n') end++;
// get line
strncpy(line, start, end - start);
line[end - start] = '\0';
- start = end+1;
- end = start+1;
// yeah, this is kinda crappy
if(strcmp(line, ";the end") == 0)
- keepGoing = 0;
+ break;
else if(line[0] != ';'){
if(line[0] == '!'){
// Bike data
@@ -286,19 +257,19 @@ cHandlingDataMgr::LoadHandlingData(void)
handling->nIdentifier = (tVehicleType)handlingId;
break;
case 1: handling->fMass = atof(word); break;
- case 2: handling->Dimension.x = atof(word); break;
- case 3: handling->Dimension.y = atof(word); break;
- case 4: handling->Dimension.z = atof(word); break;
- case 5: handling->CentreOfMass.x = atof(word); break;
- case 6: handling->CentreOfMass.y = atof(word); break;
- case 7: handling->CentreOfMass.z = atof(word); break;
- case 8: handling->nPercentSubmerged = atoi(word); break;
- case 9: handling->fTractionMultiplier = atof(word); break;
- case 10: handling->fTractionLoss = atof(word); break;
- case 11: handling->fTractionBias = atof(word); break;
- case 12: handling->Transmission.nNumberOfGears = atoi(word); break;
- case 13: handling->Transmission.fMaxVelocity = atof(word); break;
- case 14: handling->Transmission.fEngineAcceleration = atof(word) * 0.4; break;
+ case 2: handling->fTurnMass = atof(word); break;
+ case 3: handling->fDragMult = atof(word); break;
+ case 4: handling->CentreOfMass.x = atof(word); break;
+ case 5: handling->CentreOfMass.y = atof(word); break;
+ case 6: handling->CentreOfMass.z = atof(word); break;
+ case 7: handling->nPercentSubmerged = atoi(word); break;
+ case 8: handling->fTractionMultiplier = atof(word); break;
+ case 9: handling->fTractionLoss = atof(word); break;
+ case 10: handling->fTractionBias = atof(word); break;
+ case 11: handling->Transmission.nNumberOfGears = atoi(word); break;
+ case 12: handling->Transmission.fMaxVelocity = atof(word); break;
+ case 13: handling->Transmission.fEngineAcceleration = atof(word) * 0.4; break;
+ case 14: handling->Transmission.fEngineInertia = atof(word); break;
case 15: handling->Transmission.nDriveType = word[0]; break;
case 16: handling->Transmission.nEngineType = word[0]; break;
case 17: handling->fBrakeDeceleration = atof(word); break;
@@ -307,25 +278,28 @@ cHandlingDataMgr::LoadHandlingData(void)
case 20: handling->fSteeringLock = atof(word); break;
case 21: handling->fSuspensionForceLevel = atof(word); break;
case 22: handling->fSuspensionDampingLevel = atof(word); break;
- case 23: handling->fSeatOffsetDistance = atof(word); break;
- case 24: handling->fCollisionDamageMultiplier = atof(word); break;
- case 25: handling->nMonetaryValue = atoi(word); break;
- case 26: handling->fSuspensionUpperLimit = atof(word); break;
- case 27: handling->fSuspensionLowerLimit = atof(word); break;
- case 28: handling->fSuspensionBias = atof(word); break;
- case 29: handling->fSuspensionAntidiveMultiplier = atof(word); break;
- case 30:
+ // case 23: // fSuspensionHighSpdComDamp unused
+ case 24: handling->fSuspensionUpperLimit = atof(word); break;
+ case 25: handling->fSuspensionLowerLimit = atof(word); break;
+ case 26: handling->fSuspensionBias = atof(word); break;
+ case 27: handling->fSuspensionAntidiveMultiplier = atof(word); break;
+ case 28: handling->fSeatOffsetDistance = atof(word); break;
+ case 29: handling->fCollisionDamageMultiplier = atof(word); break;
+ case 30: handling->nMonetaryValue = atoi(word); break;
+ case 31:
sscanf(word, "%x", &handling->Flags);
- handling->Transmission.Flags = handling->Flags;
+ // handling->Transmission.Flags = handling->Flags;
break;
- case 31: handling->FrontLights = atoi(word); break;
- case 32: handling->RearLights = atoi(word); break;
+ case 32: handling->FrontLights = atoi(word); break;
+ case 33: handling->RearLights = atoi(word); break;
}
field++;
}
ConvertDataToGameUnits(handling);
}
}
+ start = end+1;
+ end = start+1;
}
}
@@ -353,12 +327,9 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling)
handling->Transmission.fEngineAcceleration *= 1.0f/(50.0f*50.0f);
handling->Transmission.fMaxVelocity *= 1000.0f/(60.0f*60.0f * 50.0f);
handling->fBrakeDeceleration *= 1.0f/(50.0f*50.0f);
- handling->fTurnMass = (sq(handling->Dimension.x) + sq(handling->Dimension.y)) * handling->fMass / 12.0f;
- if(handling->fTurnMass < 10.0f)
- handling->fTurnMass *= 5.0f;
- handling->fInvMass = 1.0f/handling->fMass;
- handling->fCollisionDamageMultiplier *= 2000.0f/handling->fMass;
- handling->fBuoyancy = 100.0f/handling->nPercentSubmerged * GRAVITY*handling->fMass;
+ handling->fInvMass = 1.0f/handling->GetMass();
+ handling->fCollisionDamageMultiplier = handling->GetCollisionDamageMultiplier() * 2000.0f/handling->GetMass();
+ handling->fBuoyancy = 100.0f/handling->nPercentSubmerged * GRAVITY*handling->GetMass();
// Don't quite understand this. What seems to be going on is that
// we calculate a drag (air resistance) deceleration for a given velocity and
@@ -371,10 +342,13 @@ cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling)
velocity -= 0.01f;
// what's the 1/6?
a = handling->Transmission.fEngineAcceleration/6.0f;
- // no density or drag coefficient here...
- float a_drag = 0.5f*SQR(velocity) * handling->Dimension.x*handling->Dimension.z / handling->fMass;
- // can't make sense of this... maybe v - v/(drag + 1) ? but that doesn't make so much sense either
- b = -velocity * (1.0f/(a_drag + 1.0f) - 1.0f);
+ // no idea what's happening here
+ float drag;
+ if(handling->fDragMult < 0.01f)
+ drag = 1.0f - 1.0f/(SQR(velocity)*handling->fDragMult + 1.0f);
+ else
+ drag = 0.0005f*handling->fDragMult * velocity;
+ b = velocity * drag;
}
if(handling->nIdentifier == HANDLING_RCBANDIT){
@@ -420,15 +394,15 @@ cHandlingDataMgr::GetHandlingId(const char *name)
tFlyingHandlingData*
cHandlingDataMgr::GetFlyingPointer(uint8 id)
{
- if(id >= HANDLING_SEAPLANE && id <= HANDLING_RCCOPTER)
- return &FlyingHandlingData[id-HANDLING_SEAPLANE];
+ if(id >= HANDLING_MAVERICK && id <= HANDLING_RCCOPTER)
+ return &FlyingHandlingData[id-HANDLING_MAVERICK];
return &FlyingHandlingData[0];
}
tBoatHandlingData*
cHandlingDataMgr::GetBoatPointer(uint8 id)
{
- if(id >= HANDLING_PREDATOR && id <= HANDLING_SEAPLANE)
+ if(id >= HANDLING_PREDATOR && id <= HANDLING_MAVERICK)
return &BoatHandlingData[id-HANDLING_PREDATOR];
return &BoatHandlingData[0];
}
diff --git a/src/vehicles/HandlingMgr.h b/src/vehicles/HandlingMgr.h
index 8d290f7d..2d49761c 100644
--- a/src/vehicles/HandlingMgr.h
+++ b/src/vehicles/HandlingMgr.h
@@ -36,6 +36,7 @@ enum tVehicleType
HANDLING_RHINO,
HANDLING_BARRACKS,
HANDLING_TRAIN,
+ HANDLING_FERRY,
HANDLING_HELI,
HANDLING_DODO,
HANDLING_COACH,
@@ -48,76 +49,51 @@ enum tVehicleType
HANDLING_DEADDODO,
HANDLING_FLATBED,
HANDLING_YANKEE,
- HANDLING_GOLFCART,
- HANDLING_VOODOO,
- HANDLING_WASHING,
- HANDLING_CUBAN,
- HANDLING_ROMERO,
- HANDLING_PACKER,
- HANDLING_ADMIRAL,
- HANDLING_GANGBUR,
- HANDLING_ZEBRA,
- HANDLING_TOPFUN,
- HANDLING_GLENDALE,
- HANDLING_OCEANIC,
- HANDLING_HERMES,
- HANDLING_SABRE1,
- HANDLING_SABRETUR,
- HANDLING_PHEONIX,
- HANDLING_WALTON,
- HANDLING_REGINA,
- HANDLING_COMET,
- HANDLING_DELUXO,
- HANDLING_BURRITO,
- HANDLING_SPAND,
- HANDLING_BAGGAGE,
- HANDLING_KAUFMAN,
- HANDLING_RANCHER,
- HANDLING_FBIRANCH,
- HANDLING_VIRGO,
- HANDLING_GREENWOO,
- HANDLING_HOTRING,
- HANDLING_SANDKING,
- HANDLING_BLISTAC,
- HANDLING_BOXVILLE,
- HANDLING_BENSON,
- HANDLING_DESPERAD,
- HANDLING_LOVEFIST,
- HANDLING_BLOODRA,
- HANDLING_BLOODRB,
+ HANDLING_BLISTA,
+ HANDLING_BELLYUP,
+ HANDLING_MRWONGS,
+ HANDLING_YARDIE,
+ HANDLING_YAKUZA,
+ HANDLING_DIABLOS,
+ HANDLING_COLUMB,
+ HANDLING_HOODS,
+ HANDLING_PANLANT,
+ HANDLING_BORGNINE,
+ HANDLING_CAMPVAN,
+ HANDLING_BALLOT,
+ HANDLING_SPIDER,
+ HANDLING_SHELBY,
+ HANDLING_PONTIAC,
+ HANDLING_ESPRIT,
+ HANDLING_MINI,
+ HANDLING_HOTROD,
+ HANDLING_SINDACCO,
+ HANDLING_FORELLI,
HANDLING_BIKE,
HANDLING_MOPED,
HANDLING_DIRTBIKE,
HANDLING_ANGEL,
+ HANDLING_DIRTBIK2,
+ HANDLING_ANGE2,
HANDLING_FREEWAY,
HANDLING_PREDATOR,
HANDLING_SPEEDER,
HANDLING_REEFER,
- HANDLING_RIO,
- HANDLING_SQUALO,
- HANDLING_TROPIC,
- HANDLING_COASTGRD,
- HANDLING_DINGHY,
- HANDLING_MARQUIS,
- HANDLING_CUPBOAT,
- HANDLING_SEAPLANE, // both boat and plane!
- HANDLING_SPARROW,
- HANDLING_SEASPAR,
+
HANDLING_MAVERICK,
HANDLING_COASTMAV,
HANDLING_POLMAV,
HANDLING_HUNTER,
- HANDLING_RCBARON,
HANDLING_RCGOBLIN,
HANDLING_RCCOPTER,
NUMHANDLINGS,
NUMBIKEHANDLINGS = HANDLING_FREEWAY+1 - HANDLING_BIKE,
- NUMFLYINGHANDLINGS = HANDLING_RCCOPTER+1 - HANDLING_SEAPLANE,
- NUMBOATHANDLINGS = HANDLING_SEAPLANE+1 - HANDLING_PREDATOR,
+ NUMFLYINGHANDLINGS = HANDLING_RCCOPTER+1 - HANDLING_MAVERICK,
+ NUMBOATHANDLINGS = HANDLING_REEFER+1 - HANDLING_PREDATOR,
};
enum tField // most likely a handling field enum, never used so :shrug:
@@ -155,19 +131,21 @@ enum
HANDLING_NARROW_FRONTW = 0x2000000,
HANDLING_GOOD_INSAND = 0x4000000,
HANDLING_UNKNOWN = 0x8000000, // something for helis and planes
+ HANDLING_FORCE_GRND_CLR = 0x10000000
};
struct tHandlingData
{
- tVehicleType nIdentifier;
float fMass;
- float fInvMass;
float fTurnMass;
- CVector Dimension;
+ float fTractionMultiplier;
+ float fCollisionDamageMultiplier;
+ tVehicleType nIdentifier;
+ float fInvMass;
+ float fDragMult;
CVector CentreOfMass;
int8 nPercentSubmerged;
float fBuoyancy;
- float fTractionMultiplier;
cTransmission Transmission;
float fBrakeDeceleration;
float fBrakeBias;
@@ -182,12 +160,17 @@ struct tHandlingData
float fSuspensionLowerLimit;
float fSuspensionBias;
float fSuspensionAntidiveMultiplier;
- float fCollisionDamageMultiplier;
uint32 Flags;
float fSeatOffsetDistance;
int32 nMonetaryValue;
int8 FrontLights;
int8 RearLights;
+ int unk[4];
+
+ float GetMass(void) const { return fMass; }
+ float GetTurnMass(void) const { return fTurnMass; }
+ float GetTractionMultiplier(void) const { return fTractionMultiplier; }
+ float GetCollisionDamageMultiplier(void) const { return fCollisionDamageMultiplier; }
};
struct tBikeHandlingData
diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp
index f51c8481..a8423855 100644
--- a/src/vehicles/Heli.cpp
+++ b/src/vehicles/Heli.cpp
@@ -756,7 +756,7 @@ CHeli::InitHelis(void)
for(i = 0; i < NUM_HELIS; i++)
pHelis[i] = nil;
- ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&CTempColModels::ms_colModelPed1);
+ ((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&gpTempColModels->ms_colModelPed1);
}
CHeli*
diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp
index 0b40ca7e..7684d7dd 100644
--- a/src/vehicles/Plane.cpp
+++ b/src/vehicles/Plane.cpp
@@ -681,6 +681,12 @@ CPlane::Render(void)
CEntity::Render();
}
+void
+CPlane::RenderAllRemaning(void)
+{
+ // TODO(LCS)
+}
+
#define CRUISE_SPEED (50.0f)
#define TAXI_SPEED (5.0f)
diff --git a/src/vehicles/Plane.h b/src/vehicles/Plane.h
index c8f02048..ee65913b 100644
--- a/src/vehicles/Plane.h
+++ b/src/vehicles/Plane.h
@@ -59,6 +59,7 @@ public:
void Render(void);
void FlagToDestroyWhenNextProcessed() { bRemoveFromWorld = true; }
+ static void RenderAllRemaning(void);
static void InitPlanes(void);
static void Shutdown(void);
static CPlaneNode *LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool loop);
diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp
index 5f0cf36a..3c3d45d7 100644
--- a/src/vehicles/Train.cpp
+++ b/src/vehicles/Train.cpp
@@ -15,6 +15,10 @@
#include "Train.h"
#include "AudioScriptObject.h"
+#define TRAIN_SPEED (15.0f)
+#define TRAIN_SLOWDOWN_DISTANCE (40.0f)
+#define TRAIN_TIME_STOPPED_AT_STATION (25.0f)
+
static CTrainNode* pTrackNodes;
static int16 NumTrackNodes;
static float StationDist[3] = { 873.0f, 1522.0f, 2481.0f };
@@ -459,11 +463,11 @@ CTrain::InitTrains(void)
CStreaming::LoadAllRequestedModels(false);
// El-Train wagons
- float wagonPositions[] = { 0.0f, 20.0f, 40.0f, 0.0f, 20.0f };
- int8 firstWagon[] = { 1, 0, 0, 1, 0 };
- int8 lastWagon[] = { 0, 0, 1, 0, 1 };
- int16 wagonGroup[] = { 0, 0, 0, 1, 1 };
- for(i = 0; i < 5; i++){
+ float wagonPositions[] = { 0.0f, 20.0f, 0.0f, 20.0f };
+ int8 firstWagon[] = { 1, 0, 1, 0 };
+ int8 lastWagon[] = { 0, 1, 0, 1 };
+ int16 wagonGroup[] = { 0, 0, 1, 1 };
+ for(i = 0; i < 4; i++){
train = new CTrain(MI_TRAIN, PERMANENT_VEHICLE);
train->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
train->SetStatus(STATUS_ABANDONED);
@@ -598,23 +602,23 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
interpLines[j].type = 1;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
+ interpLines[j].speed = TRAIN_SPEED;
interpLines[j].acceleration = 0.0f;
j++;
// distance to next keyframe
- float dist = (stationDists[i]-40.0f) - position;
- time += dist/15.0f;
+ float dist = (stationDists[i]-TRAIN_SLOWDOWN_DISTANCE) - position;
+ time += dist/TRAIN_SPEED;
position += dist;
// Now slow down 40 units before stop
interpLines[j].type = 2;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
- interpLines[j].acceleration = -45.0f/32.0f;
+ interpLines[j].speed = TRAIN_SPEED;
+ interpLines[j].acceleration = -(TRAIN_SPEED * TRAIN_SPEED) / (4 * TRAIN_SLOWDOWN_DISTANCE);
j++;
- time += 80.0f/15.0f;
- position += 40.0f; // at station
+ time += 2*TRAIN_SLOWDOWN_DISTANCE/TRAIN_SPEED;
+ position += TRAIN_SLOWDOWN_DISTANCE; // at station
// stopping
interpLines[j].type = 0;
@@ -623,26 +627,26 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
interpLines[j].speed = 0.0f;
interpLines[j].acceleration = 0.0f;
j++;
- time += 25.0f;
+ time += TRAIN_TIME_STOPPED_AT_STATION;
// accelerate again
interpLines[j].type = 2;
interpLines[j].time = time;
interpLines[j].position = position;
interpLines[j].speed = 0.0f;
- interpLines[j].acceleration = 45.0f/32.0f;
+ interpLines[j].acceleration = (TRAIN_SPEED * TRAIN_SPEED) / (4 * TRAIN_SLOWDOWN_DISTANCE);
j++;
- time += 80.0f/15.0f;
- position += 40.0f; // after station
+ time += 2*TRAIN_SLOWDOWN_DISTANCE /TRAIN_SPEED;
+ position += TRAIN_SLOWDOWN_DISTANCE; // after station
}
// last keyframe
interpLines[j].type = 1;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
+ interpLines[j].speed = TRAIN_SPEED;
interpLines[j].acceleration = 0.0f;
j++;
- *totalDuration = time + (*totalLength - position)/15.0f;
+ *totalDuration = time + (*totalLength - position)/ TRAIN_SPEED;
// end
interpLines[j].time = *totalDuration;
@@ -650,52 +654,6 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
}
void
-PlayAnnouncement(uint8 sound, uint8 station)
-{
- // this was gone in a PC version but inlined on PS2
- cAudioScriptObject *obj = new cAudioScriptObject;
- obj->AudioId = sound;
- obj->Posn = CTrain::aStationCoors[station];
- obj->AudioEntity = AEHANDLE_NONE;
- DMAudio.CreateOneShotScriptObject(obj);
-}
-
-void
-ProcessTrainAnnouncements(void)
-{
-#ifdef GTA_TRAIN
- for (int i = 0; i < ARRAY_SIZE(StationDist); i++) {
- for (int j = 0; j < ARRAY_SIZE(EngineTrackPosition); j++) {
- if (!bTrainArrivalAnnounced[i]) {
- float preDist = StationDist[i] - 100.0f;
- if (preDist < 0.0f)
- preDist += TotalLengthOfTrack;
- if (EngineTrackPosition[j] > preDist && EngineTrackPosition[j] < StationDist[i]) {
- bTrainArrivalAnnounced[i] = true;
- PlayAnnouncement(SCRIPT_SOUND_TRAIN_ANNOUNCEMENT_1, i);
- break;
- }
- } else {
- float postDist = StationDist[i] + 10.0f;
-#ifdef FIX_BUGS
- if (postDist > TotalLengthOfTrack)
- postDist -= TotalLengthOfTrack;
-#else
- if (postDist < 0.0f) // does this even make sense here?
- postDist += TotalLengthOfTrack;
-#endif
- if (EngineTrackPosition[j] > StationDist[i] && EngineTrackPosition[j] < postDist) {
- bTrainArrivalAnnounced[i] = false;
- PlayAnnouncement(SCRIPT_SOUND_TRAIN_ANNOUNCEMENT_2, i);
- break;
- }
- }
- }
- }
-#endif
-}
-
-void
CTrain::UpdateTrains(void)
{
#ifdef GTA_TRAIN
@@ -732,8 +690,6 @@ CTrain::UpdateTrains(void)
// time offset for each train
time += 0x20000/2;
}
-
- ProcessTrainAnnouncements();
}
// Update Subway
diff --git a/src/vehicles/Transmission.cpp b/src/vehicles/Transmission.cpp
index 1aeabfe0..efc32079 100644
--- a/src/vehicles/Transmission.cpp
+++ b/src/vehicles/Transmission.cpp
@@ -4,6 +4,7 @@
#include "HandlingMgr.h"
#include "Transmission.h"
+//--LCS: file done
void
cTransmission::InitGearRatios(void)
{
@@ -14,11 +15,14 @@ cTransmission::InitGearRatios(void)
memset(Gears, 0, sizeof(Gears));
+ float baseVelocity = 0.5f*fMaxVelocity / nNumberOfGears;
+ float step = (fMaxVelocity - baseVelocity) / nNumberOfGears;
+
for(i = 1; i <= nNumberOfGears; i++){
pGearRatio0 = &Gears[i-1];
pGearRatio1 = &Gears[i];
- pGearRatio1->fMaxVelocity = (float)i / nNumberOfGears * fMaxVelocity;
+ pGearRatio1->fMaxVelocity = baseVelocity + i*step;
velocityDiff = pGearRatio1->fMaxVelocity - pGearRatio0->fMaxVelocity;
@@ -45,9 +49,12 @@ cTransmission::CalculateGearForSimpleCar(float speed, uint8 &gear)
pGearRatio = &Gears[gear];
fCurVelocity = speed;
- if(speed > pGearRatio->fShiftUpVelocity)
- gear++;
- else if(speed < pGearRatio->fShiftDownVelocity){
+ if(speed > pGearRatio->fShiftUpVelocity){
+ if(gear + 1 > nNumberOfGears)
+ gear = nNumberOfGears;
+ else
+ gear++;
+ }else if(speed < pGearRatio->fShiftDownVelocity){
if(gear - 1 < 0)
gear = 0;
else
@@ -55,6 +62,110 @@ cTransmission::CalculateGearForSimpleCar(float speed, uint8 &gear)
}
}
+float TRANSMISSION_NITROS_INERTIA_MULT = 0.5f;
+float TRANSMISSION_AI_CHEAT_INERTIA_MULT = 0.75f;
+float TRANSMISSION_NITROS_MULT = 2.0f;
+float TRANSMISSION_AI_CHEAT_MULT = 1.2f;
+float TRANSMISSION_SMOOTHER_FRAC = 0.85f;
+float TRANSMISSION_FREE_ACCELERATION = 0.1f;
+
+//--LCS: done
+float
+cTransmission::CalculateDriveAcceleration(const float &gasPedal, uint8 &gear, float &time, const float &velocity, float *inertiaVar1, float *inertiaVar2, uint8 nDriveWheels, uint8 cheat)
+{
+ static float fAcceleration = 0.0f;
+ static float fVelocity;
+ static float fCheat;
+ static tGear *pGearRatio;
+
+ fVelocity = velocity;
+ if(fVelocity < fMaxReverseVelocity)
+ return 0.0f;
+ if(fVelocity > fMaxVelocity)
+ return 0.0f;
+ fCurVelocity = fVelocity;
+
+ assert(gear <= nNumberOfGears);
+
+ pGearRatio = &Gears[gear];
+ if(fVelocity > pGearRatio->fShiftUpVelocity){
+ if(gear != 0 || gasPedal > 0.0f){
+ gear++;
+ return CalculateDriveAcceleration(gasPedal, gear, time, fVelocity, nil, nil, 0, false);
+ }
+ }else if(fVelocity < pGearRatio->fShiftDownVelocity && gear != 0){
+ if(gear != 1 || gasPedal < 0.0f){
+ gear--;
+ return CalculateDriveAcceleration(gasPedal, gear, time, fVelocity, nil, nil, 0, false);
+ }
+ }
+
+ float accelMul;
+
+ if(nNumberOfGears == 1){
+ accelMul = 1.0f;
+ }else if(gear == 0){
+ accelMul = 4.5f;
+ }else{
+ float f = 1.0f - (gear-1.0f)/(nNumberOfGears-1.0f);
+ if(Flags & HANDLING_1G_BOOST)
+ accelMul = SQR(f)*5.0f + 1.0f;
+ else if(Flags & HANDLING_2G_BOOST)
+ accelMul = SQR(f)*4.0f + 1.0f;
+ else
+ accelMul = SQR(f)*3.0f + 1.0f;
+ }
+
+ fCheat = 1.0f;
+ float nitroMult = 1.0f;
+ if(cheat == 1)
+ fCheat = TRANSMISSION_AI_CHEAT_MULT;
+ else if(cheat == 2)
+ nitroMult = TRANSMISSION_NITROS_MULT;
+
+ fAcceleration = fEngineAcceleration*CTimer::GetTimeStep()*0.4f*accelMul*gasPedal*fCheat*nitroMult;
+
+ if(inertiaVar1 != nil && inertiaVar2 != nil){
+ if(nDriveWheels == 0){
+ float f = TRANSMISSION_FREE_ACCELERATION*CTimer::GetTimeStep()*Abs(gasPedal)/fEngineInertia;
+ *inertiaVar1 = Min(*inertiaVar1 + f, 1.0f);
+ *inertiaVar2 = 0.1f;
+ }else{
+ float var1;
+ // What is being calculated here?
+ // TODO: find better names for the inertia vars
+ if(gear == 0){
+ var1 = ((fMaxVelocity/nNumberOfGears)*(1.0f-0.6667f) - fVelocity) /
+ ((fMaxVelocity/nNumberOfGears)*(1.0f-0.6667f) - Gears[gear].fShiftDownVelocity);
+ }else if(gear == 1){
+ var1 = ((fMaxVelocity/nNumberOfGears)*(1.0f-0.6667f) + fVelocity) /
+ ((fMaxVelocity/nNumberOfGears)*(1.0f-0.6667f) + Gears[gear].fShiftUpVelocity);
+ }else{
+ var1 = (fVelocity - Gears[gear].fShiftDownVelocity) /
+ (Gears[gear].fShiftUpVelocity - Gears[gear].fShiftDownVelocity);
+ }
+ float inertiaMult = var1 - *inertiaVar1;
+ if(cheat == 1)
+ inertiaMult *= TRANSMISSION_AI_CHEAT_INERTIA_MULT;
+ else if(cheat == 2)
+ inertiaMult *= TRANSMISSION_NITROS_INERTIA_MULT;
+ float var2target = 1.0f - inertiaMult*fEngineInertia;
+ var2target = Clamp(var2target, 0.1f, 1.0f);
+ *inertiaVar2 = (1.0f-TRANSMISSION_SMOOTHER_FRAC)*var2target + TRANSMISSION_SMOOTHER_FRAC*(*inertiaVar2);
+ *inertiaVar1 = var1;
+ fAcceleration *= *inertiaVar2;
+ }
+ }
+
+ float targetVelocity = Gears[gear].fMaxVelocity*fCheat;
+ if(Gears[gear].fMaxVelocity < 0.0f && targetVelocity > fVelocity)
+ fAcceleration *= 1.0f - Min((targetVelocity - fVelocity)/0.05f, 1.0f);
+ else if(Gears[gear].fMaxVelocity > 0.0f && targetVelocity < fVelocity)
+ fAcceleration *= 1.0f - Min((fVelocity - targetVelocity)/0.05f, 1.0f);
+ return fAcceleration;
+}
+
+// TEMP old VC code until we have bikes
float
cTransmission::CalculateDriveAcceleration(const float &gasPedal, uint8 &gear, float &time, const float &velocity, bool cheat)
{
diff --git a/src/vehicles/Transmission.h b/src/vehicles/Transmission.h
index a3d15513..8aea7b02 100644
--- a/src/vehicles/Transmission.h
+++ b/src/vehicles/Transmission.h
@@ -17,6 +17,7 @@ public:
int8 nNumberOfGears;
uint8 Flags;
float fEngineAcceleration;
+ float fEngineInertia;
float fMaxVelocity;
float fMaxCruiseVelocity;
float fMaxReverseVelocity;
@@ -24,5 +25,6 @@ public:
void InitGearRatios(void);
void CalculateGearForSimpleCar(float speed, uint8 &gear);
+ float CalculateDriveAcceleration(const float &gasPedal, uint8 &gear, float &time, const float &velocity, float *inertiaVar1, float *inertiaVar2, uint8 nDriveWheels, uint8 cheat);
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 d1054191..75a979f9 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -134,6 +134,7 @@ CVehicle::CVehicle(uint8 CreatedBy)
bCreatedAsPoliceVehicle = false;
bRestingOnPhysical = false;
bParking = false;
+ m_bGarageTurnedLightsOff = false;
bCanPark = CGeneral::GetRandomNumberInRange(0.0f, 1.0f) < 0.0f; // never true. probably doesn't work very well
bIsVan = false;
bIsBus = false;
@@ -218,8 +219,8 @@ void
CVehicle::SetModelIndex(uint32 id)
{
CEntity::SetModelIndex(id);
- m_aExtras[0] = CVehicleModelInfo::ms_compsUsed[0];
- m_aExtras[1] = CVehicleModelInfo::ms_compsUsed[1];
+ m_aExtras[0] = CVehicleModelInfo::mspInfo->ms_compsUsed[0];
+ m_aExtras[1] = CVehicleModelInfo::mspInfo->ms_compsUsed[1];
m_nNumMaxPassengers = CVehicleModelInfo::GetMaximumNumberOfPassengersFromNumberOfDoors(id);
}
@@ -772,7 +773,9 @@ CVehicle::BladeColSectorList(CPtrList &list, CColModel &rotorColModel, CMatrix &
}
-float fBurstSpeedMax = 0.3f;
+float WS_ALREADY_SPINNING_LOSS = 0.2f;
+float WS_TRAC_FRAC_LIMIT = 0.3f;
+float fBurstSpeedMax = 0.2f;
float fBurstTyreMod = 0.13f;
void
@@ -800,13 +803,15 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
float contactSpeedFwd = DotProduct(wheelContactSpeed, wheelFwd);
float contactSpeedRight = DotProduct(wheelContactSpeed, wheelRight);
- if(*wheelState != WHEEL_STATE_NORMAL)
+ adhesion *= CTimer::GetTimeStep();
+ if(*wheelState != WHEEL_STATE_NORMAL){
bAlreadySkidding = true;
+ adhesion *= pHandling->fTractionLoss;
+ if(*wheelState == WHEEL_STATE_SPINNING && (GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PLAYER_REMOTE))
+ adhesion *= 1.0f - Abs(m_fGasPedal) * WS_ALREADY_SPINNING_LOSS;
+ }
*wheelState = WHEEL_STATE_NORMAL;
- adhesion *= CTimer::GetTimeStep();
- if(bAlreadySkidding)
- adhesion *= pHandling->fTractionLoss;
// moving sideways
if(contactSpeedRight != 0.0f){
@@ -848,13 +853,15 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
if(!bBraking){
if(m_fGasPedal < 0.01f){
if(IsBike())
- brake = 0.6f * mod_HandlingManager.fWheelFriction / (pHandling->fMass + 200.0f);
- else if(pHandling->fMass < 500.0f)
- brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->fMass;
+ brake = 0.6f * mod_HandlingManager.fWheelFriction / (pHandling->GetMass() + 200.0f);
+ else if(IsPlane())
+ brake = 0.0f;
+ else if(pHandling->GetMass() < 500.0f)
+ brake = 0.1f * mod_HandlingManager.fWheelFriction / pHandling->GetMass();
else if(GetModelIndex() == MI_RCBANDIT)
- brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->fMass;
+ brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->GetMass();
else
- brake = mod_HandlingManager.fWheelFriction / pHandling->fMass;
+ brake = mod_HandlingManager.fWheelFriction / pHandling->GetMass();
#ifdef FIX_BUGS
brake *= CTimer::GetTimeStepFix();
#endif
@@ -878,7 +885,10 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
float speedSq = sq(right) + sq(fwd);
if(sq(adhesion) < speedSq){
if(*wheelState != WHEEL_STATE_FIXED){
- if(bDriving && contactSpeedFwd < 0.2f)
+ float tractionLimit = WS_TRAC_FRAC_LIMIT;
+ if(contactSpeedFwd > 0.15f && (wheelId == CARWHEEL_FRONT_LEFT || wheelId == CARWHEEL_FRONT_RIGHT))
+ tractionLimit *= 2.0f;
+ if(bDriving && tractionLimit*adhesion < Abs(fwd))
*wheelState = WHEEL_STATE_SPINNING;
else
*wheelState = WHEEL_STATE_SKIDDING;
@@ -886,6 +896,8 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
float l = Sqrt(speedSq);
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss;
+ if(*wheelState == WHEEL_STATE_SPINNING && (GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PLAYER_REMOTE))
+ tractionLoss *= 1.0f - Abs(m_fGasPedal) * WS_ALREADY_SPINNING_LOSS;
right *= adhesion * tractionLoss / l;
fwd *= adhesion * tractionLoss / l;
}
@@ -894,7 +906,7 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
CVector totalSpeed = fwd*wheelFwd + right*wheelRight;
CVector turnDirection = totalSpeed;
- bool separateTurnForce = false; // BUG: not initialized on PC
+ bool separateTurnForce = false;
if(pHandling->fSuspensionAntidiveMultiplier > 0.0f){
if(bBraking){
separateTurnForce = true;
@@ -931,6 +943,7 @@ float fBurstBikeSpeedMax = 0.12f;
float fBurstBikeTyreMod = 0.05f;
float fTweakBikeWheelTurnForce = 2.0f;
+//--LCS: done
void
CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
int32 wheelsOnGround, float thrust, float brake, float adhesion, float destabTraction, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus)
@@ -1850,8 +1863,7 @@ CVehicle::SetDriver(CPed *driver)
case MI_TAXI:
case MI_CABBIE:
- case MI_ZEBRA:
- case MI_KAUFMAN:
+ case MI_BORGNINE:
CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 12;
break;
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index b59b6b19..e0043ba1 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -240,16 +240,19 @@ public:
uint8 bRestingOnPhysical : 1; // Dont go static cause car is sitting on a physical object that might get removed
uint8 bParking : 1;
uint8 bCanPark : 1;
-#if (!defined GTA_PS2 || defined FIX_BUGS)
+#if (!defined GTA_PS2 || defined FIX_BUGS) // <- I think this can be moved back to CAutomobile?
uint8 m_bombType : 3;
#endif
uint8 bDriverLastFrame : 1;
+ uint8 bRewardVehicle : 1; // 25B_40
int8 m_numPedsUseItAsCover;
uint8 m_nAmmoInClip; // Used to make the guns on boat do a reload (20 by default)
int8 m_nPacManPickupsCarried;
uint8 m_nRoadblockType;
+ bool m_bGarageTurnedLightsOff;
float m_fHealth; // 1000.0f = full health. 250.0f = fire. 0 -> explode
+ float m_fEngineEnergy; // TODO(LCS): better name. it adds up acceleration force, so possibly kinetic energy??
uint8 m_nCurrentGear;
float m_fChangeGearTime;
#if (!defined GTA_PS2 || defined FIX_BUGS)
@@ -288,6 +291,7 @@ public:
~CVehicle(void);
// from CEntity
void SetModelIndex(uint32 id);
+ void PreRender(void) {}
bool SetupLighting(void);
void RemoveLighting(bool);
void FlagToDestroyWhenNextProcessed(void) {}
@@ -384,8 +388,8 @@ public:
bool IsAlarmOn(void) { return m_nAlarmState != 0 && m_nAlarmState != -1 && GetStatus() != STATUS_WRECKED; }
CVehicleModelInfo* GetModelInfo() { return (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); }
- bool IsTaxi(void) { return GetModelIndex() == MI_TAXI || GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_ZEBRA || GetModelIndex() == MI_KAUFMAN; }
- bool IsLimo(void) { return GetModelIndex() == MI_STRETCH || GetModelIndex() == MI_LOVEFIST; }
+ bool IsTaxi(void) { return GetModelIndex() == MI_TAXI || GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE; }
+ bool IsLimo(void) { return GetModelIndex() == MI_STRETCH; }
bool IsRealHeli(void) { return !!(pHandling->Flags & HANDLING_IS_HELI); }
bool IsRealPlane(void) { return !!(pHandling->Flags & HANDLING_IS_PLANE); }