(svn r9776) [NoAI] -Add: added AITileListSlope as valuator to see if tiles are flat or not
--- a/bin/ai/regression/regression.nut Wed May 02 12:56:01 2007 +0000
+++ b/bin/ai/regression/regression.nut Fri May 04 15:57:29 2007 +0000
@@ -313,6 +313,16 @@
list.AddRectangle(41895 - 256 * 2, 256 * 2 + 41895 + 8);
print(" Count(): " + list.Count());
+ list.Valuate(AITileListSlope());
+ list.KeepValue(0);
+ print(" Slope(): done");
+ print(" KeepValue(0): done");
+ print(" Count(): " + list.Count());
+ print(" ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
+
list.Valuate(AITileListBuildable());
list.KeepValue(1);
print(" Buildable(): done");
--- a/src/ai/ai_squirrel.cpp Wed May 02 12:56:01 2007 +0000
+++ b/src/ai/ai_squirrel.cpp Fri May 04 15:57:29 2007 +0000
@@ -215,6 +215,7 @@
SQAITileListNeighbourRoadRegister(this->engine);
SQAITileListRegister(this->engine);
SQAITileListRoadTileRegister(this->engine);
+ SQAITileListSlopeRegister(this->engine);
SQAITownListGetLocationRegister(this->engine);
SQAITownListGetPopulationRegister(this->engine);
SQAITownListRegister(this->engine);
--- a/src/ai/api/ai_tilelist_valuator.cpp Wed May 02 12:56:01 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.cpp Fri May 04 15:57:29 2007 +0000
@@ -16,6 +16,11 @@
}
}
+int32 AITileListSlope::Valuate(int32 tile) const
+{
+ return GetTileSlope(tile, NULL);
+}
+
int32 AITileListNeighbourRoad::Valuate(int32 tile) const
{
int32 neighbour = 0;
--- a/src/ai/api/ai_tilelist_valuator.hpp Wed May 02 12:56:01 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp Fri May 04 15:57:29 2007 +0000
@@ -24,6 +24,22 @@
};
/**
+ * Check how tiles in an AITileList instance are sloped.
+ * @note resulting items are of the type int32 (0 = flat, > 1 = slope)
+ * @note the input items are of the type TileIndex
+ */
+class AITileListSlope : public AIAbstractList::Valuator {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AITileListSlope"; }
+
+private:
+ int32 Valuate(int32 tile) const;
+};
+
+/**
* Check if one of the neighbour tiles in AITileList has a piece of road.
* @note resulting items are of the type int32 (the amount of neighbour road tiles)
* @note the input items are of the type TileIndex
--- a/src/ai/api/ai_tilelist_valuator.hpp.sq Wed May 02 12:56:01 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp.sq Fri May 04 15:57:29 2007 +0000
@@ -19,6 +19,24 @@
}
namespace SQConvert {
+ /* Allow AITileListSlope to be used as Squirrel parameter */
+ template <> AITileListSlope *GetParam(ForceType<AITileListSlope *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListSlope *)instance; }
+ template <> AITileListSlope &GetParam(ForceType<AITileListSlope &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListSlope *)instance; }
+ template <> const AITileListSlope *GetParam(ForceType<const AITileListSlope *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListSlope *)instance; }
+ template <> const AITileListSlope &GetParam(ForceType<const AITileListSlope &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListSlope *)instance; }
+}; // namespace SQConvert
+
+void SQAITileListSlopeRegister(Squirrel *engine) {
+ DefSQClass <AITileListSlope> SQAITileListSlope("AITileListSlope");
+ SQAITileListSlope.PreRegister(engine);
+ SQAITileListSlope.AddConstructor<void (AITileListSlope::*)()>(engine, 1, "x");
+
+ SQAITileListSlope.DefSQStaticMethod(engine, &AITileListSlope::GetClassName, "GetClassName", 1, "x");
+
+ SQAITileListSlope.PostRegister(engine);
+}
+
+namespace SQConvert {
/* Allow AITileListNeighbourRoad to be used as Squirrel parameter */
template <> AITileListNeighbourRoad *GetParam(ForceType<AITileListNeighbourRoad *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITileListNeighbourRoad *)instance; }
template <> AITileListNeighbourRoad &GetParam(ForceType<AITileListNeighbourRoad &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileListNeighbourRoad *)instance; }