Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4880 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Jul 17, 2005, 2:17:09 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/weaponSystem: more functionality, but firing does not work anymore… this will soon be fixed

Location:
orxonox/branches/weaponSystem/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc

    r4836 r4880  
    120120  alDeleteSources(1, &this->sourceID);
    121121}
    122 
    123122
    124123/**
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc

    r4878 r4880  
    9191      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    9292    }
    93 
     93/*
    9494  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
    9595  this->weaponSource = new SoundSource(this->fireSound, this);
    96   this->weaponSource->setRolloffFactor(.1);
     96  this->weaponSource->setRolloffFactor(.1);*/
    9797  Projectile* p = new TestBullet(this);
    9898//  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
     
    182182void TestGun::destroy ()
    183183{}
    184 
    185 
    186 /**
    187  *  tick signal for time dependent/driven stuff
    188 */
    189 void TestGun::tick (float time)
    190 {
    191   this->stateTime += time;
    192 }
    193184
    194185
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h

    r4836 r4880  
    4747    virtual void destroy();
    4848
    49     virtual void tick(float time);
    5049    virtual void weaponIdle();
    5150    virtual void draw();
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc

    r4879 r4880  
    1313   main-programmer: Patrick Boenzli
    1414   co-programmer: Benjamin Grauer
     15
     16   2005-07-15: Benjamin Grauer: restructurating the entire Class
    1517*/
    1618
     
    2325#include "list.h"
    2426#include "state.h"
     27#include "animation3d.h"
     28#include "sound_engine.h"
    2529
    2630/**
     
    4246Weapon::~Weapon ()
    4347{
    44   // model will be deleted from WorldEntity-destructor
    45   //this->worldEntities = NULL;
    46 
    47   /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */
    48 
    49   /* all animations are deleted via the animation player*/
    50 }
    51 
     48  for (int i = 0; i < WS_STATE_COUNT; i++)
     49    if (this->animation[i])
     50      delete this->animation[i];
     51  for (int i = 0; i < WA_ACTION_COUNT; i++)
     52    if (this->soundBuffers[i])
     53      delete this->soundBuffers[i];
     54}
     55
     56/**
     57 * initializes the Weapon with ALL default values
     58 */
    5259void Weapon::init()
    5360{
    5461  this->currentState     = WS_INACTIVE;
    55   this->stateTime        = 0.0;
     62  this->stateDuration    = 0.0;
    5663  for (int i = 0; i < WS_STATE_COUNT; i++)
    57   {
    58     this->times[i] = 0.0;
    59     this->animation[i] = NULL;
    60   }
     64    {
     65      this->times[i] = 0.0;
     66      this->animation[i] = NULL;
     67    }
    6168  for (int i = 0; i < WA_ACTION_COUNT; i++)
    6269    this->soundBuffers[i] = NULL;
    6370
     71  this->requestedAction = WA_NONE;
    6472  this->weaponSource = NULL;
    65   this->minCharge;
    66   this->maxCharge;
     73  this->minCharge = 0.0;
     74  this->maxCharge = 0.0;
    6775
    6876  this->active = false;
     
    94102
    95103
     104void Weapon::requestAction(WeaponAction action)
     105{
     106  this->requestedAction = action;
     107}
     108
     109bool Weapon::execute(WeaponAction action)
     110{
     111  this->stateDuration = this->times[action] + this->stateDuration;
     112
     113  switch (action)
     114  {
     115    case WA_SHOOT:
     116      this->fire();
     117      break;
     118    case WA_CHARGE:
     119      this->charge();
     120      break;
     121    case WA_RELOAD:
     122      this->reload();
     123      break;
     124    case WA_DEACTIVATE:
     125      this->deactivate();
     126      break;
     127    case WA_ACTIVATE:
     128      this->activate();
     129      break;
     130  }
     131}
     132
    96133/**
    97134 * this activates the weapon
    98  *
    99  * This is needed, since there can be more than one weapon on a ship. the
    100  * activation can be connected with an animation. for example the weapon is
    101  * been armed out.
    102135*/
    103136void Weapon::activate()
     
    107140/**
    108141 * this deactivates the weapon
    109  *
    110  * This is needed, since there can be more than one weapon on a ship. the
    111  * activation can be connected with an animation. for example the weapon is
    112  * been armed out.
    113142*/
    114143void Weapon::deactivate()
    115144{}
    116145
    117 /**
    118  * is called, when the weapon gets hit (=collide with something)
    119  * @param from which entity it is been hit
    120  * @param where it is been hit
    121  *
    122  * this may not be used, since it would make the game relay complicated when one
    123  * can destroy the weapons of enemies or vice versa.
    124 */
    125 void Weapon::hit (WorldEntity* entity, const Vector& position)
    126 {}
     146void Weapon::fire()
     147{
     148
     149}
     150
     151void Weapon::reload()
     152{
     153
     154}
     155
     156void Weapon::charge()
     157{
     158}
    127159
    128160
     
    138170
    139171/**
    140  *  tick signal for time dependent/driven stuff
    141 */
    142 void Weapon::tick (float time)
    143 {}
     172 * tick signal for time dependent/driven stuff
     173*/
     174void Weapon::tick(float dt)
     175{
     176  if (this->isActive())
     177  {
     178    this->stateDuration -= dt;
     179
     180    if (this->stateDuration < 0.0)
     181      this->execute(this->requestedAction);
     182  }
     183  else
     184    if (this->requestedAction == WA_ACTIVATE)
     185      this->activate();
     186
     187}
    144188
    145189/**
     
    153197
    154198
     199//////////////////////
     200// HELPER FUNCTIONS //
     201//////////////////////
     202// inclass
     203/**
     204 * checks if the next Action given is valid
     205 * @returns if the Action that comes next is valid
     206 * @todo more checks
     207 */
     208bool Weapon::nextActionValid() const
     209{
     210  if (this->currentState == WS_INACTIVE)
     211  {
     212    return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE);
     213  }
     214  else
     215    return true;
     216
     217}
     218
     219
     220
     221// static
    155222/**
    156223 * Converts a String into an Action.
     
    175242    return WA_SPECIAL1;
    176243  else
    177   {
    178     PRINTF(2)("action %s could not be identified.\n", action);
    179     return WA_NONE;
    180   }
     244    {
     245      PRINTF(2)("action %s could not be identified.\n", action);
     246      return WA_NONE;
     247    }
    181248}
    182249
     
    192259  else if (!strcmp(state, "shooting"))
    193260    return WS_SHOOTING;
     261  else if (!strcmp(state, "charging"))
     262    return WS_CHARGING;
    194263  else if (!strcmp(state, "reloading"))
    195264    return WS_RELOADING;
     
    203272    return WS_IDLE;
    204273  else
    205   {
    206     PRINTF(2)("state %s could not be identified.\n", state);
    207     return WS_NONE;
    208   }
    209 }
    210 
     274    {
     275      PRINTF(2)("state %s could not be identified.\n", state);
     276      return WS_NONE;
     277    }
     278}
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h

    r4879 r4880  
    1212    weapon in this world:
    1313     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
    14      o shooting animation
     14     o animations
    1515*/
    1616
     
    4545  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
    4646  WS_SHOOTING      =    1,    //!< The State of the Shooting
     47  WS_CHARGING      =    2,    //!< The state of charging th weapon
    4748  WS_RELOADING     =    3,    //!< The State of the Reloading
    4849  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
     
    6869class Weapon : public WorldEntity
    6970{
    70   friend class World;
     71  public:
     72    // INITIALISATION //
     73    Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
     74    Weapon(const TiXmlElement* root);
     75    virtual ~Weapon ();
    7176
    72  public:
    73   Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
    74   Weapon(const TiXmlElement* root);
    75   virtual ~Weapon ();
     77    void init();
     78    void loadParams(const TiXmlElement* root);
     79    ////////////////////
    7680
    77   void init();
    78   void loadParams(const TiXmlElement* root);
     81    void requestAction(WeaponAction action);
    7982
    80   void setProjectile(Projectile* projectile);
    81   Projectile* getProjectile();
     83    /** @returns true if the Weapon is Active */
     84    inline bool isActive() const { return this->active; };
    8285
    83   virtual void activate();
    84   virtual void deactivate();
    85   virtual void fire() = 0;
    86   //virtual void reload();
    87   //virtual void charge();
    88   bool isActive() const { return this->active; };
     86    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
     87    void setProjectile(Projectile* projectile);
     88    Projectile* getProjectile();
    8989
    90   // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
    91   void setStateDuration(const char* state, float duration);
    92   void setStateDuration(WeaponState state, float duration);
    93   float getStateDuration(WeaponState state) { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
    94   /** @return true if idletime is elapsed, false otherwise */
    95   inline bool stateTimeElapsed() const { return (this->stateTime > this->times[currentState])?true:false; };
     90    /** @param state the State to time @param duration the duration of the State */
     91    inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); };
     92    /** @param state the State to time @param duration the duration of the State */
     93    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
     94    /** @param state The state to query @returns the Time the queried State takes to complete */
     95    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
     96    /** @returns true if the time of the currentState is elapsed, false otherwise */
     97    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])?true:false; };
     98    /** @returns the current State of the Weapon */
     99    inline WeaponState getCurrentState() const { return this->currentState; };
    96100
    97   /**  fires the weapon */
    98   virtual void hit (WorldEntity* weapon, const Vector& loc);
    99   virtual void destroy();
    100101
    101   virtual void tick(float time);
    102   virtual void draw();
    103102
    104   private:
     103    virtual void destroy();
     104
     105
     106
     107    virtual void tick(float dt);
     108    virtual void draw();
     109
     110  protected:
    105111    static WeaponAction  charToAction(const char* action);
    106112    static WeaponState   charToState(const char* state);
    107113
    108114
    109  protected:
    110   ////////////
    111   // PHASES //
    112   ////////////
    113   WeaponState          currentState;                     //!< The State the weapon is in.
    114   WeaponAction         requestAction;                    //!< An action to try to Engage after the currentState ends.
    115   float                stateTime;                        //!< how long the state has taken until now.
    116   float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
    117   SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    118   Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     115    bool execute(WeaponAction action);
     116    virtual void activate();
     117    virtual void deactivate();
     118    virtual void fire();
     119    virtual void reload();
     120    virtual void charge();
    119121
    120   SoundBuffer*         fireSound;
    121   SoundSource*         weaponSource;
     122  private:
     123    bool nextActionValid() const;
    122124
    123   float                minCharge;
    124   float                maxCharge;
     125  protected:
     126    SoundSource*         weaponSource;
     127    float                energy;
     128    int                  energyI;
    125129
    126  private:
    127    bool                 active;                          //!< states wheter the weapon is enabled or not
    128    Projectile*          projectile;                      //!< the projectile used for this weapon
    129 };
     130    ////////////
     131    // PHASES //
     132    ////////////
     133    WeaponState          currentState;                     //!< The State the weapon is in.
     134    WeaponAction         requestedAction;                  //!< An action to try to Engage after the currentState ends.
     135    float                stateDuration;                    //!< how long the state has taken until now.
     136    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
     137    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
     138    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     139
     140    float                minCharge;
     141    float                maxCharge;
     142
     143    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
     144
     145  private:
     146    bool                 active;                          //!< states wheter the weapon is enabled or not
     147    Projectile*          projectile;                      //!< the projectile used for this weapon
     148  };
    130149
    131150#endif /* _WEAPON_H */
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon_manager.cc

    r4849 r4880  
    201201      if( w1 != NULL )
    202202      {
    203         w1->deactivate();
     203        w1->requestAction(WA_DEACTIVATE);
    204204        printf("deactivating %i,%i\n", j,lastConfID);
    205205      }
    206206      if( w2 != NULL)
    207207      {
    208         w2->activate();
     208        w2->requestAction(WA_ACTIVATE);
    209209        printf("activating %i,%i\n", j, this->currConfID);
    210210      }
     
    223223  {
    224224    firingWeapon = this->configs[this->currConfID].slots[i];
    225     if( firingWeapon != NULL) firingWeapon->fire();
     225    if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
    226226  }
    227227  this->crosshair->setRotationSpeed(500);
Note: See TracChangeset for help on using the changeset viewer.