Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6676 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jan 24, 2006, 8:24:48 PM (19 years ago)
Author:
bensch
Message:

trunk: weaponManager works again

Location:
trunk/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/movie_entity.cc

    r6600 r6676  
    1919#include "load_param.h"
    2020#include "factory.h"
    21 
    22 #include "network_game_manager.h"
    23 #include "converter.h"
    2421
    2522using namespace std;
  • trunk/src/world_entities/playable.cc

    r6669 r6676  
    5252void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
    5353{
    54   this->weaponMan->addWeapon(weapon);
     54  this->weaponMan->addWeapon(weapon, configID, slotID);
    5555
    5656  this->weaponConfigChanged();
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r6669 r6676  
    208208  int weaponConf = this->currentConfigID;
    209209  int slot;
    210   if (slot = this->getNextFreeSlot(weaponConf, weapon->getCapability()) == -1 )
     210  if (slot = this->getNextFreeSlot(weaponConf, weapon->getCapability()) != -1 )
    211211    this->addWeapon(weapon, weaponConf, slot);
     212  else
     213    this->addWeapon(weapon, -1, -1);
    212214}
    213215
     
    231233  }
    232234
    233   if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0)
    234     PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName());
    235 
    236   if (slotID == -1) // WM_FREE_SLOT
     235  if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL)
     236  {
     237    PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getName(), weapon->getClassName(), weapon->getName());
     238    return false;
     239  }
     240
     241  if (slotID <= -1) // WM_FREE_SLOT
    237242  {
    238243    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     
    253258
    254259  //! @todo check if the weapon is already assigned to another config in another slot
     260  assert(this->configs[configID][slotID] == NULL);
     261
    255262  this->configs[configID][slotID] = weapon;
    256263  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
     
    259266    this->parent->addChild(weapon);
    260267  }
    261   PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     268  PRINTF(3)("Added a new Weapon (%s::%s) to the WeaponManager: config %i/ slot %i\n", weapon->getClassName(), weapon->getName(), configID, slotID);
    262269  return true;
    263270}
     
    433440int WeaponManager::getNextFreeSlot(int configID, long capability)
    434441{
    435   for( int i = 0; i < this->slotCount; ++i)
    436   {
    437     if( this->configs[configID][i] == NULL &&
    438         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
    439         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
    440       return i;
     442  if (configID == -1)
     443  {
     444    for (configID = 0; configID < WM_MAX_CONFIGS; configID++)
     445      for( int i = 0; i < this->slotCount; ++i)
     446      {
     447        if( this->configs[configID][i] == NULL &&
     448            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     449            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     450          return i;
     451    }
     452  }
     453  else
     454  {
     455    for( int i = 0; i < this->slotCount; ++i)
     456    {
     457      if( this->configs[configID][i] == NULL &&
     458          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     459          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     460        return i;
     461    }
    441462  }
    442463  return -1;
Note: See TracChangeset for help on using the changeset viewer.