gfxinit.c
author tron
Fri, 14 Oct 2005 07:59:16 +0000
changeset 2512 fa66ff5ebf88
parent 2411 a76c0b960e92
child 2513 4bacb4e5ac8b
permissions -rw-r--r--
(svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1844
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1250
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gfx.h"
2340
0a9f3eeccb96 (svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents: 2339
diff changeset
     8
#include "gfxinit.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1348
diff changeset
     9
#include "spritecache.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1361
diff changeset
    10
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "fileio.h"
463
91bcad840bcd (svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents: 452
diff changeset
    12
#include "newgrf.h"
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    13
#include "md5.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2142
diff changeset
    14
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include <ctype.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    17
typedef struct MD5File {
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    18
	const char * const filename;     // filename
962
c1de16d93e46 (svn r1454) -Fix: small warnings in spritecache.c
darkvater
parents: 961
diff changeset
    19
	const md5_byte_t hash[16]; // md5 sum of the file
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    20
} MD5File;
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    21
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
    22
typedef struct FileList {
1725
97841c222b55 (svn r2229) - Fix: [ 1188777 ] Non-existing sprite #5125 (presignal). The DOS grf file trgi.grf has 6 less sprites than the windows one. This results in some segfaults for certain sprites. Fixed it by added a dummy grf file consisting ofr 6 sprites and loaded when using DOS gfx at the appropiate place.
Darkvater
parents: 1437
diff changeset
    23
	const MD5File basic[5];     // grf files that always have to be loaded
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    24
	const MD5File landscape[3]; // landscape specific grf files
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
    25
} FileList;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    27
#include "table/files.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#include "table/landscape_sprite.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    30
static const SpriteID * const _landscape_spriteindexes[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	_landscape_spriteindexes_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	_landscape_spriteindexes_2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	_landscape_spriteindexes_3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    36
static const SpriteID * const _slopes_spriteindexes[] = {
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    37
	_slopes_spriteindexes_0,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    38
	_slopes_spriteindexes_1,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    39
	_slopes_spriteindexes_2,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    40
	_slopes_spriteindexes_3,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    41
};
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    42
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    43
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    44
static uint LoadGrfFile(const char* filename, uint load_index, int file_index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
{
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    46
	uint load_index_org = load_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	FioOpenFile(file_index, filename);
365
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    49
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 365
diff changeset
    50
	DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	while (LoadNextSprite(load_index, file_index)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
		load_index++;
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    54
		if (load_index >= MAX_SPRITES) {
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    55
			error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	}
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    58
	DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
365
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    60
	return load_index - load_index_org;
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    61
}
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    62
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    63
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    64
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
365
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    65
{
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    66
	uint start;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
    67
365
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    68
	FioOpenFile(file_index, filename);
5752af05ed75 (svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents: 364
diff changeset
    69
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 365
diff changeset
    70
	DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    72
	for (; (start = *index_tbl++) != 0xffff;) {
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    73
		uint end = *index_tbl++;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    74
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    75
		if (start == 0xfffe) { // skip sprites (amount in second var)
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    76
			SkipSprites(end);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    77
		} else { // load sprites and use indexes from start to end
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    78
			do {
1844
372dae999453 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    79
			#ifdef NDEBUG
372dae999453 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    80
				LoadNextSprite(start, file_index);
372dae999453 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    81
			#else
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    82
				bool b = LoadNextSprite(start, file_index);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    83
				assert(b);
1844
372dae999453 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    84
			#endif
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    85
			} while (++start <= end);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    86
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	}
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
    88
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    91
/* Check that the supplied MD5 hash matches that stored for the supplied filename */
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    92
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn)
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    93
{
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
    94
	uint i;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    95
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    96
	/* Loop through each byte of the file MD5 and the stored MD5... */
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
    97
	for (i = 0; i < 16; i++) if (file.hash[i] != digest[i]) break;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    98
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    99
		/* If all bytes of the MD5's match (i.e. the MD5's match)... */
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   100
	if (i == 16) {
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   101
		return true;
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   102
	} else {
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   103
		if (warn) fprintf(stderr, "MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename);
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   104
		return false;
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   105
	};
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   106
}
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   107
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   108
/* Calculate and check the MD5 hash of the supplied filename.
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   109
 * returns true if the checksum is correct */
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   110
static bool FileMD5(const MD5File file, bool warn)
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   111
{
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   112
	FILE *f;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   113
	char buf[MAX_PATH];
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   114
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   115
	// open file
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   116
	sprintf(buf, "%s%s", _path.data_dir, file.filename);
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   117
	f = fopen(buf, "rb");
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   118
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   119
#if !defined(WIN32)
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   120
	if (f == NULL) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
   121
		char *s;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   122
	// make lower case and check again
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   123
		for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++)
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   124
			*s = tolower(*s);
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   125
		f = fopen(buf, "rb");
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   126
	}
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   127
#endif
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   128
862
d7e52ef99f42 (svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents: 614
diff changeset
   129
	if (f != NULL) {
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   130
		md5_state_t filemd5state;
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   131
		md5_byte_t buffer[1024];
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   132
		md5_byte_t digest[16];
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   133
		size_t len;
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   134
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   135
		md5_init(&filemd5state);
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   136
		while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0)
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   137
			md5_append(&filemd5state, buffer, len);
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   138
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   139
		if (ferror(f) && warn) fprintf(stderr, "Error Reading from %s \n", buf);
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   140
		fclose(f);
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   141
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   142
		md5_finish(&filemd5state, digest);
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   143
	  return CheckMD5Digest(file, digest, warn);
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   144
	} else { // file not found
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   145
		return false;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   146
	}
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   147
}
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   148
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   149
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF)
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   150
 * by comparing the MD5 checksums of the files. _use_dos_palette is set accordingly.
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   151
 * If neither are found, Windows palette is assumed.
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   152
 *
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   153
 * (Note: Also checks sample.cat for corruption) */
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   154
void CheckExternalFiles(void)
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   155
{
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   156
	uint i;
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   157
	// count of files from this version
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   158
	uint dos = 0;
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   159
	uint win = 0;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   160
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   161
	for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++;
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   162
	for (i = 0; i < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   163
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   164
	for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++;
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   165
	for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++;
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   166
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   167
	if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false))
2028
d7686f53adf2 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   168
		fprintf(stderr, "Your sample.cat file is corrupted or missing!\n");
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   169
1380
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   170
	/*
1389
238570e5c3d3 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   171
	 * forced DOS palette via command line -> leave it that way
1380
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   172
	 * all Windows files present -> Windows palette
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   173
	 * all DOS files present -> DOS palette
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   174
	 * no Windows files present and any DOS file present -> DOS palette
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   175
	 * otherwise -> Windows palette
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   176
	 */
1389
238570e5c3d3 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   177
	if (_use_dos_palette) {
238570e5c3d3 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   178
		return;
238570e5c3d3 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   179
	} else if (win == 5) {
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   180
		_use_dos_palette = false;
1381
3837b6c64508 (svn r1885) Fix typo in r1884
tron
parents: 1380
diff changeset
   181
	} else if (dos == 5 || (win == 0 && dos > 0)) {
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   182
		_use_dos_palette = true;
1380
7faf03f67dc3 (svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents: 1378
diff changeset
   183
	} else {
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   184
		_use_dos_palette = false;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   185
	}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   186
}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   187
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
   188
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   189
static const SpriteID trg1idx[] = {
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   190
	     0,    1, // Mouse cursor, ZZZ
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   191
/* Medium font */
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   192
	     2,   92, // ' ' till 'z'
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   193
	0xFFFE,   36,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   194
	   160,  160, // Move ¾ to the correct position
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   195
	    98,   98, // Up arrow
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   196
	   131,  133,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   197
	0xFFFE,    1, // skip currency sign
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   198
	   135,  135,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   199
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   200
	   137,  137,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   201
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   202
	   139,  139,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   203
	   140,  140, // TODO Down arrow
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   204
	   141,  141,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   205
	   142,  142, // TODO Check mark
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   206
	   143,  143, // TODO Cross
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   207
	   144,  144,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   208
	   145,  145, // TODO Right arrow
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   209
	   146,  149,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   210
	   118,  122, // Transport markers
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   211
	0xFFFE,    2,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   212
	   157,  157,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   213
	   114,  115, // Small up/down arrows
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   214
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   215
	   161,  225,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   216
/* Small font */
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   217
	   226,  316, // ' ' till 'z'
2408
d86105006ee9 (svn r2934) Remove the {STATIONFEATURES} tag from the tiny station label - there are no tiny transport marker sprites
tron
parents: 2407
diff changeset
   218
	0xFFFE,   36,
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   219
	   384,  384, // Move ¾ to the correct position
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   220
	   322,  322, // Up arrow
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   221
	   355,  357,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   222
	0xFFFE,    1, // skip currency sign
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   223
	   359,  359,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   224
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   225
	   361,  361,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   226
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   227
	   363,  363,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   228
	   364,  364, // TODO Down arrow
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   229
	   365,  366,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   230
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   231
	   368,  368,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   232
	   369,  369, // TODO Right arrow
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   233
	   370,  373,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   234
	0xFFFE,    7,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   235
	   381,  381,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   236
	0xFFFE,    3,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   237
	   385,  449,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   238
/* Big font */
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   239
	   450,  540, // ' ' till 'z'
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   240
	0xFFFE,   36,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   241
	   608,  608, // Move ¾ to the correct position
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   242
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   243
	   579,  581,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   244
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   245
	   583,  583,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   246
	0xFFFE,    5,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   247
	   589,  589,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   248
	0xFFFE,   15,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   249
	   605,  605,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   250
	0xFFFE,    3,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   251
	   609,  625,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   252
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   253
	   627,  632,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   254
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   255
	   634,  639,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   256
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   257
	   641,  657,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   258
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   259
	   659,  664,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   260
	0xFFFE,    2,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   261
	   667,  671,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   262
	0xFFFE,    1,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   263
	   673,  673,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   264
/* Graphics */
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   265
	   674, 4792,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   266
	0xFFFF
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   267
};
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   268
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   269
#define OPENTTD_SPRITES_COUNT 100
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   270
static const SpriteID _openttd_grf_indexes[] = {
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   271
	SPR_OPENTTD_BASE + 0, SPR_OPENTTD_BASE + 7, // icons etc
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   272
	134, 134,  // euro symbol medium size
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   273
	582, 582,  // euro symbol large size
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   274
	358, 358,  // euro symbol tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   275
	SPR_OPENTTD_BASE+11, SPR_OPENTTD_BASE+57, // more icons
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   276
	648, 648, // nordic char: æ
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   277
	616, 616, // nordic char: Æ
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   278
	666, 666, // nordic char: ø
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   279
	634, 634, // nordic char: Ø
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   280
	SPR_OPENTTD_BASE+62, SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT, // more icons
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   281
	382, 383, // ¼ ½ tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   282
	158, 159, // ¼ ½ medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   283
	606, 607, // ¼ ½ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   284
	360, 360, // ¦ tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   285
	362, 362, // ¨ tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   286
	136, 136, // ¦ medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   287
	138, 138, // ¨ medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   288
	584, 584, // ¦ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   289
	586, 586, // ¨ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   290
	626, 626, // Ð large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   291
	658, 658, // ð large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   292
	374, 374, // ´ tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   293
	378, 378, // ¸ tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   294
	150, 150, // ´ medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   295
	154, 154, // ¸ medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   296
	598, 598, // ´ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   297
	602, 602, // ¸ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   298
	640, 640, // Þ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   299
	672, 672, // þ large
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   300
	380, 380, // º tiny
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   301
	156, 156, // º medium
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   302
	604, 604, // º large
2411
a76c0b960e92 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   303
	317, 320, // { | } ~ tiny
a76c0b960e92 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   304
	 93,  96, // { | } ~ medium
a76c0b960e92 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   305
	541, 544, // { | } ~ large
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   306
	0xffff,
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   307
};
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   308
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
   309
static byte _sprite_page_to_load = 0xFF;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
   310
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   311
static void LoadSpriteTables(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
{
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
   313
	uint load_index = 0;
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   314
	uint i;
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   315
	const FileList *files; // list of grf files to be loaded. Either Windows files or DOS files
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   317
	files = _use_dos_palette? &files_dos : &files_win;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   318
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   319
	LoadGrfIndexed(files->basic[0].filename, trg1idx, 0);
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   320
	DupSprite(  2, 130); // non-breaking space medium
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   321
	DupSprite(226, 354); // non-breaking space tiny
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   322
	DupSprite(450, 578); // non-breaking space large
2353
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   323
	load_index = 4793;
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   324
076e9b569f64 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   325
	for (i = 1; files->basic[i].filename != NULL; i++) {
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   326
		load_index += LoadGrfFile(files->basic[i].filename, load_index, i);
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   327
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   329
	if (_sprite_page_to_load != 0) {
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   330
		LoadGrfIndexed(
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   331
			files->landscape[_sprite_page_to_load - 1].filename,
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   332
			_landscape_spriteindexes[_sprite_page_to_load - 1],
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   333
			i++
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   334
		);
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   335
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
2512
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   337
	assert(load_index == SPR_CANALS_BASE);
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   338
	load_index += LoadGrfFile("canalsw.grf", load_index, i++);
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   339
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   340
	assert(load_index == SPR_SLOPES_BASE);
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   341
	LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 1019
diff changeset
   342
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   343
	load_index = SPR_AUTORAIL_BASE;
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   344
	load_index += LoadGrfFile("autorail.grf", load_index, i++);
142
0c2bd172af05 (svn r143) Fix: newgrfs are working again
dominik
parents: 74
diff changeset
   345
2512
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   346
	assert(load_index == SPR_ELRAIL_BASE);
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   347
	load_index += LoadGrfFile("elrailsw.grf", load_index, i++);
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   348
2512
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   349
	assert(load_index == SPR_OPENTTD_BASE);
fa66ff5ebf88 (svn r3038) Reorder the loading of standard graphics files to reflect a bit where in the sprite array the sprites end up and assert, that the indices are equal to the corresponding sprite base enums, to guard against typos.
tron
parents: 2411
diff changeset
   350
	LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
2309
34824a8b336f (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   351
	load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1;
142
0c2bd172af05 (svn r143) Fix: newgrfs are working again
dominik
parents: 74
diff changeset
   352
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
   353
	LoadNewGRF(load_index, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   357
void GfxLoadSprites(void)
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   358
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	// Need to reload the sprites only if the landscape changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	if (_sprite_page_to_load != _opt.landscape) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		_sprite_page_to_load = _opt.landscape;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		// Sprite cache
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
		DEBUG(spritecache, 1) ("Loading sprite set %d.", _sprite_page_to_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
2339
1c64119d5a3b (svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents: 2329
diff changeset
   366
		GfxInitSpriteMem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
		LoadSpriteTables();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		GfxInitPalettes();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
}