Fix ICU iterators on leading/trailing whitespace
[openttd/fttd.git] / src / fios.h
blobce747b1458572098a1e56ffcc7c0308c7e61b5db
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file fios.h Declarations for savegames operations */
12 #ifndef FIOS_H
13 #define FIOS_H
15 #include "gfx_type.h"
16 #include "company_base.h"
17 #include "gamelog.h"
18 #include "newgrf_config.h"
19 #include "network/core/tcp_content.h"
20 #include "saveload/saveload_data.h"
21 #include "saveload/saveload_error.h"
24 typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
26 /**
27 * Container for loading in mode SL_LOAD_CHECK.
29 struct LoadCheckData {
30 bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
31 SlErrorData error; ///< Error message from loading. INVALID_STRING_ID if no error.
33 SavegameTypeVersion sl_version; ///< Savegame type and version
35 uint32 map_size_x, map_size_y;
36 Date current_date;
38 GameSettings settings;
40 CompanyPropertiesMap companies; ///< Company information.
42 GRFConfig *grfconfig; ///< NewGrf configuration from save.
43 GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
45 Gamelog gamelog; ///< Gamelog
47 LoadCheckData() : grfconfig(NULL), grf_compatibility(GLC_NOT_FOUND), gamelog()
49 this->Clear();
52 /**
53 * Don't leak memory at program exit
55 ~LoadCheckData()
57 this->Clear();
60 /**
61 * Check whether loading the game resulted in errors.
62 * @return true if errors were encountered.
64 bool HasErrors()
66 return this->checkable && this->error.str != INVALID_STRING_ID;
69 /**
70 * Check whether the game uses any NewGrfs.
71 * @return true if NewGrfs are used.
73 bool HasNewGrfs()
75 return this->checkable && this->error.str == INVALID_STRING_ID && this->grfconfig != NULL;
78 void Clear();
81 extern LoadCheckData _load_check_data;
84 enum FileSlots {
85 /**
86 * Slot used for the GRF scanning and such. This slot cannot be reused
87 * as it will otherwise cause issues when pressing "rescan directories".
88 * It can furthermore not be larger than LAST_GRF_SLOT as that complicates
89 * the testing for "too much NewGRFs".
91 CONFIG_SLOT = 0,
92 /** Slot for the sound. */
93 SOUND_SLOT = 1,
94 /** First slot usable for (New)GRFs used during the game. */
95 FIRST_GRF_SLOT = 2,
96 /** Last slot usable for (New)GRFs used during the game. */
97 LAST_GRF_SLOT = 63,
98 /** Maximum number of slots. */
99 MAX_FILE_SLOTS = 64
102 /** Mode of the file dialogue window. */
103 enum SaveLoadDialogMode {
104 SLD_LOAD_GAME, ///< Load a game.
105 SLD_LOAD_SCENARIO, ///< Load a scenario.
106 SLD_SAVE_GAME, ///< Save a game.
107 SLD_SAVE_SCENARIO, ///< Save a scenario.
108 SLD_LOAD_HEIGHTMAP, ///< Load a heightmap.
109 SLD_SAVE_HEIGHTMAP, ///< Save a heightmap.
112 /** The different types of files that the system knows about. */
113 enum FileType {
114 FT_NONE, ///< nothing to do
115 FT_SAVEGAME, ///< old or new savegame
116 FT_SCENARIO, ///< old or new scenario
117 FT_HEIGHTMAP, ///< heightmap file
120 enum FiosType {
121 FIOS_TYPE_DRIVE,
122 FIOS_TYPE_PARENT,
123 FIOS_TYPE_DIR,
124 FIOS_TYPE_FILE,
125 FIOS_TYPE_OLDFILE,
126 FIOS_TYPE_SCENARIO,
127 FIOS_TYPE_OLD_SCENARIO,
128 FIOS_TYPE_DIRECT,
129 FIOS_TYPE_PNG,
130 FIOS_TYPE_BMP,
131 FIOS_TYPE_INVALID = 255,
134 /** Deals with finding savegames */
135 struct FiosItem {
136 FiosType type;
137 uint64 mtime;
138 char title[64];
139 char name[MAX_PATH];
142 /** Deals with the type of the savegame, independent of extension */
143 struct SmallFiosItem {
144 int mode; ///< savegame/scenario type (old, new)
145 FileType filetype; ///< what type of file are we dealing with
146 char name[MAX_PATH]; ///< name
147 char title[255]; ///< internal name of the game
150 enum SortingBits {
151 SORT_ASCENDING = 0,
152 SORT_DESCENDING = 1,
153 SORT_BY_DATE = 0,
154 SORT_BY_NAME = 2
156 DECLARE_ENUM_AS_BIT_SET(SortingBits)
158 /* Variables to display file lists */
159 extern SmallVector<FiosItem, 32> _fios_items;
160 extern SmallFiosItem _file_to_saveload;
161 extern SaveLoadDialogMode _saveload_mode;
162 extern SortingBits _savegame_sort_order;
164 void ShowSaveLoadDialog(SaveLoadDialogMode mode);
166 void FiosGetSavegameList(SaveLoadDialogMode mode);
167 void FiosGetScenarioList(SaveLoadDialogMode mode);
168 void FiosGetHeightmapList(SaveLoadDialogMode mode);
170 void FiosFreeSavegameList();
171 const char *FiosBrowseTo(const FiosItem *item);
173 StringID FiosGetDescText(const char **path, uint64 *total_free);
174 bool FiosDelete(const char *name);
175 void FiosMakeHeightmapName(char *buf, const char *name, size_t size);
176 void FiosMakeSavegameName(char *buf, const char *name, size_t size);
178 FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last);
180 int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
182 extern const TextColour _fios_colours[];
184 void BuildFileList();
185 void SetFiosType(const byte fiostype);
187 #endif /* FIOS_H */