summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_map.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
committertruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
commita3dd7506d377b1434f913bd65c019eed52b64b6e (patch)
treeced1a262eb143ad6e64ec02f4a4c89835c0c32fd /src/ai/api/ai_map.hpp
parent9294f9616866b9778c22076c19b5a32b4f85f788 (diff)
downloadopenttd-a3dd7506d377b1434f913bd65c019eed52b64b6e.tar.xz
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
NoAI is an API (a framework) to build your own AIs in. See: http://wiki.openttd.org/wiki/index.php/AI:Main_Page With many thanks to: - glx and Rubidium for their syncing, feedback and hard work - Yexo for his feedback, patches, and AIs which tested the system very deep - Morloth for his feedback and patches - TJIP for hosting a challenge which kept NoAI on track - All AI authors for testing our AI API, and all other people who helped in one way or another -Remove: all old AIs and their cheats/hacks
Diffstat (limited to 'src/ai/api/ai_map.hpp')
-rw-r--r--src/ai/api/ai_map.hpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/ai/api/ai_map.hpp b/src/ai/api/ai_map.hpp
new file mode 100644
index 000000000..f14c360eb
--- /dev/null
+++ b/src/ai/api/ai_map.hpp
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/** @file ai_map.hpp Everything to query and manipulate map metadata. */
+
+#ifndef AI_MAP_HPP
+#define AI_MAP_HPP
+
+#include "ai_object.hpp"
+
+/**
+ * Class that handles all map related functions.
+ */
+class AIMap : public AIObject {
+public:
+ static const char *GetClassName() { return "AIMap"; }
+
+ /**
+ * Checks whether the given tile is valid.
+ * @param tile The tile to check.
+ * @return True is the tile it within the boundaries of the map.
+ */
+ static bool IsValidTile(TileIndex tile);
+
+ /**
+ * Gets the number of tiles in the map.
+ * @return The size of the map in tiles.
+ * @post Return value is always positive.
+ */
+ static TileIndex GetMapSize();
+
+ /**
+ * Gets the amount of tiles along the SW and NE border.
+ * @return The length along the SW and NE borders.
+ * @post Return value is always positive.
+ */
+ static uint32 GetMapSizeX();
+
+ /**
+ * Gets the amount of tiles along the SE and NW border.
+ * @return The length along the SE and NW borders.
+ * @post Return value is always positive.
+ */
+ static uint32 GetMapSizeY();
+
+ /**
+ * Gets the place along the SW/NE border (X-value).
+ * @param tile The tile to get the X-value of.
+ * @pre IsValidTile(tile).
+ * @return The X-value.
+ * @post Return value is always lower than GetMapSizeX().
+ */
+ static uint32 GetTileX(TileIndex tile);
+
+ /**
+ * Gets the place along the SE/NW border (Y-value).
+ * @param tile The tile to get the Y-value of.
+ * @pre IsValidTile(tile).
+ * @return The Y-value.
+ * @post Return value is always lower than GetMapSizeY().
+ */
+ static uint32 GetTileY(TileIndex tile);
+
+ /**
+ * Gets the TileIndex given a x,y-coordinate.
+ * @param x The X coordinate.
+ * @param y The Y coordinate.
+ * @pre x < GetMapSizeX().
+ * @pre y < GetMapSizeY().
+ * @return The TileIndex for the given (x,y) coordinate.
+ */
+ static TileIndex GetTileIndex(uint32 x, uint32 y);
+
+ /**
+ * Calculates the Manhattan distance; the difference of
+ * the X and Y added together.
+ * @param tile_from The start tile.
+ * @param tile_to The destination tile.
+ * @pre IsValidTile(tile_from).
+ * @pre IsValidTile(tile_to).
+ * @return The Manhattan distance between the tiles.
+ */
+ static uint32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to);
+
+ /**
+ * Calculates the distance between two tiles via 1D calculation.
+ * This means the distance between X or the distance between Y, depending
+ * on which one is bigger.
+ * @param tile_from The start tile.
+ * @param tile_to The destination tile.
+ * @pre IsValidTile(tile_from).
+ * @pre IsValidTile(tile_to).
+ * @return The maximum distance between the tiles.
+ */
+ static uint32 DistanceMax(TileIndex tile_from, TileIndex tile_to);
+
+ /**
+ * The squared distance between the two tiles.
+ * This is the distance is the length of the shortest straight line
+ * between both points.
+ * @param tile_from The start tile.
+ * @param tile_to The destination tile.
+ * @pre IsValidTile(tile_from).
+ * @pre IsValidTile(tile_to).
+ * @return The squared distance between the tiles.
+ */
+ static uint32 DistanceSquare(TileIndex tile_from, TileIndex tile_to);
+
+ /**
+ * Calculates the shortest distance to the edge.
+ * @param tile From where the distance has to be calculated.
+ * @pre IsValidTile(tile).
+ * @return The distances to the closest edge.
+ */
+ static uint32 DistanceFromEdge(TileIndex tile);
+};
+
+#endif /* AI_MAP_HPP */