OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aicombataction.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_AICOMBAT_ACTION_H
2 #define OPENMW_AICOMBAT_ACTION_H
3 
4 #include <boost/shared_ptr.hpp>
5 
7 
8 #include "../mwworld/ptr.hpp"
9 #include "../mwworld/containerstore.hpp"
10 
11 namespace MWMechanics
12 {
13 
14  class Action
15  {
16  public:
17  virtual ~Action() {}
18  virtual void prepare(const MWWorld::Ptr& actor) = 0;
19  virtual float getCombatRange (bool& isRanged) const = 0;
20  virtual float getActionCooldown() { return 0.f; }
21  virtual const ESM::Weapon* getWeapon() const { return NULL; };
22  virtual bool isAttackingOrSpell() const { return true; }
23  virtual bool isFleeing() const { return false; }
24  };
25 
26  class ActionFlee : public Action
27  {
28  public:
30  virtual void prepare(const MWWorld::Ptr& actor) {}
31  virtual float getCombatRange (bool& isRanged) const { return 0.0f; }
32  virtual float getActionCooldown() { return 3.0f; }
33  virtual bool isAttackingOrSpell() const { return false; }
34  virtual bool isFleeing() const { return true; }
35  };
36 
37  class ActionSpell : public Action
38  {
39  public:
40  ActionSpell(const std::string& spellId) : mSpellId(spellId) {}
41  std::string mSpellId;
43  virtual void prepare(const MWWorld::Ptr& actor);
44 
45  virtual float getCombatRange (bool& isRanged) const;
46  };
47 
48  class ActionEnchantedItem : public Action
49  {
50  public:
54  virtual void prepare(const MWWorld::Ptr& actor);
55  virtual float getCombatRange (bool& isRanged) const;
56 
58  virtual float getActionCooldown() { return 1.f; }
59  };
60 
61  class ActionPotion : public Action
62  {
63  public:
64  ActionPotion(const MWWorld::Ptr& potion) : mPotion(potion) {}
67  virtual void prepare(const MWWorld::Ptr& actor);
68  virtual float getCombatRange (bool& isRanged) const;
69  virtual bool isAttackingOrSpell() const { return false; }
70 
72  virtual float getActionCooldown() { return 1.f; }
73  };
74 
75  class ActionWeapon : public Action
76  {
77  private:
80 
81  public:
83  ActionWeapon(const MWWorld::Ptr& weapon, const MWWorld::Ptr& ammo = MWWorld::Ptr())
84  : mAmmunition(ammo), mWeapon(weapon) {}
86  virtual void prepare(const MWWorld::Ptr& actor);
87  virtual float getCombatRange (bool& isRanged) const;
88  virtual const ESM::Weapon* getWeapon() const;
89  };
90 
91  float rateSpell (const ESM::Spell* spell, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
92  float rateMagicItem (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
93  float ratePotion (const MWWorld::Ptr& item, const MWWorld::Ptr &actor);
95  float rateWeapon (const MWWorld::Ptr& item, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy,
96  int type=-1, float arrowRating=0.f, float boltRating=0.f);
97 
99  float rateEffect (const ESM::ENAMstruct& effect, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
101  float rateEffects (const ESM::EffectList& list, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
102 
103  boost::shared_ptr<Action> prepareNextAction (const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
104 
105  float getDistanceMinusHalfExtents(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy, bool minusZDist=false);
106  float getMaxAttackDistance(const MWWorld::Ptr& actor);
107  bool canFight(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
108 
109  float vanillaRateSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
110  float vanillaRateWeaponAndAmmo(const MWWorld::Ptr& weapon, const MWWorld::Ptr& ammo, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
111  float vanillaRateFlee(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy);
112  bool makeFleeDecision(const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy, float antiFleeRating);
113 }
114 
115 #endif
virtual float getCombatRange(bool &isRanged) const =0
Iteration over a subset of objects in a ContainerStore.
Definition: containerstore.hpp:196
virtual const ESM::Weapon * getWeapon() const
Definition: aicombataction.cpp:511
virtual float getCombatRange(bool &isRanged) const
Definition: aicombataction.cpp:454
virtual float getActionCooldown()
Since this action has no animation, apply a small cool down for using it.
Definition: aicombataction.hpp:72
Definition: aicombataction.hpp:14
ActionFlee()
Definition: aicombataction.hpp:29
Definition: aicombataction.hpp:37
ActionEnchantedItem(const MWWorld::ContainerStoreIterator &item)
Definition: aicombataction.hpp:51
virtual float getActionCooldown()
Definition: aicombataction.hpp:32
virtual float getCombatRange(bool &isRanged) const
Definition: aicombataction.cpp:487
Definition: loadspel.hpp:14
virtual float getActionCooldown()
Definition: aicombataction.hpp:20
virtual float getActionCooldown()
Since this action has no animation, apply a small cool down for using it.
Definition: aicombataction.hpp:58
virtual void prepare(const MWWorld::Ptr &actor)
Equips the given weapon.
Definition: aicombataction.cpp:466
virtual bool isAttackingOrSpell() const
Definition: aicombataction.hpp:22
float rateSpell(const ESM::Spell *spell, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:171
ActionWeapon(const MWWorld::Ptr &weapon, const MWWorld::Ptr &ammo=MWWorld::Ptr())
weapon may be empty for hand-to-hand combat
Definition: aicombataction.hpp:83
virtual ~Action()
Definition: aicombataction.hpp:17
int list(Bsa::BSAFile &bsa, Arguments &info)
Definition: bsatool.cpp:183
float vanillaRateFlee(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:874
Definition: aicombataction.hpp:75
virtual bool isFleeing() const
Definition: aicombataction.hpp:23
MWWorld::Ptr mPotion
Definition: aicombataction.hpp:65
Definition: effectlist.hpp:17
std::string mSpellId
Definition: aicombataction.hpp:41
virtual const ESM::Weapon * getWeapon() const
Definition: aicombataction.hpp:21
virtual void prepare(const MWWorld::Ptr &actor)
Sets the given item as selected enchanted item in the actor's InventoryStore.
Definition: aicombataction.cpp:440
MWWorld::ContainerStoreIterator mItem
Definition: aicombataction.hpp:52
virtual void prepare(const MWWorld::Ptr &actor)=0
ActionSpell(const std::string &spellId)
Definition: aicombataction.hpp:40
virtual float getCombatRange(bool &isRanged) const
Definition: aicombataction.cpp:431
float getDistanceMinusHalfExtents(const MWWorld::Ptr &actor1, const MWWorld::Ptr &actor2, bool minusZDist)
Definition: aicombataction.cpp:630
Definition: aicombataction.hpp:26
virtual bool isFleeing() const
Definition: aicombataction.hpp:34
float vanillaRateWeaponAndAmmo(const MWWorld::Ptr &weapon, const MWWorld::Ptr &ammo, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:838
virtual void prepare(const MWWorld::Ptr &actor)
Definition: aicombataction.hpp:30
float vanillaRateSpell(const ESM::Spell *spell, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:813
MWWorld::Ptr mAmmunition
Definition: aicombataction.hpp:78
virtual void prepare(const MWWorld::Ptr &actor)
Drinks the given potion.
Definition: aicombataction.cpp:460
float getMaxAttackDistance(const MWWorld::Ptr &actor)
Definition: aicombataction.cpp:645
float ratePotion(const MWWorld::Ptr &item, const MWWorld::Ptr &actor)
Definition: aicombataction.cpp:92
virtual float getCombatRange(bool &isRanged) const
Definition: aicombataction.hpp:31
boost::shared_ptr< Action > prepareNextAction(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:518
virtual bool isAttackingOrSpell() const
Definition: aicombataction.hpp:69
Definition: aicombataction.hpp:48
float rateMagicItem(const MWWorld::Ptr &ptr, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:204
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
virtual void prepare(const MWWorld::Ptr &actor)
Sets the given spell as selected on the actor's spell list.
Definition: aicombataction.cpp:420
virtual bool isAttackingOrSpell() const
Definition: aicombataction.hpp:33
Definition: aicombataction.hpp:61
float rateEffects(const ESM::EffectList &list, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:409
EffectList, ENAM subrecord.
Definition: effectlist.hpp:33
virtual float getCombatRange(bool &isRanged) const
Definition: aicombataction.cpp:447
bool canFight(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:749
bool makeFleeDecision(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy, float antiFleeRating)
Definition: aicombataction.cpp:904
float rateEffect(const ESM::ENAMstruct &effect, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy)
Definition: aicombataction.cpp:222
ActionPotion(const MWWorld::Ptr &potion)
Definition: aicombataction.hpp:64
MWWorld::Ptr mWeapon
Definition: aicombataction.hpp:79
Definition: loadweap.hpp:16
float rateWeapon(const MWWorld::Ptr &item, const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy, int type, float arrowRating, float boltRating)
Definition: aicombataction.cpp:101