summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newgrf.c24
-rw-r--r--newgrf.h1
-rw-r--r--rail_cmd.c12
3 files changed, 34 insertions, 3 deletions
diff --git a/newgrf.c b/newgrf.c
index 5dace18e7..af3f62869 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -38,6 +38,7 @@ uint16 _custom_sprites_base;
static int _skip_sprites; // XXX
static uint _file_index; // XXX
extern int _traininfo_vehicle_pitch;
+SpriteID _signal_base = 0;
static GRFFile *_cur_grffile;
GRFFile *_first_grffile;
@@ -1823,8 +1824,27 @@ static void GraphicsNew(byte *buf, int len)
type = grf_load_byte(&buf);
num = grf_load_extended(&buf);
- grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %d (unimplemented, ignoring).\n",
- type, num);
+ switch (type) {
+ case 0x04: /* Signal graphics */
+ if (num != 112 && num != 240) {
+ grfmsg(GMS_WARN, "GraphicsNews: Signal graphics sprite count must be 112 or 240, skipping.");
+ return;
+ }
+ _signal_base = _cur_spriteid;
+ break;
+
+ default:
+ grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring).\n",
+ type, num);
+ return;
+ }
+
+ grfmsg(GMS_NOTICE, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
+
+ for (; num > 0; num--) {
+ LoadNextSprite(_cur_spriteid++, _file_index);
+ _nfo_line++;
+ }
}
/* Action 0x06 */
diff --git a/newgrf.h b/newgrf.h
index 904d44419..c4d937461 100644
--- a/newgrf.h
+++ b/newgrf.h
@@ -60,6 +60,7 @@ typedef struct GRFConfig {
} GRFConfig;
extern GRFConfig *_first_grfconfig;
+extern SpriteID _signal_base;
void LoadNewGRF(uint load_index, uint file_index);
diff --git a/rail_cmd.c b/rail_cmd.c
index 355078e04..34f563ec9 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -26,6 +26,7 @@
#include "waypoint.h"
#include "rail.h"
#include "railtypes.h" // include table for railtypes
+#include "newgrf.h"
extern uint16 _custom_sprites_base;
@@ -1047,7 +1048,16 @@ static void DrawSingleSignal(TileIndex tile, byte condition, uint image, uint po
uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
- SpriteID sprite = SignalBase[side][GetSignalVariant(tile)][GetSignalType(tile)] + image + condition;
+ SpriteID sprite;
+
+ /* _signal_base is set by our NewGRF Action 5 loader. If it is 0 then we
+ * just draw the standard signals, else we get the offset from _signal_base
+ * and draw that sprite. All the signal sprites are loaded sequentially. */
+ if (_signal_base == 0 || (GetSignalType(tile) == 0 && GetSignalVariant(tile) == SIG_ELECTRIC)) {
+ sprite = SignalBase[side][GetSignalVariant(tile)][GetSignalType(tile)] + image + condition;
+ } else {
+ sprite = _signal_base + (GetSignalType(tile) - 1) * 16 + GetSignalVariant(tile) * 64 + image + condition;
+ }
AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y));
}