From 35c546848a50c4db9fcdb9b1088c2e7b2650f421 Mon Sep 17 00:00:00 2001 From: mnelenpridumivat Date: Fri, 6 Dec 2024 14:20:45 +0300 Subject: [PATCH] Add more classes with new save system support --- src/xrGame/ArtCombiner.cpp | 20 ++++++++++++++ src/xrGame/ArtCombiner.h | 3 +++ src/xrGame/ArtContainer.cpp | 40 ++++++++++++++++++++++++++++ src/xrGame/ArtContainer.h | 4 +++ src/xrGame/Artefact.h | 4 +++ src/xrGame/ArtefactContainer.cpp | 20 ++++++++++++++ src/xrGame/ArtefactContainer.h | 3 +++ src/xrGame/CustomRocket.h | 3 +++ src/xrGame/CustomZone.cpp | 24 ++++++++++++++++- src/xrGame/CustomZone.h | 3 +++ src/xrGame/ExplosiveRocket.h | 2 ++ src/xrGame/GameObject.cpp | 12 +++++++-- src/xrGame/hud_item_object.h | 3 +++ src/xrGame/inventory_item_object.cpp | 20 ++++++++++++++ src/xrGame/inventory_item_object.h | 4 +++ 15 files changed, 162 insertions(+), 3 deletions(-) diff --git a/src/xrGame/ArtCombiner.cpp b/src/xrGame/ArtCombiner.cpp index 209abc1bce..98a7d7dba8 100644 --- a/src/xrGame/ArtCombiner.cpp +++ b/src/xrGame/ArtCombiner.cpp @@ -24,6 +24,26 @@ void CArtCombiner::load(IReader& input_packet) CArtContainer::load(input_packet); } +void CArtCombiner::Save(CSaveObjectSave* Object) const +{ + Object->BeginChunk("CArtCombiner"); + { + CArtefact::Save(Object); + CArtContainer::Save(Object); + } + Object->EndChunk(); +} + +void CArtCombiner::Load(CSaveObjectLoad* Object) +{ + Object->FindChunk("CArtCombiner"); + { + CArtefact::Load(Object); + CArtContainer::Load(Object); + } + Object->EndChunk(); +} + u32 CArtCombiner::Cost() const { auto res = CArtefact::Cost(); diff --git a/src/xrGame/ArtCombiner.h b/src/xrGame/ArtCombiner.h index 0ea1fddac4..548d25457b 100644 --- a/src/xrGame/ArtCombiner.h +++ b/src/xrGame/ArtCombiner.h @@ -15,6 +15,9 @@ class CArtCombiner : void save(NET_Packet& output_packet) override; void load(IReader& input_packet) override; + virtual void Save(CSaveObjectSave* Object) const override; + virtual void Load(CSaveObjectLoad* Object) override; + u32 Cost() const override; float Weight() const override; diff --git a/src/xrGame/ArtContainer.cpp b/src/xrGame/ArtContainer.cpp index 33298621e0..c0e19bad54 100644 --- a/src/xrGame/ArtContainer.cpp +++ b/src/xrGame/ArtContainer.cpp @@ -59,6 +59,46 @@ void CArtContainer::load(IReader& packet) } } +void CArtContainer::Save(CSaveObjectSave* Object) const +{ + Object->BeginChunk("CArtContainer"); + { + Object->GetCurrentChunk()->WriteArray(m_sArtefactsInside.size()); + { + for (const auto& artefact : m_sArtefactsInside) + { + shared_str section = artefact->cNameSect(); + Object->GetCurrentChunk()->w_stringZ(section); + artefact->Save(Object); + } + } + Object->GetCurrentChunk()->EndArray(); + } + Object->EndChunk(); +} + +void CArtContainer::Load(CSaveObjectLoad* Object) +{ + Object->FindChunk("CArtContainer"); + { + u64 ArraySize; + Object->GetCurrentChunk()->ReadArray(ArraySize); + { + for (u64 i = 0; i < ArraySize; ++i) + { + shared_str section; + Object->GetCurrentChunk()->r_stringZ(section); + CArtefact* artefact = new CArtefact(); + artefact->Load(section.c_str()); + artefact->Load(Object); + m_sArtefactsInside.push_back(artefact); + } + } + Object->GetCurrentChunk()->EndArray(); + } + Object->EndChunk(); +} + bool CArtContainer::CanStoreArt(CArtefact* art) { return true; diff --git a/src/xrGame/ArtContainer.h b/src/xrGame/ArtContainer.h index 1a8888448d..c3c84b18a9 100644 --- a/src/xrGame/ArtContainer.h +++ b/src/xrGame/ArtContainer.h @@ -1,4 +1,5 @@ #pragma once +#include "Save/SaveObject.h" class CArtefact; @@ -19,6 +20,9 @@ class CArtContainer void save(NET_Packet& output_packet); void load(IReader& input_packet); + virtual void Save(CSaveObjectSave* Object) const; + virtual void Load(CSaveObjectLoad* Object); + u32 Cost() const; float Weight() const; diff --git a/src/xrGame/Artefact.h b/src/xrGame/Artefact.h index 8654aead6b..5639a68752 100644 --- a/src/xrGame/Artefact.h +++ b/src/xrGame/Artefact.h @@ -146,6 +146,10 @@ class CArtefact : public CHudItemObject, //processing_deactivate (); } + + virtual void Save(CSaveObjectSave* Object) const override { inherited::Save(Object); }; + virtual void Load(CSaveObjectLoad* Object) override { inherited::Load(Object); }; + DECLARE_SCRIPT_REGISTER_FUNCTION }; diff --git a/src/xrGame/ArtefactContainer.cpp b/src/xrGame/ArtefactContainer.cpp index dd038c9842..6e2c566521 100644 --- a/src/xrGame/ArtefactContainer.cpp +++ b/src/xrGame/ArtefactContainer.cpp @@ -48,6 +48,26 @@ void CArtefactContainer::load(IReader& packet) CArtContainer::load(packet); } +void CArtefactContainer::Save(CSaveObjectSave* Object) const +{ + Object->BeginChunk("CArtefactContainer"); + { + inherited::Save(Object); + CArtContainer::Save(Object); + } + Object->EndChunk(); +} + +void CArtefactContainer::Load(CSaveObjectLoad* Object) +{ + Object->FindChunk("CInventoryItemObject"); + { + inherited::Load(Object); + CArtContainer::Load(Object); + } + Object->EndChunk(); +} + u32 CArtefactContainer::Cost() const { u32 res = CInventoryItem::Cost(); diff --git a/src/xrGame/ArtefactContainer.h b/src/xrGame/ArtefactContainer.h index 845959524d..99c9e90981 100644 --- a/src/xrGame/ArtefactContainer.h +++ b/src/xrGame/ArtefactContainer.h @@ -18,6 +18,9 @@ class CArtefactContainer : public CInventoryItemObject, public CArtContainer void save (NET_Packet& output_packet) override; void load (IReader& input_packet) override; + virtual void Save(CSaveObjectSave* Object) const override; + virtual void Load(CSaveObjectLoad* Object) override; + u32 Cost () const override; float Weight () const override; }; diff --git a/src/xrGame/CustomRocket.h b/src/xrGame/CustomRocket.h index 33f4548f57..2d8b89ae32 100644 --- a/src/xrGame/CustomRocket.h +++ b/src/xrGame/CustomRocket.h @@ -62,6 +62,9 @@ class CCustomRocket : public CPhysicItem, virtual void PhDataUpdate (float step); virtual void PhTune (float step); + virtual void Save(CSaveObjectSave* Object) const override { inherited::Save(Object); }; + virtual void Load(CSaveObjectLoad* Object) override { inherited::Load(Object); }; + ////////////////////////////////////////////////////////////////////////// // Rocket Properties ////////////////////////////////////////////////////////////////////////// diff --git a/src/xrGame/CustomZone.cpp b/src/xrGame/CustomZone.cpp index c76d1ce7aa..1c82a90a63 100644 --- a/src/xrGame/CustomZone.cpp +++ b/src/xrGame/CustomZone.cpp @@ -1534,4 +1534,26 @@ void CCustomZone::load (IReader &input_packet) m_eZoneState = eZoneStateDisabled; else m_eZoneState = eZoneStateIdle; -} \ No newline at end of file +} + +void CCustomZone::Save(CSaveObjectSave* Object) const +{ + Object->BeginChunk("CCustomZone"); + { + inherited::Save(Object); + Object->GetCurrentChunk()->w_u8((u8)m_eZoneState); + } + Object->EndChunk(); +} + +void CCustomZone::Load(CSaveObjectLoad* Object) +{ + Object->FindChunk("CCustomZone"); + { + inherited::Load(Object); + u8 Value; + Object->GetCurrentChunk()->r_u8(Value); + m_eZoneState = (EZoneState)Value; + } + Object->EndChunk(); +} diff --git a/src/xrGame/CustomZone.h b/src/xrGame/CustomZone.h index 148d513b93..138683f221 100644 --- a/src/xrGame/CustomZone.h +++ b/src/xrGame/CustomZone.h @@ -57,6 +57,9 @@ class CCustomZone : public CSpaceRestrictor, virtual bool is_ai_obstacle () const {return true;}; virtual void save (NET_Packet &output_packet); virtual void load (IReader &input_packet); + + virtual void Save(CSaveObjectSave* Object) const override; + virtual void Load(CSaveObjectLoad* Object) override; virtual void UpdateCL (); virtual void UpdateWorkload (u32 dt); diff --git a/src/xrGame/ExplosiveRocket.h b/src/xrGame/ExplosiveRocket.h index bed9bc38bd..2f88d7b6b3 100644 --- a/src/xrGame/ExplosiveRocket.h +++ b/src/xrGame/ExplosiveRocket.h @@ -53,6 +53,8 @@ class CExplosiveRocket : virtual void save (NET_Packet &output_packet) {inherited::save(output_packet);} virtual void load (IReader &input_packet) {inherited::load(input_packet);} + virtual void Save(CSaveObjectSave* Object) const override { inherited::Save(Object); }; + virtual void Load(CSaveObjectLoad* Object) override { inherited::Load(Object); }; virtual BOOL net_SaveRelevant () {return inherited::net_SaveRelevant();} virtual void OnH_A_Chield () {inherited::OnH_A_Chield();} diff --git a/src/xrGame/GameObject.cpp b/src/xrGame/GameObject.cpp index a1c73125e0..b3972cc047 100644 --- a/src/xrGame/GameObject.cpp +++ b/src/xrGame/GameObject.cpp @@ -489,12 +489,20 @@ void CGameObject::load (IReader &input_packet) void CGameObject::Save(CSaveObjectSave* Object) const { - m_ScriptBinderComponent->Save(Object); + Object->BeginChunk("CGameObject"); + { + m_ScriptBinderComponent->Save(Object); + } + Object->EndChunk(); } void CGameObject::Load(CSaveObjectLoad* Object) { - m_ScriptBinderComponent->Load(Object); + Object->FindChunk("CGameObject"); + { + m_ScriptBinderComponent->Load(Object); + } + Object->EndChunk(); } void CGameObject::spawn_supplies() diff --git a/src/xrGame/hud_item_object.h b/src/xrGame/hud_item_object.h index 815db66570..ee2b2b436c 100644 --- a/src/xrGame/hud_item_object.h +++ b/src/xrGame/hud_item_object.h @@ -36,6 +36,9 @@ class CHudItemObject : virtual void on_renderable_Render(); virtual void OnMoveToRuck (const SInvItemPlace& prev); + virtual void Save(CSaveObjectSave* Object) const override { CInventoryItemObject::Save(Object); } + virtual void Load(CSaveObjectLoad* Object) override { CInventoryItemObject::Load(Object); } + virtual bool use_parent_ai_locations () const { return CInventoryItemObject::use_parent_ai_locations () && (Device.dwFrame != dwXF_Frame); diff --git a/src/xrGame/inventory_item_object.cpp b/src/xrGame/inventory_item_object.cpp index e89572728a..3f0fe89a0f 100644 --- a/src/xrGame/inventory_item_object.cpp +++ b/src/xrGame/inventory_item_object.cpp @@ -128,6 +128,26 @@ void CInventoryItemObject::load (IReader &packet) CInventoryItem::load (packet); } +void CInventoryItemObject::Save(CSaveObjectSave* Object) const +{ + Object->BeginChunk("CInventoryItemObject"); + { + CPhysicItem::Save(Object); + CInventoryItem::Save(Object); + } + Object->EndChunk(); +} + +void CInventoryItemObject::Load(CSaveObjectLoad* Object) +{ + Object->FindChunk("CInventoryItemObject"); + { + CPhysicItem::Load(Object); + CInventoryItem::Load(Object); + } + Object->EndChunk(); +} + void CInventoryItemObject::renderable_Render() { CPhysicItem::renderable_Render (); diff --git a/src/xrGame/inventory_item_object.h b/src/xrGame/inventory_item_object.h index 001a37480b..5ae49a0097 100644 --- a/src/xrGame/inventory_item_object.h +++ b/src/xrGame/inventory_item_object.h @@ -50,6 +50,10 @@ class CInventoryItemObject : virtual void net_Export (NET_Packet& P); // export to server virtual void save (NET_Packet &output_packet); virtual void load (IReader &input_packet); + + virtual void Save(CSaveObjectSave* Object) const override; + virtual void Load(CSaveObjectLoad* Object) override; + virtual BOOL net_SaveRelevant () {return TRUE;} virtual void renderable_Render (); virtual void reload (LPCSTR section);