(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
--- a/bin/ai/regression/regression.nut Tue Apr 15 15:34:02 2008 +0000
+++ b/bin/ai/regression/regression.nut Tue Apr 15 16:11:29 2008 +0000
@@ -803,6 +803,24 @@
print("");
print("--TileList--");
print(" Count(): " + list.Count());
+ list.AddRectangle(27631 - 256 * 1, 256 * 1 + 27631 + 2);
+ print(" Count(): " + list.Count());
+
+ list.Valuate(AITile.GetSlope);
+ print(" Slope(): done");
+ print(" Count(): " + list.Count());
+ print(" ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ print(" " + i + " => " + AITile.GetComplementSlope(list.GetValue(i)));
+ print(" " + i + " => " + AITile.IsSteepSlope(list.GetValue(i)));
+ print(" " + i + " => " + AITile.IsHalftileSlope(list.GetValue(i)));
+ }
+ list.Clear();
+
+ print("");
+ print("--TileList--");
+ print(" Count(): " + list.Count());
list.AddRectangle(41895 - 256 * 2, 256 * 2 + 41895 + 8);
print(" Count(): " + list.Count());
--- a/bin/ai/regression/regression.txt Tue Apr 15 15:34:02 2008 +0000
+++ b/bin/ai/regression/regression.txt Tue Apr 15 16:11:29 2008 +0000
@@ -5443,6 +5443,49 @@
--TileList--
Count(): 0
+ Count(): 9
+ Slope(): done
+ Count(): 9
+ ListDump:
+ 27631 => 29
+ 27631 => 255
+ 27631 => true
+ 27631 => false
+ 27888 => 13
+ 27888 => 2
+ 27888 => false
+ 27888 => false
+ 27376 => 12
+ 27376 => 3
+ 27376 => false
+ 27376 => false
+ 27375 => 12
+ 27375 => 3
+ 27375 => false
+ 27375 => false
+ 27889 => 9
+ 27889 => 6
+ 27889 => false
+ 27889 => false
+ 27887 => 8
+ 27887 => 7
+ 27887 => false
+ 27887 => false
+ 27632 => 8
+ 27632 => 7
+ 27632 => false
+ 27632 => false
+ 27633 => 0
+ 27633 => 15
+ 27633 => false
+ 27633 => false
+ 27377 => 0
+ 27377 => 15
+ 27377 => false
+ 27377 => false
+
+--TileList--
+ Count(): 0
Count(): 45
Height(): done
Count(): 45
--- a/src/ai/api/ai_tile.cpp Tue Apr 15 15:34:02 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Tue Apr 15 16:11:29 2008 +0000
@@ -55,11 +55,34 @@
return ::GetTileType(tile) == MP_WATER;
}
-/* static */ int32 AITile::GetSlope(TileIndex tile)
+/* static */ bool AITile::IsSteepSlope(Slope slope)
{
- if (!::IsValidTile(tile)) return false;
+ if (slope == SLOPE_INVALID) return false;
- return ::GetTileSlope(tile, NULL);
+ return ::IsSteepSlope((::Slope)slope);
+}
+
+/* static */ bool AITile::IsHalftileSlope(Slope slope)
+{
+ if (slope == SLOPE_INVALID) return false;
+
+ return ::IsHalftileSlope((::Slope)slope);
+}
+
+/* static */ AITile::Slope AITile::GetSlope(TileIndex tile)
+{
+ if (!::IsValidTile(tile)) return SLOPE_INVALID;
+
+ return (Slope)::GetTileSlope(tile, NULL);
+}
+
+/* static */ AITile::Slope AITile::GetComplementSlope(Slope slope)
+{
+ if (slope == SLOPE_INVALID) return SLOPE_INVALID;
+ if (IsSteepSlope(slope)) return SLOPE_INVALID;
+ if (IsHalftileSlope(slope)) return SLOPE_INVALID;
+
+ return (Slope)::ComplementSlope((::Slope)slope);
}
/* static */ int32 AITile::GetHeight(TileIndex tile)
--- a/src/ai/api/ai_tile.hpp Tue Apr 15 15:34:02 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Tue Apr 15 16:11:29 2008 +0000
@@ -58,7 +58,9 @@
SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS, //!< A steep slope falling to east (from west)
SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE, //!< A steep slope falling to north (from south)
SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, //!< A steep slope falling to west (from east)
- SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW //!< A steep slope falling to south (from north)
+ SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW, //!< A steep slope falling to south (from north)
+
+ SLOPE_INVALID = 0xFF, //!< An invalid slope
};
/**
@@ -92,12 +94,39 @@
static bool IsWater(TileIndex tile);
/**
+ * Check if a tile has a steep slope.
+ * @param slope The slope to check on.
+ * @pre slope != SLOPE_INVALID.
+ * @return True if the slope is a steep slope.
+ */
+ static bool IsSteepSlope(Slope slope);
+
+ /**
+ * Check if a tile has a halftile slope.
+ * @param slope The slope to check on.
+ * @pre slope != SLOPE_INVALID.
+ * @return True if the slope is a halftile slope.
+ */
+ static bool IsHalftileSlope(Slope slope);
+
+ /**
* Get the slope of a tile.
* @param tile The tile to check on.
* @pre AIMap::IsValidTile(tile).
* @return 0 means flat, others indicate internal state of slope.
*/
- static int32 GetSlope(TileIndex tile);
+ static Slope GetSlope(TileIndex tile);
+
+ /**
+ * Get the complement of the slope.
+ * @param slope The slope to get the complement of.
+ * @pre slope != SLOPE_INVALID.
+ * @pre !IsSteepSlope(slope).
+ * @pre !IsHalftileSlope(slope).
+ * @return The complement of a slope. This means that all corners that
+ * weren't raised, are raised, and visa versa.
+ */
+ static Slope GetComplementSlope(Slope slope);
/**
* Get the height of the tile.
--- a/src/ai/api/ai_tile.hpp.sq Tue Apr 15 15:34:02 2008 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Tue Apr 15 16:11:29 2008 +0000
@@ -44,6 +44,7 @@
SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_S, "SLOPE_STEEP_S");
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");
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);
@@ -55,7 +56,10 @@
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::IsSteepSlope, "IsSteepSlope", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::IsHalftileSlope, "IsHalftileSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope, "GetSlope", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::GetComplementSlope, "GetComplementSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetHeight, "GetHeight", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoProduction, "GetCargoProduction", 6, "xiiiii");