|
OpenTTD Source
14.0-beta1
|
#include "stdafx.h"#include "debug.h"#include "core/alloc_func.hpp"#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 | TileAddWrap (TileIndex tile, int addx, int addy) |
| This function checks if we add addx/addy to tile, if we do wrap around the edges. More... | |
| uint | DistanceManhattan (TileIndex t0, TileIndex t1) |
| Gets the Manhattan distance between the two given tiles. More... | |
| uint | DistanceSquare (TileIndex t0, TileIndex t1) |
| Gets the 'Square' distance between the two given tiles. More... | |
| uint | DistanceMax (TileIndex t0, TileIndex t1) |
| Gets the biggest distance component (x or y) between the two given tiles. More... | |
| 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. More... | |
| uint | DistanceFromEdge (TileIndex tile) |
| Param the minimum distance to an edge. More... | |
| uint | DistanceFromEdgeDir (TileIndex tile, DiagDirection dir) |
| Gets the distance to the edge of the map in given direction. More... | |
| bool | CircularTileSearch (TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data) |
| Function performing a search around a center tile and going outward, thus in circle. More... | |
| bool | CircularTileSearch (TileIndex *tile, uint radius, uint w, uint h, TestTileOnSearchProc proc, void *user_data) |
| Generalized circular search allowing for rectangles and a hole. More... | |
| uint | GetClosestWaterDistance (TileIndex tile, bool water) |
| Finds the distance for the closest tile with water/land given a tile. More... | |
Variables | |
| const TileIndexDiffC | _tileoffs_by_diagdir [] |
| 'Lookup table' for tile offsets given a DiagDirection More... | |
| const TileIndexDiffC | _tileoffs_by_dir [] |
| 'Lookup table' for tile offsets given a Direction More... | |
Base functions related to the map and distances on them.
Definition in file map.cpp.
| bool CircularTileSearch | ( | TileIndex * | tile, |
| uint | radius, | ||
| uint | w, | ||
| uint | h, | ||
| TestTileOnSearchProc | proc, | ||
| void * | user_data | ||
| ) |
Generalized circular search allowing for rectangles and a hole.
Function performing a search around a center rectangle and going outward. The center rectangle is left out from the search. To do a rectangular search without a hole, set either h or w to zero. Every tile will be tested by means of the callback function proc, which will determine if yes or no the given tile meets criteria of search.
| tile | to start the search from. Upon completion, it will return the tile matching the search. This tile should be directly north of the hole (if any). |
| radius | How many tiles to search outwards. Note: This is a radius and thus different from the size parameter of the other CircularTileSearch function, which is a diameter. |
| w | the width of the inner rectangle |
| h | the height of the inner rectangle |
| proc | callback testing function pointer. |
| user_data | to be passed to the callback function. Depends on the implementation |
| bool CircularTileSearch | ( | TileIndex * | tile, |
| uint | size, | ||
| TestTileOnSearchProc | proc, | ||
| void * | user_data | ||
| ) |
Function performing a search around a center tile and going outward, thus in circle.
Although it really is a square search... Every tile will be tested by means of the callback function proc, which will determine if yes or no the given tile meets criteria of search.
| tile | to start the search from. Upon completion, it will return the tile matching the search |
| size | number of tiles per side of the desired search area |
| proc | callback testing function pointer. |
| user_data | to be passed to the callback function. Depends on the implementation |
Definition at line 260 of file map.cpp.
References CircularTileSearch(), DIR_N, and TileAddByDir().
Referenced by ChopLumberMillTrees(), CircularTileSearch(), CreateRivers(), FindNearestGoodCoastalTownSpot(), GetDistanceFromNearbyHouse(), GrowTownWithBridge(), TownActionBuildStatue(), and TryBuildTransmitter().
| 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 |
Definition at line 219 of file map.cpp.
References Map::SizeX(), Map::SizeY(), TileX(), and TileY().
Referenced by 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 |
Definition at line 236 of file map.cpp.
References _settings_game, GameSettings::construction, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, ConstructionSettings::freeform_edges, Map::MaxX(), Map::MaxY(), 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 |
Definition at line 159 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by AirportGetNearestTown(), CheckSubsidyDistance(), DeleteStaleLinks(), FindDeletedWaypointCloseTo(), FindSubsidyPassengerRoute(), FlowRiver(), FlowsDown(), GetClosestObject(), CargoPacket::GetDistance(), GetDistanceFromNearbyHouse(), IndustriesScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), 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 |
Definition at line 191 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by Station::AddIndustryToDeliver(), CheckIfFarEnoughFromConflictingIndustry(), and CheckIfIndustryIsAllowed().
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 |
Definition at line 207 of file map.cpp.
References Delta(), TileX(), and TileY().
Referenced by DemandCalculator::CalcDemand().
Gets the 'Square' distance between the two given tiles.
euclidian- or L2-Norm squared
The 'Square' distance is the square of the shortest (straight line) distance between the two tiles. Also known as euclidian- or L2-Norm squared.
| t0 | the start tile |
| t1 | the end tile |
Definition at line 176 of file map.cpp.
References TileX(), and TileY().
Referenced by CmdBuildBridge(), CmdBuildTunnel(), GetTownRadiusGroup(), IndustriesScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().
| 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 342 of file map.cpp.
References HasTileWaterGround().
Referenced by FindFurthestFromWater(), 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 116 of file map.cpp.
Referenced by CheckIfIndustryTilesAreFree(), CmdRemoveRoadStop(), and CountMapSquareAround().
| const TileIndexDiffC _tileoffs_by_diagdir[] |
'Lookup table' for tile offsets given a DiagDirection
Referenced by TileIndexDiffCByDiagDir(), and TileOffsByDiagDir().
| const TileIndexDiffC _tileoffs_by_dir[] |
'Lookup table' for tile offsets given a Direction
Referenced by TileIndexDiffCByDir(), and TileOffsByDir().