(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
[NoAI] -Fix [API CHANGE]: Renamed AITile::IsWater() to AITile::IsWaterTile() to be more consistant; also, it no longer returns 'true' on coast tiles
[NoAI] -Add: added AITile::IsCoastTile(). Building on such tiles is in general more expensive
--- a/bin/ai/regression/regression.nut Thu Jun 12 10:14:05 2008 +0000
+++ b/bin/ai/regression/regression.nut Thu Jun 12 10:34:21 2008 +0000
@@ -1013,7 +1013,7 @@
}
list.AddRectangle(54421 - 256 * 2, 256 * 2 + 54421 + 8);
- list.Valuate(AITile.IsWater);
+ list.Valuate(AITile.IsWaterTile);
print(" Water(): done");
print(" Count(): " + list.Count());
print(" ListDump:");
--- a/bin/ai/regression/regression.txt Thu Jun 12 10:14:05 2008 +0000
+++ b/bin/ai/regression/regression.txt Thu Jun 12 10:34:21 2008 +0000
@@ -6203,16 +6203,16 @@
54171 => 1
54170 => 1
54169 => 1
- 54168 => 1
- 54167 => 1
- 54166 => 1
- 54165 => 1
- 53917 => 1
- 53916 => 1
- 53915 => 1
- 53914 => 1
- 53913 => 1
- 53912 => 1
+ 54168 => 0
+ 54167 => 0
+ 54166 => 0
+ 54165 => 0
+ 53917 => 0
+ 53916 => 0
+ 53915 => 0
+ 53914 => 0
+ 53913 => 0
+ 53912 => 0
53911 => 0
53910 => 0
53909 => 0
--- a/src/ai/api/ai_tile.cpp Thu Jun 12 10:14:05 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Thu Jun 12 10:34:21 2008 +0000
@@ -14,6 +14,7 @@
#include "../../settings_type.h"
#include "../../player_func.h"
#include "../../road_map.h"
+#include "../../water_map.h"
/* static */ bool AITile::IsBuildable(TileIndex tile)
{
@@ -23,6 +24,9 @@
default: return false;
case MP_CLEAR: return true;
case MP_TREES: return true;
+ case MP_WATER:
+ if (IsCoast(tile)) return true;
+ return false;
case MP_ROAD:
/* Depots aren't considered buildable */
if (::GetRoadTileType(tile) == ROAD_TILE_DEPOT) return false;
@@ -49,11 +53,18 @@
return true;
}
-/* static */ bool AITile::IsWater(TileIndex tile)
+/* static */ bool AITile::IsWaterTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
- return ::GetTileType(tile) == MP_WATER;
+ return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile);
+}
+
+/* static */ bool AITile::IsCoastTile(TileIndex tile)
+{
+ if (!::IsValidTile(tile)) return false;
+
+ return ::IsTileType(tile, MP_WATER) && ::IsCoast(tile);
}
/* static */ bool AITile::IsSteepSlope(Slope slope)
--- a/src/ai/api/ai_tile.hpp Thu Jun 12 10:14:05 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Thu Jun 12 10:34:21 2008 +0000
@@ -89,12 +89,21 @@
static bool IsBuildableRectangle(TileIndex tile, uint width, uint height);
/**
- * Check if a tile is water.
+ * Checks whether the given tile is actually a water tile.
* @param tile The tile to check on.
* @pre AIMap::IsValidTile(tile).
- * @return True if it is water, false if not.
+ * @return True if and only if the tile is a water tile.
*/
- static bool IsWater(TileIndex tile);
+ static bool IsWaterTile(TileIndex tile);
+
+ /**
+ * Checks whether the given tile is actually a coast tile.
+ * @param tile The tile to check.
+ * @pre AIMap::IsValidTile(tile).
+ * @return True if and only if the tile is a coast tile.
+ * @note Building on coast tiles in general is more expensive.
+ */
+ static bool IsCoastTile(TileIndex tile);
/**
* Check if a tile has a steep slope.
--- a/src/ai/api/ai_tile.hpp.sq Thu Jun 12 10:14:05 2008 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Thu Jun 12 10:34:21 2008 +0000
@@ -58,7 +58,8 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetClassName, "GetClassName", 1, "x");
SQAITile.DefSQStaticMethod(engine, &AITile::IsBuildable, "IsBuildable", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::IsBuildableRectangle, "IsBuildableRectangle", 4, "xiii");
- SQAITile.DefSQStaticMethod(engine, &AITile::IsWater, "IsWater", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::IsWaterTile, "IsWaterTile", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::IsCoastTile, "IsCoastTile", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::IsSteepSlope, "IsSteepSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::IsHalftileSlope, "IsHalftileSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope, "GetSlope", 2, "xi");