Changeset 4892 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons/weapon.cc
- Timestamp:
- Jul 19, 2005, 4:59:58 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4891 r4892 30 30 #include "sound_engine.h" 31 31 32 //////////////////// 33 // INITAILISATION // 34 // SETTING VALUES // 35 //////////////////// 32 36 /** 33 37 * standard constructor … … 74 78 this->requestedAction = WA_NONE; 75 79 this->soundSource = new SoundSource(this); 80 this->emissionPoint.setParent(this); 76 81 77 82 this->active = true; … … 86 91 } 87 92 93 94 /** 95 * sets the emissionPoint's relative position from the Weapon 96 * @param point the Point relative to the mass-point of the Weapon 97 */ 98 void Weapon::setEmissionPoint(const Vector& point) 99 { 100 this->emissionPoint.setRelCoor(point); 101 } 88 102 89 103 /** … … 112 126 } 113 127 128 ///////////////// 129 // EXECUTION // 130 // GAME ACTION // 131 ///////////////// 132 114 133 /** 115 134 * request an action that should be executed, … … 152 171 } 153 172 173 ////////////////////// 174 // WEAPON INTERNALS // 175 ////////////////////// 154 176 /** 155 177 * executes an action, and with it starts a new State. … … 169 191 { 170 192 case WA_SHOOT: 171 //if (likely(this->currentState != WS_INACTIVE)) 172 { 173 if (this->minCharge <= this->energyLoaded) 174 { 193 this->fireW(); 194 break; 195 case WA_CHARGE: 196 this->chargeW(); 197 break; 198 case WA_RELOAD: 199 this->reloadW(); 200 break; 201 case WA_DEACTIVATE: 202 this->deactivateW(); 203 break; 204 case WA_ACTIVATE: 205 this->activateW(); 206 break; 207 } 208 } 209 210 211 /** 212 * 213 * @return 214 */ 215 bool Weapon::activateW() 216 { 217 218 if (this->currentState == WS_INACTIVE) 219 { 220 // play Sound 221 if (this->soundBuffers[WA_ACTIVATE] != NULL) 222 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 223 // activate 224 PRINTF(5)("Activating the Weapon %s\n", this->getName()); 225 this->activate(); 226 // setting up for next action 227 this->requestedAction = WA_NONE; 228 this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration; 229 } 230 } 231 232 233 /** 234 * 235 * @return 236 */ 237 bool Weapon::deactivateW() 238 { 239 if (this->currentState != WS_INACTIVE) 240 { 241 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 242 // play Sound 243 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 244 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 245 // deactivate 246 this->deactivate(); 247 // setting up for next action 248 this->requestedAction = WA_NONE; 249 this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration; 250 } 251 252 } 253 254 /** 255 * 256 * @return 257 */ 258 bool Weapon::chargeW() 259 { 260 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 261 { 262 // playing Sound 263 if (this->soundBuffers[WA_CHARGE] != NULL) 264 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 265 // charge 266 this->charge(); 267 // setting up for the next state 268 this->requestedAction = WA_NONE; 269 this->stateDuration = this->times[WA_CHARGE] + this->stateDuration; 270 } 271 else // deactivate the Weapon if we do not have enough energy 272 { 273 this->requestedAction = WA_NONE; 274 this->requestAction(WA_RELOAD); 275 } 276 277 } 278 279 /** 280 * 281 * @return 282 */ 283 bool Weapon::fireW() 284 { 285 //if (likely(this->currentState != WS_INACTIVE)) 286 if (this->minCharge <= this->energyLoaded) 287 { 175 288 // playing Sound 176 177 289 if (this->soundBuffers[WA_SHOOT] != NULL) 290 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 178 291 // fire 179 this->fire(); 292 this->fire(); 293 this->energyLoaded -= this->minCharge; 180 294 // setting up for the next state 181 this->stateDuration = this->times[WA_SHOOT] + this->stateDuration; 182 this->requestedAction = WA_NONE; 183 } 184 else // reload if we still have the charge 185 { 186 this->requestedAction = WA_NONE; 187 this->requestAction(WA_RELOAD); 188 } 189 } 190 break; 191 case WA_CHARGE: 192 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 193 { 194 // playing Sound 195 if (this->soundBuffers[WA_CHARGE] != NULL) 196 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 197 // charge 198 this->charge(); 199 // setting up for the next state 200 this->requestedAction = WA_NONE; 201 this->stateDuration = this->times[WA_CHARGE] + this->stateDuration; 202 } 203 else // deactivate the Weapon if we do not have enough energy 204 { 205 this->requestedAction = WA_NONE; 206 this->requestAction(WA_RELOAD); 207 } 208 break; 209 case WA_RELOAD: 210 //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge) 211 { 212 // playing Sound 213 if (this->soundBuffers[WA_RELOAD] != NULL) 214 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 215 // reload 216 this->reload(); 217 // setting up for next action 218 this->requestedAction = WA_NONE; 219 this->stateDuration = this->times[WA_RELOAD] + this->stateDuration; 220 } 221 break; 222 case WA_DEACTIVATE: 223 if (this->currentState != WS_INACTIVE) 224 { 225 // play Sound 226 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 227 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 228 // deactivate 229 this->deactivate(); 230 // setting up for next action 231 this->requestedAction = WA_NONE; 232 this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration; 233 } 234 break; 235 case WA_ACTIVATE: 236 if (this->currentState == WS_INACTIVE) 237 { 238 // play Sound 239 if (this->soundBuffers[WA_ACTIVATE] != NULL) 240 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 241 // activate 242 this->activate(); 243 // setting up for next action 244 this->requestedAction = WA_NONE; 245 this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration; 246 } 247 break; 248 } 249 } 250 251 /** 252 * this activates the weapon 253 */ 254 void Weapon::activate() 255 { 256 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 257 258 if (this->soundBuffers[WA_ACTIVATE] != NULL) 259 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 260 } 261 262 263 /** 264 * this deactivates the weapon 265 */ 266 void Weapon::deactivate() 267 { 268 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 269 270 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 271 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 272 } 273 274 void Weapon::fire() 275 { 276 this->energyLoaded -= this->minCharge; 277 278 if (this->soundBuffers[WA_SHOOT] != NULL) 279 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 280 } 281 282 void Weapon::reload() 295 this->stateDuration = this->times[WA_SHOOT] + this->stateDuration; 296 this->requestedAction = WA_NONE; 297 } 298 else // reload if we still have the charge 299 { 300 this->requestedAction = WA_NONE; 301 this->requestAction(WA_RELOAD); 302 } 303 } 304 305 306 /** 307 * 308 * @return 309 */ 310 bool Weapon::reloadW() 283 311 { 284 312 PRINTF(4)("Reloading Weapon %s\n", this->getName()); 285 if ( this->energy + this->energyLoaded < this->minCharge)313 if (unlikely(this->energy + this->energyLoaded < this->minCharge)) 286 314 { 287 315 this->requestAction(WA_DEACTIVATE); 288 return ;316 return false; 289 317 } 290 318 291 319 float chargeSize = this->energyLoadedMax - this->energyLoaded; //!< The energy to be charged 320 321 if (this->soundBuffers[WA_RELOAD] != NULL) 322 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 292 323 293 324 if (chargeSize > this->energy) … … 303 334 this->energy -= chargeSize; 304 335 } 305 if (this->soundBuffers[WA_RELOAD] != NULL) 306 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 307 308 } 309 310 void Weapon::charge() 311 { 312 if (this->soundBuffers[WA_CHARGE] != NULL) 313 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 314 315 } 316 317 318 /** 319 * is called, when the weapon is destroyed 320 * 321 * this is in conjunction with the hit function, so when a weapon is able to get 322 * hit, it can also be destoryed. 323 */ 324 void Weapon::destroy () 325 {} 336 this->reload(); 337 338 this->requestedAction = WA_NONE; 339 this->stateDuration = this->times[WA_RELOAD] + this->stateDuration; 340 341 } 326 342 327 343
Note: See TracChangeset
for help on using the changeset viewer.