Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/Presentation_FS16/src/orxonox/weaponsystem/WeaponMode.h @ 11642

Last change on this file since 11642 was 11208, checked in by fvultier, 9 years ago

merged discharger, thats the last one

  • Property svn:eol-style set to native
File size: 8.5 KB
Line 
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 *      Johannes Sager
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"
39#include "core/class/SubclassIdentifier.h"
40#include "tools/Timer.h"
41#include "Munition.h"
42
43namespace orxonox
44{
45    /**
46    @brief
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, ...
50    */
51    class _OrxonoxExport WeaponMode : public BaseObject
52    {
53        public:
54            WeaponMode(Context* context);
55            virtual ~WeaponMode();
56
57            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
58
59            virtual bool push(float* reloadTime);
60            virtual bool release(float* reloadTime);
61            virtual bool fire(float* reloadTime);
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_; }
107            inline bool getReloading() const
108                { return this->bReloading_; }
109
110
111            // Fire
112            inline unsigned int getMaxCharges()                 // get the maximum of charges one can have
113                { return this->maxCharges_;}
114            inline unsigned int getCharges()                    // get the current amount of charges
115                { return this->charges_;}
116            inline bool isChargeable()                          // returns if the weaponmode is chargeable
117                { return this->chargeable_;}
118            inline void setDamage(float damage)
119                { this->damage_ = damage;}
120            inline float getDamage() const
121                { return this->damage_; }
122            inline void setHealthDamage(float healthdamage)
123                { this->healthdamage_ = healthdamage; }
124            inline float getHealthDamage() const
125                { return this->healthdamage_; }
126
127            inline void setShieldDamage(float shielddamage)
128                { this->shielddamage_ = shielddamage;}
129            inline float getShieldDamage() const
130                { return this->shielddamage_; }
131
132            inline void setMuzzleOffset(const Vector3& offset)
133                { this->muzzleOffset_ = offset; }
134            inline const Vector3& getMuzzleOffset() const
135                { return this->muzzleOffset_; }
136
137            void computeMuzzleParameters(const Vector3& target);
138            const Vector3& getMuzzlePosition() const
139                { return this->muzzlePosition_; }
140            const Quaternion& getMuzzleOrientation() const
141                { return this->muzzleOrientation_; }
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
156            Vector3 getTarget();
157
158            inline const std::string& getHUDImageString() const
159                { return this->hudImageString_; }           
160
161            void updateMunition();
162        protected:
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
173            virtual void fire() = 0;
174
175            unsigned int initialMunition_;
176            unsigned int initialMagazines_;
177            unsigned int munitionPerShot_;
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)
180
181            float reloadTime_;
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
185
186            float damage_;
187            float healthdamage_;
188            float shielddamage_;
189            Vector3 muzzleOffset_;
190
191            std::string hudImageString_;
192
193        private:           
194            void reloaded();
195
196            Weapon* weapon_;
197            unsigned int mode_;
198
199            Munition* munition_;
200            SubclassIdentifier<Munition> munitiontype_;
201            std::string munitionname_;
202
203            Timer reloadTimer_;
204            bool bReloading_;                       // If true, this weapon mode is marked as reloading.
205
206            Vector3 muzzlePosition_;
207            Quaternion muzzleOrientation_;
208
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
214            WorldSound* reloadSound_;
215    };
216}
217
218#endif /* _WeaponMode_H__ */
Note: See TracBrowser for help on using the repository browser.