OpenTTD Source  13.2.1
yapf_ship.cpp
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 #include "../../stdafx.h"
11 #include "../../ship.h"
12 #include "../../industry.h"
13 #include "../../vehicle_func.h"
14 
15 #include "yapf.hpp"
16 #include "yapf_node_ship.hpp"
17 
18 #include "../../safeguards.h"
19 
20 template <class Types>
22 {
23 public:
24  typedef typename Types::Tpf Tpf;
25  typedef typename Types::TrackFollower TrackFollower;
26  typedef typename Types::NodeList::Titem Node;
27  typedef typename Node::Key Key;
28 
29 protected:
30  TileIndex m_destTile;
31  TrackdirBits m_destTrackdirs;
32  StationID m_destStation;
33 
34 public:
35  void SetDestination(const Ship *v)
36  {
37  if (v->current_order.IsType(OT_GOTO_STATION)) {
38  m_destStation = v->current_order.GetDestination();
39  m_destTile = CalcClosestStationTile(m_destStation, v->tile, STATION_DOCK);
40  m_destTrackdirs = INVALID_TRACKDIR_BIT;
41  } else {
42  m_destStation = INVALID_STATION;
43  m_destTile = v->dest_tile;
45  }
46  }
47 
48 protected:
50  inline Tpf& Yapf()
51  {
52  return *static_cast<Tpf*>(this);
53  }
54 
55 public:
57  inline bool PfDetectDestination(Node& n)
58  {
59  return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
60  }
61 
62  inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
63  {
64  if (m_destStation != INVALID_STATION) {
65  return IsDockingTile(tile) && IsShipDestinationTile(tile, m_destStation);
66  }
67 
68  return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
69  }
70 
75  inline bool PfCalcEstimate(Node& n)
76  {
77  static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
78  static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
79  if (PfDetectDestination(n)) {
80  n.m_estimate = n.m_cost;
81  return true;
82  }
83 
84  TileIndex tile = n.m_segment_last_tile;
85  DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td);
86  int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
87  int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
88  int x2 = 2 * TileX(m_destTile);
89  int y2 = 2 * TileY(m_destTile);
90  int dx = abs(x1 - x2);
91  int dy = abs(y1 - y2);
92  int dmin = std::min(dx, dy);
93  int dxy = abs(dx - dy);
94  int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
95  n.m_estimate = n.m_cost + d;
96  assert(n.m_estimate >= n.m_parent->m_estimate);
97  return true;
98  }
99 };
100 
101 
103 template <class Types>
105 {
106 public:
107  typedef typename Types::Tpf Tpf;
108  typedef typename Types::TrackFollower TrackFollower;
109  typedef typename Types::NodeList::Titem Node;
110  typedef typename Node::Key Key;
111 
112 protected:
114  inline Tpf& Yapf()
115  {
116  return *static_cast<Tpf *>(this);
117  }
118 
119 public:
125  inline void PfFollowNode(Node &old_node)
126  {
127  TrackFollower F(Yapf().GetVehicle());
128  if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
129  Yapf().AddMultipleNodes(&old_node, F);
130  }
131  }
132 
134  inline char TransportTypeChar() const
135  {
136  return 'w';
137  }
138 
139  static Trackdir ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache)
140  {
141  /* handle special case - when next tile is destination tile */
142  if (tile == v->dest_tile) {
143  /* convert tracks to trackdirs */
144  TrackdirBits trackdirs = TrackBitsToTrackdirBits(tracks);
145  /* limit to trackdirs reachable from enterdir */
146  trackdirs &= DiagdirReachesTrackdirs(enterdir);
147 
148  /* use vehicle's current direction if that's possible, otherwise use first usable one. */
149  Trackdir veh_dir = v->GetVehicleTrackdir();
150  return (HasTrackdir(trackdirs, veh_dir)) ? veh_dir : (Trackdir)FindFirstBit2x64(trackdirs);
151  }
152 
153  /* move back to the old tile/trackdir (where ship is coming from) */
154  TileIndex src_tile = TileAddByDiagDir(tile, ReverseDiagDir(enterdir));
155  Trackdir trackdir = v->GetVehicleTrackdir();
156  assert(IsValidTrackdir(trackdir));
157 
158  /* convert origin trackdir to TrackdirBits */
159  TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
160 
161  /* create pathfinder instance */
162  Tpf pf;
163  /* set origin and destination nodes */
164  pf.SetOrigin(src_tile, trackdirs);
165  pf.SetDestination(v);
166  /* find best path */
167  path_found = pf.FindPath(v);
168 
169  Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
170 
171  Node *pNode = pf.GetBestNode();
172  if (pNode != nullptr) {
173  uint steps = 0;
174  for (Node *n = pNode; n->m_parent != nullptr; n = n->m_parent) steps++;
175  uint skip = 0;
176  if (path_found) skip = YAPF_SHIP_PATH_CACHE_LENGTH / 2;
177 
178  /* walk through the path back to the origin */
179  Node *pPrevNode = nullptr;
180  while (pNode->m_parent != nullptr) {
181  steps--;
182  /* Skip tiles at end of path near destination. */
183  if (skip > 0) skip--;
184  if (skip == 0 && steps > 0 && steps < YAPF_SHIP_PATH_CACHE_LENGTH) {
185  path_cache.push_front(pNode->GetTrackdir());
186  }
187  pPrevNode = pNode;
188  pNode = pNode->m_parent;
189  }
190  /* return trackdir from the best next node (direct child of origin) */
191  Node &best_next_node = *pPrevNode;
192  assert(best_next_node.GetTile() == tile);
193  next_trackdir = best_next_node.GetTrackdir();
194  /* remove last element for the special case when tile == dest_tile */
195  if (path_found && !path_cache.empty()) path_cache.pop_back();
196  }
197  return next_trackdir;
198  }
199 
210  static bool CheckShipReverse(const Ship *v, TileIndex tile, Trackdir td1, Trackdir td2, Trackdir *trackdir)
211  {
212  /* create pathfinder instance */
213  Tpf pf;
214  /* set origin and destination nodes */
215  if (trackdir == nullptr) {
216  pf.SetOrigin(tile, TrackdirToTrackdirBits(td1) | TrackdirToTrackdirBits(td2));
217  } else {
220  pf.SetOrigin(tile, rtds);
221  }
222  pf.SetDestination(v);
223  /* find best path */
224  if (!pf.FindPath(v)) return false;
225 
226  Node *pNode = pf.GetBestNode();
227  if (pNode == nullptr) return false;
228 
229  /* path was found
230  * walk through the path back to the origin */
231  while (pNode->m_parent != nullptr) {
232  pNode = pNode->m_parent;
233  }
234 
235  Trackdir best_trackdir = pNode->GetTrackdir();
236  if (trackdir != nullptr) {
237  *trackdir = best_trackdir;
238  } else {
239  assert(best_trackdir == td1 || best_trackdir == td2);
240  }
241  return best_trackdir != td1;
242  }
243 };
244 
246 template <class Types>
248 {
249 public:
250  typedef typename Types::Tpf Tpf;
251  typedef typename Types::TrackFollower TrackFollower;
252  typedef typename Types::NodeList::Titem Node;
253  typedef typename Node::Key Key;
254 
255 protected:
258  {
259  return *static_cast<Tpf *>(this);
260  }
261 
262 public:
263  inline int CurveCost(Trackdir td1, Trackdir td2)
264  {
265  assert(IsValidTrackdir(td1));
266  assert(IsValidTrackdir(td2));
267 
268  if (HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) {
269  /* 90-deg curve penalty */
270  return Yapf().PfGetSettings().ship_curve90_penalty;
271  } else if (td2 != NextTrackdir(td1)) {
272  /* 45-deg curve penalty */
273  return Yapf().PfGetSettings().ship_curve45_penalty;
274  }
275  return 0;
276  }
277 
278  static Vehicle *CountShipProc(Vehicle *v, void *data)
279  {
280  uint *count = (uint *)data;
281  /* Ignore other vehicles (aircraft) and ships inside depot. */
282  if (v->type == VEH_SHIP && (v->vehstatus & VS_HIDDEN) == 0) (*count)++;
283 
284  return nullptr;
285  }
286 
292  inline bool PfCalcCost(Node &n, const TrackFollower *tf)
293  {
294  /* base tile cost depending on distance */
295  int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
296  /* additional penalty for curves */
297  c += CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir());
298 
299  if (IsDockingTile(n.GetTile())) {
300  /* Check docking tile for occupancy */
301  uint count = 0;
302  HasVehicleOnPos(n.GetTile(), &count, &CountShipProc);
303  c += count * 3 * YAPF_TILE_LENGTH;
304  }
305 
306  /* Skipped tile cost for aqueducts. */
307  c += YAPF_TILE_LENGTH * tf->m_tiles_skipped;
308 
309  /* Ocean/canal speed penalty. */
310  const ShipVehicleInfo *svi = ShipVehInfo(Yapf().GetVehicle()->engine_type);
311  byte speed_frac = (GetEffectiveWaterClass(n.GetTile()) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac;
312  if (speed_frac > 0) c += YAPF_TILE_LENGTH * (1 + tf->m_tiles_skipped) * speed_frac / (256 - speed_frac);
313 
314  /* apply it */
315  n.m_cost = n.m_parent->m_cost + c;
316  return true;
317  }
318 };
319 
324 template <class Tpf_, class Ttrack_follower, class Tnode_list>
326 {
329 
331  typedef Tpf_ Tpf;
333  typedef Ttrack_follower TrackFollower;
335  typedef Tnode_list NodeList;
336  typedef Ship VehicleType;
338  typedef CYapfBaseT<Types> PfBase; // base pathfinder class
339  typedef CYapfFollowShipT<Types> PfFollow; // node follower
340  typedef CYapfOriginTileT<Types> PfOrigin; // origin provider
341  typedef CYapfDestinationTileWaterT<Types> PfDestination; // destination/distance provider
342  typedef CYapfSegmentCostCacheNoneT<Types> PfCache; // segment cost cache provider
343  typedef CYapfCostShipT<Types> PfCost; // cost provider
344 };
345 
346 /* YAPF type 1 - uses TileIndex/Trackdir as Node key */
347 struct CYapfShip1 : CYapfT<CYapfShip_TypesT<CYapfShip1, CFollowTrackWater , CShipNodeListTrackDir> > {};
348 /* YAPF type 2 - uses TileIndex/DiagDirection as Node key */
349 struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , CShipNodeListExitDir > > {};
350 
352 Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache)
353 {
354  /* default is YAPF type 2 */
355  typedef Trackdir (*PfnChooseShipTrack)(const Ship*, TileIndex, DiagDirection, TrackBits, bool &path_found, ShipPathCache &path_cache);
356  PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir
357 
358  /* check if non-default YAPF type needed */
360  pfnChooseShipTrack = &CYapfShip1::ChooseShipTrack; // Trackdir
361  }
362 
363  Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks, path_found, path_cache);
364  return (td_ret != INVALID_TRACKDIR) ? TrackdirToTrack(td_ret) : INVALID_TRACK;
365 }
366 
367 bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
368 {
369  Trackdir td = v->GetVehicleTrackdir();
370  Trackdir td_rev = ReverseTrackdir(td);
371  TileIndex tile = v->tile;
372 
373  typedef bool (*PfnCheckReverseShip)(const Ship*, TileIndex, Trackdir, Trackdir, Trackdir*);
374  PfnCheckReverseShip pfnCheckReverseShip = CYapfShip2::CheckShipReverse; // default: ExitDir
375 
376  /* check if non-default YAPF type needed */
378  pfnCheckReverseShip = &CYapfShip1::CheckShipReverse; // Trackdir
379  }
380 
381  bool reverse = pfnCheckReverseShip(v, tile, td, td_rev, trackdir);
382 
383  return reverse;
384 }
ChooseShipTrack
static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
Runs the pathfinder to choose a track to continue along.
Definition: ship_cmd.cpp:462
VehicleExitDir
static DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:713
CYapfShip_TypesT::NodeList
Tnode_list NodeList
node list type
Definition: yapf_ship.cpp:335
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
LinkGraph::Node
Updatable node class.
Definition: linkgraph.h:380
CYapfShip_TypesT
Config struct of YAPF for ships.
Definition: yapf_ship.cpp:325
HasVehicleOnPos
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:513
ShipVehicleInfo::canal_speed_frac
byte canal_speed_frac
Fraction of maximum speed for canal/river tiles.
Definition: engine_type.h:77
CYapfDestinationTileWaterT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_ship.cpp:75
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
yapf.hpp
CYapfDestinationTileWaterT::Key
Node::Key Key
key to hash tables
Definition: yapf_ship.cpp:27
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
CYapfShip_TypesT::Tpf
Tpf_ Tpf
Tpf - pathfinder type.
Definition: yapf_ship.cpp:331
YapfShipCheckReverse
bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
Returns true if it is better to reverse the ship before leaving depot using YAPF.
Definition: yapf_ship.cpp:367
yapf_node_ship.hpp
YAPF_SHIP_PATH_CACHE_LENGTH
static const int YAPF_SHIP_PATH_CACHE_LENGTH
Maximum length of ship path cache.
Definition: pathfinder_type.h:42
CYapfDestinationTileWaterT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition: yapf_ship.cpp:57
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:48
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CYapfShip_TypesT::TrackFollower
Ttrack_follower TrackFollower
track follower helper class
Definition: yapf_ship.cpp:333
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
CYapfT
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
Definition: yapf_common.hpp:183
CYapfDestinationTileWaterT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_ship.cpp:26
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
CYapfShip1
Definition: yapf_ship.cpp:347
INVALID_TRACKDIR_BIT
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition: track_type.h:117
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
CYapfCostShipT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_ship.cpp:257
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:601
CYapfOriginTileT
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Definition: yapf_common.hpp:15
CYapfFollowShipT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_ship.cpp:107
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:593
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
CYapfDestinationTileWaterT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_ship.cpp:50
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:252
CYapfCostShipT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_ship.cpp:250
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
CYapfFollowShipT::PfFollowNode
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Definition: yapf_ship.cpp:125
YAPF_TILE_LENGTH
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Definition: pathfinder_type.h:28
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
TrackdirToExitdir
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:438
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
FindFirstBit2x64
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
Definition: bitmath_func.hpp:216
CYapfCostShipT::Key
Node::Key Key
key to hash tables
Definition: yapf_ship.cpp:253
CYapfDestinationTileWaterT
Definition: yapf_ship.cpp:21
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
CYapfFollowShipT::CheckShipReverse
static bool CheckShipReverse(const Ship *v, TileIndex tile, Trackdir td1, Trackdir td2, Trackdir *trackdir)
Check whether a ship should reverse to reach its destination.
Definition: yapf_ship.cpp:210
TrackdirCrossesTrackdirs
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:605
CYapfFollowShipT::Key
Node::Key Key
key to hash tables
Definition: yapf_ship.cpp:110
CYapfShip2
Definition: yapf_ship.cpp:349
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
TileAddByDiagDir
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:382
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:89
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
CYapfShip_TypesT::Types
CYapfShip_TypesT< Tpf_, Ttrack_follower, Tnode_list > Types
Types - shortcut for this struct type.
Definition: yapf_ship.cpp:328
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
CalcClosestStationTile
static 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
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:251
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:286
CYapfShip_TypesT::PfBase
CYapfBaseT< Types > PfBase
pathfinder components (modules)
Definition: yapf_ship.cpp:338
DiagdirReachesTrackdirs
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:554
CYapfSegmentCostCacheNoneT
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Definition: yapf_costcache.hpp:21
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
Ship
All ships have this type.
Definition: ship.h:26
CYapfFollowShipT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_ship.cpp:114
CYapfCostShipT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_ship.cpp:252
CYapfFollowShipT
Node Follower module of YAPF for ships.
Definition: yapf_ship.cpp:104
YAPFSettings::disable_node_optimization
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
Definition: settings_type.h:414
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
ShipVehicleInfo
Information about a ship vehicle.
Definition: engine_type.h:67
TrackStatusToTrackdirBits
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:351
CYapfCostShipT::PfCalcCost
bool PfCalcCost(Node &n, const TrackFollower *tf)
Called by YAPF to calculate the cost from the origin to the given node.
Definition: yapf_ship.cpp:292
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
IsDockingTile
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:376
TrackdirToTrackdirBits
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:110
CYapfCostShipT
Cost Provider module of YAPF for ships.
Definition: yapf_ship.cpp:247
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition: settings_type.h:473
YAPF_TILE_CORNER_LENGTH
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
Definition: pathfinder_type.h:31
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:620
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:246
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
NextTrackdir
static Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
Definition: track_func.h:402
CYapfBaseT
CYapfBaseT - A-star type path finder base class.
Definition: yapf_base.hpp:47
CYapfDestinationTileWaterT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_ship.cpp:24
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
HasTrackdir
static bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition: track_func.h:339
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
CYapfFollowShipT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_ship.cpp:109
IsValidTrackdir
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
Definition: track_func.h:51
YapfShipChooseTrack
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache)
Ship controller helper - path finder invoker.
Definition: yapf_ship.cpp:352
CYapfFollowShipT::TransportTypeChar
char TransportTypeChar() const
return debug report character to identify the transportation type
Definition: yapf_ship.cpp:134
TrackdirToTrack
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:261
IsDiagonalTrackdir
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:630
ShipVehicleInfo::ocean_speed_frac
byte ocean_speed_frac
Fraction of maximum speed for ocean tiles.
Definition: engine_type.h:76
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28