gfxinit.c
author bjarni
Sat, 26 Aug 2006 22:28:40 +0000
changeset 4408 db2afc41002a
parent 4209 f0ecce3cb2b0
child 4472 93758d1da52d
permissions -rw-r--r--
(svn r6161) -Feature: List of vehicles with the same shared orders
the list is available in the orders window and looks like the list buttons from the station windows (small vehicle)
The button is disabled if the vehicle do not have any shared orders or it got shared orders, but an empty order list
based on a patch by nycom, thought it ended up getting heavily modified
Thanks to TrueLight for proofreading and suggestions
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (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
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1844
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1250
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (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
e18ef06bc59a (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
15979a2e9001 (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
775a7ee52369 (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"
4200
e6ba94085b81 (svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents: 4059
diff changeset
    12
#include "string.h"
463
97ec66c280f2 (svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents: 452
diff changeset
    13
#include "newgrf.h"
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    14
#include "md5.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2142
diff changeset
    15
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    17
typedef struct MD5File {
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    18
	const char * const filename;     // filename
962
efeee714810e (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
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    20
} MD5File;
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    21
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
    22
typedef struct FileList {
1725
e391da994698 (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
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    24
	const MD5File landscape[3]; // landscape specific grf files
614
b96f987dbf80 (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
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    27
enum {
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    28
	SKIP = 0xFFFE,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    29
	END  = 0xFFFF
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    30
};
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    31
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    32
#include "table/files.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "table/landscape_sprite.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    35
static const SpriteID * const _landscape_spriteindexes[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	_landscape_spriteindexes_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	_landscape_spriteindexes_2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	_landscape_spriteindexes_3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    41
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
    42
	_slopes_spriteindexes_0,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    43
	_slopes_spriteindexes_1,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    44
	_slopes_spriteindexes_2,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    45
	_slopes_spriteindexes_3,
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    46
};
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    47
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    48
2342
aae24c9661ba (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
    49
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
    50
{
2342
aae24c9661ba (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
    51
	uint load_index_org = load_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	FioOpenFile(file_index, filename);
365
957b98a0e1e8 (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
    54
366
05c09e262c8e (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
    55
	DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename);
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
	while (LoadNextSprite(load_index, file_index)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
		load_index++;
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    59
		if (load_index >= MAX_SPRITES) {
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    60
			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
    61
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	}
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    63
	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
    64
365
957b98a0e1e8 (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
	return load_index - load_index_org;
957b98a0e1e8 (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
    66
}
957b98a0e1e8 (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
    67
2342
aae24c9661ba (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
    68
aae24c9661ba (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
    69
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
365
957b98a0e1e8 (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
    70
{
2342
aae24c9661ba (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
    71
	uint start;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
    72
365
957b98a0e1e8 (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
    73
	FioOpenFile(file_index, filename);
957b98a0e1e8 (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
    74
366
05c09e262c8e (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
    75
	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
    76
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    77
	while ((start = *index_tbl++) != END) {
2342
aae24c9661ba (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
    78
		uint end = *index_tbl++;
aae24c9661ba (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
    79
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
    80
		if (start == SKIP) { // 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
    81
			SkipSprites(end);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    82
		} 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
    83
			do {
1844
f1552d831ed5 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    84
			#ifdef NDEBUG
f1552d831ed5 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    85
				LoadNextSprite(start, file_index);
f1552d831ed5 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    86
			#else
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    87
				bool b = LoadNextSprite(start, file_index);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    88
				assert(b);
1844
f1552d831ed5 (svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents: 1725
diff changeset
    89
			#endif
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    90
			} while (++start <= end);
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
    91
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	}
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
    93
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    96
/* Check that the supplied MD5 hash matches that stored for the supplied filename */
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    97
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn)
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    98
{
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
    99
	uint i;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   100
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   101
	/* Loop through each byte of the file MD5 and the stored MD5... */
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   102
	for (i = 0; i < 16; i++) if (file.hash[i] != digest[i]) break;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   103
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   104
		/* If all bytes of the MD5's match (i.e. the MD5's match)... */
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   105
	if (i == 16) {
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   106
		return true;
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   107
	} else {
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   108
		if (warn) fprintf(stderr, "MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename);
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   109
		return false;
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   110
	};
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   111
}
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   112
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   113
/* Calculate and check the MD5 hash of the supplied filename.
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   114
 * returns true if the checksum is correct */
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   115
static bool FileMD5(const MD5File file, bool warn)
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   116
{
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   117
	FILE *f;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   118
	char buf[MAX_PATH];
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   119
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   120
	// open file
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   121
	sprintf(buf, "%s%s", _path.data_dir, file.filename);
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   122
	f = fopen(buf, "rb");
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   123
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   124
#if !defined(WIN32)
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   125
	if (f == NULL) {
4200
e6ba94085b81 (svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents: 4059
diff changeset
   126
		strtolower(buf + strlen(_path.data_dir) - 1);
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   127
		f = fopen(buf, "rb");
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   128
	}
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   129
#endif
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   130
862
9baf2b0cdb18 (svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents: 614
diff changeset
   131
	if (f != NULL) {
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   132
		md5_state_t filemd5state;
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   133
		md5_byte_t buffer[1024];
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   134
		md5_byte_t digest[16];
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   135
		size_t len;
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   136
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   137
		md5_init(&filemd5state);
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   138
		while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0)
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   139
			md5_append(&filemd5state, buffer, len);
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   140
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   141
		if (ferror(f) && warn) fprintf(stderr, "Error Reading from %s \n", buf);
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   142
		fclose(f);
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   143
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   144
		md5_finish(&filemd5state, digest);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2588
diff changeset
   145
		return CheckMD5Digest(file, digest, warn);
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   146
	} else { // file not found
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   147
		return false;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   148
	}
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   149
}
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   150
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   151
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF)
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   152
 * by comparing the MD5 checksums of the files. _use_dos_palette is set accordingly.
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   153
 * If neither are found, Windows palette is assumed.
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   154
 *
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   155
 * (Note: Also checks sample.cat for corruption) */
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   156
void CheckExternalFiles(void)
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   157
{
1355
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   158
	uint i;
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   159
	// count of files from this version
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   160
	uint dos = 0;
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   161
	uint win = 0;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   162
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   163
	for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++;
fff064370a36 (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 < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   165
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   166
	for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++;
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   167
	for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   168
1355
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   169
	if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false))
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   170
		fprintf(stderr, "Your sample.cat file is corrupted or missing!\n");
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   171
1380
72aa0a5df4db (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
	/*
1389
fe967eec43d1 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   173
	 * forced DOS palette via command line -> leave it that way
1380
72aa0a5df4db (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
	 * all Windows files present -> Windows palette
72aa0a5df4db (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
	 * all DOS files present -> DOS palette
72aa0a5df4db (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
	 * no Windows files present and any DOS file present -> DOS palette
72aa0a5df4db (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
   177
	 * otherwise -> Windows palette
72aa0a5df4db (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
   178
	 */
1389
fe967eec43d1 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   179
	if (_use_dos_palette) {
fe967eec43d1 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   180
		return;
fe967eec43d1 (svn r1893) If -i was specified respect it
tron
parents: 1381
diff changeset
   181
	} else if (win == 5) {
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   182
		_use_dos_palette = false;
1381
6cfd0991443d (svn r1885) Fix typo in r1884
tron
parents: 1380
diff changeset
   183
	} else if (dos == 5 || (win == 0 && dos > 0)) {
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   184
		_use_dos_palette = true;
1380
72aa0a5df4db (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
   185
	} else {
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   186
		_use_dos_palette = false;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   187
	}
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   188
}
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   189
2342
aae24c9661ba (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
   190
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   191
static const SpriteID trg1idx[] = {
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   192
	   0,    1, // Mouse cursor, ZZZ
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   193
/* Medium font */
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   194
	   2,   92, // ' ' till 'z'
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   195
	SKIP,   36,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   196
	 160,  160, // Move ¾ to the correct position
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   197
	  98,   98, // Up arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   198
	 131,  133,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   199
	SKIP,    1, // skip currency sign
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   200
	 135,  135,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   201
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   202
	 137,  137,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   203
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   204
	 139,  139,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   205
	 140,  140, // TODO Down arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   206
	 141,  141,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   207
	 142,  142, // TODO Check mark
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   208
	 143,  143, // TODO Cross
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   209
	 144,  144,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   210
	 145,  145, // TODO Right arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   211
	 146,  149,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   212
	 118,  122, // Transport markers
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   213
	SKIP,    2,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   214
	 157,  157,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   215
	 114,  115, // Small up/down arrows
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   216
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   217
	 161,  225,
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   218
/* Small font */
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   219
	 226,  316, // ' ' till 'z'
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   220
	SKIP,   36,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   221
	 384,  384, // Move ¾ to the correct position
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   222
	 322,  322, // Up arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   223
	 355,  357,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   224
	SKIP,    1, // skip currency sign
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   225
	 359,  359,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   226
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   227
	 361,  361,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   228
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   229
	 363,  363,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   230
	 364,  364, // TODO Down arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   231
	 365,  366,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   232
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   233
	 368,  368,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   234
	 369,  369, // TODO Right arrow
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   235
	 370,  373,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   236
	SKIP,    7,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   237
	 381,  381,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   238
	SKIP,    3,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   239
	 385,  449,
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   240
/* Big font */
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   241
	 450,  540, // ' ' till 'z'
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   242
	SKIP,   36,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   243
	 608,  608, // Move ¾ to the correct position
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   244
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   245
	 579,  581,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   246
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   247
	 583,  583,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   248
	SKIP,    5,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   249
	 589,  589,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   250
	SKIP,   15,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   251
	 605,  605,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   252
	SKIP,    3,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   253
	 609,  625,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   254
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   255
	 627,  632,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   256
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   257
	 634,  639,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   258
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   259
	 641,  657,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   260
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   261
	 659,  664,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   262
	SKIP,    2,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   263
	 667,  671,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   264
	SKIP,    1,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   265
	 673,  673,
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   266
/* Graphics */
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   267
	 674, 4792,
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   268
	END
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   269
};
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   270
2565
de04ba1d3a5c (svn r3102) - Fix (regression): Newly added sprite had problems when newgrf's where loaded. Thanks Tron for explaining what the problem was and how it should be solved.
Darkvater
parents: 2559
diff changeset
   271
/* NOTE: When adding a normal sprite, increase OPENTTD_SPRITES_COUNT with the
de04ba1d3a5c (svn r3102) - Fix (regression): Newly added sprite had problems when newgrf's where loaded. Thanks Tron for explaining what the problem was and how it should be solved.
Darkvater
parents: 2559
diff changeset
   272
 * amount of sprites and add them to the end of the list, with the index of
de04ba1d3a5c (svn r3102) - Fix (regression): Newly added sprite had problems when newgrf's where loaded. Thanks Tron for explaining what the problem was and how it should be solved.
Darkvater
parents: 2559
diff changeset
   273
 * the old sprite-count offset from SPR_OPENTTD_BASE. With this there is no
de04ba1d3a5c (svn r3102) - Fix (regression): Newly added sprite had problems when newgrf's where loaded. Thanks Tron for explaining what the problem was and how it should be solved.
Darkvater
parents: 2559
diff changeset
   274
 * correspondence of any kind with the ID's in the grf file, but results in
de04ba1d3a5c (svn r3102) - Fix (regression): Newly added sprite had problems when newgrf's where loaded. Thanks Tron for explaining what the problem was and how it should be solved.
Darkvater
parents: 2559
diff changeset
   275
 * a maximum use of sprite slots. */
2577
e2321aed315f (svn r3114) Close two gaps in the sprite array when loading openttd.grf. That's seven more free sprite slots, yay!
tron
parents: 2571
diff changeset
   276
#define OPENTTD_SPRITES_COUNT 95
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   277
static const SpriteID _openttd_grf_indexes[] = {
2571
550a7d323ced (svn r3108) Confine the use of SPR_OPENTTD_BASE to table/sprites.h by adding/using some sprite enums
tron
parents: 2565
diff changeset
   278
	SPR_IMG_AUTORAIL, SPR_CURSOR_WAYPOINT, // icons etc
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   279
	134, 134,  // euro symbol medium size
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   280
	582, 582,  // euro symbol large size
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   281
	358, 358,  // euro symbol tiny
2571
550a7d323ced (svn r3108) Confine the use of SPR_OPENTTD_BASE to table/sprites.h by adding/using some sprite enums
tron
parents: 2565
diff changeset
   282
	SPR_CURSOR_CANAL, SPR_IMG_FASTFORWARD, // more icons
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   283
	648, 648, // nordic char: æ
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   284
	616, 616, // nordic char: Æ
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   285
	666, 666, // nordic char: ø
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   286
	634, 634, // nordic char: Ø
2571
550a7d323ced (svn r3108) Confine the use of SPR_OPENTTD_BASE to table/sprites.h by adding/using some sprite enums
tron
parents: 2565
diff changeset
   287
	SPR_PIN_UP, SPR_CURSOR_CLONE, // more icons
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   288
	382, 383, // ¼ ½ tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   289
	158, 159, // ¼ ½ medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   290
	606, 607, // ¼ ½ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   291
	360, 360, // ¦ tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   292
	362, 362, // ¨ tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   293
	136, 136, // ¦ medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   294
	138, 138, // ¨ medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   295
	584, 584, // ¦ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   296
	586, 586, // ¨ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   297
	626, 626, // Ð large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   298
	658, 658, // ð large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   299
	374, 374, // ´ tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   300
	378, 378, // ¸ tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   301
	150, 150, // ´ medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   302
	154, 154, // ¸ medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   303
	598, 598, // ´ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   304
	602, 602, // ¸ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   305
	640, 640, // Þ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   306
	672, 672, // þ large
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   307
	380, 380, // º tiny
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   308
	156, 156, // º medium
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   309
	604, 604, // º large
2411
8c239fc63cf7 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   310
	317, 320, // { | } ~ tiny
8c239fc63cf7 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   311
	 93,  96, // { | } ~ medium
8c239fc63cf7 (svn r2937) Add sprites for {, |, } and ~
tron
parents: 2408
diff changeset
   312
	541, 544, // { | } ~ large
2571
550a7d323ced (svn r3108) Confine the use of SPR_OPENTTD_BASE to table/sprites.h by adding/using some sprite enums
tron
parents: 2565
diff changeset
   313
	SPR_HOUSE_ICON, SPR_HOUSE_ICON,
3252
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   314
	585, 585, // § large
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   315
	587, 587, // © large
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   316
	592, 592, // ® large
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   317
	594, 597, // ° ± ² ³ large
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   318
	633, 633, // × large
7e4633d205b4 (svn r3940) - FS#56 [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font.
Darkvater
parents: 3113
diff changeset
   319
	665, 665, // ÷ large
2588
e719db837e8a (svn r3125) Symbolic names for skiping sprites and the end of the sprite list
tron
parents: 2577
diff changeset
   320
	END
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   321
};
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   322
2342
aae24c9661ba (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
   323
static byte _sprite_page_to_load = 0xFF;
aae24c9661ba (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
   324
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   325
static void LoadSpriteTables(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2588
diff changeset
   327
	const FileList* files = _use_dos_palette ? &files_dos : &files_win;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2588
diff changeset
   328
	uint load_index;
1355
fbb8ffafb25a (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   329
	uint i;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   330
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   331
	LoadGrfIndexed(files->basic[0].filename, trg1idx, 0);
2407
6c378ce4d469 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   332
	DupSprite(  2, 130); // non-breaking space medium
6c378ce4d469 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   333
	DupSprite(226, 354); // non-breaking space tiny
6c378ce4d469 (svn r2933) Implement the non-breaking space
tron
parents: 2353
diff changeset
   334
	DupSprite(450, 578); // non-breaking space large
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   335
	load_index = 4793;
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   336
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   337
	for (i = 1; files->basic[i].filename != NULL; i++) {
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   338
		load_index += LoadGrfFile(files->basic[i].filename, load_index, i);
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   339
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   341
	if (_sprite_page_to_load != 0) {
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   342
		LoadGrfIndexed(
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   343
			files->landscape[_sprite_page_to_load - 1].filename,
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   344
			_landscape_spriteindexes[_sprite_page_to_load - 1],
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   345
			i++
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   346
		);
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   347
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
2512
a66b16c61a69 (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_CANALS_BASE);
a66b16c61a69 (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
	load_index += LoadGrfFile("canalsw.grf", load_index, i++);
a66b16c61a69 (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
   351
a66b16c61a69 (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
   352
	assert(load_index == SPR_SLOPES_BASE);
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   353
	LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 1019
diff changeset
   354
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   355
	load_index = SPR_AUTORAIL_BASE;
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   356
	load_index += LoadGrfFile("autorail.grf", load_index, i++);
142
0c2bd172af05 (svn r143) Fix: newgrfs are working again
dominik
parents: 74
diff changeset
   357
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3252
diff changeset
   358
	assert(load_index == SPR_ELRAIL_BASE);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3252
diff changeset
   359
	load_index += LoadGrfFile("elrailsw.grf", load_index, i++);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3252
diff changeset
   360
3113
d79500c648da (svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents: 2639
diff changeset
   361
	assert(load_index == SPR_2CCMAP_BASE);
d79500c648da (svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents: 2639
diff changeset
   362
	load_index += LoadGrfFile("2ccmap.grf", load_index, i++);
d79500c648da (svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents: 2639
diff changeset
   363
2512
a66b16c61a69 (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
   364
	assert(load_index == SPR_OPENTTD_BASE);
a66b16c61a69 (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
   365
	LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
2577
e2321aed315f (svn r3114) Close two gaps in the sprite array when loading openttd.grf. That's seven more free sprite slots, yay!
tron
parents: 2571
diff changeset
   366
	load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT;
142
0c2bd172af05 (svn r143) Fix: newgrfs are working again
dominik
parents: 74
diff changeset
   367
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3355
diff changeset
   368
	assert(load_index == SPR_AIRPORTX_BASE);
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3355
diff changeset
   369
	load_index += LoadGrfFile("airports.grf", load_index, i++);
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3355
diff changeset
   370
2342
aae24c9661ba (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
   371
	LoadNewGRF(load_index, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   375
void GfxLoadSprites(void)
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1070
diff changeset
   376
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	// 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
   378
	if (_sprite_page_to_load != _opt.landscape) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
		_sprite_page_to_load = _opt.landscape;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
		// Sprite cache
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
		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
   383
2339
b03b1fb8ccfe (svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents: 2329
diff changeset
   384
		GfxInitSpriteMem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		LoadSpriteTables();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
		GfxInitPalettes();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
}