2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file fios.h Declarations for savegames operations */
14 #include "company_base.h"
15 #include "newgrf_config.h"
16 #include "network/core/tcp_content.h"
19 /** Special values for save-load window for the data parameter of #InvalidateWindowData. */
20 enum SaveLoadInvalidateWindowData
{
21 SLIWD_RESCAN_FILES
, ///< Rescan all files (when changed directory, ...)
22 SLIWD_SELECTION_CHANGES
, ///< File selection has changed (user click, ...)
23 SLIWD_FILTER_CHANGES
, ///< The filename filter has changed (via the editbox)
26 typedef SmallMap
<uint
, CompanyProperties
*> CompanyPropertiesMap
;
29 * Container for loading in mode SL_LOAD_CHECK.
31 struct LoadCheckData
{
32 bool checkable
; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
33 StringID error
; ///< Error message from loading. INVALID_STRING_ID if no error.
34 char *error_data
; ///< Data to pass to SetDParamStr when displaying #error.
36 uint32 map_size_x
, map_size_y
;
39 GameSettings settings
;
41 CompanyPropertiesMap companies
; ///< Company information.
43 GRFConfig
*grfconfig
; ///< NewGrf configuration from save.
44 GRFListCompatibility grf_compatibility
; ///< Summary state of NewGrfs, whether missing files or only compatible found.
46 struct LoggedAction
*gamelog_action
; ///< Gamelog actions
47 uint gamelog_actions
; ///< Number of gamelog actions
49 LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
50 grf_compatibility(GLC_NOT_FOUND
), gamelog_action(nullptr), gamelog_actions(0)
56 * Don't leak memory at program exit
64 * Check whether loading the game resulted in errors.
65 * @return true if errors were encountered.
69 return this->checkable
&& this->error
!= INVALID_STRING_ID
;
73 * Check whether the game uses any NewGrfs.
74 * @return true if NewGrfs are used.
78 return this->checkable
&& this->error
== INVALID_STRING_ID
&& this->grfconfig
!= nullptr;
84 extern LoadCheckData _load_check_data
;
89 * Slot used for the GRF scanning and such.
90 * This slot is used for all temporary accesses to files when scanning/testing files,
91 * and thus cannot be used for files, which are continuously accessed during a game.
94 /** Slot for the sound. */
96 /** First slot usable for (New)GRFs used during the game. */
98 /** Maximum number of slots. */
102 /** Deals with finding savegames */
108 bool operator< (const FiosItem
&other
) const;
111 /** List of file information. */
117 * Construct a new entry in the file list.
118 * @return Pointer to the new items to be initialized.
120 inline FiosItem
*Append()
122 /*C++17: return &*/ this->files
.emplace_back();
123 return &this->files
.back();
127 * Get the number of files in the list.
128 * @return The number of files stored in the list.
130 inline size_t Length() const
132 return this->files
.size();
136 * Get a pointer to the first file information.
137 * @return Address of the first file information.
139 inline const FiosItem
*Begin() const
141 return this->files
.data();
145 * Get a pointer behind the last file information.
146 * @return Address behind the last file information.
148 inline const FiosItem
*End() const
150 return this->Begin() + this->Length();
154 * Get a pointer to the indicated file information. File information must exist.
155 * @return Address of the indicated existing file information.
157 inline const FiosItem
*Get(size_t index
) const
159 return this->files
.data() + index
;
163 * Get a pointer to the indicated file information. File information must exist.
164 * @return Address of the indicated existing file information.
166 inline FiosItem
*Get(size_t index
)
168 return this->files
.data() + index
;
171 inline const FiosItem
&operator[](size_t index
) const
173 return this->files
[index
];
177 * Get a reference to the indicated file information. File information must exist.
178 * @return The requested file information.
180 inline FiosItem
&operator[](size_t index
)
182 return this->files
[index
];
185 /** Remove all items from the list. */
191 /** Compact the list down to the smallest block size boundary. */
192 inline void Compact()
194 this->files
.shrink_to_fit();
197 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
198 const FiosItem
*FindItem(const char *file
);
200 std::vector
<FiosItem
> files
; ///< The list of files.
209 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
211 /* Variables to display file lists */
212 extern SortingBits _savegame_sort_order
;
214 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
216 void FiosGetSavegameList(SaveLoadOperation fop
, FileList
&file_list
);
217 void FiosGetScenarioList(SaveLoadOperation fop
, FileList
&file_list
);
218 void FiosGetHeightmapList(SaveLoadOperation fop
, FileList
&file_list
);
220 const char *FiosBrowseTo(const FiosItem
*item
);
222 StringID
FiosGetDescText(const char **path
, uint64
*total_free
);
223 bool FiosDelete(const char *name
);
224 void FiosMakeHeightmapName(char *buf
, const char *name
, const char *last
);
225 void FiosMakeSavegameName(char *buf
, const char *name
, const char *last
);
227 FiosType
FiosGetSavegameListCallback(SaveLoadOperation fop
, const char *file
, const char *ext
, char *title
, const char *last
);