Changeset 10676 in orxonox.OLD for branches/vs-enhencements/src/world_entities/weapons
- Timestamp:
- Jun 7, 2007, 5:10:52 PM (18 years ago)
- Location:
- branches/vs-enhencements/src/world_entities/weapons
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/vs-enhencements/src/world_entities/weapons/weapon_manager.cc
r10672 r10676 72 72 this->parentEntity = NULL; 73 73 74 for (int i = 0; i < WM_MAX_CONFIGS; i++)75 for (int j = 0; j < WM_MAX_SLOTS; j++)76 this->configs[i][j] = NULL;74 // for (int i = 0; i < WM_MAX_CONFIGS; i++) 75 // for (int j = 0; j < WM_MAX_SLOTS; j++) 76 // this->configs[i][j] = NULL; 77 77 78 78 for (int i = 0; i < WM_MAX_SLOTS; i++) 79 79 { 80 this-> currentSlotConfig[i] = new WeaponSlot();81 this-> currentSlotConfig[i]->setCapability(WTYPE_ALL);82 this->currentSlotConfig[i]->setCurrentWeapon(NULL);83 this->currentSlotConfig[i]->setNextWeapon(NULL);80 this->slotConfigs[i] = new WeaponSlot(); 81 this->slotConfigs[i]->setCapability(WTYPE_ALL); 82 // this->slotConfigs[i]->setCurrentWeapon(NULL); 83 // this->slotConfigs[i]->setNextWeapon(NULL); 84 84 85 85 // NAMING … … 95 95 sprintf(tmpName, "WeaponMan_slot%d", i); 96 96 } 97 this-> currentSlotConfig[i]->setName(tmpName);98 this-> currentSlotConfig[i]->deactivateNode();97 this->slotConfigs[i]->setName(tmpName); 98 this->slotConfigs[i]->deactivateNode(); 99 99 delete[] tmpName; 100 100 } … … 204 204 { 205 205 for (int i = 0; i < WM_MAX_SLOTS; i++) 206 this->parentNode->addChild(this-> currentSlotConfig[i]);206 this->parentNode->addChild(this->slotConfigs[i]); 207 207 } 208 208 … … 232 232 if (slot < this->slotCount) 233 233 { 234 this-> currentSlotConfig[slot]->setRelCoor(position);234 this->slotConfigs[slot]->setRelCoor(position); 235 235 236 236 if (parent != NULL) 237 this-> currentSlotConfig[slot]->setParent(parent);237 this->slotConfigs[slot]->setParent(parent); 238 238 } 239 239 } … … 248 248 { 249 249 if (slot < this->slotCount) 250 this-> currentSlotConfig[slot]->setRelDir(rotation);250 this->slotConfigs[slot]->setRelDir(rotation); 251 251 } 252 252 … … 276 276 slotID = -1; 277 277 } 278 //if no ConfigID is supplied set to Current Config.278 // if no ConfigID is supplied set to Current Config. 279 279 if (configID <= -1) 280 280 configID = this->currentConfigID; … … 287 287 } 288 288 289 if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL) 290 { 291 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getCName(), weapon->getClassCName(), weapon->getCName()); 289 // if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL) 290 // { 291 // PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getCName(), weapon->getClassCName(), weapon->getCName()); 292 // return false; 293 // } 294 295 // if (slotID <= -1) // WM_FREE_SLOT 296 // { 297 // slotID = this->getNextFreeSlot(configID, weapon->getCapability()); 298 // if( slotID < 0 || slotID >= this->slotCount) 299 // { 300 // PRINTF(1)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); 301 // return false; 302 // } 303 // } 304 305 // if (!(this->slotConfigs[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLKINDS) && 306 // this->slotConfigs[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLDIRS) 307 // { 308 // PRINTF(2)("Unable to add Weapon with wrong capatibility to Slot %d (W:%d M:%d)\n", 309 // slotID, weapon->getCapability(), this->slotConfigs[slotID]->getCapability()); 310 // return false; 311 // } 312 313 //! @todo check if the weapon is already assigned to another config in another slot 314 // if (this->configs[configID][slotID] != NULL) 315 // return false; 316 if( this->slotConfigs[slotID]->getWeapon(configID) != NULL ) 292 317 return false; 293 } 294 295 if (slotID <= -1) // WM_FREE_SLOT 296 { 297 slotID = this->getNextFreeSlot(configID, weapon->getCapability()); 298 if( slotID < 0 || slotID >= this->slotCount) 299 { 300 PRINTF(1)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); 301 return false; 302 } 303 } 304 305 if (!(this->currentSlotConfig[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLKINDS) && 306 this->currentSlotConfig[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLDIRS) 307 { 308 PRINTF(2)("Unable to add Weapon with wrong capatibility to Slot %d (W:%d M:%d)\n", 309 slotID, weapon->getCapability(), this->currentSlotConfig[slotID]->getCapability()); 310 return false; 311 } 312 313 //! @todo check if the weapon is already assigned to another config in another slot 314 if (this->configs[configID][slotID] != NULL) 315 return false; 316 317 this->configs[configID][slotID] = weapon; 318 319 this->slotConfigs[slotID]->setWeapon(weapon, configID); 318 320 weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType())); 319 if(configID == this->currentConfigID)320 this->currentSlotConfig[slotID]->setNextWeapon(weapon);321 // if(configID == this->currentConfigID) 322 // this->slotConfigs[slotID]->setNextWeapon(weapon); 321 323 //if (this->parent != NULL) 322 324 { … … 363 365 if (slot > slotCount) 364 366 return; 365 this-> currentSlotConfig[slot]->setCapability(slotCapability);367 this->slotConfigs[slot]->setCapability(slotCapability); 366 368 } 367 369 … … 383 385 for (int i = 0; i < WM_MAX_CONFIGS; i++) 384 386 { 385 if (this-> configs[i][j]== weapon)386 this-> configs[i][j] = NULL;387 if (this->slotConfigs[j]->getWeapon(i) == weapon) 388 this->slotConfigs[j]->setWeapon(NULL, i); 387 389 } 388 if (this->currentSlotConfig[j]->getCurrentWeapon() == weapon)389 {390 this->currentSlotConfig[j]->setNextWeapon(NULL);391 }390 // if (this->slotConfigs[j]->getCurrentWeapon() == weapon) 391 // { 392 // this->slotConfigs[j]->setNextWeapon(NULL); 393 // } 392 394 } 395 } 396 else { 397 393 398 } 394 399 } … … 427 432 428 433 for (int i = 0; i < WM_MAX_SLOTS; i++) 429 this-> currentSlotConfig[i]->setNextWeapon(this->configs[currentConfigID][i]);434 this->slotConfigs[i]->setNextWeapon(currentConfigID); 430 435 } 431 436 … … 440 445 { 441 446 // printf("%i ", i); 442 firingWeapon = this-> currentSlotConfig[i]->getCurrentWeapon();447 firingWeapon = this->slotConfigs[i]->getCurrentWeapon(); 443 448 if( firingWeapon != NULL) 444 449 { … … 449 454 // printf("\n"); 450 455 /* 451 452 456 this->crosshair->setRotationSpeed(500); 457 this->crossHairSizeAnim->replay(); 453 458 */ 454 459 } … … 462 467 for(int i = 0; i < this->slotCount; i++) 463 468 { 464 firingWeapon = this-> currentSlotConfig[i]->getCurrentWeapon();469 firingWeapon = this->slotConfigs[i]->getCurrentWeapon(); 465 470 if( firingWeapon != NULL) 466 471 firingWeapon->requestAction(WA_NONE); … … 481 486 Weapon* tickWeapon; 482 487 483 484 488 for(int i = 0; i < this->slotCount; i++) 485 489 { 486 487 490 //NICE LITTLE DEBUG FUNCTION 488 /* if (this-> currentSlotConfig[i]->currentWeapon != NULL || this->currentSlotConfig[i]->nextWeapon != NULL)489 printf("%p %p\n", this-> currentSlotConfig[i]->currentWeapon, this->currentSlotConfig[i]->nextWeapon);*/491 /* if (this->slotConfigs[i]->currentWeapon != NULL || this->slotConfigs[i]->nextWeapon != NULL) 492 printf("%p %p\n", this->slotConfigs[i]->currentWeapon, this->slotConfigs[i]->nextWeapon);*/ 490 493 491 494 // current Weapon in Slot i 492 tickWeapon = this-> currentSlotConfig[i]->getCurrentWeapon();495 tickWeapon = this->slotConfigs[i]->getCurrentWeapon(); 493 496 // On A change (current != next) 494 if (tickWeapon != this-> currentSlotConfig[i]->getNextWeapon())497 if (tickWeapon != this->slotConfigs[i]->getNextWeapon()) 495 498 { 496 499 // if a Weapon is Active in slot i, deactivate it. … … 505 508 { 506 509 tickWeapon->toList(OM_NULL); 507 this-> currentSlotConfig[i]->setCurrentWeapon(NULL);510 this->slotConfigs[i]->setCurrentWeapon(NULL); 508 511 } 509 512 } 510 513 // switching to next Weapon 511 this->currentSlotConfig[i]->setCurrentWeapon(this->currentSlotConfig[i]->getNextWeapon()); 512 tickWeapon = this->currentSlotConfig[i]->getCurrentWeapon(); 514 // this->slotConfigs[i]->setCurrentWeapon(this->slotConfigs[i]->getNextWeapon()); 515 this->slotConfigs[i]->setNextToCurrent(); 516 tickWeapon = this->slotConfigs[i]->getCurrentWeapon(); 513 517 514 518 if (tickWeapon != NULL) … … 517 521 tickWeapon->toList(this->parentEntity->getOMListNumber()); 518 522 tickWeapon->requestAction(WA_ACTIVATE); 519 this-> currentSlotConfig[i]->activateNode();520 tickWeapon->setParent(this-> currentSlotConfig[i]);523 this->slotConfigs[i]->activateNode(); 524 tickWeapon->setParent(this->slotConfigs[i]); 521 525 } 522 526 else 523 this-> currentSlotConfig[i]->deactivateNode();527 this->slotConfigs[i]->deactivateNode(); 524 528 if (this->parentEntity != NULL && this->parentEntity->isA(Playable::staticClassID())) 525 529 dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged(); 526 530 } 527 531 else if (unlikely(tickWeapon != NULL && tickWeapon->getCurrentState() == WS_DEACTIVATING)) 528 this-> currentSlotConfig[i]->setCurrentWeapon(NULL);532 this->slotConfigs[i]->setCurrentWeapon(NULL); 529 533 } 530 534 } … … 540 544 for (int i = 0; i < this->slotCount; i++) 541 545 { 542 drawWeapon = this-> currentSlotConfig[i]->getCurrentWeapon();546 drawWeapon = this->slotConfigs[i]->getCurrentWeapon(); 543 547 if( drawWeapon != NULL && drawWeapon->isVisible()) 544 548 drawWeapon->draw(); … … 558 562 for( int i = 0; i < this->slotCount; ++i) 559 563 { 560 if( this-> configs[configID][i]== NULL &&561 (this-> currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLKINDS) &&562 (this-> currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLDIRS))564 if( this->slotConfigs[i]->getWeapon(configID) == NULL && 565 (this->slotConfigs[i]->getCapability() & capability & WTYPE_ALLKINDS) && 566 (this->slotConfigs[i]->getCapability() & capability & WTYPE_ALLDIRS)) 563 567 return i; 564 568 } … … 568 572 for( int i = 0; i < this->slotCount; ++i) 569 573 { 570 if( this-> configs[configID][i]== NULL &&571 (this-> currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLKINDS) &&572 (this-> currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLDIRS))574 if( this->slotConfigs[i]->getWeapon(configID) == NULL && 575 (this->slotConfigs[i]->getCapability() & capability & WTYPE_ALLKINDS) && 576 (this->slotConfigs[i]->getCapability() & capability & WTYPE_ALLDIRS)) 573 577 return i; 574 578 } … … 608 612 for (int j = 0; j < WM_MAX_SLOTS; j++) 609 613 { 610 if (this-> configs[i][j]!= NULL)611 PRINT(3)("Slot %d loaded a %s\n", j, this-> configs[i][j]->getClassCName());614 if (this->slotConfigs[j]->getWeapon(i) != NULL) 615 PRINT(3)("Slot %d loaded a %s\n", j, this->slotConfigs[j]->getWeapon(i)->getClassCName()); 612 616 } 613 617 } … … 617 621 long WeaponManager::getSlotCapability(int slot) const 618 622 { 619 return this-> currentSlotConfig[slot]->getCapability();623 return this->slotConfigs[slot]->getCapability(); 620 624 } 621 625 622 626 const Vector& WeaponManager::getSlotPosition(int slot) const 623 627 { 624 return this-> currentSlotConfig[slot]->getRelCoor();628 return this->slotConfigs[slot]->getRelCoor(); 625 629 } 626 630 627 631 Weapon* WeaponManager::getWeapon(int slotID) const 628 632 { 629 return (slotID >= 0 && slotID < this->slotCount)? this-> currentSlotConfig[slotID]->getNextWeapon(): NULL;630 } 631 632 633 return (slotID >= 0 && slotID < this->slotCount)? this->slotConfigs[slotID]->getNextWeapon(): NULL; 634 } 635 636 -
branches/vs-enhencements/src/world_entities/weapons/weapon_manager.h
r10669 r10676 122 122 int slotCount; //!< number of weapon slots the ship has. 123 123 int currentConfigID; //!< the currently selected config. 124 Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon.125 WeaponSlot* currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation.126 127 Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this Weapon Manager124 // Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. 125 // WeaponSlot* currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. 126 WeaponSlot* slotConfigs[WM_MAX_SLOTS]; 127 Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponSlot 128 128 129 129 bool weaponChange; -
branches/vs-enhencements/src/world_entities/weapons/weapon_slot.cc
r10672 r10676 12 12 ### File Specific 13 13 main-programmer: Patrick Boenzli 14 14 co-programmer: Nicolas Schlumberger 15 15 */ 16 16 … … 30 30 { 31 31 this->registerObject(this, WeaponSlot::_objectList); 32 33 for (int i = 0; i < WM_MAX_CONFIGS; i++) 34 this->configs[i] = NULL; 32 35 } 33 36 … … 58 61 .describe("sets the weapon slot"); 59 62 60 LoadParam(root, "currentWeapon", this, WeaponSlot, setCurrentWeapon) 61 .describe("creates and set next weapon"); 63 // LoadParam(root, "currentWeapon", this, WeaponSlot, setCurrentWeapon) 64 // .describe("creates and set next weapon"); 65 // 66 // LoadParam(root, "nextWeapon", this, WeaponSlot, setNextWeapon) 67 // .describe("creates and set next weapon"); 62 68 63 LoadParam(root, " nextWeapon", this, WeaponSlot, setNextWeapon)64 .describe("create s and set next weapon");69 LoadParam(root, "addWeapon", this, WeaponSlot, addWeapon) 70 .describe("create a new Weapon, and add it to config"); 65 71 } 66 72 -
branches/vs-enhencements/src/world_entities/weapons/weapon_slot.h
r10672 r10676 9 9 #include "p_node.h" 10 10 #include "weapon.h" 11 #include "weapon_manager.h" 11 12 12 13 class Weapon; … … 31 32 32 33 inline Weapon* getCurrentWeapon() { return this->currentWeapon; } 33 inline void setCurrentWeapon( Weapon* weapon) { this->currentWeapon = weapon; }34 inline void setCurrentWeapon(int config) { this->currentWeapon = this->configs[config]; } 34 35 35 36 inline Weapon* getNextWeapon() { return this->nextWeapon; } 36 inline void setNextWeapon( Weapon* weapon) { this->nextWeapon = weapon; }37 inline void setNextWeapon(int config) { if (config == -1) this->nextWeapon = NULL; else this->nextWeapon = configs[config]; } 37 38 38 inline void setNextWeapon(const std::string& weaponName){this->nextWeapon = Weapon::createWeapon(weaponName); }; 39 inline void setCurrentWeapon(const std::string& weaponName){ this->currentWeapon = Weapon::createWeapon(weaponName); }; 39 inline void setNextToCurrent() {this->currentWeapon = this->nextWeapon; }; 40 // inline void setNextWeapon(const std::string& weaponName){this->nextWeapon = Weapon::createWeapon(weaponName); }; 41 // inline void setCurrentWeapon(const std::string& weaponName){ this->currentWeapon = Weapon::createWeapon(weaponName); }; 40 42 43 inline void addWeapon(const std::string& weaponName, int config) {this->configs[config] = Weapon::createWeapon(weaponName); } 44 inline void setWeapon(Weapon* weapon, int config) {this->configs[config] = weapon; }; 45 inline Weapon* getWeapon(int config) { if (config > WM_MAX_CONFIGS) return NULL; return this->configs[config]; }; 41 46 42 47 inline void setWeaponConfig(int slot, int side) { this->weaponSlot = slot; this->weaponSide = side; } … … 44 49 inline int getWeaponSide() { return this->weaponSide; } 45 50 51 void removeWeapon(Weapon* weapon); 46 52 47 53 private: … … 52 58 long capability; //!< the capabilities of the Slot @see WeaponSlotCapability. 53 59 60 Weapon* configs[WM_MAX_CONFIGS]; 61 54 62 Weapon* currentWeapon; //!< The current weapon this slot is carrying. 55 63 Weapon* nextWeapon; //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate) 64 65 // int currentConfig; 66 // int nextConfig; 56 67 }; 57 68
Note: See TracChangeset
for help on using the changeset viewer.