Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3881 in orxonox.OLD for orxonox/trunk


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

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

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

Legend:

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

    r3878 r3881  
    4444  */
    4545  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    46   //this->model = (Model*)ResourceManager::getInstance()->load("models/weapon_packet.obj", OBJ, RP_CAMPAIGN);
    4746  travelSpeed = 15.0;
    4847  velocity = new Vector();
     
    5352  //weapons:
    5453  this->weaponMan = new WeaponManager();
    55   Weapon* wpRight = new TestGun(this, new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0);
    56   Weapon* wpLeft = new TestGun(this, new Vector(-2.6, 0.1, -3.0), new Quaternion(), 1);
     54  Weapon* wpRight = new TestGun(this,Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
     55  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    5756 
    5857  this->weaponMan->addWeapon(wpRight, W_CONFIG0);
    5958  this->weaponMan->addWeapon(wpLeft, W_CONFIG1);
    60 
    61   //this->weapons->add(wpRight);
    62   //this->activeWeapon = wpRight;
    63   //this->activeWeaponL = wpLeft;
     59  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
     60  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
     61
    6462}
    6563
  • orxonox/trunk/src/world_entities/test_gun.cc

    r3855 r3881  
    4040   creates a new weapon
    4141*/
    42 TestGun::TestGun (PNode* parent, Vector* coordinate, Quaternion* direction, int leftRight)
     42TestGun::TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight)
    4343  :  Weapon (parent, coordinate, direction)
    4444{
     
    127127void TestGun::fire()
    128128{
    129   if( this->localTime < this->idleTime)
     129  if( !this->hasWeaponIdleTimeElapsed())
    130130    {
    131131      this->weaponIdle();
     
    201201                    this->getAbsCoor ().y,
    202202                    this->getAbsCoor ().z);
    203      
     203
    204204      this->getAbsDir ().matrix (matrix);
    205205      glMultMatrixf((float*)matrix);
     
    228228                this->dummy1->getAbsCoor ().y,
    229229                this->dummy1->getAbsCoor ().z);
    230 
     230 
    231231  this->dummy1->getAbsDir ().matrix (matrix);
    232232  glMultMatrixf((float*)matrix);
  • orxonox/trunk/src/world_entities/test_gun.h

    r3855 r3881  
    3737
    3838 public:
    39   TestGun (PNode* parent, Vector* coordinate, Quaternion* direction, int leftRight);
     39  TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
    4040  virtual ~TestGun ();
    4141
  • 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
  • orxonox/trunk/src/world_entities/weapon.h

    r3878 r3881  
    8888
    8989 private:
    90   int nrOfConfigs;                      //<! number of configurations defined
    9190  int nrOfSlots;                        //<! number of weapon slots a ship has
    9291  int currConfID;                       //<! the currently selected config
     
    101100
    102101 public:
    103   Weapon (PNode* parent, Vector* coordinate, Quaternion* direction);
     102  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
    104103  virtual ~Weapon ();
    105104 
     
    115114  bool isActive(void);
    116115
    117   void setWeaponIdleTime(float time);
    118   float getWeaponIdleTime(void);
    119   bool hasWeaponIdleTimeElapsed(void);
    120116
     117  /**
     118     \brief sets a weapon idle time
     119     \param idle time in ms
     120     
     121     a weapon idle time is the time spend after a shoot until the weapon can
     122     shoot again
     123  */
     124  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
     125  /**
     126     \brief gets the weapon idle time
     127     \returns idle time in ms
     128     
     129     a weapon idle time is the time spend after a shoot until the weapon can
     130     shoot again
     131  */
     132  inline float getWeaponIdleTime(void) const { return this->idleTime;}
     133  /**
     134     \brief checks if the idle time is elapsed
     135     \return true if time is elapsed
     136     
     137     a weapon idle time is the time spend after a shoot until the weapon can
     138   shoot again
     139  */
     140  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
     141
     142  /**
     143     \brief fires the weapon
     144     
     145     this is called from the player.cc, when fire-button is been pushed
     146  */
    121147  virtual void fire(void) = 0;
    122148  virtual void hit (WorldEntity* weapon, Vector* loc);
Note: See TracChangeset for help on using the changeset viewer.