Changeset 8855 for code/trunk/src/modules/weapons/projectiles
- Timestamp:
- Aug 22, 2011, 3:05:26 PM (13 years ago)
- Location:
- code/trunk/src/modules/weapons/projectiles
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc
r8767 r8855 27 27 */ 28 28 29 /** 30 @file BasicProjectile.h 31 @brief Implementation of the BasicProjectile class. 32 */ 33 29 34 #include "BasicProjectile.h" 30 35 31 36 #include "core/CoreIncludes.h" 32 #include "core/ConfigValueIncludes.h"33 37 #include "core/GameMode.h" 34 38 #include "core/command/Executor.h" 35 #include "objects/collisionshapes/SphereCollisionShape.h" 36 #include "worldentities/pawns/Pawn.h" 39 37 40 #include "graphics/ParticleSpawner.h" 38 #include "core/OrxonoxClass.h"39 41 40 42 namespace orxonox … … 46 48 BasicProjectile::BasicProjectile() : OrxonoxClass() 47 49 { 48 RegisterRootObject(BasicProjectile);// - register the BasicProjectile class to the core50 RegisterRootObject(BasicProjectile);// Register the BasicProjectile class to the core 49 51 50 52 this->bDestroy_ = false; … … 61 63 } 62 64 63 /* The function called when a projectile hits another thing. 64 * calls the hit-function, starts the reload countdown, displays visual effects 65 * hit is defined in src/orxonox/worldentities/pawns/pawn.cc 66 */ 67 bool BasicProjectile::basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_) 65 /** 66 @brief 67 The function called when a projectile hits another thing. 68 Calls the hit-function, starts the reload countdown, displays visual hit effects defined in Pawn. 69 Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile. 70 @param otherObject 71 A pointer to the object the Projectile has collided against. 72 @param contactPoint 73 A btManifoldPoint indicating the point of contact/impact. 74 @return 75 Returns true if the collision resulted in a successful hit. 76 @see Pawn.h 77 */ 78 bool BasicProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint) 68 79 { 69 if (!this _->getBDestroy()&& GameMode::isMaster())80 if (!this->bDestroy_ && GameMode::isMaster()) 70 81 { 71 if (otherObject == owner) //prevents you from shooting yourself82 if (otherObject == this->getShooter()) // Prevents you from shooting yourself 72 83 return false; 73 84 74 this _->setBDestroy(true); // If something is hit, the object is destroyed and can't hit something else.75 85 this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else. 86 // The projectile is destroyed by its tick()-function (in the following tick). 76 87 77 Pawn* victim = orxonox_cast<Pawn*>(otherObject); // if otherObject isn't a Pawn, then victim is NULL88 Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL 78 89 79 WorldEntity* entity = orxonox_cast<WorldEntity*>(this _);80 assert(entity); // entity must not be null90 WorldEntity* entity = orxonox_cast<WorldEntity*>(this); 91 assert(entity); // The projectile must not be a WorldEntity. 81 92 82 83 // if visual effects after destruction cause problems, put this block below the effects code block 93 // If visual effects after destruction cause problems, put this block below the effects code block 84 94 if (victim) 85 95 { 86 victim->hit( owner, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());96 victim->hit(this->getShooter(), contactPoint, this->getDamage(), this->getHealthDamage(), this->getShieldDamage()); 87 97 victim->startReloadCountdown(); 88 98 } 89 99 90 // visual effects for being hit, depending on whether the shield is hit or not91 if ( owner) //if the owner does not exist (anymore?), no effects are displayed.100 // Visual effects for being hit, depending on whether the shield is hit or not 101 if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed. 92 102 { 93 // damping and explosion effect is only played if the victim is no pawn (see cast above)94 // or if the victim is a pawn, has no shield left, is still alive and any damage goes to the health95 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0 && (this_->getDamage() > 0 || this_->getHealthDamage() > 0)))103 // Damping and explosion effect is only played if the victim is no Pawn (see cast above) 104 // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health 105 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f))) 96 106 { 97 107 { 98 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());108 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 99 109 effect->setPosition(entity->getPosition()); 100 110 effect->setOrientation(entity->getOrientation()); … … 103 113 effect->setLifetime(2.0f); 104 114 } 105 // second effect with same condition115 // Second effect with same condition 106 116 { 107 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());117 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 108 118 effect->setPosition(entity->getPosition()); 109 119 effect->setOrientation(entity->getOrientation()); … … 115 125 116 126 // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead 117 if (victim && victim->hasShield() && (this _->getDamage() > 0 || this_->getShieldDamage() > 0) && victim->getHealth() > 0)127 if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f) 118 128 { 119 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());129 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 120 130 effect->setDestroyAfterLife(true); 121 131 effect->setSource("Orxonox/Shield"); … … 124 134 } 125 135 } 126 136 return true; 127 137 } 128 138 return false; 129 139 } 140 141 /** 142 @brief 143 Check whether the projectile needs to be destroyed and destroys it if so. 144 Needs to be called in the tick() by every Class directly inheriting from BasicProjectile, to make sure the projectile is destroyed after it has hit something. 145 */ 146 void BasicProjectile::destroyCheck(void) 147 { 148 if(GameMode::isMaster() && this->bDestroy_) 149 this->destroy(); 150 } 151 152 /** 153 @brief 154 Destroys the object. 155 */ 156 void BasicProjectile::destroyObject(void) 157 { 158 if(GameMode::isMaster()) 159 this->destroy(); 160 } 130 161 } -
code/trunk/src/modules/weapons/projectiles/BasicProjectile.h
r8706 r8855 27 27 */ 28 28 29 /** 30 @file BasicProjectile.h 31 @brief Definition of the BasicProjectile class. 32 */ 33 29 34 #ifndef _BasicProjectile_H__ 30 35 #define _BasicProjectile_H__ … … 32 37 #include "weapons/WeaponsPrereqs.h" 33 38 34 #include "tools/Timer.h" 39 #include "worldentities/pawns/Pawn.h" 40 35 41 #include "core/OrxonoxClass.h" 36 42 37 43 namespace orxonox 38 44 { 45 46 /** 47 @brief 48 Baseclass of all projectiles. Defines the damage the projectile does. 49 50 @author 51 Simon Miescher 52 @ingroup WeaponsProjectiles 53 */ 39 54 class _WeaponsExport BasicProjectile : public virtual OrxonoxClass 40 55 { 41 56 public: 42 57 BasicProjectile(); 43 44 58 virtual ~BasicProjectile(); 45 59 46 static bool basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_); 47 48 void basicDestroyObject(); 49 60 /** 61 @brief Set the normal damage done by this projectile. 62 Normal damage can be (partially) absorbed by shields. 63 @param damage The amount of damage. Must be non-negative. 64 */ 50 65 inline void setDamage(float damage) 51 { this->damage_ = damage; } 66 { if(damage >= 0.0f) { this->damage_ = damage; return; } COUT(1) << "The input projectile damage must be non-negative. Ignoring..." << endl; } 67 /** 68 @brief Get the normal damage done by this projectile. 69 Normal damage can be (partially) absorbed by shields. 70 @return Returns the amount of damage. Is non-negative. 71 */ 52 72 inline float getDamage() const 53 73 { return this->damage_; } 54 74 75 /** 76 @brief Set the health-damage done by this projectile. 77 Health-damage cannot be absorbed by shields. 78 @param healthdamage The amount of damage. Must be non-negative. 79 */ 55 80 inline void setHealthDamage(float healthdamage) 56 { this->healthdamage_ = healthdamage; } 81 { if(healthdamage >= 0.0f) { this->healthdamage_ = healthdamage; return; } COUT(1) << "The input projectile health-damage must be non-negative. Ignoring..." << endl; } 82 /** 83 @brief Get the health-damage done by this projectile. 84 Health-damage cannot be absorbed by shields. 85 @return healthdamage The amount of damage. Is non-negative. 86 */ 57 87 inline float getHealthDamage() const 58 88 { return this->healthdamage_; } 59 89 90 /** 91 @brief Set the shield-damage done by this projectile. 92 Shield-damage only reduces shield health. 93 @param shielddamage The amount of damage. Must be non-negative. 94 */ 60 95 inline void setShieldDamage(float shielddamage) 61 { this->shielddamage_ = shielddamage; } //ShieldDamage wird korrekt gesettet vom XML-File 96 { if(shielddamage >= 0.0f) { this->shielddamage_ = shielddamage; return; } COUT(1) << "The input projectile shield-damage must be non-negative. Ignoring..." << endl; } 97 /** 98 @brief Get the shield-damage done by this projectile. 99 Shield-damage only reduces shield health. 100 @param shielddamage The amount of damage. Is non-negative. 101 */ 62 102 inline float getShieldDamage() const 63 103 { return this->shielddamage_; } 64 104 105 /** 106 @brief Set the entity that fired the projectile. 107 @param shooter A pointer to the Pawn that fired the projectile. 108 */ 109 virtual void setShooter(Pawn* shooter) 110 { this->shooter_ = shooter; } 111 /** 112 @brief Get the entity that fired the projectile. 113 @return Returns a pointer to the Pawn that fired the projectile. 114 */ 115 inline Pawn* getShooter(void) 116 { return this->shooter_; } 65 117 66 inline void setBDestroy(bool bDestroy) 67 { this->bDestroy_ = bDestroy; } 68 inline float getBDestroy() const 69 { return this->bDestroy_; } 118 virtual void destroyObject(void); 70 119 120 protected: 121 bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint); 122 void destroyCheck(void); 71 123 72 124 private: 73 // WeakPtr<Pawn> owner_; //owner cannot be set in BasicProjectile, because it's already defined in MobileEntity and Movable Entity 125 WeakPtr<Pawn> shooter_; //!< The entity that fired the projectile. 74 126 75 float damage_; 76 float healthdamage_; 77 float shielddamage_; 127 float damage_; //!< The amount of normal damage. Normal damage can be (partially) absorbed by shields. 128 float healthdamage_; //!< The amount of health-damage. Health-damage cannot be absorbed by shields. 129 float shielddamage_; //!< The amount of shield-damage. Shield-damage only reduces shield health. 78 130 79 bool bDestroy_; 131 bool bDestroy_; //!< Boolean, to check whether a projectile should be destroyed. 80 132 }; 81 133 } -
code/trunk/src/modules/weapons/projectiles/BillboardProjectile.cc
r6502 r8855 27 27 */ 28 28 29 /** 30 @file BillboardProjectile.h 31 @brief Implementation of the BillboardProjectile class. 32 */ 33 29 34 #include "BillboardProjectile.h" 30 35 … … 44 49 { 45 50 assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity 51 52 // Create the billboard. 46 53 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5f, 0.5f, 0.7f, 0.8f), 1); 47 54 this->attachOgreObject(this->billboard_.getBillboardSet()); … … 57 64 } 58 65 66 /** 67 @brief 68 Set the colour of the BillboardProjectile. 69 @param colour 70 The colour to be set. 71 */ 59 72 void BillboardProjectile::setColour(const ColourValue& colour) 60 73 { … … 62 75 } 63 76 77 /** 78 @brief 79 Set the material of the BillboardProjectile. 80 @param material 81 The material name. 82 */ 64 83 void BillboardProjectile::setMaterial(const std::string& material) 65 84 { … … 67 86 } 68 87 88 /** 89 @brief 90 Is called when the visibility of the BillboardProjectile has changed. 91 */ 69 92 void BillboardProjectile::changedVisibility() 70 93 { 71 94 SUPER(BillboardProjectile, changedVisibility); 72 95 96 // Also change the visibility of the billboard. 73 97 this->billboard_.setVisible(this->isVisible()); 74 98 } -
code/trunk/src/modules/weapons/projectiles/BillboardProjectile.h
r5781 r8855 27 27 */ 28 28 29 /** 30 @file BillboardProjectile.h 31 @brief Definition of the BillboardProjectile class. 32 */ 33 29 34 #ifndef _BillboardProjectile_H__ 30 35 #define _BillboardProjectile_H__ … … 38 43 namespace orxonox 39 44 { 45 46 /** 47 @brief 48 A BillboardProjectile is a projectile that is represented by a Billboard. 49 50 @author 51 Fabian 'x3n' Landau 52 @ingroup WeaponsProjectiles 53 */ 40 54 class _WeaponsExport BillboardProjectile : public Projectile 41 55 { … … 49 63 50 64 private: 51 BillboardSet billboard_; 65 BillboardSet billboard_; //!< The billboard that represents the projectile. 52 66 }; 53 67 } -
code/trunk/src/modules/weapons/projectiles/CMakeLists.txt
r8706 r8855 1 1 ADD_SOURCE_FILES(WEAPONS_SRC_FILES 2 BasicProjectile.cc 2 3 BillboardProjectile.cc 3 4 ParticleProjectile.cc … … 6 7 Rocket.cc 7 8 SimpleRocket.cc 8 BasicProjectile.cc9 9 ) -
code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc
r8729 r8855 27 27 */ 28 28 29 /** 30 @file LightningGunProjectile.h 31 @brief Implementation of the LightningGunProjectile class. 32 */ 33 29 34 #include "LightningGunProjectile.h" 30 35 31 #include "util/Convert.h"32 36 #include "core/CoreIncludes.h" 33 37 #include "core/command/Executor.h" 38 #include "util/Convert.h" 34 39 35 40 namespace orxonox … … 53 58 } 54 59 60 /** 61 @brief 62 Set the material. 63 @param material 64 The name of the material. Material names with 1 to 8 appended must exist. 65 */ 55 66 void LightningGunProjectile::setMaterial(const std::string& material) 56 67 { … … 60 71 } 61 72 73 /** 74 @brief 75 Change the texture. 76 */ 62 77 void LightningGunProjectile::changeTexture() 63 78 { -
code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.h
r5929 r8855 27 27 */ 28 28 29 /** 30 @file LightningGunProjectile.h 31 @brief Definition of the LightningGunProjectile class. 32 */ 33 29 34 #ifndef _LightningGunProjectile_H__ 30 35 #define _LightningGunProjectile_H__ … … 38 43 namespace orxonox 39 44 { 45 46 /** 47 @brief 48 The LightningGunProjectile is a projectile that is represented by a looped series of billboards. 49 50 @author 51 Joel Smely 52 @ingroup WeaponsProjectiles 53 */ 40 54 class _WeaponsExport LightningGunProjectile : public BillboardProjectile 41 55 { … … 46 60 virtual void setMaterial(const std::string& material); 47 61 48 protected: 62 private: 63 void registerVariables(); 49 64 void changeTexture(); 50 unsigned int textureIndex_; 51 unsigned int maxTextureIndex_; 52 Timer textureTimer_; 53 std::string materialBase_; 54 private: 55 void registerVariables(); 65 66 unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture) 67 unsigned int maxTextureIndex_; //!< The maximal index. 68 Timer textureTimer_; //!< A timer that loops and changes textures each time it expires. 69 std::string materialBase_; //!< The base name of the material. 56 70 }; 57 71 } -
code/trunk/src/modules/weapons/projectiles/ParticleProjectile.cc
r5929 r8855 27 27 */ 28 28 29 /** 30 @file ParticleProjectile.h 31 @brief Implementation of the ParticleProjectile class. 32 */ 33 29 34 #include "ParticleProjectile.h" 30 35 31 36 #include <OgreParticleEmitter.h> 37 #include "core/CoreIncludes.h" 32 38 #include "tools/ParticleInterface.h" 33 #include "core/CoreIncludes.h"34 39 #include "Scene.h" 35 40 … … 44 49 if (GameMode::showsGraphics()) 45 50 { 51 // Create the particles. 46 52 this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::Normal); 47 53 this->attachOgreObject(this->particles_->getParticleSystem()); … … 63 69 } 64 70 71 /** 72 @brief 73 Is called when the visibility of the ParticleProjectile has changed. 74 */ 65 75 void ParticleProjectile::changedVisibility() 66 76 { 67 77 SUPER(ParticleProjectile, changedVisibility); 68 78 79 // Change the visibility of the particles. 69 80 if (this->particles_) 70 81 this->particles_->setEnabled(this->isVisible()); -
code/trunk/src/modules/weapons/projectiles/ParticleProjectile.h
r5781 r8855 27 27 */ 28 28 29 /** 30 @file ParticleProjectile.h 31 @brief Definition of the ParticleProjectile class. 32 */ 33 29 34 #ifndef _ParticleProjectile_H__ 30 35 #define _ParticleProjectile_H__ … … 35 40 namespace orxonox 36 41 { 42 43 /** 44 @brief 45 A projectile that is represented by particles. 46 @author 47 Fabian 'x3n' Landau 48 @ingroup WeaponsProjectiles 49 */ 37 50 class _WeaponsExport ParticleProjectile : public BillboardProjectile 38 51 { … … 43 56 44 57 private: 45 ParticleInterface* particles_; 58 ParticleInterface* particles_; //!< The particles. 46 59 }; 47 60 } -
code/trunk/src/modules/weapons/projectiles/Projectile.cc
r8706 r8855 27 27 */ 28 28 29 /** 30 @file Projectile.h 31 @brief Implementation of the Projectile class. 32 */ 33 29 34 #include "Projectile.h" 30 35 36 #include "core/ConfigValueIncludes.h" 31 37 #include "core/CoreIncludes.h" 32 #include "core/ConfigValueIncludes.h"33 38 #include "core/GameMode.h" 34 39 #include "core/command/Executor.h" 40 35 41 #include "objects/collisionshapes/SphereCollisionShape.h" 36 42 #include "worldentities/pawns/Pawn.h" 37 #include "graphics/ParticleSpawner.h"38 43 39 44 namespace orxonox … … 46 51 47 52 this->setConfigValues(); 48 this->owner_ = 0;49 53 50 54 // Get notification about collisions 51 55 if (GameMode::isMaster()) 52 56 { 53 this->setMass(1.0 );57 this->setMass(1.0f); 54 58 this->enableCollisionCallback(); 55 59 this->setCollisionResponse(false); … … 57 61 58 62 SphereCollisionShape* shape = new SphereCollisionShape(this); 59 shape->setRadius(20 );63 shape->setRadius(20.0f); 60 64 this->attachCollisionShape(shape); 61 65 62 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(& Projectile::destroyObject, this)));66 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); 63 67 } 64 68 } … … 70 74 void Projectile::setConfigValues() 71 75 { 72 SetConfigValue(lifetime_, 4.0 ).description("The time in seconds a projectile stays alive");76 SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive"); 73 77 } 74 78 … … 81 85 return; 82 86 83 if (this->getBDestroy()) 84 this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick() 87 this->destroyCheck(); 85 88 } 86 89 87 void Projectile::destroyObject()90 bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 88 91 { 89 if (GameMode::isMaster()) 90 this->destroy(); 92 return this->processCollision(otherObject, contactPoint); 91 93 } 92 94 93 /* Calls the collidesAgainst function of BasicProjectile94 */95 bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)96 {97 return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);98 }99 100 void Projectile::setOwner(Pawn* owner)101 {102 this->owner_ = owner;103 }104 95 } -
code/trunk/src/modules/weapons/projectiles/Projectile.h
r8706 r8855 27 27 */ 28 28 29 /** 30 @file Projectile.h 31 @brief Definition of the Projectile class. 32 */ 33 29 34 #ifndef _Projectile_H__ 30 35 #define _Projectile_H__ … … 39 44 namespace orxonox 40 45 { 46 47 /** 48 @brief 49 Represents all 'standard' projectiles. 50 51 @author 52 Fabian 'x3n' Landau 53 @author 54 Simon Miescher 55 @ingroup WeaponsProjectiles 56 */ 41 57 class _WeaponsExport Projectile : public MovableEntity, public BasicProjectile 42 58 { … … 46 62 47 63 void setConfigValues(); 48 void destroyObject();49 64 50 65 virtual void tick(float dt); 51 66 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 52 67 53 void setOwner(Pawn* owner);54 inline Pawn* getOwner() const55 { return this->owner_; }56 57 58 68 private: 59 WeakPtr<Pawn> owner_; 60 float lifetime_; 61 Timer destroyTimer_; 69 float lifetime_; //!< The time the projectile exists. 70 Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out. 62 71 }; 63 72 } -
code/trunk/src/modules/weapons/projectiles/Rocket.cc
r8738 r8855 27 27 */ 28 28 29 /** 30 @file Rocket.h 31 @brief Implementation of the Rocket class. 32 */ 33 29 34 #include "Rocket.h" 30 35 … … 33 38 #include "core/CoreIncludes.h" 34 39 #include "core/XMLPort.h" 40 41 #include "Scene.h" 42 #include "controllers/Controller.h" 43 #include "graphics/Model.h" 44 #include "graphics/ParticleSpawner.h" 45 #include "infos/PlayerInfo.h" 46 #include "objects/collisionshapes/ConeCollisionShape.h" 47 #include "sound/WorldSound.h" 35 48 #include "worldentities/CameraPosition.h" 36 49 #include "worldentities/pawns/Pawn.h" 37 #include "graphics/ParticleSpawner.h"38 #include "graphics/Model.h"39 #include "objects/collisionshapes/ConeCollisionShape.h"40 #include "infos/PlayerInfo.h"41 #include "controllers/Controller.h"42 #include "sound/WorldSound.h"43 #include "Scene.h"44 50 45 51 namespace orxonox 46 52 { 47 53 CreateFactory(Rocket); 48 // create the factory for the Rocket49 54 50 55 /** … … 57 62 , RadarViewable(creator, static_cast<WorldEntity*>(this)) 58 63 { 59 RegisterObject(Rocket);// - register the Rocket class to the core64 RegisterObject(Rocket);// Register the Rocket class to the core 60 65 61 66 this->localAngularVelocity_ = 0; 62 this->lifetime_ = 100 ;67 this->lifetime_ = 100.0f; 63 68 64 69 if (GameMode::isMaster()) … … 67 72 this->setVelocity(0,0,-100); 68 73 74 // Create rocket model 69 75 Model* model = new Model(this); 70 76 model->setMeshSource("rocket.mesh"); 71 77 model->scale(0.7f); 72 78 this->attach(model); 79 80 // Add effects. 73 81 ParticleEmitter* fire = new ParticleEmitter(this); 74 82 this->attach(fire); … … 80 88 this->setCollisionType(Kinematic); 81 89 90 // Add collision shape 82 91 ConeCollisionShape* collisionShape = new ConeCollisionShape(this); 83 92 collisionShape->setRadius(3); … … 85 94 this->attachCollisionShape(collisionShape); 86 95 87 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); 88 96 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); 97 98 // Add sound 89 99 this->defSndWpnEngine_ = new WorldSound(this); 90 100 this->defSndWpnEngine_->setLooping(true); … … 105 115 } 106 116 117 // Add camera 107 118 CameraPosition* camPosition = new CameraPosition(this); 108 119 camPosition->setPosition(0,4,15); … … 141 152 /** 142 153 @brief 143 Method for creating a Rocket through XML. 144 */ 145 void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) 146 { 147 // this calls the XMLPort function of the parent class 148 SUPER(Rocket, XMLPort, xmlelement, mode); 149 } 150 151 void Rocket::setOwner(Pawn* owner) 152 { 153 this->owner_ = owner; 154 this->player_ = this->getOwner()->getPlayer(); 155 this->getOwner()->getPlayer()->startTemporaryControl(this); 154 Sets the entity that fired the Rocket. 155 @param shooter 156 A pointer to the Pawn that fired the Rocket. 157 */ 158 void Rocket::setShooter(Pawn* shooter) 159 { 160 this->BasicProjectile::setShooter(shooter); 161 162 this->player_ = this->getShooter()->getPlayer(); 163 this->getShooter()->getPlayer()->startTemporaryControl(this); 156 164 157 165 if( GameMode::isMaster() ) … … 179 187 } 180 188 181 if( GameMode::isMaster() ) 182 { 183 if( this->getBDestroy() ) 184 this->destroy(); 185 186 } 187 } 188 189 /* Calls the collidesAgainst function of BasicProjectile 190 */ 189 this->destroyCheck(); 190 } 191 191 192 bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 192 193 { 193 return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); 194 } 195 196 void Rocket::destroyObject() 197 { 198 if (GameMode::isMaster()) 199 { 200 if(this->defSndWpnEngine_->isPlaying()) 201 { 202 this->defSndWpnEngine_->stop(); 203 } 204 this->destroy(); 205 } 206 } 207 194 return this->processCollision(otherObject, contactPoint); 195 } 196 197 /** 198 @brief 199 Destroys the Rocket and stops the sound, 200 */ 201 void Rocket::destroyObject(void) 202 { 203 if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying()) 204 this->defSndWpnEngine_->stop(); 205 206 this->BasicProjectile::destroyObject(); 207 } 208 209 /** 210 @brief 211 Destroys the Rocket upon pressing "fire". 212 */ 208 213 void Rocket::fired(unsigned int firemode) 209 214 { 210 this->destroy(); 211 } 212 215 this->destroyObject(); 216 } 217 218 /** 219 @brief 220 The effects that are displayed, when the Rocket is destroyed. 221 */ 213 222 void Rocket::destructionEffect() 214 223 { 215 224 ParticleSpawner *effect1, *effect2; 216 if( this->getOwner())217 { 218 effect1 = new ParticleSpawner(this->get Owner()->getCreator());219 effect2 = new ParticleSpawner(this->get Owner()->getCreator());225 if(this->getShooter()) 226 { 227 effect1 = new ParticleSpawner(this->getShooter()->getCreator()); 228 effect2 = new ParticleSpawner(this->getShooter()->getCreator()); 220 229 } 221 230 else -
code/trunk/src/modules/weapons/projectiles/Rocket.h
r8738 r8855 27 27 */ 28 28 29 /** 30 @file Rocket.h 31 @brief Definition of the Rocket class. 32 */ 33 29 34 #ifndef _Rocket_H__ 30 35 #define _Rocket_H__ … … 33 38 34 39 #include "tools/Timer.h" 40 41 #include "interfaces/RadarViewable.h" 35 42 #include "worldentities/ControllableEntity.h" 36 #include "interfaces/RadarViewable.h"37 43 38 44 #include "BasicProjectile.h" … … 44 50 /** 45 51 @brief 46 Rocket , that is made to move upon a specified pattern.47 This class was constructed for the PPS tutorial. 52 Rocket that can be steered by the player. 53 48 54 @author 49 55 Oli Scheuss 56 @ingroup WeaponsProjectiles 50 57 */ 51 58 class _WeaponsExport Rocket : public ControllableEntity, public BasicProjectile, public RadarViewable … … 55 62 virtual ~Rocket(); 56 63 57 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Rocket through XML.58 64 virtual void tick(float dt); //!< Defines which actions the Rocket has to take in each tick. 59 65 60 66 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 61 v oid destroyObject();67 virtual void destroyObject(void); 62 68 void destructionEffect(); 63 69 64 virtual void moveFrontBack(const Vector2& value) {}65 virtual void moveRightLeft(const Vector2& value) {}66 virtual void moveUpDown(const Vector2& value) {}70 virtual void moveFrontBack(const Vector2& value) {} 71 virtual void moveRightLeft(const Vector2& value) {} 72 virtual void moveUpDown(const Vector2& value) {} 67 73 68 74 virtual void rotateYaw(const Vector2& value); … … 75 81 */ 76 82 inline void moveFrontBack(float value) 77 { this->moveFrontBack(Vector2(value, 0)); }83 { this->moveFrontBack(Vector2(value, 0)); } 78 84 /** 79 85 @brief Moves the Rocket in the Right/Left-direction by the specifed amount. … … 81 87 */ 82 88 inline void moveRightLeft(float value) 83 { this->moveRightLeft(Vector2(value, 0)); }89 { this->moveRightLeft(Vector2(value, 0)); } 84 90 /** 85 91 @brief Moves the Rocket in the Up/Down-direction by the specifed amount. … … 87 93 */ 88 94 inline void moveUpDown(float value) 89 { this->moveUpDown(Vector2(value, 0)); }95 { this->moveUpDown(Vector2(value, 0)); } 90 96 91 97 /** … … 94 100 */ 95 101 inline void rotateYaw(float value) 96 { this->rotateYaw(Vector2(value, 0)); }102 { this->rotateYaw(Vector2(value, 0)); } 97 103 /** 98 104 @brief Rotates the Rocket around the x-axis by the specifed amount. … … 100 106 */ 101 107 inline void rotatePitch(float value) 102 { this->rotatePitch(Vector2(value, 0)); }108 { this->rotatePitch(Vector2(value, 0)); } 103 109 /** 104 110 @brief Rotates the Rocket around the z-axis by the specifed amount. … … 106 112 */ 107 113 inline void rotateRoll(float value) 108 { this->rotateRoll(Vector2(value, 0)); }114 { this->rotateRoll(Vector2(value, 0)); } 109 115 110 void setOwner(Pawn* owner); 111 inline Pawn* getOwner() const 112 { return this->owner_; } 116 virtual void setShooter(Pawn* shooter); 113 117 114 118 virtual void fired(unsigned int firemode); 115 119 116 120 private: 117 WeakPtr<Pawn> owner_; 118 Vector3 localAngularVelocity_; 121 Vector3 localAngularVelocity_; //!< Variable to temporarily store accumulated steering command input. 119 122 120 WeakPtr<PlayerInfo> player_; 121 Timer destroyTimer_; 122 float lifetime_; 123 WeakPtr<PlayerInfo> player_; //!< The player that controls the Rocket. 124 Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out. 125 float lifetime_; //!< The time the projectile exists. 123 126 124 WorldSound* defSndWpnEngine_; 125 WorldSound* defSndWpnLaunch_; 127 WorldSound* defSndWpnEngine_; //!< Engine sound. 128 WorldSound* defSndWpnLaunch_; //!< Launch sound. 126 129 }; 127 130 -
code/trunk/src/modules/weapons/projectiles/SimpleRocket.cc
r8738 r8855 21 21 * 22 22 * Author: 23 * Oliver Scheuss23 * Gabriel Nadler 24 24 * Co-authors: 25 25 * simonmie … … 27 27 */ 28 28 29 /** 30 @file SimpleRocket.h 31 @brief Implementation of the SimpleRocket class. 32 */ 33 34 29 35 #include "SimpleRocket.h" 30 36 … … 33 39 #include "core/CoreIncludes.h" 34 40 #include "core/XMLPort.h" 41 #include "util/Debug.h" 42 43 #include "controllers/Controller.h" 44 #include "graphics/Model.h" 45 #include "graphics/ParticleSpawner.h" 46 #include "infos/PlayerInfo.h" 47 #include "objects/collisionshapes/ConeCollisionShape.h" 35 48 #include "worldentities/pawns/Pawn.h" 36 #include "graphics/ParticleSpawner.h" 37 #include "graphics/Model.h" 38 #include "objects/collisionshapes/ConeCollisionShape.h" 39 #include "infos/PlayerInfo.h" 40 #include "controllers/Controller.h" 49 #include "sound/WorldSound.h" 50 41 51 #include "weapons/RocketController.h" 42 #include "sound/WorldSound.h"43 #include "util/Debug.h"44 52 45 53 namespace orxonox … … 53 61 , RadarViewable(creator, static_cast<WorldEntity*>(this)) 54 62 { 55 RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core63 RegisterObject(SimpleRocket);// Register the SimpleRocket class to the core 56 64 57 65 this->localAngularVelocity_ = 0; 58 this->lifetime_ = 10; 59 60 this->setMass(15); 61 // COUT(4) << "simplerocket constructed\n"; 66 this->lifetime_ = 10.f; 67 68 this->setMass(15.0); 62 69 63 70 if (GameMode::isMaster()) 64 71 { 65 72 this->setCollisionType(WorldEntity::Kinematic); 66 this->fuel_=true; 67 73 this->fuel_ = true; 74 75 // Create rocket model. 68 76 Model* model = new Model(this); 69 77 model->setMeshSource("rocket.mesh"); … … 71 79 this->attach(model); 72 80 81 // Add effects. 73 82 this->fire_ = new ParticleEmitter(this); 74 83 this->attach(this->fire_); … … 80 89 this->setCollisionType(Kinematic); 81 90 91 // Add collision shape. 82 92 // TODO: fix the orientation and size of this collision shape to match the rocket 83 93 ConeCollisionShape* collisionShape = new ConeCollisionShape(this); … … 86 96 collisionShape->setHeight(5); 87 97 this->attachCollisionShape(collisionShape); 88 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this))); 98 99 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); 89 100 } 90 101 … … 97 108 98 109 /** 99 * @brief updates state of rocket, disables fire if no fuel 100 * @param dt tick-length 110 @brief 111 Updates state of rocket, disables fire if no fuel 112 @param dt 113 tick-length 101 114 */ 102 115 void SimpleRocket::tick(float dt) 103 116 { 104 105 117 SUPER(SimpleRocket, tick, dt); 106 if ( GameMode::isMaster() ) 118 119 if (GameMode::isMaster()) 107 120 { 108 109 110 121 this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); 111 122 this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); 112 123 this->localAngularVelocity_ = 0; 113 124 114 115 125 if (this->fuel_) 116 126 { 117 if (this->destroyTimer_.getRemainingTime() < (static_cast<float>(this->FUEL_PERCENTAGE)/100)*this->lifetime_ )118 this->fuel_ =false;127 if (this->destroyTimer_.getRemainingTime() < this->FUEL_PERCENTAGE*this->lifetime_ ) 128 this->fuel_ = false; 119 129 } else 120 130 this->disableFire(); 121 122 if( this->getBDestroy() )123 this->destroy();124 131 } 125 132 126 } 127 128 /** 129 * @brief Sets the Acceleration to 0 and detaches the fire 130 * @return void 133 this->destroyCheck(); 134 } 135 136 /** 137 @brief 138 Sets the Acceleration to 0 and detaches the fire. 131 139 */ 132 140 void SimpleRocket::disableFire() … … 136 144 } 137 145 138 /** s146 /** 139 147 @brief 140 148 Destructor. Destroys controller, if present and kills sounds, if playing. … … 153 161 /** 154 162 @brief 155 Method for creating a SimpleRocket through XML. 156 */ 157 void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) 158 { 159 // this calls the XMLPort function of the parent class 160 SUPER(SimpleRocket, XMLPort, xmlelement, mode); 161 } 162 163 void SimpleRocket::setOwner(Pawn* owner) 164 { 165 this->owner_ = owner; 166 this->player_ = this->getOwner()->getPlayer(); 167 } 168 169 170 /* Calls the collidesAgainst function of BasicProjectile 171 */ 163 Set the entity that fired the SimpleRocket. 164 @param shooter 165 A pointer to the Pawn that fired the SimpleRocket. 166 */ 167 void SimpleRocket::setShooter(Pawn* shooter) 168 { 169 BasicProjectile::setShooter(shooter); 170 171 this->player_ = this->getShooter()->getPlayer(); 172 } 173 172 174 bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 173 175 { 174 return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); 175 } 176 177 void SimpleRocket::destroyObject() 178 { 179 if (GameMode::isMaster()) 180 { 181 this->destroy(); 182 } 176 return this->processCollision(otherObject, contactPoint); 183 177 } 184 178 -
code/trunk/src/modules/weapons/projectiles/SimpleRocket.h
r8738 r8855 21 21 * 22 22 * Author: 23 * Oliver Scheuss23 * Gabriel Nadler 24 24 * Co-authors: 25 25 * simonmie 26 26 * 27 27 */ 28 29 /** 30 @file SimpleRocket.h 31 @brief Definition of the SimpleRocket class. 32 */ 28 33 29 34 #ifndef _SimpleRocket_H__ … … 33 38 34 39 #include "tools/Timer.h" 35 #include "worldentities/ControllableEntity.h" 40 36 41 #include "graphics/ParticleSpawner.h" 37 42 #include "interfaces/RadarViewable.h" 43 #include "worldentities/ControllableEntity.h" 38 44 39 45 #include "BasicProjectile.h" … … 45 51 /** 46 52 @brief 47 SimpleRocket, follows direction from a Rocketcontroller, has fuel for 80% of its lifetime, afterwards it's fire disappears. 53 SimpleRocket is a target seeking, intelligent rocket. It follows its target until it either hits something or runs out of fuel. 54 The steering is done by the RocketController. 48 55 @author 49 Gabriel Nadler (Original file: Oli Scheuss) 56 Gabriel Nadler 57 @ingroup WeaponsProjectiles 50 58 */ 51 59 class _WeaponsExport SimpleRocket : public ControllableEntity, public BasicProjectile, public RadarViewable … … 55 63 virtual ~SimpleRocket(); 56 64 virtual void tick(float dt); 57 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a SimpleRocket through XML.58 65 59 66 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 60 void destroyObject();61 67 62 68 void disableFire(); //!< Method to disable the fire and stop all acceleration … … 76 82 */ 77 83 inline void moveFrontBack(float value) 78 { this->moveFrontBack(Vector2(value, 0)); }84 { this->moveFrontBack(Vector2(value, 0)); } 79 85 /** 80 86 @brief Moves the SimpleRocket in the Right/Left-direction by the specifed amount. … … 82 88 */ 83 89 inline void moveRightLeft(float value) 84 { this->moveRightLeft(Vector2(value, 0)); }90 { this->moveRightLeft(Vector2(value, 0)); } 85 91 /** 86 92 @brief Moves the SimpleRocket in the Up/Down-direction by the specifed amount. … … 88 94 */ 89 95 inline void moveUpDown(float value) 90 { this->moveUpDown(Vector2(value, 0)); }96 { this->moveUpDown(Vector2(value, 0)); } 91 97 92 98 /** … … 95 101 */ 96 102 inline void rotateYaw(float value) 97 { this->rotateYaw(Vector2(value, 0)); }103 { this->rotateYaw(Vector2(value, 0)); } 98 104 /** 99 105 @brief Rotates the SimpleRocket around the x-axis by the specifed amount. … … 101 107 */ 102 108 inline void rotatePitch(float value) 103 { 104 this->rotatePitch(Vector2(value, 0)); } 109 { this->rotatePitch(Vector2(value, 0)); } 105 110 /** 106 111 @brief Rotates the SimpleRocket around the z-axis by the specifed amount. … … 108 113 */ 109 114 inline void rotateRoll(float value) 110 { 111 this->rotateRoll(Vector2(value, 0)); } 115 { this->rotateRoll(Vector2(value, 0)); } 112 116 113 void setOwner(Pawn* owner); 114 inline Pawn* getOwner() const 115 { return this->owner_; } 117 virtual void setShooter(Pawn* shooter); 116 118 117 119 inline bool hasFuel() const 118 { return this->fuel_; }120 { return this->fuel_; } 119 121 120 122 121 123 private: 122 WeakPtr<Pawn> owner_; 123 Vector3 localAngularVelocity_; 124 static const float FUEL_PERCENTAGE = 0.8f; //!< Percentage of lifetime the rocket has fuel 125 126 Vector3 localAngularVelocity_; //!< Variable to temporarily store accumulated steering command input. 124 127 bool fuel_; //!< Bool is true while the rocket "has fuel" 125 128 126 127 WeakPtr<PlayerInfo> player_; 128 Timer destroyTimer_; 129 float lifetime_; 130 static const int FUEL_PERCENTAGE=80; //!<Percentage of Lifetime the rocket has fuel 129 WeakPtr<PlayerInfo> player_; //!< The player the SimpleRocket belongs to. 130 Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out. 131 float lifetime_; //!< The time the projectile exists. 131 132 132 133 ParticleEmitter* fire_; //!< Fire-Emittor 133 134 135 136 134 }; 137 135
Note: See TracChangeset
for help on using the changeset viewer.