Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 9, 2015, 5:55:42 PM (9 years ago)
Author:
fvultier
Message:

Munition may and must now be defined for each pawn separately. This way a heavy cruiser may carry more munition than a drone.

Location:
code/branches/fabienHS15/src/orxonox/weaponsystem
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc

    r10724 r10791  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Fabien Vultier
    2727 *
    2828 */
     
    3232#include "core/CoreIncludes.h"
    3333#include "core/command/Executor.h"
     34#include "core/XMLPort.h"
    3435
    3536namespace orxonox
     
    5859        for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
    5960            delete it->second;
     61    }
     62
     63    void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     64    {
     65        SUPER(Munition, XMLPort, xmlelement, mode);
     66
     67        XMLPortParam(Munition, "initialmagazines", setNumMagazines, getNumMagazines, xmlelement, mode);
     68        XMLPortParam(Munition, "maxmagazines", setMaxMagazines, getMaxMagazines, xmlelement, mode);
     69        XMLPortParam(Munition, "munitionpermagazine", setMaxMunitionPerMagazine, getMaxMunitionPerMagazine, xmlelement, mode);
    6070    }
    6171
     
    121131    }
    122132
     133    void Munition::setNumMagazines(unsigned int numMagazines)
     134    {
     135        this->magazines_ = numMagazines;
     136    }
     137
    123138    unsigned int Munition::getMaxMunition() const
    124139    {
     
    138153            // If we stack munition, we don't care about the current magazine - we just need enough munition in total
    139154            if (deployment_ == MunitionDeployment::Stack)
     155            {
    140156                munition += this->maxMunitionPerMagazine_ * this->magazines_;
     157            }
    141158
    142159            if (munition == 0)
     160            {
    143161                // Absolutely no munition - no chance to take munition
    144162                return false;
     163            }
    145164            else if (this->bAllowMultiMunitionRemovementUnderflow_)
     165            {
    146166                // We're not empty AND we allow underflow, so this will always work
    147167                return true;
     168            }
    148169            else
     170            {
    149171                // We don't allow underflow, so we have to check the amount
    150172                return (munition >= amount);
     173            }
     174
    151175        }
    152176        return false;
     
    200224    {
    201225        // As long as we have enough magazines (and don't stack munition) we can reload
    202         return (this->magazines_ > 0 && !deployment_ == MunitionDeployment::Stack);
     226        return (this->magazines_ > 0 && deployment_ != MunitionDeployment::Stack);
    203227    }
    204228
     
    236260
    237261        // If we don't use separate magazines, set user to 0
    238         if (!deployment_ == MunitionDeployment::Separate)
    239             user = 0;
     262        if (deployment_ != MunitionDeployment::Separate)
     263        {
     264            user = NULL;
     265        }
    240266
    241267        // Remove the current magazine for the given user
     
    289315        {
    290316            // Stacking munition means, if a magazine gets full, the munition adds to a new magazine
    291             Magazine* magazine = this->getMagazine(0);
     317            Magazine* magazine = this->getMagazine(NULL);
    292318            if (magazine)
    293319            {
     
    386412
    387413        // If zero or less magazines are needed, we definitively don't need more magazines (unless we stack munition - then a magazine contributes directly to the munition)
    388         if (needed_magazines <= 0 && !deployment_ == MunitionDeployment::Stack)
     414        if (needed_magazines <= 0 && deployment_ != MunitionDeployment::Stack)
    389415            return false;
    390416
     
    470496
    471497        // If we don't use separate magazines, set user to 0
    472         if (!deployment_ == MunitionDeployment::Separate)
    473             user = 0;
     498        if (deployment_ != MunitionDeployment::Separate)
     499            user = NULL;
    474500
    475501        // Remove the current magazine for the given user
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h

    r10724 r10791  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Fabien Vultier
    2727 *
    2828 */
     
    6868            Munition(Context* context);
    6969            virtual ~Munition();
     70
     71            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    7072
    7173            unsigned int getNumMunition(WeaponMode* user) const;
     
    118120        private:
    119121            Magazine* getMagazine(WeaponMode* user) const;
     122            inline void setMaxMagazines(unsigned int maxMagazines)
     123                { this->maxMagazines_ = maxMagazines; }
     124            inline void setMaxMunitionPerMagazine(unsigned int maxMunitionPerMagazine)
     125                { this->maxMunitionPerMagazine_ = maxMunitionPerMagazine; }
     126            void setNumMagazines(unsigned int numMagazines);
    120127    };
    121128}
  • code/branches/fabienHS15/src/orxonox/weaponsystem/ReplenishingMunition.cc

    r10688 r10791  
    3636#include "core/CoreIncludes.h"
    3737#include "core/command/Executor.h"
     38#include "core/XMLPort.h"
    3839
    3940namespace orxonox
     
    4647
    4748        this->replenishInterval_ = 1.0f;
    48         this->replenishMunitionAmount_ = 1;
     49        this->replenishAmount_ = 1;
    4950
    5051        // Use the timer to initialize itself after the first tick (because the real values for
     
    5354        this->replenishingTimer_.setTimer(0.0f, false, createExecutor(createFunctor(&ReplenishingMunition::initializeTimer, this)));
    5455    }
     56
     57    void ReplenishingMunition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     58    {
     59        SUPER(ReplenishingMunition, XMLPort, xmlelement, mode);
     60
     61        XMLPortParam(ReplenishingMunition, "replenishamount", setReplenishAmount, getReplenishAmount, xmlelement, mode);
     62        XMLPortParam(ReplenishingMunition, "replenishinterval", setReplenishInterval, getReplenishInterval, xmlelement, mode);
     63    }   
    5564
    5665    float ReplenishingMunition::getProgress()
     
    6776    void ReplenishingMunition::replenish()
    6877    {
    69         if (this->canAddMunition(this->replenishMunitionAmount_))
     78        if (this->canAddMunition(this->replenishAmount_))
    7079        {
    7180            // Make a temporary copy of bAllowMunitionRefilling_, because this might be disallowed in every
     
    7584
    7685            // Replenish munition
    77             this->addMunition(this->replenishMunitionAmount_);
     86            this->addMunition(this->replenishAmount_);
    7887
    7988            // Write back the temporary value
  • code/branches/fabienHS15/src/orxonox/weaponsystem/ReplenishingMunition.h

    r10688 r10791  
    5353            ReplenishingMunition(Context* context);
    5454            virtual ~ReplenishingMunition() {}
     55
     56            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     57           
    5558            virtual float getProgress();
    56             inline float getReplenishingMunitionAmount() const
    57                 { return replenishMunitionAmount_; }
     59            inline float getReplenishAmount() const
     60                { return replenishAmount_; }
     61            inline float getReplenishInterval() const
     62                { return replenishInterval_; }
    5863
    5964        protected:                         
    6065            float replenishInterval_; //!< The interval in which the munition is replenished.
    61             unsigned int replenishMunitionAmount_; //!< The amount by which it is replenished.
     66            unsigned int replenishAmount_; //!< The amount by which it is replenished.
    6267
    6368        private:
     
    6671
    6772            Timer replenishingTimer_; //!< Timer to do the replenishing.
     73
     74            inline void setReplenishAmount(unsigned int replenishAmount)
     75                { this->replenishAmount_ = replenishAmount; }
     76            inline void setReplenishInterval(float replenishInterval)
     77                { this->replenishInterval_ = replenishInterval; }             
    6878    };
    6979}
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.cc

    r10688 r10791  
    155155            it->second->setWeapon(this);
    156156    }
     157
     158    void Weapon::updateMunition()
     159    {
     160        for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     161            it->second->updateMunition();
     162    }
    157163}
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.h

    r10688 r10791  
    7979            inline WeaponSlot * getWeaponSlot() const
    8080                { return this->weaponSlot_; }
     81            void updateMunition();
    8182
    8283        private:
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.cc

    r10688 r10791  
    243243        }
    244244        else
    245             this->munition_ = 0;
     245        {
     246            this->munition_ = NULL;
     247        }
    246248    }
    247249
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.h

    r10688 r10791  
    153153                { return this->hudImageString_; }           
    154154
     155            void updateMunition();
    155156        protected:
    156157            virtual void fire() = 0;
     
    171172            std::string hudImageString_;
    172173
    173         private:
    174             void updateMunition();
     174        private:           
    175175            void reloaded();
    176176
     
    189189
    190190            WorldSound* defSndWpnFire_;
    191             bool        bSoundAttached_;
     191            bool bSoundAttached_;
    192192    };
    193193}
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.cc

    r10688 r10791  
    161161            (*it)->setWeaponPack(this);
    162162    }
     163
     164    void WeaponPack::updateMunition()
     165    {
     166        for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     167            (*it)->updateMunition();
     168    }
    163169}
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.h

    r10688 r10791  
    6666            inline WeaponSystem * getWeaponSystem() const
    6767                { return this->weaponSystem_; }
     68            void updateMunition();
    6869
    6970        private:
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.cc

    r10688 r10791  
    315315            return it->second;
    316316        }
    317         else if (identifier->getIdentifier()->isA(Class(Munition)))
    318         {
    319             Munition* munition = identifier->fabricate(this->getContext());
    320             this->munitions_[identifier->getIdentifier()] = munition;
    321             return munition;
    322         }
    323317        else
    324318        {
    325             return 0;
     319            return NULL;
     320        }
     321    }
     322
     323    void WeaponSystem::addMunition(Munition* munition)
     324    {
     325        if (munition == NULL)
     326        {
     327            return;
     328        }
     329
     330        SubclassIdentifier<Munition> identifier = munition->getIdentifier();
     331
     332        if (identifier)
     333        {
     334            this->munitions_[identifier] = munition;
     335            updateMunition();
     336        }
     337        else
     338        {
     339            orxout(internal_warning) << "Adding munition failed. identifier == NULL " << endl;
     340        }
     341    }
     342
     343    void WeaponSystem::updateMunition()
     344    {
     345        for (std::vector<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
     346        {
     347            (*it)->updateMunition();
    326348        }
    327349    }
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.h

    r10688 r10791  
    7777
    7878            Munition * getMunition(SubclassIdentifier<Munition> * identifier);
     79            void addMunition(Munition* munition);
    7980
    8081            inline void setPawn(Pawn * pawn)
     
    9697
    9798        private:
     99            void updateMunition();
     100           
    98101            std::map<unsigned int, WeaponSet *> weaponSets_;
    99102            std::vector<WeaponSlot *> weaponSlots_;
Note: See TracChangeset for help on using the changeset viewer.