(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
--- a/bin/ai/regression/regression.nut Thu Jun 12 10:34:21 2008 +0000
+++ b/bin/ai/regression/regression.nut Thu Jun 12 11:15:59 2008 +0000
@@ -619,7 +619,9 @@
print(" BuildDock(): " + AIMarine.BuildDock(29253));
print(" BuildBuoy(): " + AIMarine.BuildBuoy(28481));
print(" BuildLock(): " + AIMarine.BuildLock(28487));
+ print(" HasTransportType(): " + AITile.HasTransportType(32127, AITile.TRANSPORT_WATER));
print(" BuildCanal(): " + AIMarine.BuildCanal(32127));
+ print(" HasTransportType(): " + AITile.HasTransportType(32127, AITile.TRANSPORT_WATER));
print(" IsWaterDepotTile(): " + AIMarine.IsWaterDepotTile(28479));
print(" IsDockTile(): " + AIMarine.IsDockTile(29253));
print(" IsBuoyTile(): " + AIMarine.IsBuoyTile(28481));
@@ -766,7 +768,9 @@
print(" IsRoadTile(): " + AIRoad.IsRoadTile(33411));
print(" BuildRoad(): " + AIRoad.BuildRoad(0, 1));
print(" BuildRoad(): " + AIRoad.BuildRoad(33411, 33411));
+ print(" HasTransportType(): " + AITile.HasTransportType(33413, AITile.TRANSPORT_ROAD));
print(" BuildRoad(): " + AIRoad.BuildRoad(33411, 33414));
+ print(" HasTransportType(): " + AITile.HasTransportType(33413, AITile.TRANSPORT_ROAD));
print(" AreRoadTilesConnected(): " + AIRoad.AreRoadTilesConnected(33412, 33413));
print(" IsRoadTile(): " + AIRoad.IsRoadTile(33411));
print(" HasRoadType(Road): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_ROAD));
--- a/bin/ai/regression/regression.txt Thu Jun 12 10:34:21 2008 +0000
+++ b/bin/ai/regression/regression.txt Thu Jun 12 11:15:59 2008 +0000
@@ -5696,7 +5696,9 @@
BuildDock(): true
BuildBuoy(): true
BuildLock(): true
+ HasTransportType(): false
BuildCanal(): true
+ HasTransportType(): true
IsWaterDepotTile(): true
IsDockTile(): true
IsBuoyTile(): true
@@ -5764,7 +5766,9 @@
IsRoadTile(): false
BuildRoad(): false
BuildRoad(): false
+ HasTransportType(): false
BuildRoad(): true
+ HasTransportType(): true
AreRoadTilesConnected(): true
IsRoadTile(): true
HasRoadType(Road): true
--- a/src/ai/api/ai_tile.cpp Thu Jun 12 10:34:21 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Thu Jun 12 11:15:59 2008 +0000
@@ -7,6 +7,7 @@
#include "ai_town.hpp"
#include "../../openttd.h"
#include "../../tile_map.h"
+#include "../../tile_cmd.h"
#include "../../map_func.h"
#include "../../variables.h"
#include "../../station_func.h"
@@ -113,6 +114,13 @@
return AICompany::ResolveCompanyID((AICompany::CompanyID)(byte)::GetTileOwner(tile));
}
+/* static */ bool AITile::HasTransportType(TileIndex tile, TransportType transport_type)
+{
+ if (!::IsValidTile(tile)) return false;
+
+ return GB(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX), 0, 16) != 0;
+}
+
/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
{
if (!::IsValidTile(tile)) return false;
--- a/src/ai/api/ai_tile.hpp Thu Jun 12 10:34:21 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Thu Jun 12 11:15:59 2008 +0000
@@ -39,6 +39,7 @@
* is the north-part of the tile.
*/
enum Slope {
+ /* Values are important, as they represent the internal state of the game. */
SLOPE_FLAT = 0x00, //!< A flat tile
SLOPE_W = 0x01, //!< The west corner of the tile is raised
SLOPE_S = 0x02, //!< The south corner of the tile is raised
@@ -65,6 +66,19 @@
};
/**
+ * The different transport types a tile can have.
+ */
+ enum TransportType {
+ /* Values are important, as they represent the internal state of the game. */
+ TRANSPORT_RAIL = 0, //!< Tile with rail.
+ TRANSPORT_ROAD = 1, //!< Tile with road.
+ TRANSPORT_WATER = 2, //!< Tile with navigable waterways.
+ TRANSPORT_AIR = 3, //!< Tile with airport.
+
+ INVALID_TRANSPORT = -1, //!< Tile without any transport type.
+ };
+
+ /**
* Check if this tile is buildable, i.e. no things on it that needs
* demolishing.
* @param tile The tile to check on.
@@ -158,6 +172,20 @@
static AICompany::CompanyID GetOwner(TileIndex tile);
/**
+ * Checks whether the given tile contains parts suitable for the given
+ * TransportType.
+ * @param tile The tile to check.
+ * @param transport_type The TransportType to check against.
+ * @pre AIMap::IsValidTile(tile).
+ * @note Returns false on tiles with roadworks and on road tiles with only
+ * a single piece of road as these tiles cannot be used to transport
+ * anything on. It furthermore returns true on some coast tile for
+ * TRANSPORT_WATER because ships can navigate over them.
+ * @return True if and only if the tile has the given TransportType.
+ */
+ static bool HasTransportType(TileIndex tile, TransportType transport_type);
+
+ /**
* Check how much cargo this tile accepts.
* It creates a radius around the tile, and adds up all acceptance of this
* cargo.
--- a/src/ai/api/ai_tile.hpp.sq Thu Jun 12 10:34:21 2008 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Thu Jun 12 11:15:59 2008 +0000
@@ -9,6 +9,8 @@
template <> int Return<AITile::ErrorMessages>(HSQUIRRELVM vm, AITile::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> AITile::Slope GetParam(ForceType<AITile::Slope>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AITile::Slope)tmp; }
template <> int Return<AITile::Slope>(HSQUIRRELVM vm, AITile::Slope res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> AITile::TransportType GetParam(ForceType<AITile::TransportType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AITile::TransportType)tmp; }
+ template <> int Return<AITile::TransportType>(HSQUIRRELVM vm, AITile::TransportType res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow AITile to be used as Squirrel parameter */
template <> AITile *GetParam(ForceType<AITile *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITile *)instance; }
@@ -48,6 +50,11 @@
SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_E, "SLOPE_STEEP_E");
SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_N, "SLOPE_STEEP_N");
SQAITile.DefSQConst(engine, AITile::SLOPE_INVALID, "SLOPE_INVALID");
+ SQAITile.DefSQConst(engine, AITile::TRANSPORT_RAIL, "TRANSPORT_RAIL");
+ SQAITile.DefSQConst(engine, AITile::TRANSPORT_ROAD, "TRANSPORT_ROAD");
+ SQAITile.DefSQConst(engine, AITile::TRANSPORT_WATER, "TRANSPORT_WATER");
+ SQAITile.DefSQConst(engine, AITile::TRANSPORT_AIR, "TRANSPORT_AIR");
+ SQAITile.DefSQConst(engine, AITile::INVALID_TRANSPORT, "INVALID_TRANSPORT");
AIError::RegisterErrorMap(STR_1003_ALREADY_AT_SEA_LEVEL, AITile::ERR_TILE_TOO_HIGH);
AIError::RegisterErrorMap(STR_1003_ALREADY_AT_SEA_LEVEL, AITile::ERR_TILE_TOO_LOW);
@@ -66,6 +73,7 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetComplementSlope, "GetComplementSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetHeight, "GetHeight", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetOwner, "GetOwner", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::HasTransportType, "HasTransportType", 3, "xii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoProduction, "GetCargoProduction", 6, "xiiiii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");