Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3878 in orxonox.OLD


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.

Location:
orxonox/trunk/src/world_entities
Files:
3 edited

Legend:

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

    r3877 r3878  
    3838Player::Player() : WorldEntity()
    3939{
    40   this->weapons = new tList<Weapon>();
    41   this->activeWeapon = NULL;
    4240  /*
    4341    this is the debug player - actualy we would have to make a new
     
    5149  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    5250  bFire = false;
     51  this->bWeaponChange = false;
    5352  acceleration = 10.0;
    5453  //weapons:
     
    5756  Weapon* wpLeft = new TestGun(this, new Vector(-2.6, 0.1, -3.0), new Quaternion(), 1);
    5857 
    59   this->weaponMan->addWeapon(wpRight);
    60   this->weaponMan->addWeapon(wpLeft);
     58  this->weaponMan->addWeapon(wpRight, W_CONFIG0);
     59  this->weaponMan->addWeapon(wpLeft, W_CONFIG1);
    6160
    6261  //this->weapons->add(wpRight);
     
    7473     this only frees the memory allocated to save the list.
    7574  */
    76   delete this->weapons;
    7775  delete this->weaponMan;
    7876}
     
    8583void Player::addWeapon(Weapon* weapon)
    8684{
    87   this->weapons->add(weapon);
     85  this->weaponMan->addWeapon(weapon);
    8886}
    8987
     
    9593void Player::removeWeapon(Weapon* weapon)
    9694{
    97   this->weapons->remove(weapon);
     95  this->weaponMan->removeWeapon(weapon);
    9896}
    9997
     
    157155  glPopMatrix();
    158156
    159   //this->activeWeapon->draw();
    160   //this->activeWeaponL->draw();
    161157  this->weaponMan->draw();
    162158}
     
    221217  if( this->bWeaponChange)
    222218    {
    223       //this->activeWeapon->deactivate();
    224       //this->weapons->enumerate();  FIX: strang weapon change...
    225       //this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
    226       //this->activeWeapon->activate();
    227219      this->weaponMan->nextWeaponConf();
     220      this->bWeaponChange = false;
    228221    }
    229222}
     
    244237  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
    245238  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
    246   if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp;
    247 }
     239  if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
     240}
  • 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/**
  • orxonox/trunk/src/world_entities/weapon.h

    r3877 r3878  
    7979  ~WeaponManager();
    8080 
    81   void addWeapon(Weapon* weapon, int slotID = W_FREE_SLOT, int configID = W_CONFIG0);
     81  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
     82  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
    8283  void nextWeaponConf();
    8384
     
    9293  weaponConfig configs[4];              //<! a list of four configurations
    9394 
    94   int getNextFreeSlot();
     95  int getNextFreeSlot(int configID);
    9596};
    9697
Note: See TracChangeset for help on using the changeset viewer.