(svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
--- a/src/ai/api/ai_tile.cpp Fri Feb 15 23:31:51 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Fri Feb 15 23:36:22 2008 +0000
@@ -60,6 +60,16 @@
return accepts[cargo_type];
}
+int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return 0;
+
+ AcceptedCargo produced;
+ GetProductionAroundTiles(produced, tile, width, height, _patches.modified_catchment ? rad : 4);
+ return produced[cargo_type];
+}
+
bool AITile::RaiseTile(TileIndex tile, int32 slope)
{
/* Outside of the map */
--- a/src/ai/api/ai_tile.hpp Fri Feb 15 23:31:51 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Fri Feb 15 23:36:22 2008 +0000
@@ -97,6 +97,20 @@
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.
+ * @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.
+ */
+ static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint rad);
+
+ /**
* Raise the given corners of the tile. The corners can be combined,
* for example: SLOPE_N | SLOPE_W (= SLOPE_NW)
* @pre tile is always positive and smaller than AIMap::GetMapSize().
--- a/src/ai/api/ai_tile.hpp.sq Fri Feb 15 23:31:51 2008 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Fri Feb 15 23:36:22 2008 +0000
@@ -46,6 +46,7 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetSlope, "GetSlope", 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");
SQAITile.DefSQMethod(engine, &AITile::RaiseTile, "RaiseTile", 3, "xii");
SQAITile.DefSQMethod(engine, &AITile::LowerTile, "LowerTile", 3, "xii");