OpenTTD
fios.h
Go to the documentation of this file.
1 /* $Id$ */
2 
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  */
9 
12 #ifndef FIOS_H
13 #define FIOS_H
14 
15 #include "gfx_type.h"
16 #include "company_base.h"
17 #include "newgrf_config.h"
19 
20 
26 };
27 
29 
33 struct LoadCheckData {
34  bool checkable;
36  char *error_data;
37 
38  uint32 map_size_x, map_size_y;
39  Date current_date;
40 
41  GameSettings settings;
42 
44 
47 
50 
51  LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
52  grf_compatibility(GLC_NOT_FOUND), gamelog_action(nullptr), gamelog_actions(0)
53  {
54  this->Clear();
55  }
56 
61  {
62  this->Clear();
63  }
64 
69  bool HasErrors()
70  {
71  return this->checkable && this->error != INVALID_STRING_ID;
72  }
73 
78  bool HasNewGrfs()
79  {
80  return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
81  }
82 
83  void Clear();
84 };
85 
87 
88 
89 enum FileSlots {
102 };
103 
105 struct FiosItem {
106  FiosType type;
107  uint64 mtime;
108  char title[64];
109  char name[MAX_PATH];
110  bool operator< (const FiosItem &other) const;
111 };
112 
114 class FileList {
115 public:
116  ~FileList();
117 
122  inline FiosItem *Append()
123  {
124  /*C++17: return &*/ this->files.emplace_back();
125  return &this->files.back();
126  }
127 
132  inline size_t Length() const
133  {
134  return this->files.size();
135  }
136 
141  inline const FiosItem *Begin() const
142  {
143  return this->files.data();
144  }
145 
150  inline const FiosItem *End() const
151  {
152  return this->Begin() + this->Length();
153  }
154 
159  inline const FiosItem *Get(size_t index) const
160  {
161  return this->files.data() + index;
162  }
163 
168  inline FiosItem *Get(size_t index)
169  {
170  return this->files.data() + index;
171  }
172 
173  inline const FiosItem &operator[](size_t index) const
174  {
175  return this->files[index];
176  }
177 
182  inline FiosItem &operator[](size_t index)
183  {
184  return this->files[index];
185  }
186 
188  inline void Clear()
189  {
190  this->files.clear();
191  }
192 
194  inline void Compact()
195  {
196  this->files.shrink_to_fit();
197  }
198 
199  void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
200  const FiosItem *FindItem(const char *file);
201 
202  std::vector<FiosItem> files;
203 };
204 
205 enum SortingBits {
206  SORT_ASCENDING = 0,
207  SORT_DESCENDING = 1,
208  SORT_BY_DATE = 0,
209  SORT_BY_NAME = 2
210 };
211 DECLARE_ENUM_AS_BIT_SET(SortingBits)
212 
213 /* Variables to display file lists */
214 extern SortingBits _savegame_sort_order;
215 
216 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
217 
218 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
219 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
220 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
221 
222 const char *FiosBrowseTo(const FiosItem *item);
223 
224 StringID FiosGetDescText(const char **path, uint64 *total_free);
225 bool FiosDelete(const char *name);
226 void FiosMakeHeightmapName(char *buf, const char *name, const char *last);
227 void FiosMakeSavegameName(char *buf, const char *name, const char *last);
228 
229 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
230 
231 #endif /* FIOS_H */
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:69
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:18
Slot for the sound.
Definition: fios.h:97
First slot usable for (New)GRFs used during the game.
Definition: fios.h:99
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition of stuff that is very close to a company, like the company struct itself.
const FiosItem * Get(size_t index) const
Get a pointer to the indicated file information.
Definition: fios.h:159
void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
Construct a filename for a height map.
Definition: fios.cpp:241
Container for loading in mode SL_LOAD_CHECK.
Definition: fios.h:33
void Clear()
Remove all items from the list.
Definition: fios.h:188
All settings together for the game.
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:48
std::vector< FiosItem > files
The list of files.
Definition: fios.h:202
size_t Length() const
Get the number of files in the list.
Definition: fios.h:132
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list)
Get a list of savegames.
Definition: fios.cpp:494
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:45
SaveLoadInvalidateWindowData
Special values for save-load window for the data parameter of InvalidateWindowData.
Definition: fios.h:22
Maximum number of slots.
Definition: fios.h:101
const FiosItem * Begin() const
Get a pointer to the first file information.
Definition: fios.h:141
void FiosMakeSavegameName(char *buf, const char *name, const char *last)
Make a save game or scenario filename from a name.
Definition: fios.cpp:228
File selection has changed (user click, ...)
Definition: fios.h:24
Slot used for the GRF scanning and such.
Definition: fios.h:95
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:255
Deals with finding savegames.
Definition: fios.h:105
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
Definition: fios.h:34
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:40
const FiosItem * End() const
Get a pointer behind the last file information.
Definition: fios.h:150
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list)
Get a list of scenarios.
Definition: fios.cpp:549
FiosItem * Get(size_t index)
Get a pointer to the indicated file information.
Definition: fios.h:168
Contains information about one logged action that caused at least one logged change.
Information about GRF, used in the game and (part of it) in savegames.
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:141
CompanyPropertiesMap companies
Company information.
Definition: fios.h:43
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:152
void Clear()
Reset read data.
Definition: fios_gui.cpp:49
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:36
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:69
Basic functions to receive and send TCP packets to/from the content server.
The filename filter has changed (via the editbox)
Definition: fios.h:25
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:35
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:49
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list)
Get a list of heightmaps.
Definition: fios.cpp:620
Functions to find and configure NewGRFs.
void Compact()
Compact the list down to the smallest block size boundary.
Definition: fios.h:194
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:890
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition: newgrf_config.h:53
FileSlots
Definition: fios.h:89
List of file information.
Definition: fios.h:114
At least one GRF couldn&#39;t be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:56
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:49
Rescan all files (when changed directory, ...)
Definition: fios.h:23
~LoadCheckData()
Don&#39;t leak memory at program exit.
Definition: fios.h:60
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
int32 Date
The type to store our dates in.
Definition: date_type.h:16
FiosItem & operator[](size_t index)
Get a reference to the indicated file information.
Definition: fios.h:182
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:78
FiosItem * Append()
Construct a new entry in the file list.
Definition: fios.h:122
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition: fios.h:46
Types related to the graphics and/or input devices.
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:461