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