Merge branch 'development' into master_joker
[openttd-joker.git] / src / fios.h
blobd1017344e2ba77afdd3106e1499d39b2fc66c31d
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file fios.h Declarations for savegames operations */
12 #ifndef FIOS_H
13 #define FIOS_H
15 #include "gfx_type.h"
16 #include "company_base.h"
17 #include "newgrf_config.h"
18 #include "network/core/tcp_content.h"
21 typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
23 /**
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;
32 Date current_date;
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)
47 this->Clear();
50 /**
51 * Don't leak memory at program exit
53 ~LoadCheckData()
55 this->Clear();
58 /**
59 * Check whether loading the game resulted in errors.
60 * @return true if errors were encountered.
62 bool HasErrors()
64 return this->checkable && this->error != INVALID_STRING_ID;
67 /**
68 * Check whether the game uses any NewGrfs.
69 * @return true if NewGrfs are used.
71 bool HasNewGrfs()
73 return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
76 void Clear();
79 extern LoadCheckData _load_check_data;
82 enum FileSlots {
83 /**
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.
88 CONFIG_SLOT = 0,
89 /** Slot for the sound. */
90 SOUND_SLOT = 1,
91 /** First slot usable for (New)GRFs used during the game. */
92 FIRST_GRF_SLOT = 2,
93 /** Maximum number of GRFs in single-player */
94 MAX_NEWGRFS = 256,
95 /** Maximum number of slots. */
96 MAX_FILE_SLOTS = 300,
99 /** Deals with finding savegames */
100 struct FiosItem {
101 FiosType type;
102 uint64 mtime;
103 char title[64];
104 char name[MAX_PATH];
107 /** List of file information. */
108 class FileList {
109 public:
110 ~FileList();
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. */
181 inline void Clear()
183 this->files.Clear();
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.
198 enum SortingBits {
199 SORT_ASCENDING = 0,
200 SORT_DESCENDING = 1,
201 SORT_BY_DATE = 0,
202 SORT_BY_NAME = 2
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);
226 #endif /* FIOS_H */