- Timestamp:
- Nov 9, 2015, 5:55:42 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc
r10724 r10791 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Fabien Vultier 27 27 * 28 28 */ … … 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/command/Executor.h" 34 #include "core/XMLPort.h" 34 35 35 36 namespace orxonox … … 58 59 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it) 59 60 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); 60 70 } 61 71 … … 121 131 } 122 132 133 void Munition::setNumMagazines(unsigned int numMagazines) 134 { 135 this->magazines_ = numMagazines; 136 } 137 123 138 unsigned int Munition::getMaxMunition() const 124 139 { … … 138 153 // If we stack munition, we don't care about the current magazine - we just need enough munition in total 139 154 if (deployment_ == MunitionDeployment::Stack) 155 { 140 156 munition += this->maxMunitionPerMagazine_ * this->magazines_; 157 } 141 158 142 159 if (munition == 0) 160 { 143 161 // Absolutely no munition - no chance to take munition 144 162 return false; 163 } 145 164 else if (this->bAllowMultiMunitionRemovementUnderflow_) 165 { 146 166 // We're not empty AND we allow underflow, so this will always work 147 167 return true; 168 } 148 169 else 170 { 149 171 // We don't allow underflow, so we have to check the amount 150 172 return (munition >= amount); 173 } 174 151 175 } 152 176 return false; … … 200 224 { 201 225 // 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); 203 227 } 204 228 … … 236 260 237 261 // 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 } 240 266 241 267 // Remove the current magazine for the given user … … 289 315 { 290 316 // 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); 292 318 if (magazine) 293 319 { … … 386 412 387 413 // 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) 389 415 return false; 390 416 … … 470 496 471 497 // 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; 474 500 475 501 // Remove the current magazine for the given user
Note: See TracChangeset
for help on using the changeset viewer.