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

144 lines
3.9 KiB
C++
Raw Normal View History

#ifndef OPENMW_MWWORLD_PROJECTILEMANAGER_H
#define OPENMW_MWWORLD_PROJECTILEMANAGER_H
#include <string>
2015-06-01 19:41:13 +00:00
#include <osg/ref_ptr>
#include <osg/PositionAttitudeTransform>
#include <components/esm/effectlist.hpp>
#include "../mwbase/soundmanager.hpp"
#include "ptr.hpp"
2015-05-12 17:02:56 +00:00
namespace MWPhysics
{
2015-05-12 17:02:56 +00:00
class PhysicsSystem;
}
2014-05-17 03:21:17 +00:00
namespace Loading
{
class Listener;
}
2015-06-01 19:41:13 +00:00
namespace osg
{
2015-06-01 19:41:13 +00:00
class Group;
class Quat;
}
namespace Resource
{
class ResourceSystem;
}
namespace MWRender
{
class EffectAnimationTime;
class RenderingManager;
}
namespace MWWorld
{
class ProjectileManager
{
public:
2015-06-01 19:41:13 +00:00
ProjectileManager (osg::Group* parent, Resource::ResourceSystem* resourceSystem,
MWRender::RenderingManager* rendering, MWPhysics::PhysicsSystem* physics);
/// If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used.
void launchMagicBolt (const std::string &spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection);
2015-12-18 16:13:54 +00:00
void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,
const osg::Vec3f& pos, const osg::Quat& orient, MWWorld::Ptr bow, float speed, float attackStrength);
void update(float dt);
void processHits();
/// Removes all current projectiles. Should be called when switching to a new worldspace.
void clear();
2014-05-17 03:21:17 +00:00
void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
2015-01-22 18:04:59 +00:00
bool readRecord (ESM::ESMReader& reader, uint32_t type);
2014-05-17 03:21:17 +00:00
int countSavedGameRecords() const;
private:
2015-06-01 19:41:13 +00:00
osg::ref_ptr<osg::Group> mParent;
Resource::ResourceSystem* mResourceSystem;
MWRender::RenderingManager* mRendering;
2015-06-01 19:41:13 +00:00
MWPhysics::PhysicsSystem* mPhysics;
2017-09-23 16:54:17 +00:00
float mCleanupTimer;
struct State
{
2015-06-01 19:41:13 +00:00
osg::ref_ptr<osg::PositionAttitudeTransform> mNode;
std::shared_ptr<MWRender::EffectAnimationTime> mEffectAnimationTime;
2014-05-17 03:21:17 +00:00
int mActorId;
int mProjectileId;
// TODO: this will break when the game is saved and reloaded, since there is currently
// no way to write identifiers for non-actors to a savegame.
2015-06-01 19:41:13 +00:00
MWWorld::Ptr mCasterHandle;
MWWorld::Ptr getCaster();
// MW-ids of a magic projectile
std::vector<std::string> mIdMagic;
// MW-id of an arrow projectile
std::string mIdArrow;
bool mToDelete;
};
struct MagicBoltState : public State
{
2014-05-17 03:21:17 +00:00
std::string mSpellId;
// Name of item to display as effect source in magic menu (in case we casted an enchantment)
std::string mSourceName;
ESM::EffectList mEffects;
float mSpeed;
std::vector<MWBase::Sound*> mSounds;
std::set<std::string> mSoundIds;
};
struct ProjectileState : public State
{
// RefID of the bow or crossbow the actor was using when this projectile was fired (may be empty)
std::string mBowId;
2015-06-01 19:41:13 +00:00
osg::Vec3f mVelocity;
float mAttackStrength;
2017-11-22 23:32:22 +00:00
bool mThrown;
};
std::vector<MagicBoltState> mMagicBolts;
std::vector<ProjectileState> mProjectiles;
2017-09-23 16:54:17 +00:00
void cleanupProjectile(ProjectileState& state);
void cleanupMagicBolt(MagicBoltState& state);
void periodicCleanup(float dt);
void moveProjectiles(float dt);
void moveMagicBolts(float dt);
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 = "");
2015-06-01 19:41:13 +00:00
void update (State& state, float duration);
void operator=(const ProjectileManager&);
ProjectileManager(const ProjectileManager&);
};
}
#endif