OpenTTD Source 20260531-master-g0e951f3528
elrail_data.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
12
13#ifndef ELRAIL_DATA_H
14#define ELRAIL_DATA_H
15
20enum TileLocationGroup : uint8_t {
21 XEVEN_YEVEN = 0,
22 XEVEN_YODD = 1,
23 XODD_YEVEN = 2,
24 XODD_YODD = 3,
25 TLG_END
26};
27
33enum class TileSource : uint8_t {
37};
38
39static const uint NUM_TRACKS_AT_PCP = 6;
40
48
60
70
115
116#define NUM_IGNORE_GROUPS 3
122static const DiagDirectionIndexArray<Directions> _ignored_pcp[NUM_IGNORE_GROUPS][TLG_END] = {
123 { // Ignore group 1, X and Y tracks
124 {{{ // X even, Y even
129 }}},
130 {{{ // X even, Y odd
135 }}},
136 {{{ // X odd, Y even
141 }}},
142 {{{ // X odd, Y odd
147 }}},
148 },
149 { // Ignore group 2, LEFT and RIGHT tracks
150 {{{
155 }}},
156 {{{
161 }}},
162 {{{
167 }}},
168 {{{
173 }}},
174 },
175 { // Ignore group 3, UPPER and LOWER tracks
176 {{{
181 }}},
182 {{{
187 }}},
188 {{{
193 }}},
194 {{{
199 }}},
200 }
201};
202
212
220
228
231 {{ // PCP 0
236 }},
237 {{ // PCP 1
242 }},
243 {{ // PCP 2
248 }},
249 {{ // PCP 3
254 }},
255}}};
256
264static const DirectionIndexArray<int8_t> _x_ppp_offsets{-2, -4, -2, 0, 2, 4, 2, 0};
265static const DirectionIndexArray<int8_t> _y_ppp_offsets{-2, 0, 2, 4, 2, 0, -2, -4};
267
271enum PylonSpriteOffset : uint8_t {
272 PSO_Y_NE,
273 PSO_Y_SW,
274 PSO_X_NW,
275 PSO_X_SE,
276 PSO_EW_N,
277 PSO_EW_S,
278 PSO_NS_W,
279 PSO_NS_E,
280};
281
284 PSO_EW_N,
285 PSO_Y_NE,
286 PSO_NS_E,
287 PSO_X_SE,
288 PSO_EW_S,
289 PSO_Y_SW,
290 PSO_NS_W,
291 PSO_X_NW,
292};
293
297enum WireSpriteOffset : uint8_t {
298 WSO_X_SHORT,
299 WSO_Y_SHORT,
300 WSO_EW_SHORT,
301 WSO_NS_SHORT,
302 WSO_X_SHORT_DOWN,
303 WSO_Y_SHORT_UP,
304 WSO_X_SHORT_UP,
305 WSO_Y_SHORT_DOWN,
306
307 WSO_X_SW,
308 WSO_Y_SE,
309 WSO_EW_E,
310 WSO_NS_S,
311 WSO_X_SW_DOWN,
312 WSO_Y_SE_UP,
313 WSO_X_SW_UP,
314 WSO_Y_SE_DOWN,
315
316 WSO_X_NE,
317 WSO_Y_NW,
318 WSO_EW_W,
319 WSO_NS_N,
320 WSO_X_NE_DOWN,
321 WSO_Y_NW_UP,
322 WSO_X_NE_UP,
323 WSO_Y_NW_DOWN,
324
325 WSO_ENTRANCE_SW,
326 WSO_ENTRANCE_NW,
327 WSO_ENTRANCE_NE,
328 WSO_ENTRANCE_SE,
329};
330
331struct SortableSpriteStruct : SpriteBounds {
332 uint8_t image_offset;
333
334 constexpr SortableSpriteStruct(uint8_t image_offset, const SpriteBounds &bounds) : SpriteBounds(bounds), image_offset(image_offset) {}
335 constexpr SortableSpriteStruct(uint8_t image_offset, int8_t x_offset, int8_t y_offset, uint8_t x_size, uint8_t y_size, uint8_t z_size, int8_t z_offset) :
336 SpriteBounds({x_offset, y_offset, z_offset}, {x_size, y_size, z_size}, {}), image_offset(image_offset) {}
337};
338
340static const uint ELRAIL_ELEVATION = 10;
344static const uint ELRAIL_ELEVLOWER = ELRAIL_ELEVATION - 1;
345
346static const SortableSpriteStruct _rail_catenary_sprite_data[] = {
347/* X direction
348 * Flat tiles:
349 * Wires */
350 { WSO_X_SW, 0, 7, 15, 1, 1, ELRAIL_ELEVATION },
351 { WSO_X_NE, 0, 7, 15, 1, 1, ELRAIL_ELEVATION },
352 { WSO_X_SHORT, 0, 7, 15, 1, 1, ELRAIL_ELEVATION },
353
354 /* "up" tiles
355 * Wires */
356 { WSO_X_SW_UP, 0, 7, 15, 8, 1, ELRAIL_ELEVRAISE },
357 { WSO_X_NE_UP, 0, 7, 15, 8, 1, ELRAIL_ELEVRAISE },
358 { WSO_X_SHORT_UP, 0, 7, 15, 8, 1, ELRAIL_ELEVRAISE },
359
360 /* "down" tiles
361 * Wires */
362 { WSO_X_SW_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER },
363 { WSO_X_NE_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER },
364 { WSO_X_SHORT_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER },
365
366
367/* Y direction
368 * Flat tiles:
369 * Wires */
370 { WSO_Y_SE, 7, 0, 1, 15, 1, ELRAIL_ELEVATION },
371 { WSO_Y_NW, 7, 0, 1, 15, 1, ELRAIL_ELEVATION },
372 { WSO_Y_SHORT, 7, 0, 1, 15, 1, ELRAIL_ELEVATION },
373
374 /* "up" tiles
375 * Wires */
376 { WSO_Y_SE_UP, 7, 0, 8, 15, 1, ELRAIL_ELEVRAISE },
377 { WSO_Y_NW_UP, 7, 0, 8, 15, 1, ELRAIL_ELEVRAISE },
378 { WSO_Y_SHORT_UP, 7, 0, 8, 15, 1, ELRAIL_ELEVRAISE },
379
380 /* "down" tiles
381 * Wires */
382 { WSO_Y_SE_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER },
383 { WSO_Y_NW_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER },
384 { WSO_Y_SHORT_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER },
385
386/* NS Direction */
387 { WSO_NS_SHORT, 8, 0, 8, 8, 1, ELRAIL_ELEVATION },
388 { WSO_NS_SHORT, 0, 8, 8, 8, 1, ELRAIL_ELEVATION },
389
390 { WSO_NS_N, 8, 0, 8, 8, 1, ELRAIL_ELEVATION },
391 { WSO_NS_N, 0, 8, 8, 8, 1, ELRAIL_ELEVATION },
392
393 { WSO_NS_S, 8, 0, 8, 8, 1, ELRAIL_ELEVATION },
394 { WSO_NS_S, 0, 8, 8, 8, 1, ELRAIL_ELEVATION },
395
396/* EW Direction */
397 { WSO_EW_SHORT, 7, 0, 1, 1, 1, ELRAIL_ELEVATION },
398 { WSO_EW_SHORT, 15, 8, 3, 3, 1, ELRAIL_ELEVATION },
399
400 { WSO_EW_W, 7, 0, 1, 1, 1, ELRAIL_ELEVATION },
401 { WSO_EW_W, 15, 8, 3, 3, 1, ELRAIL_ELEVATION },
402
403 { WSO_EW_E, 7, 0, 1, 1, 1, ELRAIL_ELEVATION },
404 { WSO_EW_E, 15, 8, 3, 3, 1, ELRAIL_ELEVATION }
405};
406
409 { WSO_ENTRANCE_NE, 0, 7, 15, 1, 1, ELRAIL_ELEVATION },
410 { WSO_ENTRANCE_SE, 7, 0, 1, 15, 1, ELRAIL_ELEVATION },
411 { WSO_ENTRANCE_SW, 0, 7, 15, 1, 1, ELRAIL_ELEVATION },
412 { WSO_ENTRANCE_NW, 7, 0, 1, 15, 1, ELRAIL_ELEVATION }
413}}};
414
420
423 { WSO_ENTRANCE_SW, {{0, 0, BB_Z_SEPARATOR}, {16, 15, 1}, {0, 7, ELRAIL_TUNNEL_OFFSET}} },
424 { WSO_ENTRANCE_NW, {{0, 0, BB_Z_SEPARATOR}, {15, 16, 1}, {7, 0, ELRAIL_TUNNEL_OFFSET}} },
425 { WSO_ENTRANCE_NE, {{0, 0, BB_Z_SEPARATOR}, {16, 15, 1}, {0, 7, ELRAIL_TUNNEL_OFFSET}} },
426 { WSO_ENTRANCE_SE, {{0, 0, BB_Z_SEPARATOR}, {15, 16, 1}, {7, 0, ELRAIL_TUNNEL_OFFSET}} }
427}}};
428
429
442enum RailCatenarySprite : uint8_t {
443 WIRE_X_FLAT_SW,
444 WIRE_X_FLAT_NE,
445 WIRE_X_FLAT_BOTH,
446
447 WIRE_X_UP_SW,
448 WIRE_X_UP_NE,
449 WIRE_X_UP_BOTH,
450
451 WIRE_X_DOWN_SW,
452 WIRE_X_DOWN_NE,
453 WIRE_X_DOWN_BOTH,
454
455 WIRE_Y_FLAT_SE,
456 WIRE_Y_FLAT_NW,
457 WIRE_Y_FLAT_BOTH,
458
459 WIRE_Y_UP_SE,
460 WIRE_Y_UP_NW,
461 WIRE_Y_UP_BOTH,
462
463 WIRE_Y_DOWN_SE,
464 WIRE_Y_DOWN_NW,
465 WIRE_Y_DOWN_BOTH,
466
467 WIRE_NS_W_BOTH,
468 WIRE_NS_E_BOTH,
469
470 WIRE_NS_W_N,
471 WIRE_NS_E_N,
472
473 WIRE_NS_W_S,
474 WIRE_NS_E_S,
475
476 WIRE_EW_N_BOTH,
477 WIRE_EW_S_BOTH,
478
479 WIRE_EW_N_W,
480 WIRE_EW_S_W,
481
482 WIRE_EW_N_E,
483 WIRE_EW_S_E,
484
485 INVALID_CATENARY = 0xFF
486};
487
497 { // Tileh == 0
498 {INVALID_CATENARY, WIRE_X_FLAT_NE, WIRE_X_FLAT_SW, WIRE_X_FLAT_BOTH},
499 {INVALID_CATENARY, WIRE_Y_FLAT_SE, WIRE_Y_FLAT_NW, WIRE_Y_FLAT_BOTH},
500 {INVALID_CATENARY, WIRE_EW_N_W, WIRE_EW_N_E, WIRE_EW_N_BOTH},
501 {INVALID_CATENARY, WIRE_EW_S_E, WIRE_EW_S_W, WIRE_EW_S_BOTH},
502 {INVALID_CATENARY, WIRE_NS_W_S, WIRE_NS_W_N, WIRE_NS_W_BOTH},
503 {INVALID_CATENARY, WIRE_NS_E_N, WIRE_NS_E_S, WIRE_NS_E_BOTH},
504 }, { // Tileh == 3
505 {INVALID_CATENARY, WIRE_X_UP_NE, WIRE_X_UP_SW, WIRE_X_UP_BOTH},
506 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
507 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
508 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
509 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
510 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
511 }, { // Tileh == 6
512 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
513 {INVALID_CATENARY, WIRE_Y_UP_SE, WIRE_Y_UP_NW, WIRE_Y_UP_BOTH},
514 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
515 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
516 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
517 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
518 }, { // Tileh == 9
519 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
520 {INVALID_CATENARY, WIRE_Y_DOWN_SE, WIRE_Y_DOWN_NW, WIRE_Y_DOWN_BOTH},
521 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
522 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
523 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
524 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
525 }, { // Tileh == 12
526 {INVALID_CATENARY, WIRE_X_DOWN_NE, WIRE_X_DOWN_SW, WIRE_X_DOWN_BOTH},
527 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
528 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
529 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
530 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
531 {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
532 }
533};
534
535#endif /* ELRAIL_DATA_H */
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
@ SW
Southwest.
@ NW
Northwest.
@ NE
Northeast.
@ SE
Southeast.
EnumIndexArray< T, Direction, Direction::End > DirectionIndexArray
Array with Direction as index.
EnumBitSet< Direction, uint8_t > Directions
Allow incrementing of Direction variables.
@ SW
Southwest.
@ NW
Northwest.
@ NE
Northeast, upper right on your monitor.
@ SE
Southeast.
static constexpr Directions DIRECTIONS_ALL
All possible directions.
static const uint ELRAIL_ELEVRAISE
Wires that a draw one level higher than the north corner.
static const DiagDirectionIndexArray< std::array< DirectionIndexArray< Direction >, TLG_END > > _ppp_order
Several PPPs maybe exist, here they are sorted in order of preference.
PylonSpriteOffset
Offset for pylon sprites from the base pylon sprite.
static const DiagDirectionIndexArray< int8_t > _x_pcp_offsets
static const uint ELRAIL_ELEVLOWER
Wires that a draw one level lower than the north corner.
static const DirectionIndexArray< uint8_t > _pylon_sprites
The type of pylon to draw at each PPP.
TileSource
When determining the pylon configuration on the edge, two tiles are taken into account: the tile bein...
Definition elrail_data.h:33
@ Neighbour
Neighbouring tile.
Definition elrail_data.h:35
@ Home
Home tile.
Definition elrail_data.h:34
static const DiagDirectionIndexArray< SortableSpriteStruct > _rail_catenary_sprite_data_tunnel
Catenary sprite data of a tunnel for each direction.
RailCatenarySprite
Refers to a certain element of the catenary.
static const TrackIndexArray< DiagDirectionIndexArray< Directions > > _disallowed_ppp_of_track_at_pcp
Which pylons can definitely NOT be built.
WireSpriteOffset
Offset for wire sprites from the base wire sprite.
static const TrackIndexArray< std::array< DiagDirection, 2 > > _pcp_positions
Maps a track bit onto two PCP positions.
Definition elrail_data.h:62
static const DiagDirectionIndexArray< int8_t > _y_pcp_offsets
static const DirectionIndexArray< int8_t > _x_ppp_offsets
static const DiagDirectionIndexArray< Directions > _owned_ppp_on_pcp
Which of the PPPs are inside the tile.
Definition elrail_data.h:54
static const TrackIndexArray< DiagDirectionIndexArray< Directions > > _preferred_ppp_of_track_at_pcp
Preferred points of each trackbit.
Definition elrail_data.h:77
static const DiagDirectionIndexArray< Directions > _allowed_ppp_on_pcp
Which PPPs are possible at all on a given PCP.
Definition elrail_data.h:42
static const DiagDirectionIndexArray< std::array< Track, NUM_TRACKS_AT_PCP > > _tracks_at_pcp
This array stores which track bits can meet at a tile edge.
static const int8_t ELRAIL_TUNNEL_OFFSET
In tunnelheads, the bounding box for wires covers nearly the full tile, and is lowered a bit.
static const DiagDirectionIndexArray< Directions > _ignored_pcp[NUM_IGNORE_GROUPS][TLG_END]
In case we have a straight line, we place pylon only every two tiles, so there are certain tiles whic...
static const DiagDirectionIndexArray< SortableSpriteStruct > _rail_catenary_sprite_data_depot
Catenary sprite data of a depot for each direction.
static const DiagDirectionIndexArray< std::array< TileSource, NUM_TRACKS_AT_PCP > > _track_source_tile
Takes each of the 6 track bits from the array above and assigns it to the home tile or neighbour tile...
TileLocationGroup
Tile Location group.
Definition elrail_data.h:20
static const RailCatenarySprite _rail_wires[5][TRACK_END][4]
Selects a Wire (with white and grey ends) depending on whether: a) none (should never happen) b) the ...
static const DirectionIndexArray< int8_t > _y_ppp_offsets
static const uint ELRAIL_ELEVATION
Distance between wire and rail.
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
EnumIndexArray< T, Track, TRACK_END > TrackIndexArray
Allow incrementing of Track variables.
Definition track_type.h:39
@ TRACK_Y
Track along the y-axis (north-west to south-east).
Definition track_type.h:22
@ TRACK_LOWER
Track in the lower corner of the tile (south).
Definition track_type.h:24
@ TRACK_END
Used for iterations.
Definition track_type.h:27
@ TRACK_LEFT
Track in the left corner of the tile (west).
Definition track_type.h:25
@ TRACK_RIGHT
Track in the right corner of the tile (east).
Definition track_type.h:26
@ TRACK_X
Track along the x-axis (north-east to south-west).
Definition track_type.h:21
@ TRACK_UPPER
Track in the upper corner of the tile (north).
Definition track_type.h:23
@ End
End marker.
Definition vehicle.cpp:2829
static constexpr int BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.