1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
8 /** @file script_map.hpp Everything to query and manipulate map metadata. */
9 
10 #ifndef SCRIPT_MAP_HPP
11 #define SCRIPT_MAP_HPP
12 
13 #include "script_object.hpp"
14 #include "../../tile_type.h"
15 
16 /**
17  * Class that handles all map related functions.
18  * @api ai game
19  */
20 class ScriptMap : public ScriptObject {
21 public:
22 	static const int TILE_INVALID = (int)INVALID_TILE; ///< Invalid TileIndex.
23 
24 	/**
25 	 * Checks whether the given tile is valid.
26 	 * @param tile The tile to check.
27 	 * @return True is the tile it within the boundaries of the map.
28 	 */
29 	static bool IsValidTile(TileIndex tile);
30 
31 	/**
32 	 * Gets the number of tiles in the map.
33 	 * @return The size of the map in tiles.
34 	 * @post Return value is always positive.
35 	 */
36 	static TileIndex GetMapSize();
37 
38 	/**
39 	 * Gets the amount of tiles along the SW and NE border.
40 	 * @return The length along the SW and NE borders.
41 	 * @post Return value is always positive.
42 	 */
43 	static uint32 GetMapSizeX();
44 
45 	/**
46 	 * Gets the amount of tiles along the SE and NW border.
47 	 * @return The length along the SE and NW borders.
48 	 * @post Return value is always positive.
49 	 */
50 	static uint32 GetMapSizeY();
51 
52 	/**
53 	 * Gets the place along the SW/NE border (X-value).
54 	 * @param tile The tile to get the X-value of.
55 	 * @pre IsValidTile(tile).
56 	 * @return The X-value.
57 	 * @post Return value is always lower than GetMapSizeX().
58 	 */
59 	static int32 GetTileX(TileIndex tile);
60 
61 	/**
62 	 * Gets the place along the SE/NW border (Y-value).
63 	 * @param tile The tile to get the Y-value of.
64 	 * @pre IsValidTile(tile).
65 	 * @return The Y-value.
66 	 * @post Return value is always lower than GetMapSizeY().
67 	 */
68 	static int32 GetTileY(TileIndex tile);
69 
70 	/**
71 	 * Gets the TileIndex given a x,y-coordinate.
72 	 * @param x The X coordinate.
73 	 * @param y The Y coordinate.
74 	 * @pre x < GetMapSizeX().
75 	 * @pre y < GetMapSizeY().
76 	 * @return The TileIndex for the given (x,y) coordinate.
77 	 */
78 	static TileIndex GetTileIndex(uint32 x, uint32 y);
79 
80 	/**
81 	 * Calculates the Manhattan distance; the difference of
82 	 *  the X and Y added together.
83 	 * @param tile_from The start tile.
84 	 * @param tile_to The destination tile.
85 	 * @pre IsValidTile(tile_from).
86 	 * @pre IsValidTile(tile_to).
87 	 * @return The Manhattan distance between the tiles.
88 	 */
89 	static int32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to);
90 
91 	/**
92 	 * Calculates the distance between two tiles via 1D calculation.
93 	 *  This means the distance between X or the distance between Y, depending
94 	 *  on which one is bigger.
95 	 * @param tile_from The start tile.
96 	 * @param tile_to The destination tile.
97 	 * @pre IsValidTile(tile_from).
98 	 * @pre IsValidTile(tile_to).
99 	 * @return The maximum distance between the tiles.
100 	 */
101 	static int32 DistanceMax(TileIndex tile_from, TileIndex tile_to);
102 
103 	/**
104 	 * The squared distance between the two tiles.
105 	 *  This is the distance is the length of the shortest straight line
106 	 *  between both points.
107 	 * @param tile_from The start tile.
108 	 * @param tile_to The destination tile.
109 	 * @pre IsValidTile(tile_from).
110 	 * @pre IsValidTile(tile_to).
111 	 * @return The squared distance between the tiles.
112 	 */
113 	static int32 DistanceSquare(TileIndex tile_from, TileIndex tile_to);
114 
115 	/**
116 	 * Calculates the shortest distance to the edge.
117 	 * @param tile From where the distance has to be calculated.
118 	 * @pre IsValidTile(tile).
119 	 * @return The distances to the closest edge.
120 	 */
121 	static int32 DistanceFromEdge(TileIndex tile);
122 };
123 
124 #endif /* SCRIPT_MAP_HPP */
125