[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: |
---|
| 26 | * ... |
---|
| 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 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[10713] | 41 | namespace MunitionDeployment |
---|
[10688] | 42 | { |
---|
[10713] | 43 | enum Value |
---|
| 44 | { |
---|
| 45 | Share, |
---|
| 46 | Stack, |
---|
| 47 | Separate |
---|
| 48 | }; |
---|
| 49 | } |
---|
[10688] | 50 | |
---|
[2049] | 51 | class _OrxonoxExport Munition : public BaseObject |
---|
[10688] | 52 | { |
---|
[2918] | 53 | struct Magazine |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | Magazine(Munition* munition, bool bUseReloadTime = true); |
---|
[7851] | 57 | virtual ~Magazine() {} |
---|
[2918] | 58 | |
---|
| 59 | unsigned int munition_; |
---|
[5929] | 60 | Timer loadTimer_; |
---|
[2918] | 61 | bool bLoaded_; |
---|
| 62 | |
---|
| 63 | private: |
---|
| 64 | void loaded(Munition* munition); |
---|
| 65 | }; |
---|
| 66 | |
---|
[2049] | 67 | public: |
---|
[9667] | 68 | Munition(Context* context); |
---|
[2049] | 69 | virtual ~Munition(); |
---|
| 70 | |
---|
[2918] | 71 | unsigned int getNumMunition(WeaponMode* user) const; |
---|
| 72 | unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const; |
---|
| 73 | unsigned int getNumMagazines() const; |
---|
[2049] | 74 | |
---|
[2918] | 75 | unsigned int getMaxMunition() const; |
---|
| 76 | inline unsigned int getMaxMagazines() const |
---|
| 77 | { return this->maxMagazines_; } |
---|
| 78 | inline unsigned int getMaxMunitionPerMagazine() const |
---|
| 79 | { return this->maxMunitionPerMagazine_; } |
---|
[10688] | 80 | inline bool getUseSeparateMagazines() const |
---|
[10713] | 81 | { return deployment_ == MunitionDeployment::Separate; } |
---|
[10688] | 82 | inline bool getStackMunition() const |
---|
[10713] | 83 | { return deployment_ == MunitionDeployment::Stack; } |
---|
[2662] | 84 | |
---|
[2918] | 85 | bool canTakeMunition(unsigned int amount, WeaponMode* user) const; |
---|
| 86 | bool takeMunition(unsigned int amount, WeaponMode* user); |
---|
[2662] | 87 | |
---|
[2918] | 88 | bool canReload() const; |
---|
| 89 | bool needReload(WeaponMode* user) const; |
---|
| 90 | bool reload(WeaponMode* user, bool bUseReloadTime = true); |
---|
| 91 | inline float getReloadTime() const |
---|
| 92 | { return this->reloadTime_; } |
---|
[2662] | 93 | |
---|
[2918] | 94 | bool canAddMunition(unsigned int amount) const; |
---|
| 95 | bool addMunition(unsigned int amount); |
---|
[2049] | 96 | |
---|
[2918] | 97 | bool canAddMagazines(unsigned int amount) const; |
---|
| 98 | bool addMagazines(unsigned int amount); |
---|
| 99 | |
---|
| 100 | bool canRemoveMagazines(unsigned int amount) const; |
---|
| 101 | bool removeMagazines(unsigned int amount); |
---|
| 102 | |
---|
| 103 | bool dropMagazine(WeaponMode* user); |
---|
| 104 | |
---|
[2662] | 105 | protected: |
---|
[2918] | 106 | unsigned int maxMunitionPerMagazine_; |
---|
| 107 | unsigned int maxMagazines_; |
---|
[2662] | 108 | unsigned int magazines_; |
---|
[10713] | 109 | std::map<WeaponMode*, Magazine*> currentMagazines_; // Maps weapon modes to magazines that are currently used. |
---|
[2918] | 110 | |
---|
[10713] | 111 | MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes. |
---|
[10688] | 112 | |
---|
[2918] | 113 | bool bAllowMunitionRefilling_; |
---|
| 114 | bool bAllowMultiMunitionRemovementUnderflow_; |
---|
| 115 | |
---|
| 116 | float reloadTime_; |
---|
[10713] | 117 | WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition. |
---|
[2918] | 118 | |
---|
| 119 | private: |
---|
| 120 | Magazine* getMagazine(WeaponMode* user) const; |
---|
[2049] | 121 | }; |
---|
| 122 | } |
---|
| 123 | |
---|
[2106] | 124 | #endif /* _Munition_H__ */ |
---|