Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/ci-build.yml
#	.github/workflows/release-linux.yml
#	.github/workflows/release-macos.yml
#	.github/workflows/release-source.yml
#	.github/workflows/release.yml
#	CMakeLists.txt
#	COMPILING.md
#	src/ai/ai_core.cpp
#	src/ai/ai_gui.cpp
#	src/bridge_gui.cpp
#	src/company_gui.cpp
#	src/console_cmds.cpp
#	src/core/CMakeLists.txt
#	src/core/smallmap_type.hpp
#	src/disaster_vehicle.h
#	src/effectvehicle_base.h
#	src/fontcache.cpp
#	src/game/game_core.cpp
#	src/game/game_gui.cpp
#	src/gamelog.cpp
#	src/gamelog_internal.h
#	src/group_gui.cpp
#	src/linkgraph/linkgraph.h
#	src/misc.cpp
#	src/network/core/config.h
#	src/network/core/udp.cpp
#	src/network/network_chat_gui.cpp
#	src/network/network_content_gui.cpp
#	src/network/network_gui.cpp
#	src/newgrf.cpp
#	src/newgrf_gui.cpp
#	src/newgrf_profiling.cpp
#	src/newgrf_profiling.h
#	src/object_gui.cpp
#	src/openttd.cpp
#	src/openttd.h
#	src/order_gui.cpp
#	src/os/windows/font_win32.cpp
#	src/rail_gui.cpp
#	src/road.cpp
#	src/road_gui.cpp
#	src/saveload/afterload.cpp
#	src/saveload/saveload.h
#	src/script/api/script_controller.cpp
#	src/script/api/script_roadtypelist.cpp
#	src/script/script_config.cpp
#	src/script/script_config.hpp
#	src/script/script_instance.cpp
#	src/script/script_scanner.cpp
#	src/script/squirrel.cpp
#	src/script/squirrel_helper.hpp
#	src/settings_gui.cpp
#	src/settings_internal.h
#	src/settings_type.h
#	src/table/settings/network_private_settings.ini
#	src/timetable_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-07-01 01:08:35 +01:00
246 changed files with 2023 additions and 1211 deletions

View File

@@ -15,14 +15,18 @@
#include "../textfile_gui.h"
#include "../string_func.h"
#include "../3rdparty/fmt/format.h"
#include <charconv>
#include "../safeguards.h"
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
void ScriptConfig::Change(std::optional<const std::string> name, int version, bool force_exact_match, bool is_random)
{
free(this->name);
this->name = (name == nullptr) ? nullptr : stredup(name);
this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match);
if (name.has_value()) {
this->name = std::move(name.value());
this->info = this->FindInfo(this->name, version, force_exact_match);
} else {
this->info = nullptr;
}
this->version = (info == nullptr) ? -1 : info->GetVersion();
this->is_random = is_random;
this->config_list.reset();
@@ -45,7 +49,7 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
ScriptConfig::ScriptConfig(const ScriptConfig *config)
{
this->name = (config->name == nullptr) ? nullptr : stredup(config->name);
this->name = config->name;
this->info = config->info;
this->version = config->version;
this->is_random = config->is_random;
@@ -61,7 +65,6 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config)
ScriptConfig::~ScriptConfig()
{
free(this->name);
this->ResetSettings();
this->to_load_data.reset();
}
@@ -101,7 +104,7 @@ int ScriptConfig::GetSetting(const std::string &name) const
return (*it).second;
}
void ScriptConfig::SetSetting(const std::string &name, int value)
void ScriptConfig::SetSetting(const std::string_view name, int value)
{
/* You can only set Script specific settings if an Script is selected. */
if (this->info == nullptr) return;
@@ -111,7 +114,7 @@ void ScriptConfig::SetSetting(const std::string &name, int value)
value = Clamp(value, config_item->min_value, config_item->max_value);
this->settings[name] = value;
this->settings[std::string{name}] = value;
}
void ScriptConfig::ResetSettings()
@@ -157,7 +160,7 @@ bool ScriptConfig::IsRandom() const
return this->is_random;
}
const char *ScriptConfig::GetName() const
const std::string &ScriptConfig::GetName() const
{
return this->name;
}
@@ -169,28 +172,24 @@ int ScriptConfig::GetVersion() const
void ScriptConfig::StringToSettings(const std::string &value)
{
char *value_copy = stredup(value.c_str());
char *s = value_copy;
while (s != nullptr) {
std::string_view to_process = value;
for (;;) {
/* Analyze the string ('name=value,name=value\0') */
char *item_name = s;
s = strchr(s, '=');
if (s == nullptr) break;
if (*s == '\0') break;
*s = '\0';
s++;
size_t pos = to_process.find_first_of('=');
if (pos == std::string_view::npos) return;
char *item_value = s;
s = strchr(s, ',');
if (s != nullptr) {
*s = '\0';
s++;
}
std::string_view item_name = to_process.substr(0, pos);
this->SetSetting(item_name, atoi(item_value));
to_process.remove_prefix(pos + 1);
pos = to_process.find_first_of(',');
int item_value = 0;
std::from_chars(to_process.data(), to_process.data() + std::min(pos, to_process.size()), item_value);
this->SetSetting(item_name, item_value);
if (pos == std::string_view::npos) return;
to_process.remove_prefix(pos + 1);
}
free(value_copy);
}
std::string ScriptConfig::SettingsToString() const