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