2012-09-04 13:25:53 +02:00
# ifndef GAME_MWMECHANICS_AIPACKAGE_H
# define GAME_MWMECHANICS_AIPACKAGE_H
2014-05-12 21:05:32 -04:00
# include "pathfinding.hpp"
2014-05-13 13:43:50 -04:00
# include <components/esm/defs.hpp>
2014-05-12 21:05:32 -04:00
2014-05-13 03:58:32 -04:00
# include "obstacle.hpp"
2014-10-08 10:58:52 +02:00
# include "aistate.hpp"
2014-05-13 03:58:32 -04:00
2012-09-04 13:25:53 +02:00
namespace MWWorld
{
class Ptr ;
}
2014-06-12 23:27:04 +02:00
namespace ESM
{
2015-06-14 10:30:55 +12:00
struct Cell ;
2014-06-12 23:27:04 +02:00
namespace AiSequence
{
2015-03-06 21:36:42 +13:00
struct AiSequence ;
2014-06-12 23:27:04 +02:00
}
}
2014-10-08 10:58:52 +02:00
2012-09-04 13:25:53 +02:00
namespace MWMechanics
{
2014-10-08 10:58:52 +02:00
2015-06-26 17:47:04 +02:00
class CharacterController ;
2012-09-04 13:25:53 +02:00
/// \brief Base class for AI packages
class AiPackage
{
public :
2014-04-29 23:40:59 -04:00
///Enumerates the various AITypes availible.
2014-01-07 04:12:37 +04:00
enum TypeId {
TypeIdNone = - 1 ,
TypeIdWander = 0 ,
TypeIdTravel = 1 ,
TypeIdEscort = 2 ,
TypeIdFollow = 3 ,
TypeIdActivate = 4 ,
2014-04-02 00:18:22 -04:00
TypeIdCombat = 5 ,
2014-05-13 03:58:32 -04:00
TypeIdPursue = 6 ,
TypeIdAvoidDoor = 7
2014-01-07 04:12:37 +04:00
} ;
2014-05-13 03:58:32 -04:00
///Default constructor
AiPackage ( ) ;
2014-04-29 23:40:59 -04:00
///Default Deconstructor
2012-09-04 13:25:53 +02:00
virtual ~ AiPackage ( ) ;
2014-04-29 23:40:59 -04:00
///Clones the package
2012-09-04 13:25:53 +02:00
virtual AiPackage * clone ( ) const = 0 ;
2014-04-29 23:40:59 -04:00
/// Updates and runs the package (Should run every frame)
/// \return Package completed?
2015-06-26 17:47:04 +02:00
virtual bool execute ( const MWWorld : : Ptr & actor , CharacterController & characterController , AiState & state , float duration ) = 0 ;
2014-04-29 23:40:59 -04:00
/// Returns the TypeID of the AiPackage
/// \see enum TypeId
2012-09-04 13:25:53 +02:00
virtual int getTypeId ( ) const = 0 ;
2013-11-18 12:33:09 +01:00
2014-05-12 21:05:32 -04:00
/// Higher number is higher priority (0 being the lowest)
2013-11-18 12:33:09 +01:00
virtual unsigned int getPriority ( ) const { return 0 ; }
2014-05-12 21:05:32 -04:00
2014-06-12 23:27:04 +02:00
virtual void writeState ( ESM : : AiSequence : : AiSequence & sequence ) const { }
2014-12-31 18:41:57 +01:00
/// Simulates the passing of time
virtual void fastForward ( const MWWorld : : Ptr & actor , AiState & state ) { }
2015-12-06 23:32:49 +01: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 14:20:55 +12:00
bool isTargetMagicallyHidden ( const MWWorld : : Ptr & target ) ;
2014-05-12 21:05:32 -04: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 18:28:31 +12:00
virtual bool doesPathNeedRecalc ( ESM : : Pathgrid : : Point dest , const ESM : : Cell * cell ) ;
2015-09-14 19:57:22 +12:00
void evadeObstacles ( const MWWorld : : Ptr & actor , float duration , const ESM : : Position & pos ) ;
2014-12-01 13:34:42 +01:00
// TODO: all this does not belong here, move into temporary storage
2014-05-12 21:05:32 -04:00
PathFinder mPathFinder ;
2014-05-13 03:58:32 -04:00
ObstacleCheck mObstacleCheck ;
2014-05-12 21:05:32 -04:00
2014-06-12 23:27:04 +02:00
float mTimer ;
2014-05-14 01:44:11 -04:00
ESM : : Pathgrid : : Point mPrevDest ;
2015-08-30 08:32:47 +12:00
2015-12-07 00:25:03 +01: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-30 08:32:47 +12:00
private :
2015-09-12 14:17:46 +12:00
bool isNearInactiveCell ( const ESM : : Position & actorPos ) ;
2015-08-30 08:32:47 +12:00
2012-09-04 13:25:53 +02:00
} ;
2015-12-07 00:25:03 +01:00
2012-09-04 13:25:53 +02:00
}
# endif