OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
projectilemanager.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWWORLD_PROJECTILEMANAGER_H
2 #define OPENMW_MWWORLD_PROJECTILEMANAGER_H
3 
4 #include <string>
5 
6 #include <osg/ref_ptr>
7 #include <osg/PositionAttitudeTransform>
8 
10 
11 #include "../mwbase/soundmanager.hpp"
12 
13 #include "ptr.hpp"
14 
15 namespace MWPhysics
16 {
17  class PhysicsSystem;
18 }
19 
20 namespace Loading
21 {
22  class Listener;
23 }
24 
25 namespace osg
26 {
27  class Group;
28  class Quat;
29 }
30 
31 namespace Resource
32 {
33  class ResourceSystem;
34 }
35 
36 namespace MWRender
37 {
38  class EffectAnimationTime;
39  class RenderingManager;
40 }
41 
42 namespace MWWorld
43 {
44 
46  {
47  public:
48  ProjectileManager (osg::Group* parent, Resource::ResourceSystem* resourceSystem,
50 
52  void launchMagicBolt (const std::string &spellId, bool stack, const ESM::EffectList& effects,
53  const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection);
54 
55  void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,
56  const osg::Vec3f& pos, const osg::Quat& orient, MWWorld::Ptr bow, float speed, float attackStrength);
57 
58  void update(float dt);
59 
61  void clear();
62 
63  void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
64  bool readRecord (ESM::ESMReader& reader, uint32_t type);
65  int countSavedGameRecords() const;
66 
67  private:
68  osg::ref_ptr<osg::Group> mParent;
72 
73  struct State
74  {
75  osg::ref_ptr<osg::PositionAttitudeTransform> mNode;
76  boost::shared_ptr<MWRender::EffectAnimationTime> mEffectAnimationTime;
77 
78  int mActorId;
79 
80  // TODO: this will break when the game is saved and reloaded, since there is currently
81  // no way to write identifiers for non-actors to a savegame.
83 
85 
86  // MW-ids of a magic projectile
87  std::vector<std::string> mIdMagic;
88 
89  // MW-id of an arrow projectile
90  std::string mIdArrow;
91  };
92 
93  struct MagicBoltState : public State
94  {
95  std::string mSpellId;
96 
97  // Name of item to display as effect source in magic menu (in case we casted an enchantment)
98  std::string mSourceName;
99 
101 
102  float mSpeed;
103 
104  bool mStack;
105 
106  std::vector<MWBase::SoundPtr> mSounds;
107  std::vector<std::string> mSoundIds;
108  };
109 
110  struct ProjectileState : public State
111  {
112  // RefID of the bow or crossbow the actor was using when this projectile was fired (may be empty)
113  std::string mBowId;
114 
115  osg::Vec3f mVelocity;
117  };
118 
119  std::vector<MagicBoltState> mMagicBolts;
120  std::vector<ProjectileState> mProjectiles;
121 
122  void moveProjectiles(float dt);
123  void moveMagicBolts(float dt);
124 
125  void createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient,
126  bool rotate, bool createLight, osg::Vec4 lightDiffuseColor, std::string texture = "");
127  void update (State& state, float duration);
128 
129  void operator=(const ProjectileManager&);
131  };
132 
133 }
134 
135 #endif
MWPhysics::PhysicsSystem * mPhysics
Definition: projectilemanager.hpp:71
boost::shared_ptr< MWRender::EffectAnimationTime > mEffectAnimationTime
Definition: projectilemanager.hpp:76
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:24
void operator=(const ProjectileManager &)
std::vector< ProjectileState > mProjectiles
Definition: projectilemanager.hpp:120
Definition: renderingmanager.hpp:63
MWWorld::Ptr getCaster()
Definition: projectilemanager.cpp:591
Definition: esmreader.hpp:21
bool mStack
Definition: projectilemanager.hpp:104
std::vector< MWBase::SoundPtr > mSounds
Definition: projectilemanager.hpp:106
std::string mSpellId
Definition: projectilemanager.hpp:95
std::string mBowId
Definition: projectilemanager.hpp:113
Definition: projectilemanager.hpp:110
ProjectileManager(osg::Group *parent, Resource::ResourceSystem *resourceSystem, MWRender::RenderingManager *rendering, MWPhysics::PhysicsSystem *physics)
Definition: projectilemanager.cpp:126
bool readRecord(ESM::ESMReader &reader, uint32_t type)
Definition: projectilemanager.cpp:505
void update(float dt)
Definition: projectilemanager.cpp:309
Definition: loadinglistener.hpp:8
Definition: physicssystem.hpp:51
float mSpeed
Definition: projectilemanager.hpp:102
MWWorld::Ptr mCasterHandle
Definition: projectilemanager.hpp:82
Definition: esmwriter.hpp:17
Definition: projectilemanager.hpp:45
int mActorId
Definition: projectilemanager.hpp:78
Definition: projectilemanager.hpp:73
void createModel(State &state, const std::string &model, const osg::Vec3f &pos, const osg::Quat &orient, bool rotate, bool createLight, osg::Vec4 lightDiffuseColor, std::string texture="")
Definition: projectilemanager.cpp:164
Resource::ResourceSystem * mResourceSystem
Definition: projectilemanager.hpp:69
std::string mIdArrow
Definition: projectilemanager.hpp:90
float mAttackStrength
Definition: projectilemanager.hpp:116
std::vector< MagicBoltState > mMagicBolts
Definition: projectilemanager.hpp:119
std::vector< std::string > mIdMagic
Definition: projectilemanager.hpp:87
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
void clear()
Removes all current projectiles. Should be called when switching to a new worldspace.
Definition: projectilemanager.cpp:443
MWRender::RenderingManager * mRendering
Definition: projectilemanager.hpp:70
void launchMagicBolt(const std::string &spellId, bool stack, const ESM::EffectList &effects, const MWWorld::Ptr &caster, const std::string &sourceName, const osg::Vec3f &fallbackDirection)
If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used...
Definition: projectilemanager.cpp:235
int countSavedGameRecords() const
Definition: projectilemanager.cpp:586
osg::Vec3f mVelocity
Definition: projectilemanager.hpp:115
osg::ref_ptr< osg::PositionAttitudeTransform > mNode
Definition: projectilemanager.hpp:75
void moveMagicBolts(float dt)
Definition: projectilemanager.cpp:315
void launchProjectile(MWWorld::Ptr actor, MWWorld::ConstPtr projectile, const osg::Vec3f &pos, const osg::Quat &orient, MWWorld::Ptr bow, float speed, float attackStrength)
Definition: projectilemanager.cpp:291
ESM::EffectList mEffects
Definition: projectilemanager.hpp:100
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
Definition: projectilemanager.hpp:93
std::string mSourceName
Definition: projectilemanager.hpp:98
void moveProjectiles(float dt)
Definition: projectilemanager.cpp:387
void write(ESM::ESMWriter &writer, Loading::Listener &progress) const
Definition: projectilemanager.cpp:461
std::vector< std::string > mSoundIds
Definition: projectilemanager.hpp:107
EffectList, ENAM subrecord.
Definition: effectlist.hpp:33
osg::ref_ptr< osg::Group > mParent
Definition: projectilemanager.hpp:68