[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: |
---|
[8007] | 26 | * Kevin Young |
---|
[2918] | 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef _WeaponMode_H__ |
---|
| 31 | #define _WeaponMode_H__ |
---|
| 32 | |
---|
| 33 | #include "OrxonoxPrereqs.h" |
---|
[3196] | 34 | |
---|
| 35 | #include <string> |
---|
| 36 | #include "util/Math.h" |
---|
[2918] | 37 | #include "core/BaseObject.h" |
---|
[5929] | 38 | #include "core/SubclassIdentifier.h" |
---|
[2918] | 39 | #include "tools/Timer.h" |
---|
| 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[8007] | 43 | /** |
---|
| 44 | * The WeaponMode class enables the developer, amongst other things, to attach a sound file |
---|
| 45 | * to the firing event of a weapon. The default firing sound is chosen by each weapon (ex. |
---|
| 46 | * HsW01), hard-coded for now. |
---|
| 47 | */ |
---|
[2918] | 48 | class _OrxonoxExport WeaponMode : public BaseObject |
---|
| 49 | { |
---|
| 50 | public: |
---|
| 51 | WeaponMode(BaseObject* creator); |
---|
| 52 | virtual ~WeaponMode(); |
---|
| 53 | |
---|
| 54 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 55 | |
---|
| 56 | bool fire(float* reloadTime); |
---|
| 57 | bool reload(); |
---|
| 58 | |
---|
[6417] | 59 | // Interacting with the default Firing sound |
---|
| 60 | void setDefaultSound(const std::string& soundPath); |
---|
| 61 | const std::string& getDefaultSound(); |
---|
[7163] | 62 | void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume); |
---|
[2918] | 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_; } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | // Fire |
---|
| 110 | inline void setDamage(float damage) |
---|
| 111 | { this->damage_ = damage; } |
---|
| 112 | inline float getDamage() const |
---|
| 113 | { return this->damage_; } |
---|
| 114 | |
---|
| 115 | inline void setMuzzleOffset(const Vector3& offset) |
---|
| 116 | { this->muzzleOffset_ = offset; } |
---|
| 117 | inline const Vector3& getMuzzleOffset() const |
---|
| 118 | { return this->muzzleOffset_; } |
---|
| 119 | |
---|
[6417] | 120 | void computeMuzzleParameters(const Vector3& target); |
---|
| 121 | const Vector3& getMuzzlePosition() const |
---|
| 122 | { return this->muzzlePosition_; } |
---|
| 123 | const Quaternion& getMuzzleOrientation() const |
---|
| 124 | { return this->muzzleOrientation_; } |
---|
[2918] | 125 | Vector3 getMuzzleDirection() const; |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | // Weapon |
---|
| 129 | inline void setWeapon(Weapon* weapon) |
---|
| 130 | { this->weapon_ = weapon; this->updateMunition(); } |
---|
| 131 | inline Weapon* getWeapon() const |
---|
| 132 | { return this->weapon_; } |
---|
| 133 | |
---|
| 134 | inline void setMode(unsigned int mode) |
---|
| 135 | { this->mode_ = mode; } |
---|
| 136 | inline unsigned int getMode() const |
---|
| 137 | { return this->mode_; } |
---|
| 138 | |
---|
[6417] | 139 | Vector3 getTarget(); |
---|
| 140 | |
---|
[2918] | 141 | protected: |
---|
| 142 | virtual void fire() = 0; |
---|
| 143 | |
---|
| 144 | unsigned int initialMunition_; |
---|
| 145 | unsigned int initialMagazines_; |
---|
| 146 | unsigned int munitionPerShot_; |
---|
| 147 | |
---|
| 148 | float reloadTime_; |
---|
| 149 | bool bAutoReload_; |
---|
| 150 | bool bParallelReload_; |
---|
| 151 | |
---|
| 152 | float damage_; |
---|
| 153 | Vector3 muzzleOffset_; |
---|
| 154 | |
---|
| 155 | private: |
---|
| 156 | void updateMunition(); |
---|
| 157 | void reloaded(); |
---|
| 158 | |
---|
| 159 | Weapon* weapon_; |
---|
| 160 | unsigned int mode_; |
---|
| 161 | |
---|
| 162 | Munition* munition_; |
---|
| 163 | SubclassIdentifier<Munition> munitiontype_; |
---|
| 164 | std::string munitionname_; |
---|
| 165 | |
---|
[5929] | 166 | Timer reloadTimer_; |
---|
[2918] | 167 | bool bReloading_; |
---|
[6417] | 168 | |
---|
| 169 | Vector3 muzzlePosition_; |
---|
| 170 | Quaternion muzzleOrientation_; |
---|
| 171 | |
---|
| 172 | WorldSound* defSndWpnFire_; |
---|
| 173 | bool bSoundAttached_; |
---|
[2918] | 174 | }; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | #endif /* _WeaponMode_H__ */ |
---|