Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 7, 2007, 5:10:52 PM (17 years ago)
Author:
nicolasc
Message:

xfer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/world_entities/weapons/weapon_manager.cc

    r10672 r10676  
    7272  this->parentEntity = NULL;
    7373
    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;
    7777
    7878  for (int i = 0; i < WM_MAX_SLOTS; i++)
    7979  {
    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);
    8484
    8585    // NAMING
     
    9595      sprintf(tmpName, "WeaponMan_slot%d", i);
    9696    }
    97     this->currentSlotConfig[i]->setName(tmpName);
    98     this->currentSlotConfig[i]->deactivateNode();
     97    this->slotConfigs[i]->setName(tmpName);
     98    this->slotConfigs[i]->deactivateNode();
    9999    delete[] tmpName;
    100100  }
     
    204204  {
    205205    for (int i = 0; i < WM_MAX_SLOTS; i++)
    206       this->parentNode->addChild(this->currentSlotConfig[i]);
     206      this->parentNode->addChild(this->slotConfigs[i]);
    207207  }
    208208
     
    232232  if (slot < this->slotCount)
    233233  {
    234     this->currentSlotConfig[slot]->setRelCoor(position);
     234    this->slotConfigs[slot]->setRelCoor(position);
    235235
    236236    if (parent != NULL)
    237       this->currentSlotConfig[slot]->setParent(parent);
     237      this->slotConfigs[slot]->setParent(parent);
    238238  }
    239239}
     
    248248{
    249249  if (slot < this->slotCount)
    250     this->currentSlotConfig[slot]->setRelDir(rotation);
     250    this->slotConfigs[slot]->setRelDir(rotation);
    251251}
    252252
     
    276276      slotID = -1;
    277277  }
    278   // if no ConfigID is supplied set to Current Config.
     278//  if no ConfigID is supplied set to Current Config.
    279279  if (configID <= -1)
    280280    configID = this->currentConfigID;
     
    287287  }
    288288
    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 )
    292317    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);
    318320  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);
    321323  //if (this->parent != NULL)
    322324  {
     
    363365  if (slot > slotCount)
    364366    return;
    365   this->currentSlotConfig[slot]->setCapability(slotCapability);
     367  this->slotConfigs[slot]->setCapability(slotCapability);
    366368}
    367369
     
    383385      for (int i = 0; i < WM_MAX_CONFIGS; i++)
    384386      {
    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);
    387389      }
    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//       }
    392394    }
     395  }
     396  else {
     397
    393398  }
    394399}
     
    427432
    428433  for (int i = 0; i < WM_MAX_SLOTS; i++)
    429     this->currentSlotConfig[i]->setNextWeapon(this->configs[currentConfigID][i]);
     434    this->slotConfigs[i]->setNextWeapon(currentConfigID);
    430435}
    431436
     
    440445  {
    441446//     printf("%i ", i);
    442     firingWeapon = this->currentSlotConfig[i]->getCurrentWeapon();
     447    firingWeapon = this->slotConfigs[i]->getCurrentWeapon();
    443448    if( firingWeapon != NULL)
    444449    {
     
    449454//   printf("\n");
    450455  /*
    451         this->crosshair->setRotationSpeed(500);
    452         this->crossHairSizeAnim->replay();
     456  this->crosshair->setRotationSpeed(500);
     457  this->crossHairSizeAnim->replay();
    453458  */
    454459}
     
    462467  for(int i = 0; i < this->slotCount; i++)
    463468  {
    464     firingWeapon = this->currentSlotConfig[i]->getCurrentWeapon();
     469    firingWeapon = this->slotConfigs[i]->getCurrentWeapon();
    465470    if( firingWeapon != NULL)
    466471      firingWeapon->requestAction(WA_NONE);
     
    481486  Weapon* tickWeapon;
    482487
    483 
    484488  for(int i = 0; i < this->slotCount; i++)
    485489  {
    486 
    487490    //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);*/
    490493
    491494    // current Weapon in Slot i
    492     tickWeapon = this->currentSlotConfig[i]->getCurrentWeapon();
     495    tickWeapon = this->slotConfigs[i]->getCurrentWeapon();
    493496    // On A change (current != next)
    494     if (tickWeapon != this->currentSlotConfig[i]->getNextWeapon())
     497    if (tickWeapon != this->slotConfigs[i]->getNextWeapon())
    495498    {
    496499      // if a Weapon is Active in slot i, deactivate it.
     
    505508        {
    506509          tickWeapon->toList(OM_NULL);
    507           this->currentSlotConfig[i]->setCurrentWeapon(NULL);
     510          this->slotConfigs[i]->setCurrentWeapon(NULL);
    508511        }
    509512      }
    510513      // 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();
    513517
    514518      if (tickWeapon != NULL)
     
    517521        tickWeapon->toList(this->parentEntity->getOMListNumber());
    518522        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]);
    521525      }
    522526      else
    523         this->currentSlotConfig[i]->deactivateNode();
     527        this->slotConfigs[i]->deactivateNode();
    524528      if (this->parentEntity != NULL && this->parentEntity->isA(Playable::staticClassID()))
    525529        dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged();
    526530    }
    527531    else if (unlikely(tickWeapon != NULL && tickWeapon->getCurrentState() == WS_DEACTIVATING))
    528       this->currentSlotConfig[i]->setCurrentWeapon(NULL);
     532      this->slotConfigs[i]->setCurrentWeapon(NULL);
    529533  }
    530534}
     
    540544  for (int i = 0; i < this->slotCount; i++)
    541545  {
    542     drawWeapon = this->currentSlotConfig[i]->getCurrentWeapon();
     546    drawWeapon = this->slotConfigs[i]->getCurrentWeapon();
    543547    if( drawWeapon != NULL && drawWeapon->isVisible())
    544548      drawWeapon->draw();
     
    558562      for( int i = 0; i < this->slotCount; ++i)
    559563      {
    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))
    563567          return i;
    564568      }
     
    568572    for( int i = 0; i < this->slotCount; ++i)
    569573    {
    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))
    573577        return i;
    574578    }
     
    608612    for (int j = 0; j < WM_MAX_SLOTS; j++)
    609613    {
    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());
    612616    }
    613617  }
     
    617621long WeaponManager::getSlotCapability(int slot) const
    618622{
    619   return this->currentSlotConfig[slot]->getCapability();
     623  return this->slotConfigs[slot]->getCapability();
    620624}
    621625
    622626const Vector& WeaponManager::getSlotPosition(int slot) const
    623627{
    624   return this->currentSlotConfig[slot]->getRelCoor();
     628  return this->slotConfigs[slot]->getRelCoor();
    625629}
    626630
    627631Weapon* WeaponManager::getWeapon(int slotID) const
    628632{
    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
Note: See TracChangeset for help on using the changeset viewer.