Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2005, 1:41:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: states are now flow'n through

File:
1 edited

Legend:

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

    r4895 r4906  
    8181  this->emissionPoint.setParent(this);
    8282
    83   this->active = true;
    8483  this->projectile = NULL;
     84
     85  this->hideInactive = true;
    8586
    8687  this->minCharge = 1.0;
     
    171172void Weapon::requestAction(WeaponAction action)
    172173{
    173   if (this->requestedAction != WA_NONE)
    174     return;
    175   else
    176   {
     174  if (likely(this->isActive()))
     175  {
     176    if (this->requestedAction != WA_NONE)
     177      return;
    177178    printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration);
    178179    this->requestedAction = action;
     180  }
     181  //else
     182  else if (unlikely(action == WA_ACTIVATE))
     183  {
     184    this->currentState = WS_ACTIVATING;
     185    this->requestAction(WA_ACTIVATE);
    179186  }
    180187}
     
    215222bool Weapon::execute()
    216223{
    217 
     224#if DEBUG > 4
    218225  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
    219226  this->debug();
     227#endif
    220228
    221229  switch (this->requestedAction)
     
    246254bool Weapon::activateW()
    247255{
    248 //  if (this->currentState == WS_INACTIVE)
     256  if (this->currentState == WS_INACTIVE)
    249257  {
    250258        // play Sound
     
    256264    PRINTF(4)("Activating the Weapon %s\n", this->getName());
    257265    this->activate();
    258     this->active = true;
    259266    // setting up for next action
     267    this->currentState = WS_ACTIVATING;
    260268    this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration;
    261269  }
     
    280288        // deactivate
    281289    this->deactivate();
    282     this->active = false;
    283290        // setting up for next action
     291    this->currentState = WS_DEACTIVATING;
    284292    this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration;
    285293  }
     
    305313        // setting up for the next state
    306314    this->requestedAction = WA_NONE;
     315    this->currentState = WS_CHARGING;
    307316    this->stateDuration = this->times[WA_CHARGE] + this->stateDuration;
    308317  }
     
    334343          // setting up for the next state
    335344    this->stateDuration = this->times[WA_SHOOT] + this->stateDuration;
     345    this->currentState = WS_SHOOTING;
    336346    this->requestedAction = WA_NONE;
    337347  }
     
    379389
    380390  this->requestedAction = WA_NONE;
     391  this->currentState = WS_RELOADING;
    381392  this->stateDuration = this->times[WA_RELOAD] + this->stateDuration;
    382393
     
    387398 * tick signal for time dependent/driven stuff
    388399*/
    389 void Weapon::tick(float dt)
     400void Weapon::tickW(float dt)
    390401{
    391402  // setting up the timing properties
     
    394405  if (this->isActive())
    395406  {
    396     if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE)
    397     {
    398       this->stateDuration = -dt;
    399       this->execute();
    400     }
    401   }
    402   else
    403     if (this->requestedAction == WA_ACTIVATE)
    404       this->activate();
    405 
     407    if (this->stateDuration <= 0.0)
     408    {
     409      if (unlikely (this->currentState != WS_DEACTIVATING))
     410        this->currentState = WS_IDLE;
     411      else
     412        this->currentState = WS_INACTIVE;
     413
     414      if (this->requestedAction != WA_NONE)
     415      {
     416        this->stateDuration = -dt;
     417        this->execute();
     418      }
     419    }
     420  }
     421  tick(dt);
    406422}
    407423
     
    569585      return "idle";
    570586      break;
     587    case WS_INACTIVE:
     588      return "inactive";
     589      break;
    571590    default:
    572591      return "none";
Note: See TracChangeset for help on using the changeset viewer.