|
OpenTTD Source 20260711-master-g3fb3006dff
|
Base functions related to the map and distances on them. More...
#include "stdafx.h"#include "debug.h"#include "water_map.h"#include "error_func.h"#include "string_func.h"#include "pathfinder/water_regions.h"#include "safeguards.h"Go to the source code of this file.
Functions | |
| TileIndex | TileVirtXYClampedToMap (int x, int y) |
| Get a tile from the virtual XY-coordinate. | |
| TileIndex | TileAddWrap (TileIndex tile, int addx, int addy) |
| This function checks if we add addx/addy to tile, if we do wrap around the edges. | |
| uint | DistanceManhattan (TileIndex t0, TileIndex t1) |
| Gets the Manhattan distance between the two given tiles. | |
| uint | DistanceSquare (TileIndex t0, TileIndex t1) |
| Gets the 'Square' distance between the two given tiles. | |
| uint | DistanceMax (TileIndex t0, TileIndex t1) |
| Gets the biggest distance component (x or y) between the two given tiles. | |
| uint | DistanceMaxPlusManhattan (TileIndex t0, TileIndex t1) |
| Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance, i.e. | |
| uint | DistanceFromEdge (TileIndex tile) |
| Param the minimum distance to an edge. | |
| uint | DistanceFromEdgeDir (TileIndex tile, DiagDirection dir) |
| Gets the distance to the edge of the map in given direction. | |
| uint | GetClosestWaterDistance (TileIndex tile, bool water) |
| Finds the distance for the closest tile with water/land given a tile. | |
Variables | |
| const AxisIndexArray< TileIndexDiffC > | _tileoffs_by_axis |
| 'Lookup table' for tile offsets given an Axis | |
| const DiagDirectionIndexArray< TileIndexDiffC > | _tileoffs_by_diagdir |
| 'Lookup table' for tile offsets given a DiagDirection | |
| const DirectionIndexArray< TileIndexDiffC > | _tileoffs_by_dir |
| 'Lookup table' for tile offsets given a Direction | |
Base functions related to the map and distances on them.
Definition in file map.cpp.
| uint DistanceFromEdge | ( | TileIndex | tile | ) |
Param the minimum distance to an edge.
shortest distance from any edge of the map
| tile | the tile to get the distance from |
Param the minimum distance to an edge.
Definition at line 229 of file map.cpp.
References Map::SizeX(), Map::SizeY(), TileX(), and TileY().
Referenced by CountConnectedSeaTiles(), GenerateStationName(), GreyscaleToMapHeights(), GrowTownWithExtraHouse(), IsRoadAllowedHere(), and TownCanBePlacedHere().
| uint DistanceFromEdgeDir | ( | TileIndex | tile, |
| DiagDirection | dir ) |
Gets the distance to the edge of the map in given direction.
distance from the map edge in given direction
| tile | the tile to get the distance from |
| dir | the direction of interest |
Gets the distance to the edge of the map in given direction.
Definition at line 246 of file map.cpp.
References _settings_game, Map::MaxX(), Map::MaxY(), NE, NW, SE, SW, TileX(), and TileY().
Referenced by CheckScaledDistanceFromEdge(), and GetOtherAqueductEnd().
Gets the Manhattan distance between the two given tiles.
also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)
The Manhattan distance is the sum of the delta of both the X and Y component. Also known as L1-Norm
| t0 | the start tile |
| t1 | the end tile |
Gets the Manhattan distance between the two given tiles.
Definition at line 169 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by AfterLoadGame(), AirportGetNearestTown(), CalcClosestTownFromTile(), CalcRaildirsDrawstyle(), CheckSubsidyDistance(), ClosestTownFromTile(), DeleteStaleLinks(), FindDeletedWaypointCloseTo(), FindSubsidyPassengerRoute(), FlowRiver(), WaterRegion::ForceUpdate(), GetClosestDeletedStation(), GetClosestObject(), GetCountAndDistanceOfClosestInstance(), CargoPacket::GetDistance(), GetDistanceFromNearbyHouse(), GetOrderDistance(), IndustriesScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), HighlightTownLocalAuthorityTiles(), IsCloseToTown(), ModifyStationRatingAround(), YapfRiverBuilder::PfCalcEstimate(), LinkRefresher::RefreshStats(), RiverFlowsDown(), TileLoop_Road(), TryMakeRiverTerminus(), VpSelectTilesWithMethod(), VpSetPresizeRange(), and YapfTrainCheckReverse().
Gets the biggest distance component (x or y) between the two given tiles.
also known as L-Infinity-Norm
Also known as L-Infinity-Norm.
| t0 | the start tile |
| t1 | the end tile |
Gets the biggest distance component (x or y) between the two given tiles.
Definition at line 201 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by Station::AddIndustryToDeliver(), CheckIfFarEnoughFromConflictingIndustry(), CheckIfIndustryIsAllowed(), FindStationsNearby(), and GenerateStationName().
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance, i.e.
Max + Manhattan.
two times the biggest distance component and once the smallest component.
| t0 | the start tile |
| t1 | the end tile |
Gets the biggest distance component (x or y) between the two given tiles plus the Manhattan distance, i.e.
Definition at line 217 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by DemandCalculator::CalcDemand(), DemandCalculator::DemandCalculator(), and MultiCommodityFlow::Dijkstra().
Gets the 'Square' distance between the two given tiles.
Euclidean- or L2-Norm squared.
The 'Square' distance is the square of the shortest (straight line) distance between the two tiles. Also known as Euclidean- or L2-Norm squared.
| t0 | the start tile |
| t1 | the end tile |
Gets the 'Square' distance between the two given tiles.
Definition at line 186 of file map.cpp.
References TileX(), and TileY().
Referenced by AircraftEventHandler(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildTunnel(), FindNearestHangar(), GetOrderDistance(), GetTownRadiusGroup(), IndustriesScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), MakeWetlands(), and PlaceTreeGroupAroundTile().
| uint GetClosestWaterDistance | ( | TileIndex | tile, |
| bool | water ) |
Finds the distance for the closest tile with water/land given a tile.
| tile | the tile to find the distance too |
| water | whether to find water or land |
Definition at line 263 of file map.cpp.
References _settings_game, End, HasTileWaterGround(), IsInsideMM(), IsTileType(), Map::Iterate(), Map::MaxX(), Map::MaxY(), TileX(), TileXY(), TileY(), Void, and Water.
Referenced by FindNearestGoodCoastalTownSpot(), and IndustriesScopeResolver::GetVariable().
This function checks if we add addx/addy to tile, if we do wrap around the edges.
For example, tile = (10,2) and addx = +3 and addy = -4. This function will now return INVALID_TILE, because the y is wrapped. This is needed in for example, farmland. When the tile is not wrapped, the result will be tile + TileDiffXY(addx, addy)
| tile | the 'starting' point of the adding |
| addx | the amount of tiles in the X direction to add |
| addy | the amount of tiles in the Y direction to add |
Definition at line 120 of file map.cpp.
References _settings_game, INVALID_TILE, Map::MaxX(), Map::MaxY(), TileX(), TileXY(), and TileY().
Referenced by CheckIfIndustryTilesAreFree(), CheckIfIndustryTileSlopes(), CmdBuildRailStation(), CmdBuildRoadStop(), CmdRemoveRoadStop(), CountMapSquareAround(), DisasterTick_Big_Ufo_Destroyer(), PlaceTreeAtSameHeight(), PlaceTreeGroupAroundTile(), PlaceTreeGroups(), and TryBuildTownLighthouse().
| TileIndex TileVirtXYClampedToMap | ( | int | x, |
| int | y ) |
Get a tile from the virtual XY-coordinate.
Coordinates outside of the map are clamped to the map edge.
| x | The virtual x coordinate of the tile. |
| y | The virtual y coordinate of the tile. |
Definition at line 84 of file map.cpp.
References Clamp(), Map::LogX(), Map::MaxX(), Map::MaxY(), and TILE_SIZE.
Referenced by CrashAirplane(), and FindNearestHangar().
|
extern |
'Lookup table' for tile offsets given an Axis
Referenced by TileOffsByAxis().
|
extern |
'Lookup table' for tile offsets given a DiagDirection
Referenced by TileIndexDiffCByDiagDir(), and TileOffsByDiagDir().
|
extern |
'Lookup table' for tile offsets given a Direction
Referenced by TileIndexDiffCByDir(), and TileOffsByDir().