Fix handling of GRF programmable signal graphics with trace restrict

pull/82/head
Jonathan G Rennison 5 years ago
parent 53ff27370d
commit 5242ec4642

@ -50,6 +50,7 @@ static const SpriteID * const _landscape_spriteindexes[] = {
/** file index of first user-added GRF file */
int _first_user_grf_file_index;
int _opengfx_grf_file_index;
int _progsig_grf_file_index;
/**
* Load an old fashioned GRF file.
@ -182,8 +183,14 @@ static void LoadSpriteTables()
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, i++);
/* Progsignal sprites. */
_progsig_grf_file_index = i;
LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, i++);
/* Fill duplicate programmable signal graphics sprite block */
for (uint i = 0; i < PROGSIGNAL_SPRITE_COUNT; i++) {
DupSprite(SPR_PROGSIGNAL_BASE + i, SPR_DUP_PROGSIGNAL_BASE + i);
}
/* Tracerestrict sprites. */
LoadGrfFile("tracerestrict.grf", SPR_TRACERESTRICT_BASE, i++);

@ -2357,33 +2357,43 @@ void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, Sign
uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition);
bool is_custom_sprite = (sprite != 0);
if (sprite != 0) {
sprite += image;
SpriteID sprite;
bool is_custom_sprite;
if (type == SIGTYPE_PROG) {
if (variant == SIG_SEMAPHORE) {
sprite = SPR_PROGSIGNAL_BASE + image * 2 + condition;
} else {
sprite = SPR_PROGSIGNAL_BASE + 16 + image * 2 + condition;
}
extern int _progsig_grf_file_index;
is_custom_sprite = (int) GetOriginFileSlot(sprite) != _progsig_grf_file_index;
} else {
/* 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 + (IsSignalSpritePBS(type) ? 64 : 0);
}
sprite = GetCustomSignalSprite(rti, tile, type, variant, condition);
is_custom_sprite = (sprite != 0);
if (sprite != 0) {
sprite += image;
} else {
/* 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 + (IsSignalSpritePBS(type) ? 64 : 0);
}
if (type == SIGTYPE_PROG && variant == SIG_SEMAPHORE) {
sprite = SPR_PROGSIGNAL_BASE + image * 2 + condition;
is_custom_sprite = false;
} else if (type == SIGTYPE_PROG && variant == SIG_ELECTRIC) {
sprite = SPR_PROGSIGNAL_BASE + 16 + image * 2 + condition;
is_custom_sprite = false;
} else {
int origin_slot = GetOriginFileSlot(sprite);
extern int _first_user_grf_file_index;
extern int _opengfx_grf_file_index;
if (!is_custom_sprite) is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index);
if (!is_custom_sprite) {
int origin_slot = GetOriginFileSlot(sprite);
extern int _first_user_grf_file_index;
extern int _opengfx_grf_file_index;
is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index);
}
}
if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default) {
/* Use duplicate sprite block, instead of GRF-specified signals */
sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_DUP_ORIGINAL_SIGNALS_BASE : SPR_DUP_SIGNALS_BASE - 16;
sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0);
if (type == SIGTYPE_PROG) {
sprite += SPR_DUP_PROGSIGNAL_BASE - SPR_PROGSIGNAL_BASE;
} else {
sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_DUP_ORIGINAL_SIGNALS_BASE : SPR_DUP_SIGNALS_BASE - 16;
sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0);
}
is_custom_sprite = false;
}

@ -312,9 +312,10 @@ static const uint16 PALETTE_SPRITE_COUNT = 1;
/* Programmable signal sprites */
static const SpriteID SPR_PROGSIGNAL_BASE = SPR_PALETTE_BASE + PALETTE_SPRITE_COUNT;
static const uint16 PROGSIGNAL_SPRITE_COUNT = 32;
static const SpriteID SPR_DUP_PROGSIGNAL_BASE = SPR_PROGSIGNAL_BASE + PROGSIGNAL_SPRITE_COUNT;
/* Zoning sprites */
static const SpriteID SPR_ZONING_INNER_HIGHLIGHT_BASE = SPR_PROGSIGNAL_BASE + PROGSIGNAL_SPRITE_COUNT;
static const SpriteID SPR_ZONING_INNER_HIGHLIGHT_BASE = SPR_DUP_PROGSIGNAL_BASE + PROGSIGNAL_SPRITE_COUNT;
static const uint16 ZONING_INNER_HIGHLIGHT_SPRITE_COUNT = 32;
static const SpriteID SPR_ZONING_INNER_HIGHLIGHT_RED = SPR_ZONING_INNER_HIGHLIGHT_BASE + 19;
static const SpriteID SPR_ZONING_INNER_HIGHLIGHT_GREEN = SPR_ZONING_INNER_HIGHLIGHT_BASE + 20;

Loading…
Cancel
Save