diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index b436fae75..73e30ef19 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -7,6 +7,7 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/combat.hpp" +#include "../mwmechanics/levelledlist.hpp" #include "../mwmechanics/spellcasting.hpp" #include "../mwworld/class.hpp" @@ -14,9 +15,11 @@ #include "MechanicsHelper.hpp" #include "Main.hpp" +#include "Networking.hpp" #include "LocalPlayer.hpp" #include "DedicatedPlayer.hpp" #include "PlayerList.hpp" +#include "WorldEvent.hpp" #include "CellController.hpp" using namespace mwmp; @@ -38,6 +41,34 @@ osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f return (start + osg::componentMultiply(position, (end - start))); } +// Inspired by similar code in mwclass\creaturelevlist.cpp +void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore) +{ + MWWorld::CellRefList *creatureLevList = cellStore->getCreatureLists(); + + for (typename MWWorld::CellRefList::List::iterator listIter(creatureLevList->mList.begin()); + listIter != creatureLevList->mList.end(); ++listIter) + { + MWWorld::Ptr ptr(&*listIter, cellStore); + + MWWorld::LiveCellRef *ref = ptr.get(); + + std::string id = MWMechanics::getLevelledItem(ref->mBase, true); + + if (!id.empty()) + { + const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + MWWorld::ManualRef manualRef(store, id); + manualRef.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition()); + MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(manualRef.getPtr(), ptr.getCell(), ptr.getCellRef().getPosition()); + + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->sendObjectPlace(placed); + MWBase::Environment::get().getWorld()->deleteObject(placed); + } + } +} + Attack *MechanicsHelper::getLocalAttack(const MWWorld::Ptr& ptr) { if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index 9b534e51e..02584686f 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -16,6 +16,8 @@ namespace mwmp osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent); + void spawnLeveledCreatures(MWWorld::CellStore* cellStore); + Attack *getLocalAttack(const MWWorld::Ptr& ptr); Attack *getDedicatedAttack(const MWWorld::Ptr& ptr); diff --git a/apps/openmw/mwmp/processors/actor/ProcessorActorList.hpp b/apps/openmw/mwmp/processors/actor/ProcessorActorList.hpp index 1d2af872f..6b13287e5 100644 --- a/apps/openmw/mwmp/processors/actor/ProcessorActorList.hpp +++ b/apps/openmw/mwmp/processors/actor/ProcessorActorList.hpp @@ -8,6 +8,7 @@ #include "apps/openmw/mwmp/ActorProcessor.hpp" #include "apps/openmw/mwmp/Main.hpp" #include "apps/openmw/mwmp/CellController.hpp" +#include "apps/openmw/mwmp/MechanicsHelper.hpp" namespace mwmp { @@ -30,7 +31,10 @@ namespace mwmp // If we've received a request for information, comply with it if (actorList.action == mwmp::BaseActorList::REQUEST) + { + mwmp::Main::get().getMechanicsHelper()->spawnLeveledCreatures(ptrCellStore); actorList.sendActorsInCell(ptrCellStore); + } } }; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 917dbc61b..ba33f8f68 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -526,6 +526,12 @@ namespace MWWorld return &mCreatures; } + // Added by tes3mp and used to get all the creatures in the cell + CellRefList *CellStore::getCreatureLists() + { + return &mCreatureLists; + } + // Added by tes3mp and used to get all the containers in the cell CellRefList *CellStore::getContainers() { diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 8bbaaacfc..ef1e0fa3d 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -243,6 +243,9 @@ namespace MWWorld CellRefList *getCreatures(); // Added by tes3mp and used to get all the creatures in the cell + CellRefList *getCreatureLists(); + // Added by tes3mp and used to get all the leveled creature lists in the cell + CellRefList *getContainers(); // Added by tes3mp and used to get all the containers in the cell