Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 19, 2005, 12:20:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: remake of the Projectile and TestBullet

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

Legend:

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

    r4836 r4890  
    3636
    3737  this->weapon = weapon;
    38   this->flightDirection = NULL;
    39   this->currentLifeTime = 0.0f;
    40   this->ttl = 0.75f; /* sec */
    41   this->speed = 2.0f;
     38  this->lifeCycle = 0.0;
     39  this->lifeSpan = 0.75f; /* sec */
    4240}
    4341
     
    6563void Projectile::setFlightDirection(Quaternion flightDirection)
    6664{
    67   if( this->flightDirection == NULL)
    68     this->flightDirection = new Vector();
    6965  Vector v(1, 0, 0);
    70   *this->flightDirection = flightDirection.apply(v);
    71   this->flightDirection->normalize();
     66  this->flightDirection = flightDirection.apply(v);
     67  this->flightDirection.normalize();
    7268}
    73 
    74 
    75 /**
    76  *  this sets the time to life of the projectile
    77  * @param ttl in second
    78 
    79    after this life time, the projectile will garbage collect itself
    80 */
    81 void Projectile::setTTL(float ttl)
    82 {
    83   this->ttl = ttl;
    84 }
    85 
    86 
    87 /**
    88  *  sets the speed of the projectile
    89 */
    90 void Projectile::setSpeed(float speed)
    91 {
    92   this->speed = speed * 3; /* fix speed settings */
    93   PRINTF(4)("Projectile::setting speed to: %f\n", this->speed);
    94 }
    95 
    9669
    9770/**
     
    10174void Projectile::setVelocity(const Vector &velocity)
    10275{
    103   this->offsetVel = this->velocity = velocity;
    104   this->offsetVel.normalize();
    105   this->velocity += (this->offsetVel * 50.0);
     76  Vector offsetVel = this->velocity = velocity;
     77  offsetVel.normalize();
     78  this->velocity += (offsetVel * 50.0);
    10679}
    10780
     
    11689  this->shiftCoor(v);
    11790
    118   this->currentLifeTime += time;
    119   if( this->ttl < this->currentLifeTime)
    120     {
    121       PRINTF(5)("FINALIZE==========================\n");
    122       PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl);
    123       PRINTF(5)("FINALIZE===========================\n");
    124       this->finalize();
    125       this->currentLifeTime = 0.0f;
    126     }
     91  this->lifeCycle += time/this->lifeSpan;
     92  if( this->lifeCycle >= 1)
     93  {
     94    PRINTF(5)("FINALIZE==========================\n");
     95    PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
     96    PRINTF(5)("FINALIZE===========================\n");
     97    this->finalize();
     98  }
    12799}
    128 
    129 /**
    130  *  the projectile gets hit by another entity
    131  * @param the other entity
    132  * @param place where it is hit
    133 */
    134 void Projectile::hit (WorldEntity* entity, Vector* place)
    135 {}
    136100
    137101
  • orxonox/trunk/src/world_entities/weapons/projectile.h

    r4836 r4890  
    11/*!
    2     \projectile.h
     2    \file projectile.h
    33  *  a projectile, that is been shooted by a weapon
    44
     
    2626class Vector;
    2727class Weapon;
     28class ParticleEmitter;
    2829
    2930class Projectile : public WorldEntity
    3031{
    31   friend class World;
     32  public:
     33    Projectile (Weapon* weapon);
     34    virtual ~Projectile ();
    3235
    33  public:
    34   Projectile (Weapon* weapon);
    35   virtual ~Projectile ();
     36    void setFlightDirection(Quaternion flightDirection);
     37    void setVelocity(const Vector &velocity);
     38    void setLifeSpan(float lifeSpan);
    3639
    37   void setFlightDirection(Quaternion flightDirection);
    38   void setSpeed(float speed);
    39   void setVelocity(const Vector &velocity);
    40   void setTTL(float ttl);
    4140
    42   virtual void hit (WorldEntity* weapon, Vector* loc);
    43   virtual void destroy ();
    4441
    45   virtual void tick (float time);
    46   virtual void draw ();
    4742
    48  protected:
    49   //physical attriutes like: force, speed, acceleration etc.
    50   float          speed;                     //!< this is the speed of the projectile
    51   float          currentLifeTime;           //!< this is the time, the projectile exists in this world (incremented by tick)
    52   float          ttl;                       //!< time to life, after this time, the projectile will garbage collect itself
    53   Vector*        flightDirection;           //!< direction in which the shoot flights
    54   Weapon*        weapon;                    //!< weapon the shoot belongs to
     43    virtual void destroy ();
    5544
    56   Vector         velocity;                  //!< velocity of the projectile
    57   Vector         offsetVel;                 //!< offset velocity TEMP
     45    virtual void tick (float time);
     46    virtual void draw ();
     47
     48  protected:
     49
     50    // energy
     51    float                 energyMin;
     52    float                 energyMax;
     53
     54
     55    float                 lifeCycle;                 //!< The percentage of the Lifetime done [0-1]
     56    float                 lifeSpan;                  //!< The entire lifespan of the Shoot.
     57
     58    Vector                flightDirection;           //!< direction in which the shoot flighs
     59    Weapon*               weapon;                    //!< weapon the shoot belongs to.
     60
     61    Vector                velocity;                  //!< velocity of the projectile.
     62
     63    ParticleEmitter*      emitter;                   //!< For special effects each Projectile consists of an emitter.
    5864};
    5965
  • orxonox/trunk/src/world_entities/weapons/test_bullet.cc

    r4836 r4890  
    6464  this->shiftCoor(v);
    6565
    66   this->currentLifeTime += time;
    67   if( this->ttl < this->currentLifeTime)
     66  this->lifeCycle += time/this->lifeSpan;
     67  if( this->lifeCycle >= 1)
    6868    {
    6969      PRINTF(5)("FINALIZE==========================\n");
    70       PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl);
     70      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
    7171      PRINTF(5)("FINALIZE===========================\n");
    7272      this->finalize();
    73       this->currentLifeTime = 0.0f;
    7473    }
    7574}
    76 
    77 /**
    78  *  the projectile gets hit by another entity
    79  * @param the other entity
    80  * @param place where it is hit
    81 */
    82 void TestBullet::hit (WorldEntity* entity, Vector* place)
    83 {}
    84 
    8575
    8676/**
  • orxonox/trunk/src/world_entities/weapons/test_bullet.h

    r4836 r4890  
    1 /*! 
     1/*!
    22    \projectile.h
    33  *  a projectile, that is been shooted by a weapon
     
    1212class Weapon;
    1313
    14 class TestBullet : public Projectile 
     14class TestBullet : public Projectile
    1515{
    1616  friend class World;
     
    2020  virtual ~TestBullet ();
    2121
    22   virtual void hit (WorldEntity* weapon, Vector* loc);
    2322  virtual void destroy ();
    2423
    2524  virtual void tick (float time);
    2625  virtual void draw ();
    27  
     26
    2827};
    2928
  • orxonox/trunk/src/world_entities/weapons/test_gun.cc

    r4885 r4890  
    101101
    102102  this->setStateDuration(WS_SHOOTING, .2);
     103  this->setStateDuration(WS_RELOADING, .5);
    103104
    104105  this->energy = 100;
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4885 r4890  
    122122    printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration);
    123123    this->requestedAction = action;
     124  }
     125}
     126
     127
     128/**
     129 * adds energy to the Weapon
     130 * @param energyToAdd The amount of energy
     131 * @returns the amount of energy we did not pick up, because the weapon is already full
     132 */
     133float Weapon::increaseEnergy(float energyToAdd)
     134{
     135  float maxAddEnergy = this->energyMax - this->energy;
     136
     137  if (maxAddEnergy >= energyToAdd)
     138  {
     139    this->energy += energyToAdd;
     140    return 0.0;
     141  }
     142  else
     143  {
     144    this->energy += maxAddEnergy;
     145    return energyToAdd - maxAddEnergy;
    124146  }
    125147}
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4885 r4890  
    2828class TiXmlElement;
    2929
    30 //! An enumerator defining actions a Weapon can take
     30//! An enumerator defining Actions a Weapon can take
    3131typedef enum {
    3232  WA_NONE          =    0,    //!< No Action taken
     
    8080
    8181    void requestAction(WeaponAction action);
     82    float increaseEnergy(float energyToAdd);
    8283
    8384    /** @returns true if the Weapon is Active */
     
    117118
    118119  protected:
    119     // utility:
    120     static WeaponAction  charToAction(const char* action);
    121     static const char*   actionToChar(WeaponAction action);
    122     static WeaponState   charToState(const char* state);
    123     static const char*   stateToChar(WeaponState state);
    124 
    125120    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
    126121    bool execute();
     
    131126    virtual void charge();
    132127
     128
     129    // utility:
     130    static WeaponAction  charToAction(const char* action);
     131    static const char*   actionToChar(WeaponAction action);
     132    static WeaponState   charToState(const char* state);
     133    static const char*   stateToChar(WeaponState state);
    133134  private:
    134135    bool nextActionValid() const;
    135136
     137
     138
    136139  protected:
    137     SoundSource*         soundSource;
     140    SoundSource*         soundSource;                      //!< A SoundSource to play sound from (this is connected to the PNode of the Weapon)
    138141    // it is all about energy
    139     float                energy;
    140     float                energyLoaded;
    141     float                energyMax;
    142     float                energyLoadedMax;
    143     float                minCharge;
    144     float                maxCharge;
     142    float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
     143    float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (firewithout reload)
     144    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
     145    float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
     146    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
     147    float                maxCharge;                        //!< The maximal energy to be loaded onto one projectile (this is only availible if chargeable is enabled)
    145148
    146149    ////////////
     
    156159
    157160
     161    bool                 active;                          //!< states wheter the weapon is enabled or not
    158162    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
     163    bool                 chargeable;                      //!< if the Weapon is charcheable
    159164
    160     bool                 active;                          //!< states wheter the weapon is enabled or not
    161165    Projectile*          projectile;                      //!< the projectile used for this weapon
    162166  };
Note: See TracChangeset for help on using the changeset viewer.