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
2020-05-17 20:10:36 +00:00
# include "typedaipackage.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"
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
* */
2020-05-17 20:10:36 +00:00
class AiFollow final : public TypedAiPackage < AiFollow >
2014-06-12 21:27:04 +00:00
{
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 ) ;
2020-10-22 21:57:53 +00:00
bool execute ( const MWWorld : : Ptr & actor , CharacterController & characterController , AiState & state , float duration ) override ;
2014-04-30 03:40:59 +00:00
2020-05-16 19:52:16 +00:00
static constexpr AiPackageTypeId getTypeId ( ) { return AiPackageTypeId : : Follow ; }
2012-11-15 21:32:15 +00:00
2020-05-16 19:08:39 +00:00
static constexpr Options makeDefaultOptions ( )
{
AiPackage : : Options options ;
options . mUseVariableSpeed = true ;
options . mSideWithTarget = true ;
options . mFollowTargetThroughDoors = true ;
return options ;
}
2019-10-31 05:44:40 +00:00
2014-04-30 03:40:59 +00:00
/// Returns the actor being followed
2014-01-12 13:02:40 +00:00
std : : string getFollowedActor ( ) ;
2020-10-22 21:57:53 +00:00
void writeState ( ESM : : AiSequence : : AiSequence & sequence ) const override ;
2014-06-12 21:27:04 +00:00
2014-08-06 19:16:14 +00:00
bool isCommanded ( ) const ;
2014-12-09 15:02:07 +00:00
int getFollowIndex ( ) const ;
2020-10-22 21:57:53 +00:00
void fastForward ( const MWWorld : : Ptr & actor , AiState & state ) override ;
2016-06-11 13:34:49 +00:00
2020-10-22 21:57:53 +00:00
osg : : Vec3f getDestination ( ) const override
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). **/
2020-06-02 19:30:46 +00:00
const bool mAlwaysFollow ;
const float mDuration ; // Hours
2016-06-11 13:34:49 +00:00
float mRemainingDuration ; // Hours
2020-06-02 19:30:46 +00:00
const float mX ;
const float mY ;
const float mZ ;
const std : : string mCellId ;
2014-12-09 21:25:28 +00:00
bool mActive ; // have we spotted the target?
2020-06-02 19:30:46 +00:00
const int mFollowIndex ;
2014-12-09 15:02:07 +00:00
static int mFollowIndexCounter ;
2014-06-12 21:27:04 +00:00
} ;
}
# endif