Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added orxout() for every release lvl for debug purpose

  • 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 fire(float* reloadTime);
60            virtual void release(float* reloadTime);
61            bool reload();
62
63            // Munition
64            inline Munition* getMunition() const
65                { return this->munition_; }
66
67            void setMunitionType(Identifier* identifier);
68            inline Identifier* getMunitionType() const
69                { return this->munitiontype_; }
70
71            void setMunitionName(const std::string& munitionname);
72            inline const std::string& getMunitionName() const
73                { return this->munitionname_; }
74
75            inline void setInitialMunition(unsigned int amount)
76                { this->initialMunition_ = amount; }
77            inline unsigned int getInitialMunition() const
78                { return this->initialMunition_; }
79
80            inline void setInitialMagazines(unsigned int amount)
81                { this->initialMagazines_ = amount; }
82            inline unsigned int getInitialMagazines() const
83                { return this->initialMagazines_; }
84
85            inline void setMunitionPerShot(unsigned int amount)
86                { this->munitionPerShot_ = amount; }
87            inline unsigned int getMunitionPerShot() const
88                { return this->munitionPerShot_; }
89
90
91            // Reloading
92            inline void setReloadTime(float time)
93                { this->reloadTime_ = time; }
94            inline float getReloadTime() const
95                { return this->reloadTime_; }
96
97            inline void setAutoReload(bool autoreload)
98                { this->bAutoReload_ = autoreload; }
99            inline bool getAutoReload() const
100                { return this->bAutoReload_; }
101
102            inline void setParallelReload(bool parallelreload)
103                { this->bParallelReload_ = parallelreload; }
104            inline bool getParallelReload() const
105                { return this->bParallelReload_; }
106            inline bool getReloading() const
107                { return this->bReloading_; }
108
109
110            // Fire
111            inline void setDamage(float damage)
112                { this->damage_ = damage;}
113            inline float getDamage() const
114                { return this->damage_; }
115            inline void setHealthDamage(float healthdamage)
116                { this->healthdamage_ = healthdamage; }
117            inline float getHealthDamage() const
118                { return this->healthdamage_; }
119
120            inline void setShieldDamage(float shielddamage)
121                { this->shielddamage_ = shielddamage;}
122            inline float getShieldDamage() const
123                { return this->shielddamage_; }
124
125            inline void setMuzzleOffset(const Vector3& offset)
126                { this->muzzleOffset_ = offset; }
127            inline const Vector3& getMuzzleOffset() const
128                { return this->muzzleOffset_; }
129
130            void computeMuzzleParameters(const Vector3& target);
131            const Vector3& getMuzzlePosition() const
132                { return this->muzzlePosition_; }
133            const Quaternion& getMuzzleOrientation() const
134                { return this->muzzleOrientation_; }
135            Vector3 getMuzzleDirection() const;
136
137
138            // Weapon
139            inline void setWeapon(Weapon* weapon)
140                { this->weapon_ = weapon; this->updateMunition(); }
141            inline Weapon* getWeapon() const
142                { return this->weapon_; }
143
144            inline void setMode(unsigned int mode)
145                { this->mode_ = mode; }
146            inline unsigned int getMode() const
147                { return this->mode_; }
148
149            Vector3 getTarget();
150
151            inline const std::string& getHUDImageString() const
152                { return this->hudImageString_; }           
153
154            void updateMunition();
155        protected:
156            // Interacting with the firing sound
157            void setFireSound(const std::string& soundPath, const float soundVolume = 1.0);
158            const std::string& getFireSound();
159            void playFireSound();
160
161            // Interacting with the reloading sound
162            void setReloadSound(const std::string& soundPath, const float soundVolume = 1.0);
163            const std::string& getReloadSound();
164            void playReloadSound();
165
166            virtual void fire() = 0;
167
168            unsigned int initialMunition_;
169            unsigned int initialMagazines_;
170            unsigned int munitionPerShot_;
171
172            float reloadTime_;
173            bool bAutoReload_; // If true, the weapon reloads the magazine automatically.
174            bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading.
175
176            float damage_;
177            float healthdamage_;
178            float shielddamage_;
179            Vector3 muzzleOffset_;
180
181            std::string hudImageString_;
182
183        private:           
184            void reloaded();
185
186            Weapon* weapon_;
187            unsigned int mode_;
188
189            Munition* munition_;
190            SubclassIdentifier<Munition> munitiontype_;
191            std::string munitionname_;
192
193            Timer reloadTimer_;
194            bool bReloading_; // If true, this weapon mode is marked as reloading.
195
196            Vector3 muzzlePosition_;
197            Quaternion muzzleOrientation_;
198
199            std::string fireSoundPath_; // The path of the sound played when fireing
200            float fireSoundVolume_; // The volume of the sound played when fireing
201            std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.
202            std::string reloadSoundPath_; // The path of the sound played when reloading
203            float reloadSoundVolume_; // The volume of the sound played when reloading
204            WorldSound* reloadSound_;
205    };
206}
207
208#endif /* _WeaponMode_H__ */
Note: See TracBrowser for help on using the repository browser.