Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Tutorial_HS19/src/orxonox/weaponsystem/WeaponMode.h @ 12373

Last change on this file since 12373 was 11108, checked in by fvultier, 9 years ago

A few modifications in the weapon system: WeaponModes may play a reload sound now. Fireing Sounds of WeaponModes may overlap now. New weapon: FlameGun, a flame thrower for close combat (e.g. for the FPS player)

  • Property svn:eol-style set to native
File size: 7.4 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 @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, ...
48    */
49    class _OrxonoxExport WeaponMode : public BaseObject
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_;
174            float healthdamage_;
175            float shielddamage_;
176            Vector3 muzzleOffset_;
177
178            std::string hudImageString_;
179
180        private:           
181            void reloaded();
182
183            Weapon* weapon_;
184            unsigned int mode_;
185
186            Munition* munition_;
187            SubclassIdentifier<Munition> munitiontype_;
188            std::string munitionname_;
189
190            Timer reloadTimer_;
191            bool bReloading_; // If true, this weapon mode is marked as reloading.
192
193            Vector3 muzzlePosition_;
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
201            WorldSound* reloadSound_;
202    };
203}
204
205#endif /* _WeaponMode_H__ */
Note: See TracBrowser for help on using the repository browser.