From c5ef47ee09691e4f4447a36953c92b8b489fbb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Sat, 20 Apr 2024 16:58:46 +0200 Subject: [PATCH] Codechange: [Script] Use std::unique_ptr for Company::ai_instance (#12544) --- src/ai/ai_core.cpp | 5 ++--- src/company_base.h | 2 +- src/company_cmd.cpp | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index c62f05f9293b7..951ad0c525d6a 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -60,7 +60,7 @@ c->ai_info = info; assert(c->ai_instance == nullptr); - c->ai_instance = new AIInstance(); + c->ai_instance = std::make_unique(); c->ai_instance->Initialize(info); c->ai_instance->LoadOnStack(config->GetToLoadData()); config->SetToLoadData(nullptr); @@ -112,8 +112,7 @@ Backup cur_company(_current_company, company); Company *c = Company::Get(company); - delete c->ai_instance; - c->ai_instance = nullptr; + c->ai_instance.reset(); c->ai_info = nullptr; c->ai_config.reset(); diff --git a/src/company_base.h b/src/company_base.h index c177243686068..9d4a3dc87b38c 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -134,7 +134,7 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> { RailTypes avail_railtypes; ///< Rail types available to this company. RoadTypes avail_roadtypes; ///< Road types available to this company. - class AIInstance *ai_instance; + std::unique_ptr ai_instance; class AIInfo *ai_info; std::unique_ptr ai_config; diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index a92ced1154d5d..f88ad635388fa 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -20,6 +20,7 @@ #include "network/network_base.h" #include "network/network_admin.h" #include "ai/ai.hpp" +#include "ai/ai_instance.hpp" #include "ai/ai_config.hpp" #include "company_manager_face.h" #include "window_func.h"