Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.