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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.