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 /** Deals with finding savegames */
110 /** List of file information. */
116 * Construct a new entry in the file list.
117 * @return Pointer to the new items to be initialized.
119 inline FiosItem
*Append()
121 return this->files
.Append();
125 * Get the number of files in the list.
126 * @return The number of files stored in the list.
128 inline uint
Length() const
130 return this->files
.Length();
134 * Get a pointer to the first file information.
135 * @return Address of the first file information.
137 inline const FiosItem
*Begin() const
139 return this->files
.Begin();
143 * Get a pointer behind the last file information.
144 * @return Address behind the last file information.
146 inline const FiosItem
*End() const
148 return this->files
.End();
152 * Get a pointer to the indicated file information. File information must exist.
153 * @return Address of the indicated existing file information.
155 inline const FiosItem
*Get(uint index
) const
157 return this->files
.Get(index
);
161 * Get a pointer to the indicated file information. File information must exist.
162 * @return Address of the indicated existing file information.
164 inline FiosItem
*Get(uint index
)
166 return this->files
.Get(index
);
169 inline const FiosItem
&operator[](uint index
) const
171 return this->files
[index
];
175 * Get a reference to the indicated file information. File information must exist.
176 * @return The requested file information.
178 inline FiosItem
&operator[](uint index
)
180 return this->files
[index
];
183 /** Remove all items from the list. */
189 /** Compact the list down to the smallest block size boundary. */
190 inline void Compact()
192 this->files
.Compact();
195 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
196 const FiosItem
*FindItem(const char *file
);
198 SmallVector
<FiosItem
, 32> files
; ///< The list of files.
207 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
209 /* Variables to display file lists */
210 extern SortingBits _savegame_sort_order
;
212 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
214 void FiosGetSavegameList(SaveLoadOperation fop
, FileList
&file_list
);
215 void FiosGetScenarioList(SaveLoadOperation fop
, FileList
&file_list
);
216 void FiosGetHeightmapList(SaveLoadOperation fop
, FileList
&file_list
);
218 const char *FiosBrowseTo(const FiosItem
*item
);
220 /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
221 bool FiosGetDiskFreeSpace (const char *path
, uint64
*tot
);
223 const char *FiosGetPath (void);
224 bool FiosDelete(const char *name
);
225 void FiosMakeHeightmapName(char *buf
, const char *name
, size_t size
);
226 void FiosMakeSavegameName(char *buf
, const char *name
, size_t size
);
228 FiosType
FiosGetSavegameListCallback (SaveLoadOperation fop
, const char *file
, const char *ext
, stringb
*title
= NULL
);
230 int CDECL
CompareFiosItems(const FiosItem
*a
, const FiosItem
*b
);