//this actually causes the ship to move to a waypoint void AISteering::moveTo(const Position &destination) { turnTo(destination); if (isFacing(destination)) bot->thrust(true); }
//Straight line distance + minimum rotations required //Could be used as a better A* heuristic for the // ZOMBIE's path finding function int AI::zombieDistance(int startX, int startY, int targetX, int targetY, int facing) { bool thisWay; int initRotations = 6; //rotations needed before moving int otherRotations = 0; //rotations needed later int dis = distance(startX, startY, targetX, targetY); int rotNeeded; //rotations needed to meet the current facing. for (int i = 0; i < 6; i++) { thisWay = isFacing(startX, startY, targetX, targetY, i); if (thisWay) { rotNeeded = abs(facing - i); rotNeeded = min(abs(facing - i - 6), rotNeeded); rotNeeded = min(abs(facing - i + 6), rotNeeded); initRotations = min(initRotations, rotNeeded); if (facing != i) { otherRotations += 1; } } } if (initRotations > 0) otherRotations -= 1; if (dis > 0) dis = dis + initRotations + otherRotations; return dis; }