--- a/bin/ai/regression/regression.nut Wed Feb 27 22:45:27 2008 +0000
+++ b/bin/ai/regression/regression.nut Wed Feb 27 23:06:43 2008 +0000
@@ -932,6 +932,16 @@
}
}
+function Regression::Tunnel()
+{
+ print(" IsTunnelTile(): " + AITunnel.IsTunnelTile(29050));
+ print(" RemoveTunnel(): " + AITunnel.RemoveTunnel(29050));
+ print(" BuildTunnel(): " + AITunnel.BuildTunnel(AIVehicle.VEHICLE_ROAD, 29050));
+ print(" IsTunnelTile(): " + AITunnel.IsTunnelTile(29050));
+ print(" RemoveTunnel(): " + AITunnel.RemoveTunnel(29050));
+ print(" IsTunnelTile(): " + AITunnel.IsTunnelTile(29050));
+}
+
function Regression::Vehicle()
{
local accounting = AIAccounting();
@@ -1094,6 +1104,7 @@
this.TileList();
this.Town();
this.TownList();
+ this.Tunnel();
this.Vehicle();
/* Order has to be after Vehicle */
this.Order();
--- a/bin/ai/regression/regression.txt Wed Feb 27 22:45:27 2008 +0000
+++ b/bin/ai/regression/regression.txt Wed Feb 27 23:06:43 2008 +0000
@@ -5658,6 +5658,12 @@
6 => 566
25 => 548
0 => 538
+ IsTunnelTile(): false
+ RemoveTunnel(): false
+ BuildTunnel(): true
+ IsTunnelTile(): true
+ RemoveTunnel(): true
+ IsTunnelTile(): false
--Vehicle--
IsValidVehicle(-1): false
@@ -5686,7 +5692,7 @@
IsStoppedInDepot(): false
--Accounting--
GetCosts(): -5945
- Should be: -5945
+ Should be: -5944
GetName(): Road Vehicle 1
SetName(): true
GetName(): MyVehicleName
@@ -5734,10 +5740,10 @@
13 => 1
11 => 1
Age ListDump:
- 12 => 1
11 => 1
15 => 0
13 => 0
+ 12 => 0
MaxAge ListDump:
15 => 10980
13 => 10980
@@ -5746,7 +5752,7 @@
AgeLeft ListDump:
15 => 10980
13 => 10980
- 12 => 5489
+ 12 => 5490
11 => 5489
ProfitThisYear ListDump:
15 => 0
--- a/projects/openttd_vs80.vcproj Wed Feb 27 22:45:27 2008 +0000
+++ b/projects/openttd_vs80.vcproj Wed Feb 27 23:06:43 2008 +0000
@@ -2096,6 +2096,10 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\api\ai_tunnel.hpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\api\ai_transactionmode.hpp"
>
</File>
@@ -2280,6 +2284,10 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\api\ai_tunnel.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\api\ai_transactionmode.cpp"
>
</File>
--- a/projects/openttd_vs90.vcproj Wed Feb 27 22:45:27 2008 +0000
+++ b/projects/openttd_vs90.vcproj Wed Feb 27 23:06:43 2008 +0000
@@ -2093,6 +2093,10 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\api\ai_tunnel.hpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\api\ai_transactionmode.hpp"
>
</File>
@@ -2277,6 +2281,10 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\api\ai_tunnel.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\api\ai_transactionmode.cpp"
>
</File>
--- a/source.list Wed Feb 27 22:45:27 2008 +0000
+++ b/source.list Wed Feb 27 23:06:43 2008 +0000
@@ -440,6 +440,7 @@
ai/api/ai_town.hpp
ai/api/ai_townlist.hpp
ai/api/ai_townlist_valuator.hpp
+ai/api/ai_tunnel.hpp
ai/api/ai_transactionmode.hpp
ai/api/ai_vehicle.hpp
ai/api/ai_vehiclelist.hpp
@@ -487,6 +488,7 @@
ai/api/ai_town.cpp
ai/api/ai_townlist.cpp
ai/api/ai_townlist_valuator.cpp
+ai/api/ai_tunnel.cpp
ai/api/ai_transactionmode.cpp
ai/api/ai_vehicle.cpp
ai/api/ai_vehiclelist.cpp
--- a/src/ai/ai_squirrel.cpp Wed Feb 27 22:45:27 2008 +0000
+++ b/src/ai/ai_squirrel.cpp Wed Feb 27 23:06:43 2008 +0000
@@ -64,6 +64,7 @@
#include "api/ai_townlist.hpp.sq"
#include "api/ai_townlist_valuator.hpp.sq"
#include "api/ai_transactionmode.hpp.sq"
+#include "api/ai_tunnel.hpp.sq"
#include "api/ai_vehicle.hpp.sq"
#include "api/ai_vehiclelist.hpp.sq"
#include "api/ai_vehiclelist_valuator.hpp.sq"
@@ -299,6 +300,7 @@
SQAITownList_vLocation_Register(this->engine);
SQAITownList_vPopulation_Register(this->engine);
SQAITransactionMode_Register(this->engine);
+ SQAITunnel_Register(this->engine);
SQAIVehicle_Register(this->engine);
SQAIVehicleList_Register(this->engine);
SQAIVehicleList_Station_Register(this->engine);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_tunnel.cpp Wed Feb 27 23:06:43 2008 +0000
@@ -0,0 +1,42 @@
+/** @file ai_tunnel.cpp handles the query-related of the AITunnel class and can construct tunnels **/
+
+#include "ai_tunnel.hpp"
+#include "../../landscape.h"
+#include "../../tunnel_map.h"
+#include "../../road_type.h"
+
+/* static */ bool AITunnel::IsTunnelTile(TileIndex tile)
+{
+ return ::IsTunnelTile(tile);
+}
+
+/* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile)
+{
+ if (!IsTunnelTile(tile)) return INVALID_TILE;
+
+ return ::GetOtherTunnelEnd(tile);
+}
+
+/* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start)
+{
+ if (!::IsValidTile(start)) return false;
+ if (vehicle_type != AIVehicle::VEHICLE_RAIL && vehicle_type != AIVehicle::VEHICLE_ROAD) return false;
+
+ uint type = 0;
+ if (vehicle_type == AIVehicle::VEHICLE_ROAD) {
+ type |= (TRANSPORT_ROAD << 9);
+ type |= ROADTYPES_ROAD;
+ } else {
+ type |= (TRANSPORT_RAIL << 9);
+ type |= RAILTYPES_RAIL;
+ }
+
+ return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL);
+}
+
+/* static */ bool AITunnel::RemoveTunnel(TileIndex tile)
+{
+ if (!IsTunnelTile(tile)) return false;
+
+ return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_tunnel.hpp Wed Feb 27 23:06:43 2008 +0000
@@ -0,0 +1,57 @@
+/** @file ai_tunnel.hpp Used to query and build tunnels. */
+
+#ifndef AI_TUNNEL_HPP
+#define AI_TUNNEL_HPP
+
+#include "ai_object.hpp"
+#include "ai_vehicle.hpp"
+
+/**
+ * Class that handles all tunnel related functions.
+ */
+class AITunnel : public AIObject {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AITunnel"; }
+
+ /**
+ * Check wether the tile is an entrance to a tunnel.
+ * @pre tile is always positive and smaller than AIMap::GetMapSize().
+ * @param tile The tile to check.
+ * @note true if and only if the tile is the beginning or end of a tunnel.
+ */
+ static bool IsTunnelTile(TileIndex tile);
+
+ /**
+ * Get the tile that exits on the other end of a tunnel starting at tunnelTile.
+ * @pre tile is always positive and smaller than AIMap::GetMapSize() and tunnel entrance must be located on that tile.
+ * @param tile A tile that is an entrance to a tunnel.
+ * @return The TileIndex that is the other end of the tunnel.
+ */
+ static TileIndex GetOtherTunnelEnd(TileIndex tile);
+
+ /**
+ * Builds a tunnel starting at start. The direction of the tunnel depends
+ * on the slope of the start tile. Tunnels can be created for either
+ * rails or roads; use the appropriate AIVehicle::VehicleType.
+ * @param start Where to start the tunnel.
+ * @param vehicle_type The vehicle-type of tunnel to build.
+ * @pre start is always positive and smaller than AIMap::GetMapSize().
+ * @pre vehicle_type is either AIVehicle::VEHICLE_RAIL or AIVEHICLE::VEHICLE_ROAD.
+ * @return Whether the tunnel has been/can be build or not.
+ * @note The slope of a tile can be determined by AITile::GetSlope(TileIndex).
+ */
+ static bool BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start);
+
+ /**
+ * Remove the tunnel whose entrance is located at tile.
+ * @pre tile is always positive and smaller than AIMap::GetMapSize().
+ * @param tile a tile that is an entrance to a tunnel.
+ * @return Whether the tunnel has been/can be removed or not.
+ */
+ static bool RemoveTunnel(TileIndex tile);
+};
+
+#endif /* AI_TUNNEL_HPP */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_tunnel.hpp.sq Wed Feb 27 23:06:43 2008 +0000
@@ -0,0 +1,24 @@
+#include "ai_tunnel.hpp"
+
+namespace SQConvert {
+ /* Allow AITunnel to be used as Squirrel parameter */
+ template <> AITunnel *GetParam(ForceType<AITunnel *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITunnel *)instance; }
+ template <> AITunnel &GetParam(ForceType<AITunnel &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITunnel *)instance; }
+ template <> const AITunnel *GetParam(ForceType<const AITunnel *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITunnel *)instance; }
+ template <> const AITunnel &GetParam(ForceType<const AITunnel &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITunnel *)instance; }
+ template <> int Return<AITunnel *>(HSQUIRRELVM vm, AITunnel *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AITunnel", res, NULL, DefSQDestructorCallback<AITunnel>); return 1; }
+}; // namespace SQConvert
+
+void SQAITunnel_Register(Squirrel *engine) {
+ DefSQClass <AITunnel> SQAITunnel("AITunnel");
+ SQAITunnel.PreRegister(engine);
+ SQAITunnel.AddConstructor<void (AITunnel::*)(), 1>(engine, "x");
+
+ SQAITunnel.DefSQStaticMethod(engine, &AITunnel::GetClassName, "GetClassName", 1, "x");
+ SQAITunnel.DefSQStaticMethod(engine, &AITunnel::IsTunnelTile, "IsTunnelTile", 2, "xi");
+ SQAITunnel.DefSQStaticMethod(engine, &AITunnel::GetOtherTunnelEnd, "GetOtherTunnelEnd", 2, "xi");
+ SQAITunnel.DefSQStaticMethod(engine, &AITunnel::BuildTunnel, "BuildTunnel", 3, "xii");
+ SQAITunnel.DefSQStaticMethod(engine, &AITunnel::RemoveTunnel, "RemoveTunnel", 2, "xi");
+
+ SQAITunnel.PostRegister(engine);
+}