Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2006, 2:19:46 PM (18 years ago)
Author:
patrick
Message:

branches: removed spaceshipcontrol branche

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/weapons/weapon_manager.cc

    r6568 r6693  
    217217bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    218218{
     219  assert(weapon != NULL);
     220
    219221  if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount))
    220222  {
    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());
    222243    return false;
    223244  }
    224245
    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
    229247  {
    230248    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     
    245263
    246264  //! @todo check if the weapon is already assigned to another config in another slot
     265  assert(this->configs[configID][slotID] == NULL);
     266
    247267  this->configs[configID][slotID] = weapon;
     268  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
    248269  if (this->parent != NULL)
    249270  {
    250271    this->parent->addChild(weapon);
    251272  }
    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);
    253274  return true;
    254275}
     
    420441/**
    421442 * private gets the next free slot in a certain weaponconfig
    422  * @param the selected weaponconfig
     443 * @param the selected weaponconfig -1 if none found
    423444 */
    424445int WeaponManager::getNextFreeSlot(int configID, long capability)
    425446{
    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    }
    432467  }
    433468  return -1;
    434469}
    435470
     471CountPointer<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}
    436481
    437482
Note: See TracChangeset for help on using the changeset viewer.