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