[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" |
---|
| 33 | #include "objects/worldentities/ControllableEntity.h" |
---|
[2662] | 34 | #include "objects/worldentities/pawns/Pawn.h" |
---|
| 35 | #include "objects/gametypes/Gametype.h" |
---|
[2872] | 36 | #include "objects/infos/PlayerInfo.h" |
---|
[3089] | 37 | #include "overlays/map/Map.h" |
---|
[2072] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand(); |
---|
| 42 | SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand(); |
---|
| 43 | SetConsoleCommand(HumanController, moveUpDown, true).setAsInputCommand(); |
---|
| 44 | SetConsoleCommand(HumanController, rotateYaw, true).setAsInputCommand(); |
---|
| 45 | SetConsoleCommand(HumanController, rotatePitch, true).setAsInputCommand(); |
---|
| 46 | SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); |
---|
| 47 | SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); |
---|
[3053] | 48 | SetConsoleCommand(HumanController, reload, true); |
---|
[2662] | 49 | SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); |
---|
[2072] | 50 | SetConsoleCommand(HumanController, greet, true); |
---|
| 51 | SetConsoleCommand(HumanController, switchCamera, true); |
---|
[2662] | 52 | SetConsoleCommand(HumanController, mouseLook, true); |
---|
| 53 | SetConsoleCommand(HumanController, suicide, true); |
---|
| 54 | SetConsoleCommand(HumanController, addBots, true).defaultValues(1); |
---|
| 55 | SetConsoleCommand(HumanController, killBots, true).defaultValues(0); |
---|
| 56 | SetConsoleCommand(HumanController, dropItems, true); |
---|
[3073] | 57 | SetConsoleCommand(HumanController, useItem, true); |
---|
[2072] | 58 | |
---|
| 59 | CreateUnloadableFactory(HumanController); |
---|
| 60 | |
---|
| 61 | HumanController* HumanController::localController_s = 0; |
---|
| 62 | |
---|
| 63 | HumanController::HumanController(BaseObject* creator) : Controller(creator) |
---|
| 64 | { |
---|
| 65 | RegisterObject(HumanController); |
---|
| 66 | |
---|
| 67 | HumanController::localController_s = this; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | HumanController::~HumanController() |
---|
| 71 | { |
---|
| 72 | HumanController::localController_s = 0; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void HumanController::moveFrontBack(const Vector2& value) |
---|
| 76 | { |
---|
| 77 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 78 | HumanController::localController_s->controllableEntity_->moveFrontBack(value); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void HumanController::moveRightLeft(const Vector2& value) |
---|
| 82 | { |
---|
| 83 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 84 | HumanController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void HumanController::moveUpDown(const Vector2& value) |
---|
| 88 | { |
---|
| 89 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 90 | HumanController::localController_s->controllableEntity_->moveUpDown(value); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void HumanController::rotateYaw(const Vector2& value) |
---|
| 94 | { |
---|
[3089] | 95 | //Hack to enable mouselook in map |
---|
| 96 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
| 97 | { |
---|
| 98 | Map::getSingletonPtr()->rotateYaw(value); |
---|
| 99 | return; |
---|
| 100 | } |
---|
[2072] | 101 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 102 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void HumanController::rotatePitch(const Vector2& value) |
---|
| 106 | { |
---|
[3089] | 107 | //Hack to enable mouselook in map |
---|
| 108 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
| 109 | { |
---|
| 110 | Map::getSingletonPtr()->rotatePitch(value); |
---|
| 111 | return; |
---|
| 112 | } |
---|
[2072] | 113 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 114 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void HumanController::rotateRoll(const Vector2& value) |
---|
| 118 | { |
---|
| 119 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 120 | HumanController::localController_s->controllableEntity_->rotateRoll(value); |
---|
| 121 | } |
---|
| 122 | |
---|
[3053] | 123 | void HumanController::fire(unsigned int firemode) |
---|
[2072] | 124 | { |
---|
| 125 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 126 | HumanController::localController_s->controllableEntity_->fire(firemode); |
---|
[2072] | 127 | } |
---|
| 128 | |
---|
[3053] | 129 | void HumanController::reload() |
---|
[2072] | 130 | { |
---|
| 131 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
[3053] | 132 | HumanController::localController_s->controllableEntity_->reload(); |
---|
[2072] | 133 | } |
---|
| 134 | |
---|
[2662] | 135 | void HumanController::boost() |
---|
| 136 | { |
---|
| 137 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 138 | HumanController::localController_s->controllableEntity_->boost(); |
---|
| 139 | } |
---|
| 140 | |
---|
[2072] | 141 | void HumanController::greet() |
---|
| 142 | { |
---|
| 143 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 144 | HumanController::localController_s->controllableEntity_->greet(); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void HumanController::switchCamera() |
---|
| 148 | { |
---|
| 149 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 150 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
| 151 | } |
---|
[2662] | 152 | |
---|
| 153 | void HumanController::mouseLook() |
---|
| 154 | { |
---|
| 155 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 156 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | void HumanController::suicide() |
---|
| 160 | { |
---|
| 161 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 162 | { |
---|
| 163 | Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
| 164 | if (pawn) |
---|
| 165 | pawn->kill(); |
---|
[2872] | 166 | else if (HumanController::localController_s->player_) |
---|
[3038] | 167 | HumanController::localController_s->player_->stopControl(); |
---|
[2662] | 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
[3073] | 171 | void HumanController::useItem() |
---|
| 172 | { |
---|
| 173 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 174 | HumanController::localController_s->controllableEntity_->useItem(); |
---|
| 175 | } |
---|
| 176 | |
---|
[2662] | 177 | void HumanController::addBots(unsigned int amount) |
---|
| 178 | { |
---|
| 179 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 180 | HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | void HumanController::killBots(unsigned int amount) |
---|
| 184 | { |
---|
| 185 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
| 186 | HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | void HumanController::dropItems() |
---|
| 190 | { |
---|
| 191 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
| 192 | HumanController::localController_s->controllableEntity_->dropItems(); |
---|
| 193 | } |
---|
[3196] | 194 | |
---|
| 195 | Pawn* HumanController::getLocalControllerEntityAsPawn() |
---|
| 196 | { |
---|
| 197 | if (HumanController::localController_s) |
---|
| 198 | return dynamic_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); |
---|
| 199 | else |
---|
| 200 | return NULL; |
---|
| 201 | } |
---|
[2072] | 202 | } |
---|