src/newgrf_config.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9088 d60882689d41
child 10429 1b99254f9607
child 10655 b862a4add8b0
permissions -rw-r--r--
update tags
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
6905
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6674
diff changeset
     3
/** @file newgrf_config.cpp */
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
#ifdef WIN32
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    22
# include <io.h>
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    23
#endif /* WIN32 */
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    24
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    25
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    26
GRFConfig *_all_grfs;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    27
GRFConfig *_grfconfig;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    28
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
    29
GRFConfig *_grfconfig_static;
5228
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
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    32
/* 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
    33
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
    34
{
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    35
	FILE *f;
8629
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    36
	Md5 checksum;
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    37
	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
    38
	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
    39
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    40
	/* 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
    41
	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
    42
	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
    43
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    44
	/* 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
    45
	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
    46
		size -= len;
8629
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    47
		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
    48
	}
8629
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    49
	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
    50
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
    51
	FioFCloseFile(f);
5228
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
	return true;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    54
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    55
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    56
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    57
/* 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
    58
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
    59
{
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
    60
	if (!FioCheckFileExists(config->filename)) {
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6509
diff changeset
    61
		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
    62
		return false;
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
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    65
	/* 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
    66
	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
    67
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    68
	/* 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
    69
	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
    70
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
    71
	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
    72
		/* 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
    73
		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
    74
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
    75
		/* 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
    76
		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
    77
	}
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
    78
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    79
	return CalcGRFMD5Sum(config);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    80
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    81
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    82
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
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
    84
{
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
    85
	/* 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
    86
	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
    87
		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
    88
		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
    89
		free((*config)->info);
7369
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7330
diff changeset
    90
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7330
diff changeset
    91
		if ((*config)->error != NULL) {
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7330
diff changeset
    92
			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
    93
			free((*config)->error->data);
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7330
diff changeset
    94
			free((*config)->error);
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7330
diff changeset
    95
		}
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
    96
	}
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
    97
	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
    98
	*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
    99
}
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
   100
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
   101
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   102
/* Clear a GRF Config list */
5347
18836f961808 (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   103
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
   104
{
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   105
	GRFConfig *c, *next;
5347
18836f961808 (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   106
	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
   107
		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
   108
		ClearGRFConfig(&c);
5228
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
	*config = NULL;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   111
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   112
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   113
5347
18836f961808 (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   114
/** Copy a GRF Config list
18836f961808 (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   115
 * @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
   116
 * @param src pointer to source list values
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   117
 * @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
   118
 * @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
   119
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
   120
{
5351
0980b66406af (svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents: 5349
diff changeset
   121
	/* Clear destination as it will be overwritten */
0980b66406af (svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents: 5349
diff changeset
   122
	ClearGRFConfigList(dst);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   123
	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
   124
		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
   125
		*c = *src;
6920
ee15b916f758 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6905
diff changeset
   126
		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
   127
		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
   128
		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
   129
		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
   130
			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
   131
			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
   132
			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
   133
			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
   134
		}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   135
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
   136
		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
   137
		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
   138
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   139
		*dst = c;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   140
		dst = &c->next;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   141
	}
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
   142
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
   143
	return dst;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   144
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   145
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
   146
/**
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
 * 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
   148
 * 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
   149
 * 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
   150
 * 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
   151
 * 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
   152
 * 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
   153
 *
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
 * 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
   155
 * 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
   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
 * @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
   158
 */
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
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
   160
{
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
	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
   162
	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
   163
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
   164
	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
   165
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
	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
   167
		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
   168
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
   169
		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
   170
		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
   171
		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
   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
	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
   175
}
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
/**
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
 * 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
   179
 * @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
   180
 */
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
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
   182
{
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
	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
   184
	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
   185
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   186
	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
   187
	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
   188
}
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
   189
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
/** Appends an element to a list of GRFs
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6921
diff changeset
   191
 * @param dst the head of the list to add to
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6921
diff changeset
   192
 * @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
   193
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
   194
{
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
	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
   196
	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
   197
	*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
   198
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
   199
	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
   200
}
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
   201
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   202
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   203
/* 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
   204
void ResetGRFConfig(bool defaults)
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   205
{
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   206
	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
   207
	AppendStaticGRFConfigs(&_grfconfig);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   208
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   209
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   210
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
   211
/** 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
   212
 * @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
   213
 * <ul>
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6509
diff changeset
   214
 * <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
   215
 * <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
   216
 *     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
   217
 * <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
   218
 * </ul> */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6555
diff changeset
   219
GRFListCompatibility IsGoodGRFConfigList()
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   220
{
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6509
diff changeset
   221
	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
   222
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
   223
	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
   224
		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
   225
		if (f == NULL) {
5903
cd2d0ef3a3b9 (svn r8111) -Fix r8106: silence warnings
glx
parents: 5899
diff changeset
   226
			char buf[256];
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   227
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
   228
			/* 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
   229
			 * 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
   230
			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
   231
			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
   232
				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
   233
				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
   234
				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
   235
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
   236
				/* 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
   237
				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
   238
				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
   239
			}
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
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
   241
			/* 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
   242
			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
   243
			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
   244
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6509
diff changeset
   245
			c->status = GCS_NOT_FOUND;
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6509
diff changeset
   246
			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
   247
		} 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
   248
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
   249
			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
   250
			/* 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
   251
			 * 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
   252
			 * 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
   253
			 * 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
   254
			 * 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
   255
			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
   256
				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
   257
				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
   258
				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
   259
				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
   260
				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
   261
				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
   262
			}
5228
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
	}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   265
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   266
	return res;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   267
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   268
8068
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   269
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
   270
{
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   271
	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
   272
	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
   273
8068
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   274
	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
   275
	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
   276
		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
   277
			_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
   278
		} else {
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   279
			/* Insert file into list at a position determined by its
9088
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   280
			 * 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
   281
			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
   282
			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
   283
			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
   284
				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
   285
				/* 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
   286
				 *  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
   287
				 *  just after the first with the same name. Avoids doubles in the list. */
9088
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   288
				if (strcasecmp(c->name, d->name) <= 0) {
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   289
					stop = true;
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   290
				} else if (stop) {
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   291
					break;
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   292
				}
8068
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
			if (added) {
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   295
				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
   296
				*pd = c;
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
	} else {
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   300
		added = false;
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   301
	}
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   302
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   303
	if (!added) {
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   304
		/* File couldn't be opened, or is either not a NewGRF or is a
9088
d60882689d41 (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8710
diff changeset
   305
		 * '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
   306
		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
   307
		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
   308
		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
   309
		free(c);
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   310
	}
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   311
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   312
	return added;
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   313
}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   314
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   315
/* Scan a path for NewGRFs */
7330
577e92774f23 (svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents: 6977
diff changeset
   316
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
   317
{
8068
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   318
	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
   319
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   320
	uint num = 0;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   321
	struct stat sb;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   322
	struct dirent *dirent;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   323
	DIR *dir;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   324
6920
ee15b916f758 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6905
diff changeset
   325
	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
   326
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   327
	while ((dirent = readdir(dir)) != NULL) {
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   328
		const char *d_name = FS2OTTD(dirent->d_name);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   329
		char filename[MAX_PATH];
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 (!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
   332
6920
ee15b916f758 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6905
diff changeset
   333
		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
   334
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   335
		if (sb.st_mode & S_IFDIR) {
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   336
			/* Directory */
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   337
			if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
6920
ee15b916f758 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6905
diff changeset
   338
			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
   339
			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
   340
		} 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
   341
			/* File */
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   342
			char *ext = strrchr(filename, '.');
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   343
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   344
			/* If no extension or extension isn't .grf, skip the file */
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   345
			if (ext == NULL) continue;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   346
			if (strcasecmp(ext, ".grf") != 0) continue;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   347
8068
5dd156184d13 (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 8067
diff changeset
   348
			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
   349
		}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   350
	}
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
	closedir(dir);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   353
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   354
	return num;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   355
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   356
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
   357
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
   358
{
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
   359
	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
   360
	const char *filename = (*tar).first.c_str();
8082
15235b938558 (svn r11111) -Fix (r11106): missing const broke compilation with MSVC
glx
parents: 8077
diff changeset
   361
	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
   362
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
   363
	/* 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
   364
	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
   365
	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
   366
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
   367
	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
   368
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
   369
	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
   370
}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   371
8140
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   372
/**
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   373
 * 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
   374
 * @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
   375
 * @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
   376
 * @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
   377
 */
8144
108caca4f232 (svn r11179) -Fix [FS#1262] (r11175): compilation with MSVC was broken
glx
parents: 8140
diff changeset
   378
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
   379
{
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   380
	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
   381
	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
   382
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   383
	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
   384
		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
   385
}
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   386
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   387
/* Scan for all NewGRFs */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6555
diff changeset
   388
void ScanNewGRFFiles()
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   389
{
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7369
diff changeset
   390
	Searchpath sp;
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7369
diff changeset
   391
	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
   392
	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
   393
	uint num = 0;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   394
5347
18836f961808 (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   395
	ClearGRFConfigList(&_all_grfs);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   396
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5554
diff changeset
   397
	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
   398
	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
   399
		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
   400
		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
   401
	}
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
   402
	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
   403
		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
   404
	}
8140
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   405
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5554
diff changeset
   406
	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
   407
	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
   408
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   409
	/* 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
   410
	 * 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
   411
	 * 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
   412
	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
   413
	if (to_sort == NULL) return; // No memory, then don't sort
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   414
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   415
	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
   416
	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
   417
		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
   418
	}
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   419
	/* 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
   420
	num = 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
	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
   423
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   424
	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
   425
		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
   426
	}
9dc85f265c1b (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 8088
diff changeset
   427
	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
   428
	_all_grfs = to_sort[0];
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   429
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   430
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
/* 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
   433
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
   434
{
5897
016df903f3bb (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5885
diff changeset
   435
	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
   436
		if (c->grfid == grfid) {
016df903f3bb (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5885
diff changeset
   437
			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
   438
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   439
			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
   440
		}
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
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   443
	return NULL;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   444
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   445
5692
b83442e14fd4 (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5652
diff changeset
   446
#ifdef ENABLE_NETWORK
b83442e14fd4 (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5652
diff changeset
   447
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
   448
/** 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
   449
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
   450
	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
   451
	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
   452
};
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
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
 * 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
   456
 * 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
   457
 *
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
 * 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
   459
 * 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
   460
 * 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
   461
 * 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
   462
 *
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
 * @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
   464
 * @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
   465
 * @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
   466
 *               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
   467
 * @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
   468
 *         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
   469
 *         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
   470
 */
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
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
   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
	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
   474
	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
   475
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
	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
   477
		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
   478
			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
   479
		}
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
	}
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
   481
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
	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
   483
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
   484
	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
   485
	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
   486
	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
   487
	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
   488
	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
   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
	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
   491
	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
   492
}
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
   493
5692
b83442e14fd4 (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5652
diff changeset
   494
#endif /* ENABLE_NETWORK */
b83442e14fd4 (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5652
diff changeset
   495
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   496
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
   497
/* 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
   498
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
   499
{
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
	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
   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
	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
   503
		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
   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
	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
   507
}
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
   508
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
   509
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   510
/* 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
   511
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
   512
{
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   513
	uint i;
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
	/* 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
   516
	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
   517
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   518
	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
   519
		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
   520
		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
   521
	}
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   522
	return dst;
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   523
}
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   524
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8301
diff changeset
   525
/** 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
   526
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
   527
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
 * 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
   530
 * @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
   531
 */
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8301
diff changeset
   532
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
   533
{
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8301
diff changeset
   534
	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
   535
}
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8301
diff changeset
   536
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   537
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   538
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
   539
	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
   540
	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
   541
	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
   542
	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
   543
	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
   544
	SLE_END()
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   545
};
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6555
diff changeset
   548
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
   549
{
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   550
	int index = 0;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   551
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
   552
	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
   553
		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
   554
		SlSetArrayIndex(index++);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   555
		SlObject(c, _grfconfig_desc);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   556
	}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   557
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   558
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   559
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6555
diff changeset
   560
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
   561
{
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
   562
	ClearGRFConfigList(&_grfconfig);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   563
	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
   564
		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
   565
		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
   566
		AppendToGRFConfigList(&_grfconfig, c);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   567
	}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   568
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
   569
	/* 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
   570
	AppendStaticGRFConfigs(&_grfconfig);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   571
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   572
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   573
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
   574
	{ '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
   575
};
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   576
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5554
diff changeset
   577
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6574
diff changeset
   578