1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Peter Nelson ed1e9dfb42
Merge 77d78f3069 into b8e56cd05d 2025-07-19 04:45:24 +00:00
translators b8e56cd05d Update: Translations from eints
chinese (traditional): 3 changes by KogentaSan
chinese (simplified): 1 change by ahyangyi
2025-07-19 04:43:14 +00:00
Peter Nelson df5237e721
Fix: Vehicle liveries did not update when switching company. (#14456)
Vehicle liveries must be refreshed if "Show vehicle-type specific liveries" is set to "Own company".
2025-07-18 23:43:07 +00:00
Peter Nelson 77d78f3069
Codechange: Use unique_ptr for all pointers in script instance.
Removes manual memory management with new/delete.
2025-07-15 12:16:20 +01:00
7 changed files with 28 additions and 29 deletions

View File

@ -83,7 +83,7 @@ void AIInstance::Died()
void AIInstance::LoadDummyScript()
{
ScriptAllocatorScope alloc_scope(this->engine);
ScriptAllocatorScope alloc_scope(this->engine.get());
Script_CreateDummy(this->engine->GetVM(), STR_ERROR_AI_NO_AI_FOUND, "AI");
}

View File

@ -141,6 +141,8 @@ void SetLocalCompany(CompanyID new_company)
MarkWholeScreenDirty();
InvalidateWindowClassesData(WC_SIGN_LIST, -1);
InvalidateWindowClassesData(WC_GOALS_LIST);
InvalidateWindowClassesData(WC_COMPANY_COLOUR, -1);
ResetVehicleColourMap();
}
/**

View File

@ -5001,6 +5001,7 @@ STR_ERROR_FLAT_LAND_REQUIRED :{WHITE}需要
STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}土地倾斜的方向不对
STR_ERROR_CAN_T_DO_THIS :{WHITE}不能这样做……
STR_ERROR_BUILDING_MUST_BE_DEMOLISHED :{WHITE}必须先摧毁建筑
STR_ERROR_BUILDING_IS_PROTECTED :{WHITE}……建筑物被保护
STR_ERROR_CAN_T_CLEAR_THIS_AREA :{WHITE}无法清除这个区域……
STR_ERROR_SITE_UNSUITABLE :{WHITE}……地点不合适
STR_ERROR_ALREADY_BUILT :{WHITE}……已经建成

View File

@ -1356,8 +1356,8 @@ STR_CONFIG_SETTING_AUTOSLOPE_HELPTEXT :可以在建築
STR_CONFIG_SETTING_CATCHMENT :容許更真實的服務範圍設定:{STRING}
STR_CONFIG_SETTING_CATCHMENT_HELPTEXT :使車站和機場的服務範圍根據其種類和大小而改變。
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES :公司車站可以為自帶車站的工業設施提供服務{STRING}
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES_HELPTEXT :啟用後,公司車站可以為附近自帶車站的工業設施(如油井)提供服務。禁用後,這些工業設施只能由其自帶的車站提供服務,並且這些車站不會提供除了該工業設施以外的產品
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES :公司車站可以服務附設車站的工業設施{STRING}
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES_HELPTEXT :啟用後,公司車站可以為附近附設車站的工業(如鑽油平台)提供服務。停用後,這些工業只能由其附設的車站提供服務,並且附設車站不會提供除了該工業設施以外的任何服務
STR_CONFIG_SETTING_EXTRADYNAMITE :允許移除更多市鎮擁有的道路、橋樑及隧道:{STRING}
STR_CONFIG_SETTING_EXTRADYNAMITE_HELPTEXT :使玩家更容易地移除市鎮擁有的基礎建設和建築物。
@ -5001,7 +5001,7 @@ STR_ERROR_FLAT_LAND_REQUIRED :{WHITE}需要
STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}地面斜坡方向不對
STR_ERROR_CAN_T_DO_THIS :{WHITE}不能執行以下動作...
STR_ERROR_BUILDING_MUST_BE_DEMOLISHED :{WHITE}必須先摧毀建築物
STR_ERROR_BUILDING_IS_PROTECTED :{WHITE}……建築物受到保護
STR_ERROR_BUILDING_IS_PROTECTED :{WHITE}……建築物保護
STR_ERROR_CAN_T_CLEAR_THIS_AREA :{WHITE}不能清除這個地段...
STR_ERROR_SITE_UNSUITABLE :{WHITE}... 地點不適合
STR_ERROR_ALREADY_BUILT :{WHITE}……經已建成

View File

@ -53,7 +53,7 @@ static ScriptStorage &GetStorage()
/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = nullptr;
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance &instance) : alc_scope(instance.engine)
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance &instance) : alc_scope(instance.engine.get())
{
this->last_active = ScriptObject::ActiveInstance::active;
ScriptObject::ActiveInstance::active = &instance;
@ -230,8 +230,8 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
/* static */ bool ScriptObject::CanSuspend()
{
Squirrel *squirrel = ScriptObject::GetActiveInstance().engine;
return GetStorage().allow_do_command && squirrel->CanSuspend();
Squirrel &squirrel = *ScriptObject::GetActiveInstance().engine;
return GetStorage().allow_do_command && squirrel.CanSuspend();
}
/* static */ ScriptEventQueue &ScriptObject::GetEventQueue()

