diff options
Diffstat (limited to 'src/vehicles')
-rw-r--r-- | src/vehicles/Automobile.cpp | 194 | ||||
-rw-r--r-- | src/vehicles/Automobile.h | 8 | ||||
-rw-r--r-- | src/vehicles/Bike.cpp | 24 | ||||
-rw-r--r-- | src/vehicles/Boat.cpp | 15 | ||||
-rw-r--r-- | src/vehicles/Cranes.cpp | 6 | ||||
-rw-r--r-- | src/vehicles/Cranes.h | 8 | ||||
-rw-r--r-- | src/vehicles/HandlingMgr.cpp | 21 | ||||
-rw-r--r-- | src/vehicles/HandlingMgr.h | 26 | ||||
-rw-r--r-- | src/vehicles/Heli.cpp | 2 | ||||
-rw-r--r-- | src/vehicles/Plane.cpp | 7 | ||||
-rw-r--r-- | src/vehicles/Train.cpp | 2 | ||||
-rw-r--r-- | src/vehicles/Vehicle.cpp | 2 | ||||
-rw-r--r-- | src/vehicles/Vehicle.h | 15 |
13 files changed, 247 insertions, 83 deletions
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 8d95bcd9..8a771a40 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -48,6 +48,7 @@ #include "PlayerPed.h" #include "Object.h" #include "Automobile.h" +#include "Bike.h" //--MIAMI: file done @@ -99,8 +100,8 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy) break; } - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); - pFlyingHandling = mod_HandlingManager.GetFlyingPointer((eHandlingId)mi->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId); + pFlyingHandling = mod_HandlingManager.GetFlyingPointer((tVehicleType)mi->m_handlingId); m_auto_unused1 = 20.0f; m_auto_unused2 = 0; @@ -808,7 +809,7 @@ CAutomobile::ProcessControl(void) // dampen springs for(i = 0; i < 4; i++) - if(m_aSuspensionSpringRatio[i] < 1.0f) + if(m_aSuspensionSpringRatio[i] < 0.99999f) ApplySpringDampening(pHandling->fSuspensionDampingLevel, springDirections[i], contactPoints[i], contactSpeeds[i]); @@ -849,7 +850,7 @@ CAutomobile::ProcessControl(void) 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*(1.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; @@ -937,7 +938,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB); WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT]; - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], m_nWheelsOnGround, fThrust, @@ -980,7 +981,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB); WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT]; - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], m_nWheelsOnGround, fThrust, @@ -1041,7 +1042,7 @@ CAutomobile::ProcessControl(void) if(m_aWheelTimer[CARWHEEL_REAR_LEFT] > 0.0f || m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ CVector wheelFwd = GetForward(); - CVector wheelRight = GetRight(); + CVector wheelRight = GetRight(); // overwritten for resp. wheel float rearBrake = brake; float rearTraction = traction; @@ -1072,7 +1073,6 @@ CAutomobile::ProcessControl(void) else fThrust = acceleration; - wheelFwd = GetForward(); 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); @@ -1084,7 +1084,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB); WheelState[CARWHEEL_REAR_LEFT] = m_aWheelState[CARWHEEL_REAR_LEFT]; - if(Damage.GetWheelStatus(VEHWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_REAR_LEFT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_REAR_LEFT], contactPoints[CARWHEEL_REAR_LEFT], m_nWheelsOnGround, fThrust, @@ -1109,7 +1109,7 @@ CAutomobile::ProcessControl(void) #ifdef FIX_BUGS // Shouldn't we reset these after the left wheel? wheelFwd = GetForward(); - wheelRight = GetRight(); + wheelRight = GetRight(); // actually useless #endif if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] > 0.0f){ @@ -1118,7 +1118,6 @@ CAutomobile::ProcessControl(void) else fThrust = acceleration; - wheelFwd = GetForward(); 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); @@ -1130,7 +1129,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB); WheelState[CARWHEEL_REAR_RIGHT] = m_aWheelState[CARWHEEL_REAR_RIGHT]; - if(Damage.GetWheelStatus(VEHWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_REAR_RIGHT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_REAR_RIGHT], contactPoints[CARWHEEL_REAR_RIGHT], m_nWheelsOnGround, fThrust, @@ -1166,7 +1165,9 @@ CAutomobile::ProcessControl(void) if(!IsRealHeli()){ if(m_aWheelTimer[CARWHEEL_REAR_LEFT] <= 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + if(bIsHandbrakeOn) + m_aWheelSpeed[CARWHEEL_REAR_LEFT] = 0.0f; + else if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) m_aWheelSpeed[CARWHEEL_REAR_LEFT] *= 0.95f; else{ if(acceleration > 0.0f){ @@ -1180,7 +1181,9 @@ CAutomobile::ProcessControl(void) m_aWheelRotation[CARWHEEL_REAR_LEFT] += m_aWheelSpeed[CARWHEEL_REAR_LEFT]; } if(m_aWheelTimer[CARWHEEL_REAR_RIGHT] <= 0.0f){ - if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) + if(bIsHandbrakeOn) + m_aWheelSpeed[CARWHEEL_REAR_RIGHT] = 0.0f; + else if(mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) || acceleration == 0.0f) m_aWheelSpeed[CARWHEEL_REAR_RIGHT] *= 0.95f; else{ if(acceleration > 0.0f){ @@ -1225,7 +1228,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB); WheelState[CARWHEEL_FRONT_LEFT] = m_aWheelState[CARWHEEL_FRONT_LEFT]; - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_FRONT_LEFT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_FRONT_LEFT], contactPoints[CARWHEEL_FRONT_LEFT], m_nWheelsOnGround, fThrust, @@ -1268,7 +1271,7 @@ CAutomobile::ProcessControl(void) adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB); WheelState[CARWHEEL_FRONT_RIGHT] = m_aWheelState[CARWHEEL_FRONT_RIGHT]; - if(Damage.GetWheelStatus(VEHWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) + if(Damage.GetWheelStatus(CARWHEEL_FRONT_RIGHT) == WHEEL_STATUS_BURST) ProcessWheel(wheelFwd, wheelRight, contactSpeeds[CARWHEEL_FRONT_RIGHT], contactPoints[CARWHEEL_FRONT_RIGHT], m_nWheelsOnGround, fThrust, @@ -1719,11 +1722,11 @@ CAutomobile::PreRender(void) int i, j, n; CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); - if(GetModelIndex() == MI_RHINO && m_aCarNodes[CAR_BONNET]){ + if(GetModelIndex() == MI_RHINO && m_aCarNodes[CAR_WINDSCREEN]){ // Rotate Rhino turret CMatrix m; CVector p; - m.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BONNET])); + m.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WINDSCREEN])); p = m.GetPosition(); m.SetRotateZ(m_fCarGunLR); m.Translate(p); @@ -3187,7 +3190,11 @@ CAutomobile::ProcessControlInputs(uint8 pad) // Brake if player isn't in control // BUG: game always uses pad 0 here +#ifdef FIX_BUGS if(CPad::GetPad(pad)->ArePlayerControlsDisabled()){ +#else + if(CPad::GetPad(0)->ArePlayerControlsDisabled()){ +#endif m_fBrakePedal = 1.0f; bIsHandbrakeOn = true; m_fGasPedal = 0.0f; @@ -3205,7 +3212,7 @@ void CAutomobile::FireTruckControl(void) { if(this == FindPlayerVehicle()){ - if(!CPad::GetPad(0)->GetWeapon()) + if(!CPad::GetPad(0)->GetCarGunFired()) return; #ifdef FREE_CAM if (!CCamera::bFreeCam) @@ -3834,7 +3841,7 @@ CAutomobile::DoDriveByShootings(void) return; CWeapon *weapon = pDriver->GetWeapon(); - if(CWeaponInfo::GetWeaponInfo(weapon->m_eWeaponType)->m_nWeaponSlot != 5) + if(CWeaponInfo::GetWeaponInfo(weapon->m_eWeaponType)->m_nWeaponSlot != WEAPONSLOT_SUBMACHINEGUN) return; weapon->Update(pDriver->m_audioEntityId, nil); @@ -4861,10 +4868,10 @@ CAutomobile::BurstTyre(uint8 wheel, bool applyForces) return; switch(wheel){ - case CAR_PIECE_WHEEL_LF: wheel = VEHWHEEL_FRONT_LEFT; break; - case CAR_PIECE_WHEEL_LR: wheel = VEHWHEEL_REAR_LEFT; break; - case CAR_PIECE_WHEEL_RF: wheel = VEHWHEEL_FRONT_RIGHT; break; - case CAR_PIECE_WHEEL_RR: wheel = VEHWHEEL_REAR_RIGHT; break; + case CAR_PIECE_WHEEL_LF: wheel = CARWHEEL_FRONT_LEFT; break; + case CAR_PIECE_WHEEL_RF: wheel = CARWHEEL_FRONT_RIGHT; break; + case CAR_PIECE_WHEEL_LR: wheel = CARWHEEL_REAR_LEFT; break; + case CAR_PIECE_WHEEL_RR: wheel = CARWHEEL_REAR_RIGHT; break; } int status = Damage.GetWheelStatus(wheel); @@ -5073,7 +5080,7 @@ CAutomobile::BlowUpCarsInPath(void) m_aCollisionRecords[i]->GetModelIndex() != MI_RHINO && !m_aCollisionRecords[i]->bRenderScorched){ if(this == FindPlayerVehicle()) - CEventList::RegisterEvent(EVENT_EXPLOSION, EVENT_ENTITY_VEHICLE, this, FindPlayerPed(), 2000); + CEventList::RegisterEvent(EVENT_EXPLOSION, EVENT_ENTITY_VEHICLE, m_aCollisionRecords[i], FindPlayerPed(), 2000); ((CVehicle*)m_aCollisionRecords[i])->BlowUpCar(this); } } @@ -5109,6 +5116,141 @@ CAutomobile::HasCarStoppedBecauseOfLight(void) return false; } +// --MIAMI: Done +void +CPed::DeadPedMakesTyresBloody(void) +{ + int minX = CWorld::GetSectorIndexX(GetPosition().x - 2.0f); + if (minX < 0) minX = 0; + int minY = CWorld::GetSectorIndexY(GetPosition().y - 2.0f); + if (minY < 0) minY = 0; + int maxX = CWorld::GetSectorIndexX(GetPosition().x + 2.0f); + if (maxX > NUMSECTORS_X-1) maxX = NUMSECTORS_X-1; + int maxY = CWorld::GetSectorIndexY(GetPosition().y + 2.0f); + if (maxY > NUMSECTORS_Y-1) maxY = NUMSECTORS_Y-1; + + CWorld::AdvanceCurrentScanCode(); + + for (int curY = minY; curY <= maxY; curY++) { + for (int curX = minX; curX <= maxX; curX++) { + CSector *sector = CWorld::GetSector(curX, curY); + MakeTyresMuddySectorList(sector->m_lists[ENTITYLIST_VEHICLES]); + MakeTyresMuddySectorList(sector->m_lists[ENTITYLIST_VEHICLES_OVERLAP]); + } + } +} + +// --MIAMI: Done +void +CPed::MakeTyresMuddySectorList(CPtrList &list) +{ + CAutomobile *car = nil; + CBike *bike = nil; + for (CPtrNode *node = list.first; node; node = node->next) { + CVehicle *veh = (CVehicle*)node->item; + if (veh->m_scanCode != CWorld::GetCurrentScanCode()) { + veh->m_scanCode = CWorld::GetCurrentScanCode(); + + if (Abs(GetPosition().x - veh->GetPosition().x) < 10.0f && Abs(GetPosition().y - veh->GetPosition().y) < 10.0f) { + if (veh->IsCar()) { + bike = nil; + car = (CAutomobile*)veh; + } else if (veh->IsBike()) { + bike = (CBike*)veh; + car = nil; + } + if (veh->m_vecMoveSpeed.MagnitudeSqr2D() > 0.05f) { + if (car) { + for (int wheel = 0; wheel < 4; wheel++) { + if (!car->m_aWheelSkidmarkBloody[wheel] && car->m_aSuspensionSpringRatio[wheel] < 1.0f) { + + CColModel* vehCol = car->GetModelInfo()->GetColModel(); + CVector approxWheelOffset; + switch (wheel) { + case 0: + approxWheelOffset = CVector(-vehCol->boundingBox.max.x, vehCol->boundingBox.max.y, 0.0f); + break; + case 1: + approxWheelOffset = CVector(-vehCol->boundingBox.max.x, vehCol->boundingBox.min.y, 0.0f); + break; + case 2: + approxWheelOffset = CVector(vehCol->boundingBox.max.x, vehCol->boundingBox.max.y, 0.0f); + break; + case 3: + approxWheelOffset = CVector(vehCol->boundingBox.max.x, vehCol->boundingBox.min.y, 0.0f); + break; + default: + break; + } + + // I hope so + CVector wheelPos = car->GetMatrix() * approxWheelOffset; + if (Abs(wheelPos.z - GetPosition().z) < 2.0f) { + + if ((wheelPos - GetPosition()).MagnitudeSqr2D() < 1.0f) { + if (CGame::nastyGame) { + car->m_aWheelSkidmarkBloody[wheel] = true; + DMAudio.PlayOneShot(car->m_audioEntityId, SOUND_SPLATTER, 0.0f); + } + if (car->m_fMass > 500.f) { + car->ApplyMoveForce(CVector(0.0f, 0.0f, 50.0f * Min(1.0f, m_fMass * 0.001f))); + + CVector vehAndWheelDist = wheelPos - car->GetPosition(); + car->ApplyTurnForce(CVector(0.0f, 0.0f, 50.0f * Min(1.0f, m_fTurnMass * 0.0005f)), vehAndWheelDist); + if (car == FindPlayerVehicle()) { + CPad::GetPad(0)->StartShake(300, 70); + } + } + } + } + } + } + } else if (bike) { + for (int wheel = 0; wheel < 2; wheel++) { + if (!bike->m_aWheelSkidmarkBloody[wheel] && bike->m_aSuspensionSpringRatio[wheel] < 1.0f) { + + CColModel* vehCol = bike->GetModelInfo()->GetColModel(); + CVector approxWheelOffset; + switch (wheel) { + case 0: + approxWheelOffset = CVector(0.0f, 0.8f * vehCol->boundingBox.max.y, 0.0f); + break; + case 1: + approxWheelOffset = CVector(0.0f, 0.8f * vehCol->boundingBox.min.y, 0.0f); + default: + break; + } + + // I hope so + CVector wheelPos = bike->GetMatrix() * approxWheelOffset; + if (Abs(wheelPos.z - GetPosition().z) < 2.0f) { + + if ((wheelPos - GetPosition()).MagnitudeSqr2D() < 1.0f) { + if (CGame::nastyGame) { + bike->m_aWheelSkidmarkBloody[wheel] = true; + DMAudio.PlayOneShot(bike->m_audioEntityId, SOUND_SPLATTER, 0.0f); + } + if (bike->m_fMass > 100.0f) { + bike->ApplyMoveForce(CVector(0.0f, 0.0f, 10.0f)); + + CVector vehAndWheelDist = wheelPos - bike->GetPosition(); + bike->ApplyTurnForce(CVector(0.0f, 0.0f, 10.0f), vehAndWheelDist); + + if (bike == FindPlayerVehicle()) { + CPad::GetPad(0)->StartShake(300, 70); + } + } + } + } + } + } + } + } + } + } + } +} + void CAutomobile::SetBusDoorTimer(uint32 timer, uint8 type) { @@ -5627,7 +5769,7 @@ CAutomobile::PopBoot(void) case DOOR_STATUS_OK: case DOOR_STATUS_SMASHED: Doors[DOOR_BOOT].m_fAngle = Doors[DOOR_BOOT].m_fMinAngle; - CMatrix mat(RwFrameGetMatrix(m_aCarNodes[DOOR_BOOT])); + CMatrix mat(RwFrameGetMatrix(m_aCarNodes[CAR_BOOT])); CVector pos = mat.GetPosition(); float axes[3] = { 0.0f, 0.0f, 0.0f }; axes[Doors[DOOR_BOOT].m_nAxis] = Doors[DOOR_BOOT].m_fAngle; diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h index b2f0643c..16d86917 100644 --- a/src/vehicles/Automobile.h +++ b/src/vehicles/Automobile.h @@ -7,8 +7,6 @@ class CObject; -// These are used for all the wheel arrays -// DON'T confuse with VEHWHEEL, which are vehicle components enum { CARWHEEL_FRONT_LEFT, CARWHEEL_REAR_LEFT, @@ -35,6 +33,9 @@ public: float m_aWheelPosition[4]; float m_aWheelSpeed[4]; uint8 m_auto_unused2; +#if (defined GTA_PS2 && !defined FIX_BUGS) + uint8 m_bombType : 3; +#endif uint8 bTaxiLight : 1; uint8 bFixedColour : 1; uint8 bBigWheels : 1; @@ -44,6 +45,9 @@ public: uint8 bTankDetonateCars : 1; uint8 bStuckInSand : 1; uint8 bHeliDestroyed : 1; +#if (defined GTA_PS2 && !defined FIX_BUGS) + CEntity* m_pBombRigger; +#endif int16 m_doingBurnout; uint16 m_hydraulicState; uint32 m_nBusDoorTimerEnd; diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index 62633464..0cfbedc1 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -93,9 +93,9 @@ CBike::CBike(int32 id, uint8 CreatedBy) SetModelIndex(id); - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); - pBikeHandling = mod_HandlingManager.GetBikePointer((eHandlingId)mi->m_handlingId); - pFlyingHandling = mod_HandlingManager.GetFlyingPointer((eHandlingId)mi->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId); + pBikeHandling = mod_HandlingManager.GetBikePointer((tVehicleType)mi->m_handlingId); + pFlyingHandling = mod_HandlingManager.GetFlyingPointer((tVehicleType)mi->m_handlingId); m_bike_unused1 = 20.0f; m_bike_unused2 = 0; @@ -202,9 +202,11 @@ CVector vecTestResistance(0.9995f, 0.9f, 0.95f); float fDAxisX = 1.0f; float fDAxisXExtra = 100.0f; float fDAxisY = 1000.0f; -float fInAirXRes = 0.88f; +float fInAirXRes = 0.98f; float fFlySpeedMult = -0.6f; +#pragma optimize("", off) // a workaround for another compiler bug =P, original had optimize off for this function too though + void CBike::ProcessControl(void) { @@ -476,7 +478,7 @@ CBike::ProcessControl(void) if(m_vecMoveSpeedAvg.MagnitudeSqr() <= sq(moveSpeedLimit*CTimer::GetTimeStep()) && m_vecTurnSpeedAvg.MagnitudeSqr() <= sq(turnSpeedLimit*CTimer::GetTimeStep()) && - m_fDistanceTravelled < distanceLimit && + m_fDistanceTravelled < distanceLimit || makeStatic){ m_nStaticFrames++; @@ -1144,7 +1146,12 @@ CBike::ProcessControl(void) float suspChange = m_aSuspensionSpringRatioPrev[i] - m_aSuspensionSpringRatio[i]; if(suspChange > 0.3f && (i == BIKESUSP_F1 || i == BIKESUSP_R1) && speedsq > 0.04f){ if(GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PHYSICS){ +#ifdef FIX_BUGS + // only two wheels but 4 suspensions + if(m_wheelStatus[i/2] == WHEEL_STATUS_BURST) +#else if(m_wheelStatus[i] == WHEEL_STATUS_BURST) +#endif DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP_2, suspChange); else DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, suspChange); @@ -1213,7 +1220,8 @@ CBike::ProcessControl(void) // Balance bike if(bBalancedByRider || bIsBeingPickedUp || bIsStanding){ - float onSideness = clamp(DotProduct(GetRight(), m_vecAvgSurfaceNormal), -1.0f, 1.0f); + float onSideness = DotProduct(GetRight(), m_vecAvgSurfaceNormal); + onSideness = clamp(onSideness, -1.0f, 1.0f); CVector worldCOM = Multiply3x3(GetMatrix(), m_vecCentreOfMass); // Keep bike upright if(bBalancedByRider){ @@ -1256,6 +1264,8 @@ CBike::ProcessControl(void) } } +#pragma optimize("", on) + void CBike::Teleport(CVector pos) { @@ -1596,7 +1606,7 @@ CBike::PreRender(void) CVector forkAxis(0.0f, Sin(DEGTORAD(mi->m_bikeSteerAngle)), -Cos(DEGTORAD(mi->m_bikeSteerAngle))); forkAxis.Normalise(); // as if that's not already the case CQuaternion quat; - quat.Set((RwV3d*)&forkAxis, -m_fWheelAngle); + quat.Set(&forkAxis, -m_fWheelAngle); quat.Get(rot.m_attachment); rot.Update(); diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index 7fea8c6e..695d380f 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -26,6 +26,7 @@ #include "AnimBlendAssociation.h" #include "RpAnimBlend.h" #include "Record.h" +#include "Shadows.h" //--MIAMI: file done @@ -63,9 +64,9 @@ CBoat::CBoat(int mi, uint8 owner) : CVehicle(owner) m_nPoliceShoutTimer = CTimer::GetTimeInMilliseconds(); SetModelIndex(mi); - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)minfo->m_handlingId); - pFlyingHandling = mod_HandlingManager.GetFlyingPointer((eHandlingId)minfo->m_handlingId); - pBoatHandling = mod_HandlingManager.GetBoatPointer((eHandlingId)minfo->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)minfo->m_handlingId); + pFlyingHandling = mod_HandlingManager.GetFlyingPointer((tVehicleType)minfo->m_handlingId); + pBoatHandling = mod_HandlingManager.GetBoatPointer((tVehicleType)minfo->m_handlingId); minfo->ChooseVehicleColour(m_currentColour1, m_currentColour2); m_fMass = pHandling->fMass; @@ -442,7 +443,7 @@ CBoat::ProcessControl(void) CVector wakePos = GetPosition() + sternPos; // no actual particles for player... }else if(IsVisible() && ((CTimer::GetFrameCounter() + m_randomSeed) & 1) && - CVisibilityPlugins::GetDistanceSquaredFromCamera((RwV3d*)&propellerWorld) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ + CVisibilityPlugins::GetDistanceSquaredFromCamera(&propellerWorld) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ jetDir.z = 0.015f; jetDir.x *= 3.5f; jetDir.y *= 3.5f; @@ -612,7 +613,7 @@ CBoat::ProcessControl(void) splashDir.z += 0.0003f*m_nDeltaVolumeUnderWater; CWaterLevel::GetWaterLevel(splashPos, &waterLevel, true); if(splashPos.z-waterLevel < 3.0f && - CVisibilityPlugins::GetDistanceSquaredFromCamera((RwV3d*)&splashPos) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ + CVisibilityPlugins::GetDistanceSquaredFromCamera(&splashPos) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ splashPos.z = waterLevel + 0.1f; CParticle::AddParticle(PARTICLE_CAR_SPLASH, splashPos, 0.75f*splashDir, nil, splashSize+0.1f, splashColor, CGeneral::GetRandomNumberInRange(0.0f, 10.0f), CGeneral::GetRandomNumberInRange(0.0f, 90.0f), @@ -669,7 +670,7 @@ CBoat::ProcessControl(void) splashDir.z += 0.0003f*m_nDeltaVolumeUnderWater; CWaterLevel::GetWaterLevel(splashPos, &waterLevel, true); if(splashPos.z-waterLevel < 3.0f && - CVisibilityPlugins::GetDistanceSquaredFromCamera((RwV3d*)&splashPos) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ + CVisibilityPlugins::GetDistanceSquaredFromCamera(&splashPos) < SQR(70.0f * TheCamera.GenerationDistMultiplier)){ splashPos.z = waterLevel + 0.1f; CParticle::AddParticle(PARTICLE_CAR_SPLASH, splashPos, 0.75f*splashDir, nil, splashSize+0.1f, splashColor, CGeneral::GetRandomNumberInRange(0.0f, 10.0f), CGeneral::GetRandomNumberInRange(0.0f, 90.0f), @@ -1006,7 +1007,7 @@ CBoat::PreRender(void) if(atomic) SetComponentAtomicAlpha(atomic, Max(150-alpha, 0)); } - //CShadows::StoreShadowForVehicle(this); + CShadows::StoreShadowForVehicle(this, VEH_SHD_TYPE_SEAPLANE); }else if(GetModelIndex() == MI_COASTG || GetModelIndex() == MI_DINGHY || GetModelIndex() == MI_RIO || GetModelIndex() == MI_SQUALO || GetModelIndex() == MI_MARQUIS){ if(m_aBoatNodes[BOAT_RUDDER]){ diff --git a/src/vehicles/Cranes.cpp b/src/vehicles/Cranes.cpp index 2a571a67..8433a0ba 100644 --- a/src/vehicles/Cranes.cpp +++ b/src/vehicles/Cranes.cpp @@ -629,11 +629,11 @@ void CCranes::Save(uint8* buf, uint32* size) for (int i = 0; i < NUM_CRANES; i++) { CCrane *pCrane = WriteSaveBuf(buf, aCranes[i]); if (pCrane->m_pCraneEntity != nil) - pCrane->m_pCraneEntity = (CBuilding*)(CPools::GetBuildingPool()->GetJustIndex(pCrane->m_pCraneEntity) + 1); + pCrane->m_pCraneEntity = (CBuilding*)(CPools::GetBuildingPool()->GetJustIndex_NoFreeAssert(pCrane->m_pCraneEntity) + 1); if (pCrane->m_pHook != nil) - pCrane->m_pHook = (CObject*)(CPools::GetObjectPool()->GetJustIndex(pCrane->m_pHook) + 1); + pCrane->m_pHook = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(pCrane->m_pHook) + 1); if (pCrane->m_pVehiclePickedUp != nil) - pCrane->m_pVehiclePickedUp = (CVehicle*)(CPools::GetVehiclePool()->GetJustIndex(pCrane->m_pVehiclePickedUp) + 1); + pCrane->m_pVehiclePickedUp = (CVehicle*)(CPools::GetVehiclePool()->GetJustIndex_NoFreeAssert(pCrane->m_pVehiclePickedUp) + 1); } VALIDATESAVEBUF(*size); diff --git a/src/vehicles/Cranes.h b/src/vehicles/Cranes.h index 45ea7a8d..162f9af9 100644 --- a/src/vehicles/Cranes.h +++ b/src/vehicles/Cranes.h @@ -11,7 +11,7 @@ class CBuilding; class CCrane { public: - enum CraneState : uint8 { + enum CraneState { IDLE = 0, GOING_TOWARDS_TARGET = 1, LIFTING_TARGET = 2, @@ -19,7 +19,7 @@ public: ROTATING_TARGET = 4, DROPPING_TARGET = 5 }; - enum CraneStatus : uint8 { + enum CraneStatus { NONE = 0, ACTIVATED = 1, DEACTIVATED = 2 @@ -46,8 +46,8 @@ public: CVector2D m_vecHookVelocity; CVehicle *m_pVehiclePickedUp; uint32 m_nTimeForNextCheck; - CraneStatus m_nCraneStatus; - CraneState m_nCraneState; + uint8 m_nCraneStatus; + uint8 m_nCraneState; uint8 m_nVehiclesCollected; bool m_bIsCrusher; bool m_bIsMilitaryCrane; diff --git a/src/vehicles/HandlingMgr.cpp b/src/vehicles/HandlingMgr.cpp index 3d5d4e77..b8c8566c 100644 --- a/src/vehicles/HandlingMgr.cpp +++ b/src/vehicles/HandlingMgr.cpp @@ -2,6 +2,7 @@ #include "main.h" #include "FileMgr.h" +#include "Physical.h" #include "HandlingMgr.h" //--MIAMI: done @@ -172,7 +173,7 @@ cHandlingDataMgr::LoadHandlingData(void) end = start+1; // yeah, this is kinda crappy - if(strncmp(line, ";the end", 9) == 0) + if(strcmp(line, ";the end") == 0) keepGoing = 0; else if(line[0] != ';'){ if(line[0] == '!'){ @@ -187,7 +188,7 @@ cHandlingDataMgr::LoadHandlingData(void) handlingId = FindExactWord(word, (const char*)VehicleNames, 14, NUMHANDLINGS); assert(handlingId >= 0 && handlingId < NUMHANDLINGS); bikeHandling = GetBikePointer(handlingId); - bikeHandling->nIdentifier = (eHandlingId)handlingId; + bikeHandling->nIdentifier = (tVehicleType)handlingId; break; case 2: bikeHandling->fLeanFwdCOM = atof(word); break; case 3: bikeHandling->fLeanFwdForce = atof(word); break; @@ -220,7 +221,7 @@ cHandlingDataMgr::LoadHandlingData(void) handlingId = FindExactWord(word, (const char*)VehicleNames, 14, NUMHANDLINGS); assert(handlingId >= 0 && handlingId < NUMHANDLINGS); flyingHandling = GetFlyingPointer(handlingId); - flyingHandling->nIdentifier = (eHandlingId)handlingId; + flyingHandling->nIdentifier = (tVehicleType)handlingId; break; case 2: flyingHandling->fThrust = atof(word); break; case 3: flyingHandling->fThrustFallOff = atof(word); break; @@ -255,7 +256,7 @@ cHandlingDataMgr::LoadHandlingData(void) handlingId = FindExactWord(word, (const char*)VehicleNames, 14, NUMHANDLINGS); assert(handlingId >= 0 && handlingId < NUMHANDLINGS); boatHandling = GetBoatPointer(handlingId); - boatHandling->nIdentifier = (eHandlingId)handlingId; + boatHandling->nIdentifier = (tVehicleType)handlingId; break; case 2: boatHandling->fThrustY = atof(word); break; case 3: boatHandling->fThrustZ = atof(word); break; @@ -284,7 +285,7 @@ cHandlingDataMgr::LoadHandlingData(void) handlingId = FindExactWord(word, (const char*)VehicleNames, 14, NUMHANDLINGS); assert(handlingId >= 0 && handlingId < NUMHANDLINGS); handling = &HandlingData[handlingId]; - handling->nIdentifier = (eHandlingId)handlingId; + handling->nIdentifier = (tVehicleType)handlingId; break; case 1: handling->fMass = atof(word); break; case 2: handling->Dimension.x = atof(word); break; @@ -348,18 +349,18 @@ cHandlingDataMgr::FindExactWord(const char *word, const char *words, int wordLen void cHandlingDataMgr::ConvertDataToGameUnits(tHandlingData *handling) { - // TODO: figure out what exactly is being converted here + // convert distance to m, time to 1/50s float velocity, a, b, specificVolume; - handling->Transmission.fEngineAcceleration /= 2500.0f; - handling->Transmission.fMaxVelocity /= 180.0f; - handling->fBrakeDeceleration /= 2500.0f; + 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 * 0.008f*handling->fMass; + handling->fBuoyancy = 100.0f/handling->nPercentSubmerged * GRAVITY*handling->fMass; // What the hell is going on here? specificVolume = handling->Dimension.x*handling->Dimension.z*0.5f / handling->fMass; // ? diff --git a/src/vehicles/HandlingMgr.h b/src/vehicles/HandlingMgr.h index e93f7879..446395f2 100644 --- a/src/vehicles/HandlingMgr.h +++ b/src/vehicles/HandlingMgr.h @@ -2,7 +2,7 @@ #include "Transmission.h" -enum eHandlingId +enum tVehicleType { HANDLING_LANDSTAL, HANDLING_IDAHO, @@ -120,6 +120,11 @@ enum eHandlingId NUMBOATHANDLINGS = HANDLING_SEAPLANE+1 - HANDLING_PREDATOR, }; +enum tField // most likely a handling field enum, never used so :shrug: +{ + +}; + enum { HANDLING_1G_BOOST = 1, @@ -154,7 +159,7 @@ enum struct tHandlingData { - eHandlingId nIdentifier; + tVehicleType nIdentifier; float fMass; float fInvMass; float fTurnMass; @@ -170,7 +175,7 @@ struct tHandlingData float fSteeringLock; float fTractionLoss; float fTractionBias; - float fABS; // should be VC leftover + float fUnused; float fSuspensionForceLevel; float fSuspensionDampingLevel; float fSuspensionUpperLimit; @@ -187,7 +192,7 @@ struct tHandlingData struct tBikeHandlingData { - eHandlingId nIdentifier; + tVehicleType nIdentifier; float fLeanFwdCOM; float fLeanFwdForce; float fLeanBakCOM; @@ -207,7 +212,7 @@ struct tBikeHandlingData struct tBoatHandlingData { - eHandlingId nIdentifier; + tVehicleType nIdentifier; float fThrustY; float fThrustZ; float fThrustAppZ; @@ -222,7 +227,7 @@ struct tBoatHandlingData struct tFlyingHandlingData { - eHandlingId nIdentifier; + tVehicleType nIdentifier; float fThrust; float fThrustFallOff; float fYaw; @@ -239,6 +244,8 @@ struct tFlyingHandlingData CVector vecSpeedRes; }; +class CVehicle; + class cHandlingDataMgr { float field_0; // unused it seems @@ -258,14 +265,15 @@ public: void Initialise(void); void LoadHandlingData(void); int FindExactWord(const char *word, const char *words, int wordLen, int numWords); + void ConvertDataToWorldUnits(tHandlingData *handling); void ConvertDataToGameUnits(tHandlingData *handling); void ConvertBikeDataToGameUnits(tBikeHandlingData *handling); int32 GetHandlingId(const char *name); - tHandlingData *GetHandlingData(eHandlingId id) { return &HandlingData[id]; } + tHandlingData *GetHandlingData(tVehicleType id) { return &HandlingData[id]; } tBikeHandlingData *GetBikePointer(uint8 id) { return &BikeHandlingData[id-HANDLING_BIKE]; } tFlyingHandlingData *GetFlyingPointer(uint8 id); tBoatHandlingData *GetBoatPointer(uint8 id); - bool HasRearWheelDrive(eHandlingId id) { return HandlingData[id].Transmission.nDriveType == 'R'; } - bool HasFrontWheelDrive(eHandlingId id) { return HandlingData[id].Transmission.nDriveType == 'F'; } + bool HasRearWheelDrive(tVehicleType id) { return HandlingData[id].Transmission.nDriveType == 'R'; } + bool HasFrontWheelDrive(tVehicleType id) { return HandlingData[id].Transmission.nDriveType == 'F'; } }; extern cHandlingDataMgr mod_HandlingManager; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index d6a237e5..644fdde8 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -57,7 +57,7 @@ CHeli::CHeli(int32 id, uint8 CreatedBy) CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); m_vehType = VEHICLE_TYPE_HELI; - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId); SetModelIndex(id); m_heliStatus = HELI_STATUS_HOVER; m_pathState = 0; diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index ffe9ffbf..5b5536fd 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -18,6 +18,7 @@ #include "HandlingMgr.h" #include "Heli.h" #include "Plane.h" +#include "MemoryHeap.h" //--MIAMI: file done @@ -70,7 +71,7 @@ CPlane::CPlane(int32 id, uint8 CreatedBy) { CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); m_vehType = VEHICLE_TYPE_PLANE; - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId); SetModelIndex(id); m_fMass = 100000000.0f; @@ -564,9 +565,11 @@ CPlane::ProcessControl(void) if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP){ DeleteRwObject(); if(mi->m_planeLodId != -1){ + PUSH_MEMID(MEMID_WORLD); m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); + POP_MEMID(); if(m_rwObject) - m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); + m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); } } }else if(CStreaming::HasModelLoaded(GetModelIndex())){ diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp index fb8361c5..1a4af307 100644 --- a/src/vehicles/Train.cpp +++ b/src/vehicles/Train.cpp @@ -44,7 +44,7 @@ CTrain::CTrain(int32 id, uint8 CreatedBy) #ifdef GTA_TRAIN CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id); m_vehType = VEHICLE_TYPE_TRAIN; - pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)mi->m_handlingId); + pHandling = mod_HandlingManager.GetHandlingData((tVehicleType)mi->m_handlingId); SetModelIndex(id); Doors[0].Init(0.8f, 0.0f, 1, 0); diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index f083e0f6..56de3562 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -2492,7 +2492,7 @@ IsVehiclePointerValid(CVehicle* pVehicle) { if (!pVehicle) return false; - int index = CPools::GetVehiclePool()->GetJustIndex(pVehicle); + int index = CPools::GetVehiclePool()->GetJustIndex_NoFreeAssert(pVehicle); #ifdef FIX_BUGS if (index < 0 || index >= NUMVEHICLES) #else diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index 004f1fd9..a42106cc 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -102,14 +102,6 @@ enum eLights VEHLIGHT_REAR_RIGHT, }; -enum eWheels -{ - VEHWHEEL_FRONT_LEFT, - VEHWHEEL_FRONT_RIGHT, - VEHWHEEL_REAR_LEFT, - VEHWHEEL_REAR_RIGHT, -}; - enum { CAR_PIECE_BONNET = 1, @@ -248,8 +240,9 @@ 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) uint8 m_bombType : 3; +#endif uint8 bDriverLastFrame : 1; int8 m_numPedsUseItAsCover; @@ -259,7 +252,9 @@ public: float m_fHealth; // 1000.0f = full health. 250.0f = fire. 0 -> explode uint8 m_nCurrentGear; float m_fChangeGearTime; +#if (!defined GTA_PS2 || defined FIX_BUGS) CEntity* m_pBombRigger; +#endif uint32 m_nSetPieceExtendedRangeTime; uint32 m_nGunFiringTime; // last time when gun on vehicle was fired (used on boats) uint32 m_nTimeOfDeath; @@ -281,7 +276,7 @@ public: int8 m_comedyControlState; CStoredCollPoly m_aCollPolys[2]; // poly which is under front/rear part of car float m_fSteerInput; - eVehicleType m_vehType; + uint8 m_vehType; static void *operator new(size_t); static void *operator new(size_t sz, int slot); |