Changeset 10713 for code/branches/fabienHS15/src/orxonox/weaponsystem
- Timestamp:
- Oct 26, 2015, 11:34:23 PM (9 years ago)
- Location:
- code/branches/fabienHS15/src/orxonox/weaponsystem
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc
r10688 r10713 45 45 this->magazines_ = 10; 46 46 47 this->deployment_ = DEPLOYMENT_STACK;47 this->deployment_ = MunitionDeployment::Stack; 48 48 this->bAllowMunitionRefilling_ = true; 49 49 this->bAllowMultiMunitionRemovementUnderflow_ = true; 50 50 51 51 this->reloadTime_ = 0.5f; 52 53 this->lastFilledWeaponMode_ = NULL; 52 54 } 53 55 … … 60 62 Munition::Magazine* Munition::getMagazine(WeaponMode* user) const 61 63 { 62 if (deployment_ == DEPLOYMENT_SEPARATE)64 if (deployment_ == MunitionDeployment::Separate) 63 65 { 64 66 // For separated magazines we definitively need a given user … … 86 88 if (magazine) 87 89 { 88 if (deployment_ == DEPLOYMENT_STACK)90 if (deployment_ == MunitionDeployment::Stack) 89 91 // With stacked munition every magazine contributes to the total amount 90 92 return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_; … … 108 110 unsigned int Munition::getNumMagazines() const 109 111 { 110 if (deployment_ == DEPLOYMENT_STACK)112 if (deployment_ == MunitionDeployment::Stack) 111 113 { 112 114 // If we stack munition and the current magazine is still full, it counts too … … 121 123 unsigned int Munition::getMaxMunition() const 122 124 { 123 if (deployment_ == DEPLOYMENT_STACK)125 if (deployment_ == MunitionDeployment::Stack) 124 126 return this->maxMunitionPerMagazine_ * this->maxMagazines_; 125 127 else … … 135 137 136 138 // 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) 138 140 munition += this->maxMunitionPerMagazine_ * this->magazines_; 139 141 … … 168 170 { 169 171 // Not enough munition 170 if (deployment_ == DEPLOYMENT_STACK)172 if (deployment_ == MunitionDeployment::Stack) 171 173 { 172 174 // We stack munition, so just take what we can and then load the next magazine … … 198 200 { 199 201 // 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); 201 203 } 202 204 … … 206 208 if (magazine) 207 209 { 208 if (deployment_ == DEPLOYMENT_STACK)210 if (deployment_ == MunitionDeployment::Stack) 209 211 // With stacked munition, we never have to reload 210 212 return false; … … 230 232 231 233 // 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) 233 235 return false; 234 236 235 237 // If we don't use separate magazines, set user to 0 236 if (!deployment_ == DEPLOYMENT_SEPARATE)238 if (!deployment_ == MunitionDeployment::Separate) 237 239 user = 0; 238 240 … … 241 243 if (it != this->currentMagazines_.end()) 242 244 { 245 if (it->first == lastFilledWeaponMode_) 246 { 247 lastFilledWeaponMode_ = NULL; 248 } 243 249 delete it->second; 244 250 this->currentMagazines_.erase(it); … … 259 265 return false; 260 266 261 if (deployment_ == DEPLOYMENT_STACK)267 if (deployment_ == MunitionDeployment::Stack) 262 268 { 263 269 // If we stack munition, we can always add munition until we reach the limit … … 280 286 return false; 281 287 282 if (deployment_ == DEPLOYMENT_STACK)288 if (deployment_ == MunitionDeployment::Stack) 283 289 { 284 290 // Stacking munition means, if a magazine gets full, the munition adds to a new magazine … … 311 317 else 312 318 { 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 /* 313 370 // Share the munition equally to the current magazines 314 371 while (amount > 0) … … 331 388 } 332 389 333 return true; 390 return true;*/ 334 391 } 335 392 } … … 339 396 // TODO: 'amount' is not used 340 397 341 if (deployment_ == DEPLOYMENT_STACK)398 if (deployment_ == MunitionDeployment::Stack) 342 399 // If we stack munition, we can always add new magazines because they contribute directly to the munition 343 400 return (this->getNumMunition(0) < this->getMaxMunition()); … … 356 413 357 414 // 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) 359 416 return false; 360 417 … … 368 425 // We get more magazines than we need, so just add the needed amount 369 426 this->magazines_ += needed_magazines; 370 if (deployment_ == DEPLOYMENT_STACK)427 if (deployment_ == MunitionDeployment::Stack) 371 428 { 372 429 // We stack munition, so the additional amount contributes directly to the munition of the current magazine … … 382 439 bool Munition::canRemoveMagazines(unsigned int amount) const 383 440 { 384 if (deployment_ == DEPLOYMENT_STACK)441 if (deployment_ == MunitionDeployment::Stack) 385 442 { 386 443 if (this->magazines_ >= amount) … … 421 478 this->magazines_ -= amount; 422 479 } 423 else if (deployment_ == DEPLOYMENT_STACK)480 else if (deployment_ == MunitionDeployment::Stack) 424 481 { 425 482 // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine … … 436 493 { 437 494 // If we use separate magazines, we need a user 438 if (deployment_ == DEPLOYMENT_SEPARATE&& !user)495 if (deployment_ == MunitionDeployment::Separate && !user) 439 496 return false; 440 497 441 498 // If we don't use separate magazines, set user to 0 442 if (!deployment_ == DEPLOYMENT_SEPARATE)499 if (!deployment_ == MunitionDeployment::Separate) 443 500 user = 0; 444 501 … … 447 504 if (it != this->currentMagazines_.end()) 448 505 { 506 if (it->first == lastFilledWeaponMode_) 507 { 508 lastFilledWeaponMode_ = NULL; 509 } 449 510 delete it->second; 450 this->currentMagazines_.erase(it); 511 this->currentMagazines_.erase(it); 451 512 return true; 452 513 } … … 464 525 this->bLoaded_ = false; 465 526 466 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == DEPLOYMENT_STACK)527 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == MunitionDeployment::Stack) 467 528 { 468 529 const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this)); -
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h
r10688 r10713 39 39 namespace orxonox 40 40 { 41 enumDeployment41 namespace MunitionDeployment 42 42 { 43 DEPLOYMENT_SHARE, 44 DEPLOYMENT_STACK, 45 DEPLOYMENT_SEPARATE 46 }; 47 43 enum Value 44 { 45 Share, 46 Stack, 47 Separate 48 }; 49 } 48 50 49 51 class _OrxonoxExport Munition : public BaseObject … … 77 79 { return this->maxMunitionPerMagazine_; } 78 80 inline bool getUseSeparateMagazines() const 79 { return deployment_ == DEPLOYMENT_SEPARATE; }81 { return deployment_ == MunitionDeployment::Separate; } 80 82 inline bool getStackMunition() const 81 { return deployment_ == DEPLOYMENT_STACK; }83 { return deployment_ == MunitionDeployment::Stack; } 82 84 83 85 bool canTakeMunition(unsigned int amount, WeaponMode* user) const; … … 105 107 unsigned int maxMagazines_; 106 108 unsigned int magazines_; 107 std::map<WeaponMode*, Magazine*> currentMagazines_; 109 std::map<WeaponMode*, Magazine*> currentMagazines_; // Maps weapon modes to magazines that are currently used. 108 110 109 Deployment deployment_;111 MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes. 110 112 111 113 bool bAllowMunitionRefilling_; … … 113 115 114 116 float reloadTime_; 117 WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition. 115 118 116 119 private:
Note: See TracChangeset
for help on using the changeset viewer.