diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 260ebcd70f..0fe62ea4f9 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,41 +68,96 @@ 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/actionteleport.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/action.hpp + mwworld/nullaction.hpp + mwworld/actionteleport.hpp ) -source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) +source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) + +set(GAMECLASS + mwclass/classes.cpp + mwclass/activator.cpp + mwclass/creature.cpp + 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 + mwclass/activator.hpp + mwclass/creature.hpp + 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}) 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} + ${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 43a01b271e..5b6aea3c2f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -24,6 +24,8 @@ #include "mwworld/ptr.hpp" #include "mwworld/environment.hpp" +#include "mwclass/classes.hpp" + #include "mwmechanics/mechanicsmanager.hpp" #include @@ -78,6 +80,7 @@ OMW::Engine::Engine() , mScriptManager (0) , mScriptContext (0) { + MWClass::registerClasses(); } OMW::Engine::~Engine() diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp new file mode 100644 index 0000000000..ff2d559f46 --- /dev/null +++ b/apps/openmw/mwclass/activator.cpp @@ -0,0 +1,26 @@ + +#include "activator.hpp" + +#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); + + registerClass (typeid (ESM::Activator).name(), instance); + } +} diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp new file mode 100644 index 0000000000..5639117b72 --- /dev/null +++ b/apps/openmw/mwclass/activator.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_ACTIVATOR_H +#define GAME_MWCLASS_ACTIVATOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Activator : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp new file mode 100644 index 0000000000..1a936e76ba --- /dev/null +++ b/apps/openmw/mwclass/apparatus.cpp @@ -0,0 +1,26 @@ + +#include "apparatus.hpp" + +#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); + + 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 0000000000..96c838e8d9 --- /dev/null +++ b/apps/openmw/mwclass/apparatus.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_APPARATUS_H +#define GAME_MWCLASS_APPARATUS_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Apparatus : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp new file mode 100644 index 0000000000..1a339c7034 --- /dev/null +++ b/apps/openmw/mwclass/armor.cpp @@ -0,0 +1,39 @@ + +#include "armor.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +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; + } + + 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 0000000000..4a6cd2f75d --- /dev/null +++ b/apps/openmw/mwclass/armor.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWCLASS_ARMOR_H +#define GAME_MWCLASS_ARMOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Armor : public MWWorld::Class + { + 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? + + 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/book.cpp b/apps/openmw/mwclass/book.cpp new file mode 100644 index 0000000000..d162698571 --- /dev/null +++ b/apps/openmw/mwclass/book.cpp @@ -0,0 +1,26 @@ + +#include "book.hpp" + +#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); + + 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 0000000000..b9a03f2e76 --- /dev/null +++ b/apps/openmw/mwclass/book.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_BOOK_H +#define GAME_MWCLASS_BOOK_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Book : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/classes.cpp b/apps/openmw/mwclass/classes.cpp new file mode 100644 index 0000000000..7456148527 --- /dev/null +++ b/apps/openmw/mwclass/classes.cpp @@ -0,0 +1,50 @@ + +#include "classes.hpp" + +#include "activator.hpp" +#include "creature.hpp" +#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 +{ + void registerClasses() + { + Activator::registerSelf(); + Creature::registerSelf(); + 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/classes.hpp b/apps/openmw/mwclass/classes.hpp new file mode 100644 index 0000000000..0ab90b677b --- /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/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp new file mode 100644 index 0000000000..a728394d94 --- /dev/null +++ b/apps/openmw/mwclass/clothing.cpp @@ -0,0 +1,26 @@ + +#include "clothing.hpp" + +#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); + + 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 0000000000..1b8dcf16dc --- /dev/null +++ b/apps/openmw/mwclass/clothing.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_CLOTHING_H +#define GAME_MWCLASS_CLOTHING_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Clothing : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp new file mode 100644 index 0000000000..a6df294e7d --- /dev/null +++ b/apps/openmw/mwclass/container.cpp @@ -0,0 +1,26 @@ + +#include "container.hpp" + +#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); + + 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 0000000000..0b907b2b79 --- /dev/null +++ b/apps/openmw/mwclass/container.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_CONTAINER_H +#define GAME_MWCLASS_CONTAINER_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Container : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp new file mode 100644 index 0000000000..198c0e72fd --- /dev/null +++ b/apps/openmw/mwclass/creature.cpp @@ -0,0 +1,53 @@ + +#include "creature.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" + +#include "../mwworld/ptr.hpp" + +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()) + { + 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/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp new file mode 100644 index 0000000000..5056501c5c --- /dev/null +++ b/apps/openmw/mwclass/creature.hpp @@ -0,0 +1,23 @@ +#ifndef GAME_MWCLASS_CREATURE_H +#define GAME_MWCLASS_CREATURE_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Creature : public MWWorld::Class + { + 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 + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp new file mode 100644 index 0000000000..53dd34bb48 --- /dev/null +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -0,0 +1,19 @@ + +#include "creaturelevlist.hpp" + +#include + +namespace MWClass +{ + std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + 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 0000000000..81965efd58 --- /dev/null +++ b/apps/openmw/mwclass/creaturelevlist.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_CREATURELEVLIST_H +#define GAME_MWCLASS_CREATURELEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class CreatureLevList : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp new file mode 100644 index 0000000000..24710fa4cc --- /dev/null +++ b/apps/openmw/mwclass/door.cpp @@ -0,0 +1,62 @@ + +#include "door.hpp" + +#include + +#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 +{ + std::string Door::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + 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); + + 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 0000000000..28d0486331 --- /dev/null +++ b/apps/openmw/mwclass/door.hpp @@ -0,0 +1,24 @@ +#ifndef GAME_MWCLASS_DOOR_H +#define GAME_MWCLASS_DOOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Door : public MWWorld::Class + { + 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 boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp new file mode 100644 index 0000000000..6ae80c4408 --- /dev/null +++ b/apps/openmw/mwclass/ingredient.cpp @@ -0,0 +1,26 @@ + +#include "ingredient.hpp" + +#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); + + 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 0000000000..eed520cb15 --- /dev/null +++ b/apps/openmw/mwclass/ingredient.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_INGREDIENT_H +#define GAME_MWCLASS_INGREDIENT_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Ingredient : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/itemlevlist.cpp b/apps/openmw/mwclass/itemlevlist.cpp new file mode 100644 index 0000000000..6ed9ab2e53 --- /dev/null +++ b/apps/openmw/mwclass/itemlevlist.cpp @@ -0,0 +1,19 @@ + +#include "itemlevlist.hpp" + +#include + +namespace MWClass +{ + std::string ItemLevList::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + 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 0000000000..0b71b072c8 --- /dev/null +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_ITEMLEVLIST_H +#define GAME_MWCLASS_ITEMLEVLIST_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class ItemLevList : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp new file mode 100644 index 0000000000..bf983259b7 --- /dev/null +++ b/apps/openmw/mwclass/light.cpp @@ -0,0 +1,29 @@ + +#include "light.hpp" + +#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); + + 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 0000000000..8fa53aeaf9 --- /dev/null +++ b/apps/openmw/mwclass/light.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_LIGHT_H +#define GAME_MWCLASS_LIGHT_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Light : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp new file mode 100644 index 0000000000..ee861c30b3 --- /dev/null +++ b/apps/openmw/mwclass/lockpick.cpp @@ -0,0 +1,26 @@ + +#include "lockpick.hpp" + +#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); + + 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 0000000000..daff07f85f --- /dev/null +++ b/apps/openmw/mwclass/lockpick.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_LOCKPICK_H +#define GAME_MWCLASS_LOCKPICK_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Lockpick : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp new file mode 100644 index 0000000000..eabb7ba7ae --- /dev/null +++ b/apps/openmw/mwclass/misc.cpp @@ -0,0 +1,26 @@ + +#include "misc.hpp" + +#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); + + 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 0000000000..d2f685d406 --- /dev/null +++ b/apps/openmw/mwclass/misc.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_MISC_H +#define GAME_MWCLASS_MISC_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Misc : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp new file mode 100644 index 0000000000..dbb7f2a934 --- /dev/null +++ b/apps/openmw/mwclass/npc.cpp @@ -0,0 +1,53 @@ + +#include "npc.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" + +#include "../mwworld/ptr.hpp" + +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()) + { + 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/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp new file mode 100644 index 0000000000..76c56de40e --- /dev/null +++ b/apps/openmw/mwclass/npc.hpp @@ -0,0 +1,23 @@ +#ifndef GAME_MWCLASS_NPC_H +#define GAME_MWCLASS_NPC_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Npc : public MWWorld::Class + { + 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 + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp new file mode 100644 index 0000000000..75f2f6ccb2 --- /dev/null +++ b/apps/openmw/mwclass/potion.cpp @@ -0,0 +1,26 @@ + +#include "potion.hpp" + +#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); + + 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 0000000000..350aba1569 --- /dev/null +++ b/apps/openmw/mwclass/potion.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_POTION_H +#define GAME_MWCLASS_POTION_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Potion : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp new file mode 100644 index 0000000000..65fbf47cbf --- /dev/null +++ b/apps/openmw/mwclass/probe.cpp @@ -0,0 +1,26 @@ + +#include "probe.hpp" + +#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); + + 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 0000000000..1a60f220a5 --- /dev/null +++ b/apps/openmw/mwclass/probe.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_PROBE_H +#define GAME_MWCLASS_PROBE_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Probe : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp new file mode 100644 index 0000000000..722baebde3 --- /dev/null +++ b/apps/openmw/mwclass/repair.cpp @@ -0,0 +1,26 @@ + +#include "repair.hpp" + +#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); + + 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 0000000000..e7a9928ede --- /dev/null +++ b/apps/openmw/mwclass/repair.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_REPAIR_H +#define GAME_MWCLASS_REPAIR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Repair : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp new file mode 100644 index 0000000000..f2bc4f6357 --- /dev/null +++ b/apps/openmw/mwclass/static.cpp @@ -0,0 +1,19 @@ + +#include "static.hpp" + +#include + +namespace MWClass +{ + std::string Static::getName (const MWWorld::Ptr& ptr) const + { + return ""; + } + + 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 0000000000..fb80801827 --- /dev/null +++ b/apps/openmw/mwclass/static.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWCLASS_STATIC_H +#define GAME_MWCLASS_STATIC_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Static : public MWWorld::Class + { + 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(); + }; +} + +#endif diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp new file mode 100644 index 0000000000..5ca80bcb7b --- /dev/null +++ b/apps/openmw/mwclass/weapon.cpp @@ -0,0 +1,39 @@ + +#include "weapon.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +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; + } + + 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 0000000000..98e5930f87 --- /dev/null +++ b/apps/openmw/mwclass/weapon.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWCLASS_WEAPON_H +#define GAME_MWCLASS_WEAPON_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Weapon : public MWWorld::Class + { + 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? + + 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/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 310695959c..229a351ac6 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 997e2473a5..e28b5593bc 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -7,6 +7,10 @@ #include #include +#include "../mwworld/class.hpp" + +#include "../mwmechanics/creaturestats.hpp" + #include "interpretercontext.hpp" namespace MWScript @@ -26,8 +30,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 +56,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 +82,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 +108,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 +131,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 +160,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,35 +184,20 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - if (mIndex==0) + MWWorld::Ptr ptr = context.getReference(); + + 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 = 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; - } + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getItemMaxHealth (ptr); + runtime.push (value); + + return; } Interpreter::Type_Integer value = - context.getReference().getCreatureStats().mDynamic[mIndex]. + MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. getCurrent(); runtime.push (value); @@ -219,35 +220,20 @@ namespace MWScript std::string id = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - if (mIndex==0) + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + 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 = 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; - } + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getItemMaxHealth (ptr); + runtime.push (value); + + return; } 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 +256,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 +282,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 +305,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 +337,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 +368,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 +397,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 +421,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 +452,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/action.hpp b/apps/openmw/mwworld/action.hpp new file mode 100644 index 0000000000..1558193355 --- /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/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp new file mode 100644 index 0000000000..4edc02c30a --- /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 0000000000..78a55fba2f --- /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 new file mode 100644 index 0000000000..9cca8035eb --- /dev/null +++ b/apps/openmw/mwworld/class.cpp @@ -0,0 +1,63 @@ + +#include "class.hpp" + +#include + +#include "ptr.hpp" +#include "nullaction.hpp" + +namespace MWWorld +{ + std::map > Class::sClasses; + + Class::Class() {} + + Class::~Class() {} + + MWMechanics::CreatureStats& Class::getCreatureStats (const Ptr& ptr) const + { + 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"); + } + + 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 Environment& environment) const + { + return boost::shared_ptr (new NullAction); + } + + 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; + } + + 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 new file mode 100644 index 0000000000..9535786e27 --- /dev/null +++ b/apps/openmw/mwworld/class.hpp @@ -0,0 +1,71 @@ +#ifndef GAME_MWWORLD_CLASS_H +#define GAME_MWWORLD_CLASS_H + +#include +#include + +#include + +#include "action.hpp" + +namespace MWMechanics +{ + struct CreatureStats; +} + +namespace MWWorld +{ + class Ptr; + + /// \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(); + + 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) + + 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) + + 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 Environment& environment) + 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. + + 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); + }; +} + +#endif diff --git a/apps/openmw/mwworld/nullaction.hpp b/apps/openmw/mwworld/nullaction.hpp new file mode 100644 index 0000000000..820fc45388 --- /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 diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index f05a9bef29..8bf75aa3cb 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -5,12 +5,8 @@ #include -#include -#include #include -#include "../mwmechanics/creaturestats.hpp" - #include "refdata.hpp" namespace MWWorld @@ -27,6 +23,7 @@ namespace MWWorld ESM::CellRef *mCellRef; RefData *mRefData; CellStore *mCell; + std::string mTypeName; public: @@ -43,6 +40,11 @@ namespace MWWorld return mPtr.type(); } + const std::string& getTypeName() const + { + return mTypeName; + } + template Ptr (ESMS::LiveCellRef *liveCellRef, CellStore *cell) { @@ -50,6 +52,7 @@ namespace MWWorld mCellRef = &liveCellRef->ref; mRefData = &liveCellRef->mData; mCell = cell; + mTypeName = typeid (T).name(); } template @@ -75,63 +78,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) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a759b93841..5a4ac432ca 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -120,10 +120,10 @@ namespace MWWorld 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)) @@ -183,10 +183,10 @@ namespace MWWorld if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.npcs)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.probes)) + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.probes)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.repairs)) + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.repairs)) return Ptr (ref, &cell); if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.statics)) diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index acd8a7805d..3b7913ea97 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 941dba6fe2..d4d7cc2f83 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 7c4971ac40..fd4a47d4b8 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;