Orxonox  0.0.5 Codename: Arcturus
Munition.h
Go to the documentation of this file.
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  * Authors:
23  * Martin Polak
24  * Fabian 'x3n' Landau
25  * Co-authors:
26  * Fabien Vultier
27  *
28  */
29 
30 #ifndef _Munition_H__
31 #define _Munition_H__
32 
33 #include "OrxonoxPrereqs.h"
34 
35 #include <map>
36 #include "core/BaseObject.h"
37 #include "tools/Timer.h"
38 
39 namespace orxonox
40 {
41  enum class MunitionDeployment
42  {
43  Separate, // Every comsuming weapon mode has its own magazine. It is possible that one weapon mode is out of ammo while another still has some.
44  Share, // All comsuming weapon modes take their munition from the same magazine. If this magazine is empty a new one is loaded.
45  Stack // There is only one magazine where all the munition is stored. Use this deployment mode for heavy weapons loke rockets, bombs, ...
46  };
47 
49  {
50  struct Magazine
51  {
52  public:
53  Magazine(Munition* munition, bool bUseReloadTime = true);
54  virtual ~Magazine() {}
55 
56  unsigned int munition_;
58  bool bLoaded_;
59 
60  private:
61  void loaded(Munition* munition);
62  };
63 
64  public:
65  Munition(Context* context);
66  virtual ~Munition();
67 
68  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
69 
70  unsigned int getNumMunition(WeaponMode* user) const;
71  unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const;
72  unsigned int getNumMagazines() const;
73 
74  unsigned int getMaxMunition() const;
75  inline unsigned int getMaxMagazines() const
76  { return this->maxMagazines_; }
77  inline unsigned int getMaxMunitionPerMagazine() const
78  { return this->maxMunitionPerMagazine_; }
80  { return deployment_; }
81 
82 
83  bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
84  bool takeMunition(unsigned int amount, WeaponMode* user);
85 
86  bool canReload() const;
87  bool needReload(WeaponMode* user) const;
88  bool reload(WeaponMode* user, bool bUseReloadTime = true);
89  inline float getReloadTime() const
90  { return this->reloadTime_; }
91 
92  bool canAddMunition(unsigned int amount) const;
93  bool addMunition(unsigned int amount);
94 
95  bool canAddMagazines(unsigned int amount) const;
101  unsigned int addMagazines(unsigned int amount);
102 
103  bool canRemoveMagazines(unsigned int amount) const;
104  bool removeMagazines(unsigned int amount);
105 
106  bool dropMagazine(WeaponMode* user);
107 
108  protected:
110  unsigned int maxMagazines_;
111  unsigned int unassignedMagazines_; // Number of magazines that are not assigned to a weapon mode. These are alway treated as full.
112  std::map<WeaponMode*, Magazine*> assignedMagazines_; // Maps weapon modes to magazines that are currently used.
113 
114  MunitionDeployment deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes.
115 
118 
119  float reloadTime_; // The time needed to replace a magazine by a new one.
120  WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition.
121 
122  private:
123  Magazine* getMagazine(WeaponMode* user) const;
124  inline void setMaxMagazines(unsigned int maxMagazines)
125  { this->maxMagazines_ = maxMagazines; }
126  inline void setMaxMunitionPerMagazine(unsigned int maxMunitionPerMagazine)
127  { this->maxMunitionPerMagazine_ = maxMunitionPerMagazine; }
128  void setNumMagazines(unsigned int numMagazines);
129  };
130 }
131 
132 #endif /* _Munition_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
MunitionDeployment getMunitionDeployment() const
Definition: Munition.h:79
MunitionDeployment deployment_
Definition: Munition.h:114
unsigned int munition_
Definition: Munition.h:56
Definition: Munition.h:48
void setMaxMagazines(unsigned int maxMagazines)
Definition: Munition.h:124
Definition: Munition.h:50
bool bLoaded_
Definition: Munition.h:58
bool bAllowMunitionRefilling_
Definition: Munition.h:116
Timer loadTimer_
Definition: Munition.h:57
void setMaxMunitionPerMagazine(unsigned int maxMunitionPerMagazine)
Definition: Munition.h:126
xmlelement
Definition: Super.h:519
A WeaponMode defines how a Weapon is used.
Definition: WeaponMode.h:49
Declaration of the Timer class, used to call functions after a given time-interval.
unsigned int maxMagazines_
Definition: Munition.h:110
MunitionDeployment
Definition: Munition.h:41
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
unsigned int maxMunitionPerMagazine_
Definition: Munition.h:109
Mode
Definition: CorePrereqs.h:102
unsigned int getMaxMagazines() const
Definition: Munition.h:75
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Declaration of BaseObject, the base class of all objects in Orxonox.
virtual ~Magazine()
Definition: Munition.h:54
std::map< WeaponMode *, Magazine * > assignedMagazines_
Definition: Munition.h:112
Definition: Context.h:45
unsigned int unassignedMagazines_
Definition: Munition.h:111
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
bool bAllowMultiMunitionRemovementUnderflow_
Definition: Munition.h:117
float getReloadTime() const
Definition: Munition.h:89
float reloadTime_
Definition: Munition.h:119
unsigned int getMaxMunitionPerMagazine() const
Definition: Munition.h:77
Timer is a helper class that executes a function after a given amount of seconds in game-time...
Definition: Timer.h:105
WeaponMode * lastFilledWeaponMode_
Definition: Munition.h:120