Orxonox  0.0.5 Codename: Arcturus
WeaponMode.h
Go to the documentation of this file.
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 <vector>
37 #include "util/Math.h"
38 #include "core/BaseObject.h"
40 #include "tools/Timer.h"
41 #include "Munition.h"
42 
43 namespace orxonox
44 {
50  {
51  public:
52  WeaponMode(Context* context);
53  virtual ~WeaponMode();
54 
55  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
56 
57  virtual bool fire(float* reloadTime);
58  bool reload();
59 
60  // Munition
61  inline Munition* getMunition() const
62  { return this->munition_; }
63 
64  void setMunitionType(Identifier* identifier);
65  inline Identifier* getMunitionType() const
66  { return this->munitiontype_; }
67 
68  void setMunitionName(const std::string& munitionname);
69  inline const std::string& getMunitionName() const
70  { return this->munitionname_; }
71 
72  inline void setInitialMunition(unsigned int amount)
73  { this->initialMunition_ = amount; }
74  inline unsigned int getInitialMunition() const
75  { return this->initialMunition_; }
76 
77  inline void setInitialMagazines(unsigned int amount)
78  { this->initialMagazines_ = amount; }
79  inline unsigned int getInitialMagazines() const
80  { return this->initialMagazines_; }
81 
82  inline void setMunitionPerShot(unsigned int amount)
83  { this->munitionPerShot_ = amount; }
84  inline unsigned int getMunitionPerShot() const
85  { return this->munitionPerShot_; }
86 
87 
88  // Reloading
89  inline void setReloadTime(float time)
90  { this->reloadTime_ = time; }
91  inline float getReloadTime() const
92  { return this->reloadTime_; }
93 
94  inline void setAutoReload(bool autoreload)
95  { this->bAutoReload_ = autoreload; }
96  inline bool getAutoReload() const
97  { return this->bAutoReload_; }
98 
99  inline void setParallelReload(bool parallelreload)
100  { this->bParallelReload_ = parallelreload; }
101  inline bool getParallelReload() const
102  { return this->bParallelReload_; }
103  inline bool getReloading() const
104  { return this->bReloading_; }
105 
106 
107  // Fire
108  inline void setDamage(float damage)
109  { this->damage_ = damage;}
110  inline float getDamage() const
111  { return this->damage_; }
112  inline void setHealthDamage(float healthdamage)
113  { this->healthdamage_ = healthdamage; }
114  inline float getHealthDamage() const
115  { return this->healthdamage_; }
116 
117  inline void setShieldDamage(float shielddamage)
118  { this->shielddamage_ = shielddamage;}
119  inline float getShieldDamage() const
120  { return this->shielddamage_; }
121 
122  inline void setMuzzleOffset(const Vector3& offset)
123  { this->muzzleOffset_ = offset; }
124  inline const Vector3& getMuzzleOffset() const
125  { return this->muzzleOffset_; }
126 
127  void computeMuzzleParameters(const Vector3& target);
128  const Vector3& getMuzzlePosition() const
129  { return this->muzzlePosition_; }
130  const Quaternion& getMuzzleOrientation() const
131  { return this->muzzleOrientation_; }
132  Vector3 getMuzzleDirection() const;
133 
134 
135  // Weapon
136  inline void setWeapon(Weapon* weapon)
137  { this->weapon_ = weapon; this->updateMunition(); }
138  inline Weapon* getWeapon() const
139  { return this->weapon_; }
140 
141  inline void setMode(unsigned int mode)
142  { this->mode_ = mode; }
143  inline unsigned int getMode() const
144  { return this->mode_; }
145 
146  Vector3 getTarget();
147 
148  inline const std::string& getHUDImageString() const
149  { return this->hudImageString_; }
150 
151  void updateMunition();
152  protected:
153  // Interacting with the firing sound
154  void setFireSound(const std::string& soundPath, const float soundVolume = 1.0);
155  const std::string& getFireSound();
156  void playFireSound();
157 
158  // Interacting with the reloading sound
159  void setReloadSound(const std::string& soundPath, const float soundVolume = 1.0);
160  const std::string& getReloadSound();
161  void playReloadSound();
162 
163  virtual void fire() = 0;
164 
165  unsigned int initialMunition_;
166  unsigned int initialMagazines_;
167  unsigned int munitionPerShot_;
168 
169  float reloadTime_;
170  bool bAutoReload_; // If true, the weapon reloads the magazine automatically.
171  bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading.
172 
173  float damage_;
176  Vector3 muzzleOffset_;
177 
179 
180  private:
181  void reloaded();
182 
184  unsigned int mode_;
185 
189 
191  bool bReloading_; // If true, this weapon mode is marked as reloading.
192 
194  Quaternion muzzleOrientation_;
195 
196  std::string fireSoundPath_; // The path of the sound played when fireing
197  float fireSoundVolume_; // The volume of the sound played when fireing
198  std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.
199  std::string reloadSoundPath_; // The path of the sound played when reloading
200  float reloadSoundVolume_; // The volume of the sound played when reloading
202  };
203 }
204 
205 #endif /* _WeaponMode_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
Definition of SubclassIdentifier.
bool getReloading() const
Definition: WeaponMode.h:103
void setReloadTime(float time)
Definition: WeaponMode.h:89
void setHealthDamage(float healthdamage)
Definition: WeaponMode.h:112
void setMunitionPerShot(unsigned int amount)
Definition: WeaponMode.h:82
const Quaternion & getMuzzleOrientation() const
Definition: WeaponMode.h:130
The WorldSound class is to be used for sounds with position and orientation.
Definition: WorldSound.h:44
Definition: Munition.h:48
const Vector3 & getMuzzleOffset() const
Definition: WeaponMode.h:124
Vector3 muzzleOffset_
Definition: WeaponMode.h:176
::std::string string
Definition: gtest-port.h:756
std::string reloadSoundPath_
Definition: WeaponMode.h:199
float healthdamage_
Definition: WeaponMode.h:174
void setInitialMunition(unsigned int amount)
Definition: WeaponMode.h:72
void setAutoReload(bool autoreload)
Definition: WeaponMode.h:94
float fireSoundVolume_
Definition: WeaponMode.h:197
unsigned int mode_
Definition: WeaponMode.h:184
unsigned int initialMunition_
Definition: WeaponMode.h:165
const Vector3 & getMuzzlePosition() const
Definition: WeaponMode.h:128
void setWeapon(Weapon *weapon)
Definition: WeaponMode.h:136
void setMode(unsigned int mode)
Definition: WeaponMode.h:141
float shielddamage_
Definition: WeaponMode.h:175
float reloadSoundVolume_
Definition: WeaponMode.h:200
std::string fireSoundPath_
Definition: WeaponMode.h:196
void setDamage(float damage)
Definition: WeaponMode.h:108
float getShieldDamage() const
Definition: WeaponMode.h:119
bool bReloading_
Definition: WeaponMode.h:191
void setShieldDamage(float shielddamage)
Definition: WeaponMode.h:117
Vector3 muzzlePosition_
Definition: WeaponMode.h:193
std::string munitionname_
Definition: WeaponMode.h:188
Munition * getMunition() const
Definition: WeaponMode.h:61
xmlelement
Definition: Super.h:519
Munition * munition_
Definition: WeaponMode.h:186
unsigned int getInitialMagazines() const
Definition: WeaponMode.h:79
const std::string & getHUDImageString() const
Definition: WeaponMode.h:148
A WeaponMode defines how a Weapon is used.
Definition: WeaponMode.h:49
Weapon * weapon_
Definition: WeaponMode.h:183
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
std::string hudImageString_
Definition: WeaponMode.h:178
Declaration of the Timer class, used to call functions after a given time-interval.
bool bAutoReload_
Definition: WeaponMode.h:170
Quaternion muzzleOrientation_
Definition: WeaponMode.h:194
SubclassIdentifier< Munition > munitiontype_
Definition: WeaponMode.h:187
const std::string & getMunitionName() const
Definition: WeaponMode.h:69
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
bool getParallelReload() const
Definition: WeaponMode.h:101
unsigned int getMode() const
Definition: WeaponMode.h:143
void setMuzzleOffset(const Vector3 &offset)
Definition: WeaponMode.h:122
Mode
Definition: CorePrereqs.h:102
A Weapon is a StaticEntity that can be attached to a WeaponSlot.
Definition: Weapon.h:46
The Identifier is used to identify the class of an object and to store information about the class...
Definition: Identifier.h:109
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Identifier * getMunitionType() const
Definition: WeaponMode.h:65
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
float getDamage() const
Definition: WeaponMode.h:110
float getHealthDamage() const
Definition: WeaponMode.h:114
Timer reloadTimer_
Definition: WeaponMode.h:190
std::vector< WorldSound * > fireSounds_
Definition: WeaponMode.h:198
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
unsigned int initialMagazines_
Definition: WeaponMode.h:166
bool bParallelReload_
Definition: WeaponMode.h:171
float getReloadTime() const
Definition: WeaponMode.h:91
unsigned int getInitialMunition() const
Definition: WeaponMode.h:74
void setParallelReload(bool parallelreload)
Definition: WeaponMode.h:99
bool getAutoReload() const
Definition: WeaponMode.h:96
float damage_
Definition: WeaponMode.h:173
Timer is a helper class that executes a function after a given amount of seconds in game-time...
Definition: Timer.h:105
void setInitialMagazines(unsigned int amount)
Definition: WeaponMode.h:77
The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
Definition: SubclassIdentifier.h:90
Weapon * getWeapon() const
Definition: WeaponMode.h:138
unsigned int getMunitionPerShot() const
Definition: WeaponMode.h:84
WorldSound * reloadSound_
Definition: WeaponMode.h:201
float reloadTime_
Definition: WeaponMode.h:169
unsigned int munitionPerShot_
Definition: WeaponMode.h:167