(svn r10565) [NoAI] -Add: allow giving width, height and radius to check for cargo acceptance noai
authortruelight
Sat, 14 Jul 2007 22:06:38 +0000
branchnoai
changeset 9658 e7675771bca4
parent 9657 f2c6e332d8bc
child 9659 ff5908205170
(svn r10565) [NoAI] -Add: allow giving width, height and radius to check for cargo acceptance
bin/ai/regression/regression.nut
src/ai/api/ai_tile.cpp
src/ai/api/ai_tile.hpp
src/ai/api/ai_tile.hpp.sq
src/ai/api/ai_tilelist_valuator.cpp
src/ai/api/ai_tilelist_valuator.hpp
src/ai/api/ai_tilelist_valuator.hpp.sq
src/squirrel_helper.hpp
--- a/bin/ai/regression/regression.nut	Sat Jul 14 21:15:49 2007 +0000
+++ b/bin/ai/regression/regression.nut	Sat Jul 14 22:06:38 2007 +0000
@@ -516,7 +516,7 @@
 		print("    " + i + " => " + list.GetValue(i));
 	}
 
-	list.Valuate(AITileListCargoAcceptance(0));
+	list.Valuate(AITileListCargoAcceptance(0, 1, 1, 3));
 	list.KeepAboveValue(10);
 	print("  CargoAcceptance():   done");
 	print("  KeepAboveValue(10):  done");
--- a/src/ai/api/ai_tile.cpp	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tile.cpp	Sat Jul 14 22:06:38 2007 +0000
@@ -30,15 +30,12 @@
 	return GetTileSlope(tile, NULL);
 }
 
-int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type)
+int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad)
 {
 	/* Outside of the map */
 	if (tile >= ::MapSize()) return false;
 
-	/* TODO -- Make it an enum via constructor, for now it assumes RoadVehicle Station */
-	uint rad = 3;
-
 	AcceptedCargo accepts;
-	GetAcceptanceAroundTiles(accepts, tile, 1, 1, _patches.modified_catchment ? rad : 4);
+	GetAcceptanceAroundTiles(accepts, tile, width, height, _patches.modified_catchment ? rad : 4);
 	return accepts[cargo_type];
 }
--- a/src/ai/api/ai_tile.hpp	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tile.hpp	Sat Jul 14 22:06:38 2007 +0000
@@ -41,9 +41,12 @@
 	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
 	 * @param tile the tile to check on.
 	 * @param cargo_type the cargo to check the acceptance of.
+	 * @param width the width of the station.
+	 * @param height the height of the station.
+	 * @param radius the radius of the station.
 	 * @return value below 8 means no acceptance; the more the better.
 	 */
-	static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type);
+	static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);
 };
 
 #endif /* AI_TILE_HPP */
--- a/src/ai/api/ai_tile.hpp.sq	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tile.hpp.sq	Sat Jul 14 22:06:38 2007 +0000
@@ -16,7 +16,7 @@
 	SQAITile.DefSQStaticMethod(engine, &AITile::GetClassName,       "GetClassName",       1, "x");
 	SQAITile.DefSQStaticMethod(engine, &AITile::IsBuildable,        "IsBuildable",        2, "xi");
 	SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope,           "GetSlope",           2, "xi");
-	SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 3, "xii");
+	SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
 
 	SQAITile.PostRegister(engine);
 }
--- a/src/ai/api/ai_tilelist_valuator.cpp	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.cpp	Sat Jul 14 22:06:38 2007 +0000
@@ -43,7 +43,7 @@
 
 int32 AITileListCargoAcceptance::Valuate(int32 tile) const
 {
-	return AITile::GetCargoAcceptance(tile, this->cargo_type);
+	return AITile::GetCargoAcceptance(tile, this->cargo_type, this->width, this->height, this->radius);
 }
 
 int32 AITileListDistanceManhattanToTile::Valuate(int32 tile) const
--- a/src/ai/api/ai_tilelist_valuator.hpp	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp	Sat Jul 14 22:06:38 2007 +0000
@@ -110,10 +110,11 @@
 	/**
 	 * Custom constructor, we want a cargo-type as parameter.
 	 */
