Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sagerjFS16/src/orxonox/weaponsystem/WeaponMode.h @ 11174

Last change on this file since 11174 was 11174, checked in by sagerj, 8 years ago

everything beneath weaponmode changed to push/release - wm modified only need to implement timer/ticker

  • Property svn:eol-style set to native
File size: 7.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 *      ...
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 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            // Interacting with the firing sound
158            void setFireSound(const std::string& soundPath, const float soundVolume = 1.0);
159            const std::string& getFireSound();
160            void playFireSound();
161
162            // Interacting with the reloading sound
163            void setReloadSound(const std::string& soundPath, const float soundVolume = 1.0);
164            const std::string& getReloadSound();
165            void playReloadSound();
166
167            virtual void fire() = 0;
168
169            unsigned int initialMunition_;
170            unsigned int initialMagazines_;
171            unsigned int munitionPerShot_;
172
173            float reloadTime_;
174            bool bAutoReload_; // If true, the weapon reloads the magazine automatically.
175            bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading.
176
177            float damage_;
178            float healthdamage_;
179            float shielddamage_;
180            Vector3 muzzleOffset_;
181
182            std::string hudImageString_;
183
184        private:           
185            void reloaded();
186
187            Weapon* weapon_;
188            unsigned int mode_;
189
190            Munition* munition_;
191            SubclassIdentifier<Munition> munitiontype_;
192            std::string munitionname_;
193
194            Timer reloadTimer_;
195            bool bReloading_; // If true, this weapon mode is marked as reloading.
196
197            Vector3 muzzlePosition_;
198            Quaternion muzzleOrientation_;
199
200            std::string fireSoundPath_; // The path of the sound played when fireing
201            float fireSoundVolume_; // The volume of the sound played when fireing
202            std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.
203            std::string reloadSoundPath_; // The path of the sound played when reloading
204            float reloadSoundVolume_; // The volume of the sound played when reloading
205            WorldSound* reloadSound_;
206    };
207}
208
209#endif /* _WeaponMode_H__ */
Note: See TracBrowser for help on using the repository browser.