1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codechange: Use FlatSet to store and test alternate rail/road types.

This commit is contained in:
Peter Nelson
2025-09-07 14:13:57 +01:00
committed by Peter Nelson
parent 97674ac2a2
commit 4d40966303
6 changed files with 8 additions and 8 deletions

View File

@@ -204,7 +204,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint first, uint last, int prop, Byt
if (type_map[id] != INVALID_RAILTYPE) {
int n = buf.ReadByte();
for (int j = 0; j != n; j++) {
_railtypes[type_map[id]].alternate_labels.push_back(std::byteswap(buf.ReadDWord()));
_railtypes[type_map[id]].alternate_labels.insert(std::byteswap(buf.ReadDWord()));
}
break;
}

View File

@@ -192,7 +192,7 @@ static ChangeInfoResult RoadTypeReserveInfo(uint first, uint last, int prop, Byt
if (type_map[id] != INVALID_ROADTYPE) {
int n = buf.ReadByte();
for (int j = 0; j != n; j++) {
_roadtypes[type_map[id]].alternate_labels.push_back(std::byteswap(buf.ReadDWord()));
_roadtypes[type_map[id]].alternate_labels.insert(std::byteswap(buf.ReadDWord()));
}
break;
}

View File

@@ -205,8 +205,7 @@ RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
if (allow_alternate_labels) {
/* Test if any rail type defines the label as an alternate. */
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
const RailTypeInfo *rti = GetRailTypeInfo(r);
if (std::ranges::find(rti->alternate_labels, label) != rti->alternate_labels.end()) return r;
if (GetRailTypeInfo(r)->alternate_labels.contains(label)) return r;
}
}

View File

@@ -15,6 +15,7 @@
#include "gfx_type.h"
#include "core/bitmath_func.hpp"
#include "core/enum_type.hpp"
#include "core/flatset_type.hpp"
#include "economy_func.h"
#include "slope_type.h"
#include "strings_type.h"
@@ -227,7 +228,7 @@ public:
/**
* Rail type labels this type provides in addition to the main label.
*/
std::vector<RailTypeLabel> alternate_labels;
FlatSet<RailTypeLabel> alternate_labels;
/**
* Colour on mini-map

View File

@@ -275,8 +275,7 @@ RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels)
if (allow_alternate_labels) {
/* Test if any road type defines the label as an alternate. */
for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) {
const RoadTypeInfo *rti = GetRoadTypeInfo(r);
if (std::ranges::find(rti->alternate_labels, label) != rti->alternate_labels.end()) return r;
if (GetRoadTypeInfo(r)->alternate_labels.contains(label)) return r;
}
}

View File

@@ -13,6 +13,7 @@
#include "road_type.h"
#include "gfx_type.h"
#include "core/bitmath_func.hpp"
#include "core/flatset_type.hpp"
#include "strings_type.h"
#include "timer/timer_game_calendar.h"
#include "core/enum_type.hpp"
@@ -137,7 +138,7 @@ public:
/**
* Road type labels this type provides in addition to the main label.
*/
std::vector<RoadTypeLabel> alternate_labels;
FlatSet<RoadTypeLabel> alternate_labels;
/**
* Colour on mini-map