-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocation.cpp
More file actions
188 lines (181 loc) · 3.81 KB
/
location.cpp
File metadata and controls
188 lines (181 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "pch.h"
#include "location.h"
#include "util.h"
#include <algorithm>
#include <array>
#include <memory>
#include <utility>
namespace trainlist8::location {
namespace {
constexpr size_t count = 146;
constexpr std::array<std::pair<int32_t, unsigned int>, count> blockIDToLocationStringID{{
{1000, 10065},
{1005, 10068},
{1006, 10070},
{1007, 10068},
{1008, 10070},
{1009, 10068},
{10010, 10068},
{10011, 10040},
{10012, 10068},
{10015, 10069},
{10016, 10072},
{10017, 10069},
{10018, 10072},
{10020, 10018},
{10021, 10018},
{10023, 10001},
{10024, 10003},
{10026, 10003},
{10027, 10001},
{10028, 10001},
{10029, 10003},
{10032, 10082},
{10033, 10082},
{10034, 10082},
{10036, 10000},
{10037, 10005},
{10040, 10002},
{10041, 10004},
{10043, 10056},
{10044, 10056},
{10046, 10022},
{10047, 10023},
{10049, 10057},
{10050, 10057},
{10051, 10057},
{10053, 10047},
{10054, 10048},
{10056, 10059},
{10057, 10059},
{10059, 10079},
{10060, 10080},
{10062, 10053},
{10063, 10053},
{10065, 10077},
{10066, 10078},
{10069, 10037},
{10070, 10038},
{10071, 10011},
{10072, 10012},
{10074, 10058},
{10075, 10058},
{10076, 10058},
{10078, 10041},
{10079, 10036},
{10080, 10036},
{10081, 10041},
{10084, 10035},
{10085, 10043},
{10086, 10035},
{10087, 10043},
{10090, 10042},
{10091, 10030},
{10092, 10034},
{10093, 10034},
{10094, 10034},
{10095, 10042},
{10096, 10042},
{10097, 10029},
{100102, 10032},
{100103, 10040},
{100104, 10040},
{100105, 10032},
{100106, 10039},
{100107, 10040},
{100108, 10032},
{100109, 10032},
{100110, 10031},
{100115, 10034},
{100118, 10068},
{100120, 10042},
{100122, 10013},
{100125, 10033},
{100126, 10019},
{100127, 10017},
{100129, 10081},
{100135, 10015},
{100141, 10070},
{100142, 10070},
{100143, 10070},
{100144, 10070},
{100147, 10067},
{100149, 10044},
{100150, 10014},
{100154, 10074},
{100155, 10074},
{100159, 10046},
{100160, 10051},
{100161, 10016},
{100162, 10066},
{100165, 10045},
{100166, 10049},
{100167, 10066},
{100169, 10061},
{100171, 10061},
{100172, 10061},
{100173, 10024},
{100174, 10050},
{100176, 10063},
{100178, 10054},
{100179, 10055},
{100180, 10063},
{100181, 10063},
{100182, 10052},
{100185, 10052},
{100186, 10020},
{100187, 10021},
{100189, 10062},
{100190, 10062},
{100191, 10062},
{100193, 10062},
{100194, 10028},
{100195, 10027},
{100197, 10065},
{100202, 10064},
{100204, 10025},
{100205, 10026},
{100207, 10065},
{100208, 10065},
{100209, 10065},
{100210, 10065},
{100212, 10007},
{100213, 10006},
{100216, 10067},
{100218, 10071},
{100220, 10064},
{100221, 10060},
{100222, 10060},
{100223, 10060},
{100224, 10060},
{100225, 10070},
{100227, 10076},
{100228, 10073},
{100230, 10008},
{100232, 10010},
{100233, 10009},
{100235, 10075},
}};
static_assert(std::is_sorted(blockIDToLocationStringID.cbegin(), blockIDToLocationStringID.cend()));
// The loaded string resources, in the same order as blockIDToLocationStringID.
constinit std::array<std::unique_ptr<std::wstring>, count> strings;
}
}
// Loads the location name strings.
void trainlist8::location::init(HINSTANCE instance) {
for(size_t i = 0; i != blockIDToLocationStringID.size(); ++i) {
strings[i].reset(new std::wstring(util::loadString(instance, blockIDToLocationStringID[i].second)));
}
}
// Finds the name of a location, if known, or nullptr if not.
const std::wstring *trainlist8::location::nameByBlock(int32_t block) {
auto i = std::lower_bound(blockIDToLocationStringID.cbegin(), blockIDToLocationStringID.cend(), block,
[](const std::pair<int32_t, unsigned int> &candidate, int32_t target) -> bool {
return candidate.first < target;
});
if(i != blockIDToLocationStringID.cend() && i->first == block) {
return strings[i - blockIDToLocationStringID.cbegin()].get();
} else {
return nullptr;
}
}