equal
deleted
inserted
replaced
485 } |
485 } |
486 |
486 |
487 |
487 |
488 bool IsTrainDepotTile(TileIndex tile) |
488 bool IsTrainDepotTile(TileIndex tile) |
489 { |
489 { |
490 return IS_TILETYPE(tile, MP_RAILWAY) && |
490 return IsTileType(tile, MP_RAILWAY) && |
491 (_map5[tile] & 0xFC) == 0xC0; |
491 (_map5[tile] & 0xFC) == 0xC0; |
492 } |
492 } |
493 |
493 |
494 static bool IsTunnelTile(TileIndex tile) |
494 static bool IsTunnelTile(TileIndex tile) |
495 { |
495 { |
496 return IS_TILETYPE(tile, MP_TUNNELBRIDGE) && |
496 return IsTileType(tile, MP_TUNNELBRIDGE) && |
497 (_map5[tile]&0x80) == 0; |
497 (_map5[tile]&0x80) == 0; |
498 } |
498 } |
499 |
499 |
500 |
500 |
501 int CheckStoppedInDepot(Vehicle *v) |
501 int CheckStoppedInDepot(Vehicle *v) |
981 t = (t - 1) & 3; |
981 t = (t - 1) & 3; |
982 } |
982 } |
983 /* Calculate next tile */ |
983 /* Calculate next tile */ |
984 tile += TileOffsByDir(t); |
984 tile += TileOffsByDir(t); |
985 /* Test if we have a rail/road-crossing */ |
985 /* Test if we have a rail/road-crossing */ |
986 if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0)==0x10) { |
986 if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
987 /* Check if there is a train on the tile itself */ |
987 /* Check if there is a train on the tile itself */ |
988 if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) { |
988 if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) { |
989 /* If light is on, switch light off */ |
989 /* If light is on, switch light off */ |
990 if (_map5[tile] & 4) { |
990 if (_map5[tile] & 4) { |
991 _map5[tile] &= ~4; |
991 _map5[tile] &= ~4; |
1117 byte owner; |
1117 byte owner; |
1118 } TrainFindDepotData; |
1118 } TrainFindDepotData; |
1119 |
1119 |
1120 static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int track, uint length, byte *state) |
1120 static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int track, uint length, byte *state) |
1121 { |
1121 { |
1122 if (IS_TILETYPE(tile, MP_RAILWAY) && _map_owner[tile] == tfdd->owner) { |
1122 if (IsTileType(tile, MP_RAILWAY) && _map_owner[tile] == tfdd->owner) { |
1123 if ((_map5[tile] & ~0x3) == 0xC0) { |
1123 if ((_map5[tile] & ~0x3) == 0xC0) { |
1124 if (length < tfdd->best_length) { |
1124 if (length < tfdd->best_length) { |
1125 tfdd->best_length = length; |
1125 tfdd->best_length = length; |
1126 tfdd->tile = tile; |
1126 tfdd->tile = tile; |
1127 } |
1127 } |
1355 uint best_track_dist; |
1355 uint best_track_dist; |
1356 byte best_track; |
1356 byte best_track; |
1357 } TrainTrackFollowerData; |
1357 } TrainTrackFollowerData; |
1358 |
1358 |
1359 static bool TrainTrackFollower(uint tile, TrainTrackFollowerData *ttfd, int track, uint length, byte *state){ |
1359 static bool TrainTrackFollower(uint tile, TrainTrackFollowerData *ttfd, int track, uint length, byte *state){ |
1360 if (IS_TILETYPE(tile, MP_RAILWAY) && (_map5[tile]&0xC0) == 0x40) { |
1360 if (IsTileType(tile, MP_RAILWAY) && (_map5[tile]&0xC0) == 0x40) { |
1361 // the tile has a signal |
1361 // the tile has a signal |
1362 byte m3 = _map3_lo[tile]; |
1362 byte m3 = _map3_lo[tile]; |
1363 if (!(m3 & _signal_onedir[track])) { |
1363 if (!(m3 & _signal_onedir[track])) { |
1364 // if one way signal not pointing towards us, stop going in this direction. |
1364 // if one way signal not pointing towards us, stop going in this direction. |
1365 if (m3 & _signal_otherdir[track]) |
1365 if (m3 & _signal_otherdir[track]) |
1378 if (ttfd->dest_coords == 0) |
1378 if (ttfd->dest_coords == 0) |
1379 return false; |
1379 return false; |
1380 |
1380 |
1381 // did we reach the final station? |
1381 // did we reach the final station? |
1382 if ((ttfd->station_index == -1 && tile == ttfd->dest_coords) || |
1382 if ((ttfd->station_index == -1 && tile == ttfd->dest_coords) || |
1383 (IS_TILETYPE(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8) && _map2[tile] == ttfd->station_index)) { |
1383 (IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8) && _map2[tile] == ttfd->station_index)) { |
1384 /* We do not check for dest_coords if we have a station_index, |
1384 /* We do not check for dest_coords if we have a station_index, |
1385 * because in that case the dest_coords are just an |
1385 * because in that case the dest_coords are just an |
1386 * approximation of where the station is */ |
1386 * approximation of where the station is */ |
1387 // found station |
1387 // found station |
1388 ttfd->best_bird_dist = 0; |
1388 ttfd->best_bird_dist = 0; |
1893 } |
1893 } |
1894 |
1894 |
1895 /* Check if the vehicle is compatible with the specified tile */ |
1895 /* Check if the vehicle is compatible with the specified tile */ |
1896 static bool CheckCompatibleRail(Vehicle *v, uint tile) |
1896 static bool CheckCompatibleRail(Vehicle *v, uint tile) |
1897 { |
1897 { |
1898 if (IS_TILETYPE(tile, MP_RAILWAY) || IS_TILETYPE(tile, MP_STATION)) { |
1898 if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION)) { |
1899 // normal tracks, jump to owner check |
1899 // normal tracks, jump to owner check |
1900 } else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
1900 } else if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
1901 if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part? |
1901 if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part? |
1902 TileInfo ti; |
1902 TileInfo ti; |
1903 FindLandscapeHeightByTile(&ti, tile); |
1903 FindLandscapeHeightByTile(&ti, tile); |
1904 |
1904 |
1905 // correct Z position of a train going under a bridge on slopes |
1905 // correct Z position of a train going under a bridge on slopes |
1907 ti.z += 8; |
1907 ti.z += 8; |
1908 |
1908 |
1909 if(v->z_pos != ti.z) // train is going over bridge |
1909 if(v->z_pos != ti.z) // train is going over bridge |
1910 return true; |
1910 return true; |
1911 } |
1911 } |
1912 } else if (IS_TILETYPE(tile, MP_STREET)) { // train is going over a road-crossing |
1912 } else if (IsTileType(tile, MP_STREET)) { // train is going over a road-crossing |
1913 // tracks over roads, do owner check of tracks (_map_owner[tile]) |
1913 // tracks over roads, do owner check of tracks (_map_owner[tile]) |
1914 if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype)) |
1914 if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype)) |
1915 return false; |
1915 return false; |
1916 |
1916 |
1917 return true; |
1917 return true; |
1975 }; |
1975 }; |
1976 |
1976 |
1977 static void TrainMovedChangeSignals(uint tile, int dir) |
1977 static void TrainMovedChangeSignals(uint tile, int dir) |
1978 { |
1978 { |
1979 int i; |
1979 int i; |
1980 if (IS_TILETYPE(tile, MP_RAILWAY) && (_map5[tile]&0xC0)==0x40) { |
1980 if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) { |
1981 i = FindFirstBit2x64((_map5[tile]+(_map5[tile]<<8)) & _reachable_tracks[dir]); |
1981 i = FindFirstBit2x64((_map5[tile]+(_map5[tile]<<8)) & _reachable_tracks[dir]); |
1982 UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]); |
1982 UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]); |
1983 } |
1983 } |
1984 } |
1984 } |
1985 |
1985 |
2213 } |
2213 } |
2214 } else { |
2214 } else { |
2215 /* in tunnel */ |
2215 /* in tunnel */ |
2216 GetNewVehiclePos(v, &gp); |
2216 GetNewVehiclePos(v, &gp); |
2217 |
2217 |
2218 if (IS_TILETYPE(gp.new_tile, MP_TUNNELBRIDGE) && |
2218 if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && |
2219 !(_map5[gp.new_tile] & 0xF0)) { |
2219 !(_map5[gp.new_tile] & 0xF0)) { |
2220 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
2220 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
2221 if (r & 0x4) goto common; |
2221 if (r & 0x4) goto common; |
2222 } |
2222 } |
2223 |
2223 |
2441 return true; |
2441 return true; |
2442 |
2442 |
2443 tile = v->tile; |
2443 tile = v->tile; |
2444 |
2444 |
2445 // tunnel entrance? |
2445 // tunnel entrance? |
2446 if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && |
2446 if (IsTileType(tile, MP_TUNNELBRIDGE) && |
2447 (_map5[tile] & 0xF0) == 0 && (byte)((_map5[tile] & 3)*2+1) == v->direction) |
2447 (_map5[tile] & 0xF0) == 0 && (byte)((_map5[tile] & 3)*2+1) == v->direction) |
2448 return true; |
2448 return true; |
2449 |
2449 |
2450 // depot? |
2450 // depot? |
2451 /* XXX -- When enabled, this makes it possible to crash trains of others |
2451 /* XXX -- When enabled, this makes it possible to crash trains of others |
2452 (by building a depot right against a station) */ |
2452 (by building a depot right against a station) */ |
2453 /* if (IS_TILETYPE(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0) |
2453 /* if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0) |
2454 return true;*/ |
2454 return true;*/ |
2455 |
2455 |
2456 /* Determine the non-diagonal direction in which we will exit this tile */ |
2456 /* Determine the non-diagonal direction in which we will exit this tile */ |
2457 t = v->direction >> 1; |
2457 t = v->direction >> 1; |
2458 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[t]) { |
2458 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[t]) { |
2498 ReverseTrainDirection(v); |
2498 ReverseTrainDirection(v); |
2499 return false; |
2499 return false; |
2500 } |
2500 } |
2501 if ((ts &= (ts >> 16)) == 0) { |
2501 if ((ts &= (ts >> 16)) == 0) { |
2502 // make a rail/road crossing red |
2502 // make a rail/road crossing red |
2503 if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0)==0x10) { |
2503 if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
2504 if (!(_map5[tile] & 4)) { |
2504 if (!(_map5[tile] & 4)) { |
2505 _map5[tile] |= 4; |
2505 _map5[tile] |= 4; |
2506 SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
2506 SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
2507 MarkTileDirtyByTile(tile); |
2507 MarkTileDirtyByTile(tile); |
2508 } |
2508 } |