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