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