2012-09-04 11:25:53 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_AIPACKAGE_H
|
|
|
|
#define GAME_MWMECHANICS_AIPACKAGE_H
|
|
|
|
|
2020-06-01 13:36:14 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-06-12 23:56:04 +00:00
|
|
|
#include <components/detournavigator/areatype.hpp>
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2016-06-17 14:07:16 +00:00
|
|
|
#include "pathfinding.hpp"
|
2014-05-13 07:58:32 +00:00
|
|
|
#include "obstacle.hpp"
|
2014-10-08 08:58:52 +00:00
|
|
|
#include "aistate.hpp"
|
2020-05-16 19:52:16 +00:00
|
|
|
#include "aipackagetypeid.hpp"
|
2021-03-19 22:23:26 +00:00
|
|
|
#include "aitimer.hpp"
|
2014-05-13 07:58:32 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-06-13 22:30:55 +00:00
|
|
|
struct Cell;
|
2014-06-12 21:27:04 +00:00
|
|
|
namespace AiSequence
|
|
|
|
{
|
2015-03-06 08:36:42 +00:00
|
|
|
struct AiSequence;
|
2014-06-12 21:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:58:52 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2015-06-26 15:47:04 +00:00
|
|
|
class CharacterController;
|
2017-11-27 17:30:31 +00:00
|
|
|
class PathgridGraph;
|
2015-06-26 15:47:04 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
/// \brief Base class for AI packages
|
|
|
|
class AiPackage
|
|
|
|
{
|
|
|
|
public:
|
2020-05-16 19:08:39 +00:00
|
|
|
struct Options
|
|
|
|
{
|
|
|
|
unsigned int mPriority = 0;
|
|
|
|
bool mUseVariableSpeed = false;
|
|
|
|
bool mSideWithTarget = false;
|
|
|
|
bool mFollowTargetThroughDoors = false;
|
|
|
|
bool mCanCancel = true;
|
|
|
|
bool mShouldCancelPreviousAi = true;
|
|
|
|
bool mRepeat = false;
|
|
|
|
bool mAlwaysActive = false;
|
|
|
|
|
|
|
|
constexpr Options withRepeat(bool value)
|
|
|
|
{
|
|
|
|
mRepeat = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr Options withShouldCancelPreviousAi(bool value)
|
|
|
|
{
|
|
|
|
mShouldCancelPreviousAi = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-16 19:52:16 +00:00
|
|
|
AiPackage(AiPackageTypeId typeId, const Options& options);
|
2014-05-13 07:58:32 +00:00
|
|
|
|
2020-05-16 17:05:52 +00:00
|
|
|
virtual ~AiPackage() = default;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2020-05-16 19:08:39 +00:00
|
|
|
static constexpr Options makeDefaultOptions()
|
|
|
|
{
|
|
|
|
return Options{};
|
|
|
|
}
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
///Clones the package
|
2020-06-01 13:36:14 +00:00
|
|
|
virtual std::unique_ptr<AiPackage> clone() const = 0;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Updates and runs the package (Should run every frame)
|
|
|
|
/// \return Package completed?
|
2015-06-26 15:47:04 +00:00
|
|
|
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) = 0;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Returns the TypeID of the AiPackage
|
|
|
|
/// \see enum TypeId
|
2020-05-16 19:52:16 +00:00
|
|
|
AiPackageTypeId getTypeId() const { return mTypeId; }
|
2013-11-18 11:33:09 +00:00
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
/// Higher number is higher priority (0 being the lowest)
|
2020-05-16 19:08:39 +00:00
|
|
|
unsigned int getPriority() const { return mOptions.mPriority; }
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2019-10-31 05:44:40 +00:00
|
|
|
/// Check if package use movement with variable speed
|
2020-05-16 19:08:39 +00:00
|
|
|
bool useVariableSpeed() const { return mOptions.mUseVariableSpeed; }
|
2019-10-31 05:44:40 +00:00
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
virtual void writeState (ESM::AiSequence::AiSequence& sequence) const {}
|
|
|
|
|
2014-12-31 17:41:57 +00:00
|
|
|
/// Simulates the passing of time
|
|
|
|
virtual void fastForward(const MWWorld::Ptr& actor, AiState& state) {}
|
|
|
|
|
2015-12-06 22:32:49 +00:00
|
|
|
/// Get the target actor the AI is targeted at (not applicable to all AI packages, default return empty Ptr)
|
2016-02-16 18:17:04 +00:00
|
|
|
virtual MWWorld::Ptr getTarget() const;
|
2015-12-06 22:32:49 +00:00
|
|
|
|
2017-12-01 14:53:31 +00:00
|
|
|
/// Get the destination point of the AI package (not applicable to all AI packages, default return (0, 0, 0))
|
|
|
|
virtual osg::Vec3f getDestination(const MWWorld::Ptr& actor) const { return osg::Vec3f(0, 0, 0); };
|
|
|
|
|
2015-12-06 22:32:49 +00:00
|
|
|
/// Return true if having this AiPackage makes the actor side with the target in fights (default false)
|
2020-05-16 19:08:39 +00:00
|
|
|
bool sideWithTarget() const { return mOptions.mSideWithTarget; }
|
2015-12-06 22:32:49 +00:00
|
|
|
|
2015-12-19 14:11:07 +00:00
|
|
|
/// Return true if the actor should follow the target through teleport doors (default false)
|
2020-05-16 19:08:39 +00:00
|
|
|
bool followTargetThroughDoors() const { return mOptions.mFollowTargetThroughDoors; }
|
2015-12-19 14:11:07 +00:00
|
|
|
|
2016-01-19 13:51:42 +00:00
|
|
|
/// Can this Ai package be canceled? (default true)
|
2020-05-16 19:08:39 +00:00
|
|
|
bool canCancel() const { return mOptions.mCanCancel; }
|
2016-01-19 13:51:42 +00:00
|
|
|
|
|
|
|
/// Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default true)?
|
2020-05-16 19:08:39 +00:00
|
|
|
bool shouldCancelPreviousAi() const { return mOptions.mShouldCancelPreviousAi; }
|
2016-01-19 13:51:42 +00:00
|
|
|
|
2016-06-05 16:14:17 +00:00
|
|
|
/// Return true if this package should repeat. Currently only used for Wander packages.
|
2020-05-16 19:08:39 +00:00
|
|
|
bool getRepeat() const { return mOptions.mRepeat; }
|
2016-05-28 16:02:22 +00:00
|
|
|
|
2020-02-11 09:33:22 +00:00
|
|
|
virtual osg::Vec3f getDestination() const { return osg::Vec3f(0, 0, 0); }
|
2019-10-31 05:44:40 +00:00
|
|
|
|
2020-05-16 19:08:39 +00:00
|
|
|
/// Return true if any loaded actor with this AI package must be active.
|
|
|
|
bool alwaysActive() const { return mOptions.mAlwaysActive; }
|
2020-01-09 11:11:53 +00:00
|
|
|
|
2016-08-19 19:15:26 +00:00
|
|
|
/// Reset pathfinding state
|
|
|
|
void reset();
|
|
|
|
|
2016-09-09 20:57:19 +00:00
|
|
|
/// Return if actor's rotation speed is sufficient to rotate to the destination pathpoint on the run. Otherwise actor should rotate while standing.
|
2018-07-21 09:30:14 +00:00
|
|
|
static bool isReachableRotatingOnTheRun(const MWWorld::Ptr& actor, const osg::Vec3f& dest);
|
2016-09-09 20:57:19 +00:00
|
|
|
|
2021-05-29 20:29:53 +00:00
|
|
|
osg::Vec3f getNextPathPoint(const osg::Vec3f& destination) const;
|
|
|
|
|
|
|
|
float getNextPathPointTolerance(float speed, float duration, const osg::Vec3f& halfExtents) const;
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
protected:
|
2016-08-19 19:15:26 +00:00
|
|
|
/// Handles path building and shortcutting with obstacles avoiding
|
2014-05-13 01:05:32 +00:00
|
|
|
/** \return If the actor has arrived at his destination **/
|
2018-07-21 09:30:14 +00:00
|
|
|
bool pathTo(const MWWorld::Ptr& actor, const osg::Vec3f& dest, float duration, float destTolerance = 0.0f);
|
2016-08-19 19:15:26 +00:00
|
|
|
|
|
|
|
/// Check if there aren't any obstacles along the path to make shortcut possible
|
|
|
|
/// If a shortcut is possible then path will be cleared and filled with the destination point.
|
2018-10-09 06:21:12 +00:00
|
|
|
/// \param destInLOS If not nullptr function will return ray cast check result
|
2016-08-19 19:15:26 +00:00
|
|
|
/// \return If can shortcut the path
|
2018-07-21 09:30:14 +00:00
|
|
|
bool shortcutPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::Ptr& actor,
|
|
|
|
bool *destInLOS, bool isPathClear);
|
2016-08-19 19:15:26 +00:00
|
|
|
|
|
|
|
/// Check if the way to the destination is clear, taking into account actor speed
|
2018-07-21 09:30:14 +00:00
|
|
|
bool checkWayIsClearForActor(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::Ptr& actor);
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2019-10-07 18:19:12 +00:00
|
|
|
bool doesPathNeedRecalc(const osg::Vec3f& newDest, const MWWorld::Ptr& actor) const;
|
2015-06-11 06:28:31 +00:00
|
|
|
|
2018-08-18 15:41:48 +00:00
|
|
|
void evadeObstacles(const MWWorld::Ptr& actor);
|
2018-08-18 15:26:00 +00:00
|
|
|
|
2017-12-01 06:07:02 +00:00
|
|
|
void openDoors(const MWWorld::Ptr& actor);
|
2015-09-14 07:57:22 +00:00
|
|
|
|
2017-11-27 17:30:31 +00:00
|
|
|
const PathgridGraph& getPathGridGraph(const MWWorld::CellStore* cell);
|
|
|
|
|
2018-07-21 11:16:19 +00:00
|
|
|
DetourNavigator::Flags getNavigatorFlags(const MWWorld::Ptr& actor) const;
|
|
|
|
|
2020-06-12 23:56:04 +00:00
|
|
|
DetourNavigator::AreaCosts getAreaCosts(const MWWorld::Ptr& actor) const;
|
|
|
|
|
2020-05-16 19:52:16 +00:00
|
|
|
const AiPackageTypeId mTypeId;
|
2020-05-16 19:08:39 +00:00
|
|
|
const Options mOptions;
|
|
|
|
|
2014-12-01 12:34:42 +00:00
|
|
|
// TODO: all this does not belong here, move into temporary storage
|
2014-05-13 01:05:32 +00:00
|
|
|
PathFinder mPathFinder;
|
2014-05-13 07:58:32 +00:00
|
|
|
ObstacleCheck mObstacleCheck;
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2021-03-19 22:23:26 +00:00
|
|
|
AiReactionTimer mReaction;
|
2014-06-12 21:27:04 +00:00
|
|
|
|
2017-11-21 16:00:51 +00:00
|
|
|
std::string mTargetActorRefId;
|
|
|
|
mutable int mTargetActorId;
|
|
|
|
|
2016-09-09 20:57:19 +00:00
|
|
|
short mRotateOnTheRunChecks; // attempts to check rotation to the pathpoint on the run possibility
|
|
|
|
|
2016-08-19 19:15:26 +00:00
|
|
|
bool mIsShortcutting; // if shortcutting at the moment
|
|
|
|
bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt
|
2018-07-21 09:30:14 +00:00
|
|
|
osg::Vec3f mShortcutFailPos; // position of last shortcut fail
|
2021-05-29 20:29:53 +00:00
|
|
|
float mLastDestinationTolerance = 0;
|
2015-08-29 20:32:47 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-03 21:10:58 +00:00
|
|
|
bool isNearInactiveCell(osg::Vec3f position);
|
2012-09-04 11:25:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|