annotate src/gfxinit.cpp @ 10039:6301378f3e0f draft

(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.
author rubidium <rubidium@openttd.org>
date Sun, 31 Aug 2008 10:50:05 +0000
parents 83d0016c127e
children d9459f6eb49e
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"
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
26
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
27 /** 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
28 PaletteType _use_palette = PAL_AUTODETECT;
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
29 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
30
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
31 /** 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
32 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
33 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
34 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
35 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
36 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
38 /** 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
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 };
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
48
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
49 /** 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
50 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
51 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
52 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
53 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
54 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
55 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
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 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
58 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
59
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
60 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
61
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
62 /** 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
63 ~GraphicsSet()
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 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
66 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
67 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
68 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
69 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
70 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
71
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
72 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
73 }
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
74 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
75
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
76 /** 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
77 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
78 /** 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
79 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
80
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
81 #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
82 #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
83
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
84 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
85 _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
86 _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
87 _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
88 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
89
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
90 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
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 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
93 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
94
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95 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
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 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
98
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
99 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
100 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 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
102 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
103 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
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
106 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
107
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
108 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
109 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
111
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
112 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
113 {
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
114 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
115 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
116 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
117
8432
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
118 do {
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
119 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
120 assert(b);
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
121 (*sprite_id)++;
e802c4a2fa5e (svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138 <peter1138@openttd.org>
parents: 8411
diff changeset
122 } 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
123 }
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 }
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
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
126 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
127 {
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
128 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
129
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
130 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
131
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
132 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
133
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
134 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
135 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
136
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
137
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
138 /**
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
139 * 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
140 * @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
141 * @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
142 */
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
143 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
144 {
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
145 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
146 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
147
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
148 if (f != NULL) {
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
149 Md5 checksum;
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
150 uint8 buffer[1024];
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
151 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
152 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
153
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
154 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
155 size -= len;
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
156 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
157 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158
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
159 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
160
8133
455889a24c77 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13 <skidd13@openttd.org>
parents: 8131
diff changeset
161 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
162 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
163 } 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
164 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
165 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167
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
168 /**
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
169 * 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
170 * 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
171 */
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
172 static void DetermineGraphicsPack()
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
173 {
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
174 if (_used_graphics_set != NULL) return;
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
175
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
176 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
177 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
178 if (best->found_grfs < c->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
179 (best->found_grfs == c->found_grfs && best->shortname == c->shortname && best->version < c->version)) {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
180 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
181 }
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
182 }
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 _used_graphics_set = best;
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
185 }
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
186
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
187 /**
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
188 * 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
189 * - 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
190 * - 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
191 */
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
192 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
193 {
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
194 if (_use_palette < MAX_PAL) return;
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
195
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
196 _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
197 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198
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
199 /**
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
200 * 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
201 *
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
202 * @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
203 */
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 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
205 {
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
206 DetermineGraphicsPack();
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
207 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
208
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
209 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
210 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
211 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
212 char *add_pos = 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
213
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
214 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
215 if (!FileMD5(_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
216 add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! %s\n", _used_graphics_set->files[i].filename, _used_graphics_set->files[i].missing_warning);
7841
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
217 }
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
218 }
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
219
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
220 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
221 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
222 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
223 }
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
224
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
225 if (!sound) {
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
226 add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
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
227 }
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 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
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
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
233 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
234 {
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
235 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
236
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
237 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
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 /*
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
240 * 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
241 * 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
242 * 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
243 * 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
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 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
246
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
247 /*
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 * 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
249 * 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
250 * 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
251 */
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
252 if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
253 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
254 _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
255 _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
256 i++
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
258 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
259
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 /* 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
261 InitializeUnicodeGlyphMap();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262
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
263 /*
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
264 * 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
265 * 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
266 * 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
267 */
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
268 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
269 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
270 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
271 FillGRFDetails(master, false);
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
272 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
273 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
274 _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
275
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
276 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
277
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
278 /* 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
279 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
280 _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
281 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
282
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
284 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
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 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
287
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288 GfxInitSpriteMem();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
289 LoadSpriteTables();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
290 GfxInitPalettes();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
291 }
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
292
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
293 /**
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
294 * 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
295 * @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
296 */
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
297 #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
298 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
299 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
300 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
301 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
302 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
303
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
304 /** 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
305 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
306
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
307 /**
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
308 * 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
309 * @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
310 * @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
311 * @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
312 * @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
313 */
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
314 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
315 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
316 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
317
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
318 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
319 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
320
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
321 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
322 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
323
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
324 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
325 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
326
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
327 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
328 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
329 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
330 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
331
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
332 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
333 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
334
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
335 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
336 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
337
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
338 /* 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
339 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
340 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
341 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
342 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
343 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
344 /* 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
345 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
346 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
347 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
348 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
349 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
350
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
351 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
352 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
353 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
354
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
355 /* 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
356 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
357 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
358 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
359 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
360 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
361 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
362 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
363 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
364 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
365 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
366 } 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
367 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
368 } 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
369 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
370 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
371 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
372 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
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 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
375 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
376 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
377 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
378 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
379 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
380
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
381 /* 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
382 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
383 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
384 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
385 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
386 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
387 } else {
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->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
389 }
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 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
392 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
393
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
394 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
395 }
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 /** 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
398 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
399 public:
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
400 /* 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
401
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
402 /** 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
403 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
404 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
405 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
406 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
407 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
408 };
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 /**
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
411 * 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
412 * @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
413 * @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
414 * @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
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 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
417 {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
418 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
419 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
420
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
421 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
422 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
423 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
424
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
425 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
426 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
427 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
428 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
429 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
430 *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
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 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
434 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
435 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
436 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
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 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
439 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
440 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
441 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
442 _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
443 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
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 } else {
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
446 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
447 }
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
448 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
449
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
450 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
451 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
452 }
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
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
455
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
456 /** 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
457 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
458 {
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
459 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
460 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
461 }
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
462
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
463 /**
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
464 * 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
465 * @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
466 * @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
467 */
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
468 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
469 {
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
470 if (StrEmpty(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
471 DetermineGraphicsPack();
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
472 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
473 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
474 }
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
475
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
476 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
477 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
478 _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
479 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
480 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
481 }
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
482 }
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
483 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
484 }
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
485
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
486 /**
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
487 * 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
488 * @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
489 * @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
490 * @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
491 */
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
492 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
493 {
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 p += snprintf(p, last - p, "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
495 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
496 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
497
10037
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
498 p += snprintf(p, last - p, "%18s: %s", g->name, g->description);
83d0016c127e (svn r14197) -Codechange: rework (original) base graphics determination methods. This yields in the following:
rubidium <rubidium@openttd.org>
parents: 9995
diff changeset
499 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
500 if (difference != 0) {
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 p += snprintf(p, last - p, " (missing %i file%s)\n", difference, difference == 1 ? "" : "s");
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 } else {
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 p += snprintf(p, last - p, "\n");
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 }
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 p += snprintf(p, last - p, "\n");
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
507
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 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
509 }