1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-29 07:04:35 +01:00

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 GitHub
parent 8e8eebd785
commit 5c89dff677
5 changed files with 27 additions and 41 deletions

View File

@@ -965,14 +965,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;
@@ -997,10 +992,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;