[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 "HumanController.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
| 32 | #include "core/ConsoleCommand.h" |
---|
[5735] | 33 | #include "worldentities/ControllableEntity.h" |
---|
| 34 | #include "worldentities/pawns/Pawn.h" |
---|
| 35 | #include "gametypes/Gametype.h" |
---|
| 36 | #include "infos/PlayerInfo.h" |
---|
[5732] | 37 | #include "overlays/Map.h" |
---|
[5929] | 38 | #include "Radar.h" |
---|
| 39 | #include "Scene.h" |
---|
[2072] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
| 43 | SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand(); |
---|
| 44 | SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand(); |
---|
| 45 | SetConsoleCommand(HumanController, moveUpDown, true).setAsInputCommand(); |
---|
| 46 | SetConsoleCommand(HumanController, rotateYaw, true).setAsInputCommand(); |
---|
| 47 | SetConsoleCommand(HumanController, rotatePitch, true).setAsInputCommand(); |
---|
| 48 | SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); |
---|
| 49 | SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); |
---|
[3053] | 50 | SetConsoleCommand(HumanController, reload, true); |
---|
[2662] | 51 | SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); |
---|
[2072] | 52 | SetConsoleCommand(HumanController, greet, true); |
---|
| 53 | SetConsoleCommand(HumanController, switchCamera, true); |
---|
[2662] | 54 | SetConsoleCommand(HumanController, mouseLook, true); |
---|
| 55 | SetConsoleCommand(HumanController, suicide, true); |
---|
| 56 | SetConsoleCommand(HumanController, addBots, true).defaultValues(1); |
---|
| 57 | SetConsoleCommand(HumanController, killBots, true).defaultValues(0); |
---|
| 58 | SetConsoleCommand(HumanController, dropItems, true); |
---|
[3073] | 59 | SetConsoleCommand(HumanController, useItem, true); |
---|
[5929] | 60 | SetConsoleCommand(HumanController, cycleNavigationFocus, true); |
---|
| 61 | SetConsoleCommand(HumanController, releaseNavigationFocus, true); |
---|
[2072] | 62 | |
---|
| 63 | CreateUnloadableFactory(HumanController); |
---|
| 64 | |
---|
| 65 | HumanController* HumanController::localController_s = 0; |
---|
| 66 | |
---|
| 67 | HumanController::HumanController(BaseObject* creator) : Controller(creator) |
---|
| 68 | { |
---|
| 69 | RegisterObject(HumanController); |
---|
| 70 | |
---|
[6195] | 71 | controlPaused_ = false; |
---|
| 72 | |
---|
[2072] | 73 | HumanController::localController_s = this; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | HumanController::~HumanController() |
---|
| 77 | { |
---|
| 78 | HumanController::localController_s = 0; |
---|
| 79 | } |
---|
| 80 | |
---|
[5929] | 81 | void HumanController::tick(float dt) |
---|
| 82 | { |
---|
| 83 | if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 84 | { |
---|
| 85 | Camera* camera = HumanController::localController_s->controllableEntity_->getCamera(); |
---|
[6191] | 86 | if (!camera) |
---|
[5929] | 87 | COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
[6159] | 91 | void HumanController::moveFrontBack(const Vector2& value) |
---|
| 92 | { |
---|
| 93 | if (HumanController::localController_s) |
---|
| 94 | HumanController::localController_s->frontback(value); |
---|
| 95 | } |
---|
| 96 | |
---|
[6149] | 97 | void HumanController::frontback(const Vector2& value) |
---|
[2072] | 98 | { |
---|
| 99 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 100 | HumanController::localController_s->controllableEntity_->moveFrontBack(value); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | void HumanController::moveRightLeft(const Vector2& value) |
---|
| 104 | { |
---|
| 105 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 106 | HumanController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void HumanController::moveUpDown(const Vector2& value) |
---|
| 110 | { |
---|
| 111 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 112 | HumanController::localController_s->controllableEntity_->moveUpDown(value); |
---|
| 113 | } |
---|
| 114 | |
---|
[6108] | 115 | void HumanController::yaw(const Vector2& value) |
---|
[2072] | 116 | { |
---|
[3089] | 117 | //Hack to enable mouselook in map |
---|
| 118 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
| 119 | { |
---|
| 120 | Map::getSingletonPtr()->rotateYaw(value); |
---|
| 121 | return; |
---|
| 122 | } |
---|
[2072] | 123 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 124 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
| 125 | } |
---|
| 126 | |
---|
[6108] | 127 | void HumanController::pitch(const Vector2& value) |
---|
[2072] | 128 | { |
---|
[3089] | 129 | //Hack to enable mouselook in map |
---|
| 130 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
| 131 | { |
---|
| 132 | Map::getSingletonPtr()->rotatePitch(value); |
---|
| 133 | return; |
---|
| 134 | } |
---|
[2072] | 135 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 136 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
| 137 | } |
---|
| 138 | |
---|
[6159] | 139 | void HumanController::rotateYaw(const Vector2& value) |
---|
| 140 | { |
---|
| 141 | if (HumanController::localController_s) |
---|
| 142 | HumanController::localController_s->yaw(value); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | void HumanController::rotatePitch(const Vector2& value) |
---|
| 146 | { |
---|
| 147 | if (HumanController::localController_s) |
---|
| 148 | HumanController::localController_s->pitch(value); |
---|
| 149 | } |
---|
| 150 | |
---|
[2072] | 151 | void HumanController::rotateRoll(const Vector2& value) |
---|
| 152 | { |
---|
| 153 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 154 | HumanController::localController_s->controllableEntity_->rotateRoll(value); |
---|
| 155 | } |
---|
| 156 | |
---|
[6159] | 157 | void HumanController::fire(unsigned int firemode) |
---|
| 158 | { |
---|
| 159 | if (HumanController::localController_s) |
---|
| 160 | HumanController::localController_s->doFire(firemode); |
---|
| 161 | } |
---|
| 162 | |
---|
[6108] | 163 | void HumanController::doFire(unsigned int firemode) |
---|
[2072] | 164 | { |
---|
| 165 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 166 | HumanController::localController_s->controllableEntity_->fire(firemode); |
---|
[2072] | 167 | } |
---|
| 168 | |
---|
[3053] | 169 | void HumanController::reload() |
---|
[2072] | 170 | { |
---|
| 171 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 172 | HumanController::localController_s->controllableEntity_->reload(); |
---|
[2072] | 173 | } |
---|
| 174 | |
---|
[2662] | 175 | void HumanController::boost() |
---|
| 176 | { |
---|
| 177 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 178 | HumanController::localController_s->controllableEntity_->boost(); |
---|
| 179 | } |
---|
| 180 | |
---|
[2072] | 181 | void HumanController::greet() |
---|
| 182 | { |
---|
| 183 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 184 | HumanController::localController_s->controllableEntity_->greet(); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | void HumanController::switchCamera() |
---|
| 188 | { |
---|
| 189 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 190 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
| 191 | } |
---|
[2662] | 192 | |
---|
| 193 | void HumanController::mouseLook() |
---|
| 194 | { |
---|
| 195 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 196 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | void HumanController::suicide() |
---|
| 200 | { |
---|
| 201 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 202 | { |
---|
[3325] | 203 | Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
[2662] | 204 | if (pawn) |
---|
| 205 | pawn->kill(); |
---|
[2872] | 206 | else if (HumanController::localController_s->player_) |
---|
[3038] | 207 | HumanController::localController_s->player_->stopControl(); |
---|
[2662] | 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
[3073] | 211 | void HumanController::useItem() |
---|
| 212 | { |
---|
| 213 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 214 | HumanController::localController_s->controllableEntity_->useItem(); |
---|
| 215 | } |
---|
| 216 | |
---|
[2662] | 217 | void HumanController::addBots(unsigned int amount) |
---|
| 218 | { |
---|
| 219 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 220 | HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | void HumanController::killBots(unsigned int amount) |
---|
| 224 | { |
---|
| 225 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 226 | HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | void HumanController::dropItems() |
---|
| 230 | { |
---|
| 231 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 232 | HumanController::localController_s->controllableEntity_->dropItems(); |
---|
| 233 | } |
---|
[3196] | 234 | |
---|
| 235 | Pawn* HumanController::getLocalControllerEntityAsPawn() |
---|
| 236 | { |
---|
| 237 | if (HumanController::localController_s) |
---|
[3325] | 238 | return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); |
---|
[3196] | 239 | else |
---|
| 240 | return NULL; |
---|
| 241 | } |
---|
[5929] | 242 | |
---|
| 243 | void HumanController::cycleNavigationFocus() |
---|
| 244 | { |
---|
| 245 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 246 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus(); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | void HumanController::releaseNavigationFocus() |
---|
| 250 | { |
---|
| 251 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 252 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus(); |
---|
| 253 | } |
---|
[6195] | 254 | |
---|
| 255 | void HumanController::pauseControl() |
---|
| 256 | { |
---|
| 257 | if (HumanController::localController_s) |
---|
| 258 | HumanController::localController_s->doPauseControl(); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | void HumanController::resumeControl() |
---|
| 262 | { |
---|
| 263 | if (HumanController::localController_s) |
---|
| 264 | HumanController::localController_s->doResumeControl(); |
---|
| 265 | } |
---|
[2072] | 266 | } |
---|