[6778] | 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 "SimpleRocket.h" |
---|
| 30 | |
---|
| 31 | #include <BulletDynamics/Dynamics/btRigidBody.h> |
---|
| 32 | |
---|
| 33 | #include "core/CoreIncludes.h" |
---|
| 34 | #include "core/XMLPort.h" |
---|
| 35 | #include "worldentities/pawns/Pawn.h" |
---|
| 36 | #include "graphics/ParticleSpawner.h" |
---|
| 37 | #include "graphics/Model.h" |
---|
| 38 | #include "objects/collisionshapes/ConeCollisionShape.h" |
---|
| 39 | #include "infos/PlayerInfo.h" |
---|
| 40 | #include "controllers/Controller.h" |
---|
[6803] | 41 | #include "weapons/RocketController.h" |
---|
[6778] | 42 | #include "sound/WorldSound.h" |
---|
[6815] | 43 | #include "util/Debug.h" |
---|
[6778] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[7021] | 47 | /** |
---|
| 48 | @file |
---|
| 49 | @brief |
---|
| 50 | SimpleRocket, follows direction from a Rocketcontroller, has fuel for 80% of its lifetime, afterwords it's fire disappears. |
---|
| 51 | @author |
---|
| 52 | Gabriel Nadler (Original file: Oli Scheuss) |
---|
| 53 | */ |
---|
[6778] | 54 | CreateFactory(SimpleRocket); |
---|
| 55 | |
---|
[7021] | 56 | |
---|
[6778] | 57 | SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator) |
---|
| 58 | { |
---|
| 59 | RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core |
---|
| 60 | |
---|
| 61 | this->localAngularVelocity_ = 0; |
---|
| 62 | this->bDestroy_ = false; |
---|
[7018] | 63 | this->lifetime_ = 120; |
---|
[7021] | 64 | |
---|
[7018] | 65 | this->setMass(15); |
---|
[6951] | 66 | COUT(4) << "simplerocket constructed\n"; |
---|
[6778] | 67 | |
---|
[6900] | 68 | if (GameMode::isMaster()) |
---|
[7019] | 69 | { |
---|
[7018] | 70 | this->setCollisionType(WorldEntity::Kinematic); |
---|
| 71 | this->fuel_=true; |
---|
[6778] | 72 | |
---|
| 73 | Model* model = new Model(this); |
---|
[6827] | 74 | model->setMeshSource("rocket.mesh"); |
---|
[6834] | 75 | model->scale(0.7f); |
---|
[6778] | 76 | this->attach(model); |
---|
[6834] | 77 | |
---|
[7018] | 78 | this->fire_ = new ParticleEmitter(this); |
---|
| 79 | this->attach(this->fire_); |
---|
| 80 | |
---|
| 81 | this->fire_->setOrientation(this->getOrientation()); |
---|
| 82 | this->fire_->setSource("Orxonox/simplerocketfire"); |
---|
[6778] | 83 | this->enableCollisionCallback(); |
---|
| 84 | this->setCollisionResponse(false); |
---|
| 85 | this->setCollisionType(Kinematic); |
---|
| 86 | |
---|
[6949] | 87 | // TODO: fix the orientation and size of this collision shape to match the rocket |
---|
[6778] | 88 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
[7018] | 89 | collisionShape->setOrientation(this->getOrientation()); |
---|
| 90 | collisionShape->setRadius(1.5f); |
---|
[6949] | 91 | collisionShape->setHeight(5); |
---|
[6834] | 92 | this->attachCollisionShape(collisionShape); |
---|
[6778] | 93 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this))); |
---|
[6900] | 94 | } |
---|
[6778] | 95 | |
---|
| 96 | } |
---|
[7018] | 97 | |
---|
| 98 | |
---|
[7021] | 99 | |
---|
| 100 | /** |
---|
| 101 | * @brief updates state of rocket, disables fire if no fuel |
---|
| 102 | * @param dt tick-length |
---|
| 103 | */ |
---|
[6951] | 104 | void SimpleRocket::tick(float dt) |
---|
[6900] | 105 | { |
---|
[7018] | 106 | |
---|
[6900] | 107 | SUPER(SimpleRocket, tick, dt); |
---|
[7019] | 108 | if ( GameMode::isMaster() ) |
---|
| 109 | { |
---|
[6902] | 110 | |
---|
[7021] | 111 | |
---|
[6902] | 112 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
| 113 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
[6949] | 114 | this->localAngularVelocity_ = 0; |
---|
[6902] | 115 | |
---|
[7021] | 116 | |
---|
[7019] | 117 | if (this->fuel_) |
---|
| 118 | { |
---|
[7021] | 119 | if (this->destroyTimer_.getRemainingTime()< (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ ) |
---|
[7018] | 120 | this->fuel_=false; |
---|
[7021] | 121 | } else |
---|
[7019] | 122 | this->disableFire(); |
---|
[7018] | 123 | |
---|
[7021] | 124 | if( this->bDestroy_ ) |
---|
[6902] | 125 | this->destroy(); |
---|
[7019] | 126 | } |
---|
[7018] | 127 | |
---|
[6951] | 128 | } |
---|
[6778] | 129 | |
---|
[7021] | 130 | /** |
---|
| 131 | * @brief Sets the Acceleration to 0 and detaches the fire |
---|
| 132 | * @return void |
---|
| 133 | */ |
---|
[7019] | 134 | void SimpleRocket::disableFire() |
---|
| 135 | { |
---|
[7021] | 136 | this->setAcceleration(0,0,0); |
---|
| 137 | this->fire_->detachFromParent(); |
---|
[7018] | 138 | } |
---|
| 139 | |
---|
[6810] | 140 | /**s |
---|
[6778] | 141 | @brief |
---|
| 142 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
| 143 | */ |
---|
| 144 | SimpleRocket::~SimpleRocket() |
---|
| 145 | { |
---|
[6951] | 146 | if (this->isInitialized()) |
---|
| 147 | { |
---|
[7019] | 148 | if( GameMode::isMaster() ) |
---|
| 149 | { |
---|
| 150 | this->getController()->destroy(); |
---|
| 151 | } |
---|
[6951] | 152 | } |
---|
| 153 | } |
---|
[6778] | 154 | |
---|
| 155 | /** |
---|
| 156 | @brief |
---|
| 157 | Method for creating a SimpleRocket through XML. |
---|
| 158 | */ |
---|
| 159 | void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 160 | { |
---|
| 161 | // this calls the XMLPort function of the parent class |
---|
| 162 | SUPER(SimpleRocket, XMLPort, xmlelement, mode); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void SimpleRocket::setOwner(Pawn* owner) |
---|
| 166 | { |
---|
| 167 | this->owner_ = owner; |
---|
| 168 | this->player_ = this->owner_->getPlayer(); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
[7018] | 172 | |
---|
[7021] | 173 | |
---|
[6778] | 174 | bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 175 | { |
---|
| 176 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
| 177 | { |
---|
| 178 | if (otherObject == this->owner_) |
---|
| 179 | return false; |
---|
| 180 | |
---|
| 181 | this->bDestroy_ = true; |
---|
| 182 | |
---|
| 183 | if (this->owner_) |
---|
| 184 | { |
---|
| 185 | { |
---|
| 186 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 187 | effect->setPosition(this->getPosition()); |
---|
| 188 | effect->setOrientation(this->getOrientation()); |
---|
| 189 | effect->setDestroyAfterLife(true); |
---|
| 190 | effect->setSource("Orxonox/explosion4"); |
---|
| 191 | effect->setLifetime(2.0f); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | { |
---|
| 195 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 196 | effect->setPosition(this->getPosition()); |
---|
| 197 | effect->setOrientation(this->getOrientation()); |
---|
| 198 | effect->setDestroyAfterLife(true); |
---|
| 199 | effect->setSource("Orxonox/smoke4"); |
---|
| 200 | effect->setLifetime(3.0f); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | float dmg = this->damage_; |
---|
[6951] | 205 | // if (this->owner_) |
---|
| 206 | // dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); |
---|
[6778] | 207 | |
---|
| 208 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); |
---|
| 209 | if (victim) |
---|
| 210 | victim->hit(this->owner_, contactPoint, dmg); |
---|
| 211 | } |
---|
| 212 | return false; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void SimpleRocket::destroyObject() |
---|
| 216 | { |
---|
| 217 | if (GameMode::isMaster()) |
---|
| 218 | { |
---|
| 219 | this->destroy(); |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | @brief |
---|
| 225 | Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 226 | @param value |
---|
| 227 | The vector determining the amount of the angular movement. |
---|
| 228 | */ |
---|
| 229 | void SimpleRocket::rotateYaw(const Vector2& value) |
---|
| 230 | { |
---|
| 231 | ControllableEntity::rotateYaw(value); |
---|
| 232 | |
---|
| 233 | if( !this->isInMouseLook() ) |
---|
| 234 | this->localAngularVelocity_.y += value.x; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /** |
---|
| 238 | @brief |
---|
| 239 | Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 240 | @param value |
---|
| 241 | The vector determining the amount of the angular movement. |
---|
| 242 | */ |
---|
| 243 | void SimpleRocket::rotatePitch(const Vector2& value) |
---|
| 244 | { |
---|
| 245 | ControllableEntity::rotatePitch(value); |
---|
| 246 | |
---|
| 247 | if( !this->isInMouseLook() ) |
---|
| 248 | this->localAngularVelocity_.x += value.x; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | /** |
---|
| 252 | @brief |
---|
| 253 | Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 254 | @param value |
---|
| 255 | The vector determining the amount of the angular movement. |
---|
| 256 | */ |
---|
| 257 | void SimpleRocket::rotateRoll(const Vector2& value) |
---|
| 258 | { |
---|
| 259 | ControllableEntity::rotateRoll(value); |
---|
| 260 | |
---|
| 261 | if( !this->isInMouseLook() ) |
---|
| 262 | this->localAngularVelocity_.z += value.x; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | } |
---|