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 return &this->files
.emplace_back();
126 * Get the number of files in the list.
127 * @return The number of files stored in the list.
129 inline size_t Length() const
131 return this->files
.size();
135 * Get a pointer to the first file information.
136 * @return Address of the first file information.
138 inline const FiosItem
*Begin() const
140 return this->files
.data();
144 * Get a pointer behind the last file information.
145 * @return Address behind the last file information.
147 inline const FiosItem
*End() const
149 return this->Begin() + this->Length();
153 * Get a pointer to the indicated file information. File information must exist.
154 * @return Address of the indicated existing file information.
156 inline const FiosItem
*Get(size_t index
) const
158 return this->files
.data() + index
;
162 * Get a pointer to the indicated file information. File information must exist.
163 * @return Address of the indicated existing file information.
165 inline FiosItem
*Get(size_t index
)
167 return this->files
.data() + index
;
170 inline const FiosItem
&operator[](size_t index
) const
172 return this->files
[index
];
176 * Get a reference to the indicated file information. File information must exist.
177 * @return The requested file information.
179 inline FiosItem
&operator[](size_t index
)
181 return this->files
[index
];
184 /** Remove all items from the list. */
190 /** Compact the list down to the smallest block size boundary. */
191 inline void Compact()
193 this->files
.shrink_to_fit();
196 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
197 const FiosItem
*FindItem(const char *file
);
199 std::vector
<FiosItem
> files
; ///< The list of files.
208 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
210 /* Variables to display file lists */
211 extern SortingBits _savegame_sort_order
;
213 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
215 void FiosGetSavegameList(SaveLoadOperation fop
, FileList
&file_list
);
216 void FiosGetScenarioList(SaveLoadOperation fop
, FileList
&file_list
);
217 void FiosGetHeightmapList(SaveLoadOperation fop
, FileList
&file_list
);
219 const char *FiosBrowseTo(const FiosItem
*item
);
221 StringID
FiosGetDescText(const char **path
, uint64
*total_free
);
222 bool FiosDelete(const char *name
);
223 std::string
FiosMakeHeightmapName(const char *name
);
224 std::string
FiosMakeSavegameName(const char *name
);
226 FiosType
FiosGetSavegameListCallback(SaveLoadOperation fop
, const std::string
&file
, const char *ext
, char *title
, const char *last
);