1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:19:56 +00:00
openmw-tes3mp/apps/openmw/mwworld/class.hpp

376 lines
17 KiB
C++
Raw Normal View History

#ifndef GAME_MWWORLD_CLASS_H
#define GAME_MWWORLD_CLASS_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <osg/Vec4f>
2013-08-15 08:21:43 +00:00
#include "ptr.hpp"
2019-08-25 13:20:14 +00:00
#include "doorstate.hpp"
#include "../mwmechanics/creaturestats.hpp"
namespace ESM
{
struct ObjectState;
}
namespace MWRender
{
class RenderingInterface;
}
namespace MWPhysics
{
class PhysicsSystem;
}
namespace MWMechanics
{
class NpcStats;
struct Movement;
}
namespace MWGui
{
struct ToolTipInfo;
}
namespace ESM
{
struct Position;
}
namespace MWWorld
{
class ContainerStore;
class InventoryStore;
class CellStore;
2013-08-15 08:21:43 +00:00
class Action;
/// \brief Base class for referenceable esm records
class Class
{
static std::map<std::string, std::shared_ptr<Class> > sClasses;
std::string mTypeName;
// not implemented
Class (const Class&);
Class& operator= (const Class&);
protected:
Class();
std::shared_ptr<Action> defaultItemActivate(const Ptr &ptr, const Ptr &actor) const;
2013-08-09 05:34:53 +00:00
///< Generate default action for activating inventory items
2015-12-18 15:24:24 +00:00
virtual Ptr copyToCellImpl(const ConstPtr &ptr, CellStore &cell) const;
public:
virtual ~Class();
const std::string& getTypeName() const {
return mTypeName;
}
virtual void insertObjectRendering (const Ptr& ptr, const std::string& mesh, MWRender::RenderingInterface& renderingInterface) const;
virtual void insertObject(const Ptr& ptr, const std::string& mesh, MWPhysics::PhysicsSystem& physics) const;
///< Add reference into a cell for rendering (default implementation: don't render anything).
virtual std::string getName (const ConstPtr& ptr) const = 0;
///< \return name or ID; can return an empty string.
2010-08-03 15:11:41 +00:00
virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const;
///< Adjust position to stand on ground. Must be called post model load
/// @param force do this even if the ptr is flying
virtual MWMechanics::CreatureStats& getCreatureStats (const Ptr& ptr) const;
///< Return creature stats or throw an exception, if class does not have creature stats
2014-10-05 22:59:53 +00:00
/// (default implementation: throw an exception)
2015-12-19 15:13:00 +00:00
virtual bool hasToolTip (const ConstPtr& ptr) const;
///< @return true if this object has a tooltip when focused (default implementation: true)
2015-12-19 15:29:07 +00:00
virtual MWGui::ToolTipInfo getToolTipInfo (const ConstPtr& ptr, int count) const;
///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip.
virtual bool showsInInventory (const ConstPtr& ptr) const;
///< Return whether ptr shows in inventory views.
/// Hidden items are not displayed and cannot be (re)moved by the user.
/// \return True if shown, false if hidden.
2010-08-19 10:49:13 +00:00
virtual MWMechanics::NpcStats& getNpcStats (const Ptr& ptr) const;
///< Return NPC stats or throw an exception, if class does not have NPC stats
2014-10-05 22:59:53 +00:00
/// (default implementation: throw an exception)
2010-08-19 10:49:13 +00:00
virtual bool hasItemHealth (const ConstPtr& ptr) const;
2010-08-03 12:14:04 +00:00
///< \return Item health data available? (default implementation: false)
virtual int getItemHealth (const ConstPtr& ptr) const;
///< Return current item health or throw an exception if class does not have item health
virtual float getItemNormalizedHealth (const ConstPtr& ptr) const;
///< Return current item health re-scaled to maximum health
virtual int getItemMaxHealth (const ConstPtr& ptr) const;
2010-08-03 12:14:04 +00:00
///< Return item max health or throw an exception, if class does not have item health
/// (default implementation: throw an exception)
2013-07-24 09:51:42 +00:00
virtual void hit(const Ptr& ptr, float attackStrength, int type=-1) const;
2013-07-24 09:51:42 +00:00
///< Execute a melee hit, using the current weapon. This will check the relevant skills
/// of the given attacker, and whoever is hit.
/// \param attackStrength how long the attack was charged for, a value in 0-1 range.
/// \param type - type of attack, one of the MWMechanics::CreatureStats::AttackType
/// enums. ignored for creature attacks.
2014-10-05 22:59:53 +00:00
/// (default implementation: throw an exception)
2013-07-24 09:51:42 +00:00
2016-09-12 15:49:31 +00:00
virtual void onHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, const osg::Vec3f &hitPosition, bool successful) const;
2013-07-28 13:48:25 +00:00
///< Alerts \a ptr that it's being hit for \a damage points to health if \a ishealth is
/// true (else fatigue) by \a object (sword, arrow, etc). \a attacker specifies the
/// actor responsible for the attack, and \a successful specifies if the hit is
/// successful or not.
virtual void block (const Ptr& ptr) const;
///< Play the appropriate sound for a blocked attack, depending on the currently equipped shield
/// (default implementation: throw an exception)
virtual std::shared_ptr<Action> activate (const Ptr& ptr, const Ptr& actor) const;
2010-08-03 16:20:15 +00:00
///< Generate action for activation (default implementation: return a null action).
virtual std::shared_ptr<Action> use (const Ptr& ptr, bool force=false)
const;
2010-08-03 16:20:15 +00:00
///< Generate action for using via inventory menu (default implementation: return a
/// null action).
virtual ContainerStore& getContainerStore (const Ptr& ptr) const;
2010-08-04 12:37:23 +00:00
///< Return container store or throw an exception, if class does not have a
2014-10-05 22:59:53 +00:00
/// container store (default implementation: throw an exception)
2010-08-04 12:37:23 +00:00
virtual InventoryStore& getInventoryStore (const Ptr& ptr) const;
///< Return inventory store or throw an exception, if class does not have a
2014-10-05 22:59:53 +00:00
/// inventory store (default implementation: throw an exception)
virtual bool hasInventoryStore (const Ptr& ptr) const;
///< Does this object have an inventory store, i.e. equipment slots? (default implementation: false)
2015-12-18 15:50:32 +00:00
virtual bool canLock (const ConstPtr& ptr) const;
virtual void setRemainingUsageTime (const Ptr& ptr, float duration) const;
///< Sets the remaining duration of the object, such as an equippable light
/// source. (default implementation: throw an exception)
virtual float getRemainingUsageTime (const ConstPtr& ptr) const;
///< Returns the remaining duration of the object, such as an equippable light
2013-12-16 12:31:03 +00:00
/// source. (default implementation: -1, i.e. infinite)
2015-12-17 23:12:03 +00:00
virtual std::string getScript (const ConstPtr& ptr) const;
///< Return name of the script attached to ptr (default implementation: return an empty
/// string).
virtual float getWalkSpeed(const Ptr& ptr) const;
virtual float getRunSpeed(const Ptr& ptr) const;
virtual float getSwimSpeed(const Ptr& ptr) const;
/// Return maximal movement speed for the current state.
virtual float getMaxSpeed(const Ptr& ptr) const;
/// Return current movement speed.
virtual float getCurrentSpeed(const Ptr& ptr) const;
2011-01-18 09:45:29 +00:00
virtual float getJump(const MWWorld::Ptr &ptr) const;
///< Return jump velocity (not accounting for movement)
virtual MWMechanics::Movement& getMovementSettings (const Ptr& ptr) const;
///< Return desired movement.
2015-06-03 17:41:19 +00:00
virtual osg::Vec3f getRotationVector (const Ptr& ptr) const;
///< Return desired rotations, as euler angles. Sets getMovementSettings(ptr).mRotation to zero.
virtual std::pair<std::vector<int>, bool> getEquipmentSlots (const ConstPtr& ptr) const;
///< \return first: Return IDs of the slot this object can be equipped in; second: can object
/// stay stacked when equipped?
///
/// Default implementation: return (empty vector, false).
virtual int getEquipmentSkill (const ConstPtr& ptr)
const;
2015-12-19 14:50:13 +00:00
/// Return the index of the skill this item corresponds to when equipped or -1, if there is
/// no such skill.
/// (default implementation: return -1)
virtual int getValue (const ConstPtr& ptr) const;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
/// (default implementation: throws an exception)
2012-05-15 20:31:52 +00:00
virtual float getCapacity (const MWWorld::Ptr& ptr) const;
2012-05-15 19:34:00 +00:00
///< Return total weight that fits into the object. Throws an exception, if the object can't
/// hold other objects.
/// (default implementation: throws an exception)
virtual float getEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns total weight of objects inside this object (including modifications from magic
2012-05-15 19:17:00 +00:00
/// effects). Throws an exception, if the object can't hold other objects.
/// (default implementation: throws an exception)
virtual float getNormalizedEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns encumbrance re-scaled to capacity
virtual bool apply (const MWWorld::Ptr& ptr, const std::string& id,
const MWWorld::Ptr& actor) const;
///< Apply \a id on \a ptr.
/// \param actor Actor that is resposible for the ID being applied to \a ptr.
/// \return Any effect?
///
/// (default implementation: ignore and return false)
virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor=1.f) const;
///< Inform actor \a ptr that a skill use has succeeded.
///
/// (default implementations: throws an exception)
2015-12-18 15:39:35 +00:00
virtual bool isEssential (const MWWorld::ConstPtr& ptr) const;
2012-10-27 11:33:54 +00:00
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
///
/// (default implementation: return false)
2015-12-18 15:09:08 +00:00
virtual std::string getUpSoundId (const ConstPtr& ptr) const;
2012-03-13 16:05:38 +00:00
///< Return the up sound ID of \a ptr or throw an exception, if class does not support ID retrieval
/// (default implementation: throw an exception)
2015-12-18 15:09:08 +00:00
virtual std::string getDownSoundId (const ConstPtr& ptr) const;
2012-03-13 16:05:38 +00:00
///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval
/// (default implementation: throw an exception)
2013-07-18 06:58:21 +00:00
virtual std::string getSoundIdFromSndGen(const Ptr &ptr, const std::string &type) const;
///< Returns the sound ID for \a ptr of the given soundgen \a type.
2013-03-17 21:29:12 +00:00
virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
///< @return combined armor rating of this actor
2015-12-18 14:53:47 +00:00
virtual std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const;
///< Return name of inventory icon.
2015-12-18 14:56:45 +00:00
virtual std::string getEnchantment (const MWWorld::ConstPtr& ptr) const;
2012-05-12 14:17:03 +00:00
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
/// (default implementation: return empty string)
2012-05-21 08:58:04 +00:00
virtual int getEnchantmentPoints (const MWWorld::ConstPtr& ptr) const;
2013-03-16 18:00:14 +00:00
///< @return the number of enchantment points available for possible enchanting
2015-12-18 15:46:02 +00:00
virtual void adjustScale(const MWWorld::ConstPtr& ptr, osg::Vec3f& scale, bool rendering) const;
/// @param rendering Indicates if the scale to adjust is for the rendering mesh, or for the collision mesh
2015-12-18 14:58:23 +00:00
virtual bool canSell (const MWWorld::ConstPtr& item, int npcServices) const;
///< Determine whether or not \a item can be sold to an npc with the given \a npcServices
2015-12-18 15:44:35 +00:00
virtual int getServices (const MWWorld::ConstPtr& actor) const;
2013-05-11 16:38:27 +00:00
2015-12-18 14:51:05 +00:00
virtual std::string getModel(const MWWorld::ConstPtr &ptr) const;
virtual bool useAnim() const;
///< Whether or not to use animated variant of model (default false)
virtual void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector<std::string>& models) const;
///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: list getModel().
2015-12-18 15:43:11 +00:00
virtual std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
2013-03-28 16:41:00 +00:00
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const;
2013-04-08 20:10:55 +00:00
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
/// Second item in the pair specifies the error message
2013-04-05 13:42:05 +00:00
2015-12-18 15:00:50 +00:00
virtual float getWeight (const MWWorld::ConstPtr& ptr) const;
2013-05-11 16:38:27 +00:00
2015-12-18 15:41:37 +00:00
virtual bool isPersistent (const MWWorld::ConstPtr& ptr) const;
2013-05-16 16:50:26 +00:00
virtual bool isKey (const MWWorld::ConstPtr& ptr) const { return false; }
2015-12-18 15:43:11 +00:00
virtual bool isGold(const MWWorld::ConstPtr& ptr) const { return false; }
virtual bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const { return true; }
///< Return whether this class of object can be activated with telekinesis
2019-08-25 13:20:14 +00:00
2014-01-17 09:52:44 +00:00
/// Get a blood texture suitable for \a ptr (see Blood Texture 0-2 in Morrowind.ini)
2015-12-18 15:38:14 +00:00
virtual int getBloodTexture (const MWWorld::ConstPtr& ptr) const;
2014-01-17 09:52:44 +00:00
virtual Ptr copyToCell(const ConstPtr &ptr, CellStore &cell, int count) const;
virtual Ptr copyToCell(const ConstPtr &ptr, CellStore &cell, const ESM::Position &pos, int count) const;
2013-08-09 05:34:53 +00:00
virtual bool isActivator() const {
return false;
}
2013-08-09 05:34:53 +00:00
virtual bool isActor() const {
return false;
}
virtual bool isNpc() const {
2012-07-30 19:28:14 +00:00
return false;
}
2013-08-15 08:21:43 +00:00
virtual bool isDoor() const {
return false;
}
2015-12-18 15:15:40 +00:00
virtual bool isBipedal(const MWWorld::ConstPtr& ptr) const;
virtual bool canFly(const MWWorld::ConstPtr& ptr) const;
virtual bool canSwim(const MWWorld::ConstPtr& ptr) const;
virtual bool canWalk(const MWWorld::ConstPtr& ptr) const;
bool isPureWaterCreature(const MWWorld::ConstPtr& ptr) const;
bool isPureFlyingCreature(const MWWorld::ConstPtr& ptr) const;
2016-11-16 19:15:25 +00:00
bool isPureLandCreature(const MWWorld::Ptr& ptr) const;
bool isMobile(const MWWorld::Ptr& ptr) const;
virtual float getSkill(const MWWorld::Ptr& ptr, int skill) const;
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const;
///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const;
///< Write additional state from \a ptr into \a state.
2013-08-15 08:21:43 +00:00
static const Class& get (const std::string& key);
///< If there is no class for this \a key, an exception is thrown.
static void registerClass (const std::string& key, std::shared_ptr<Class> instance);
2015-12-18 15:28:20 +00:00
virtual int getBaseGold(const MWWorld::ConstPtr& ptr) const;
2014-04-01 18:15:55 +00:00
2015-12-18 15:29:30 +00:00
virtual bool isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const;
2019-08-25 13:20:14 +00:00
virtual DoorState getDoorState (const MWWorld::ConstPtr &ptr) const;
/// This does not actually cause the door to move. Use World::activateDoor instead.
2019-08-25 13:20:14 +00:00
virtual void setDoorState (const MWWorld::Ptr &ptr, DoorState state) const;
virtual void respawn (const MWWorld::Ptr& ptr) const {}
/// Returns sound id
2015-12-18 15:11:03 +00:00
virtual std::string getSound(const MWWorld::ConstPtr& ptr) const;
virtual int getBaseFightRating (const MWWorld::ConstPtr& ptr) const;
2015-01-27 16:32:21 +00:00
virtual std::string getPrimaryFaction (const MWWorld::ConstPtr& ptr) const;
virtual int getPrimaryFactionRank (const MWWorld::ConstPtr& ptr) const;
/// Get the effective armor rating, factoring in the actor's skills, for the given armor.
virtual float getEffectiveArmorRating(const MWWorld::ConstPtr& armor, const MWWorld::Ptr& actor) const;
virtual osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const;
virtual void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const;
virtual void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const;
};
}
#endif