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, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection);
53 
54  void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,
55  const osg::Vec3f& pos, const osg::Quat& orient, MWWorld::Ptr bow, float speed, float attackStrength);
56 
57  void update(float dt);
58 
60  void clear();
61 
62  void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
63  bool readRecord (ESM::ESMReader& reader, uint32_t type);
64  int countSavedGameRecords() const;
65 
66  private:
67  osg::ref_ptr<osg::Group> mParent;
72 
73  struct State
74  {
75  osg::ref_ptr<osg::PositionAttitudeTransform> mNode;
76  std::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  std::vector<MWBase::Sound*> mSounds;
105  std::vector<std::string> mSoundIds;
106  };
107 
108  struct ProjectileState : public State
109  {
110  // RefID of the bow or crossbow the actor was using when this projectile was fired (may be empty)
111  std::string mBowId;
112 
113  osg::Vec3f mVelocity;
115  bool mThrown;
116  };
117 
118  std::vector<MagicBoltState> mMagicBolts;
119  std::vector<ProjectileState> mProjectiles;
120 
121  void cleanupProjectile(ProjectileState& state);
122  void cleanupMagicBolt(MagicBoltState& state);
123  void periodicCleanup(float dt);
124 
125  void moveProjectiles(float dt);
126  void moveMagicBolts(float dt);
127 
128  void createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient,
129  bool rotate, bool createLight, osg::Vec4 lightDiffuseColor, std::string texture = "");
130  void update (State& state, float duration);
131 
132  void operator=(const ProjectileManager&);
134  };
135 
136 }
137 
138 #endif
MWPhysics::PhysicsSystem * mPhysics
Definition: projectilemanager.hpp:70
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:30
void operator=(const ProjectileManager &)
void cleanupProjectile(ProjectileState &state)
Definition: projectilemanager.cpp:536
std::vector< ProjectileState > mProjectiles
Definition: projectilemanager.hpp:119
Definition: renderingmanager.hpp:72
MWWorld::Ptr getCaster()
Definition: projectilemanager.cpp:698
Definition: esmreader.hpp:21
std::string mSpellId
Definition: projectilemanager.hpp:95
std::string mBowId
Definition: projectilemanager.hpp:111
Definition: projectilemanager.hpp:108
ProjectileManager(osg::Group *parent, Resource::ResourceSystem *resourceSystem, MWRender::RenderingManager *rendering, MWPhysics::PhysicsSystem *physics)
Definition: projectilemanager.cpp:150
bool readRecord(ESM::ESMReader &reader, uint32_t type)
Definition: projectilemanager.cpp:604
void update(float dt)
Definition: projectilemanager.cpp:339
Definition: loadinglistener.hpp:8
Definition: physicssystem.hpp:52
float mSpeed
Definition: projectilemanager.hpp:102
MWWorld::Ptr mCasterHandle
Definition: projectilemanager.hpp:82
Definition: esmwriter.hpp:17
void launchMagicBolt(const std::string &spellId, const MWWorld::Ptr &caster, const osg::Vec3f &fallbackDirection)
If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used...
Definition: projectilemanager.cpp:266
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:189
Resource::ResourceSystem * mResourceSystem
Definition: projectilemanager.hpp:68
float mCleanupTimer
Definition: projectilemanager.hpp:71
std::string mIdArrow
Definition: projectilemanager.hpp:90
std::vector< MWBase::Sound * > mSounds
Definition: projectilemanager.hpp:104
float mAttackStrength
Definition: projectilemanager.hpp:114
std::vector< MagicBoltState > mMagicBolts
Definition: projectilemanager.hpp:118
std::vector< std::string > mIdMagic
Definition: projectilemanager.hpp:87
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
std::shared_ptr< MWRender::EffectAnimationTime > mEffectAnimationTime
Definition: projectilemanager.hpp:76
void clear()
Removes all current projectiles. Should be called when switching to a new worldspace.
Definition: projectilemanager.cpp:550
MWRender::RenderingManager * mRendering
Definition: projectilemanager.hpp:69
int countSavedGameRecords() const
Definition: projectilemanager.cpp:693
void periodicCleanup(float dt)
Definition: projectilemanager.cpp:346
void cleanupMagicBolt(MagicBoltState &state)
Definition: projectilemanager.cpp:541
osg::Vec3f mVelocity
Definition: projectilemanager.hpp:113
osg::ref_ptr< osg::PositionAttitudeTransform > mNode
Definition: projectilemanager.hpp:75
void moveMagicBolts(float dt)
Definition: projectilemanager.cpp:384
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:320
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:459
void write(ESM::ESMWriter &writer, Loading::Listener &progress) const
Definition: projectilemanager.cpp:564
std::vector< std::string > mSoundIds
Definition: projectilemanager.hpp:105
EffectList, ENAM subrecord.
Definition: effectlist.hpp:33
bool mThrown
Definition: projectilemanager.hpp:115
osg::ref_ptr< osg::Group > mParent
Definition: projectilemanager.hpp:67