2013-09-25 16:01:36 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_AICOMBAT_H
|
|
|
|
#define GAME_MWMECHANICS_AICOMBAT_H
|
|
|
|
|
2020-05-17 20:10:36 +00:00
|
|
|
#include "typedaipackage.hpp"
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2014-04-18 22:16:56 +00:00
|
|
|
#include "../mwworld/cellstore.hpp" // for Doors
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2014-01-15 20:56:55 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2016-06-17 14:07:16 +00:00
|
|
|
#include "pathfinding.hpp"
|
|
|
|
#include "movement.hpp"
|
2021-03-19 22:23:26 +00:00
|
|
|
#include "aitimer.hpp"
|
2014-08-27 22:41:52 +00:00
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
namespace AiSequence
|
|
|
|
{
|
|
|
|
struct AiCombat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:01:36 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2014-08-27 22:41:52 +00:00
|
|
|
class Action;
|
|
|
|
|
2018-06-27 08:48:34 +00:00
|
|
|
/// \brief This class holds the variables AiCombat needs which are deleted if the package becomes inactive.
|
|
|
|
struct AiCombatStorage : AiTemporaryBase
|
|
|
|
{
|
|
|
|
float mAttackCooldown;
|
2021-03-19 22:23:26 +00:00
|
|
|
AiReactionTimer mReaction;
|
2018-06-27 08:48:34 +00:00
|
|
|
float mTimerCombatMove;
|
|
|
|
bool mReadyToAttack;
|
|
|
|
bool mAttack;
|
|
|
|
float mAttackRange;
|
|
|
|
bool mCombatMove;
|
|
|
|
osg::Vec3f mLastTargetPos;
|
|
|
|
const MWWorld::CellStore* mCell;
|
|
|
|
std::shared_ptr<Action> mCurrentAction;
|
|
|
|
float mActionCooldown;
|
|
|
|
float mStrength;
|
|
|
|
bool mForceNoShortcut;
|
|
|
|
ESM::Position mShortcutFailPos;
|
|
|
|
MWMechanics::Movement mMovement;
|
|
|
|
|
|
|
|
enum FleeState
|
|
|
|
{
|
|
|
|
FleeState_None,
|
|
|
|
FleeState_Idle,
|
|
|
|
FleeState_RunBlindly,
|
|
|
|
FleeState_RunToDestination
|
|
|
|
};
|
|
|
|
FleeState mFleeState;
|
|
|
|
bool mLOS;
|
|
|
|
float mUpdateLOSTimer;
|
|
|
|
float mFleeBlindRunTimer;
|
|
|
|
ESM::Pathgrid::Point mFleeDest;
|
|
|
|
|
2021-02-14 03:07:08 +00:00
|
|
|
bool mUseCustomDestination;
|
|
|
|
osg::Vec3f mCustomDestination;
|
|
|
|
|
2018-06-27 08:48:34 +00:00
|
|
|
AiCombatStorage():
|
|
|
|
mAttackCooldown(0.0f),
|
|
|
|
mTimerCombatMove(0.0f),
|
|
|
|
mReadyToAttack(false),
|
|
|
|
mAttack(false),
|
|
|
|
mAttackRange(0.0f),
|
|
|
|
mCombatMove(false),
|
|
|
|
mLastTargetPos(0,0,0),
|
2018-10-09 06:21:12 +00:00
|
|
|
mCell(nullptr),
|
2018-06-27 08:48:34 +00:00
|
|
|
mCurrentAction(),
|
|
|
|
mActionCooldown(0.0f),
|
|
|
|
mStrength(),
|
|
|
|
mForceNoShortcut(false),
|
|
|
|
mShortcutFailPos(),
|
|
|
|
mMovement(),
|
|
|
|
mFleeState(FleeState_None),
|
|
|
|
mLOS(false),
|
|
|
|
mUpdateLOSTimer(0.0f),
|
2021-02-14 03:07:08 +00:00
|
|
|
mFleeBlindRunTimer(0.0f),
|
|
|
|
mUseCustomDestination(false),
|
|
|
|
mCustomDestination()
|
2018-06-27 08:48:34 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void startCombatMove(bool isDistantCombat, float distToTarget, float rangeAttack, const MWWorld::Ptr& actor, const MWWorld::Ptr& target);
|
|
|
|
void updateCombatMove(float duration);
|
|
|
|
void stopCombatMove();
|
|
|
|
void startAttackIfReady(const MWWorld::Ptr& actor, CharacterController& characterController,
|
|
|
|
const ESM::Weapon* weapon, bool distantCombat);
|
|
|
|
void updateAttack(CharacterController& characterController);
|
|
|
|
void stopAttack();
|
|
|
|
|
|
|
|
void startFleeing();
|
|
|
|
void stopFleeing();
|
|
|
|
bool isFleeing();
|
|
|
|
};
|
2015-07-26 05:32:29 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// \brief Causes the actor to fight another actor
|
2020-05-17 20:10:36 +00:00
|
|
|
class AiCombat final : public TypedAiPackage<AiCombat>
|
2013-09-25 16:01:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-04-30 03:40:59 +00:00
|
|
|
///Constructor
|
|
|
|
/** \param actor Actor to fight **/
|
2020-10-22 21:57:53 +00:00
|
|
|
explicit AiCombat(const MWWorld::Ptr& actor);
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2020-10-22 21:57:53 +00:00
|
|
|
explicit AiCombat (const ESM::AiSequence::AiCombat* combat);
|
2014-06-12 21:27:04 +00:00
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2020-10-22 21:57:53 +00:00
|
|
|
bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) override;
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2020-05-16 19:52:16 +00:00
|
|
|
static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Combat; }
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2020-05-16 19:08:39 +00:00
|
|
|
static constexpr Options makeDefaultOptions()
|
|
|
|
{
|
|
|
|
AiPackage::Options options;
|
|
|
|
options.mPriority = 1;
|
|
|
|
options.mCanCancel = false;
|
|
|
|
options.mShouldCancelPreviousAi = false;
|
|
|
|
return options;
|
|
|
|
}
|
2013-11-18 11:33:09 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
///Returns target ID
|
2020-10-22 21:57:53 +00:00
|
|
|
MWWorld::Ptr getTarget() const override;
|
2014-01-07 00:12:37 +00:00
|
|
|
|
2020-10-22 21:57:53 +00:00
|
|
|
void writeState(ESM::AiSequence::AiSequence &sequence) const override;
|
2014-06-12 21:27:04 +00:00
|
|
|
|
2013-09-25 16:01:36 +00:00
|
|
|
private:
|
2016-12-25 15:18:52 +00:00
|
|
|
/// Returns true if combat should end
|
|
|
|
bool attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController);
|
2015-07-26 05:23:45 +00:00
|
|
|
|
2016-12-06 13:23:06 +00:00
|
|
|
void updateLOS(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, AiCombatStorage& storage);
|
|
|
|
|
2016-11-16 19:15:25 +00:00
|
|
|
void updateFleeing(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, AiCombatStorage& storage);
|
|
|
|
|
2015-07-26 05:23:45 +00:00
|
|
|
/// Transfer desired movement (from AiCombatStorage) to Actor
|
2016-08-19 19:15:26 +00:00
|
|
|
void updateActorsMovement(const MWWorld::Ptr& actor, float duration, AiCombatStorage& storage);
|
2015-08-09 02:18:55 +00:00
|
|
|
void rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
|
2018-08-15 15:05:57 +00:00
|
|
|
MWMechanics::Movement& actorMovementSettings, AiCombatStorage& storage);
|
2013-09-25 16:01:36 +00:00
|
|
|
};
|
2014-10-08 21:00:36 +00:00
|
|
|
|
2014-10-09 21:11:10 +00:00
|
|
|
|
2013-09-25 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 00:12:37 +00:00
|
|
|
#endif
|