diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -67,6 +67,7 @@ #include "framerate_type.h" #include "industry.h" #include "network/network_gui.h" +#include "network/network_survey.h" #include "misc_cmd.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" @@ -822,6 +823,7 @@ void HandleExitGameRequest() _exit_game = true; } else if (_settings_client.gui.autosave_on_exit) { DoExitSave(); + _survey.Transmit(NetworkSurveyHandler::Reason::EXIT, true); _exit_game = true; } else { AskExitGame(); @@ -1036,9 +1038,16 @@ void SwitchToMode(SwitchMode new_mode) /* When we change mode, reset the autosave. */ if (new_mode != SM_SAVE_GAME) ChangeAutosaveFrequency(true); + /* Transmit the survey if we were in normal-mode and not saving. It always means we leaving the current game. */ + if (_game_mode == GM_NORMAL && new_mode != SM_SAVE_GAME) _survey.Transmit(NetworkSurveyHandler::Reason::LEAVE); + + /* Keep track when we last switch mode. Used for survey, to know how long someone was in a game. */ + if (new_mode != SM_SAVE_GAME) _switch_mode_time = std::chrono::steady_clock::now(); + switch (new_mode) { case SM_EDITOR: // Switch to scenario editor MakeNewEditorWorld(); + GenerateSavegameId(); break; case SM_RELOADGAME: // Reload with what-ever started the game @@ -1055,11 +1064,13 @@ void SwitchToMode(SwitchMode new_mode) } MakeNewGame(false, new_mode == SM_NEWGAME); + GenerateSavegameId(); break; case SM_RESTARTGAME: // Restart --> 'Random game' with current settings case SM_NEWGAME: // New Game --> 'Random game' MakeNewGame(false, new_mode == SM_NEWGAME); + GenerateSavegameId(); break; case SM_LOAD_GAME: { // Load game, Play Scenario @@ -1083,18 +1094,21 @@ void SwitchToMode(SwitchMode new_mode) case SM_RESTART_HEIGHTMAP: // Load a heightmap and start a new game from it with current settings case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it MakeNewGame(true, new_mode == SM_START_HEIGHTMAP); + GenerateSavegameId(); break; case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor SetLocalCompany(OWNER_NONE); GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); + GenerateSavegameId(); MarkWholeScreenDirty(); break; case SM_LOAD_SCENARIO: { // Load scenario from scenario editor if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) { SetLocalCompany(OWNER_NONE); + GenerateSavegameId(); _settings_newgame.game_creation.starting_year = TimerGameCalendar::year; /* Cancel the saveload pausing */ Command::Post(PM_PAUSED_SAVELOAD, false); @@ -1116,6 +1130,14 @@ void SwitchToMode(SwitchMode new_mode) ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL); BaseSounds::ini_set = BaseSounds::GetUsedSet()->name; } + if (_settings_client.network.participate_survey == PS_ASK) { + /* No matter how often you go back to the main menu, only ask the first time. */ + static bool asked_once = false; + if (!asked_once) { + asked_once = true; + ShowNetworkAskSurvey(); + } + } break; case SM_SAVE_GAME: // Save game.