1 | #include "PacmanRandom.h" |
---|
2 | |
---|
3 | #include "core/CoreIncludes.h" |
---|
4 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | namespace orxonox { |
---|
10 | |
---|
11 | |
---|
12 | RegisterClass(PacmanRandom); |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | PacmanRandom::PacmanRandom(Context* context) : PacmanGhost(context){ |
---|
17 | |
---|
18 | RegisterObject(PacmanRandom); |
---|
19 | |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | /** |
---|
24 | @brief |
---|
25 | Method for creating a ghost through XML. |
---|
26 | */ |
---|
27 | void PacmanRandom::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
28 | { |
---|
29 | SUPER(PacmanRandom, XMLPort, xmlelement, mode); |
---|
30 | } |
---|
31 | |
---|
32 | void PacmanRandom::tick(float dt) |
---|
33 | { |
---|
34 | SUPER(PacmanGhost, tick, dt); |
---|
35 | |
---|
36 | this->actuelposition = this->getPosition(); |
---|
37 | |
---|
38 | //Stop, if target arrived |
---|
39 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
40 | this->ismoving = false; |
---|
41 | } |
---|
42 | |
---|
43 | //Move, if ghost hasn't arrived yet |
---|
44 | if(this->ismoving){ |
---|
45 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
46 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
47 | move(dt, actuelposition, velocity); |
---|
48 | } |
---|
49 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
50 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
51 | move(dt, actuelposition, velocity); |
---|
52 | } |
---|
53 | } |
---|
54 | //Check on which position the ghost has arrived and set new target |
---|
55 | else{ |
---|
56 | while(lockmove){}; |
---|
57 | lockmove = true; |
---|
58 | |
---|
59 | if(findpos(actuelposition,possibleposition[0])){ |
---|
60 | setnewTarget(1,17,19); |
---|
61 | } |
---|
62 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
63 | setnewTarget(0,2); |
---|
64 | } |
---|
65 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
66 | setnewTarget(1,3); |
---|
67 | } |
---|
68 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
69 | setnewTarget(2,4,5); |
---|
70 | } |
---|
71 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
72 | setnewTarget(3,6); |
---|
73 | } |
---|
74 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
75 | setnewTarget(3,7); |
---|
76 | } |
---|
77 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
78 | setnewTarget(4,9,26); |
---|
79 | } |
---|
80 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
81 | setnewTarget(5,8); |
---|
82 | } |
---|
83 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
84 | setnewTarget(7,9); |
---|
85 | } |
---|
86 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
87 | setnewTarget(6,8,10,38); |
---|
88 | } |
---|
89 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
90 | setnewTarget(9,11,45); |
---|
91 | } |
---|
92 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
93 | setnewTarget(10,12,13); |
---|
94 | } |
---|
95 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
96 | setnewTarget(11,14); |
---|
97 | } |
---|
98 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
99 | setnewTarget(11,14,16,61); |
---|
100 | } |
---|
101 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
102 | setnewTarget(12,13,15); |
---|
103 | } |
---|
104 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
105 | setnewTarget(14,16); |
---|
106 | } |
---|
107 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
108 | setnewTarget(13,15,62); |
---|
109 | } |
---|
110 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
111 | setnewTarget(0,25); |
---|
112 | } |
---|
113 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
114 | setnewTarget(19,24); |
---|
115 | } |
---|
116 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
117 | setnewTarget(0,18,20); |
---|
118 | } |
---|
119 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
120 | setnewTarget(19,21); |
---|
121 | } |
---|
122 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
123 | setnewTarget(20,22); |
---|
124 | } |
---|
125 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
126 | setnewTarget(21,23,31); |
---|
127 | } |
---|
128 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
129 | setnewTarget(22,30); |
---|
130 | } |
---|
131 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
132 | setnewTarget(18,29); |
---|
133 | } |
---|
134 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
135 | setnewTarget(17,26); |
---|
136 | } |
---|
137 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
138 | setnewTarget(6,25,27); |
---|
139 | } |
---|
140 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
141 | setnewTarget(26,28,37); |
---|
142 | } |
---|
143 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
144 | setnewTarget(27,29,36); |
---|
145 | } |
---|
146 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
147 | setnewTarget(24,28,30); |
---|
148 | } |
---|
149 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
150 | setnewTarget(23,29,34); |
---|
151 | } |
---|
152 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
153 | setnewTarget(22,32); |
---|
154 | } |
---|
155 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
156 | setnewTarget(31,33); |
---|
157 | } |
---|
158 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
159 | setnewTarget(32,34); |
---|
160 | } |
---|
161 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
162 | setnewTarget(30,33,35,42); |
---|
163 | } |
---|
164 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
165 | setnewTarget(34,36,41); |
---|
166 | } |
---|
167 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
168 | setnewTarget(28,35); |
---|
169 | } |
---|
170 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
171 | setnewTarget(27,38); |
---|
172 | } |
---|
173 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
174 | setnewTarget(9,37,39); |
---|
175 | } |
---|
176 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
177 | setnewTarget(38,40,45); |
---|
178 | } |
---|
179 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
180 | setnewTarget(39,41); //Shouldn't be able to return in center |
---|
181 | } |
---|
182 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
183 | setnewTarget(35,43); |
---|
184 | } |
---|
185 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
186 | setnewTarget(34,43,54); |
---|
187 | } |
---|
188 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
189 | setnewTarget(41,46); |
---|
190 | } |
---|
191 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
192 | setnewTarget(40,66); |
---|
193 | } |
---|
194 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
195 | setnewTarget(10,39,49); |
---|
196 | } |
---|
197 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
198 | setnewTarget(43,47); |
---|
199 | } |
---|
200 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
201 | setnewTarget(46,52,66); |
---|
202 | } |
---|
203 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
204 | setnewTarget(49,51,66); |
---|
205 | } |
---|
206 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
207 | setnewTarget(45,48); |
---|
208 | } |
---|
209 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
210 | setnewTarget(51,61); |
---|
211 | } |
---|
212 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
213 | setnewTarget(48,50); |
---|
214 | } |
---|
215 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
216 | setnewTarget(47,53); |
---|
217 | } |
---|
218 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
219 | setnewTarget(52,58); |
---|
220 | } |
---|
221 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
222 | setnewTarget(42,55,57); |
---|
223 | } |
---|
224 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
225 | setnewTarget(54,56); |
---|
226 | } |
---|
227 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
228 | setnewTarget(55,57,65); |
---|
229 | } |
---|
230 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
231 | setnewTarget(54,56,58,64); |
---|
232 | } |
---|
233 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
234 | setnewTarget(53,57,59); |
---|
235 | } |
---|
236 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
237 | setnewTarget(58,59,63); |
---|
238 | } |
---|
239 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
240 | setnewTarget(59,61,62); |
---|
241 | } |
---|
242 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
243 | setnewTarget(13,50,60); |
---|
244 | } |
---|
245 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
246 | setnewTarget(16,60); |
---|
247 | } |
---|
248 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
249 | setnewTarget(59,64); |
---|
250 | } |
---|
251 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
252 | setnewTarget(57,63,65); |
---|
253 | } |
---|
254 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
255 | setnewTarget(56,64); |
---|
256 | } |
---|
257 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
258 | setnewTarget(47,48); |
---|
259 | } |
---|
260 | |
---|
261 | else{ |
---|
262 | this->resetGhost(); //Shouldn't happen... |
---|
263 | } //End of Position table |
---|
264 | lockmove = false; //never forget this one !!!! |
---|
265 | } |
---|
266 | |
---|
267 | } |
---|
268 | |
---|
269 | void PacmanRandom::setnewTarget(int firstdec){ |
---|
270 | |
---|
271 | decision = rand()%1; |
---|
272 | switch(decision){ |
---|
273 | case 0: |
---|
274 | this->target_x = possibleposition[firstdec].x; |
---|
275 | this->target_z = possibleposition[firstdec].z; |
---|
276 | this->ismoving = true; |
---|
277 | break; |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | //Random choice of new target |
---|
282 | void PacmanRandom::setnewTarget(int firstdec, int seconddec){ |
---|
283 | decision = rand()%2; |
---|
284 | switch(decision){ |
---|
285 | case 0: |
---|
286 | this->target_x = possibleposition[firstdec].x; |
---|
287 | this->target_z = possibleposition[firstdec].z; |
---|
288 | this->ismoving = true; |
---|
289 | break; |
---|
290 | case 1: |
---|
291 | this->target_x = possibleposition[seconddec].x; |
---|
292 | this->target_z = possibleposition[seconddec].z; |
---|
293 | this->ismoving = true; |
---|
294 | break; |
---|
295 | } |
---|
296 | |
---|
297 | } |
---|
298 | |
---|
299 | //Random choice of new target |
---|
300 | void PacmanRandom::setnewTarget(int firstdec, int seconddec, int thirddec){ |
---|
301 | |
---|
302 | decision = rand()%3; |
---|
303 | switch(decision){ |
---|
304 | case 0: |
---|
305 | this->target_x = possibleposition[firstdec].x; |
---|
306 | this->target_z = possibleposition[firstdec].z; |
---|
307 | this->ismoving = true; |
---|
308 | break; |
---|
309 | case 1: |
---|
310 | this->target_x = possibleposition[seconddec].x; |
---|
311 | this->target_z = possibleposition[seconddec].z; |
---|
312 | this->ismoving = true; |
---|
313 | break; |
---|
314 | case 2: |
---|
315 | this->target_x = possibleposition[thirddec].x; |
---|
316 | this->target_z = possibleposition[thirddec].z; |
---|
317 | this->ismoving = true; |
---|
318 | break; |
---|
319 | } |
---|
320 | |
---|
321 | } |
---|
322 | |
---|
323 | //Random choice of new target |
---|
324 | void PacmanRandom::setnewTarget(int firstdec, int seconddec, int thirddec, int fourthdec){ |
---|
325 | |
---|
326 | decision = rand()%4; |
---|
327 | switch(decision){ |
---|
328 | case 0: |
---|
329 | this->target_x = possibleposition[firstdec].x; |
---|
330 | this->target_z = possibleposition[firstdec].z; |
---|
331 | this->ismoving = true; |
---|
332 | break; |
---|
333 | case 1: |
---|
334 | this->target_x = possibleposition[seconddec].x; |
---|
335 | this->target_z = possibleposition[seconddec].z; |
---|
336 | this->ismoving = true; |
---|
337 | break; |
---|
338 | case 2: |
---|
339 | this->target_x = possibleposition[thirddec].x; |
---|
340 | this->target_z = possibleposition[thirddec].z; |
---|
341 | this->ismoving = true; |
---|
342 | break; |
---|
343 | case 3: |
---|
344 | this->target_x = possibleposition[fourthdec].x; |
---|
345 | this->target_z = possibleposition[fourthdec].z; |
---|
346 | this->ismoving = true; |
---|
347 | break; |
---|
348 | } |
---|
349 | |
---|
350 | } |
---|
351 | |
---|
352 | |
---|
353 | } |
---|