From a70c3876a27da394d2f33ff6d1977f93172aa7e4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 11:14:57 +0200 Subject: [PATCH 01/12] added foundation for esm record class hierarchy --- apps/openmw/CMakeLists.txt | 36 +++++++++++++++++------------- apps/openmw/engine.cpp | 2 ++ apps/openmw/mwworld/activator.cpp | 14 ++++++++++++ apps/openmw/mwworld/activator.hpp | 17 ++++++++++++++ apps/openmw/mwworld/class.cpp | 28 +++++++++++++++++++++++ apps/openmw/mwworld/class.hpp | 37 +++++++++++++++++++++++++++++++ apps/openmw/mwworld/classes.cpp | 12 ++++++++++ apps/openmw/mwworld/classes.hpp | 10 +++++++++ apps/openmw/mwworld/ptr.hpp | 7 ++++++ 9 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 apps/openmw/mwworld/activator.cpp create mode 100644 apps/openmw/mwworld/activator.hpp create mode 100644 apps/openmw/mwworld/class.cpp create mode 100644 apps/openmw/mwworld/class.hpp create mode 100644 apps/openmw/mwworld/classes.cpp create mode 100644 apps/openmw/mwworld/classes.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 260ebcd70..2dc4473ba 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -2,33 +2,33 @@ project(OpenMW) # local files -set(GAME +set(GAME main.cpp engine.cpp) -set(GAME_HEADER +set(GAME_HEADER engine.hpp) source_group(game FILES ${GAME} ${GAME_HEADER}) -set(GAMEREND +set(GAMEREND mwrender/mwscene.cpp mwrender/cellimp.cpp mwrender/interior.cpp mwrender/sky.cpp) -set(GAMEREND_HEADER +set(GAMEREND_HEADER mwrender/cell.hpp mwrender/cellimp.hpp mwrender/mwscene.hpp mwrender/interior.hpp mwrender/playerpos.hpp mwrender/sky.hpp) -source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER}) +source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER}) set(GAMEINPUT mwinput/inputmanager.cpp ) -set(GAMEINPUT_HEADER +set(GAMEINPUT_HEADER mwinput/inputmanager.hpp) -source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) +source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) set(GAMEGUI_HEADER mwgui/mw_layouts.hpp @@ -54,7 +54,7 @@ set(GAMESCRIPT mwscript/extensions.cpp mwscript/globalscripts.cpp ) -set(GAMESCRIPT_HEADER +set(GAMESCRIPT_HEADER mwscript/locals.hpp mwscript/scriptmanager.hpp mwscript/compilercontext.hpp @@ -68,35 +68,41 @@ set(GAMESCRIPT_HEADER mwscript/extensions.hpp mwscript/globalscripts.hpp ) -source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) +source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) set(GAMESOUND mwsound/soundmanager.cpp) -set(GAMESOUND_HEADER +set(GAMESOUND_HEADER mwsound/soundmanager.hpp) -source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER}) +source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER}) set(GAMEWORLD mwworld/world.cpp mwworld/globals.cpp + mwworld/class.cpp + mwworld/classes.cpp + mwworld/activator.cpp ) -set(GAMEWORLD_HEADER +set(GAMEWORLD_HEADER mwworld/refdata.hpp mwworld/world.hpp mwworld/ptr.hpp mwworld/environment.hpp mwworld/globals.hpp + mwworld/class.hpp + mwworld/classes.hpp + mwworld/activator.hpp ) -source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) +source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) set(GAMEMECHANICS mwmechanics/mechanicsmanager.cpp) -set(GAMEMECHANICS_HEADER +set(GAMEMECHANICS_HEADER mwmechanics/mechanicsmanager.hpp mwmechanics/stat.hpp mwmechanics/creaturestats.hpp ) -source_group(apps\\openmw\\mwmechanics FILES ${GAMEMECHANICS} ${GAMEMECHANICS_HEADER}) +source_group(apps\\openmw\\mwmechanics FILES ${GAMEMECHANICS} ${GAMEMECHANICS_HEADER}) set(OPENMW_CPP ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT} ${GAMESOUND} ${GAMEGUI} ${GAMEWORLD} ${GAMEMECHANICS} diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 43a01b271..f49216cda 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -23,6 +23,7 @@ #include "mwworld/world.hpp" #include "mwworld/ptr.hpp" #include "mwworld/environment.hpp" +#include "mwworld/classes.hpp" #include "mwmechanics/mechanicsmanager.hpp" @@ -78,6 +79,7 @@ OMW::Engine::Engine() , mScriptManager (0) , mScriptContext (0) { + MWWorld::registerClasses(); } OMW::Engine::~Engine() diff --git a/apps/openmw/mwworld/activator.cpp b/apps/openmw/mwworld/activator.cpp new file mode 100644 index 000000000..27bf00e10 --- /dev/null +++ b/apps/openmw/mwworld/activator.cpp @@ -0,0 +1,14 @@ + +#include "activator.hpp" + +#include + +namespace MWWorld +{ + void Activator::registerSelf() + { + boost::shared_ptr instance (new Activator); + + registerClass (typeid (ESM::Activator).name(), instance); + } +} diff --git a/apps/openmw/mwworld/activator.hpp b/apps/openmw/mwworld/activator.hpp new file mode 100644 index 000000000..023790e6f --- /dev/null +++ b/apps/openmw/mwworld/activator.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWWORLD_ACTIVATOR_H +#define GAME_MWWORLD_ACTIVATOR_H + +#include "class.hpp" + +namespace MWWorld +{ + class Activator : public Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp new file mode 100644 index 000000000..1520916be --- /dev/null +++ b/apps/openmw/mwworld/class.cpp @@ -0,0 +1,28 @@ + +#include "class.hpp" + +#include + +namespace MWWorld +{ + std::map > Class::sClasses; + + Class::Class() {} + + Class::~Class() {} + + const Class& Class::get (const std::string& key) + { + std::map >::const_iterator iter = sClasses.find (key); + + if (iter==sClasses.end()) + throw std::logic_error ("unknown class key: " + key); + + return *iter->second; + } + + void Class::registerClass (const std::string& key, boost::shared_ptr instance) + { + sClasses.insert (std::make_pair (key, instance)); + } +} diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp new file mode 100644 index 000000000..c7c6a26f9 --- /dev/null +++ b/apps/openmw/mwworld/class.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWWORLD_CLASS_H +#define GAME_MWWORLD_CLASS_H + +#include +#include + +#include + +namespace MWWorld +{ + /// \brief Base class for referenceable esm records + class Class + { + static std::map > sClasses; + + // not implemented + Class (const Class&); + Class& operator= (const Class&); + + protected: + + Class(); + + public: + + virtual ~Class(); + + + + static const Class& get (const std::string& key); + ///< If there is no class for this \a key, an exception is thrown. + + static void registerClass (const std::string& key, boost::shared_ptr instance); + }; +} + +#endif diff --git a/apps/openmw/mwworld/classes.cpp b/apps/openmw/mwworld/classes.cpp new file mode 100644 index 000000000..79f9b52d7 --- /dev/null +++ b/apps/openmw/mwworld/classes.cpp @@ -0,0 +1,12 @@ + +#include "classes.hpp" + +#include "activator.hpp" + +namespace MWWorld +{ + void registerClasses() + { + Activator::registerSelf(); + } +} diff --git a/apps/openmw/mwworld/classes.hpp b/apps/openmw/mwworld/classes.hpp new file mode 100644 index 000000000..9b83b8d73 --- /dev/null +++ b/apps/openmw/mwworld/classes.hpp @@ -0,0 +1,10 @@ +#ifndef GAME_MWWORLD_CLASSES_H +#define GAME_MWWORLD_CLASSES_H + +namespace MWWorld +{ + void registerClasses(); + ///< register all known classes +} + +#endif diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index f05a9bef2..92eed194c 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -27,6 +27,7 @@ namespace MWWorld ESM::CellRef *mCellRef; RefData *mRefData; CellStore *mCell; + std::string mTypeName; public: @@ -43,6 +44,11 @@ namespace MWWorld return mPtr.type(); } + const std::string& getTypeName() const + { + return mTypeName; + } + template Ptr (ESMS::LiveCellRef *liveCellRef, CellStore *cell) { @@ -50,6 +56,7 @@ namespace MWWorld mCellRef = &liveCellRef->ref; mRefData = &liveCellRef->mData; mCell = cell; + mTypeName = typeid (T).name(); } template From ca842d1b4d942764437bd2df2077d2c65551f7ea Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 11:49:12 +0200 Subject: [PATCH 02/12] reimplemented access to creature stats via new class interface --- apps/openmw/CMakeLists.txt | 4 ++ apps/openmw/mwmechanics/mechanicsmanager.cpp | 5 +- apps/openmw/mwscript/statsextensions.cpp | 70 +++++++++++++++----- apps/openmw/mwworld/class.cpp | 12 ++++ apps/openmw/mwworld/class.hpp | 13 ++++ apps/openmw/mwworld/classes.cpp | 4 ++ apps/openmw/mwworld/ptr.hpp | 57 ---------------- 7 files changed, 89 insertions(+), 76 deletions(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 2dc4473ba..7f384a794 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -82,6 +82,8 @@ set(GAMEWORLD mwworld/class.cpp mwworld/classes.cpp mwworld/activator.cpp + mwworld/creature.cpp + mwworld/npc.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -92,6 +94,8 @@ set(GAMEWORLD_HEADER mwworld/class.hpp mwworld/classes.hpp mwworld/activator.hpp + mwworld/creature.hpp + mwworld/npc.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 310695959..229a351ac 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -5,6 +5,8 @@ #include "../mwgui/window_manager.hpp" +#include "../mwworld/class.hpp" + namespace MWMechanics { MechanicsManager::MechanicsManager (const ESMS::ESMStore& store, @@ -46,7 +48,8 @@ namespace MWMechanics { if (!mWatched.isEmpty()) { - MWMechanics::CreatureStats& stats = mWatched.getCreatureStats(); + MWMechanics::CreatureStats& stats = + MWWorld::Class::get (mWatched).getCreatureStats (mWatched); static const char *attributeNames[8] = { diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 997e2473a..2abf1f284 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -7,6 +7,8 @@ #include #include +#include "../mwworld/class.hpp" + #include "interpretercontext.hpp" namespace MWScript @@ -26,8 +28,10 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); + MWWorld::Ptr ptr = context.getReference(); + Interpreter::Type_Integer value = - context.getReference().getCreatureStats().mAttributes[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. getModified(); runtime.push (value); @@ -50,8 +54,10 @@ namespace MWScript std::string id = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + Interpreter::Type_Integer value = - context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. getModified(); runtime.push (value); @@ -74,7 +80,9 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - context.getReference().getCreatureStats().mAttributes[mIndex]. + MWWorld::Ptr ptr = context.getReference(); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. setModified (value, 0); } }; @@ -98,7 +106,9 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. setModified (value, 0); } }; @@ -119,10 +129,12 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - value += context.getReference().getCreatureStats().mAttributes[mIndex]. + MWWorld::Ptr ptr = context.getReference(); + + value += MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. getModified(); - context.getReference().getCreatureStats().mAttributes[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. setModified (value, 0, 100); } }; @@ -146,11 +158,13 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + value += - context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. getModified(); - context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. setModified (value, 0, 100); } }; @@ -168,6 +182,8 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); + MWWorld::Ptr ptr = context.getReference(); + if (mIndex==0) { // health is a special case @@ -196,7 +212,7 @@ namespace MWScript } Interpreter::Type_Integer value = - context.getReference().getCreatureStats().mDynamic[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. getCurrent(); runtime.push (value); @@ -219,6 +235,8 @@ namespace MWScript std::string id = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + if (mIndex==0) { // health is a special case @@ -247,7 +265,7 @@ namespace MWScript } Interpreter::Type_Integer value = - context.getWorld().getPtr (id, false).getCreatureStats().mDynamic[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. getCurrent(); runtime.push (value); @@ -270,7 +288,9 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - context.getReference().getCreatureStats().mDynamic[mIndex]. + MWWorld::Ptr ptr = context.getReference(); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. setModified (value, 0); } }; @@ -294,7 +314,9 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - context.getWorld().getPtr (id, false).getCreatureStats().mDynamic[mIndex]. + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. setModified (value, 0); } }; @@ -315,7 +337,9 @@ namespace MWScript Interpreter::Type_Integer diff = runtime[0].mInteger; runtime.pop(); - MWMechanics::CreatureStats& stats = context.getReference().getCreatureStats(); + MWWorld::Ptr ptr = context.getReference(); + + MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); @@ -345,8 +369,10 @@ namespace MWScript Interpreter::Type_Integer diff = runtime[0].mInteger; runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + MWMechanics::CreatureStats& stats = - context.getWorld().getPtr (id, false).getCreatureStats(); + MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); @@ -374,7 +400,9 @@ namespace MWScript Interpreter::Type_Integer diff = runtime[0].mInteger; runtime.pop(); - MWMechanics::CreatureStats& stats = context.getReference().getCreatureStats(); + MWWorld::Ptr ptr = context.getReference(); + + MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); @@ -401,8 +429,10 @@ namespace MWScript Interpreter::Type_Integer diff = runtime[0].mInteger; runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + MWMechanics::CreatureStats& stats = - context.getWorld().getPtr (id, false).getCreatureStats(); + MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); @@ -423,7 +453,9 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - MWMechanics::CreatureStats& stats = context.getReference().getCreatureStats(); + MWWorld::Ptr ptr = context.getReference(); + + MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Float value = 0; @@ -452,8 +484,10 @@ namespace MWScript std::string id = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + MWMechanics::CreatureStats& stats = - context.getWorld().getPtr (id, false).getCreatureStats(); + MWWorld::Class::get (ptr).getCreatureStats (ptr); Interpreter::Type_Float value = 0; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 1520916be..9a2020337 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -3,6 +3,8 @@ #include +#include "ptr.hpp" + namespace MWWorld { std::map > Class::sClasses; @@ -11,6 +13,11 @@ namespace MWWorld Class::~Class() {} + MWMechanics::CreatureStats& Class::getCreatureStats (const Ptr& ptr) const + { + throw std::runtime_error ("class does not have creature stats"); + } + const Class& Class::get (const std::string& key) { std::map >::const_iterator iter = sClasses.find (key); @@ -21,6 +28,11 @@ namespace MWWorld return *iter->second; } + const Class& Class::get (const Ptr& ptr) + { + return get (ptr.getTypeName()); + } + void Class::registerClass (const std::string& key, boost::shared_ptr instance) { sClasses.insert (std::make_pair (key, instance)); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index c7c6a26f9..3144a7108 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -6,8 +6,15 @@ #include +namespace MWMechanics +{ + struct CreatureStats; +} + namespace MWWorld { + class Ptr; + /// \brief Base class for referenceable esm records class Class { @@ -25,11 +32,17 @@ namespace MWWorld virtual ~Class(); + virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; + ///< Return creature stats or throw an exception, if class does not have creature stats + /// (default implementation: throw an exceoption) static const Class& get (const std::string& key); ///< If there is no class for this \a key, an exception is thrown. + static const Class& get (const Ptr& ptr); + ///< If there is no class for this pointer, an exception is thrown. + static void registerClass (const std::string& key, boost::shared_ptr instance); }; } diff --git a/apps/openmw/mwworld/classes.cpp b/apps/openmw/mwworld/classes.cpp index 79f9b52d7..4ae2076d9 100644 --- a/apps/openmw/mwworld/classes.cpp +++ b/apps/openmw/mwworld/classes.cpp @@ -2,11 +2,15 @@ #include "classes.hpp" #include "activator.hpp" +#include "creature.hpp" +#include "npc.hpp" namespace MWWorld { void registerClasses() { Activator::registerSelf(); + Creature::registerSelf(); + Npc::registerSelf(); } } diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 92eed194c..bf119b8f4 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -82,63 +82,6 @@ namespace MWWorld assert (mCell); return mCell; } - - /// Throws an exception, if the ID type does not support creature stats. - MWMechanics::CreatureStats& getCreatureStats() const - { - RefData& data = getRefData(); - - if (!data.getCreatureStats().get()) - { - if (mPtr.type()==typeid (ESMS::LiveCellRef *)) - { - boost::shared_ptr stats ( - new MWMechanics::CreatureStats); - - ESMS::LiveCellRef *ref = get(); - - stats->mAttributes[0].set (ref->base->data.strength); - stats->mAttributes[1].set (ref->base->data.intelligence); - stats->mAttributes[2].set (ref->base->data.willpower); - stats->mAttributes[3].set (ref->base->data.agility); - stats->mAttributes[4].set (ref->base->data.speed); - stats->mAttributes[5].set (ref->base->data.endurance); - stats->mAttributes[6].set (ref->base->data.personality); - stats->mAttributes[7].set (ref->base->data.luck); - stats->mDynamic[0].set (ref->base->data.health); - stats->mDynamic[1].set (ref->base->data.mana); - stats->mDynamic[2].set (ref->base->data.fatigue); - - data.getCreatureStats() = stats; - } - else if (mPtr.type()==typeid (ESMS::LiveCellRef *)) - { - boost::shared_ptr stats ( - new MWMechanics::CreatureStats); - - ESMS::LiveCellRef *ref = get(); - - stats->mAttributes[0].set (ref->base->npdt52.strength); - stats->mAttributes[1].set (ref->base->npdt52.intelligence); - stats->mAttributes[2].set (ref->base->npdt52.willpower); - stats->mAttributes[3].set (ref->base->npdt52.agility); - stats->mAttributes[4].set (ref->base->npdt52.speed); - stats->mAttributes[5].set (ref->base->npdt52.endurance); - stats->mAttributes[6].set (ref->base->npdt52.personality); - stats->mAttributes[7].set (ref->base->npdt52.luck); - stats->mDynamic[0].set (ref->base->npdt52.health); - stats->mDynamic[1].set (ref->base->npdt52.mana); - stats->mDynamic[2].set (ref->base->npdt52.fatigue); - - data.getCreatureStats() = stats; - } - else - throw std::runtime_error ( - "CreatureStats not available for this ID type"); - } - - return *data.getCreatureStats(); - } }; inline bool operator== (const Ptr& left, const Ptr& right) From 9d6e658e052b045adff765f2851ecee53d3bb8ec Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 13:03:08 +0200 Subject: [PATCH 03/12] previous commit was missing some files --- apps/openmw/mwclass/activator.cpp | 14 ++++++++++ apps/openmw/mwworld/creature.cpp | 45 +++++++++++++++++++++++++++++++ apps/openmw/mwworld/creature.hpp | 19 +++++++++++++ apps/openmw/mwworld/npc.cpp | 43 +++++++++++++++++++++++++++++ apps/openmw/mwworld/npc.hpp | 19 +++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 apps/openmw/mwclass/activator.cpp create mode 100644 apps/openmw/mwworld/creature.cpp create mode 100644 apps/openmw/mwworld/creature.hpp create mode 100644 apps/openmw/mwworld/npc.cpp create mode 100644 apps/openmw/mwworld/npc.hpp diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp new file mode 100644 index 000000000..27bf00e10 --- /dev/null +++ b/apps/openmw/mwclass/activator.cpp @@ -0,0 +1,14 @@ + +#include "activator.hpp" + +#include + +namespace MWWorld +{ + void Activator::registerSelf() + { + boost::shared_ptr instance (new Activator); + + registerClass (typeid (ESM::Activator).name(), instance); + } +} diff --git a/apps/openmw/mwworld/creature.cpp b/apps/openmw/mwworld/creature.cpp new file mode 100644 index 000000000..dff1cb1c9 --- /dev/null +++ b/apps/openmw/mwworld/creature.cpp @@ -0,0 +1,45 @@ + +#include "creature.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" + +#include "ptr.hpp" + +namespace MWWorld +{ + MWMechanics::CreatureStats& Creature::getCreatureStats (const Ptr& ptr) const + { + if (!ptr.getRefData().getCreatureStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::CreatureStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + stats->mAttributes[0].set (ref->base->data.strength); + stats->mAttributes[1].set (ref->base->data.intelligence); + stats->mAttributes[2].set (ref->base->data.willpower); + stats->mAttributes[3].set (ref->base->data.agility); + stats->mAttributes[4].set (ref->base->data.speed); + stats->mAttributes[5].set (ref->base->data.endurance); + stats->mAttributes[6].set (ref->base->data.personality); + stats->mAttributes[7].set (ref->base->data.luck); + stats->mDynamic[0].set (ref->base->data.health); + stats->mDynamic[1].set (ref->base->data.mana); + stats->mDynamic[2].set (ref->base->data.fatigue); + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + void Creature::registerSelf() + { + boost::shared_ptr instance (new Creature); + + registerClass (typeid (ESM::Creature).name(), instance); + } +} diff --git a/apps/openmw/mwworld/creature.hpp b/apps/openmw/mwworld/creature.hpp new file mode 100644 index 000000000..7ab2b5af0 --- /dev/null +++ b/apps/openmw/mwworld/creature.hpp @@ -0,0 +1,19 @@ +#ifndef GAME_MWWORLD_CREATURE_H +#define GAME_MWWORLD_CREATURE_H + +#include "class.hpp" + +namespace MWWorld +{ + class Creature : public Class + { + public: + + virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; + ///< Return creature stats + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwworld/npc.cpp b/apps/openmw/mwworld/npc.cpp new file mode 100644 index 000000000..e98e532da --- /dev/null +++ b/apps/openmw/mwworld/npc.cpp @@ -0,0 +1,43 @@ + +#include "npc.hpp" + +#include + +#include "ptr.hpp" + +namespace MWWorld +{ + MWMechanics::CreatureStats& Npc::getCreatureStats (const Ptr& ptr) const + { + if (!ptr.getRefData().getCreatureStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::CreatureStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + stats->mAttributes[0].set (ref->base->npdt52.strength); + stats->mAttributes[1].set (ref->base->npdt52.intelligence); + stats->mAttributes[2].set (ref->base->npdt52.willpower); + stats->mAttributes[3].set (ref->base->npdt52.agility); + stats->mAttributes[4].set (ref->base->npdt52.speed); + stats->mAttributes[5].set (ref->base->npdt52.endurance); + stats->mAttributes[6].set (ref->base->npdt52.personality); + stats->mAttributes[7].set (ref->base->npdt52.luck); + stats->mDynamic[0].set (ref->base->npdt52.health); + stats->mDynamic[1].set (ref->base->npdt52.mana); + stats->mDynamic[2].set (ref->base->npdt52.fatigue); + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + void Npc::registerSelf() + { + boost::shared_ptr instance (new Npc); + + registerClass (typeid (ESM::NPC).name(), instance); + } +} diff --git a/apps/openmw/mwworld/npc.hpp b/apps/openmw/mwworld/npc.hpp new file mode 100644 index 000000000..7b10ccb32 --- /dev/null +++ b/apps/openmw/mwworld/npc.hpp @@ -0,0 +1,19 @@ +#ifndef GAME_MWWORLD_NPC_H +#define GAME_MWWORLD_NPC_H + +#include "class.hpp" + +namespace MWWorld +{ + class Npc : public Class + { + public: + + virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; + ///< Return creature stats + + static void registerSelf(); + }; +} + +#endif From 33b6a0b8006b5f33c036a556581b511e60b883e6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 13:17:31 +0200 Subject: [PATCH 04/12] moved concrete record classes to separate sub-system (mwclass) --- apps/openmw/CMakeLists.txt | 27 ++++++++++++------- apps/openmw/engine.cpp | 5 ++-- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/activator.hpp | 17 ++++++++++++ apps/openmw/{mwworld => mwclass}/classes.cpp | 2 +- apps/openmw/mwclass/classes.hpp | 10 +++++++ apps/openmw/{mwworld => mwclass}/creature.cpp | 8 +++--- apps/openmw/mwclass/creature.hpp | 19 +++++++++++++ apps/openmw/{mwworld => mwclass}/npc.cpp | 8 +++--- apps/openmw/{mwworld => mwclass}/npc.hpp | 12 ++++----- apps/openmw/mwworld/activator.cpp | 14 ---------- apps/openmw/mwworld/activator.hpp | 17 ------------ apps/openmw/mwworld/classes.hpp | 10 ------- apps/openmw/mwworld/creature.hpp | 19 ------------- 14 files changed, 82 insertions(+), 88 deletions(-) create mode 100644 apps/openmw/mwclass/activator.hpp rename apps/openmw/{mwworld => mwclass}/classes.cpp (92%) create mode 100644 apps/openmw/mwclass/classes.hpp rename apps/openmw/{mwworld => mwclass}/creature.cpp (88%) create mode 100644 apps/openmw/mwclass/creature.hpp rename apps/openmw/{mwworld => mwclass}/npc.cpp (85%) rename apps/openmw/{mwworld => mwclass}/npc.hpp (51%) delete mode 100644 apps/openmw/mwworld/activator.cpp delete mode 100644 apps/openmw/mwworld/activator.hpp delete mode 100644 apps/openmw/mwworld/classes.hpp delete mode 100644 apps/openmw/mwworld/creature.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 7f384a794..b8784dc81 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -80,10 +80,6 @@ set(GAMEWORLD mwworld/world.cpp mwworld/globals.cpp mwworld/class.cpp - mwworld/classes.cpp - mwworld/activator.cpp - mwworld/creature.cpp - mwworld/npc.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -92,13 +88,23 @@ set(GAMEWORLD_HEADER mwworld/environment.hpp mwworld/globals.hpp mwworld/class.hpp - mwworld/classes.hpp - mwworld/activator.hpp - mwworld/creature.hpp - mwworld/npc.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) +set(GAMECLASS + mwclass/classes.cpp + mwclass/activator.cpp + mwclass/creature.cpp + mwclass/npc.cpp + ) +set(GAMECLASS_HEADER + mwclass/classes.hpp + mwclass/activator.hpp + mwclass/creature.hpp + mwclass/npc.hpp + ) +source_group(apps\\openmw\\mwclass FILES ${GAMECLASS} ${GAMECLASS_HEADER}) + set(GAMEMECHANICS mwmechanics/mechanicsmanager.cpp) set(GAMEMECHANICS_HEADER @@ -109,10 +115,11 @@ set(GAMEMECHANICS_HEADER source_group(apps\\openmw\\mwmechanics FILES ${GAMEMECHANICS} ${GAMEMECHANICS_HEADER}) set(OPENMW_CPP ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT} ${GAMESOUND} ${GAMEGUI} ${GAMEWORLD} - ${GAMEMECHANICS} + ${GAMECLASS} ${GAMEMECHANICS} ) set(OPENMW_HEADER ${GAME_HEADER} ${GAMEREND_HEADER} ${GAMEINPUT_HEADER} ${GAMESCRIPT_HEADER} - ${GAMESOUND_HEADER} ${GAMEGUI_HEADER} ${GAMEWORLD_HEADER} ${GAMEMECHANICS_HEADER} + ${GAMESOUND_HEADER} ${GAMEGUI_HEADER} ${GAMEWORLD_HEADER} ${GAMECLASS_HEADER} + ${GAMEMECHANICS_HEADER} ) # Main executable diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index f49216cda..5b6aea3c2 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -23,7 +23,8 @@ #include "mwworld/world.hpp" #include "mwworld/ptr.hpp" #include "mwworld/environment.hpp" -#include "mwworld/classes.hpp" + +#include "mwclass/classes.hpp" #include "mwmechanics/mechanicsmanager.hpp" @@ -79,7 +80,7 @@ OMW::Engine::Engine() , mScriptManager (0) , mScriptContext (0) { - MWWorld::registerClasses(); + MWClass::registerClasses(); } OMW::Engine::~Engine() diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 27bf00e10..0e3df53a2 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -3,7 +3,7 @@ #include -namespace MWWorld +namespace MWClass { void Activator::registerSelf() { diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp new file mode 100644 index 000000000..a649ce6ef --- /dev/null +++ b/apps/openmw/mwclass/activator.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_ACTIVATOR_H +#define GAME_MWCLASS_ACTIVATOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Activator : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwworld/classes.cpp b/apps/openmw/mwclass/classes.cpp similarity index 92% rename from apps/openmw/mwworld/classes.cpp rename to apps/openmw/mwclass/classes.cpp index 4ae2076d9..16f3fab4d 100644 --- a/apps/openmw/mwworld/classes.cpp +++ b/apps/openmw/mwclass/classes.cpp @@ -5,7 +5,7 @@ #include "creature.hpp" #include "npc.hpp" -namespace MWWorld +namespace MWClass { void registerClasses() { diff --git a/apps/openmw/mwclass/classes.hpp b/apps/openmw/mwclass/classes.hpp new file mode 100644 index 000000000..0ab90b677 --- /dev/null +++ b/apps/openmw/mwclass/classes.hpp @@ -0,0 +1,10 @@ +#ifndef GAME_MWCLASS_CLASSES_H +#define GAME_MWCLASS_CLASSES_H + +namespace MWClass +{ + void registerClasses(); + ///< register all known classes +} + +#endif diff --git a/apps/openmw/mwworld/creature.cpp b/apps/openmw/mwclass/creature.cpp similarity index 88% rename from apps/openmw/mwworld/creature.cpp rename to apps/openmw/mwclass/creature.cpp index dff1cb1c9..a367b0f8f 100644 --- a/apps/openmw/mwworld/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -5,18 +5,18 @@ #include "../mwmechanics/creaturestats.hpp" -#include "ptr.hpp" +#include "../mwworld/ptr.hpp" -namespace MWWorld +namespace MWClass { - MWMechanics::CreatureStats& Creature::getCreatureStats (const Ptr& ptr) const + MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getCreatureStats().get()) { boost::shared_ptr stats ( new MWMechanics::CreatureStats); - ESMS::LiveCellRef *ref = ptr.get(); + ESMS::LiveCellRef *ref = ptr.get(); stats->mAttributes[0].set (ref->base->data.strength); stats->mAttributes[1].set (ref->base->data.intelligence); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp new file mode 100644 index 000000000..a583fb6d4 --- /dev/null +++ b/apps/openmw/mwclass/creature.hpp @@ -0,0 +1,19 @@ +#ifndef GAME_MWCLASS_CREATURE_H +#define GAME_MWCLASS_CREATURE_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Creature : public MWWorld::Class + { + public: + + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; + ///< Return creature stats + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwworld/npc.cpp b/apps/openmw/mwclass/npc.cpp similarity index 85% rename from apps/openmw/mwworld/npc.cpp rename to apps/openmw/mwclass/npc.cpp index e98e532da..eba033ef7 100644 --- a/apps/openmw/mwworld/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -3,18 +3,18 @@ #include -#include "ptr.hpp" +#include "../mwworld/ptr.hpp" -namespace MWWorld +namespace MWClass { - MWMechanics::CreatureStats& Npc::getCreatureStats (const Ptr& ptr) const + MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getCreatureStats().get()) { boost::shared_ptr stats ( new MWMechanics::CreatureStats); - ESMS::LiveCellRef *ref = ptr.get(); + ESMS::LiveCellRef *ref = ptr.get(); stats->mAttributes[0].set (ref->base->npdt52.strength); stats->mAttributes[1].set (ref->base->npdt52.intelligence); diff --git a/apps/openmw/mwworld/npc.hpp b/apps/openmw/mwclass/npc.hpp similarity index 51% rename from apps/openmw/mwworld/npc.hpp rename to apps/openmw/mwclass/npc.hpp index 7b10ccb32..48367bc71 100644 --- a/apps/openmw/mwworld/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -1,15 +1,15 @@ -#ifndef GAME_MWWORLD_NPC_H -#define GAME_MWWORLD_NPC_H +#ifndef GAME_MWCLASS_NPC_H +#define GAME_MWCLASS_NPC_H -#include "class.hpp" +#include "../mwworld/class.hpp" -namespace MWWorld +namespace MWClass { - class Npc : public Class + class Npc : public MWWorld::Class { public: - virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats static void registerSelf(); diff --git a/apps/openmw/mwworld/activator.cpp b/apps/openmw/mwworld/activator.cpp deleted file mode 100644 index 27bf00e10..000000000 --- a/apps/openmw/mwworld/activator.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -#include "activator.hpp" - -#include - -namespace MWWorld -{ - void Activator::registerSelf() - { - boost::shared_ptr instance (new Activator); - - registerClass (typeid (ESM::Activator).name(), instance); - } -} diff --git a/apps/openmw/mwworld/activator.hpp b/apps/openmw/mwworld/activator.hpp deleted file mode 100644 index 023790e6f..000000000 --- a/apps/openmw/mwworld/activator.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef GAME_MWWORLD_ACTIVATOR_H -#define GAME_MWWORLD_ACTIVATOR_H - -#include "class.hpp" - -namespace MWWorld -{ - class Activator : public Class - { - public: - - - static void registerSelf(); - }; -} - -#endif diff --git a/apps/openmw/mwworld/classes.hpp b/apps/openmw/mwworld/classes.hpp deleted file mode 100644 index 9b83b8d73..000000000 --- a/apps/openmw/mwworld/classes.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef GAME_MWWORLD_CLASSES_H -#define GAME_MWWORLD_CLASSES_H - -namespace MWWorld -{ - void registerClasses(); - ///< register all known classes -} - -#endif diff --git a/apps/openmw/mwworld/creature.hpp b/apps/openmw/mwworld/creature.hpp deleted file mode 100644 index 7ab2b5af0..000000000 --- a/apps/openmw/mwworld/creature.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GAME_MWWORLD_CREATURE_H -#define GAME_MWWORLD_CREATURE_H - -#include "class.hpp" - -namespace MWWorld -{ - class Creature : public Class - { - public: - - virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; - ///< Return creature stats - - static void registerSelf(); - }; -} - -#endif From 93754b285169eeccc75aded63955449956a96013 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 13:32:37 +0200 Subject: [PATCH 05/12] moved some includes around --- apps/openmw/mwclass/npc.cpp | 2 ++ apps/openmw/mwscript/statsextensions.cpp | 2 ++ apps/openmw/mwworld/ptr.hpp | 2 -- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index eba033ef7..97bcd54ad 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -3,6 +3,8 @@ #include +#include "../mwmechanics/creaturestats.hpp" + #include "../mwworld/ptr.hpp" namespace MWClass diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 2abf1f284..106f1b72e 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -9,6 +9,8 @@ #include "../mwworld/class.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include "interpretercontext.hpp" namespace MWScript diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index bf119b8f4..3769efdce 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -9,8 +9,6 @@ #include #include -#include "../mwmechanics/creaturestats.hpp" - #include "refdata.hpp" namespace MWWorld From bfc282779b2c56d3091b5707f2c75b3c76c7ab70 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 14:14:04 +0200 Subject: [PATCH 06/12] added item health interface --- apps/openmw/CMakeLists.txt | 4 ++ apps/openmw/mwclass/armor.cpp | 31 ++++++++++++++ apps/openmw/mwclass/armor.hpp | 22 ++++++++++ apps/openmw/mwclass/classes.cpp | 4 ++ apps/openmw/mwclass/weapon.cpp | 31 ++++++++++++++ apps/openmw/mwclass/weapon.hpp | 22 ++++++++++ apps/openmw/mwscript/statsextensions.cpp | 54 +++++------------------- apps/openmw/mwworld/class.cpp | 10 +++++ apps/openmw/mwworld/class.hpp | 6 +++ 9 files changed, 140 insertions(+), 44 deletions(-) create mode 100644 apps/openmw/mwclass/armor.cpp create mode 100644 apps/openmw/mwclass/armor.hpp create mode 100644 apps/openmw/mwclass/weapon.cpp create mode 100644 apps/openmw/mwclass/weapon.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b8784dc81..bf188b963 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -96,12 +96,16 @@ set(GAMECLASS mwclass/activator.cpp mwclass/creature.cpp mwclass/npc.cpp + mwclass/weapon.cpp + mwclass/armor.cpp ) set(GAMECLASS_HEADER mwclass/classes.hpp mwclass/activator.hpp mwclass/creature.hpp mwclass/npc.hpp + mwclass/weapon.hpp + mwclass/armor.hpp ) source_group(apps\\openmw\\mwclass FILES ${GAMECLASS} ${GAMECLASS_HEADER}) diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp new file mode 100644 index 000000000..cdeeb06e0 --- /dev/null +++ b/apps/openmw/mwclass/armor.cpp @@ -0,0 +1,31 @@ + +#include "armor.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +namespace MWClass +{ + bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const + { + return true; + } + + int Armor::getItemMaxHealth (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->data.health; + } + + void Armor::registerSelf() + { + boost::shared_ptr instance (new Armor); + + registerClass (typeid (ESM::Armor).name(), instance); + } +} diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp new file mode 100644 index 000000000..0bc3856ce --- /dev/null +++ b/apps/openmw/mwclass/armor.hpp @@ -0,0 +1,22 @@ +#ifndef GAME_MWCLASS_ARMOR_H +#define GAME_MWCLASS_ARMOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Armor : public MWWorld::Class + { + public: + + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; + ///< \return Item health data available? + + virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; + ///< Return item max health or throw an exception, if class does not have item health + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/classes.cpp b/apps/openmw/mwclass/classes.cpp index 16f3fab4d..655159e35 100644 --- a/apps/openmw/mwclass/classes.cpp +++ b/apps/openmw/mwclass/classes.cpp @@ -4,6 +4,8 @@ #include "activator.hpp" #include "creature.hpp" #include "npc.hpp" +#include "weapon.hpp" +#include "armor.hpp" namespace MWClass { @@ -12,5 +14,7 @@ namespace MWClass Activator::registerSelf(); Creature::registerSelf(); Npc::registerSelf(); + Weapon::registerSelf(); + Armor::registerSelf(); } } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp new file mode 100644 index 000000000..de45582ef --- /dev/null +++ b/apps/openmw/mwclass/weapon.cpp @@ -0,0 +1,31 @@ + +#include "weapon.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +namespace MWClass +{ + bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const + { + return true; + } + + int Weapon::getItemMaxHealth (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->data.health; + } + + void Weapon::registerSelf() + { + boost::shared_ptr instance (new Weapon); + + registerClass (typeid (ESM::Weapon).name(), instance); + } +} diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp new file mode 100644 index 000000000..e14750bca --- /dev/null +++ b/apps/openmw/mwclass/weapon.hpp @@ -0,0 +1,22 @@ +#ifndef GAME_MWCLASS_WEAPON_H +#define GAME_MWCLASS_WEAPON_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Weapon : public MWWorld::Class + { + public: + + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; + ///< \return Item health data available? + + virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const; + ///< Return item max health or throw an exception, if class does not have item health + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 106f1b72e..e28b5593b 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -186,31 +186,14 @@ namespace MWScript MWWorld::Ptr ptr = context.getReference(); - if (mIndex==0) + if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr)) { // health is a special case - if (context.getReference().getType()== - typeid (ESMS::LiveCellRef *)) - { - ESMS::LiveCellRef *ref = - context.getReference().get(); + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getItemMaxHealth (ptr); + runtime.push (value); - Interpreter::Type_Integer value = ref->base->data.health; - runtime.push (value); - - return; - } - else if (context.getReference().getType()== - typeid (ESMS::LiveCellRef *)) - { - ESMS::LiveCellRef *ref = - context.getReference().get(); - - Interpreter::Type_Integer value = ref->base->data.health; - runtime.push (value); - - return; - } + return; } Interpreter::Type_Integer value = @@ -239,31 +222,14 @@ namespace MWScript MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); - if (mIndex==0) + if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr)) { // health is a special case - if (context.getWorld().getPtr (id, false).getType()== - typeid (ESMS::LiveCellRef *)) - { - ESMS::LiveCellRef *ref = - context.getWorld().getPtr (id, false).get(); + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getItemMaxHealth (ptr); + runtime.push (value); - Interpreter::Type_Integer value = ref->base->data.health; - runtime.push (value); - - return; - } - else if (context.getWorld().getPtr (id, false).getType()== - typeid (ESMS::LiveCellRef *)) - { - ESMS::LiveCellRef *ref = - context.getWorld().getPtr (id, false).get(); - - Interpreter::Type_Integer value = ref->base->data.health; - runtime.push (value); - - return; - } + return; } Interpreter::Type_Integer value = diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 9a2020337..e5840b96d 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -18,6 +18,16 @@ namespace MWWorld throw std::runtime_error ("class does not have creature stats"); } + bool Class::hasItemHealth (const Ptr& ptr) const + { + return false; + } + + int Class::getItemMaxHealth (const Ptr& ptr) const + { + throw std::runtime_error ("class does not have item health"); + } + 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 3144a7108..3d9eee7be 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -36,6 +36,12 @@ namespace MWWorld ///< Return creature stats or throw an exception, if class does not have creature stats /// (default implementation: throw an exceoption) + virtual bool hasItemHealth (const Ptr& ptr) const; + ///< \return Item health data available? (default implementation: false) + + virtual int getItemMaxHealth (const Ptr& ptr) const; + ///< Return item max health or throw an exception, if class does not have item health + /// (default implementation: throw an exceoption) static const Class& get (const std::string& key); ///< If there is no class for this \a key, an exception is thrown. From 0851044fa61348c0eb544df989b46b3853f9ea86 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 14:43:14 +0200 Subject: [PATCH 07/12] removed superfluous includes --- apps/openmw/mwworld/ptr.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 3769efdce..8bf75aa3c 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -5,8 +5,6 @@ #include -#include -#include #include #include "refdata.hpp" From f50ced4616b2181fe13e6a968a65c35e7b38bb01 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 15:24:44 +0200 Subject: [PATCH 08/12] added missing record classes --- apps/openmw/CMakeLists.txt | 30 ++++ apps/openmw/mwclass/apparatus.cpp | 14 ++ apps/openmw/mwclass/apparatus.hpp | 17 ++ apps/openmw/mwclass/book.cpp | 14 ++ apps/openmw/mwclass/book.hpp | 17 ++ apps/openmw/mwclass/classes.cpp | 30 ++++ apps/openmw/mwclass/clothing.cpp | 14 ++ apps/openmw/mwclass/clothing.hpp | 17 ++ apps/openmw/mwclass/container.cpp | 14 ++ apps/openmw/mwclass/container.hpp | 17 ++ apps/openmw/mwclass/creaturelevlist.cpp | 14 ++ apps/openmw/mwclass/creaturelevlist.hpp | 17 ++ apps/openmw/mwclass/door.cpp | 14 ++ apps/openmw/mwclass/door.hpp | 17 ++ apps/openmw/mwclass/ingredient.cpp | 14 ++ apps/openmw/mwclass/ingredient.hpp | 17 ++ apps/openmw/mwclass/itemlevlist.cpp | 14 ++ apps/openmw/mwclass/itemlevlist.hpp | 17 ++ apps/openmw/mwclass/light.cpp | 14 ++ apps/openmw/mwclass/light.hpp | 17 ++ apps/openmw/mwclass/lockpick.cpp | 14 ++ apps/openmw/mwclass/lockpick.hpp | 17 ++ apps/openmw/mwclass/misc.cpp | 14 ++ apps/openmw/mwclass/misc.hpp | 17 ++ apps/openmw/mwclass/potion.cpp | 14 ++ apps/openmw/mwclass/potion.hpp | 17 ++ apps/openmw/mwclass/probe.cpp | 14 ++ apps/openmw/mwclass/probe.hpp | 17 ++ apps/openmw/mwclass/repair.cpp | 14 ++ apps/openmw/mwclass/repair.hpp | 17 ++ apps/openmw/mwclass/static.cpp | 14 ++ apps/openmw/mwclass/static.hpp | 17 ++ apps/openmw/mwworld/world.cpp | 200 ++++++++++++------------ components/esm/loadlocks.hpp | 11 ++ components/esm_store/cell_store.hpp | 16 +- components/esm_store/store.hpp | 4 +- 36 files changed, 646 insertions(+), 110 deletions(-) create mode 100644 apps/openmw/mwclass/apparatus.cpp create mode 100644 apps/openmw/mwclass/apparatus.hpp create mode 100644 apps/openmw/mwclass/book.cpp create mode 100644 apps/openmw/mwclass/book.hpp create mode 100644 apps/openmw/mwclass/clothing.cpp create mode 100644 apps/openmw/mwclass/clothing.hpp create mode 100644 apps/openmw/mwclass/container.cpp create mode 100644 apps/openmw/mwclass/container.hpp create mode 100644 apps/openmw/mwclass/creaturelevlist.cpp create mode 100644 apps/openmw/mwclass/creaturelevlist.hpp create mode 100644 apps/openmw/mwclass/door.cpp create mode 100644 apps/openmw/mwclass/door.hpp create mode 100644 apps/openmw/mwclass/ingredient.cpp create mode 100644 apps/openmw/mwclass/ingredient.hpp create mode 100644 apps/openmw/mwclass/itemlevlist.cpp create mode 100644 apps/openmw/mwclass/itemlevlist.hpp create mode 100644 apps/openmw/mwclass/light.cpp create mode 100644 apps/openmw/mwclass/light.hpp create mode 100644 apps/openmw/mwclass/lockpick.cpp create mode 100644 apps/openmw/mwclass/lockpick.hpp create mode 100644 apps/openmw/mwclass/misc.cpp create mode 100644 apps/openmw/mwclass/misc.hpp create mode 100644 apps/openmw/mwclass/potion.cpp create mode 100644 apps/openmw/mwclass/potion.hpp create mode 100644 apps/openmw/mwclass/probe.cpp create mode 100644 apps/openmw/mwclass/probe.hpp create mode 100644 apps/openmw/mwclass/repair.cpp create mode 100644 apps/openmw/mwclass/repair.hpp create mode 100644 apps/openmw/mwclass/static.cpp create mode 100644 apps/openmw/mwclass/static.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index bf188b963..41392def0 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -98,6 +98,21 @@ set(GAMECLASS mwclass/npc.cpp mwclass/weapon.cpp mwclass/armor.cpp + mwclass/potion.cpp + mwclass/apparatus.cpp + mwclass/book.cpp + mwclass/clothing.cpp + mwclass/container.cpp + mwclass/door.cpp + mwclass/ingredient.cpp + mwclass/creaturelevlist.cpp + mwclass/itemlevlist.cpp + mwclass/light.cpp + mwclass/lockpick.cpp + mwclass/misc.cpp + mwclass/probe.cpp + mwclass/repair.cpp + mwclass/static.cpp ) set(GAMECLASS_HEADER mwclass/classes.hpp @@ -106,6 +121,21 @@ set(GAMECLASS_HEADER mwclass/npc.hpp mwclass/weapon.hpp mwclass/armor.hpp + mwclass/potion.hpp + mwclass/apparatus.hpp + mwclass/book.hpp + mwclass/clothing.hpp + mwclass/container.hpp + mwclass/door.hpp + mwclass/ingredient.hpp + mwclass/creaturelevlist.hpp + mwclass/itemlevlist.hpp + mwclass/light.hpp + mwclass/lockpick.hpp + mwclass/misc.hpp + mwclass/probe.hpp + mwclass/repair.hpp + mwclass/static.hpp ) source_group(apps\\openmw\\mwclass FILES ${GAMECLASS} ${GAMECLASS_HEADER}) diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp new file mode 100644 index 000000000..a141ef014 --- /dev/null +++ b/apps/openmw/mwclass/apparatus.cpp @@ -0,0 +1,14 @@ + +#include "apparatus.hpp" + +#include + +namespace MWClass +{ + void Apparatus::registerSelf() + { + boost::shared_ptr instance (new Apparatus); + + registerClass (typeid (ESM::Apparatus).name(), instance); + } +} diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp new file mode 100644 index 000000000..89a097b79 --- /dev/null +++ b/apps/openmw/mwclass/apparatus.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_APPARATUS_H +#define GAME_MWCLASS_APPARATUS_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Apparatus : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp new file mode 100644 index 000000000..2f89e2481 --- /dev/null +++ b/apps/openmw/mwclass/book.cpp @@ -0,0 +1,14 @@ + +#include "book.hpp" + +#include + +namespace MWClass +{ + void Book::registerSelf() + { + boost::shared_ptr instance (new Book); + + registerClass (typeid (ESM::Book).name(), instance); + } +} diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp new file mode 100644 index 000000000..e7cde69fa --- /dev/null +++ b/apps/openmw/mwclass/book.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_BOOK_H +#define GAME_MWCLASS_BOOK_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Book : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/classes.cpp b/apps/openmw/mwclass/classes.cpp index 655159e35..745614852 100644 --- a/apps/openmw/mwclass/classes.cpp +++ b/apps/openmw/mwclass/classes.cpp @@ -6,6 +6,21 @@ #include "npc.hpp" #include "weapon.hpp" #include "armor.hpp" +#include "potion.hpp" +#include "apparatus.hpp" +#include "book.hpp" +#include "clothing.hpp" +#include "container.hpp" +#include "door.hpp" +#include "ingredient.hpp" +#include "creaturelevlist.hpp" +#include "itemlevlist.hpp" +#include "light.hpp" +#include "lockpick.hpp" +#include "misc.hpp" +#include "probe.hpp" +#include "repair.hpp" +#include "static.hpp" namespace MWClass { @@ -16,5 +31,20 @@ namespace MWClass Npc::registerSelf(); Weapon::registerSelf(); Armor::registerSelf(); + Potion::registerSelf(); + Apparatus::registerSelf(); + Book::registerSelf(); + Clothing::registerSelf(); + Container::registerSelf(); + Door::registerSelf(); + Ingredient::registerSelf(); + CreatureLevList::registerSelf(); + ItemLevList::registerSelf(); + Light::registerSelf(); + Lockpick::registerSelf(); + Misc::registerSelf(); + Probe::registerSelf(); + Repair::registerSelf(); + Static::registerSelf(); } } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp new file mode 100644 index 000000000..820034cbf --- /dev/null +++ b/apps/openmw/mwclass/clothing.cpp @@ -0,0 +1,14 @@ + +#include "clothing.hpp" + +#include + +namespace MWClass +{ + void Clothing::registerSelf() + { + boost::shared_ptr instance (new Clothing); + + registerClass (typeid (ESM::Clothing).name(), instance); + } +} diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp new file mode 100644 index 000000000..a37ac8f43 --- /dev/null +++ b/apps/openmw/mwclass/clothing.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_CLOTHING_H +#define GAME_MWCLASS_CLOTHING_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Clothing : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp new file mode 100644 index 000000000..be194d71a --- /dev/null +++ b/apps/openmw/mwclass/container.cpp @@ -0,0 +1,14 @@ + +#include "container.hpp" + +#include + +namespace MWClass +{ + void Container::registerSelf() + { + boost::shared_ptr instance (new Container); + + registerClass (typeid (ESM::Container).name(), instance); + } +} diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp new file mode 100644 index 000000000..c26bb2e48 --- /dev/null +++ b/apps/openmw/mwclass/container.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_CONTAINER_H +#define GAME_MWCLASS_CONTAINER_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Container : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp new file mode 100644 index 000000000..700a3190b --- /dev/null +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -0,0 +1,14 @@ + +#include "creaturelevlist.hpp" + +#include + +namespace MWClass +{ + void CreatureLevList::registerSelf() + { + boost::shared_ptr instance (new CreatureLevList); + + registerClass (typeid (ESM::CreatureLevList).name(), instance); + } +} diff --git a/apps/openmw/mwclass/creaturelevlist.hpp b/apps/openmw/mwclass/creaturelevlist.hpp new file mode 100644 index 000000000..a8e8f5a1d --- /dev/null +++ b/apps/openmw/mwclass/creaturelevlist.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_CREATURELEVLIST_H +#define GAME_MWCLASS_CREATURELEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class CreatureLevList : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp new file mode 100644 index 000000000..20472e6f8 --- /dev/null +++ b/apps/openmw/mwclass/door.cpp @@ -0,0 +1,14 @@ + +#include "door.hpp" + +#include + +namespace MWClass +{ + void Door::registerSelf() + { + boost::shared_ptr instance (new Door); + + registerClass (typeid (ESM::Door).name(), instance); + } +} diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp new file mode 100644 index 000000000..2dc15b528 --- /dev/null +++ b/apps/openmw/mwclass/door.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_DOOR_H +#define GAME_MWCLASS_DOOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Door : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp new file mode 100644 index 000000000..4d0d4f567 --- /dev/null +++ b/apps/openmw/mwclass/ingredient.cpp @@ -0,0 +1,14 @@ + +#include "ingredient.hpp" + +#include + +namespace MWClass +{ + void Ingredient::registerSelf() + { + boost::shared_ptr instance (new Ingredient); + + registerClass (typeid (ESM::Ingredient).name(), instance); + } +} diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp new file mode 100644 index 000000000..2ed4aa66b --- /dev/null +++ b/apps/openmw/mwclass/ingredient.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_INGREDIENT_H +#define GAME_MWCLASS_INGREDIENT_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Ingredient : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/itemlevlist.cpp b/apps/openmw/mwclass/itemlevlist.cpp new file mode 100644 index 000000000..d0e466b01 --- /dev/null +++ b/apps/openmw/mwclass/itemlevlist.cpp @@ -0,0 +1,14 @@ + +#include "itemlevlist.hpp" + +#include + +namespace MWClass +{ + void ItemLevList::registerSelf() + { + boost::shared_ptr instance (new ItemLevList); + + registerClass (typeid (ESM::ItemLevList).name(), instance); + } +} diff --git a/apps/openmw/mwclass/itemlevlist.hpp b/apps/openmw/mwclass/itemlevlist.hpp new file mode 100644 index 000000000..2047d4025 --- /dev/null +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_ITEMLEVLIST_H +#define GAME_MWCLASS_ITEMLEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class ItemLevList : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp new file mode 100644 index 000000000..4ab18ea70 --- /dev/null +++ b/apps/openmw/mwclass/light.cpp @@ -0,0 +1,14 @@ + +#include "light.hpp" + +#include + +namespace MWClass +{ + void Light::registerSelf() + { + boost::shared_ptr instance (new Light); + + registerClass (typeid (ESM::Light).name(), instance); + } +} diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp new file mode 100644 index 000000000..a1c7b7c0f --- /dev/null +++ b/apps/openmw/mwclass/light.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_LIGHT_H +#define GAME_MWCLASS_LIGHT_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Light : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp new file mode 100644 index 000000000..ed7ce3eaa --- /dev/null +++ b/apps/openmw/mwclass/lockpick.cpp @@ -0,0 +1,14 @@ + +#include "lockpick.hpp" + +#include + +namespace MWClass +{ + void Lockpick::registerSelf() + { + boost::shared_ptr instance (new Lockpick); + + registerClass (typeid (ESM::Tool).name(), instance); + } +} diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp new file mode 100644 index 000000000..32e641a08 --- /dev/null +++ b/apps/openmw/mwclass/lockpick.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_LOCKPICK_H +#define GAME_MWCLASS_LOCKPICK_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Lockpick : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp new file mode 100644 index 000000000..04b76fe6a --- /dev/null +++ b/apps/openmw/mwclass/misc.cpp @@ -0,0 +1,14 @@ + +#include "misc.hpp" + +#include + +namespace MWClass +{ + void Misc::registerSelf() + { + boost::shared_ptr instance (new Misc); + + registerClass (typeid (ESM::Misc).name(), instance); + } +} diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp new file mode 100644 index 000000000..94b699d53 --- /dev/null +++ b/apps/openmw/mwclass/misc.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_MISC_H +#define GAME_MWCLASS_MISC_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Misc : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp new file mode 100644 index 000000000..21f8f4f99 --- /dev/null +++ b/apps/openmw/mwclass/potion.cpp @@ -0,0 +1,14 @@ + +#include "potion.hpp" + +#include + +namespace MWClass +{ + void Potion::registerSelf() + { + boost::shared_ptr instance (new Potion); + + registerClass (typeid (ESM::Potion).name(), instance); + } +} diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp new file mode 100644 index 000000000..c0d3faca6 --- /dev/null +++ b/apps/openmw/mwclass/potion.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_POTION_H +#define GAME_MWCLASS_POTION_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Potion : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp new file mode 100644 index 000000000..c19c873b4 --- /dev/null +++ b/apps/openmw/mwclass/probe.cpp @@ -0,0 +1,14 @@ + +#include "probe.hpp" + +#include + +namespace MWClass +{ + void Probe::registerSelf() + { + boost::shared_ptr instance (new Probe); + + registerClass (typeid (ESM::Probe).name(), instance); + } +} diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp new file mode 100644 index 000000000..dd0215c71 --- /dev/null +++ b/apps/openmw/mwclass/probe.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_PROBE_H +#define GAME_MWCLASS_PROBE_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Probe : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp new file mode 100644 index 000000000..d5bc79fc7 --- /dev/null +++ b/apps/openmw/mwclass/repair.cpp @@ -0,0 +1,14 @@ + +#include "repair.hpp" + +#include + +namespace MWClass +{ + void Repair::registerSelf() + { + boost::shared_ptr instance (new Repair); + + registerClass (typeid (ESM::Repair).name(), instance); + } +} diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp new file mode 100644 index 000000000..81beec628 --- /dev/null +++ b/apps/openmw/mwclass/repair.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_REPAIR_H +#define GAME_MWCLASS_REPAIR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Repair : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp new file mode 100644 index 000000000..ab601ff42 --- /dev/null +++ b/apps/openmw/mwclass/static.cpp @@ -0,0 +1,14 @@ + +#include "static.hpp" + +#include + +namespace MWClass +{ + void Static::registerSelf() + { + boost::shared_ptr instance (new Static); + + registerClass (typeid (ESM::Static).name(), instance); + } +} diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp new file mode 100644 index 000000000..aa462d0a1 --- /dev/null +++ b/apps/openmw/mwclass/static.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWCLASS_STATIC_H +#define GAME_MWCLASS_STATIC_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Static : public MWWorld::Class + { + public: + + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 55be70f1c..dd46e87ab 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -28,9 +28,9 @@ namespace if (!iter->base->script.empty()) { if (const ESM::Script *script = store.scripts.find (iter->base->script)) - { + { iter->mData.setLocals (*script); - + scriptList.push_back ( std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell))); } @@ -61,7 +61,7 @@ namespace MWWorld listCellScripts (mStore, cell.repairs, mLocalScripts, &cell); listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); } - + Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = cell.activators.find (name)) @@ -69,68 +69,68 @@ namespace MWWorld if (ESMS::LiveCellRef *ref = cell.potions.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.appas.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.armors.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.books.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.containers.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.doors.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.lights.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.probes.find (name)) + + if (ESMS::LiveCellRef *ref = cell.probes.find (name)) return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) + + if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.statics.find (name)) return Ptr (ref, &cell); - + if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) return Ptr (ref, &cell); - + return Ptr(); } - + MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { CellRenderCollection::iterator iter = mActiveCells.find (store); - + if (iter!=mActiveCells.end()) { return iter->second; @@ -141,10 +141,10 @@ namespace MWWorld if (iter!=mBufferedCells.end()) return iter->second; } - + return 0; } - + int World::getDaysPerMonth (int month) const { switch (month) @@ -162,84 +162,84 @@ namespace MWWorld case 10: return 30; case 11: return 31; } - + throw std::runtime_error ("month out of range"); } - + World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, bool newGame, Environment& environment) : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), mSky (false), mCellChanged (false), mEnvironment (environment) - { + { boost::filesystem::path masterPath (dataDir); masterPath /= master; - + std::cout << "Loading ESM " << masterPath.string() << "\n"; // This parses the ESM file and loads a sample cell mEsm.open (masterPath.file_string()); mStore.load (mEsm); - + mPlayerPos = new MWRender::PlayerPos (mScene.getCamera(), mStore.npcs.find ("player")); // global variables mGlobalVariables = new Globals (mStore); - + if (newGame) - { + { // set new game mark mGlobalVariables->setInt ("chargenstate", 1); } - + mSkyManager = - MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera()); + MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera()); } - + World::~World() { for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) delete iter->second; - + for (CellRenderCollection::iterator iter (mBufferedCells.begin()); iter!=mBufferedCells.end(); ++iter) delete iter->second; - + delete mPlayerPos; delete mSkyManager; delete mGlobalVariables; } - + MWRender::PlayerPos& World::getPlayerPos() { return *mPlayerPos; } - + ESMS::ESMStore& World::getStore() { return mStore; } - + const World::ScriptList& World::getLocalScripts() const { return mLocalScripts; } - + bool World::hasCellChanged() const { return mCellChanged; } - + Globals::Data& World::getGlobalVariable (const std::string& name) { return (*mGlobalVariables)[name]; } - + char World::getGlobalVariableType (const std::string& name) const { return mGlobalVariables->getType (name); - } - + } + Ptr World::getPtr (const std::string& name, bool activeOnly) { // the player is always in an active cell. @@ -247,35 +247,35 @@ namespace MWWorld { return mPlayerPos->getPlayer(); } - + // active cells for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) { Ptr ptr = getPtr (name, *iter->first); - + if (!ptr.isEmpty()) return ptr; } - + if (!activeOnly) { // TODO: inactive cells } - + throw std::runtime_error ("unknown ID: " + name); } - + void World::enable (Ptr reference) { if (!reference.getRefData().isEnabled()) { reference.getRefData().enable(); - + if (MWRender::CellRender *render = searchRender (reference.getCell())) { render->enable (reference.getRefData().getHandle()); - + if (mActiveCells.find (reference.getCell())!=mActiveCells.end() && (reference.getType()==typeid (ESMS::LiveCellRef) || reference.getType()==typeid (ESMS::LiveCellRef))) @@ -285,69 +285,69 @@ namespace MWWorld } } } - + void World::disable (Ptr reference) { if (!reference.getRefData().isEnabled()) { reference.getRefData().enable(); - + if (MWRender::CellRender *render = searchRender (reference.getCell())) { render->disable (reference.getRefData().getHandle()); - + if (mActiveCells.find (reference.getCell())!=mActiveCells.end() && (reference.getType()==typeid (ESMS::LiveCellRef) || reference.getType()==typeid (ESMS::LiveCellRef))) { mEnvironment.mMechanicsManager->removeActor (reference); - } + } } - } + } } - + void World::advanceTime (double hours) { hours += mGlobalVariables->getFloat ("gamehour"); setHour (hours); - + int days = hours / 24; - + if (days>0) mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed")); } - + void World::setHour (double hour) { if (hour<0) hour = 0; - + int days = hour / 24; - + hour = std::fmod (hour, 24); - + mGlobalVariables->setFloat ("gamehour", hour); - + mSkyManager->setHour (hour); - + if (days>0) setDay (days + mGlobalVariables->getInt ("day")); } - + void World::setDay (int day) { if (day<0) day = 0; int month = mGlobalVariables->getInt ("month"); - + while (true) { - int days = getDaysPerMonth (month); + int days = getDaysPerMonth (month); if (daysetInt ("year", mGlobalVariables->getInt ("year")+1); } - + day -= days; - } - - mGlobalVariables->setInt ("day", day); + } + + mGlobalVariables->setInt ("day", day); mGlobalVariables->setInt ("month", month); mSkyManager->setDate (day, month); - } - + } + void World::setMonth (int month) { if (month<0) month = 0; - + int years = month / 12; month = month % 12; - + int days = getDaysPerMonth (month); - + if (mGlobalVariables->getInt ("day")>=days) mGlobalVariables->setInt ("day", days-1); - + mGlobalVariables->setInt ("month", month); - + if (years>0) mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year")); mSkyManager->setDate (mGlobalVariables->getInt ("day"), month); } - + void World::toggleSky() { if (mSky) @@ -405,36 +405,36 @@ namespace MWWorld mSkyManager->enable(); } } - + int World::getMasserPhase() const { return mSkyManager->getMasserPhase(); } - + int World::getSecundaPhase() const { return mSkyManager->getSecundaPhase(); } - + void World::setMoonColour (bool red) { - mSkyManager->setMoonColour (red); + mSkyManager->setMoonColour (red); } - + float World::getTimeScaleFactor() const { return mGlobalVariables->getInt ("timescale"); } - + void World::changeCell (const std::string& cellName, const ESM::Position& position) { - // Load cell. + // Load cell. mInteriors[cellName].loadInt (cellName, mStore, mEsm); Ptr::CellStore *cell = &mInteriors[cellName]; - + // remove active CellRenderCollection::iterator active = mActiveCells.begin(); - + if (active!=mActiveCells.end()) { mEnvironment.mMechanicsManager->dropActors (active->first); @@ -444,7 +444,7 @@ namespace MWWorld } // register local scripts - mLocalScripts.clear(); // FIXME won't work with exteriors + mLocalScripts.clear(); // FIXME won't work with exteriors insertInteriorScripts (*cell); // adjust player @@ -458,11 +458,11 @@ namespace MWWorld new MWRender::InteriorCellRender (*cell, mScene))); if (result.second) - { + { // Load the cell and insert it into the renderer result.first->second->show(); } - + // Actors mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer()); mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer()); @@ -496,12 +496,12 @@ namespace MWWorld // TODO set weather toggleSky(); } - + mCellChanged = true; } - + void World::markCellAsUnchanged() { - mCellChanged = false; + mCellChanged = false; } } diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index acd8a7805..3b7913ea9 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -50,5 +50,16 @@ struct Tool icon = esm.getHNOString("ITEX"); } }; + +struct Probe : Tool +{ + +}; + +struct Repair : Tool +{ + +}; + } #endif diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 941dba6fe..d4d7cc2f8 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -63,7 +63,7 @@ namespace ESMS list.push_back(lr); } - + LiveRef *find (const std::string& name) { for (typename std::list::iterator iter (list.begin()); iter!=list.end(); ++iter) @@ -71,9 +71,9 @@ namespace ESMS if (iter->ref.refID==name) return &*iter; } - + return 0; - } + } }; /// A storage struct for one single cell reference. @@ -102,8 +102,8 @@ namespace ESMS CellRefList lockpicks; CellRefList miscItems; CellRefList npcs; - CellRefList probes; - CellRefList repairs; + CellRefList probes; + CellRefList repairs; CellRefList statics; CellRefList weapons; @@ -119,12 +119,12 @@ namespace ESMS throw str_exception("Cell not found - " + name); loadRefs(store, esm); - } + } /** Ditto for exterior cell. */ void loadExt(int X, int Y, const ESMStore &store, ESMReader &esm) { - + } private: @@ -176,7 +176,7 @@ namespace ESMS } } } - + }; } diff --git a/components/esm_store/store.hpp b/components/esm_store/store.hpp index 7c4971ac4..fd4a47d4b 100644 --- a/components/esm_store/store.hpp +++ b/components/esm_store/store.hpp @@ -55,10 +55,10 @@ namespace ESMS RecListT miscItems; RecListT npcs; RecListT npcChange; - RecListT probes; + RecListT probes; RecListT races; RecListT regions; - RecListT repairs; + RecListT repairs; RecListT soundGens; RecListT sounds; RecListT spells; From 239498bcd4f42d35da044f01f8d8731d85192fbf Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 17:11:41 +0200 Subject: [PATCH 09/12] added getName function --- apps/openmw/mwclass/activator.cpp | 12 ++++++++++++ apps/openmw/mwclass/activator.hpp | 3 +++ apps/openmw/mwclass/apparatus.cpp | 12 ++++++++++++ apps/openmw/mwclass/apparatus.hpp | 3 +++ apps/openmw/mwclass/armor.cpp | 8 ++++++++ apps/openmw/mwclass/armor.hpp | 4 ++++ apps/openmw/mwclass/book.cpp | 12 ++++++++++++ apps/openmw/mwclass/book.hpp | 3 +++ apps/openmw/mwclass/clothing.cpp | 12 ++++++++++++ apps/openmw/mwclass/clothing.hpp | 3 +++ apps/openmw/mwclass/container.cpp | 12 ++++++++++++ apps/openmw/mwclass/container.hpp | 3 +++ apps/openmw/mwclass/creature.cpp | 8 ++++++++ apps/openmw/mwclass/creature.hpp | 4 ++++ apps/openmw/mwclass/creaturelevlist.cpp | 5 +++++ apps/openmw/mwclass/creaturelevlist.hpp | 3 +++ apps/openmw/mwclass/door.cpp | 12 ++++++++++++ apps/openmw/mwclass/door.hpp | 3 +++ apps/openmw/mwclass/ingredient.cpp | 12 ++++++++++++ apps/openmw/mwclass/ingredient.hpp | 3 +++ apps/openmw/mwclass/itemlevlist.cpp | 5 +++++ apps/openmw/mwclass/itemlevlist.hpp | 3 +++ apps/openmw/mwclass/light.cpp | 15 +++++++++++++++ apps/openmw/mwclass/light.hpp | 3 +++ apps/openmw/mwclass/lockpick.cpp | 12 ++++++++++++ apps/openmw/mwclass/lockpick.hpp | 3 +++ apps/openmw/mwclass/misc.cpp | 12 ++++++++++++ apps/openmw/mwclass/misc.hpp | 3 +++ apps/openmw/mwclass/npc.cpp | 8 ++++++++ apps/openmw/mwclass/npc.hpp | 4 ++++ apps/openmw/mwclass/potion.cpp | 12 ++++++++++++ apps/openmw/mwclass/potion.hpp | 3 +++ apps/openmw/mwclass/probe.cpp | 12 ++++++++++++ apps/openmw/mwclass/probe.hpp | 3 +++ apps/openmw/mwclass/repair.cpp | 12 ++++++++++++ apps/openmw/mwclass/repair.hpp | 3 +++ apps/openmw/mwclass/static.cpp | 5 +++++ apps/openmw/mwclass/static.hpp | 3 +++ apps/openmw/mwclass/weapon.cpp | 8 ++++++++ apps/openmw/mwclass/weapon.hpp | 4 ++++ apps/openmw/mwworld/class.hpp | 4 ++++ 41 files changed, 274 insertions(+) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 0e3df53a2..ff2d559f4 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Activator::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Activator::registerSelf() { boost::shared_ptr instance (new Activator); diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index a649ce6ef..5639117b7 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index a141ef014..1a936e76b 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Apparatus::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Apparatus::registerSelf() { boost::shared_ptr instance (new Apparatus); diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 89a097b79..96c838e8d 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index cdeeb06e0..1a339c703 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -9,6 +9,14 @@ namespace MWClass { + std::string Armor::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const { return true; diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 0bc3856ce..4a6cd2f75 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -9,6 +9,10 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; ///< \return Item health data available? diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 2f89e2481..d16269857 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Book::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Book::registerSelf() { boost::shared_ptr instance (new Book); diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index e7cde69fa..b9a03f2e7 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 820034cbf..a728394d9 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Clothing::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Clothing::registerSelf() { boost::shared_ptr instance (new Clothing); diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index a37ac8f43..1b8dcf16d 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index be194d71a..a6df294e7 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Container::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Container::registerSelf() { boost::shared_ptr instance (new Container); diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index c26bb2e48..0b907b2b7 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index a367b0f8f..198c0e72f 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -9,6 +9,14 @@ namespace MWClass { + std::string Creature::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getCreatureStats().get()) diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index a583fb6d4..5056501c5 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -9,6 +9,10 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index 700a3190b..53dd34bb4 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -5,6 +5,11 @@ namespace MWClass { + std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + void CreatureLevList::registerSelf() { boost::shared_ptr instance (new CreatureLevList); diff --git a/apps/openmw/mwclass/creaturelevlist.hpp b/apps/openmw/mwclass/creaturelevlist.hpp index a8e8f5a1d..81965efd5 100644 --- a/apps/openmw/mwclass/creaturelevlist.hpp +++ b/apps/openmw/mwclass/creaturelevlist.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 20472e6f8..50bd749c8 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Door::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Door::registerSelf() { boost::shared_ptr instance (new Door); diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index 2dc15b528..ae2c90ec7 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 4d0d4f567..6ae80c440 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Ingredient::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Ingredient::registerSelf() { boost::shared_ptr instance (new Ingredient); diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 2ed4aa66b..eed520cb1 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/itemlevlist.cpp b/apps/openmw/mwclass/itemlevlist.cpp index d0e466b01..6ed9ab2e5 100644 --- a/apps/openmw/mwclass/itemlevlist.cpp +++ b/apps/openmw/mwclass/itemlevlist.cpp @@ -5,6 +5,11 @@ namespace MWClass { + std::string ItemLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + void ItemLevList::registerSelf() { boost::shared_ptr instance (new ItemLevList); diff --git a/apps/openmw/mwclass/itemlevlist.hpp b/apps/openmw/mwclass/itemlevlist.hpp index 2047d4025..0b71b072c 100644 --- a/apps/openmw/mwclass/itemlevlist.hpp +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 4ab18ea70..bf983259b 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -3,8 +3,23 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Light::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->base->model.empty()) + return ""; + + return ref->base->name; + } + void Light::registerSelf() { boost::shared_ptr instance (new Light); diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index a1c7b7c0f..8fa53aeaf 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index ed7ce3eaa..ee861c30b 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Lockpick::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Lockpick::registerSelf() { boost::shared_ptr instance (new Lockpick); diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 32e641a08..daff07f85 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 04b76fe6a..eabb7ba7a 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Misc::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Misc::registerSelf() { boost::shared_ptr instance (new Misc); diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 94b699d53..d2f685d40 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 97bcd54ad..dbb7f2a93 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -9,6 +9,14 @@ namespace MWClass { + std::string Npc::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getCreatureStats().get()) diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 48367bc71..76c56de40 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -9,6 +9,10 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 21f8f4f99..75f2f6ccb 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Potion::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Potion::registerSelf() { boost::shared_ptr instance (new Potion); diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index c0d3faca6..350aba156 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index c19c873b4..65fbf47cb 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Probe::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Probe::registerSelf() { boost::shared_ptr instance (new Probe); diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index dd0215c71..1a60f220a 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index d5bc79fc7..722baebde 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -3,8 +3,20 @@ #include +#include + +#include "../mwworld/ptr.hpp" + namespace MWClass { + std::string Repair::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + void Repair::registerSelf() { boost::shared_ptr instance (new Repair); diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 81beec628..e7a9928ed 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index ab601ff42..f2bc4f635 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -5,6 +5,11 @@ namespace MWClass { + std::string Static::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + void Static::registerSelf() { boost::shared_ptr instance (new Static); diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index aa462d0a1..fb8080182 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -9,6 +9,9 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. static void registerSelf(); }; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index de45582ef..5ca80bcb7 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -9,6 +9,14 @@ namespace MWClass { + std::string Weapon::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const { return true; diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index e14750bca..98e5930f8 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -9,6 +9,10 @@ namespace MWClass { public: + virtual std::string getName (const MWWorld::Ptr& ptr) const; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; ///< \return Item health data available? diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 3d9eee7be..ceaf14292 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -32,6 +32,10 @@ namespace MWWorld virtual ~Class(); + virtual std::string getName (const Ptr& ptr) const = 0; + ///< \return name (the one that is to be presented to the user; not the internal one); + /// can return an empty string. + virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const; ///< Return creature stats or throw an exception, if class does not have creature stats /// (default implementation: throw an exceoption) From c38b02bd5c031ee7a4deab3ff96a402952f7ff1e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 18:20:15 +0200 Subject: [PATCH 10/12] added action interface --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwworld/action.hpp | 25 +++++++++++++++++++++++++ apps/openmw/mwworld/class.cpp | 11 +++++++++++ apps/openmw/mwworld/class.hpp | 9 +++++++++ apps/openmw/mwworld/nullaction.hpp | 17 +++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 apps/openmw/mwworld/action.hpp create mode 100644 apps/openmw/mwworld/nullaction.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 41392def0..466f7570f 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -88,6 +88,8 @@ set(GAMEWORLD_HEADER mwworld/environment.hpp mwworld/globals.hpp mwworld/class.hpp + mwworld/action.hpp + mwworld/nullaction.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp new file mode 100644 index 000000000..155819335 --- /dev/null +++ b/apps/openmw/mwworld/action.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_MWWORLD_ACTION_H +#define GAME_MWWORLD_ACTION_H + +namespace MWWorld +{ + class Environment; + + /// \brief Abstract base for actions + class Action + { + // not implemented + Action (const Action& action); + Action& operator= (const Action& action); + + public: + + Action() {} + + virtual ~Action() {} + + virtual void execute (Environment& environment) = 0; + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index e5840b96d..9a6a73a87 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -4,6 +4,7 @@ #include #include "ptr.hpp" +#include "nullaction.hpp" namespace MWWorld { @@ -28,6 +29,16 @@ namespace MWWorld throw std::runtime_error ("class does not have item health"); } + boost::shared_ptr Class::activate (const Ptr& ptr) const + { + return boost::shared_ptr (new NullAction); + } + + boost::shared_ptr Class::use (const Ptr& ptr) const + { + return boost::shared_ptr (new NullAction); + } + 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 ceaf14292..8287284c0 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -6,6 +6,8 @@ #include +#include "action.hpp" + namespace MWMechanics { struct CreatureStats; @@ -47,6 +49,13 @@ 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; + ///< Generate action for activation (default implementation: return a null action). + + virtual boost::shared_ptr use (const Ptr& ptr) const; + ///< Generate action for using via inventory menu (default implementation: return a + /// null action). + static const Class& get (const std::string& key); ///< If there is no class for this \a key, an exception is thrown. diff --git a/apps/openmw/mwworld/nullaction.hpp b/apps/openmw/mwworld/nullaction.hpp new file mode 100644 index 000000000..820fc4538 --- /dev/null +++ b/apps/openmw/mwworld/nullaction.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWWORLD_NULLACTION_H +#define GAME_MWWORLD_NULLACTION_H + +#include "action.hpp" + +namespace MWWorld +{ + /// \brief Action: do nothing + class NullAction : public Action + { + public: + + virtual void execute (Environment& environment) {} + }; +} + +#endif From 7e5ddae3b3377ecf489dc68b76e4f70de049cedf Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 18:22:01 +0200 Subject: [PATCH 11/12] modified action interface to allow other actors besides the player --- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 9a6a73a87..02859a7c8 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -29,7 +29,7 @@ namespace MWWorld throw std::runtime_error ("class does not have item health"); } - boost::shared_ptr Class::activate (const Ptr& ptr) const + boost::shared_ptr Class::activate (const Ptr& ptr, const Ptr& actor) const { return boost::shared_ptr (new NullAction); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 8287284c0..55efbcc53 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -49,7 +49,7 @@ 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; + virtual boost::shared_ptr activate (const Ptr& ptr, const Ptr& actor) const; ///< Generate action for activation (default implementation: return a null action). virtual boost::shared_ptr use (const Ptr& ptr) const; From 002345270bbb9e2567940f93d8441e174e340fb0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 18:44:52 +0200 Subject: [PATCH 12/12] 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).