mirror of https://github.com/OpenTTD/OpenTTD
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
parent
2c67320bae
commit
fce4c5e2c2
|
@ -74,33 +74,38 @@ static uint LoadGrfFile(const char* filename, uint load_index, int file_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
|
void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl)
|
||||||
{
|
{
|
||||||
uint start;
|
uint start;
|
||||||
|
while ((start = *index_tbl++) != END) {
|
||||||
|
uint end = *index_tbl++;
|
||||||
|
|
||||||
|
if (start == SKIP) { // skip sprites (amount in second var)
|
||||||
|
SkipSprites(end);
|
||||||
|
(*sprite_id) += end;
|
||||||
|
} else { // load sprites and use indexes from start to end
|
||||||
|
do {
|
||||||
|
#ifdef NDEBUG
|
||||||
|
LoadNextSprite(start, file_index, *sprite_id);
|
||||||
|
#else
|
||||||
|
bool b = LoadNextSprite(start, file_index, *sprite_id);
|
||||||
|
assert(b);
|
||||||
|
#endif
|
||||||
|
(*sprite_id)++;
|
||||||
|
} while (++start <= end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
|
||||||
|
{
|
||||||
uint sprite_id = 0;
|
uint sprite_id = 0;
|
||||||
|
|
||||||
FioOpenFile(file_index, filename);
|
FioOpenFile(file_index, filename);
|
||||||
|
|
||||||
DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
|
DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
|
||||||
|
|
||||||
while ((start = *index_tbl++) != END) {
|
LoadSpritesIndexed(file_index, &sprite_id, index_tbl);
|
||||||
uint end = *index_tbl++;
|
|
||||||
|
|
||||||
if (start == SKIP) { // skip sprites (amount in second var)
|
|
||||||
SkipSprites(end);
|
|
||||||
sprite_id += end;
|
|
||||||
} else { // load sprites and use indexes from start to end
|
|
||||||
do {
|
|
||||||
#ifdef NDEBUG
|
|
||||||
LoadNextSprite(start, file_index, sprite_id);
|
|
||||||
#else
|
|
||||||
bool b = LoadNextSprite(start, file_index, sprite_id);
|
|
||||||
assert(b);
|
|
||||||
#endif
|
|
||||||
sprite_id++;
|
|
||||||
} while (++start <= end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
|
|
||||||
void CheckExternalFiles();
|
void CheckExternalFiles();
|
||||||
void GfxLoadSprites();
|
void GfxLoadSprites();
|
||||||
|
void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl);
|
||||||
|
|
||||||
#endif /* GFXINIT_H */
|
#endif /* GFXINIT_H */
|
||||||
|
|
|
@ -45,6 +45,8 @@
|
||||||
#include "newgrf_commons.h"
|
#include "newgrf_commons.h"
|
||||||
#include "newgrf_townname.h"
|
#include "newgrf_townname.h"
|
||||||
#include "newgrf_industries.h"
|
#include "newgrf_industries.h"
|
||||||
|
#include "table/landscape_sprite.h"
|
||||||
|
#include "gfxinit.h"
|
||||||
|
|
||||||
/* TTDPatch extended GRF format codec
|
/* TTDPatch extended GRF format codec
|
||||||
* (c) Petr Baudis 2004 (GPL'd)
|
* (c) Petr Baudis 2004 (GPL'd)
|
||||||
|
@ -3232,6 +3234,7 @@ static void GraphicsNew(byte *buf, int len)
|
||||||
/* TODO */
|
/* TODO */
|
||||||
|
|
||||||
SpriteID replace = 0;
|
SpriteID replace = 0;
|
||||||
|
const SpriteID *index_tbl = NULL;
|
||||||
|
|
||||||
if (!check_length(len, 2, "GraphicsNew")) return;
|
if (!check_length(len, 2, "GraphicsNew")) return;
|
||||||
buf++;
|
buf++;
|
||||||
|
@ -3256,11 +3259,13 @@ static void GraphicsNew(byte *buf, int len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x06: // Foundations
|
case 0x06: // Foundations
|
||||||
if (num != 74) {
|
switch (num) {
|
||||||
grfmsg(1, "GraphicsNew: Foundation graphics sprite count must be 74, skipping");
|
case 74: replace = SPR_SLOPES_BASE; break;
|
||||||
return;
|
case 90: index_tbl = _slopes_action05_90; break;
|
||||||
|
default:
|
||||||
|
grfmsg(1, "GraphicsNew: Foundation graphics sprite count must be 74 or 90, skipping");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
replace = SPR_SLOPES_BASE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x08: // Canal graphics
|
case 0x08: // Canal graphics
|
||||||
|
@ -3326,6 +3331,12 @@ static void GraphicsNew(byte *buf, int len)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index_tbl != NULL) {
|
||||||
|
grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at indexed SpriteIDs", num, type);
|
||||||
|
LoadSpritesIndexed(_file_index, &_nfo_line, index_tbl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (replace == 0) {
|
if (replace == 0) {
|
||||||
grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
|
grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -197,3 +197,10 @@ static const SpriteID _halftile_foundation_spriteindexes_3[] = {
|
||||||
SPR_HALFTILE_FOUNDATION_BASE, SPR_HALFTILE_FOUNDATION_BASE + 4 * SPR_HALFTILE_BLOCK_SIZE - 1,
|
SPR_HALFTILE_FOUNDATION_BASE, SPR_HALFTILE_FOUNDATION_BASE + 4 * SPR_HALFTILE_BLOCK_SIZE - 1,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Slope graphics indexes for Action 05 type 06, 90 sprites */
|
||||||
|
static const SpriteID _slopes_action05_90[] = {
|
||||||
|
SPR_SLOPES_VIRTUAL_BASE + 15, SPR_SLOPES_VIRTUAL_BASE + 4 * SPR_TRKFOUND_BLOCK_SIZE,
|
||||||
|
SPR_HALFTILE_FOUNDATION_BASE, SPR_HALFTILE_FOUNDATION_BASE + 4 * SPR_HALFTILE_BLOCK_SIZE - 1,
|
||||||
|
END
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue