From d4a12856ee5e0882d8301976f65fb75b2b9d0edf Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 6 Apr 2017 04:59:55 +0300 Subject: [PATCH] [Client] Enable AI for LocalActors --- apps/openmw/mwmechanics/actors.cpp | 13 ++++++++++++- apps/openmw/mwmp/Cell.cpp | 12 ++++++++++++ apps/openmw/mwmp/Cell.hpp | 1 + apps/openmw/mwmp/CellController.cpp | 1 + apps/openmw/mwworld/livecellref.cpp | 9 +++++++++ apps/openmw/mwworld/livecellref.hpp | 11 +++++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index fcb6a20e2..bda1c6383 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1131,7 +1131,18 @@ namespace MWMechanics return; // for now abort update of the old cell when cell changes by teleportation magic effect // a better solution might be to apply cell changes at the end of the frame } - if (MWBase::Environment::get().getMechanicsManager()->isAIActive() && inProcessingRange) + /* + Start of tes3mp change (major) + + Allow AI processing when LiveCellRefBase's isLocalActor set to true + */ + //if (MWBase::Environment::get().getMechanicsManager()->isAIActive() && inProcessingRange) + + if ((MWBase::Environment::get().getMechanicsManager()->isAIActive() || actor.getBase()->isLocalActor) + && inProcessingRange) + /* + End of tes3mp change (major) + */ { if (timerUpdateAITargets == 0) { diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index d26586e17..4b3f4605f 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -54,11 +54,23 @@ void Cell::initializeLocalActors() std::string mapIndex = generateMapIndex(ptr); localActors[mapIndex] = new LocalActor(); localActors[mapIndex]->cell = esmCell; + ptr.getBase()->isLocalActor = true; localActors[mapIndex]->setPtr(ptr); LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str()); } } +void Cell::uninitializeLocalActors() +{ + for (std::map::iterator it = localActors.begin(); it != localActors.end(); ++it) + { + LocalActor *actor = it->second; + actor->getPtr().getBase()->isLocalActor = false; + } + + localActors.clear(); +} + std::string Cell::generateMapIndex(MWWorld::Ptr ptr) { std::string mapIndex = ""; diff --git a/apps/openmw/mwmp/Cell.hpp b/apps/openmw/mwmp/Cell.hpp index 34db2ab9f..a7c110d7d 100644 --- a/apps/openmw/mwmp/Cell.hpp +++ b/apps/openmw/mwmp/Cell.hpp @@ -16,6 +16,7 @@ namespace mwmp void update(); void initializeLocalActors(); + void uninitializeLocalActors(); std::string generateMapIndex(MWWorld::Ptr ptr); diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index 7d7205abd..af99ae19b 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -30,6 +30,7 @@ void CellController::update() if (!MWBase::Environment::get().getWorld()->isCellActive(mpCell->getCellStore())) { + mpCell->uninitializeLocalActors(); it = cellsActive.erase(it); } else diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 66d1c8d70..48ec0ac91 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -14,7 +14,16 @@ MWWorld::LiveCellRefBase::LiveCellRefBase(const std::string& type, const ESM::CellRef &cref) : mClass(&Class::get(type)), mRef(cref), mData(cref) { + /* + Start of tes3mp addition + + Set default values for tes3mp-only booleans + */ canChangeCell = true; + isLocalActor = false; + /* + End of tes3mp addition + */ } void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state) diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index 493f2e4ca..a42baf732 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -38,6 +38,17 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Useful boolean for quickly establishing which creatures and NPCs should be + processed locally by the player + */ + bool isLocalActor; + /* + End of tes3mp addition + */ + /** runtime-data */ RefData mData;