Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc @ 12317

Last change on this file since 12317 was 12317, checked in by peterf, 5 years ago

Red Pacman seems to work even better

File size: 22.8 KB
Line 
1       
2#include "PacmanPink.h"
3
4#include "core/CoreIncludes.h"
5#include "BulletDynamics/Dynamics/btRigidBody.h"
6
7       
8namespace orxonox{
9
10        RegisterClass(PacmanPink);
11
12                PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){
13
14        RegisterObject(PacmanPink);
15         
16    }
17
18    /**
19    @brief
20        Method for creating a ghost through XML.
21    */
22    void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
23    {
24        SUPER(PacmanPink, XMLPort, xmlelement, mode);
25    }
26
27
28    void PacmanPink::tick(float dt)
29    {
30        SUPER(PacmanGhost, tick, dt);
31
32        this->actuelposition = this->getPosition();
33       
34        //Stop, if target arrived
35        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
36                 this->ismoving = false;
37        }
38
39        //Move, if ghost hasn't arrived yet
40        if(this->ismoving){
41            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
42                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
43                move(dt, actuelposition, velocity);
44            }   
45            if(!(abs(this->actuelposition.x-target_x)<0.5)){
46                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
47                move(dt, actuelposition, velocity);
48            }
49        }
50        //Check on which position the ghost has arrived and set new target
51         else{
52            while(lockmove){};
53            lockmove = true;
54
55            if(findPos(player.getPos(), player.lastPassedPoint)){
56                // if player is on a point, for simplicity go to it
57            Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint);
58            setNewTargetPink(nextMove);
59            }
60
61            else{ //if player is not on a point either go to next neighboor, or if no
62            //neighboor in player direction available, go to last point passed by player.
63
64            int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos());
65            //not in other sense!
66
67            Vector3[] neighboors;
68            findNeighboor(player.lastPassedPoint, neighboors);
69            //we need to create function that finds neighboors of player last point
70            //We can use and even should use the part of the tick random function
71            // that determines the neighboors. But array neighboor should be in form
72            // south-west-north-east respectively to array index.
73
74            for(int s=0; s < 4; s++){
75                //find next neighboor between player and player.lastPassedPoint
76                if((neighboors[s]!=NULL)&&(s==dir)){
77                        if(dir==0){
78                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
79                                setNewTargetPink(nextMove);
80                        }
81                        else if(dir==1){
82                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
83                                setNewTargetPink(nextMove);
84                        }
85                        else if(dir==2){
86                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
87                                setNewTargetPink(nextMove);
88                        }
89                        else{//last is default
90                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
91                                setNewTargetPink(nextMove);
92                                        }
93                        }
94                else{//if no further point after last player point possible
95                        //then simply go to this last point.
96                Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint);
97                        setNewTargetPink(nextMove);
98                        }
99
100                }
101
102            }
103
104        }
105
106
107
108        /*
109        Vector3 diffVector (Vector3 start, Vector3 goal){
110
111                Vector3 result;
112                result.x=goal.x-start.x;
113                result.z=goal.z-start.z;
114                return result;
115        }
116
117        int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
118                //return 0 for south, 1 for west, 2 for north, 3 for east
119
120                Vector3 difference = diffVector(playerPosBefore, playerPos);
121
122
123                if((difference.z < 0)&&(difference.z>difference.x)){ //move south
124
125                        return 0;
126                }
127                else if((difference.x < 0)&&(difference.x > difference.z )){//move west
128
129                        return 1;
130                }
131
132                else if((difference.z>0)&&(difference.z>difference.x)){ //mouve north
133
134                        return 2;
135                }
136
137                else if((difference.x>0)&&(difference.x>difference.z)){ //move east
138                        return 3;
139
140                }
141
142                else { //default move west
143
144                return 1;
145                }
146               
147
148        Vector3 getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){
149                //return the Vector3 point that Pinky should target to
150                //be in front of pacman
151
152                Vector3 listOfNeighboors[4];
153                //first element is south, 2nd west, 3d north, 4th east
154       
155
156
157                if(findpos(pacLasVisPos,possibleposition[0])){
158                        //no south neighbor
159                        listOfNeighboors[1]=possibleposition[19]; // west neighbor
160                        listOfNeighboors[2]=possibleposition[17]; //north
161                        listOfNeighboors[3]=possibleposition[1]; //east
162                        return listOfNeighboors[s];
163            }
164            else if(findpos(pacLasVisPos,possibleposition[1])){
165                listOfNeighboors[1]=possibleposition[0]; // west neighbor
166                        listOfNeighboors[2]=possibleposition[2]; //north
167                        return listOfNeighboors[s];
168            }
169            else if(findpos(pacLasVisPos,possibleposition[2])){
170                listOfNeighboors[0]=possibleposition[1];  //south
171                listOfNeighboors[1]=possibleposition[3]; //west
172                        return listOfNeighboors[s];
173            }
174            else if(findpos(pacLasVisPos,possibleposition[3])){
175                listOfNeighboors[1]=possibleposition[4]; //west
176                        listOfNeighboors[2]=possibleposition[5]; //north
177                        listOfNeighboors[3]=possibleposition[2]; //east
178                        return listOfNeighboors[s];
179            }
180            else if(findpos(pacLasVisPos,possibleposition[4])){
181                        listOfNeighboors[2]=possibleposition[6]; //north
182                        listOfNeighboors[3]=possibleposition[3]; //east
183                        return listOfNeighboors[s];
184            }
185            else if(findpos(pacLasVisPos,possibleposition[5])){
186                listOfNeighboors[0]=possibleposition[3]; //south
187                        listOfNeighboors[3]=possibleposition[7]; //east
188                        return listOfNeighboors[s];
189            }
190            else if(findpos(pacLasVisPos,possibleposition[6])){
191                listOfNeighboors[0]=possibleposition[4]; //south
192                listOfNeighboors[1]=possibleposition[26]; //west
193                        listOfNeighboors[2]=possibleposition[9]; //north
194                        return listOfNeighboors[s];
195            }
196            else if(findpos(pacLasVisPos,possibleposition[7])){
197                listOfNeighboors[1]=possibleposition[5]; //west
198                        listOfNeighboors[2]=possibleposition[8]; //north
199                        return listOfNeighboors[s];
200            }
201            else if(findpos(pacLasVisPos,possibleposition[8])){
202                listOfNeighboors[0]=possibleposition[7]; //south
203                listOfNeighboors[1]=possibleposition[9]; //west
204                        return listOfNeighboors[s];
205            }
206            else if(findpos(pacLasVisPos,possibleposition[9])){
207                listOfNeighboors[0]=possibleposition[6]; //south
208                listOfNeighboors[1]=possibleposition[38]; //west
209                        listOfNeighboors[2]=possibleposition[10]; //north
210                        listOfNeighboors[3]=possibleposition[8]; //east
211                        return listOfNeighboors[s];
212            }
213            else if(findpos(pacLasVisPos,possibleposition[10])){
214                listOfNeighboors[0]=possibleposition[9]; //south
215                listOfNeighboors[1]=possibleposition[45]; //west
216                        listOfNeighboors[2]=possibleposition[11]; //north
217                        return listOfNeighboors[s];
218            }
219            else if(findpos(pacLasVisPos,possibleposition[11])){
220                listOfNeighboors[0]=possibleposition[10]; //south
221                        listOfNeighboors[2]=possibleposition[13]; //north
222                        listOfNeighboors[3]=possibleposition[12]; //east
223                        return listOfNeighboors[s];
224            }
225            else if(findpos(pacLasVisPos,possibleposition[12])){
226                listOfNeighboors[1]=possibleposition[11]; //west
227                        listOfNeighboors[2]=possibleposition[14]; //north
228                        return listOfNeighboors[s];
229            }
230            else if(findpos(pacLasVisPos,possibleposition[13])){
231                listOfNeighboors[0]=possibleposition[11]; //south
232                listOfNeighboors[1]=possibleposition[61]; //west
233                        listOfNeighboors[2]=possibleposition[16]; //north
234                        listOfNeighboors[3]=possibleposition[14]; //east
235                        return listOfNeighboors[s];
236            }
237            else if(findpos(pacLasVisPos,possibleposition[14])){
238                listOfNeighboors[0]=possibleposition[12]; //south
239                listOfNeighboors[1]=possibleposition[13]; //west
240                        listOfNeighboors[2]=possibleposition[15]; //north
241                        return listOfNeighboors[s];
242            }
243            else if(findpos(pacLasVisPos,possibleposition[15])){
244                listOfNeighboors[0]=possibleposition[14]; //south
245                listOfNeighboors[1]=possibleposition[16]; //west
246                        return listOfNeighboors[s];
247            }
248            else if(findpos(pacLasVisPos,possibleposition[16])){
249                listOfNeighboors[0]=possibleposition[13]; //south
250                listOfNeighboors[1]=possibleposition[62]; //west
251                        listOfNeighboors[2]=possibleposition[15]; //north
252                        return listOfNeighboors[s];
253            }
254            else if(findpos(pacLasVisPos,possibleposition[17])){
255                listOfNeighboors[0]=possibleposition[0]; //south
256                        listOfNeighboors[3]=possibleposition[25]; //east
257                        return listOfNeighboors[s];
258            }
259            else if(findpos(pacLasVisPos,possibleposition[18])){
260                listOfNeighboors[0]=possibleposition[19]; //south
261                listOfNeighboors[1]=possibleposition[24]; //west
262                        return listOfNeighboors[s];
263            }
264            else if(findpos(pacLasVisPos,possibleposition[19])){
265                listOfNeighboors[1]=possibleposition[20]; //west
266                        listOfNeighboors[2]=possibleposition[18]; //north
267                        listOfNeighboors[3]=possibleposition[0]; //east
268                        return listOfNeighboors[s];
269            }
270            else if(findpos(pacLasVisPos,possibleposition[20])){
271                        listOfNeighboors[2]=possibleposition[21]; //north
272                        listOfNeighboors[3]=possibleposition[19]; //east
273                        return listOfNeighboors[s];
274            }
275            else if(findpos(pacLasVisPos,possibleposition[21])){
276                listOfNeighboors[0]=possibleposition[20]; //south
277                        listOfNeighboors[3]=possibleposition[22]; //east
278                        return listOfNeighboors[s];
279            }
280            else if(findpos(pacLasVisPos,possibleposition[22])){
281                listOfNeighboors[1]=possibleposition[21]; //west
282                        listOfNeighboors[2]=possibleposition[31]; //north
283                        listOfNeighboors[3]=possibleposition[23]; //east
284                        return listOfNeighboors[s];
285            }
286            else if(findpos(pacLasVisPos,possibleposition[23])){
287                listOfNeighboors[1]=possibleposition[22]; //west
288                        listOfNeighboors[2]=possibleposition[30]; //north
289                        return listOfNeighboors[s];
290            }
291            else if(findpos(pacLasVisPos,possibleposition[24])){
292                        listOfNeighboors[2]=possibleposition[29]; //north
293                        listOfNeighboors[3]=possibleposition[18]; //east
294                        return listOfNeighboors[s];
295            }
296            else if(findpos(pacLasVisPos,possibleposition[25])){
297                listOfNeighboors[1]=possibleposition[17]; //west
298                        listOfNeighboors[2]=possibleposition[26]; //north
299                        return listOfNeighboors[s];
300            }
301            else if(findpos(pacLasVisPos,possibleposition[26])){
302                listOfNeighboors[0]=possibleposition[25]; //south
303                listOfNeighboors[1]=possibleposition[27]; //west
304                        listOfNeighboors[3]=possibleposition[6]; //east
305                        return listOfNeighboors[s];
306            }
307            else if(findpos(pacLasVisPos,possibleposition[27])){
308                listOfNeighboors[1]=possibleposition[28]; //west
309                        listOfNeighboors[2]=possibleposition[37]; //north
310                        listOfNeighboors[3]=possibleposition[26]; //east
311                        return listOfNeighboors[s];
312            }
313            else if(findpos(pacLasVisPos,possibleposition[28])){
314                listOfNeighboors[1]=possibleposition[29]; //west
315                        listOfNeighboors[2]=possibleposition[36]; //north
316                        listOfNeighboors[3]=possibleposition[27]; //east
317                        return listOfNeighboors[s];
318            }
319            else if(findpos(pacLasVisPos,possibleposition[29])){
320                listOfNeighboors[0]=possibleposition[24]; //south
321                listOfNeighboors[1]=possibleposition[30]; //west
322                        listOfNeighboors[3]=possibleposition[28]; //east
323                        return listOfNeighboors[s];
324            }
325            else if(findpos(pacLasVisPos,possibleposition[30])){
326                listOfNeighboors[0]=possibleposition[23]; //south
327                        listOfNeighboors[2]=possibleposition[34]; //north
328                        listOfNeighboors[3]=possibleposition[29]; //east
329                        return listOfNeighboors[s];
330            }
331            else if(findpos(pacLasVisPos,possibleposition[31])){
332                listOfNeighboors[0]=possibleposition[22]; //south
333                listOfNeighboors[1]=possibleposition[32]; //west
334                        return listOfNeighboors[s];
335            }
336            else if(findpos(pacLasVisPos,possibleposition[32])){
337                        listOfNeighboors[2]=possibleposition[33]; //north
338                        listOfNeighboors[3]=possibleposition[31]; //east
339                        return listOfNeighboors[s];
340            }
341            else if(findpos(pacLasVisPos,possibleposition[33])){
342                listOfNeighboors[0]=possibleposition[32]; //south
343                        listOfNeighboors[3]=possibleposition[34]; //east
344                        return listOfNeighboors[s];
345            }
346            else if(findpos(pacLasVisPos,possibleposition[34])){
347                listOfNeighboors[0]=possibleposition[30]; //south
348                listOfNeighboors[1]=possibleposition[33]; //west
349                        listOfNeighboors[2]=possibleposition[92]; //north
350                        listOfNeighboors[3]=possibleposition[35]; //east
351                        return listOfNeighboors[s];
352            }
353            else if(findpos(pacLasVisPos,possibleposition[35])){
354                listOfNeighboors[1]=possibleposition[34]; //west
355                        listOfNeighboors[2]=possibleposition[91]; //north
356                        listOfNeighboors[3]=possibleposition[36]; //east
357                        return listOfNeighboors[s];
358            }
359            else if(findpos(pacLasVisPos,possibleposition[36])){
360                listOfNeighboors[0]=possibleposition[28]; //south
361                listOfNeighboors[1]=possibleposition[35]; //west
362                        return listOfNeighboors[s];
363            }
364            else if(findpos(pacLasVisPos,possibleposition[37])){
365                listOfNeighboors[0]=possibleposition[27]; //south
366                        listOfNeighboors[3]=possibleposition[38]; //east
367                        return listOfNeighboors[s];
368            }
369            else if(findpos(pacLasVisPos,possibleposition[38])){
370                listOfNeighboors[1]=possibleposition[37]; //west
371                        listOfNeighboors[2]=possibleposition[39]; //north
372                        listOfNeighboors[3]=possibleposition[9]; //east
373                        return listOfNeighboors[s];
374            }
375            else if(findpos(pacLasVisPos,possibleposition[39])){
376                listOfNeighboors[0]=possibleposition[38]; //south
377                listOfNeighboors[1]=possibleposition[40]; //west
378                        listOfNeighboors[2]=possibleposition[45]; //north
379                        return listOfNeighboors[s];
380            }
381            else if(findpos(pacLasVisPos,possibleposition[40])){
382                listOfNeighboors[1]=possibleposition[41]; //west
383                        //Not return in center
384                        listOfNeighboors[3]=possibleposition[39]; //east
385                        return listOfNeighboors[s];
386            }
387            else if(findpos(pacLasVisPos,possibleposition[41])){
388                listOfNeighboors[0]=possibleposition[35]; //south
389                        listOfNeighboors[2]=possibleposition[43]; //north
390                        listOfNeighboors[3]=possibleposition[40]; //east
391                        return listOfNeighboors[s];
392            }
393            else if(findpos(pacLasVisPos,possibleposition[42])){
394                listOfNeighboors[0]=possibleposition[39]; //south
395                        listOfNeighboors[2]=possibleposition[59]; //north
396                        listOfNeighboors[3]=possibleposition[43]; //east
397                        return listOfNeighboors[s];
398            }
399            else if(findpos(pacLasVisPos,possibleposition[43])){
400                listOfNeighboors[0]=possibleposition[41]; //south
401                listOfNeighboors[1]=possibleposition[42]; //west
402                        listOfNeighboors[2]=possibleposition[46]; //north
403                        return listOfNeighboors[s];
404            }
405            else if(findpos(pacLasVisPos,possibleposition[44])){
406                listOfNeighboors[0]=possibleposition[40]; //south
407                        listOfNeighboors[2]=possibleposition[66]; //north
408                        return listOfNeighboors[s];
409            }
410            else if(findpos(pacLasVisPos,possibleposition[45])){
411                listOfNeighboors[0]=possibleposition[39]; //south
412                        listOfNeighboors[2]=possibleposition[49]; //north
413                        listOfNeighboors[3]=possibleposition[10]; //east
414                        return listOfNeighboors[s];
415            }
416            else if(findpos(pacLasVisPos,possibleposition[46])){
417                listOfNeighboors[0]=possibleposition[43]; //south
418                        listOfNeighboors[3]=possibleposition[47]; //east
419                        return listOfNeighboors[s];
420            }
421            else if(findpos(pacLasVisPos,possibleposition[47])){
422                listOfNeighboors[1]=possibleposition[46]; //west
423                        listOfNeighboors[2]=possibleposition[52]; //north
424                        listOfNeighboors[3]=possibleposition[66]; //east
425                        return listOfNeighboors[s];
426            }
427            else if(findpos(pacLasVisPos,possibleposition[48])){
428                listOfNeighboors[1]=possibleposition[66]; //west
429                        listOfNeighboors[2]=possibleposition[51]; //north
430                        listOfNeighboors[3]=possibleposition[49]; //east
431                        return listOfNeighboors[s];
432            }
433            else if(findpos(pacLasVisPos,possibleposition[49])){
434                listOfNeighboors[0]=possibleposition[45]; //south
435                listOfNeighboors[1]=possibleposition[48]; //west
436                        return listOfNeighboors[s];
437            }
438            else if(findpos(pacLasVisPos,possibleposition[50])){
439                listOfNeighboors[1]=possibleposition[51]; //west
440                        listOfNeighboors[2]=possibleposition[61]; //north
441                        return listOfNeighboors[s];
442            }
443            else if(findpos(pacLasVisPos,possibleposition[51])){
444                listOfNeighboors[0]=possibleposition[48]; //south
445                        listOfNeighboors[3]=possibleposition[50]; //east
446                        return listOfNeighboors[s];
447            }
448            else if(findpos(pacLasVisPos,possibleposition[52])){
449                listOfNeighboors[0]=possibleposition[47]; //south
450                listOfNeighboors[1]=possibleposition[53]; //west
451                        return listOfNeighboors[s];
452            }
453            else if(findpos(pacLasVisPos,possibleposition[53])){
454                        listOfNeighboors[2]=possibleposition[58]; //north
455                        listOfNeighboors[3]=possibleposition[52]; //east
456                        return listOfNeighboors[s];
457            }
458            else if(findpos(pacLasVisPos,possibleposition[54])){
459                listOfNeighboors[0]=possibleposition[42]; //south
460                listOfNeighboors[1]=possibleposition[55]; //west
461                        listOfNeighboors[2]=possibleposition[57]; //north
462                        return listOfNeighboors[s];
463            }
464            else if(findpos(pacLasVisPos,possibleposition[55])){
465                        listOfNeighboors[2]=possibleposition[56]; //north
466                        listOfNeighboors[3]=possibleposition[54]; //east
467                        return listOfNeighboors[s];
468            }
469            else if(findpos(pacLasVisPos,possibleposition[56])){
470                listOfNeighboors[0]=possibleposition[55]; //south
471                        listOfNeighboors[2]=possibleposition[65]; //north
472                        listOfNeighboors[3]=possibleposition[57]; //east
473                        return listOfNeighboors[s];
474            }
475            else if(findpos(pacLasVisPos,possibleposition[57])){
476                listOfNeighboors[0]=possibleposition[54]; //south
477                listOfNeighboors[1]=possibleposition[56]; //west
478                        listOfNeighboors[2]=possibleposition[64]; //north
479                        listOfNeighboors[3]=possibleposition[58]; //east
480                        return listOfNeighboors[s];
481            }
482            else if(findpos(pacLasVisPos,possibleposition[58])){
483                listOfNeighboors[0]=possibleposition[53]; //south
484                listOfNeighboors[1]=possibleposition[57]; //west
485                        listOfNeighboors[3]=possibleposition[59]; //east
486                        return listOfNeighboors[s];
487            }
488            else if(findpos(pacLasVisPos,possibleposition[59])){
489                listOfNeighboors[1]=possibleposition[58]; //west
490                        listOfNeighboors[2]=possibleposition[63]; //north
491                        listOfNeighboors[3]=possibleposition[60]; //east
492                        return listOfNeighboors[s];
493            }
494            else if(findpos(pacLasVisPos,possibleposition[60])){
495                listOfNeighboors[1]=possibleposition[59]; //west
496                        listOfNeighboors[2]=possibleposition[62]; //north
497                        listOfNeighboors[3]=possibleposition[61]; //east
498                        return listOfNeighboors[s];
499            }
500            else if(findpos(pacLasVisPos,possibleposition[61])){
501                listOfNeighboors[0]=possibleposition[50]; //south
502                listOfNeighboors[1]=possibleposition[60]; //west
503                        listOfNeighboors[3]=possibleposition[13]; //east
504                        return listOfNeighboors[s];
505            }
506            else if(findpos(pacLasVisPos,possibleposition[62])){
507                listOfNeighboors[0]=possibleposition[60]; //south
508                        listOfNeighboors[3]=possibleposition[16]; //east
509                        return listOfNeighboors[s];
510            }
511            else if(findpos(pacLasVisPos,possibleposition[63])){
512                listOfNeighboors[0]=possibleposition[59]; //south
513                listOfNeighboors[1]=possibleposition[64]; //west
514                        return listOfNeighboors[s];
515            }
516            else if(findpos(pacLasVisPos,possibleposition[64])){
517                listOfNeighboors[0]=possibleposition[57]; //south
518                listOfNeighboors[1]=possibleposition[65]; //west
519                        listOfNeighboors[3]=possibleposition[63]; //east
520                        return listOfNeighboors[s];
521            }
522            else if(findpos(pacLasVisPos,possibleposition[65])){
523                listOfNeighboors[0]=possibleposition[56]; //south
524                        listOfNeighboors[3]=possibleposition[64]; //east
525                        return listOfNeighboors[s];
526            }
527            else if(findpos(pacLasVisPos,possibleposition[66])){
528                //Not back in center
529                listOfNeighboors[1]=possibleposition[47]; //west
530                        listOfNeighboors[3]=possibleposition[48]; //east
531                        return listOfNeighboors[s];           
532                }
533*/
534
535        }
536
537       
538
539       
Note: See TracBrowser for help on using the repository browser.