- Timestamp:
- Aug 22, 2011, 3:05:26 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.