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
{
2014-10-08 08:58:52 +00:00
2015-06-26 15:47:04 +00:00
class CharacterController ;
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?
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
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 ) { }
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)
virtual MWWorld : : Ptr getTarget ( ) ;
/// Return true if having this AiPackage makes the actor side with the target in fights (default false)
virtual bool sideWithTarget ( ) const ;
2015-08-09 02:20:55 +00:00
bool isTargetMagicallyHidden ( const MWWorld : : Ptr & target ) ;
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 **/
bool pathTo ( const MWWorld : : Ptr & actor , ESM : : Pathgrid : : Point dest , float duration ) ;
2015-06-11 06:28:31 +00:00
virtual bool doesPathNeedRecalc ( ESM : : Pathgrid : : Point dest , const ESM : : Cell * cell ) ;
2015-09-14 07:57:22 +00:00
void evadeObstacles ( const MWWorld : : Ptr & actor , float duration , const ESM : : Position & pos ) ;
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 ;
2014-05-14 05:44:11 +00:00
ESM : : Pathgrid : : Point mPrevDest ;
2015-08-29 20:32:47 +00:00
2015-12-06 23:25:03 +00:00
bool isWithinMaxRange ( const osg : : Vec3f & pos1 , const osg : : Vec3f & pos2 ) const
{
// Maximum travel distance for vanilla compatibility.
// Was likely meant to prevent NPCs walking into non-loaded exterior cells, but for some reason is used in interior cells as well.
// We can make this configurable at some point, but the default *must* be the below value. Anything else will break shoddily-written content (*cough* MW *cough*) in bizarre ways.
return ( pos1 - pos2 ) . length2 ( ) < = 7168 * 7168 ;
}
2015-08-29 20:32:47 +00:00
private :
2015-09-12 02:17:46 +00:00
bool isNearInactiveCell ( const ESM : : Position & actorPos ) ;
2015-08-29 20:32:47 +00:00
2012-09-04 11:25:53 +00:00
} ;
2015-12-06 23:25:03 +00:00
2012-09-04 11:25:53 +00:00
}
# endif