From e58f2f5363ec8f6f6b3c960335bdc8544f958b8a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 19 Feb 2012 02:01:15 -0500 Subject: [PATCH] Eliminating unnecessary data from skeletons and shape saving --- apps/openmw/class2/activator.cpp | 66 ++++++ apps/openmw/class2/activator.hpp | 28 +++ apps/openmw/class2/apparatus.cpp | 81 ++++++++ apps/openmw/class2/apparatus.hpp | 37 ++++ apps/openmw/class2/armor.cpp | 93 +++++++++ apps/openmw/class2/armor.hpp | 43 ++++ apps/openmw/class2/book.cpp | 83 ++++++++ apps/openmw/class2/book.hpp | 37 ++++ apps/openmw/class2/classes.cpp | 50 +++++ apps/openmw/class2/classes.hpp | 10 + apps/openmw/class2/clothing.cpp | 81 ++++++++ apps/openmw/class2/clothing.hpp | 37 ++++ apps/openmw/class2/container.cpp | 80 +++++++ apps/openmw/class2/container.hpp | 33 +++ apps/openmw/class2/containerutil.hpp | 28 +++ apps/openmw/class2/creature.cpp | 138 +++++++++++++ apps/openmw/class2/creature.hpp | 51 +++++ apps/openmw/class2/creaturelevlist.cpp | 19 ++ apps/openmw/class2/creaturelevlist.hpp | 20 ++ apps/openmw/class2/door.cpp | 129 ++++++++++++ apps/openmw/class2/door.hpp | 39 ++++ apps/openmw/class2/ingredient.cpp | 82 ++++++++ apps/openmw/class2/ingredient.hpp | 37 ++++ apps/openmw/class2/itemlevlist.cpp | 19 ++ apps/openmw/class2/itemlevlist.hpp | 20 ++ apps/openmw/class2/light.cpp | 110 ++++++++++ apps/openmw/class2/light.hpp | 42 ++++ apps/openmw/class2/lockpick.cpp | 81 ++++++++ apps/openmw/class2/lockpick.hpp | 37 ++++ apps/openmw/class2/misc.cpp | 80 +++++++ apps/openmw/class2/misc.hpp | 37 ++++ apps/openmw/class2/npc.cpp | 276 +++++++++++++++++++++++++ apps/openmw/class2/npc.hpp | 72 +++++++ apps/openmw/class2/potion.cpp | 81 ++++++++ apps/openmw/class2/potion.hpp | 37 ++++ apps/openmw/class2/probe.cpp | 81 ++++++++ apps/openmw/class2/probe.hpp | 37 ++++ apps/openmw/class2/repair.cpp | 80 +++++++ apps/openmw/class2/repair.hpp | 37 ++++ apps/openmw/class2/static.cpp | 52 +++++ apps/openmw/class2/static.hpp | 26 +++ apps/openmw/class2/weapon.cpp | 94 +++++++++ apps/openmw/class2/weapon.hpp | 43 ++++ apps/openmw/mwrender/animation.cpp | 7 +- components/nifogre/ogre_nif_loader.cpp | 19 +- components/nifogre/ogre_nif_loader.hpp | 4 +- 46 files changed, 2661 insertions(+), 13 deletions(-) create mode 100644 apps/openmw/class2/activator.cpp create mode 100644 apps/openmw/class2/activator.hpp create mode 100644 apps/openmw/class2/apparatus.cpp create mode 100644 apps/openmw/class2/apparatus.hpp create mode 100644 apps/openmw/class2/armor.cpp create mode 100644 apps/openmw/class2/armor.hpp create mode 100644 apps/openmw/class2/book.cpp create mode 100644 apps/openmw/class2/book.hpp create mode 100644 apps/openmw/class2/classes.cpp create mode 100644 apps/openmw/class2/classes.hpp create mode 100644 apps/openmw/class2/clothing.cpp create mode 100644 apps/openmw/class2/clothing.hpp create mode 100644 apps/openmw/class2/container.cpp create mode 100644 apps/openmw/class2/container.hpp create mode 100644 apps/openmw/class2/containerutil.hpp create mode 100644 apps/openmw/class2/creature.cpp create mode 100644 apps/openmw/class2/creature.hpp create mode 100644 apps/openmw/class2/creaturelevlist.cpp create mode 100644 apps/openmw/class2/creaturelevlist.hpp create mode 100644 apps/openmw/class2/door.cpp create mode 100644 apps/openmw/class2/door.hpp create mode 100644 apps/openmw/class2/ingredient.cpp create mode 100644 apps/openmw/class2/ingredient.hpp create mode 100644 apps/openmw/class2/itemlevlist.cpp create mode 100644 apps/openmw/class2/itemlevlist.hpp create mode 100644 apps/openmw/class2/light.cpp create mode 100644 apps/openmw/class2/light.hpp create mode 100644 apps/openmw/class2/lockpick.cpp create mode 100644 apps/openmw/class2/lockpick.hpp create mode 100644 apps/openmw/class2/misc.cpp create mode 100644 apps/openmw/class2/misc.hpp create mode 100644 apps/openmw/class2/npc.cpp create mode 100644 apps/openmw/class2/npc.hpp create mode 100644 apps/openmw/class2/potion.cpp create mode 100644 apps/openmw/class2/potion.hpp create mode 100644 apps/openmw/class2/probe.cpp create mode 100644 apps/openmw/class2/probe.hpp create mode 100644 apps/openmw/class2/repair.cpp create mode 100644 apps/openmw/class2/repair.hpp create mode 100644 apps/openmw/class2/static.cpp create mode 100644 apps/openmw/class2/static.hpp create mode 100644 apps/openmw/class2/weapon.cpp create mode 100644 apps/openmw/class2/weapon.hpp diff --git a/apps/openmw/class2/activator.cpp b/apps/openmw/class2/activator.cpp new file mode 100644 index 000000000..086cb433d --- /dev/null +++ b/apps/openmw/class2/activator.cpp @@ -0,0 +1,66 @@ + +#include "activator.hpp" +#include "../mwrender/objects.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + + +namespace MWClass +{ + void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Activator::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + std::string Activator::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Activator::registerSelf() + { + boost::shared_ptr instance (new Activator); + + registerClass (typeid (ESM::Activator).name(), instance); + } +} diff --git a/apps/openmw/class2/activator.hpp b/apps/openmw/class2/activator.hpp new file mode 100644 index 000000000..08be8a5ff --- /dev/null +++ b/apps/openmw/class2/activator.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_MWCLASS_ACTIVATOR_H +#define GAME_MWCLASS_ACTIVATOR_H + +#include "../mwworld/class.hpp" + +namespace MWClass +{ + class Activator : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/apparatus.cpp b/apps/openmw/class2/apparatus.cpp new file mode 100644 index 000000000..4c5ba0721 --- /dev/null +++ b/apps/openmw/class2/apparatus.cpp @@ -0,0 +1,81 @@ + +#include "apparatus.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Apparatus::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Apparatus::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Apparatus::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.appas); + } + + std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Apparatus::registerSelf() + { + boost::shared_ptr instance (new Apparatus); + + registerClass (typeid (ESM::Apparatus).name(), instance); + } +} diff --git a/apps/openmw/class2/apparatus.hpp b/apps/openmw/class2/apparatus.hpp new file mode 100644 index 000000000..4c8a2c0e2 --- /dev/null +++ b/apps/openmw/class2/apparatus.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_APPARATUS_H +#define GAME_MWCLASS_APPARATUS_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Apparatus : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/armor.cpp b/apps/openmw/class2/armor.cpp new file mode 100644 index 000000000..2ad1dbfa2 --- /dev/null +++ b/apps/openmw/class2/armor.cpp @@ -0,0 +1,93 @@ + +#include "armor.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Armor::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Armor::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + 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::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.armors); + } + + std::string Armor::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Armor::registerSelf() + { + boost::shared_ptr instance (new Armor); + + registerClass (typeid (ESM::Armor).name(), instance); + } +} diff --git a/apps/openmw/class2/armor.hpp b/apps/openmw/class2/armor.hpp new file mode 100644 index 000000000..c5f9812b7 --- /dev/null +++ b/apps/openmw/class2/armor.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWCLASS_ARMOR_H +#define GAME_MWCLASS_ARMOR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Armor : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/book.cpp b/apps/openmw/class2/book.cpp new file mode 100644 index 000000000..5c0d8767a --- /dev/null +++ b/apps/openmw/class2/book.cpp @@ -0,0 +1,83 @@ + +#include "book.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Book::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Book::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + // TODO implement reading + + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Book::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.books); + } + + std::string Book::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Book::registerSelf() + { + boost::shared_ptr instance (new Book); + + registerClass (typeid (ESM::Book).name(), instance); + } +} diff --git a/apps/openmw/class2/book.hpp b/apps/openmw/class2/book.hpp new file mode 100644 index 000000000..f0e38cceb --- /dev/null +++ b/apps/openmw/class2/book.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_BOOK_H +#define GAME_MWCLASS_BOOK_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Book : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/classes.cpp b/apps/openmw/class2/classes.cpp new file mode 100644 index 000000000..e9538a6cb --- /dev/null +++ b/apps/openmw/class2/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(); + Miscellaneous::registerSelf(); + Probe::registerSelf(); + Repair::registerSelf(); + Static::registerSelf(); + } +} diff --git a/apps/openmw/class2/classes.hpp b/apps/openmw/class2/classes.hpp new file mode 100644 index 000000000..0ab90b677 --- /dev/null +++ b/apps/openmw/class2/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/class2/clothing.cpp b/apps/openmw/class2/clothing.cpp new file mode 100644 index 000000000..b81a181f4 --- /dev/null +++ b/apps/openmw/class2/clothing.cpp @@ -0,0 +1,81 @@ + +#include "clothing.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Clothing::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Clothing::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Clothing::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.clothes); + } + + std::string Clothing::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Clothing::registerSelf() + { + boost::shared_ptr instance (new Clothing); + + registerClass (typeid (ESM::Clothing).name(), instance); + } +} diff --git a/apps/openmw/class2/clothing.hpp b/apps/openmw/class2/clothing.hpp new file mode 100644 index 000000000..76c2c4a3e --- /dev/null +++ b/apps/openmw/class2/clothing.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_CLOTHING_H +#define GAME_MWCLASS_CLOTHING_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Clothing : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/container.cpp b/apps/openmw/class2/container.cpp new file mode 100644 index 000000000..fff3a9bda --- /dev/null +++ b/apps/openmw/class2/container.cpp @@ -0,0 +1,80 @@ + +#include "container.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" + +namespace MWClass +{ + void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Container::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Container::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Container::registerSelf() + { + boost::shared_ptr instance (new Container); + + registerClass (typeid (ESM::Container).name(), instance); + } +} diff --git a/apps/openmw/class2/container.hpp b/apps/openmw/class2/container.hpp new file mode 100644 index 000000000..01763870a --- /dev/null +++ b/apps/openmw/class2/container.hpp @@ -0,0 +1,33 @@ +#ifndef GAME_MWCLASS_CONTAINER_H +#define GAME_MWCLASS_CONTAINER_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Container : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/containerutil.hpp b/apps/openmw/class2/containerutil.hpp new file mode 100644 index 000000000..76bdf0236 --- /dev/null +++ b/apps/openmw/class2/containerutil.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_MWCLASS_CONTAINERUTIL_H +#define GAME_MWCLASS_CONTAINERUTIL_H + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/containerstore.hpp" + +namespace MWClass +{ + template + void insertIntoContainerStore (const MWWorld::Ptr& ptr, + ESMS::CellRefList& containerStore) + { + if (!ptr.isEmpty()) + { + // TODO check stacking + + ESMS::LiveCellRef cellRef(ptr.getCellRef(), ptr.get()->base); + cellRef.mData = ptr.getRefData(); + + containerStore.list.push_back (cellRef); + + } + } +} + +#endif diff --git a/apps/openmw/class2/creature.cpp b/apps/openmw/class2/creature.cpp new file mode 100644 index 000000000..5aa203a49 --- /dev/null +++ b/apps/openmw/class2/creature.cpp @@ -0,0 +1,138 @@ + +#include "creature.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" + + +#include "../mwmechanics/mechanicsmanager.hpp" + +namespace MWClass +{ + std::string Creature::getId (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->mId; + } + + void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + + /*ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + {*/ + MWRender::Actors& actors = renderingInterface.getActors(); + actors.insertCreature(ptr); + + } + + void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertActorPhysics(ptr, "meshes\\" + model); + } + + } + + void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Creature::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + + 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); + + stats->mLevel = ref->base->data.level; + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + boost::shared_ptr Creature::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); + } + + MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Creature::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Creature::registerSelf() + { + boost::shared_ptr instance (new Creature); + + registerClass (typeid (ESM::Creature).name(), instance); + } +} diff --git a/apps/openmw/class2/creature.hpp b/apps/openmw/class2/creature.hpp new file mode 100644 index 000000000..b7b654bc0 --- /dev/null +++ b/apps/openmw/class2/creature.hpp @@ -0,0 +1,51 @@ +#ifndef GAME_MWCLASS_CREATURE_H +#define GAME_MWCLASS_CREATURE_H + +#include "../mwworld/class.hpp" +#include "../mwrender/renderinginterface.hpp" +#include "../mwrender/actors.hpp" + + +namespace MWClass +{ + class Creature : public MWWorld::Class + { + public: + + virtual std::string getId (const MWWorld::Ptr& ptr) const; + ///< Return ID of \a ptr + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + 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 + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/creaturelevlist.cpp b/apps/openmw/class2/creaturelevlist.cpp new file mode 100644 index 000000000..53dd34bb4 --- /dev/null +++ b/apps/openmw/class2/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/class2/creaturelevlist.hpp b/apps/openmw/class2/creaturelevlist.hpp new file mode 100644 index 000000000..81965efd5 --- /dev/null +++ b/apps/openmw/class2/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/class2/door.cpp b/apps/openmw/class2/door.cpp new file mode 100644 index 000000000..baced8a9c --- /dev/null +++ b/apps/openmw/class2/door.cpp @@ -0,0 +1,129 @@ + +#include "door.hpp" + +#include + +#include + +#include "../mwworld/player.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/nullaction.hpp" +#include "../mwworld/actionteleport.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwrender/objects.hpp" + +#include + +namespace MWClass +{ + void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Door::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->ref.teleport && !ref->ref.destCell.empty()) // TODO doors that lead to exteriors + return ref->ref.destCell; + + 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 (ptr.getCellRef().lockLevel>0) + { + // TODO check for key + // TODO report failure to player (message, sound?). Look up behaviour of original MW. + std::cout << "Locked!" << std::endl; + return boost::shared_ptr (new MWWorld::NullAction); + } + + // TODO check trap + + if (ref->ref.teleport) + { + // teleport door + if (environment.mWorld->getPlayer().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::lock (const MWWorld::Ptr& ptr, int lockLevel) const + { + if (lockLevel<0) + lockLevel = 0; + + ptr.getCellRef().lockLevel = lockLevel; + } + + void Door::unlock (const MWWorld::Ptr& ptr) const + { + ptr.getCellRef().lockLevel = 0; + } + + std::string Door::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Door::registerSelf() + { + boost::shared_ptr instance (new Door); + + registerClass (typeid (ESM::Door).name(), instance); + } +} diff --git a/apps/openmw/class2/door.hpp b/apps/openmw/class2/door.hpp new file mode 100644 index 000000000..c230cf357 --- /dev/null +++ b/apps/openmw/class2/door.hpp @@ -0,0 +1,39 @@ +#ifndef GAME_MWCLASS_DOOR_H +#define GAME_MWCLASS_DOOR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Door : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void lock (const MWWorld::Ptr& ptr, int lockLevel) const; + ///< Lock object + + virtual void unlock (const MWWorld::Ptr& ptr) const; + ///< Unlock object + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/ingredient.cpp b/apps/openmw/class2/ingredient.cpp new file mode 100644 index 000000000..42e3d11e4 --- /dev/null +++ b/apps/openmw/class2/ingredient.cpp @@ -0,0 +1,82 @@ + +#include "ingredient.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Ingredient::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Ingredient::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Ingredient::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.ingreds); + } + + std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Ingredient::registerSelf() + { + boost::shared_ptr instance (new Ingredient); + + registerClass (typeid (ESM::Ingredient).name(), instance); + } +} diff --git a/apps/openmw/class2/ingredient.hpp b/apps/openmw/class2/ingredient.hpp new file mode 100644 index 000000000..47bd1a9e5 --- /dev/null +++ b/apps/openmw/class2/ingredient.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_INGREDIENT_H +#define GAME_MWCLASS_INGREDIENT_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Ingredient : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/itemlevlist.cpp b/apps/openmw/class2/itemlevlist.cpp new file mode 100644 index 000000000..6ed9ab2e5 --- /dev/null +++ b/apps/openmw/class2/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/class2/itemlevlist.hpp b/apps/openmw/class2/itemlevlist.hpp new file mode 100644 index 000000000..0b71b072c --- /dev/null +++ b/apps/openmw/class2/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/class2/light.cpp b/apps/openmw/class2/light.cpp new file mode 100644 index 000000000..a3ceea4a6 --- /dev/null +++ b/apps/openmw/class2/light.cpp @@ -0,0 +1,110 @@ + +#include "light.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" +#include "../mwworld/nullaction.hpp" +#include "../mwworld/environment.hpp" + +#include "../mwsound/soundmanager.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + const int color = ref->base->data.color; + const float r = ((color >> 0) & 0xFF) / 255.0f; + const float g = ((color >> 8) & 0xFF) / 255.0f; + const float b = ((color >> 16) & 0xFF) / 255.0f; + const float radius = float (ref->base->data.radius); + objects.insertLight (ptr, r, g, b, radius); + } + } + + void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (!ref->base->sound.empty()) + { + environment.mSoundManager->playSound3D (ptr, ref->base->sound, 1.0, 1.0, true); + } + } + + std::string Light::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (ref->base->model.empty()) + return ""; + + return ref->base->name; + } + + boost::shared_ptr Light::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + if (!(ref->base->data.flags & ESM::Light::Carry)) + return boost::shared_ptr (new MWWorld::NullAction); + + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Light::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.lights); + } + + std::string Light::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Light::registerSelf() + { + boost::shared_ptr instance (new Light); + + registerClass (typeid (ESM::Light).name(), instance); + } +} diff --git a/apps/openmw/class2/light.hpp b/apps/openmw/class2/light.hpp new file mode 100644 index 000000000..34421ff51 --- /dev/null +++ b/apps/openmw/class2/light.hpp @@ -0,0 +1,42 @@ +#ifndef GAME_MWCLASS_LIGHT_H +#define GAME_MWCLASS_LIGHT_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Light : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + /// \attention This is not the same as the script instruction with the same name. References + /// should only be enabled while in an active cell. + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/lockpick.cpp b/apps/openmw/class2/lockpick.cpp new file mode 100644 index 000000000..c07d5592c --- /dev/null +++ b/apps/openmw/class2/lockpick.cpp @@ -0,0 +1,81 @@ + +#include "lockpick.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + + std::string Lockpick::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Lockpick::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Lockpick::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.lockpicks); + } + + std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Lockpick::registerSelf() + { + boost::shared_ptr instance (new Lockpick); + + registerClass (typeid (ESM::Tool).name(), instance); + } +} diff --git a/apps/openmw/class2/lockpick.hpp b/apps/openmw/class2/lockpick.hpp new file mode 100644 index 000000000..c5f1539b4 --- /dev/null +++ b/apps/openmw/class2/lockpick.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_LOCKPICK_H +#define GAME_MWCLASS_LOCKPICK_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Lockpick : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/misc.cpp b/apps/openmw/class2/misc.cpp new file mode 100644 index 000000000..a58142905 --- /dev/null +++ b/apps/openmw/class2/misc.cpp @@ -0,0 +1,80 @@ + +#include "misc.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Miscellaneous::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Miscellaneous::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Miscellaneous::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.miscItems); + } + + std::string Miscellaneous::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Miscellaneous::registerSelf() + { + boost::shared_ptr instance (new Miscellaneous); + + registerClass (typeid (ESM::Miscellaneous).name(), instance); + } +} diff --git a/apps/openmw/class2/misc.hpp b/apps/openmw/class2/misc.hpp new file mode 100644 index 000000000..36ee2c1b2 --- /dev/null +++ b/apps/openmw/class2/misc.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_MISC_H +#define GAME_MWCLASS_MISC_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Miscellaneous : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/npc.cpp b/apps/openmw/class2/npc.cpp new file mode 100644 index 000000000..acb0a5a35 --- /dev/null +++ b/apps/openmw/class2/npc.cpp @@ -0,0 +1,276 @@ + +#include "npc.hpp" + +#include + +#include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/npcstats.hpp" + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" +#include + +namespace +{ + const Ogre::Radian kOgrePi (Ogre::Math::PI); + const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0)); +} + +namespace MWClass +{ + std::string Npc::getId (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->mId; + } + + void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + renderingInterface.getActors().insertNPC(ptr); + } + + void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + + + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + std::string headID = ref->base->head; + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + + std::string smodel = "meshes\\base_anim.nif"; + if(beast) + smodel = "meshes\\base_animkna.nif"; + physics.insertActorPhysics(ptr, smodel); + + + } + + void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->addActor (ptr); + } + + void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + environment.mMechanicsManager->removeActor (ptr); + } + + 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); + + stats->mLevel = ref->base->npdt52.level; + + ptr.getRefData().getCreatureStats() = stats; + } + + return *ptr.getRefData().getCreatureStats(); + } + + MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getNpcStats().get()) + { + boost::shared_ptr stats ( + new MWMechanics::NpcStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + if (!ref->base->faction.empty()) + { + // TODO research how initial rank is stored. The information in loadnpc.hpp are at + // best very unclear. + stats->mFactionRank[ref->base->faction] = 0; + } + + for (int i=0; i<27; ++i) + stats->mSkill[i].setBase (ref->base->npdt52.skills[i]); + + ptr.getRefData().getNpcStats() = stats; + } + + return *ptr.getRefData().getNpcStats(); + } + + boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); + } + + MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + + std::string Npc::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + stats.mForceRun = force; + break; + + case Sneak: + + stats.mForceSneak = force; + break; + + case Combat: + + throw std::runtime_error ("combat stance not enforcable for NPCs"); + } + } + + void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + stats.mRun = set; + break; + + case Sneak: + + stats.mSneak = set; + break; + + case Combat: + + stats.mCombat = set; + break; + } + } + + bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const + { + MWMechanics::NpcStats& stats = getNpcStats (ptr); + + switch (stance) + { + case Run: + + if (!ignoreForce && stats.mForceRun) + return true; + + return stats.mRun; + + case Sneak: + + if (!ignoreForce && stats.mForceSneak) + return true; + + return stats.mSneak; + + case Combat: + + return stats.mCombat; + } + + return false; + } + + float Npc::getSpeed (const MWWorld::Ptr& ptr) const + { + return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats + } + + MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getMovement().get()) + { + boost::shared_ptr movement ( + new MWMechanics::Movement); + + ptr.getRefData().getMovement() = movement; + } + + return *ptr.getRefData().getMovement(); + } + + Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const + { + Ogre::Vector3 vector (0, 0, 0); + + if (ptr.getRefData().getMovement().get()) + { + vector.x = - ptr.getRefData().getMovement()->mLeftRight * 200; + vector.y = ptr.getRefData().getMovement()->mForwardBackward * 200; + + if (getStance (ptr, Run, false)) + vector *= 2; + } + + return vector; + } + + void Npc::registerSelf() + { + boost::shared_ptr instance (new Npc); + + registerClass (typeid (ESM::NPC).name(), instance); + } +} diff --git a/apps/openmw/class2/npc.hpp b/apps/openmw/class2/npc.hpp new file mode 100644 index 000000000..cc9dbef7f --- /dev/null +++ b/apps/openmw/class2/npc.hpp @@ -0,0 +1,72 @@ +#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 getId (const MWWorld::Ptr& ptr) const; + ///< Return ID of \a ptr + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + virtual void disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< Enable reference; only does the non-rendering part + + 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 + + virtual MWMechanics::NpcStats& getNpcStats (const MWWorld::Ptr& ptr) const; + ///< Return NPC stats + + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; + ///< Generate action for activation + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + virtual void setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const; + ///< Force or unforce a stance. + + virtual void setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const; + ///< Set or unset a stance. + + virtual bool getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce = false) + const; + ////< Check if a stance is active or not. + + virtual float getSpeed (const MWWorld::Ptr& ptr) const; + ///< Return movement speed. + + virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const; + ///< Return desired movement. + + virtual Ogre::Vector3 getMovementVector (const MWWorld::Ptr& ptr) const; + ///< Return desired movement vector (determined based on movement settings, + /// stance and stats). + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/potion.cpp b/apps/openmw/class2/potion.cpp new file mode 100644 index 000000000..0ab1c7aad --- /dev/null +++ b/apps/openmw/class2/potion.cpp @@ -0,0 +1,81 @@ + +#include "potion.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Potion::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Potion::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Potion::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.potions); + } + + std::string Potion::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Potion::registerSelf() + { + boost::shared_ptr instance (new Potion); + + registerClass (typeid (ESM::Potion).name(), instance); + } +} diff --git a/apps/openmw/class2/potion.hpp b/apps/openmw/class2/potion.hpp new file mode 100644 index 000000000..85678121f --- /dev/null +++ b/apps/openmw/class2/potion.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_POTION_H +#define GAME_MWCLASS_POTION_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Potion : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/probe.cpp b/apps/openmw/class2/probe.cpp new file mode 100644 index 000000000..83c0e1ef4 --- /dev/null +++ b/apps/openmw/class2/probe.cpp @@ -0,0 +1,81 @@ + +#include "probe.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + + std::string Probe::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + boost::shared_ptr Probe::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Probe::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.probes); + } + + std::string Probe::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Probe::registerSelf() + { + boost::shared_ptr instance (new Probe); + + registerClass (typeid (ESM::Probe).name(), instance); + } +} diff --git a/apps/openmw/class2/probe.hpp b/apps/openmw/class2/probe.hpp new file mode 100644 index 000000000..d7b9df738 --- /dev/null +++ b/apps/openmw/class2/probe.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_PROBE_H +#define GAME_MWCLASS_PROBE_H + +#include "../mwworld/class.hpp" + + +namespace MWClass +{ + class Probe : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/repair.cpp b/apps/openmw/class2/repair.cpp new file mode 100644 index 000000000..feee7e988 --- /dev/null +++ b/apps/openmw/class2/repair.cpp @@ -0,0 +1,80 @@ + +#include "repair.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + +#include "containerutil.hpp" + +namespace MWClass +{ + void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Repair::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Repair::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + void Repair::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.repairs); + } + + std::string Repair::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Repair::registerSelf() + { + boost::shared_ptr instance (new Repair); + + registerClass (typeid (ESM::Repair).name(), instance); + } +} diff --git a/apps/openmw/class2/repair.hpp b/apps/openmw/class2/repair.hpp new file mode 100644 index 000000000..1e0ea5178 --- /dev/null +++ b/apps/openmw/class2/repair.hpp @@ -0,0 +1,37 @@ +#ifndef GAME_MWCLASS_REPAIR_H +#define GAME_MWCLASS_REPAIR_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Repair : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/class2/static.cpp b/apps/openmw/class2/static.cpp new file mode 100644 index 000000000..af14bb306 --- /dev/null +++ b/apps/openmw/class2/static.cpp @@ -0,0 +1,52 @@ + +#include "static.hpp" + +#include + +#include "../mwworld/ptr.hpp" + + +namespace MWClass +{ + void Static::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + 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/class2/static.hpp b/apps/openmw/class2/static.hpp new file mode 100644 index 000000000..be3fdb180 --- /dev/null +++ b/apps/openmw/class2/static.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWCLASS_STATIC_H +#define GAME_MWCLASS_STATIC_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Static : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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/class2/weapon.cpp b/apps/openmw/class2/weapon.cpp new file mode 100644 index 000000000..d5f7e6853 --- /dev/null +++ b/apps/openmw/class2/weapon.cpp @@ -0,0 +1,94 @@ + +#include "weapon.hpp" + +#include + +#include + +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontake.hpp" + + +#include "containerutil.hpp" + +namespace MWClass +{ + void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + const std::string &model = ref->base->model; + + if (!model.empty()) + { + MWRender::Objects& objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(),true); + objects.insertMesh(ptr, "meshes\\" + model); + } + } + + void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr, "meshes\\" + model); + } + + } + + std::string Weapon::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } + + boost::shared_ptr Weapon::activate (const MWWorld::Ptr& ptr, + const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const + { + return boost::shared_ptr ( + new MWWorld::ActionTake (ptr)); + } + + 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::insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const + { + insertIntoContainerStore (ptr, containerStore.weapons); + } + + std::string Weapon::getScript (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->script; + } + + void Weapon::registerSelf() + { + boost::shared_ptr instance (new Weapon); + + registerClass (typeid (ESM::Weapon).name(), instance); + } +} diff --git a/apps/openmw/class2/weapon.hpp b/apps/openmw/class2/weapon.hpp new file mode 100644 index 000000000..79bc4d4de --- /dev/null +++ b/apps/openmw/class2/weapon.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWCLASS_WEAPON_H +#define GAME_MWCLASS_WEAPON_H + +#include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" + +namespace MWClass +{ + class Weapon : public MWWorld::Class + { + public: + + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + + 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 + + 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 + + virtual void insertIntoContainer (const MWWorld::Ptr& ptr, + MWWorld::ContainerStore& containerStore) const; + ///< Insert into a containe + + virtual std::string getScript (const MWWorld::Ptr& ptr) const; + ///< Return name of the script attached to ptr + + static void registerSelf(); + }; +} + +#endif diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 96d65e00d..4013d69fe 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -261,11 +261,13 @@ namespace MWRender{ Ogre::Vector3 shapetrans = copy.trafo.trans; float shapescale = copy.trafo.scale; std::vector boneSequence = copy.boneSequence; - std::vector::iterator boneSequenceIter = boneSequence.begin(); + Ogre::Vector3 transmult; Ogre::Quaternion rotmult; float scale; - if(skel->hasBone(*boneSequenceIter)){ + if(boneSequence.size() > 0){ + std::vector::iterator boneSequenceIter = boneSequence.begin(); + if(skel->hasBone(*boneSequenceIter)){ Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); @@ -292,6 +294,7 @@ namespace MWRender{ //std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n"; } + } else { transmult = shapetrans; diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 2ac05f2c8..68cd532e9 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -583,6 +583,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { assert(shape != NULL); + bool saveTheShape = inTheSkeletonTree; // Interpret flags bool hidden = (flags & 0x01) != 0; // Not displayed bool collide = (flags & 0x02) != 0; // Use mesh for collision @@ -741,6 +742,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou std::list vertexBoneAssignments; Nif::NiTriShapeCopy copy = shape->clone(); + if(!shape->controller.empty()) { Nif::Controller* cont = shape->controller.getPtr(); @@ -750,6 +752,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.morph = morph->data.get(); copy.morph.setStartTime(morph->timeStart); copy.morph.setStopTime(morph->timeStop); + saveTheShape = true; } } @@ -928,10 +931,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } if(!mSkel.isNull() ){ int boneIndex; - Ogre::Bone *parentBone = mSkel->getBone(boneSequence[boneSequence.size() - 1]); - if(parentBone) - boneIndex = parentBone->getHandle(); - else + boneIndex = mSkel->getNumBones() - 1; for(int i = 0; i < numVerts; i++){ VertexBoneAssignment vba; @@ -947,7 +947,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { // Add this vertex set to the bounding box bounds.add(optr, numVerts); - if(addShapes) + if(saveTheShape) shapes.push_back(copy); // Create the submesh @@ -1069,21 +1069,22 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - addShapes = true; + inTheSkeletonTree = true; mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } else if (!mSkel.isNull() && !parentBone) - addShapes = false; + inTheSkeletonTree = false; if (!mSkel.isNull()) //if there is a skeleton { std::string name = node->name.toString(); - boneSequence.push_back(name); + // Quick-n-dirty workaround for the fact that several // bones may have the same name. if(!mSkel->hasBone(name)) { + boneSequence.push_back(name); bone = mSkel->createBone(name); if (parentBone) @@ -1148,7 +1149,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, void NIFLoader::loadResource(Resource *resource) { - addShapes = false; + inTheSkeletonTree = false; allanim.clear(); shapes.clear(); needBoneAssignments.clear(); diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 1361ffaca..b43d2992c 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -121,7 +121,7 @@ class NIFLoader : Ogre::ManualResourceLoader private: NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), - mFlipVertexWinding(false), mOutputAnimFiles(false), addShapes(false) {} + mFlipVertexWinding(false), mOutputAnimFiles(false), inTheSkeletonTree(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); @@ -190,7 +190,7 @@ class NIFLoader : Ogre::ManualResourceLoader std::vector mAnim; std::vector mS; std::vector needBoneAssignments; - bool addShapes; + bool inTheSkeletonTree; };