Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai2/src/orxonox/weaponsystem/Munition.h @ 8741

Last change on this file since 8741 was 7851, checked in by landauf, 14 years ago

added "safe mode" feature to FunctorMember: if enabled, the functor acts like a WeakPtr and sets the object-pointer to NULL if the object is deleted, hence the functor can not be executed anymore and instead prints an error message. safe mode is _disabled_ by default.

enabled safe mode for timers

To implement safe mode, FunctorMember<void> (= FunctorStatic) was spezialized and implemented differently. Additionally functors now work only with polymorphic objects due to a dynamic cast, hence XMLPortVariableHelperClass and Magazine got a virtual destructor.

  • Property svn:eol-style set to native
File size: 3.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 *   Authors:
23 *      Martin Polak
24 *      Fabian 'x3n' Landau
25 *   Co-authors:
26 *      ...
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
39namespace orxonox
40{
41    class _OrxonoxExport Munition : public BaseObject
42    {
43        struct Magazine
44        {
45            public:
46                Magazine(Munition* munition, bool bUseReloadTime = true);
47                virtual ~Magazine() {}
48
49                unsigned int munition_;
50                Timer loadTimer_;
51                bool bLoaded_;
52
53            private:
54                void loaded(Munition* munition);
55        };
56
57        public:
58            Munition(BaseObject* creator);
59            virtual ~Munition();
60
61            unsigned int getNumMunition(WeaponMode* user) const;
62            unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const;
63            unsigned int getNumMagazines() const;
64
65            unsigned int getMaxMunition() const;
66            inline unsigned int getMaxMagazines() const
67                { return this->maxMagazines_; }
68            inline unsigned int getMaxMunitionPerMagazine() const
69                { return this->maxMunitionPerMagazine_; }
70
71            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
72            bool takeMunition(unsigned int amount, WeaponMode* user);
73
74            bool canReload() const;
75            bool needReload(WeaponMode* user) const;
76            bool reload(WeaponMode* user, bool bUseReloadTime = true);
77            inline float getReloadTime() const
78                { return this->reloadTime_; }
79
80            bool canAddMunition(unsigned int amount) const;
81            bool addMunition(unsigned int amount);
82
83            bool canAddMagazines(unsigned int amount) const;
84            bool addMagazines(unsigned int amount);
85
86            bool canRemoveMagazines(unsigned int amount) const;
87            bool removeMagazines(unsigned int amount);
88
89            bool dropMagazine(WeaponMode* user);
90
91        protected:
92            unsigned int maxMunitionPerMagazine_;
93            unsigned int maxMagazines_;
94            unsigned int magazines_;
95            std::map<WeaponMode*, Magazine*> currentMagazines_;
96
97            bool bUseSeparateMagazines_;
98            bool bStackMunition_;
99            bool bAllowMunitionRefilling_;
100            bool bAllowMultiMunitionRemovementUnderflow_;
101
102            float reloadTime_;
103
104        private:
105            Magazine* getMagazine(WeaponMode* user) const;
106    };
107}
108
109#endif /* _Munition_H__ */
Note: See TracBrowser for help on using the repository browser.