From 002345270bbb9e2567940f93d8441e174e340fb0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 18:44:52 +0200 Subject: [PATCH] implemented teleport doors (only for the player for now) --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwclass/door.cpp | 36 ++++++++++++++++++++++++++ apps/openmw/mwclass/door.hpp | 4 +++ apps/openmw/mwworld/actionteleport.cpp | 18 +++++++++++++ apps/openmw/mwworld/actionteleport.hpp | 25 ++++++++++++++++++ apps/openmw/mwworld/class.cpp | 6 +++-- apps/openmw/mwworld/class.hpp | 6 +++-- 7 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 apps/openmw/mwworld/actionteleport.cpp create mode 100644 apps/openmw/mwworld/actionteleport.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 466f7570f..0fe62ea4f 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -80,6 +80,7 @@ set(GAMEWORLD mwworld/world.cpp mwworld/globals.cpp mwworld/class.cpp + mwworld/actionteleport.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -90,6 +91,7 @@ set(GAMEWORLD_HEADER mwworld/class.hpp mwworld/action.hpp mwworld/nullaction.hpp + mwworld/actionteleport.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 50bd749c8..24710fa4c 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -5,7 +5,13 @@ #include +#include "../mwrender/playerpos.hpp" + #include "../mwworld/ptr.hpp" +#include "../mwworld/nullaction.hpp" +#include "../mwworld/actionteleport.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" namespace MWClass { @@ -17,6 +23,36 @@ namespace MWClass return ref->base->name; } + boost::shared_ptr Door::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->ref.teleport) + { + // teleport door + if (environment.mWorld->getPlayerPos().getPlayer()==actor) + { + // the player is using the door + return boost::shared_ptr ( + new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); + } + else + { + // another NPC or a create is using the door + // TODO return action for teleporting other NPC/creature + return boost::shared_ptr (new MWWorld::NullAction); + } + } + else + { + // animated door + // TODO return action for rotating the door + return boost::shared_ptr (new MWWorld::NullAction); + } + } + void Door::registerSelf() { boost::shared_ptr instance (new Door); diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index ae2c90ec7..28d048633 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -13,6 +13,10 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + static void registerSelf(); }; } diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp new file mode 100644 index 000000000..4edc02c30 --- /dev/null +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -0,0 +1,18 @@ + +#include "actionteleport.hpp" + +#include "environment.hpp" +#include "world.hpp" + +namespace MWWorld +{ + ActionTeleportPlayer::ActionTeleportPlayer (const std::string& cellName, + const ESM::Position& position) + : mCellName (cellName), mPosition (position) + {} + + void ActionTeleportPlayer::ActionTeleportPlayer::execute (Environment& environment) + { + environment.mWorld->changeCell (mCellName, mPosition); + } +} diff --git a/apps/openmw/mwworld/actionteleport.hpp b/apps/openmw/mwworld/actionteleport.hpp new file mode 100644 index 000000000..78a55fba2 --- /dev/null +++ b/apps/openmw/mwworld/actionteleport.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_MWWORLD_ACTIONTELEPORT_H +#define GAME_MWWORLD_ACTIONTELEPORT_H + +#include + +#include + +#include "action.hpp" + +namespace MWWorld +{ + class ActionTeleportPlayer : public Action + { + std::string mCellName; + ESM::Position mPosition; + + public: + + ActionTeleportPlayer (const std::string& cellName, const ESM::Position& position); + + virtual void execute (Environment& environment); + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 02859a7c8..9cca8035e 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -29,12 +29,14 @@ namespace MWWorld throw std::runtime_error ("class does not have item health"); } - boost::shared_ptr Class::activate (const Ptr& ptr, const Ptr& actor) const + boost::shared_ptr Class::activate (const Ptr& ptr, const Ptr& actor, + const Environment& environment) const { return boost::shared_ptr (new NullAction); } - boost::shared_ptr Class::use (const Ptr& ptr) const + boost::shared_ptr Class::use (const Ptr& ptr, + const Environment& environment) const { return boost::shared_ptr (new NullAction); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 55efbcc53..9535786e2 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -49,10 +49,12 @@ namespace MWWorld ///< Return item max health or throw an exception, if class does not have item health /// (default implementation: throw an exceoption) - virtual boost::shared_ptr activate (const Ptr& ptr, const Ptr& actor) const; + virtual boost::shared_ptr activate (const Ptr& ptr, const Ptr& actor, + const Environment& environment) const; ///< Generate action for activation (default implementation: return a null action). - virtual boost::shared_ptr use (const Ptr& ptr) const; + virtual boost::shared_ptr use (const Ptr& ptr, const Environment& environment) + const; ///< Generate action for using via inventory menu (default implementation: return a /// null action).