Changeset 6693 in orxonox.OLD for branches/network/src/world_entities/weapons/weapon_manager.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_manager.cc
r6568 r6693 217 217 bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 218 218 { 219 assert(weapon != NULL); 220 219 221 if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount)) 220 222 { 221 PRINTF(2)("Slot %d of config %d is not availiabe (max: %d)\n", slotID, configID, this->slotCount); 223 PRINTF(2)("Slot %d of config %d is not availiabe (max: %d) searching for suitable slot\n", slotID, configID, this->slotCount); 224 if (configID >= WM_MAX_CONFIGS) 225 configID = -1; 226 if (slotID >= (int)this->slotCount) 227 slotID = -1; 228 } 229 // if no ConfigID is supplied set to Current Config. 230 if (configID <= -1) 231 configID = this->currentConfigID; 232 // 233 if (configID > -1 && slotID == -1) 234 { 235 slotID = this->getNextFreeSlot(configID, weapon->getCapability()); 236 if (slotID == -1) 237 configID = -1; 238 } 239 240 if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL) 241 { 242 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getName(), weapon->getClassName(), weapon->getName()); 222 243 return false; 223 244 } 224 245 225 if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0) 226 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName()); 227 228 if (slotID == -1) // WM_FREE_SLOT 246 if (slotID <= -1) // WM_FREE_SLOT 229 247 { 230 248 slotID = this->getNextFreeSlot(configID, weapon->getCapability()); … … 245 263 246 264 //! @todo check if the weapon is already assigned to another config in another slot 265 assert(this->configs[configID][slotID] == NULL); 266 247 267 this->configs[configID][slotID] = weapon; 268 weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType())); 248 269 if (this->parent != NULL) 249 270 { 250 271 this->parent->addChild(weapon); 251 272 } 252 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);273 PRINTF(3)("Added a new Weapon (%s::%s) to the WeaponManager: config %i/ slot %i\n", weapon->getClassName(), weapon->getName(), configID, slotID); 253 274 return true; 254 275 } … … 420 441 /** 421 442 * private gets the next free slot in a certain weaponconfig 422 * @param the selected weaponconfig 443 * @param the selected weaponconfig -1 if none found 423 444 */ 424 445 int WeaponManager::getNextFreeSlot(int configID, long capability) 425 446 { 426 for( int i = 0; i < this->slotCount; ++i) 427 { 428 if( this->configs[configID][i] == NULL && 429 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 430 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 431 return i; 447 if (configID == -1) 448 { 449 for (configID = 0; configID < WM_MAX_CONFIGS; configID++) 450 for( int i = 0; i < this->slotCount; ++i) 451 { 452 if( this->configs[configID][i] == NULL && 453 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 454 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 455 return i; 456 } 457 } 458 else 459 { 460 for( int i = 0; i < this->slotCount; ++i) 461 { 462 if( this->configs[configID][i] == NULL && 463 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 464 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 465 return i; 466 } 432 467 } 433 468 return -1; 434 469 } 435 470 471 CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType) 472 { 473 for (unsigned int i = 0; i < this->ammo.size(); i++) 474 { 475 if (this->ammo[i]->getProjectileType() == projectileType) 476 return this->ammo[i]; 477 } 478 this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType))); 479 return this->ammo.back(); 480 } 436 481 437 482
Note: See TracChangeset
for help on using the changeset viewer.