Merge branch 'master' into jgrpp
# Conflicts: # cmake/CompileFlags.cmake # src/cargomonitor.cpp # src/core/CMakeLists.txt # src/economy.cpp # src/landscape.cpp # src/linkgraph/flowmapper.cpp # src/linkgraph/linkgraph_gui.cpp # src/linkgraph/linkgraphschedule.cpp # src/misc_gui.cpp # src/newgrf_generic.cpp # src/newgrf_storage.cpp # src/rail_gui.cpp # src/saveload/afterload.cpp # src/saveload/station_sl.cpp # src/script/script_gui.cpp # src/station_cmd.cpp # src/station_gui.cpp # src/string_func.h # src/terraform_cmd.cpp
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "../script_gui.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../network/network.h"
|
||||
#include "../../3rdparty/fmt/format.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
@@ -75,16 +76,6 @@ ScriptController::ScriptController(CompanyID company) :
|
||||
ScriptObject::SetCompany(company);
|
||||
}
|
||||
|
||||
ScriptController::~ScriptController()
|
||||
{
|
||||
for (const auto &item : this->loaded_library) {
|
||||
free(item.second);
|
||||
free(item.first);
|
||||
}
|
||||
|
||||
this->loaded_library.clear();
|
||||
}
|
||||
|
||||
/* static */ uint ScriptController::GetTick()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance()->GetController()->ticks;
|
||||
@@ -124,24 +115,22 @@ ScriptController::~ScriptController()
|
||||
}
|
||||
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
char library_name[1024];
|
||||
seprintf(library_name, lastof(library_name), "%s.%d", library, version);
|
||||
strtolower(library_name);
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
/* Get the current table/class we belong to */
|
||||
HSQOBJECT parent;
|
||||
sq_getstackobj(vm, 1, &parent);
|
||||
|
||||
char fake_class[1024];
|
||||
std::string fake_class;
|
||||
|
||||
LoadedLibraryList::iterator it = controller->loaded_library.find(library_name);
|
||||
if (it != controller->loaded_library.end()) {
|
||||
strecpy(fake_class, (*it).second, lastof(fake_class));
|
||||
fake_class = (*it).second;
|
||||
} else {
|
||||
int next_number = ++controller->loaded_library_count;
|
||||
|
||||
/* Create a new fake internal name */
|
||||
seprintf(fake_class, lastof(fake_class), "_internalNA%d", next_number);
|
||||
fake_class = fmt::format("_internalNA{}", next_number);
|
||||
|
||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||
sq_pushroottable(vm);
|
||||
@@ -157,7 +146,7 @@ ScriptController::~ScriptController()
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
controller->loaded_library[stredup(library_name)] = stredup(fake_class);
|
||||
controller->loaded_library[library_name] = fake_class;
|
||||
}
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define SCRIPT_CONTROLLER_HPP
|
||||
|
||||
#include "script_types.hpp"
|
||||
#include "../../core/string_compare_type.hpp"
|
||||
#include "../../string_func.h"
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
@@ -55,11 +55,6 @@ public:
|
||||
*/
|
||||
ScriptController(CompanyID company);
|
||||
|
||||
/**
|
||||
* Destructor of the ScriptController.
|
||||
*/
|
||||
~ScriptController();
|
||||
|
||||
#else
|
||||
/**
|
||||
* This function is called to start your script. Your script starts here. If you
|
||||
@@ -215,7 +210,7 @@ public:
|
||||
static HSQOBJECT Import(const char *library, const char *class_name, int version);
|
||||
|
||||
private:
|
||||
typedef std::map<const char *, const char *, StringCompare> LoadedLibraryList; ///< The type for loaded libraries.
|
||||
typedef std::map<std::string, std::string, CaseInsensitiveComparator> LoadedLibraryList; ///< The type for loaded libraries.
|
||||
|
||||
uint ticks; ///< The amount of ticks we're sleeping.
|
||||
LoadedLibraryList loaded_library; ///< The libraries we loaded.
|
||||
|
@@ -171,7 +171,7 @@
|
||||
if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1;
|
||||
if (IsWagon(engine_id)) return -1;
|
||||
|
||||
return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort();
|
||||
return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort() / 1000;
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptEngine::GetDesignDate(EngineID engine_id)
|
||||
|
@@ -564,9 +564,9 @@ void ScriptList::AddList(ScriptList *list)
|
||||
this->modifications++;
|
||||
} else {
|
||||
ScriptListMap *list_items = &list->items;
|
||||
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
|
||||
this->AddItem((*iter).first);
|
||||
this->SetValue((*iter).first, (*iter).second);
|
||||
for (auto &it : *list_items) {
|
||||
this->AddItem(it.first);
|
||||
this->SetValue(it.first, it.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user