--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_pathfinder_stupid.cpp Fri Jul 13 19:12:43 2007 +0000
@@ -0,0 +1,60 @@
+/* $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;
+}