OpenTTD Source  20240917-master-g9ab0a47812
pathfinder_func.h
Go to the documentation of this file.
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 
10 #ifndef PATHFINDER_FUNC_H
11 #define PATHFINDER_FUNC_H
12 
13 #include "../tile_cmd.h"
14 #include "../waypoint_base.h"
15 
25 inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
26 {
27  const BaseStation *st = BaseStation::Get(station);
28  TileArea ta;
29  st->GetTileArea(&ta, station_type);
30 
31  /* If the rail station is (temporarily) not present, use the station sign to drive near the station */
32  if (ta.tile == INVALID_TILE) return st->xy;
33 
34  uint minx = TileX(ta.tile); // topmost corner of station
35  uint miny = TileY(ta.tile);
36  uint maxx = minx + ta.w - 1; // lowermost corner of station
37  uint maxy = miny + ta.h - 1;
38 
39  /* we are going the aim for the x coordinate of the closest corner
40  * but if we are between those coordinates, we will aim for our own x coordinate */
41  uint x = ClampU(TileX(tile), minx, maxx);
42 
43  /* same for y coordinate, see above comment */
44  uint y = ClampU(TileY(tile), miny, maxy);
45 
46  /* return the tile of our target coordinates */
47  return TileXY(x, y);
48 }
49 
60 inline TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
61 {
63 
64  if (rtt == RTT_TRAM && bits == TRACKDIR_BIT_NONE) {
65  if (IsNormalRoadTile(tile)) {
66  RoadBits rb = GetRoadBits(tile, RTT_TRAM);
67  switch (rb) {
68  case ROAD_NE:
69  case ROAD_SW:
71  break;
72 
73  case ROAD_NW:
74  case ROAD_SE:
76  break;
77 
78  default: break;
79  }
80  }
81  }
82 
83  return bits;
84 }
85 
86 #endif /* PATHFINDER_FUNC_H */
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
Pool::PoolItem<&_station_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:52
TrackStatusToTrackdirBits
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:352
BaseStation::GetTileArea
virtual void GetTileArea(TileArea *ta, StationType type) const =0
Get the tile area for a given station type.
ROAD_SE
@ ROAD_SE
South-east part.
Definition: road_type.h:56
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
ClampU
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:150
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition: track_type.h:108
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
ROAD_NW
@ ROAD_NW
North-west part.
Definition: road_type.h:54
StationType
StationType
Station types.
Definition: station_type.h:31
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:553
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
ROAD_SW
@ ROAD_SW
South-west part.
Definition: road_type.h:55
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:99
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
IsNormalRoadTile
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition: road_map.h:74
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition: track_type.h:100
GetTrackdirBitsForRoad
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
Definition: pathfinder_func.h:60
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
CalcClosestStationTile
TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
Calculates the tile of given station that is closest to a given tile for this we assume the station i...
Definition: pathfinder_func.h:25
ROAD_NE
@ ROAD_NE
North-east part.
Definition: road_type.h:57
GetRoadBits
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:128
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:60
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:59
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition: track_type.h:101
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition: track_type.h:98
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition: track_type.h:107