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:
@@ -91,9 +91,9 @@ public:
|
||||
/** Wrapper function for GameScanner::GetUniqueInfoList */
|
||||
static const ScriptInfoList *GetUniqueInfoList();
|
||||
/** Wrapper function for GameScannerInfo::FindInfo */
|
||||
static class GameInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
static class GameInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
/** Wrapper function for GameScanner::FindLibrary */
|
||||
static class GameLibrary *FindLibrary(const char *library, int version);
|
||||
static class GameLibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
/**
|
||||
* Get the current active instance.
|
||||
|
||||
@@ -32,7 +32,7 @@ class GameInfo *GameConfig::GetInfo() const
|
||||
return static_cast<class GameInfo *>(ScriptConfig::GetInfo());
|
||||
}
|
||||
|
||||
ScriptInfo *GameConfig::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
ScriptInfo *GameConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return static_cast<ScriptInfo *>(Game::FindInfo(name, version, force_exact_match));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
bool ResetInfo(bool force_exact_match);
|
||||
|
||||
protected:
|
||||
ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) override;
|
||||
ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) override;
|
||||
};
|
||||
|
||||
#endif /* GAME_CONFIG_HPP */
|
||||
|
||||
@@ -171,8 +171,8 @@
|
||||
* the GameConfig. If not, remove the Game from the list. */
|
||||
if (_settings_game.game_config != nullptr && _settings_game.game_config->HasScript()) {
|
||||
if (!_settings_game.game_config->ResetInfo(true)) {
|
||||
DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_game.game_config->GetName());
|
||||
_settings_game.game_config->Change(nullptr);
|
||||
DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_game.game_config->GetName().c_str());
|
||||
_settings_game.game_config->Change(std::nullopt);
|
||||
if (Game::instance != nullptr) {
|
||||
delete Game::instance;
|
||||
Game::instance = nullptr;
|
||||
@@ -184,8 +184,8 @@
|
||||
}
|
||||
if (_settings_newgame.game_config != nullptr && _settings_newgame.game_config->HasScript()) {
|
||||
if (!_settings_newgame.game_config->ResetInfo(false)) {
|
||||
DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_newgame.game_config->GetName());
|
||||
_settings_newgame.game_config->Change(nullptr);
|
||||
DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_newgame.game_config->GetName().c_str());
|
||||
_settings_newgame.game_config->Change(std::nullopt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,12 +236,12 @@
|
||||
return Game::scanner_info->GetUniqueInfoList();
|
||||
}
|
||||
|
||||
/* static */ GameInfo *Game::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
/* static */ GameInfo *Game::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return Game::scanner_info->FindInfo(name, version, force_exact_match);
|
||||
}
|
||||
|
||||
/* static */ GameLibrary *Game::FindLibrary(const char *library, int version)
|
||||
/* static */ GameLibrary *Game::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return Game::scanner_library->FindLibrary(library, version);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ struct GSConfigWindow : public Window {
|
||||
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
{
|
||||
if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_END) {
|
||||
if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) {
|
||||
if (GameConfig::GetConfig() == nullptr) return;
|
||||
|
||||
ShowScriptTextfileWindow((TextfileType)(widget - WID_GSC_TEXTFILE), (CompanyID)OWNER_DEITY);
|
||||
@@ -273,13 +273,13 @@ struct GSConfigWindow : public Window {
|
||||
break;
|
||||
|
||||
case WID_GSC_SETTINGS: {
|
||||
Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
|
||||
int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
|
||||
if (num >= (int)this->visible_settings.size()) break;
|
||||
auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
|
||||
if (it == this->visible_settings.end()) break;
|
||||
|
||||
const ScriptConfigItem &config_item = *this->visible_settings[num];
|
||||
const ScriptConfigItem &config_item = **it;
|
||||
if (!this->IsEditableItem(config_item)) return;
|
||||
|
||||
int num = it - this->visible_settings.begin();
|
||||
if (this->clicked_row != num) {
|
||||
this->DeleteChildWindows(WC_QUERY_STRING);
|
||||
HideDropDownMenu(this);
|
||||
@@ -289,6 +289,7 @@ struct GSConfigWindow : public Window {
|
||||
|
||||
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
|
||||
|
||||
Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
|
||||
int x = pt.x - r.left;
|
||||
if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
|
||||
|
||||
@@ -413,7 +414,7 @@ struct GSConfigWindow : public Window {
|
||||
|
||||
this->SetWidgetDisabledState(WID_GSC_CHANGE, !UserIsAllowedToChangeGameScript() || !IsEditable());
|
||||
|
||||
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
|
||||
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, GameConfig::GetConfig()->GetTextfile(tft, (CompanyID)OWNER_DEITY) == nullptr);
|
||||
}
|
||||
this->RebuildVisibleSettings();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* Check if the API version provided by the Game is supported.
|
||||
* @param api_version The API version as provided by the Game.
|
||||
*/
|
||||
static bool CheckAPIVersion(const char *api_version)
|
||||
static bool CheckAPIVersion(const std::string &api_version)
|
||||
{
|
||||
static const std::set<std::string> versions = { "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
|
||||
return versions.find(api_version) != versions.end();
|
||||
@@ -60,22 +60,22 @@ template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInf
|
||||
SQInteger res = ScriptInfo::Constructor(vm, info);
|
||||
if (res != 0) return res;
|
||||
|
||||
if (info->engine->MethodExists(*info->SQ_instance, "MinVersionToLoad")) {
|
||||
if (!info->engine->CallIntegerMethod(*info->SQ_instance, "MinVersionToLoad", &info->min_loadable_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (info->engine->MethodExists(info->SQ_instance, "MinVersionToLoad")) {
|
||||
if (!info->engine->CallIntegerMethod(info->SQ_instance, "MinVersionToLoad", &info->min_loadable_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
} else {
|
||||
info->min_loadable_version = info->GetVersion();
|
||||
}
|
||||
/* When there is an IsSelectable function, call it. */
|
||||
if (info->engine->MethodExists(*info->SQ_instance, "IsDeveloperOnly")) {
|
||||
if (!info->engine->CallBoolMethod(*info->SQ_instance, "IsDeveloperOnly", &info->is_developer_only, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (info->engine->MethodExists(info->SQ_instance, "IsDeveloperOnly")) {
|
||||
if (!info->engine->CallBoolMethod(info->SQ_instance, "IsDeveloperOnly", &info->is_developer_only, MAX_GET_OPS)) return SQ_ERROR;
|
||||
} else {
|
||||
info->is_developer_only = false;
|
||||
}
|
||||
/* Try to get the API version the AI is written for. */
|
||||
if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR;
|
||||
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (!info->engine->CallStringMethod(info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (!CheckAPIVersion(info->api_version)) {
|
||||
DEBUG(script, 1, "Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->GetName(), info->GetVersion());
|
||||
DEBUG(script, 1, "Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->GetName().c_str(), info->GetVersion());
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
@@ -88,16 +88,10 @@ template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInf
|
||||
|
||||
GameInfo::GameInfo() :
|
||||
min_loadable_version(0),
|
||||
is_developer_only(false),
|
||||
api_version(nullptr)
|
||||
is_developer_only(false)
|
||||
{
|
||||
}
|
||||
|
||||
GameInfo::~GameInfo()
|
||||
{
|
||||
free(this->api_version);
|
||||
}
|
||||
|
||||
bool GameInfo::CanLoadFromVersion(int version) const
|
||||
{
|
||||
if (version == -1) return true;
|
||||
@@ -105,11 +99,6 @@ bool GameInfo::CanLoadFromVersion(int version) const
|
||||
}
|
||||
|
||||
|
||||
GameLibrary::~GameLibrary()
|
||||
{
|
||||
free(this->category);
|
||||
}
|
||||
|
||||
/* static */ void GameLibrary::RegisterAPI(Squirrel *engine)
|
||||
{
|
||||
/* Create the GameLibrary class, and add the RegisterLibrary function */
|
||||
@@ -130,7 +119,7 @@ GameLibrary::~GameLibrary()
|
||||
}
|
||||
|
||||
/* Cache the category */
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethodStrdup(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
delete library;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
class GameInfo : public ScriptInfo {
|
||||
public:
|
||||
GameInfo();
|
||||
~GameInfo();
|
||||
|
||||
/**
|
||||
* Register the functions of this class.
|
||||
@@ -36,21 +35,20 @@ public:
|
||||
/**
|
||||
* Get the API version this Game is written for.
|
||||
*/
|
||||
const char *GetAPIVersion() const { return this->api_version; }
|
||||
const std::string &GetAPIVersion() const { return this->api_version; }
|
||||
|
||||
bool IsDeveloperOnly() const override { return this->is_developer_only; }
|
||||
|
||||
private:
|
||||
int min_loadable_version; ///< The Game can load savegame data if the version is equal or greater than this.
|
||||
bool is_developer_only; ///< Is the script selectable by non-developers?
|
||||
const char *api_version; ///< API version used by this Game.
|
||||
std::string api_version; ///< API version used by this Game.
|
||||
};
|
||||
|
||||
/** All static information from an Game library like name, version, etc. */
|
||||
class GameLibrary : public ScriptInfo {
|
||||
public:
|
||||
GameLibrary() : ScriptInfo(), category(nullptr) {};
|
||||
~GameLibrary();
|
||||
GameLibrary() : ScriptInfo() {};
|
||||
|
||||
/**
|
||||
* Register the functions of this class.
|
||||
@@ -65,10 +63,10 @@ public:
|
||||
/**
|
||||
* Get the category this library is in.
|
||||
*/
|
||||
const char *GetCategory() const { return this->category; }
|
||||
const std::string &GetCategory() const { return this->category; }
|
||||
|
||||
private:
|
||||
const char *category; ///< The category this library is in.
|
||||
std::string category; ///< The category this library is in.
|
||||
};
|
||||
|
||||
#endif /* GAME_INFO_HPP */
|
||||
|
||||
@@ -52,12 +52,12 @@ void GameInstance::RegisterAPI()
|
||||
if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died();
|
||||
}
|
||||
|
||||
int GameInstance::GetSetting(const char *name)
|
||||
int GameInstance::GetSetting(const std::string &name)
|
||||
{
|
||||
return GameConfig::GetConfig()->GetSetting(name);
|
||||
}
|
||||
|
||||
ScriptInfo *GameInstance::FindLibrary(const char *library, int version)
|
||||
ScriptInfo *GameInstance::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return (ScriptInfo *)Game::FindLibrary(library, version);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ void GameInstance::Died()
|
||||
if (info != nullptr) {
|
||||
ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
|
||||
|
||||
if (info->GetURL() != nullptr) {
|
||||
if (!info->GetURL().empty()) {
|
||||
ScriptLog::Info("Please report the error to the following URL:");
|
||||
ScriptLog::Info(info->GetURL());
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
*/
|
||||
void Initialize(class GameInfo *info);
|
||||
|
||||
int GetSetting(const char *name) override;
|
||||
ScriptInfo *FindLibrary(const char *library, int version) override;
|
||||
int GetSetting(const std::string &name) override;
|
||||
ScriptInfo *FindLibrary(const std::string &library, int version) override;
|
||||
|
||||
private:
|
||||
void RegisterAPI() override;
|
||||
|
||||
@@ -33,10 +33,10 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
GameInfo::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
GameInfo *GameScannerInfo::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
GameInfo *GameScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
if (this->info_list.size() == 0) return nullptr;
|
||||
if (name == nullptr) return nullptr;
|
||||
if (name.empty()) return nullptr;
|
||||
|
||||
if (version == -1) {
|
||||
/* We want to load the latest version of this Game script; so find it */
|
||||
@@ -86,7 +86,7 @@ void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
GameLibrary::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
GameLibrary *GameScannerLibrary::FindLibrary(const char *library, int version)
|
||||
GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
* @param force_exact_match Only match name+version, never latest.
|
||||
* @return nullptr if no match found, otherwise the game script that matched.
|
||||
*/
|
||||
class GameInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
class GameInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
|
||||
protected:
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
* @param version The version the library should have.
|
||||
* @return The library if found, nullptr otherwise.
|
||||
*/
|
||||
class GameLibrary *FindLibrary(const char *library, int version);
|
||||
class GameLibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
protected:
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
|
||||
Reference in New Issue
Block a user