Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

first commit, added discharger weaponclass

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