Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/CompileFlags.cmake
#	src/crashlog.cpp
#	src/fileio.cpp
#	src/fileio_func.h
#	src/fios_gui.cpp
#	src/ini_load.cpp
#	src/ini_type.h
#	src/lang/english.txt
#	src/lang/german.txt
#	src/lang/korean.txt
#	src/network/network_client.cpp
#	src/order_base.h
#	src/order_cmd.cpp
#	src/os/windows/win32.cpp
#	src/road_cmd.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/settings.cpp
#	src/station_cmd.cpp
#	src/stdafx.h
#	src/table/settings.ini
#	src/tree_cmd.cpp
#	src/tree_gui.cpp
#	src/vehicle_base.h
#	src/video/cocoa/cocoa_v.mm
#	src/video/cocoa/event.mm
#	src/video/cocoa/wnd_quartz.mm
#	src/viewport.cpp
#	src/widgets/tree_widget.h
This commit is contained in:
Jonathan G Rennison
2021-01-30 23:24:40 +00:00
235 changed files with 3537 additions and 3063 deletions

View File

@@ -204,8 +204,10 @@
if (loan == GetLoanAmount()) return true;
Money amount = abs(loan - GetLoanAmount());
return ScriptObject::DoCommand(0,
abs(loan - GetLoanAmount()), 2,
amount >> 32, (amount & 0xFFFFFFFC) | 2,
(loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN);
}

View File

