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 /** Special values for save-load window for the data parameter of #InvalidateWindowData. */
22 enum SaveLoadInvalidateWindowData
{
23 SLIWD_RESCAN_FILES
, ///< Rescan all files (when changed directory, ...)
24 SLIWD_SELECTION_CHANGES
, ///< File selection has changed (user click, ...)
25 SLIWD_FILTER_CHANGES
, ///< The filename filter has changed (via the editbox)
28 typedef SmallMap
<uint
, CompanyProperties
*> CompanyPropertiesMap
;
31 * Container for loading in mode SL_LOAD_CHECK.
33 struct LoadCheckData
{
34 bool checkable
; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
35 StringID error
; ///< Error message from loading. INVALID_STRING_ID if no error.
36 char *error_data
; ///< Data to pass to SetDParamStr when displaying #error.
38 uint32 map_size_x
, map_size_y
;
41 GameSettings settings
;
43 CompanyPropertiesMap companies
; ///< Company information.
45 GRFConfig
*grfconfig
; ///< NewGrf configuration from save.
46 GRFListCompatibility grf_compatibility
; ///< Summary state of NewGrfs, whether missing files or only compatible found.
48 struct LoggedAction
*gamelog_action
; ///< Gamelog actions
49 uint gamelog_actions
; ///< Number of gamelog actions
51 LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
52 grf_compatibility(GLC_NOT_FOUND
), gamelog_action(nullptr), gamelog_actions(0)
58 * Don't leak memory at program exit
66 * Check whether loading the game resulted in errors.
67 * @return true if errors were encountered.
71 return this->checkable
&& this->error
!= INVALID_STRING_ID
;
75 * Check whether the game uses any NewGrfs.
76 * @return true if NewGrfs are used.
80 return this->checkable
&& this->error
== INVALID_STRING_ID
&& this->grfconfig
!= nullptr;
86 extern LoadCheckData _load_check_data
;
91 * Slot used for the GRF scanning and such.
92 * This slot is used for all temporary accesses to files when scanning/testing files,
93 * and thus cannot be used for files, which are continuously accessed during a game.
96 /** Slot for the sound. */
98 /** First slot usable for (New)GRFs used during the game. */
100 /** Maximum number of slots. */
101 MAX_FILE_SLOTS
= 128,
104 /** Deals with finding savegames */
112 /** List of file information. */
118 * Construct a new entry in the file list.
119 * @return Pointer to the new items to be initialized.
121 inline FiosItem
*Append()
123 /*C++17: return &*/ this->files
.emplace_back();
124 return &this->files
.back();
128 * Get the number of files in the list.
129 * @return The number of files stored in the list.
131 inline size_t Length() const
133 return this->files
.size();
137 * Get a pointer to the first file information.
138 * @return Address of the first file information.
140 inline const FiosItem
*Begin() const
142 return this->files
.data();
146 * Get a pointer behind the last file information.
147 * @return Address behind the last file information.
149 inline const FiosItem
*End() const
151 return this->Begin() + this->Length();
155 * Get a pointer to the indicated file information. File information must exist.
156 * @return Address of the indicated existing file information.
158 inline const FiosItem
*Get(size_t index
) const
160 return this->files
.data() + index
;
164 * Get a pointer to the indicated file information. File information must exist.
165 * @return Address of the indicated existing file information.
167 inline FiosItem
*Get(size_t index
)
169 return this->files
.data() + index
;
172 inline const FiosItem
&operator[](size_t index
) const
174 return this->files
[index
];
178 * Get a reference to the indicated file information. File information must exist.
179 * @return The requested file information.
181 inline FiosItem
&operator[](size_t index
)
183 return this->files
[index
];
186 /** Remove all items from the list. */
192 /** Compact the list down to the smallest block size boundary. */
193 inline void Compact()
195 this->files
.shrink_to_fit();
198 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
199 const FiosItem
*FindItem(const char *file
);
201 std::vector
<FiosItem
> files
; ///< The list of files.
210 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
212 /* Variables to display file lists */
213 extern SortingBits _savegame_sort_order
;
215 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
217 void FiosGetSavegameList(SaveLoadOperation fop
, FileList
&file_list
);
218 void FiosGetScenarioList(SaveLoadOperation fop
, FileList
&file_list
);
219 void FiosGetHeightmapList(SaveLoadOperation fop
, FileList
&file_list
);
221 const char *FiosBrowseTo(const FiosItem
*item
);
223 StringID
FiosGetDescText(const char **path
, uint64
*total_free
);
224 bool FiosDelete(const char *name
);
225 void FiosMakeHeightmapName(char *buf
, const char *name
, const char *last
);
226 void FiosMakeSavegameName(char *buf
, const char *name
, const char *last
);
228 FiosType
FiosGetSavegameListCallback(SaveLoadOperation fop
, const char *file
, const char *ext
, char *title
, const char *last
);
230 int CDECL
CompareFiosItems(const FiosItem
*a
, const FiosItem
*b
);