--- a/bin/ai/regression/regression.nut Sun Aug 19 13:22:13 2007 +0000
+++ b/bin/ai/regression/regression.nut Sun Aug 19 13:31:04 2007 +0000
@@ -686,6 +686,15 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+
+ list.AddRectangle(54421 - 256 * 2, 256 * 2 + 54421 + 8);
+ list.Valuate(AITileListWater());
+ print(" Water(): done");
+ print(" Count(): " + list.Count());
+ print(" ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
}
function Regression::Town()
--- a/bin/ai/regression/regression.txt Sun Aug 19 13:22:13 2007 +0000
+++ b/bin/ai/regression/regression.txt Sun Aug 19 13:31:04 2007 +0000
@@ -1392,6 +1392,55 @@
Count(): 1
ListDump:
42409 => 1
+ Water(): done
+ Count(): 46
+ ListDump:
+ 54941 => 1
+ 54940 => 1
+ 54939 => 1
+ 54938 => 1
+ 54937 => 1
+ 54936 => 1
+ 54935 => 1
+ 54934 => 1
+ 54933 => 1
+ 54685 => 1
+ 54684 => 1
+ 54683 => 1
+ 54682 => 1
+ 54681 => 1
+ 54680 => 1
+ 54679 => 1
+ 54678 => 1
+ 54677 => 1
+ 54429 => 1
+ 54428 => 1
+ 54427 => 1
+ 54426 => 1
+ 54425 => 1
+ 54424 => 1
+ 54423 => 1
+ 54422 => 1
+ 54421 => 1
+ 54173 => 1
+ 54172 => 1
+ 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 => 0
+ 53911 => 0
+ 53910 => 0
+ 53909 => 0
+ 42409 => 0
--Town--
GetMaxTownID(): 31
--- a/src/ai/ai_squirrel.cpp Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/ai_squirrel.cpp Sun Aug 19 13:31:04 2007 +0000
@@ -256,6 +256,7 @@
SQAITileListRegister(this->engine);
SQAITileListRoadTileRegister(this->engine);
SQAITileListSlopeRegister(this->engine);
+ SQAITileListWaterRegister(this->engine);
SQAITileRegister(this->engine);
SQAITownListDistanceManhattanToTileRegister(this->engine);
SQAITownListDistanceSquareToTileRegister(this->engine);
--- a/src/ai/api/ai_tile.cpp Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tile.cpp Sun Aug 19 13:31:04 2007 +0000
@@ -23,6 +23,14 @@
}
}
+bool AITile::IsWater(TileIndex tile)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return false;
+
+ return ::GetTileType(tile) == MP_WATER;
+}
+
int32 AITile::GetSlope(TileIndex tile)
{
/* Outside of the map */
--- a/src/ai/api/ai_tile.hpp Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tile.hpp Sun Aug 19 13:31:04 2007 +0000
@@ -27,6 +27,14 @@
static bool IsBuildable(TileIndex tile);
/**
+ * Check if a tile is water.
+ * @pre tile is always positive and smaller than AIMap::GetMapSize().
+ * @param tile the tile to check on.
+ * @return true if it is water, false if not.
+ */
+ static bool IsWater(TileIndex tile);
+
+ /**
* Get the slope of a tile.
* @pre tile is always positive and smaller than AIMap::GetMapSize().
* @param tile the tile to check on.
--- a/src/ai/api/ai_tile.hpp.sq Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Sun Aug 19 13:31:04 2007 +0000
@@ -16,6 +16,7 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetClassName, "GetClassName", 1, "x");
SQAITile.DefSQStaticMethod(engine, &AITile::IsBuildable, "IsBuildable", 2, "xi");
+ SQAITile.DefSQStaticMethod(engine, &AITile::IsWater, "IsWater", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope, "GetSlope", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
--- a/src/ai/api/ai_tilelist_valuator.cpp Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.cpp Sun Aug 19 13:31:04 2007 +0000
@@ -10,6 +10,11 @@
return AITile::IsBuildable(tile);
}
+int32 AITileListWater::Valuate(int32 tile) const
+{
+ return AITile::IsWater(tile);
+}
+
int32 AITileListBuildableRectangle::Valuate(int32 tile) const
{
uint tx, ty;
--- a/src/ai/api/ai_tilelist_valuator.hpp Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp Sun Aug 19 13:31:04 2007 +0000
@@ -24,6 +24,22 @@
};
/**
+ * Check if tiles are water-tiles for entries in an AITileList instance.
+ * @note resulting items are of the type bool (0 = not water-tile, 1 = water-tile)
+ * @note the input items are of the type TileIndex
+ */
+class AITileListWater : public AIAbstractList::Valuator {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AITileListWater"; }
+
+private:
+ int32 Valuate(int32 tile) const;
+};
+
+/**
* Check if tiles are buildable in a rectangle around entries in an AITileList instance, with the entry in the list as top-left.
* @note resulting items are of the type bool (0 = not buildable, 1 = buildable)
* @note the input items are of the type TileIndex
--- a/src/ai/api/ai_tilelist_valuator.hpp.sq Sun Aug 19 13:22:13 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp.sq Sun Aug 19 13:31:04 2007 +0000
@@ -20,6 +20,25 @@
}
namespace SQConvert {
+ /* Allow AITileListWater to be used as Squirrel parameter */
+ template <> AITileListWater *GetParam(ForceType<AITileListWater *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListWater *)instance; }
+ template <> AITileListWater &GetParam(ForceType<AITileListWater &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListWater *)instance; }
+ template <> const AITileListWater *GetParam(ForceType<const AITileListWater *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListWater *)instance; }
+ template <> const AITileListWater &GetParam(ForceType<const AITileListWater &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListWater *)instance; }
+ template <> int Return<AITileListWater *>(HSQUIRRELVM vm, AITileListWater *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AITileListWater", res, NULL, DefSQDestructorCallback<AITileListWater>); return 1; }
+}; // namespace SQConvert
+
+void SQAITileListWaterRegister(Squirrel *engine) {
+ DefSQClass <AITileListWater> SQAITileListWater("AITileListWater");
+ SQAITileListWater.PreRegister(engine);
+ SQAITileListWater.AddConstructor<void (AITileListWater::*)(), 1>(engine, "x");
+
+ SQAITileListWater.DefSQStaticMethod(engine, &AITileListWater::GetClassName, "GetClassName", 1, "x");
+
+ SQAITileListWater.PostRegister(engine);
+}
+
+namespace SQConvert {
/* Allow AITileListBuildableRectangle to be used as Squirrel parameter */
template <> AITileListBuildableRectangle *GetParam(ForceType<AITileListBuildableRectangle *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListBuildableRectangle *)instance; }
template <> AITileListBuildableRectangle &GetParam(ForceType<AITileListBuildableRectangle &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListBuildableRectangle *)instance; }