(svn r13610) [NoAI] -Add: AIDepotList giving you a list of the locations of your depots (including hangars). noai
authorrubidium
Sun, 22 Jun 2008 21:41:03 +0000
branchnoai
changeset 11053 d8d48e076a3f
parent 11051 00251d01f070
child 11056 d91b79ffff9c
(svn r13610) [NoAI] -Add: AIDepotList giving you a list of the locations of your depots (including hangars).
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
projects/openttd_vs80.vcproj
projects/openttd_vs90.vcproj
source.list
src/ai/api/ai_controller.cpp
src/ai/api/ai_depotlist.cpp
src/ai/api/ai_depotlist.hpp
src/ai/api/ai_depotlist.hpp.sq
--- a/bin/ai/regression/regression.nut	Sun Jun 22 16:01:48 2008 +0000
+++ b/bin/ai/regression/regression.nut	Sun Jun 22 21:41:03 2008 +0000
@@ -828,6 +828,14 @@
 	print("    GetRoadDepotFrontTile():       " + AIRoad.GetRoadDepotFrontTile(33411));
 	print("    IsRoadDepotTile():             " + AIRoad.IsRoadDepotTile(33411));
 	print("    IsBuildable():                 " + AITile.IsBuildable(33411));
+	local list = AIDepotList(AITile.TRANSPORT_ROAD);
+	print("    DepotList");
+	print("      Count():                     " + list.Count());
+	list.Valuate(AITile.GetDistanceManhattanToTile, 0);
+	print("      Depot distance from (0,0) ListDump:");
+	for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+		print("        " + i + " => " + list.GetValue(i));
+	}
 	print("    RemoveRoadDepot():             " + AIRoad.RemoveRoadDepot(33411));
 	print("    RemoveRoadDepot():             " + AIRoad.RemoveRoadDepot(33411));
 
--- a/bin/ai/regression/regression.txt	Sun Jun 22 16:01:48 2008 +0000
+++ b/bin/ai/regression/regression.txt	Sun Jun 22 21:41:03 2008 +0000
@@ -6039,6 +6039,10 @@
     GetRoadDepotFrontTile():       33412
     IsRoadDepotTile():             true
     IsBuildable():                 false
+    DepotList
+      Count():                     1
+      Depot distance from (0,0) ListDump:
+        33411 => 261
     RemoveRoadDepot():             true
     RemoveRoadDepot():             false
   Station
--- a/projects/openttd_vs80.vcproj	Sun Jun 22 16:01:48 2008 +0000
+++ b/projects/openttd_vs80.vcproj	Sun Jun 22 21:41:03 2008 +0000
@@ -1360,6 +1360,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\squirrel_helper_type.hpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\squirrel_std.hpp"
 				>
 			</File>
@@ -2336,6 +2340,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\ai\api\ai_depotlist.hpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\ai\api\ai_engine.hpp"
 				>
 			</File>
@@ -2512,6 +2520,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\ai\api\ai_depotlist.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\ai\api\ai_engine.cpp"
 				>
 			</File>
--- a/projects/openttd_vs90.vcproj	Sun Jun 22 16:01:48 2008 +0000
+++ b/projects/openttd_vs90.vcproj	Sun Jun 22 21:41:03 2008 +0000
@@ -1357,6 +1357,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\squirrel_helper_type.hpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\squirrel_std.hpp"
 				>
 			</File>
@@ -2333,6 +2337,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\ai\api\ai_depotlist.hpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\ai\api\ai_engine.hpp"
 				>
 			</File>
@@ -2509,6 +2517,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\ai\api\ai_depotlist.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\ai\api\ai_engine.cpp"
 				>
 			</File>
--- a/source.list	Sun Jun 22 16:01:48 2008 +0000
+++ b/source.list	Sun Jun 22 21:41:03 2008 +0000
@@ -265,6 +265,7 @@
 squirrel.hpp
 squirrel_class.hpp
 squirrel_helper.hpp
+squirrel_helper_type.hpp
 squirrel_std.hpp
 video/sdl_v.h
 settings_func.h
@@ -532,6 +533,7 @@
 ai/api/ai_company.hpp
 ai/api/ai_controller.hpp
 ai/api/ai_date.hpp
+ai/api/ai_depotlist.hpp
 ai/api/ai_engine.hpp
 ai/api/ai_enginelist.hpp
 ai/api/ai_error.hpp
@@ -577,6 +579,7 @@
 ai/api/ai_company.cpp
 ai/api/ai_controller.cpp
 ai/api/ai_date.cpp
+ai/api/ai_depotlist.cpp
 ai/api/ai_engine.cpp
 ai/api/ai_enginelist.cpp
 ai/api/ai_error.cpp
