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_tile.cpp Implementation of ScriptTile. */
|
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_tile.hpp"
|
|
|
|
#include "script_map.hpp"
|
|
|
|
#include "script_town.hpp"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "../../station_func.h"
|
|
|
|
#include "../../water_map.h"
|
|
|
|
#include "../../clear_map.h"
|
2010-01-03 13:42:50 +01:00
|
|
|
#include "../../tree_map.h"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "../../town.h"
|
2009-04-26 18:26:41 +02:00
|
|
|
#include "../../landscape.h"
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsBuildable(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
|
|
|
switch (::GetTileType(tile)) {
|
|
|
|
default: return false;
|
|
|
|
case MP_CLEAR: return true;
|
|
|
|
case MP_TREES: return true;
|
|
|
|
case MP_WATER: return IsCoast(tile);
|
|
|
|
case MP_ROAD:
|
|
|
|
/* Tram bits aren't considered buildable */
|
2019-04-06 08:46:15 +02:00
|
|
|
if (::GetRoadTypeTram(tile) != INVALID_ROADTYPE) return false;
|
2009-01-12 18:11:45 +01:00
|
|
|
/* Depots and crossings aren't considered buildable */
|
|
|
|
if (::GetRoadTileType(tile) != ROAD_TILE_NORMAL) return false;
|
2019-04-06 08:46:15 +02:00
|
|
|
if (!HasExactlyOneBit(::GetRoadBits(tile, RTT_ROAD))) return false;
|
|
|
|
if (::IsRoadOwner(tile, RTT_ROAD, OWNER_TOWN)) return true;
|
|
|
|
if (::IsRoadOwner(tile, RTT_ROAD, ScriptObject::GetCompany())) return true;
|
2009-01-12 18:11:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsBuildableRectangle(TileIndex tile, uint width, uint height)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2013-10-06 13:16:00 +02:00
|
|
|
/* Check whether we can extract valid X and Y */
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2013-10-06 13:16:00 +02:00
|
|
|
uint tx = ScriptMap::GetTileX(tile);
|
|
|
|
uint ty = ScriptMap::GetTileY(tile);
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
for (uint x = tx; x < width + tx; x++) {
|
|
|
|
for (uint y = ty; y < height + ty; y++) {
|
2011-11-30 00:15:35 +01:00
|
|
|
if (!IsBuildable(ScriptMap::GetTileIndex(x, y))) return false;
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsWaterTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
|
|
|
return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsCoastTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2010-01-03 13:42:50 +01:00
|
|
|
return (::IsTileType(tile, MP_WATER) && ::IsCoast(tile)) ||
|
|
|
|
(::IsTileType(tile, MP_TREES) && ::GetTreeGround(tile) == TREE_GROUND_SHORE);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsStationTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
|
|
|
return ::IsTileType(tile, MP_STATION);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsSteepSlope(Slope slope)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-05-09 21:45:02 +02:00
|
|
|
if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
return ::IsSteepSlope((::Slope)slope);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsHalftileSlope(Slope slope)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-05-09 21:45:02 +02:00
|
|
|
if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
return ::IsHalftileSlope((::Slope)slope);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::HasTreeOnTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2009-01-12 18:11:45 +01:00
|
|
|
return ::IsTileType(tile, MP_TREES);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsFarmTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2009-01-12 18:11:45 +01:00
|
|
|
return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_FIELDS));
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsRockTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2010-01-04 19:33:43 +01:00
|
|
|
return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROCKS);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsRoughTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2010-01-04 19:33:43 +01:00
|
|
|
return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROUGH);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsSnowTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2010-01-04 19:33:43 +01:00
|
|
|
return (::IsTileType(tile, MP_CLEAR) && ::IsSnowTile(tile));
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsDesertTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-09-02 14:48:23 +02:00
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2009-01-12 18:11:45 +01:00
|
|
|
return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_DESERT));
|
|
|
|
}
|
|
|
|
|
2013-04-30 19:16:32 +02:00
|
|
|
/* static */ ScriptTile::TerrainType ScriptTile::GetTerrainType(TileIndex tile)
|
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return TERRAIN_NORMAL;
|
|
|
|
|
|
|
|
switch (::GetTerrainType(tile)) {
|
|
|
|
default:
|
|
|
|
case 0: return TERRAIN_NORMAL;
|
|
|
|
case 1: return TERRAIN_DESERT;
|
|
|
|
case 2: return TERRAIN_RAINFOREST;
|
|
|
|
case 4: return TERRAIN_SNOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ ScriptTile::Slope ScriptTile::GetSlope(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return SLOPE_INVALID;
|
|
|
|
|
2011-11-04 11:22:27 +01:00
|
|
|
return (Slope)::GetTileSlope(tile);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ ScriptTile::Slope ScriptTile::GetComplementSlope(Slope slope)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-05-09 21:45:02 +02:00
|
|
|
if ((slope & ~SLOPE_ELEVATED) != 0) return SLOPE_INVALID;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
return (Slope)::ComplementSlope((::Slope)slope);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetMinHeight(TileIndex tile)
|
2009-04-26 18:26:41 +02:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return -1;
|
|
|
|
|
2011-11-04 11:25:33 +01:00
|
|
|
return ::GetTileZ(tile);
|
2009-04-26 18:26:41 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetMaxHeight(TileIndex tile)
|
2009-04-26 18:26:41 +02:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return -1;
|
|
|
|
|
2011-11-04 11:25:33 +01:00
|
|
|
return ::GetTileMaxZ(tile);
|
2009-04-26 18:26:41 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetCornerHeight(TileIndex tile, Corner corner)
|
2009-04-26 18:26:41 +02:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1;
|
|
|
|
|
2011-11-04 12:30:37 +01:00
|
|
|
int z;
|
2011-11-04 11:25:33 +01:00
|
|
|
::Slope slope = ::GetTileSlope(tile, &z);
|
|
|
|
return (z + ::GetSlopeZInCorner(slope, (::Corner)corner));
|
2009-04-26 18:26:41 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ ScriptCompany::CompanyID ScriptTile::GetOwner(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
if (!::IsValidTile(tile)) return ScriptCompany::COMPANY_INVALID;
|
|
|
|
if (::IsTileType(tile, MP_HOUSE)) return ScriptCompany::COMPANY_INVALID;
|
|
|
|
if (::IsTileType(tile, MP_INDUSTRY)) return ScriptCompany::COMPANY_INVALID;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)(byte)::GetTileOwner(tile));
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::HasTransportType(TileIndex tile, TransportType transport_type)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return false;
|
|
|
|
|
2019-04-06 08:46:15 +02:00
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
|
|
|
return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, 0)) != TRACKDIR_BIT_NONE ||
|
|
|
|
::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, 1)) != TRACKDIR_BIT_NONE;
|
|
|
|
} else {
|
|
|
|
return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, 0)) != TRACKDIR_BIT_NONE;
|
|
|
|
}
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2009-06-27 23:06:58 +02:00
|
|
|
CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED);
|
2009-06-27 20:26:50 +02:00
|
|
|
return acceptance[cargo_type];
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2009-06-27 23:06:58 +02:00
|
|
|
CargoArray produced = ::GetProductionAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED);
|
2009-01-12 18:11:45 +01:00
|
|
|
return produced[cargo_type];
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptMap::DistanceManhattan(tile_from, tile_to);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ int32 ScriptTile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptMap::DistanceSquare(tile_from, tile_to);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::RaiseTile(TileIndex tile, int32 slope)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-12-19 22:05:36 +01:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-21 03:31:55 +01:00
|
|
|
EnforcePrecondition(false, tile < ::MapSize());
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::LowerTile(TileIndex tile, int32 slope)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-12-19 22:05:36 +01:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-21 03:31:55 +01:00
|
|
|
EnforcePrecondition(false, tile < ::MapSize());
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::LevelTiles(TileIndex start_tile, TileIndex end_tile)
|
2009-01-16 16:01:54 +01:00
|
|
|
{
|
2011-12-19 22:05:36 +01:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-21 03:31:55 +01:00
|
|
|
EnforcePrecondition(false, start_tile < ::MapSize());
|
|
|
|
EnforcePrecondition(false, end_tile < ::MapSize());
|
2009-01-16 16:01:54 +01:00
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(end_tile, start_tile, LM_LEVEL << 1, CMD_LEVEL_LAND);
|
2009-01-16 16:01:54 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::DemolishTile(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
EnforcePrecondition(false, ::IsValidTile(tile));
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::PlantTree(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-12-19 22:05:36 +01:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-12 18:11:45 +01:00
|
|
|
EnforcePrecondition(false, ::IsValidTile(tile));
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(tile, TREE_INVALID, tile, CMD_PLANT_TREE);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-12-19 22:05:36 +01:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-12 18:11:45 +01:00
|
|
|
EnforcePrecondition(false, ::IsValidTile(tile));
|
|
|
|
EnforcePrecondition(false, width >= 1 && width <= 20);
|
|
|
|
EnforcePrecondition(false, height >= 1 && height <= 20);
|
|
|
|
TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptObject::DoCommand(tile, TREE_INVALID, end_tile, CMD_PLANT_TREE);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2011-11-30 00:15:35 +01:00
|
|
|
return ScriptTown::IsWithinTownInfluence(town_id, tile);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ TownID ScriptTile::GetTownAuthority(TileIndex tile)
|
2011-08-19 23:19:10 +02:00
|
|
|
{
|
2011-12-10 22:07:04 +01:00
|
|
|
if (!::IsValidTile(tile)) return INVALID_TOWN;
|
2011-08-19 23:19:10 +02:00
|
|
|
|
2011-12-10 22:07:04 +01:00
|
|
|
Town *town = ::ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (town == nullptr) return INVALID_TOWN;
|
2011-12-10 22:07:04 +01:00
|
|
|
|
|
|
|
return town->index;
|
2011-08-19 23:19:10 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ TownID ScriptTile::GetClosestTown(TileIndex tile)
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
if (!::IsValidTile(tile)) return INVALID_TOWN;
|
|
|
|
|
2011-12-10 22:07:04 +01:00
|
|
|
Town *town = ::ClosestTownFromTile(tile, UINT_MAX);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (town == nullptr) return INVALID_TOWN;
|
2011-12-10 22:07:04 +01:00
|
|
|
|
|
|
|
return town->index;
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
2010-01-30 00:56:42 +01:00
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/* static */ Money ScriptTile::GetBuildCost(BuildType build_type)
|
2010-01-30 00:56:42 +01:00
|
|
|
{
|
|
|
|
switch (build_type) {
|
2019-04-10 23:07:06 +02:00
|
|
|
case BT_FOUNDATION: return ::GetPrice(PR_BUILD_FOUNDATION, 1, nullptr);
|
|
|
|
case BT_TERRAFORM: return ::GetPrice(PR_TERRAFORM, 1, nullptr);
|
|
|
|
case BT_BUILD_TREES: return ::GetPrice(PR_BUILD_TREES, 1, nullptr);
|
|
|
|
case BT_CLEAR_GRASS: return ::GetPrice(PR_CLEAR_GRASS, 1, nullptr);
|
|
|
|
case BT_CLEAR_ROUGH: return ::GetPrice(PR_CLEAR_ROUGH, 1, nullptr);
|
|
|
|
case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, nullptr);
|
|
|
|
case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, nullptr);
|
|
|
|
case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, nullptr);
|
2010-01-30 00:56:42 +01:00
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
}
|