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"
17 #include "newgrf_config.h"
18 #include "network/core/tcp_content.h"
21 typedef SmallMap
<uint
, CompanyProperties
*> CompanyPropertiesMap
;
24 * Container for loading in mode SL_LOAD_CHECK.
26 struct LoadCheckData
{
27 bool checkable
; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
28 StringID error
; ///< Error message from loading. INVALID_STRING_ID if no error.
29 char *error_data
; ///< Data to pass to SetDParamStr when displaying #error.
31 uint32 map_size_x
, map_size_y
;
34 GameSettings settings
;
36 CompanyPropertiesMap companies
; ///< Company information.
38 GRFConfig
*grfconfig
; ///< NewGrf configuration from save.
39 GRFListCompatibility grf_compatibility
; ///< Summary state of NewGrfs, whether missing files or only compatible found.
41 struct LoggedAction
*gamelog_action
; ///< Gamelog actions
42 uint gamelog_actions
; ///< Number of gamelog actions
44 LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
45 grf_compatibility(GLC_NOT_FOUND
), gamelog_action(nullptr), gamelog_actions(0)
51 * Don't leak memory at program exit
59 * Check whether loading the game resulted in errors.
60 * @return true if errors were encountered.
64 return this->checkable
&& this->error
!= INVALID_STRING_ID
;
68 * Check whether the game uses any NewGrfs.
69 * @return true if NewGrfs are used.
73 return this->checkable
&& this->error
== INVALID_STRING_ID
&& this->grfconfig
!= nullptr;
79 extern LoadCheckData _load_check_data
;
84 * Slot used for the GRF scanning and such.
85 * This slot is used for all temporary accesses to files when scanning/testing files,
86 * and thus cannot be used for files, which are continuously accessed during a game.
89 /** Slot for the sound. */
91 /** First slot usable for (New)GRFs used during the game. */
93 /** Maximum number of GRFs in single-player */
95 /** Maximum number of slots. */
99 /** Deals with finding savegames */
107 /** List of file information. */
113 * Construct a new entry in the file list.
114 * @return Pointer to the new items to be initialized.
116 inline FiosItem
*Append()
118 return this->files
.Append();
122 * Get the number of files in the list.
123 * @return The number of files stored in the list.
125 inline uint
Length() const
127 return this->files
.Length();
131 * Get a pointer to the first file information.
132 * @return Address of the first file information.
134 inline const FiosItem
*Begin() const
136 return this->files
.Begin();
140 * Get a pointer behind the last file information.
141 * @return Address behind the last file information.
143 inline const FiosItem
*End() const
145 return this->files
.End();
149 * Get a pointer to the indicated file information. File information must exist.
150 * @return Address of the indicated existing file information.
152 inline const FiosItem
*Get(uint index
) const
154 return this->files
.Get(index
);
158 * Get a pointer to the indicated file information. File information must exist.
159 * @return Address of the indicated existing file information.
161 inline FiosItem
*Get(uint index
)
163 return this->files
.Get(index
);
166 inline const FiosItem
&operator[](uint index
) const
168 return this->files
[index
];
172 * Get a reference to the indicated file information. File information must exist.
173 * @return The requested file information.
175 inline FiosItem
&operator[](uint index
)
177 return this->files
[index
];
180 /** Remove all items from the list. */
186 /** Compact the list down to the smallest block size boundary. */
187 inline void Compact()
189 this->files
.Compact();
192 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
193 const FiosItem
*FindItem(const char *file
);
195 SmallVector
<FiosItem
, 32> files
; ///< The list of files.
204 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
206 /* Variables to display file lists */
207 extern SortingBits _savegame_sort_order
;
209 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
211 void FiosGetSavegameList(SaveLoadOperation fop
, FileList
&file_list
);
212 void FiosGetScenarioList(SaveLoadOperation fop
, FileList
&file_list
);
213 void FiosGetHeightmapList(SaveLoadOperation fop
, FileList
&file_list
);
215 const char *FiosBrowseTo(const FiosItem
*item
);
217 StringID
FiosGetDescText(const char **path
, uint64
*total_free
);
218 bool FiosDelete(const char *name
);
219 void FiosMakeHeightmapName(char *buf
, const char *name
, const char *last
);
220 void FiosMakeSavegameName(char *buf
, const char *name
, const char *last
);
222 FiosType
FiosGetSavegameListCallback(SaveLoadOperation fop
, const char *file
, const char *ext
, char *title
, const char *last
);
224 int CDECL
CompareFiosItems(const FiosItem
*a
, const FiosItem
*b
);