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->aimAtTarget(); |
---|
62 | this->doFire(); |
---|
63 | this->bShooting_ = true; |
---|
64 | }*/ |
---|
65 | |
---|
66 | if (this->bHasTargetPosition_) |
---|
67 | { |
---|
68 | this->moveToTargetPosition(); |
---|
69 | } |
---|
70 | if (this->bShooting_) |
---|
71 | doFire(); |
---|
72 | SUPER(DivisionController, tick, dt); |
---|
73 | |
---|
74 | } |
---|
75 | void DivisionController::action() |
---|
76 | { |
---|
77 | /* |
---|
78 | Vector3* pos = new Vector3(4000,1000,2000); |
---|
79 | this->setTargetPosition(*pos);*/ |
---|
80 | |
---|
81 | setTargetPositionOfFollower(); |
---|
82 | setTargetPositionOfWingman(); |
---|
83 | |
---|
84 | |
---|
85 | if (this->myFollower_ && this->target_) |
---|
86 | this->myFollower_->setTarget(this->target_); |
---|
87 | if (this->target_ && this->myWingman_) |
---|
88 | this->myWingman_->setTarget(this->target_); |
---|
89 | /* |
---|
90 | for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) |
---|
91 | { |
---|
92 | if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0) |
---|
93 | { |
---|
94 | this->setTargetPosition(it->getControllableEntity()->getWorldPosition()); |
---|
95 | |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | */ |
---|
100 | if (canFire()) |
---|
101 | this->bShooting_ = true; |
---|
102 | else |
---|
103 | this->bShooting_ = false; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | void DivisionController::setTargetPositionOfWingman() |
---|
109 | { |
---|
110 | if (!this->myWingman_) |
---|
111 | return; |
---|
112 | Vector3* targetRelativePositionOfWingman; |
---|
113 | switch (this->formationMode_){ |
---|
114 | case FormationMode::WALL: |
---|
115 | { |
---|
116 | targetRelativePositionOfWingman = new Vector3 (400, 0, 0); |
---|
117 | break; |
---|
118 | } |
---|
119 | case FormationMode::FINGER4: |
---|
120 | { |
---|
121 | targetRelativePositionOfWingman = new Vector3 (400, 0, -200); |
---|
122 | break; |
---|
123 | } |
---|
124 | case FormationMode::VEE: |
---|
125 | { |
---|
126 | break; |
---|
127 | } |
---|
128 | case FormationMode::DIAMOND: |
---|
129 | { |
---|
130 | targetRelativePositionOfWingman = new Vector3 (400, 0, -200); |
---|
131 | break; |
---|
132 | } |
---|
133 | } |
---|
134 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
135 | |
---|
136 | Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + |
---|
137 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); |
---|
138 | |
---|
139 | myWingman_->setTargetOrientation(orient); |
---|
140 | myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); |
---|
141 | |
---|
142 | } |
---|
143 | void DivisionController::setTargetPositionOfFollower() |
---|
144 | { |
---|
145 | if (!this->myFollower_) |
---|
146 | return; |
---|
147 | this->myFollower_->setFormationMode(this->formationMode_); |
---|
148 | |
---|
149 | Vector3* targetRelativePositionOfFollower; |
---|
150 | switch (this->formationMode_){ |
---|
151 | case FormationMode::WALL: |
---|
152 | { |
---|
153 | targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); |
---|
154 | break; |
---|
155 | } |
---|
156 | case FormationMode::FINGER4: |
---|
157 | { |
---|
158 | targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); |
---|
159 | break; |
---|
160 | } |
---|
161 | case FormationMode::VEE: |
---|
162 | { |
---|
163 | break; |
---|
164 | } |
---|
165 | case FormationMode::DIAMOND: |
---|
166 | { |
---|
167 | targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); |
---|
168 | break; |
---|
169 | } |
---|
170 | } |
---|
171 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
172 | |
---|
173 | Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + |
---|
174 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); |
---|
175 | |
---|
176 | myFollower_->setTargetOrientation(orient); |
---|
177 | myFollower_->setTargetPosition(targetAbsolutePositionOfFollower); |
---|
178 | |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | bool DivisionController::setWingman(CommonController* cwingman) |
---|
183 | { |
---|
184 | |
---|
185 | WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); |
---|
186 | if (!this->myWingman_) |
---|
187 | { |
---|
188 | this->myWingman_ = wingman; |
---|
189 | return true; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | return false; |
---|
194 | } |
---|
195 | |
---|
196 | } |
---|
197 | bool DivisionController::setFollower(LeaderController* myFollower) |
---|
198 | { |
---|
199 | if (!this->myFollower_) |
---|
200 | { |
---|
201 | this->myFollower_ = myFollower; |
---|
202 | return true; |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | return false; |
---|
207 | } |
---|
208 | } |
---|
209 | bool DivisionController::hasWingman() |
---|
210 | { |
---|
211 | if (this->myWingman_) |
---|
212 | return true; |
---|
213 | else |
---|
214 | return false; |
---|
215 | } |
---|
216 | bool DivisionController::hasFollower() |
---|
217 | { |
---|
218 | if (this->myFollower_) |
---|
219 | return true; |
---|
220 | else |
---|
221 | return false; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
226 | { |
---|
227 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
228 | |
---|
229 | //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | } |
---|