Update to 14.0-beta1
This commit is contained in:
70
src/misc.cpp
70
src/misc.cpp
@@ -11,11 +11,13 @@
|
||||
#include "landscape.h"
|
||||
#include "news_func.h"
|
||||
#include "ai/ai.hpp"
|
||||
#include "ai/ai_gui.hpp"
|
||||
#include "script/script_gui.h"
|
||||
#include "newgrf.h"
|
||||
#include "newgrf_house.h"
|
||||
#include "economy_func.h"
|
||||
#include "date_func.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#include "timer/timer_game_economy.h"
|
||||
#include "timer/timer_game_tick.h"
|
||||
#include "texteff.hpp"
|
||||
#include "gfx_func.h"
|
||||
#include "gamelog.h"
|
||||
@@ -30,9 +32,11 @@
|
||||
#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();
|
||||
@@ -55,17 +59,50 @@ 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();
|
||||
|
||||
AllocateMap(size_x, size_y);
|
||||
Map::Allocate(size_x, size_y);
|
||||
|
||||
_pause_mode = PM_UNPAUSED;
|
||||
_game_speed = 100;
|
||||
_tick_counter = 0;
|
||||
TimerGameTick::counter = 0;
|
||||
_cur_tileloop_tile = 1;
|
||||
_thd.redsq = INVALID_TILE;
|
||||
if (reset_settings) MakeNewgameSettingsLive();
|
||||
@@ -73,7 +110,16 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
||||
_newgrf_profilers.clear();
|
||||
|
||||
if (reset_date) {
|
||||
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
|
||||
TimerGameCalendar::Date new_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
|
||||
TimerGameCalendar::SetDate(new_date, 0);
|
||||
|
||||
if (TimerGameEconomy::UsingWallclockUnits()) {
|
||||
/* If using wallclock units, start at year 1. */
|
||||
TimerGameEconomy::SetDate(TimerGameEconomy::ConvertYMDToDate(1, 0, 1), 0);
|
||||
} else {
|
||||
/* Otherwise, we always keep the economy date synced with the calendar date. */
|
||||
TimerGameEconomy::SetDate(new_date.base(), 0);
|
||||
}
|
||||
InitializeOldNames();
|
||||
}
|
||||
|
||||
@@ -100,7 +146,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
||||
InitializeGraphGui();
|
||||
InitializeObjectGui();
|
||||
InitializeTownGui();
|
||||
InitializeAIGui();
|
||||
InitializeScriptGui();
|
||||
InitializeTrees();
|
||||
InitializeIndustries();
|
||||
InitializeObjects();
|
||||
@@ -121,10 +167,10 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
GamelogReset();
|
||||
GamelogStartAction(GLAT_START);
|
||||
GamelogRevision();
|
||||
GamelogMode();
|
||||
GamelogGRFAddList(_grfconfig);
|
||||
GamelogStopAction();
|
||||
_gamelog.Reset();
|
||||
_gamelog.StartAction(GLAT_START);
|
||||
_gamelog.Revision();
|
||||
_gamelog.Mode();
|
||||
_gamelog.GRFAddList(_grfconfig);
|
||||
_gamelog.StopAction();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user