author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9111 | 48ce04029fe4 |
child 9704 | 54123af5f9a5 |
permissions | -rw-r--r-- |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
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 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
31 |
/** Status of post-gameload GRF compatibility check */ |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
32 |
enum GRFListCompatibility{ |
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
}; |
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
|
37 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
38 |
/** 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
|
39 |
struct GRFIdentifier { |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
40 |
uint32 grfid; ///< GRF ID (defined by Action 0x08) |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
41 |
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
|
42 |
}; |
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
|
43 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
44 |
/** Information about why GRF had problems during initialisation */ |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
45 |
struct GRFError { |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
46 |
char *custom_message; ///< Custom message (if present) |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
47 |
char *data; ///< Additional data for message and custom_message |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
48 |
StringID message; ///< Default message |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
49 |
StringID severity; ///< Info / Warning / Error / Fatal |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
}; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
53 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
54 |
/** 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
|
55 |
struct GRFConfig : public GRFIdentifier { |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
56 |
char *filename; ///< Filename - either with or without full path |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
57 |
char *name; ///< NOSAVE: GRF name (Action 0x08) |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
58 |
char *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08) |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
59 |
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
|
60 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
61 |
uint8 flags; ///< NOSAVE: GCF_Flags, bitset |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
62 |
GRFStatus status; ///< NOSAVE: GRFStatus, enum |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
63 |
uint32 param[0x80]; ///< GRF parameters |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
64 |
uint8 num_params; ///< Number of used parameters |
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
65 |
|
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
66 |
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
|
67 |
|
308cab08d2f3
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
7831
diff
changeset
|
68 |
bool IsOpenTTDBaseGRF() const; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
69 |
}; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
70 |
|
8799
6d3a845d5793
(svn r12537) -Cleanup: comment newgrf_config.h a bit
smatz
parents:
8142
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
|
6247 | 76 |
void ScanNewGRFFiles(); |
5646
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5475
diff
changeset
|
77 |
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
|
78 |
GRFConfig *GetGRFConfig(uint32 grfid); |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6873
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
void ClearGRFConfig(GRFConfig **config); |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
83 |
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
|
84 |
void ResetGRFConfig(bool defaults); |
6247 | 85 |
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
|
86 |
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
|
87 |
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
|
88 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6248
diff
changeset
|
89 |
/* 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
|
90 |
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
|
91 |
|
5441
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5393
diff
changeset
|
92 |
#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
|
93 |
/* 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
|
94 |
#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
|
95 |
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
|
96 |
#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
|
97 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
98 |
#endif /* NEWGRF_CONFIG_H */ |