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 | * Dominik Solenicki |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "DivisionController.h" |
---|
30 | |
---|
31 | |
---|
32 | namespace orxonox |
---|
33 | { |
---|
34 | |
---|
35 | RegisterClass(DivisionController); |
---|
36 | |
---|
37 | DivisionController::DivisionController(Context* context) : LeaderController(context) |
---|
38 | { |
---|
39 | RegisterObject(DivisionController); |
---|
40 | |
---|
41 | this->setFormationMode(FormationMode::DIAMOND); |
---|
42 | this->target_ = 0; |
---|
43 | this->myFollower_ = 0; |
---|
44 | this->myWingman_ = 0; |
---|
45 | this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); |
---|
46 | this->rank_ = Rank::DIVISIONLEADER; |
---|
47 | |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | DivisionController::~DivisionController() |
---|
52 | { |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | void DivisionController::tick(float dt) |
---|
58 | { |
---|
59 | if (this->target_ ) |
---|
60 | { |
---|
61 | this->setPositionOfTarget(target_->getWorldPosition()); |
---|
62 | |
---|
63 | } |
---|
64 | /*if (this->target_) |
---|
65 | { |
---|
66 | this->aimAtTarget(); |
---|
67 | this->doFire(); |
---|
68 | this->bShooting_ = true; |
---|
69 | }*/ |
---|
70 | |
---|
71 | /* if (this->bHasTargetPosition_) |
---|
72 | { |
---|
73 | this->moveToTargetPosition(); |
---|
74 | }*/ |
---|
75 | if (executingMoveToPoint_) |
---|
76 | { |
---|
77 | executingMoveToPoint_ = !this->moveAndRoll(dt); |
---|
78 | } |
---|
79 | if (this->bShooting_) |
---|
80 | doFire(); |
---|
81 | SUPER(DivisionController, tick, dt); |
---|
82 | |
---|
83 | } |
---|
84 | void DivisionController::action() |
---|
85 | { |
---|
86 | /* |
---|
87 | Vector3* pos = new Vector3(4000,1000,2000); |
---|
88 | this->setTargetPosition(*pos);*/ |
---|
89 | |
---|
90 | /* if (!this->target_) |
---|
91 | { |
---|
92 | |
---|
93 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) |
---|
94 | { |
---|
95 | if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*it)->getTeam()) |
---|
96 | continue; |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) |
---|
101 | { |
---|
102 | this->setTarget(*it); |
---|
103 | } |
---|
104 | } |
---|
105 | }*/ |
---|
106 | this->chooseManeuverType(); |
---|
107 | switch (this->maneuverType_) |
---|
108 | { |
---|
109 | case ManeuverType::NONE: |
---|
110 | { |
---|
111 | setTargetPositionOfFollower(); |
---|
112 | setTargetPositionOfWingman(); |
---|
113 | break; |
---|
114 | } |
---|
115 | case ManeuverType::DEFENSIVE: |
---|
116 | { |
---|
117 | this->gunsD(); |
---|
118 | } |
---|
119 | case ManeuverType::OFFENSIVE: |
---|
120 | { |
---|
121 | this->attack(); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | if (!executingMoveToPoint_) |
---|
126 | { |
---|
127 | Vector3* targetPosition = new Vector3 (0, 0, -2000); |
---|
128 | moveToPoint(*targetPosition, 180); |
---|
129 | executingMoveToPoint_ = true; |
---|
130 | } |
---|
131 | |
---|
132 | if (this->myFollower_ && this->target_) |
---|
133 | this->myFollower_->setTarget(this->target_); |
---|
134 | if (this->target_ && this->myWingman_) |
---|
135 | this->myWingman_->setTarget(this->target_); |
---|
136 | /* |
---|
137 | for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) |
---|
138 | { |
---|
139 | if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0) |
---|
140 | { |
---|
141 | this->setTargetPosition(it->getControllableEntity()->getWorldPosition()); |
---|
142 | |
---|
143 | break; |
---|
144 | } |
---|
145 | } |
---|
146 | */ |
---|
147 | if (canFire()) |
---|
148 | this->bShooting_ = true; |
---|
149 | else |
---|
150 | this->bShooting_ = false; |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | void DivisionController::setTargetPositionOfWingman() |
---|
156 | { |
---|
157 | if (!this->myWingman_) |
---|
158 | return; |
---|
159 | Vector3* targetRelativePositionOfWingman; |
---|
160 | switch (this->formationMode_){ |
---|
161 | case FormationMode::WALL: |
---|
162 | { |
---|
163 | targetRelativePositionOfWingman = new Vector3 (400, 0, 0); |
---|
164 | break; |
---|
165 | } |
---|
166 | case FormationMode::FINGER4: |
---|
167 | { |
---|
168 | targetRelativePositionOfWingman = new Vector3 (400, 0, -200); |
---|
169 | break; |
---|
170 | } |
---|
171 | case FormationMode::VEE: |
---|
172 | { |
---|
173 | break; |
---|
174 | } |
---|
175 | case FormationMode::DIAMOND: |
---|
176 | { |
---|
177 | targetRelativePositionOfWingman = new Vector3 (400, 0, -200); |
---|
178 | break; |
---|
179 | } |
---|
180 | } |
---|
181 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
182 | |
---|
183 | Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + |
---|
184 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); |
---|
185 | |
---|
186 | myWingman_->setTargetOrientation(orient); |
---|
187 | myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); |
---|
188 | |
---|
189 | } |
---|
190 | void DivisionController::setTargetPositionOfFollower() |
---|
191 | { |
---|
192 | if (!this->myFollower_) |
---|
193 | return; |
---|
194 | this->myFollower_->setFormationMode(this->formationMode_); |
---|
195 | |
---|
196 | Vector3* targetRelativePositionOfFollower; |
---|
197 | switch (this->formationMode_){ |
---|
198 | case FormationMode::WALL: |
---|
199 | { |
---|
200 | targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); |
---|
201 | break; |
---|
202 | } |
---|
203 | case FormationMode::FINGER4: |
---|
204 | { |
---|
205 | targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); |
---|
206 | break; |
---|
207 | } |
---|
208 | case FormationMode::VEE: |
---|
209 | { |
---|
210 | break; |
---|
211 | } |
---|
212 | case FormationMode::DIAMOND: |
---|
213 | { |
---|
214 | targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); |
---|
215 | break; |
---|
216 | } |
---|
217 | } |
---|
218 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
219 | |
---|
220 | Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + |
---|
221 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); |
---|
222 | |
---|
223 | myFollower_->setTargetOrientation(orient); |
---|
224 | myFollower_->setTargetPosition(targetAbsolutePositionOfFollower); |
---|
225 | |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | bool DivisionController::setWingman(CommonController* cwingman) |
---|
230 | { |
---|
231 | |
---|
232 | WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); |
---|
233 | if (!this->myWingman_) |
---|
234 | { |
---|
235 | this->myWingman_ = wingman; |
---|
236 | return true; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | return false; |
---|
241 | } |
---|
242 | |
---|
243 | } |
---|
244 | bool DivisionController::setFollower(LeaderController* myFollower) |
---|
245 | { |
---|
246 | if (!this->myFollower_) |
---|
247 | { |
---|
248 | this->myFollower_ = myFollower; |
---|
249 | return true; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | return false; |
---|
254 | } |
---|
255 | } |
---|
256 | bool DivisionController::hasWingman() |
---|
257 | { |
---|
258 | if (this->myWingman_) |
---|
259 | return true; |
---|
260 | else |
---|
261 | return false; |
---|
262 | } |
---|
263 | bool DivisionController::hasFollower() |
---|
264 | { |
---|
265 | if (this->myFollower_) |
---|
266 | return true; |
---|
267 | else |
---|
268 | return false; |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
273 | { |
---|
274 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
275 | |
---|
276 | //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | } |
---|