src/gfxinit.cpp
author rubidium
Tue, 02 Sep 2008 18:45:15 +0000
changeset 10062 8ec5e3f048b7
parent 10048 a0e67d110e5a
child 10066 f18e97752eeb
permissions -rw-r--r--
(svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8432
diff changeset
     3
/** @file gfxinit.cpp Initializing of the (GRF) graphics. */
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6103
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1844
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1250
diff changeset
     7
#include "debug.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"
10039
1f236afd6cd1 (svn r14199) -Codechange: split fileio.h into fileio_type.h and fileio_func.h so not everything that includes saveload.h needs to include everything else too.
rubidium
parents: 10037
diff changeset
    10
#include "fileio_func.h"
7805
7ab20f94cc80 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 7800
diff changeset
    11
#include "fios.h"
463
97ec66c280f2 (svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents: 452
diff changeset
    12
#include "newgrf.h"
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    13
#include "md5.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2142
diff changeset
    14
#include "variables.h"
5156
771ed0d9f836 (svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents: 5151
diff changeset
    15
#include "fontcache.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    16
#include "gfx_func.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8133
diff changeset
    17
#include "core/alloc_func.hpp"
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8214
diff changeset
    18
#include "core/bitmath_func.hpp"
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    19
#include "core/smallvec_type.hpp"
4472
93758d1da52d (svn r6257) Use memcmp() to check the MD5 sum instead of using a home brewed loop
tron
parents: 4209
diff changeset
    20
#include <string.h>
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    21
#include "settings_type.h"
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    22
#include "string_func.h"
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    23
#include "ini_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8236
diff changeset
    25
#include "table/sprites.h"
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    26
#include "table/palette_convert.h"
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8236
diff changeset
    27
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    28
/** The currently used palette */
9995
7f2dab0093c1 (svn r14152) -Fix (r14146): Apple decided to use a name I wanted to use... thus making compilation fail on OSX (planetmaker)
rubidium
parents: 9994
diff changeset
    29
PaletteType _use_palette = PAL_AUTODETECT;
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    30
/** Whether the given NewGRFs must get a palette remap or not. */
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    31
bool _palette_remap_grf[MAX_FILE_SLOTS];
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    32
/** Palette map to go from the !_use_palette to the _use_palette */
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    33
const byte *_palette_remap = NULL;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    34
/** Palette map to go from the _use_palette to the !_use_palette */
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    35
const byte *_palette_reverse_remap = NULL;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
    36
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    37
char _ini_graphics_set[32];
9989
62e68bd41c90 (svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents: 9470
diff changeset
    38
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    39
/** Structure holding filename and MD5 information about a single file */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    40
struct MD5File {
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    41
	const char *filename;        ///< filename
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    42
	uint8 hash[16];              ///< md5 sum of the file
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    43
	const char *missing_warning; ///< warning when this file is missing
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    44
};
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    45
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    46
/** Types of graphics in the base graphics set */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    47
enum GraphicsFileType {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    48
	GFT_BASE,     ///< Base sprites for all climates
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    49
	GFT_LOGOS,    ///< Logos, landscape icons and original terrain generator sprites
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    50
	GFT_ARCTIC,   ///< Landscape replacement sprites for arctic
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    51
	GFT_TROPICAL, ///< Landscape replacement sprites for tropical
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    52
	GFT_TOYLAND,  ///< Landscape replacement sprites for toyland
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    53
	GFT_EXTRA,    ///< Extra sprites that were not part of the original sprites
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    54
	MAX_GFT       ///< We are looking for this amount of GRFs
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    55
};
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    56
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    57
/** Information about a single graphics set. */
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    58
struct GraphicsSet {
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    59
	const char *name;          ///< The name of the graphics set
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    60
	const char *description;   ///< Description of the graphics set
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    61
	uint32 shortname;          ///< Four letter short variant of the name
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    62
	uint32 version;            ///< The version of this graphics set
9995
7f2dab0093c1 (svn r14152) -Fix (r14146): Apple decided to use a name I wanted to use... thus making compilation fail on OSX (planetmaker)
rubidium
parents: 9994
diff changeset
    63
	PaletteType palette;       ///< Palette of this graphics set
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    64
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    65
	MD5File files[MAX_GFT];    ///< All GRF files part of this set
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    66
	uint found_grfs;           ///< Number of the GRFs that could be found
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    67
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    68
	GraphicsSet *next;         ///< The next graphics set in this list
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    69
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    70
	/** Free everything we allocated */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    71
	~GraphicsSet()
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    72
	{
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    73
		free((void*)this->name);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    74
		free((void*)this->description);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    75
		for (uint i = 0; i < MAX_GFT; i++) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    76
			free((void*)this->files[i].filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    77
			free((void*)this->files[i].missing_warning);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    78
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    79
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    80
		delete this->next;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    81
	}
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    82
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    84
/** All graphics sets currently available */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    85
static GraphicsSet *_available_graphics_sets = NULL;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    86
/** The one and only graphics set that is currently being used. */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
    87
static const GraphicsSet *_used_graphics_set = NULL;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
    88
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
    89
#include "table/files.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
#include "table/landscape_sprite.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    92
static const SpriteID * const _landscape_spriteindexes[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	_landscape_spriteindexes_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	_landscape_spriteindexes_2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	_landscape_spriteindexes_3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
    98
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
    99
{
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
   100
	uint load_index_org = load_index;
6908
6b1324d7a2c9 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 6780
diff changeset
   101
	uint sprite_id = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	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
   104
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   105
	DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
6908
6b1324d7a2c9 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 6780
diff changeset
   107
	while (LoadNextSprite(load_index, file_index, sprite_id)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		load_index++;
6908
6b1324d7a2c9 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 6780
diff changeset
   109
		sprite_id++;
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   110
		if (load_index >= MAX_SPRITES) {
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9436
diff changeset
   111
			usererror("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
   112
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	}
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   114
	DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
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
   116
	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
   117
}
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
   118
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
   119
7772
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   120
void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl)
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   121
{
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   122
	uint start;
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   123
	while ((start = *index_tbl++) != END) {
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   124
		uint end = *index_tbl++;
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   125
8432
19e2849a638c (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents: 8411
diff changeset
   126
		do {
19e2849a638c (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents: 8411
diff changeset
   127
			bool b = LoadNextSprite(start, file_index, *sprite_id);
19e2849a638c (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents: 8411
diff changeset
   128
			assert(b);
19e2849a638c (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents: 8411
diff changeset
   129
			(*sprite_id)++;
19e2849a638c (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents: 8411
diff changeset
   130
		} while (++start <= end);
7772
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   131
	}
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   132
}
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   133
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
   134
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
   135
{
6908
6b1324d7a2c9 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 6780
diff changeset
   136
	uint sprite_id = 0;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   137
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
   138
	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
   139
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   140
	DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
7772
c89384e3f8de (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 7767
diff changeset
   142
	LoadSpritesIndexed(file_index, &sprite_id, index_tbl);
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   143
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   146
/**
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   147
 * Calculate and check the MD5 hash of the supplied filename.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   148
 * @param file filename and expected MD5 hash for the given filename.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   149
 * @return true if the checksum is correct.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   150
 */
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   151
static bool FileMD5(const MD5File file)
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   152
{
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 6917
diff changeset
   153
	size_t size;
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 6917
diff changeset
   154
	FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
5482
0528f1dfb732 (svn r7766) -Fix: [OSX] removed incorrect debug message about corrupted/missing grf files
bjarni
parents: 5475
diff changeset
   155
862
9baf2b0cdb18 (svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents: 614
diff changeset
   156
	if (f != NULL) {
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
   157
		Md5 checksum;
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
   158
		uint8 buffer[1024];
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
   159
		uint8 digest[16];
2028
fff064370a36 (svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents: 2027
diff changeset
   160
		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
   161
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 6917
diff changeset
   162
		while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 6917
diff changeset
   163
			size -= len;
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
   164
			checksum.Append(buffer, len);
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 6917
diff changeset
   165
		}
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   166
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7574
diff changeset
   167
		FioFCloseFile(f);
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   168
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
   169
		checksum.Finish(digest);
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   170
		return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   171
	} else { // file not found
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   172
		return false;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 966
diff changeset
   173
	}
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   174
}
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   175
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   176
/**
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   177
 * Determine the graphics pack that has to be used.
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   178
 * The one with the most correct files wins.
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   179
 */
10048
a0e67d110e5a (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138
parents: 10039
diff changeset
   180
static bool DetermineGraphicsPack()
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   181
{
10048
a0e67d110e5a (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138
parents: 10039
diff changeset
   182
	if (_used_graphics_set != NULL) return true;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   183
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   184
	const GraphicsSet *best = _available_graphics_sets;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   185
	for (const GraphicsSet *c = _available_graphics_sets; c != NULL; c = c->next) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   186
		if (best->found_grfs < c->found_grfs ||
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   187
				(best->found_grfs == c->found_grfs && (
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   188
					(best->shortname == c->shortname && best->version < c->version) ||
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   189
					(best->palette != _use_palette && c->palette == _use_palette)))) {
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   190
			best = c;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   191
		}
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   192
	}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   193
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   194
	_used_graphics_set = best;
10048
a0e67d110e5a (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138
parents: 10039
diff changeset
   195
	return _used_graphics_set != NULL;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   196
}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   197
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   198
/**
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   199
 * Determine the palette that has to be used.
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   200
 *  - forced palette via command line -> leave it that way
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   201
 *  - otherwise -> palette based on the graphics pack
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   202
 */
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   203
static void DeterminePalette()
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   204
{
10048
a0e67d110e5a (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138
parents: 10039
diff changeset
   205
	assert(_used_graphics_set != NULL);
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   206
	if (_use_palette >= MAX_PAL) _use_palette = _used_graphics_set->palette;
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   207
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   208
	switch (_use_palette) {
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   209
		case PAL_DOS:
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   210
			_palette_remap = _palmap_w2d;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   211
			_palette_reverse_remap = _palmap_d2w;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   212
			break;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   213
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   214
		case PAL_WINDOWS:
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   215
			_palette_remap = _palmap_d2w;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   216
			_palette_reverse_remap = _palmap_w2d;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   217
			break;
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   218
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   219
		default:
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   220
			NOT_REACHED();
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   221
	}
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   222
}
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   223
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   224
/**
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   225
 * Checks whether the MD5 checksums of the files are correct.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   226
 *
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   227
 * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   228
 */
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   229
void CheckExternalFiles()
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   230
{
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   231
	DeterminePalette();
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   232
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   233
	DEBUG(grf, 1, "Using the %s base graphics set with the %s palette", _used_graphics_set->name, _use_palette == PAL_DOS ? "DOS" : "Windows");
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   234
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   235
	static const size_t ERROR_MESSAGE_LENGTH = 128;
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   236
	char error_msg[ERROR_MESSAGE_LENGTH * (MAX_GFT + 1)];
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   237
	error_msg[0] = '\0';
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   238
	char *add_pos = error_msg;
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   239
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   240
	for (uint i = 0; i < lengthof(_used_graphics_set->files); i++) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   241
		if (!FileMD5(_used_graphics_set->files[i])) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   242
			add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! %s\n", _used_graphics_set->files[i].filename, _used_graphics_set->files[i].missing_warning);
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   243
		}
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   244
	}
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   245
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   246
	bool sound = false;
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   247
	for (uint i = 0; !sound && i < lengthof(_sound_sets); i++) {
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   248
		sound = FileMD5(_sound_sets[i]);
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   249
	}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   250
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   251
	if (!sound) {
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   252
		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   253
	}
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   254
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   255
	if (add_pos != error_msg) ShowInfoF(error_msg);
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   256
}
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   257
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
   258
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6179
diff changeset
   259
static void LoadSpriteTables()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
{
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   261
	memset(_palette_remap_grf, 0, sizeof(_palette_remap_grf));
7805
7ab20f94cc80 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 7800
diff changeset
   262
	uint i = FIRST_GRF_SLOT;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 579
diff changeset
   263
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   264
	_palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   265
	LoadGrfFile(_used_graphics_set->files[GFT_BASE].filename, 0, i++);
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2342
diff changeset
   266
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   267
	/*
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   268
	 * The second basic file always starts at the given location and does
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   269
	 * contain a different amount of sprites depending on the "type"; DOS
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   270
	 * has a few sprites less. However, we do not care about those missing
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   271
	 * sprites as they are not shown anyway (logos in intro game).
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   272
	 */
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   273
	_palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   274
	LoadGrfFile(_used_graphics_set->files[GFT_LOGOS].filename, 4793, i++);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
7841
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   276
	/*
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   277
	 * Load additional sprites for climates other than temperate.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   278
	 * This overwrites some of the temperate sprites, such as foundations
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   279
	 * and the ground sprites.
8f9ab4f7064b (svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents: 7805
diff changeset
   280
	 */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   281
	if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   282
		_palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   283
		LoadGrfIndexed(
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   284
			_used_graphics_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename,
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   285
			_landscape_spriteindexes[_settings_game.game_creation.landscape - 1],
2309
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   286
			i++
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   287
		);
c48687a02a6c (svn r2833) Remove saving of sprite cache data:
tron
parents: 2305
diff changeset
   288
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
5156
771ed0d9f836 (svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents: 5151
diff changeset
   290
	/* Initialize the unicode to sprite mapping table */
771ed0d9f836 (svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents: 5151
diff changeset
   291
	InitializeUnicodeGlyphMap();
771ed0d9f836 (svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents: 5151
diff changeset
   292
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   293
	/*
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   294
	 * Load the base NewGRF with OTTD required graphics as first NewGRF.
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   295
	 * However, we do not want it to show up in the list of used NewGRFs,
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   296
	 * so we have to manually add it, and then remove it later.
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   297
	 */
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   298
	GRFConfig *top = _grfconfig;
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   299
	GRFConfig *master = CallocT<GRFConfig>(1);
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   300
	master->filename = strdup(_used_graphics_set->files[GFT_EXTRA].filename);
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   301
	FillGRFDetails(master, false);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7882
diff changeset
   302
	ClrBit(master->flags, GCF_INIT_ONLY);
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   303
	master->next = top;
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   304
	_grfconfig = master;
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   305
10062
8ec5e3f048b7 (svn r14229) -Feature: allow overriding the palette of the base GRFs. This way you can play with NewGRFs made for the Windows palette with the DOS palettes base GRFs (and vice versa). Note that for this to work correctly ALL NewGRFs must use the same palette; mix and match is not yet supported.
rubidium
parents: 10048
diff changeset
   306
	_palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   307
	LoadNewGRF(SPR_NEWGRFS_BASE, i);
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   308
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   309
	/* Free and remove the top element. */
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   310
	ClearGRFConfig(&master);
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7841
diff changeset
   311
	_grfconfig = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6179
diff changeset
   315
void GfxLoadSprites()
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
   316
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   317
	DEBUG(sprite, 2, "Loading sprite set %d", _settings_game.game_creation.landscape);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
5151
23150e1b0660 (svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents: 5000
diff changeset
   319
	GfxInitSpriteMem();
23150e1b0660 (svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents: 5000
diff changeset
   320
	LoadSpriteTables();
23150e1b0660 (svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents: 5000
diff changeset
   321
	GfxInitPalettes();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
}
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   323
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   324
/**
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   325
 * Try to read a single piece of metadata and return false if it doesn't exist.
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   326
 * @param name the name of the item to fetch.
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   327
 */
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   328
#define fetch_metadata(name) \
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   329
	item = metadata->GetItem(name, false); \
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   330
	if (item == NULL || strlen(item->value) == 0) { \
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   331
		DEBUG(grf, 0, "Base graphics set detail loading: %s field missing", name); \
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   332
		return false; \
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   333
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   334
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   335
/** Names corresponding to the GraphicsFileType */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   336
static const char *_gft_names[MAX_GFT] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   337
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   338
/**
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   339
 * Read the graphics set information from a loaded ini.
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   340
 * @param graphics the graphics set to write to
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   341
 * @param ini      the ini to read from
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   342
 * @param path     the path to this ini file (for filenames)
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   343
 * @return true if loading was successful.
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   344
 */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   345
static bool FillGraphicsSetDetails(GraphicsSet *graphics, IniFile *ini, const char *path)
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   346
{
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   347
	memset(graphics, 0, sizeof(*graphics));
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   348
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   349
	IniGroup *metadata = ini->GetGroup("metadata");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   350
	IniItem *item;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   351
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   352
	fetch_metadata("name");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   353
	graphics->name = strdup(item->value);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   354
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   355
	fetch_metadata("description");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   356
	graphics->description = strdup(item->value);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   357
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   358
	fetch_metadata("shortname");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   359
	for (uint i = 0; item->value[i] != '\0' && i < 4; i++) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   360
		graphics->shortname |= ((uint8)item->value[i]) << (32 - i * 8);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   361
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   362
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   363
	fetch_metadata("version");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   364
	graphics->version = atoi(item->value);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   365
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   366
	fetch_metadata("palette");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   367
	graphics->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   368
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   369
	/* For each of the graphics file types we want to find the file, MD5 checksums and warning messages. */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   370
	IniGroup *files  = ini->GetGroup("files");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   371
	IniGroup *md5s   = ini->GetGroup("md5s");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   372
	IniGroup *origin = ini->GetGroup("origin");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   373
	for (uint i = 0; i < MAX_GFT; i++) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   374
		MD5File *file = &graphics->files[i];
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   375
		/* Find the filename first. */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   376
		item = files->GetItem(_gft_names[i], false);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   377
		if (item == NULL) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   378
			DEBUG(grf, 0, "No graphics file for: %s", _gft_names[i]);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   379
			return false;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   380
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   381
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   382
		const char *filename = item->value;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   383
		file->filename = MallocT<char>(strlen(filename) + strlen(path) + 1);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   384
		sprintf((char*)file->filename, "%s%s", path, filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   385
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   386
		/* Then find the MD5 checksum */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   387
		item = md5s->GetItem(filename, false);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   388
		if (item == NULL) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   389
			DEBUG(grf, 0, "No MD5 checksum specified for: %s", filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   390
			return false;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   391
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   392
		char *c = item->value;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   393
		for (uint i = 0; i < sizeof(file->hash) * 2; i++, c++) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   394
			uint j;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   395
			if ('0' <= *c && *c <= '9') {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   396
				j = *c - '0';
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   397
			} else if ('a' <= *c && *c <= 'f') {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   398
				j = *c - 'a' + 10;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   399
			} else if ('A' <= *c && *c <= 'F') {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   400
				j = *c - 'A' + 10;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   401
			} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   402
				DEBUG(grf, 0, "Malformed MD5 checksum specified for: %s", filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   403
				return false;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   404
			}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   405
			if (i % 2 == 0) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   406
				file->hash[i / 2] = j << 4;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   407
			} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   408
				file->hash[i / 2] |= j;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   409
			}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   410
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   411
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   412
		/* Then find the warning message when the file's missing */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   413
		item = origin->GetItem(filename, false);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   414
		if (item == NULL) item = origin->GetItem("default", false);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   415
		if (item == NULL) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   416
			DEBUG(grf, 1, "No origin warning message specified for: %s", filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   417
			file->missing_warning = strdup("");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   418
		} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   419
			file->missing_warning = strdup(item->value);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   420
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   421
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   422
		if (FileMD5(*file)) graphics->found_grfs++;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   423
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   424
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   425
	return true;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   426
}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   427
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   428
/** Helper for scanning for files with GRF as extension */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   429
class OBGFileScanner : FileScanner {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   430
public:
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   431
	/* virtual */ bool AddFile(const char *filename, size_t basepath_length);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   432
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   433
	/** Do the scan for OBGs. */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   434
	static uint DoScan()
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   435
	{
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   436
		OBGFileScanner fs;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   437
		return fs.Scan(".obg", DATA_DIR);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   438
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   439
};
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   440
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   441
/**
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   442
 * Try to add a graphics set with the given filename.
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   443
 * @param filename        the full path to the file to read
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   444
 * @param basepath_length amount of characters to chop of before to get a relative DATA_DIR filename
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   445
 * @return true if the file is added.
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   446
 */
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   447
bool OBGFileScanner::AddFile(const char *filename, size_t basepath_length)
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   448
{
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   449
	bool ret = false;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   450
	DEBUG(grf, 1, "Found %s as base graphics set", filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   451
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   452
	GraphicsSet *graphics = new GraphicsSet();;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   453
	IniFile *ini = new IniFile();
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   454
	ini->LoadFromDisk(filename);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   455
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   456
	char *path = strdup(filename + basepath_length);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   457
	char *psep = strrchr(path, PATHSEPCHAR);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   458
	if (psep != NULL) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   459
		psep[1] = '\0';
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   460
	} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   461
		*path = '\0';
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   462
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   463
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   464
	if (FillGraphicsSetDetails(graphics, ini, path)) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   465
		bool duplicate = false;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   466
		for (const GraphicsSet *c = _available_graphics_sets; !duplicate && c != NULL; c = c->next) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   467
			duplicate = (strcmp(c->name, graphics->name) == 0) || (c->shortname == graphics->shortname && c->version == graphics->version);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   468
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   469
		if (duplicate) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   470
			delete graphics;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   471
		} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   472
			graphics->next = _available_graphics_sets;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   473
			_available_graphics_sets = graphics;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   474
			ret = true;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   475
		}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   476
	} else {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   477
		delete graphics;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   478
	}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   479
	free(path);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   480
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   481
	delete ini;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   482
	return ret;
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   483
}
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   484
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   485
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   486
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   487
/** Scan for all Grahpics sets */
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   488
void FindGraphicsSets()
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   489
{
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   490
	DEBUG(grf, 1, "Scanning for Graphics sets");
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   491
	OBGFileScanner::DoScan();
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   492
}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   493
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   494
/**
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   495
 * Set the graphics set to be used.
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   496
 * @param name of the graphics set to use
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   497
 * @return true if it could be loaded
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   498
 */
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   499
bool SetGraphicsSet(const char *name)
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   500
{
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   501
	if (StrEmpty(name)) {
10048
a0e67d110e5a (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138
parents: 10039
diff changeset
   502
		if (!DetermineGraphicsPack()) return false;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   503
		CheckExternalFiles();
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   504
		return true;
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   505
	}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   506
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   507
	for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   508
		if (strcmp(name, g->name) == 0) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   509
			_used_graphics_set = g;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   510
			CheckExternalFiles();
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   511
			return true;
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   512
		}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   513
	}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   514
	return false;
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   515
}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   516
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   517
/**
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   518
 * Returns a list with the graphics sets.
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   519
 * @param p    where to print to
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   520
 * @param last the last character to print to
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   521
 * @return the last printed character
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   522
 */
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   523
char *GetGraphicsSetsList(char *p, const char *last)
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   524
{
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   525
	p += snprintf(p, last - p, "List of graphics sets:\n");
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   526
	for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   527
		if (g->found_grfs <= 1) continue;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   528
10037
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   529
		p += snprintf(p, last - p, "%18s: %s", g->name, g->description);
a06670f961a8 (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium
parents: 9995
diff changeset
   530
		int difference = MAX_GFT - g->found_grfs;
9994
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   531
		if (difference != 0) {
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   532
			p += snprintf(p, last - p, " (missing %i file%s)\n", difference, difference == 1 ? "" : "s");
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   533
		} else {
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   534
			p += snprintf(p, last - p, "\n");
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   535
		}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   536
	}
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   537
	p += snprintf(p, last - p, "\n");
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   538
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   539
	return p;
f9d5859f6aee (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium
parents: 9989
diff changeset
   540
}