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 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand(); |
---|
41 | SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand(); |
---|
42 | SetConsoleCommand(HumanController, moveUpDown, true).setAsInputCommand(); |
---|
43 | SetConsoleCommand(HumanController, rotateYaw, true).setAsInputCommand(); |
---|
44 | SetConsoleCommand(HumanController, rotatePitch, true).setAsInputCommand(); |
---|
45 | SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); |
---|
46 | SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); |
---|
47 | SetConsoleCommand(HumanController, altFire, true).keybindMode(KeybindMode::OnHold); |
---|
48 | SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); |
---|
49 | SetConsoleCommand(HumanController, greet, true); |
---|
50 | SetConsoleCommand(HumanController, switchCamera, true); |
---|
51 | SetConsoleCommand(HumanController, mouseLook, true); |
---|
52 | SetConsoleCommand(HumanController, suicide, true); |
---|
53 | SetConsoleCommand(HumanController, addBots, true).defaultValues(1); |
---|
54 | SetConsoleCommand(HumanController, killBots, true).defaultValues(0); |
---|
55 | SetConsoleCommand(HumanController, dropItems, true); |
---|
56 | SetConsoleCommand(HumanController, useItem, true); |
---|
57 | |
---|
58 | CreateUnloadableFactory(HumanController); |
---|
59 | |
---|
60 | HumanController* HumanController::localController_s = 0; |
---|
61 | |
---|
62 | HumanController::HumanController(BaseObject* creator) : Controller(creator) |
---|
63 | { |
---|
64 | RegisterObject(HumanController); |
---|
65 | |
---|
66 | HumanController::localController_s = this; |
---|
67 | } |
---|
68 | |
---|
69 | HumanController::~HumanController() |
---|
70 | { |
---|
71 | HumanController::localController_s = 0; |
---|
72 | } |
---|
73 | |
---|
74 | void HumanController::moveFrontBack(const Vector2& value) |
---|
75 | { |
---|
76 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
77 | HumanController::localController_s->controllableEntity_->moveFrontBack(value); |
---|
78 | } |
---|
79 | |
---|
80 | void HumanController::moveRightLeft(const Vector2& value) |
---|
81 | { |
---|
82 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
83 | HumanController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
84 | } |
---|
85 | |
---|
86 | void HumanController::moveUpDown(const Vector2& value) |
---|
87 | { |
---|
88 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
89 | HumanController::localController_s->controllableEntity_->moveUpDown(value); |
---|
90 | } |
---|
91 | |
---|
92 | void HumanController::rotateYaw(const Vector2& value) |
---|
93 | { |
---|
94 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
95 | HumanController::localController_s->controllableEntity_->rotateYaw(value); |
---|
96 | } |
---|
97 | |
---|
98 | void HumanController::rotatePitch(const Vector2& value) |
---|
99 | { |
---|
100 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
101 | HumanController::localController_s->controllableEntity_->rotatePitch(value); |
---|
102 | } |
---|
103 | |
---|
104 | void HumanController::rotateRoll(const Vector2& value) |
---|
105 | { |
---|
106 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
107 | HumanController::localController_s->controllableEntity_->rotateRoll(value); |
---|
108 | } |
---|
109 | |
---|
110 | void HumanController::fire() |
---|
111 | { |
---|
112 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
113 | HumanController::localController_s->controllableEntity_->fire(WeaponMode::fire); |
---|
114 | } |
---|
115 | |
---|
116 | void HumanController::altFire() |
---|
117 | { |
---|
118 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
119 | HumanController::localController_s->controllableEntity_->fire(WeaponMode::altFire); |
---|
120 | } |
---|
121 | |
---|
122 | void HumanController::boost() |
---|
123 | { |
---|
124 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
125 | HumanController::localController_s->controllableEntity_->boost(); |
---|
126 | } |
---|
127 | |
---|
128 | void HumanController::greet() |
---|
129 | { |
---|
130 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
131 | HumanController::localController_s->controllableEntity_->greet(); |
---|
132 | } |
---|
133 | |
---|
134 | void HumanController::switchCamera() |
---|
135 | { |
---|
136 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
137 | HumanController::localController_s->controllableEntity_->switchCamera(); |
---|
138 | } |
---|
139 | |
---|
140 | void HumanController::mouseLook() |
---|
141 | { |
---|
142 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
143 | HumanController::localController_s->controllableEntity_->mouseLook(); |
---|
144 | } |
---|
145 | |
---|
146 | void HumanController::suicide() |
---|
147 | { |
---|
148 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
149 | { |
---|
150 | Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_); |
---|
151 | if (pawn) |
---|
152 | pawn->kill(); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | void HumanController::useItem() |
---|
157 | { |
---|
158 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
159 | HumanController::localController_s->controllableEntity_->useItem(); |
---|
160 | } |
---|
161 | |
---|
162 | void HumanController::addBots(unsigned int amount) |
---|
163 | { |
---|
164 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
165 | HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); |
---|
166 | } |
---|
167 | |
---|
168 | void HumanController::killBots(unsigned int amount) |
---|
169 | { |
---|
170 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) |
---|
171 | HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); |
---|
172 | } |
---|
173 | |
---|
174 | void HumanController::dropItems() |
---|
175 | { |
---|
176 | if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) |
---|
177 | HumanController::localController_s->controllableEntity_->dropItems(); |
---|
178 | } |
---|
179 | } |
---|