1 | /*! |
---|
2 | * @file projectile.h |
---|
3 | * a projectile, that is been shooted by a weapon |
---|
4 | * |
---|
5 | * You can use this class to make some Projectiles/Bullets/Lasers/Rockets/etc. |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef _PROJECTILE_H |
---|
10 | #define _PROJECTILE_H |
---|
11 | |
---|
12 | #include "world_entity.h" |
---|
13 | #include "loading/fast_factory.h" |
---|
14 | #include "space_ships/space_ship.h" |
---|
15 | |
---|
16 | #include "sound_source.h" |
---|
17 | #include "sound_buffer.h" |
---|
18 | |
---|
19 | class Projectile : public WorldEntity |
---|
20 | { |
---|
21 | ObjectListDeclaration(Projectile); |
---|
22 | public: |
---|
23 | Projectile (); |
---|
24 | virtual ~Projectile (); |
---|
25 | |
---|
26 | /** @brief Constructor with variable passing*/ |
---|
27 | Projectile (float pDamage, float eDamage, PNode* target); |
---|
28 | /** @brief for void construction; setting values later - needed for FastFactory*/ |
---|
29 | virtual void initialize(float pDamage, float eDamage, PNode* target); |
---|
30 | |
---|
31 | void setFlightDirection(const Quaternion& flightDirection); |
---|
32 | void setVelocity(const Vector &velocity); |
---|
33 | void setLifeSpan(float lifeSpan); |
---|
34 | |
---|
35 | void loadExplosionSound(const std::string& explosionSound); |
---|
36 | void loadEngineSound(const std::string& engineSound); |
---|
37 | void setMinEnergy(float energyMin); |
---|
38 | /** @returns the minimal charched energy */ |
---|
39 | inline float getMinEnergy() { return this->energyMin; }; |
---|
40 | /** @returns if the Projectile can be charged */ |
---|
41 | inline bool isChageable() { return this->bChargeable; }; |
---|
42 | |
---|
43 | void setTarget(PNode* target); |
---|
44 | |
---|
45 | /** @brief This is called, when the Projectile is Emitted */ |
---|
46 | virtual void activate() = 0; |
---|
47 | /** @brief This is called, when the Projectile is being destroyed, or deleted */ |
---|
48 | virtual void deactivate() = 0; |
---|
49 | |
---|
50 | virtual void destroy (WorldEntity* killer); |
---|
51 | |
---|
52 | virtual void collidesWith (SpaceShip* target, const Vector& location); //!< collision handler; used against SpaceShip as most target will be |
---|
53 | |
---|
54 | |
---|
55 | virtual void tick (float dt); |
---|
56 | /** @brief convenience function |
---|
57 | * @param dt the Time passed |
---|
58 | * @returns true if the Projectile is past its lifeTime, false if it shall still live */ |
---|
59 | inline bool tickLifeCycle(float dt ) { this->lifeCycle += dt/this->lifeSpan; return(unlikely(this->lifeCycle >= 1)); } |
---|
60 | |
---|
61 | inline float getPhysDamage() { return this->physDamage; }; |
---|
62 | inline float getElecDamage() { return this->elecDamage; }; |
---|
63 | |
---|
64 | protected: |
---|
65 | // energy |
---|
66 | float energyMin; //!< The minimal Energy a Projectile needs to be emitted. |
---|
67 | bool bChargeable; //!< if the Projectile is Charegeable |
---|
68 | |
---|
69 | float lifeCycle; //!< The percentage of the Lifetime done [0-1] |
---|
70 | float lifeSpan; //!< The entire lifespan of the Shoot. in seconds |
---|
71 | |
---|
72 | float physDamage; //!< damage to shield and armor |
---|
73 | float elecDamage; //!< damage to elctronic |
---|
74 | float turningSpeed; //!< degrees per tick |
---|
75 | |
---|
76 | Vector flightDirection; //!< DOF direction in which the shoot flighs |
---|
77 | |
---|
78 | Vector velocity; //!< velocity of the projectile. |
---|
79 | |
---|
80 | PNode* target; //!< A target for guided Weapons. |
---|
81 | //Vector targetPosition; //!< current target position relative to projectile |
---|
82 | //Vector targetVelocity; //!< current target speed and direction |
---|
83 | //float eta; //!< estimated time of arrival == time to kaboom! |
---|
84 | |
---|
85 | OrxSound::SoundSource soundSource; |
---|
86 | private: |
---|
87 | OrxSound::SoundBuffer explosionBuffer; |
---|
88 | OrxSound::SoundBuffer engineBuffer; |
---|
89 | |
---|
90 | virtual Vector newDirection(Vector curDirection, Vector estTargetDir, float angle); |
---|
91 | }; |
---|
92 | |
---|
93 | #endif /* _PROJECTILE_H */ |
---|