Feature: Import town data from JSON file (#10409)
[openttd-github.git] / src / fios.h
blobf981c6c74c4724c449a525e9bdc53d2784db0204
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 <http://www.gnu.org/licenses/>.
6 */
8 /** @file fios.h Declarations for savegames operations */
10 #ifndef FIOS_H
11 #define FIOS_H
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"
21 /** Special values for save-load window for the data parameter of #InvalidateWindowData. */
22 enum SaveLoadInvalidateWindowData {
23 SLIWD_RESCAN_FILES, ///< Rescan all files (when changed directory, ...)
24 SLIWD_SELECTION_CHANGES, ///< File selection has changed (user click, ...)
25 SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
28 using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>;
30 /**
31 * Container for loading in mode SL_LOAD_CHECK.
33 struct LoadCheckData {
34 bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
35 StringID error; ///< Error message from loading. INVALID_STRING_ID if no error.
36 std::string error_msg; ///< Data to pass to SetDParamStr when displaying #error.
38 uint32_t map_size_x, map_size_y;
39 TimerGameCalendar::Date current_date;
41 GameSettings settings;
43 CompanyPropertiesMap companies; ///< Company information.
45 GRFConfig *grfconfig; ///< NewGrf configuration from save.
46 GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
48 Gamelog gamelog; ///< Gamelog actions
50 LoadCheckData() : grfconfig(nullptr),
51 grf_compatibility(GLC_NOT_FOUND)
55 /**
56 * Check whether loading the game resulted in errors.
57 * @return true if errors were encountered.
59 bool HasErrors()
61 return this->checkable && this->error != INVALID_STRING_ID;
64 /**
65 * Check whether the game uses any NewGrfs.
66 * @return true if NewGrfs are used.
68 bool HasNewGrfs()
70 return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
73 void Clear();
76 extern LoadCheckData _load_check_data;
78 /** Deals with finding savegames */
79 struct FiosItem {
80 FiosType type;
81 int64_t mtime;
82 std::string title;
83 std::string name;
84 bool operator< (const FiosItem &other) const;
87 /** List of file information. */
88 class FileList : public std::vector<FiosItem> {
89 public:
90 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs);
91 const FiosItem *FindItem(const std::string_view file);
94 enum SortingBits {
95 SORT_ASCENDING = 0,
96 SORT_DESCENDING = 1,
97 SORT_BY_DATE = 0,
98 SORT_BY_NAME = 2
100 DECLARE_ENUM_AS_BIT_SET(SortingBits)
102 /* Variables to display file lists */
103 extern SortingBits _savegame_sort_order;
105 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
107 void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
108 void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
109 void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
110 void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
112 bool FiosBrowseTo(const FiosItem *item);
114 std::string FiosGetCurrentPath();
115 std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path);
116 bool FiosDelete(const char *name);
117 std::string FiosMakeHeightmapName(const char *name);
118 std::string FiosMakeSavegameName(const char *name);
120 std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
121 std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
122 std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
124 void ScanScenarios();
125 const char *FindScenario(const ContentInfo *ci, bool md5sum);
128 * A savegame name automatically numbered.
130 struct FiosNumberedSaveName {
131 FiosNumberedSaveName(const std::string &prefix);
132 std::string Filename();
133 std::string Extension();
134 private:
135 std::string prefix;
136 int number;
139 #endif /* FIOS_H */