[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: |
---|
| 25 | * ... |
---|
| 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 | */ |
---|
| 54 | Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator) |
---|
| 55 | { |
---|
| 56 | RegisterObject(Rocket);// - register the Rocket class to the core |
---|
| 57 | |
---|
[6120] | 58 | this->localAngularVelocity_ = 0; |
---|
[6315] | 59 | this->bDestroy_ = false; |
---|
| 60 | this->lifetime_ = 100; |
---|
[8701] | 61 | this->bIsRocket=true; |
---|
[6387] | 62 | |
---|
[6119] | 63 | if (GameMode::isMaster()) |
---|
| 64 | { |
---|
| 65 | this->setCollisionType(WorldEntity::Kinematic); |
---|
| 66 | this->setVelocity(0,0,-100); |
---|
[6387] | 67 | |
---|
[6167] | 68 | Model* model = new Model(this); |
---|
| 69 | model->setMeshSource("rocket.mesh"); |
---|
[6502] | 70 | model->scale(0.7f); |
---|
[6167] | 71 | this->attach(model); |
---|
| 72 | ParticleEmitter* fire = new ParticleEmitter(this); |
---|
[6119] | 73 | this->attach(fire); |
---|
| 74 | fire->setOrientation(this->getOrientation()); |
---|
| 75 | fire->setSource("Orxonox/rocketfire"); |
---|
[6387] | 76 | |
---|
[6119] | 77 | this->enableCollisionCallback(); |
---|
| 78 | this->setCollisionResponse(false); |
---|
| 79 | this->setCollisionType(Kinematic); |
---|
| 80 | |
---|
[6167] | 81 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
| 82 | collisionShape->setRadius(3); |
---|
| 83 | collisionShape->setHeight(500); |
---|
| 84 | this->attachCollisionShape(collisionShape); |
---|
[6119] | 85 | |
---|
| 86 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); |
---|
[6387] | 87 | |
---|
[6313] | 88 | this->defSndWpnEngine_ = new WorldSound(this); |
---|
| 89 | this->defSndWpnEngine_->setLooping(true); |
---|
| 90 | this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg"); |
---|
[7163] | 91 | this->defSndWpnEngine_->setVolume(100); |
---|
[6313] | 92 | this->attach(defSndWpnEngine_); |
---|
[6285] | 93 | |
---|
[6313] | 94 | this->defSndWpnLaunch_ = new WorldSound(this); |
---|
| 95 | this->defSndWpnLaunch_->setLooping(false); |
---|
| 96 | this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg"); |
---|
[7163] | 97 | this->defSndWpnLaunch_->setVolume(100); |
---|
[6313] | 98 | this->attach(defSndWpnLaunch_); |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | this->defSndWpnEngine_ = 0; |
---|
| 103 | this->defSndWpnLaunch_ = 0; |
---|
| 104 | } |
---|
[6387] | 105 | |
---|
[6315] | 106 | CameraPosition* camPosition = new CameraPosition(this); |
---|
| 107 | camPosition->setPosition(0,4,15); |
---|
| 108 | camPosition->setAllowMouseLook(true); |
---|
| 109 | this->addCameraPosition(camPosition); |
---|
[6119] | 110 | } |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | @brief |
---|
[6247] | 114 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
[6119] | 115 | */ |
---|
| 116 | Rocket::~Rocket() |
---|
| 117 | { |
---|
[8701] | 118 | this->bIsRocket=false; |
---|
[6119] | 119 | if(this->isInitialized()) |
---|
| 120 | { |
---|
[7163] | 121 | if (GameMode::isMaster()) |
---|
| 122 | { |
---|
| 123 | this->destructionEffect(); |
---|
[6383] | 124 | |
---|
[7163] | 125 | if (this->getPlayer() && this->getController()) |
---|
| 126 | this->player_->stopTemporaryControl(); |
---|
| 127 | } |
---|
| 128 | |
---|
[6315] | 129 | if ( this->defSndWpnEngine_ ) |
---|
[6381] | 130 | this->defSndWpnEngine_->destroy(); |
---|
[6383] | 131 | |
---|
[6315] | 132 | if ( this->defSndWpnLaunch_ ) |
---|
[6381] | 133 | this->defSndWpnLaunch_->destroy(); |
---|
[6119] | 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | @brief |
---|
| 139 | Method for creating a Rocket through XML. |
---|
| 140 | */ |
---|
| 141 | void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 142 | { |
---|
| 143 | // this calls the XMLPort function of the parent class |
---|
| 144 | SUPER(Rocket, XMLPort, xmlelement, mode); |
---|
| 145 | } |
---|
[6387] | 146 | |
---|
[6119] | 147 | void Rocket::setOwner(Pawn* owner) |
---|
| 148 | { |
---|
| 149 | this->owner_ = owner; |
---|
| 150 | this->player_ = this->owner_->getPlayer(); |
---|
| 151 | this->owner_->getPlayer()->startTemporaryControl(this); |
---|
[6247] | 152 | |
---|
[6315] | 153 | if( GameMode::isMaster() ) |
---|
| 154 | { |
---|
| 155 | this->defSndWpnEngine_->play(); |
---|
| 156 | this->defSndWpnLaunch_->play(); |
---|
| 157 | } |
---|
[6119] | 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | @brief |
---|
| 162 | Defines which actions the Rocket has to take in each tick. |
---|
| 163 | @param dt |
---|
| 164 | The length of the tick. |
---|
| 165 | */ |
---|
| 166 | void Rocket::tick(float dt) |
---|
| 167 | { |
---|
| 168 | SUPER(Rocket, tick, dt); |
---|
[6387] | 169 | |
---|
[6119] | 170 | if( this->hasLocalController() ) |
---|
| 171 | { |
---|
| 172 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
| 173 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
| 174 | this->localAngularVelocity_ = 0; |
---|
[7163] | 175 | } |
---|
[6387] | 176 | |
---|
[7163] | 177 | if( GameMode::isMaster() ) |
---|
| 178 | { |
---|
[6119] | 179 | if( this->bDestroy_ ) |
---|
| 180 | this->destroy(); |
---|
[7163] | 181 | |
---|
[6119] | 182 | } |
---|
| 183 | } |
---|
[6387] | 184 | |
---|
[6119] | 185 | bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 186 | { |
---|
| 187 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
| 188 | { |
---|
| 189 | if (otherObject == this->owner_) |
---|
| 190 | return false; |
---|
[6387] | 191 | |
---|
[6119] | 192 | this->bDestroy_ = true; |
---|
| 193 | |
---|
| 194 | if (this->owner_) |
---|
| 195 | { |
---|
| 196 | { |
---|
| 197 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 198 | effect->setPosition(this->getPosition()); |
---|
| 199 | effect->setOrientation(this->getOrientation()); |
---|
| 200 | effect->setDestroyAfterLife(true); |
---|
| 201 | effect->setSource("Orxonox/explosion4"); |
---|
| 202 | effect->setLifetime(2.0f); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | { |
---|
| 206 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 207 | effect->setPosition(this->getPosition()); |
---|
| 208 | effect->setOrientation(this->getOrientation()); |
---|
| 209 | effect->setDestroyAfterLife(true); |
---|
| 210 | effect->setSource("Orxonox/smoke4"); |
---|
| 211 | effect->setLifetime(3.0f); |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); |
---|
| 216 | if (victim) |
---|
[6540] | 217 | victim->hit(this->owner_, contactPoint, this->damage_); |
---|
[6119] | 218 | // this->destroy(); |
---|
| 219 | } |
---|
| 220 | return false; |
---|
| 221 | } |
---|
[6387] | 222 | |
---|
[6119] | 223 | void Rocket::destroyObject() |
---|
| 224 | { |
---|
| 225 | if (GameMode::isMaster()) |
---|
[6247] | 226 | { |
---|
| 227 | if(this->defSndWpnEngine_->isPlaying()) |
---|
| 228 | { |
---|
| 229 | this->defSndWpnEngine_->stop(); |
---|
| 230 | } |
---|
[6119] | 231 | this->destroy(); |
---|
[6247] | 232 | } |
---|
[6119] | 233 | } |
---|
[6387] | 234 | |
---|
[6119] | 235 | void Rocket::fired(unsigned int firemode) |
---|
| 236 | { |
---|
[7163] | 237 | // if (this->owner_) |
---|
| 238 | // { |
---|
| 239 | this->destroy(); |
---|
| 240 | // } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | void Rocket::destructionEffect() |
---|
| 244 | { |
---|
| 245 | ParticleSpawner *effect1, *effect2; |
---|
| 246 | if( this->owner_ ) |
---|
[6119] | 247 | { |
---|
[7163] | 248 | effect1 = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 249 | effect2 = new ParticleSpawner(this->owner_->getCreator()); |
---|
[6119] | 250 | } |
---|
[7163] | 251 | else |
---|
| 252 | { |
---|
| 253 | effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get())); |
---|
| 254 | effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get())); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | effect1->setPosition(this->getPosition()); |
---|
| 258 | effect1->setOrientation(this->getOrientation()); |
---|
| 259 | effect1->setDestroyAfterLife(true); |
---|
| 260 | effect1->setSource("Orxonox/explosion4"); |
---|
| 261 | effect1->setLifetime(2.0f); |
---|
| 262 | |
---|
| 263 | effect2->setPosition(this->getPosition()); |
---|
| 264 | effect2->setOrientation(this->getOrientation()); |
---|
| 265 | effect2->setDestroyAfterLife(true); |
---|
| 266 | effect2->setSource("Orxonox/smoke4"); |
---|
| 267 | effect2->setLifetime(3.0f); |
---|
[6119] | 268 | } |
---|
| 269 | |
---|
| 270 | /** |
---|
| 271 | @brief |
---|
| 272 | Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 273 | @param value |
---|
| 274 | The vector determining the amount of the angular movement. |
---|
| 275 | */ |
---|
| 276 | void Rocket::rotateYaw(const Vector2& value) |
---|
| 277 | { |
---|
| 278 | ControllableEntity::rotateYaw(value); |
---|
[6387] | 279 | |
---|
[6119] | 280 | if( !this->isInMouseLook() ) |
---|
| 281 | this->localAngularVelocity_.y += value.x; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | @brief |
---|
| 286 | Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 287 | @param value |
---|
| 288 | The vector determining the amount of the angular movement. |
---|
| 289 | */ |
---|
| 290 | void Rocket::rotatePitch(const Vector2& value) |
---|
| 291 | { |
---|
| 292 | ControllableEntity::rotatePitch(value); |
---|
[6387] | 293 | |
---|
[6119] | 294 | if( !this->isInMouseLook() ) |
---|
| 295 | this->localAngularVelocity_.x += value.x; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /** |
---|
| 299 | @brief |
---|
| 300 | Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 301 | @param value |
---|
| 302 | The vector determining the amount of the angular movement. |
---|
| 303 | */ |
---|
| 304 | void Rocket::rotateRoll(const Vector2& value) |
---|
| 305 | { |
---|
| 306 | ControllableEntity::rotateRoll(value); |
---|
[6387] | 307 | |
---|
[6119] | 308 | if( !this->isInMouseLook() ) |
---|
| 309 | this->localAngularVelocity_.z += value.x; |
---|
| 310 | } |
---|
[6387] | 311 | |
---|
[6119] | 312 | } |
---|