From 87c84e6fcdc04f1935ba8f10cddf32b5a95a09c4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 13:29:49 +0200 Subject: [PATCH 1/8] limited activation range according to GMST settings --- apps/openmw/engine.cpp | 10 ++++------ apps/openmw/mwworld/world.cpp | 11 +++++++++++ apps/openmw/mwworld/world.hpp | 5 +++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 8734ffaada..3c6eb6f16a 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -74,22 +74,20 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) if (focusFrameCounter++ == focusUpdateFrame) { - std::pair handle = mEnvironment.mWorld->getMWScene()->getFacedHandle(); + std::string handle = mEnvironment.mWorld->getFacedHandle(); std::string name; - if (!handle.first.empty()) + if (!handle.empty()) { - // TODO compare handle.second with max activation range (from a GMST) - - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle.first); + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); if (!ptr.isEmpty()) name = MWWorld::Class::get (ptr).getName (ptr); } if (!name.empty()) - std::cout << "Object: " << name << ", distance: " << handle.second << std::endl; + std::cout << "Object: " << name << std::endl; focusFrameCounter = 0; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 73a9d6ad30..94a6758c75 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -600,4 +600,15 @@ namespace MWWorld { mCellChanged = false; } + + std::string World::getFacedHandle() + { + std::pair result = mScene.getFacedHandle(); + + if (result.first.empty() || + result.second>getStore().gameSettings.find ("iMaxActivateDist")->i) + return ""; + + return result.first; + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 354c3603c3..d201616983 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -83,8 +83,6 @@ namespace MWWorld ~World(); - MWRender::MWScene* getMWScene() { return &mScene; } - MWRender::PlayerPos& getPlayerPos(); ESMS::ESMStore& getStore(); @@ -133,6 +131,9 @@ namespace MWWorld ///< works only for interior cells currently. void markCellAsUnchanged(); + + std::string getFacedHandle(); + ///< Return handle of the object the player is looking at }; } From 2d695cc8065d2faa4226dbcab2774b99948d9a8d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 13:36:33 +0200 Subject: [PATCH 2/8] routed activate signal from input sub-system to engine-class --- apps/openmw/engine.cpp | 7 ++++++- apps/openmw/engine.hpp | 5 ++++- apps/openmw/mwinput/inputmanager.cpp | 14 ++++++++++---- apps/openmw/mwinput/inputmanager.hpp | 8 +++++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3c6eb6f16a..251aeac20d 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -253,7 +253,7 @@ void OMW::Engine::go() // Sets up the input system MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), - *mEnvironment.mWindowManager, mDebug); + *mEnvironment.mWindowManager, mDebug, *this); focusFrameCounter = 0; @@ -266,3 +266,8 @@ void OMW::Engine::go() std::cout << "Quitting peacefully.\n"; } + +void OMW::Engine::activate() +{ + std::cout << "activate" << std::endl; +} diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 412c4fa736..62166e0500 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -111,12 +111,15 @@ namespace OMW /// Enable verbose script output void enableVerboseScripts(); - + /// Start as a new game. void setNewGame(); /// Initialise and enter main loop. void go(); + + /// Activate the focussed object. + void activate(); }; } diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index f851b43b2e..f730150b0b 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -17,6 +17,8 @@ #include #include "../mwrender/playerpos.hpp" +#include "../engine.hpp" + #include #include #include @@ -58,6 +60,7 @@ namespace MWInput OEngine::GUI::EventInjectorPtr guiEvents; MWRender::PlayerPos &player; MWGui::WindowManager &windows; + OMW::Engine& mEngine; // Count screenshots. int shotCount; @@ -137,7 +140,7 @@ namespace MWInput void activate() { - + mEngine.activate(); } // Exit program now button (which is disabled in GUI mode) @@ -151,13 +154,15 @@ namespace MWInput InputImpl(OEngine::Render::OgreRenderer &_ogre, MWRender::PlayerPos &_player, MWGui::WindowManager &_windows, - bool debug) + bool debug, + OMW::Engine& engine) : ogre(_ogre), exit(ogre.getWindow()), input(ogre.getWindow(), !debug), poller(input), player(_player), windows(_windows), + mEngine (engine), shotCount(0) { using namespace OEngine::Input; @@ -275,9 +280,10 @@ namespace MWInput MWInputManager::MWInputManager(OEngine::Render::OgreRenderer &ogre, MWRender::PlayerPos &player, MWGui::WindowManager &windows, - bool debug) + bool debug, + OMW::Engine& engine) { - impl = new InputImpl(ogre,player,windows,debug); + impl = new InputImpl(ogre,player,windows,debug, engine); } MWInputManager::~MWInputManager() diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index 094b848eef..554089588d 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -19,6 +19,11 @@ namespace MWGui class WindowManager; } +namespace OMW +{ + class Engine; +} + namespace MWInput { // Forward declaration of the real implementation. @@ -37,7 +42,8 @@ namespace MWInput MWInputManager(OEngine::Render::OgreRenderer &_ogre, MWRender::PlayerPos &_player, MWGui::WindowManager &_windows, - bool debug); + bool debug, + OMW::Engine& engine); ~MWInputManager(); }; } From f630157bf8222e540e3570722dd011d3d3f701bf Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 13:51:26 +0200 Subject: [PATCH 3/8] implemented basic object activation --- apps/openmw/engine.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 251aeac20d..4e7b3eef7a 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -269,5 +269,19 @@ void OMW::Engine::go() void OMW::Engine::activate() { - std::cout << "activate" << std::endl; + std::string handle = mEnvironment.mWorld->getFacedHandle(); + + if (handle.empty()) + return; + + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + + if (ptr.isEmpty()) + return; + + boost::shared_ptr action = + MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), + mEnvironment); + + action->execute (mEnvironment); } From 7a313f24abc0362955ab90dccd4b60dfc4ff029b Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 15:40:03 +0200 Subject: [PATCH 4/8] integrated activation into script system --- apps/openmw/engine.cpp | 15 ++++++++++++++- apps/openmw/mwclass/activator.cpp | 8 ++++++++ apps/openmw/mwclass/activator.hpp | 3 +++ apps/openmw/mwclass/apparatus.cpp | 8 ++++++++ apps/openmw/mwclass/apparatus.hpp | 3 +++ apps/openmw/mwclass/armor.cpp | 8 ++++++++ apps/openmw/mwclass/armor.hpp | 3 +++ apps/openmw/mwclass/book.cpp | 8 ++++++++ apps/openmw/mwclass/book.hpp | 3 +++ apps/openmw/mwclass/clothing.cpp | 8 ++++++++ apps/openmw/mwclass/clothing.hpp | 3 +++ apps/openmw/mwclass/container.cpp | 8 ++++++++ apps/openmw/mwclass/container.hpp | 3 +++ apps/openmw/mwclass/creature.cpp | 8 ++++++++ apps/openmw/mwclass/creature.hpp | 3 +++ apps/openmw/mwclass/door.cpp | 8 ++++++++ apps/openmw/mwclass/door.hpp | 3 +++ apps/openmw/mwclass/ingredient.cpp | 8 ++++++++ apps/openmw/mwclass/ingredient.hpp | 3 +++ apps/openmw/mwclass/light.cpp | 8 ++++++++ apps/openmw/mwclass/light.hpp | 3 +++ apps/openmw/mwclass/lockpick.cpp | 8 ++++++++ apps/openmw/mwclass/lockpick.hpp | 3 +++ apps/openmw/mwclass/misc.cpp | 8 ++++++++ apps/openmw/mwclass/misc.hpp | 3 +++ apps/openmw/mwclass/npc.cpp | 8 ++++++++ apps/openmw/mwclass/npc.hpp | 3 +++ apps/openmw/mwclass/potion.cpp | 8 ++++++++ apps/openmw/mwclass/potion.hpp | 3 +++ apps/openmw/mwclass/probe.cpp | 8 ++++++++ apps/openmw/mwclass/probe.hpp | 3 +++ apps/openmw/mwclass/repair.cpp | 8 ++++++++ apps/openmw/mwclass/repair.hpp | 3 +++ apps/openmw/mwclass/weapon.cpp | 8 ++++++++ apps/openmw/mwclass/weapon.hpp | 3 +++ apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 4 ++++ 37 files changed, 210 insertions(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 4e7b3eef7a..badb19629d 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -279,9 +279,22 @@ void OMW::Engine::activate() if (ptr.isEmpty()) return; + MWScript::InterpreterContext interpreterContext (mEnvironment, + &ptr.getRefData().getLocals(), ptr); + boost::shared_ptr action = MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), mEnvironment); - action->execute (mEnvironment); + interpreterContext.activate (ptr, action); + + std::string script = MWWorld::Class::get (ptr).getScript (ptr); + + if (!script.empty()) + mScriptManager->run (script, interpreterContext); + + if (!interpreterContext.hasActivationBeenHandled()) + { + interpreterContext.executeActivation(); + } } diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index ff2d559f46..3cdc1f8508 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Activator::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Activator::registerSelf() { boost::shared_ptr instance (new Activator); diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 5639117b72..66821a7c5d 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 1a936e76ba..066eacd3fa 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Apparatus::registerSelf() { boost::shared_ptr instance (new Apparatus); diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 96c838e8d9..7b3ccff6a1 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 1a339c7034..786868c816 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -30,6 +30,14 @@ namespace MWClass return ref->base->data.health; } + std::string Armor::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Armor::registerSelf() { boost::shared_ptr instance (new Armor); diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 4a6cd2f75d..ebae75a9f8 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -19,6 +19,9 @@ namespace MWClass virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; ///< Return item max health or throw an exception, if class does not have item health + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index d162698571..9c0a484099 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Book::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Book::registerSelf() { boost::shared_ptr instance (new Book); diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index b9a03f2e76..d45f569b50 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index a728394d94..2c0d76fb3a 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Clothing::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Clothing::registerSelf() { boost::shared_ptr instance (new Clothing); diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 1b8dcf16dc..09b66b92d3 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index a6df294e7d..dd0fc729cc 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Container::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Container::registerSelf() { boost::shared_ptr instance (new Container); diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 0b907b2b79..959e6a6344 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 198c0e72fd..e34f92fb49 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -44,6 +44,14 @@ namespace MWClass return *ptr.getRefData().getCreatureStats(); } + std::string Creature::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Creature::registerSelf() { boost::shared_ptr instance (new Creature); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 5056501c5c..03333a50a4 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -16,6 +16,9 @@ namespace MWClass virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 24710fa4cc..2c4bd35629 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -53,6 +53,14 @@ namespace MWClass } } + std::string Door::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Door::registerSelf() { boost::shared_ptr instance (new Door); diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index 28d0486331..fa3b6d6573 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -17,6 +17,9 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 6ae80c4408..81d19b2fa7 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Ingredient::registerSelf() { boost::shared_ptr instance (new Ingredient); diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index eed520cb15..c2edd9484b 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index bf983259b7..98e0b01b49 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -20,6 +20,14 @@ namespace MWClass return ref->base->name; } + std::string Light::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Light::registerSelf() { boost::shared_ptr instance (new Light); diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 8fa53aeaf9..08c3ddf7c9 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index ee861c30b3..ce57e0c99b 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Lockpick::registerSelf() { boost::shared_ptr instance (new Lockpick); diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index daff07f85f..e009e9fdde 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index eabb7ba7ae..dda21aaa76 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Misc::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Misc::registerSelf() { boost::shared_ptr instance (new Misc); diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index d2f685d406..526235aa02 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index dbb7f2a934..2887ad0b58 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -44,6 +44,14 @@ namespace MWClass return *ptr.getRefData().getCreatureStats(); } + std::string Npc::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Npc::registerSelf() { boost::shared_ptr instance (new Npc); diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 76c56de40e..e0b828f61f 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -16,6 +16,9 @@ namespace MWClass virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 75f2f6ccb2..f8e9ee0a0f 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Potion::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Potion::registerSelf() { boost::shared_ptr instance (new Potion); diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 350aba1569..c851d1b4eb 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 65fbf47cbf..3c22e4c7f5 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Probe::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Probe::registerSelf() { boost::shared_ptr instance (new Probe); diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 1a60f220a5..84e93d1ce5 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 722baebde3..f22b8607a7 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -17,6 +17,14 @@ namespace MWClass return ref->base->name; } + std::string Repair::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Repair::registerSelf() { boost::shared_ptr instance (new Repair); diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index e7a9928ede..803e21d51c 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -13,6 +13,9 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 5ca80bcb7b..a7fce960c1 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -30,6 +30,14 @@ namespace MWClass return ref->base->data.health; } + std::string Weapon::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + void Weapon::registerSelf() { boost::shared_ptr instance (new Weapon); diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 98e5930f87..01b6f8e138 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -19,6 +19,9 @@ namespace MWClass virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; ///< Return item max health or throw an exception, if class does not have item health + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + static void registerSelf(); }; } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 9cca8035eb..267ff72940 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -41,6 +41,11 @@ namespace MWWorld return boost::shared_ptr (new NullAction); } + std::string Class::getScript (const Ptr& ptr) const + { + return ""; + } + const Class& Class::get (const std::string& key) { std::map >::const_iterator iter = sClasses.find (key); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 9535786e27..3f5722ce25 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -58,6 +58,10 @@ namespace MWWorld ///< Generate action for using via inventory menu (default implementation: return a /// null action). + virtual std::string getScript (const Ptr& ptr) const; + ///< Return name of the script attached to ptr (default implementation: return an empty + /// string). + static const Class& get (const std::string& key); ///< If there is no class for this \a key, an exception is thrown. From 15124601aa23927253202a6fe268d4cd7b182cf6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 15:46:50 +0200 Subject: [PATCH 5/8] stop local scripts from being run twice in case of activation --- apps/openmw/engine.cpp | 18 +++++++++++++----- apps/openmw/engine.hpp | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index badb19629d..b67bcd0ac7 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -38,13 +38,18 @@ void OMW::Engine::executeLocalScripts() mEnvironment.mWorld->getLocalScripts().begin()); iter!=mEnvironment.mWorld->getLocalScripts().end(); ++iter) { - MWScript::InterpreterContext interpreterContext (mEnvironment, - &iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second)); - mScriptManager->run (iter->first, interpreterContext); + if (!mIgnoreLocalPtr.isEmpty() && mIgnoreLocalPtr!=iter->second) + { + MWScript::InterpreterContext interpreterContext (mEnvironment, + &iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second)); + mScriptManager->run (iter->first, interpreterContext); - if (mEnvironment.mWorld->hasCellChanged()) - break; + if (mEnvironment.mWorld->hasCellChanged()) + break; + } } + + mIgnoreLocalPtr = MWWorld::Ptr(); } bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) @@ -291,7 +296,10 @@ void OMW::Engine::activate() std::string script = MWWorld::Class::get (ptr).getScript (ptr); if (!script.empty()) + { + mIgnoreLocalPtr = ptr; mScriptManager->run (script, interpreterContext); + } if (!interpreterContext.hasActivationBeenHandled()) { diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 62166e0500..bc612d13c0 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -11,6 +11,7 @@ #include #include "mwworld/environment.hpp" +#include "mwworld/ptr.hpp" namespace Compiler { @@ -68,6 +69,8 @@ namespace OMW int focusFrameCounter; static const int focusUpdateFrame = 10; + MWWorld::Ptr mIgnoreLocalPtr; + // not implemented Engine (const Engine&); Engine& operator= (const Engine&); From 1902dfb7b2623f312bf13a60ffb63c8351a04266 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 15:52:07 +0200 Subject: [PATCH 6/8] added activate instruction --- apps/openmw/mwscript/docs/vmformat.txt | 3 ++- apps/openmw/mwscript/miscextensions.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 9394679604..5807f26d48 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -76,4 +76,5 @@ op 0x2000069-0x200006b: ModDynamic (health, magicka, fatigue) op 0x200006c-0x200006e: ModDynamic (health, magicka, fatigue), explicit reference op 0x200006f-0x2000071: GetDynamic (health, magicka, fatigue) op 0x2000072-0x2000074: GetDynamic (health, magicka, fatigue), explicit reference -opcodes 0x2000075-0x3ffffff unused +op 0x2000075: Activate +opcodes 0x2000076-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 6abd224544..1ecfd0c57b 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -38,19 +38,37 @@ namespace MWScript } }; + class OpActivate : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + MWWorld::Ptr ptr = context.getReference(); + + context.executeActivation(); + } + }; + const int opcodeXBox = 0x200000c; const int opcodeOnActivate = 0x200000d; + const int opcodeActivate = 0x2000075; void registerExtensions (Compiler::Extensions& extensions) { extensions.registerFunction ("xbox", 'l', "", opcodeXBox); extensions.registerFunction ("onactivate", 'l', "", opcodeOnActivate); + extensions.registerInstruction ("activate", "", opcodeActivate); } void installOpcodes (Interpreter::Interpreter& interpreter) { interpreter.installSegment5 (opcodeXBox, new OpXBox); interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate); + interpreter.installSegment5 (opcodeActivate, new OpActivate); } } } From c883921af31da3816e1cdb106acedbbb6b357ad8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 15:57:06 +0200 Subject: [PATCH 7/8] minor cell change fix --- apps/openmw/mwworld/world.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 94a6758c75..581dcc5862 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -544,7 +544,7 @@ namespace MWWorld insertInteriorScripts (*cell); // adjust player - mPlayerPos->setPos (position.pos[0], position.pos[1], position.pos[2]); + mPlayerPos->setPos (position.pos[0], position.pos[1], position.pos[2], true); mPlayerPos->setCell (cell); // TODO orientation From 8e6a765603398a2565656f1f0e736773992c30b3 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Aug 2010 16:40:21 +0200 Subject: [PATCH 8/8] fixed a stats bug (reducing modified stats via setModified didn't work correctly --- apps/openmw/mwmechanics/stat.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/stat.hpp b/apps/openmw/mwmechanics/stat.hpp index a42b534446..d6422b0847 100644 --- a/apps/openmw/mwmechanics/stat.hpp +++ b/apps/openmw/mwmechanics/stat.hpp @@ -49,7 +49,7 @@ namespace MWMechanics value = min + (mModified - mBase); diff = value - mModified; } - else if (mBase>max-diff) + else if (mBase+diff>max) { value = max + (mModified - mBase); diff = value - mModified;