-	AITileListCargoAcceptance(CargoID cargo_type) { this->cargo_type = cargo_type; }
+	AITileListCargoAcceptance(CargoID cargo_type, uint width, uint height, uint radius) { this->cargo_type = cargo_type; this->width = width; this->height = height; this->radius = radius; }
 
 private:
 	CargoID cargo_type;
+	uint width, height, radius;
 
 	int32 Valuate(int32 tile) const;
 };
--- a/src/ai/api/ai_tilelist_valuator.hpp.sq	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp.sq	Sat Jul 14 22:06:38 2007 +0000
@@ -101,7 +101,7 @@
 void SQAITileListCargoAcceptanceRegister(Squirrel *engine) {
 	DefSQClass <AITileListCargoAcceptance> SQAITileListCargoAcceptance("AITileListCargoAcceptance");
 	SQAITileListCargoAcceptance.PreRegister(engine);
-	SQAITileListCargoAcceptance.AddConstructor<void (AITileListCargoAcceptance::*)(CargoID cargo_type), 2>(engine, "xi");
+	SQAITileListCargoAcceptance.AddConstructor<void (AITileListCargoAcceptance::*)(CargoID cargo_type, uint width, uint height, uint radius), 5>(engine, "xiiii");
 
 	SQAITileListCargoAcceptance.DefSQStaticMethod(engine, &AITileListCargoAcceptance::GetClassName, "GetClassName", 1, "x");
 
--- a/src/squirrel_helper.hpp	Sat Jul 14 21:15:49 2007 +0000
+++ b/src/squirrel_helper.hpp	Sat Jul 14 22:06:38 2007 +0000
@@ -33,12 +33,14 @@
 	template <typename Tretval, typename Targ1, typename Targ2> struct HasVoidReturnT<Tretval (*)(Targ1, Targ2)> : IsVoidT<Tretval> {};
 	template <typename Tretval, typename Targ1, typename Targ2, typename Targ3> struct HasVoidReturnT<Tretval (*)(Targ1, Targ2, Targ3)> : IsVoidT<Tretval> {};
 	template <typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4> struct HasVoidReturnT<Tretval (*)(Targ1, Targ2, Targ3, Targ4)> : IsVoidT<Tretval> {};
+	template <typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5> struct HasVoidReturnT<Tretval (*)(Targ1, Targ2, Targ3, Targ4, Targ5)> : IsVoidT<Tretval> {};
 	/* methods */
 	template <class Tcls, typename Tretval> struct HasVoidReturnT<Tretval (Tcls::*)()> : IsVoidT<Tretval> {};
 	template <class Tcls, typename Tretval, typename Targ1> struct HasVoidReturnT<Tretval (Tcls::*)(Targ1)> : IsVoidT<Tretval> {};
 	template <class Tcls, typename Tretval, typename Targ1, typename Targ2> struct HasVoidReturnT<Tretval (Tcls::*)(Targ1, Targ2)> : IsVoidT<Tretval> {};
 	template <class Tcls, typename Tretval, typename Targ1, typename Targ2, typename Targ3> struct HasVoidReturnT<Tretval (Tcls::*)(Targ1, Targ2, Targ3)> : IsVoidT<Tretval> {};
 	template <class Tcls, typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4> struct HasVoidReturnT<Tretval (Tcls::*)(Targ1, Targ2, Targ3, Targ4)> : IsVoidT<Tretval> {};
+	template <class Tcls, typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5> struct HasVoidReturnT<Tretval (Tcls::*)(Targ1, Targ2, Targ3, Targ4, Targ5)> : IsVoidT<Tretval> {};
 
 
 	/**
@@ -466,6 +468,111 @@
 		}
 	};
 
+	/**
+	 * The real C++ caller for function with return value and 5 params.
+	 */
+	template <typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5>
+	struct HelperT<Tretval (*)(Targ1, Targ2, Targ3, Targ4, Targ5), false> {
+		static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3, Targ4, Targ5), HSQUIRRELVM vm)
+		{
+			Tretval ret = (*func)(
+				GetParam(ForceType<Targ1>(), vm, 2),
+				GetParam(ForceType<Targ2>(), vm, 3),
+				GetParam(ForceType<Targ3>(), vm, 4),
+				GetParam(ForceType<Targ4>(), vm, 5),
+				GetParam(ForceType<Targ5>(), vm, 6)
+			);
+			sq_remove(vm, 2);
+			sq_remove(vm, 3);
+			sq_remove(vm, 4);
+			sq_remove(vm, 5);
+			sq_remove(vm, 6);
+			return Return(vm, ret);
+		}
+	};
+
+	/**
+	 * The real C++ caller for function with no return value and 5 params.
+	 */
+	template <typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5>
+	struct HelperT<Tretval (*)(Targ1, Targ2, Targ3, Targ4, Targ5), true> {
+		static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3, Targ4, Targ5), HSQUIRRELVM vm)
+		{
+			(*func)(
+				GetParam(ForceType<Targ1>(), vm, 2),
+				GetParam(ForceType<Targ2>(), vm, 3),
+				GetParam(ForceType<Targ3>(), vm, 4),
+				GetParam(ForceType<Targ4>(), vm, 5),
+				GetParam(ForceType<Targ5>(), vm, 6)
+			);
+			sq_remove(vm, 2);
+			sq_remove(vm, 3);
+			sq_remove(vm, 4);
+			sq_remove(vm, 5);
+			sq_remove(vm, 6);
+			return 0;
+		}
+	};
+
+	/**
+	 * The real C++ caller for method with return value and 5 params.
+	 */
+	template <class Tcls, typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5>
+	struct HelperT<Tretval (Tcls::*)(Targ1, Targ2, Targ3, Targ4, Targ5), false> {
+		static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3, Targ4, Targ5), HSQUIRRELVM vm)
+		{
+			Tretval ret = (instance->*func)(
+				GetParam(ForceType<Targ1>(), vm, 2),
+				GetParam(ForceType<Targ2>(), vm, 3),
+				GetParam(ForceType<Targ3>(), vm, 4),
+				GetParam(ForceType<Targ4>(), vm, 5),
+				GetParam(ForceType<Targ5>(), vm, 6)
+			);
+			sq_remove(vm, 2);
+			sq_remove(vm, 3);
+			sq_remove(vm, 4);
+			sq_remove(vm, 5);
+			sq_remove(vm, 6);
+			return Return(vm, ret);
+		}
+	};
+
+	/**
+	 * The real C++ caller for method with no return value and 5 params.
+	 */
+	template <class Tcls, typename Tretval, typename Targ1, typename Targ2, typename Targ3, typename Targ4, typename Targ5>
+	struct HelperT<Tretval (Tcls::*)(Targ1, Targ2, Targ3, Targ4, Targ5), true> {
+		static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3, Targ4, Targ5), HSQUIRRELVM vm)
+		{
+			(instance->*func)(
+				GetParam(ForceType<Targ1>(), vm, 2),
+				GetParam(ForceType<Targ2>(), vm, 3),
+				GetParam(ForceType<Targ3>(), vm, 4),
+				GetParam(ForceType<Targ4>(), vm, 5),
+				GetParam(ForceType<Targ5>(), vm, 6)
+			);
+			sq_remove(vm, 2);
+			sq_remove(vm, 3);
+			sq_remove(vm, 4);
+			sq_remove(vm, 5);
+			sq_remove(vm, 6);
+			return 0;
+		}
+
+		static Tcls *SQConstruct(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3, Targ4, Targ5), HSQUIRRELVM vm)
+		{
+			Tcls *inst = new Tcls(
+				GetParam(ForceType<Targ1>(), vm, 2),
+				GetParam(ForceType<Targ2>(), vm, 3),
+				GetParam(ForceType<Targ3>(), vm, 4),
+				GetParam(ForceType<Targ4>(), vm, 5),
+				GetParam(ForceType<Targ5>(), vm, 6)
+			);
+
+			return inst;
+		}
+	};
+
 
 	/**
 	 * A general template for all non-static method callbacks from Squirrel.