Changeset 9869 in orxonox.OLD for trunk/src/world_entities/weapons/weapon.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/weapons/weapon.cc
r9406 r9869 21 21 #include "weapon.h" 22 22 23 #include " fast_factory.h"23 #include "loading/fast_factory.h" 24 24 #include "world_entities/projectiles/projectile.h" 25 25 26 #include "util/loading/resource_manager.h"27 #include "class_list.h"28 26 #include "util/loading/factory.h" 29 27 #include "util/loading/load_param.h" … … 33 31 #include "sound_source.h" 34 32 #include "sound_buffer.h" 33 #include "resource_sound_buffer.h" 35 34 36 35 #include "elements/glgui_energywidget.h" 37 36 38 37 ObjectListDefinition(Weapon); 39 38 40 39 //////////////////// … … 58 57 { 59 58 for (int i = 0; i < WS_STATE_COUNT; i++) 60 if (this->animation[i] && ClassList::exists(animation[i], CL_ANIMATION)) //!< @todo this should check animation3D59 if (this->animation[i] && Animation::objectList().exists(animation[i])) //!< @todo this should check animation3D 61 60 delete this->animation[i]; 62 for (int i = 0; i < WA_ACTION_COUNT; i++) 63 if (this->soundBuffers[i] != NULL && ClassList::exists(this->soundBuffers[i], CL_SOUND_BUFFER)) 64 ResourceManager::getInstance()->unload(this->soundBuffers[i]); 65 66 if (ClassList::exists(this->soundSource, CL_SOUND_SOURCE)) 61 62 if (OrxSound::SoundSource::objectList().exists(this->soundSource)) 67 63 delete this->soundSource; 68 64 } … … 73 69 * @returns the newly created Weapon. 74 70 */ 75 Weapon* Weapon::createWeapon( ClassIDweaponID)71 Weapon* Weapon::createWeapon(const ClassID& weaponID) 76 72 { 77 73 BaseObject* createdObject = Factory::fabricate(weaponID); 78 74 if (createdObject != NULL) 79 75 { 80 if (createdObject->isA( CL_WEAPON))76 if (createdObject->isA(Weapon::staticClassID())) 81 77 return dynamic_cast<Weapon*>(createdObject); 82 78 else … … 89 85 } 90 86 87 Weapon* Weapon::createWeapon(const std::string& weaponName) 88 { 89 BaseObject* createdObject = Factory::fabricate(weaponName); 90 if (createdObject != NULL) 91 { 92 if (createdObject->isA(Weapon::staticClassID())) 93 return dynamic_cast<Weapon*>(createdObject); 94 else 95 { 96 delete createdObject; 97 return NULL; 98 } 99 } 100 return NULL; 101 } 102 103 91 104 /** 92 105 * initializes the Weapon with ALL default values … … 96 109 void Weapon::init() 97 110 { 98 this-> setClassID(CL_WEAPON, "Weapon");111 this->registerObject(this, Weapon::_objectList); 99 112 this->currentState = WS_INACTIVE; //< Normaly the Weapon is Inactive 100 113 this->requestedAction = WA_NONE; //< No action is requested by default … … 105 118 this->animation[i] = NULL; //< No animation 106 119 } 107 for (int i = 0; i < WA_ACTION_COUNT; i++)108 this->soundBuffers[i] = NULL; //< No Sounds109 120 110 121 this->soundSource = new OrxSound::SoundSource(this); //< Every Weapon has exacty one SoundSource. … … 115 126 this->defaultTarget = NULL; //< Nothing is Targeted by default. 116 127 117 this->projectile = CL_NULL;//< No Projectile Class is Connected to this weapon128 this->projectile = NullClass::staticClassID(); //< No Projectile Class is Connected to this weapon 118 129 this->projectileFactory = NULL; //< No Factory generating Projectiles is selected. 119 130 … … 163 174 * What it does, is telling the Weapon what Projectiles it can Emit. 164 175 */ 165 void Weapon::setProjectileType(ClassID projectile) 166 { 167 if (projectile == CL_NULL) 168 return; 176 void Weapon::setProjectileType(const ClassID& projectile) 177 { 169 178 this->projectile = projectile; 170 179 this->projectileFactory = FastFactory::searchFastFactory(projectile); … … 259 268 if (action >= WA_ACTION_COUNT) 260 269 return; 261 if (this->soundBuffers[action] != NULL)262 ResourceManager::getInstance()->unload(this->soundBuffers[action]);263 270 264 271 else if (!soundFile.empty()) 265 272 { 266 this->soundBuffers[action] = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV);267 if (this->soundBuffers[action] != NULL)273 this->soundBuffers[action] = OrxSound::ResourceSoundBuffer(soundFile); 274 if (this->soundBuffers[action].loaded()) 268 275 { 269 276 PRINTF(4)("Loaded sound %s to action %s.\n", soundFile.c_str(), actionToChar(action)); … … 275 282 } 276 283 else 277 this->soundBuffers[action] = NULL;284 this->soundBuffers[action] = OrxSound::SoundBuffer(); 278 285 } 279 286 … … 409 416 { 410 417 case WA_SHOOT: 411 412 418 return this->fireW(); 419 break; 413 420 case WA_CHARGE: 414 415 421 return this->chargeW(); 422 break; 416 423 case WA_RELOAD: 417 418 424 return this->reloadW(); 425 break; 419 426 case WA_DEACTIVATE: 420 421 427 return this->deactivateW(); 428 break; 422 429 case WA_ACTIVATE: 423 424 430 return this->activateW(); 431 break; 425 432 default: 426 427 433 PRINTF(2)("Action %s Not Implemented yet \n", Weapon::actionToChar(action)); 434 return false; 428 435 } 429 436 } … … 438 445 { 439 446 // play Sound 440 if (likely(this->soundBuffers[WA_ACTIVATE] != NULL))447 if (likely(this->soundBuffers[WA_ACTIVATE].loaded())) 441 448 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 442 449 this->updateWidgets(); … … 460 467 PRINTF(4)("Deactivating the Weapon %s\n", this->getCName()); 461 468 // play Sound 462 if (this->soundBuffers[WA_DEACTIVATE] != NULL)469 if (this->soundBuffers[WA_DEACTIVATE].loaded()) 463 470 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 464 471 // deactivate … … 479 486 { 480 487 // playing Sound 481 if (this->soundBuffers[WA_CHARGE] != NULL)488 if (this->soundBuffers[WA_CHARGE].loaded()) 482 489 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 483 490 … … 504 511 { 505 512 // playing Sound 506 if (this->soundBuffers[WA_SHOOT] != NULL)513 if (this->soundBuffers[WA_SHOOT].loaded()) 507 514 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 508 515 this->updateWidgets(); … … 528 535 { 529 536 PRINTF(4)("Reloading Weapon %s\n", this->getCName()); 530 if ( this->ammoContainer.get() != NULL&&537 if (!this->ammoContainer.isNull() && 531 538 unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge)) 532 539 { … … 537 544 538 545 539 if (this->soundBuffers[WA_RELOAD] != NULL)546 if (this->soundBuffers[WA_RELOAD].loaded()) 540 547 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 541 548 542 if ( this->ammoContainer.get() != NULL)549 if (!this->ammoContainer.isNull()) 543 550 this->ammoContainer->fillWeapon(this); 544 551 else … … 680 687 { 681 688 case WA_SHOOT: 682 683 689 return "shoot"; 690 break; 684 691 case WA_CHARGE: 685 686 692 return "charge"; 693 break; 687 694 case WA_RELOAD: 688 689 695 return "reload"; 696 break; 690 697 case WA_ACTIVATE: 691 692 698 return "activate"; 699 break; 693 700 case WA_DEACTIVATE: 694 695 701 return "deactivate"; 702 break; 696 703 case WA_SPECIAL1: 697 698 704 return "special1"; 705 break; 699 706 default: 700 701 707 return "none"; 708 break; 702 709 } 703 710 } … … 743 750 { 744 751 case WS_SHOOTING: 745 746 752 return "shooting"; 753 break; 747 754 case WS_CHARGING: 748 749 755 return "charging"; 756 break; 750 757 case WS_RELOADING: 751 752 758 return "reloading"; 759 break; 753 760 case WS_ACTIVATING: 754 755 761 return "activating"; 762 break; 756 763 case WS_DEACTIVATING: 757 758 764 return "deactivating"; 765 break; 759 766 case WS_IDLE: 760 761 767 return "idle"; 768 break; 762 769 case WS_INACTIVE: 763 764 770 return "inactive"; 771 break; 765 772 default: 766 767 768 } 769 } 773 return "none"; 774 break; 775 } 776 }
Note: See TracChangeset
for help on using the changeset viewer.