Changeset 11208 for code/branches/presentationFS16/src/orxonox/weaponsystem
- Timestamp:
- May 26, 2016, 4:53:34 PM (9 years ago)
- Location:
- code/branches/presentationFS16
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS16
- Property svn:mergeinfo changed
/code/branches/sagerjFS16 (added) merged: 11138,11142,11153,11164,11166,11170,11174-11175,11185,11189,11205
- Property svn:mergeinfo changed
-
code/branches/presentationFS16/src/orxonox/weaponsystem/Weapon.cc
r11071 r11208 99 99 Fire this Weapon with the the WeaponMode defined by @param mode 100 100 */ 101 void Weapon:: fire(unsigned int mode)101 void Weapon::push(unsigned int mode) 102 102 { 103 103 // To avoid firing with more than one mode at the same time, we lock the weapon (reloading) for … … 114 114 // Note: The reloading of each WeaponMode is internally handled by each A, B and C. 115 115 // The reloading of the weapon is only performed to avoid firing with different modes at the same time. 116 117 116 118 if (this->bReloading_ && this->reloadingWeaponmode_ != mode) 117 119 return; … … 123 125 { 124 126 float reloading_time = 0; 125 if (it->second->fire(&reloading_time)) 127 if (it->second->push(&reloading_time)) 128 { 129 this->bReloading_ = true; 130 this->reloadingWeaponmode_ = mode; 131 132 this->reloadTimer_.setInterval(reloading_time); 133 this->reloadTimer_.startTimer(); 134 } 135 } 136 } 137 138 void Weapon::release(unsigned int mode) 139 { 140 if (this->bReloading_ && this->reloadingWeaponmode_ != mode) 141 return; 142 143 std::multimap<unsigned int, WeaponMode*>::iterator start = this->weaponmodes_.lower_bound(mode); 144 std::multimap<unsigned int, WeaponMode*>::iterator end = this->weaponmodes_.upper_bound(mode); 145 146 for (std::multimap<unsigned int, WeaponMode*>::iterator it = start; it != end; ++it) 147 { 148 float reloading_time = 0; 149 if (it->second->release(&reloading_time)) 126 150 { 127 151 this->bReloading_ = true; -
code/branches/presentationFS16/src/orxonox/weaponsystem/Weapon.h
r11071 r11208 52 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 53 53 54 void fire(unsigned int mode); 54 void push(unsigned int mode); 55 void release(unsigned int mode); 55 56 void reload(); 56 57 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponMode.cc
r11108 r11208 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Johannes Sager 27 27 * 28 28 */ … … 63 63 this->bAutoReload_ = true; 64 64 this->bParallelReload_ = true; 65 this->chargeable_ = false; // most weapons are not chargeable 66 this->charges_ = 0; // always start with no charges 67 this->maxCharges_ = 100; // default maximum charges one can have are 100 65 68 66 69 this->reloadTimer_.setTimer(0.0f, false, createExecutor(createFunctor(&WeaponMode::reloaded, this))); … … 121 124 { 122 125 (*reloadTime) = this->reloadTime_; 123 124 126 // Fireing is only possible if this weapon mode is not reloading and there is enough munition 125 127 if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this)) … … 169 171 } 170 172 173 bool WeaponMode::push(float* reloadTime) 174 { 175 176 if( this->chargeable_) // chargeable weapons are supposed to charge on push 177 { 178 this->munition_ = this->weapon_->getWeaponPack()->getWeaponSystem()->getMunition(&this->munitiontype_); // updates the pointer to the munition(which we use in the next step) 179 if(this->charges_ < this->maxCharges_ && this->bReloading_ == false && this->munition_->canTakeMunition(1, this)) // charges up unless: 180 { // - we are fully charged 181 this->charges_ += 1; // - we are reloading 182 } // - we have no munition 183 return false; 184 } 185 else // normal (not chargeable) weapons are supposed to fire on push 186 { 187 return fire(reloadTime); 188 } 189 } 190 191 bool WeaponMode::release(float* reloadTime) 192 { 193 if( this->chargeable_) // chargeable weapons are supposed to fire on release 194 { 195 return fire(reloadTime); 196 } 197 else // normal (not chargeable) weapons should do nothing on release 198 { 199 return false; 200 } 201 } 202 171 203 bool WeaponMode::reload() 172 204 { -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponMode.h
r11108 r11208 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Johannes Sager 27 27 * 28 28 */ … … 45 45 /** 46 46 @brief 47 A WeaponMode defines how a Weapon is used. It specifies what kind of @ref orxonox::Projectile is created when you fire it, how much time it takes to reload, what sound you hear while shooting, how much damage the projectile deals to a target, ... 47 A WeaponMode defines how a Weapon is used. It specifies what kind of 48 @ref orxonox::Projectile is created when you fire it, how much time it takes to reload, 49 what sound you hear while shooting, how much damage the projectile deals to a target, ... 48 50 */ 49 51 class _OrxonoxExport WeaponMode : public BaseObject … … 55 57 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 56 58 59 virtual bool push(float* reloadTime); 60 virtual bool release(float* reloadTime); 57 61 virtual bool fire(float* reloadTime); 58 62 bool reload(); … … 106 110 107 111 // Fire 112 inline unsigned int getMaxCharges() // get the maximum of charges one can have 113 { return this->maxCharges_;} 114 inline unsigned int getCharges() // get the current amount of charges 115 { return this->charges_;} 116 inline bool isChargeable() // returns if the weaponmode is chargeable 117 { return this->chargeable_;} 108 118 inline void setDamage(float damage) 109 119 { this->damage_ = damage;} … … 166 176 unsigned int initialMagazines_; 167 177 unsigned int munitionPerShot_; 178 unsigned int charges_; // current amount of charges only matters for chargeable weapons(chargeable == true) 179 unsigned int maxCharges_; // maximum amount of charges (is initialized with 100 in weaponmode.cc) only matters for chargeable weapons(chargeable == true) 168 180 169 181 float reloadTime_; 170 bool bAutoReload_; // If true, the weapon reloads the magazine automatically. 171 bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. 182 bool bAutoReload_; // If true, the weapon reloads the magazine automatically. 183 bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. 184 bool chargeable_; // If true, the weapon charges up on push and fires on release 172 185 173 186 float damage_; … … 189 202 190 203 Timer reloadTimer_; 191 bool bReloading_; // If true, this weapon mode is marked as reloading.204 bool bReloading_; // If true, this weapon mode is marked as reloading. 192 205 193 206 Vector3 muzzlePosition_; 194 207 Quaternion muzzleOrientation_; 195 208 196 std::string fireSoundPath_; // The path of the sound played when fireing197 float fireSoundVolume_; // The volume of the sound played when fireing198 std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.199 std::string reloadSoundPath_; // The path of the sound played when reloading200 float reloadSoundVolume_; // The volume of the sound played when reloading209 std::string fireSoundPath_; // The path of the sound played when fireing 210 float fireSoundVolume_; // The volume of the sound played when fireing 211 std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance. 212 std::string reloadSoundPath_; // The path of the sound played when reloading 213 float reloadSoundVolume_; // The volume of the sound played when reloading 201 214 WorldSound* reloadSound_; 202 215 }; -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponPack.cc
r11071 r11208 74 74 Fire all weapons in this WeaponSet with the defined weaponmode. 75 75 */ 76 void WeaponPack:: fire(unsigned int weaponmode)76 void WeaponPack::push(unsigned int weaponmode) 77 77 { 78 78 for (Weapon* weapon : this->weapons_) 79 weapon->fire(weaponmode); 79 weapon->push(weaponmode); 80 } 81 82 void WeaponPack::release(unsigned int weaponmode) 83 { 84 for (Weapon* weapon : this->weapons_) 85 weapon->release(weaponmode); 80 86 } 81 87 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponPack.h
r11071 r11208 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 47 47 48 void fire(unsigned int weaponmode); 48 void push(unsigned int weaponmode); 49 void release(unsigned int weaponmode); 49 50 void reload(); 50 51 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSet.cc
r11071 r11208 60 60 } 61 61 62 void WeaponSet:: fire()62 void WeaponSet::push() 63 63 { 64 64 // Fire all WeaponPacks with their defined weaponmode 65 65 for (const auto& mapEntry : this->weaponpacks_) 66 66 if (mapEntry.second != WeaponSystem::WEAPON_MODE_UNASSIGNED) 67 mapEntry.first->fire(mapEntry.second); 67 mapEntry.first->push(mapEntry.second); 68 } 69 70 void WeaponSet::release() 71 { 72 // Fire all WeaponPacks with their defined weaponmode 73 for (const auto& mapEntry : this->weaponpacks_) 74 if (mapEntry.second != WeaponSystem::WEAPON_MODE_UNASSIGNED) 75 mapEntry.first->release(mapEntry.second); 68 76 } 69 77 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSet.h
r11071 r11208 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 47 47 48 void fire(); 48 void push(); 49 void release(); 49 50 void reload(); 50 51 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSystem.cc
r11099 r11208 287 287 Fires the @ref orxonox::WeaponSet with the specified firemode. 288 288 */ 289 void WeaponSystem:: fire(unsigned int firemode)289 void WeaponSystem::push(unsigned int firemode) 290 290 { 291 291 std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(firemode); 292 292 if (it != this->weaponSets_.end() && it->second) 293 it->second->fire(); 293 it->second->push(); 294 } 295 296 void WeaponSystem::release(unsigned int firemode) 297 { 298 std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(firemode); 299 if (it != this->weaponSets_.end() && it->second) 300 it->second->release(); 294 301 } 295 302 -
code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSystem.h
r11176 r11208 76 76 void changeWeaponmode(WeaponPack * wPack, WeaponSet * wSet, unsigned int weaponmode); 77 77 78 void fire(unsigned int firemode); 78 void push(unsigned int firemode); 79 void release(unsigned int firemode); 79 80 void reload(); 80 81
Note: See TracChangeset
for help on using the changeset viewer.