src/ai/api/ai_pathfinder_stupid.cpp
branchnoai
changeset 9652 c15bf5355b95
child 9723 eee46cb39750
equal deleted inserted replaced
9651:6e2860c67455 9652:c15bf5355b95
       
     1 /* $Id$ */
       
     2 
       
     3 #include "ai_pathfinder_stupid.hpp"
       
     4 #include "ai_road.hpp"
       
     5 #include "ai_testmode.hpp"
       
     6 
       
     7 bool AIPathFinderStupid::BuildRealRoute(TileIndex start, TileIndex end, bool continue_on_error)
       
     8 {
       
     9 	bool ret = true;
       
    10 	uint sx, sy, ex, ey;
       
    11 
       
    12 	sx = TileX(start);
       
    13 	sy = TileY(start);
       
    14 	ex = TileX(end);
       
    15 	ey = TileY(end);
       
    16 
       
    17 	/* Build the road, really stupid: first the X, than the Y */
       
    18 	if (this->type == PATHFINDER_ROAD) {
       
    19 		AIRoad road;
       
    20 		if (!road.BuildRoad(start, TileXY(ex, sy))) ret = false;
       
    21 		if (!road.BuildRoad(TileXY(ex, sy), end)) ret = false;
       
    22 		if (!ret && !continue_on_error) return false;
       
    23 	}
       
    24 
       
    25 	return ret;
       
    26 }
       
    27 
       
    28 void *AIPathFinderStupid::FindRoute(AITileList *start, AITileList *end)
       
    29 {
       
    30 	TileIndex s, e;
       
    31 
       
    32 	s = start->Begin();
       
    33 	e = end->Begin();
       
    34 
       
    35 	/* Force test-mode */
       
    36 	{
       
    37 		AITestMode mode;
       
    38 		if (!this->BuildRealRoute(s, e, false)) return false;
       
    39 	}
       
    40 
       
    41 	Path *result = new Path;
       
    42 	result->start = s;
       
    43 	result->end = e;
       
    44 	return result;
       
    45 }
       
    46 
       
    47 bool AIPathFinderStupid::BuildRoute(void *res)
       
    48 {
       
    49 	if (res == NULL) return false;
       
    50 	Path *result = (Path *)res;
       
    51 
       
    52 	return this->BuildRealRoute(result->start, result->end, true);
       
    53 }
       
    54 
       
    55 void AIPathFinderStupid::FreeRoute(void *res)
       
    56 {
       
    57 	if (res == NULL) return;
       
    58 	Path *result = (Path *)res;
       
    59 	delete result;
       
    60 }