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