Promote ai_info_ from pointer to a member object
We used to create a new ai_info object in the constructor of playsingle_controller in order to reset it on scenario changes. Now when the AI manager is a part of game state, resetting the game state implicitly creates a new ai_info object, and setting the AI info manually is no longer necessary. This also ensures that ai_info can't ever be null, fixing #2522. In the process, I also discovered that ai::registry::init() doesn't do anything, so I removed it, its declaration, and ai/registry.hpp which contained nothing except said function declaration.
This commit is contained in:
parent
05d52c5db5
commit
f96b9d2bba
7 changed files with 8 additions and 85 deletions
|
@ -3564,7 +3564,6 @@
|
|||
<ClInclude Include="..\..\src\ai\lua\engine_lua.hpp" />
|
||||
<ClInclude Include="..\..\src\ai\lua\lua_object.hpp" />
|
||||
<ClInclude Include="..\..\src\ai\manager.hpp" />
|
||||
<ClInclude Include="..\..\src\ai\registry.hpp" />
|
||||
<ClInclude Include="..\..\src\ai\simulated_actions.hpp" />
|
||||
<ClInclude Include="..\..\src\ai\testing.hpp" />
|
||||
<ClInclude Include="..\..\src\animated.hpp" />
|
||||
|
|
|
@ -1596,9 +1596,6 @@
|
|||
<ClInclude Include="..\..\src\ai\manager.hpp">
|
||||
<Filter>AI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ai\registry.hpp">
|
||||
<Filter>AI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ai\simulated_actions.hpp">
|
||||
<Filter>AI</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "ai/game_info.hpp" // for side_number, engine_ptr, etc
|
||||
#include "game_config.hpp" // for debug
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "ai/registry.hpp" // for init
|
||||
|
||||
#include <algorithm> // for min
|
||||
#include <cassert> // for assert
|
||||
|
@ -305,7 +304,7 @@ component* holder::get_component(component *root, const std::string &path) {
|
|||
manager::manager()
|
||||
: history_()
|
||||
, history_item_counter_(0)
|
||||
, ai_info_(nullptr)
|
||||
, ai_info_()
|
||||
, map_changed_("ai_map_changed")
|
||||
, recruit_list_changed_("ai_recruit_list_changed")
|
||||
, user_interact_("ai_user_interact")
|
||||
|
@ -323,21 +322,6 @@ manager::manager()
|
|||
manager* manager::singleton_ = nullptr;
|
||||
|
||||
|
||||
void manager::set_ai_info(const game_info& i)
|
||||
{
|
||||
if (ai_info_!=nullptr){
|
||||
clear_ai_info();
|
||||
}
|
||||
ai_info_.reset(new game_info(i));
|
||||
registry::init();
|
||||
}
|
||||
|
||||
|
||||
void manager::clear_ai_info(){
|
||||
ai_info_.reset(nullptr);
|
||||
}
|
||||
|
||||
|
||||
void manager::add_observer( events::observer* event_observer){
|
||||
user_interact_.attach_handler(event_observer);
|
||||
sync_network_.attach_handler(event_observer);
|
||||
|
@ -691,19 +675,12 @@ void manager::clear_ais()
|
|||
|
||||
void manager::modify_active_ai_for_side ( side_number side, const config &cfg )
|
||||
{
|
||||
if (ai_info_==nullptr) {
|
||||
//replay ?
|
||||
return;
|
||||
}
|
||||
get_active_ai_holder_for_side(side).modify_ai(cfg);
|
||||
}
|
||||
|
||||
|
||||
void manager::append_active_ai_for_side(side_number side, const config& cfg)
|
||||
{
|
||||
if(!ai_info_) {
|
||||
return;
|
||||
}
|
||||
get_active_ai_holder_for_side(side).append_ai(cfg);
|
||||
}
|
||||
|
||||
|
@ -741,15 +718,15 @@ config manager::to_config( side_number side )
|
|||
}
|
||||
|
||||
|
||||
game_info& manager::get_active_ai_info_for_side( side_number /*side*/ ) const
|
||||
game_info& manager::get_active_ai_info_for_side( side_number /*side*/ )
|
||||
{
|
||||
return *ai_info_;
|
||||
return ai_info_;
|
||||
}
|
||||
|
||||
|
||||
game_info& manager::get_ai_info() const
|
||||
game_info& manager::get_ai_info()
|
||||
{
|
||||
return *ai_info_;
|
||||
return ai_info_;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -164,19 +164,6 @@ public:
|
|||
// LIFECYCLE
|
||||
// =======================================================================
|
||||
|
||||
/**
|
||||
* Sets AI information.
|
||||
* @param info ai_information to be set.
|
||||
*/
|
||||
void set_ai_info(const game_info& info);
|
||||
|
||||
|
||||
/**
|
||||
* Clears AI information.
|
||||
* Should be called in playsingle_controller 's destructor.
|
||||
*/
|
||||
void clear_ai_info();
|
||||
|
||||
|
||||
/**
|
||||
* Adds observer of game events.
|
||||
|
@ -398,7 +385,7 @@ public:
|
|||
* @param side side number (1-based).
|
||||
* @return a reference to active AI info.
|
||||
*/
|
||||
game_info& get_active_ai_info_for_side( side_number side ) const;
|
||||
game_info& get_active_ai_info_for_side( side_number side );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -443,7 +430,7 @@ public:
|
|||
* Gets global AI-game info
|
||||
* @return a reference to the AI-game info.
|
||||
*/
|
||||
game_info& get_ai_info() const;
|
||||
game_info& get_ai_info();
|
||||
|
||||
|
||||
// =======================================================================
|
||||
|
@ -485,7 +472,7 @@ private:
|
|||
|
||||
std::deque< command_history_item > history_;
|
||||
long history_item_counter_;
|
||||
std::unique_ptr<game_info> ai_info_;
|
||||
game_info ai_info_;
|
||||
|
||||
events::generic_event map_changed_;
|
||||
events::generic_event recruit_list_changed_;
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
#include "ai/registry.hpp"
|
||||
|
||||
#include "config.hpp" // for config, operator<<
|
||||
#include "terrain/filter.hpp" // for terrain_filter
|
||||
#include "ai/composite/engine.hpp" // for register_engine_factory
|
||||
|
@ -477,8 +475,4 @@ static register_aspect_factory< default_recruitment::recruitment_aspect >
|
|||
static register_aspect_factory< default_recruitment::recruitment_aspect >
|
||||
recruitment__standard_aspect_factory2("recruitment*");
|
||||
|
||||
void registry::init()
|
||||
{
|
||||
}
|
||||
|
||||
} //end of namespace ai
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2009 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* All known AI parts
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ai {
|
||||
namespace registry {
|
||||
|
||||
void init();
|
||||
|
||||
}
|
||||
} //end of namespace ai
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "actions/undo.hpp"
|
||||
#include "ai/manager.hpp"
|
||||
#include "ai/game_info.hpp"
|
||||
#include "ai/testing.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
|
@ -85,8 +84,6 @@ playsingle_controller::playsingle_controller(const config& level,
|
|||
// game may need to start in linger mode
|
||||
linger_ = this->is_regular_game_end();
|
||||
|
||||
ai::game_info ai_info;
|
||||
ai::manager::get_singleton().set_ai_info(ai_info);
|
||||
ai::manager::get_singleton().add_observer(this);
|
||||
|
||||
plugins_context_->set_accessor_string("level_result", std::bind(&playsingle_controller::describe_result, this));
|
||||
|
|
Loading…
Add table
Reference in a new issue