1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:19:55 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/aicombat.hpp

139 lines
4.2 KiB
C++
Raw Normal View History

2013-09-25 16:01:36 +00:00
#ifndef GAME_MWMECHANICS_AICOMBAT_H
#define GAME_MWMECHANICS_AICOMBAT_H
#include "aipackage.hpp"
#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"
#include "obstacle.hpp"
2014-06-12 21:27:04 +00:00
namespace ESM
{
namespace AiSequence
{
struct AiCombat;
}
}
2013-09-25 16:01:36 +00:00
namespace MWMechanics
{
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;
float mTimerReact;
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;
AiCombatStorage():
mAttackCooldown(0.0f),
mTimerReact(AI_REACTION_TIME),
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),
mFleeBlindRunTimer(0.0f)
{}
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();
};
/// \brief Causes the actor to fight another actor
2013-09-25 16:01:36 +00:00
class AiCombat : public AiPackage
{
public:
///Constructor
/** \param actor Actor to fight **/
2014-01-15 20:56:55 +00:00
AiCombat(const MWWorld::Ptr& actor);
2013-09-25 16:01:36 +00:00
2014-06-12 21:27:04 +00:00
AiCombat (const ESM::AiSequence::AiCombat* combat);
void init();
2013-09-25 16:01:36 +00:00
virtual AiCombat *clone() const;
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration);
2013-09-25 16:01:36 +00:00
virtual int getTypeId() const;
virtual unsigned int getPriority() const;
///Returns target ID
2014-05-17 15:20:57 +00:00
MWWorld::Ptr getTarget() const;
2014-06-12 21:27:04 +00:00
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
virtual bool canCancel() const { return false; }
virtual bool shouldCancelPreviousAi() const { return false; }
2013-09-25 16:01:36 +00:00
private:
/// Returns true if combat should end
bool attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController);
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);
/// Transfer desired movement (from AiCombatStorage) to Actor
void updateActorsMovement(const MWWorld::Ptr& actor, float duration, AiCombatStorage& storage);
void rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
MWMechanics::Movement& actorMovementSettings, AiCombatStorage& storage);
2013-09-25 16:01:36 +00:00
};
2013-09-25 16:01:36 +00:00
}
#endif