(svn r12264) [NoAI] -Add: added AITileList_vCargoProduction (yorick) noai
authortruebrain
Tue, 26 Feb 2008 10:47:22 +0000
branchnoai
changeset 9771 769496a7b02e
parent 9770 ad3c5f807d7c
child 9772 c1035f0ac732
(svn r12264) [NoAI] -Add: added AITileList_vCargoProduction (yorick)
[NoAI] -Fix: fixed comments around CargoProduction, so now it reflects what is really does
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/ai_squirrel.cpp
src/ai/api/ai_tile.hpp
src/ai/api/ai_tilelist_valuator.cpp
src/ai/api/ai_tilelist_valuator.hpp
src/ai/api/ai_tilelist_valuator.hpp.sq
--- a/bin/ai/regression/regression.nut	Mon Feb 25 18:18:35 2008 +0000
+++ b/bin/ai/regression/regression.nut	Tue Feb 26 10:47:22 2008 +0000
@@ -758,7 +758,7 @@
 	print("");
 	print("--TileList_IndustryProducing--");
 	print("  Count():             " + list.Count());
-	list.Valuate(AITileList_vBuildable());
+	list.Valuate(AITileList_vCargoProduction(7, 1, 1, 3));
 	print("  Location ListDump:");
 	for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
 		print("    " + i + " => " + list.GetValue(i));
--- a/bin/ai/regression/regression.txt	Mon Feb 25 18:18:35 2008 +0000
+++ b/bin/ai/regression/regression.txt	Tue Feb 26 10:47:22 2008 +0000
@@ -5302,95 +5302,95 @@
 --TileList_IndustryProducing--
   Count():             90
   Location ListDump:
+    46149 => 14
+    46146 => 14
+    45894 => 14
+    45889 => 14
+    45638 => 14
+    45633 => 14
+    45382 => 14
+    45377 => 14
+    45126 => 12
+    45121 => 12
+    44869 => 12
+    44868 => 12
+    44867 => 12
+    44866 => 12
+    46150 => 11
+    46145 => 11
+    46405 => 10
+    46404 => 10
+    46403 => 10
+    46402 => 10
+    45895 => 9
+    45888 => 9
+    45639 => 9
+    45632 => 9
+    45383 => 9
+    45376 => 9
+    44870 => 9
+    44865 => 9
+    46406 => 8
+    46401 => 8
+    45127 => 8
+    45120 => 8
+    44613 => 8
+    44612 => 8
+    44611 => 8
+    44610 => 8
+    46151 => 7
+    46144 => 7
+    46661 => 6
+    46660 => 6
+    46659 => 6
+    46658 => 6
+    44871 => 6
+    44864 => 6
+    44614 => 6
+    44609 => 6
+    46662 => 5
+    46657 => 5
+    46407 => 5
+    46400 => 5
+    45896 => 4
+    45887 => 4
+    45640 => 4
+    45631 => 4
+    45384 => 4
+    45375 => 4
+    45128 => 4
+    45119 => 4
+    44615 => 4
+    44608 => 4
+    44357 => 4
+    44356 => 4
+    44355 => 4
+    44354 => 4
+    46663 => 3
+    46656 => 3
+    46152 => 3
+    46143 => 3
+    44872 => 3
+    44863 => 3
+    44358 => 3
+    44353 => 3
+    46918 => 2
+    46917 => 2
+    46916 => 2
+    46915 => 2
+    46914 => 2
+    46913 => 2
+    46408 => 2
+    46399 => 2
+    44616 => 2
+    44607 => 2
+    44359 => 2
+    44352 => 2
     46919 => 1
-    46918 => 1
-    46917 => 1
-    46916 => 1
-    46915 => 1
-    46914 => 1
-    46913 => 1
     46912 => 1
     46664 => 1
-    46663 => 1
-    46662 => 1
-    46661 => 1
-    46660 => 1
-    46659 => 1
-    46658 => 1
-    46657 => 1
-    46656 => 1
     46655 => 1
