* Get the road type that towns should build at this current moment. * They may have built a different type in the past. */
| 963 | * They may have built a different type in the past. |
| 964 | */ |
| 965 | RoadType GetTownRoadType() |
| 966 | { |
| 967 | RoadType best_rt = ROADTYPE_ROAD; |
| 968 | const RoadTypeInfo *best = nullptr; |
| 969 | const uint16_t assume_max_speed = 50; |
| 970 | |
| 971 | for (RoadType rt : GetMaskForRoadTramType(RTT_ROAD)) { |
| 972 | const RoadTypeInfo *rti = GetRoadTypeInfo(rt); |
| 973 | |
| 974 | /* Can town build this road. */ |
| 975 | if (!rti->flags.Test(RoadTypeFlag::TownBuild)) continue; |
| 976 | |
| 977 | /* Not yet introduced at this date. */ |
| 978 | if (IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base()) && rti->introduction_date > TimerGameCalendar::date) continue; |
| 979 | |
| 980 | if (best != nullptr) { |
| 981 | if ((rti->max_speed == 0 ? assume_max_speed : rti->max_speed) < (best->max_speed == 0 ? assume_max_speed : best->max_speed)) continue; |
| 982 | } |
| 983 | |
| 984 | best_rt = rt; |
| 985 | best = rti; |
| 986 | } |
| 987 | |
| 988 | return best_rt; |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Get the calendar date of the earliest town-buildable road type. |
no test coverage detected