MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AllocateRailType

Function AllocateRailType

src/rail_cmd.cpp:148–177  ·  view source on GitHub ↗

* Allocate a new rail type label */

Source from the content-addressed store, hash-verified

146 * Allocate a new rail type label
147 */
148RailType AllocateRailType(RailTypeLabel label)
149{
150 auto it = std::ranges::find(_railtypes, 0, &RailTypeInfo::label);
151 if (it == std::end(_railtypes)) return INVALID_RAILTYPE;
152
153 RailTypeInfo &rti = *it;
154 RailType rt = rti.Index();
155
156 /* Set up new rail type based on default rail. */
157 rti = _original_railtypes[RAILTYPE_RAIL];
158 rti.label = label;
159 rti.alternate_labels.clear();
160
161 /* Make us compatible with ourself. */
162 rti.powered_railtypes = rt;
163 rti.compatible_railtypes = rt;
164
165 /* We also introduce ourself. */
166 rti.introduces_railtypes = rt;
167
168 /* Default sort order; order of allocation, but with some
169 * offsets so it's easier for NewGRF to pick a spot without
170 * changing the order of other (original) rail types.
171 * The << is so you can place other railtypes in between the
172 * other railtypes, the 7 is to be able to place something
173 * before the first (default) rail type. */
174 rti.sorting_order = rt << 4 | 7;
175
176 return rt;
177}
178
179static const uint8_t _track_sloped_sprites[14] = {
180 14, 15, 22, 13,

Callers 1

RailTypeReserveInfoFunction · 0.85

Calls 4

findFunction · 0.50
endFunction · 0.50
IndexMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected