Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10676 in orxonox.OLD


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

xfer

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  
    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
  • branches/vs-enhencements/src/world_entities/weapons/weapon_manager.h

    r10669 r10676  
    122122    int                     slotCount;                                //!< number of weapon slots the ship has.
    123123    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 WeaponManager
     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    WeaponSlot*             slotConfigs[WM_MAX_SLOTS];
     127    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponSlot
    128128
    129129    bool                    weaponChange;
  • branches/vs-enhencements/src/world_entities/weapons/weapon_slot.cc

    r10672 r10676  
    1212### File Specific
    1313   main-programmer: Patrick Boenzli
    14 
     14   co-programmer: Nicolas Schlumberger
    1515*/
    1616
     
    3030{
    3131  this->registerObject(this, WeaponSlot::_objectList);
     32
     33  for (int i = 0; i < WM_MAX_CONFIGS; i++)
     34    this->configs[i] = NULL;
    3235}
    3336
     
    5861  .describe("sets the weapon slot");
    5962
    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");
    6268
    63   LoadParam(root, "nextWeapon", this, WeaponSlot, setNextWeapon)
    64   .describe("creates and set next weapon");
     69  LoadParam(root, "addWeapon", this, WeaponSlot, addWeapon)
     70  .describe("create a new Weapon, and add it to config");
    6571}
    6672
  • branches/vs-enhencements/src/world_entities/weapons/weapon_slot.h

    r10672 r10676  
    99#include "p_node.h"
    1010#include "weapon.h"
     11#include "weapon_manager.h"
    1112
    1213class Weapon;
     
    3132
    3233  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]; }
    3435
    3536  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]; }
    3738
    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); };
    4042
     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]; };
    4146
    4247  inline void setWeaponConfig(int slot, int side) { this->weaponSlot = slot; this->weaponSide = side; }
     
    4449  inline int getWeaponSide() { return this->weaponSide; }
    4550
     51  void removeWeapon(Weapon* weapon);
    4652
    4753private:
     
    5258  long          capability;             //!< the capabilities of the Slot @see WeaponSlotCapability.
    5359
     60  Weapon*       configs[WM_MAX_CONFIGS];
     61
    5462  Weapon*       currentWeapon;          //!< The current weapon this slot is carrying.
    5563  Weapon*       nextWeapon;             //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate)
     64
     65//   int           currentConfig;
     66//   int           nextConfig;
    5667};
    5768
Note: See TracChangeset for help on using the changeset viewer.