6 #include "openttd.h" |
6 #include "openttd.h" |
7 #include "bridge_map.h" |
7 #include "bridge_map.h" |
8 #include "rail.h" |
8 #include "rail.h" |
9 #include "station_map.h" |
9 #include "station_map.h" |
10 #include "tunnel_map.h" |
10 #include "tunnel_map.h" |
|
11 #include "tunnelbridge_map.h" |
|
12 #include "settings_type.h" |
|
13 #include "date_func.h" |
|
14 #include "player_func.h" |
|
15 #include "player_base.h" |
|
16 |
11 |
17 |
12 /* XXX: Below 3 tables store duplicate data. Maybe remove some? */ |
18 /* XXX: Below 3 tables store duplicate data. Maybe remove some? */ |
13 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
19 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
14 * direction along with the trackdir */ |
20 * direction along with the trackdir */ |
15 extern const byte _signal_along_trackdir[] = { |
21 extern const byte _signal_along_trackdir[TRACKDIR_END] = { |
16 0x8, 0x8, 0x8, 0x2, 0x4, 0x1, 0, 0, |
22 0x8, 0x8, 0x8, 0x2, 0x4, 0x1, 0, 0, |
17 0x4, 0x4, 0x4, 0x1, 0x8, 0x2 |
23 0x4, 0x4, 0x4, 0x1, 0x8, 0x2 |
18 }; |
24 }; |
19 |
25 |
20 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
26 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
21 * direction against the trackdir */ |
27 * direction against the trackdir */ |
22 extern const byte _signal_against_trackdir[] = { |
28 extern const byte _signal_against_trackdir[TRACKDIR_END] = { |
23 0x4, 0x4, 0x4, 0x1, 0x8, 0x2, 0, 0, |
29 0x4, 0x4, 0x4, 0x1, 0x8, 0x2, 0, 0, |
24 0x8, 0x8, 0x8, 0x2, 0x4, 0x1 |
30 0x8, 0x8, 0x8, 0x2, 0x4, 0x1 |
25 }; |
31 }; |
26 |
32 |
27 /* Maps a Track to the bits that store the status of the two signals that can |
33 /* Maps a Track to the bits that store the status of the two signals that can |
38 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ |
44 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ |
39 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ |
45 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ |
40 TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ |
46 TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ |
41 }; |
47 }; |
42 |
48 |
43 extern const Trackdir _next_trackdir[] = { |
49 extern const Trackdir _next_trackdir[TRACKDIR_END] = { |
44 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, |
50 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, |
45 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N |
51 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N |
46 }; |
52 }; |
47 |
53 |
48 /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ |
54 /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ |
49 extern const TrackdirBits _track_crosses_trackdirs[] = { |
55 extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END] = { |
50 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ |
56 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ |
51 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ |
57 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ |
52 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ |
58 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ |
53 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ |
59 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ |
54 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ |
60 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ |
65 TRACK_BIT_HORZ /* TRACK_RIGHT */ |
71 TRACK_BIT_HORZ /* TRACK_RIGHT */ |
66 }; |
72 }; |
67 |
73 |
68 /* Maps a trackdir to the (4-way) direction the tile is exited when following |
74 /* Maps a trackdir to the (4-way) direction the tile is exited when following |
69 * that trackdir */ |
75 * that trackdir */ |
70 extern const DiagDirection _trackdir_to_exitdir[] = { |
76 extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END] = { |
71 DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_NE, |
77 DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_NE, |
72 DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, |
78 DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, |
73 }; |
79 }; |
74 |
80 |
75 extern const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = { |
81 extern const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = { |
128 case MP_STATION: |
134 case MP_STATION: |
129 if (IsRailwayStationTile(tile)) return GetRailType(tile); |
135 if (IsRailwayStationTile(tile)) return GetRailType(tile); |
130 break; |
136 break; |
131 |
137 |
132 case MP_TUNNELBRIDGE: |
138 case MP_TUNNELBRIDGE: |
133 if (IsTunnel(tile)) { |
139 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile); |
134 if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile); |
|
135 } else { |
|
136 if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile); |
|
137 } |
|
138 break; |
140 break; |
139 |
141 |
140 default: |
142 default: |
141 break; |
143 break; |
142 } |
144 } |
143 return INVALID_RAILTYPE; |
145 return INVALID_RAILTYPE; |
144 } |
146 } |
|
147 |
|
148 bool HasRailtypeAvail(const PlayerID p, const RailType railtype) |
|
149 { |
|
150 return HasBit(GetPlayer(p)->avail_railtypes, railtype); |
|
151 } |
|
152 |
|
153 bool ValParamRailtype(const RailType rail) |
|
154 { |
|
155 return HasRailtypeAvail(_current_player, rail); |
|
156 } |
|
157 |
|
158 RailType GetBestRailtype(const PlayerID p) |
|
159 { |
|
160 if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV; |
|
161 if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO; |
|
162 if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC; |
|
163 return RAILTYPE_RAIL; |
|
164 } |
|
165 |
|
166 RailTypes GetPlayerRailtypes(PlayerID p) |
|
167 { |
|
168 RailTypes rt = RAILTYPES_NONE; |
|
169 |
|
170 for (EngineID i = 0; i != TOTAL_NUM_ENGINES; i++) { |
|
171 const Engine* e = GetEngine(i); |
|
172 const EngineInfo *ei = EngInfo(i); |
|
173 |
|
174 if (e->type == VEH_TRAIN && HasBit(ei->climates, _opt.landscape) && |
|
175 (HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) { |
|
176 const RailVehicleInfo *rvi = RailVehInfo(i); |
|
177 |
|
178 if (rvi->railveh_type != RAILVEH_WAGON) { |
|
179 assert(rvi->railtype < RAILTYPE_END); |
|
180 SetBit(rt, rvi->railtype); |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 return rt; |
|
186 } |