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:
committed by
Peter Nelson
parent
97674ac2a2
commit
4d40966303
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user