Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4926 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons


Ignore:
Timestamp:
Jul 21, 2005, 4:59:16 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the activation and deactivation-phase of the Weapon work too.

Location:
orxonox/trunk/src/world_entities/weapons
Files:
4 edited

Legend:

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

    r4910 r4926  
    7777    this->soundBuffers[i] = NULL;
    7878
    79   this->requestedAction = WA_NONE;
    8079  this->soundSource = new SoundSource(this);
    8180  this->emissionPoint.setParent(this);
     
    183182  {
    184183    this->currentState = WS_ACTIVATING;
    185     this->requestAction(WA_ACTIVATE);
    186   }
    187 }
    188 
     184    this->requestedAction = WA_ACTIVATE;
     185  }
     186}
    189187
    190188/**
     
    227225#endif
    228226
    229   switch (this->requestedAction)
     227  WeaponAction action = this->requestedAction;
     228  this->requestedAction = WA_NONE;
     229
     230  switch (action)
    230231  {
    231232    case WA_SHOOT:
     
    254255bool Weapon::activateW()
    255256{
    256   if (this->currentState == WS_INACTIVE)
     257//  if (this->currentState == WS_INACTIVE)
    257258  {
    258259        // play Sound
    259260    if (likely(this->soundBuffers[WA_ACTIVATE] != NULL))
    260261      this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
    261     if (likely(this->animation[WS_ACTIVATING] != NULL))
    262       this->animation[WS_ACTIVATING]->replay();
    263262        // activate
    264263    PRINTF(4)("Activating the Weapon %s\n", this->getName());
    265264    this->activate();
    266265    // setting up for next action
    267     this->currentState = WS_ACTIVATING;
    268     this->stateDuration = this->times[WS_ACTIVATING] + this->stateDuration;
    269   }
    270   this->requestedAction = WA_NONE;
     266    this->enterState(WS_ACTIVATING);
     267  }
    271268}
    272269
     
    284281    if (this->soundBuffers[WA_DEACTIVATE] != NULL)
    285282      this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
    286     if (likely(this->animation[WS_DEACTIVATING] != NULL))
    287       this->animation[WS_DEACTIVATING]->replay();
    288         // deactivate
     283    // deactivate
    289284    this->deactivate();
    290         // setting up for next action
    291     this->currentState = WS_DEACTIVATING;
    292     this->stateDuration = this->times[WS_DEACTIVATING] + this->stateDuration;
    293   }
    294   this->requestedAction = WA_NONE;
     285    this->enterState(WS_DEACTIVATING);
     286  }
    295287}
    296288
     
    306298    if (this->soundBuffers[WA_CHARGE] != NULL)
    307299      this->soundSource->play(this->soundBuffers[WA_CHARGE]);
    308     if (likely(this->animation[WS_CHARGING] != NULL))
    309       this->animation[WS_CHARGING]->replay();
    310300
    311301        // charge
    312302    this->charge();
    313303        // setting up for the next state
    314     this->requestedAction = WA_NONE;
    315     this->currentState = WS_CHARGING;
    316     this->stateDuration = this->times[WS_CHARGING] + this->stateDuration;
     304    this->enterState(WS_CHARGING);
    317305  }
    318306  else // deactivate the Weapon if we do not have enough energy
    319307  {
    320     this->requestedAction = WA_NONE;
    321308    this->requestAction(WA_RELOAD);
    322309  }
     
    336323    if (this->soundBuffers[WA_SHOOT] != NULL)
    337324      this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    338     if (likely(this->animation[WS_SHOOTING] != NULL))
    339       this->animation[WS_SHOOTING]->replay();
    340325          // fire
    341326    this->fire();
    342327    this->energyLoaded -= this->minCharge;
    343328          // setting up for the next state
    344     this->stateDuration = this->times[WS_SHOOTING] + this->stateDuration;
    345     this->currentState = WS_SHOOTING;
    346     this->requestedAction = WA_NONE;
     329    this->enterState(WS_SHOOTING);
    347330  }
    348331  else  // reload if we still have the charge
    349332  {
    350     this->requestedAction = WA_NONE;
    351333    this->requestAction(WA_RELOAD);
    352334  }
     
    371353  if (this->soundBuffers[WA_RELOAD] != NULL)
    372354    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    373   if (likely(this->animation[WS_RELOADING] != NULL))
    374     this->animation[WS_RELOADING]->replay();
    375355
    376356  if (chargeSize > this->energy)
     
    387367  }
    388368  this->reload();
    389 
    390   this->requestedAction = WA_NONE;
    391   this->currentState = WS_RELOADING;
    392   this->stateDuration = this->times[WS_RELOADING] + this->stateDuration;
    393 
     369  this->enterState(WS_RELOADING);
     370}
     371
     372
     373/**
     374 * enters the requested State, plays back animations updates the timing.
     375 * @param state the state to enter.
     376 */
     377inline void Weapon::enterState(WeaponState state)
     378{
     379  // playing animation if availiable
     380  if (likely(this->animation[state] != NULL))
     381    this->animation[state]->replay();
     382
     383  this->stateDuration = this->times[state] + this->stateDuration;
     384  this->currentState = state;
    394385}
    395386
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4910 r4926  
    155155    bool reloadW();
    156156
     157    inline void enterState(WeaponState state);
     158
    157159
    158160  protected:
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4909 r4926  
    3434 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3535 */
    36 WeaponManager::WeaponManager(int nrOfSlots)
     36WeaponManager::WeaponManager(int slotCount)
    3737{
    3838  this->init();
    39   this->nrOfSlots = nrOfSlots;
     39  this->slotCount = slotCount;
    4040}
    4141
     
    127127/**
    128128 * sets the number of Slots the WeaponManager has
    129  * @param nrOfSlots the number of slots
    130  */
    131 void WeaponManager::setSlotCount(int nrOfSlots)
    132 {
    133   this->nrOfSlots = nrOfSlots;
     129 * @param slotCount the number of slots
     130 */
     131void WeaponManager::setSlotCount(int slotCount)
     132{
     133  this->slotCount = slotCount;
    134134}
    135135
     
    150150  {
    151151    int freeSlot = this->getNextFreeSlot( configID);
    152     if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
     152    if( freeSlot < 0 || freeSlot >= this->slotCount)
    153153    {
    154154      PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
     
    262262  {
    263263    w = this->configs[j].slots[i];
    264     if( w != NULL)// && w->isVisible())
     264    if( w != NULL && w->isVisible())
    265265      w->draw();
    266266  }
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4906 r4926  
    7676class WeaponManager : public BaseObject {
    7777  public:
    78     WeaponManager(int nrOfSlots = 2);
     78    WeaponManager(int slotCount);
    7979    WeaponManager(const TiXmlElement* root);
    8080    ~WeaponManager();
     
    8484    void loadWeapons(const TiXmlElement* root);
    8585
    86     void setSlotCount(int nrOfSlots);
     86    void setSlotCount(int slotCount);
    8787
    8888    void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT);
     
    101101    tAnimation<Crosshair>*  crossHairSizeAnim;
    102102
    103     int                     nrOfSlots;               //<! number of weapon slots a ship has
     103    int                     slotCount;               //<! number of weapon slots a ship has
    104104    int                     currConfID;              //<! the currently selected config
    105105    weaponConfig            configs[4];              //<! a list of four configurations
Note: See TracChangeset for help on using the changeset viewer.