(svn r28004) -Update from Eints:
[openttd.git] / src / fios.h
blob5e17e8ee17737610c45886d4c949fb51c463f43c
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(NULL), grfconfig(NULL),
45 grf_compatibility(GLC_NOT_FOUND), gamelog_action(NULL), 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 != NULL;
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 slots. */
94 MAX_FILE_SLOTS = 128,
97 /** Deals with finding savegames */
98 struct FiosItem {
99 FiosType type;
100 uint64 mtime;
101 char title[64];
102 char name[MAX_PATH];
105 /** List of file information. */
106 class FileList {
107 public:
108 ~FileList();
111 * Construct a new entry in the file list.
112 * @return Pointer to the new items to be initialized.
114 inline FiosItem *Append()
116 return this->files.Append();
120 * Get the number of files in the list.
121 * @return The number of files stored in the list.
123 inline uint Length() const
125 return this->files.Length();
129 * Get a pointer to the first file information.
130 * @return Address of the first file information.
132 inline const FiosItem *Begin() const
134 return this->files.Begin();
138 * Get a pointer behind the last file information.
139 * @return Address behind the last file information.
141 inline const FiosItem *End() const
143 return this->files.End();
147 * Get a pointer to the indicated file information. File information must exist.
148 * @return Address of the indicated existing file information.
150 inline const FiosItem *Get(uint index) const
152 return this->files.Get(index);
156 * Get a pointer to the indicated file information. File information must exist.
157 * @return Address of the indicated existing file information.
159 inline FiosItem *Get(uint index)
161 return this->files.Get(index);
164 inline const FiosItem &operator[](uint index) const
166 return this->files[index];
170 * Get a reference to the indicated file information. File information must exist.
171 * @return The requested file information.
173 inline FiosItem &operator[](uint index)
175 return this->files[index];
178 /** Remove all items from the list. */
179 inline void Clear()
181 this->files.Clear();
184 /** Compact the list down to the smallest block size boundary. */
185 inline void Compact()
187 this->files.Compact();
190 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
191 const FiosItem *FindItem(const char *file);
193 SmallVector<FiosItem, 32> files; ///< The list of files.
196 enum SortingBits {
197 SORT_ASCENDING = 0,
198 SORT_DESCENDING = 1,
199 SORT_BY_DATE = 0,
200 SORT_BY_NAME = 2
202 DECLARE_ENUM_AS_BIT_SET(SortingBits)
204 /* Variables to display file lists */
205 extern SortingBits _savegame_sort_order;
207 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
209 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
210 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
211 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
213 const char *FiosBrowseTo(const FiosItem *item);
215 StringID FiosGetDescText(const char **path, uint64 *total_free);
216 bool FiosDelete(const char *name);
217 void FiosMakeHeightmapName(char *buf, const char *name, const char *last);
218 void FiosMakeSavegameName(char *buf, const char *name, const char *last);
220 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
222 int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
224 #endif /* FIOS_H */