From a58601fb2bba6471190afa96d1d05928f954af52 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 26 Feb 2017 16:59:53 +0200 Subject: [PATCH] [Client] Delineate tes3mp-only code more clearly, part 1 --- apps/openmw/engine.cpp | 12 ++++- apps/openmw/mwbase/world.hpp | 9 +++- apps/openmw/mwgui/container.cpp | 29 ++++++++-- apps/openmw/mwgui/hud.cpp | 22 ++++++-- apps/openmw/mwgui/inventorywindow.cpp | 15 ++++-- apps/openmw/mwgui/spellbuyingwindow.cpp | 11 ++-- apps/openmw/mwgui/spellcreationdialog.cpp | 12 +++-- apps/openmw/mwgui/spellwindow.cpp | 11 ++-- apps/openmw/mwmechanics/npcstats.cpp | 30 +++++++++-- apps/openmw/mwmechanics/npcstats.hpp | 14 +++-- apps/openmw/mwmechanics/security.cpp | 9 +++- apps/openmw/mwscript/animationextensions.cpp | 10 +++- apps/openmw/mwscript/containerextensions.cpp | 12 +++-- apps/openmw/mwscript/dialogueextensions.cpp | 24 ++++++--- apps/openmw/mwscript/interpretercontext.cpp | 53 ++++++++++++++++--- apps/openmw/mwscript/interpretercontext.hpp | 9 +++- apps/openmw/mwscript/miscextensions.cpp | 40 ++++++++++++-- apps/openmw/mwscript/soundextensions.cpp | 10 +++- apps/openmw/mwscript/statsextensions.cpp | 24 ++++++--- .../mwscript/transformationextensions.cpp | 20 ++++++- apps/openmw/mwworld/actiontake.cpp | 14 ++++- apps/openmw/mwworld/livecellref.hpp | 9 +++- apps/openmw/mwworld/scene.cpp | 42 ++++++++++++--- apps/openmw/mwworld/worldimp.cpp | 27 ++++++++-- apps/openmw/mwworld/worldimp.hpp | 9 +++- 25 files changed, 402 insertions(+), 75 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 40e81c7e6..3da83c4b9 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -82,11 +82,21 @@ void OMW::Engine::executeLocalScripts() MWScript::InterpreterContext interpreterContext ( &script.second.getRefData().getLocals(), script.second); - // Added by tes3mp to check and set whether packets should be sent about this script + /* + Start of tes3mp addition + + By comparing its name with a list of script names, check if this script + is allowed to send packets about its value changes + + If it is, set a tes3mp-only boolean to true in its interpreterContext + */ if (mwmp::Main::isValidPacketScript(script.first)) { interpreterContext.sendPackets = true; } + /* + End of tes3mp addition + */ mEnvironment.getScriptManager()->run (script.first, interpreterContext); } diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 60d405307..3e6a9ecc0 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -408,8 +408,15 @@ namespace MWBase /// @note throws an exception when invoked on a teleport door virtual void activateDoor(const MWWorld::Ptr& door, int state) = 0; - // Added by tes3mp to allow saving a door state received from a packet + /* + Start of tes3mp addition + + Useful self-contained method for saving door states + */ virtual void saveDoorState(const MWWorld::Ptr& door, int state) = 0; + /* + End of tes3mp addition + */ virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 999578105..7ad7e007a 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -101,7 +101,12 @@ namespace MWGui if (!onTakeItem(mModel->getItem(mSelectedItem), count)) return; - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_CONTAINER packet every time an item starts being dragged + from a container + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::REMOVE; @@ -129,6 +134,9 @@ namespace MWGui worldEvent->cell.getDescription().c_str(), containerItem.refId.c_str(), containerItem.count); + /* + End of tes3mp addition + */ mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count); } @@ -156,7 +164,11 @@ namespace MWGui } } - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_CONTAINER packet every time an item is dropped in a container + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::ADD; @@ -186,6 +198,9 @@ namespace MWGui worldEvent->cell.getDescription().c_str(), containerItem.refId.c_str(), containerItem.count); + /* + End of tes3mp addition + */ mDragAndDrop->drop(mModel, mItemView); } @@ -306,7 +321,12 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_CONTAINER packet every time the Take All button is used on + a container + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::SET; @@ -322,6 +342,9 @@ namespace MWGui worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str()); + /* + End of tes3mp addition + */ } } diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 5d1e97bb5..35cd9e46f 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -66,7 +66,12 @@ namespace MWGui cellStore->setLastRefNumIndex(cellStore->getLastRefNumIndex() + 1); dropped.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex()); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_PLACE packet every time an object is dropped into the world from + the inventory screen + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *dropped.getCell()->getCell(); @@ -94,6 +99,9 @@ namespace MWGui worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.count); + /* + End of tes3mp addition + */ return dropped; } @@ -288,10 +296,16 @@ namespace MWGui WorldItemModel drop (mouseX, mouseY); mDragAndDrop->drop(&drop, NULL); - // Added by tes3mp - // - // LocalPlayer's inventory has changed, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_INVENTORY packet every time a player loses an item + by dropping it in the world + */ mwmp::Main::get().getLocalPlayer()->sendInventory(); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWindowManager()->changePointer("arrow"); } diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index d8ce07a43..cf3d0e2d7 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -635,7 +635,15 @@ namespace MWGui // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object MWWorld::Ptr newObject = *player.getClass().getContainerStore (player).add (object, object.getRefData().getCount(), player); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_DELETE packet every time an item from the world is picked up + by the player through the inventory HUD + + Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained + by the player + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *object.getCell()->getCell(); @@ -645,9 +653,10 @@ namespace MWGui worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(worldEvent); - - // LocalPlayer's inventory has changed, so send a packet with it mwmp::Main::get().getLocalPlayer()->sendInventory(); + /* + End of tes3mp addition + */ // remove from world MWBase::Environment::get().getWorld()->deleteObject (object); diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 6116e199b..2a6530cd9 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -144,10 +144,15 @@ namespace MWGui MWMechanics::Spells& spells = stats.getSpells(); spells.add (mSpellsWidgetMap.find(_sender)->second); - // Added by tes3mp - // - // LocalPlayer has gained a spell, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_SPELLBOOK packet every time a player buys a spell + */ mwmp::Main::get().getLocalPlayer()->sendSpellAddition(mSpellsWidgetMap.find(_sender)->second); + /* + End of tes3mp addition + */ player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price, player); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 21f1cb8b7..4da04118e 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -407,10 +407,16 @@ namespace MWGui MWMechanics::Spells& spells = stats.getSpells(); spells.add (spell->mId); - // Added by tes3mp - // - // LocalPlayer has gained a spell, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_SPELLBOOK packet every time a player buys a custom spell from + the Spellmaking screen + */ mwmp::Main::get().getLocalPlayer()->sendSpellAddition(*spell); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_SpellCreation); } diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 553bcfdd6..84a39ba7d 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -189,10 +189,15 @@ namespace MWGui spells.remove(mSpellToDelete); - // Added by tes3mp - // - // LocalPlayer has lost a spell, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_SPELLBOOK packet every time a player deletes one of their spells + */ mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(mSpellToDelete); + /* + End of tes3mp addition + */ updateSpells(); } diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index f0994f509..e9ca8f474 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -284,23 +284,47 @@ int MWMechanics::NpcStats::getLevelProgress () const return mLevelProgress; } -// Added by tes3mp +/* + Start of tes3mp addition + + Make it possible to set a player's level progress directly instead of going + through other methods +*/ void MWMechanics::NpcStats::setLevelProgress(int value) { mLevelProgress = value; } +/* + End of tes3mp addition +*/ + +/* + Start of tes3mp addition -// Added by tes3mp + Make it possible to get a player's skill increases for an attribute directly + instead of going through other methods +*/ int MWMechanics::NpcStats::getSkillIncrease(int attribute) const { return mSkillIncreases[attribute]; } +/* + End of tes3mp addition +*/ + +/* + Start of tes3mp addition -// Added by tes3mp + Make it possible to set a player's skill increases for an attribute directly + instead of going through other methods +*/ void MWMechanics::NpcStats::setSkillIncrease(int attribute, int value) { mSkillIncreases[attribute] = value; } +/* + End of tes3mp addition +*/ void MWMechanics::NpcStats::levelUp() { diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 42aa2ca1e..515772bb5 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -84,10 +84,18 @@ namespace MWMechanics void increaseSkill (int skillIndex, const ESM::Class& class_, bool preserveProgress); int getLevelProgress() const; - void setLevelProgress(int value); // Added by tes3mp - int getSkillIncrease(int attribute) const; // Added by tes3mp - void setSkillIncrease(int attribute, int value); // Added by tes3mp + /* + Start of tes3mp addition + + Useful methods for setting player stats + */ + void setLevelProgress(int value); + int getSkillIncrease(int attribute) const; + void setSkillIncrease(int attribute, int value); + /* + End of tes3mp addition + */ int getLevelupAttributeMultiplier(int attribute) const; diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 39434be0d..f8d2d26a3 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -58,7 +58,11 @@ namespace MWMechanics MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, lock); if (Misc::Rng::roll0to99() <= x) { - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_UNLOCK packet every time an object is unlocked + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *lock.getCell()->getCell(); @@ -68,6 +72,9 @@ namespace MWMechanics worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(worldEvent); + /* + End of tes3mp addition + */ lock.getClass().unlock(lock); resultMessage = "#{sLockSuccess}"; diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index 1a87723ff..defa3e1eb 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -63,7 +63,12 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - // Added by tes3mp to check and set whether packets should be sent about this script + /* + Start of tes3mp addition + + Send an ID_OBJECT_ANIM_PLAY every time an animation is played for an object + through an approved script + */ if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr))) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); @@ -78,6 +83,9 @@ namespace MWScript mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->Send(worldEvent); } + /* + End of tes3mp addition + */ MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, std::numeric_limits::max(), true); } diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 277710487..5dcc7cb4f 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -70,10 +70,16 @@ namespace MWScript // Spawn a messagebox (only for items added to player's inventory and if player is talking to someone) if (ptr == MWBase::Environment::get().getWorld ()->getPlayerPtr() ) { - // Added by tes3mp - // - // LocalPlayer's inventory has changed, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_INVENTORY packet every time a player gains an item + through a script + */ mwmp::Main::get().getLocalPlayer()->sendInventory(); + /* + End of tes3mp addition + */ // The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory std::string msgBox; diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index b52b95508..ff05ee9f4 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -47,10 +47,16 @@ namespace MWScript { MWBase::Environment::get().getJournal()->addEntry (quest, index, ptr); - // Added by tes3mp - // - // LocalPlayer has gained a journal entry, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_JOURNAL packet every time a journal entry is added + through a script + */ mwmp::Main::get().getLocalPlayer()->sendJournalEntry(quest, index, ptr); + /* + End of tes3mp addition + */ } catch (...) { @@ -74,10 +80,16 @@ namespace MWScript MWBase::Environment::get().getJournal()->setJournalIndex (quest, index); - // Added by tes3mp - // - // LocalPlayer has gained a journal index, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_JOURNAL packet every time a journal index is set + through a script + */ mwmp::Main::get().getLocalPlayer()->sendJournalIndex(quest, index); + /* + End of tes3mp addition + */ } }; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 32939063e..7172b5dea 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -151,8 +151,16 @@ namespace MWScript if (targetId.empty() && !reference.isEmpty()) mTargetId = reference.getCellRef().getRefId(); - // Added by tes3mp + /* + Start of tes3mp addition + + Boolean used to check whether value change packets should be sent for the + script being processed by the InterpreterContext + */ sendPackets = false; + /* + End of tes3mp addition + */ } int InterpreterContext::getLocalShort (int index) const @@ -186,7 +194,12 @@ namespace MWScript mLocals->mShorts.at (index) = value; - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_SCRIPT_LOCAL_SHORT packet every time a local short changes its value + in a script approved for packet sending + */ if (sendPackets) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); @@ -208,6 +221,9 @@ namespace MWScript worldObject.index, worldObject.shortVal); } + /* + End of tes3mp addition + */ } void InterpreterContext::setLocalLong (int index, int value) @@ -225,9 +241,13 @@ namespace MWScript mLocals->mFloats.at (index) = value; - // Added by tes3mp - // - // Only send a packet if this float has no decimals (to avoid spam) + /* + Start of tes3mp addition + + Send an ID_SCRIPT_LOCAL_FLOAT packet every time a local float changes its value + to one without decimals (to avoid packet spam for timers) in a script approved + for packet sending + */ if (sendPackets && value == (int) value) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); @@ -249,6 +269,9 @@ namespace MWScript worldObject.index, worldObject.floatVal); } + /* + End of tes3mp addition + */ } void InterpreterContext::messageBox (const std::string& message, @@ -292,7 +315,12 @@ namespace MWScript void InterpreterContext::setGlobalShort (const std::string& name, int value) { - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_SCRIPT_GLOBAL_SHORT packet every time a global short changes its value + in a script approved for packet sending + */ if (sendPackets) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); @@ -308,6 +336,9 @@ namespace MWScript worldObject.varName.c_str(), worldObject.shortVal); } + /* + End of tes3mp addition + */ MWBase::Environment::get().getWorld()->setGlobalInt (name, value); } @@ -629,7 +660,12 @@ namespace MWScript locals.mShorts[index] = value; - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_SCRIPT_MEMBER_SHORT packet every time a member short changes its value + in a script approved for packet sending + */ if (sendPackets && !global) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); @@ -647,6 +683,9 @@ namespace MWScript worldObject.index, worldObject.shortVal); } + /* + End of tes3mp addition + */ } void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global) diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 55c4e4efe..f70add679 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -55,8 +55,15 @@ namespace MWScript const std::string& targetId = ""); ///< The ownership of \a locals is not transferred. 0-pointer allowed. - // Added by tes3mp + /* + Start of tes3mp addition + + Useful boolean for setting whether scripts send packets + */ bool sendPackets; + /* + End of tes3mp addition + */ virtual int getLocalShort (int index) const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 1ab485437..eb9b9093e 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -89,7 +89,12 @@ namespace MWScript bool allowSkipping = runtime[0].mInteger != 0; runtime.pop(); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_VIDEO_PLAY packet every time a video is played + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldObject worldObject; @@ -98,6 +103,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(worldEvent); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWindowManager()->playVideo (name, allowSkipping); } @@ -197,7 +205,12 @@ namespace MWScript runtime.pop(); } - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_LOCK packet every time an object is locked + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *ptr.getCell()->getCell(); @@ -208,6 +221,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(worldEvent); + /* + End of tes3mp addition + */ ptr.getClass().lock (ptr, lockLevel); @@ -235,7 +251,12 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_UNLOCK packet every time an object is unlocked + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *ptr.getCell()->getCell(); @@ -245,6 +266,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(worldEvent); + /* + End of tes3mp addition + */ ptr.getClass().unlock (ptr); } @@ -706,7 +730,12 @@ namespace MWScript if (parameter == 1) { - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_DELETE packet every time an object is deleted + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *ptr.getCell()->getCell(); @@ -716,6 +745,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(worldEvent); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWorld()->deleteObject(ptr); } diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 973a071f2..b9c0eb1f9 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -70,7 +70,12 @@ namespace MWScript std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_MUSIC_PLAY packet every time new music is streamed through + a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldObject worldObject; @@ -78,6 +83,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(worldEvent); + /* + End of tes3mp addition + */ MWBase::Environment::get().getSoundManager()->streamMusic (sound); } diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 8b327f94a..59b6d5829 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -446,11 +446,17 @@ namespace MWScript ptr.getClass().getCreatureStats (ptr).getSpells().add (id); - // Added by tes3mp - // - // LocalPlayer has gained a spell, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_SPELLBOOK packet every time a player gains a spell + through a script + */ if (ptr == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->sendSpellAddition(id); + /* + End of tes3mp addition + */ } }; @@ -476,11 +482,17 @@ namespace MWScript wm->unsetSelectedSpell(); } - // Added by tes3mp - // - // LocalPlayer has lost a spell, so send a packet with it + /* + Start of tes3mp addition + + Send an ID_PLAYER_SPELLBOOK packet every time a player loses a spell + through a script + */ if (ptr == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(id); + /* + End of tes3mp addition + */ } }; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index a8e88e063..612663b5a 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -46,7 +46,12 @@ namespace MWScript Interpreter::Type_Float scale = runtime[0].mFloat; runtime.pop(); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_SCALE every time an object's scale is changed + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *ptr.getCell()->getCell(); @@ -57,6 +62,9 @@ namespace MWScript worldEvent->addObject(worldObject); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(worldEvent); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); } @@ -549,7 +557,12 @@ namespace MWScript cellStore->setLastRefNumIndex(cellStore->getLastRefNumIndex() + 1); ptr.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex()); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_PLACE packet every time an object is placed in the world + through a script + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *ptr.getCell()->getCell(); @@ -571,6 +584,9 @@ namespace MWScript worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.count); + /* + End of tes3mp addition + */ } } }; diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index c75cb53ed..29eb419eb 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -25,7 +25,15 @@ namespace MWWorld actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); MWWorld::Ptr newitem = *actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_OBJECT_DELETE packet every time an item is taken from the world + by the player outside of the inventory screen + + Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained + by the player + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *getTarget().getCell()->getCell(); @@ -41,8 +49,10 @@ namespace MWWorld worldObject.refNumIndex, worldEvent->cell.getDescription().c_str()); - // LocalPlayer's inventory has changed, so send a packet with it mwmp::Main::get().getLocalPlayer()->sendInventory(); + /* + End of tes3mp addition + */ MWBase::Environment::get().getWorld()->deleteObject (getTarget()); setTarget(newitem); diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index 91495eed2..493f2e4ca 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -28,10 +28,15 @@ namespace MWWorld */ MWWorld::CellRef mRef; - /* Added by tes3mp to prevent dedicated players' references from automatically - * and unpredictably moving across exterior cell boundaries on clients + /* + Start of tes3mp addition + + Useful boolean for stopping momentum-based cell changes not approved by server */ bool canChangeCell; + /* + End of tes3mp addition + */ /** runtime-data */ RefData mData; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index a95ad05a6..2c7a86379 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -259,10 +259,15 @@ namespace MWWorld MWBase::Environment::get().getSoundManager()->stopSound (*iter); mActiveCells.erase(*iter); - // Added by tes3mp - // - // LocalPlayer has unloaded a cell, so store it + /* + Start of tes3mp addition + + Store a cell unload for the LocalPlayer + */ mwmp::Main::get().getLocalPlayer()->storeCellState(*(*iter)->getCell(), mwmp::CellState::UNLOAD); + /* + End of tes3mp addition + */ } void Scene::loadCell (CellStore *cell, Loading::Listener* loadingListener, bool respawn) @@ -332,10 +337,15 @@ namespace MWWorld if (!cell->isExterior() && !(cell->getCell()->mData.mFlags & ESM::Cell::QuasiEx)) mRendering.configureAmbient(cell->getCell()); - // Added by tes3mp - // - // LocalPlayer has loaded a cell, so store it + /* + Start of tes3mp addition + + Store a cell load for the LocalPlayer + */ mwmp::Main::get().getLocalPlayer()->storeCellState(*cell->getCell(), mwmp::CellState::LOAD); + /* + End of tes3mp addition + */ } mPreloader->notifyLoaded(cell); @@ -452,12 +462,20 @@ namespace MWWorld } } - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_PLAYER_CELL_STATE packet with all cell states stored in LocalPlayer + and then clear them, but only if the player has finished character generation + */ if (mwmp::Main::get().getLocalPlayer()->hasFinishedCharGen()) { mwmp::Main::get().getLocalPlayer()->sendCellStates(); mwmp::Main::get().getLocalPlayer()->clearCellStates(); } + /* + End of tes3mp addition + */ CellStore* current = MWBase::Environment::get().getWorld()->getExterior(X,Y); MWBase::Environment::get().getWindowManager()->changeCell(current); @@ -588,12 +606,20 @@ namespace MWWorld // Load cell. loadCell (cell, loadingListener, changeEvent); - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_PLAYER_CELL_STATE packet with all cell states stored in LocalPlayer + and then clear them, but only if the player has finished character generation + */ if (mwmp::Main::get().getLocalPlayer()->hasFinishedCharGen()) { mwmp::Main::get().getLocalPlayer()->sendCellStates(); mwmp::Main::get().getLocalPlayer()->clearCellStates(); } + /* + End of tes3mp addition + */ changePlayerCell(cell, position, adjustPlayerPos); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index acd3dd0b0..c9ef6b987 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2320,7 +2320,11 @@ namespace MWWorld break; } - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_DOOR_STATE packet every time a door is activated + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *door.getCell()->getCell(); @@ -2337,6 +2341,9 @@ namespace MWWorld worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), worldObject.doorState ? "true" : "false"); + /* + End of tes3mp addition + */ door.getClass().setDoorState(door, state); mDoorStates[door] = state; @@ -2344,7 +2351,11 @@ namespace MWWorld void World::activateDoor(const Ptr &door, int state) { - // Added by tes3mp + /* + Start of tes3mp addition + + Send an ID_DOOR_STATE packet every time a door is activated + */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); worldEvent->cell = *door.getCell()->getCell(); @@ -2361,6 +2372,9 @@ namespace MWWorld worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), worldObject.doorState ? "true" : "false"); + /* + End of tes3mp addition + */ door.getClass().setDoorState(door, state); mDoorStates[door] = state; @@ -2368,13 +2382,20 @@ namespace MWWorld mDoorStates.erase(door); } - // Added by tes3mp to allow saving a door state received from a packet + /* + Start of tes3mp addition + + Allow the saving of door states without going through World::activateDoor() + */ void World::saveDoorState(const Ptr &door, int state) { mDoorStates[door] = state; if (state == 0) mDoorStates.erase(door); } + /* + End of tes3mp addition + */ bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object) { diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 0cd4c6746..ee566595a 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -524,8 +524,15 @@ namespace MWWorld /// @note throws an exception when invoked on a teleport door virtual void activateDoor(const MWWorld::Ptr& door, int state); - // Added by tes3mp to allow saving a door state received from a packet + /* + Start of tes3mp addition + + Useful self-contained method for saving door states + */ virtual void saveDoorState(const MWWorld::Ptr& door, int state); + /* + End of tes3mp addition + */ virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object); ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object); ///< @return true if any actor is standing on \a object