274 } |
274 } |
275 tile = SkipToEndOfTunnel(tpf, tile, direction); |
275 tile = SkipToEndOfTunnel(tpf, tile, direction); |
276 } |
276 } |
277 tile += TileOffsByDiagDir(direction); |
277 tile += TileOffsByDiagDir(direction); |
278 |
278 |
279 /* check if the new tile can be entered from that direction */ |
279 /* Check in case of rail if the owner is the same */ |
280 /* Inside this block we should not use 'return' to indicate 'no way' condition (at least for rail transport type) */ |
280 if (tpf->tracktype == TRANSPORT_RAIL) { |
281 if (tpf->tracktype == TRANSPORT_ROAD || tpf->tracktype == TRANSPORT_RAIL) { |
281 // don't enter train depot from the back |
282 if (tpf->tracktype == TRANSPORT_RAIL) { |
282 if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) return; |
283 /* don't enter train depot from the back */ |
283 |
284 if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) goto no_way; |
284 if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE)) |
285 |
285 if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) |
286 /* Check in case of rail if the owner is the same */ |
286 /* Check if we are on a bridge (middle parts don't have an owner */ |
287 if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE)) |
287 if (!IsBridgeTile(tile) || !IsBridgeMiddle(tile)) |
288 if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) |
288 if (!IsBridgeTile(tile_org) || !IsBridgeMiddle(tile_org)) |
289 /* Check if we are on a bridge (middle parts don't have an owner */ |
289 if (GetTileOwner(tile_org) != GetTileOwner(tile)) |
290 if (!IsBridgeTile(tile) || !IsBridgeMiddle(tile)) |
290 return; |
291 if (!IsBridgeTile(tile_org) || !IsBridgeMiddle(tile_org)) |
291 } |
292 if (GetTileOwner(tile_org) != GetTileOwner(tile)) goto no_way; |
292 |
293 |
293 // check if the new tile can be entered from that direction |
294 } else if (tpf->tracktype == TRANSPORT_ROAD) { |
294 if (tpf->tracktype == TRANSPORT_ROAD) { |
295 /* road stops and depots now have a track (r4419) */ |
295 // road stops and depots now have a track (r4419) |
296 /* don't enter road stop from the back */ |
296 // don't enter road stop from the back |
297 if (IsRoadStopTile(tile) && ReverseDiagDir(GetRoadStopDir(tile)) != direction) goto no_way; |
297 if (IsRoadStopTile(tile) && ReverseDiagDir(GetRoadStopDir(tile)) != direction) return; |
298 /* don't enter road depot from the back */ |
298 // don't enter road depot from the back |
299 if (IsTileDepotType(tile, TRANSPORT_ROAD) && ReverseDiagDir(GetRoadDepotDirection(tile)) != direction) goto no_way; |
299 if (IsTileDepotType(tile, TRANSPORT_ROAD) && ReverseDiagDir(GetRoadDepotDirection(tile)) != direction) return; |
300 } |
300 } |
301 |
301 |
302 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
302 /* Check if the new tile is a tunnel or bridge head and that the direction |
303 if (IsTunnel(tile)) { |
303 * and transport type match */ |
304 /* tunnel hole can be entered only from one direction */ |
304 if (IsTileType(tile, MP_TUNNELBRIDGE) && IsTunnel(tile)) { |
305 if (GetTunnelDirection(tile) != direction) goto no_way; |
305 if (GetTunnelDirection(tile) != direction || |
306 } |
306 GetTunnelTransportType(tile) != tpf->tracktype) { |
307 } |
307 return; |
308 if (tpf->tracktype == TRANSPORT_RAIL) { |
308 } |
309 /* check for the rail type compatibility */ |
309 } |
310 Trackdir td = DiagdirToDiagTrackdir(direction); |
310 |
311 RailType type_org = GetTileRailType(tile_org, td); |
311 tpf->rd.cur_length++; |
312 RailType type = GetTileRailType(tile, td); |
312 |
313 if (type != type_org) { |
|
314 // they can be compatible only if one is normal and the other one is elrail |
|
315 if (type_org == RAILTYPE_RAIL && type != RAILTYPE_ELECTRIC) goto no_way; |
|
316 if (type == RAILTYPE_RAIL && type_org != RAILTYPE_ELECTRIC) goto no_way; |
|
317 } |
|
318 } |
|
319 } |
|
320 |
|
321 /* the next line is skipped when the new tile can't be entered from tile_org */ |
|
322 bits = GetTileTrackStatus(tile, tpf->tracktype); |
313 bits = GetTileTrackStatus(tile, tpf->tracktype); |
323 no_way: |
|
324 |
|
325 tpf->rd.cur_length++; |
|
326 |
314 |
327 if ((byte)bits != tpf->var2) { |
315 if ((byte)bits != tpf->var2) { |
328 bits &= _tpfmode1_and[direction]; |
316 bits &= _tpfmode1_and[direction]; |
329 bits = bits | (bits>>8); |
317 bits = bits | (bits>>8); |
330 } |
318 } |