diff --git a/apps/openmw/mwclass/classes.cpp b/apps/openmw/mwclass/classes.cpp index ca4bbee5db..1e62b0e18e 100644 --- a/apps/openmw/mwclass/classes.cpp +++ b/apps/openmw/mwclass/classes.cpp @@ -1,5 +1,7 @@ #include "classes.hpp" +#include + #include "activator.hpp" #include "apparatus.hpp" #include "armor.hpp" @@ -49,7 +51,18 @@ namespace MWClass Static::registerSelf(); BodyPart::registerSelf(); - ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); + ESM4Static::registerSelf(); ESM4Light::registerSelf(); } } diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 0f29fa4e22..82e974c7e0 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -65,13 +65,8 @@ namespace MWClass return MWWorld::Ptr(cell.insert(ref), &cell); } - ESM4Static::ESM4Static() - : MWWorld::RegisteredClass(ESM4::Static::sRecordId) - { - } - - void ESM4Static ::insertObjectRendering( - const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const + void ESM4StaticImpl::insertObjectRendering( + const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) { if (!model.empty()) { @@ -80,37 +75,9 @@ namespace MWClass } } - void ESM4Static::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const - { - insertObjectPhysics(ptr, model, rotation, physics); - } - - void ESM4Static::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const + void ESM4StaticImpl::insertObjectPhysics( + const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) { physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); } - - std::string ESM4Static::getModel(const MWWorld::ConstPtr& ptr) const - { - return getClassModel(ptr); - } - - std::string_view ESM4Static ::getName(const MWWorld::ConstPtr& ptr) const - { - return {}; - } - - bool ESM4Static::hasToolTip(const MWWorld::ConstPtr& ptr) const - { - return false; - } - - MWWorld::Ptr ESM4Static::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const - { - const MWWorld::LiveCellRef* ref = ptr.get(); - - return MWWorld::Ptr(cell.insert(ref), &cell); - } } diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index f16dfdd2a6..326909ebca 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -1,8 +1,11 @@ #ifndef GAME_MWCLASS_STATIC_H #define GAME_MWCLASS_STATIC_H +#include "../mwworld/cellstore.hpp" #include "../mwworld/registeredclass.hpp" +#include "classmodel.hpp" + namespace MWClass { class Static : public MWWorld::RegisteredClass @@ -32,31 +35,56 @@ namespace MWClass std::string getModel(const MWWorld::ConstPtr& ptr) const override; }; - class ESM4Static : public MWWorld::RegisteredClass + namespace ESM4StaticImpl + { + void insertObjectRendering( + const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface); + void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, + MWPhysics::PhysicsSystem& physics); + } + + // Templated because it is used as a dummy MWClass implementation for several ESM4 recors + template + class ESM4Static : public MWWorld::RegisteredClass> { friend MWWorld::RegisteredClass; - ESM4Static(); + ESM4Static() + : MWWorld::RegisteredClass(Record::sRecordId) + { + } - MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override; + MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override + { + const MWWorld::LiveCellRef* ref = ptr.get(); + return MWWorld::Ptr(cell.insert(ref), &cell); + } public: void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model, - MWRender::RenderingInterface& renderingInterface) const override; - ///< Add reference into a cell for rendering + MWRender::RenderingInterface& renderingInterface) const override + { + ESM4StaticImpl::insertObjectRendering(ptr, model, renderingInterface); + } void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const override; + MWPhysics::PhysicsSystem& physics) const override + { + insertObjectPhysics(ptr, model, rotation, physics); + } void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const override; + MWPhysics::PhysicsSystem& physics) const override + { + ESM4StaticImpl::insertObjectPhysics(ptr, model, rotation, physics); + } - std::string_view getName(const MWWorld::ConstPtr& ptr) const override; + std::string_view getName(const MWWorld::ConstPtr& ptr) const override { return ""; } ///< \return name or ID; can return an empty string. - bool hasToolTip(const MWWorld::ConstPtr& ptr) const override; + bool hasToolTip(const MWWorld::ConstPtr& ptr) const override { return false; } ///< @return true if this object has a tooltip when focused (default implementation: true) - std::string getModel(const MWWorld::ConstPtr& ptr) const override; + std::string getModel(const MWWorld::ConstPtr& ptr) const override { return getClassModel(ptr); } }; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 82e310c156..9c48cd2c9e 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 23b0a84443..0cc06f4d2f 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -60,6 +60,17 @@ namespace ESM4 struct Reference; struct Static; struct Light; + struct Activator; + struct Potion; + struct Ammunition; + struct Armor; + struct Book; + struct Clothing; + struct Container; + struct Door; + struct Ingredient; + struct MiscItem; + struct Weapon; } namespace MWWorld @@ -74,7 +85,10 @@ namespace MWWorld CellRefList, CellRefList, CellRefList, CellRefList, CellRefList, CellRefList, CellRefList, CellRefList, - CellRefList, CellRefList>; + CellRefList, CellRefList, CellRefList, CellRefList, + CellRefList, CellRefList, CellRefList, CellRefList, + CellRefList, CellRefList, CellRefList, + CellRefList, CellRefList>; /// \brief Mutable state of a cell class CellStore diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index c4b76401c5..0b8b8150a1 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -14,10 +14,6 @@ #include #include -#include -#include -#include -#include #include #include #include @@ -281,6 +277,16 @@ namespace MWWorld case ESM::REC_BODY: case ESM::REC_STAT4: case ESM::REC_LIGH4: + case ESM::REC_ACTI4: + case ESM::REC_ALCH4: + case ESM::REC_AMMO4: + case ESM::REC_ARMO4: + case ESM::REC_BOOK4: + case ESM::REC_CONT4: + case ESM::REC_DOOR4: + case ESM::REC_INGR4: + case ESM::REC_MISC4: + case ESM::REC_WEAP4: return true; break; } diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index a2375859f0..4ad9b6eab2 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -31,6 +31,17 @@ namespace ESM4 struct Cell; struct Light; struct Reference; + struct Activator; + struct Potion; + struct Ammunition; + struct Armor; + struct Book; + struct Clothing; + struct Container; + struct Door; + struct Ingredient; + struct MiscItem; + struct Weapon; } namespace ESM @@ -106,7 +117,10 @@ namespace MWWorld // Special entry which is hardcoded and not loaded from an ESM Store, - Store, Store, Store, Store>; + Store, Store, Store, Store, Store, + Store, Store, Store, Store, Store, + Store, Store, Store, Store, + Store>; private: template diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 39d022a393..79142b44f0 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -8,10 +8,6 @@ #include #include #include -#include -#include -#include -#include #include #include @@ -1266,7 +1262,18 @@ template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; diff --git a/components/esm/records.hpp b/components/esm/records.hpp index 7df0f6790f..1ef0c72c8f 100644 --- a/components/esm/records.hpp +++ b/components/esm/records.hpp @@ -42,6 +42,23 @@ #include "components/esm3/loadsscr.hpp" #include "components/esm3/loadstat.hpp" #include "components/esm3/loadweap.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "defs.hpp" // Special records which are not loaded from ESM diff --git a/components/esm4/loadacti.cpp b/components/esm4/loadacti.cpp index c69c6d0fd6..b9eb595632 100644 --- a/components/esm4/loadacti.cpp +++ b/components/esm4/loadacti.cpp @@ -34,8 +34,7 @@ void ESM4::Activator::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadacti.hpp b/components/esm4/loadacti.hpp index f65699ca59..c6d4090512 100644 --- a/components/esm4/loadacti.hpp +++ b/components/esm4/loadacti.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -39,7 +42,7 @@ namespace ESM4 struct Activator { - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -61,6 +64,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ACTI4; }; } diff --git a/components/esm4/loadalch.cpp b/components/esm4/loadalch.cpp index 0c8205fba7..8837641ab6 100644 --- a/components/esm4/loadalch.cpp +++ b/components/esm4/loadalch.cpp @@ -35,8 +35,7 @@ void ESM4::Potion::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadalch.hpp b/components/esm4/loadalch.hpp index 6ba720ab32..2644811a0e 100644 --- a/components/esm4/loadalch.hpp +++ b/components/esm4/loadalch.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "effect.hpp" // FormId, ScriptEffect namespace ESM4 @@ -55,7 +58,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -79,6 +82,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ALCH4; }; } diff --git a/components/esm4/loadammo.cpp b/components/esm4/loadammo.cpp index de2a99eb80..7e21ee4986 100644 --- a/components/esm4/loadammo.cpp +++ b/components/esm4/loadammo.cpp @@ -33,8 +33,7 @@ void ESM4::Ammunition::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadammo.hpp b/components/esm4/loadammo.hpp index 42c430c7f3..13592f4ff1 100644 --- a/components/esm4/loadammo.hpp +++ b/components/esm4/loadammo.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -54,7 +57,7 @@ namespace ESM4 float mConsumedPercentage{ 0.f }; }; - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -84,6 +87,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_AMMO4; }; } diff --git a/components/esm4/loadarmo.cpp b/components/esm4/loadarmo.cpp index dde2fe6768..178798e5ee 100644 --- a/components/esm4/loadarmo.cpp +++ b/components/esm4/loadarmo.cpp @@ -34,8 +34,7 @@ void ESM4::Armor::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); mIsFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadarmo.hpp b/components/esm4/loadarmo.hpp index ccc28dc834..29b5a75800 100644 --- a/components/esm4/loadarmo.hpp +++ b/components/esm4/loadarmo.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -148,7 +151,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details bool mIsTES4; // TODO: check that these match the general flags @@ -187,6 +190,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ARMO4; }; } diff --git a/components/esm4/loadbook.cpp b/components/esm4/loadbook.cpp index d8b4004aef..3e7524cf08 100644 --- a/components/esm4/loadbook.cpp +++ b/components/esm4/loadbook.cpp @@ -33,8 +33,7 @@ void ESM4::Book::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; // std::uint32_t esmVer = reader.esmVersion(); // currently unused diff --git a/components/esm4/loadbook.hpp b/components/esm4/loadbook.hpp index bbdbf12fe5..0281425701 100644 --- a/components/esm4/loadbook.hpp +++ b/components/esm4/loadbook.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -81,7 +84,7 @@ namespace ESM4 float weight; }; - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -105,6 +108,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_BOOK4; }; } diff --git a/components/esm4/loadclot.cpp b/components/esm4/loadclot.cpp index 1d7dc72474..19ff0af402 100644 --- a/components/esm4/loadclot.cpp +++ b/components/esm4/loadclot.cpp @@ -34,8 +34,7 @@ void ESM4::Clothing::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadclot.hpp b/components/esm4/loadclot.hpp index 26a7163c44..4b0adc7581 100644 --- a/components/esm4/loadclot.hpp +++ b/components/esm4/loadclot.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -47,7 +50,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -74,6 +77,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_CLOT4; }; } diff --git a/components/esm4/loadcont.cpp b/components/esm4/loadcont.cpp index 4cb00d83a1..12e5fd911b 100644 --- a/components/esm4/loadcont.cpp +++ b/components/esm4/loadcont.cpp @@ -33,8 +33,7 @@ void ESM4::Container::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadcont.hpp b/components/esm4/loadcont.hpp index bd4916e2bc..945e93b101 100644 --- a/components/esm4/loadcont.hpp +++ b/components/esm4/loadcont.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "formid.hpp" #include "inventory.hpp" // InventoryItem @@ -41,7 +44,7 @@ namespace ESM4 struct Container { - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -62,6 +65,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_CONT4; }; } diff --git a/components/esm4/loaddoor.cpp b/components/esm4/loaddoor.cpp index f3f261e5fc..6538a47340 100644 --- a/components/esm4/loaddoor.cpp +++ b/components/esm4/loaddoor.cpp @@ -33,8 +33,7 @@ void ESM4::Door::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loaddoor.hpp b/components/esm4/loaddoor.hpp index fdf9b2cdda..808f80d536 100644 --- a/components/esm4/loaddoor.hpp +++ b/components/esm4/loaddoor.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -47,7 +50,7 @@ namespace ESM4 Flag_MinimalUse = 0x08 }; - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -67,6 +70,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_DOOR4; }; } diff --git a/components/esm4/loadingr.cpp b/components/esm4/loadingr.cpp index 33ced513bc..41a8a92f9f 100644 --- a/components/esm4/loadingr.cpp +++ b/components/esm4/loadingr.cpp @@ -34,8 +34,7 @@ void ESM4::Ingredient::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadingr.hpp b/components/esm4/loadingr.hpp index 9a80d52824..e34172a035 100644 --- a/components/esm4/loadingr.hpp +++ b/components/esm4/loadingr.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "effect.hpp" namespace ESM4 @@ -53,7 +56,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -74,6 +77,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_INGR4; }; } diff --git a/components/esm4/loadligh.cpp b/components/esm4/loadligh.cpp index f0b15e5a2a..539384f2be 100644 --- a/components/esm4/loadligh.cpp +++ b/components/esm4/loadligh.cpp @@ -33,9 +33,7 @@ void ESM4::Light::load(ESM4::Reader& reader) { - FormId formId = reader.hdr().record.getFormId(); - reader.adjustFormId(formId); - mId = ESM::RefId::formIdRefId(formId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadmisc.cpp b/components/esm4/loadmisc.cpp index dbb136298c..5f48a38eb3 100644 --- a/components/esm4/loadmisc.cpp +++ b/components/esm4/loadmisc.cpp @@ -33,8 +33,7 @@ void ESM4::MiscItem::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmisc.hpp b/components/esm4/loadmisc.hpp index 07e8b18f79..c0468f26bb 100644 --- a/components/esm4/loadmisc.hpp +++ b/components/esm4/loadmisc.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -47,7 +50,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -68,6 +71,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_MISC4; }; } diff --git a/components/esm4/loadstat.cpp b/components/esm4/loadstat.cpp index 5dcff407ec..d1aa4dc054 100644 --- a/components/esm4/loadstat.cpp +++ b/components/esm4/loadstat.cpp @@ -34,9 +34,7 @@ void ESM4::Static::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); - mId = ESM::RefId::formIdRefId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadweap.cpp b/components/esm4/loadweap.cpp index 5feec1c8ba..04dff6eb01 100644 --- a/components/esm4/loadweap.cpp +++ b/components/esm4/loadweap.cpp @@ -33,8 +33,7 @@ void ESM4::Weapon::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getRefIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadweap.hpp b/components/esm4/loadweap.hpp index 52c8c22d17..9cd0861181 100644 --- a/components/esm4/loadweap.hpp +++ b/components/esm4/loadweap.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "formid.hpp" namespace ESM4 @@ -72,7 +75,7 @@ namespace ESM4 } }; - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -97,6 +100,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_WEAP4; }; } diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index 220cf6914e..b0b7e3155a 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -603,7 +603,7 @@ namespace ESM4 // FIXME: Apparently ModIndex '00' in an ESP means the object is defined in one of its masters. // This means we may need to search multiple times to get the correct id. // (see https://www.uesp.net/wiki/Tes4Mod:Formid#ModIndex_Zero) - void Reader::adjustFormId(FormId& id) + void Reader::adjustFormId(FormId& id) const { if (id.hasContentFile() && id.mContentFile < static_cast(mCtx.parentFileIndices.size())) id.mContentFile = mCtx.parentFileIndices[id.mContentFile]; @@ -611,7 +611,7 @@ namespace ESM4 id.mContentFile = mCtx.modIndex; } - void Reader::adjustFormId(FormId32& id) + void Reader::adjustFormId(FormId32& id) const { FormId formId = FormId::fromUint32(id); adjustFormId(formId); @@ -629,6 +629,13 @@ namespace ESM4 return true; } + ESM::FormIdRefId Reader::getRefIdFromHeader() const + { + FormId formId = hdr().record.getFormId(); + adjustFormId(formId); + return ESM::FormIdRefId(formId); + } + void Reader::adjustGRUPFormId() { adjustFormId(mCtx.recordHeader.group.label.value); diff --git a/components/esm4/reader.hpp b/components/esm4/reader.hpp index b6b4b6017e..c24319be0d 100644 --- a/components/esm4/reader.hpp +++ b/components/esm4/reader.hpp @@ -33,6 +33,7 @@ #include "common.hpp" #include "loadtes4.hpp" +#include #include #include @@ -333,12 +334,13 @@ namespace ESM4 } // ModIndex adjusted formId according to master file dependencies - void adjustFormId(FormId& id); + void adjustFormId(FormId& id) const; // Temporary. Doesn't support mod index > 255 - void adjustFormId(FormId32& id); + void adjustFormId(FormId32& id) const; bool getFormId(FormId& id); + ESM::FormIdRefId getRefIdFromHeader() const; void adjustGRUPFormId();