(svn r12493) [NoAI] -Remove [API CHANGE]: AIPathFinder should never been part of this API (more like a contrib or extended something)
--- a/bin/ai/regression/regression.nut Mon Mar 31 06:33:22 2008 +0000
+++ b/bin/ai/regression/regression.nut Mon Mar 31 06:36:54 2008 +0000
@@ -658,26 +658,6 @@
}
}
-function Regression::PathFinder()
-{
- local pf = AIPathFinderStupid(AIPathFinder.PATHFINDER_ROAD);
- local start = AITileList();
- local end = AITileList();
-
- start.AddTile(33421);
- end.AddTile(33480 + 256 * 10);
-
- print("");
- print("--PathFinderStupid--");
- local ret = pf.FindRoute(start, end);
- print(" FindRoute(): " + (ret ? "Route Array" : "Nil"));
- print(" BuildRoute(): " + pf.BuildRoute(ret));
- pf.FreeRoute(ret);
-
- print(" IsRoadTile(): " + AIRoad.IsRoadTile(33425));
- print(" IsRoadTile(): " + AIRoad.IsRoadTile(33480 + 256 * 5));
-}
-
function Regression::Road()
{
print("");
@@ -1141,7 +1121,6 @@
this.IndustryList();
this.Map();
this.Marine();
- this.PathFinder();
this.Road();
this.Sign();
this.Station();
--- a/bin/ai/regression/regression.txt Mon Mar 31 06:33:22 2008 +0000
+++ b/bin/ai/regression/regression.txt Mon Mar 31 06:36:54 2008 +0000
@@ -5318,12 +5318,6 @@
BuildWaterDepot(): true
BuildDock(): true
---PathFinderStupid--
- FindRoute(): Route Array
- BuildRoute(): true
- IsRoadTile(): true
- IsRoadTile(): true
-
--Road--
Road
IsRoadTile(): false
@@ -6175,7 +6169,7 @@
IsStoppedInDepot(): false
--Accounting--
GetCosts(): -5945
- Should be: -5945
+ Should be: -5944
GetName(): Road Vehicle 1
SetName(): true
GetName(): MyVehicleName
@@ -6188,7 +6182,7 @@
GetMaxAge(): 5490
GetAgeLeft(): 5489
GetRunningCost(): 421
- GetProfitThisYear(): 0
+ GetProfitThisYear(): -1
GetProfitLastYear(): 0
GetVehicleType(): 1
IsInDepot(): false
@@ -6246,7 +6240,7 @@
15 => 0
13 => 0
12 => 0
- 11 => 0
+ 11 => -1
ProfitLastYear ListDump:
15 => 0
13 => 0
@@ -6307,8 +6301,8 @@
GetEventType: 3
EventName: SubsidiaryOffer
CargoID: 0
- GetFromTownID: 16
+ GetFromTownID: 0
GetToTownID: 65535
GetFromIndustryID: 65535
- GetToIndustryID: 0
+ GetToIndustryID: 21
IsEventWaiting: false
--- a/source.list Mon Mar 31 06:33:22 2008 +0000
+++ b/source.list Mon Mar 31 06:36:54 2008 +0000
@@ -479,8 +479,6 @@
ai/api/ai_marine.hpp
ai/api/ai_object.hpp
ai/api/ai_order.hpp
-ai/api/ai_pathfinder.hpp
-ai/api/ai_pathfinder_stupid.hpp
ai/api/ai_road.hpp
ai/api/ai_settings.hpp
ai/api/ai_sign.hpp
@@ -520,7 +518,6 @@
ai/api/ai_marine.cpp
ai/api/ai_object.cpp
ai/api/ai_order.cpp
-ai/api/ai_pathfinder_stupid.cpp
ai/api/ai_road.cpp
ai/api/ai_settings.cpp
ai/api/ai_sign.cpp
--- a/src/ai/ai_squirrel.cpp Mon Mar 31 06:33:22 2008 +0000
+++ b/src/ai/ai_squirrel.cpp Mon Mar 31 06:36:54 2008 +0000
@@ -44,8 +44,6 @@
#include "api/ai_map.hpp.sq"
#include "api/ai_marine.hpp.sq"
#include "api/ai_order.hpp.sq"
-#include "api/ai_pathfinder.hpp.sq"
-#include "api/ai_pathfinder_stupid.hpp.sq"
#include "api/ai_road.hpp.sq"
#include "api/ai_settings.hpp.sq"
#include "api/ai_sign.hpp.sq"
@@ -240,8 +238,6 @@
SQAIMap_Register(this->engine);
SQAIMarine_Register(this->engine);
SQAIOrder_Register(this->engine);
- SQAIPathFinder_Register(this->engine);
- SQAIPathFinderStupid_Register(this->engine);
SQAIRoad_Register(this->engine);
SQAISettings_Register(this->engine);
SQAISign_Register(this->engine);
--- a/src/ai/api/ai_pathfinder.hpp Mon Mar 31 06:33:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/* $Id$ */
-
-/** @file ai_pathfinder.hpp Everything to query and build pathfinders */
-
-#ifndef AI_PATHFINDER_HPP
-#define AI_PATHFINDER_HPP
-
-#include "ai_object.hpp"
-#include "ai_tilelist.hpp"
-
-/**
- * A class that handles the base pathfinder. It is ment as
- * parent-class for real implementation so all PFs have a general
- * interface, but can have different backends.
- */
-class AIPathFinder : public AIObject {
-public:
- /**
- * The type of pathfinders known in the game.
- */
- enum PathFinderType {
- PATHFINDER_ROAD,
- PATHFINDER_RAIL,
- };
-
- /**
- * The name of the class, needed by several sub-processes.
- */
- static const char *GetClassName() { return "AIPathFinder"; }
-
- /**
- * Find a route between 2 points. Any pathfinder might have specific
- * functions to calibrate penalties and stuff.
- * @param start a list of tiles from where we can start.
- * @param end a list of tiles where we can end.
- * @return internal structure about how to make the route, or NULL if no route was found.
- */
- virtual void *FindRoute(AITileList *start, AITileList *end) = 0;
-
- /**
- * Build the route as found by FindRoute.
- * @param result the result 'void *' from FindRoute.
- * @return true if the route was build, false if anything went wrong.
- */
- virtual bool BuildRoute(void *result) = 0;
-
- /**
- * When you are done with the route result, we have to free it in order to avoid memleaks.
- * @note Always call this function on the result of FindRoute, even when you ran BuildRoute before!
- */
- virtual void FreeRoute(void *result) = 0;
-
- /** Keep the compilers happy */
- virtual ~AIPathFinder() {}
-};
-
-#endif /* AI_PATHFINDER_HPP */
--- a/src/ai/api/ai_pathfinder.hpp.sq Mon Mar 31 06:33:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#include "ai_pathfinder.hpp"
-
-namespace SQConvert {
- /* Allow enums to be used as Squirrel parameters */
- template <> AIPathFinder::PathFinderType GetParam(ForceType<AIPathFinder::PathFinderType>, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIPathFinder::PathFinderType)tmp; }
- template <> int Return<AIPathFinder::PathFinderType>(HSQUIRRELVM vm, AIPathFinder::PathFinderType res) { sq_pushinteger(vm, (int32)res); return 1; }
-
- /* Allow AIPathFinder to be used as Squirrel parameter */
- template <> AIPathFinder *GetParam(ForceType<AIPathFinder *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIPathFinder *)instance; }
- template <> AIPathFinder &GetParam(ForceType<AIPathFinder &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIPathFinder *)instance; }
- template <> const AIPathFinder *GetParam(ForceType<const AIPathFinder *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIPathFinder *)instance; }
- template <> const AIPathFinder &GetParam(ForceType<const AIPathFinder &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIPathFinder *)instance; }
- template <> int Return<AIPathFinder *>(HSQUIRRELVM vm, AIPathFinder *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIPathFinder", res, NULL, DefSQDestructorCallback<AIPathFinder>); return 1; }
-}; // namespace SQConvert
-
-void SQAIPathFinder_Register(Squirrel *engine) {
- DefSQClass <AIPathFinder> SQAIPathFinder("AIPathFinder");
- SQAIPathFinder.PreRegister(engine);
-
- SQAIPathFinder.DefSQConst(engine, AIPathFinder::PATHFINDER_ROAD, "PATHFINDER_ROAD");
- SQAIPathFinder.DefSQConst(engine, AIPathFinder::PATHFINDER_RAIL, "PATHFINDER_RAIL");
-
- SQAIPathFinder.DefSQStaticMethod(engine, &AIPathFinder::GetClassName, "GetClassName", 1, "x");
-
- SQAIPathFinder.PostRegister(engine);
-}
--- a/src/ai/api/ai_pathfinder_stupid.cpp Mon Mar 31 06:33:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/* $Id$ */
-
-/** @file ai_pathfinder_stupid.cpp A very stupid pathfinder */
-
-#include "ai_pathfinder_stupid.hpp"
-#include "ai_road.hpp"
-#include "ai_testmode.hpp"
-#include "../../map_func.h"
-
-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;
-}
--- a/src/ai/api/ai_pathfinder_stupid.hpp Mon Mar 31 06:33:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/* $Id$ */
-
-/** @file ai_pathfinder_stupid.hpp A really stupid pathfinder */
-
-#ifndef AI_PATHFINDER_STUPID_HPP
-#define AI_PATHFINDER_STUPID_HPP
-
-#include "ai_pathfinder.hpp"
-
-/**
- * A stupid pathfinder. It first makes a straight line on the X-axis, than
- * it does the same on the Y-axis. The result is rarely optimal, or connected.
- */
-class AIPathFinderStupid : public AIPathFinder {
-public:
- /**
- * The name of the class, needed by several sub-processes.
- */
- static const char *GetClassName() { return "AIPathFinderStupid"; }
-
- /**
- * Custom constructor, to see for which type we are going to be a pathfinder.
- */
- AIPathFinderStupid(AIPathFinder::PathFinderType type) { this->type = type; }
-
- void *FindRoute(AITileList *start, AITileList *end);
- bool BuildRoute(void *result);
- void FreeRoute(void *result);
-
- /** Keep the compilers happy */
- virtual ~AIPathFinderStupid() {}
-private:
- AIPathFinder::PathFinderType type;
-
- /**
- * Internal storage of the pointer returned by FindRoute which can be given to BuildRoute.
- */
- struct Path {
- TileIndex start;
- TileIndex end;
- };
-
- /**
- * Build the real route based on begin and end tile.
- */
- bool BuildRealRoute(TileIndex start, TileIndex end, bool continue_on_error);
-};
-
-#endif /* AI_PATHFINDER_HPP */
--- a/src/ai/api/ai_pathfinder_stupid.hpp.sq Mon Mar 31 06:33:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#include "ai_pathfinder_stupid.hpp"
-
-namespace SQConvert {
- /* Allow AIPathFinderStupid to be used as Squirrel parameter */
- template <> AIPathFinderStupid *GetParam(ForceType<AIPathFinderStupid *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIPathFinderStupid *)instance; }
- template <> AIPathFinderStupid &GetParam(ForceType<AIPathFinderStupid &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIPathFinderStupid *)instance; }
- template <> const AIPathFinderStupid *GetParam(ForceType<const AIPathFinderStupid *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIPathFinderStupid *)instance; }
- template <> const AIPathFinderStupid &GetParam(ForceType<const AIPathFinderStupid &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIPathFinderStupid *)instance; }
- template <> int Return<AIPathFinderStupid *>(HSQUIRRELVM vm, AIPathFinderStupid *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIPathFinderStupid", res, NULL, DefSQDestructorCallback<AIPathFinderStupid>); return 1; }
-}; // namespace SQConvert
-
-void SQAIPathFinderStupid_Register(Squirrel *engine) {
- DefSQClass <AIPathFinderStupid> SQAIPathFinderStupid("AIPathFinderStupid");
- SQAIPathFinderStupid.PreRegister(engine, "AIPathFinder");
- SQAIPathFinderStupid.AddConstructor<void (AIPathFinderStupid::*)(AIPathFinder::PathFinderType type), 2>(engine, "xi");
-
- SQAIPathFinderStupid.DefSQStaticMethod(engine, &AIPathFinderStupid::GetClassName, "GetClassName", 1, "x");
-
- SQAIPathFinderStupid.DefSQMethod(engine, &AIPathFinderStupid::FindRoute, "FindRoute", 3, "xxx");
- SQAIPathFinderStupid.DefSQMethod(engine, &AIPathFinderStupid::BuildRoute, "BuildRoute", 2, "xp");
- SQAIPathFinderStupid.DefSQMethod(engine, &AIPathFinderStupid::FreeRoute, "FreeRoute", 2, "xp");
-
- SQAIPathFinderStupid.PostRegister(engine);
-}