Play_controller: register as AI observer in reset_gamestate()

Now when play controller can outlive AI manager, it needs to register
itself as an observer when the AI manager is recreated.

While I was working with this code, I also moved the existing
registration from playsingle_controller to play_controller (for
consistency) and stopped using the singleton pointer to access the
manager.

Thanks to @gfgtdf for spotting the problem.
This commit is contained in:
Jyrki Vesterinen 2018-02-23 08:12:13 +02:00
parent 87289338f4
commit d256a7b609
2 changed files with 2 additions and 2 deletions

View file

@ -216,6 +216,7 @@ void play_controller::init(const config& level)
resources::game_events = gamestate().events_manager_.get();
resources::lua_kernel = gamestate().lua_kernel_.get();
gamestate_->ai_manager_.add_observer(this);
gamestate_->init(level, *this);
resources::tunnels = gamestate().pathfind_manager_.get();
@ -314,6 +315,7 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
resources::game_events = gamestate().events_manager_.get();
resources::lua_kernel = gamestate().lua_kernel_.get();
gamestate_->ai_manager_.add_observer(this);
gamestate_->init(level, *this);
gamestate().set_game_display(gui_.get());
resources::tunnels = gamestate().pathfind_manager_.get();

View file

@ -84,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::manager::get_singleton().add_observer(this);
plugins_context_->set_accessor_string("level_result", std::bind(&playsingle_controller::describe_result, this));
plugins_context_->set_accessor_int("turn", std::bind(&play_controller::turn, this));
}