2014-08-27 22:41:52 +00:00
|
|
|
#ifndef OPENMW_AICOMBAT_ACTION_H
|
|
|
|
#define OPENMW_AICOMBAT_ACTION_H
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
#include <memory>
|
2014-08-27 22:41:52 +00:00
|
|
|
|
2016-06-17 14:07:16 +00:00
|
|
|
#include <components/esm/loadspel.hpp>
|
|
|
|
|
2014-08-27 22:41:52 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
class Action
|
|
|
|
{
|
|
|
|
public:
|
2014-08-29 00:47:44 +00:00
|
|
|
virtual ~Action() {}
|
2014-08-27 22:41:52 +00:00
|
|
|
virtual void prepare(const MWWorld::Ptr& actor) = 0;
|
2016-08-19 19:15:26 +00:00
|
|
|
virtual float getCombatRange (bool& isRanged) const = 0;
|
2014-08-27 22:41:52 +00:00
|
|
|
virtual float getActionCooldown() { return 0.f; }
|
2020-10-16 18:18:54 +00:00
|
|
|
virtual const ESM::Weapon* getWeapon() const { return nullptr; }
|
2016-09-20 20:00:00 +00:00
|
|
|
virtual bool isAttackingOrSpell() const { return true; }
|
2016-11-16 19:15:25 +00:00
|
|
|
virtual bool isFleeing() const { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class ActionFlee : public Action
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ActionFlee() {}
|
2020-10-16 18:18:54 +00:00
|
|
|
void prepare(const MWWorld::Ptr& actor) override {}
|
|
|
|
float getCombatRange (bool& isRanged) const override { return 0.0f; }
|
|
|
|
float getActionCooldown() override { return 3.0f; }
|
|
|
|
bool isAttackingOrSpell() const override { return false; }
|
|
|
|
bool isFleeing() const override { return true; }
|
2014-08-27 22:41:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ActionSpell : public Action
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ActionSpell(const std::string& spellId) : mSpellId(spellId) {}
|
|
|
|
std::string mSpellId;
|
|
|
|
/// Sets the given spell as selected on the actor's spell list.
|
2020-10-16 18:18:54 +00:00
|
|
|
void prepare(const MWWorld::Ptr& actor) override;
|
2014-08-27 22:41:52 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
float getCombatRange (bool& isRanged) const override;
|
2014-08-27 22:41:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ActionEnchantedItem : public Action
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ActionEnchantedItem(const MWWorld::ContainerStoreIterator& item) : mItem(item) {}
|
|
|
|
MWWorld::ContainerStoreIterator mItem;
|
|
|
|
/// Sets the given item as selected enchanted item in the actor's InventoryStore.
|
2020-10-16 18:18:54 +00:00
|
|
|
void prepare(const MWWorld::Ptr& actor) override;
|
|
|
|
float getCombatRange (bool& isRanged) const override;
|
2014-08-27 22:41:52 +00:00
|
|
|
|
|
|
|
/// Since this action has no animation, apply a small cool down for using it
|
2020-10-16 18:18:54 +00:00
|
|
|
float getActionCooldown() override { return 0.75f; }
|
2014-08-27 22:41:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ActionPotion : public Action
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ActionPotion(const MWWorld::Ptr& potion) : mPotion(potion) {}
|
|
|
|
MWWorld::Ptr mPotion;
|
|
|
|
/// Drinks the given potion.
|
2020-10-16 18:18:54 +00:00
|
|
|
void prepare(const MWWorld::Ptr& actor) override;
|
|
|
|
float getCombatRange (bool& isRanged) const override;
|
|
|
|
bool isAttackingOrSpell() const override { return false; }
|
2014-08-27 22:41:52 +00:00
|
|
|
|
|
|
|
/// Since this action has no animation, apply a small cool down for using it
|
2020-10-16 18:18:54 +00:00
|
|
|
float getActionCooldown() override { return 0.75f; }
|
2014-08-27 22:41:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ActionWeapon : public Action
|
|
|
|
{
|
2014-08-27 23:54:32 +00:00
|
|
|
private:
|
|
|
|
MWWorld::Ptr mAmmunition;
|
|
|
|
MWWorld::Ptr mWeapon;
|
|
|
|
|
2014-08-27 22:41:52 +00:00
|
|
|
public:
|
|
|
|
/// \a weapon may be empty for hand-to-hand combat
|
2014-08-27 23:54:32 +00:00
|
|
|
ActionWeapon(const MWWorld::Ptr& weapon, const MWWorld::Ptr& ammo = MWWorld::Ptr())
|
2015-04-25 18:37:42 +00:00
|
|
|
: mAmmunition(ammo), mWeapon(weapon) {}
|
2014-08-27 22:41:52 +00:00
|
|
|
/// Equips the given weapon.
|
2020-10-16 18:18:54 +00:00
|
|
|
void prepare(const MWWorld::Ptr& actor) override;
|
|
|
|
float getCombatRange (bool& isRanged) const override;
|
|
|
|
const ESM::Weapon* getWeapon() const override;
|
2014-08-27 22:41:52 +00:00
|
|
|
};
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<Action> prepareNextAction (const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
|
2017-06-16 12:11:12 +00:00
|
|
|
float getBestActionRating(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy);
|
2016-11-16 19:15:25 +00:00
|
|
|
|
|
|
|
float getDistanceMinusHalfExtents(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy, bool minusZDist=false);
|
|
|
|
float getMaxAttackDistance(const MWWorld::Ptr& actor);
|
|
|
|
bool canFight(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
|
|
|
|
|
|
|
|
float vanillaRateFlee(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
|
|
|
|
bool makeFleeDecision(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy, float antiFleeRating);
|
2014-08-27 22:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|