2012-03-30 16:18:58 +02:00
|
|
|
#ifndef GAME_MWMECHANICS_ACTORS_H
|
|
|
|
#define GAME_MWMECHANICS_ACTORS_H
|
|
|
|
|
2015-01-31 23:27:34 +01:00
|
|
|
#include <list>
|
2019-02-19 01:10:55 +03:00
|
|
|
#include <map>
|
2012-03-30 16:18:58 +02:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-05-18 19:24:57 +02:00
|
|
|
#include "actor.hpp"
|
2020-05-17 04:06:39 +03:00
|
|
|
|
2019-02-19 01:10:55 +03:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMReader;
|
|
|
|
class ESMWriter;
|
|
|
|
}
|
2013-01-12 07:12:12 -08:00
|
|
|
|
2019-02-19 01:10:55 +03:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Vec3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Loading
|
|
|
|
{
|
|
|
|
class Listener;
|
|
|
|
}
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2012-07-03 13:55:53 +02:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
class CellStore;
|
|
|
|
}
|
|
|
|
|
2012-03-30 16:18:58 +02:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2014-12-21 16:45:30 +01:00
|
|
|
class Actor;
|
2019-02-07 19:11:12 +04:00
|
|
|
class CharacterController;
|
2016-06-12 02:43:33 +02:00
|
|
|
class CreatureStats;
|
2014-12-21 16:45:30 +01:00
|
|
|
|
2012-03-30 16:18:58 +02:00
|
|
|
class Actors
|
|
|
|
{
|
|
|
|
public:
|
2012-04-23 15:27:03 +02:00
|
|
|
Actors();
|
2014-01-07 19:49:16 +01:00
|
|
|
|
2022-05-18 19:24:57 +02:00
|
|
|
std::list<Actor>::const_iterator begin() const { return mActors.begin(); }
|
2019-08-27 22:42:41 +04:00
|
|
|
std::list<Actor>::const_iterator end() const { return mActors.end(); }
|
2020-05-22 00:11:23 +02:00
|
|
|
std::size_t size() const { return mActors.size(); }
|
2019-08-27 22:42:41 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void notifyDied(const MWWorld::Ptr& actor);
|
2017-09-18 21:46:57 +04:00
|
|
|
|
2013-11-17 23:15:57 +01: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
|
2022-07-04 22:36:08 +02:00
|
|
|
bool isActorDetected(const MWWorld::Ptr& actor, const MWWorld::Ptr& observer) const;
|
2013-11-17 23:15:57 +01:00
|
|
|
|
2018-09-21 16:34:23 +04: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)
|
|
|
|
void updateMagicEffects(const MWWorld::Ptr& ptr) const;
|
|
|
|
|
2014-05-13 19:01:02 +02:00
|
|
|
void updateProcessingRange();
|
2012-03-30 16:18:58 +02:00
|
|
|
float getProcessingRange() const;
|
|
|
|
|
2021-08-28 14:36:30 +02:00
|
|
|
void addActor(const MWWorld::Ptr& ptr, bool updateImmediately = false);
|
2012-03-30 16:18:58 +02:00
|
|
|
///< Register an actor for stats management
|
2012-05-24 13:21:52 +02:00
|
|
|
///
|
|
|
|
/// \note Dead actors are ignored.
|
2012-03-30 16:18:58 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void removeActor(const MWWorld::Ptr& ptr, bool keepActive);
|
|
|
|
///< Deregister an actor for stats management
|
2022-09-22 21:26:05 +03:00
|
|
|
///
|
2013-11-30 10:50:02 +01:00
|
|
|
/// \note Ignored, if \a ptr is not a registered actor.
|
2019-09-21 20:22:45 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void resurrect(const MWWorld::Ptr& ptr) const;
|
2018-06-28 16:58:51 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell = false) const;
|
2013-01-29 00:19:24 -08:00
|
|
|
|
2013-11-30 10:50:02 +01:00
|
|
|
void updateActor(const MWWorld::Ptr& old, const MWWorld::Ptr& ptr) const;
|
|
|
|
///< Updates an actor with a new Ptr
|
2012-03-30 16:18:58 +02:00
|
|
|
|
2017-11-28 20:49:48 +04:00
|
|
|
void dropActors(const MWWorld::CellStore* cellStore, const MWWorld::Ptr& ignore);
|
|
|
|
///< Deregister all actors (except for \a ignore) in the given cell.
|
|
|
|
|
2013-01-16 08:22:38 -08:00
|
|
|
void updateCombatMusic();
|
2012-03-30 16:18:58 +02:00
|
|
|
///< Update combat music state
|
2012-05-18 13:54:07 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void update(float duration, bool paused);
|
2012-05-18 13:54:07 +02:00
|
|
|
///< Update actor stats and store desired velocity vectors in \a movement
|
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void updateActor(const MWWorld::Ptr& ptr, float duration) const;
|
|
|
|
///< This function is normally called automatically during the update process, but it can
|
2012-05-18 13:54:07 +02:00
|
|
|
/// also be called explicitly at any time to force an update.
|
2014-05-16 00:03:48 +04:00
|
|
|
|
2020-05-18 23:04:48 +03:00
|
|
|
/// Removes an actor from combat and makes all of their allies stop fighting the actor's targets
|
2022-07-04 22:36:08 +02:00
|
|
|
void stopCombat(const MWWorld::Ptr& ptr) const;
|
2018-12-14 18:29:56 +03:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void playIdleDialogue(const MWWorld::Ptr& actor) const;
|
|
|
|
void updateMovementSpeed(const MWWorld::Ptr& actor) const;
|
|
|
|
void updateGreetingState(const MWWorld::Ptr& actor, Actor& actorState, bool turnOnly);
|
2019-01-25 20:04:35 +04:00
|
|
|
void turnActorToFacePlayer(const MWWorld::Ptr& actor, Actor& actorState, const osg::Vec3f& dir) const;
|
2014-01-14 02:52:34 +01:00
|
|
|
|
2019-01-13 05:11:51 +03:00
|
|
|
void rest(double hours, bool sleep) const;
|
|
|
|
///< Update actors while the player is waiting or sleeping.
|
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void updateSneaking(CharacterController* ctrl, float duration);
|
|
|
|
///< Update the sneaking indicator state according to the given player character controller.
|
2014-07-24 00:25:02 +02:00
|
|
|
|
2014-01-14 02:52:34 +01:00
|
|
|
void restoreDynamicStats(const MWWorld::Ptr& actor, double hours, bool sleep) const;
|
2014-01-28 12:33:31 +01:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
int getHoursToRest(const MWWorld::Ptr& ptr) const;
|
2014-12-31 18:41:57 +01:00
|
|
|
///< Calculate how many hours the given actor needs to rest in order to be fully healed
|
|
|
|
|
2012-10-27 11:33:18 +02:00
|
|
|
void fastForwardAi() const;
|
|
|
|
///< Simulate the passing of time
|
2013-01-16 17:53:18 -08:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
int countDeaths(const std::string& id) const;
|
|
|
|
///< Return the number of deaths for actors with the given ID.
|
2017-08-16 20:30:47 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
bool isAttackPreparing(const MWWorld::Ptr& ptr) const;
|
|
|
|
bool isRunning(const MWWorld::Ptr& ptr) const;
|
|
|
|
bool isSneaking(const MWWorld::Ptr& ptr) const;
|
2013-04-25 07:08:11 -07:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void forceStateUpdate(const MWWorld::Ptr& ptr) const;
|
2014-01-07 19:49:16 +01:00
|
|
|
|
2022-08-23 18:25:25 +02:00
|
|
|
bool playAnimationGroup(
|
2022-07-04 22:36:08 +02:00
|
|
|
const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist = false) const;
|
|
|
|
void skipAnimation(const MWWorld::Ptr& ptr) const;
|
|
|
|
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) const;
|
|
|
|
void persistAnimationStates() const;
|
2014-01-28 12:33:31 +01:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out) const;
|
2017-11-11 12:31:18 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
bool isAnyObjectInRange(const osg::Vec3f& position, float radius) const;
|
2016-06-12 02:43:33 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void cleanupSummonedCreature(CreatureStats& casterStats, int creatureActorId) const;
|
2014-04-24 22:47:45 -04:00
|
|
|
|
2016-12-20 12:38:51 +01: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 **/
|
2022-07-04 22:36:08 +02:00
|
|
|
std::vector<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor, bool excludeInfighting = false) const;
|
|
|
|
std::vector<MWWorld::Ptr> getActorsFollowing(const MWWorld::Ptr& actor) const;
|
2016-12-20 12:38:51 +01:00
|
|
|
|
2014-12-09 16:02:07 +01:00
|
|
|
/// Recursive version of getActorsFollowing
|
2022-07-04 22:36:08 +02:00
|
|
|
void getActorsFollowing(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) const;
|
2016-12-20 12:38:51 +01:00
|
|
|
/// Recursive version of getActorsSidingWith
|
2022-07-04 22:36:08 +02:00
|
|
|
void getActorsSidingWith(
|
|
|
|
const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out, bool excludeInfighting = false) const;
|
2014-12-09 16:02:07 +01:00
|
|
|
|
2014-04-24 22:47:45 -04:00
|
|
|
/// Get the list of AiFollow::mFollowIndex for all actors following this target
|
|
|
|
std::vector<int> getActorsFollowingIndices(const MWWorld::Ptr& actor) const;
|
2022-07-04 22:36:08 +02:00
|
|
|
std::map<int, MWWorld::Ptr> getActorsFollowingByIndex(const MWWorld::Ptr& actor) const;
|
2014-01-20 13:00:43 +01:00
|
|
|
|
2016-06-07 01:53:16 +02:00
|
|
|
/// Returns the list of actors which are fighting the given actor
|
|
|
|
/**ie AiCombat is active and the target is the actor **/
|
2022-07-04 22:36:08 +02:00
|
|
|
std::vector<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor) const;
|
2016-06-07 01:53:16 +02:00
|
|
|
|
2014-06-13 01:24:58 +02:00
|
|
|
/// Unlike getActorsFighting, also returns actors that *would* fight the given actor if they saw him.
|
|
|
|
std::vector<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor) const;
|
|
|
|
|
2015-01-22 19:04:59 +01:00
|
|
|
void write(ESM::ESMWriter& writer, Loading::Listener& listener) const;
|
2014-06-13 01:24:58 +02:00
|
|
|
|
|
|
|
void readRecord(ESM::ESMReader& reader, uint32_t type);
|
|
|
|
|
2014-12-12 16:49:22 +01:00
|
|
|
void clear(); // Clear death counter
|
|
|
|
|
2020-05-17 04:06:39 +03:00
|
|
|
bool isCastingSpell(const MWWorld::Ptr& ptr) const;
|
|
|
|
bool isReadyToBlock(const MWWorld::Ptr& ptr) const;
|
2017-08-18 19:24:34 +04:00
|
|
|
bool isAttackingOrSpell(const MWWorld::Ptr& ptr) const;
|
2020-05-17 04:06:39 +03:00
|
|
|
|
|
|
|
int getGreetingTimer(const MWWorld::Ptr& ptr) const;
|
|
|
|
float getAngleToPlayer(const MWWorld::Ptr& ptr) const;
|
2022-05-06 23:59:27 +02:00
|
|
|
GreetingState getGreetingState(const MWWorld::Ptr& ptr) const;
|
2022-05-07 00:11:12 +02:00
|
|
|
bool isTurningToPlayer(const MWWorld::Ptr& ptr) const;
|
|
|
|
|
2022-05-18 19:24:57 +02:00
|
|
|
private:
|
2022-05-23 01:08:53 +02:00
|
|
|
enum class MusicType
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-05-23 01:08:53 +02:00
|
|
|
Title,
|
|
|
|
Explore,
|
2022-09-22 21:26:05 +03:00
|
|
|
Battle
|
2022-05-23 01:08:53 +02:00
|
|
|
};
|
2019-02-07 19:11:12 +04:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
std::map<std::string, int> mDeathCount;
|
|
|
|
std::list<Actor> mActors;
|
|
|
|
std::map<const MWWorld::LiveCellRefBase*, std::list<Actor>::iterator> mIndex;
|
|
|
|
float mTimerDisposeSummonsCorpses;
|
|
|
|
float mTimerUpdateHeadTrack = 0;
|
2022-05-07 00:11:12 +02:00
|
|
|
float mTimerUpdateEquippedLight = 0;
|
|
|
|
float mTimerUpdateHello = 0;
|
2022-07-04 22:36:08 +02:00
|
|
|
float mSneakTimer = 0; // Times update of sneak icon
|
|
|
|
float mSneakSkillTimer = 0; // Times sneak skill progress from "avoid notice"
|
2022-05-06 23:59:27 +02:00
|
|
|
float mActorsProcessingRange;
|
2022-07-04 22:36:08 +02:00
|
|
|
bool mSmoothMovement;
|
|
|
|
MusicType mCurrentMusic = MusicType::Title;
|
2014-01-07 19:49:16 +01:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void updateVisibility(const MWWorld::Ptr& ptr, CharacterController& ctrl) const;
|
2022-05-06 23:59:27 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void adjustMagicEffects(const MWWorld::Ptr& creature, float duration) const;
|
2022-05-06 23:59:27 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void calculateRestoration(const MWWorld::Ptr& ptr, float duration) const;
|
2022-05-06 23:59:27 +02:00
|
|
|
|
|
|
|
void updateCrimePursuit(const MWWorld::Ptr& ptr, float duration) const;
|
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void killDeadActors();
|
2022-05-06 23:59:27 +02:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void purgeSpellEffects(int casterActorId) const;
|
2021-11-27 14:20:55 +01:00
|
|
|
|
2022-07-04 22:36:08 +02:00
|
|
|
void predictAndAvoidCollisions(float duration) const;
|
2021-11-27 14:20:55 +01:00
|
|
|
|
2022-07-04 22:36:08 +02: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.
|
|
|
|
*/
|
|
|
|
void engageCombat(const MWWorld::Ptr& actor1, const MWWorld::Ptr& actor2,
|
|
|
|
std::map<const MWWorld::Ptr, const std::set<MWWorld::Ptr>>& cachedAllies, bool againstPlayer) const;
|
2021-11-27 14:20:55 +01:00
|
|
|
|
2015-12-06 23:32:49 +01:00
|
|
|
/// Recursive version of getActorsSidingWith that takes, adds to and returns a cache of
|
2022-07-04 22:36:08 +02:00
|
|
|
/// actors mapped to their allies. Excludes infighting
|
|
|
|
void getActorsSidingWith(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out,
|
|
|
|
std::map<const MWWorld::Ptr, const std::set<MWWorld::Ptr>>& cachedAllies) const;
|
2012-03-30 16:18:58 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|