Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2015, 9:08:40 PM (9 years ago)
Author:
fvultier
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/modules/pickup/items/MunitionPickup.cc

    r10692 r10715  
    3838#include "core/XMLPort.h"
    3939
    40 #include "worldentities/pawns/SpaceShip.h"
     40#include "worldentities/pawns/Pawn.h"
    4141
    4242namespace orxonox
     
    7171        //Defines who is allowed to pick up the pickup.
    7272        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    73         munitionAmount_ = 1;
    74         setMunitionName("LaserMunition");
    7573    }
    7674
     
    8381        SUPER(MunitionPickup, XMLPort, xmlelement, mode);
    8482
    85         XMLPortParam(MunitionPickup, "amount", setMunitionAmount, getMunitionAmount, xmlelement, mode);
    86         XMLPortParam(MunitionPickup, "munitiontype", setMunitionName, getMunitionName, xmlelement, mode);
     83        XMLPortObject(MunitionPickup, MunitionContainer, "munitioncontainers", addMunitionContainer, getMunitionContainer, xmlelement, mode);
     84    }
     85
     86    void MunitionPickup::addMunitionContainer(MunitionContainer* munitionContainer)
     87    {
     88        OrxAssert(munitionContainer != NULL, "The munitionContainer cannot be NULL.");
     89        this->munitionContainers_.push_back(munitionContainer);
     90    }
     91
     92    MunitionContainer* MunitionPickup::getMunitionContainer(unsigned int index)
     93    {
     94        if(this->munitionContainers_.size() >= index)
     95            return NULL;
     96        else
     97            return this->munitionContainers_[index];
    8798    }
    8899
     
    104115        if(this->isUsed())
    105116        {
    106             //Get pointer to the appropriate munition
    107             Munition* munition = pawn->getMunition(&munitionType_);
    108             if (munition)
     117            for(std::vector<MunitionContainer*>::iterator it = this->munitionContainers_.begin(); it != this->munitionContainers_.end(); ++it)
    109118            {
    110                 // Add munition
    111                 munition->addMunition(munitionAmount_);
    112                 // This will destroy the pickp
    113                 this->setUsed(false);
    114             }           
     119                //Get pointer to the appropriate munition
     120                SubclassIdentifier<Munition> identifier = (*it)->getMunitionType();
     121                Munition* munition = pawn->getMunition(&identifier);
     122                if (munition)
     123                {
     124                    // Add munition and magzines
     125                    munition->addMunition((*it)->getMunitionAmount());
     126                    munition->addMagazines((*it)->getMagazinesAmount());
     127                }
     128                (*it)->destroy();
     129            }
     130            // This will destroy the pickp
     131            this->setUsed(false);
    115132        }
    116133        else
     
    118135            this->Pickupable::destroy();
    119136        }       
    120     }
     137    }   
    121138
    122139    /**
     
    136153        }
    137154        return pawn;
    138     }
    139 
    140     void MunitionPickup::setMunitionName(const std::string& munitionname)
    141     {
    142         Identifier* identifier = ClassByString(munitionname);
    143         if (identifier)
    144         {
    145             this->munitionType_ = identifier;
    146         }
    147         else
    148         {
    149             orxout(internal_warning) << "No munition class defined in MunitionPickup." << endl;
    150         }
    151     }
    152 
    153     void MunitionPickup::setMunitionAmount(int munitionAmount)
    154     {
    155         if (munitionAmount > 0)
    156         {
    157             munitionAmount_ = munitionAmount;
    158         }
    159         else
    160         {
    161             munitionAmount = 0;
    162         }
    163     }
     155    }     
    164156}
    165157
Note: See TracChangeset for help on using the changeset viewer.