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.cpp Implementation of ScriptMap. */
9 
10 #include "../../stdafx.h"
11 #include "script_map.hpp"
12 #include "../../tile_map.h"
13 
14 #include "../../safeguards.h"
15 
IsValidTile(TileIndex t)16 /* static */ bool ScriptMap::IsValidTile(TileIndex t)
17 {
18 	return ::IsValidTile(t);
19 }
20 
GetMapSize()21 /* static */ TileIndex ScriptMap::GetMapSize()
22 {
23 	return ::MapSize();
24 }
25 
GetMapSizeX()26 /* static */ uint32 ScriptMap::GetMapSizeX()
27 {
28 	return ::MapSizeX();
29 }
30 
GetMapSizeY()31 /* static */ uint32 ScriptMap::GetMapSizeY()
32 {
33 	return ::MapSizeY();
34 }
35 
GetTileX(TileIndex t)36 /* static */ int32 ScriptMap::GetTileX(TileIndex t)
37 {
38 	if (!::IsValidTile(t)) return -1;
39 	return ::TileX(t);
40 }
41 
GetTileY(TileIndex t)42 /* static */ int32 ScriptMap::GetTileY(TileIndex t)
43 {
44 	if (!::IsValidTile(t)) return -1;
45 	return ::TileY(t);
46 }
47 
GetTileIndex(uint32 x,uint32 y)48 /* static */ TileIndex ScriptMap::GetTileIndex(uint32 x, uint32 y)
49 {
50 	return ::TileXY(x, y);
51 }
52 
DistanceManhattan(TileIndex t1,TileIndex t2)53 /* static */ int32 ScriptMap::DistanceManhattan(TileIndex t1, TileIndex t2)
54 {
55 	if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
56 	return ::DistanceManhattan(t1, t2);
57 }
58 
DistanceMax(TileIndex t1,TileIndex t2)59 /* static */ int32 ScriptMap::DistanceMax(TileIndex t1, TileIndex t2)
60 {
61 	if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
62 	return ::DistanceMax(t1, t2);
63 }
64 
DistanceSquare(TileIndex t1,TileIndex t2)65 /* static */ int32 ScriptMap::DistanceSquare(TileIndex t1, TileIndex t2)
66 {
67 	if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
68 	return ::DistanceSquare(t1, t2);
69 }
70 
DistanceFromEdge(TileIndex t)71 /* static */ int32 ScriptMap::DistanceFromEdge(TileIndex t)
72 {
73 	if (!::IsValidTile(t)) return -1;
74 	return ::DistanceFromEdge(t);
75 }
76