OpenTTD

fios.h
Go to the documentation of this file.
1 /* $Id: fios.h 27729 2017-01-14 13:12:49Z frosch $ */
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"
18 #include "network/core/tcp_content.h"
19
20
21 typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
22
26 struct LoadCheckData {
27 bool checkable;
28 StringID error;
29 char *error_data;
30
31 uint32 map_size_x, map_size_y;
32 Date current_date;
33
34 GameSettings settings;
35
36 CompanyPropertiesMap companies;
37
38 GRFConfig *grfconfig;
39 GRFListCompatibility grf_compatibility;
40
41 struct LoggedAction *gamelog_action;
42 uint gamelog_actions;
43
44 LoadCheckData() : error_data(NULL), grfconfig(NULL),
45 grf_compatibility(GLC_NOT_FOUND), gamelog_action(NULL), gamelog_actions(0)
46 {
47 this->Clear();
48 }
49
53 ~LoadCheckData()
54 {
55 this->Clear();
56 }
57
62 bool HasErrors()
63 {
64 return this->checkable && this->error != INVALID_STRING_ID;
65 }
66
71 bool HasNewGrfs()
72 {
73 return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != NULL;
74 }
75
76 void Clear();
77 };
78
79 extern LoadCheckData _load_check_data;
80
81
82 enum FileSlots {
88 CONFIG_SLOT = 0,
90 SOUND_SLOT = 1,
92 FIRST_GRF_SLOT = 2,
94 MAX_FILE_SLOTS = 128,
95 };
96
98 struct FiosItem {
99 FiosType type;
100 uint64 mtime;
101 char title[64];
102 char name[MAX_PATH];
103 };
104
106 class FileList {
107 public:
108 ~FileList();
109
114 inline FiosItem *Append()
115 {
116 return this->files.Append();
117 }
118
123 inline uint Length() const
124 {
125 return this->files.Length();
126 }
127
132 inline const FiosItem *Begin() const
133 {
134 return this->files.Begin();
135 }
136
141 inline const FiosItem *End() const
142 {
143 return this->files.End();
144 }
145
150 inline const FiosItem *Get(uint index) const
151 {
152 return this->files.Get(index);
153 }
154
159 inline FiosItem *Get(uint index)
160 {
161 return this->files.Get(index);
162 }
163
164 inline const FiosItem &operator[](uint index) const
165 {
166 return this->files[index];
167 }
168
173 inline FiosItem &operator[](uint index)
174 {
175 return this->files[index];
176 }
177
179 inline void Clear()
180 {
181 this->files.Clear();
182 }
183
185 inline void Compact()
186 {
187 this->files.Compact();
188 }
189
190 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
191 const FiosItem *FindItem(const char *file);
192
193 SmallVector<FiosItem, 32> files;
194 };
195
196 enum SortingBits {
197 SORT_ASCENDING = 0,
198 SORT_DESCENDING = 1,
199 SORT_BY_DATE = 0,
200 SORT_BY_NAME = 2
201 };
202 DECLARE_ENUM_AS_BIT_SET(SortingBits)
203
204 /* Variables to display file lists */
205 extern SortingBits _savegame_sort_order;
206
207 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
208
209 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
210 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
211 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
212
213 const char *FiosBrowseTo(const FiosItem *item);
214
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);
219
220 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
221
222 int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
223
224 #endif /* FIOS_H */
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:69
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:18
SOUND_SLOT
Slot for the sound.
Definition: fios.h:90
FIRST_GRF_SLOT
First slot usable for (New)GRFs used during the game.
Definition: fios.h:92
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:31
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
FiosMakeHeightmapName
void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
Construct a filename for a height map.
Definition: fios.cpp:256
LoadCheckData
Container for loading in mode SL_LOAD_CHECK.
Definition: fios.h:26
FileList::Clear
void Clear()
Remove all items from the list.
Definition: fios.h:179
GameSettings
All settings together for the game.
Definition: settings_type.h:542
LoadCheckData::gamelog_action
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:41
SmallMap< uint, CompanyProperties * >
FiosGetSavegameList
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list)
Get a list of savegames.
Definition: fios.cpp:493
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:38
MAX_FILE_SLOTS
Maximum number of slots.
Definition: fios.h:94
FileList::Begin
const FiosItem * Begin() const
Get a pointer to the first file information.
Definition: fios.h:132
FiosMakeSavegameName
void FiosMakeSavegameName(char *buf, const char *name, const char *last)
Make a save game or scenario filename from a name.
Definition: fios.cpp:243
SmallVector< FiosItem, 32 >
CONFIG_SLOT
Slot used for the GRF scanning and such.
Definition: fios.h:88
FiosDelete
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:270
FiosItem
Deals with finding savegames.
Definition: fios.h:98
FileList::files
SmallVector< FiosItem, 32 > files
The list of files.
Definition: fios.h:193
LoadCheckData::checkable
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
Definition: fios.h:27
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:39
FileList::Length
uint Length() const
Get the number of files in the list.
Definition: fios.h:123
FileList::End
const FiosItem * End() const
Get a pointer behind the last file information.
Definition: fios.h:141
FiosGetScenarioList
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list)
Get a list of scenarios.
Definition: fios.cpp:548
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition: gamelog_internal.h:81
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:153
FiosGetDescText
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:141
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition: fios.h:36
FiosBrowseTo
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:152
LoadCheckData::Clear
void Clear()
Reset read data.
Definition: fios_gui.cpp:48
CompareFiosItems
int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b)
Compare two FiosItem&#39;s.
Definition: fios.cpp:52
LoadCheckData::error_data
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:29
FileList::Get
const FiosItem * Get(uint index) const
Get a pointer to the indicated file information.
Definition: fios.h:150
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:62
tcp_content.h
Basic functions to receive and send TCP packets to/from the content server.
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:28
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:49
FiosGetHeightmapList
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list)
Get a list of heightmaps.
Definition: fios.cpp:619
newgrf_config.h
Functions to find and configure NewGRFs.
FileList::Compact
void Compact()
Compact the list down to the smallest block size boundary.
Definition: fios.h:185
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:768
GRFListCompatibility
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition: newgrf_config.h:53
FileSlots
FileSlots
Definition: fios.h:82
FileList
List of file information.
Definition: fios.h:106
GLC_NOT_FOUND
At least one GRF couldn&#39;t be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:56
FileList::operator[]
FiosItem & operator[](uint index)
Get a reference to the indicated file information.
Definition: fios.h:173
LoadCheckData::gamelog_actions
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:42
LoadCheckData::~LoadCheckData
~LoadCheckData()
Don&#39;t leak memory at program exit.
Definition: fios.h:53
FileList::Get
FiosItem * Get(uint index)
Get a pointer to the indicated file information.
Definition: fios.h:159
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:71
FileList::Append
FiosItem * Append()
Construct a new entry in the file list.
Definition: fios.h:114
LoadCheckData::grf_compatibility
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition: fios.h:39
gfx_type.h
Types related to the graphics and/or input devices.
FiosGetSavegameListCallback
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:460