2012-08-11 15:30:55 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_MECHANICSMANAGERIMP_H
|
|
|
|
#define GAME_MWMECHANICS_MECHANICSMANAGERIMP_H
|
2010-07-26 09:15:38 +00:00
|
|
|
|
2018-09-21 12:34:23 +00:00
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
2012-08-11 15:30:55 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2010-07-27 12:05:05 +00:00
|
|
|
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2010-07-27 13:59:41 +00:00
|
|
|
#include "creaturestats.hpp"
|
2010-09-21 15:42:07 +00:00
|
|
|
#include "npcstats.hpp"
|
2015-04-25 13:19:17 +00:00
|
|
|
#include "objects.hpp"
|
|
|
|
#include "actors.hpp"
|
2010-07-27 13:59:41 +00:00
|
|
|
|
2012-07-03 11:55:53 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class CellStore;
|
|
|
|
}
|
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2012-08-11 15:30:55 +00:00
|
|
|
class MechanicsManager : public MWBase::MechanicsManager
|
2010-07-26 09:15:38 +00:00
|
|
|
{
|
2010-09-15 12:33:02 +00:00
|
|
|
bool mUpdatePlayer;
|
2010-09-26 08:01:30 +00:00
|
|
|
bool mClassSelected;
|
|
|
|
bool mRaceSelected;
|
2013-11-18 22:03:44 +00:00
|
|
|
bool mAI;///< is AI active?
|
2013-01-29 07:39:11 +00:00
|
|
|
|
2015-04-25 13:19:17 +00:00
|
|
|
Objects mObjects;
|
|
|
|
Actors mActors;
|
2010-09-13 20:59:28 +00:00
|
|
|
|
2015-02-04 20:18:43 +00:00
|
|
|
typedef std::pair<std::string, bool> Owner; // < Owner id, bool isFaction >
|
|
|
|
typedef std::map<Owner, int> OwnerMap; // < Owner, number of stolen items with this id from this owner >
|
|
|
|
typedef std::map<std::string, OwnerMap> StolenItemsMap;
|
|
|
|
StolenItemsMap mStolenItems;
|
|
|
|
|
2013-11-14 13:41:10 +00:00
|
|
|
public:
|
|
|
|
|
2010-09-15 11:31:26 +00:00
|
|
|
void buildPlayer();
|
|
|
|
///< build player according to stored class/race/birthsign information. Will
|
|
|
|
/// default to the values of the ESM::NPC object, if no explicit information is given.
|
|
|
|
|
2012-08-11 15:30:55 +00:00
|
|
|
MechanicsManager();
|
2010-09-13 20:59:28 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void add (const MWWorld::Ptr& ptr) override;
|
2013-01-29 07:39:11 +00:00
|
|
|
///< Register an object for management
|
2010-07-27 12:43:46 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void remove (const MWWorld::Ptr& ptr) override;
|
2013-01-29 07:39:11 +00:00
|
|
|
///< Deregister an object for management
|
2010-09-13 20:59:28 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void updateCell(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr) override;
|
2013-01-29 08:19:24 +00:00
|
|
|
///< Moves an object to a new cell
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void drop(const MWWorld::CellStore *cellStore) override;
|
2013-01-29 07:39:11 +00:00
|
|
|
///< Deregister all objects in the given cell.
|
2010-09-13 20:59:28 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void update (float duration, bool paused) override;
|
2013-01-29 07:39:11 +00:00
|
|
|
///< Update objects
|
2012-03-30 15:01:55 +00:00
|
|
|
///
|
|
|
|
/// \param paused In game type does not currently advance (this usually means some GUI
|
|
|
|
/// component is up).
|
2010-09-13 20:59:28 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setPlayerName (const std::string& name) override;
|
2010-09-13 20:59:28 +00:00
|
|
|
///< Set player name.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setPlayerRace (const std::string& id, bool male, const std::string &head, const std::string &hair) override;
|
2010-09-13 20:59:28 +00:00
|
|
|
///< Set player race.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setPlayerBirthsign (const std::string& id) override;
|
2010-09-13 20:59:28 +00:00
|
|
|
///< Set player birthsign.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setPlayerClass (const std::string& id) override;
|
2010-09-13 20:59:28 +00:00
|
|
|
///< Set player class to stock class.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setPlayerClass (const ESM::Class& class_) override;
|
2010-09-13 20:59:28 +00:00
|
|
|
///< Set player class to custom class.
|
2012-09-21 15:53:16 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void restoreDynamicStats(MWWorld::Ptr actor, double hours, bool sleep) override;
|
2018-09-23 18:03:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void rest(double hours, bool sleep) override;
|
2014-01-14 01:20:13 +00:00
|
|
|
///< If the player is sleeping or waiting, this should be called every hour.
|
|
|
|
/// @param sleep is the player sleeping or waiting?
|
2012-11-05 10:07:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getHoursToRest() const override;
|
2014-01-14 01:52:34 +00:00
|
|
|
///< Calculate how many hours the player needs to rest in order to be fully healed
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getBarterOffer(const MWWorld::Ptr& ptr,int basePrice, bool buying) override;
|
2012-11-05 10:07:43 +00:00
|
|
|
///< This is used by every service to determine the price of objects given the trading skills of the player and NPC.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getDerivedDisposition(const MWWorld::Ptr& ptr, bool addTemporaryDispositionChange = true) override;
|
2012-11-05 10:07:43 +00:00
|
|
|
///< Calculate the diposition of an NPC toward the player.
|
2012-11-08 22:16:40 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int countDeaths (const std::string& id) const override;
|
2012-10-27 09:33:18 +00:00
|
|
|
///< Return the number of deaths for actors with the given ID.
|
2013-11-19 08:10:48 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type, bool& success, float& tempChange, float& permChange) override;
|
2012-11-09 23:29:36 +00:00
|
|
|
///< Perform a persuasion action on NPC
|
2013-01-17 01:53:18 +00:00
|
|
|
|
2014-01-06 23:51:09 +00:00
|
|
|
/// Check if \a observer is potentially aware of \a ptr. Does not do a line of sight check!
|
2020-10-16 18:18:54 +00:00
|
|
|
bool awarenessCheck (const MWWorld::Ptr& ptr, const MWWorld::Ptr& observer) override;
|
2014-01-06 23:51:09 +00:00
|
|
|
|
2014-05-05 22:13:31 +00:00
|
|
|
/// Makes \a ptr fight \a target. Also shouts a combat taunt.
|
2020-10-16 18:18:54 +00:00
|
|
|
void startCombat (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target) override;
|
2014-05-05 22:13:31 +00:00
|
|
|
|
2014-01-07 18:49:16 +00:00
|
|
|
/**
|
2014-06-16 02:03:53 +00:00
|
|
|
* @note victim may be empty
|
2014-01-07 18:49:16 +00:00
|
|
|
* @param arg Depends on \a type, e.g. for Theft, the value of the item that was stolen.
|
2014-12-19 20:45:26 +00:00
|
|
|
* @param victimAware Is the victim already aware of the crime?
|
|
|
|
* If this parameter is false, it will be determined by a line-of-sight and awareness check.
|
|
|
|
* @return was the crime seen?
|
2014-01-07 18:49:16 +00:00
|
|
|
*/
|
2020-10-16 18:18:54 +00:00
|
|
|
bool commitCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
|
2019-09-16 10:20:43 +00:00
|
|
|
OffenseType type, const std::string& factionId="", int arg=0, bool victimAware=false) override;
|
2014-09-26 20:08:07 +00:00
|
|
|
/// @return false if the attack was considered a "friendly hit" and forgiven
|
2020-10-16 18:18:54 +00:00
|
|
|
bool actorAttacked (const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker) override;
|
2015-07-18 18:39:45 +00:00
|
|
|
|
|
|
|
/// Notify that actor was killed, add a murder bounty if applicable
|
|
|
|
/// @note No-op for non-player attackers
|
2020-10-16 18:18:54 +00:00
|
|
|
void actorKilled (const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker) override;
|
2018-08-15 23:26:02 +00:00
|
|
|
|
2014-01-07 18:49:16 +00:00
|
|
|
/// Utility to check if taking this item is illegal and calling commitCrime if so
|
2015-02-03 22:43:56 +00:00
|
|
|
/// @param container The container the item is in; may be empty for an item in the world
|
2020-10-16 18:18:54 +00:00
|
|
|
void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, const MWWorld::Ptr& container,
|
2018-10-31 06:09:32 +00:00
|
|
|
int count, bool alarm = true) override;
|
2019-09-05 14:36:49 +00:00
|
|
|
/// Utility to check if unlocking this object is illegal and calling commitCrime if so
|
2020-10-16 18:18:54 +00:00
|
|
|
void unlockAttempted (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item) override;
|
2014-01-08 16:19:43 +00:00
|
|
|
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
|
2014-04-25 02:47:45 +00:00
|
|
|
/// @return was it illegal, and someone saw you doing it? Also returns fail when enemies are nearby
|
2020-10-16 18:18:54 +00:00
|
|
|
bool sleepInBed (const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed) override;
|
2014-01-07 18:49:16 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void forceStateUpdate(const MWWorld::Ptr &ptr) override;
|
2013-04-25 14:08:11 +00:00
|
|
|
|
2015-07-29 18:15:06 +00:00
|
|
|
/// Attempt to play an animation group
|
|
|
|
/// @return Success or error
|
2020-10-16 18:18:54 +00:00
|
|
|
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false) override;
|
|
|
|
void skipAnimation(const MWWorld::Ptr& ptr) override;
|
|
|
|
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName) override;
|
|
|
|
void persistAnimationStates() override;
|
2013-11-17 22:15:57 +00:00
|
|
|
|
|
|
|
/// Update magic effects for an actor. Usually done automatically once per frame, but if we're currently
|
|
|
|
/// paused we may want to do it manually (after equipping permanent enchantment)
|
2020-10-16 18:18:54 +00:00
|
|
|
void updateMagicEffects (const MWWorld::Ptr& ptr) override;
|
2013-11-17 22:15:57 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void getObjectsInRange (const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& objects) override;
|
|
|
|
void getActorsInRange(const osg::Vec3f &position, float radius, std::vector<MWWorld::Ptr> &objects) override;
|
2014-01-20 12:00:43 +00:00
|
|
|
|
2017-11-11 08:31:18 +00:00
|
|
|
/// Check if there are actors in selected range
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isAnyActorInRange(const osg::Vec3f &position, float radius) override;
|
2017-11-11 08:31:18 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor) override;
|
|
|
|
std::list<MWWorld::Ptr> getActorsFollowing(const MWWorld::Ptr& actor) override;
|
|
|
|
std::list<int> getActorsFollowingIndices(const MWWorld::Ptr& actor) override;
|
2020-12-25 22:57:01 +00:00
|
|
|
std::map<int, MWWorld::Ptr> getActorsFollowingByIndex(const MWWorld::Ptr& actor) override;
|
2014-01-28 11:33:31 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor) override;
|
|
|
|
std::list<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor) override;
|
2014-04-25 02:47:45 +00:00
|
|
|
|
2016-12-20 11:38:51 +00:00
|
|
|
/// Recursive version of getActorsFollowing
|
2020-10-16 18:18:54 +00:00
|
|
|
void getActorsFollowing(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) override;
|
2016-12-20 11:38:51 +00:00
|
|
|
/// Recursive version of getActorsSidingWith
|
2020-10-16 18:18:54 +00:00
|
|
|
void getActorsSidingWith(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) override;
|
2016-12-20 11:38:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool toggleAI() override;
|
|
|
|
bool isAIActive() override;
|
2013-12-07 12:17:28 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void playerLoaded() override;
|
2014-06-12 23:24:58 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool onOpen(const MWWorld::Ptr& ptr) override;
|
|
|
|
void onClose(const MWWorld::Ptr& ptr) override;
|
2018-09-22 08:57:50 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int countSavedGameRecords() const override;
|
2014-06-12 23:24:58 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void write (ESM::ESMWriter& writer, Loading::Listener& listener) const override;
|
2014-06-12 23:24:58 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void readRecord (ESM::ESMReader& reader, uint32_t type) override;
|
2014-06-12 23:24:58 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void clear() override;
|
2014-06-16 17:34:53 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isAggressive (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target) override;
|
2014-07-21 18:37:14 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void resurrect(const MWWorld::Ptr& ptr) override;
|
2014-12-12 15:49:22 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isCastingSpell (const MWWorld::Ptr& ptr) const override;
|
2018-06-28 12:58:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isReadyToBlock (const MWWorld::Ptr& ptr) const override;
|
2017-08-18 15:24:34 +00:00
|
|
|
/// Is \a ptr casting spell or using weapon now?
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isAttackingOrSpell(const MWWorld::Ptr &ptr) const override;
|
2014-12-19 20:45:26 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void castSpell(const MWWorld::Ptr& ptr, const std::string spellId, bool manualSpell=false) override;
|
2018-06-28 12:58:51 +00:00
|
|
|
|
2018-09-21 12:34:23 +00:00
|
|
|
void processChangedSettings(const Settings::CategorySettingVector& settings) override;
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
float getActorsProcessingRange() const override;
|
2018-09-21 12:34:23 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void notifyDied(const MWWorld::Ptr& actor) override;
|
2019-08-27 18:42:41 +00:00
|
|
|
|
2017-09-18 17:46:57 +00:00
|
|
|
/// Check if the target actor was detected by an observer
|
|
|
|
/// If the observer is a non-NPC, check all actors in AI processing distance as observers
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isActorDetected(const MWWorld::Ptr& actor, const MWWorld::Ptr& observer) override;
|
2017-09-18 17:46:57 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void confiscateStolenItems (const MWWorld::Ptr& player, const MWWorld::Ptr& targetContainer) override;
|
2015-02-04 20:18:43 +00:00
|
|
|
|
|
|
|
/// List the owners that the player has stolen this item from (the owner can be an NPC or a faction).
|
|
|
|
/// <Owner, item count>
|
2020-10-16 18:18:54 +00:00
|
|
|
std::vector<std::pair<std::string, int> > getStolenItemOwners(const std::string& itemid) override;
|
2015-02-04 20:18:43 +00:00
|
|
|
|
|
|
|
/// Has the player stolen this item from the given owner?
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) override;
|
2017-08-16 16:30:47 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isBoundItem(const MWWorld::Ptr& item) override;
|
2017-11-10 05:43:22 +00:00
|
|
|
|
2017-09-30 16:22:26 +00:00
|
|
|
/// @return is \a ptr allowed to take/use \a target or is it a crime?
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim) override;
|
2015-02-04 20:18:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setWerewolf(const MWWorld::Ptr& actor, bool werewolf) override;
|
|
|
|
void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) override;
|
2015-12-26 17:22:21 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId) override;
|
2016-06-12 00:43:33 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void confiscateStolenItemToOwner(const MWWorld::Ptr &player, const MWWorld::Ptr &item, const MWWorld::Ptr& victim, int count) override;
|
2017-08-14 06:41:37 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isAttackPreparing(const MWWorld::Ptr& ptr) override;
|
|
|
|
bool isRunning(const MWWorld::Ptr& ptr) override;
|
|
|
|
bool isSneaking(const MWWorld::Ptr& ptr) override;
|
2017-09-01 05:34:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
|
2020-05-21 22:11:23 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getGreetingTimer(const MWWorld::Ptr& ptr) const override;
|
|
|
|
float getAngleToPlayer(const MWWorld::Ptr& ptr) const override;
|
|
|
|
GreetingState getGreetingState(const MWWorld::Ptr& ptr) const override;
|
|
|
|
bool isTurningToPlayer(const MWWorld::Ptr& ptr) const override;
|
2020-05-17 01:06:39 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void restoreStatsAfterCorprus(const MWWorld::Ptr& actor, const std::string& sourceId) override;
|
2019-09-30 16:27:42 +00:00
|
|
|
|
2014-12-19 20:45:26 +00:00
|
|
|
private:
|
2018-10-31 06:09:32 +00:00
|
|
|
bool canCommitCrimeAgainst(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker);
|
2018-06-01 08:41:31 +00:00
|
|
|
bool canReportCrime(const MWWorld::Ptr &actor, const MWWorld::Ptr &victim, std::set<MWWorld::Ptr> &playerFollowers);
|
|
|
|
|
|
|
|
bool reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
|
2019-09-16 10:20:43 +00:00
|
|
|
OffenseType type, const std::string& factionId, int arg=0);
|
2010-07-26 09:15:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|