diff options
Diffstat (limited to 'src/vehicles/Vehicle.cpp')
-rw-r--r-- | src/vehicles/Vehicle.cpp | 141 |
1 files changed, 133 insertions, 8 deletions
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index d0ccd31b..5dc7bc72 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -98,7 +98,7 @@ CVehicle::CVehicle(uint8 CreatedBy) bHasAlreadyBeenRecorded = false; m_bSirenOrAlarm = 0; m_nCarHornTimer = 0; - field_22D = 0; + m_nCarHornPattern = 0; m_nAlarmState = 0; m_nDoorLock = CARLOCK_UNLOCKED; m_nLastWeaponDamage = -1; @@ -393,7 +393,7 @@ CVehicle::FlyingControl(eFlightModel flightModel) m_vecMoveSpeed.x *= rmX; m_vecMoveSpeed.y *= rmY; m_vecMoveSpeed.z *= rmZ; - if (m_status != STATUS_PLAYER && m_status != STATUS_PLAYER_REMOTE) + if (GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE) return; float fThrust; if (bCheat5) @@ -623,13 +623,13 @@ CVehicle::InflictDamage(CEntity* damagedBy, eWeaponType weaponType, float damage } if (m_fHealth > 0.0f) { if (VehicleCreatedBy == RANDOM_VEHICLE && pDriver && - (m_status == STATUS_SIMPLE || m_status == STATUS_PHYSICS) && + (GetStatus() == STATUS_SIMPLE || GetStatus() == STATUS_PHYSICS) && AutoPilot.m_nCarMission == MISSION_CRUISE) { if (m_randomSeed < DAMAGE_FLEE_IN_CAR_PROBABILITY_VALUE) { CCarCtrl::SwitchVehicleToRealPhysics(this); AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS; AutoPilot.m_nCruiseSpeed = GAME_SPEED_TO_CARAI_SPEED * pHandling->Transmission.fUnkMaxVelocity; - m_status = STATUS_PHYSICS; + SetStatus(STATUS_PHYSICS); } } m_nLastWeaponDamage = weaponType; @@ -639,11 +639,11 @@ CVehicle::InflictDamage(CEntity* damagedBy, eWeaponType weaponType, float damage if (VehicleCreatedBy == RANDOM_VEHICLE && (m_fHealth < DAMAGE_HEALTH_TO_FLEE_ALWAYS || bFrightensDriver && m_randomSeed > DAMAGE_FLEE_ON_FOOT_PROBABILITY_VALUE)) { - switch (m_status) { + switch (GetStatus()) { case STATUS_SIMPLE: case STATUS_PHYSICS: if (pDriver) { - m_status = STATUS_ABANDONED; + SetStatus(STATUS_ABANDONED); pDriver->bFleeAfterExitingCar = true; pDriver->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); } @@ -871,7 +871,7 @@ CVehicle::UsesSiren(uint32 id) bool CVehicle::IsVehicleNormal(void) { - if (!pDriver || m_nNumPassengers != 0 || m_status == STATUS_WRECKED) + if (!pDriver || m_nNumPassengers != 0 || GetStatus() == STATUS_WRECKED) return false; switch (GetModelIndex()){ case MI_FIRETRUCK: @@ -1141,7 +1141,7 @@ CVehicle::AddPassenger(CPed *passenger, uint8 n) void CVehicle::RemoveDriver(void) { - m_status = STATUS_ABANDONED; + SetStatus(STATUS_ABANDONED); pDriver = nil; } @@ -1222,3 +1222,128 @@ DestroyVehicleAndDriverAndPassengers(CVehicle* pVehicle) CWorld::Remove(pVehicle); delete pVehicle; } + +#ifdef COMPATIBLE_SAVES +void +CVehicle::Save(uint8*& buf) +{ + SkipSaveBuf(buf, 4); + WriteSaveBuf<float>(buf, GetRight().x); + WriteSaveBuf<float>(buf, GetRight().y); + WriteSaveBuf<float>(buf, GetRight().z); + SkipSaveBuf(buf, 4); + WriteSaveBuf<float>(buf, GetForward().x); + WriteSaveBuf<float>(buf, GetForward().y); + WriteSaveBuf<float>(buf, GetForward().z); + SkipSaveBuf(buf, 4); + WriteSaveBuf<float>(buf, GetUp().x); + WriteSaveBuf<float>(buf, GetUp().y); + WriteSaveBuf<float>(buf, GetUp().z); + SkipSaveBuf(buf, 4); + WriteSaveBuf<float>(buf, GetPosition().x); + WriteSaveBuf<float>(buf, GetPosition().y); + WriteSaveBuf<float>(buf, GetPosition().z); + SkipSaveBuf(buf, 16); + SaveEntityFlags(buf); + SkipSaveBuf(buf, 212); + AutoPilot.Save(buf); + WriteSaveBuf<int8>(buf, m_currentColour1); + WriteSaveBuf<int8>(buf, m_currentColour2); + SkipSaveBuf(buf, 2); + WriteSaveBuf<int16>(buf, m_nAlarmState); + SkipSaveBuf(buf, 43); + WriteSaveBuf<uint8>(buf, m_nNumMaxPassengers); + SkipSaveBuf(buf, 2); + WriteSaveBuf<float>(buf, field_1D0[0]); + WriteSaveBuf<float>(buf, field_1D0[1]); + WriteSaveBuf<float>(buf, field_1D0[2]); + WriteSaveBuf<float>(buf, field_1D0[3]); + SkipSaveBuf(buf, 8); + WriteSaveBuf<float>(buf, m_fSteerAngle); + WriteSaveBuf<float>(buf, m_fGasPedal); + WriteSaveBuf<float>(buf, m_fBrakePedal); + WriteSaveBuf<uint8>(buf, VehicleCreatedBy); + uint8 flags = 0; + if (bIsLawEnforcer) flags |= BIT(0); + if (bIsLocked) flags |= BIT(3); + if (bEngineOn) flags |= BIT(4); + if (bIsHandbrakeOn) flags |= BIT(5); + if (bLightsOn) flags |= BIT(6); + if (bFreebies) flags |= BIT(7); + WriteSaveBuf<uint8>(buf, flags); + SkipSaveBuf(buf, 10); + WriteSaveBuf<float>(buf, m_fHealth); + WriteSaveBuf<uint8>(buf, m_nCurrentGear); + SkipSaveBuf(buf, 3); + WriteSaveBuf<float>(buf, m_fChangeGearTime); + SkipSaveBuf(buf, 4); + WriteSaveBuf<uint32>(buf, m_nTimeOfDeath); + SkipSaveBuf(buf, 2); + WriteSaveBuf<int16>(buf, m_nBombTimer); + SkipSaveBuf(buf, 12); + WriteSaveBuf<int8>(buf, m_nDoorLock); + SkipSaveBuf(buf, 99); +} + +void +CVehicle::Load(uint8*& buf) +{ + CMatrix tmp; + SkipSaveBuf(buf, 4); + tmp.GetRight().x = ReadSaveBuf<float>(buf); + tmp.GetRight().y = ReadSaveBuf<float>(buf); + tmp.GetRight().z = ReadSaveBuf<float>(buf); + SkipSaveBuf(buf, 4); + tmp.GetForward().x = ReadSaveBuf<float>(buf); + tmp.GetForward().y = ReadSaveBuf<float>(buf); + tmp.GetForward().z = ReadSaveBuf<float>(buf); + SkipSaveBuf(buf, 4); + tmp.GetUp().x = ReadSaveBuf<float>(buf); + tmp.GetUp().y = ReadSaveBuf<float>(buf); + tmp.GetUp().z = ReadSaveBuf<float>(buf); + SkipSaveBuf(buf, 4); + tmp.GetPosition().x = ReadSaveBuf<float>(buf); + tmp.GetPosition().y = ReadSaveBuf<float>(buf); + tmp.GetPosition().z = ReadSaveBuf<float>(buf); + m_matrix = tmp; + SkipSaveBuf(buf, 16); + LoadEntityFlags(buf); + SkipSaveBuf(buf, 212); + AutoPilot.Load(buf); + m_currentColour1 = ReadSaveBuf<int8>(buf); + m_currentColour2 = ReadSaveBuf<int8>(buf); + SkipSaveBuf(buf, 2); + m_nAlarmState = ReadSaveBuf<int16>(buf); + SkipSaveBuf(buf, 43); + m_nNumMaxPassengers = ReadSaveBuf<int8>(buf); + SkipSaveBuf(buf, 2); + field_1D0[0] = ReadSaveBuf<float>(buf); + field_1D0[1] = ReadSaveBuf<float>(buf); + field_1D0[2] = ReadSaveBuf<float>(buf); + field_1D0[3] = ReadSaveBuf<float>(buf); + SkipSaveBuf(buf, 8); + m_fSteerAngle = ReadSaveBuf<float>(buf); + m_fGasPedal = ReadSaveBuf<float>(buf); + m_fBrakePedal = ReadSaveBuf<float>(buf); + VehicleCreatedBy = ReadSaveBuf<uint8>(buf); + uint8 flags = ReadSaveBuf<uint8>(buf); + bIsLawEnforcer = !!(flags & BIT(0)); + bIsLocked = !!(flags & BIT(3)); + bEngineOn = !!(flags & BIT(4)); + bIsHandbrakeOn = !!(flags & BIT(5)); + bLightsOn = !!(flags & BIT(6)); + bFreebies = !!(flags & BIT(7)); + SkipSaveBuf(buf, 10); + m_fHealth = ReadSaveBuf<float>(buf); + m_nCurrentGear = ReadSaveBuf<uint8>(buf); + SkipSaveBuf(buf, 3); + m_fChangeGearTime = ReadSaveBuf<float>(buf); + SkipSaveBuf(buf, 4); + m_nTimeOfDeath = ReadSaveBuf<uint32>(buf); + SkipSaveBuf(buf, 2); + m_nBombTimer = ReadSaveBuf<int16>(buf); + SkipSaveBuf(buf, 12); + m_nDoorLock = (eCarLock)ReadSaveBuf<int8>(buf); + SkipSaveBuf(buf, 99); +} +#endif |