Codechange: Iterate road/tram masks instead of checking each type. (#14716)

This commit is contained in:
Peter Nelson
2025-10-23 20:59:58 +01:00
committed by dP
parent a2b897592b
commit 427ba3bfd3
5 changed files with 27 additions and 41 deletions

View File

@@ -1134,14 +1134,9 @@ RoadType GetTownRoadType()
const RoadTypeInfo *best = nullptr;
const uint16_t assume_max_speed = 50;
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (RoadTypeIsTram(rt)) continue;
for (RoadType rt : GetMaskForRoadTramType(RTT_ROAD)) {
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
/* Unused road type. */
if (rti->label == 0) continue;
/* Can town build this road. */
if (!rti->flags.Test(RoadTypeFlag::TownBuild)) continue;
@@ -1166,10 +1161,9 @@ RoadType GetTownRoadType()
static TimerGameCalendar::Date GetTownRoadTypeFirstIntroductionDate()
{
const RoadTypeInfo *best = nullptr;
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (RoadTypeIsTram(rt)) continue;
for (RoadType rt : GetMaskForRoadTramType(RTT_ROAD)) {
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
if (rti->label == 0) continue; // Unused road type.
if (!rti->flags.Test(RoadTypeFlag::TownBuild)) continue; // Town can't build this road type.
if (best != nullptr && rti->introduction_date >= best->introduction_date) continue;