2014-05-13 03:58:32 -04:00
|
|
|
#ifndef GAME_MWMECHANICS_AIFOLLOW_H
|
|
|
|
#define GAME_MWMECHANICS_AIFOLLOW_H
|
2012-11-15 22:32:15 +01:00
|
|
|
|
2022-07-16 13:00:03 +02:00
|
|
|
#include "aitemporarybase.hpp"
|
2020-05-17 22:10:36 +02:00
|
|
|
#include "typedaipackage.hpp"
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2012-11-15 22:32:15 +01:00
|
|
|
#include <string>
|
2022-01-27 23:53:09 +01:00
|
|
|
#include <string_view>
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2014-05-13 13:43:50 -04:00
|
|
|
#include <components/esm/defs.hpp>
|
2012-11-15 22:32:15 +01:00
|
|
|
|
2019-10-31 09:44:40 +04:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2022-01-22 22:44:02 +01:00
|
|
|
namespace ESM::AiSequence
|
2014-06-12 23:27:04 +02:00
|
|
|
{
|
|
|
|
struct AiFollow;
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:32:15 +01:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2018-06-27 12:48:34 +04: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-29 23:40:59 -04: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 23:27:04 +02:00
|
|
|
**/
|
2020-05-17 22:10:36 +02:00
|
|
|
class AiFollow final : public TypedAiPackage<AiFollow>
|
2014-06-12 23:27:04 +02:00
|
|
|
{
|
2012-11-16 18:38:15 +01:00
|
|
|
public:
|
2014-04-29 23:40:59 -04:00
|
|
|
/// Follow Actor for duration or until you arrive at a world position
|
2022-01-27 23:53:09 +01:00
|
|
|
AiFollow(std::string_view actorId, float duration, float x, float y, float z, bool repeat);
|
2014-04-29 23:40:59 -04:00
|
|
|
/// Follow Actor for duration or until you arrive at a position in a cell
|
2022-01-27 23:53:09 +01:00
|
|
|
AiFollow(
|
|
|
|
std::string_view actorId, std::string_view cellId, float duration, float x, float y, float z, bool repeat);
|
2014-04-29 23:40:59 -04:00
|
|
|
/// Follow Actor indefinitively
|
2017-11-21 20:00:51 +04:00
|
|
|
AiFollow(const MWWorld::Ptr& actor, bool commanded = false);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-06-12 23:27:04 +02:00
|
|
|
AiFollow(const ESM::AiSequence::AiFollow* follow);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-10-22 23:57:53 +02:00
|
|
|
bool execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state,
|
|
|
|
float duration) override;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-05-16 21:52:16 +02:00
|
|
|
static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Follow; }
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-05-16 21:08:39 +02:00
|
|
|
static constexpr Options makeDefaultOptions()
|
|
|
|
{
|
|
|
|
AiPackage::Options options;
|
|
|
|
options.mUseVariableSpeed = true;
|
|
|
|
options.mSideWithTarget = true;
|
|
|
|
options.mFollowTargetThroughDoors = true;
|
|
|
|
return options;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-29 23:40:59 -04:00
|
|
|
/// Returns the actor being followed
|
2014-01-12 14:02:40 +01:00
|
|
|
std::string getFollowedActor();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-10-22 23:57:53 +02:00
|
|
|
void writeState(ESM::AiSequence::AiSequence& sequence) const override;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-08-06 21:16:14 +02:00
|
|
|
bool isCommanded() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-12-09 16:02:07 +01:00
|
|
|
int getFollowIndex() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-10-22 23:57:53 +02:00
|
|
|
void fastForward(const MWWorld::Ptr& actor, AiState& state) override;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2020-10-22 23:57:53 +02:00
|
|
|
osg::Vec3f getDestination() const override
|
2019-10-31 09:44:40 +04:00
|
|
|
{
|
|
|
|
MWWorld::Ptr target = getTarget();
|
|
|
|
if (target.isEmpty())
|
|
|
|
return osg::Vec3f(0, 0, 0);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2019-10-31 09:44:40 +04:00
|
|
|
return target.getRefData().getPosition().asVec3();
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2012-11-16 18:38:15 +01:00
|
|
|
private:
|
2014-04-29 23:40:59 -04:00
|
|
|
/// This will make the actor always follow.
|
|
|
|
/** Thus ignoring mDuration and mX,mY,mZ (used for summoned creatures). **/
|
2020-06-02 21:30:46 +02:00
|
|
|
const bool mAlwaysFollow;
|
|
|
|
const float mDuration; // Hours
|
2016-06-11 22:34:49 +09:00
|
|
|
float mRemainingDuration; // Hours
|
2020-06-02 21:30:46 +02:00
|
|
|
const float mX;
|
|
|
|
const float mY;
|
|
|
|
const float mZ;
|
|
|
|
const std::string mCellId;
|
2014-12-09 22:25:28 +01:00
|
|
|
bool mActive; // have we spotted the target?
|
2020-06-02 21:30:46 +02:00
|
|
|
const int mFollowIndex;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-12-09 16:02:07 +01:00
|
|
|
static int mFollowIndexCounter;
|
2014-06-12 23:27:04 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|