Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 18, 2005, 8:05:00 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: weapon change enhanced. weapon handling is now better and safer

File:
1 edited

Legend:

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

    r3879 r3881  
    3737WeaponManager::WeaponManager(int nrOfSlots)
    3838{
    39   this->nrOfSlots = nrOfSlots;
    40  
    4139  for(int i = 0; i < W_MAX_CONFIGS; ++i)
    4240    {
     
    4543        this->configs[i].slots[j] = NULL;
    4644    }
    47 
     45  this->nrOfSlots = nrOfSlots;
    4846  this->currConfID = W_CONFIG0;
    49   this->configs[this->currConfID].bUsed = true;
    5047}
    5148
     
    5350WeaponManager::~WeaponManager()
    5451{
    55   /* i dont have to delete the weapons itself, because they are
     52  /*
     53     i dont have to delete the weapons itself, because they are
    5654     worldentities and therefore in the entities list of the world
    5755  */
     56  for(int i = 0; i < W_MAX_CONFIGS; ++i)
     57    {
     58      this->configs[i].bUsed = false;
     59      for(int j = 0; j < W_MAX_SLOTS; ++j)
     60        this->configs[i].slots[j] = NULL;
     61    }
    5862}
    5963
     
    101105
    102106   if there are multiple weapon configurations defined by the manager, use this to switch between them
     107   this function will deactivate the weapons first, change the config and reactivate them later
    103108*/
    104109void WeaponManager::nextWeaponConf()
    105110{
    106111  PRINTF(4)("Changing weapon configuration: from %i\n", this->currConfID);
     112
     113  Weapon* w;
     114  for(int i = 0; i < W_MAX_SLOTS; ++i)
     115    {
     116      w = this->configs[this->currConfID].slots[i];
     117      if( w != NULL) w->deactivate();
     118    }
    107119  int i;
    108120  for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
     
    110122  else this->currConfID = i; 
    111123  PRINTF(4)("\tto %i\n", this->currConfID);
     124
     125  for(int i = 0; i < W_MAX_SLOTS; ++i)
     126    {
     127      w = this->configs[this->currConfID].slots[i];
     128      if( w != NULL) w->activate();
     129    }
    112130}
    113131
     
    181199   creates a new weapon
    182200*/
    183 Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction)
     201Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
    184202  : WorldEntity()
    185203{
    186204  parent->addChild(this, PNODE_ALL);
    187   this->setRelCoor(*coordinate);
    188   this->setRelDir(*direction);
     205  this->setRelCoor(coordinate);
     206  this->setRelDir(direction);
    189207  WorldInterface* wi = WorldInterface::getInstance();
    190208  this->worldEntities = wi->getEntityList();
     
    293311{}
    294312
    295 /**
    296    \brief sets a weapon idle time
    297    \param idle time in ms
    298 
    299    a weapon idle time is the time spend after a shoot until the weapon can
    300    shoot again
    301 */
    302 void Weapon::setWeaponIdleTime(float time)
    303 {
    304   this->idleTime = time;
    305 }
    306 
    307 /**
    308    \brief gets the weapon idle time
    309    \returns idle time in ms
    310 
    311    a weapon idle time is the time spend after a shoot until the weapon can
    312    shoot again
    313 */
    314 float Weapon::getWeaponIdleTime(void)
    315 {
    316   return this->idleTime;
    317 }
    318 
    319 /**
    320    \brief checks if the idle time is elapsed
    321    \return true if time is elapsed
    322 
    323    a weapon idle time is the time spend after a shoot until the weapon can
    324    shoot again
    325 */
    326 bool Weapon::hasWeaponIdleTimeElapsed(void)
    327 {
    328   return (this->localTime>this->idleTime)?true:false;
    329 }
    330 
    331 
    332 /**
    333    \brief fires the weapon
    334    
    335    this is called from the player.cc, when fire-button is been pushed
    336 */
    337 void Weapon::fire()
    338 {}
     313
     314
     315
    339316
    340317
Note: See TracChangeset for help on using the changeset viewer.