Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4891 in orxonox.OLD


Ignore:
Timestamp:
Jul 19, 2005, 3:21:43 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more elaborate execute function

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

Legend:

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

    r4890 r4891  
    8787
    8888
     89/**
     90 * assigns a Sound-file to an action
     91 * @param action the action the sound should be assigned too
     92 * @param soundFile the soundFile's relative position to the data-directory (will be looked for by the ResourceManager)
     93 */
    8994void Weapon::setActionSound(WeaponAction action, const char* soundFile)
    9095{
     
    147152}
    148153
     154/**
     155 * executes an action, and with it starts a new State.
     156 * @return true, if it worked, false otherwise
     157 *
     158 * This function checks, wheter the possibility of executing an action is valid,
     159 * and does all the necessary stuff, to execute them. If an action does not succeed,
     160 * it tries to go around it. (ex. shoot->noAmo->reload()->wait until shoot comes again)
     161 */
    149162bool Weapon::execute()
    150163{
    151   this->stateDuration = this->times[this->requestedAction] + this->stateDuration;
    152164
    153165  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
     
    161173        if (this->minCharge <= this->energyLoaded)
    162174        {
     175          // playing Sound
    163176          if (this->soundBuffers[WA_SHOOT] != NULL)
    164177            this->soundSource->play(this->soundBuffers[WA_SHOOT]);
     178          // fire
    165179          this->fire();
     180          // setting up for the next state
     181          this->stateDuration = this->times[WA_SHOOT] + this->stateDuration;
    166182          this->requestedAction = WA_NONE;
    167183        }
     
    176192      if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
    177193      {
     194        // playing Sound
    178195        if (this->soundBuffers[WA_CHARGE] != NULL)
    179196         this->soundSource->play(this->soundBuffers[WA_CHARGE]);
     197        // charge
    180198        this->charge();
     199        // setting up for the next state
    181200        this->requestedAction = WA_NONE;
     201        this->stateDuration = this->times[WA_CHARGE] + this->stateDuration;
    182202      }
    183203      else // deactivate the Weapon if we do not have enough energy
     
    190210      //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge)
    191211      {
     212        // playing Sound
    192213        if (this->soundBuffers[WA_RELOAD] != NULL)
    193214          this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    194 
     215        // reload
    195216        this->reload();
     217        // setting up for next action
    196218        this->requestedAction = WA_NONE;
     219        this->stateDuration = this->times[WA_RELOAD] + this->stateDuration;
    197220      }
    198221      break;
     
    200223      if (this->currentState != WS_INACTIVE)
    201224      {
     225        // play Sound
    202226        if (this->soundBuffers[WA_DEACTIVATE] != NULL)
    203227          this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
    204 
     228        // deactivate
    205229        this->deactivate();
     230        // setting up for next action
    206231        this->requestedAction = WA_NONE;
     232        this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration;
    207233      }
    208234      break;
     
    210236      if (this->currentState == WS_INACTIVE)
    211237      {
     238        // play Sound
    212239        if (this->soundBuffers[WA_ACTIVATE] != NULL)
    213240          this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
    214 
     241        // activate
    215242        this->activate();
     243        // setting up for next action
    216244        this->requestedAction = WA_NONE;
     245        this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration;
    217246      }
    218247      break;
     
    349378}
    350379
     380
     381/**
     382 * checks wether all the Weapons functions are valid, and if it is possible to go to action with it.
     383 *
     384 */
     385bool Weapon::check() const
     386{
     387  bool retVal = true;
     388
     389  if (this->projectile == NULL)
     390  {
     391    PRINTF(2)("There was no projectile assigned to the Weapon.\n");
     392    retVal = false;
     393  }
     394
     395
     396
     397
     398  return retVal;
     399}
    351400
    352401/**
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4890 r4891  
    115115    virtual void draw();
    116116
     117    bool check() const;
    117118    void debug() const;
    118119
     
    132133    static WeaponState   charToState(const char* state);
    133134    static const char*   stateToChar(WeaponState state);
     135
     136
    134137  private:
    135138    bool nextActionValid() const;
Note: See TracChangeset for help on using the changeset viewer.