[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" |
---|
[7284] | 32 | #include "core/command/ConsoleCommand.h" |
---|
[5735] | 33 | #include "worldentities/ControllableEntity.h" |
---|
| 34 | #include "worldentities/pawns/Pawn.h" |
---|
| 35 | #include "gametypes/Gametype.h" |
---|
| 36 | #include "infos/PlayerInfo.h" |
---|
[5929] | 37 | #include "Radar.h" |
---|
| 38 | #include "Scene.h" |
---|
[2072] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[7862] | 42 | extern const std::string __CC_fire_name = "fire"; |
---|
[7863] | 43 | extern const std::string __CC_suicide_name = "suicide"; |
---|
[8379] | 44 | const std::string __CC_boost_name = "boost"; |
---|
[7862] | 45 | |
---|
[7284] | 46 | SetConsoleCommand("HumanController", "moveFrontBack", &HumanController::moveFrontBack ).addShortcut().setAsInputCommand(); |
---|
| 47 | SetConsoleCommand("HumanController", "moveRightLeft", &HumanController::moveRightLeft ).addShortcut().setAsInputCommand(); |
---|
| 48 | SetConsoleCommand("HumanController", "moveUpDown", &HumanController::moveUpDown ).addShortcut().setAsInputCommand(); |
---|
| 49 | SetConsoleCommand("HumanController", "rotateYaw", &HumanController::rotateYaw ).addShortcut().setAsInputCommand(); |
---|
| 50 | SetConsoleCommand("HumanController", "rotatePitch", &HumanController::rotatePitch ).addShortcut().setAsInputCommand(); |
---|
| 51 | SetConsoleCommand("HumanController", "rotateRoll", &HumanController::rotateRoll ).addShortcut().setAsInputCommand(); |
---|
[7862] | 52 | SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold); |
---|
[7284] | 53 | SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut(); |
---|
[8541] | 54 | //SetConsoleCommand("HumanController", __CC_boost_name, &HumanController::toggleBoost ).addShortcut().keybindMode(KeybindMode::OnPress); |
---|
| 55 | SetConsoleCommand("HumanController", "startBoost", &HumanController::startBoost ).addShortcut().keybindMode(KeybindMode::OnPress); |
---|
| 56 | SetConsoleCommand("HumanController", "stopBoost", &HumanController::stopBoost ).addShortcut().keybindMode(KeybindMode::OnRelease); |
---|
[7284] | 57 | SetConsoleCommand("HumanController", "greet", &HumanController::greet ).addShortcut(); |
---|
| 58 | SetConsoleCommand("HumanController", "switchCamera", &HumanController::switchCamera ).addShortcut(); |
---|
| 59 | SetConsoleCommand("HumanController", "mouseLook", &HumanController::mouseLook ).addShortcut(); |
---|
[7863] | 60 | SetConsoleCommand("HumanController", __CC_suicide_name, &HumanController::suicide ).addShortcut(); |
---|
[7284] | 61 | SetConsoleCommand("HumanController", "toggleGodMode", &HumanController::toggleGodMode ).addShortcut(); |
---|
| 62 | SetConsoleCommand("HumanController", "addBots", &HumanController::addBots ).addShortcut().defaultValues(1); |
---|
| 63 | SetConsoleCommand("HumanController", "killBots", &HumanController::killBots ).addShortcut().defaultValues(0); |
---|
| 64 | SetConsoleCommand("HumanController", "cycleNavigationFocus", &HumanController::cycleNavigationFocus).addShortcut(); |
---|
| 65 | SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut(); |
---|
[8079] | 66 | SetConsoleCommand("HumanController", "myposition", &HumanController::myposition ).addShortcut(); |
---|
[2072] | 67 | |
---|
| 68 | CreateUnloadableFactory(HumanController); |
---|
| 69 | |
---|
| 70 | HumanController* HumanController::localController_s = 0; |
---|
| 71 | |
---|
| 72 | HumanController::HumanController(BaseObject* creator) : Controller(creator) |
---|
| 73 | { |
---|
| 74 | RegisterObject(HumanController); |
---|
| 75 | |
---|
[6417] | 76 | controlPaused_ = false; |
---|
[8379] | 77 | this->boosting_ = false; |
---|
[6417] | 78 | |
---|
[2072] | 79 | HumanController::localController_s = this; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | HumanController::~HumanController() |
---|
| 83 | { |
---|
| 84 | HumanController::localController_s = 0; |
---|
| 85 | } |
---|
| 86 | |
---|
[5929] | 87 | void HumanController::tick(float dt) |
---|
| 88 | { |
---|
| 89 | if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 90 | { |
---|
| 91 | Camera* camera = HumanController::localController_s->controllableEntity_->getCamera(); |
---|
[6417] | 92 | if (!camera) |
---|
[5929] | 93 | COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
[2072] | 97 | void HumanController::moveFrontBack(const Vector2& value) |
---|
| 98 | { |
---|
[6417] | 99 | if (HumanController::localController_s) |
---|
| 100 | HumanController::localController_s->frontback(value); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | void HumanController::frontback(const Vector2& value) |
---|
| 104 | { |
---|
[2072] | 105 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 106 | HumanController::localController_s->controllableEntity_->moveFrontBack(value); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void HumanController::moveRightLeft(const Vector2& value) |
---|
| 110 | { |
---|
| 111 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 112 | HumanController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void HumanController::moveUpDown(const Vector2& value) |
---|
| 116 | { |
---|
| 117 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 118 | HumanController::localController_s->controllableEntity_->moveUpDown(value); |
---|
| 119 | } |
---|
| 120 | |
---|
[6417] | 121 | void HumanController::yaw(const Vector2& value) |
---|
[2072] | 122 | { |
---|
| 123 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 124 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
| 125 | } |
---|
| 126 | |
---|
[6417] | 127 | void HumanController::pitch(const Vector2& value) |
---|
[2072] | 128 | { |
---|
| 129 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 130 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
| 131 | } |
---|
| 132 | |
---|
[6417] | 133 | void HumanController::rotateYaw(const Vector2& value) |
---|
| 134 | { |
---|
| 135 | if (HumanController::localController_s) |
---|
| 136 | HumanController::localController_s->yaw(value); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | void HumanController::rotatePitch(const Vector2& value) |
---|
| 140 | { |
---|
| 141 | if (HumanController::localController_s) |
---|
| 142 | HumanController::localController_s->pitch(value); |
---|
| 143 | } |
---|
| 144 | |
---|
[2072] | 145 | void HumanController::rotateRoll(const Vector2& value) |
---|
| 146 | { |
---|
| 147 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 148 | HumanController::localController_s->controllableEntity_->rotateRoll(value); |
---|
| 149 | } |
---|
| 150 | |
---|
[3053] | 151 | void HumanController::fire(unsigned int firemode) |
---|
[2072] | 152 | { |
---|
[6417] | 153 | if (HumanController::localController_s) |
---|
| 154 | HumanController::localController_s->doFire(firemode); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | void HumanController::doFire(unsigned int firemode) |
---|
| 158 | { |
---|
[2072] | 159 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 160 | HumanController::localController_s->controllableEntity_->fire(firemode); |
---|
[2072] | 161 | } |
---|
| 162 | |
---|
[3053] | 163 | void HumanController::reload() |
---|
[2072] | 164 | { |
---|
| 165 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 166 | HumanController::localController_s->controllableEntity_->reload(); |
---|
[2072] | 167 | } |
---|
| 168 | |
---|
[8379] | 169 | /** |
---|
| 170 | @brief |
---|
| 171 | Static method,toggles boosting. |
---|
| 172 | */ |
---|
| 173 | /*static*/ void HumanController::toggleBoost() |
---|
[2662] | 174 | { |
---|
[8541] | 175 | COUT(0) << "Toggling boost!"; |
---|
[2662] | 176 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[8379] | 177 | HumanController::localController_s->toggleBoosting(); |
---|
[2662] | 178 | } |
---|
[8379] | 179 | |
---|
| 180 | /** |
---|
| 181 | @brief |
---|
| 182 | Toggles the boosting mode. |
---|
| 183 | Changes the keybind mode of the boost console command and tells the ControllableEntity to boost (or not boost anymore). |
---|
| 184 | */ |
---|
| 185 | void HumanController::toggleBoosting(void) |
---|
| 186 | { |
---|
[8541] | 187 | /* |
---|
[8379] | 188 | this->boosting_ = !this->boosting_; |
---|
| 189 | |
---|
| 190 | // The keybind mode of the boosting console command is onRelease if in boosting mode and onPress of not in boosting mode. |
---|
| 191 | if(this->boosting_) |
---|
| 192 | ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnRelease); |
---|
| 193 | else |
---|
| 194 | ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnPress); |
---|
[2662] | 195 | |
---|
[8541] | 196 | this->controllableEntity_->boost(this->boosting_);*/ |
---|
[8379] | 197 | } |
---|
[8541] | 198 | |
---|
| 199 | void HumanController::startBoost() |
---|
| 200 | { |
---|
| 201 | COUT(0) << "Starting boost" << std::endl; |
---|
| 202 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 203 | HumanController::localController_s->setBoost(true); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void HumanController::stopBoost() |
---|
| 207 | { |
---|
| 208 | COUT(0) << "Stopping boost" << std::endl; |
---|
| 209 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 210 | HumanController::localController_s->setBoost(false); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | void HumanController::setBoost(bool bBoost) |
---|
| 214 | { |
---|
| 215 | this->controllableEntity_->boost(bBoost); |
---|
| 216 | } |
---|
[8379] | 217 | |
---|
[2072] | 218 | void HumanController::greet() |
---|
| 219 | { |
---|
| 220 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 221 | HumanController::localController_s->controllableEntity_->greet(); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | void HumanController::switchCamera() |
---|
| 225 | { |
---|
| 226 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 227 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
| 228 | } |
---|
[2662] | 229 | |
---|
| 230 | void HumanController::mouseLook() |
---|
| 231 | { |
---|
| 232 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 233 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | void HumanController::suicide() |
---|
| 237 | { |
---|
| 238 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 239 | { |
---|
[3325] | 240 | Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
[2662] | 241 | if (pawn) |
---|
| 242 | pawn->kill(); |
---|
[2872] | 243 | else if (HumanController::localController_s->player_) |
---|
[3038] | 244 | HumanController::localController_s->player_->stopControl(); |
---|
[2662] | 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
[6417] | 248 | void HumanController::toggleGodMode() |
---|
| 249 | { |
---|
[8079] | 250 | if (HumanController::localController_s) |
---|
| 251 | HumanController::localController_s->setGodMode(!HumanController::localController_s->getGodMode()); |
---|
[6417] | 252 | } |
---|
| 253 | |
---|
[8079] | 254 | void HumanController::myposition() |
---|
| 255 | { |
---|
| 256 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 257 | { |
---|
| 258 | const Vector3& position = HumanController::localController_s->controllableEntity_->getPosition(); |
---|
| 259 | const Quaternion& orientation = HumanController::localController_s->controllableEntity_->getOrientation(); |
---|
| 260 | |
---|
| 261 | COUT(0) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" "; |
---|
| 262 | COUT(0) << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << std::endl; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | |
---|
[2662] | 266 | void HumanController::addBots(unsigned int amount) |
---|
| 267 | { |
---|
| 268 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 269 | HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | void HumanController::killBots(unsigned int amount) |
---|
| 273 | { |
---|
| 274 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 275 | HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); |
---|
| 276 | } |
---|
| 277 | |
---|
[3196] | 278 | Pawn* HumanController::getLocalControllerEntityAsPawn() |
---|
| 279 | { |
---|
| 280 | if (HumanController::localController_s) |
---|
[3325] | 281 | return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); |
---|
[3196] | 282 | else |
---|
| 283 | return NULL; |
---|
| 284 | } |
---|
[5929] | 285 | |
---|
| 286 | void HumanController::cycleNavigationFocus() |
---|
| 287 | { |
---|
| 288 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 289 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus(); |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | void HumanController::releaseNavigationFocus() |
---|
| 293 | { |
---|
| 294 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 295 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus(); |
---|
| 296 | } |
---|
[6417] | 297 | |
---|
| 298 | void HumanController::pauseControl() |
---|
| 299 | { |
---|
| 300 | if (HumanController::localController_s) |
---|
| 301 | HumanController::localController_s->doPauseControl(); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | void HumanController::resumeControl() |
---|
| 305 | { |
---|
| 306 | if (HumanController::localController_s) |
---|
| 307 | HumanController::localController_s->doResumeControl(); |
---|
| 308 | } |
---|
[2072] | 309 | } |
---|