src/newgrf_config.h
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10066 f18e97752eeb
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     1
/* $Id$ */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8799
diff changeset
     3
/** @file newgrf_config.h Functions to find and configure NewGRFs. */
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
     4
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     5
#ifndef NEWGRF_CONFIG_H
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     6
#define NEWGRF_CONFIG_H
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     7
8142
837f47089a7c (svn r11704) -Codechange: remove another bunch of useless includes.
rubidium
parents: 7882
diff changeset
     8
#include "strings_type.h"
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6108
diff changeset
     9
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    10
/** GRF config bit flags */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    11
enum GCF_Flags {
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    12
	GCF_SYSTEM,     ///< GRF file is an openttd-internal system grf
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    13
	GCF_UNSAFE,     ///< GRF file is unsafe for static usage
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    14
	GCF_STATIC,     ///< GRF file is used statically (can be used in any MP game)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    15
	GCF_COMPATIBLE, ///< GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    16
	GCF_COPY,       ///< The data is copied from a grf in _all_grfs
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    17
	GCF_INIT_ONLY,  ///< GRF file is processed up to GLS_INIT
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    18
	GCF_RESERVED,   ///< GRF file passed GLS_RESERVE stage
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    19
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    20
};
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    21
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    22
/** Status of GRF */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    23
enum GRFStatus {
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    24
	GCS_UNKNOWN,      ///< The status of this grf file is unknown
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    25
	GCS_DISABLED,     ///< GRF file is disabled
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    26
	GCS_NOT_FOUND,    ///< GRF file was not found in the local cache
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    27
	GCS_INITIALISED,  ///< GRF file has been initialised
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    28
	GCS_ACTIVATED     ///< GRF file has been activated
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    29
};
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6139
diff changeset
    30
9704
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    31
/** Encountered GRF bugs */
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    32
enum GRFBugs {
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    33
	GBUG_VEH_LENGTH,  ///< Length of rail vehicle changes when not inside a depot
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    34
};
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    35
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    36
/** Status of post-gameload GRF compatibility check */
9704
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    37
enum GRFListCompatibility {
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    38
	GLC_ALL_GOOD,   ///< All GRF needed by game are present
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    39
	GLC_COMPATIBLE, ///< Compatible (eg. the same ID, but different chacksum) GRF found in at least one case
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    40
	GLC_NOT_FOUND   ///< At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    41
};
5765
27dbbe543fcf (svn r8316) -Codechange: move the GRF ID and MD5 checksum from GRFConfig to GRFIdentifier so it can be reused.
rubidium
parents: 5647
diff changeset
    42
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    43
/** Basic data to distinguish a GRF. Used in the server list window */
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    44
struct GRFIdentifier {
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    45
	uint32 grfid;     ///< GRF ID (defined by Action 0x08)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    46
	uint8 md5sum[16]; ///< MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    47
};
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6108
diff changeset
    48
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    49
/** Information about why GRF had problems during initialisation */
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    50
struct GRFError {
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    51
	char *custom_message;  ///< Custom message (if present)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    52
	char *data;            ///< Additional data for message and custom_message
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    53
	StringID message;      ///< Default message
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    54
	StringID severity;     ///< Info / Warning / Error / Fatal
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    55
	uint8 num_params;      ///< Number of additinal parameters for custom_message (0, 1 or 2)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    56
	uint8 param_number[2]; ///< GRF parameters to show for custom_message
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    57
};
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    58
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    59
/** Information about GRF, used in the game and (part of it) in savegames */
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    60
struct GRFConfig : public GRFIdentifier {
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    61
	char *filename;     ///< Filename - either with or without full path
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    62
	char *name;         ///< NOSAVE: GRF name (Action 0x08)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    63
	char *info;         ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    64
	GRFError *error;    ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    65
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    66
	uint8 flags;        ///< NOSAVE: GCF_Flags, bitset
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    67
	GRFStatus status;   ///< NOSAVE: GRFStatus, enum
9704
54123af5f9a5 (svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents: 9111
diff changeset
    68
	uint32 grf_bugs;    ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    69
	uint32 param[0x80]; ///< GRF parameters
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    70
	uint8 num_params;   ///< Number of used parameters
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9704
diff changeset
    71
	bool windows_paletted;  ///< Whether the NewGRF is Windows paletted or not
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    72
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    73
	struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7831
diff changeset
    74
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7831
diff changeset
    75
	bool IsOpenTTDBaseGRF() const;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    76
};
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    77
8799
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    78
extern GRFConfig *_all_grfs;          ///< First item in list of all scanned NewGRFs
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    79
extern GRFConfig *_grfconfig;         ///< First item in list of current GRF set up
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    80
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
6d3a845d5793 (svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents: 8142
diff changeset
    81
extern GRFConfig *_grfconfig_static;  ///< First item in list of static GRF set up
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    82
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
    83
void ScanNewGRFFiles();
5646
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5475
diff changeset
    84
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum = NULL);
5333
dedf1f6de6d3 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
    85
GRFConfig *GetGRFConfig(uint32 grfid);
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
    86
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5352
diff changeset
    87
void AppendStaticGRFConfigs(GRFConfig **dst);
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
    88
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
5346
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    89
void ClearGRFConfig(GRFConfig **config);
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
    90
void ClearGRFConfigList(GRFConfig **config);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    91
void ResetGRFConfig(bool defaults);
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
    92
GRFListCompatibility IsGoodGRFConfigList();
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    93
bool FillGRFDetails(GRFConfig *config, bool is_static);
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5237
diff changeset
    94
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    95
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
    96
/* In newgrf_gui.cpp */
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5347
diff changeset
    97
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents: 5234
diff changeset
    98
5441
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5393
diff changeset
    99
#ifdef ENABLE_NETWORK
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   100
/* For communication about GRFs over the network */
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   101
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   102
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
5441
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5393
diff changeset
   103
#endif /* ENABLE_NETWORK */
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   104
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   105
#endif /* NEWGRF_CONFIG_H */