[2072] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "Spectator.h" |
---|
| 31 | |
---|
[2662] | 32 | #include <OgreBillboardSet.h> |
---|
| 33 | |
---|
[2072] | 34 | #include "core/CoreIncludes.h" |
---|
[2662] | 35 | #include "core/ConfigValueIncludes.h" |
---|
[2896] | 36 | #include "core/GameMode.h" |
---|
[2072] | 37 | #include "objects/worldentities/Model.h" |
---|
| 38 | #include "objects/Scene.h" |
---|
| 39 | #include "objects/infos/PlayerInfo.h" |
---|
| 40 | #include "objects/gametypes/Gametype.h" |
---|
| 41 | #include "tools/BillboardSet.h" |
---|
| 42 | #include "overlays/OverlayText.h" |
---|
| 43 | #include "overlays/OverlayGroup.h" |
---|
| 44 | #include "util/Convert.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | CreateFactory(Spectator); |
---|
| 49 | |
---|
| 50 | Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator) |
---|
| 51 | { |
---|
| 52 | RegisterObject(Spectator); |
---|
| 53 | |
---|
[2662] | 54 | this->speed_ = 200; |
---|
[2072] | 55 | |
---|
| 56 | this->yaw_ = 0; |
---|
| 57 | this->pitch_ = 0; |
---|
| 58 | this->roll_ = 0; |
---|
[2662] | 59 | this->localVelocity_ = Vector3::ZERO; |
---|
[2072] | 60 | this->setHudTemplate("spectatorhud"); |
---|
[2662] | 61 | this->greetingFlare_ = 0; |
---|
[2072] | 62 | |
---|
| 63 | this->setDestroyWhenPlayerLeft(true); |
---|
| 64 | |
---|
[2896] | 65 | if (GameMode::showsGraphics()) |
---|
[2662] | 66 | { |
---|
| 67 | this->greetingFlare_ = new BillboardSet(); |
---|
| 68 | this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); |
---|
| 69 | if (this->greetingFlare_->getBillboardSet()) |
---|
| 70 | this->attachOgreObject(this->greetingFlare_->getBillboardSet()); |
---|
| 71 | this->greetingFlare_->setVisible(false); |
---|
| 72 | } |
---|
| 73 | |
---|
[2072] | 74 | this->bGreetingFlareVisible_ = false; |
---|
| 75 | this->bGreeting_ = false; |
---|
| 76 | |
---|
[2662] | 77 | this->setConfigValues(); |
---|
[2072] | 78 | this->registerVariables(); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Spectator::~Spectator() |
---|
| 82 | { |
---|
| 83 | if (this->isInitialized()) |
---|
| 84 | { |
---|
| 85 | if (this->greetingFlare_) |
---|
| 86 | { |
---|
[2171] | 87 | if (this->greetingFlare_->getBillboardSet()) |
---|
[2662] | 88 | this->detachOgreObject(this->greetingFlare_->getBillboardSet()); |
---|
| 89 | |
---|
[2072] | 90 | delete this->greetingFlare_; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
[2662] | 95 | void Spectator::setConfigValues() |
---|
| 96 | { |
---|
| 97 | SetConfigValue(speed_, 200.0f); |
---|
| 98 | } |
---|
| 99 | |
---|
[2072] | 100 | void Spectator::registerVariables() |
---|
| 101 | { |
---|
[2662] | 102 | registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); |
---|
| 103 | registerVariable(this->bGreeting_, variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); |
---|
[2072] | 104 | } |
---|
| 105 | |
---|
| 106 | void Spectator::changedGreeting() |
---|
| 107 | { |
---|
| 108 | this->bGreetingFlareVisible_ = this->bGreeting_; |
---|
| 109 | this->changedFlareVisibility(); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void Spectator::changedFlareVisibility() |
---|
| 113 | { |
---|
[3034] | 114 | if (this->greetingFlare_) |
---|
[2662] | 115 | this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); |
---|
[2072] | 116 | } |
---|
| 117 | |
---|
| 118 | void Spectator::tick(float dt) |
---|
| 119 | { |
---|
[2662] | 120 | if (this->hasLocalController()) |
---|
[2072] | 121 | { |
---|
[2662] | 122 | float localSpeedSquared = this->localVelocity_.squaredLength(); |
---|
| 123 | float localSpeed; |
---|
| 124 | if (localSpeedSquared > 1.0) |
---|
| 125 | localSpeed = this->speed_ / sqrtf(localSpeedSquared); |
---|
| 126 | else |
---|
| 127 | localSpeed = this->speed_; |
---|
[2072] | 128 | |
---|
[2662] | 129 | this->localVelocity_.x *= localSpeed; |
---|
| 130 | this->localVelocity_.y *= localSpeed; |
---|
| 131 | this->localVelocity_.z *= localSpeed; |
---|
| 132 | this->setVelocity(this->getOrientation() * this->localVelocity_); |
---|
| 133 | this->localVelocity_.x = 0; |
---|
| 134 | this->localVelocity_.y = 0; |
---|
| 135 | this->localVelocity_.z = 0; |
---|
[2072] | 136 | |
---|
[2662] | 137 | if (!this->isInMouseLook()) |
---|
| 138 | { |
---|
| 139 | this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed())); |
---|
| 140 | this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed())); |
---|
| 141 | this->roll(Radian(this->roll_ * this->getMouseLookSpeed())); |
---|
| 142 | } |
---|
| 143 | |
---|
[2072] | 144 | this->yaw_ = this->pitch_ = this->roll_ = 0; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | SUPER(Spectator, tick, dt); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void Spectator::setPlayer(PlayerInfo* player) |
---|
| 151 | { |
---|
| 152 | ControllableEntity::setPlayer(player); |
---|
| 153 | |
---|
[2662] | 154 | // this->setObjectMode(objectDirection::toclient); |
---|
[2072] | 155 | } |
---|
| 156 | |
---|
[2662] | 157 | void Spectator::startLocalHumanControl() |
---|
[2072] | 158 | { |
---|
[2662] | 159 | ControllableEntity::startLocalHumanControl(); |
---|
[2072] | 160 | } |
---|
| 161 | |
---|
| 162 | void Spectator::moveFrontBack(const Vector2& value) |
---|
| 163 | { |
---|
[2662] | 164 | this->localVelocity_.z -= value.x; |
---|
[2072] | 165 | } |
---|
| 166 | |
---|
| 167 | void Spectator::moveRightLeft(const Vector2& value) |
---|
| 168 | { |
---|
[2662] | 169 | this->localVelocity_.x += value.x; |
---|
[2072] | 170 | } |
---|
| 171 | |
---|
| 172 | void Spectator::moveUpDown(const Vector2& value) |
---|
| 173 | { |
---|
[2662] | 174 | this->localVelocity_.y += value.x; |
---|
[2072] | 175 | } |
---|
| 176 | |
---|
| 177 | void Spectator::rotateYaw(const Vector2& value) |
---|
| 178 | { |
---|
[3039] | 179 | this->yaw_ += value.y; |
---|
[2662] | 180 | |
---|
| 181 | ControllableEntity::rotateYaw(value); |
---|
[2072] | 182 | } |
---|
| 183 | |
---|
| 184 | void Spectator::rotatePitch(const Vector2& value) |
---|
| 185 | { |
---|
[2662] | 186 | this->pitch_ += value.y; |
---|
| 187 | |
---|
| 188 | ControllableEntity::rotatePitch(value); |
---|
[2072] | 189 | } |
---|
| 190 | |
---|
| 191 | void Spectator::rotateRoll(const Vector2& value) |
---|
| 192 | { |
---|
[2662] | 193 | this->roll_ += value.y; |
---|
| 194 | |
---|
| 195 | ControllableEntity::rotateRoll(value); |
---|
[2072] | 196 | } |
---|
| 197 | |
---|
[3053] | 198 | void Spectator::fire(unsigned int firemode) |
---|
[2072] | 199 | { |
---|
| 200 | if (this->getPlayer()) |
---|
| 201 | this->getPlayer()->setReadyToSpawn(true); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | void Spectator::greet() |
---|
| 205 | { |
---|
| 206 | this->bGreeting_ = !this->bGreeting_; |
---|
| 207 | |
---|
[2896] | 208 | if (GameMode::isMaster()) |
---|
[2072] | 209 | { |
---|
| 210 | this->bGreetingFlareVisible_ = this->bGreeting_; |
---|
| 211 | this->changedFlareVisibility(); |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | } |
---|