21#include "3rdparty/fmt/ranges.h"
47# include <fontconfig/fontconfig.h>
56# include FT_FREETYPE_H
62# include <unicode/uversion.h>
77# include <curl/curl.h>
121 static const SettingTable _generic_setting_tables[] = {
122 _difficulty_settings,
128 _multimedia_settings,
130 _news_display_settings,
131 _pathfinding_settings,
135 return _generic_setting_tables;
146static void SurveySettingsTable(nlohmann::json &survey,
const SettingTable &table,
void *
object,
bool skip_if_default)
148 for (
auto &desc : table) {
153 const auto &name = sd->
GetName();
167#if defined(_WIN32) && !defined(DEDICATED)
185 survey[
"name"] =
"MSVC";
186 survey[
"version"] = _MSC_VER;
187#elif defined(__ICC) && defined(__GNUC__)
188 survey[
"name"] =
"ICC";
189 survey[
"version"] = __ICC;
190# if defined(__GNUC__)
191 survey[
"extra"] = fmt::format(
"GCC {}.{}.{} mode", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
193#elif defined(__GNUC__)
194 survey[
"name"] =
"GCC";
195 survey[
"version"] = fmt::format(
"{}.{}.{}", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
197 survey[
"name"] =
"unknown";
200#if defined(__VERSION__)
201 survey[
"extra"] = __VERSION__;
212 survey[
"version"][
"revision"] = std::string(_openttd_revision);
213 survey[
"version"][
"modified"] = _openttd_revision_modified;
214 survey[
"version"][
"tagged"] = _openttd_revision_tagged;
215 survey[
"version"][
"hash"] = std::string(_openttd_revision_hash);
216 survey[
"version"][
"newgrf"] = fmt::format(
"{:X}", _openttd_newgrf_version);
217 survey[
"version"][
"content"] = std::string(_openttd_content_version);
218 survey[
"build_date"] = std::string(_openttd_build_date);
220#ifdef POINTER_IS_64BIT
226 if constexpr (std::endian::native == std::endian::little) survey[
"endian"] =
"little";
227 if constexpr (std::endian::native == std::endian::big) survey[
"endian"] =
"big";
228 survey[
"dedicated_build"] =
245 survey[
"seconds"] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() -
_game_session_stats.
start_time).count();
280 if (extra_cfg !=
nullptr && !extra_cfg->
param.empty()) {
281 survey[
"graphics_set_parameters"] = std::span<const uint32_t>(extra_cfg->
param);
283 survey[
"graphics_set_parameters"] = std::span<const uint32_t>();
303 auto &font = survey[std::string(FontSizeToName(fs))];
304 font[
"configured"][
"font"] = setting->
font;
305 font[
"configured"][
"size"] = setting->
size;
308 if (fc ==
nullptr)
continue;
309 auto &font = survey[std::string(FontSizeToName(fc->GetSize()))];
310 font[
"active"].push_back(fc->GetFontName());
322 auto &company = survey[fmt::format(
"{}", c->index.base())];
323 if (c->ai_info ==
nullptr) {
324 company[
"type"] =
"human";
326 company[
"type"] =
"ai";
327 company[
"script"] = fmt::format(
"{}.{}", c->ai_info->GetName(), c->ai_info->GetVersion());
331 uint amount = c->group_all[type].num_vehicle;
335 company[
"infrastructure"][
"road"] = c->infrastructure.GetRoadTotal();
336 company[
"infrastructure"][
"tram"] = c->infrastructure.GetTramTotal();
337 company[
"infrastructure"][
"rail"] = c->infrastructure.GetRailTotal();
338 company[
"infrastructure"][
"signal"] = c->infrastructure.signal;
339 company[
"infrastructure"][
"water"] = c->infrastructure.water;
340 company[
"infrastructure"][
"station"] = c->infrastructure.station;
341 company[
"infrastructure"][
"airport"] = c->infrastructure.airport;
355 survey[
"economy"] = fmt::format(
"{:04}-{:02}-{:02} ({})", economy_ymd.year, economy_ymd.month + 1, economy_ymd.day,
TimerGameEconomy::date_fract);
369 auto grfid = fmt::format(
"{:08x}", std::byteswap(c->ident.grfid));
370 auto &grf = survey[std::move(grfid)];
373 grf[
"status"] = c->status;
384 grf[
"parameters"] = std::span<const uint32_t>(c->param);
408 survey[
"allegro"] = std::string(allegro_id);
411#ifdef WITH_FONTCONFIG
412 int version = FcGetVersion();
413 survey[
"fontconfig"] = fmt::format(
"{}.{}.{}", version / 10000, (version / 100) % 100, version % 100);
418 int major, minor, patch;
419 FT_Init_FreeType(&library);
420 FT_Library_Version(library, &major, &minor, &patch);
421 FT_Done_FreeType(library);
422 survey[
"freetype"] = fmt::format(
"{}.{}.{}", major, minor, patch);
425#if defined(WITH_HARFBUZZ)
426 survey[
"harfbuzz"] = hb_version_string();
429#if defined(WITH_ICU_I18N)
431 char buf[4 * 3 + 3 + 1];
434 u_versionToString(ver, buf);
435 survey[
"icu_i18n"] = buf;
439 survey[
"lzma"] = lzma_version_string();
443 survey[
"lzo"] = lzo_version_string();
447 survey[
"png"] = png_get_libpng_ver(
nullptr);
452 SDL_GetVersion(&sdl2_v);
453 survey[
"sdl2"] = fmt::format(
"{}.{}.{}", sdl2_v.major, sdl2_v.minor, sdl2_v.patch);
457 survey[
"zlib"] = zlibVersion();
461 auto *curl_v = curl_version_info(CURLVERSION_NOW);
462 survey[
"curl"] = curl_v->version;
463 survey[
"curl_ssl"] = curl_v->ssl_version ==
nullptr ?
"none" : curl_v->ssl_version;
477 auto &platform = survey[plugin->social_platform];
479 {
"name", plugin->name},
480 {
"version", plugin->version},
481 {
"basepath", plugin->basepath},
482 {
"state", plugin->state},
497 memory = memory / 1024;
498 memory =
CeilDiv(memory, 1024);
502 return fmt::format(
"{} GiB",
CeilDiv(memory, 1024));
507 return fmt::format(
"{} MiB",
Ceil(memory, 128));
511 return fmt::format(
"{} MiB",
Ceil(memory, 4));
AIInfo keeps track of all information of an AI, like Author, Description, ...
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
virtual std::string_view GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
virtual std::string_view GetName() const =0
Get the name of this driver.
static std::span< const std::unique_ptr< FontCache > > Get()
Get span of all FontCaches.
static class GameInfo * GetInfo()
Get the current GameInfo.
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
@ PLATFORM_NOT_RUNNING
The plugin failed to initialize because the Social Platform is not running.
@ UNSUPPORTED_API
The plugin does not support the current API version.
@ RUNNING
The plugin is successfully loaded and running.
@ FAILED
The plugin failed to initialize.
@ DUPLICATE
Another plugin of the same Social Platform is already loaded.
@ INVALID_SIGNATURE
The signature of the plugin is invalid.
@ UNLOADED
The plugin is unloaded upon request.
static std::vector< SocialIntegrationPlugin * > GetPlugins()
Get the list of loaded social integration plugins.
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Functions to handle different currencies.
CurrencySpec & GetCustomCurrency()
Get the custom currency.
Factory to 'query' all available blitters.
Functions to read fonts from files and cache them.
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Base functions for all Games.
GameInfo keeps track of all information of an Game, like Author, Description, ...
GameSessionStats _game_session_stats
Statistics about the current session.
FontSize
Available font sizes.
Information about languages and their files.
const LanguageMetadata * _current_language
The currently loaded language.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
Base for all music playback.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, { {NetworkSurveyHandler::Reason::PREVIEW, "preview"}, {NetworkSurveyHandler::Reason::LEAVE, "leave"}, {NetworkSurveyHandler::Reason::EXIT, "exit"}, {NetworkSurveyHandler::Reason::CRASH, "crash"}, }) std
Create the payload for the survey.
GRFConfigList _grfconfig
First item in list of current GRF set up.
@ GCS_INITIALISED
GRF file has been initialised.
@ GCS_DISABLED
GRF file is disabled.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
@ GCS_UNKNOWN
The status of this grf file is unknown.
@ GCS_ACTIVATED
GRF file has been activated.
@ Static
GRF file is used statically (can be used in any MP game)
@ GRFP_GRF_UNSET
The NewGRF provided no information.
@ GRFP_BLT_UNSET
The NewGRF provided no information or doesn't care about a 32 bpp blitter.
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
@ GRFP_GRF_ANY
The NewGRF says any palette can be used.
@ GRFP_BLT_MASK
Bitmask to only get the blitter information.
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
declaration of OTTD revision dependent variables
A number of safeguards to prevent using unsafe methods.
bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
Definition of the configuration tables of the settings.
Types related to global configuration settings.
static std::vector< std::unique_ptr< InternalSocialIntegrationPlugin > > _plugins
List of loaded plugins.
Interface definitions for game to report/respond to social integration.
Base for all sound drivers.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
CompanySettings company
default values for per-company settings
Settings for a single font.
std::string font
The name of the font, or path to the font.
uint size
The (requested) size of the font.
Information about GRF, used in the game and (part of it) in savegames.
std::vector< uint32_t > param
GRF parameters.
std::chrono::steady_clock::time_point start_time
Time when the current game was started.
std::string savegame_id
Unique ID of the savegame.
std::optional< size_t > savegame_size
Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
SaveLoadVersion version_to
Save/load the variable before this savegame version.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Properties of config file settings.
constexpr const std::string & GetName() const
Get the name of this setting.
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
virtual bool IsDefaultValue(void *object) const =0
Check whether the value is the same as the default value.
SaveLoad save
Internal structure (going to savegame, parts to config).
void SurveySettings(nlohmann::json &survey, bool skip_if_default)
Convert settings to JSON.
void SurveyPlugins(nlohmann::json &survey)
Convert plugin information to JSON.
void SurveyTimers(nlohmann::json &survey)
Convert timer information to JSON.
static void SurveySettingsTable(nlohmann::json &survey, const SettingTable &table, void *object, bool skip_if_default)
Convert a settings table to JSON.
void SurveyGameSession(nlohmann::json &survey)
Convert game session information to JSON.
std::string SurveyMemoryToText(uint64_t memory)
Change the bytes of memory into a textual version rounded up to the biggest unit.
void SurveyGameScript(nlohmann::json &survey)
Convert game-script information to JSON.
void SurveyConfiguration(nlohmann::json &survey)
Convert generic game information to JSON.
void SurveyOpenTTD(nlohmann::json &survey)
Convert generic OpenTTD information to JSON.
void SurveyFont(nlohmann::json &survey)
Convert font information to JSON.
void SurveyCompanies(nlohmann::json &survey)
Convert company information to JSON.
static auto & GenericSettingTables()
List of all the generic setting tables.
void SurveyCompiler(nlohmann::json &survey)
Convert compiler information to JSON.
void SurveyLibraries(nlohmann::json &survey)
Convert compiled libraries information to JSON.
static const std::string _vehicle_type_to_string[]
Lookup table to convert a VehicleType to a string.
void SurveyGrfs(nlohmann::json &survey)
Convert GRF information to JSON.
Functions to survey the current game / system, for crashlog and network-survey.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
VehicleType
Available vehicle types.
@ VEH_COMPANY_END
Last company-ownable type.
Base of all video drivers.
std::string FS2OTTD(std::wstring_view name)
Convert to OpenTTD's encoding from a wide string.