- Timestamp:
- Oct 27, 2015, 9:08:40 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/modules/pickup/items/MunitionPickup.cc
r10692 r10715 38 38 #include "core/XMLPort.h" 39 39 40 #include "worldentities/pawns/ SpaceShip.h"40 #include "worldentities/pawns/Pawn.h" 41 41 42 42 namespace orxonox … … 71 71 //Defines who is allowed to pick up the pickup. 72 72 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 73 munitionAmount_ = 1;74 setMunitionName("LaserMunition");75 73 } 76 74 … … 83 81 SUPER(MunitionPickup, XMLPort, xmlelement, mode); 84 82 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]; 87 98 } 88 99 … … 104 115 if(this->isUsed()) 105 116 { 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) 109 118 { 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); 115 132 } 116 133 else … … 118 135 this->Pickupable::destroy(); 119 136 } 120 } 137 } 121 138 122 139 /** … … 136 153 } 137 154 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 } 164 156 } 165 157
Note: See TracChangeset
for help on using the changeset viewer.