Mercurial > hg > openttd
annotate src/pbs.cpp @ 20706:79930f9362c3 draft
-Change: [Win32] Position the IME composition window at the caret position.
author | Michael Lutz <michi@icosahedron.de> |
---|---|
date | Sun, 07 Apr 2013 17:10:38 +0200 |
parents | 67557b5abe00 |
children |
rev | line source |
---|---|
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
5 * 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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
6 * 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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
7 * 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/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
9 |
13835
c601c149b453
(svn r18364) -Codechange: move the pathfinders and their related files into a separate directory
rubidium <rubidium@openttd.org>
parents:
13194
diff
changeset
|
10 /** @file pbs.cpp PBS support routines */ |
c601c149b453
(svn r18364) -Codechange: move the pathfinders and their related files into a separate directory
rubidium <rubidium@openttd.org>
parents:
13194
diff
changeset
|
11 |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
17277
5b204f51b151
(svn r22017) -Codechange: move MarkTileDirtyByTile to viewport_func.h
rubidium <rubidium@openttd.org>
parents:
15504
diff
changeset
|
13 #include "viewport_func.h" |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
14 #include "vehicle_func.h" |
19973
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
15 #include "newgrf_station.h" |
13890
32e58ed16e0b
(svn r18420) -Codechange: split YAPF's track follower from the actual YAPF code
rubidium <rubidium@openttd.org>
parents:
13863
diff
changeset
|
16 #include "pathfinder/follow_track.hpp" |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
17 |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
18 /** |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
19 * Get the reserved trackbits for any tile, regardless of type. |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
20 * @param t the tile |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
21 * @return the reserved trackbits. TRACK_BIT_NONE on nothing reserved or |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
22 * a tile without rail. |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
23 */ |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
24 TrackBits GetReservedTrackbits(TileIndex t) |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
25 { |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
26 switch (GetTileType(t)) { |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
27 case MP_RAILWAY: |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
28 if (IsRailDepot(t)) return GetDepotReservationTrackBits(t); |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
29 if (IsPlainRail(t)) return GetRailReservationTrackBits(t); |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
30 break; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
31 |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
32 case MP_ROAD: |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
33 if (IsLevelCrossing(t)) return GetCrossingReservationTrackBits(t); |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
34 break; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
35 |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
36 case MP_STATION: |
12501
44606771f552
(svn r16938) -Codechange: introduce helper function to tell whether a tile is either a rail station or rail waypoint tile
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
37 if (HasStationRail(t)) return GetStationReservationTrackBits(t); |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
38 break; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
39 |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
40 case MP_TUNNELBRIDGE: |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
41 if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) return GetTunnelBridgeReservationTrackBits(t); |
9786
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
42 break; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
43 |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
44 default: |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
45 break; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
46 } |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
47 return TRACK_BIT_NONE; |
f94081b1f0dc
(svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
48 } |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
49 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
50 /** |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
51 * Set the reservation for a complete station platform. |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
52 * @pre IsRailStationTile(start) |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
53 * @param start starting tile of the platform |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
54 * @param dir the direction in which to follow the platform |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
55 * @param b the state the reservation should be set to |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
56 */ |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
57 void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b) |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
58 { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
59 TileIndex tile = start; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
60 TileIndexDiff diff = TileOffsByDiagDir(dir); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
61 |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
62 assert(IsRailStationTile(start)); |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
63 assert(GetRailStationAxis(start) == DiagDirToAxis(dir)); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
64 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
65 do { |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
66 SetRailStationReservation(tile, b); |
9823
7e2bcaec0fc7
(svn r13965) -Add [YAPP]: Implement newgrf var 0x44 for stations (PBS reservation state). (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9814
diff
changeset
|
67 MarkTileDirtyByTile(tile); |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
68 tile = TILE_ADD(tile, diff); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
69 } while (IsCompatibleTrainStationTile(tile, start)); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
70 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
71 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
72 /** |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
73 * Try to reserve a specific track on a tile |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
74 * @param tile the tile |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
75 * @param t the track |
19973
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
76 * @param trigger_stations whether to call station randomisation trigger |
14690
6cc90e733c5d
(svn r19272) -Doc: successfull -> successful.
alberth <alberth@openttd.org>
parents:
14258
diff
changeset
|
77 * @return \c true if reservation was successful, i.e. the track was |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
78 * free and didn't cross any other reserved tracks. |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
79 */ |
19973
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
80 bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations) |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
81 { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
82 assert((GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & TrackToTrackBits(t)) != 0); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
83 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
84 if (_settings_client.gui.show_track_reservation) { |
9954
cec8f85994d3
(svn r14109) -Fix (r14107): marking reserved tile dirty is needed for waypoints and stations even when patch option is disabled
smatz <smatz@openttd.org>
parents:
9952
diff
changeset
|
85 /* show the reserved rail if needed */ |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
86 MarkTileDirtyByTile(tile); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
87 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
88 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
89 switch (GetTileType(tile)) { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
90 case MP_RAILWAY: |
11946
d5716f5a9844
(svn r16349) -Codechange: rename IsPlainRailTile() to IsPlainRail(), introduce shiny new IsPlainRailTile()
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
91 if (IsPlainRail(tile)) return TryReserveTrack(tile, t); |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
92 if (IsRailDepot(tile)) { |
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
93 if (!HasDepotReservation(tile)) { |
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
94 SetDepotReservation(tile, true); |
9954
cec8f85994d3
(svn r14109) -Fix (r14107): marking reserved tile dirty is needed for waypoints and stations even when patch option is disabled
smatz <smatz@openttd.org>
parents:
9952
diff
changeset
|
95 MarkTileDirtyByTile(tile); // some GRFs change their appearance when tile is reserved |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
96 return true; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
97 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
98 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
99 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
100 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
101 case MP_ROAD: |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
102 if (IsLevelCrossing(tile) && !HasCrossingReservation(tile)) { |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
103 SetCrossingReservation(tile, true); |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9823
diff
changeset
|
104 BarCrossing(tile); |
9954
cec8f85994d3
(svn r14109) -Fix (r14107): marking reserved tile dirty is needed for waypoints and stations even when patch option is disabled
smatz <smatz@openttd.org>
parents:
9952
diff
changeset
|
105 MarkTileDirtyByTile(tile); // crossing barred, make tile dirty |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
106 return true; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
107 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
108 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
109 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
110 case MP_STATION: |
12501
44606771f552
(svn r16938) -Codechange: introduce helper function to tell whether a tile is either a rail station or rail waypoint tile
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
111 if (HasStationRail(tile) && !HasStationReservation(tile)) { |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
112 SetRailStationReservation(tile, true); |
19974
67557b5abe00
(svn r24906) -Fix (24905): Don't trigger on path reservation for waypoints.
peter1138 <peter1138@openttd.org>
parents:
19973
diff
changeset
|
113 if (trigger_stations && IsRailStation(tile)) TriggerStationRandomisation(NULL, tile, SRT_PATH_RESERVATION); |
9954
cec8f85994d3
(svn r14109) -Fix (r14107): marking reserved tile dirty is needed for waypoints and stations even when patch option is disabled
smatz <smatz@openttd.org>
parents:
9952
diff
changeset
|
114 MarkTileDirtyByTile(tile); // some GRFs need redraw after reserving track |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
115 return true; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
116 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
117 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
118 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
119 case MP_TUNNELBRIDGE: |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
120 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL && !GetTunnelBridgeReservationTrackBits(tile)) { |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
121 SetTunnelBridgeReservation(tile, true); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
122 return true; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
123 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
124 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
125 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
126 default: |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
127 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
128 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
129 return false; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
130 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
131 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
132 /** |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
133 * Lift the reservation of a specific track on a tile |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
134 * @param tile the tile |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
135 * @param t the track |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
136 */ |
13194
4b124fd22c06
(svn r17701) -Codechange: don't start line with a space if it's not inside comment
smatz <smatz@openttd.org>
parents:
13186
diff
changeset
|
137 void UnreserveRailTrack(TileIndex tile, Track t) |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
138 { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
139 assert((GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & TrackToTrackBits(t)) != 0); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
140 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
141 if (_settings_client.gui.show_track_reservation) { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
142 MarkTileDirtyByTile(tile); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
143 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
144 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
145 switch (GetTileType(tile)) { |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
146 case MP_RAILWAY: |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
147 if (IsRailDepot(tile)) { |
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
148 SetDepotReservation(tile, false); |
9823
7e2bcaec0fc7
(svn r13965) -Add [YAPP]: Implement newgrf var 0x44 for stations (PBS reservation state). (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9814
diff
changeset
|
149 MarkTileDirtyByTile(tile); |
9954
cec8f85994d3
(svn r14109) -Fix (r14107): marking reserved tile dirty is needed for waypoints and stations even when patch option is disabled
smatz <smatz@openttd.org>
parents:
9952
diff
changeset
|
150 break; |
9823
7e2bcaec0fc7
(svn r13965) -Add [YAPP]: Implement newgrf var 0x44 for stations (PBS reservation state). (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9814
diff
changeset
|
151 } |
11946
d5716f5a9844
(svn r16349) -Codechange: rename IsPlainRailTile() to IsPlainRail(), introduce shiny new IsPlainRailTile()
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
152 if (IsPlainRail(tile)) UnreserveTrack(tile, t); |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
153 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
154 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
155 case MP_ROAD: |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9823
diff
changeset
|
156 if (IsLevelCrossing(tile)) { |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9823
diff
changeset
|
157 SetCrossingReservation(tile, false); |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9823
diff
changeset
|
158 UpdateLevelCrossing(tile); |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9823
diff
changeset
|
159 } |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
160 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
161 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
162 case MP_STATION: |
12501
44606771f552
(svn r16938) -Codechange: introduce helper function to tell whether a tile is either a rail station or rail waypoint tile
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
163 if (HasStationRail(tile)) { |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
164 SetRailStationReservation(tile, false); |
9823
7e2bcaec0fc7
(svn r13965) -Add [YAPP]: Implement newgrf var 0x44 for stations (PBS reservation state). (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9814
diff
changeset
|
165 MarkTileDirtyByTile(tile); |
7e2bcaec0fc7
(svn r13965) -Add [YAPP]: Implement newgrf var 0x44 for stations (PBS reservation state). (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9814
diff
changeset
|
166 } |
9787
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
167 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
168 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
169 case MP_TUNNELBRIDGE: |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
170 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) SetTunnelBridgeReservation(tile, false); |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
171 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
172 |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
173 default: |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
174 break; |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
175 } |
7b4d79522b7e
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9786
diff
changeset
|
176 } |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
177 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
178 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
179 /** Follow a reservation starting from a specific tile to the end. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
180 static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Trackdir trackdir, bool ignore_oneway = false) |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
181 { |
10586
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
182 TileIndex start_tile = tile; |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
183 Trackdir start_trackdir = trackdir; |
10596
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
184 bool first_loop = true; |
10586
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
185 |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
186 /* Start track not reserved? This can happen if two trains |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
187 * are on the same tile. The reservation on the next tile |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
188 * is not ours in this case, so exit. */ |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
189 if (!HasReservedTracks(tile, TrackToTrackBits(TrackdirToTrack(trackdir)))) return PBSTileInfo(tile, trackdir, false); |
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
190 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
191 /* Do not disallow 90 deg turns as the setting might have changed between reserving and now. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
192 CFollowTrackRail ft(o, rts); |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
193 while (ft.Follow(tile, trackdir)) { |
10586
62d3b2269885
(svn r14849) -Fix [FS#2478]: A train meeting its end could lead to an endless loop.
michi_cc <michi_cc@openttd.org>
parents:
10210
diff
changeset
|
194 TrackdirBits reserved = ft.m_new_td_bits & TrackBitsToTrackdirBits(GetReservedTrackbits(ft.m_new_tile)); |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
195 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
196 /* No reservation --> path end found */ |
18716
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
197 if (reserved == TRACKDIR_BIT_NONE) { |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
198 if (ft.m_is_station) { |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
199 /* Check skipped station tiles as well, maybe our reservation ends inside the station. */ |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
200 TileIndexDiff diff = TileOffsByDiagDir(ft.m_exitdir); |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
201 while (ft.m_tiles_skipped-- > 0) { |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
202 ft.m_new_tile -= diff; |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
203 if (HasStationReservation(ft.m_new_tile)) { |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
204 tile = ft.m_new_tile; |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
205 trackdir = DiagDirToDiagTrackdir(ft.m_exitdir); |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
206 break; |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
207 } |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
208 } |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
209 } |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
210 break; |
30959e70d2f7
(svn r23564) -Fix [FS#4888]: Extending a path reservation starting at a partially reserved rail station could fail.
michi_cc <michi_cc@openttd.org>
parents:
17277
diff
changeset
|
211 } |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
212 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
213 /* Can't have more than one reserved trackdir */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
214 Trackdir new_trackdir = FindFirstTrackdir(reserved); |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
215 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
216 /* One-way signal against us. The reservation can't be ours as it is not |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
217 * a safe position from our direction and we can never pass the signal. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
218 if (!ignore_oneway && HasOnewaySignalBlockingTrackdir(ft.m_new_tile, new_trackdir)) break; |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
219 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
220 tile = ft.m_new_tile; |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
221 trackdir = new_trackdir; |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
222 |
10596
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
223 if (first_loop) { |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
224 /* Update the start tile after we followed the track the first |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19201
diff
changeset
|
225 * time. This is necessary because the track follower can skip |
10596
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
226 * tiles (in stations for example) which means that we might |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
227 * never visit our original starting tile again. */ |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
228 start_tile = tile; |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
229 start_trackdir = trackdir; |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
230 first_loop = false; |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
231 } else { |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
232 /* Loop encountered? */ |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
233 if (tile == start_tile && trackdir == start_trackdir) break; |
e72122aee052
(svn r14876) -Fix [FS#2509] (r14849): Reserved path loop detection was broken for stations.
michi_cc <michi_cc@openttd.org>
parents:
10586
diff
changeset
|
234 } |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
235 /* Depot tile? Can't continue. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
236 if (IsRailDepotTile(tile)) break; |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
237 /* Non-pbs signal? Reservation can't continue. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
238 if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break; |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
239 } |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
240 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
241 return PBSTileInfo(tile, trackdir, false); |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
242 } |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
243 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
244 /** |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
245 * Helper struct for finding the best matching vehicle on a specific track. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
246 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
247 struct FindTrainOnTrackInfo { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
248 PBSTileInfo res; ///< Information about the track. |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
249 Train *best; ///< The currently "best" vehicle we have found. |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
250 |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
251 /** Init the best location to NULL always! */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
252 FindTrainOnTrackInfo() : best(NULL) {} |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
253 }; |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
254 |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
255 /** Callback for Has/FindVehicleOnPos to find a train on a specific track. */ |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
256 static Vehicle *FindTrainOnTrackEnum(Vehicle *v, void *data) |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
257 { |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
258 FindTrainOnTrackInfo *info = (FindTrainOnTrackInfo *)data; |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
259 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
260 if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return NULL; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
261 |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
11986
diff
changeset
|
262 Train *t = Train::From(v); |
13863
5e0d41f1c723
(svn r18392) -Fix (r13956)[FS#3345]: [YAPP] Trains on bridges were not found, when searching for the origin of a reservation. (Hirundo)
frosch <frosch@openttd.org>
parents:
13835
diff
changeset
|
263 if (t->track == TRACK_BIT_WORMHOLE || HasBit((TrackBits)t->track, TrackdirToTrack(info->res.trackdir))) { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
264 t = t->First(); |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
265 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
266 /* ALWAYS return the lowest ID (anti-desync!) */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
267 if (info->best == NULL || t->index < info->best->index) info->best = t; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
268 return t; |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
269 } |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
270 |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
271 return NULL; |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
272 } |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
273 |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
274 /** |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
275 * Follow a train reservation to the last tile. |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
276 * |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
277 * @param v the vehicle |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9824
diff
changeset
|
278 * @param train_on_res Is set to a train we might encounter |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
279 * @returns The last tile of the reservation or the current train tile if no reservation present. |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
280 */ |
14100
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
281 PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res) |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
282 { |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
283 assert(v->type == VEH_TRAIN); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
284 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
285 TileIndex tile = v->tile; |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11946
diff
changeset
|
286 Trackdir trackdir = v->GetVehicleTrackdir(); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
287 |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12114
diff
changeset
|
288 if (IsRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
289 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
290 FindTrainOnTrackInfo ftoti; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
291 ftoti.res = FollowReservation(v->owner, GetRailTypeInfo(v->railtype)->compatible_railtypes, tile, trackdir); |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
292 ftoti.res.okay = IsSafeWaitingPosition(v, ftoti.res.tile, ftoti.res.trackdir, true, _settings_game.pf.forbid_90_deg); |
14100
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
293 if (train_on_res != NULL) { |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
294 FindVehicleOnPos(ftoti.res.tile, &ftoti, FindTrainOnTrackEnum); |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
295 if (ftoti.best != NULL) *train_on_res = ftoti.best->First(); |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
296 if (*train_on_res == NULL && IsRailStationTile(ftoti.res.tile)) { |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
297 /* The target tile is a rail station. The track follower |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
298 * has stopped on the last platform tile where we haven't |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
299 * found a train. Also check all previous platform tiles |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
300 * for a possible train. */ |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
301 TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(ftoti.res.trackdir))); |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
302 for (TileIndex st_tile = ftoti.res.tile + diff; *train_on_res == NULL && IsCompatibleTrainStationTile(st_tile, ftoti.res.tile); st_tile += diff) { |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
303 FindVehicleOnPos(st_tile, &ftoti, FindTrainOnTrackEnum); |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
304 if (ftoti.best != NULL) *train_on_res = ftoti.best->First(); |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
305 } |
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
306 } |
14834
4c3c17b0060b
(svn r19425) -Fix: [YAPP] A train on a bridge/tunnel was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14690
diff
changeset
|
307 if (*train_on_res == NULL && IsTileType(ftoti.res.tile, MP_TUNNELBRIDGE)) { |
4c3c17b0060b
(svn r19425) -Fix: [YAPP] A train on a bridge/tunnel was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14690
diff
changeset
|
308 /* The target tile is a bridge/tunnel, also check the other end tile. */ |
4c3c17b0060b
(svn r19425) -Fix: [YAPP] A train on a bridge/tunnel was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14690
diff
changeset
|
309 FindVehicleOnPos(GetOtherTunnelBridgeEnd(ftoti.res.tile), &ftoti, FindTrainOnTrackEnum); |
4c3c17b0060b
(svn r19425) -Fix: [YAPP] A train on a bridge/tunnel was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14690
diff
changeset
|
310 if (ftoti.best != NULL) *train_on_res = ftoti.best->First(); |
4c3c17b0060b
(svn r19425) -Fix: [YAPP] A train on a bridge/tunnel was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14690
diff
changeset
|
311 } |
14100
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
13890
diff
changeset
|
312 } |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
313 return ftoti.res; |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
314 } |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
315 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
316 /** |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
317 * Find the train which has reserved a specific path. |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
318 * |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
319 * @param tile A tile on the path. |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
320 * @param track A reserved track on the tile. |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
321 * @return The vehicle holding the reservation or NULL if the path is stray. |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
322 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
323 Train *GetTrainForReservation(TileIndex tile, Track track) |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
324 { |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
325 assert(HasReservedTracks(tile, TrackToTrackBits(track))); |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
326 Trackdir trackdir = TrackToTrackdir(track); |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
327 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
328 RailTypes rts = GetRailTypeInfo(GetTileRailType(tile))->compatible_railtypes; |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
329 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
330 /* Follow the path from tile to both ends, one of the end tiles should |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
331 * have a train on it. We need FollowReservation to ignore one-way signals |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
332 * here, as one of the two search directions will be the "wrong" way. */ |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
333 for (int i = 0; i < 2; ++i, trackdir = ReverseTrackdir(trackdir)) { |
15504
fd3787b52d77
(svn r20156) -Fix [FS#3937]: [YAPP] Converting a one-way block to a path signal with trains on both sides could lead to a train crash.
michi_cc <michi_cc@openttd.org>
parents:
14834
diff
changeset
|
334 /* If the tile has a one-way block signal in the current trackdir, skip the |
fd3787b52d77
(svn r20156) -Fix [FS#3937]: [YAPP] Converting a one-way block to a path signal with trains on both sides could lead to a train crash.
michi_cc <michi_cc@openttd.org>
parents:
14834
diff
changeset
|
335 * search in this direction as the reservation can't come from this side.*/ |
fd3787b52d77
(svn r20156) -Fix [FS#3937]: [YAPP] Converting a one-way block to a path signal with trains on both sides could lead to a train crash.
michi_cc <michi_cc@openttd.org>
parents:
14834
diff
changeset
|
336 if (HasOnewaySignalBlockingTrackdir(tile, ReverseTrackdir(trackdir)) && !HasPbsSignalOnTrackdir(tile, trackdir)) continue; |
fd3787b52d77
(svn r20156) -Fix [FS#3937]: [YAPP] Converting a one-way block to a path signal with trains on both sides could lead to a train crash.
michi_cc <michi_cc@openttd.org>
parents:
14834
diff
changeset
|
337 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
338 FindTrainOnTrackInfo ftoti; |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
339 ftoti.res = FollowReservation(GetTileOwner(tile), rts, tile, trackdir, true); |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
340 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
341 FindVehicleOnPos(ftoti.res.tile, &ftoti, FindTrainOnTrackEnum); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
342 if (ftoti.best != NULL) return ftoti.best; |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
343 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
344 /* Special case for stations: check the whole platform for a vehicle. */ |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12501
diff
changeset
|
345 if (IsRailStationTile(ftoti.res.tile)) { |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
346 TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(ftoti.res.trackdir))); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
347 for (TileIndex st_tile = ftoti.res.tile + diff; IsCompatibleTrainStationTile(st_tile, ftoti.res.tile); st_tile += diff) { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
348 FindVehicleOnPos(st_tile, &ftoti, FindTrainOnTrackEnum); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
349 if (ftoti.best != NULL) return ftoti.best; |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
350 } |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
351 } |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
352 |
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
353 /* Special case for bridges/tunnels: check the other end as well. */ |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
354 if (IsTileType(ftoti.res.tile, MP_TUNNELBRIDGE)) { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
355 FindVehicleOnPos(GetOtherTunnelBridgeEnd(ftoti.res.tile), &ftoti, FindTrainOnTrackEnum); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9954
diff
changeset
|
356 if (ftoti.best != NULL) return ftoti.best; |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
357 } |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
358 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
359 |
9814
7cd3c451b12d
(svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9798
diff
changeset
|
360 return NULL; |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
361 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
362 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
363 /** |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
364 * Determine whether a certain track on a tile is a safe position to end a path. |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
365 * |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
366 * @param v the vehicle to test for |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
367 * @param tile The tile |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
368 * @param trackdir The trackdir to test |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
369 * @param include_line_end Should end-of-line tiles be considered safe? |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
370 * @param forbid_90deg Don't allow trains to make 90 degree turns |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
371 * @return True if it is a safe position |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
372 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
373 bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg) |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
374 { |
19201
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
375 if (IsRailDepotTile(tile)) return true; |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
376 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
377 if (IsTileType(tile, MP_RAILWAY)) { |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
378 /* For non-pbs signals, stop on the signal tile. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
379 if (HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) return true; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
380 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
381 |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19201
diff
changeset
|
382 /* Check next tile. For performance reasons, we check for 90 degree turns ourself. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
383 CFollowTrackRail ft(v, GetRailTypeInfo(v->railtype)->compatible_railtypes); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
384 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
385 /* End of track? */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
386 if (!ft.Follow(tile, trackdir)) { |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
387 /* Last tile of a terminus station is a safe position. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
388 if (include_line_end) return true; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
389 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
390 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
391 /* Check for reachable tracks. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
392 ft.m_new_td_bits &= DiagdirReachesTrackdirs(ft.m_exitdir); |
10210
727edf4d6501
(svn r14428) -Fix [FS#2306]: A 90-degree curve can be a safe waiting position if they are forbidden for trains.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
393 if (forbid_90deg) ft.m_new_td_bits &= ~TrackdirCrossesTrackdirs(trackdir); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
394 if (ft.m_new_td_bits == TRACKDIR_BIT_NONE) return include_line_end; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
395 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
396 if (ft.m_new_td_bits != TRACKDIR_BIT_NONE && KillFirstBit(ft.m_new_td_bits) == TRACKDIR_BIT_NONE) { |
14101
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
397 Trackdir td = FindFirstTrackdir(ft.m_new_td_bits); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
398 /* PBS signal on next trackdir? Safe position. */ |
14101
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
399 if (HasPbsSignalOnTrackdir(ft.m_new_tile, td)) return true; |
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
400 /* One-way PBS signal against us? Safe if end-of-line is allowed. */ |
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
401 if (IsTileType(ft.m_new_tile, MP_RAILWAY) && HasSignalOnTrackdir(ft.m_new_tile, ReverseTrackdir(td)) && |
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
402 GetSignalType(ft.m_new_tile, TrackdirToTrack(td)) == SIGTYPE_PBS_ONEWAY) { |
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
403 return include_line_end; |
bc2511d7b627
(svn r18648) -Fix/Feature [FS#3430-ish]: [YAPP] Treat the backside of an one-way path signals as a safe waiting point.
michi_cc <michi_cc@openttd.org>
parents:
14100
diff
changeset
|
404 } |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
405 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
406 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
407 return false; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
408 } |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
409 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
410 /** |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
411 * Check if a safe position is free. |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
412 * |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
413 * @param v the vehicle to test for |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
414 * @param tile The tile |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
415 * @param trackdir The trackdir to test |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
416 * @param forbid_90deg Don't allow trains to make 90 degree turns |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
417 * @return True if the position is free |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
418 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
419 bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg) |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
420 { |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
421 Track track = TrackdirToTrack(trackdir); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
422 TrackBits reserved = GetReservedTrackbits(tile); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
423 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
424 /* Tile reserved? Can never be a free waiting position. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
425 if (TrackOverlapsTracks(reserved, track)) return false; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
426 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
427 /* Not reserved and depot or not a pbs signal -> free. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
428 if (IsRailDepotTile(tile)) return true; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
429 if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
430 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
431 /* Check the next tile, if it's a PBS signal, it has to be free as well. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
432 CFollowTrackRail ft(v, GetRailTypeInfo(v->railtype)->compatible_railtypes); |
9798
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
433 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
434 if (!ft.Follow(tile, trackdir)) return true; |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
435 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
436 /* Check for reachable tracks. */ |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
437 ft.m_new_td_bits &= DiagdirReachesTrackdirs(ft.m_exitdir); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
438 if (forbid_90deg) ft.m_new_td_bits &= ~TrackdirCrossesTrackdirs(trackdir); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
439 |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
440 return !HasReservedTracks(ft.m_new_tile, TrackdirBitsToTrackBits(ft.m_new_td_bits)); |
ccd88d3e3e23
(svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9787
diff
changeset
|
441 } |