summaryrefslogtreecommitdiff
path: root/src/rail_cmd.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2012-07-01 23:12:50 +0000
committermichi_cc <michi_cc@openttd.org>2012-07-01 23:12:50 +0000
commitb0d21d2fadc9e7df11a2758e3e5cc411af2b0452 (patch)
tree533cf8897f15d02ccc19156034692ee32fa27976 /src/rail_cmd.cpp
parenta6244ed0dc39f520283abf2530154f0ae3996f2f (diff)
downloadopenttd-b0d21d2fadc9e7df11a2758e3e5cc411af2b0452.tar.xz
(svn r24367) -Feature: [NewGRF] Customisable signals for rail types.
Diffstat (limited to 'src/rail_cmd.cpp')
-rw-r--r--src/rail_cmd.cpp69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 12be60f35..ffa42de82 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -44,6 +44,18 @@ RailtypeInfo _railtypes[RAILTYPE_END];
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
+/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
+enum SignalOffsets {
+ SIGNAL_TO_SOUTHWEST,
+ SIGNAL_TO_NORTHEAST,
+ SIGNAL_TO_SOUTHEAST,
+ SIGNAL_TO_NORTHWEST,
+ SIGNAL_TO_EAST,
+ SIGNAL_TO_WEST,
+ SIGNAL_TO_SOUTH,
+ SIGNAL_TO_NORTH,
+};
+
/**
* Reset all rail type information to its default values.
*/
@@ -74,6 +86,24 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti)
rti->cursor.tunnel = cursors_base + 14;
rti->cursor.convert = cursors_base + 15;
}
+
+ /* Array of default GUI signal sprite numbers. */
+ const SpriteID _signal_lookup[2][SIGTYPE_END] = {
+ {SPR_IMG_SIGNAL_ELECTRIC_NORM, SPR_IMG_SIGNAL_ELECTRIC_ENTRY, SPR_IMG_SIGNAL_ELECTRIC_EXIT,
+ SPR_IMG_SIGNAL_ELECTRIC_COMBO, SPR_IMG_SIGNAL_ELECTRIC_PBS, SPR_IMG_SIGNAL_ELECTRIC_PBS_OWAY},
+
+ {SPR_IMG_SIGNAL_SEMAPHORE_NORM, SPR_IMG_SIGNAL_SEMAPHORE_ENTRY, SPR_IMG_SIGNAL_SEMAPHORE_EXIT,
+ SPR_IMG_SIGNAL_SEMAPHORE_COMBO, SPR_IMG_SIGNAL_SEMAPHORE_PBS, SPR_IMG_SIGNAL_SEMAPHORE_PBS_OWAY},
+ };
+
+ for (SignalType type = SIGTYPE_NORMAL; type < SIGTYPE_END; type = (SignalType)(type + 1)) {
+ for (SignalVariant var = SIG_ELECTRIC; var <= SIG_SEMAPHORE; var = (SignalVariant)(var + 1)) {
+ SpriteID red = GetCustomSignalSprite(rti, INVALID_TILE, type, var, SIGNAL_STATE_RED, true);
+ SpriteID green = GetCustomSignalSprite(rti, INVALID_TILE, type, var, SIGNAL_STATE_GREEN, true);
+ rti->gui_sprites.signals[type][var][0] = (red != 0) ? red + SIGNAL_TO_SOUTH : _signal_lookup[var][type];
+ rti->gui_sprites.signals[type][var][1] = (green != 0) ? green + SIGNAL_TO_SOUTH : _signal_lookup[var][type] + 1;
+ }
+ }
}
/**
@@ -1798,7 +1828,7 @@ static uint GetSaveSlopeZ(uint x, uint y, Track track)
return GetSlopePixelZ(x, y);
}
-static void DrawSingleSignal(TileIndex tile, Track track, byte condition, uint image, uint pos)
+static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, SignalState condition, SignalOffsets image, uint pos)
{
bool side;
switch (_settings_game.construction.train_signal_side) {
@@ -1823,17 +1853,16 @@ static void DrawSingleSignal(TileIndex tile, Track track, byte condition, uint i
uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
- SpriteID sprite;
-
SignalType type = GetSignalType(tile, track);
SignalVariant variant = GetSignalVariant(tile, track);
- if (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) {
- /* Normal electric signals are picked from original sprites. */
- sprite = SPR_ORIGINAL_SIGNALS_BASE + image + condition;
+ SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition);
+ if (sprite != 0) {
+ sprite += image;
} else {
- /* All other signals are picked from add on sprites. */
- sprite = SPR_SIGNALS_BASE + (type - 1) * 16 + variant * 64 + image + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
+ /* Normal electric signals are stored in a different sprite block than all other signals. */
+ sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16;
+ sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
}
AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track));
@@ -2277,27 +2306,9 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
}
}
-/**
- * Enums holding the offsets from base signal sprite,
- * according to the side it is representing.
- * The addtion of 2 per enum is necessary in order to "jump" over the
- * green state sprite, all signal sprites being in pair,
- * starting with the off-red state
- */
-enum SignalOffsets {
- SIGNAL_TO_SOUTHWEST = 0,
- SIGNAL_TO_NORTHEAST = 2,
- SIGNAL_TO_SOUTHEAST = 4,
- SIGNAL_TO_NORTHWEST = 6,
- SIGNAL_TO_EAST = 8,
- SIGNAL_TO_WEST = 10,
- SIGNAL_TO_SOUTH = 12,
- SIGNAL_TO_NORTH = 14,
-};
-
-static void DrawSignals(TileIndex tile, TrackBits rails)
+static void DrawSignals(TileIndex tile, TrackBits rails, const RailtypeInfo *rti)
{
-#define MAYBE_DRAW_SIGNAL(x, y, z, t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, t, GetSingleSignalState(tile, x), y, z)
+#define MAYBE_DRAW_SIGNAL(x, y, z, t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, rti, t, GetSingleSignalState(tile, x), y, z)
if (!(rails & TRACK_BIT_Y)) {
if (!(rails & TRACK_BIT_X)) {
@@ -2342,7 +2353,7 @@ static void DrawTile_Track(TileInfo *ti)
if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
- if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
+ if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails, rti);
} else {
/* draw depot */
const DrawTileSprites *dts;