Files @ r28548:1c4b0e7a2a67
Branch filter:

Location: cpp/openttd-patchpack/source/src/misc.cpp - annotation

EmperorJake
Change: set amount of smoke/sparks to "realistic" by default (#11624)
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r9111:983de9c5a848
r6201:2e76eb9a1d7a
r5584:545d748cc681
r6453:b0b56773284a
r8763:c2c776621d56
r10696:8dfe83e30d01
r26856:c988753485d9
r17884:c09c40617963
r6332:7393965b5322
r8119:8fdb3a371896
r27229:662da0bb155f
r27149:50ec6b0c653e
r8144:1432edd15267
r8224:194097dc7288
r9457:ecfeb802c57a
r9005:e59c0b10c56a
r9127:933c13888121
r9898:bbef3303e005
r10911:571c959dc9ed
r17360:71e102cec3ce
r18746:ffe36c655ceb
r20341:d334ae194449
r23436:cfad304b5b27
r23435:0f8f3f8f40ec
r23437:6ce81d75a8ed
r24069:49625df81342
r28521:35e6c20016f8
r8224:194097dc7288
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r27371:b9ad4c1bff08
r5584:545d748cc681
r8973:bd926d7578a7
r10696:8dfe83e30d01
r5584:545d748cc681
r12674:8254ab83ecad
r14055:e4168a875df8
r6247:96e840dbefcc
r6247:96e840dbefcc
r6247:96e840dbefcc
r6247:96e840dbefcc
r6247:96e840dbefcc
r23287:0e81c2168d96
r15972:6463015373ad
r23800:f8cc74842443
r6247:96e840dbefcc
r15797:444e01a3fa29
r6247:96e840dbefcc
r10207:a1fc2f2a33db
r8965:16f6e5e9ed36
r6247:96e840dbefcc
r8987:5af9a103757a
r5584:545d748cc681
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r27371:b9ad4c1bff08
r28521:35e6c20016f8
r27371:b9ad4c1bff08
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r28521:35e6c20016f8
r27371:b9ad4c1bff08
r27392:b8be4cd54ca6
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r27371:b9ad4c1bff08
r12635:3d67c34135d4
r5584:545d748cc681
r10911:571c959dc9ed
r10911:571c959dc9ed
r10911:571c959dc9ed
r10911:571c959dc9ed
r26789:79b05bbf3bd2
r5584:545d748cc681
r11847:235c011992a8
r24970:1ff44d19fa4a
r27149:50ec6b0c653e
r19229:5550f5cdc59d
r10816:2ed0dff886de
r12635:3d67c34135d4
r5584:545d748cc681
r24069:49625df81342
r24069:49625df81342
r15897:d700bcc8403e
r27229:662da0bb155f
r15897:d700bcc8403e
r15897:d700bcc8403e
r15897:d700bcc8403e
r20341:d334ae194449
r17360:71e102cec3ce
r17360:71e102cec3ce
r23436:cfad304b5b27
r23435:0f8f3f8f40ec
r23437:6ce81d75a8ed
r23435:0f8f3f8f40ec
r17884:c09c40617963
r17884:c09c40617963
r12674:8254ab83ecad
r14055:e4168a875df8
r12674:8254ab83ecad
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r23287:0e81c2168d96
r15972:6463015373ad
r23800:f8cc74842443
r26856:c988753485d9
r5584:545d748cc681
r5584:545d748cc681
r15797:444e01a3fa29
r6332:7393965b5322
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r10207:a1fc2f2a33db
r10696:8dfe83e30d01
r18746:ffe36c655ceb
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9898:bbef3303e005
r5584:545d748cc681
r5584:545d748cc681
r12930:ae0ddab1903d
r5584:545d748cc681
r5584:545d748cc681
r9457:ecfeb802c57a
r27223:23146c90355d
r27223:23146c90355d
r27223:23146c90355d
r27223:23146c90355d
r27223:23146c90355d
r27223:23146c90355d
r5584:545d748cc681
/*
 * 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/monocypher/monocypher.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 but more a hashed digest of a random
 * string and a time. It is very likely to be unique, but it does not follow
 * any UUID standard.
 */
std::string GenerateUid(std::string_view subject)
{
	std::array<uint8_t, 32> random_bytes;
	RandomBytesWithFallback(random_bytes);

	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("{}{}", current_time, subject);

	std::array<uint8_t, 16> digest;
	crypto_blake2b_ctx ctx;
	crypto_blake2b_init(&ctx, digest.size());
	crypto_blake2b_update(&ctx, random_bytes.data(), random_bytes.size());
	crypto_blake2b_update(&ctx, reinterpret_cast<const uint8_t *>(coding_string.data()), coding_string.size());
	crypto_blake2b_final(&ctx, digest.data());

	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();
}