Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2015, 9:08:40 PM (9 years ago)
Author:
fvultier
Message:
 
Location:
code/branches/fabienHS15/src/modules/pickup/items
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/modules/pickup/items/CMakeLists.txt

    r10692 r10715  
    99  DamageBoostPickup.cc
    1010  MunitionPickup.cc
     11  MunitionContainer.cc
    1112)
  • 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
  • code/branches/fabienHS15/src/modules/pickup/items/MunitionPickup.h

    r10692 r10715  
    3939
    4040#include <string>
     41#include <vector>
    4142
    4243#include "pickup/Pickup.h"
     44#include "pickup/items/MunitionContainer.h"
    4345#include "core/class/SubclassIdentifier.h"
    4446#include "weaponsystem/Munition.h"
     
    5860            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    5961
    60         protected:
    61             void setMunitionName(const std::string& munitionname);
    62             inline const std::string& getMunitionName() const
    63                 { return this->munitionname_; }
    64             void setMunitionAmount(int munitionAmount);
    65             inline int getMunitionAmount() const
    66                 { return this->munitionAmount_; }
     62            virtual void addMunitionContainer(MunitionContainer* munitionContainer);
     63            MunitionContainer* getMunitionContainer(unsigned int index);
    6764
    6865        private:           
    6966            void initialize(void); //!< Initializes the member variables.
    7067            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    71 
    72             SubclassIdentifier<Munition> munitionType_; //!< Indentifier of the munition type.
    73             std::string munitionname_; //!< String containing the class name of the munition type (e.g. "LaserMunition")
    74             int munitionAmount_; //!< The amount of munition added if the pickup is used
     68           
     69            std::vector<MunitionContainer*> munitionContainers_;
    7570
    7671    };
Note: See TracChangeset for help on using the changeset viewer.