[6119] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Oliver Scheuss |
---|
| 24 | * Co-authors: |
---|
[8706] | 25 | * simonmie |
---|
[6119] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Rocket.h" |
---|
| 30 | |
---|
[6378] | 31 | #include <BulletDynamics/Dynamics/btRigidBody.h> |
---|
| 32 | |
---|
| 33 | #include "core/CoreIncludes.h" |
---|
[6119] | 34 | #include "core/XMLPort.h" |
---|
[6378] | 35 | #include "worldentities/CameraPosition.h" |
---|
[6119] | 36 | #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" |
---|
[6247] | 42 | #include "sound/WorldSound.h" |
---|
[7163] | 43 | #include "Scene.h" |
---|
[6247] | 44 | |
---|
[6119] | 45 | namespace orxonox |
---|
| 46 | { |
---|
[6120] | 47 | CreateFactory(Rocket); |
---|
[6119] | 48 | // create the factory for the Rocket |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | @brief |
---|
| 52 | Constructor. Registers the object and initializes some default values. |
---|
| 53 | */ |
---|
[8706] | 54 | Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator), BasicProjectile() |
---|
[6119] | 55 | { |
---|
| 56 | RegisterObject(Rocket);// - register the Rocket class to the core |
---|
| 57 | |
---|
[6120] | 58 | this->localAngularVelocity_ = 0; |
---|
[6315] | 59 | this->lifetime_ = 100; |
---|
[8733] | 60 | this->bIsRocket_= true; |
---|
[6387] | 61 | |
---|
[6119] | 62 | if (GameMode::isMaster()) |
---|
| 63 | { |
---|
| 64 | this->setCollisionType(WorldEntity::Kinematic); |
---|
| 65 | this->setVelocity(0,0,-100); |
---|
[6387] | 66 | |
---|
[6167] | 67 | Model* model = new Model(this); |
---|
| 68 | model->setMeshSource("rocket.mesh"); |
---|
[6502] | 69 | model->scale(0.7f); |
---|
[6167] | 70 | this->attach(model); |
---|
| 71 | ParticleEmitter* fire = new ParticleEmitter(this); |
---|
[6119] | 72 | this->attach(fire); |
---|
| 73 | fire->setOrientation(this->getOrientation()); |
---|
| 74 | fire->setSource("Orxonox/rocketfire"); |
---|
[6387] | 75 | |
---|
[6119] | 76 | this->enableCollisionCallback(); |
---|
| 77 | this->setCollisionResponse(false); |
---|
| 78 | this->setCollisionType(Kinematic); |
---|
| 79 | |
---|
[6167] | 80 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
| 81 | collisionShape->setRadius(3); |
---|
| 82 | collisionShape->setHeight(500); |
---|
| 83 | this->attachCollisionShape(collisionShape); |
---|
[6119] | 84 | |
---|
| 85 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); |
---|
[6387] | 86 | |
---|
[6313] | 87 | this->defSndWpnEngine_ = new WorldSound(this); |
---|
| 88 | this->defSndWpnEngine_->setLooping(true); |
---|
| 89 | this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg"); |
---|
[7848] | 90 | this->defSndWpnEngine_->setVolume(1.0f); |
---|
[6313] | 91 | this->attach(defSndWpnEngine_); |
---|
[6285] | 92 | |
---|
[6313] | 93 | this->defSndWpnLaunch_ = new WorldSound(this); |
---|
| 94 | this->defSndWpnLaunch_->setLooping(false); |
---|
| 95 | this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg"); |
---|
[7848] | 96 | this->defSndWpnLaunch_->setVolume(1.0f); |
---|
[6313] | 97 | this->attach(defSndWpnLaunch_); |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | this->defSndWpnEngine_ = 0; |
---|
| 102 | this->defSndWpnLaunch_ = 0; |
---|
| 103 | } |
---|
[6387] | 104 | |
---|
[6315] | 105 | CameraPosition* camPosition = new CameraPosition(this); |
---|
| 106 | camPosition->setPosition(0,4,15); |
---|
| 107 | camPosition->setAllowMouseLook(true); |
---|
| 108 | this->addCameraPosition(camPosition); |
---|
[6119] | 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | @brief |
---|
[6247] | 113 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
[6119] | 114 | */ |
---|
| 115 | Rocket::~Rocket() |
---|
| 116 | { |
---|
| 117 | if(this->isInitialized()) |
---|
| 118 | { |
---|
[8733] | 119 | this->bIsRocket_= false; |
---|
[7163] | 120 | if (GameMode::isMaster()) |
---|
| 121 | { |
---|
| 122 | this->destructionEffect(); |
---|
[6383] | 123 | |
---|
[7163] | 124 | if (this->getPlayer() && this->getController()) |
---|
| 125 | this->player_->stopTemporaryControl(); |
---|
| 126 | } |
---|
| 127 | |
---|
[6315] | 128 | if ( this->defSndWpnEngine_ ) |
---|
[6381] | 129 | this->defSndWpnEngine_->destroy(); |
---|
[6383] | 130 | |
---|
[6315] | 131 | if ( this->defSndWpnLaunch_ ) |
---|
[6381] | 132 | this->defSndWpnLaunch_->destroy(); |
---|
[6119] | 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | @brief |
---|
| 138 | Method for creating a Rocket through XML. |
---|
| 139 | */ |
---|
| 140 | void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 141 | { |
---|
| 142 | // this calls the XMLPort function of the parent class |
---|
| 143 | SUPER(Rocket, XMLPort, xmlelement, mode); |
---|
| 144 | } |
---|
[6387] | 145 | |
---|
[6119] | 146 | void Rocket::setOwner(Pawn* owner) |
---|
| 147 | { |
---|
| 148 | this->owner_ = owner; |
---|
[8706] | 149 | this->player_ = this->getOwner()->getPlayer(); |
---|
| 150 | this->getOwner()->getPlayer()->startTemporaryControl(this); |
---|
[6247] | 151 | |
---|
[6315] | 152 | if( GameMode::isMaster() ) |
---|
| 153 | { |
---|
| 154 | this->defSndWpnEngine_->play(); |
---|
| 155 | this->defSndWpnLaunch_->play(); |
---|
| 156 | } |
---|
[6119] | 157 | } |
---|
| 158 | |
---|
| 159 | /** |
---|
| 160 | @brief |
---|
| 161 | Defines which actions the Rocket has to take in each tick. |
---|
| 162 | @param dt |
---|
| 163 | The length of the tick. |
---|
| 164 | */ |
---|
| 165 | void Rocket::tick(float dt) |
---|
| 166 | { |
---|
| 167 | SUPER(Rocket, tick, dt); |
---|
[6387] | 168 | |
---|
[6119] | 169 | if( this->hasLocalController() ) |
---|
| 170 | { |
---|
| 171 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
| 172 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
| 173 | this->localAngularVelocity_ = 0; |
---|
[7163] | 174 | } |
---|
[6387] | 175 | |
---|
[7163] | 176 | if( GameMode::isMaster() ) |
---|
| 177 | { |
---|
[8706] | 178 | if( this->getBDestroy() ) |
---|
[6119] | 179 | this->destroy(); |
---|
[7163] | 180 | |
---|
[6119] | 181 | } |
---|
| 182 | } |
---|
[6387] | 183 | |
---|
[8706] | 184 | /* Calls the collidesAgainst function of BasicProjectile |
---|
| 185 | */ |
---|
[6119] | 186 | bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 187 | { |
---|
[8706] | 188 | return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); |
---|
[6119] | 189 | } |
---|
[6387] | 190 | |
---|
[6119] | 191 | void Rocket::destroyObject() |
---|
| 192 | { |
---|
| 193 | if (GameMode::isMaster()) |
---|
[6247] | 194 | { |
---|
| 195 | if(this->defSndWpnEngine_->isPlaying()) |
---|
| 196 | { |
---|
| 197 | this->defSndWpnEngine_->stop(); |
---|
| 198 | } |
---|
[6119] | 199 | this->destroy(); |
---|
[6247] | 200 | } |
---|
[6119] | 201 | } |
---|
[6387] | 202 | |
---|
[6119] | 203 | void Rocket::fired(unsigned int firemode) |
---|
| 204 | { |
---|
[8706] | 205 | this->destroy(); |
---|
[7163] | 206 | } |
---|
[7848] | 207 | |
---|
[7163] | 208 | void Rocket::destructionEffect() |
---|
| 209 | { |
---|
| 210 | ParticleSpawner *effect1, *effect2; |
---|
[8706] | 211 | if( this->getOwner() ) |
---|
[6119] | 212 | { |
---|
[8706] | 213 | effect1 = new ParticleSpawner(this->getOwner()->getCreator()); |
---|
| 214 | effect2 = new ParticleSpawner(this->getOwner()->getCreator()); |
---|
[6119] | 215 | } |
---|
[7163] | 216 | else |
---|
| 217 | { |
---|
| 218 | effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get())); |
---|
| 219 | effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get())); |
---|
| 220 | } |
---|
[7848] | 221 | |
---|
[7163] | 222 | effect1->setPosition(this->getPosition()); |
---|
| 223 | effect1->setOrientation(this->getOrientation()); |
---|
| 224 | effect1->setDestroyAfterLife(true); |
---|
| 225 | effect1->setSource("Orxonox/explosion4"); |
---|
| 226 | effect1->setLifetime(2.0f); |
---|
[7848] | 227 | |
---|
[7163] | 228 | effect2->setPosition(this->getPosition()); |
---|
| 229 | effect2->setOrientation(this->getOrientation()); |
---|
| 230 | effect2->setDestroyAfterLife(true); |
---|
| 231 | effect2->setSource("Orxonox/smoke4"); |
---|
| 232 | effect2->setLifetime(3.0f); |
---|
[6119] | 233 | } |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | @brief |
---|
| 237 | Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 238 | @param value |
---|
| 239 | The vector determining the amount of the angular movement. |
---|
| 240 | */ |
---|
| 241 | void Rocket::rotateYaw(const Vector2& value) |
---|
| 242 | { |
---|
| 243 | ControllableEntity::rotateYaw(value); |
---|
[6387] | 244 | |
---|
[6119] | 245 | if( !this->isInMouseLook() ) |
---|
| 246 | this->localAngularVelocity_.y += value.x; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | /** |
---|
| 250 | @brief |
---|
| 251 | Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 252 | @param value |
---|
| 253 | The vector determining the amount of the angular movement. |
---|
| 254 | */ |
---|
| 255 | void Rocket::rotatePitch(const Vector2& value) |
---|
| 256 | { |
---|
| 257 | ControllableEntity::rotatePitch(value); |
---|
[6387] | 258 | |
---|
[6119] | 259 | if( !this->isInMouseLook() ) |
---|
| 260 | this->localAngularVelocity_.x += value.x; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | /** |
---|
| 264 | @brief |
---|
| 265 | Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 266 | @param value |
---|
| 267 | The vector determining the amount of the angular movement. |
---|
| 268 | */ |
---|
| 269 | void Rocket::rotateRoll(const Vector2& value) |
---|
| 270 | { |
---|
| 271 | ControllableEntity::rotateRoll(value); |
---|
[6387] | 272 | |
---|
[6119] | 273 | if( !this->isInMouseLook() ) |
---|
| 274 | this->localAngularVelocity_.z += value.x; |
---|
| 275 | } |
---|
[6387] | 276 | |
---|
[6119] | 277 | } |
---|