#include "PacmanPink.h" #include "core/CoreIncludes.h" #include "BulletDynamics/Dynamics/btRigidBody.h" namespace orxonox{ RegisterClass(PacmanPink); PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){ RegisterObject(PacmanPink); } /** @brief Method for creating a ghost through XML. */ void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(PacmanPink, XMLPort, xmlelement, mode); } void PacmanPink::tick(float dt) { SUPER(PacmanGhost, tick, dt); this->actuelposition = this->getPosition(); //Stop, if target arrived if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ this->ismoving = false; } //Move, if ghost hasn't arrived yet if(this->ismoving){ if(!(abs(this->actuelposition.z-target_z)<0.5)) { velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); move(dt, actuelposition, velocity); } if(!(abs(this->actuelposition.x-target_x)<0.5)){ velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); move(dt, actuelposition, velocity); } } //Check on which position the ghost has arrived and set new target else{ while(lockmove){}; lockmove = true; if(findPos(player.getPos(), player.lastPassedPoint)){ // if player is on a point, for simplicity go to it Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint); setNewTargetPink(nextMove); } else{ //if player is not on a point either go to next neighboor, or if no //neighboor in player direction available, go to last point passed by player. int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos()); //not in other sense! Vector3[] neighboors; findNeighboor(player.lastPassedPoint, neighboors); //we need to create function that finds neighboors of player last point //We can use and even should use the part of the tick random function // that determines the neighboors. But array neighboor should be in form // south-west-north-east respectively to array index. for(int s=0; s < 4; s++){ //find next neighboor between player and player.lastPassedPoint if((neighboors[s]!=NULL)&&(s==dir)){ if(dir==0){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else if(dir==1){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else if(dir==2){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else{//last is default Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } } else{//if no further point after last player point possible //then simply go to this last point. Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint); setNewTargetPink(nextMove); } } } } Vector3 diffVector (Vector3 start, Vector3 goal){ Vector3 result; result.x=goal.x-start.x; result.z=goal.z-start.z; return result; } int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){ //return 0 for south, 1 for west, 2 for north, 3 for east Vector3 difference = diffVector(playerPosBefore, playerPos); if((difference.z < 0)&&(difference.z>difference.x)){ //move south return 0; } else if((difference.x < 0)&&(difference.x > difference.z )){//move west return 1; } else if((difference.z>0)&&(difference.z>difference.x)){ //mouve north return 2; } else if((difference.x>0)&&(difference.x>difference.z)){ //move east return 3; } else { //default move west return 1; } Vector3 getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){ //return the Vector3 point that Pinky should target to //be in front of pacman Vector3 listOfNeighboors[4]; //first element is south, 2nd west, 3d north, 4th east /*Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4 Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14 Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19 Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24 Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29 Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34 Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39 Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44 Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49 Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54 Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66*/ if(findpos(pacLasVisPos,possibleposition[0])){ //no south neighbor listOfNeighboors[1]=possibleposition[19]; // west neighbor listOfNeighboors[2]=possibleposition[17]; //north listOfNeighboors[3]=possibleposition[1]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[1])){ listOfNeighboors[1]=possibleposition[0]; // west neighbor listOfNeighboors[2]=possibleposition[2]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[2])){ listOfNeighboors[0]=possibleposition[1]; //south listOfNeighboors[1]=possibleposition[3]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[3])){ listOfNeighboors[1]=possibleposition[4]; //west listOfNeighboors[2]=possibleposition[5]; //north listOfNeighboors[3]=possibleposition[2]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[4])){ listOfNeighboors[2]=possibleposition[6]; //north listOfNeighboors[3]=possibleposition[3]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[5])){ listOfNeighboors[0]=possibleposition[3]; //south listOfNeighboors[3]=possibleposition[7]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[6])){ listOfNeighboors[0]=possibleposition[4]; //south listOfNeighboors[1]=possibleposition[26]; //west listOfNeighboors[2]=possibleposition[9]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[7])){ listOfNeighboors[1]=possibleposition[5]; //west listOfNeighboors[2]=possibleposition[8]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[8])){ listOfNeighboors[0]=possibleposition[7]; //south listOfNeighboors[1]=possibleposition[9]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[9])){ listOfNeighboors[0]=possibleposition[6]; //south listOfNeighboors[1]=possibleposition[38]; //west listOfNeighboors[2]=possibleposition[10]; //north listOfNeighboors[3]=possibleposition[8]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[10])){ listOfNeighboors[0]=possibleposition[9]; //south listOfNeighboors[1]=possibleposition[45]; //west listOfNeighboors[2]=possibleposition[11]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[11])){ listOfNeighboors[0]=possibleposition[10]; //south listOfNeighboors[2]=possibleposition[13]; //north listOfNeighboors[3]=possibleposition[12]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[12])){ listOfNeighboors[1]=possibleposition[11]; //west listOfNeighboors[2]=possibleposition[14]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[13])){ listOfNeighboors[0]=possibleposition[11]; //south listOfNeighboors[1]=possibleposition[61]; //west listOfNeighboors[2]=possibleposition[16]; //north listOfNeighboors[3]=possibleposition[14]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[14])){ listOfNeighboors[0]=possibleposition[12]; //south listOfNeighboors[1]=possibleposition[13]; //west listOfNeighboors[2]=possibleposition[15]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[15])){ listOfNeighboors[0]=possibleposition[14]; //south listOfNeighboors[1]=possibleposition[16]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[16])){ listOfNeighboors[0]=possibleposition[13]; //south listOfNeighboors[1]=possibleposition[62]; //west listOfNeighboors[2]=possibleposition[15]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[17])){ listOfNeighboors[0]=possibleposition[0]; //south listOfNeighboors[3]=possibleposition[25]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[18])){ listOfNeighboors[0]=possibleposition[19]; //south listOfNeighboors[1]=possibleposition[24]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[19])){ listOfNeighboors[1]=possibleposition[20]; //west listOfNeighboors[2]=possibleposition[18]; //north listOfNeighboors[3]=possibleposition[0]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[20])){ listOfNeighboors[2]=possibleposition[21]; //north listOfNeighboors[3]=possibleposition[19]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[21])){ listOfNeighboors[0]=possibleposition[20]; //south listOfNeighboors[3]=possibleposition[22]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[22])){ listOfNeighboors[1]=possibleposition[21]; //west listOfNeighboors[2]=possibleposition[31]; //north listOfNeighboors[3]=possibleposition[23]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[23])){ listOfNeighboors[1]=possibleposition[22]; //west listOfNeighboors[2]=possibleposition[30]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[24])){ listOfNeighboors[2]=possibleposition[29]; //north listOfNeighboors[3]=possibleposition[18]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[25])){ listOfNeighboors[1]=possibleposition[17]; //west listOfNeighboors[2]=possibleposition[26]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[26])){ listOfNeighboors[0]=possibleposition[25]; //south listOfNeighboors[1]=possibleposition[27]; //west listOfNeighboors[3]=possibleposition[6]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[27])){ listOfNeighboors[1]=possibleposition[28]; //west listOfNeighboors[2]=possibleposition[37]; //north listOfNeighboors[3]=possibleposition[26]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[28])){ listOfNeighboors[1]=possibleposition[29]; //west listOfNeighboors[2]=possibleposition[36]; //north listOfNeighboors[3]=possibleposition[27]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[29])){ listOfNeighboors[0]=possibleposition[24]; //south listOfNeighboors[1]=possibleposition[30]; //west listOfNeighboors[3]=possibleposition[28]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[30])){ listOfNeighboors[0]=possibleposition[23]; //south listOfNeighboors[2]=possibleposition[34]; //north listOfNeighboors[3]=possibleposition[29]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[31])){ listOfNeighboors[0]=possibleposition[22]; //south listOfNeighboors[1]=possibleposition[32]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[32])){ listOfNeighboors[2]=possibleposition[33]; //north listOfNeighboors[3]=possibleposition[31]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[33])){ listOfNeighboors[0]=possibleposition[32]; //south listOfNeighboors[3]=possibleposition[34]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[34])){ listOfNeighboors[0]=possibleposition[30]; //south listOfNeighboors[1]=possibleposition[33]; //west listOfNeighboors[2]=possibleposition[92]; //north listOfNeighboors[3]=possibleposition[35]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[35])){ listOfNeighboors[1]=possibleposition[34]; //west listOfNeighboors[2]=possibleposition[91]; //north listOfNeighboors[3]=possibleposition[36]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[36])){ listOfNeighboors[0]=possibleposition[28]; //south listOfNeighboors[1]=possibleposition[35]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[37])){ listOfNeighboors[0]=possibleposition[27]; //south listOfNeighboors[3]=possibleposition[38]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[38])){ listOfNeighboors[1]=possibleposition[37]; //west listOfNeighboors[2]=possibleposition[39]; //north listOfNeighboors[3]=possibleposition[9]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[39])){ listOfNeighboors[0]=possibleposition[38]; //south listOfNeighboors[1]=possibleposition[40]; //west listOfNeighboors[2]=possibleposition[45]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[40])){ listOfNeighboors[1]=possibleposition[41]; //west //Not return in center listOfNeighboors[3]=possibleposition[39]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[41])){ listOfNeighboors[0]=possibleposition[35]; //south listOfNeighboors[2]=possibleposition[43]; //north listOfNeighboors[3]=possibleposition[40]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[42])){ listOfNeighboors[0]=possibleposition[39]; //south listOfNeighboors[2]=possibleposition[59]; //north listOfNeighboors[3]=possibleposition[43]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[43])){ listOfNeighboors[0]=possibleposition[41]; //south listOfNeighboors[1]=possibleposition[42]; //west listOfNeighboors[2]=possibleposition[46]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[44])){ listOfNeighboors[0]=possibleposition[40]; //south listOfNeighboors[2]=possibleposition[66]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[45])){ listOfNeighboors[0]=possibleposition[39]; //south listOfNeighboors[2]=possibleposition[49]; //north listOfNeighboors[3]=possibleposition[10]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[46])){ listOfNeighboors[0]=possibleposition[43]; //south listOfNeighboors[3]=possibleposition[47]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[47])){ listOfNeighboors[1]=possibleposition[46]; //west listOfNeighboors[2]=possibleposition[52]; //north listOfNeighboors[3]=possibleposition[66]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[48])){ listOfNeighboors[1]=possibleposition[66]; //west listOfNeighboors[2]=possibleposition[51]; //north listOfNeighboors[3]=possibleposition[49]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[49])){ listOfNeighboors[0]=possibleposition[45]; //south listOfNeighboors[1]=possibleposition[48]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[50])){ listOfNeighboors[1]=possibleposition[51]; //west listOfNeighboors[2]=possibleposition[61]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[51])){ listOfNeighboors[0]=possibleposition[48]; //south listOfNeighboors[3]=possibleposition[50]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[52])){ listOfNeighboors[0]=possibleposition[47]; //south listOfNeighboors[1]=possibleposition[53]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[53])){ listOfNeighboors[2]=possibleposition[58]; //north listOfNeighboors[3]=possibleposition[52]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[54])){ listOfNeighboors[0]=possibleposition[42]; //south listOfNeighboors[1]=possibleposition[55]; //west listOfNeighboors[2]=possibleposition[57]; //north return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[55])){ listOfNeighboors[2]=possibleposition[56]; //north listOfNeighboors[3]=possibleposition[54]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[56])){ listOfNeighboors[0]=possibleposition[55]; //south listOfNeighboors[2]=possibleposition[65]; //north listOfNeighboors[3]=possibleposition[57]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[57])){ listOfNeighboors[0]=possibleposition[54]; //south listOfNeighboors[1]=possibleposition[56]; //west listOfNeighboors[2]=possibleposition[64]; //north listOfNeighboors[3]=possibleposition[58]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[58])){ listOfNeighboors[0]=possibleposition[53]; //south listOfNeighboors[1]=possibleposition[57]; //west listOfNeighboors[3]=possibleposition[59]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[59])){ listOfNeighboors[1]=possibleposition[58]; //west listOfNeighboors[2]=possibleposition[63]; //north listOfNeighboors[3]=possibleposition[60]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[60])){ listOfNeighboors[1]=possibleposition[59]; //west listOfNeighboors[2]=possibleposition[62]; //north listOfNeighboors[3]=possibleposition[61]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[61])){ listOfNeighboors[0]=possibleposition[50]; //south listOfNeighboors[1]=possibleposition[60]; //west listOfNeighboors[3]=possibleposition[13]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[62])){ listOfNeighboors[0]=possibleposition[60]; //south listOfNeighboors[3]=possibleposition[16]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[63])){ listOfNeighboors[0]=possibleposition[59]; //south listOfNeighboors[1]=possibleposition[64]; //west return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[64])){ listOfNeighboors[0]=possibleposition[57]; //south listOfNeighboors[1]=possibleposition[65]; //west listOfNeighboors[3]=possibleposition[63]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[65])){ listOfNeighboors[0]=possibleposition[56]; //south listOfNeighboors[3]=possibleposition[64]; //east return listOfNeighboors[s]; } else if(findpos(pacLasVisPos,possibleposition[66])){ //Not back in center listOfNeighboors[1]=possibleposition[47]; //west listOfNeighboors[3]=possibleposition[48]; //east return listOfNeighboors[s]; } }