[7129] | 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: |
---|
[8855] | 23 | * Gabriel Nadler |
---|
[7129] | 24 | * Co-authors: |
---|
[8706] | 25 | * simonmie |
---|
[7129] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[8855] | 29 | /** |
---|
| 30 | @file SimpleRocket.h |
---|
| 31 | @brief Implementation of the SimpleRocket class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | |
---|
[7129] | 35 | #include "SimpleRocket.h" |
---|
| 36 | |
---|
| 37 | #include <BulletDynamics/Dynamics/btRigidBody.h> |
---|
| 38 | |
---|
| 39 | #include "core/CoreIncludes.h" |
---|
| 40 | #include "core/XMLPort.h" |
---|
[8855] | 41 | |
---|
| 42 | #include "controllers/Controller.h" |
---|
| 43 | #include "graphics/Model.h" |
---|
[7129] | 44 | #include "graphics/ParticleSpawner.h" |
---|
[8855] | 45 | #include "infos/PlayerInfo.h" |
---|
[7129] | 46 | #include "objects/collisionshapes/ConeCollisionShape.h" |
---|
[8855] | 47 | #include "worldentities/pawns/Pawn.h" |
---|
[7129] | 48 | #include "sound/WorldSound.h" |
---|
| 49 | |
---|
[8855] | 50 | #include "weapons/RocketController.h" |
---|
| 51 | |
---|
[7129] | 52 | namespace orxonox |
---|
| 53 | { |
---|
| 54 | |
---|
| 55 | CreateFactory(SimpleRocket); |
---|
| 56 | |
---|
[8738] | 57 | SimpleRocket::SimpleRocket(BaseObject* creator) |
---|
| 58 | : ControllableEntity(creator) |
---|
| 59 | , BasicProjectile() |
---|
| 60 | , RadarViewable(creator, static_cast<WorldEntity*>(this)) |
---|
[7129] | 61 | { |
---|
[8855] | 62 | RegisterObject(SimpleRocket);// Register the SimpleRocket class to the core |
---|
[7129] | 63 | |
---|
| 64 | this->localAngularVelocity_ = 0; |
---|
[8855] | 65 | this->lifetime_ = 10.f; |
---|
[7129] | 66 | |
---|
[8855] | 67 | this->setMass(15.0); |
---|
[7129] | 68 | |
---|
| 69 | if (GameMode::isMaster()) |
---|
| 70 | { |
---|
| 71 | this->setCollisionType(WorldEntity::Kinematic); |
---|
[8855] | 72 | this->fuel_ = true; |
---|
[7129] | 73 | |
---|
[8855] | 74 | // Create rocket model. |
---|
[7129] | 75 | Model* model = new Model(this); |
---|
| 76 | model->setMeshSource("rocket.mesh"); |
---|
| 77 | model->scale(0.7f); |
---|
| 78 | this->attach(model); |
---|
| 79 | |
---|
[8855] | 80 | // Add effects. |
---|
[7129] | 81 | this->fire_ = new ParticleEmitter(this); |
---|
| 82 | this->attach(this->fire_); |
---|
| 83 | |
---|
| 84 | this->fire_->setOrientation(this->getOrientation()); |
---|
| 85 | this->fire_->setSource("Orxonox/simplerocketfire"); |
---|
| 86 | this->enableCollisionCallback(); |
---|
| 87 | this->setCollisionResponse(false); |
---|
| 88 | this->setCollisionType(Kinematic); |
---|
| 89 | |
---|
[8855] | 90 | // Add collision shape. |
---|
[7129] | 91 | // TODO: fix the orientation and size of this collision shape to match the rocket |
---|
| 92 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
| 93 | collisionShape->setOrientation(this->getOrientation()); |
---|
| 94 | collisionShape->setRadius(1.5f); |
---|
| 95 | collisionShape->setHeight(5); |
---|
| 96 | this->attachCollisionShape(collisionShape); |
---|
[8855] | 97 | |
---|
| 98 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); |
---|
[7129] | 99 | } |
---|
| 100 | |
---|
[8738] | 101 | this->setRadarObjectColour(ColourValue(1.0, 1.0, 0.0)); // yellow |
---|
| 102 | this->setRadarObjectShape(RadarViewable::Triangle); |
---|
| 103 | this->setRadarObjectScale(0.5f); |
---|
[7129] | 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /** |
---|
[8855] | 109 | @brief |
---|
| 110 | Updates state of rocket, disables fire if no fuel |
---|
| 111 | @param dt |
---|
| 112 | tick-length |
---|
[7129] | 113 | */ |
---|
| 114 | void SimpleRocket::tick(float dt) |
---|
| 115 | { |
---|
| 116 | SUPER(SimpleRocket, tick, dt); |
---|
[8855] | 117 | |
---|
| 118 | if (GameMode::isMaster()) |
---|
[7129] | 119 | { |
---|
| 120 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
| 121 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
| 122 | this->localAngularVelocity_ = 0; |
---|
| 123 | |
---|
| 124 | if (this->fuel_) |
---|
| 125 | { |
---|
[8855] | 126 | if (this->destroyTimer_.getRemainingTime() < this->FUEL_PERCENTAGE*this->lifetime_ ) |
---|
| 127 | this->fuel_ = false; |
---|
[7129] | 128 | } else |
---|
| 129 | this->disableFire(); |
---|
| 130 | } |
---|
| 131 | |
---|
[8855] | 132 | this->destroyCheck(); |
---|
[7129] | 133 | } |
---|
| 134 | |
---|
| 135 | /** |
---|
[8855] | 136 | @brief |
---|
| 137 | Sets the Acceleration to 0 and detaches the fire. |
---|
[7129] | 138 | */ |
---|
| 139 | void SimpleRocket::disableFire() |
---|
| 140 | { |
---|
| 141 | this->setAcceleration(0,0,0); |
---|
| 142 | this->fire_->detachFromParent(); |
---|
| 143 | } |
---|
| 144 | |
---|
[8855] | 145 | /** |
---|
[7129] | 146 | @brief |
---|
| 147 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
| 148 | */ |
---|
| 149 | SimpleRocket::~SimpleRocket() |
---|
| 150 | { |
---|
| 151 | if (this->isInitialized()) |
---|
| 152 | { |
---|
| 153 | if( GameMode::isMaster() ) |
---|
| 154 | { |
---|
| 155 | this->getController()->destroy(); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | @brief |
---|
[8855] | 162 | Set the entity that fired the SimpleRocket. |
---|
| 163 | @param shooter |
---|
| 164 | A pointer to the Pawn that fired the SimpleRocket. |
---|
[7129] | 165 | */ |
---|
[8855] | 166 | void SimpleRocket::setShooter(Pawn* shooter) |
---|
[7129] | 167 | { |
---|
[8855] | 168 | BasicProjectile::setShooter(shooter); |
---|
| 169 | |
---|
| 170 | this->player_ = this->getShooter()->getPlayer(); |
---|
[7129] | 171 | } |
---|
| 172 | |
---|
| 173 | bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 174 | { |
---|
[8855] | 175 | return this->processCollision(otherObject, contactPoint); |
---|
[7129] | 176 | } |
---|
| 177 | |
---|
| 178 | /** |
---|
| 179 | @brief |
---|
| 180 | Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 181 | @param value |
---|
| 182 | The vector determining the amount of the angular movement. |
---|
| 183 | */ |
---|
| 184 | void SimpleRocket::rotateYaw(const Vector2& value) |
---|
| 185 | { |
---|
| 186 | ControllableEntity::rotateYaw(value); |
---|
| 187 | |
---|
| 188 | if( !this->isInMouseLook() ) |
---|
| 189 | this->localAngularVelocity_.y += value.x; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /** |
---|
| 193 | @brief |
---|
| 194 | Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 195 | @param value |
---|
| 196 | The vector determining the amount of the angular movement. |
---|
| 197 | */ |
---|
| 198 | void SimpleRocket::rotatePitch(const Vector2& value) |
---|
| 199 | { |
---|
| 200 | ControllableEntity::rotatePitch(value); |
---|
| 201 | |
---|
| 202 | if( !this->isInMouseLook() ) |
---|
| 203 | this->localAngularVelocity_.x += value.x; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /** |
---|
| 207 | @brief |
---|
| 208 | Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 209 | @param value |
---|
| 210 | The vector determining the amount of the angular movement. |
---|
| 211 | */ |
---|
| 212 | void SimpleRocket::rotateRoll(const Vector2& value) |
---|
| 213 | { |
---|
| 214 | ControllableEntity::rotateRoll(value); |
---|
| 215 | |
---|
| 216 | if( !this->isInMouseLook() ) |
---|
| 217 | this->localAngularVelocity_.z += value.x; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | } |
---|