src/ai/api/ai_pathfinder_stupid.cpp
author truelight
Sun, 19 Aug 2007 13:16:06 +0000
branchnoai
changeset 9696 4384ed3de1f0
parent 9652 c15bf5355b95
child 9723 eee46cb39750
permissions -rw-r--r--
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
[NoAI] -Fix: AICompant::GetCompanyName returned \0 for invalid company instead of NULL
/* $Id$ */

#include "ai_pathfinder_stupid.hpp"
#include "ai_road.hpp"
#include "ai_testmode.hpp"

bool AIPathFinderStupid::BuildRealRoute(TileIndex start, TileIndex end, bool continue_on_error)
{
	bool ret = true;
	uint sx, sy, ex, ey;

	sx = TileX(start);
	sy = TileY(start);
	ex = TileX(end);
	ey = TileY(end);

	/* Build the road, really stupid: first the X, than the Y */
	if (this->type == PATHFINDER_ROAD) {
		AIRoad road;
		if (!road.BuildRoad(start, TileXY(ex, sy))) ret = false;
		if (!road.BuildRoad(TileXY(ex, sy), end)) ret = false;
		if (!ret && !continue_on_error) return false;
	}

	return ret;
}

void *AIPathFinderStupid::FindRoute(AITileList *start, AITileList *end)
{
	TileIndex s, e;

	s = start->Begin();
	e = end->Begin();

	/* Force test-mode */
	{
		AITestMode mode;
		if (!this->BuildRealRoute(s, e, false)) return false;
	}

	Path *result = new Path;
	result->start = s;
	result->end = e;
	return result;
}

bool AIPathFinderStupid::BuildRoute(void *res)
{
	if (res == NULL) return false;
	Path *result = (Path *)res;

	return this->BuildRealRoute(result->start, result->end, true);
}

void AIPathFinderStupid::FreeRoute(void *res)
{
	if (res == NULL) return;
	Path *result = (Path *)res;
	delete result;
}