--- a/src/ai/api/ai_controller.cpp	Sun Jun 22 16:01:48 2008 +0000
+++ b/src/ai/api/ai_controller.cpp	Sun Jun 22 21:41:03 2008 +0000
@@ -31,6 +31,7 @@
 #include "ai_company.hpp.sq"
 #include "ai_controller.hpp.sq"
 #include "ai_date.hpp.sq"
+#include "ai_depotlist.hpp.sq"
 #include "ai_engine.hpp.sq"
 #include "ai_enginelist.hpp.sq"
 #include "ai_error.hpp.sq"
@@ -94,6 +95,7 @@
 	SQAICompany_Register(this->engine);
 	SQAIController_Register(this->engine);
 	SQAIDate_Register(this->engine);
+	SQAIDepotList_Register(this->engine);
 	SQAIEngine_Register(this->engine);
 	SQAIEngineList_Register(this->engine);
 	SQAIError_Register(this->engine);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_depotlist.cpp	Sun Jun 22 21:41:03 2008 +0000
@@ -0,0 +1,42 @@
+/* $Id$ */
+
+/** @file ai_depotlist.cpp Implementation of AIDepotList and friends. */
+
+#include "ai_depotlist.hpp"
+#include "../../core/math_func.hpp"
+#include "../../tile_map.h"
+#include "../../player_func.h"
+#include "../../depot_base.h"
+#include "../../station_base.h"
+
+AIDepotList::AIDepotList(AITile::TransportType transport_type)
+{
+	::TileType tile_type;
+	switch (transport_type) {
+		default: return;
+
+		case AITile::TRANSPORT_ROAD:  tile_type = ::MP_ROAD; break;
+		case AITile::TRANSPORT_RAIL:  tile_type = ::MP_RAILWAY; break;
+		case AITile::TRANSPORT_WATER: tile_type = ::MP_WATER; break;
+
+		case AITile::TRANSPORT_AIR: {
+			/* Hangars are not seen as real depots by the depot code. */
+			const Station *st;
+			FOR_ALL_STATIONS(st) {
+				if (st->owner == ::_current_player) {
+					const AirportFTAClass *afc = st->Airport();
+					for (uint i = 0; i < afc->nof_depots; i++) {
+						this->AddItem(st->xy + ToTileIndexDiff(afc->airport_depots[i]));
+					}
+				}
+			}
+			return;
+		}
+	}
+
+	/* Handle 'standard' depots. */
+	const Depot *depot;
+	FOR_ALL_DEPOTS(depot) {
+		if (::GetTileOwner(depot->xy) == ::_current_player && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_depotlist.hpp	Sun Jun 22 21:41:03 2008 +0000
@@ -0,0 +1,25 @@
+/* $Id$ */
+
+/** @file ai_depotlist.hpp List all the depots (you own). */
+
+#ifndef AI_DEPOTLIST_HPP
+#define AI_DEPOTLIST_HPP
+
+#include "ai_abstractlist.hpp"
+#include "ai_tile.hpp"
+
+/**
+ * Creates a list of the locations of the depots (and hangars) of which you are the owner.
+ * @ingroup AIList
+ */
+class AIDepotList : public AIAbstractList {
+public:
+	static const char *GetClassName() { return "AIDepotList"; }
+
+	/**
+	 * @param transport_type The type of transport to make a list of depots for.
+	 */
+	AIDepotList(AITile::TransportType transport_type);
+};
+
+#endif /* AI_DEPOTLIST_HPP */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_depotlist.hpp.sq	Sun Jun 22 21:41:03 2008 +0000
@@ -0,0 +1,23 @@
+/* $Id$ */
+/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
+
+#include "ai_depotlist.hpp"
+
+namespace SQConvert {
+	/* Allow AIDepotList to be used as Squirrel parameter */
+	template <> AIDepotList *GetParam(ForceType<AIDepotList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AIDepotList *)instance; }
+	template <> AIDepotList &GetParam(ForceType<AIDepotList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIDepotList *)instance; }
+	template <> const AIDepotList *GetParam(ForceType<const AIDepotList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AIDepotList *)instance; }
+	template <> const AIDepotList &GetParam(ForceType<const AIDepotList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIDepotList *)instance; }
+	template <> int Return<AIDepotList *>(HSQUIRRELVM vm, AIDepotList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIDepotList", res, NULL, DefSQDestructorCallback<AIDepotList>); return 1; }
+}; // namespace SQConvert
+
+void SQAIDepotList_Register(Squirrel *engine) {
+	DefSQClass <AIDepotList> SQAIDepotList("AIDepotList");
+	SQAIDepotList.PreRegister(engine, "AIAbstractList");
+	SQAIDepotList.AddConstructor<void (AIDepotList::*)(AITile::TransportType transport_type), 2>(engine, "xi");
+
+	SQAIDepotList.DefSQStaticMethod(engine, &AIDepotList::GetClassName, "GetClassName", 1, "x");
+
+	SQAIDepotList.PostRegister(engine);
+}