Skip to content

Commit

Permalink
Codechange: [Script] Use std::unique_ptr for Company::ai_instance (Op…
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 authored Apr 20, 2024
1 parent 1dfd0c1 commit c5ef47e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/ai/ai_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

c->ai_info = info;
assert(c->ai_instance == nullptr);
c->ai_instance = new AIInstance();
c->ai_instance = std::make_unique<AIInstance>();
c->ai_instance->Initialize(info);
c->ai_instance->LoadOnStack(config->GetToLoadData());
config->SetToLoadData(nullptr);
Expand Down Expand Up @@ -112,8 +112,7 @@
Backup<CompanyID> 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();

Expand Down
2 changes: 1 addition & 1 deletion src/company_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class AIInstance> ai_instance;
class AIInfo *ai_info;
std::unique_ptr<class AIConfig> ai_config;

Expand Down
1 change: 1 addition & 0 deletions src/company_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c5ef47e

Please sign in to comment.