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: |
---|
26 | * ... |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef _WeaponMode_H__ |
---|
31 | #define _WeaponMode_H__ |
---|
32 | |
---|
33 | #include "OrxonoxPrereqs.h" |
---|
34 | |
---|
35 | #include <string> |
---|
36 | #include "util/Math.h" |
---|
37 | #include "core/BaseObject.h" |
---|
38 | #include "core/class/SubclassIdentifier.h" |
---|
39 | #include "tools/Timer.h" |
---|
40 | #include "Munition.h" |
---|
41 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | /** |
---|
45 | @brief |
---|
46 | A WeaponMode defines how a Weapon is used. It specifies what kind of @ref orxonox::Projectile is created when you fire it, how much time it takes to reload, what sound you hear while shooting, how much damage the projectile deals to a target, ... |
---|
47 | */ |
---|
48 | class _OrxonoxExport WeaponMode : public BaseObject |
---|
49 | { |
---|
50 | public: |
---|
51 | WeaponMode(Context* context); |
---|
52 | virtual ~WeaponMode(); |
---|
53 | |
---|
54 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
55 | |
---|
56 | bool fire(float* reloadTime); |
---|
57 | bool reload(); |
---|
58 | |
---|
59 | // Interacting with the default Firing sound |
---|
60 | void setDefaultSound(const std::string& soundPath); |
---|
61 | const std::string& getDefaultSound(); |
---|
62 | void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume); |
---|
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 | inline bool getReloading() const |
---|
108 | { return this->bReloading_; } |
---|
109 | |
---|
110 | |
---|
111 | // Fire |
---|
112 | inline void setDamage(float damage) |
---|
113 | { this->damage_ = damage;} |
---|
114 | inline float getDamage() const |
---|
115 | { return this->damage_; } |
---|
116 | inline void setHealthDamage(float healthdamage) |
---|
117 | { this->healthdamage_ = healthdamage; } |
---|
118 | inline float getHealthDamage() const |
---|
119 | { return this->healthdamage_; } |
---|
120 | |
---|
121 | inline void setShieldDamage(float shielddamage) |
---|
122 | { this->shielddamage_ = shielddamage;} |
---|
123 | inline float getShieldDamage() const |
---|
124 | { return this->shielddamage_; } |
---|
125 | |
---|
126 | inline void setMuzzleOffset(const Vector3& offset) |
---|
127 | { this->muzzleOffset_ = offset; } |
---|
128 | inline const Vector3& getMuzzleOffset() const |
---|
129 | { return this->muzzleOffset_; } |
---|
130 | |
---|
131 | void computeMuzzleParameters(const Vector3& target); |
---|
132 | const Vector3& getMuzzlePosition() const |
---|
133 | { return this->muzzlePosition_; } |
---|
134 | const Quaternion& getMuzzleOrientation() const |
---|
135 | { return this->muzzleOrientation_; } |
---|
136 | Vector3 getMuzzleDirection() const; |
---|
137 | |
---|
138 | |
---|
139 | // Weapon |
---|
140 | inline void setWeapon(Weapon* weapon) |
---|
141 | { this->weapon_ = weapon; this->updateMunition(); } |
---|
142 | inline Weapon* getWeapon() const |
---|
143 | { return this->weapon_; } |
---|
144 | |
---|
145 | inline void setMode(unsigned int mode) |
---|
146 | { this->mode_ = mode; } |
---|
147 | inline unsigned int getMode() const |
---|
148 | { return this->mode_; } |
---|
149 | |
---|
150 | Vector3 getTarget(); |
---|
151 | |
---|
152 | inline const std::string& getHUDImageString() const |
---|
153 | { return this->hudImageString_; } |
---|
154 | |
---|
155 | void updateMunition(); |
---|
156 | protected: |
---|
157 | virtual void fire() = 0; |
---|
158 | |
---|
159 | unsigned int initialMunition_; |
---|
160 | unsigned int initialMagazines_; |
---|
161 | unsigned int munitionPerShot_; |
---|
162 | |
---|
163 | float reloadTime_; |
---|
164 | bool bAutoReload_; // If true, the weapon reloads the magazine automatically. |
---|
165 | bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. |
---|
166 | |
---|
167 | float damage_; |
---|
168 | float healthdamage_; |
---|
169 | float shielddamage_; |
---|
170 | Vector3 muzzleOffset_; |
---|
171 | |
---|
172 | std::string hudImageString_; |
---|
173 | |
---|
174 | private: |
---|
175 | void reloaded(); |
---|
176 | |
---|
177 | Weapon* weapon_; |
---|
178 | unsigned int mode_; |
---|
179 | |
---|
180 | Munition* munition_; |
---|
181 | SubclassIdentifier<Munition> munitiontype_; |
---|
182 | std::string munitionname_; |
---|
183 | |
---|
184 | Timer reloadTimer_; |
---|
185 | bool bReloading_; // If true, this weapon mode is marked as reloading. |
---|
186 | |
---|
187 | Vector3 muzzlePosition_; |
---|
188 | Quaternion muzzleOrientation_; |
---|
189 | |
---|
190 | WorldSound* defSndWpnFire_; |
---|
191 | bool bSoundAttached_; |
---|
192 | }; |
---|
193 | } |
---|
194 | |
---|
195 | #endif /* _WeaponMode_H__ */ |
---|