-    46408 => 1
-    46407 => 1
-    46406 => 1
-    46405 => 1
-    46404 => 1
-    46403 => 1
-    46402 => 1
-    46401 => 1
-    46400 => 1
-    46399 => 1
-    46152 => 1
-    46151 => 1
-    46150 => 1
-    46149 => 1
-    46146 => 1
-    46145 => 1
-    46144 => 1
-    46143 => 1
-    45896 => 1
-    45895 => 1
-    45894 => 1
-    45889 => 1
-    45888 => 1
-    45887 => 1
-    45640 => 1
-    45639 => 1
-    45638 => 1
-    45633 => 1
-    45632 => 1
-    45631 => 1
-    45384 => 1
-    45383 => 1
-    45382 => 1
-    45377 => 1
-    45376 => 1
-    45375 => 1
-    45128 => 1
-    45127 => 1
-    45126 => 1
-    45121 => 1
-    45120 => 1
-    45119 => 1
-    44872 => 1
-    44871 => 1
-    44870 => 1
-    44869 => 1
-    44868 => 1
-    44867 => 1
-    44866 => 1
-    44865 => 1
-    44864 => 1
-    44863 => 1
-    44616 => 1
-    44615 => 1
-    44614 => 1
-    44613 => 1
-    44612 => 1
-    44611 => 1
-    44610 => 1
-    44609 => 1
-    44608 => 1
-    44607 => 1
     44360 => 1
-    44359 => 1
-    44358 => 1
-    44357 => 1
-    44356 => 1
-    44355 => 1
-    44354 => 1
-    44353 => 1
-    44352 => 1
     44351 => 1
 
 --Town--
--- a/src/ai/ai_squirrel.cpp	Mon Feb 25 18:18:35 2008 +0000
+++ b/src/ai/ai_squirrel.cpp	Tue Feb 26 10:47:22 2008 +0000
@@ -266,6 +266,7 @@
 	SQAITileList_vBuildable_Register(this->engine);
 	SQAITileList_vBuildableRectangle_Register(this->engine);
 	SQAITileList_vCargoAcceptance_Register(this->engine);
+	SQAITileList_vCargoProduction_Register(this->engine);
 	SQAITileList_vDistanceManhattanToTile_Register(this->engine);
 	SQAITileList_vDistanceSquareToTile_Register(this->engine);
 	SQAITileList_vHeight_Register(this->engine);
--- a/src/ai/api/ai_tile.hpp	Mon Feb 25 18:18:35 2008 +0000
+++ b/src/ai/api/ai_tile.hpp	Tue Feb 26 10:47:22 2008 +0000
@@ -84,8 +84,8 @@
 
 	/**
 	 * Check how much cargo this tile accepts.
-	 *  It creates a radius around the tile and adds up all acceptance of this
-	 *   cargo and returns that value.
+	 *  It creates a radius around the tile, and adds up all acceptance of this
+	 *   cargo.
 	 * @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.
@@ -97,16 +97,17 @@
 	static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);
 
 	/**
-	 * Check how much cargo this tile produces.
-	 *  It creates a radius around the tile and adds up all production of this
-	 *   cargo and returns that value.
+	 * Checks how many tiles in the radius produces this cargo.
+	 *  It creates a radius around the tile, and adds up all tiles that produce
+	 *  this cargo.
 	 * @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 production of.
 	 * @param width the width of the station.
 	 * @param height the height of the station.
 	 * @param radius the radius of the station.
-	 * @return the production for the given cargo type.
+	 * @return the tiles that produce this cargo within radius of the tile.
+	 * @note town(houses) are not included in the value.
 	 */
 	static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);
 
--- a/src/ai/api/ai_tilelist_valuator.cpp	Mon Feb 25 18:18:35 2008 +0000
+++ b/src/ai/api/ai_tilelist_valuator.cpp	Tue Feb 26 10:47:22 2008 +0000
@@ -55,6 +55,11 @@
 	return AITile::GetCargoAcceptance(tile, this->cargo_type, this->width, this->height, this->radius);
 }
 
