summaryrefslogtreecommitdiff
path: root/src/spritecache.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-09-02 18:45:15 +0000
committerrubidium <rubidium@openttd.org>2008-09-02 18:45:15 +0000
commitfc216aeeb86f5e84db06f51ad1e3172d6c343b3b (patch)
treec6bcdba91fc3571e2f542bbd9644b62991808118 /src/spritecache.cpp
parentc0cdfea97d298bf64f507e48e711888ef6681db6 (diff)
downloadopenttd-fc216aeeb86f5e84db06f51ad1e3172d6c343b3b.tar.xz
(svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
Diffstat (limited to 'src/spritecache.cpp')
-rw-r--r--src/spritecache.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index f7ab69b72..5d141cce3 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -11,6 +11,7 @@
#include "spriteloader/grf.hpp"
#include "core/alloc_func.hpp"
#include "core/math_func.hpp"
+#include "gfx_func.h"
#ifdef WITH_PNG
#include "spriteloader/png.hpp"
#endif /* WITH_PNG */
@@ -188,11 +189,30 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
}
- byte *dest = (byte *)AllocSprite(num);
+ /* "Normal" recolour sprites are ALWAYS 257 bytes. Then there is a small
+ * number of recolour sprites that are 17 bytes that only exist in DOS
+ * GRFs which are the same as 257 byte recolour sprites, but with the last
+ * 240 bytes zeroed. */
+ static const int RECOLOUR_SPRITE_SIZE = 257;
+ byte *dest = (byte *)AllocSprite(max(RECOLOUR_SPRITE_SIZE, num));
sc->ptr = dest;
sc->type = sprite_type;
- FioReadBlock(dest, num);
+
+ if (_palette_remap_grf[sc->file_slot]) {
+ byte *dest_tmp = AllocaM(byte, max(RECOLOUR_SPRITE_SIZE, num));
+
+ /* Only a few recolour sprites are less than 257 bytes */
+ if (num < RECOLOUR_SPRITE_SIZE) memset(dest_tmp, 0, RECOLOUR_SPRITE_SIZE);
+ FioReadBlock(dest_tmp, num);
+
+ /* The data of index 0 is never used; "literal 00" according to the (New)GRF specs. */
+ for (int i = 1; i < RECOLOUR_SPRITE_SIZE; i++) {
+ dest[i] = _palette_remap[dest_tmp[_palette_reverse_remap[i - 1] + 1]];
+ }
+ } else {
+ FioReadBlock(dest, num);
+ }
return sc->ptr;
}