Skip to content

Commit

Permalink
Feature: Slope-aware and roadtype-specific one-way sprites.
Browse files Browse the repository at this point in the history
Per OpenTTD#10238, the baseset only provided one-way sprites for flat tiles,
 matching the default road type. These look bad on slopes or on
 some custom roadtypes.

Action5 type 0x09 is extended to accept a set of 18 sprites.
The first 6 are unchanged from before this patch, followed by
 similar groups for north-facing and then south-facing slopes.

For compatibility with older basesets and NewGRFs, if an Action5
 provides only sprites for flat tiles these will be used on slopes
 as in previous versions.

Action3 type 0x0B, for roadtypes only, may optionally provide a
 set of 18 sprites as above for use with that roadtype.
  • Loading branch information
FLHerne committed Dec 25, 2022
1 parent 73e5c57 commit fd6b72d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/newgrf.cpp
Expand Up @@ -6250,9 +6250,17 @@ static void GraphicsNew(ByteReader *buf)
if (offset <= depot_no_track_offset && offset + num > depot_no_track_offset) _loaded_newgrf_features.tram = TRAMWAY_REPLACE_DEPOT_NO_TRACK;
}

/* If the baseset or grf only provides sprites for flat tiles (pre #10282), duplicate those for use on slopes. */
bool dup_oneway_sprites = ((type == 0x09) && (offset + num) <= SPR_ONEWAY_SLOPE_N_OFFSET);

for (; num > 0; num--) {
_cur.nfo_line++;
LoadNextSprite(replace == 0 ? _cur.spriteid++ : replace++, *_cur.file, _cur.nfo_line);
int load_index = (replace == 0 ? _cur.spriteid++ : replace++);
LoadNextSprite(load_index, *_cur.file, _cur.nfo_line);
if (dup_oneway_sprites) {
DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
}
}

_cur.skip_sprites = skip_num;
Expand Down
1 change: 1 addition & 0 deletions src/road.h
Expand Up @@ -66,6 +66,7 @@ enum RoadTypeSpriteGroup {
ROTSG_DEPOT, ///< Optional: Depot images
ROTSG_reserved3, ///< Placeholder, if we add road fences (for highways).
ROTSG_ROADSTOP, ///< Required: Drive-in stop surface
ROTSG_ONEWAY, ///< Optional: One-way indicator images
ROTSG_END,
};

Expand Down
12 changes: 11 additions & 1 deletion src/road_cmd.cpp
Expand Up @@ -1600,7 +1600,17 @@ static void DrawRoadBits(TileInfo *ti)
if (road_rti != nullptr) {
DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
if (drd != DRD_NONE) {
DrawGroundSpriteAt(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
SpriteID oneway = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_ONEWAY);

if (oneway == 0) oneway = SPR_ONEWAY_BASE;

if ((ti->tileh == SLOPE_NE) || (ti->tileh == SLOPE_NW)) {
oneway += SPR_ONEWAY_SLOPE_N_OFFSET;
} else if ((ti->tileh == SLOPE_SE) || (ti->tileh == SLOPE_SW)) {
oneway += SPR_ONEWAY_SLOPE_S_OFFSET;
}

DrawGroundSpriteAt(oneway + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/table/sprites.h
Expand Up @@ -290,8 +290,10 @@ static const SpriteID SPR_TRAMWAY_DEPOT_NO_TRACK = SPR_TRAMWAY_BASE + 113;
static const uint16 TRAMWAY_SPRITE_COUNT = 119;

/** One way road sprites */
static const SpriteID SPR_ONEWAY_BASE = SPR_TRAMWAY_BASE + TRAMWAY_SPRITE_COUNT;
static const uint16 ONEWAY_SPRITE_COUNT = 6;
static const SpriteID SPR_ONEWAY_BASE = SPR_TRAMWAY_BASE + TRAMWAY_SPRITE_COUNT;
static const SpriteID SPR_ONEWAY_SLOPE_N_OFFSET = 6;
static const SpriteID SPR_ONEWAY_SLOPE_S_OFFSET = 12;
static const uint16 ONEWAY_SPRITE_COUNT = 18;

/** Flags sprites (in same order as enum NetworkLanguage) */
static const SpriteID SPR_FLAGS_BASE = SPR_ONEWAY_BASE + ONEWAY_SPRITE_COUNT;
Expand Down

0 comments on commit fd6b72d

Please sign in to comment.