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/>.
10 /** @file fios.h Declarations for savegames operations */
16 #include "company_base.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
;
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
;
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()
53 * Don't leak memory at program exit
61 * Check whether loading the game resulted in errors.
62 * @return true if errors were encountered.
66 return this->checkable
&& this->error
.str
!= INVALID_STRING_ID
;
70 * Check whether the game uses any NewGrfs.
71 * @return true if NewGrfs are used.
75 return this->checkable
&& this->error
.str
== INVALID_STRING_ID
&& this->grfconfig
!= NULL
;
81 extern LoadCheckData _load_check_data
;
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".
92 /** Slot for the sound. */
94 /** First slot usable for (New)GRFs used during the game. */
96 /** Last slot usable for (New)GRFs used during the game. */
98 /** Maximum number of slots. */
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. */
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
127 FIOS_TYPE_OLD_SCENARIO
,
131 FIOS_TYPE_INVALID
= 255,
134 /** Deals with finding savegames */
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
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
);