Codechange: avoid magic numbers and generic types when drawing autorail (#15689)

This commit is contained in:
Peter Nelson
2026-06-08 22:22:15 +01:00
committed by GitHub
parent 0ff5f81319
commit 7e2bcaf792
2 changed files with 9 additions and 10 deletions
+2 -2
View File
@@ -19,10 +19,10 @@
#define RED(c) -c
/**
* Table maps each of the six rail directions and tileh combinations to a sprite.
* Table maps each of the six rail directions and tileh combinations to a sprite offset.
* Invalid entries are required to make sure that this array can be quickly accessed.
*/
static const int _AutorailTilehSprite[][6] = {
static const int _autorail_slope_sprite_offsets[][6] = {
/* type 0 1 2 3 4 5 */
{ 0, 8, 16, 25, 34, 42 }, // tileh = 0
{ 5, 13, RED(22), RED(31), 35, 42 }, // tileh = 1
+7 -8
View File
@@ -965,27 +965,26 @@ static const HighLightStyle _autorail_type[6][2] = {
* Draws autorail highlights.
*
* @param *ti TileInfo Tile that is being drawn
* @param autorail_type Offset into _AutorailTilehSprite[][]
* @param highlight_style Highlight to draw
*/
static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
static void DrawAutorailSelection(const TileInfo *ti, HighLightStyle highlight_style)
{
SpriteID image;
PaletteID pal;
int offset;
FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
Slope autorail_tileh = RemoveHalftileSlope(ti->tileh);
Slope slope = RemoveHalftileSlope(ti->tileh);
if (IsHalftileSlope(ti->tileh)) {
static constexpr CornerIndexArray<uint> lower_rail = {5U, 2U, 4U, 3U};
static constexpr CornerIndexArray<HighLightStyle> lower_rail{HT_DIR_VR, HT_DIR_HU, HT_DIR_VL, HT_DIR_HL};
Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
if (autorail_type != lower_rail[halftile_corner]) {
if ((highlight_style & HT_DIR_MASK) != lower_rail[halftile_corner]) {
foundation_part = FOUNDATION_PART_HALFTILE;
/* Here we draw the highlights of the "three-corners-raised"-slope. That looks ok to me. */
autorail_tileh = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
}
}
offset = _AutorailTilehSprite[autorail_tileh][autorail_type];
int offset = _autorail_slope_sprite_offsets[slope][highlight_style & HT_DIR_MASK];
if (offset >= 0) {
image = SPR_AUTORAIL_BASE + offset;
pal = PAL_NONE;