- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/orxonox/weaponsystem/WeaponMode.cc
r5929 r6412 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "controllers/Controller.h" 35 #include "worldentities/pawns/Pawn.h" 34 36 35 37 #include "Munition.h" … … 37 39 #include "WeaponPack.h" 38 40 #include "WeaponSystem.h" 41 #include "WeaponSlot.h" 42 43 #include "sound/WorldSound.h" 39 44 40 45 namespace orxonox … … 61 66 62 67 this->damage_ = 0; 68 63 69 this->muzzleOffset_ = Vector3::ZERO; 70 this->muzzlePosition_ = Vector3::ZERO; 71 this->muzzleOrientation_ = Quaternion::IDENTITY; 72 73 if( GameMode::isMaster() ) 74 { 75 this->defSndWpnFire_ = new WorldSound(this); 76 this->defSndWpnFire_->setLooping(false); 77 this->bSoundAttached_ = false; 78 } 79 else 80 this->defSndWpnFire_ = 0; 64 81 } 65 82 66 83 WeaponMode::~WeaponMode() 67 84 { 85 if (this->isInitialized()) 86 { 87 if (this->defSndWpnFire_) 88 this->defSndWpnFire_->destroy(); 89 } 68 90 } 69 91 … … 90 112 { 91 113 (*reloadTime) = this->reloadTime_; 114 if( !this->bSoundAttached_ && GameMode::isMaster() ) 115 { 116 assert(this->getWeapon()); 117 this->getWeapon()->attach(this->defSndWpnFire_); 118 this->bSoundAttached_ = true; 119 } 92 120 93 121 if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this)) … … 108 136 this->reloadTimer_.startTimer(); 109 137 138 if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying())) 139 { 140 this->defSndWpnFire_->play(); 141 } 142 110 143 this->fire(); 111 144 … … 145 178 { 146 179 this->munitionname_ = munitionname; 147 this->munitiontype_ = ClassByString(this->munitionname_); 180 Identifier* identifier = ClassByString(this->munitionname_); 181 if (identifier) 182 this->munitiontype_ = identifier; 183 else 184 COUT(2) << "Warning: No munition class defined in WeaponMode " << this->getName() << std::endl; 148 185 this->updateMunition(); 149 186 } … … 191 228 void WeaponMode::reloaded() 192 229 { 230 if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying()) 231 { 232 this->defSndWpnFire_->stop(); 233 } 193 234 this->bReloading_ = false; 194 235 } 195 236 196 Vector3 WeaponMode::getMuzzlePosition() const237 void WeaponMode::computeMuzzleParameters(const Vector3& target) 197 238 { 198 239 if (this->weapon_) 199 return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_); 200 else 201 return this->muzzleOffset_; 202 } 203 204 const Quaternion& WeaponMode::getMuzzleOrientation() const 240 { 241 this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_; 242 243 Vector3 muzzleDirection; 244 muzzleDirection = target - this->muzzlePosition_; 245 // COUT(0) << "muzzleDirection " << muzzleDirection << endl; 246 this->muzzleOrientation_ = (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection) * this->weapon_->getWorldOrientation(); 247 } 248 else 249 { 250 this->muzzlePosition_ = this->muzzleOffset_; 251 this->muzzleOrientation_ = Quaternion::IDENTITY; 252 } 253 } 254 255 Vector3 WeaponMode::getMuzzleDirection() const 205 256 { 206 257 if (this->weapon_) 207 return this->weapon_->getWorldOrientation(); 208 else 209 return Quaternion::IDENTITY; 210 } 211 212 Vector3 WeaponMode::getMuzzleDirection() const 213 { 214 if (this->weapon_) 215 return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT); 258 return (this->getMuzzleOrientation() * WorldEntity::FRONT); 216 259 else 217 260 return WorldEntity::FRONT; 218 261 } 262 263 void WeaponMode::setDefaultSound(const std::string& soundPath) 264 { 265 if( this->defSndWpnFire_ ) 266 this->defSndWpnFire_->setSource(soundPath); 267 } 268 269 const std::string& WeaponMode::getDefaultSound() 270 { 271 if( this->defSndWpnFire_ ) 272 return this->defSndWpnFire_->getSource(); 273 else 274 return BLANKSTRING; 275 } 219 276 }
Note: See TracChangeset
for help on using the changeset viewer.