author | smatz |
Tue, 03 Jun 2008 18:35:58 +0000 | |
changeset 9457 | 75f11a6caef8 |
parent 9428 | 1ba05b499957 |
child 9581 | 0d8f232e1721 |
permissions | -rw-r--r-- |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8592
diff
changeset
|
3 |
/** @file newgrf_config.cpp Finding NewGRFs and configuring them. */ |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
4 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
7 |
#include "debug.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
8 |
#include "variables.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
9 |
#include "saveload.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
10 |
#include "md5.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
11 |
#include "newgrf.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
12 |
#include "newgrf_config.h" |
8213
7bdd7593eb9b
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8133
diff
changeset
|
13 |
#include "core/alloc_func.hpp" |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8213
diff
changeset
|
14 |
#include "string_func.h" |
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9428
diff
changeset
|
15 |
#include "gamelog.h" |
9428
1ba05b499957
(svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents:
9146
diff
changeset
|
16 |
#include "network/network_type.h" |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
17 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
18 |
#include "fileio.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
19 |
#include "fios.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
20 |
#include <sys/stat.h> |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
21 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
22 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
23 |
GRFConfig *_all_grfs; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
24 |
GRFConfig *_grfconfig; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
25 |
GRFConfig *_grfconfig_newgame; |
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
26 |
GRFConfig *_grfconfig_static; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
27 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
28 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
29 |
/* Calculate the MD5 Sum for a GRF */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
30 |
static bool CalcGRFMD5Sum(GRFConfig *config) |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
31 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
32 |
FILE *f; |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8131
diff
changeset
|
33 |
Md5 checksum; |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8131
diff
changeset
|
34 |
uint8 buffer[1024]; |
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:
7573
diff
changeset
|
35 |
size_t len, size; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
36 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
37 |
/* open the file */ |
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:
7573
diff
changeset
|
38 |
f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
39 |
if (f == NULL) return false; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
40 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
41 |
/* calculate md5sum */ |
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:
7573
diff
changeset
|
42 |
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:
7573
diff
changeset
|
43 |
size -= len; |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8131
diff
changeset
|
44 |
checksum.Append(buffer, len); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
45 |
} |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8131
diff
changeset
|
46 |
checksum.Finish(config->md5sum); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
47 |
|
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:
7586
diff
changeset
|
48 |
FioFCloseFile(f); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
49 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
50 |
return true; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
51 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
52 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
53 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
54 |
/* Find the GRFID and calculate the md5sum */ |
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
55 |
bool FillGRFDetails(GRFConfig *config, bool is_static) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
56 |
{ |
7034
e2d80a01d9c1
(svn r10298) -Fix [FS#903]: show the subdirectory below the default data directory in this filename in the newgrf list. The directory was removed in r9560 because then it used to full path instead of the path relative to the data directory, but since the inclusion of "search paths" that is not necessary anymore.
rubidium
parents:
6967
diff
changeset
|
57 |
if (!FioCheckFileExists(config->filename)) { |
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
58 |
config->status = GCS_NOT_FOUND; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
59 |
return false; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
60 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
61 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
62 |
/* Find and load the Action 8 information */ |
7805
7ab20f94cc80
(svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents:
7649
diff
changeset
|
63 |
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
64 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
65 |
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */ |
7882
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
66 |
if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
67 |
|
5502
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
68 |
if (is_static) { |
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
69 |
/* Perform a 'safety scan' for static GRFs */ |
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
70 |
LoadNewGRFFile(config, 62, GLS_SAFETYSCAN); |
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
71 |
|
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
72 |
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7882
diff
changeset
|
73 |
if (HasBit(config->flags, GCF_UNSAFE)) return false; |
5502
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
74 |
} |
003b36599ff8
(svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents:
5475
diff
changeset
|
75 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
76 |
return CalcGRFMD5Sum(config); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
77 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
78 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
79 |
|
5346
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
80 |
void ClearGRFConfig(GRFConfig **config) |
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
81 |
{ |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
82 |
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7882
diff
changeset
|
83 |
if (!HasBit((*config)->flags, GCF_COPY)) { |
5346
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
84 |
free((*config)->filename); |
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
85 |
free((*config)->name); |
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
86 |
free((*config)->info); |
6873
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
87 |
|
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
88 |
if ((*config)->error != NULL) { |
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
89 |
free((*config)->error->custom_message); |
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
90 |
free((*config)->error->data); |
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
91 |
free((*config)->error); |
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
92 |
} |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
93 |
} |
5346
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
94 |
free(*config); |
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
95 |
*config = NULL; |
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
96 |
} |
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
97 |
|
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
98 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
99 |
/* Clear a GRF Config list */ |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
100 |
void ClearGRFConfigList(GRFConfig **config) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
101 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
102 |
GRFConfig *c, *next; |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
103 |
for (c = *config; c != NULL; c = next) { |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
104 |
next = c->next; |
5346
3687c73bc65b
(svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents:
5339
diff
changeset
|
105 |
ClearGRFConfig(&c); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
106 |
} |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
107 |
*config = NULL; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
108 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
109 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
110 |
|
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
111 |
/** Copy a GRF Config list |
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
112 |
* @param dst pointer to destination list |
6073
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
113 |
* @param src pointer to source list values |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6929
diff
changeset
|
114 |
* @param init_only the copied GRF will be processed up to GLS_INIT |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
115 |
* @return pointer to the last value added to the destination list */ |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6929
diff
changeset
|
116 |
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
117 |
{ |
5351
c83b547490f0
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
118 |
/* Clear destination as it will be overwritten */ |
c83b547490f0
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
119 |
ClearGRFConfigList(dst); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
120 |
for (; src != NULL; src = src->next) { |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
121 |
GRFConfig *c = CallocT<GRFConfig>(1); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
122 |
*c = *src; |
6424
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
123 |
if (src->filename != NULL) c->filename = strdup(src->filename); |
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
124 |
if (src->name != NULL) c->name = strdup(src->name); |
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
125 |
if (src->info != NULL) c->info = strdup(src->info); |
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
126 |
if (src->error != NULL) { |
6139
cd42df0c1f0f
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6108
diff
changeset
|
127 |
c->error = CallocT<GRFError>(1); |
cd42df0c1f0f
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6108
diff
changeset
|
128 |
memcpy(c->error, src->error, sizeof(GRFError)); |
6873
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
129 |
if (src->error->data != NULL) c->error->data = strdup(src->error->data); |
b4d0648edd29
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
6834
diff
changeset
|
130 |
if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message); |
6139
cd42df0c1f0f
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6108
diff
changeset
|
131 |
} |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
132 |
|
7929
6c9b25842b0f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
133 |
ClrBit(c->flags, GCF_INIT_ONLY); |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
134 |
if (init_only) SetBit(c->flags, GCF_INIT_ONLY); |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6929
diff
changeset
|
135 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
136 |
*dst = c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
137 |
dst = &c->next; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
138 |
} |
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
139 |
|
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
140 |
return dst; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
141 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
142 |
|
5393
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
143 |
/** |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
144 |
* Removes duplicates from lists of GRFConfigs. These duplicates |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
145 |
* are introduced when the _grfconfig_static GRFs are appended |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
146 |
* to the _grfconfig on a newgame or savegame. As the parameters |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
147 |
* of the static GRFs could be different that the parameters of |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
148 |
* the ones used non-statically. This can result in desyncs in |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
149 |
* multiplayers, so the duplicate static GRFs have to be removed. |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
150 |
* |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
151 |
* This function _assumes_ that all static GRFs are placed after |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
152 |
* the non-static GRFs. |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
153 |
* |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
154 |
* @param list the list to remove the duplicates from |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
155 |
*/ |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
156 |
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list) |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
157 |
{ |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
158 |
GRFConfig *prev; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
159 |
GRFConfig *cur; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
160 |
|
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
161 |
if (list == NULL) return; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
162 |
|
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
163 |
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) { |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
164 |
if (cur->grfid != list->grfid) continue; |
5675
bbc57cf5cf18
(svn r8135) -Fix (r7582): Don't assert on duplicate non-static grfs when removing duplicates as the PEBKAC effect can result in the user adding the same grf's in the config file.
Darkvater
parents:
5652
diff
changeset
|
165 |
|
5393
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
166 |
prev->next = cur->next; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
167 |
ClearGRFConfig(&cur); |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
168 |
cur = prev; // Just go back one so it continues as normal later on |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
169 |
} |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
170 |
|
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
171 |
RemoveDuplicatesFromGRFConfigList(list->next); |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
172 |
} |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
173 |
|
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
174 |
/** |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
175 |
* Appends the static GRFs to a list of GRFs |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
176 |
* @param dst the head of the list to add to |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
177 |
*/ |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
178 |
void AppendStaticGRFConfigs(GRFConfig **dst) |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
179 |
{ |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
180 |
GRFConfig **tail = dst; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
181 |
while (*tail != NULL) tail = &(*tail)->next; |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
182 |
|
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6929
diff
changeset
|
183 |
CopyGRFConfigList(tail, _grfconfig_static, false); |
5393
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
184 |
RemoveDuplicatesFromGRFConfigList(*dst); |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
185 |
} |
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
186 |
|
6073
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
187 |
/** Appends an element to a list of GRFs |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6425
diff
changeset
|
188 |
* @param dst the head of the list to add to |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6425
diff
changeset
|
189 |
* @param el the new tail to be */ |
6108
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
190 |
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el) |
6073
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
191 |
{ |
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
192 |
GRFConfig **tail = dst; |
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
193 |
while (*tail != NULL) tail = &(*tail)->next; |
6108
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
194 |
*tail = el; |
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
195 |
|
6073
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
196 |
RemoveDuplicatesFromGRFConfigList(*dst); |
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
197 |
} |
0fb2bb966428
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents:
5765
diff
changeset
|
198 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
199 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
200 |
/* Reset the current GRF Config to either blank or newgame settings */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
201 |
void ResetGRFConfig(bool defaults) |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
202 |
{ |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6929
diff
changeset
|
203 |
CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults); |
5393
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
204 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
205 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
206 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
207 |
|
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
208 |
/** Check if all GRFs in the GRF config from a savegame can be loaded. |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
209 |
* @return will return any of the following 3 values:<br> |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
210 |
* <ul> |
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
211 |
* <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded |
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
212 |
* <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a |
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
213 |
* compatible GRF with the same grfid was found and used instead |
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
214 |
* <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all |
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
215 |
* </ul> */ |
6247 | 216 |
GRFListCompatibility IsGoodGRFConfigList() |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
217 |
{ |
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
218 |
GRFListCompatibility res = GLC_ALL_GOOD; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
219 |
|
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
220 |
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
221 |
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
222 |
if (f == NULL) { |
5652 | 223 |
char buf[256]; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
224 |
|
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
225 |
/* If we have not found the exactly matching GRF try to find one with the |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
226 |
* same grfid, as it most likely is compatible */ |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
227 |
f = FindGRFConfig(c->grfid); |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
228 |
if (f != NULL) { |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
229 |
md5sumToString(buf, lastof(buf), c->md5sum); |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
230 |
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf); |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
231 |
SetBit(c->flags, GCF_COMPATIBLE); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
232 |
|
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
233 |
/* Non-found has precedence over compatibility load */ |
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
234 |
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE; |
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9428
diff
changeset
|
235 |
GamelogGRFCompatible(f); |
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
236 |
goto compatible_grf; |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
237 |
} |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
238 |
|
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
239 |
/* No compatible grf was found, mark it as disabled */ |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
240 |
md5sumToString(buf, lastof(buf), c->md5sum); |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
241 |
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf); |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
242 |
|
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9428
diff
changeset
|
243 |
GamelogGRFRemove(c->grfid); |
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9428
diff
changeset
|
244 |
|
6229
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
245 |
c->status = GCS_NOT_FOUND; |
695400602ab0
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6183
diff
changeset
|
246 |
res = GLC_NOT_FOUND; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
247 |
} else { |
5647
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
248 |
compatible_grf: |
9a96d72c23be
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents:
5646
diff
changeset
|
249 |
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename); |
5349
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
250 |
/* The filename could be the filename as in the savegame. As we need |
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
251 |
* to load the GRF here, we need the correct filename, so overwrite that |
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
252 |
* in any case and set the name and info when it is not set already. |
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
253 |
* When the GCF_COPY flag is set, it is certain that the filename is |
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
254 |
* already a local one, so there is no need to replace it. */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7882
diff
changeset
|
255 |
if (!HasBit(c->flags, GCF_COPY)) { |
5349
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
256 |
free(c->filename); |
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
257 |
c->filename = strdup(f->filename); |
5701
fdb25177500c
(svn r8165) -Revert r8107 and show the MD5SUM of the *REPLACEMENT* grf file, NOT the original one. Reason for this is that this md5sum is saved, and otherwise a wrong md5sum would be stored in a savegame.
Darkvater
parents:
5675
diff
changeset
|
258 |
memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum)); |
6183
59fa5aa7ea3a
(svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents:
6139
diff
changeset
|
259 |
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name); |
59fa5aa7ea3a
(svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents:
6139
diff
changeset
|
260 |
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info); |
6103
d38163ddfef9
(svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents:
6088
diff
changeset
|
261 |
c->error = NULL; |
5349
5e39937d6247
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
262 |
} |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
263 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
264 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
265 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
266 |
return res; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
267 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
268 |
|
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
269 |
static bool ScanPathAddGrf(const char *filename) |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
270 |
{ |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
271 |
GRFConfig *c = CallocT<GRFConfig>(1); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
272 |
c->filename = strdup(filename); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
273 |
|
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
274 |
bool added = true; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
275 |
if (FillGRFDetails(c, false)) { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
276 |
if (_all_grfs == NULL) { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
277 |
_all_grfs = c; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
278 |
} else { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
279 |
/* Insert file into list at a position determined by its |
8592 | 280 |
* name, so the list is sorted as we go along */ |
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
281 |
GRFConfig **pd, *d; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
282 |
bool stop = false; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
283 |
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
284 |
if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
285 |
/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, |
7573
505e9d05c10a
(svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents:
7572
diff
changeset
|
286 |
* before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of |
505e9d05c10a
(svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents:
7572
diff
changeset
|
287 |
* just after the first with the same name. Avoids doubles in the list. */ |
8592 | 288 |
if (strcasecmp(c->name, d->name) <= 0) { |
289 |
stop = true; |
|
290 |
} else if (stop) { |
|
291 |
break; |
|
292 |
} |
|
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
293 |
} |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
294 |
if (added) { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
295 |
c->next = d; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
296 |
*pd = c; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
297 |
} |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
298 |
} |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
299 |
} else { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
300 |
added = false; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
301 |
} |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
302 |
|
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
303 |
if (!added) { |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
304 |
/* File couldn't be opened, or is either not a NewGRF or is a |
8592 | 305 |
* 'system' NewGRF or it's already known, so forget about it. */ |
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
306 |
free(c->filename); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
307 |
free(c->name); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
308 |
free(c->info); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
309 |
free(c); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
310 |
} |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
311 |
|
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
312 |
return added; |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
313 |
} |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
314 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
315 |
/* Scan a path for NewGRFs */ |
9146
dbe2317185eb
(svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents:
9133
diff
changeset
|
316 |
static uint ScanPath(const char *path, size_t basepath_length) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
317 |
{ |
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
318 |
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
319 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
320 |
uint num = 0; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
321 |
struct stat sb; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
322 |
struct dirent *dirent; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
323 |
DIR *dir; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
324 |
|
6424
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
325 |
if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
326 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
327 |
while ((dirent = readdir(dir)) != NULL) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
328 |
const char *d_name = FS2OTTD(dirent->d_name); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
329 |
char filename[MAX_PATH]; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
330 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
331 |
if (!FiosIsValidFile(path, dirent, &sb)) continue; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
332 |
|
6424
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
333 |
snprintf(filename, lengthof(filename), "%s%s", path, d_name); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
334 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
335 |
if (sb.st_mode & S_IFDIR) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
336 |
/* Directory */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
337 |
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; |
6424
d410d4c31d15
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6409
diff
changeset
|
338 |
AppendPathSeparator(filename, lengthof(filename)); |
6834
7a64c73d5f45
(svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents:
6481
diff
changeset
|
339 |
num += ScanPath(filename, basepath_length); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
340 |
} else if (sb.st_mode & S_IFREG) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
341 |
/* File */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
342 |
char *ext = strrchr(filename, '.'); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
343 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
344 |
/* If no extension or extension isn't .grf, skip the file */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
345 |
if (ext == NULL) continue; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
346 |
if (strcasecmp(ext, ".grf") != 0) continue; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
347 |
|
7572
817d4302228e
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
7571
diff
changeset
|
348 |
if (ScanPathAddGrf(filename + basepath_length)) num++; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
349 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
350 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
351 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
352 |
closedir(dir); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
353 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
354 |
return num; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
355 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
356 |
|
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:
7586
diff
changeset
|
357 |
static uint ScanTar(TarFileList::iterator tar) |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
358 |
{ |
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:
7586
diff
changeset
|
359 |
uint num = 0; |
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:
7586
diff
changeset
|
360 |
const char *filename = (*tar).first.c_str(); |
7586
efc1a25de95e
(svn r11111) -Fix (r11106): missing const broke compilation with MSVC
glx
parents:
7581
diff
changeset
|
361 |
const char *ext = strrchr(filename, '.'); |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
362 |
|
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
363 |
/* If no extension or extension isn't .grf, skip the file */ |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
364 |
if (ext == NULL) return false; |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
365 |
if (strcasecmp(ext, ".grf") != 0) return false; |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
366 |
|
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:
7586
diff
changeset
|
367 |
if (ScanPathAddGrf(filename)) num++; |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
368 |
|
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
369 |
return num; |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
370 |
} |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
371 |
|
7644
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
372 |
/** |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
373 |
* Simple sorter for GRFS |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
374 |
* @param p1 the first GRFConfig * |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
375 |
* @param p2 the second GRFConfig * |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
376 |
* @return the same strcmp would return for the name of the NewGRF. |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
377 |
*/ |
7648
c3f25e9f71e4
(svn r11179) -Fix [FS#1262] (r11175): compilation with MSVC was broken
glx
parents:
7644
diff
changeset
|
378 |
static int CDECL GRFSorter(const void *p1, const void *p2) |
7644
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
379 |
{ |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
380 |
const GRFConfig *c1 = *(const GRFConfig **)p1; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
381 |
const GRFConfig *c2 = *(const GRFConfig **)p2; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
382 |
|
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
383 |
return strcmp(c1->name != NULL ? c1->name : c1->filename, |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
384 |
c2->name != NULL ? c2->name : c2->filename); |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
385 |
} |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
386 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
387 |
/* Scan for all NewGRFs */ |
6247 | 388 |
void ScanNewGRFFiles() |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
389 |
{ |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
390 |
Searchpath sp; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
391 |
char path[MAX_PATH]; |
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:
7586
diff
changeset
|
392 |
TarFileList::iterator tar; |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
393 |
uint num = 0; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
394 |
|
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
395 |
ClearGRFConfigList(&_all_grfs); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
396 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
397 |
DEBUG(grf, 1, "Scanning for NewGRFs"); |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
398 |
FOR_ALL_SEARCHPATHS(sp) { |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
399 |
FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6873
diff
changeset
|
400 |
num += ScanPath(path, strlen(path)); |
6834
7a64c73d5f45
(svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents:
6481
diff
changeset
|
401 |
} |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
402 |
FOR_ALL_TARS(tar) { |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
403 |
num += ScanTar(tar); |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
404 |
} |
7644
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
405 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
406 |
DEBUG(grf, 1, "Scan complete, found %d files", num); |
7649
c4e93cf27732
(svn r11180) -Fix (r11175): crash on load when you don't have any NewGRFs. More interesting is: who plays without them ;)
rubidium
parents:
7648
diff
changeset
|
407 |
if (num == 0 || _all_grfs == NULL) return; |
7644
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
408 |
|
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
409 |
/* Sort the linked list using quicksort. |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
410 |
* For that we first have to make an array, the qsort and |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
411 |
* then remake the linked list. */ |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
412 |
GRFConfig **to_sort = MallocT<GRFConfig*>(num); |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
413 |
|
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
414 |
uint i = 0; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
415 |
for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) { |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
416 |
to_sort[i] = p; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
417 |
} |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
418 |
/* Number of files is not necessarily right */ |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
419 |
num = i; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
420 |
|
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
421 |
qsort(to_sort, num, sizeof(GRFConfig*), GRFSorter); |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
422 |
|
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
423 |
for (i = 1; i < num; i++) { |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
424 |
to_sort[i - 1]->next = to_sort[i]; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
425 |
} |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
426 |
to_sort[num - 1]->next = NULL; |
a7ff5c8ae47e
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
7592
diff
changeset
|
427 |
_all_grfs = to_sort[0]; |
9133
705318ad20db
(svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents:
9131
diff
changeset
|
428 |
|
705318ad20db
(svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents:
9131
diff
changeset
|
429 |
free(to_sort); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
430 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
431 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
432 |
|
5646
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
433 |
/* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/ |
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
434 |
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
435 |
{ |
5646
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
436 |
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) { |
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
437 |
if (c->grfid == grfid) { |
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
438 |
if (md5sum == NULL) return c; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
439 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
440 |
if (memcmp(md5sum, c->md5sum, sizeof(c->md5sum)) == 0) return c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
441 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
442 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
443 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
444 |
return NULL; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
445 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
446 |
|
5441
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
447 |
#ifdef ENABLE_NETWORK |
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
448 |
|
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
449 |
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */ |
5765
27dbbe543fcf
(svn r8316) -Codechange: move the GRF ID and MD5 checksum from GRFConfig to GRFIdentifier so it can be reused.
rubidium
parents:
5701
diff
changeset
|
450 |
struct UnknownGRF : public GRFIdentifier { |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
451 |
UnknownGRF *next; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
452 |
char name[NETWORK_GRF_NAME_LENGTH]; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
453 |
}; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
454 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
455 |
/** |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
456 |
* Finds the name of a NewGRF in the list of names for unknown GRFs. An |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
457 |
* unknown GRF is a GRF where the .grf is not found during scanning. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
458 |
* |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
459 |
* The names are resolved via UDP calls to servers that should know the name, |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
460 |
* though the replies may not come. This leaves "<Unknown>" as name, though |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
461 |
* that shouldn't matter _very_ much as they need GRF crawler or so to look |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
462 |
* up the GRF anyway and that works better with the GRF ID. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
463 |
* |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
464 |
* @param grfid the GRF ID part of the 'unique' GRF identifier |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
465 |
* @param md5sum the MD5 checksum part of the 'unique' GRF identifier |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
466 |
* @param create whether to create a new GRFConfig if the GRFConfig did not |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
467 |
* exist in the fake list of GRFConfigs. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
468 |
* @return the GRFConfig with the given GRF ID and MD5 checksum or NULL when |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
469 |
* it does not exist and create is false. This value must NEVER be |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
470 |
* freed by the caller. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
471 |
*/ |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
472 |
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create) |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
473 |
{ |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
474 |
UnknownGRF *grf; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
475 |
static UnknownGRF *unknown_grfs = NULL; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
476 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
477 |
for (grf = unknown_grfs; grf != NULL; grf = grf->next) { |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
478 |
if (grf->grfid == grfid) { |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
479 |
if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
480 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
481 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
482 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
483 |
if (!create) return NULL; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
484 |
|
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
485 |
grf = CallocT<UnknownGRF>(1); |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
486 |
grf->grfid = grfid; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
487 |
grf->next = unknown_grfs; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
488 |
ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name)); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
489 |
memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum)); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
490 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
491 |
unknown_grfs = grf; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
492 |
return grf->name; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
493 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
494 |
|
5441
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
495 |
#endif /* ENABLE_NETWORK */ |
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
496 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
497 |
|
5234
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
498 |
/* Retrieve a NewGRF from the current config by its grfid */ |
5333
dedf1f6de6d3
(svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents:
5329
diff
changeset
|
499 |
GRFConfig *GetGRFConfig(uint32 grfid) |
5234
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
500 |
{ |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
501 |
GRFConfig *c; |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
502 |
|
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
503 |
for (c = _grfconfig; c != NULL; c = c->next) { |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
504 |
if (c->grfid == grfid) return c; |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
505 |
} |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
506 |
|
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
507 |
return NULL; |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
508 |
} |
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
509 |
|
980aa61260aa
(svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents:
5229
diff
changeset
|
510 |
|
5308
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
511 |
/* Build a space separated list of parameters, and terminate */ |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
512 |
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last) |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
513 |
{ |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
514 |
uint i; |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
515 |
|
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
516 |
/* Return an empty string if there are no parameters */ |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
517 |
if (c->num_params == 0) return strecpy(dst, "", last); |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
518 |
|
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
519 |
for (i = 0; i < c->num_params; i++) { |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
520 |
if (i > 0) dst = strecpy(dst, " ", last); |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
521 |
dst += snprintf(dst, last - dst, "%d", c->param[i]); |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
522 |
} |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
523 |
return dst; |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
524 |
} |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
525 |
|
7882
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
526 |
/** Base GRF ID for OpenTTD's base graphics GRFs. */ |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
527 |
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400); |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
528 |
|
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
529 |
/** |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
530 |
* Checks whether this GRF is a OpenTTD base graphic GRF. |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
531 |
* @return true if and only if it is a base GRF. |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
532 |
*/ |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
533 |
bool GRFConfig::IsOpenTTDBaseGRF() const |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
534 |
{ |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
535 |
return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID; |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
536 |
} |
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7805
diff
changeset
|
537 |
|
5308
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
538 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
539 |
static const SaveLoad _grfconfig_desc[] = { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
540 |
SLE_STR(GRFConfig, filename, SLE_STR, 0x40), |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
541 |
SLE_VAR(GRFConfig, grfid, SLE_UINT32), |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
542 |
SLE_ARR(GRFConfig, md5sum, SLE_UINT8, 16), |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
543 |
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80), |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
544 |
SLE_VAR(GRFConfig, num_params, SLE_UINT8), |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
545 |
SLE_END() |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
546 |
}; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
547 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
548 |
|
6247 | 549 |
static void Save_NGRF() |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
550 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
551 |
int index = 0; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
552 |
|
6108
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
553 |
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7882
diff
changeset
|
554 |
if (HasBit(c->flags, GCF_STATIC)) continue; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
555 |
SlSetArrayIndex(index++); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
556 |
SlObject(c, _grfconfig_desc); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
557 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
558 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
559 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
560 |
|
6247 | 561 |
static void Load_NGRF() |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
562 |
{ |
6108
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
563 |
ClearGRFConfigList(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
564 |
while (SlIterateArray() != -1) { |
6108
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
565 |
GRFConfig *c = CallocT<GRFConfig>(1); |
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
566 |
SlObject(c, _grfconfig_desc); |
c0929232db31
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6103
diff
changeset
|
567 |
AppendToGRFConfigList(&_grfconfig, c); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
568 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
569 |
|
5329
9c5e8061ea0f
(svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents:
5308
diff
changeset
|
570 |
/* Append static NewGRF configuration */ |
5393
cf584337ea2c
(svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents:
5380
diff
changeset
|
571 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
572 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
573 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
574 |
extern const ChunkHandler _newgrf_chunk_handlers[] = { |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
575 |
{ 'NGRF', Save_NGRF, Load_NGRF, CH_ARRAY | CH_LAST } |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
576 |
}; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
577 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
578 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
579 |