+int32 AITileList_vCargoProduction::Valuate(int32 tile) const
+{
+	return AITile::GetCargoProduction(tile, this->cargo_type, this->width, this->height, this->radius);
+}
+
 int32 AITileList_vDistanceManhattanToTile::Valuate(int32 tile) const
 {
 	return AIMap::DistanceManhattan(this->tile, tile);
--- a/src/ai/api/ai_tilelist_valuator.hpp	Mon Feb 25 18:18:35 2008 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
@@ -128,7 +128,7 @@
 };
 
 /**
- * Get the amount of estimated accepted cargo for all tiles in AITileList_v.
+ * Get the amount of estimated accepted cargo for all tiles in AITileList.
  * If this value is >= 8, it means it will accept this cargo. For passengers
  *  and mail it is also a good indicator how much cargo would be brought to
  *  the station.
@@ -156,6 +156,33 @@
 };
 
 /**
+ * Get the amount of tiles producing cargo for all tiles in AITileList.
+ *  This counts the tiles that produce this cargo. It doesn't give any
+ *  indication about the amount it will be producing.
+ * @note town(houses) are not included in the value.
+ * @note resulting items are of the type int32 (indicating tiles of production).
+ * @note the input items are of the type TileIndex.
+ */
+class AITileList_vCargoProduction : public AIAbstractList::Valuator {
+public:
+	/**
+	 * The name of the class, needed by several sub-processes.
+	 */
+	static const char *GetClassName() { return "AITileList_vCargoProduction"; }
+
+	/**
+	 * Custom constructor, we want a cargo-type as parameter.
+	 */
+	AITileList_vCargoProduction(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;
+};
+
+/**
  * Get the manhattan distance to a tile for entries in an AITileList instance.
  * @note resulting items are of the type distance
  * @note the input items are of the type TileIndex
--- a/src/ai/api/ai_tilelist_valuator.hpp.sq	Mon Feb 25 18:18:35 2008 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp.sq	Tue Feb 26 10:47:22 2008 +0000
@@ -153,6 +153,25 @@
 }
 
 namespace SQConvert {
+	/* Allow AITileList_vCargoProduction to be used as Squirrel parameter */
+	template <> AITileList_vCargoProduction *GetParam(ForceType<AITileList_vCargoProduction *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AITileList_vCargoProduction *)instance; }
+	template <> AITileList_vCargoProduction &GetParam(ForceType<AITileList_vCargoProduction &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileList_vCargoProduction *)instance; }
+	template <> const AITileList_vCargoProduction *GetParam(ForceType<const AITileList_vCargoProduction *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AITileList_vCargoProduction *)instance; }
+	template <> const AITileList_vCargoProduction &GetParam(ForceType<const AITileList_vCargoProduction &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileList_vCargoProduction *)instance; }
+	template <> int Return<AITileList_vCargoProduction *>(HSQUIRRELVM vm, AITileList_vCargoProduction *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AITileList_vCargoProduction", res, NULL, DefSQDestructorCallback<AITileList_vCargoProduction>); return 1; }
+}; // namespace SQConvert
+
+void SQAITileList_vCargoProduction_Register(Squirrel *engine) {
+	DefSQClass <AITileList_vCargoProduction> SQAITileList_vCargoProduction("AITileList_vCargoProduction");
+	SQAITileList_vCargoProduction.PreRegister(engine);
+	SQAITileList_vCargoProduction.AddConstructor<void (AITileList_vCargoProduction::*)(CargoID cargo_type, uint width, uint height, uint radius), 5>(engine, "xiiii");
+
+	SQAITileList_vCargoProduction.DefSQStaticMethod(engine, &AITileList_vCargoProduction::GetClassName, "GetClassName", 1, "x");
+
+	SQAITileList_vCargoProduction.PostRegister(engine);
+}
+
+namespace SQConvert {
 	/* Allow AITileList_vDistanceManhattanToTile to be used as Squirrel parameter */
 	template <> AITileList_vDistanceManhattanToTile *GetParam(ForceType<AITileList_vDistanceManhattanToTile *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AITileList_vDistanceManhattanToTile *)instance; }
 	template <> AITileList_vDistanceManhattanToTile &GetParam(ForceType<AITileList_vDistanceManhattanToTile &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITileList_vDistanceManhattanToTile *)instance; }