Changeset 11052 for code/trunk/src/orxonox/weaponsystem
- Timestamp:
- Jan 9, 2016, 6:26:20 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 12 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/weaponsystem/CMakeLists.txt
r5781 r11052 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Munition.cc 3 ReplenishingMunition.cc 3 4 Weapon.cc 4 5 WeaponMode.cc -
code/trunk/src/orxonox/weaponsystem/Munition.cc
r9667 r11052 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 … … 43 44 this->maxMunitionPerMagazine_ = 10; 44 45 this->maxMagazines_ = 10; 45 this->magazines_ = 10; 46 47 this->bUseSeparateMagazines_ = false; 48 this->bStackMunition_ = true; 46 this->unassignedMagazines_ = 10; 47 48 this->deployment_ = MunitionDeployment::Stack; 49 49 this->bAllowMunitionRefilling_ = true; 50 50 this->bAllowMultiMunitionRemovementUnderflow_ = true; 51 51 52 this->reloadTime_ = 0; 52 this->reloadTime_ = 0.5f; 53 54 this->lastFilledWeaponMode_ = NULL; 53 55 } 54 56 55 57 Munition::~Munition() 56 58 { 57 for (std::map<WeaponMode*, Magazine*>::iterator it = this-> currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)59 for (std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 58 60 delete it->second; 59 61 } 60 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); 70 } 71 61 72 Munition::Magazine* Munition::getMagazine(WeaponMode* user) const 62 73 { 63 if ( this->bUseSeparateMagazines_)74 if (deployment_ == MunitionDeployment::Separate) 64 75 { 65 76 // For separated magazines we definitively need a given user … … 68 79 69 80 // Use the map to get the magazine assigned to the given user 70 std::map<WeaponMode*, Magazine*>::const_iterator it = this-> currentMagazines_.find(user);71 if (it != this-> currentMagazines_.end())81 std::map<WeaponMode*, Magazine*>::const_iterator it = this->assignedMagazines_.find(user); 82 if (it != this->assignedMagazines_.end()) 72 83 return it->second; 73 84 } … … 75 86 { 76 87 // We don't use separate magazines for each user, so just take the first magazine 77 if (this-> currentMagazines_.size() > 0)78 return this-> currentMagazines_.begin()->second;88 if (this->assignedMagazines_.size() > 0) 89 return this->assignedMagazines_.begin()->second; 79 90 } 80 91 … … 87 98 if (magazine) 88 99 { 89 if ( this->bStackMunition_)100 if (deployment_ == MunitionDeployment::Stack) 90 101 // With stacked munition every magazine contributes to the total amount 91 return this->maxMunitionPerMagazine_ * this-> magazines_ + magazine->munition_;102 return this->maxMunitionPerMagazine_ * this->unassignedMagazines_ + magazine->munition_; 92 103 else 93 104 // Wihtout stacked munition we just consider the current magazine … … 109 120 unsigned int Munition::getNumMagazines() const 110 121 { 111 if ( this->bStackMunition_)122 if (deployment_ == MunitionDeployment::Stack) 112 123 { 113 124 // If we stack munition and the current magazine is still full, it counts too 114 125 Magazine* magazine = this->getMagazine(0); 115 126 if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_) 116 return this->magazines_ + 1; 117 } 118 119 return this->magazines_; 127 return this->unassignedMagazines_ + 1; 128 } 129 130 return this->unassignedMagazines_; 131 } 132 133 void Munition::setNumMagazines(unsigned int numMagazines) 134 { 135 this->unassignedMagazines_ = numMagazines; 120 136 } 121 137 122 138 unsigned int Munition::getMaxMunition() const 123 139 { 124 if ( this->bStackMunition_)140 if (deployment_ == MunitionDeployment::Stack) 125 141 return this->maxMunitionPerMagazine_ * this->maxMagazines_; 126 142 else … … 135 151 unsigned int munition = magazine->munition_; 136 152 137 // If we stack munition, we con't care about the current magazine - we just need enough munition in total 138 if (this->bStackMunition_) 139 munition += this->maxMunitionPerMagazine_ * this->magazines_; 153 // If we stack munition, we don't care about the current magazine - we just need enough munition in total 154 if (deployment_ == MunitionDeployment::Stack) 155 { 156 munition += this->maxMunitionPerMagazine_ * this->unassignedMagazines_; 157 } 140 158 141 159 if (munition == 0) 160 { 142 161 // Absolutely no munition - no chance to take munition 143 162 return false; 163 } 144 164 else if (this->bAllowMultiMunitionRemovementUnderflow_) 165 { 145 166 // We're not empty AND we allow underflow, so this will always work 146 167 return true; 168 } 147 169 else 170 { 148 171 // We don't allow underflow, so we have to check the amount 149 172 return (munition >= amount); 173 } 174 150 175 } 151 176 return false; … … 169 194 { 170 195 // Not enough munition 171 if ( this->bStackMunition_)196 if (deployment_ == MunitionDeployment::Stack) 172 197 { 173 198 // We stack munition, so just take what we can and then load the next magazine … … 175 200 magazine->munition_ = 0; 176 201 177 if (this->reload( 0))202 if (this->reload(NULL)) 178 203 // Successfully reloaded, continue recursively 179 204 return this->takeMunition(amount, 0); … … 199 224 { 200 225 // As long as we have enough magazines (and don't stack munition) we can reload 201 return (this-> magazines_ > 0 && !this->bStackMunition_);226 return (this->unassignedMagazines_ > 0 && deployment_ != MunitionDeployment::Stack); 202 227 } 203 228 … … 207 232 if (magazine) 208 233 { 209 if ( this->bStackMunition_)234 if (deployment_ == MunitionDeployment::Stack) 210 235 // With stacked munition, we never have to reload 211 236 return false; … … 227 252 228 253 // Check if we actually can reload 229 if (this-> magazines_ == 0)254 if (this->unassignedMagazines_ == 0) 230 255 return false; 231 256 232 257 // If we use separate magazines for each user, we definitively need a user given 233 if ( this->bUseSeparateMagazines_&& !user)258 if (deployment_ == MunitionDeployment::Separate && !user) 234 259 return false; 235 260 236 261 // If we don't use separate magazines, set user to 0 237 if (!this->bUseSeparateMagazines_) 238 user = 0; 262 if (deployment_ != MunitionDeployment::Separate) 263 { 264 user = NULL; 265 } 239 266 240 267 // Remove the current magazine for the given user 241 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 242 if (it != this->currentMagazines_.end()) 243 { 268 std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.find(user); 269 if (it != this->assignedMagazines_.end()) 270 { 271 if (it->first == lastFilledWeaponMode_) 272 { 273 lastFilledWeaponMode_ = NULL; 274 } 244 275 delete it->second; 245 this-> currentMagazines_.erase(it);276 this->assignedMagazines_.erase(it); 246 277 } 247 278 248 279 // Load a new magazine 249 this-> currentMagazines_[user] = new Magazine(this, bUseReloadTime);250 this-> magazines_--;280 this->assignedMagazines_[user] = new Magazine(this, bUseReloadTime); 281 this->unassignedMagazines_--; 251 282 252 283 return true; … … 260 291 return false; 261 292 262 if ( this->bStackMunition_)293 if (deployment_ == MunitionDeployment::Stack) 263 294 { 264 295 // If we stack munition, we can always add munition until we reach the limit … … 268 299 { 269 300 // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition) 270 for (std::map<WeaponMode*, Magazine*>::const_iterator it = this-> currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)301 for (std::map<WeaponMode*, Magazine*>::const_iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 271 302 if (it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_) 272 303 return true; … … 281 312 return false; 282 313 283 if ( this->bStackMunition_)314 if (deployment_ == MunitionDeployment::Stack) 284 315 { 285 316 // Stacking munition means, if a magazine gets full, the munition adds to a new magazine 286 Magazine* magazine = this->getMagazine( 0);317 Magazine* magazine = this->getMagazine(NULL); 287 318 if (magazine) 288 319 { … … 294 325 { 295 326 magazine->munition_ -= this->maxMunitionPerMagazine_; 296 this-> magazines_++;327 this->unassignedMagazines_++; 297 328 } 298 329 299 // If we reached the limit, redu ze both magazines and munition to the maximum300 if (this-> magazines_ >= this->maxMagazines_)301 { 302 this-> magazines_ = this->maxMagazines_ - 1;330 // If we reached the limit, reduce both magazines and munition to the maximum 331 if (this->unassignedMagazines_ >= this->maxMagazines_) 332 { 333 this->unassignedMagazines_ = this->maxMagazines_; 303 334 magazine->munition_ = this->maxMunitionPerMagazine_; 304 335 } … … 312 343 else 313 344 { 345 std::map<WeaponMode*, Magazine*>::iterator it; 346 347 // 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 348 // Otherwise set it to the next weapon mode 349 if (lastFilledWeaponMode_ == NULL) 350 { 351 it = this->assignedMagazines_.begin(); 352 } 353 else 354 { 355 it = this->assignedMagazines_.find(lastFilledWeaponMode_); 356 ++ it; 357 } 358 314 359 // Share the munition equally to the current magazines 360 bool firstLoop = true; 315 361 while (amount > 0) 316 362 { 317 363 bool change = false; 318 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)364 while (it != this->assignedMagazines_.end()) 319 365 { 320 366 // Add munition if the magazine isn't full (but only to loaded magazines) … … 323 369 it->second->munition_++; 324 370 amount--; 371 lastFilledWeaponMode_ = it->first; 325 372 change = true; 326 373 } 374 375 ++it; 327 376 } 328 377 329 378 // If there was no change in a loop, all magazines are full (or locked due to loading) 330 if (!change) 379 // Because the first loop does not start at the beginning of the map we have to treat is separately 380 if (!change && !firstLoop) 381 { 331 382 break; 383 } 384 385 it = this->assignedMagazines_.begin(); 386 firstLoop = false; 332 387 } 333 388 … … 340 395 // TODO: 'amount' is not used 341 396 342 if ( this->bStackMunition_)397 if (deployment_ == MunitionDeployment::Stack) 343 398 // If we stack munition, we can always add new magazines because they contribute directly to the munition 344 399 return (this->getNumMunition(0) < this->getMaxMunition()); 345 400 else 346 401 // If we don't stack munition, we're more limited 347 return ((this->currentMagazines_.size() + this->magazines_) < this->maxMagazines_); 348 } 349 350 bool Munition::addMagazines(unsigned int amount) 351 { 402 return ((this->assignedMagazines_.size() + this->unassignedMagazines_) < this->maxMagazines_); 403 } 404 405 unsigned int Munition::addMagazines(unsigned int amount) 406 { 407 unsigned int addedMagazines = 0; 408 352 409 if (!this->canAddMagazines(amount)) 353 return false;410 return 0; 354 411 355 412 // Calculate how many magazines are needed 356 int needed_magazines = this->maxMagazines_ - this-> magazines_ - this->currentMagazines_.size();413 int needed_magazines = this->maxMagazines_ - this->unassignedMagazines_ - this->assignedMagazines_.size(); 357 414 358 415 // 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) 359 if (needed_magazines <= 0 && !this->bStackMunition_)360 return false;416 if (needed_magazines <= 0 && deployment_ != MunitionDeployment::Stack) 417 return 0; 361 418 362 419 if (amount <= static_cast<unsigned int>(needed_magazines)) 363 420 { 364 421 // We need more magazines than we get, so just add them 365 this->magazines_ += amount; 422 this->unassignedMagazines_ += amount; 423 addedMagazines = amount; 366 424 } 367 425 else 368 426 { 369 427 // We get more magazines than we need, so just add the needed amount 370 this->magazines_ += needed_magazines; 371 if (this->bStackMunition_) 428 this->unassignedMagazines_ += needed_magazines; 429 addedMagazines = needed_magazines; 430 if (deployment_ == MunitionDeployment::Stack) 372 431 { 373 432 // We stack munition, so the additional amount contributes directly to the munition of the current magazine … … 378 437 } 379 438 380 return true; 439 // Reload as many empty magazines as possible 440 // Double loop and break is needed because the reload function changes the assigned magazines. This may confuse the iterator. 441 for (unsigned int i = 0; i < addedMagazines; ++i) 442 { 443 for (std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 444 { 445 if (needReload(it->first)) 446 { 447 reload(it->first); 448 break; 449 } 450 } 451 } 452 453 return addedMagazines; 381 454 } 382 455 383 456 bool Munition::canRemoveMagazines(unsigned int amount) const 384 457 { 385 if ( this->bStackMunition_)386 { 387 if (this-> magazines_ >= amount)458 if (deployment_ == MunitionDeployment::Stack) 459 { 460 if (this->unassignedMagazines_ >= amount) 388 461 { 389 462 // We have enough magazines 390 463 return true; 391 464 } 392 else if (this-> magazines_ == amount - 1)465 else if (this->unassignedMagazines_ == amount - 1) 393 466 { 394 467 // We lack one magazine, check if the current magazine is still full, if yes we're fine … … 406 479 { 407 480 // In case we're not stacking munition, just check the number of magazines 408 return (this-> magazines_ >= amount);481 return (this->unassignedMagazines_ >= amount); 409 482 } 410 483 … … 417 490 return false; 418 491 419 if (this-> magazines_ >= amount)492 if (this->unassignedMagazines_ >= amount) 420 493 { 421 494 // We have enough magazines, just remove the amount 422 this-> magazines_ -= amount;423 } 424 else if ( this->bStackMunition_)495 this->unassignedMagazines_ -= amount; 496 } 497 else if (deployment_ == MunitionDeployment::Stack) 425 498 { 426 499 // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine 427 this-> magazines_ = 0;500 this->unassignedMagazines_ = 0; 428 501 Magazine* magazine = this->getMagazine(0); 429 502 if (magazine) … … 437 510 { 438 511 // If we use separate magazines, we need a user 439 if ( this->bUseSeparateMagazines_&& !user)512 if (deployment_ == MunitionDeployment::Separate && !user) 440 513 return false; 441 514 442 515 // If we don't use separate magazines, set user to 0 443 if ( !this->bUseSeparateMagazines_)444 user = 0;516 if (deployment_ != MunitionDeployment::Separate) 517 user = NULL; 445 518 446 519 // Remove the current magazine for the given user 447 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 448 if (it != this->currentMagazines_.end()) 449 { 520 std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.find(user); 521 if (it != this->assignedMagazines_.end()) 522 { 523 if (it->first == lastFilledWeaponMode_) 524 { 525 lastFilledWeaponMode_ = NULL; 526 } 450 527 delete it->second; 451 this-> currentMagazines_.erase(it);528 this->assignedMagazines_.erase(it); 452 529 return true; 453 530 } … … 465 542 this->bLoaded_ = false; 466 543 467 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->bStackMunition_)544 if (bUseReloadTime && munition->reloadTime_ > 0 && munition->deployment_ != MunitionDeployment::Stack) 468 545 { 469 546 const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this)); -
code/trunk/src/orxonox/weaponsystem/Munition.h
r9667 r11052 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Fabien Vultier 27 27 * 28 28 */ … … 39 39 namespace orxonox 40 40 { 41 namespace MunitionDeployment 42 { 43 enum Value 44 { 45 Separate, // Every comsuming weapon mode has its own magazine. It is possible that one weapon mode is out of ammo while another still has some. 46 Share, // All comsuming weapon modes take their munition from the same magazine. If this magazine is empty a new one is loaded. 47 Stack // There is only one magazine where all the munition is stored. Use this deployment mode for heavy weapons loke rockets, bombs, ... 48 }; 49 } 50 41 51 class _OrxonoxExport Munition : public BaseObject 42 { 52 { 43 53 struct Magazine 44 54 { … … 59 69 virtual ~Munition(); 60 70 71 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 72 61 73 unsigned int getNumMunition(WeaponMode* user) const; 62 74 unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const; … … 68 80 inline unsigned int getMaxMunitionPerMagazine() const 69 81 { return this->maxMunitionPerMagazine_; } 82 inline MunitionDeployment::Value getMunitionDeployment() const 83 { return deployment_; } 84 70 85 71 86 bool canTakeMunition(unsigned int amount, WeaponMode* user) const; … … 82 97 83 98 bool canAddMagazines(unsigned int amount) const; 84 bool addMagazines(unsigned int amount); 99 /** 100 @brief Try to add magazines. 101 @param amount The amount of magazines tried to add. 102 @return The amount of magazines sucessfully added. 103 */ 104 unsigned int addMagazines(unsigned int amount); 85 105 86 106 bool canRemoveMagazines(unsigned int amount) const; … … 92 112 unsigned int maxMunitionPerMagazine_; 93 113 unsigned int maxMagazines_; 94 unsigned int magazines_;95 std::map<WeaponMode*, Magazine*> currentMagazines_;114 unsigned int unassignedMagazines_; // Number of magazines that are not assigned to a weapon mode. These are alway treated as full. 115 std::map<WeaponMode*, Magazine*> assignedMagazines_; // Maps weapon modes to magazines that are currently used. 96 116 97 bool bUseSeparateMagazines_;98 bool bStackMunition_; 117 MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes. 118 99 119 bool bAllowMunitionRefilling_; 100 120 bool bAllowMultiMunitionRemovementUnderflow_; 101 121 102 float reloadTime_; 122 float reloadTime_; // The time needed to replace a magazine by a new one. 123 WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition. 103 124 104 125 private: 105 126 Magazine* getMagazine(WeaponMode* user) const; 127 inline void setMaxMagazines(unsigned int maxMagazines) 128 { this->maxMagazines_ = maxMagazines; } 129 inline void setMaxMunitionPerMagazine(unsigned int maxMunitionPerMagazine) 130 { this->maxMunitionPerMagazine_ = maxMunitionPerMagazine; } 131 void setNumMagazines(unsigned int numMagazines); 106 132 }; 107 133 } -
code/trunk/src/orxonox/weaponsystem/Weapon.cc
r10650 r11052 134 134 } 135 135 136 /** 137 @brief 138 Reload all @ref orxonox::WeaponMode weapon modes of this weapon. 139 */ 136 140 void Weapon::reload() 137 141 { … … 151 155 it->second->setWeapon(this); 152 156 } 157 158 void Weapon::updateMunition() 159 { 160 for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 161 it->second->updateMunition(); 162 } 153 163 } -
code/trunk/src/orxonox/weaponsystem/Weapon.h
r10650 r11052 57 57 void addWeaponmode(WeaponMode* weaponmode); 58 58 WeaponMode* getWeaponmode(unsigned int index) const; 59 inline std::multimap<unsigned int, WeaponMode*>* getAllWeaponmodes() 60 { return &weaponmodes_; } 61 inline int getNumWeaponModes() const 62 { return weaponmodes_.size(); } 59 63 60 64 /** … … 75 79 inline WeaponSlot * getWeaponSlot() const 76 80 { return this->weaponSlot_; } 81 void updateMunition(); 77 82 78 83 private: -
code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
r10650 r11052 75 75 this->muzzleOrientation_ = Quaternion::IDENTITY; 76 76 77 hudImageString_ = "Orxonox/WSHUD_WM_Unknown"; 78 77 79 if( GameMode::isMaster() ) 78 80 { … … 125 127 this->bSoundAttached_ = true; 126 128 } 127 129 130 // Fireing is only possible if this weapon mode is not reloading and there is enough munition 128 131 if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this)) 129 132 { … … 134 137 if (this->munition_->reload(this)) 135 138 { 139 // If true, the weapon reloads in parallel to the magazine reloading 136 140 if (this->bParallelReload_) 141 { 142 // The time needed to reload is the maximum of the reload time of the weapon mode and the magazine. 137 143 tempReloadtime = std::max(this->reloadTime_, this->munition_->getReloadTime()); 144 } 138 145 else 146 { 147 // The time needed to reload is the sum of the reload time of the weapon mode and the magazine. 139 148 tempReloadtime = this->reloadTime_ + this->munition_->getReloadTime(); 149 } 140 150 } 141 151 } 142 152 153 // Mark this weapon mode as reloading and start the reload timer 143 154 this->bReloading_ = true; 144 155 this->reloadTimer_.setInterval(tempReloadtime); … … 232 243 } 233 244 else 234 this->munition_ = 0; 245 { 246 this->munition_ = NULL; 247 } 235 248 } 236 249 … … 283 296 } 284 297 285 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){ 286 if (this->defSndWpnFire_) { 298 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume) 299 { 300 if (this->defSndWpnFire_) 301 { 287 302 this->defSndWpnFire_->setSource(soundPath); 288 303 this->defSndWpnFire_->setVolume(soundVolume); -
code/trunk/src/orxonox/weaponsystem/WeaponMode.h
r10650 r11052 38 38 #include "core/class/SubclassIdentifier.h" 39 39 #include "tools/Timer.h" 40 #include "Munition.h" 40 41 41 42 namespace orxonox … … 104 105 inline bool getParallelReload() const 105 106 { return this->bParallelReload_; } 107 inline bool getReloading() const 108 { return this->bReloading_; } 106 109 107 110 … … 147 150 Vector3 getTarget(); 148 151 152 inline const std::string& getHUDImageString() const 153 { return this->hudImageString_; } 154 155 void updateMunition(); 149 156 protected: 150 157 virtual void fire() = 0; … … 155 162 156 163 float reloadTime_; 157 bool bAutoReload_; 158 bool bParallelReload_; 164 bool bAutoReload_; // If true, the weapon reloads the magazine automatically. 165 bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. 159 166 160 167 float damage_; … … 163 170 Vector3 muzzleOffset_; 164 171 165 private: 166 void updateMunition(); 172 std::string hudImageString_; 173 174 private: 167 175 void reloaded(); 168 176 … … 175 183 176 184 Timer reloadTimer_; 177 bool bReloading_; 185 bool bReloading_; // If true, this weapon mode is marked as reloading. 178 186 179 187 Vector3 muzzlePosition_; … … 181 189 182 190 WorldSound* defSndWpnFire_; 183 bool 191 bool bSoundAttached_; 184 192 }; 185 193 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.cc
r10650 r11052 124 124 } 125 125 126 std::vector<Weapon*>* WeaponPack::getAllWeapons() 127 { 128 return &weapons_; 129 } 130 126 131 void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link) 127 132 { … … 156 161 (*it)->setWeaponPack(this); 157 162 } 163 164 void WeaponPack::updateMunition() 165 { 166 for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 167 (*it)->updateMunition(); 168 } 158 169 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.h
r9667 r11052 52 52 void removeWeapon(Weapon * weapon); 53 53 Weapon * getWeapon(unsigned int index) const; 54 std::vector<Weapon*>* getAllWeapons(); 54 55 55 56 inline size_t getNumWeapons() const … … 65 66 inline WeaponSystem * getWeaponSystem() const 66 67 { return this->weaponSystem_; } 68 void updateMunition(); 67 69 68 70 private: -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
r10650 r11052 240 240 } 241 241 242 std::vector<WeaponPack *> * WeaponSystem::getAllWeaponPacks() 243 { 244 return &weaponPacks_; 245 } 246 242 247 bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2) 243 248 { … … 310 315 return it->second; 311 316 } 312 else if (identifier->getIdentifier()->isA(Class(Munition)))313 {314 Munition* munition = identifier->fabricate(this->getContext());315 this->munitions_[identifier->getIdentifier()] = munition;316 return munition;317 }318 317 else 319 318 { 320 return 0; 319 return NULL; 320 } 321 } 322 323 void WeaponSystem::addMunition(Munition* munition) 324 { 325 if (munition == NULL) 326 { 327 return; 328 } 329 330 SubclassIdentifier<Munition> identifier = munition->getIdentifier(); 331 332 if (identifier) 333 { 334 this->munitions_[identifier] = munition; 335 updateMunition(); 336 } 337 else 338 { 339 orxout(internal_warning) << "Adding munition failed. identifier == NULL " << endl; 340 } 341 } 342 343 void WeaponSystem::updateMunition() 344 { 345 for (std::vector<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it) 346 { 347 (*it)->updateMunition(); 321 348 } 322 349 } -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.h
r10650 r11052 67 67 void removeWeaponPack(WeaponPack * wPack); 68 68 WeaponPack * getWeaponPack(unsigned int index) const; 69 std::vector<WeaponPack *> * getAllWeaponPacks(); 69 70 70 71 // configure slots and firemodes … … 76 77 77 78 Munition * getMunition(SubclassIdentifier<Munition> * identifier); 79 void addMunition(Munition* munition); 78 80 79 81 inline void setPawn(Pawn * pawn) … … 95 97 96 98 private: 99 void updateMunition(); 100 97 101 std::map<unsigned int, WeaponSet *> weaponSets_; 98 102 std::vector<WeaponSlot *> weaponSlots_;
Note: See TracChangeset
for help on using the changeset viewer.