| 1710 | } |
| 1711 | |
| 1712 | void City::fillRoadSegmentMap(GameState &state [[maybe_unused]]) |
| 1713 | { |
| 1714 | LogWarning("Begun filling road segment map"); |
| 1715 | // Expecting this to be done on clean intact map |
| 1716 | tileToRoadSegmentMap.clear(); |
| 1717 | roadSegments.clear(); |
| 1718 | auto &m = *map; |
| 1719 | auto helper = GroundVehicleTileHelper{m, VehicleType::Type::Road}; |
| 1720 | |
| 1721 | // -2 means not processed, -1 means no road, otherwise segment index |
| 1722 | tileToRoadSegmentMap.resize(m.size.x * m.size.y * m.size.z, -2); |
| 1723 | |
| 1724 | // [First Loop] |
| 1725 | // Try every tile on the map as new segment |
| 1726 | // - on first pass only try terminals |
| 1727 | // - on second pass only try crossings |
| 1728 | // - on third pass try anything |
| 1729 | Vec3<int> tileToTryNext; |
| 1730 | int nextSegmentToProcess = 0; |
| 1731 | int currentPass = 0; |
| 1732 | while (currentPass++ < 3) |
| 1733 | { |
| 1734 | for (tileToTryNext.x = 0; tileToTryNext.x < m.size.x; tileToTryNext.x++) |
| 1735 | { |
| 1736 | for (tileToTryNext.y = 0; tileToTryNext.y < m.size.y; tileToTryNext.y++) |
| 1737 | { |
| 1738 | for (tileToTryNext.z = 0; tileToTryNext.z < m.size.z; tileToTryNext.z++) |
| 1739 | { |
| 1740 | // Already processed |
| 1741 | if (tileToRoadSegmentMap[tileToTryNext.z * map->size.x * map->size.y + |
| 1742 | tileToTryNext.y * map->size.x + tileToTryNext.x] != -2) |
| 1743 | { |
| 1744 | continue; |
| 1745 | } |
| 1746 | // Get data |
| 1747 | auto tile = m.getTile(tileToTryNext); |
| 1748 | auto scenery = tile->presentScenery ? tile->presentScenery->type : nullptr; |
| 1749 | // Not a road |
| 1750 | if (!scenery || scenery->tile_type != SceneryTileType::TileType::Road) |
| 1751 | { |
| 1752 | tileToRoadSegmentMap[tileToTryNext.z * map->size.x * map->size.y + |
| 1753 | tileToTryNext.y * map->size.x + tileToTryNext.x] = -1; |
| 1754 | continue; |
| 1755 | } |
| 1756 | // Not fit for this pass |
| 1757 | switch (currentPass) |
| 1758 | { |
| 1759 | // First pass only terminals |
| 1760 | case 1: |
| 1761 | if (scenery->road_type != SceneryTileType::RoadType::Terminal) |
| 1762 | { |
| 1763 | continue; |
| 1764 | } |
| 1765 | break; |
| 1766 | // Second pass only junctions |
| 1767 | case 2: |
| 1768 | if (scenery->road_type != SceneryTileType::RoadType::Junction) |
| 1769 | { |
no test coverage detected