From f323f231db9c5d8f749fd675e92c008666d0155f Mon Sep 17 00:00:00 2001 From: MiroslavR Date: Thu, 15 Sep 2016 16:47:50 +0200 Subject: [PATCH] Allow activating actors without a name (Fixes #3551) --- apps/openmw/mwclass/actor.cpp | 15 +++++++++++++++ apps/openmw/mwclass/actor.hpp | 4 ++++ apps/openmw/mwclass/creature.hpp | 5 ----- apps/openmw/mwclass/npc.hpp | 4 ---- apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 4 ++++ apps/openmw/mwworld/player.cpp | 10 +--------- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwclass/actor.cpp b/apps/openmw/mwclass/actor.cpp index 56de5e3f8..d46729c1d 100644 --- a/apps/openmw/mwclass/actor.cpp +++ b/apps/openmw/mwclass/actor.cpp @@ -83,4 +83,19 @@ namespace MWClass bool Actor::allowTelekinesis(const MWWorld::ConstPtr &ptr) const { return false; } + + bool Actor::isActor() const + { + return true; + } + + bool Actor::canBeActivated(const MWWorld::Ptr& ptr) const + { + MWMechanics::CreatureStats &stats = getCreatureStats(ptr); + + if (stats.getAiSequence().isInCombat() && !stats.isDead()) + return false; + + return true; + } } diff --git a/apps/openmw/mwclass/actor.hpp b/apps/openmw/mwclass/actor.hpp index 1aca5e660..84b8f4ad8 100644 --- a/apps/openmw/mwclass/actor.hpp +++ b/apps/openmw/mwclass/actor.hpp @@ -38,6 +38,10 @@ namespace MWClass virtual bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const; ///< Return whether this class of object can be activated with telekinesis + virtual bool isActor() const; + + virtual bool canBeActivated(const MWWorld::Ptr& ptr) const; + // not implemented Actor(const Actor&); Actor& operator= (const Actor&); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 654df60b6..076bc8572 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -104,11 +104,6 @@ namespace MWClass virtual void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector& models) const; ///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: list getModel(). - virtual bool - isActor() const { - return true; - } - virtual bool isBipedal (const MWWorld::ConstPtr &ptr) const; virtual bool canFly (const MWWorld::ConstPtr &ptr) const; virtual bool canSwim (const MWWorld::ConstPtr &ptr) const; diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 941605176..3120c498c 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -135,10 +135,6 @@ namespace MWClass /// Get a blood texture suitable for \a ptr (see Blood Texture 0-2 in Morrowind.ini) virtual int getBloodTexture (const MWWorld::ConstPtr& ptr) const; - virtual bool isActor() const { - return true; - } - virtual bool isNpc() const { return true; } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 12b69c7ca..3725065b7 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -98,6 +98,11 @@ namespace MWWorld throw std::runtime_error("class cannot block"); } + bool Class::canBeActivated(const Ptr& ptr) const + { + return !getName(ptr).empty(); + } + void Class::onHit(const Ptr& ptr, float damage, bool ishealth, const Ptr& object, const Ptr& attacker, const osg::Vec3f& hitPosition, bool successful) const { throw std::runtime_error("class cannot be hit"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 01d20032b..8a8e0191e 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -130,6 +130,10 @@ namespace MWWorld ///< Play the appropriate sound for a blocked attack, depending on the currently equipped shield /// (default implementation: throw an exception) + virtual bool canBeActivated(const Ptr& ptr) const; + ///< \return Can the player activate this object? + /// (default implementation: true if object's user-readable name is not empty, false otherwise) + virtual boost::shared_ptr activate (const Ptr& ptr, const Ptr& actor) const; ///< Generate action for activation (default implementation: return a null action). diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 0fcb2eb6d..baa90a0ec 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -220,17 +220,9 @@ namespace MWWorld if (toActivate.isEmpty()) return; - if (toActivate.getClass().getName(toActivate) == "") // objects without name presented to user can never be activated + if (!toActivate.getClass().canBeActivated(toActivate)) return; - if (toActivate.getClass().isActor()) - { - MWMechanics::CreatureStats &stats = toActivate.getClass().getCreatureStats(toActivate); - - if (stats.getAiSequence().isInCombat() && !stats.isDead()) - return; - } - MWBase::Environment::get().getWorld()->activate(toActivate, player); }