summaryrefslogtreecommitdiff
path: root/src/vehicles
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-05-02 23:48:17 +0300
committerGitHub <noreply@github.com>2020-05-02 23:48:17 +0300
commit4448156e29c1c2dc6db476bbde53926efdba7331 (patch)
tree4be7e31e00dacbdfb2a6fadfd414aab0eaf64c39 /src/vehicles
parent89961325b28ce887501189b5baa9eb50175de5d4 (diff)
parentb095bc1b5a48f9923afada88a7f117e757716d00 (diff)
Merge pull request #494 from Nick007J/master
pools compatibility
Diffstat (limited to 'src/vehicles')
-rw-r--r--src/vehicles/Automobile.cpp26
-rw-r--r--src/vehicles/Automobile.h6
-rw-r--r--src/vehicles/Boat.cpp23
-rw-r--r--src/vehicles/Boat.h7
-rw-r--r--src/vehicles/Vehicle.cpp125
-rw-r--r--src/vehicles/Vehicle.h4
6 files changed, 191 insertions, 0 deletions
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index e38c93ae..acca4d60 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -51,6 +51,13 @@ RwObject *GetCurrentAtomicObjectCB(RwObject *object, void *data);
bool CAutomobile::m_sAllTaxiLights;
+const uint32 CAutomobile::nSaveStructSize =
+#ifdef COMPATIBLE_SAVES
+ 1448;
+#else
+ sizeof(CAutomobile);
+#endif
+
CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
: CVehicle(CreatedBy)
{
@@ -4580,3 +4587,22 @@ CAutomobile::SetAllTaxiLights(bool set)
{
m_sAllTaxiLights = set;
}
+
+#ifdef COMPATIBLE_SAVES
+void
+CAutomobile::Save(uint8*& buf)
+{
+ CVehicle::Save(buf);
+ WriteSaveBuf<CDamageManager>(buf, Damage);
+ SkipSaveBuf(buf, 800 - sizeof(CDamageManager));
+}
+
+void
+CAutomobile::Load(uint8*& buf)
+{
+ CVehicle::Load(buf);
+ Damage = ReadSaveBuf<CDamageManager>(buf);
+ SkipSaveBuf(buf, 800 - sizeof(CDamageManager));
+ SetupDamageAfterLoad();
+}
+#endif
diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h
index 2de85a99..041302bf 100644
--- a/src/vehicles/Automobile.h
+++ b/src/vehicles/Automobile.h
@@ -188,9 +188,15 @@ public:
void HideAllComps(void);
void ShowAllComps(void);
void ReduceHornCounter(void);
+#ifdef COMPATIBLE_SAVES
+ virtual void Save(uint8*& buf);
+ virtual void Load(uint8*& buf);
+#endif
+ static const uint32 nSaveStructSize;
static void SetAllTaxiLights(bool set);
};
+
static_assert(sizeof(CAutomobile) == 0x5A8, "CAutomobile: error");
inline uint8 GetCarDoorFlag(int32 carnode) {
diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp
index 5e75dc21..1f80c43e 100644
--- a/src/vehicles/Boat.cpp
+++ b/src/vehicles/Boat.cpp
@@ -32,6 +32,13 @@ float WAKE_LIFETIME = 400.0f;
CBoat *CBoat::apFrameWakeGeneratingBoats[4];
+const uint32 CBoat::nSaveStructSize =
+#ifdef COMPATIBLE_SAVES
+ 1156;
+#else
+ sizeof(CBoat);
+#endif
+
CBoat::CBoat(int mi, uint8 owner) : CVehicle(owner)
{
CVehicleModelInfo *minfo = (CVehicleModelInfo*)CModelInfo::GetModelInfo(mi);
@@ -899,3 +906,19 @@ CBoat::AddWakePoint(CVector point)
m_nNumWakePoints = 1;
}
}
+
+#ifdef COMPATIBLE_SAVES
+void
+CBoat::Save(uint8*& buf)
+{
+ CVehicle::Save(buf);
+ SkipSaveBuf(buf, 1156 - 648);
+}
+
+void
+CBoat::Load(uint8*& buf)
+{
+ CVehicle::Load(buf);
+ SkipSaveBuf(buf, 1156 - 648);
+}
+#endif
diff --git a/src/vehicles/Boat.h b/src/vehicles/Boat.h
index ba56e355..70407ab9 100644
--- a/src/vehicles/Boat.h
+++ b/src/vehicles/Boat.h
@@ -64,7 +64,14 @@ public:
static float IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat);
static void FillBoatList(void);
+#ifdef COMPATIBLE_SAVES
+ virtual void Save(uint8*& buf);
+ virtual void Load(uint8*& buf);
+#endif
+ static const uint32 nSaveStructSize;
+
};
+
static_assert(sizeof(CBoat) == 0x484, "CBoat: error");
extern float MAX_WAKE_LENGTH;
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index 590e68f2..75f43515 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -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
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index 293cb1a8..d8f90d92 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -231,6 +231,10 @@ public:
virtual bool IsRoomForPedToLeaveCar(uint32 component, CVector *forcedDoorPos) { return false;}
virtual float GetHeightAboveRoad(void);
virtual void PlayCarHorn(void) {}
+#ifdef COMPATIBLE_SAVES
+ virtual void Save(uint8*& buf);
+ virtual void Load(uint8*& buf);
+#endif
bool IsCar(void) { return m_vehType == VEHICLE_TYPE_CAR; }
bool IsBoat(void) { return m_vehType == VEHICLE_TYPE_BOAT; }