[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" |
---|
[10624] | 32 | #include "core/command/ConsoleCommandIncludes.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"; |
---|
[7862] | 44 | |
---|
[7284] | 45 | SetConsoleCommand("HumanController", "moveFrontBack", &HumanController::moveFrontBack ).addShortcut().setAsInputCommand(); |
---|
| 46 | SetConsoleCommand("HumanController", "moveRightLeft", &HumanController::moveRightLeft ).addShortcut().setAsInputCommand(); |
---|
| 47 | SetConsoleCommand("HumanController", "moveUpDown", &HumanController::moveUpDown ).addShortcut().setAsInputCommand(); |
---|
| 48 | SetConsoleCommand("HumanController", "rotateYaw", &HumanController::rotateYaw ).addShortcut().setAsInputCommand(); |
---|
| 49 | SetConsoleCommand("HumanController", "rotatePitch", &HumanController::rotatePitch ).addShortcut().setAsInputCommand(); |
---|
| 50 | SetConsoleCommand("HumanController", "rotateRoll", &HumanController::rotateRoll ).addShortcut().setAsInputCommand(); |
---|
[9016] | 51 | SetConsoleCommand("HumanController", "toggleFormationFlight", &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress); |
---|
[9979] | 52 | SetConsoleCommand("HumanController", "FFChangeMode", &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress); |
---|
[7862] | 53 | SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold); |
---|
[7284] | 54 | SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut(); |
---|
[9979] | 55 | SetConsoleCommand("HumanController", "boost", &HumanController::boost ).addShortcut().setAsInputCommand().keybindMode(KeybindMode::OnPressAndRelease); |
---|
[7284] | 56 | SetConsoleCommand("HumanController", "greet", &HumanController::greet ).addShortcut(); |
---|
| 57 | SetConsoleCommand("HumanController", "switchCamera", &HumanController::switchCamera ).addShortcut(); |
---|
| 58 | SetConsoleCommand("HumanController", "mouseLook", &HumanController::mouseLook ).addShortcut(); |
---|
[7863] | 59 | SetConsoleCommand("HumanController", __CC_suicide_name, &HumanController::suicide ).addShortcut(); |
---|
[7284] | 60 | SetConsoleCommand("HumanController", "toggleGodMode", &HumanController::toggleGodMode ).addShortcut(); |
---|
| 61 | SetConsoleCommand("HumanController", "cycleNavigationFocus", &HumanController::cycleNavigationFocus).addShortcut(); |
---|
| 62 | SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut(); |
---|
[8079] | 63 | SetConsoleCommand("HumanController", "myposition", &HumanController::myposition ).addShortcut(); |
---|
[2072] | 64 | |
---|
[9667] | 65 | RegisterUnloadableClass(HumanController); |
---|
[2072] | 66 | |
---|
[11071] | 67 | HumanController* HumanController::localController_s = nullptr; |
---|
[2072] | 68 | |
---|
[9667] | 69 | HumanController::HumanController(Context* context) : FormationController(context) |
---|
[2072] | 70 | { |
---|
| 71 | RegisterObject(HumanController); |
---|
| 72 | |
---|
[8706] | 73 | this->controlPaused_ = false; |
---|
[2072] | 74 | HumanController::localController_s = this; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | HumanController::~HumanController() |
---|
| 78 | { |
---|
[9256] | 79 | if (HumanController::localController_s) |
---|
[9016] | 80 | { |
---|
| 81 | HumanController::localController_s->removeFromFormation(); |
---|
| 82 | } |
---|
[11071] | 83 | HumanController::localController_s = nullptr; |
---|
[2072] | 84 | } |
---|
| 85 | |
---|
[5929] | 86 | void HumanController::tick(float dt) |
---|
| 87 | { |
---|
| 88 | if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 89 | { |
---|
| 90 | Camera* camera = HumanController::localController_s->controllableEntity_->getCamera(); |
---|
[6417] | 91 | if (!camera) |
---|
[8858] | 92 | orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl; |
---|
[5929] | 93 | } |
---|
[9016] | 94 | |
---|
| 95 | // commandslaves when Master of a formation |
---|
[9625] | 96 | if (HumanController::localController_s && HumanController::localController_s->state_==MASTER && FormationController::slaves_.size() > 0) |
---|
[9016] | 97 | { |
---|
| 98 | if (HumanController::localController_s->formationMode_ != ATTACK) |
---|
| 99 | HumanController::localController_s->commandSlaves(); |
---|
| 100 | } |
---|
[5929] | 101 | } |
---|
| 102 | |
---|
[2072] | 103 | void HumanController::moveFrontBack(const Vector2& value) |
---|
| 104 | { |
---|
[6417] | 105 | if (HumanController::localController_s) |
---|
| 106 | HumanController::localController_s->frontback(value); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void HumanController::frontback(const Vector2& value) |
---|
| 110 | { |
---|
[2072] | 111 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 112 | HumanController::localController_s->controllableEntity_->moveFrontBack(value); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void HumanController::moveRightLeft(const Vector2& value) |
---|
| 116 | { |
---|
| 117 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 118 | HumanController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void HumanController::moveUpDown(const Vector2& value) |
---|
| 122 | { |
---|
| 123 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 124 | HumanController::localController_s->controllableEntity_->moveUpDown(value); |
---|
| 125 | } |
---|
| 126 | |
---|
[6417] | 127 | void HumanController::yaw(const Vector2& value) |
---|
[2072] | 128 | { |
---|
| 129 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 130 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
| 131 | } |
---|
| 132 | |
---|
[6417] | 133 | void HumanController::pitch(const Vector2& value) |
---|
[2072] | 134 | { |
---|
| 135 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 136 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
| 137 | } |
---|
| 138 | |
---|
[6417] | 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 | |
---|
[3053] | 157 | void HumanController::fire(unsigned int firemode) |
---|
[2072] | 158 | { |
---|
[6417] | 159 | if (HumanController::localController_s) |
---|
| 160 | HumanController::localController_s->doFire(firemode); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void HumanController::doFire(unsigned int firemode) |
---|
| 164 | { |
---|
[2072] | 165 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[9016] | 166 | { |
---|
[3053] | 167 | HumanController::localController_s->controllableEntity_->fire(firemode); |
---|
[9016] | 168 | //if human fires, set slaves free. See FormationController::forceFreeSlaves() |
---|
| 169 | if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL) |
---|
| 170 | { |
---|
| 171 | HumanController::localController_s->forceFreeSlaves(); |
---|
| 172 | } |
---|
| 173 | } |
---|
[2072] | 174 | } |
---|
| 175 | |
---|
[3053] | 176 | void HumanController::reload() |
---|
[2072] | 177 | { |
---|
| 178 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 179 | HumanController::localController_s->controllableEntity_->reload(); |
---|
[2072] | 180 | } |
---|
| 181 | |
---|
[8706] | 182 | /** |
---|
| 183 | @brief |
---|
[9979] | 184 | Static method, controls boosting. |
---|
[8706] | 185 | */ |
---|
[9979] | 186 | /*static*/ void HumanController::boost(const Vector2& value) |
---|
[2662] | 187 | { |
---|
| 188 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[9979] | 189 | { |
---|
| 190 | float abs = value.x; |
---|
| 191 | if (abs > 0) |
---|
| 192 | HumanController::localController_s->startBoosting(); |
---|
| 193 | else |
---|
| 194 | HumanController::localController_s->stopBoosting(); |
---|
| 195 | } |
---|
[2662] | 196 | } |
---|
[9256] | 197 | |
---|
[8706] | 198 | /** |
---|
| 199 | @brief |
---|
[9979] | 200 | Starts the boosting mode. |
---|
[11052] | 201 | Resets the boosting timeout and tells the ControllableEntity to boost (or not boost anymore). |
---|
[8706] | 202 | */ |
---|
[9979] | 203 | void HumanController::startBoosting(void) |
---|
[8706] | 204 | { |
---|
[9979] | 205 | if(this->controllableEntity_) |
---|
| 206 | this->controllableEntity_->boost(true); |
---|
[8706] | 207 | } |
---|
[2662] | 208 | |
---|
[8706] | 209 | /** |
---|
| 210 | @brief |
---|
[9979] | 211 | Stops the boosting mode. |
---|
[8706] | 212 | */ |
---|
[9979] | 213 | void HumanController::stopBoosting(void) |
---|
[8706] | 214 | { |
---|
[9016] | 215 | if(this->controllableEntity_) |
---|
[9979] | 216 | this->controllableEntity_->boost(false); |
---|
[8706] | 217 | } |
---|
| 218 | |
---|
[2072] | 219 | void HumanController::greet() |
---|
| 220 | { |
---|
| 221 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 222 | HumanController::localController_s->controllableEntity_->greet(); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | void HumanController::switchCamera() |
---|
| 226 | { |
---|
| 227 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 228 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
| 229 | } |
---|
[2662] | 230 | |
---|
| 231 | void HumanController::mouseLook() |
---|
| 232 | { |
---|
| 233 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 234 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | void HumanController::suicide() |
---|
| 238 | { |
---|
| 239 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 240 | { |
---|
[3325] | 241 | Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
[2662] | 242 | if (pawn) |
---|
| 243 | pawn->kill(); |
---|
[2872] | 244 | else if (HumanController::localController_s->player_) |
---|
[3038] | 245 | HumanController::localController_s->player_->stopControl(); |
---|
[2662] | 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
[6417] | 249 | void HumanController::toggleGodMode() |
---|
| 250 | { |
---|
[8079] | 251 | if (HumanController::localController_s) |
---|
| 252 | HumanController::localController_s->setGodMode(!HumanController::localController_s->getGodMode()); |
---|
[6417] | 253 | } |
---|
| 254 | |
---|
[8079] | 255 | void HumanController::myposition() |
---|
| 256 | { |
---|
| 257 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 258 | { |
---|
| 259 | const Vector3& position = HumanController::localController_s->controllableEntity_->getPosition(); |
---|
| 260 | const Quaternion& orientation = HumanController::localController_s->controllableEntity_->getOrientation(); |
---|
| 261 | |
---|
[8858] | 262 | orxout(message) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" " |
---|
| 263 | << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << endl; |
---|
[8079] | 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
[9016] | 267 | /** |
---|
| 268 | @brief |
---|
| 269 | toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_) |
---|
| 270 | */ |
---|
| 271 | void HumanController::toggleFormationFlight() |
---|
| 272 | { |
---|
| 273 | if (HumanController::localController_s) |
---|
| 274 | { |
---|
| 275 | if (!HumanController::localController_s->formationFlight_) |
---|
| 276 | { |
---|
| 277 | return; //dont use when formationFlight is disabled |
---|
| 278 | } |
---|
| 279 | if (HumanController::localController_s->state_==MASTER) |
---|
| 280 | { |
---|
| 281 | HumanController::localController_s->loseMasterState(); |
---|
| 282 | orxout(message) <<"FormationFlight disabled "<< endl; |
---|
| 283 | } else //SLAVE or FREE |
---|
| 284 | { |
---|
| 285 | HumanController::localController_s->takeLeadOfFormation(); |
---|
| 286 | orxout(message) <<"FormationFlight enabled "<< endl; |
---|
| 287 | } |
---|
[9256] | 288 | |
---|
[9016] | 289 | } |
---|
| 290 | |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /** |
---|
| 294 | @brief |
---|
| 295 | Switch through the different Modes of formationflight. You must be a master of a formation to use. |
---|
| 296 | */ |
---|
| 297 | void HumanController::FFChangeMode() |
---|
| 298 | { |
---|
| 299 | if (HumanController::localController_s && HumanController::localController_s->state_==MASTER) |
---|
| 300 | { |
---|
| 301 | switch (HumanController::localController_s->getFormationMode()) { |
---|
| 302 | case NORMAL: |
---|
| 303 | HumanController::localController_s->setFormationMode(DEFEND); |
---|
| 304 | orxout(message) <<"Mode: DEFEND "<< endl; |
---|
| 305 | break; |
---|
| 306 | case DEFEND: |
---|
| 307 | HumanController::localController_s->setFormationMode(ATTACK); |
---|
| 308 | orxout(message) <<"Mode: ATTACK "<< endl; |
---|
| 309 | break; |
---|
| 310 | case ATTACK: |
---|
| 311 | HumanController::localController_s->setFormationMode(NORMAL); |
---|
| 312 | orxout(message) <<"Mode: NORMAL "<< endl; |
---|
| 313 | break; |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | |
---|
[3196] | 318 | Pawn* HumanController::getLocalControllerEntityAsPawn() |
---|
| 319 | { |
---|
| 320 | if (HumanController::localController_s) |
---|
[3325] | 321 | return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); |
---|
[3196] | 322 | else |
---|
[11071] | 323 | return nullptr; |
---|
[3196] | 324 | } |
---|
[5929] | 325 | |
---|
| 326 | void HumanController::cycleNavigationFocus() |
---|
| 327 | { |
---|
| 328 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 329 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus(); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | void HumanController::releaseNavigationFocus() |
---|
| 333 | { |
---|
| 334 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 335 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus(); |
---|
| 336 | } |
---|
[6417] | 337 | |
---|
| 338 | void HumanController::pauseControl() |
---|
| 339 | { |
---|
| 340 | if (HumanController::localController_s) |
---|
| 341 | HumanController::localController_s->doPauseControl(); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | void HumanController::resumeControl() |
---|
| 345 | { |
---|
| 346 | if (HumanController::localController_s) |
---|
| 347 | HumanController::localController_s->doResumeControl(); |
---|
| 348 | } |
---|
[2072] | 349 | } |
---|