View File

@ -50,8 +50,8 @@ static void PrintFunc(bool error_msg, std::string_view message)
ScriptInstance::ScriptInstance(std::string_view api_name)
{
this->storage = new ScriptStorage();
this->engine = new Squirrel(api_name);
this->storage = std::make_unique<ScriptStorage>();
this->engine = std::make_unique<Squirrel>(api_name);
this->engine->SetPrintFunction(&PrintFunc);
}
@ -59,10 +59,10 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
{
ScriptObject::ActiveInstance active(*this);
this->controller = new ScriptController(company);
this->controller = std::make_unique<ScriptController>(company);
/* Register the API functions and classes */
this->engine->SetGlobalPointer(this->engine);
this->engine->SetGlobalPointer(this->engine.get());
this->RegisterAPI();
if (this->IsDead()) {
/* Failed to register API; a message has already been logged. */
@ -81,12 +81,11 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
}
/* Create the main-class */
this->instance = new SQObject();
if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) {
this->instance = std::make_unique<SQObject>();
if (!this->engine->CreateClassInstance(instance_name, this->controller.get(), this->instance.get())) {
/* If CreateClassInstance has returned false instance has not been
* registered with squirrel, so avoid trying to Release it by clearing it now */
delete this->instance;
this->instance = nullptr;
this->instance.reset();
this->Died();
return;
}
@ -158,11 +157,10 @@ ScriptInstance::~ScriptInstance()
ScriptObject::ActiveInstance active(*this);
this->in_shutdown = true;
if (instance != nullptr) this->engine->ReleaseObject(this->instance);
if (engine != nullptr) delete this->engine;
delete this->storage;
delete this->controller;
delete this->instance;
if (instance != nullptr) this->engine->ReleaseObject(this->instance.get());
/* Engine must be reset explicitly in scope of the active instance. */
this->engine.reset();
}
void ScriptInstance::Continue()
@ -179,11 +177,9 @@ void ScriptInstance::Died()
this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance);
delete this->instance;
delete this->engine;
this->instance = nullptr;
this->engine = nullptr;
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance.get());
this->engine.reset();
this->instance.reset();
}
void ScriptInstance::GameLoop()

View File

@ -256,7 +256,7 @@ public:
void ReleaseSQObject(HSQOBJECT *obj);
protected:
class Squirrel *engine = nullptr; ///< A wrapper around the squirrel vm.
std::unique_ptr<class Squirrel> engine; ///< A wrapper around the squirrel vm.
std::string api_version{}; ///< Current API used by this script.
/**
@ -288,9 +288,9 @@ protected:
virtual void LoadDummyScript() = 0;
private:
class ScriptController *controller = nullptr; ///< The script main class.
class ScriptStorage *storage = nullptr; ///< Some global information for each running script.
SQObject *instance = nullptr; ///< Squirrel-pointer to the script main class.
std::unique_ptr<class ScriptStorage> storage; ///< Some global information for each running script.
std::unique_ptr<class ScriptController> controller; ///< The script main class.
std::unique_ptr<SQObject> instance; ///< Squirrel-pointer to the script main class.
bool is_started = false; ///< Is the scripts constructor executed?
bool is_dead = false; ///< True if the script has been stopped.