Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 19, 2005, 6:27:06 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: messed things up a bit, try fixing

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

Legend:

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

    r4893 r4895  
    5353
    5454  this->objectComponent1 = new PNode();
    55   Animation3D* animation1 = this->createAnimation(WS_SHOOTING, this->objectComponent1);
    56   Animation3D* animation2 = this->createAnimation(WS_ACTIVATING, this);
    57   Animation3D* animation3 = this->createAnimation(WS_DEACTIVATING, this);
     55  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
     56  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
     57  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
    5858  //parent->addChild(this->objectComponent1, PNODE_ALL);
    5959  this->addChild(this->objectComponent1, PNODE_ALL);
     
    8585      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
    8686
    87       animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    88       animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    89 
    90       animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    91       animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
     87      animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     88      animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     89
     90      animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     91      animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    9292    }
    9393/*
     
    102102  this->setStateDuration(WS_SHOOTING, .2);
    103103  this->setStateDuration(WS_RELOADING, .5);
     104  //this->setStateDuration(WS_ACTIVATING, .4);
     105  //this->setStateDuration(WS_DEACTIVATING, .4);
    104106
    105107  this->energy = 100;
     
    181183void TestGun::destroy ()
    182184{}
    183 
    184 
    185 /**
    186  *  is called, when there is no fire button pressed
    187 */
    188 void TestGun::weaponIdle()
    189 {}
    190 
    191185
    192186/**
  • orxonox/trunk/src/world_entities/weapons/test_gun.h

    r4893 r4895  
    4545    virtual void destroy();
    4646
    47     virtual void weaponIdle();
    4847    virtual void draw();
    4948
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4894 r4895  
    129129
    130130/**
    131  * creates an Animation3D for a certain State.
    132  * @param state what state should the Animation be created for
    133  * @param node the node this Animation should apply to.
    134  * @returns The created animation.Animation(), NULL on error.
     131 * creates/returns an Animation3D for a certain State.
     132 * @param state what State should the Animation be created/returned for
     133 * @param node the node this Animation should apply to. (NULL is fine if the animation was already created)
     134 * @returns The created animation.Animation(), NULL on error (or if the animation does not yet exist).
    135135 *
    136136 * This function does only generate the Animation Object, and if set it will
     
    138138 * What this does not do, is set keyframes, you have to operate on the returned animation.
    139139 */
    140 Animation3D* Weapon::createAnimation(WeaponState state, PNode* node)
    141 {
    142   if (state >= WS_STATE_COUNT || node == NULL)
     140Animation3D* Weapon::getAnimation(WeaponState state, PNode* node)
     141{
     142  if (state >= WS_STATE_COUNT) // if the state is not known
    143143    return NULL;
    144144
    145   if (unlikely(this->animation[state] != NULL))
    146   {
    147     delete this->animation[state];
    148     this->animation[state] = NULL;
    149   }
    150   return this->animation[state] = new Animation3D(node);
     145  if (unlikely(this->animation[state] == NULL)) // if the animation does not exist yet create it.
     146  {
     147    if (likely(node != NULL))
     148      return this->animation[state] = new Animation3D(node);
     149    else
     150    {
     151      PRINTF(2)("Node not defined for the Creation of the 3D-animation of state %s\n", stateToChar(state));
     152      return NULL;
     153    }
     154  }
     155  else
     156    return this->animation[state];
    151157}
    152158
     
    156162// GAME ACTION //
    157163/////////////////
    158 
    159164/**
    160165 * request an action that should be executed,
     
    241246bool Weapon::activateW()
    242247{
    243 
    244   if (this->currentState == WS_INACTIVE)
     248//  if (this->currentState == WS_INACTIVE)
    245249  {
    246250        // play Sound
     
    250254      this->animation[WS_ACTIVATING]->replay();
    251255        // activate
    252     PRINTF(5)("Activating the Weapon %s\n", this->getName());
     256    PRINTF(4)("Activating the Weapon %s\n", this->getName());
    253257    this->activate();
    254         // setting up for next action
    255     this->requestedAction = WA_NONE;
     258    this->active = true;
     259    // setting up for next action
    256260    this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration;
    257261  }
     262  this->requestedAction = WA_NONE;
    258263}
    259264
     
    275280        // deactivate
    276281    this->deactivate();
     282    this->active = false;
    277283        // setting up for next action
    278     this->requestedAction = WA_NONE;
    279284    this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration;
    280285  }
    281 
     286  this->requestedAction = WA_NONE;
    282287}
    283288
     
    414419// HELPER FUNCTIONS //
    415420//////////////////////
    416 // inclass
    417 /**
    418  * checks if the next Action given is valid
    419  * @returns if the Action that comes next is valid
    420  * @todo more checks
    421  */
    422 bool Weapon::nextActionValid() const
    423 {
    424   if (this->currentState == WS_INACTIVE)
    425   {
    426     return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE);
    427   }
    428   else
    429     return true;
    430 
    431 }
    432 
    433 
    434421/**
    435422 * checks wether all the Weapons functions are valid, and if it is possible to go to action with it.
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4893 r4895  
    112112    void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); };
    113113
    114     Animation3D* createAnimation(WeaponState state, PNode* node);
     114    Animation3D* getAnimation(WeaponState state, PNode* node = NULL);
    115115
    116116    // FLOW
     
    137137    static const char*   stateToChar(WeaponState state);
    138138
    139 
    140139  private:
    141140    /** executive functions, that handle timing with actions.
     
    151150    bool fireW();
    152151    bool reloadW();
    153 
    154     bool nextActionValid() const;
    155 
    156152
    157153
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4885 r4895  
    7676  }
    7777  this->currConfID = W_CONFIG0;
     78
     79
     80
     81
    7882  this->crosshair = new Crosshair();
    7983
     
    237241{
    238242  Weapon* w;
     243  for (int j = 0; j < 4; ++j )
     244    for(int i = 0; i < W_MAX_SLOTS; ++i)
     245  {
     246    w = this->configs[j].slots[i];
     247    if( w != NULL) w->tick(dt);
     248  }
     249
     250  crosshair->setRotationSpeed(5);
     251}
     252
     253
     254/**
     255 * triggers draw of all weapons in the current weaponconfig
     256 */
     257void WeaponManager::draw()
     258{
     259  Weapon* w;
     260  for (int j = 0; j < 4; ++j )
    239261  for(int i = 0; i < W_MAX_SLOTS; ++i)
    240262  {
    241     w = this->configs[this->currConfID].slots[i];
    242     if( w != NULL) w->tick(dt);
    243   }
    244 
    245   crosshair->setRotationSpeed(5);
    246 }
    247 
    248 
    249 /**
    250  * triggers draw of all weapons in the current weaponconfig
    251  */
    252 void WeaponManager::draw()
    253 {
    254   Weapon* w;
    255   for(int i = 0; i < W_MAX_SLOTS; ++i)
    256   {
    257     w = this->configs[this->currConfID].slots[i];
     263    w = this->configs[j].slots[i];
    258264    if( w != NULL)
    259265      w->draw();
Note: See TracChangeset for help on using the changeset viewer.