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