Changeset 6438 in orxonox.OLD for trunk/src/world_entities/weapons/weapon.cc
- Timestamp:
- Jan 8, 2006, 1:51:55 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/weapons/weapon.cc
r6435 r6438 34 34 #include "sound_buffer.h" 35 35 36 #include "glgui_bar.h" 37 36 38 //////////////////// 37 39 // INITAILISATION // … … 75 77 this->stateDuration = 0.0; //< All the States have zero duration 76 78 for (int i = 0; i < WS_STATE_COUNT; i++) //< Every State has: 77 78 79 80 79 { 80 this->times[i] = 0.0; //< An infinitesimal duration 81 this->animation[i] = NULL; //< No animation 82 } 81 83 for (int i = 0; i < WA_ACTION_COUNT; i++) 82 84 this->soundBuffers[i] = NULL; //< No Sounds … … 98 100 this->energyMax = 10.0; //< How much energy can be carried 99 101 this->capability = WTYPE_ALL; //< The Weapon has all capabilities @see W_Capability. 102 103 this->energyWidget = NULL; 104 this->energyLoadedWidget = NULL; 100 105 } 101 106 … … 109 114 110 115 LoadParam(root, "projectile", this, Weapon, setProjectileType) 111 116 .describe("Sets the name of the Projectile to load onto the Entity"); 112 117 113 118 LoadParam(root, "emission-point", this, Weapon, setEmissionPoint) 114 119 .describe("Sets the Point of emission of this weapon"); 115 120 116 121 LoadParam(root, "state-duration", this, Weapon, setStateDuration) 117 122 .describe("Sets the duration of a given state (1: state-Name; 2: duration in seconds)"); 118 123 119 124 LoadParam(root, "action-sound", this, Weapon, setActionSound) 120 125 .describe("Sets a given sound to an action (1: action-Name; 2: name of the sound (relative to the Data-Path))"); 121 126 } 122 127 … … 271 276 } 272 277 278 GLGuiWidget* Weapon::getEnergyWidget() 279 { 280 if (this->energyWidget == NULL) 281 { 282 this->energyWidget = new GLGuiBar; 283 this->energyWidget->setSize2D( 20, 100); 284 this->energyWidget->setMaximum(this->getEnergyMax()); 285 this->energyWidget->setValue(this->getEnergy()); 286 } 287 return this->energyWidget; 288 } 289 290 291 GLGuiWidget* Weapon::getMaxEnergyWidget() 292 { 293 if (this->energyLoadedWidget == NULL) 294 { 295 this->energyLoadedWidget = new GLGuiBar; 296 //this->energyLoadedWidget->setParent2D(this->bar); 297 this->energyLoadedWidget->setRelCoor2D(20,0); 298 this->energyLoadedWidget->setSize2D(10,50); 299 this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax()); 300 } 301 return this->energyLoadedWidget; 302 } 303 304 void Weapon::updateWidgets() 305 { 306 if (this->energyWidget != NULL) 307 { 308 this->energyWidget->setMaximum(this->energyMax); 309 this->energyWidget->setValue(this->energy); 310 } 311 if (this->energyLoadedWidget != NULL) 312 { 313 this->energyLoadedWidget->setMaximum(this->energyLoadedMax); 314 this->energyLoadedWidget->setValue(this->energyLoaded); 315 } 316 } 317 273 318 ///////////////// 274 319 // EXECUTION // … … 371 416 bool Weapon::activateW() 372 417 { 373 // if (this->currentState == WS_INACTIVE)418 // if (this->currentState == WS_INACTIVE) 374 419 { 375 420 // play Sound 376 421 if (likely(this->soundBuffers[WA_ACTIVATE] != NULL)) 377 422 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 378 423 // activate 379 424 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 380 425 this->activate(); … … 390 435 bool Weapon::deactivateW() 391 436 { 392 // if (this->currentState != WS_INACTIVE)437 // if (this->currentState != WS_INACTIVE) 393 438 { 394 439 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 395 440 // play Sound 396 441 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 397 442 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); … … 410 455 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 411 456 { 412 457 // playing Sound 413 458 if (this->soundBuffers[WA_CHARGE] != NULL) 414 459 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 415 460 416 461 // charge 417 462 this->charge(); 418 463 // setting up for the next state 419 464 this->enterState(WS_CHARGING); 420 465 } … … 431 476 bool Weapon::fireW() 432 477 { 433 478 //if (likely(this->currentState != WS_INACTIVE)) 434 479 if (this->minCharge <= this->energyLoaded) 435 480 { 436 481 // playing Sound 437 482 if (this->soundBuffers[WA_SHOOT] != NULL) 438 483 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 439 484 // fire 440 485 this->energyLoaded -= this->minCharge; 441 486 this->fire(); 442 487 // setting up for the next state 443 488 this->enterState(WS_SHOOTING); 444 489 } … … 546 591 bool retVal = true; 547 592 548 // if (this->projectile == NULL)593 // if (this->projectile == NULL) 549 594 { 550 595 PRINTF(1)("There was no projectile assigned to the Weapon.\n"); … … 565 610 PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction)); 566 611 PRINT(0)("Energy: max: %f; current: %f; loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n", 567 612 this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge); 568 613 569 614 … … 595 640 return WA_SPECIAL1; 596 641 else 597 598 599 600 642 { 643 PRINTF(2)("action %s could not be identified.\n", action); 644 return WA_NONE; 645 } 601 646 } 602 647 … … 658 703 return WS_IDLE; 659 704 else 660 661 662 663 705 { 706 PRINTF(2)("state %s could not be identified.\n", state); 707 return WS_NONE; 708 } 664 709 } 665 710
Note: See TracChangeset
for help on using the changeset viewer.