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 "worldentities/ControllableEntity.h" |
---|
34 | #include "worldentities/pawns/Pawn.h" |
---|
35 | #include "gametypes/Gametype.h" |
---|
36 | #include "infos/PlayerInfo.h" |
---|
37 | #include "overlays/Map.h" |
---|
38 | #include "graphics/Camera.h" |
---|
39 | #include "sound/SoundManager.h" |
---|
40 | #include "Radar.h" |
---|
41 | #include "Scene.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand(); |
---|
46 | SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand(); |
---|
47 | SetConsoleCommand(HumanController, moveUpDown, true).setAsInputCommand(); |
---|
48 | SetConsoleCommand(HumanController, rotateYaw, true).setAsInputCommand(); |
---|
49 | SetConsoleCommand(HumanController, rotatePitch, true).setAsInputCommand(); |
---|
50 | SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); |
---|
51 | SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); |
---|
52 | SetConsoleCommand(HumanController, reload, true); |
---|
53 | SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); |
---|
54 | SetConsoleCommand(HumanController, greet, true); |
---|
55 | SetConsoleCommand(HumanController, switchCamera, true); |
---|
56 | SetConsoleCommand(HumanController, mouseLook, true); |
---|
57 | SetConsoleCommand(HumanController, suicide, true); |
---|
58 | SetConsoleCommand(HumanController, addBots, true).defaultValues(1); |
---|
59 | SetConsoleCommand(HumanController, killBots, true).defaultValues(0); |
---|
60 | SetConsoleCommand(HumanController, dropItems, true); |
---|
61 | SetConsoleCommand(HumanController, useItem, true); |
---|
62 | SetConsoleCommand(HumanController, cycleNavigationFocus, true); |
---|
63 | SetConsoleCommand(HumanController, releaseNavigationFocus, true); |
---|
64 | |
---|
65 | CreateUnloadableFactory(HumanController); |
---|
66 | |
---|
67 | HumanController* HumanController::localController_s = 0; |
---|
68 | |
---|
69 | HumanController::HumanController(BaseObject* creator) : Controller(creator) |
---|
70 | { |
---|
71 | RegisterObject(HumanController); |
---|
72 | |
---|
73 | HumanController::localController_s = this; |
---|
74 | } |
---|
75 | |
---|
76 | HumanController::~HumanController() |
---|
77 | { |
---|
78 | HumanController::localController_s = 0; |
---|
79 | } |
---|
80 | |
---|
81 | void HumanController::tick(float dt) |
---|
82 | { |
---|
83 | if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
84 | { |
---|
85 | // Update sound listener |
---|
86 | Camera* camera = HumanController::localController_s->controllableEntity_->getCamera(); |
---|
87 | if (camera) |
---|
88 | { |
---|
89 | SoundManager::getInstance().setListenerPosition(camera->getWorldPosition()); |
---|
90 | SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation()); |
---|
91 | } |
---|
92 | else |
---|
93 | COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | void HumanController::moveFrontBack(const Vector2& value) |
---|
98 | { |
---|
99 | if (HumanController::localController_s) |
---|
100 | HumanController::localController_s->frontback(value); |
---|
101 | } |
---|
102 | |
---|
103 | void HumanController::frontback(const Vector2& value) |
---|
104 | { |
---|
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 | |
---|
121 | void HumanController::yaw(const Vector2& value) |
---|
122 | { |
---|
123 | //Hack to enable mouselook in map |
---|
124 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
125 | { |
---|
126 | Map::getSingletonPtr()->rotateYaw(value); |
---|
127 | return; |
---|
128 | } |
---|
129 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
130 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
131 | } |
---|
132 | |
---|
133 | void HumanController::pitch(const Vector2& value) |
---|
134 | { |
---|
135 | //Hack to enable mouselook in map |
---|
136 | if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() ) |
---|
137 | { |
---|
138 | Map::getSingletonPtr()->rotatePitch(value); |
---|
139 | return; |
---|
140 | } |
---|
141 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
142 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
143 | } |
---|
144 | |
---|
145 | void HumanController::rotateYaw(const Vector2& value) |
---|
146 | { |
---|
147 | if (HumanController::localController_s) |
---|
148 | HumanController::localController_s->yaw(value); |
---|
149 | } |
---|
150 | |
---|
151 | void HumanController::rotatePitch(const Vector2& value) |
---|
152 | { |
---|
153 | if (HumanController::localController_s) |
---|
154 | HumanController::localController_s->pitch(value); |
---|
155 | } |
---|
156 | |
---|
157 | void HumanController::rotateRoll(const Vector2& value) |
---|
158 | { |
---|
159 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
160 | HumanController::localController_s->controllableEntity_->rotateRoll(value); |
---|
161 | } |
---|
162 | |
---|
163 | void HumanController::fire(unsigned int firemode) |
---|
164 | { |
---|
165 | if (HumanController::localController_s) |
---|
166 | HumanController::localController_s->doFire(firemode); |
---|
167 | } |
---|
168 | |
---|
169 | void HumanController::doFire(unsigned int firemode) |
---|
170 | { |
---|
171 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
172 | HumanController::localController_s->controllableEntity_->fire(firemode); |
---|
173 | } |
---|
174 | |
---|
175 | void HumanController::reload() |
---|
176 | { |
---|
177 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
178 | HumanController::localController_s->controllableEntity_->reload(); |
---|
179 | } |
---|
180 | |
---|
181 | void HumanController::boost() |
---|
182 | { |
---|
183 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
184 | HumanController::localController_s->controllableEntity_->boost(); |
---|
185 | } |
---|
186 | |
---|
187 | void HumanController::greet() |
---|
188 | { |
---|
189 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
190 | HumanController::localController_s->controllableEntity_->greet(); |
---|
191 | } |
---|
192 | |
---|
193 | void HumanController::switchCamera() |
---|
194 | { |
---|
195 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
196 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
197 | } |
---|
198 | |
---|
199 | void HumanController::mouseLook() |
---|
200 | { |
---|
201 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
202 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
203 | } |
---|
204 | |
---|
205 | void HumanController::suicide() |
---|
206 | { |
---|
207 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
208 | { |
---|
209 | Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
210 | if (pawn) |
---|
211 | pawn->kill(); |
---|
212 | else if (HumanController::localController_s->player_) |
---|
213 | HumanController::localController_s->player_->stopControl(); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | void HumanController::useItem() |
---|
218 | { |
---|
219 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
220 | HumanController::localController_s->controllableEntity_->useItem(); |
---|
221 | } |
---|
222 | |
---|
223 | void HumanController::addBots(unsigned int amount) |
---|
224 | { |
---|
225 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
226 | HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); |
---|
227 | } |
---|
228 | |
---|
229 | void HumanController::killBots(unsigned int amount) |
---|
230 | { |
---|
231 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
232 | HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); |
---|
233 | } |
---|
234 | |
---|
235 | void HumanController::dropItems() |
---|
236 | { |
---|
237 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
238 | HumanController::localController_s->controllableEntity_->dropItems(); |
---|
239 | } |
---|
240 | |
---|
241 | Pawn* HumanController::getLocalControllerEntityAsPawn() |
---|
242 | { |
---|
243 | if (HumanController::localController_s) |
---|
244 | return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); |
---|
245 | else |
---|
246 | return NULL; |
---|
247 | } |
---|
248 | |
---|
249 | void HumanController::cycleNavigationFocus() |
---|
250 | { |
---|
251 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
252 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus(); |
---|
253 | } |
---|
254 | |
---|
255 | void HumanController::releaseNavigationFocus() |
---|
256 | { |
---|
257 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
258 | HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus(); |
---|
259 | } |
---|
260 | } |
---|