Changeset 10601 for code/branches/weaponFS15/src/modules/weapons
- Timestamp:
- Sep 27, 2015, 10:03:53 PM (9 years ago)
- Location:
- code/branches/weaponFS15/src/modules/weapons
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponFS15/src/modules/weapons/munitions/GravityBombMunition.cc
r10455 r10601 12 12 RegisterClass(GravityBombMunition); 13 13 14 15 16 17 18 19 14 GravityBombMunition::GravityBombMunition(Context* context) : Munition(context) 15 { 16 RegisterObject(GravityBombMunition); 17 this->maxMunitionPerMagazine_ = 1; 18 this->maxMagazines_ = 30; 19 this->magazines_ = 15; 20 20 21 22 21 this->bUseSeparateMagazines_ = false; 22 this->bStackMunition_ = true; 23 23 24 25 26 24 this->bAllowMunitionRefilling_ = true; 25 this->bAllowMultiMunitionRemovementUnderflow_ = false; 26 } 27 27 28 28 } -
code/branches/weaponFS15/src/modules/weapons/munitions/GravityBombMunition.h
r10455 r10601 14 14 namespace orxonox 15 15 { 16 17 * @classGravityBombMunition18 19 * @briefThis class is used to set the behaviour of various20 *munition specific attributes of the GravityBomb like max count of munition per magazine.21 22 * @authorManuel23 * @date23.05.201524 25 16 /** 17 * @class GravityBombMunition 18 * 19 * @brief This class is used to set the behaviour of various 20 * munition specific attributes of the GravityBomb like max count of munition per magazine. 21 * 22 * @author Manuel 23 * @date 23.05.2015 24 */ 25 class _WeaponsExport GravityBombMunition : public Munition 26 26 { 27 27 public: 28 28 GravityBombMunition(Context* context); 29 29 virtual ~GravityBombMunition() {} 30 30 }; -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.cc
r10502 r10601 10 10 11 11 namespace orxonox{ 12 12 RegisterClass(GravityBomb); 13 13 14 14 const float GravityBomb::LIFETIME = 2.5; ///< The gravity bomb lifetime in seconds. 15 15 16 17 18 19 20 21 16 GravityBomb::GravityBomb(Context* context): 17 BasicProjectile(), 18 MovableEntity(context), 19 RadarViewable(this,static_cast<WorldEntity*>(this)) 20 { 21 RegisterObject(GravityBomb); 22 22 23 24 25 26 27 28 29 30 31 23 this->setMass(10.0); 24 this->hasCollided_ = false; 25 if (GameMode::isMaster()) 26 { 27 //Define CollisionType of the bomb 28 this->timeToLife_= LIFETIME; 29 this->setCollisionResponse(false); 30 this->setCollisionType(WorldEntity::Dynamic); 31 this->enableCollisionCallback(); 32 32 33 34 35 36 33 //Add Collision Shape 34 SphereCollisionShape* collisionShape = new SphereCollisionShape(context); 35 collisionShape->setRadius(1.0); 36 this->attachCollisionShape(collisionShape); 37 37 38 39 40 41 42 43 44 45 46 47 38 //Create Bomb Model 39 Model* rocketModel = new Model(this->getContext()); 40 rocketModel->setMeshSource("GravityBombRocket.mesh"); //Demo Model from SimpleRocket 41 rocketModel->scale(3.0f); 42 this->attach(rocketModel); 43 //Add second model because the bomb consists of the bomb and attached rockets (2 separate models) 44 Model* bombModel = new Model(this->getContext()); 45 bombModel->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket 46 bombModel->scale(3.0f); 47 this->attach(bombModel); 48 48 49 50 51 52 53 49 //Add particle effect to the flying rockets. 50 ParticleEmitter* fire = new ParticleEmitter(this->getContext()); 51 fire->setOrientation(this->getOrientation()); 52 fire->setSource("Orxonox/simplerocketfire"); 53 this->attach(fire); 54 54 55 56 57 58 59 60 61 62 63 55 //Add sound effect while the bomb is flying. 56 WorldSound* bombSound = new WorldSound(context); 57 bombSound->setSource("sounds/GravityBombFlight.ogg"); 58 bombSound->setLooping(true); 59 bombSound->setVolume(1.0); 60 this->attach(bombSound); 61 bombSound->play(); 62 } 63 } 64 64 65 65 GravityBomb::~GravityBomb(){} 66 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 67 void GravityBomb::tick(float dt) 68 { 69 SUPER(GravityBomb, tick, dt); 70 timeToLife_ -= dt; 71 if (timeToLife_ < 0) 72 { 73 //orxout(debug_output) << "bomb has stoped moving" <<endl; 74 setVelocity(Vector3::ZERO); //Stop the bomb. 75 detonate(); 76 this->destroy(); 77 } 78 else 79 { 80 if (hasCollided_) detonate(); 81 destroyCheck(); //Bomb is going to be destroyed by destroyCheck(). As written in BasicProectile, this Method should be called by every Projectile. 82 } 83 } 84 84 85 86 87 88 89 85 bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) 86 { 87 hasCollided_ = processCollision(otherObject, contactPoint, cs); 88 return hasCollided_; 89 } 90 90 91 92 93 94 95 96 97 98 99 91 void GravityBomb::detonate() 92 { 93 //Create the GravityBombField and destroy the Projectil. 94 GravityBombField* field = new GravityBombField(this->getContext()); 95 field->setShooter(this->getShooter()); 96 field->setPosition(getPosition()); 97 //orxout(debug_output) << "detonating. Creating GravityBombField." <<endl; 98 //orxout(debug_output) << "Field is at Position: " << getPosition() << endl; 99 } 100 100 } 101 101 -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.h
r10502 r10601 26 26 namespace orxonox 27 27 { 28 29 * @classGravityBomb30 31 * @briefThis class implements how long the bomb flies before it places the GravityField at it's last possition.32 *The field will be created either because the timelimit of the bomb expired or it hit something. After creation of the field,33 *the projectile (this object) is destroyed.34 35 * @authorManuel Eggimann36 * @date23.05.201537 38 39 40 41 42 43 28 /** 29 * @class GravityBomb 30 * 31 * @brief This class implements how long the bomb flies before it places the GravityField at it's last possition. 32 * The field will be created either because the timelimit of the bomb expired or it hit something. After creation of the field, 33 * the projectile (this object) is destroyed. 34 * 35 * @author Manuel Eggimann 36 * @date 23.05.2015 37 */ 38 class _WeaponsExport GravityBomb : public BasicProjectile , public MovableEntity, public RadarViewable 39 { 40 public: 41 GravityBomb(Context* context); 42 virtual ~GravityBomb(); 43 virtual void tick(float dt); 44 44 45 46 47 48 45 virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint); 46 void detonate(); 47 private: 48 static const float LIFETIME; 49 49 50 51 52 53 50 bool hasCollided_; 51 float timeToLife_; //Time the bomb flies before it explodes. 52 WorldSound* bombSound_; 53 }; 54 54 } 55 55 #endif /* GravityBOMB_H_ */ -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.cc
r10502 r10601 10 10 11 11 namespace orxonox{ 12 12 RegisterClass(GravityBombField); 13 13 14 15 16 17 18 19 20 21 22 23 24 14 //Change these constants to alter the behaviour of the field. 15 16 const float GravityBombField::FORCE_FIELD_LIFETIME = 15; 17 const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250; 18 const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -700; 19 const float GravityBombField::PEAK_EXPLOSION_FORCE = 5e4; 20 const float GravityBombField::FORCE_FIELD_EXPLOSION_DAMMAGE = 100; 21 const float GravityBombField::EXPLOSION_DURATION = 1; 22 const float GravityBombField::EXPLOSION_RADIUS = 600; 23 const float GravityBombField::PEAK_ANGULAR_VELOCITY = 20; 24 const float GravityBombField::CENTRE_MODEL_END_SIZE = 1.5; 25 25 26 27 28 29 30 31 32 33 34 26 GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this)) 27 { 28 RegisterObject(GravityBombField); 29 //Initialize variable with their initial values. 30 lifetime_=FORCE_FIELD_LIFETIME; 31 forceStrength_ = FORCE_SPHERE_START_STRENGTH; 32 forceSphereRadius_ = FORCE_SPHERE_START_RADIUS; 33 modelScaling_ = 1; 34 fieldExploded_ = false; 35 35 36 37 38 39 36 setVelocity(FORCE_SPHERE_START_STRENGTH); 37 setDiameter(2*FORCE_SPHERE_START_RADIUS); 38 setMode(modeSphere_s); 39 setCollisionResponse(false); 40 40 41 42 43 44 45 41 //Make the Field visible on Radar and minimap. 42 this->setRadarObjectColour(ColourValue(1.0, 0.0, 0.2,1)); // Red 43 this->setRadarObjectShape(RadarViewable::Dot); 44 this->setRadarObjectScale(1.0f); 45 46 46 47 48 49 50 51 52 53 47 //Attach Model 48 Model* model = new Model(this->getContext()); 49 model->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket 50 model->scale(2.5f); 51 bombModel_ = new MovableEntity(context); 52 bombModel_->attach(model); 53 this->attach(bombModel_); 54 54 55 56 57 58 59 60 61 62 55 //Add a Backlight to the centre. 56 centreLight_ = new Backlight(context); 57 centreLight_->setColour(ColourValue(0.2,0.9,0.2,1)); 58 centreLight_->setScale(0.3); 59 centreLight_->setTrailMaterial("Trail/backlighttrail"); 60 centreLight_->setMaterial("Examples/Flare"); 61 centreLight_->setLifetime(20); 62 bombModel_->attach(centreLight_); 63 63 64 65 66 67 68 69 70 71 64 //Let the Bomb Modell in the centre rotate in a random direction. 65 Vector3 randomRotation; 66 srand(time(NULL)); 67 randomRotation.x = rand(); 68 randomRotation.y = rand(); 69 randomRotation.y = rand(); 70 randomRotation.normalise(); 71 bombModel_->setAngularAcceleration(randomRotation*(PEAK_ANGULAR_VELOCITY/FORCE_FIELD_LIFETIME)); 72 72 73 74 75 76 73 //Add Collision Shape 74 SphereCollisionShape* collisionShape = new SphereCollisionShape(context); 75 collisionShape->setRadius(10.0); 76 this->attachCollisionShape(collisionShape); 77 77 78 79 80 81 78 //Add particle effect to visualize the force field. 79 this->particleSphere_ = new ParticleEmitter(this->getContext()); 80 this->attach(this->particleSphere_); 81 particleSphere_->setSource("Orxonox/GravityBombField"); 82 82 83 84 85 86 87 88 89 90 83 //Add a sound effect to the field. 84 WorldSound* fieldSound = new WorldSound(context); 85 fieldSound->setSource("sounds/GravityField.ogg"); 86 fieldSound->setLooping(true); 87 fieldSound->setVolume(1.0); 88 this->attach(fieldSound); 89 fieldSound->play(); 90 } 91 91 92 92 GravityBombField::~GravityBombField(){} 93 93 94 95 96 97 98 94 95 void GravityBombField::tick(float dt) 96 { 97 SUPER(GravityBombField,tick,dt); 98 lifetime_-=dt; 99 99 100 101 102 103 104 105 106 107 108 109 110 111 100 if(lifetime_ > EXPLOSION_DURATION)//If field is still alive, make it smaller and stronger. 101 { 102 modelScaling_ += ((CENTRE_MODEL_END_SIZE-1) / FORCE_FIELD_LIFETIME)*dt; 103 forceStrength_ *= (1+dt/10); 104 forceSphereRadius_ = FORCE_SPHERE_START_RADIUS*(1-((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)); 105 } 106 else if(lifetime_ > 0) 107 { 108 if (!fieldExploded_) // Start the field explosion if it has not been started yet. 109 { 110 forceStrength_ = pow((EXPLOSION_DURATION + lifetime_),4)/EXPLOSION_DURATION * PEAK_EXPLOSION_FORCE; 111 fieldExploded_ = true; 112 112 113 114 115 116 117 118 113 //Add particle effect to visualize explosion 114 explosionCross_ = new ParticleEmitter(this->getContext()); 115 explosionCross_->setSource("Orxonox/FieldExplosion"); 116 explosionCross_->setOrientation(rand(), rand(), rand(), rand()); 117 explosionCross_->setScale(0.7); 118 this->attach(explosionCross_); 119 119 120 121 122 123 124 125 120 //Add explosion sound effect. 121 explosionSound_ = new WorldSound(getContext()); 122 explosionSound_->setSource("sounds/GravityFieldExplosion.ogg"); 123 explosionSound_->setVolume(1.0); 124 explosionSound_->play(); 125 } 126 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 127 //Check if any pawn is inside the shockwave and hit it with dammage proportional to the distance between explosion centre and pawn. Make sure, the same pawn is damaged only once. 128 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 129 { 130 Vector3 distanceVector = it->getWorldPosition()-this->getWorldPosition(); 131 //orxout(debug_output) << "Found Pawn:" << it->getWorldPosition() << endl; 132 if(distanceVector.length()< forceSphereRadius_) 133 { 134 //orxout(debug_output) << "Force sphere radius is: " << forceSphereRadius_ << " Distance to Pawn is: " << distanceVector.length(); 135 if (std::find(victimsAlreadyDamaged_.begin(),victimsAlreadyDamaged_.end(),*it) == victimsAlreadyDamaged_.end()) 136 { 137 //orxout(debug_output) << "Found Pawn to damage: " << it->getWorldPosition() << endl; 138 float damage = FORCE_FIELD_EXPLOSION_DAMMAGE*(1-distanceVector.length()/EXPLOSION_RADIUS); 139 //orxout(debug_output) << "Damage: " << damage << endl; 140 it->hit(shooter_, it->getWorldPosition(), NULL, damage, 0,0); 141 victimsAlreadyDamaged_.push_back(*it); 142 } 143 } 144 } 145 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 146 forceSphereRadius_ = EXPLOSION_RADIUS*(1-lifetime_/EXPLOSION_DURATION); 147 explosionCross_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS); 148 } 149 else if (lifetime_ > -6) //The field has to exist for 6 more seconds for the particles of the particle effect to vanish smoothly. 150 { 151 //Make the bomb model invisible, let the strength of the field be zero and remove all particle emitters so the particle effect will slowly vanish. 152 bombModel_->setVisible(false); 153 this->setRadarVisibility(false); 154 forceStrength_ = 0; 155 forceSphereRadius_ = 0.00001; 156 particleSphere_->getParticleInterface()->removeAllEmitters(); 157 explosionCross_->getParticleInterface()->removeAllEmitters(); 158 } 159 160 setDiameter(forceSphereRadius_*2); 161 setVelocity(forceStrength_); 162 if(lifetime_>0) particleSphere_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS); 163 bombModel_->setScale(modelScaling_); 164 164 165 166 167 168 169 170 165 if (lifetime_ <= -4) 166 { 167 orxout(debug_output) << "Timeout. Destroying field." << endl; 168 this->destroy(); 169 } 170 } 171 171 172 173 174 175 172 void GravityBombField::destroy() 173 { 174 ForceField::destroy(); 175 } 176 176 177 177 } -
code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.h
r10455 r10601 27 27 28 28 /** 29 * @class 29 * @class GravityBombField 30 30 * 31 * @brief 32 * 31 * @brief This class is used by GravityBomb to place the ForceField and Visual effect to the environment. 32 * The field has a maximum lifetime and gets smaller and stronger the more time passes. In the end, the field explodes and damages all pawns nearby. 33 33 * 34 * @author 35 * @date 34 * @author Manuel Eggimann 35 * @date 23.05.2015 36 36 */ 37 37 class GravityBombField: public ForceField, public RadarViewable { 38 38 public: 39 40 41 42 39 GravityBombField(Context* context); 40 virtual ~GravityBombField(); 41 virtual void tick(float dt); 42 virtual void destroy(); 43 43 44 45 * @fnvoid GravityBombField::setShooter(Pawn* shooter)46 47 * @briefThis function is used to determine save the pawn who created the field and is used inside the GravityBomb class.48 49 * @authorManuel Eggimann50 * @date23.05.201551 52 * @param [in,out]the Pawn that created the field.53 54 55 44 /** 45 * @fn void GravityBombField::setShooter(Pawn* shooter) 46 * 47 * @brief This function is used to determine save the pawn who created the field and is used inside the GravityBomb class. 48 * 49 * @author Manuel Eggimann 50 * @date 23.05.2015 51 * 52 * @param [in,out] the Pawn that created the field. 53 */ 54 void setShooter(Pawn* shooter) 55 { this->shooter_ = shooter; } 56 56 57 58 57 Pawn* getShooter() 58 { return this->shooter_; } 59 59 60 60 private: 61 62 63 static const float FORCE_FIELD_LIFETIME;///< The lifetime of the ForceField in seconds. After lifetime seconds, has already exploded and the particle effects will start to vanish.64 65 66 67 68 static const float EXPLOSION_RADIUS;///< How far does the shockwave reach. All pawns which outside of a sphere witch this radius rest unharmed by the explosion.69 70 static const float PEAK_EXPLOSION_FORCE;///< The peak force the explosion exerts on the pawns nearby.71 61 //Set these constants inside GravityBombField.cc to alter the behaviour of the field. 62 63 static const float FORCE_FIELD_LIFETIME; ///< The lifetime of the ForceField in seconds. After lifetime seconds, has already exploded and the particle effects will start to vanish. 64 static const float FORCE_SPHERE_START_RADIUS; ///< The initial sphere radius of the Force Field. The forcefield gets smaller by time. 65 static const float FORCE_SPHERE_START_STRENGTH; ///< The initial Force the Field exerts on every object with non-zero mass. 66 static const float FORCE_FIELD_EXPLOSION_DAMMAGE; ///< The maximum dammage a pawn gets nearby an exploding field. The farer away from explosion center the smaller the dammage. 67 static const float EXPLOSION_DURATION; ///< Determines how fast the shockwave of the Explosion expands. It takes GravityBombField::EXPLOSION_DURATION seconds for the field to expand from 0 radius to GravityBombField::EXPLOSION_RADIUS. 68 static const float EXPLOSION_RADIUS; ///< How far does the shockwave reach. All pawns which outside of a sphere witch this radius rest unharmed by the explosion. 69 static const float PEAK_ANGULAR_VELOCITY; ///< The model of the bomb in the center of the Field does rotate faster and faster as time passes until it reaches PEAK_ANGULAR_VELOCITY at the fields end of life. 70 static const float PEAK_EXPLOSION_FORCE; ///< The peak force the explosion exerts on the pawns nearby. 71 static const float CENTRE_MODEL_END_SIZE; ///< Size of the 3d-model of the bomb in the fields centre. 72 72 73 74 75 76 77 78 79 80 81 82 83 84 85 73 float forceSphereRadius_; 74 float forceStrength_; 75 float lifetime_; 76 float modelScaling_; 77 Vector3 rotationVector_; 78 bool fieldExploded_; 79 ParticleEmitter * particleSphere_; 80 ParticleEmitter * explosionCross_; 81 std::vector<Pawn*> victimsAlreadyDamaged_; 82 MovableEntity * bombModel_; 83 Pawn* shooter_; 84 Backlight* centreLight_; 85 WorldSound* explosionSound_; 86 86 }; 87 87 -
code/branches/weaponFS15/src/modules/weapons/weaponmodes/GravityBombFire.cc
r10503 r10601 17 17 namespace orxonox 18 18 { 19 19 RegisterClass(GravityBombFire); 20 20 21 21 const float GravityBombFire::BOMB_VELOCITY = 600.0; ///< The velocity of the bomb after launch 22 22 23 24 25 23 GravityBombFire::GravityBombFire(Context* context) : WeaponMode(context) 24 { 25 RegisterObject(GravityBombFire); 26 26 27 28 29 27 this->reloadTime_ = 0.50f; 28 this->bParallelReload_ = false; 29 this->damage_ = 20.0f; ///< The damage of the Bomb if it hits a pawn. 30 30 31 32 this->setDefaultSoundWithVolume("sounds/Rocket_launch.ogg",0.8);///< sets sound of the bomb as it is fired.33 31 this->setMunitionName("GravityBombMunition"); 32 this->setDefaultSoundWithVolume("sounds/Rocket_launch.ogg",0.8); ///< sets sound of the bomb as it is fired. 33 } 34 34 35 35 GravityBombFire::~GravityBombFire(){}; 36 36 37 38 39 37 void GravityBombFire::fire() 38 { 39 GravityBomb* bomb = new GravityBomb(this->getContext()); 40 40 //Create a new Bomb in 3D-Space and set the right direction speed and orientation. 41 41 this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition()); 42 42 bomb->setOrientation(this->getMuzzleOrientation()); 43 43 bomb->setPosition(this->getMuzzlePosition()); 44 44 bomb->setVelocity(this->getMuzzleDirection() * (this->BOMB_VELOCITY+this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getVelocity().length())); 45 45 46 46 //Set the shooter of the bomb so it is possible to determine the pawn that killed another one and define damage to shield and healt the bomb does. 47 47 bomb->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); 48 49 50 51 48 bomb->setDamage(this->getDamage()); 49 bomb->setShieldDamage(this->getShieldDamage()); 50 bomb->setHealthDamage(this->getHealthDamage()); 51 } 52 52 53 53
Note: See TracChangeset
for help on using the changeset viewer.