@@ -31,9 +31,7 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
for (const Vehicle *v : Vehicle::Iterate()) {
if ((v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && v->IsPrimaryVehicle()) {
const Order *order;
FOR_VEHICLE_ORDERS(v, order) {
for (const Order *order : v->Orders()) {
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station_id) {
this->AddItem(v->index);
break;
@@ -81,9 +79,7 @@ ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
for (const Vehicle *v : Vehicle::Iterate()) {
if ((v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && v->IsPrimaryVehicle() && v->type == type) {
const Order *order;
FOR_VEHICLE_ORDERS(v, order) {
for (const Order *order : v->Orders()) {
if (order->IsType(OT_GOTO_DEPOT) && order->GetDestination() == dest) {
this->AddItem(v->index);
break;

View File

@@ -127,6 +127,26 @@ void ScriptConfig::ResetSettings()
this->settings.clear();
}
void ScriptConfig::ResetEditableSettings(bool yet_to_start)
{
if (this->info == nullptr) return ResetSettings();
for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end();) {
const ScriptConfigItem *config_item = this->info->GetConfigItem(it->first);
assert(config_item != nullptr);
bool editable = yet_to_start || (config_item->flags & SCRIPTCONFIG_INGAME) != 0;
bool visible = _settings_client.gui.ai_developer_tools || (config_item->flags & SCRIPTCONFIG_DEVELOPER) == 0;
if (editable && visible) {
free(it->first);
it = this->settings.erase(it);
} else {
it++;
}
}
}
void ScriptConfig::AddRandomDeviation()
{
for (const auto &item : *this->GetConfigList()) {

View File

@@ -134,6 +134,11 @@ public:
*/
void ResetSettings();
/**
* Reset only editable and visible settings to their default value.
*/
void ResetEditableSettings(bool yet_to_start);
/**
* Randomize all settings the Script requested to be randomized.
*/

View File

@@ -39,8 +39,6 @@ ScriptInfo::~ScriptInfo()
free(this->date);
free(this->instance_name);
free(this->url);
free(this->main_script);
free(this->tar_file);
free(this->SQ_instance);
}
@@ -81,9 +79,8 @@ bool ScriptInfo::CheckMethod(const char *name) const
}
/* Get location information of the scanner */
info->main_script = stredup(info->scanner->GetMainScript());
const char *tar_name = info->scanner->GetTarFile();
if (tar_name != nullptr) info->tar_file = stredup(tar_name);
info->main_script = info->scanner->GetMainScript();
info->tar_file = info->scanner->GetTarFile();
/* Cache the data the info file gives us. */
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author, MAX_GET_OPS)) return SQ_ERROR;

View File

@@ -32,8 +32,6 @@ public:
ScriptInfo() :
engine(nullptr),
SQ_instance(nullptr),
main_script(nullptr),
tar_file(nullptr),
author(nullptr),
name(nullptr),
short_name(nullptr),
@@ -89,12 +87,12 @@ public:
/**
* Get the filename of the main.nut script.
*/
const char *GetMainScript() const { return this->main_script; }
const char *GetMainScript() const { return this->main_script.c_str(); }
/**
* Get the filename of the tar the script is in.
*/
const char *GetTarFile() const { return this->tar_file; }
std::string GetTarFile() const { return this->tar_file; }
/**
* Check if a given method exists.
@@ -152,8 +150,8 @@ protected:
ScriptConfigItemList config_list; ///< List of settings from this Script.
private:
char *main_script; ///< The full path of the script.
char *tar_file; ///< If, which tar file the script was in.
std::string main_script; ///< The full path of the script.
std::string tar_file; ///< If, which tar file the script was in.
const char *author; ///< Author of the script.
const char *name; ///< Full name of the script.
const char *short_name; ///< Short name (4 chars) which uniquely identifies the script.

View File

@@ -123,17 +123,16 @@ bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirect
{
char script_name[32];
seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version);
char buf[MAX_PATH];
Searchpath sp;
FOR_ALL_SEARCHPATHS(sp) {
FioAppendDirectory(buf, lastof(buf), sp, dir);
strecat(buf, script_name, lastof(buf));
std::string buf = FioGetDirectory(sp, dir);
buf += script_name;
if (!FileExists(buf)) continue;
if (this->engine->LoadScript(buf)) return true;
if (this->engine->LoadScript(buf.c_str())) return true;
ScriptLog::Error("Failed to load API compatibility script");
DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf);
DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf.c_str());
return false;
}

View File

@@ -23,47 +23,29 @@
#include "../safeguards.h"
bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
bool ScriptScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename)
{
free(this->main_script);
this->main_script = stredup(filename);
if (this->main_script == nullptr) return false;
this->main_script = filename;
this->tar_file = tar_filename;
free(this->tar_file);
if (tar_filename != nullptr) {
this->tar_file = stredup(tar_filename);
if (this->tar_file == nullptr) return false;
} else {
this->tar_file = nullptr;
}
const char *end = this->main_script + strlen(this->main_script) + 1;
char *p = strrchr(this->main_script, PATHSEPCHAR);
if (p == nullptr) {
p = this->main_script;
} else {
/* Skip over the path separator character. We don't need that. */
p++;
}
strecpy(p, "main.nut", end);
auto p = this->main_script.rfind(PATHSEPCHAR);
this->main_script.erase(p != std::string::npos ? p + 1 : 0);
this->main_script += "main.nut";
if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false;
this->ResetEngine();
try {
this->engine->LoadScript(filename);
this->engine->LoadScript(filename.c_str());
} catch (Script_FatalError &e) {
DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage(), filename);
DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage(), filename.c_str());
return false;
}
return true;
}
ScriptScanner::ScriptScanner() :
engine(nullptr),
main_script(nullptr),
tar_file(nullptr)
engine(nullptr)
{
}
@@ -87,8 +69,6 @@ ScriptScanner::~ScriptScanner()
{
this->Reset();
free(this->main_script);
free(this->tar_file);
delete this->engine;
}
@@ -194,7 +174,7 @@ struct ScriptFileChecksumCreator : FileScanner {
}
/* Add the file and calculate the md5 sum. */
virtual bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
virtual bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename)
{
Md5 checksum;
uint8 buffer[1024];
@@ -202,7 +182,7 @@ struct ScriptFileChecksumCreator : FileScanner {
byte tmp_md5sum[16];
/* Open the file ... */
FILE *f = FioFOpenFile(filename, "rb", this->dir, &size);
FILE *f = FioFOpenFile(filename.c_str(), "rb", this->dir, &size);
if (f == nullptr) return false;
/* ... calculate md5sum... */
@@ -239,9 +219,9 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
if (!md5sum) return true;
ScriptFileChecksumCreator checksum(dir);
const char *tar_filename = info->GetTarFile();
auto tar_filename = info->GetTarFile();
TarList::iterator iter;
if (tar_filename != nullptr && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
/* The main script is in a tar file, so find all files that
* are in the same tar and add them to the MD5 checksumming. */
TarFileList::iterator tar;
@@ -253,7 +233,7 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
const char *ext = strrchr(tar->first.c_str(), '.');
if (ext == nullptr || strcasecmp(ext, ".nut") != 0) continue;
checksum.AddFile(tar->first.c_str(), 0, tar_filename);
checksum.AddFile(tar->first, 0, tar_filename);
}
} else {
char path[MAX_PATH];

View File

@@ -32,12 +32,12 @@ public:
/**
* Get the current main script the ScanDir is currently tracking.
*/
const char *GetMainScript() { return this->main_script; }
std::string GetMainScript() { return this->main_script; }
/**
* Get the current tar file the ScanDir is currently tracking.
*/
const char *GetTarFile() { return this->tar_file; }
std::string GetTarFile() { return this->tar_file; }
/**
* Get the list of all registered scripts.
@@ -75,7 +75,7 @@ public:
*/
const char *FindMainScript(const ContentInfo *ci, bool md5sum);
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override;
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
/**
* Rescan the script dir.
@@ -83,9 +83,9 @@ public:
void RescanDir();
protected:
class Squirrel *engine; ///< The engine we're scanning with.
char *main_script; ///< The full path of the script.
char *tar_file; ///< If, which tar file the script was in.
class Squirrel *engine; ///< The engine we're scanning with.
std::string main_script; ///< The full path of the script.
std::string tar_file; ///< If, which tar file the script was in.
ScriptInfoList info_list; ///< The list of all script.
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.