From 18a7ac5940c65a417accc8594cf3a20672b6745d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 28 Sep 2019 13:10:43 +0300 Subject: [PATCH] [Client] Make it possible to override Cell records in ESMStore --- apps/openmw/mwworld/esmstore.hpp | 14 +++++++++++++ apps/openmw/mwworld/store.cpp | 36 ++++++++++++++++++++++++++++++++ apps/openmw/mwworld/store.hpp | 10 +++++++++ 3 files changed, 60 insertions(+) diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index d170a32c5..e90ca1ef9 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -241,6 +241,20 @@ namespace MWWorld ///< \return Known type? }; + /* + Start of tes3mp addition + + Make it possible to override a cell record similarly to how + other types of records can be overridden + */ + template <> + inline const ESM::Cell *ESMStore::overrideRecord(const ESM::Cell &cell) { + return mCells.override(cell); + } + /* + End of tes3mp addition + */ + template <> inline const ESM::Cell *ESMStore::insert(const ESM::Cell &cell) { return mCells.insert(cell); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 444650217..c101c6b9e 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -801,6 +801,42 @@ namespace MWWorld list.push_back(sharedCell->mName); } } + /* + Start of tes3mp addition + + Make it possible to override a cell record similarly to how + other types of records can be overridden + */ + ESM::Cell *Store::override(const ESM::Cell &cell) + { + if (search(cell) != 0) + { + for (auto it = mSharedInt.begin(); it != mSharedInt.end(); ++it) + { + if (Misc::StringUtils::ciEqual((*it)->mName, cell.mName)) + { + (*it) = &const_cast(cell); + break; + } + } + + for (auto it = mInt.begin(); it != mInt.end(); ++it) + { + if (Misc::StringUtils::ciEqual((*it).second.mName, cell.mName)) + { + (*it).second = cell; + return &(*it).second; + } + } + } + else + { + return insert(cell); + } + } + /* + End of tes3mp addition + */ ESM::Cell *Store::insert(const ESM::Cell &cell) { if (search(cell) != 0) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index c595e3ecb..97e927afb 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -315,6 +315,16 @@ namespace MWWorld void listIdentifier(std::vector &list) const; + /* + Start of tes3mp addition + + Make it possible to override a cell record similarly to how + other types of records can be overridden + */ + ESM::Cell *override(const ESM::Cell &cell); + /* + End of tes3mp addition + */ ESM::Cell *insert(const ESM::Cell &cell); bool erase(const ESM::Cell &cell);