mirror of https://github.com/OpenTTD/OpenTTD
Fix: "restart current" reproduces how the script config of the current game was when it started
Restore Random AI slot upon stopping a randomly started AI. On "restart current" console command, use the seed of the current game to set the seed of scripts. Apply random deviation to non-random script settings upon starting a new game, except when using "restart current" via console, where the randomization counter is simulated but the values remain not deviated. Show random deviation range for scripts only outside normal game mode.pull/12011/head
parent
3534214dfc
commit
67b0fec6ed
|
@ -48,7 +48,6 @@
|
|||
/* Load default data and store the name in the settings */
|
||||
config->Change(info->GetName(), -1, false, true);
|
||||
}
|
||||
if (rerandomise_ai) config->AddRandomDeviation();
|
||||
config->AnchorUnchangeableSettings();
|
||||
|
||||
Backup<CompanyID> cur_company(_current_company, company, FILE_LINE);
|
||||
|
@ -115,6 +114,10 @@
|
|||
cur_company.Restore();
|
||||
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
|
||||
|
||||
if (AIConfig::GetConfig(company)->IsRandom()) {
|
||||
AIConfig::GetConfig(company)->Change(std::nullopt);
|
||||
}
|
||||
CloseWindowById(WC_SCRIPT_SETTINGS, company);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,8 @@ public:
|
|||
|
||||
/**
|
||||
* Start up a new GameScript.
|
||||
* @param randomise Whether to randomise the configured GameScript.
|
||||
*/
|
||||
static void StartNew(bool randomise = true);
|
||||
static void StartNew();
|
||||
|
||||
/**
|
||||
* Uninitialize the Game system.
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* static */ void Game::StartNew(bool randomise)
|
||||
/* static */ void Game::StartNew()
|
||||
{
|
||||
if (Game::instance != nullptr) return;
|
||||
|
||||
|
@ -83,7 +83,6 @@
|
|||
GameInfo *info = config->GetInfo();
|
||||
if (info == nullptr) return;
|
||||
|
||||
if (randomise) config->AddRandomDeviation();
|
||||
config->AnchorUnchangeableSettings();
|
||||
|
||||
Backup<CompanyID> cur_company(_current_company, FILE_LINE);
|
||||
|
|
|
@ -91,11 +91,8 @@ static void _GenerateWorld()
|
|||
try {
|
||||
_generating_world = true;
|
||||
if (_network_dedicated) Debug(net, 3, "Generating map, please wait...");
|
||||
/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
|
||||
_random.SetSeed(_settings_game.game_creation.generation_seed);
|
||||
SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
|
||||
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
|
||||
ScriptObject::InitializeRandomizers();
|
||||
|
||||
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
|
||||
|
||||
|
@ -307,8 +304,6 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
|
|||
_settings_game.construction.map_height_limit = std::max(MAP_HEIGHT_LIMIT_AUTO_MINIMUM, std::min(MAX_MAP_HEIGHT_LIMIT, estimated_height + MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM));
|
||||
}
|
||||
|
||||
if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = InteractiveRandom();
|
||||
|
||||
/* Load the right landscape stuff, and the NewGRFs! */
|
||||
GfxLoadSprites();
|
||||
LoadStringWidthTable();
|
||||
|
|
28
src/misc.cpp
28
src/misc.cpp
|
@ -8,6 +8,9 @@
|
|||
/** @file misc.cpp Misc functions that shouldn't be here. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ai/ai_config.hpp"
|
||||
#include "game/game_config.hpp"
|
||||
#include "genworld.h"
|
||||
#include "landscape.h"
|
||||
#include "news_func.h"
|
||||
#include "ai/ai.hpp"
|
||||
|
@ -173,4 +176,29 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
|||
_gamelog.Mode();
|
||||
_gamelog.GRFAddList(_grfconfig);
|
||||
_gamelog.StopAction();
|
||||
|
||||
/* Set the Random() seed to generation_seed so we produce the same map with the same seed. */
|
||||
if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = InteractiveRandom();
|
||||
|
||||
_random.SetSeed(_settings_game.game_creation.generation_seed);
|
||||
ScriptObject::InitializeRandomizers();
|
||||
|
||||
if (reset_settings) {
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
_settings_game.ai_config[c] = nullptr;
|
||||
if (_settings_newgame.ai_config[c] != nullptr) {
|
||||
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
|
||||
}
|
||||
}
|
||||
_settings_game.game_config = nullptr;
|
||||
if (_settings_newgame.game_config != nullptr) {
|
||||
_settings_game.game_config = new GameConfig(_settings_newgame.game_config);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set random deviation for scripts. */
|
||||
for (auto &ai_config : _settings_game.ai_config) {
|
||||
if (ai_config != nullptr) ai_config->AddRandomDeviation();
|
||||
}
|
||||
if (_settings_game.game_config != nullptr) _settings_game.game_config->AddRandomDeviation();
|
||||
}
|
||||
|
|
|
@ -553,7 +553,7 @@ static void StartScripts()
|
|||
}
|
||||
|
||||
/* Start the GameScript. */
|
||||
Game::StartNew(false);
|
||||
Game::StartNew();
|
||||
|
||||
ShowScriptDebugWindowIfScriptError();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@ void ScriptConfig::Change(std::optional<const std::string> name, int version, bo
|
|||
this->to_load_data.reset();
|
||||
|
||||
this->ClearConfigList();
|
||||
|
||||
if (_game_mode == GM_NORMAL && _switch_mode != SM_LOAD_GAME && this->info != nullptr) {
|
||||
this->AddRandomDeviation();
|
||||
}
|
||||
}
|
||||
|
||||
ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
||||
|
@ -129,7 +133,8 @@ void ScriptConfig::AddRandomDeviation()
|
|||
{
|
||||
for (const auto &item : *this->GetConfigList()) {
|
||||
if (item.random_deviation != 0) {
|
||||
this->SetSetting(item.name, ScriptObject::GetRandomizer(OWNER_NONE).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
|
||||
uint32_t randomize = ScriptObject::GetRandomizer(OWNER_NONE).Next(item.random_deviation * 2 + 1);
|
||||
if (_switch_mode != SM_RESTARTGAME) this->SetSetting(item.name, randomize - item.random_deviation + this->GetSetting(item.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -379,14 +379,14 @@ struct ScriptSettingsWindow : public Window {
|
|||
TextColour colour;
|
||||
uint idx = 0;
|
||||
if (config_item.description.empty()) {
|
||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
||||
if (this->slot != OWNER_DEITY && _game_mode != GM_NORMAL && config_item.random_deviation != 0) {
|
||||
str = STR_AI_SETTINGS_JUST_DEVIATION;
|
||||
} else {
|
||||
str = STR_JUST_STRING1;
|
||||
}
|
||||
colour = TC_ORANGE;
|
||||
} else {
|
||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
||||
if (this->slot != OWNER_DEITY && _game_mode != GM_NORMAL && config_item.random_deviation != 0) {
|
||||
str = STR_AI_SETTINGS_SETTING_DEVIATION;
|
||||
} else {
|
||||
str = STR_AI_SETTINGS_SETTING;
|
||||
|
@ -405,7 +405,7 @@ struct ScriptSettingsWindow : public Window {
|
|||
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||
}
|
||||
|
||||
if (this->slot == OWNER_DEITY || Company::IsValidID(this->slot) || config_item.random_deviation == 0) {
|
||||
if (this->slot == OWNER_DEITY || _game_mode == GM_NORMAL || config_item.random_deviation == 0) {
|
||||
auto config_iterator = config_item.labels.find(current_value);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
|
|
Loading…
Reference in New Issue