2012-09-04 11:25:53 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_AIPACKAGE_H
|
|
|
|
#define GAME_MWMECHANICS_AIPACKAGE_H
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
#include "pathfinding.hpp"
|
2014-05-13 17:43:50 +00:00
|
|
|
#include <components/esm/defs.hpp>
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2014-05-13 07:58:32 +00:00
|
|
|
#include "obstacle.hpp"
|
2014-10-08 08:58:52 +00:00
|
|
|
#include "aistate.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-07-04 15:00:16 +00:00
|
|
|
const float AI_REACTION_TIME = 0.25f;
|
2014-10-08 08:58:52 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
/// \brief Base class for AI packages
|
|
|
|
class AiPackage
|
|
|
|
{
|
|
|
|
public:
|
2014-04-30 03:40:59 +00:00
|
|
|
///Enumerates the various AITypes availible.
|
2014-01-07 00:12:37 +00:00
|
|
|
enum TypeId {
|
|
|
|
TypeIdNone = -1,
|
|
|
|
TypeIdWander = 0,
|
|
|
|
TypeIdTravel = 1,
|
|
|
|
TypeIdEscort = 2,
|
|
|
|
TypeIdFollow = 3,
|
|
|
|
TypeIdActivate = 4,
|
2014-04-02 04:18:22 +00:00
|
|
|
TypeIdCombat = 5,
|
2014-05-13 07:58:32 +00:00
|
|
|
TypeIdPursue = 6,
|
|
|
|
TypeIdAvoidDoor = 7
|
2014-01-07 00:12:37 +00:00
|
|
|
};
|
|
|
|
|
2014-05-13 07:58:32 +00:00
|
|
|
///Default constructor
|
|
|
|
AiPackage();
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
///Default Deconstructor
|
2012-09-04 11:25:53 +00:00
|
|
|
virtual ~AiPackage();
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
///Clones the package
|
2012-09-04 11:25:53 +00:00
|
|
|
virtual AiPackage *clone() const = 0;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Updates and runs the package (Should run every frame)
|
|
|
|
/// \return Package completed?
|
2014-10-08 08:58:52 +00:00
|
|
|
virtual bool execute (const MWWorld::Ptr& actor, AiState& state, float duration) = 0;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Returns the TypeID of the AiPackage
|
|
|
|
/// \see enum TypeId
|
2012-09-04 11:25:53 +00:00
|
|
|
virtual int getTypeId() const = 0;
|
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)
|
2013-11-18 11:33:09 +00:00
|
|
|
virtual unsigned int getPriority() const {return 0;}
|
2014-05-13 01:05:32 +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) {}
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
protected:
|
|
|
|
/// Causes the actor to attempt to walk to the specified location
|
|
|
|
/** \return If the actor has arrived at his destination **/
|
2015-07-04 15:00:16 +00:00
|
|
|
bool pathTo(const MWWorld::Ptr& actor, const ESM::Pathgrid::Point& dest, float duration, float destTolerance = 0.0f);
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
/// \param destInLOS If not NULL function will return ray cast check result
|
|
|
|
/// \return If can shortcut the path
|
|
|
|
bool shortcutPath(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor, bool *destInLOS);
|
|
|
|
|
|
|
|
/// Check if the way to the destination is clear, taking into account actor speed
|
|
|
|
bool checkWayIsClearForActor(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor);
|
2014-05-13 01:05:32 +00:00
|
|
|
|
2015-06-11 06:28:31 +00:00
|
|
|
virtual bool doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell);
|
|
|
|
|
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
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
float mTimer;
|
|
|
|
float mStuckTimer;
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
ESM::Position mStuckPos;
|
2014-05-14 05:44:11 +00:00
|
|
|
ESM::Pathgrid::Point mPrevDest;
|
2015-07-04 15:00:16 +00:00
|
|
|
|
|
|
|
bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt
|
|
|
|
ESM::Pathgrid::Point mShortcutFailPos; // position of last shortcut fail
|
2012-09-04 11:25:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|