* Tries to change owner of this rail tile to a valid owner. In very old versions it could happen that * a rail track had an invalid owner. When conversion isn't possible, track is removed. * @param t tile to update */
| 416 | * @param t tile to update |
| 417 | */ |
| 418 | static void FixOwnerOfRailTrack(Tile t) |
| 419 | { |
| 420 | assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t))); |
| 421 | |
| 422 | /* remove leftover rail piece from crossing (from very old savegames) */ |
| 423 | Train *v = nullptr; |
| 424 | for (Train *w : Train::Iterate()) { |
| 425 | if (w->tile == TileIndex(t)) { |
| 426 | v = w; |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | if (v != nullptr) { |
| 432 | /* when there is a train on crossing (it could happen in TTD), set owner of crossing to train owner */ |
| 433 | SetTileOwner(t, v->owner); |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | /* try to find any connected rail */ |
| 438 | for (DiagDirection dd = DIAGDIR_BEGIN; dd < DIAGDIR_END; dd++) { |
| 439 | TileIndex tt{t + TileOffsByDiagDir(dd)}; |
| 440 | if (GetTileTrackStatus(t, TRANSPORT_RAIL, 0, dd) != 0 && |
| 441 | GetTileTrackStatus(tt, TRANSPORT_RAIL, 0, ReverseDiagDir(dd)) != 0 && |
| 442 | Company::IsValidID(GetTileOwner(tt))) { |
| 443 | SetTileOwner(t, GetTileOwner(tt)); |
| 444 | return; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if (IsLevelCrossingTile(t)) { |
| 449 | /* else change the crossing to normal road (road vehicles won't care) */ |
| 450 | Owner road = GetRoadOwner(t, RTT_ROAD); |
| 451 | Owner tram = GetRoadOwner(t, RTT_TRAM); |
| 452 | RoadBits bits = GetCrossingRoadBits(t); |
| 453 | bool hasroad = HasBit(t.m7(), 6); |
| 454 | bool hastram = HasBit(t.m7(), 7); |
| 455 | |
| 456 | /* MakeRoadNormal */ |
| 457 | SetTileType(t, MP_ROAD); |
| 458 | SetTileOwner(t, road); |
| 459 | t.m3() = (hasroad ? bits : 0); |
| 460 | t.m5() = (hastram ? bits : 0) | to_underlying(RoadTileType::Normal) << 6; |
| 461 | SB(t.m6(), 2, 4, 0); |
| 462 | SetRoadOwner(t, RTT_TRAM, tram); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | /* if it's not a crossing, make it clean land */ |
| 467 | MakeClear(t, CLEAR_GRASS, 0); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Fixes inclination of a vehicle. Older OpenTTD versions didn't update the bits correctly. |
no test coverage detected