Update to OpenTTD 1.9.0-beta2

--HG--
branch : openttd
This commit is contained in:
Pavel Stupnikov
2019-02-13 15:17:23 +03:00
parent 42ec3bd611
commit 2bda8d4f34
1362 changed files with 22145 additions and 10644 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: openttd.cpp 27732 2017-01-14 18:30:26Z frosch $ */
/* $Id$ */
/*
* This file is part of OpenTTD.
@@ -63,6 +63,7 @@
#include "subsidy_func.h"
#include "gfx_layout.h"
#include "viewport_sprite_sorter.h"
#include "framerate_type.h"
#include "linkgraph/linkgraphschedule.h"
@@ -75,7 +76,7 @@ void IncreaseDate();
void DoPaletteAnimations();
void MusicLoop();
void ResetMusic();
void CallWindowTickEvent();
void CallWindowGameTickEvent();
bool HandleBootstrap();
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
@@ -116,7 +117,9 @@ void CDECL error(const char *s, ...)
vseprintf(buf, lastof(buf), s, va);
va_end(va);
ShowOSErrorBox(buf, true);
if (VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) {
ShowOSErrorBox(buf, true);
}
/* Set the error message for the crash log and then invoke it. */
CrashLog::SetErrorMessage(buf);
@@ -167,7 +170,7 @@ static void ShowHelp()
" -P password = Password to join company\n"
" -D [ip][:port] = Start dedicated server\n"
" -l ip[:port] = Redirect DEBUG()\n"
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(_WIN32)
" -f = Fork into the background (dedicated only)\n"
#endif
#endif /* ENABLE_NETWORK */
@@ -211,7 +214,7 @@ static void ShowHelp()
/* ShowInfo put output to stderr, but version information should go
* to stdout; this is the only exception */
#if !defined(WIN32) && !defined(WIN64)
#if !defined(_WIN32)
printf("%s\n", buf);
#else
ShowInfo(buf);
@@ -220,7 +223,7 @@ static void ShowHelp()
static void WriteSavegameInfo(const char *name)
{
extern uint16 _sl_version;
extern SaveLoadVersion _sl_version;
uint32 last_ottd_rev = 0;
byte ever_modified = 0;
bool removed_newgrfs = false;
@@ -249,7 +252,7 @@ static void WriteSavegameInfo(const char *name)
/* ShowInfo put output to stderr, but version information should go
* to stdout; this is the only exception */
#if !defined(WIN32) && !defined(WIN64)
#if !defined(_WIN32)
printf("%s\n", buf);
#else
ShowInfo(buf);
@@ -277,7 +280,7 @@ static void ParseResolution(Dimension *res, const char *s)
/**
* Unitializes drivers, frees allocated memory, cleans pools, ...
* Uninitializes drivers, frees allocated memory, cleans pools, ...
* Generally, prepares the game for shutting down
*/
static void ShutdownGame()
@@ -341,8 +344,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
CheckForMissingGlyphs();
/* Play main theme */
if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
MusicLoop(); // ensure music is correct
}
void MakeNewgameSettingsLive()
@@ -365,6 +367,9 @@ void MakeNewgameSettingsLive()
_settings_game.ai_config[c] = NULL;
if (_settings_newgame.ai_config[c] != NULL) {
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
if (!AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->HasScript()) {
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(NULL);
}
}
}
_settings_game.game_config = NULL;
@@ -385,7 +390,7 @@ void OpenBrowser(const char *url)
/** Callback structure of statements to be executed after the NewGRF scan. */
struct AfterNewGRFScan : NewGRFScanCallback {
Year startyear; ///< The start year.
uint generation_seed; ///< Seed for the new game.
uint32 generation_seed; ///< Seed for the new game.
char *dedicated_host; ///< Hostname for the dedicated server.
uint16 dedicated_port; ///< Port for the dedicated server.
char *network_conn; ///< Information about the server to connect to, or NULL.
@@ -405,6 +410,9 @@ struct AfterNewGRFScan : NewGRFScanCallback {
join_server_password(NULL), join_company_password(NULL),
save_config_ptr(save_config_ptr), save_config(true)
{
/* Visual C++ 2015 fails compiling this line (AfterNewGRFScan::generation_seed undefined symbol)
* if it's placed outside a member function, directly in the struct body. */
assert_compile(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
}
virtual void OnNewGRFsScanned()
@@ -508,7 +516,7 @@ static const OptionData _options[] = {
GETOPT_SHORT_VALUE('l'),
GETOPT_SHORT_VALUE('p'),
GETOPT_SHORT_VALUE('P'),
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(_WIN32)
GETOPT_SHORT_NOVAL('f'),
#endif
#endif /* ENABLE_NETWORK */
@@ -608,7 +616,7 @@ int openttd_main(int argc, char *argv[])
case 'r': ParseResolution(&resolution, mgo.opt); break;
case 't': scanner->startyear = atoi(mgo.opt); break;
case 'd': {
#if defined(WIN32)
#if defined(_WIN32)
CreateConsole();
#endif
if (mgo.opt != NULL) SetDebugString(mgo.opt);
@@ -666,7 +674,7 @@ int openttd_main(int argc, char *argv[])
goto exit_noshutdown;
}
case 'G': scanner->generation_seed = atoi(mgo.opt); break;
case 'G': scanner->generation_seed = strtoul(mgo.opt, NULL, 10); break;
case 'c': free(_config_file); _config_file = stredup(mgo.opt); break;
case 'x': scanner->save_config = false; break;
case 'h':
@@ -692,11 +700,6 @@ int openttd_main(int argc, char *argv[])
goto exit_noshutdown;
}
#if defined(WINCE) && defined(_DEBUG)
/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
SetDebugString("4");
#endif
DeterminePaths(argv[0]);
TarScanner::DoScan(TarScanner::BASESET);
@@ -815,7 +818,7 @@ int openttd_main(int argc, char *argv[])
if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = stredup(BaseSounds::ini_set);
if (!BaseSounds::SetSet(sounds_set)) {
if (StrEmpty(sounds_set) || !BaseSounds::SetSet(NULL)) {
usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of README.md.");
} else {
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
msg.SetDParamStr(0, sounds_set);
@@ -828,7 +831,7 @@ int openttd_main(int argc, char *argv[])
if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = stredup(BaseMusic::ini_set);
if (!BaseMusic::SetSet(music_set)) {
if (StrEmpty(music_set) || !BaseMusic::SetSet(NULL)) {
usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of README.md.");
} else {
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
msg.SetDParamStr(0, music_set);
@@ -941,6 +944,14 @@ static void MakeNewGameDone()
Company *c = Company::Get(COMPANY_FIRST);
c->settings = _settings_client.company;
/* Overwrite color from settings if needed
* COLOUR_END corresponds to Random colour */
if (_settings_client.gui.starting_colour != COLOUR_END) {
c->colour = _settings_client.gui.starting_colour;
ResetCompanyLivery(c);
_company_colours[c->index] = (Colours)c->colour;
}
IConsoleCmdExec("exec scripts/game_start.scr 0");
SetLocalCompany(COMPANY_FIRST);
@@ -991,9 +1002,9 @@ static void MakeNewEditorWorld()
* Load the specified savegame but on error do different things.
* If loading fails due to corrupt savegame, bad version, etc. go back to
* a previous correct state. In the menu for example load the intro game again.
* @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
* @param newgm switch to this mode of loading fails due to some unknown error
* @param filename file to be loaded
* @param fop mode of loading, always SLO_LOAD
* @param newgm switch to this mode of loading fails due to some unknown error
* @param subdir default directory to look for filename, set to 0 if not needed
* @param lf Load filter to use, if NULL: use filename + subdir.
*/
@@ -1342,13 +1353,23 @@ void StateGameLoop()
{
/* don't execute the state loop during pause */
if (_pause_mode != PM_UNPAUSED) {
PerformanceMeasurer::Paused(PFE_GAMELOOP);
PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
PerformanceMeasurer::Paused(PFE_GL_TRAINS);
PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
PerformanceMeasurer::Paused(PFE_GL_SHIPS);
PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
UpdateLandscapingLimits();
#ifndef DEBUG_DUMP_COMMANDS
Game::GameLoop();
#endif
CallWindowTickEvent();
return;
}
PerformanceMeasurer framerate(PFE_GAMELOOP);
PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
if (HasModalProgress()) return;
Layouter::ReduceLineCache();
@@ -1361,7 +1382,7 @@ void StateGameLoop()
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
UpdateLandscapingLimits();
CallWindowTickEvent();
CallWindowGameTickEvent();
NewsLoop();
} else {
if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
@@ -1391,7 +1412,7 @@ void StateGameLoop()
#endif
UpdateLandscapingLimits();
CallWindowTickEvent();
CallWindowGameTickEvent();
NewsLoop();
cur_company.Restore();
}
@@ -1407,11 +1428,6 @@ static void DoAutosave()
{
char buf[MAX_PATH];
#if defined(PSP)
/* Autosaving in networking is too time expensive for the PSP */
if (_networking) return;
#endif /* PSP */
if (_settings_client.gui.keep_all_autosave) {
GenerateDefaultSaveName(buf, lastof(buf));
strecat(buf, ".sav", lastof(buf));
@@ -1459,10 +1475,6 @@ void GameLoop()
IncreaseSpriteLRU();
InteractiveRandom();
extern int _caret_timer;
_caret_timer += 3;
CursorTick();
#ifdef ENABLE_NETWORK
/* Check for UDP stuff */
if (_network_available) NetworkBackgroundLoop();
@@ -1479,21 +1491,12 @@ void GameLoop()
/* Singleplayer */
StateGameLoop();
}
/* Check chat messages roughly once a second. */
static uint check_message = 0;
if (++check_message > 1000 / MILLISECONDS_PER_TICK) {
check_message = 0;
NetworkChatMessageLoop();
}
#else
StateGameLoop();
#endif /* ENABLE_NETWORK */
if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects();
InputLoop();
SoundDriver::GetInstance()->MainLoop();