OpenTTD Source: src/fios.h Source File

OpenTTD Source 15.0-RC2

fios.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef FIOS_H
11#define FIOS_H
12
13#include "gfx_type.h"
14#include "company_base.h"
15#include "newgrf_config.h"
16#include "gamelog.h"
17#include "network/core/tcp_content_type.h"
18#include "timer/timer_game_calendar.h"
19
20
22 enum SaveLoadInvalidateWindowData : uint8_t {
23 SLIWD_RESCAN_FILES,
24 SLIWD_SELECTION_CHANGES,
25 SLIWD_FILTER_CHANGES,
26};
27
28using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>;
29
33 struct LoadCheckData {
34 bool checkable = false;
35 StringID error{};
36 std::string error_msg{};
37
38 uint32_t map_size_x = 0;
39 uint32_t map_size_y = 0;
40 TimerGameCalendar::Date current_date{};
41
42 LandscapeType landscape{};
43 TimerGameCalendar::Year starting_year{};
44
45 CompanyPropertiesMap companies{};
46
47 GRFConfigList grfconfig{};
48 GRFListCompatibility grf_compatibility = GLC_NOT_FOUND;
49
50 Gamelog gamelog{};
51
52 LoadCheckData() {}
53
58 bool HasErrors()
59 {
60 return this->checkable && this->error != INVALID_STRING_ID;
61 }
62
67 bool HasNewGrfs()
68 {
69 return this->checkable && this->error == INVALID_STRING_ID && !this->grfconfig.empty();
70 }
71
72 void Clear();
73};
74
75extern LoadCheckData _load_check_data;
76
78 struct FiosItem {
79 FiosType type;
80 int64_t mtime;
81 EncodedString title;
82 std::string name;
83 bool operator< (const FiosItem &other) const;
84};
85
87 class FileList : public std::vector<FiosItem> {
88public:
89 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs);
90 const FiosItem *FindItem(std::string_view file);
91};
92
93enum SortingBits : uint8_t {
94 SORT_ASCENDING = 0,
95 SORT_DESCENDING = 1,
96 SORT_BY_DATE = 0,
97 SORT_BY_NAME = 2
98};
99 DECLARE_ENUM_AS_BIT_SET(SortingBits)
100
101/* Variables to display file lists */
102extern SortingBits _savegame_sort_order;
103
104void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
105
106void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
107void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
108void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
109void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
110
111bool FiosBrowseTo(const FiosItem *item);
112
113std::string FiosGetCurrentPath();
114std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path);
115std::string FiosMakeHeightmapName(std::string_view name);
116std::string FiosMakeSavegameName(std::string_view name);
117
118std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
119std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
120std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
121
122void ScanScenarios();
123std::optional<std::string_view> FindScenario(const ContentInfo &ci, bool md5sum);
124
128 struct FiosNumberedSaveName {
129 FiosNumberedSaveName(const std::string &prefix);
130 std::string Filename();
131 std::string Extension();
132private:
133 std::string prefix;
134 int number;
135};
136
137#endif /* FIOS_H */
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
FileList
List of file information.
Definition fios.h:87
FileList::BuildFileList
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Definition fios.cpp:67
FileList::FindItem
const FiosItem * FindItem(std::string_view file)
Find file information of a file by its name from the file list.
Definition fios.cpp:103
Gamelog
Definition gamelog.h:49
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
DECLARE_ENUM_AS_BIT_SET
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:119
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition fileio_type.h:52
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition fileio_type.h:17
FiosGetScenarioListCallback
std::tuple< FiosType, std::string > FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:441
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition fios_gui.cpp:999
FindScenario
std::optional< std::string_view > FindScenario(const ContentInfo &ci, bool md5sum)
Find a given scenario based on its unique ID.
Definition fios.cpp:664
FiosMakeSavegameName
std::string FiosMakeSavegameName(std::string_view name)
Make a save game or scenario filename from a name.
Definition fios.cpp:216
FiosGetSavegameListCallback
std::tuple< FiosType, std::string > FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:392
FiosGetCurrentPath
std::string FiosGetCurrentPath()
Get the current path/working directory.
Definition fios.cpp:132
SaveLoadInvalidateWindowData
SaveLoadInvalidateWindowData
Special values for save-load window for the data parameter of InvalidateWindowData.
Definition fios.h:22
SLIWD_FILTER_CHANGES
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
Definition fios.h:25
SLIWD_SELECTION_CHANGES
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
Definition fios.h:24
SLIWD_RESCAN_FILES
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
Definition fios.h:23
FiosGetSavegameList
void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of savegames.
Definition fios.cpp:421
FiosGetHeightmapList
void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of heightmaps.
Definition fios.cpp:528
ScanScenarios
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition fios.cpp:692
FiosMakeHeightmapName
std::string FiosMakeHeightmapName(std::string_view name)
Construct a filename for a height map.
Definition fios.cpp:228
FiosGetScenarioList
void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of scenarios.
Definition fios.cpp:468
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:41
FiosBrowseTo
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at _fios_path.
Definition fios.cpp:142
FiosGetTownDataList
void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of town data files.
Definition fios.cpp:564
gamelog.h
Functions to be called to log fundamental changes to the game.
gfx_type.h
Types related to the graphics and/or input devices.
LandscapeType
LandscapeType
Landscape types.
Definition landscape_type.h:16
newgrf_config.h
Functions to find and configure NewGRFs.
GRFListCompatibility
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition newgrf_config.h:52
GLC_NOT_FOUND
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
Definition newgrf_config.h:55
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
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:20
ContentInfo
Container for all important information about a piece of content.
Definition tcp_content_type.h:56
FiosItem
Deals with finding savegames.
Definition fios.h:78
FiosItem::operator<
bool operator<(const FiosItem &other) const
Compare two FiosItem's.
Definition fios.cpp:48
FiosNumberedSaveName
A savegame name automatically numbered.
Definition fios.h:128
FiosNumberedSaveName::Filename
std::string Filename()
Generate a savegame name and number according to _settings_client.gui.max_num_autosaves.
Definition fios.cpp:738
FiosNumberedSaveName::Extension
std::string Extension()
Generate an extension for a savegame name.
Definition fios.cpp:748
FiosType
Elements of a file system that are recognized.
Definition fileio_type.h:63
LoadCheckData
Container for loading in mode SL_LOAD_CHECK.
Definition fios.h:33
LoadCheckData::checkable
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
Definition fios.h:34
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition fios.h:67
LoadCheckData::error_msg
std::string error_msg
Data to pass to string parameters when displaying error.
Definition fios.h:36
LoadCheckData::starting_year
TimerGameCalendar::Year starting_year
Starting date.
Definition fios.h:43
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition fios.h:45
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition fios.h:35
LoadCheckData::gamelog
Gamelog gamelog
Gamelog actions.
Definition fios.h:50
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition fios.h:58
LoadCheckData::Clear
void Clear()
Reset read data.
Definition fios_gui.cpp:49
LoadCheckData::grf_compatibility
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition fios.h:48
LoadCheckData::landscape
LandscapeType landscape
Landscape type.
Definition fios.h:42
LoadCheckData::grfconfig
GRFConfigList grfconfig
NewGrf configuration from save.
Definition fios.h:47
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
tcp_content_type.h
Basic types related to the content on the content server.
timer_game_calendar.h
Definition of the game-calendar-timer.