2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/** @file script_map.cpp Implementation of ScriptMap. */
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-01-22 11:33:16 +01:00
|
|
|
#include "../../stdafx.h"
|
2011-11-30 00:07:38 +01:00
|
|
|
#include "script_map.hpp"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "../../tile_map.h"
|
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptMap::IsValidTile(TileIndex t)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
return ::IsValidTile(t);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::GetMapSize()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2023-01-21 10:43:03 +01:00
|
|
|
return ::Map::Size();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::GetMapSizeX()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2023-01-21 10:43:03 +01:00
|
|
|
return ::Map::SizeX();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::GetMapSizeY()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2023-01-21 10:43:03 +01:00
|
|
|
return ::Map::SizeY();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::GetTileX(TileIndex t)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::TileX(t);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::GetTileY(TileIndex t)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::TileY(t);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ TileIndex ScriptMap::GetTileIndex(SQInteger x, SQInteger y)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
return ::TileXY(x, y);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::DistanceManhattan(TileIndex t1, TileIndex t2)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::DistanceManhattan(t1, t2);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::DistanceMax(TileIndex t1, TileIndex t2)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::DistanceMax(t1, t2);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::DistanceSquare(TileIndex t1, TileIndex t2)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::DistanceSquare(t1, t2);
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:51:14 +01:00
|
|
|
/* static */ SQInteger ScriptMap::DistanceFromEdge(TileIndex t)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-01-14 00:50:12 +01:00
|
|
|
if (!::IsValidTile(t)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::DistanceFromEdge(t);
|
|
|
|
}
|