[2918] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Martin Polak |
---|
| 24 | * Fabian 'x3n' Landau |
---|
| 25 | * Co-authors: |
---|
[11189] | 26 | * Johannes Sager |
---|
[2918] | 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef _WeaponMode_H__ |
---|
| 31 | #define _WeaponMode_H__ |
---|
| 32 | |
---|
| 33 | #include "OrxonoxPrereqs.h" |
---|
[3196] | 34 | |
---|
| 35 | #include <string> |
---|
[11108] | 36 | #include <vector> |
---|
[3196] | 37 | #include "util/Math.h" |
---|
[2918] | 38 | #include "core/BaseObject.h" |
---|
[9667] | 39 | #include "core/class/SubclassIdentifier.h" |
---|
[2918] | 40 | #include "tools/Timer.h" |
---|
[11052] | 41 | #include "Munition.h" |
---|
[2918] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[10650] | 45 | /** |
---|
| 46 | @brief |
---|
[11142] | 47 | A WeaponMode defines how a Weapon is used. It specifies what kind of |
---|
| 48 | @ref orxonox::Projectile is created when you fire it, how much time it takes to reload, |
---|
| 49 | what sound you hear while shooting, how much damage the projectile deals to a target, ... |
---|
[10650] | 50 | */ |
---|
[2918] | 51 | class _OrxonoxExport WeaponMode : public BaseObject |
---|
| 52 | { |
---|
| 53 | public: |
---|
[9667] | 54 | WeaponMode(Context* context); |
---|
[2918] | 55 | virtual ~WeaponMode(); |
---|
| 56 | |
---|
[11071] | 57 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
[2918] | 58 | |
---|
[11174] | 59 | virtual bool push(float* reloadTime); |
---|
| 60 | virtual bool release(float* reloadTime); |
---|
[11108] | 61 | virtual bool fire(float* reloadTime); |
---|
[2918] | 62 | bool reload(); |
---|
| 63 | |
---|
| 64 | // Munition |
---|
| 65 | inline Munition* getMunition() const |
---|
| 66 | { return this->munition_; } |
---|
| 67 | |
---|
| 68 | void setMunitionType(Identifier* identifier); |
---|
| 69 | inline Identifier* getMunitionType() const |
---|
| 70 | { return this->munitiontype_; } |
---|
| 71 | |
---|
| 72 | void setMunitionName(const std::string& munitionname); |
---|
| 73 | inline const std::string& getMunitionName() const |
---|
| 74 | { return this->munitionname_; } |
---|
| 75 | |
---|
| 76 | inline void setInitialMunition(unsigned int amount) |
---|
| 77 | { this->initialMunition_ = amount; } |
---|
| 78 | inline unsigned int getInitialMunition() const |
---|
| 79 | { return this->initialMunition_; } |
---|
| 80 | |
---|
| 81 | inline void setInitialMagazines(unsigned int amount) |
---|
| 82 | { this->initialMagazines_ = amount; } |
---|
| 83 | inline unsigned int getInitialMagazines() const |
---|
| 84 | { return this->initialMagazines_; } |
---|
| 85 | |
---|
| 86 | inline void setMunitionPerShot(unsigned int amount) |
---|
| 87 | { this->munitionPerShot_ = amount; } |
---|
| 88 | inline unsigned int getMunitionPerShot() const |
---|
| 89 | { return this->munitionPerShot_; } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | // Reloading |
---|
| 93 | inline void setReloadTime(float time) |
---|
| 94 | { this->reloadTime_ = time; } |
---|
| 95 | inline float getReloadTime() const |
---|
| 96 | { return this->reloadTime_; } |
---|
| 97 | |
---|
| 98 | inline void setAutoReload(bool autoreload) |
---|
| 99 | { this->bAutoReload_ = autoreload; } |
---|
| 100 | inline bool getAutoReload() const |
---|
| 101 | { return this->bAutoReload_; } |
---|
| 102 | |
---|
| 103 | inline void setParallelReload(bool parallelreload) |
---|
| 104 | { this->bParallelReload_ = parallelreload; } |
---|
| 105 | inline bool getParallelReload() const |
---|
| 106 | { return this->bParallelReload_; } |
---|
[11052] | 107 | inline bool getReloading() const |
---|
| 108 | { return this->bReloading_; } |
---|
[2918] | 109 | |
---|
| 110 | |
---|
| 111 | // Fire |
---|
[11189] | 112 | inline unsigned int getMaxCharges() // get the maximum of charges one can have |
---|
[11185] | 113 | { return this->maxCharges_;} |
---|
[11189] | 114 | inline unsigned int getCharges() // get the current amount of charges |
---|
[11185] | 115 | { return this->charges_;} |
---|
[11189] | 116 | inline bool isChargeable() // returns if the weaponmode is chargeable |
---|
[11185] | 117 | { return this->chargeable_;} |
---|
[2918] | 118 | inline void setDamage(float damage) |
---|
[8706] | 119 | { this->damage_ = damage;} |
---|
[2918] | 120 | inline float getDamage() const |
---|
| 121 | { return this->damage_; } |
---|
[8706] | 122 | inline void setHealthDamage(float healthdamage) |
---|
| 123 | { this->healthdamage_ = healthdamage; } |
---|
| 124 | inline float getHealthDamage() const |
---|
| 125 | { return this->healthdamage_; } |
---|
[2918] | 126 | |
---|
[8706] | 127 | inline void setShieldDamage(float shielddamage) |
---|
| 128 | { this->shielddamage_ = shielddamage;} |
---|
| 129 | inline float getShieldDamage() const |
---|
| 130 | { return this->shielddamage_; } |
---|
| 131 | |
---|
[2918] | 132 | inline void setMuzzleOffset(const Vector3& offset) |
---|
| 133 | { this->muzzleOffset_ = offset; } |
---|
| 134 | inline const Vector3& getMuzzleOffset() const |
---|
| 135 | { return this->muzzleOffset_; } |
---|
| 136 | |
---|
[6417] | 137 | void computeMuzzleParameters(const Vector3& target); |
---|
| 138 | const Vector3& getMuzzlePosition() const |
---|
| 139 | { return this->muzzlePosition_; } |
---|
| 140 | const Quaternion& getMuzzleOrientation() const |
---|
| 141 | { return this->muzzleOrientation_; } |
---|
[2918] | 142 | Vector3 getMuzzleDirection() const; |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | // Weapon |
---|
| 146 | inline void setWeapon(Weapon* weapon) |
---|
| 147 | { this->weapon_ = weapon; this->updateMunition(); } |
---|
| 148 | inline Weapon* getWeapon() const |
---|
| 149 | { return this->weapon_; } |
---|
| 150 | |
---|
| 151 | inline void setMode(unsigned int mode) |
---|
| 152 | { this->mode_ = mode; } |
---|
| 153 | inline unsigned int getMode() const |
---|
| 154 | { return this->mode_; } |
---|
| 155 | |
---|
[6417] | 156 | Vector3 getTarget(); |
---|
| 157 | |
---|
[11052] | 158 | inline const std::string& getHUDImageString() const |
---|
| 159 | { return this->hudImageString_; } |
---|
| 160 | |
---|
| 161 | void updateMunition(); |
---|
[2918] | 162 | protected: |
---|
[11108] | 163 | // Interacting with the firing sound |
---|
| 164 | void setFireSound(const std::string& soundPath, const float soundVolume = 1.0); |
---|
| 165 | const std::string& getFireSound(); |
---|
| 166 | void playFireSound(); |
---|
| 167 | |
---|
| 168 | // Interacting with the reloading sound |
---|
| 169 | void setReloadSound(const std::string& soundPath, const float soundVolume = 1.0); |
---|
| 170 | const std::string& getReloadSound(); |
---|
| 171 | void playReloadSound(); |
---|
| 172 | |
---|
[2918] | 173 | virtual void fire() = 0; |
---|
| 174 | |
---|
| 175 | unsigned int initialMunition_; |
---|
| 176 | unsigned int initialMagazines_; |
---|
| 177 | unsigned int munitionPerShot_; |
---|
[11189] | 178 | unsigned int charges_; // current amount of charges only matters for chargeable weapons(chargeable == true) |
---|
| 179 | unsigned int maxCharges_; // maximum amount of charges (is initialized with 100 in weaponmode.cc) only matters for chargeable weapons(chargeable == true) |
---|
[2918] | 180 | |
---|
| 181 | float reloadTime_; |
---|
[11189] | 182 | bool bAutoReload_; // If true, the weapon reloads the magazine automatically. |
---|
| 183 | bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. |
---|
| 184 | bool chargeable_; // If true, the weapon charges up on push and fires on release |
---|
[2918] | 185 | |
---|
| 186 | float damage_; |
---|
[8706] | 187 | float healthdamage_; |
---|
| 188 | float shielddamage_; |
---|
[2918] | 189 | Vector3 muzzleOffset_; |
---|
| 190 | |
---|
[11052] | 191 | std::string hudImageString_; |
---|
| 192 | |
---|
| 193 | private: |
---|
[2918] | 194 | void reloaded(); |
---|
| 195 | |
---|
| 196 | Weapon* weapon_; |
---|
| 197 | unsigned int mode_; |
---|
| 198 | |
---|
| 199 | Munition* munition_; |
---|
| 200 | SubclassIdentifier<Munition> munitiontype_; |
---|
| 201 | std::string munitionname_; |
---|
| 202 | |
---|
[5929] | 203 | Timer reloadTimer_; |
---|
[11189] | 204 | bool bReloading_; // If true, this weapon mode is marked as reloading. |
---|
[6417] | 205 | |
---|
| 206 | Vector3 muzzlePosition_; |
---|
| 207 | Quaternion muzzleOrientation_; |
---|
| 208 | |
---|
[11189] | 209 | std::string fireSoundPath_; // The path of the sound played when fireing |
---|
| 210 | float fireSoundVolume_; // The volume of the sound played when fireing |
---|
| 211 | std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance. |
---|
| 212 | std::string reloadSoundPath_; // The path of the sound played when reloading |
---|
| 213 | float reloadSoundVolume_; // The volume of the sound played when reloading |
---|
[11108] | 214 | WorldSound* reloadSound_; |
---|
[2918] | 215 | }; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | #endif /* _WeaponMode_H__ */ |
---|