From 0f30e21312691cc30655395d2111f19823162856 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 10 Jul 2018 11:30:32 +0300 Subject: [PATCH] [Client] Add searchPtrViaRefIndex method to World to easily find objects --- apps/openmw/mwbase/world.hpp | 10 ++++++++++ apps/openmw/mwworld/worldimp.cpp | 24 ++++++++++++++++++++++++ apps/openmw/mwworld/worldimp.hpp | 10 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 4336ccbc0..5e3f6739d 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -184,6 +184,16 @@ namespace MWBase virtual MWWorld::Ptr searchPtrViaActorId (int actorId) = 0; ///< Search is limited to the active cells. + /* + Start of tes3mp addition + + Make it possible to find a Ptr in any active cell based on its refNumIndex and mpNum + */ + virtual MWWorld::Ptr searchPtrViaRefIndex(int refNumIndex, int mpNum) = 0; + /* + End of tes3mp addition + */ + virtual MWWorld::Ptr findContainer (const MWWorld::ConstPtr& ptr) = 0; ///< Return a pointer to a liveCellRef which contains \a ptr. /// \note Search is limited to the active cells. diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c0fbb2305..cf91ca57b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -729,6 +729,30 @@ namespace MWWorld return mWorldScene->searchPtrViaActorId (actorId); } + /* + Start of tes3mp addition + + Make it possible to find a Ptr in any active cell based on its refNumIndex and mpNum + */ + Ptr World::searchPtrViaRefIndex(int refNumIndex, int mpNum) + { + for (Scene::CellStoreCollection::const_iterator iter(mWorldScene->getActiveCells().begin()); + iter != mWorldScene->getActiveCells().end(); ++iter) + { + CellStore* cellStore = *iter; + + MWWorld::Ptr ptrFound = cellStore->searchExact(refNumIndex, mpNum); + + if (ptrFound) + return ptrFound; + } + + return nullptr; + } + /* + End of tes3mp addition + */ + struct FindContainerVisitor { ConstPtr mContainedPtr; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index ab6c3f04a..223cd777f 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -291,6 +291,16 @@ namespace MWWorld Ptr searchPtrViaActorId (int actorId) override; ///< Search is limited to the active cells. + /* + Start of tes3mp addition + + Make it possible to find a Ptr in any active cell based on its refNumIndex and mpNum + */ + Ptr searchPtrViaRefIndex(int refNumIndex, int mpNum) override; + /* + End of tes3mp addition + */ + MWWorld::Ptr findContainer (const MWWorld::ConstPtr& ptr) override; ///< Return a pointer to a liveCellRef which contains \a ptr. /// \note Search is limited to the active cells.