2012-03-30 14:18:58 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_ACTORS_H
|
|
|
|
#define GAME_MWMECHANICS_ACTORS_H
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2015-01-31 22:27:34 +00:00
|
|
|
#include <list>
|
2012-03-30 14:18:58 +00:00
|
|
|
|
2013-02-05 19:03:39 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2013-01-12 15:12:12 +00:00
|
|
|
|
2016-06-17 14:07:16 +00:00
|
|
|
#include "movement.hpp"
|
|
|
|
|
2012-07-03 11:55:53 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
class CellStore;
|
|
|
|
}
|
|
|
|
|
2012-03-30 14:18:58 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2014-12-21 15:45:30 +00:00
|
|
|
class Actor;
|
2016-06-12 00:43:33 +00:00
|
|
|
class CreatureStats;
|
2014-12-21 15:45:30 +00:00
|
|
|
|
2012-03-30 14:18:58 +00:00
|
|
|
class Actors
|
|
|
|
{
|
2013-12-20 21:38:23 +00:00
|
|
|
std::map<std::string, int> mDeathCount;
|
2017-11-23 15:57:36 +00:00
|
|
|
|
2017-12-24 13:18:16 +00:00
|
|
|
void addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
|
|
|
void removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
2013-11-09 09:49:00 +00:00
|
|
|
|
2012-05-17 11:21:49 +00:00
|
|
|
void adjustMagicEffects (const MWWorld::Ptr& creature);
|
|
|
|
|
2012-07-17 10:18:43 +00:00
|
|
|
void calculateDynamicStats (const MWWorld::Ptr& ptr);
|
|
|
|
|
2013-11-16 02:16:21 +00:00
|
|
|
void calculateCreatureStatModifiers (const MWWorld::Ptr& ptr, float duration);
|
2014-11-02 17:01:12 +00:00
|
|
|
void calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration);
|
2012-07-17 13:49:37 +00:00
|
|
|
|
2014-07-23 22:25:02 +00:00
|
|
|
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);
|
2012-09-21 15:53:16 +00:00
|
|
|
|
2018-09-22 11:48:36 +00:00
|
|
|
void updateDrowning (const MWWorld::Ptr& ptr, float duration, bool isKnockedOut, bool isPlayer);
|
2012-09-21 15:53:16 +00:00
|
|
|
|
2018-03-03 13:18:40 +00:00
|
|
|
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
|
2013-10-15 19:23:42 +00:00
|
|
|
|
2018-03-23 12:10:43 +00:00
|
|
|
void updateCrimePursuit (const MWWorld::Ptr& ptr, float duration);
|
2014-04-03 04:50:09 +00:00
|
|
|
|
2014-09-05 15:17:45 +00:00
|
|
|
void killDeadActors ();
|
|
|
|
|
2016-06-11 22:41:13 +00:00
|
|
|
void purgeSpellEffects (int casterActorId);
|
|
|
|
|
2012-03-30 14:18:58 +00:00
|
|
|
public:
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
Actors();
|
2013-12-30 20:47:06 +00:00
|
|
|
~Actors();
|
2012-03-30 14:18:58 +00:00
|
|
|
|
2014-12-21 15:45:30 +00:00
|
|
|
typedef std::map<MWWorld::Ptr,Actor*> PtrActorMap;
|
2014-01-07 18:49:16 +00:00
|
|
|
|
2014-12-21 15:45:30 +00:00
|
|
|
PtrActorMap::const_iterator begin() { return mActors.begin(); }
|
|
|
|
PtrActorMap::const_iterator end() { return mActors.end(); }
|
2014-01-07 18:49:16 +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
|
|
|
|
bool isActorDetected(const MWWorld::Ptr& actor, const MWWorld::Ptr& observer);
|
|
|
|
|
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)
|
2014-08-14 23:13:38 +00:00
|
|
|
void updateMagicEffects (const MWWorld::Ptr& ptr);
|
2013-11-17 22:15:57 +00:00
|
|
|
|
2014-05-13 17:01:02 +00:00
|
|
|
void addActor (const MWWorld::Ptr& ptr, bool updateImmediately=false);
|
2012-03-30 14:18:58 +00:00
|
|
|
///< Register an actor for stats management
|
2012-10-20 08:49:48 +00:00
|
|
|
///
|
|
|
|
/// \note Dead actors are ignored.
|
2012-03-30 14:18:58 +00:00
|
|
|
|
|
|
|
void removeActor (const MWWorld::Ptr& ptr);
|
|
|
|
///< Deregister an actor for stats management
|
2012-05-24 11:21:52 +00:00
|
|
|
///
|
|
|
|
/// \note Ignored, if \a ptr is not a registered actor.
|
2012-03-30 14:18:58 +00:00
|
|
|
|
2018-06-28 12:58:51 +00:00
|
|
|
void castSpell(const MWWorld::Ptr& ptr, const std::string spellId, bool manualSpell=false);
|
|
|
|
|
2013-02-25 17:57:34 +00:00
|
|
|
void updateActor(const MWWorld::Ptr &old, const MWWorld::Ptr& ptr);
|
|
|
|
///< Updates an actor with a new Ptr
|
2013-01-29 08:19:24 +00:00
|
|
|
|
2013-11-30 09:50:02 +00:00
|
|
|
void dropActors (const MWWorld::CellStore *cellStore, const MWWorld::Ptr& ignore);
|
|
|
|
///< Deregister all actors (except for \a ignore) in the given cell.
|
2012-03-30 14:18:58 +00:00
|
|
|
|
2017-11-28 16:49:48 +00:00
|
|
|
void updateCombatMusic();
|
|
|
|
///< Update combat music state
|
|
|
|
|
2013-01-16 16:22:38 +00:00
|
|
|
void update (float duration, bool paused);
|
2012-03-30 14:18:58 +00:00
|
|
|
///< Update actor stats and store desired velocity vectors in \a movement
|
2012-05-18 11:54:07 +00:00
|
|
|
|
|
|
|
void updateActor (const MWWorld::Ptr& ptr, float duration);
|
|
|
|
///< This function is normally called automatically during the update process, but it can
|
|
|
|
/// also be called explicitly at any time to force an update.
|
|
|
|
|
2014-05-15 20:03:48 +00:00
|
|
|
/** Start combat between two actors
|
|
|
|
@Notes: If againstPlayer = true then actor2 should be the Player.
|
|
|
|
If one of the combatants is creature it should be actor1.
|
|
|
|
*/
|
2017-04-12 16:01:50 +00:00
|
|
|
void engageCombat(const MWWorld::Ptr& actor1, const MWWorld::Ptr& actor2, std::map<const MWWorld::Ptr, const std::set<MWWorld::Ptr> >& cachedAllies, bool againstPlayer);
|
2014-05-15 20:03:48 +00:00
|
|
|
|
2014-12-16 19:47:45 +00:00
|
|
|
void updateHeadTracking(const MWWorld::Ptr& actor, const MWWorld::Ptr& targetActor,
|
|
|
|
MWWorld::Ptr& headTrackTarget, float& sqrHeadTrackDistance);
|
|
|
|
|
2016-07-05 22:20:23 +00:00
|
|
|
void rest(bool sleep);
|
|
|
|
///< Update actors while the player is waiting or sleeping. This should be called every hour.
|
2014-01-14 01:52:34 +00:00
|
|
|
|
2014-07-23 22:25:02 +00:00
|
|
|
void restoreDynamicStats(const MWWorld::Ptr& actor, bool sleep);
|
|
|
|
|
2014-01-14 01:52:34 +00:00
|
|
|
int getHoursToRest(const MWWorld::Ptr& ptr) const;
|
|
|
|
///< Calculate how many hours the given actor needs to rest in order to be fully healed
|
2014-01-28 11:33:31 +00:00
|
|
|
|
2014-12-31 17:41:57 +00:00
|
|
|
void fastForwardAi();
|
|
|
|
///< Simulate the passing of time
|
|
|
|
|
2012-10-27 09:33:18 +00:00
|
|
|
int countDeaths (const std::string& id) const;
|
|
|
|
///< Return the number of deaths for actors with the given ID.
|
2013-01-17 01:53:18 +00:00
|
|
|
|
2018-08-16 13:47:06 +00:00
|
|
|
bool isAttackPreparing(const MWWorld::Ptr& ptr);
|
2017-08-16 16:30:47 +00:00
|
|
|
bool isRunning(const MWWorld::Ptr& ptr);
|
|
|
|
bool isSneaking(const MWWorld::Ptr& ptr);
|
|
|
|
|
2017-11-11 08:31:18 +00:00
|
|
|
void forceStateUpdate(const MWWorld::Ptr &ptr);
|
2013-04-25 14:08:11 +00:00
|
|
|
|
2017-11-11 08:31:18 +00:00
|
|
|
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false);
|
|
|
|
void skipAnimation(const MWWorld::Ptr& ptr);
|
|
|
|
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName);
|
|
|
|
void persistAnimationStates();
|
2014-01-07 18:49:16 +00:00
|
|
|
|
2015-06-01 19:41:13 +00:00
|
|
|
void getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out);
|
2014-01-28 11:33:31 +00:00
|
|
|
|
2017-11-11 08:31:18 +00:00
|
|
|
bool isAnyObjectInRange(const osg::Vec3f& position, float radius);
|
|
|
|
|
2016-06-12 00:43:33 +00:00
|
|
|
void cleanupSummonedCreature (CreatureStats& casterStats, int creatureActorId);
|
|
|
|
|
2015-12-06 22:32:49 +00:00
|
|
|
///Returns the list of actors which are siding with the given actor in fights
|
|
|
|
/**ie AiFollow or AiEscort is active and the target is the actor **/
|
|
|
|
std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor);
|
2015-12-19 14:11:07 +00:00
|
|
|
std::list<MWWorld::Ptr> getActorsFollowing(const MWWorld::Ptr& actor);
|
2014-04-25 02:47:45 +00:00
|
|
|
|
2016-12-20 11:38:51 +00:00
|
|
|
/// Recursive version of getActorsFollowing
|
|
|
|
void getActorsFollowing(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out);
|
|
|
|
/// Recursive version of getActorsSidingWith
|
|
|
|
void getActorsSidingWith(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out);
|
2017-04-12 16:01:50 +00:00
|
|
|
/// Recursive version of getActorsSidingWith that takes, adds to and returns a cache of actors mapped to their allies
|
|
|
|
void getActorsSidingWith(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out, std::map<const MWWorld::Ptr, const std::set<MWWorld::Ptr> >& cachedAllies);
|
2016-12-20 11:38:51 +00:00
|
|
|
|
2014-12-09 15:02:07 +00:00
|
|
|
/// Get the list of AiFollow::mFollowIndex for all actors following this target
|
|
|
|
std::list<int> getActorsFollowingIndices(const MWWorld::Ptr& actor);
|
|
|
|
|
2014-04-25 02:47:45 +00:00
|
|
|
///Returns the list of actors which are fighting the given actor
|
|
|
|
/**ie AiCombat is active and the target is the actor **/
|
|
|
|
std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor);
|
2014-01-20 12:00:43 +00:00
|
|
|
|
2016-06-06 23:53:16 +00:00
|
|
|
/// Unlike getActorsFighting, also returns actors that *would* fight the given actor if they saw him.
|
|
|
|
std::list<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor);
|
|
|
|
|
2014-06-12 23:24:58 +00:00
|
|
|
void write (ESM::ESMWriter& writer, Loading::Listener& listener) const;
|
|
|
|
|
2015-01-22 18:04:59 +00:00
|
|
|
void readRecord (ESM::ESMReader& reader, uint32_t type);
|
2014-06-12 23:24:58 +00:00
|
|
|
|
|
|
|
void clear(); // Clear death counter
|
|
|
|
|
2018-06-28 12:58:51 +00:00
|
|
|
bool isCastingSpell(const MWWorld::Ptr& ptr) const;
|
2014-12-12 15:49:22 +00:00
|
|
|
bool isReadyToBlock(const MWWorld::Ptr& ptr) const;
|
2017-08-18 15:24:34 +00:00
|
|
|
bool isAttackingOrSpell(const MWWorld::Ptr& ptr) const;
|
2014-12-12 15:49:22 +00:00
|
|
|
|
2014-01-07 18:49:16 +00:00
|
|
|
private:
|
2014-12-21 15:45:30 +00:00
|
|
|
PtrActorMap mActors;
|
2017-08-18 07:58:28 +00:00
|
|
|
float mTimerDisposeSummonsCorpses;
|
2014-01-07 18:49:16 +00:00
|
|
|
|
2012-03-30 14:18:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|