author | rubidium |
Wed, 07 May 2008 21:45:27 +0000 | |
changeset 10457 | ea18877d8eba |
parent 10451 | 02dc0c5f3647 |
child 10465 | 0c68afe3d725 |
permissions | -rw-r--r-- |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
2 |
|
10429
1b99254f9607
(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:
9088
diff
changeset
|
3 |
/** @file newgrf_config.cpp Finding NewGRFs and configuring them. */ |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6574
diff
changeset
|
4 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
7 |
#include "debug.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
8 |
#include "variables.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
9 |
#include "saveload.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
10 |
#include "md5.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5692
diff
changeset
|
11 |
#include "network/network_data.h" |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
12 |
#include "newgrf.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
13 |
#include "newgrf_config.h" |
8709
4187ad809fe7
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8629
diff
changeset
|
14 |
#include "core/alloc_func.hpp" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8709
diff
changeset
|
15 |
#include "string_func.h" |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
16 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
17 |
#include "fileio.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
18 |
#include "fios.h" |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
19 |
#include <sys/stat.h> |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
20 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
21 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
22 |
GRFConfig *_all_grfs; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
23 |
GRFConfig *_grfconfig; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
24 |
GRFConfig *_grfconfig_newgame; |
5329
2b117d8652f0
(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
|
25 |
GRFConfig *_grfconfig_static; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
26 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
27 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
28 |
/* Calculate the MD5 Sum for a GRF */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
29 |
static bool CalcGRFMD5Sum(GRFConfig *config) |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
30 |
{ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
31 |
FILE *f; |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
32 |
Md5 checksum; |
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
33 |
uint8 buffer[1024]; |
8070
959633559d9f
(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:
8069
diff
changeset
|
34 |
size_t len, size; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
35 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
36 |
/* open the file */ |
8070
959633559d9f
(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:
8069
diff
changeset
|
37 |
f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
38 |
if (f == NULL) return false; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
39 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
40 |
/* calculate md5sum */ |
8070
959633559d9f
(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:
8069
diff
changeset
|
41 |
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) { |
959633559d9f
(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:
8069
diff
changeset
|
42 |
size -= len; |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
43 |
checksum.Append(buffer, len); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
44 |
} |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
45 |
checksum.Finish(config->md5sum); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
46 |
|
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
47 |
FioFCloseFile(f); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
48 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
49 |
return true; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
50 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
51 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
52 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
53 |
/* Find the GRFID and calculate the md5sum */ |
5329
2b117d8652f0
(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
|
54 |
bool FillGRFDetails(GRFConfig *config, bool is_static) |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
55 |
{ |
7530
31257d744079
(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:
7463
diff
changeset
|
56 |
if (!FioCheckFileExists(config->filename)) { |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
57 |
config->status = GCS_NOT_FOUND; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
58 |
return false; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
59 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
60 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
61 |
/* Find and load the Action 8 information */ |
8301
47e8f031a6ab
(svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents:
8145
diff
changeset
|
62 |
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
63 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
64 |
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */ |
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
65 |
if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
66 |
|
5753
788f8d55eb54
(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:
5726
diff
changeset
|
67 |
if (is_static) { |
788f8d55eb54
(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:
5726
diff
changeset
|
68 |
/* Perform a 'safety scan' for static GRFs */ |
788f8d55eb54
(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:
5726
diff
changeset
|
69 |
LoadNewGRFFile(config, 62, GLS_SAFETYSCAN); |
788f8d55eb54
(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:
5726
diff
changeset
|
70 |
|
788f8d55eb54
(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:
5726
diff
changeset
|
71 |
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8378
diff
changeset
|
72 |
if (HasBit(config->flags, GCF_UNSAFE)) return false; |
5753
788f8d55eb54
(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:
5726
diff
changeset
|
73 |
} |
788f8d55eb54
(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:
5726
diff
changeset
|
74 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
75 |
return CalcGRFMD5Sum(config); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
76 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
77 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
78 |
|
5346
0d7cc9cefd2b
(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
|
79 |
void ClearGRFConfig(GRFConfig **config) |
5329
2b117d8652f0
(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
|
80 |
{ |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
81 |
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8378
diff
changeset
|
82 |
if (!HasBit((*config)->flags, GCF_COPY)) { |
5346
0d7cc9cefd2b
(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
|
83 |
free((*config)->filename); |
0d7cc9cefd2b
(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)->name); |
0d7cc9cefd2b
(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)->info); |
7369
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
86 |
|
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
87 |
if ((*config)->error != NULL) { |
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
88 |
free((*config)->error->custom_message); |
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
89 |
free((*config)->error->data); |
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
90 |
free((*config)->error); |
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
91 |
} |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
92 |
} |
5346
0d7cc9cefd2b
(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
|
93 |
free(*config); |
0d7cc9cefd2b
(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 |
*config = NULL; |
5329
2b117d8652f0
(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
|
95 |
} |
2b117d8652f0
(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 |
|
2b117d8652f0
(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 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
98 |
/* Clear a GRF Config list */ |
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
99 |
void ClearGRFConfigList(GRFConfig **config) |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
100 |
{ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
101 |
GRFConfig *c, *next; |
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
102 |
for (c = *config; c != NULL; c = next) { |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
103 |
next = c->next; |
5346
0d7cc9cefd2b
(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
|
104 |
ClearGRFConfig(&c); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
105 |
} |
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
106 |
*config = NULL; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
107 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
108 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
109 |
|
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
110 |
/** Copy a GRF Config list |
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
111 |
* @param dst pointer to destination list |
6399
d704bf2ec4ee
(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:
6016
diff
changeset
|
112 |
* @param src pointer to source list values |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7425
diff
changeset
|
113 |
* @param init_only the copied GRF will be processed up to GLS_INIT |
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
114 |
* @return pointer to the last value added to the destination list */ |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7425
diff
changeset
|
115 |
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only) |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
116 |
{ |
5351
0980b66406af
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
117 |
/* Clear destination as it will be overwritten */ |
0980b66406af
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
118 |
ClearGRFConfigList(dst); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
119 |
for (; src != NULL; src = src->next) { |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
120 |
GRFConfig *c = CallocT<GRFConfig>(1); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
121 |
*c = *src; |
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
122 |
if (src->filename != NULL) c->filename = strdup(src->filename); |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
123 |
if (src->name != NULL) c->name = strdup(src->name); |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
124 |
if (src->info != NULL) c->info = strdup(src->info); |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
125 |
if (src->error != NULL) { |
6465
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6434
diff
changeset
|
126 |
c->error = CallocT<GRFError>(1); |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6434
diff
changeset
|
127 |
memcpy(c->error, src->error, sizeof(GRFError)); |
7369
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
128 |
if (src->error->data != NULL) c->error->data = strdup(src->error->data); |
26325201d4d7
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents:
7330
diff
changeset
|
129 |
if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message); |
6465
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6434
diff
changeset
|
130 |
} |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
131 |
|
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
132 |
ClrBit(c->flags, GCF_INIT_ONLY); |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
133 |
if (init_only) SetBit(c->flags, GCF_INIT_ONLY); |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7425
diff
changeset
|
134 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
135 |
*dst = c; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
136 |
dst = &c->next; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
137 |
} |
5329
2b117d8652f0
(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
|
138 |
|
2b117d8652f0
(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 |
return dst; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
140 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
141 |
|
5581
d0407b8e20ce
(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:
5568
diff
changeset
|
142 |
/** |
d0407b8e20ce
(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:
5568
diff
changeset
|
143 |
* Removes duplicates from lists of GRFConfigs. These duplicates |
d0407b8e20ce
(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:
5568
diff
changeset
|
144 |
* are introduced when the _grfconfig_static GRFs are appended |
d0407b8e20ce
(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:
5568
diff
changeset
|
145 |
* to the _grfconfig on a newgame or savegame. As the parameters |
d0407b8e20ce
(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:
5568
diff
changeset
|
146 |
* of the static GRFs could be different that the parameters of |
d0407b8e20ce
(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:
5568
diff
changeset
|
147 |
* the ones used non-statically. This can result in desyncs in |
d0407b8e20ce
(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:
5568
diff
changeset
|
148 |
* multiplayers, so the duplicate static GRFs have to be removed. |
d0407b8e20ce
(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:
5568
diff
changeset
|
149 |
* |
d0407b8e20ce
(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:
5568
diff
changeset
|
150 |
* This function _assumes_ that all static GRFs are placed after |
d0407b8e20ce
(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:
5568
diff
changeset
|
151 |
* the non-static GRFs. |
d0407b8e20ce
(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:
5568
diff
changeset
|
152 |
* |
d0407b8e20ce
(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:
5568
diff
changeset
|
153 |
* @param list the list to remove the duplicates from |
d0407b8e20ce
(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:
5568
diff
changeset
|
154 |
*/ |
d0407b8e20ce
(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:
5568
diff
changeset
|
155 |
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list) |
d0407b8e20ce
(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:
5568
diff
changeset
|
156 |
{ |
d0407b8e20ce
(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:
5568
diff
changeset
|
157 |
GRFConfig *prev; |
d0407b8e20ce
(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:
5568
diff
changeset
|
158 |
GRFConfig *cur; |
d0407b8e20ce
(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:
5568
diff
changeset
|
159 |
|
d0407b8e20ce
(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:
5568
diff
changeset
|
160 |
if (list == NULL) return; |
d0407b8e20ce
(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:
5568
diff
changeset
|
161 |
|
d0407b8e20ce
(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:
5568
diff
changeset
|
162 |
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) { |
d0407b8e20ce
(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:
5568
diff
changeset
|
163 |
if (cur->grfid != list->grfid) continue; |
5926
97834f38dab2
(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:
5903
diff
changeset
|
164 |
|
5581
d0407b8e20ce
(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:
5568
diff
changeset
|
165 |
prev->next = cur->next; |
d0407b8e20ce
(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:
5568
diff
changeset
|
166 |
ClearGRFConfig(&cur); |
d0407b8e20ce
(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:
5568
diff
changeset
|
167 |
cur = prev; // Just go back one so it continues as normal later on |
d0407b8e20ce
(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:
5568
diff
changeset
|
168 |
} |
d0407b8e20ce
(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:
5568
diff
changeset
|
169 |
|
d0407b8e20ce
(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:
5568
diff
changeset
|
170 |
RemoveDuplicatesFromGRFConfigList(list->next); |
d0407b8e20ce
(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:
5568
diff
changeset
|
171 |
} |
d0407b8e20ce
(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:
5568
diff
changeset
|
172 |
|
d0407b8e20ce
(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:
5568
diff
changeset
|
173 |
/** |
d0407b8e20ce
(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:
5568
diff
changeset
|
174 |
* Appends the static GRFs to a list of GRFs |
d0407b8e20ce
(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:
5568
diff
changeset
|
175 |
* @param dst the head of the list to add to |
d0407b8e20ce
(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:
5568
diff
changeset
|
176 |
*/ |
d0407b8e20ce
(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:
5568
diff
changeset
|
177 |
void AppendStaticGRFConfigs(GRFConfig **dst) |
d0407b8e20ce
(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:
5568
diff
changeset
|
178 |
{ |
d0407b8e20ce
(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:
5568
diff
changeset
|
179 |
GRFConfig **tail = dst; |
d0407b8e20ce
(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:
5568
diff
changeset
|
180 |
while (*tail != NULL) tail = &(*tail)->next; |
d0407b8e20ce
(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:
5568
diff
changeset
|
181 |
|
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7425
diff
changeset
|
182 |
CopyGRFConfigList(tail, _grfconfig_static, false); |
5581
d0407b8e20ce
(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:
5568
diff
changeset
|
183 |
RemoveDuplicatesFromGRFConfigList(*dst); |
d0407b8e20ce
(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:
5568
diff
changeset
|
184 |
} |
d0407b8e20ce
(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:
5568
diff
changeset
|
185 |
|
6399
d704bf2ec4ee
(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:
6016
diff
changeset
|
186 |
/** Appends an element to a list of GRFs |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6921
diff
changeset
|
187 |
* @param dst the head of the list to add to |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6921
diff
changeset
|
188 |
* @param el the new tail to be */ |
6434
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
189 |
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el) |
6399
d704bf2ec4ee
(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:
6016
diff
changeset
|
190 |
{ |
d704bf2ec4ee
(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:
6016
diff
changeset
|
191 |
GRFConfig **tail = dst; |
d704bf2ec4ee
(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:
6016
diff
changeset
|
192 |
while (*tail != NULL) tail = &(*tail)->next; |
6434
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
193 |
*tail = el; |
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
194 |
|
6399
d704bf2ec4ee
(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:
6016
diff
changeset
|
195 |
RemoveDuplicatesFromGRFConfigList(*dst); |
d704bf2ec4ee
(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:
6016
diff
changeset
|
196 |
} |
d704bf2ec4ee
(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:
6016
diff
changeset
|
197 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
198 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
199 |
/* Reset the current GRF Config to either blank or newgame settings */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
200 |
void ResetGRFConfig(bool defaults) |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
201 |
{ |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7425
diff
changeset
|
202 |
CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults); |
5581
d0407b8e20ce
(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:
5568
diff
changeset
|
203 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
204 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
205 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
206 |
|
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
207 |
/** Check if all GRFs in the GRF config from a savegame can be loaded. |
2ee7d23291fa
(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:
5897
diff
changeset
|
208 |
* @return will return any of the following 3 values:<br> |
2ee7d23291fa
(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:
5897
diff
changeset
|
209 |
* <ul> |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
210 |
* <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded |
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
211 |
* <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a |
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
212 |
* compatible GRF with the same grfid was found and used instead |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
213 |
* <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all |
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
214 |
* </ul> */ |
6573 | 215 |
GRFListCompatibility IsGoodGRFConfigList() |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
216 |
{ |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
217 |
GRFListCompatibility res = GLC_ALL_GOOD; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
218 |
|
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
219 |
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
220 |
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
221 |
if (f == NULL) { |
5903 | 222 |
char buf[256]; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
223 |
|
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
224 |
/* If we have not found the exactly matching GRF try to find one with the |
2ee7d23291fa
(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:
5897
diff
changeset
|
225 |
* same grfid, as it most likely is compatible */ |
2ee7d23291fa
(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:
5897
diff
changeset
|
226 |
f = FindGRFConfig(c->grfid); |
2ee7d23291fa
(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:
5897
diff
changeset
|
227 |
if (f != NULL) { |
2ee7d23291fa
(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:
5897
diff
changeset
|
228 |
md5sumToString(buf, lastof(buf), c->md5sum); |
2ee7d23291fa
(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:
5897
diff
changeset
|
229 |
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf); |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
230 |
SetBit(c->flags, GCF_COMPATIBLE); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
231 |
|
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
232 |
/* Non-found has precedence over compatibility load */ |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
233 |
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE; |
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
234 |
goto compatible_grf; |
2ee7d23291fa
(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:
5897
diff
changeset
|
235 |
} |
2ee7d23291fa
(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:
5897
diff
changeset
|
236 |
|
2ee7d23291fa
(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:
5897
diff
changeset
|
237 |
/* No compatible grf was found, mark it as disabled */ |
2ee7d23291fa
(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:
5897
diff
changeset
|
238 |
md5sumToString(buf, lastof(buf), c->md5sum); |
2ee7d23291fa
(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:
5897
diff
changeset
|
239 |
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf); |
2ee7d23291fa
(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:
5897
diff
changeset
|
240 |
|
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
241 |
c->status = GCS_NOT_FOUND; |
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6509
diff
changeset
|
242 |
res = GLC_NOT_FOUND; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
243 |
} else { |
5898
2ee7d23291fa
(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:
5897
diff
changeset
|
244 |
compatible_grf: |
2ee7d23291fa
(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:
5897
diff
changeset
|
245 |
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename); |
5349
6a220d58c0ce
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
246 |
/* The filename could be the filename as in the savegame. As we need |
6a220d58c0ce
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
247 |
* to load the GRF here, we need the correct filename, so overwrite that |
6a220d58c0ce
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
248 |
* in any case and set the name and info when it is not set already. |
6a220d58c0ce
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
249 |
* When the GCF_COPY flag is set, it is certain that the filename is |
6a220d58c0ce
(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 |
* already a local one, so there is no need to replace it. */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8378
diff
changeset
|
251 |
if (!HasBit(c->flags, GCF_COPY)) { |
5349
6a220d58c0ce
(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 |
free(c->filename); |
6a220d58c0ce
(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 |
c->filename = strdup(f->filename); |
5952
701521003c56
(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:
5926
diff
changeset
|
254 |
memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum)); |
6509
5978ce669c8e
(svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents:
6465
diff
changeset
|
255 |
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name); |
5978ce669c8e
(svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents:
6465
diff
changeset
|
256 |
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info); |
6429
02c062eb2c74
(svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents:
6414
diff
changeset
|
257 |
c->error = NULL; |
5349
6a220d58c0ce
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents:
5347
diff
changeset
|
258 |
} |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
259 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
260 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
261 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
262 |
return res; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
263 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
264 |
|
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
265 |
static bool ScanPathAddGrf(const char *filename) |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
266 |
{ |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
267 |
GRFConfig *c = CallocT<GRFConfig>(1); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
268 |
c->filename = strdup(filename); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
269 |
|
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
270 |
bool added = true; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
271 |
if (FillGRFDetails(c, false)) { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
272 |
if (_all_grfs == NULL) { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
273 |
_all_grfs = c; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
274 |
} else { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
275 |
/* Insert file into list at a position determined by its |
9088 | 276 |
* name, so the list is sorted as we go along */ |
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
277 |
GRFConfig **pd, *d; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
278 |
bool stop = false; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
279 |
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
280 |
if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
281 |
/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, |
8069
da9d65ad1615
(svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents:
8068
diff
changeset
|
282 |
* before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of |
da9d65ad1615
(svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents:
8068
diff
changeset
|
283 |
* just after the first with the same name. Avoids doubles in the list. */ |
9088 | 284 |
if (strcasecmp(c->name, d->name) <= 0) { |
285 |
stop = true; |
|
286 |
} else if (stop) { |
|
287 |
break; |
|
288 |
} |
|
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
289 |
} |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
290 |
if (added) { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
291 |
c->next = d; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
292 |
*pd = c; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
293 |
} |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
294 |
} |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
295 |
} else { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
296 |
added = false; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
297 |
} |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
298 |
|
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
299 |
if (!added) { |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
300 |
/* File couldn't be opened, or is either not a NewGRF or is a |
9088 | 301 |
* 'system' NewGRF or it's already known, so forget about it. */ |
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
302 |
free(c->filename); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
303 |
free(c->name); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
304 |
free(c->info); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
305 |
free(c); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
306 |
} |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
307 |
|
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
308 |
return added; |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
309 |
} |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
310 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
311 |
/* Scan a path for NewGRFs */ |
7330
577e92774f23
(svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents:
6977
diff
changeset
|
312 |
static uint ScanPath(const char *path, int basepath_length) |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
313 |
{ |
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
314 |
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
315 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
316 |
uint num = 0; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
317 |
struct stat sb; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
318 |
struct dirent *dirent; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
319 |
DIR *dir; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
320 |
|
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
321 |
if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
322 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
323 |
while ((dirent = readdir(dir)) != NULL) { |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
324 |
const char *d_name = FS2OTTD(dirent->d_name); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
325 |
char filename[MAX_PATH]; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
326 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
327 |
if (!FiosIsValidFile(path, dirent, &sb)) continue; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
328 |
|
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
329 |
snprintf(filename, lengthof(filename), "%s%s", path, d_name); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
330 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
331 |
if (sb.st_mode & S_IFDIR) { |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
332 |
/* Directory */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
333 |
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; |
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6905
diff
changeset
|
334 |
AppendPathSeparator(filename, lengthof(filename)); |
7330
577e92774f23
(svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents:
6977
diff
changeset
|
335 |
num += ScanPath(filename, basepath_length); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
336 |
} else if (sb.st_mode & S_IFREG) { |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
337 |
/* File */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
338 |
char *ext = strrchr(filename, '.'); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
339 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
340 |
/* If no extension or extension isn't .grf, skip the file */ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
341 |
if (ext == NULL) continue; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
342 |
if (strcasecmp(ext, ".grf") != 0) continue; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
343 |
|
8068
5dd156184d13
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents:
8067
diff
changeset
|
344 |
if (ScanPathAddGrf(filename + basepath_length)) num++; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
345 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
346 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
347 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
348 |
closedir(dir); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
349 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
350 |
return num; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
351 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
352 |
|
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
353 |
static uint ScanTar(TarFileList::iterator tar) |
8077
92edb3688fdf
(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:
8070
diff
changeset
|
354 |
{ |
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
355 |
uint num = 0; |
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
356 |
const char *filename = (*tar).first.c_str(); |
8082
15235b938558
(svn r11111) -Fix (r11106): missing const broke compilation with MSVC
glx
parents:
8077
diff
changeset
|
357 |
const char *ext = strrchr(filename, '.'); |
8077
92edb3688fdf
(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:
8070
diff
changeset
|
358 |
|
92edb3688fdf
(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:
8070
diff
changeset
|
359 |
/* If no extension or extension isn't .grf, skip the file */ |
92edb3688fdf
(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:
8070
diff
changeset
|
360 |
if (ext == NULL) return false; |
92edb3688fdf
(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:
8070
diff
changeset
|
361 |
if (strcasecmp(ext, ".grf") != 0) return false; |
92edb3688fdf
(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:
8070
diff
changeset
|
362 |
|
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
363 |
if (ScanPathAddGrf(filename)) num++; |
8077
92edb3688fdf
(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:
8070
diff
changeset
|
364 |
|
92edb3688fdf
(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:
8070
diff
changeset
|
365 |
return num; |
92edb3688fdf
(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:
8070
diff
changeset
|
366 |
} |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
367 |
|
8140
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
368 |
/** |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
369 |
* Simple sorter for GRFS |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
370 |
* @param p1 the first GRFConfig * |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
371 |
* @param p2 the second GRFConfig * |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
372 |
* @return the same strcmp would return for the name of the NewGRF. |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
373 |
*/ |
8144
108caca4f232
(svn r11179) -Fix [FS#1262] (r11175): compilation with MSVC was broken
glx
parents:
8140
diff
changeset
|
374 |
static int CDECL GRFSorter(const void *p1, const void *p2) |
8140
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
375 |
{ |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
376 |
const GRFConfig *c1 = *(const GRFConfig **)p1; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
377 |
const GRFConfig *c2 = *(const GRFConfig **)p2; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
378 |
|
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
379 |
return strcmp(c1->name != NULL ? c1->name : c1->filename, |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
380 |
c2->name != NULL ? c2->name : c2->filename); |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
381 |
} |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
382 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
383 |
/* Scan for all NewGRFs */ |
6573 | 384 |
void ScanNewGRFFiles() |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
385 |
{ |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
386 |
Searchpath sp; |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
387 |
char path[MAX_PATH]; |
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8082
diff
changeset
|
388 |
TarFileList::iterator tar; |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
389 |
uint num = 0; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
390 |
|
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
391 |
ClearGRFConfigList(&_all_grfs); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
392 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5554
diff
changeset
|
393 |
DEBUG(grf, 1, "Scanning for NewGRFs"); |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
394 |
FOR_ALL_SEARCHPATHS(sp) { |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
395 |
FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7369
diff
changeset
|
396 |
num += ScanPath(path, strlen(path)); |
7330
577e92774f23
(svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents:
6977
diff
changeset
|
397 |
} |
8077
92edb3688fdf
(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:
8070
diff
changeset
|
398 |
FOR_ALL_TARS(tar) { |
92edb3688fdf
(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:
8070
diff
changeset
|
399 |
num += ScanTar(tar); |
92edb3688fdf
(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:
8070
diff
changeset
|
400 |
} |
8140
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
401 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5554
diff
changeset
|
402 |
DEBUG(grf, 1, "Scan complete, found %d files", num); |
8145
19efa5646e94
(svn r11180) -Fix (r11175): crash on load when you don't have any NewGRFs. More interesting is: who plays without them ;)
rubidium
parents:
8144
diff
changeset
|
403 |
if (num == 0 || _all_grfs == NULL) return; |
8140
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
404 |
|
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
405 |
/* Sort the linked list using quicksort. |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
406 |
* For that we first have to make an array, the qsort and |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
407 |
* then remake the linked list. */ |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
408 |
GRFConfig **to_sort = MallocT<GRFConfig*>(num); |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
409 |
|
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
410 |
uint i = 0; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
411 |
for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) { |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
412 |
to_sort[i] = p; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
413 |
} |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
414 |
/* Number of files is not necessarily right */ |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
415 |
num = i; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
416 |
|
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
417 |
qsort(to_sort, num, sizeof(GRFConfig*), GRFSorter); |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
418 |
|
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
419 |
for (i = 1; i < num; i++) { |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
420 |
to_sort[i - 1]->next = to_sort[i]; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
421 |
} |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
422 |
to_sort[num - 1]->next = NULL; |
9dc85f265c1b
(svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents:
8088
diff
changeset
|
423 |
_all_grfs = to_sort[0]; |
10451
02dc0c5f3647
(svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents:
10449
diff
changeset
|
424 |
|
02dc0c5f3647
(svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents:
10449
diff
changeset
|
425 |
free(to_sort); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
426 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
427 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
428 |
|
5897
016df903f3bb
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5885
diff
changeset
|
429 |
/* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/ |
016df903f3bb
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5885
diff
changeset
|
430 |
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
431 |
{ |
5897
016df903f3bb
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5885
diff
changeset
|
432 |
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) { |
016df903f3bb
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5885
diff
changeset
|
433 |
if (c->grfid == grfid) { |
016df903f3bb
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5885
diff
changeset
|
434 |
if (md5sum == NULL) return c; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
435 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
436 |
if (memcmp(md5sum, c->md5sum, sizeof(c->md5sum)) == 0) return c; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
437 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
438 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
439 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
440 |
return NULL; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
441 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
442 |
|
5692
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5652
diff
changeset
|
443 |
#ifdef ENABLE_NETWORK |
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5652
diff
changeset
|
444 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
445 |
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */ |
6016
9d7b851ffe1c
(svn r8316) -Codechange: move the GRF ID and MD5 checksum from GRFConfig to GRFIdentifier so it can be reused.
rubidium
parents:
5952
diff
changeset
|
446 |
struct UnknownGRF : public GRFIdentifier { |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
447 |
UnknownGRF *next; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
448 |
char name[NETWORK_GRF_NAME_LENGTH]; |
7573f179efe8
(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 |
}; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
450 |
|
7573f179efe8
(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 |
/** |
7573f179efe8
(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 |
* Finds the name of a NewGRF in the list of names for unknown GRFs. An |
7573f179efe8
(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 |
* unknown GRF is a GRF where the .grf is not found during scanning. |
7573f179efe8
(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 |
* |
7573f179efe8
(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 |
* The names are resolved via UDP calls to servers that should know the name, |
7573f179efe8
(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 |
* though the replies may not come. This leaves "<Unknown>" as name, though |
7573f179efe8
(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 |
* that shouldn't matter _very_ much as they need GRF crawler or so to look |
7573f179efe8
(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 |
* up the GRF anyway and that works better with the GRF ID. |
7573f179efe8
(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 |
* |
7573f179efe8
(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 |
* @param grfid the GRF ID part of the 'unique' GRF identifier |
7573f179efe8
(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 |
* @param md5sum the MD5 checksum part of the 'unique' GRF identifier |
7573f179efe8
(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 |
* @param create whether to create a new GRFConfig if the GRFConfig did not |
7573f179efe8
(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 |
* exist in the fake list of GRFConfigs. |
7573f179efe8
(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 |
* @return the GRFConfig with the given GRF ID and MD5 checksum or NULL when |
7573f179efe8
(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 |
* it does not exist and create is false. This value must NEVER be |
7573f179efe8
(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 |
* freed by the caller. |
7573f179efe8
(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 |
*/ |
7573f179efe8
(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 |
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create) |
7573f179efe8
(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 |
{ |
7573f179efe8
(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 |
UnknownGRF *grf; |
7573f179efe8
(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 |
static UnknownGRF *unknown_grfs = NULL; |
7573f179efe8
(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 |
|
7573f179efe8
(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 |
for (grf = unknown_grfs; grf != NULL; grf = grf->next) { |
7573f179efe8
(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 |
if (grf->grfid == grfid) { |
7573f179efe8
(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 |
if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name; |
7573f179efe8
(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 |
} |
7573f179efe8
(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 |
} |
7573f179efe8
(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 |
|
7573f179efe8
(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 (!create) return NULL; |
7573f179efe8
(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 |
|
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
481 |
grf = CallocT<UnknownGRF>(1); |
5339
7573f179efe8
(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 |
grf->grfid = grfid; |
7573f179efe8
(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 |
grf->next = unknown_grfs; |
7573f179efe8
(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 |
ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name)); |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5333
diff
changeset
|
485 |
memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum)); |
7573f179efe8
(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 |
|
7573f179efe8
(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 |
unknown_grfs = grf; |
7573f179efe8
(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 |
return grf->name; |
7573f179efe8
(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 |
} |
7573f179efe8
(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 |
|
5692
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5652
diff
changeset
|
491 |
#endif /* ENABLE_NETWORK */ |
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5652
diff
changeset
|
492 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
493 |
|
5234
91b7def5e4b2
(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
|
494 |
/* Retrieve a NewGRF from the current config by its grfid */ |
5333
8e7d68b06399
(svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents:
5329
diff
changeset
|
495 |
GRFConfig *GetGRFConfig(uint32 grfid) |
5234
91b7def5e4b2
(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
|
496 |
{ |
91b7def5e4b2
(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
|
497 |
GRFConfig *c; |
91b7def5e4b2
(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 |
|
91b7def5e4b2
(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
|
499 |
for (c = _grfconfig; c != NULL; c = c->next) { |
91b7def5e4b2
(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 |
if (c->grfid == grfid) return c; |
91b7def5e4b2
(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 |
} |
91b7def5e4b2
(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 |
|
91b7def5e4b2
(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 |
return NULL; |
91b7def5e4b2
(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 |
} |
91b7def5e4b2
(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 |
|
91b7def5e4b2
(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 |
|
5308
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
507 |
/* Build a space separated list of parameters, and terminate */ |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
508 |
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last) |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
509 |
{ |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
510 |
uint i; |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
511 |
|
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
512 |
/* Return an empty string if there are no parameters */ |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
513 |
if (c->num_params == 0) return strecpy(dst, "", last); |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
514 |
|
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
515 |
for (i = 0; i < c->num_params; i++) { |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
516 |
if (i > 0) dst = strecpy(dst, " ", last); |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
517 |
dst += snprintf(dst, last - dst, "%d", c->param[i]); |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
518 |
} |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
519 |
return dst; |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
520 |
} |
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
521 |
|
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
522 |
/** Base GRF ID for OpenTTD's base graphics GRFs. */ |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
523 |
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400); |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
524 |
|
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
525 |
/** |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
526 |
* Checks whether this GRF is a OpenTTD base graphic GRF. |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
527 |
* @return true if and only if it is a base GRF. |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
528 |
*/ |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
529 |
bool GRFConfig::IsOpenTTDBaseGRF() const |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
530 |
{ |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
531 |
return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID; |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
532 |
} |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8301
diff
changeset
|
533 |
|
5308
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
534 |
|
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
535 |
static const SaveLoad _grfconfig_desc[] = { |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
536 |
SLE_STR(GRFConfig, filename, SLE_STR, 0x40), |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
537 |
SLE_VAR(GRFConfig, grfid, SLE_UINT32), |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
538 |
SLE_ARR(GRFConfig, md5sum, SLE_UINT8, 16), |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
539 |
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80), |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
540 |
SLE_VAR(GRFConfig, num_params, SLE_UINT8), |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
541 |
SLE_END() |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
542 |
}; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
543 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
544 |
|
6573 | 545 |
static void Save_NGRF() |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
546 |
{ |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
547 |
int index = 0; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
548 |
|
6434
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
549 |
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8378
diff
changeset
|
550 |
if (HasBit(c->flags, GCF_STATIC)) continue; |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
551 |
SlSetArrayIndex(index++); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
552 |
SlObject(c, _grfconfig_desc); |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
553 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
554 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
555 |
|
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
556 |
|
6573 | 557 |
static void Load_NGRF() |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
558 |
{ |
6434
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
559 |
ClearGRFConfigList(&_grfconfig); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
560 |
while (SlIterateArray() != -1) { |
6434
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
561 |
GRFConfig *c = CallocT<GRFConfig>(1); |
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
562 |
SlObject(c, _grfconfig_desc); |
d12a3ab5acbc
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents:
6429
diff
changeset
|
563 |
AppendToGRFConfigList(&_grfconfig, c); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
564 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
565 |
|
5329
2b117d8652f0
(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
|
566 |
/* Append static NewGRF configuration */ |
5581
d0407b8e20ce
(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:
5568
diff
changeset
|
567 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
568 |
} |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
569 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
570 |
extern const ChunkHandler _newgrf_chunk_handlers[] = { |
5228
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
571 |
{ 'NGRF', Save_NGRF, Load_NGRF, CH_ARRAY | CH_LAST } |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
572 |
}; |
c4a780348f66
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
573 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5554
diff
changeset
|
574 |
|
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6574
diff
changeset
|
575 |