annotate src/gfxinit.cpp @ 10299:26fd53f1fd8d draft

(svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
author rubidium <rubidium@openttd.org>
date Tue, 28 Oct 2008 14:42:31 +0000
parents 7737958e76ad
children a7c0533f0263
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
9111
d48433370037 (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 <rubidium@openttd.org>
parents: 8432
diff changeset
3 /** @file gfxinit.cpp Initializing of the (GRF) graphics. */
6179
e3e61b92574b (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6103
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #include "debug.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
8 #include "gfxinit.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
9 #include "spritecache.h"
10039
6301378f3e0f (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 <rubidium@openttd.org>
parents: 10037
diff changeset
10 #include "fileio_func.h"
7805
9a2371156469 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium <rubidium@openttd.org>
parents: 7800
diff changeset
11 #include "fios.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "newgrf.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "md5.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
14 #include "variables.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
15 #include "fontcache.h"
8123
c26c28875749 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
16 #include "gfx_func.h"
8213
87c85bb42d6f (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents: 8133
diff changeset
17 #include "core/alloc_func.hpp"
8236
d1191295967a (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
18 #include "core/bitmath_func.hpp"
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
19 #include "core/smallvec_type.hpp"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
20 #include <string.h>
8270
5613b863190d (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents: 8264
diff changeset
21 #include "settings_type.h"
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
22 #include "string_func.h"
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
23 #include "ini_type.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
24
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8236
diff changeset
25 #include "table/sprites.h"
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
26 #include "table/palette_convert.h"
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8236
diff changeset
27
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
28 /** The currently used palette */
9995
a5aaa00e55ae (svn r14152) -Fix (r14146): Apple decided to use a name I wanted to use... thus making compilation fail on OSX (planetmaker)
rubidium <rubidium@openttd.org>
parents: 9994
diff changeset
29 PaletteType _use_palette = PAL_AUTODETECT;
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
30 /** Whether the given NewGRFs must get a palette remap or not. */
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
31 bool _palette_remap_grf[MAX_FILE_SLOTS];
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
32 /** Palette map to go from the !_use_palette to the _use_palette */
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
33 const byte *_palette_remap = NULL;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
34 /** Palette map to go from the _use_palette to the !_use_palette */
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
35 const byte *_palette_reverse_remap = NULL;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
36
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
37 char _ini_graphics_set[32];
9989
10fd2a3a4a1c (svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium <rubidium@openttd.org>
parents: 9470
diff changeset
38
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
39 /** Structure holding filename and MD5 information about a single file */
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
40 struct MD5File {
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
41 const char *filename; ///< filename
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
42 uint8 hash[16]; ///< md5 sum of the file
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
43 const char *missing_warning; ///< warning when this file is missing
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
44 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
45
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
46 /** Types of graphics in the base graphics set */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
47 enum GraphicsFileType {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
48 GFT_BASE, ///< Base sprites for all climates
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
49 GFT_LOGOS, ///< Logos, landscape icons and original terrain generator sprites
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
50 GFT_ARCTIC, ///< Landscape replacement sprites for arctic
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
51 GFT_TROPICAL, ///< Landscape replacement sprites for tropical
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
52 GFT_TOYLAND, ///< Landscape replacement sprites for toyland
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
53 GFT_EXTRA, ///< Extra sprites that were not part of the original sprites
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
54 MAX_GFT ///< We are looking for this amount of GRFs
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
55 };
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
56
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
57 /** Information about a single graphics set. */
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
58 struct GraphicsSet {
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
59 const char *name; ///< The name of the graphics set
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
60 const char *description; ///< Description of the graphics set
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
61 uint32 shortname; ///< Four letter short variant of the name
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
62 uint32 version; ///< The version of this graphics set
9995
a5aaa00e55ae (svn r14152) -Fix (r14146): Apple decided to use a name I wanted to use... thus making compilation fail on OSX (planetmaker)
rubidium <rubidium@openttd.org>
parents: 9994
diff changeset
63 PaletteType palette; ///< Palette of this graphics set
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
64
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
65 MD5File files[MAX_GFT]; ///< All GRF files part of this set
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
66 uint found_grfs; ///< Number of the GRFs that could be found
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
67
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
68 GraphicsSet *next; ///< The next graphics set in this list
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
69
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
70 /** Free everything we allocated */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
71 ~GraphicsSet()
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
72 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
73 free((void*)this->name);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
74 free((void*)this->description);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
75 for (uint i = 0; i < MAX_GFT; i++) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
76 free((void*)this->files[i].filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
77 free((void*)this->files[i].missing_warning);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
78 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
79
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
80 delete this->next;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
81 }
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
82 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
83
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
84 /** All graphics sets currently available */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
85 static GraphicsSet *_available_graphics_sets = NULL;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
86 /** The one and only graphics set that is currently being used. */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
87 static const GraphicsSet *_used_graphics_set = NULL;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
88
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
89 #include "table/files.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
90 #include "table/landscape_sprite.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
91
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
92 static const SpriteID * const _landscape_spriteindexes[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
93 _landscape_spriteindexes_1,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
94 _landscape_spriteindexes_2,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95 _landscape_spriteindexes_3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
96 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
97
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
98 static uint LoadGrfFile(const char *filename, uint load_index, int file_index)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100 uint load_index_org = load_index;
6908
71da5dd33fa4 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight <truelight@openttd.org>
parents: 6780
diff changeset
101 uint sprite_id = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
102
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103 FioOpenFile(file_index, filename);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
104
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
105 DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
106
6908
71da5dd33fa4 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight <truelight@openttd.org>
parents: 6780
diff changeset
107 while (LoadNextSprite(load_index, file_index, sprite_id)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
108 load_index++;
6908
71da5dd33fa4 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight <truelight@openttd.org>
parents: 6780
diff changeset
109 sprite_id++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110 if (load_index >= MAX_SPRITES) {
9470
47924a4b2ad4 (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 <glx@openttd.org>
parents: 9436
diff changeset
111 usererror("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
112 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
113 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
114 DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
116 return load_index - load_index_org;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
117 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
118
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
119
7772
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
120 void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl)
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
121 {
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
122 uint start;
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
123 while ((start = *index_tbl++) != END) {
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
124 uint end = *index_tbl++;
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
125
8432
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
126 do {
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
127 bool b = LoadNextSprite(start, file_index, *sprite_id);
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
128 assert(b);
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
129 (*sprite_id)++;
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
130 } while (++start <= end);
7772
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
131 }
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
132 }
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
133
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
134 static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
135 {
6908
71da5dd33fa4 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight <truelight@openttd.org>
parents: 6780
diff changeset
136 uint sprite_id = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
137
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138 FioOpenFile(file_index, filename);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
139
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
140 DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
141
7772
e14b246ba55c (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7767
diff changeset
142 LoadSpritesIndexed(file_index, &sprite_id, index_tbl);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
143 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
144
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
145
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
146 /**
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
147 * Calculate and check the MD5 hash of the supplied filename.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
148 * @param file filename and expected MD5 hash for the given filename.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
149 * @return true if the checksum is correct.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
150 */
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
151 static bool FileMD5(const MD5File file)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
152 {
7574
62a4ffc139c0 (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 <truelight@openttd.org>
parents: 6917
diff changeset
153 size_t size;
62a4ffc139c0 (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 <truelight@openttd.org>
parents: 6917
diff changeset
154 FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
155
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 if (f != NULL) {
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
157 Md5 checksum;
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
158 uint8 buffer[1024];
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
159 uint8 digest[16];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160 size_t len;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161
7574
62a4ffc139c0 (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 <truelight@openttd.org>
parents: 6917
diff changeset
162 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
62a4ffc139c0 (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 <truelight@openttd.org>
parents: 6917
diff changeset
163 size -= len;
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
164 checksum.Append(buffer, len);
7574
62a4ffc139c0 (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 <truelight@openttd.org>
parents: 6917
diff changeset
165 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166
7592
eb177cee0aa4 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight <truelight@openttd.org>
parents: 7574
diff changeset
167 FioFCloseFile(f);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
169 checksum.Finish(digest);
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
170 return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
171 } else { // file not found
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
173 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
174 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
175
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
176 /**
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
177 * Determine the graphics pack that has to be used.
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
178 * The one with the most correct files wins.
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
179 */
10048
d9459f6eb49e (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138 <peter1138@openttd.org>
parents: 10039
diff changeset
180 static bool DetermineGraphicsPack()
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
181 {
10048
d9459f6eb49e (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138 <peter1138@openttd.org>
parents: 10039
diff changeset
182 if (_used_graphics_set != NULL) return true;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
183
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
184 const GraphicsSet *best = _available_graphics_sets;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
185 for (const GraphicsSet *c = _available_graphics_sets; c != NULL; c = c->next) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
186 if (best->found_grfs < c->found_grfs ||
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
187 (best->found_grfs == c->found_grfs && (
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
188 (best->shortname == c->shortname && best->version < c->version) ||
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
189 (best->palette != _use_palette && c->palette == _use_palette)))) {
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
190 best = c;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
191 }
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
192 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
193
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
194 _used_graphics_set = best;
10048
d9459f6eb49e (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138 <peter1138@openttd.org>
parents: 10039
diff changeset
195 return _used_graphics_set != NULL;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
196 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
197
10077
7737958e76ad (svn r14245) -Fix: NewGRF configs loaded from the config file would always default to the DOS palette instead of the "default" palette.
rubidium <rubidium@openttd.org>
parents: 10066
diff changeset
198 extern void UpdateNewGRFConfigPalette();
7737958e76ad (svn r14245) -Fix: NewGRF configs loaded from the config file would always default to the DOS palette instead of the "default" palette.
rubidium <rubidium@openttd.org>
parents: 10066
diff changeset
199
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
200 /**
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
201 * Determine the palette that has to be used.
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
202 * - forced palette via command line -> leave it that way
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
203 * - otherwise -> palette based on the graphics pack
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
204 */
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
205 static void DeterminePalette()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
206 {
10048
d9459f6eb49e (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138 <peter1138@openttd.org>
parents: 10039
diff changeset
207 assert(_used_graphics_set != NULL);
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
208 if (_use_palette >= MAX_PAL) _use_palette = _used_graphics_set->palette;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
209
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
210 switch (_use_palette) {
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
211 case PAL_DOS:
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
212 _palette_remap = _palmap_w2d;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
213 _palette_reverse_remap = _palmap_d2w;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
214 break;
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
215
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
216 case PAL_WINDOWS:
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
217 _palette_remap = _palmap_d2w;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
218 _palette_reverse_remap = _palmap_w2d;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
219 break;
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
220
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
221 default:
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
222 NOT_REACHED();
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
223 }
10077
7737958e76ad (svn r14245) -Fix: NewGRF configs loaded from the config file would always default to the DOS palette instead of the "default" palette.
rubidium <rubidium@openttd.org>
parents: 10066
diff changeset
224
7737958e76ad (svn r14245) -Fix: NewGRF configs loaded from the config file would always default to the DOS palette instead of the "default" palette.
rubidium <rubidium@openttd.org>
parents: 10066
diff changeset
225 UpdateNewGRFConfigPalette();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
226 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
227
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
228 /**
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
229 * Checks whether the MD5 checksums of the files are correct.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
230 *
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
231 * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
232 */
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
233 void CheckExternalFiles()
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
234 {
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
235 DeterminePalette();
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
236
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
237 DEBUG(grf, 1, "Using the %s base graphics set with the %s palette", _used_graphics_set->name, _use_palette == PAL_DOS ? "DOS" : "Windows");
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
238
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
239 static const size_t ERROR_MESSAGE_LENGTH = 128;
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
240 char error_msg[ERROR_MESSAGE_LENGTH * (MAX_GFT + 1)];
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
241 error_msg[0] = '\0';
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
242 char *add_pos = error_msg;
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
243 const char *last = lastof(error_msg);
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
244
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
245 for (uint i = 0; i < lengthof(_used_graphics_set->files); i++) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
246 if (!FileMD5(_used_graphics_set->files[i])) {
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
247 add_pos += seprintf(add_pos, last, "Your '%s' file is corrupted or missing! %s\n", _used_graphics_set->files[i].filename, _used_graphics_set->files[i].missing_warning);
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
248 }
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
249 }
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
250
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
251 bool sound = false;
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
252 for (uint i = 0; !sound && i < lengthof(_sound_sets); i++) {
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
253 sound = FileMD5(_sound_sets[i]);
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
254 }
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
255
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
256 if (!sound) {
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
257 add_pos += seprintf(add_pos, last, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
258 }
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
259
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
260 if (add_pos != error_msg) ShowInfoF(error_msg);
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
261 }
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
262
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
264 static void LoadSpriteTables()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 {
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
266 memset(_palette_remap_grf, 0, sizeof(_palette_remap_grf));
7805
9a2371156469 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium <rubidium@openttd.org>
parents: 7800
diff changeset
267 uint i = FIRST_GRF_SLOT;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
269 _palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
270 LoadGrfFile(_used_graphics_set->files[GFT_BASE].filename, 0, i++);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
271
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
272 /*
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
273 * The second basic file always starts at the given location and does
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
274 * contain a different amount of sprites depending on the "type"; DOS
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
275 * has a few sprites less. However, we do not care about those missing
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
276 * sprites as they are not shown anyway (logos in intro game).
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
277 */
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
278 _palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
279 LoadGrfFile(_used_graphics_set->files[GFT_LOGOS].filename, 4793, i++);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
280
7841
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
281 /*
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
282 * Load additional sprites for climates other than temperate.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
283 * This overwrites some of the temperate sprites, such as foundations
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
284 * and the ground sprites.
076cd8a1d64c (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 <rubidium@openttd.org>
parents: 7805
diff changeset
285 */
9413
512ea64da840 (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 <rubidium@openttd.org>
parents: 9358
diff changeset
286 if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
10062
fdd9ed12cdc1 (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 <rubidium@openttd.org>
parents: 10048
diff changeset
287 _palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288 LoadGrfIndexed(
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
289 _used_graphics_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename,
9413
512ea64da840 (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 <rubidium@openttd.org>
parents: 9358
diff changeset
290 _landscape_spriteindexes[_settings_game.game_creation.landscape - 1],
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
291 i++
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
292 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
294
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295 /* Initialize the unicode to sprite mapping table */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
296 InitializeUnicodeGlyphMap();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
297
7882
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
298 /*
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
299 * Load the base NewGRF with OTTD required graphics as first NewGRF.
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
300 * However, we do not want it to show up in the list of used NewGRFs,
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
301 * so we have to manually add it, and then remove it later.
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
302 */
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
303 GRFConfig *top = _grfconfig;
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
304 GRFConfig *master = CallocT<GRFConfig>(1);
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
305 master->filename = strdup(_used_graphics_set->files[GFT_EXTRA].filename);
7882
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
306 FillGRFDetails(master, false);
10066
42653fe231a2 (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium <rubidium@openttd.org>
parents: 10062
diff changeset
307 master->windows_paletted = (_used_graphics_set->palette == PAL_WINDOWS);
7929
4d13dbed828c (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7882
diff changeset
308 ClrBit(master->flags, GCF_INIT_ONLY);
7882
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
309 master->next = top;
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
310 _grfconfig = master;
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
311
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
312 LoadNewGRF(SPR_NEWGRFS_BASE, i);
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
313
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
314 /* Free and remove the top element. */
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
315 ClearGRFConfig(&master);
3cf133973d26 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium <rubidium@openttd.org>
parents: 7841
diff changeset
316 _grfconfig = top;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
317 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
318
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
319
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
320 void GfxLoadSprites()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
321 {
9413
512ea64da840 (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 <rubidium@openttd.org>
parents: 9358
diff changeset
322 DEBUG(sprite, 2, "Loading sprite set %d", _settings_game.game_creation.landscape);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
323
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
324 GfxInitSpriteMem();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
325 LoadSpriteTables();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
326 GfxInitPalettes();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
327 }
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
328
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
329 /**
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
330 * Try to read a single piece of metadata and return false if it doesn't exist.
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
331 * @param name the name of the item to fetch.
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
332 */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
333 #define fetch_metadata(name) \
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
334 item = metadata->GetItem(name, false); \
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
335 if (item == NULL || strlen(item->value) == 0) { \
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
336 DEBUG(grf, 0, "Base graphics set detail loading: %s field missing", name); \
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
337 return false; \
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
338 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
339
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
340 /** Names corresponding to the GraphicsFileType */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
341 static const char *_gft_names[MAX_GFT] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
342
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
343 /**
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
344 * Read the graphics set information from a loaded ini.
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
345 * @param graphics the graphics set to write to
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
346 * @param ini the ini to read from
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
347 * @param path the path to this ini file (for filenames)
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
348 * @return true if loading was successful.
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
349 */
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
350 static bool FillGraphicsSetDetails(GraphicsSet *graphics, IniFile *ini, const char *path)
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
351 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
352 memset(graphics, 0, sizeof(*graphics));
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
353
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
354 IniGroup *metadata = ini->GetGroup("metadata");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
355 IniItem *item;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
356
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
357 fetch_metadata("name");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
358 graphics->name = strdup(item->value);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
359
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
360 fetch_metadata("description");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
361 graphics->description = strdup(item->value);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
362
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
363 fetch_metadata("shortname");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
364 for (uint i = 0; item->value[i] != '\0' && i < 4; i++) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
365 graphics->shortname |= ((uint8)item->value[i]) << (32 - i * 8);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
366 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
367
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
368 fetch_metadata("version");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
369 graphics->version = atoi(item->value);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
370
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
371 fetch_metadata("palette");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
372 graphics->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
373
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
374 /* For each of the graphics file types we want to find the file, MD5 checksums and warning messages. */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
375 IniGroup *files = ini->GetGroup("files");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
376 IniGroup *md5s = ini->GetGroup("md5s");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
377 IniGroup *origin = ini->GetGroup("origin");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
378 for (uint i = 0; i < MAX_GFT; i++) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
379 MD5File *file = &graphics->files[i];
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
380 /* Find the filename first. */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
381 item = files->GetItem(_gft_names[i], false);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
382 if (item == NULL) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
383 DEBUG(grf, 0, "No graphics file for: %s", _gft_names[i]);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
384 return false;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
385 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
386
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
387 const char *filename = item->value;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
388 file->filename = MallocT<char>(strlen(filename) + strlen(path) + 1);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
389 sprintf((char*)file->filename, "%s%s", path, filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
390
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
391 /* Then find the MD5 checksum */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
392 item = md5s->GetItem(filename, false);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
393 if (item == NULL) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
394 DEBUG(grf, 0, "No MD5 checksum specified for: %s", filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
395 return false;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
396 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
397 char *c = item->value;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
398 for (uint i = 0; i < sizeof(file->hash) * 2; i++, c++) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
399 uint j;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
400 if ('0' <= *c && *c <= '9') {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
401 j = *c - '0';
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
402 } else if ('a' <= *c && *c <= 'f') {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
403 j = *c - 'a' + 10;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
404 } else if ('A' <= *c && *c <= 'F') {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
405 j = *c - 'A' + 10;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
406 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
407 DEBUG(grf, 0, "Malformed MD5 checksum specified for: %s", filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
408 return false;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
409 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
410 if (i % 2 == 0) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
411 file->hash[i / 2] = j << 4;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
412 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
413 file->hash[i / 2] |= j;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
414 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
415 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
416
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
417 /* Then find the warning message when the file's missing */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
418 item = origin->GetItem(filename, false);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
419 if (item == NULL) item = origin->GetItem("default", false);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
420 if (item == NULL) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
421 DEBUG(grf, 1, "No origin warning message specified for: %s", filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
422 file->missing_warning = strdup("");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
423 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
424 file->missing_warning = strdup(item->value);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
425 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
426
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
427 if (FileMD5(*file)) graphics->found_grfs++;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
428 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
429
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
430 return true;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
431 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
432
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
433 /** Helper for scanning for files with GRF as extension */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
434 class OBGFileScanner : FileScanner {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
435 public:
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
436 /* virtual */ bool AddFile(const char *filename, size_t basepath_length);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
437
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
438 /** Do the scan for OBGs. */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
439 static uint DoScan()
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
440 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
441 OBGFileScanner fs;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
442 return fs.Scan(".obg", DATA_DIR);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
443 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
444 };
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
445
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
446 /**
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
447 * Try to add a graphics set with the given filename.
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
448 * @param filename the full path to the file to read
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
449 * @param basepath_length amount of characters to chop of before to get a relative DATA_DIR filename
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
450 * @return true if the file is added.
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
451 */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
452 bool OBGFileScanner::AddFile(const char *filename, size_t basepath_length)
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
453 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
454 bool ret = false;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
455 DEBUG(grf, 1, "Found %s as base graphics set", filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
456
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
457 GraphicsSet *graphics = new GraphicsSet();;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
458 IniFile *ini = new IniFile();
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
459 ini->LoadFromDisk(filename);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
460
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
461 char *path = strdup(filename + basepath_length);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
462 char *psep = strrchr(path, PATHSEPCHAR);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
463 if (psep != NULL) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
464 psep[1] = '\0';
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
465 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
466 *path = '\0';
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
467 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
468
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
469 if (FillGraphicsSetDetails(graphics, ini, path)) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
470 bool duplicate = false;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
471 for (const GraphicsSet *c = _available_graphics_sets; !duplicate && c != NULL; c = c->next) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
472 duplicate = (strcmp(c->name, graphics->name) == 0) || (c->shortname == graphics->shortname && c->version == graphics->version);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
473 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
474 if (duplicate) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
475 delete graphics;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
476 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
477 graphics->next = _available_graphics_sets;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
478 _available_graphics_sets = graphics;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
479 ret = true;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
480 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
481 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
482 delete graphics;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
483 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
484 free(path);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
485
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
486 delete ini;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
487 return ret;
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
488 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
489
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
490
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
491
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
492 /** Scan for all Grahpics sets */
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
493 void FindGraphicsSets()
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
494 {
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
495 DEBUG(grf, 1, "Scanning for Graphics sets");
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
496 OBGFileScanner::DoScan();
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
497 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
498
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
499 /**
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
500 * Set the graphics set to be used.
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
501 * @param name of the graphics set to use
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
502 * @return true if it could be loaded
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
503 */
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
504 bool SetGraphicsSet(const char *name)
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
505 {
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
506 if (StrEmpty(name)) {
10048
d9459f6eb49e (svn r14208) -Fix (r14197): Crash if no .obg files are found.
peter1138 <peter1138@openttd.org>
parents: 10039
diff changeset
507 if (!DetermineGraphicsPack()) return false;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
508 CheckExternalFiles();
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
509 return true;
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
510 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
511
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
512 for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
513 if (strcmp(name, g->name) == 0) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
514 _used_graphics_set = g;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
515 CheckExternalFiles();
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
516 return true;
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
517 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
518 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
519 return false;
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
520 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
521
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
522 /**
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
523 * Returns a list with the graphics sets.
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
524 * @param p where to print to
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
525 * @param last the last character to print to
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
526 * @return the last printed character
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
527 */
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
528 char *GetGraphicsSetsList(char *p, const char *last)
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
529 {
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
530 p += seprintf(p, last, "List of graphics sets:\n");
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
531 for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
532 if (g->found_grfs <= 1) continue;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
533
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
534 p += seprintf(p, last, "%18s: %s", g->name, g->description);
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
535 int difference = MAX_GFT - g->found_grfs;
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
536 if (difference != 0) {
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
537 p += seprintf(p, last, " (missing %i file%s)\n", difference, difference == 1 ? "" : "s");
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
538 } else {
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
539 p += seprintf(p, last, "\n");
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
540 }
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
541 }
10299
26fd53f1fd8d (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium <rubidium@openttd.org>
parents: 10077
diff changeset
542 p += seprintf(p, last, "\n");
9994
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
543
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
544 return p;
4687a554c837 (svn r14151) -Codechange: make it possible to choose between the DOS and Windows graphics packs while retaining the possibility to override the palette.
rubidium <rubidium@openttd.org>
parents: 9989
diff changeset
545 }