Files
@ r28060:53690f1ef210
Branch filter:
Location: cpp/openttd-patchpack/source/src/misc.cpp
r28060:53690f1ef210
4.5 KiB
text/x-c
Feature: Base graphics can offer parameters for additional settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file misc.cpp Misc functions that shouldn't be here. */
#include "stdafx.h"
#include "landscape.h"
#include "news_func.h"
#include "ai/ai.hpp"
#include "script/script_gui.h"
#include "newgrf.h"
#include "newgrf_house.h"
#include "economy_func.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_tick.h"
#include "texteff.hpp"
#include "gfx_func.h"
#include "gamelog.h"
#include "animated_tile_func.h"
#include "tilehighlight_func.h"
#include "network/network_func.h"
#include "window_func.h"
#include "core/pool_type.hpp"
#include "game/game.hpp"
#include "linkgraph/linkgraphschedule.h"
#include "station_kdtree.h"
#include "town_kdtree.h"
#include "viewport_kdtree.h"
#include "newgrf_profiling.h"
#include "3rdparty/md5/md5.h"
#include "safeguards.h"
std::string _savegame_id; ///< Unique ID of the current savegame.
extern TileIndex _cur_tileloop_tile;
extern void MakeNewgameSettingsLive();
void InitializeSound();
void InitializeMusic();
void InitializeVehicles();
void InitializeRailGui();
void InitializeRoadGui();
void InitializeAirportGui();
void InitializeDockGui();
void InitializeGraphGui();
void InitializeObjectGui();
void InitializeTownGui();
void InitializeIndustries();
void InitializeObjects();
void InitializeTrees();
void InitializeCompanies();
void InitializeCheats();
void InitializeNPF();
void InitializeOldNames();
/**
* Generate an unique ID.
*
* It isn't as much of an unique ID as we would like, but our random generator
* can only produce 32bit random numbers.
* That is why we combine InteractiveRandom with the current (steady) clock.
* The first to add a bit of randomness, the second to ensure you can't get
* the same unique ID when you run it twice from the same state at different
* times.
*
* This makes it unlikely that two users generate the same ID for different
* subjects. But as this is not an UUID, so it can't be ruled out either.
*/
std::string GenerateUid(std::string_view subject)
{
auto current_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
std::string coding_string = fmt::format("{}{}{}", InteractiveRandom(), current_time, subject);
Md5 checksum;
MD5Hash digest;
checksum.Append(coding_string.c_str(), coding_string.length());
checksum.Finish(digest);
return FormatArrayAsHex(digest);
}
/**
* Generate an unique savegame ID.
*/
void GenerateSavegameId()
{
_savegame_id = GenerateUid("OpenTTD Savegame ID");
}
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings)
{
/* Make sure there isn't any window that can influence anything
* related to the new game we're about to start/load. */
UnInitWindowSystem();
Map::Allocate(size_x, size_y);
_pause_mode = PM_UNPAUSED;
_game_speed = 100;
TimerGameTick::counter = 0;
_cur_tileloop_tile = 1;
_thd.redsq = INVALID_TILE;
if (reset_settings) MakeNewgameSettingsLive();
_newgrf_profilers.clear();
if (reset_date) {
TimerGameCalendar::SetDate(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
InitializeOldNames();
}
LinkGraphSchedule::Clear();
PoolBase::Clean(PT_NORMAL);
RebuildStationKdtree();
RebuildTownKdtree();
RebuildViewportKdtree();
ResetPersistentNewGRFData();
InitializeSound();
InitializeMusic();
InitializeVehicles();
InitNewsItemStructs();
InitializeLandscape();
InitializeRailGui();
InitializeRoadGui();
InitializeAirportGui();
InitializeDockGui();
InitializeGraphGui();
InitializeObjectGui();
InitializeTownGui();
InitializeScriptGui();
InitializeTrees();
InitializeIndustries();
InitializeObjects();
InitializeBuildingCounts();
InitializeNPF();
InitializeCompanies();
AI::Initialize();
Game::Initialize();
InitializeCheats();
InitTextEffects();
NetworkInitChatMessage();
InitializeAnimatedTiles();
InitializeEconomy();
ResetObjectToPlace();
_gamelog.Reset();
_gamelog.StartAction(GLAT_START);
_gamelog.Revision();
_gamelog.Mode();
_gamelog.GRFAddList(_grfconfig);
_gamelog.StopAction();
}
|