2014-05-13 07:58:32 +00:00
# ifndef GAME_MWMECHANICS_AIFOLLOW_H
# define GAME_MWMECHANICS_AIFOLLOW_H
2012-11-15 21:32:15 +00:00
# include "aipackage.hpp"
2016-06-17 14:07:16 +00:00
2012-11-15 21:32:15 +00:00
# include <string>
2016-06-17 14:07:16 +00:00
2014-05-13 17:43:50 +00:00
# include <components/esm/defs.hpp>
2012-11-15 21:32:15 +00:00
2019-10-31 05:44:40 +00:00
# include "../mwworld/ptr.hpp"
2016-06-17 14:07:16 +00:00
# include "pathfinding.hpp"
2014-06-12 21:27:04 +00:00
namespace ESM
{
namespace AiSequence
{
struct AiFollow ;
}
}
2012-11-15 21:32:15 +00:00
namespace MWMechanics
{
2018-06-27 08:48:34 +00:00
struct AiFollowStorage : AiTemporaryBase
{
float mTimer ;
bool mMoving ;
float mTargetAngleRadians ;
bool mTurnActorToTarget ;
AiFollowStorage ( ) :
mTimer ( 0.f ) ,
mMoving ( false ) ,
mTargetAngleRadians ( 0.f ) ,
mTurnActorToTarget ( false )
{ }
} ;
2014-04-30 03:40:59 +00:00
/// \brief AiPackage for an actor to follow another actor/the PC
/** The AI will follow the target until a condition (time, or position) are set. Both can be disabled to cause the actor to follow the other indefinitely
2014-06-12 21:27:04 +00:00
* */
class AiFollow : public AiPackage
{
2012-11-16 17:38:15 +00:00
public :
2017-11-21 16:00:51 +00:00
AiFollow ( const std : : string & actorId , float duration , float x , float y , float z ) ;
AiFollow ( const std : : string & actorId , const std : : string & CellId , float duration , float x , float y , float z ) ;
2014-04-30 03:40:59 +00:00
/// Follow Actor for duration or until you arrive at a world position
2017-11-21 16:00:51 +00:00
AiFollow ( const MWWorld : : Ptr & actor , float duration , float X , float Y , float Z ) ;
2014-04-30 03:40:59 +00:00
/// Follow Actor for duration or until you arrive at a position in a cell
2017-11-21 16:00:51 +00:00
AiFollow ( const MWWorld : : Ptr & actor , const std : : string & CellId , float duration , float X , float Y , float Z ) ;
2014-04-30 03:40:59 +00:00
/// Follow Actor indefinitively
2017-11-21 16:00:51 +00:00
AiFollow ( const MWWorld : : Ptr & actor , bool commanded = false ) ;
2014-04-30 03:40:59 +00:00
2014-06-12 21:27:04 +00:00
AiFollow ( const ESM : : AiSequence : : AiFollow * follow ) ;
2015-12-06 22:32:49 +00:00
virtual bool sideWithTarget ( ) const { return true ; }
2015-12-19 14:11:07 +00:00
virtual bool followTargetThroughDoors ( ) const { return true ; }
2017-01-11 15:07:22 +00:00
virtual bool shouldCancelPreviousAi ( ) const { return ! mCommanded ; }
2014-07-27 18:30:52 +00:00
2012-11-16 17:38:15 +00:00
virtual AiFollow * clone ( ) const ;
2014-04-30 03:40:59 +00:00
2015-06-26 15:47:04 +00:00
virtual bool execute ( const MWWorld : : Ptr & actor , CharacterController & characterController , AiState & state , float duration ) ;
2014-04-30 03:40:59 +00:00
2012-11-16 17:38:15 +00:00
virtual int getTypeId ( ) const ;
2012-11-15 21:32:15 +00:00
2019-10-31 05:44:40 +00:00
virtual bool useVariableSpeed ( ) const { return true ; }
2014-04-30 03:40:59 +00:00
/// Returns the actor being followed
2014-01-12 13:02:40 +00:00
std : : string getFollowedActor ( ) ;
2014-06-12 21:27:04 +00:00
virtual void writeState ( ESM : : AiSequence : : AiSequence & sequence ) const ;
2014-08-06 19:16:14 +00:00
bool isCommanded ( ) const ;
2014-12-09 15:02:07 +00:00
int getFollowIndex ( ) const ;
2016-06-11 13:34:49 +00:00
void fastForward ( const MWWorld : : Ptr & actor , AiState & state ) ;
2020-02-11 09:33:22 +00:00
virtual osg : : Vec3f getDestination ( ) const
2019-10-31 05:44:40 +00:00
{
MWWorld : : Ptr target = getTarget ( ) ;
if ( target . isEmpty ( ) )
return osg : : Vec3f ( 0 , 0 , 0 ) ;
return target . getRefData ( ) . getPosition ( ) . asVec3 ( ) ;
}
2012-11-16 17:38:15 +00:00
private :
2014-04-30 03:40:59 +00:00
/// This will make the actor always follow.
/** Thus ignoring mDuration and mX,mY,mZ (used for summoned creatures). **/
bool mAlwaysFollow ;
2014-08-06 19:16:14 +00:00
bool mCommanded ;
2016-06-11 13:34:49 +00:00
float mDuration ; // Hours
float mRemainingDuration ; // Hours
2012-11-16 17:38:15 +00:00
float mX ;
float mY ;
float mZ ;
2014-06-12 21:27:04 +00:00
std : : string mCellId ;
2014-12-09 21:25:28 +00:00
bool mActive ; // have we spotted the target?
2014-12-09 15:02:07 +00:00
int mFollowIndex ;
static int mFollowIndexCounter ;
2014-06-12 21:27:04 +00:00
} ;
}
# endif