Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10713


Ignore:
Timestamp:
Oct 26, 2015, 11:34:23 PM (9 years ago)
Author:
fvultier
Message:
 
Location:
code/branches/fabienHS15/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/modules/weapons/munitions/FusionMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 10;
    4848
    49         this->deployment_ = DEPLOYMENT_SEPARATE;
     49        this->deployment_ = MunitionDeployment::Separate;
    5050
    5151        this->reloadTime_ = 1.0f;
  • code/branches/fabienHS15/src/modules/weapons/munitions/GravityBombMunition.cc

    r10688 r10713  
    1919        this->magazines_ = 15;
    2020
    21         this->deployment_ = DEPLOYMENT_STACK;
     21        this->deployment_ = MunitionDeployment::Stack;
    2222
    2323        this->bAllowMunitionRefilling_ = true;
  • code/branches/fabienHS15/src/modules/weapons/munitions/IceMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 25;
    4848
    49         this->deployment_ = DEPLOYMENT_STACK;
     49        this->deployment_ = MunitionDeployment::Stack;
    5050
    5151        this->bAllowMunitionRefilling_ = false;
  • code/branches/fabienHS15/src/modules/weapons/munitions/LaserMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 10;
    4848
    49         this->deployment_ = DEPLOYMENT_SEPARATE;
     49        this->deployment_ = MunitionDeployment::Separate;
    5050
    5151        this->bAllowMunitionRefilling_ = true;
  • code/branches/fabienHS15/src/modules/weapons/munitions/LightningMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 1;
    4848
    49         this->deployment_ = DEPLOYMENT_SHARE;
     49        this->deployment_ = MunitionDeployment::Share;
    5050
    5151        this->bAllowMunitionRefilling_ = true;
  • code/branches/fabienHS15/src/modules/weapons/munitions/RocketMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 10;
    4848
    49         this->deployment_ = DEPLOYMENT_STACK;
     49        this->deployment_ = MunitionDeployment::Stack;
    5050
    5151        this->bAllowMunitionRefilling_ = false;
  • code/branches/fabienHS15/src/modules/weapons/munitions/SplitMunition.cc

    r10688 r10713  
    4747        this->magazines_ = 25;
    4848
    49         this->deployment_ = DEPLOYMENT_STACK;
     49        this->deployment_ = MunitionDeployment::Stack;
    5050
    5151        this->bAllowMunitionRefilling_ = true;
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc

    r10688 r10713  
    4545        this->magazines_ = 10;
    4646
    47         this->deployment_ = DEPLOYMENT_STACK;
     47        this->deployment_ = MunitionDeployment::Stack;
    4848        this->bAllowMunitionRefilling_ = true;
    4949        this->bAllowMultiMunitionRemovementUnderflow_ = true;
    5050
    5151        this->reloadTime_ = 0.5f;
     52
     53        this->lastFilledWeaponMode_ = NULL;
    5254    }
    5355
     
    6062    Munition::Magazine* Munition::getMagazine(WeaponMode* user) const
    6163    {
    62         if (deployment_ == DEPLOYMENT_SEPARATE)
     64        if (deployment_ == MunitionDeployment::Separate)
    6365        {
    6466            // For separated magazines we definitively need a given user
     
    8688        if (magazine)
    8789        {
    88             if (deployment_ == DEPLOYMENT_STACK)
     90            if (deployment_ == MunitionDeployment::Stack)
    8991                // With stacked munition every magazine contributes to the total amount
    9092                return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_;
     
    108110    unsigned int Munition::getNumMagazines() const
    109111    {
    110         if (deployment_ == DEPLOYMENT_STACK)
     112        if (deployment_ == MunitionDeployment::Stack)
    111113        {
    112114            // If we stack munition and the current magazine is still full, it counts too
     
    121123    unsigned int Munition::getMaxMunition() const
    122124    {
    123         if (deployment_ == DEPLOYMENT_STACK)
     125        if (deployment_ == MunitionDeployment::Stack)
    124126            return this->maxMunitionPerMagazine_ * this->maxMagazines_;
    125127        else
     
    135137
    136138            // If we stack munition, we don't care about the current magazine - we just need enough munition in total
    137             if (deployment_ == DEPLOYMENT_STACK)
     139            if (deployment_ == MunitionDeployment::Stack)
    138140                munition += this->maxMunitionPerMagazine_ * this->magazines_;
    139141
     
    168170            {
    169171                // Not enough munition
    170                 if (deployment_ == DEPLOYMENT_STACK)
     172                if (deployment_ == MunitionDeployment::Stack)
    171173                {
    172174                    // We stack munition, so just take what we can and then load the next magazine
     
    198200    {
    199201        // As long as we have enough magazines (and don't stack munition) we can reload
    200         return (this->magazines_ > 0 && !deployment_ == DEPLOYMENT_STACK);
     202        return (this->magazines_ > 0 && !deployment_ == MunitionDeployment::Stack);
    201203    }
    202204
     
    206208        if (magazine)
    207209        {
    208             if (deployment_ == DEPLOYMENT_STACK)
     210            if (deployment_ == MunitionDeployment::Stack)
    209211                // With stacked munition, we never have to reload
    210212                return false;
     
    230232
    231233        // If we use separate magazines for each user, we definitively need a user given
    232         if (deployment_ == DEPLOYMENT_SEPARATE && !user)
     234        if (deployment_ == MunitionDeployment::Separate && !user)
    233235            return false;
    234236
    235237        // If we don't use separate magazines, set user to 0
    236         if (!deployment_ == DEPLOYMENT_SEPARATE)
     238        if (!deployment_ == MunitionDeployment::Separate)
    237239            user = 0;
    238240
     
    241243        if (it != this->currentMagazines_.end())
    242244        {
     245            if (it->first == lastFilledWeaponMode_)
     246            {
     247                lastFilledWeaponMode_ = NULL;
     248            }           
    243249            delete it->second;
    244250            this->currentMagazines_.erase(it);
     
    259265            return false;
    260266
    261         if (deployment_ == DEPLOYMENT_STACK)
     267        if (deployment_ == MunitionDeployment::Stack)
    262268        {
    263269            // If we stack munition, we can always add munition until we reach the limit
     
    280286            return false;
    281287
    282         if (deployment_ == DEPLOYMENT_STACK)
     288        if (deployment_ == MunitionDeployment::Stack)
    283289        {
    284290            // Stacking munition means, if a magazine gets full, the munition adds to a new magazine
     
    311317        else
    312318        {
     319            std::map<WeaponMode*, Magazine*>::iterator it;
     320
     321            // If the pointer to the weapon mode whose magazine got munition added to is NULL, then set the iterator to the beginning of the map
     322            // Otherwise set it to the next weapon mode
     323            if (lastFilledWeaponMode_ == NULL)
     324            {
     325                it = this->currentMagazines_.begin();
     326            }
     327            else
     328            {
     329                it = this->currentMagazines_.find(lastFilledWeaponMode_);
     330                ++ it;
     331            }
     332
     333            // Share the munition equally to the current magazines
     334            bool firstLoop = true;
     335            while (amount > 0)
     336            {
     337                bool change = false;
     338                while (it != this->currentMagazines_.end())
     339                {
     340                    // Add munition if the magazine isn't full (but only to loaded magazines)
     341                    if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
     342                    {
     343                        it->second->munition_++;
     344                        amount--;
     345                        lastFilledWeaponMode_ = it->first;
     346                        change = true;
     347                    }
     348
     349                    ++it;
     350                }
     351
     352                // If there was no change in a loop, all magazines are full (or locked due to loading)
     353                // Because the first loop does not stat at the beginning of the map we have to treat is separately
     354                if (!change && !firstLoop)
     355                {
     356                    break;
     357                }                   
     358
     359                it = this->currentMagazines_.begin();
     360                firstLoop = false;
     361            }
     362
     363            return true;
     364
     365
     366
     367
     368
     369            /*
    313370            // Share the munition equally to the current magazines
    314371            while (amount > 0)
     
    331388            }
    332389
    333             return true;
     390            return true;*/
    334391        }
    335392    }
     
    339396        // TODO: 'amount' is not used
    340397
    341         if (deployment_ == DEPLOYMENT_STACK)
     398        if (deployment_ == MunitionDeployment::Stack)
    342399            // If we stack munition, we can always add new magazines because they contribute directly to the munition
    343400            return (this->getNumMunition(0) < this->getMaxMunition());
     
    356413
    357414        // 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)
    358         if (needed_magazines <= 0 && !deployment_ == DEPLOYMENT_STACK)
     415        if (needed_magazines <= 0 && !deployment_ == MunitionDeployment::Stack)
    359416            return false;
    360417
     
    368425            // We get more magazines than we need, so just add the needed amount
    369426            this->magazines_ += needed_magazines;
    370             if (deployment_ == DEPLOYMENT_STACK)
     427            if (deployment_ == MunitionDeployment::Stack)
    371428            {
    372429                // We stack munition, so the additional amount contributes directly to the munition of the current magazine
     
    382439    bool Munition::canRemoveMagazines(unsigned int amount) const
    383440    {
    384         if (deployment_ == DEPLOYMENT_STACK)
     441        if (deployment_ == MunitionDeployment::Stack)
    385442        {
    386443            if (this->magazines_ >= amount)
     
    421478            this->magazines_ -= amount;
    422479        }
    423         else if (deployment_ == DEPLOYMENT_STACK)
     480        else if (deployment_ == MunitionDeployment::Stack)
    424481        {
    425482            // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine
     
    436493    {
    437494        // If we use separate magazines, we need a user
    438         if (deployment_ == DEPLOYMENT_SEPARATE && !user)
     495        if (deployment_ == MunitionDeployment::Separate && !user)
    439496            return false;
    440497
    441498        // If we don't use separate magazines, set user to 0
    442         if (!deployment_ == DEPLOYMENT_SEPARATE)
     499        if (!deployment_ == MunitionDeployment::Separate)
    443500            user = 0;
    444501
     
    447504        if (it != this->currentMagazines_.end())
    448505        {
     506            if (it->first == lastFilledWeaponMode_)
     507            {
     508                lastFilledWeaponMode_ = NULL;
     509            }
    449510            delete it->second;
    450             this->currentMagazines_.erase(it);
     511            this->currentMagazines_.erase(it);           
    451512            return true;
    452513        }
     
    464525        this->bLoaded_ = false;
    465526
    466         if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == DEPLOYMENT_STACK)
     527        if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == MunitionDeployment::Stack)
    467528        {
    468529            const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this));
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h

    r10688 r10713  
    3939namespace orxonox
    4040{
    41     enum Deployment
     41    namespace MunitionDeployment
    4242    {
    43         DEPLOYMENT_SHARE,
    44         DEPLOYMENT_STACK,
    45         DEPLOYMENT_SEPARATE
    46     };
    47 
     43        enum Value
     44        {
     45            Share,
     46            Stack,
     47            Separate
     48        };
     49    }
    4850
    4951    class _OrxonoxExport Munition : public BaseObject
     
    7779                { return this->maxMunitionPerMagazine_; }
    7880            inline bool getUseSeparateMagazines() const
    79                 { return deployment_ == DEPLOYMENT_SEPARATE; }
     81                { return deployment_ == MunitionDeployment::Separate; }
    8082            inline bool getStackMunition() const
    81                 { return deployment_ == DEPLOYMENT_STACK; }
     83                { return deployment_ == MunitionDeployment::Stack; }
    8284
    8385            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
     
    105107            unsigned int maxMagazines_;
    106108            unsigned int magazines_;
    107             std::map<WeaponMode*, Magazine*> currentMagazines_;
     109            std::map<WeaponMode*, Magazine*> currentMagazines_; // Maps weapon modes to magazines that are currently used.
    108110
    109             Deployment deployment_;
     111            MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes.
    110112
    111113            bool bAllowMunitionRefilling_;
     
    113115
    114116            float reloadTime_;
     117            WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition.
    115118
    116119        private:
Note: See TracChangeset for help on using the changeset viewer.