Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2009, 6:14:52 PM (16 years ago)
Author:
landauf
Message:

Added many new features in the Munition class:

  • there are now 3 modes: a) every weapon has it's own magazine b) all weapons use the same magazin c) no magazines, just a big munition pool
  • the Munition class handles the reloading of the magazine

Split the Weapon class into Weapon and WeaponMode. WeaponMode creates the fire of the Weapon. A weapon can own several WeaponModes (for example primary and secondary fire). But it's also possible to have a weapon with several muzzles which all fire at the same time (there's a WeaponMode for each muzzle).

Renamed LaserGun to LaserFire and Fusion to FusionFire. They inherit now from WeaponMode.

Changed the code in the Weapon class to use the new Munition functionality.

Added ReplenishingMunition, a subclass of Munition that replenishes itself (used for LaserGunMunition).

Added a reload command to reload magazines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.h

    r2912 r2918  
    2020 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2121 *
    22  *   Author:
     22 *   Authors:
    2323 *      Martin Polak
     24 *      Fabian 'x3n' Landau
    2425 *   Co-authors:
    2526 *      ...
     
    3132
    3233#include "OrxonoxPrereqs.h"
     34
     35#include <map>
     36
    3337#include "core/BaseObject.h"
     38#include "tools/Timer.h"
    3439
    3540namespace orxonox
     
    3742    class _OrxonoxExport Munition : public BaseObject
    3843    {
     44        struct Magazine
     45        {
     46            public:
     47                Magazine(Munition* munition, bool bUseReloadTime = true);
     48
     49                unsigned int munition_;
     50                Timer<Magazine> loadTimer_;
     51                bool bLoaded_;
     52
     53            private:
     54                void loaded(Munition* munition);
     55        };
     56
    3957        public:
    4058            Munition(BaseObject* creator);
    4159            virtual ~Munition();
    4260
    43             void setMaxBullets(unsigned int amount);
    44             void setMaxMagazines(unsigned int amount);
     61            unsigned int getNumMunition(WeaponMode* user) const;
     62            unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const;
     63            unsigned int getNumMagazines() const;
    4564
    46             void fillBullets();
    47             void fillMagazines();
     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_; }
    4870
    49             unsigned int bullets();
    50             unsigned int magazines();
     71            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
     72            bool takeMunition(unsigned int amount, WeaponMode* user);
    5173
    52             void removeBullets(unsigned int k);
    53             void removeMagazines(unsigned int k);
    54             void addBullets(unsigned int k);
    55             void addMagazines(unsigned int k);
     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_;
    56103
    57104        private:
    58 
    59         protected:
    60             unsigned int bullets_;
    61             unsigned int magazines_;
    62             unsigned int maxBullets_;
    63             unsigned int maxMagazines_;
     105            Magazine* getMagazine(WeaponMode* user) const;
    64106    };
    65107}
Note: See TracChangeset for help on using the changeset viewer.