Changeset 10688 for code/branches/fabienHS15/src/orxonox
- Timestamp:
- Oct 24, 2015, 10:51:18 PM (9 years ago)
- Location:
- code/branches/fabienHS15/src/orxonox
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/orxonox/weaponsystem/CMakeLists.txt
r5781 r10688 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Munition.cc 3 ReplenishingMunition.cc 3 4 Weapon.cc 4 5 WeaponMode.cc -
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc
r9667 r10688 45 45 this->magazines_ = 10; 46 46 47 this->bUseSeparateMagazines_ = false; 48 this->bStackMunition_ = true; 47 this->deployment_ = DEPLOYMENT_STACK; 49 48 this->bAllowMunitionRefilling_ = true; 50 49 this->bAllowMultiMunitionRemovementUnderflow_ = true; 51 50 52 this->reloadTime_ = 0 ;51 this->reloadTime_ = 0.5f; 53 52 } 54 53 … … 61 60 Munition::Magazine* Munition::getMagazine(WeaponMode* user) const 62 61 { 63 if ( this->bUseSeparateMagazines_)62 if (deployment_ == DEPLOYMENT_SEPARATE) 64 63 { 65 64 // For separated magazines we definitively need a given user … … 87 86 if (magazine) 88 87 { 89 if ( this->bStackMunition_)88 if (deployment_ == DEPLOYMENT_STACK) 90 89 // With stacked munition every magazine contributes to the total amount 91 90 return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_; … … 109 108 unsigned int Munition::getNumMagazines() const 110 109 { 111 if ( this->bStackMunition_)110 if (deployment_ == DEPLOYMENT_STACK) 112 111 { 113 112 // If we stack munition and the current magazine is still full, it counts too … … 122 121 unsigned int Munition::getMaxMunition() const 123 122 { 124 if ( this->bStackMunition_)123 if (deployment_ == DEPLOYMENT_STACK) 125 124 return this->maxMunitionPerMagazine_ * this->maxMagazines_; 126 125 else … … 135 134 unsigned int munition = magazine->munition_; 136 135 137 // If we stack munition, we con't care about the current magazine - we just need enough munition in total138 if ( this->bStackMunition_)136 // 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 138 munition += this->maxMunitionPerMagazine_ * this->magazines_; 140 139 … … 169 168 { 170 169 // Not enough munition 171 if ( this->bStackMunition_)170 if (deployment_ == DEPLOYMENT_STACK) 172 171 { 173 172 // We stack munition, so just take what we can and then load the next magazine … … 199 198 { 200 199 // As long as we have enough magazines (and don't stack munition) we can reload 201 return (this->magazines_ > 0 && ! this->bStackMunition_);200 return (this->magazines_ > 0 && !deployment_ == DEPLOYMENT_STACK); 202 201 } 203 202 … … 207 206 if (magazine) 208 207 { 209 if ( this->bStackMunition_)208 if (deployment_ == DEPLOYMENT_STACK) 210 209 // With stacked munition, we never have to reload 211 210 return false; … … 231 230 232 231 // If we use separate magazines for each user, we definitively need a user given 233 if ( this->bUseSeparateMagazines_&& !user)232 if (deployment_ == DEPLOYMENT_SEPARATE && !user) 234 233 return false; 235 234 236 235 // If we don't use separate magazines, set user to 0 237 if (! this->bUseSeparateMagazines_)236 if (!deployment_ == DEPLOYMENT_SEPARATE) 238 237 user = 0; 239 238 … … 260 259 return false; 261 260 262 if ( this->bStackMunition_)261 if (deployment_ == DEPLOYMENT_STACK) 263 262 { 264 263 // If we stack munition, we can always add munition until we reach the limit … … 281 280 return false; 282 281 283 if ( this->bStackMunition_)282 if (deployment_ == DEPLOYMENT_STACK) 284 283 { 285 284 // Stacking munition means, if a magazine gets full, the munition adds to a new magazine … … 340 339 // TODO: 'amount' is not used 341 340 342 if ( this->bStackMunition_)341 if (deployment_ == DEPLOYMENT_STACK) 343 342 // If we stack munition, we can always add new magazines because they contribute directly to the munition 344 343 return (this->getNumMunition(0) < this->getMaxMunition()); … … 357 356 358 357 // 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_)358 if (needed_magazines <= 0 && !deployment_ == DEPLOYMENT_STACK) 360 359 return false; 361 360 … … 369 368 // We get more magazines than we need, so just add the needed amount 370 369 this->magazines_ += needed_magazines; 371 if ( this->bStackMunition_)370 if (deployment_ == DEPLOYMENT_STACK) 372 371 { 373 372 // We stack munition, so the additional amount contributes directly to the munition of the current magazine … … 383 382 bool Munition::canRemoveMagazines(unsigned int amount) const 384 383 { 385 if ( this->bStackMunition_)384 if (deployment_ == DEPLOYMENT_STACK) 386 385 { 387 386 if (this->magazines_ >= amount) … … 422 421 this->magazines_ -= amount; 423 422 } 424 else if ( this->bStackMunition_)423 else if (deployment_ == DEPLOYMENT_STACK) 425 424 { 426 425 // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine … … 437 436 { 438 437 // If we use separate magazines, we need a user 439 if ( this->bUseSeparateMagazines_&& !user)438 if (deployment_ == DEPLOYMENT_SEPARATE && !user) 440 439 return false; 441 440 442 441 // If we don't use separate magazines, set user to 0 443 if (! this->bUseSeparateMagazines_)442 if (!deployment_ == DEPLOYMENT_SEPARATE) 444 443 user = 0; 445 444 … … 465 464 this->bLoaded_ = false; 466 465 467 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition-> bStackMunition_)466 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == DEPLOYMENT_STACK) 468 467 { 469 468 const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this)); -
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h
r9667 r10688 39 39 namespace orxonox 40 40 { 41 enum Deployment 42 { 43 DEPLOYMENT_SHARE, 44 DEPLOYMENT_STACK, 45 DEPLOYMENT_SEPARATE 46 }; 47 48 41 49 class _OrxonoxExport Munition : public BaseObject 42 { 50 { 43 51 struct Magazine 44 52 { … … 68 76 inline unsigned int getMaxMunitionPerMagazine() const 69 77 { return this->maxMunitionPerMagazine_; } 78 inline bool getUseSeparateMagazines() const 79 { return deployment_ == DEPLOYMENT_SEPARATE; } 80 inline bool getStackMunition() const 81 { return deployment_ == DEPLOYMENT_STACK; } 70 82 71 83 bool canTakeMunition(unsigned int amount, WeaponMode* user) const; … … 95 107 std::map<WeaponMode*, Magazine*> currentMagazines_; 96 108 97 bool bUseSeparateMagazines_;98 bool bStackMunition_; 109 Deployment deployment_; 110 99 111 bool bAllowMunitionRefilling_; 100 112 bool bAllowMultiMunitionRemovementUnderflow_; -
code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.cc
r10650 r10688 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 { -
code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.h
r10650 r10688 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 /** -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.cc
r10650 r10688 75 75 this->muzzleOrientation_ = Quaternion::IDENTITY; 76 76 77 hudImageString_ = "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); … … 283 294 } 284 295 285 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){ 286 if (this->defSndWpnFire_) { 296 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume) 297 { 298 if (this->defSndWpnFire_) 299 { 287 300 this->defSndWpnFire_->setSource(soundPath); 288 301 this->defSndWpnFire_->setVolume(soundVolume); -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.h
r10650 r10688 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 149 155 protected: 150 156 virtual void fire() = 0; … … 155 161 156 162 float reloadTime_; 157 bool bAutoReload_; 158 bool bParallelReload_; 163 bool bAutoReload_; // If true, the weapon reloads the magazine automatically. 164 bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. 159 165 160 166 float damage_; … … 162 168 float shielddamage_; 163 169 Vector3 muzzleOffset_; 170 171 std::string hudImageString_; 164 172 165 173 private: … … 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_; -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.cc
r10650 r10688 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 { -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.h
r9667 r10688 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 -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.cc
r10650 r10688 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 { -
code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.h
r10650 r10688 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 -
code/branches/fabienHS15/src/orxonox/worldentities/pawns/Pawn.cc
r10650 r10688 554 554 } 555 555 556 std::vector<WeaponPack *> * Pawn::getAllWeaponPacks() 557 { 558 if (this->weaponSystem_) 559 return this->weaponSystem_->getAllWeaponPacks(); 560 else 561 return 0; 562 } 563 556 564 //Tell the Map (RadarViewable), if this is a playership 557 565 void Pawn::startLocalHumanControl() -
code/branches/fabienHS15/src/orxonox/worldentities/pawns/Pawn.h
r10437 r10688 154 154 void addWeaponPackXML(WeaponPack * wPack); 155 155 WeaponPack * getWeaponPack(unsigned int index) const; 156 std::vector<WeaponPack *> * getAllWeaponPacks(); 156 157 157 158 virtual void addedWeaponPack(WeaponPack* wPack) {}
Note: See TracChangeset
for help on using the changeset viewer.