Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/weaponsystem/Munition.h @ 11661

Last change on this file since 11661 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[2049]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 *
[2918]22 *   Authors:
[2049]23 *      Martin Polak
[2918]24 *      Fabian 'x3n' Landau
[2049]25 *   Co-authors:
[11052]26 *      Fabien Vultier
[2049]27 *
28 */
29
30#ifndef _Munition_H__
31#define _Munition_H__
32
33#include "OrxonoxPrereqs.h"
[2918]34
35#include <map>
[2049]36#include "core/BaseObject.h"
[2918]37#include "tools/Timer.h"
[2049]38
39namespace orxonox
40{
[11071]41    enum class MunitionDeployment
[11052]42    {
[11071]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    };
[11052]47
[2049]48    class _OrxonoxExport Munition : public BaseObject
[11052]49    {       
[2918]50        struct Magazine
51        {
52            public:
53                Magazine(Munition* munition, bool bUseReloadTime = true);
[7851]54                virtual ~Magazine() {}
[2918]55
56                unsigned int munition_;
[5929]57                Timer loadTimer_;
[2918]58                bool bLoaded_;
59
60            private:
61                void loaded(Munition* munition);
62        };
63
[2049]64        public:
[9667]65            Munition(Context* context);
[2049]66            virtual ~Munition();
67
[11071]68            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
[11052]69
[2918]70            unsigned int getNumMunition(WeaponMode* user) const;
71            unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const;
72            unsigned int getNumMagazines() const;
[2049]73
[2918]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_; }
[11071]79            inline MunitionDeployment getMunitionDeployment() const
[11052]80                { return deployment_; }
[2662]81
[11052]82
[2918]83            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
84            bool takeMunition(unsigned int amount, WeaponMode* user);
[2662]85
[2918]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_; }
[2662]91
[2918]92            bool canAddMunition(unsigned int amount) const;
93            bool addMunition(unsigned int amount);
[2049]94
[2918]95            bool canAddMagazines(unsigned int amount) const;
[11052]96            /**
97            @brief Try to add magazines.
98            @param amount The amount of magazines tried to add.
99            @return The amount of magazines sucessfully added.
100            */
101            unsigned int addMagazines(unsigned int amount);
[2918]102
103            bool canRemoveMagazines(unsigned int amount) const;
104            bool removeMagazines(unsigned int amount);
105
106            bool dropMagazine(WeaponMode* user);
107
[2662]108        protected:
[2918]109            unsigned int maxMunitionPerMagazine_;
110            unsigned int maxMagazines_;
[11052]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.
[2918]113
[11071]114            MunitionDeployment deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes.
[11052]115
[2918]116            bool bAllowMunitionRefilling_;
117            bool bAllowMultiMunitionRemovementUnderflow_;
118
[11052]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.
[2918]121
122        private:
123            Magazine* getMagazine(WeaponMode* user) const;
[11052]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);
[2049]129    };
130}
131
[2106]132#endif /* _Munition_H__ */
Note: See TracBrowser for help on using the repository browser.