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