Changeset 4890 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons
- Timestamp:
- Jul 19, 2005, 12:20:58 PM (19 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/projectile.cc
r4836 r4890 36 36 37 37 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 */ 42 40 } 43 41 … … 65 63 void Projectile::setFlightDirection(Quaternion flightDirection) 66 64 { 67 if( this->flightDirection == NULL)68 this->flightDirection = new Vector();69 65 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(); 72 68 } 73 74 75 /**76 * this sets the time to life of the projectile77 * @param ttl in second78 79 after this life time, the projectile will garbage collect itself80 */81 void Projectile::setTTL(float ttl)82 {83 this->ttl = ttl;84 }85 86 87 /**88 * sets the speed of the projectile89 */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 96 69 97 70 /** … … 101 74 void Projectile::setVelocity(const Vector &velocity) 102 75 { 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); 106 79 } 107 80 … … 116 89 this->shiftCoor(v); 117 90 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 } 127 99 } 128 129 /**130 * the projectile gets hit by another entity131 * @param the other entity132 * @param place where it is hit133 */134 void Projectile::hit (WorldEntity* entity, Vector* place)135 {}136 100 137 101 -
orxonox/trunk/src/world_entities/weapons/projectile.h
r4836 r4890 1 1 /*! 2 \ projectile.h2 \file projectile.h 3 3 * a projectile, that is been shooted by a weapon 4 4 … … 26 26 class Vector; 27 27 class Weapon; 28 class ParticleEmitter; 28 29 29 30 class Projectile : public WorldEntity 30 31 { 31 friend class World; 32 public: 33 Projectile (Weapon* weapon); 34 virtual ~Projectile (); 32 35 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); 36 39 37 void setFlightDirection(Quaternion flightDirection);38 void setSpeed(float speed);39 void setVelocity(const Vector &velocity);40 void setTTL(float ttl);41 40 42 virtual void hit (WorldEntity* weapon, Vector* loc);43 virtual void destroy ();44 41 45 virtual void tick (float time);46 virtual void draw ();47 42 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 (); 55 44 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. 58 64 }; 59 65 -
orxonox/trunk/src/world_entities/weapons/test_bullet.cc
r4836 r4890 64 64 this->shiftCoor(v); 65 65 66 this-> currentLifeTime += time;67 if( this-> ttl < this->currentLifeTime)66 this->lifeCycle += time/this->lifeSpan; 67 if( this->lifeCycle >= 1) 68 68 { 69 69 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); 71 71 PRINTF(5)("FINALIZE===========================\n"); 72 72 this->finalize(); 73 this->currentLifeTime = 0.0f;74 73 } 75 74 } 76 77 /**78 * the projectile gets hit by another entity79 * @param the other entity80 * @param place where it is hit81 */82 void TestBullet::hit (WorldEntity* entity, Vector* place)83 {}84 85 75 86 76 /** -
orxonox/trunk/src/world_entities/weapons/test_bullet.h
r4836 r4890 1 /*! 1 /*! 2 2 \projectile.h 3 3 * a projectile, that is been shooted by a weapon … … 12 12 class Weapon; 13 13 14 class TestBullet : public Projectile 14 class TestBullet : public Projectile 15 15 { 16 16 friend class World; … … 20 20 virtual ~TestBullet (); 21 21 22 virtual void hit (WorldEntity* weapon, Vector* loc);23 22 virtual void destroy (); 24 23 25 24 virtual void tick (float time); 26 25 virtual void draw (); 27 26 28 27 }; 29 28 -
orxonox/trunk/src/world_entities/weapons/test_gun.cc
r4885 r4890 101 101 102 102 this->setStateDuration(WS_SHOOTING, .2); 103 this->setStateDuration(WS_RELOADING, .5); 103 104 104 105 this->energy = 100; -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4885 r4890 122 122 printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration); 123 123 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 */ 133 float 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; 124 146 } 125 147 } -
orxonox/trunk/src/world_entities/weapons/weapon.h
r4885 r4890 28 28 class TiXmlElement; 29 29 30 //! An enumerator defining actions a Weapon can take30 //! An enumerator defining Actions a Weapon can take 31 31 typedef enum { 32 32 WA_NONE = 0, //!< No Action taken … … 80 80 81 81 void requestAction(WeaponAction action); 82 float increaseEnergy(float energyToAdd); 82 83 83 84 /** @returns true if the Weapon is Active */ … … 117 118 118 119 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 125 120 //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction); 126 121 bool execute(); … … 131 126 virtual void charge(); 132 127 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); 133 134 private: 134 135 bool nextActionValid() const; 135 136 137 138 136 139 protected: 137 SoundSource* soundSource; 140 SoundSource* soundSource; //!< A SoundSource to play sound from (this is connected to the PNode of the Weapon) 138 141 // 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) 145 148 146 149 //////////// … … 156 159 157 160 161 bool active; //!< states wheter the weapon is enabled or not 158 162 bool hideInactive; //!< Hides the Weapon if it is inactive 163 bool chargeable; //!< if the Weapon is charcheable 159 164 160 bool active; //!< states wheter the weapon is enabled or not161 165 Projectile* projectile; //!< the projectile used for this weapon 162 166 };
Note: See TracChangeset
for help on using the changeset viewer.