Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3878 in orxonox.OLD for orxonox/trunk/src/world_entities/weapon.cc


Ignore:
Timestamp:
Apr 18, 2005, 6:12:16 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: the weaponconfiguration can now be changed by pressing the 'm' key.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/weapon.cc

    r3877 r3878  
    5656
    5757
    58 void WeaponManager::addWeapon(Weapon* weapon, int slotID, int configID)
     58/**
     59   \brief adds a weapon to the selected weaponconfiguration into the selected slot
     60   \param the weapon to add
     61   \param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot
     62   \param an identifier for the weapon configuration, number between 0..3
     63
     64   if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be
     65   replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free
     66   slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be
     67   a error message.
     68*/
     69void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    5970{
    6071  if( slotID == W_FREE_SLOT)
    6172    {
    62       int freeSlot = this->getNextFreeSlot();
     73      int freeSlot = this->getNextFreeSlot( configID);
    6374      if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
    6475        {
     
    6778        }
    6879      PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot);
     80      this->configs[configID].bUsed = true;
    6981      this->configs[configID].slots[freeSlot] = weapon;
    7082      return;
    7183    }
     84  this->configs[configID].bUsed = true;
    7285  this->configs[configID].slots[slotID] = weapon;
    7386  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     
    7588
    7689
     90void WeaponManager::removeWeapon(Weapon* weapon, int configID)
     91{
     92  /* empty */
     93}
     94
     95
     96/**
     97   \brief changes to the next weapon configuration
     98
     99   if there are multiple weapon configurations defined by the manager, use this to switch between them
     100*/
    77101void WeaponManager::nextWeaponConf()
    78102{
    79   PRINTF(3)("Changing weapon configuration: from %i ", this->currConfID);
     103  PRINTF(3)("Changing weapon configuration: from %i\n", this->currConfID);
    80104  int i;
    81   for(i = this->currConfID; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
     105  for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
    82106  if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0;
    83107  else this->currConfID = i; 
    84   PRINTF(3)("to %i\n", this->currConfID);
    85 }
    86 
    87 
    88 int WeaponManager::getNextFreeSlot()
    89 {
    90   for( int i = 0; i < W_MAX_SLOTS; ++i)
    91     {
    92       if( this->configs[this->currConfID].slots[i] == NULL)
    93         return i;
    94     }
    95   return -1;
    96 }
    97 
    98 
     108  PRINTF(3)("\tto %i\n", this->currConfID);
     109}
     110
     111
     112
     113/**
     114   \brief triggers fire of all weapons in the current weaponconfig
     115*/
    99116void WeaponManager::fire()
    100117{
     
    108125
    109126
     127/**
     128   \brief triggers tick of all weapons in the current weaponconfig
     129   \param second passed since last tick
     130*/
    110131void WeaponManager::tick(float sec)
    111132{
     
    119140
    120141
     142/**
     143   \brief triggers draw of all weapons in the current weaponconfig
     144*/
    121145void WeaponManager::draw()
    122146{
     
    128152    }
    129153}
     154
     155
     156/**
     157   \brief private gets the next free slot in a certain weaponconfig
     158   \param the selected weaponconfig
     159*/
     160int WeaponManager::getNextFreeSlot(int configID)
     161{
     162  for( int i = 0; i < W_MAX_SLOTS; ++i)
     163    {
     164      if( this->configs[configID].slots[i] == NULL)
     165        return i;
     166    }
     167  return -1;
     168}
     169
     170
     171
     172
     173
    130174
    131175/**
Note: See TracChangeset for help on using the changeset viewer.