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