Changeset 6693 in orxonox.OLD for branches/network/src/world_entities/weapons/weapon.cc
- Timestamp:
- Jan 25, 2006, 2:19:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/weapons/weapon.cc
r6674 r6693 95 95 this->maxCharge = 1.0; //< The maximum charge is also one unit. 96 96 97 this->energyLoaded = .0; //< How much energy is loaded in the Gun. (Weapons must be charged befor usage) 98 this->energyLoadedMax = 5.0; //< Each Weapon has a Maximum energy that can be charged onto it 99 this->energy = .0; //< The secondary Buffer (before we have to reload) 97 this->energy = 10; //< The secondary Buffer (before we have to reload) 100 98 this->energyMax = 10.0; //< How much energy can be carried 101 99 this->capability = WTYPE_ALL; //< The Weapon has all capabilities @see W_Capability. 102 100 103 101 this->energyWidget = NULL; 104 this->energyLoadedWidget = NULL;105 102 106 103 // set this object to be synchronized over network … … 291 288 } 292 289 293 294 GLGuiWidget* Weapon::getLoadedEnergyWidget()295 {296 if (this->energyLoadedWidget == NULL)297 {298 this->energyLoadedWidget = new GLGuiBar;299 //this->energyLoadedWidget->setParent2D(this->bar);300 this->energyLoadedWidget->setRelCoor2D(20,0);301 this->energyLoadedWidget->setSize2D(10,50);302 this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax());303 }304 return this->energyLoadedWidget;305 }306 307 290 void Weapon::updateWidgets() 308 291 { … … 311 294 this->energyWidget->setMaximum(this->energyMax); 312 295 this->energyWidget->setValue(this->energy); 313 }314 if (this->energyLoadedWidget != NULL)315 {316 this->energyLoadedWidget->setMaximum(this->energyLoadedMax);317 this->energyLoadedWidget->setValue(this->energyLoaded);318 296 } 319 297 } … … 395 373 switch (action) 396 374 { 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 375 case WA_SHOOT: 376 return this->fireW(); 377 break; 378 case WA_CHARGE: 379 return this->chargeW(); 380 break; 381 case WA_RELOAD: 382 return this->reloadW(); 383 break; 384 case WA_DEACTIVATE: 385 return this->deactivateW(); 386 break; 387 case WA_ACTIVATE: 388 return this->activateW(); 389 break; 412 390 } 413 391 } … … 457 435 bool Weapon::chargeW() 458 436 { 459 if ( this->currentState != WS_INACTIVE && this->energy Loaded>= this->minCharge)437 if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge) 460 438 { 461 439 // playing Sound … … 481 459 { 482 460 //if (likely(this->currentState != WS_INACTIVE)) 483 if (this->minCharge <= this->energy Loaded)461 if (this->minCharge <= this->energy) 484 462 { 485 463 // playing Sound … … 488 466 this->updateWidgets(); 489 467 // fire 490 this->energy Loaded-= this->minCharge;468 this->energy -= this->minCharge; 491 469 this->fire(); 492 470 // setting up for the next state … … 507 485 { 508 486 PRINTF(4)("Reloading Weapon %s\n", this->getName()); 509 if (unlikely(this->energy + this->energyLoaded < this->minCharge)) 487 if (this->ammoContainer.get() != NULL && 488 unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge)) 510 489 { 511 490 this->requestAction(WA_DEACTIVATE); … … 514 493 } 515 494 516 float chargeSize = this->energyLoadedMax - this->energyLoaded; //!< The energy to be charged517 495 518 496 if (this->soundBuffers[WA_RELOAD] != NULL) 519 497 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 520 498 521 if (chargeSize > this->energy) 522 { 523 this->energyLoaded += this->energy; 524 this->energy = 0.0; 525 PRINT(5)("Energy depleted\n"); 526 } 527 else 528 { 529 PRINTF(5)("Loaded %f energy into the Guns Buffer\n", chargeSize); 530 this->energyLoaded += chargeSize; 531 this->energy -= chargeSize; 532 } 533 499 if (this->ammoContainer.get() != NULL) 500 this->ammoContainer->fillWeapon(this); 501 else 502 { 503 this->energy = this->energyMax; 504 } 534 505 this->updateWidgets(); 535 506 this->reload(); … … 617 588 { 618 589 PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction)); 619 PRINT(0)("Energy: max: %f; current: %f; loadedMax: %f; loadedCurrent: %f;chargeMin: %f, chargeMax %f\n",620 this->energyMax, this->energy, this-> energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);590 PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n", 591 this->energyMax, this->energy, this->minCharge, this->maxCharge); 621 592 622 593 … … 663 634 switch (action) 664 635 { 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 636 case WA_SHOOT: 637 return "shoot"; 638 break; 639 case WA_CHARGE: 640 return "charge"; 641 break; 642 case WA_RELOAD: 643 return "reload"; 644 break; 645 case WA_ACTIVATE: 646 return "activate"; 647 break; 648 case WA_DEACTIVATE: 649 return "deactivate"; 650 break; 651 case WA_SPECIAL1: 652 return "special1"; 653 break; 654 default: 655 return "none"; 656 break; 686 657 } 687 658 } … … 726 697 switch (state) 727 698 { 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 } 753 } 699 case WS_SHOOTING: 700 return "shooting"; 701 break; 702 case WS_CHARGING: 703 return "charging"; 704 break; 705 case WS_RELOADING: 706 return "reloading"; 707 break; 708 case WS_ACTIVATING: 709 return "activating"; 710 break; 711 case WS_DEACTIVATING: 712 return "deactivating"; 713 break; 714 case WS_IDLE: 715 return "idle"; 716 break; 717 case WS_INACTIVE: 718 return "inactive"; 719 break; 720 default: 721 return "none"; 722 break; 723 } 724 }
Note: See TracChangeset
for help on using the changeset viewer.