run initial lua directly after creating gamestate.

this should fix http://gna.org/bugs/?24304
This commit is contained in:
gfgtdf 2016-01-29 22:45:35 +01:00
parent f880c6036e
commit e9f0fe726d
4 changed files with 15 additions and 12 deletions

View file

@ -306,6 +306,8 @@ void play_controller::init(CVideo& video, const config& level)
init_managers();
loadscreen::global_loadscreen->start_stage("start game");
loadscreen_manager->reset();
gamestate().gamedata_.set_phase(game_data::PRELOAD);
gamestate().lua_kernel_->initialize(level);
plugins_context_.reset(new plugins_context("Game"));
plugins_context_->set_callback("save_game", boost::bind(&play_controller::save_game_auto, this, boost::bind(get_str, _1, "filename" )), true);
@ -345,6 +347,8 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
gui_->reset_reports(*gamestate().reports_);
gui_->change_display_context(&gamestate().board_);
saved_game_.get_replay().set_pos(replay_pos);
gamestate().gamedata_.set_phase(game_data::PRELOAD);
gamestate().lua_kernel_->initialize(level);
}
void play_controller::init_managers()
@ -358,11 +362,9 @@ void play_controller::init_managers()
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl;
}
void play_controller::fire_preload(const config& level)
void play_controller::fire_preload()
{
// Run initialization scripts, even if loading from a snapshot.
gamestate().gamedata_.set_phase(game_data::PRELOAD);
gamestate().lua_kernel_->initialize(level);
gamestate().gamedata_.get_variable("turn_number") = int(turn());
pump().fire("preload");
}
@ -1084,9 +1086,9 @@ void play_controller::play_slice_catch()
}
}
void play_controller::start_game(const config& level)
void play_controller::start_game()
{
fire_preload(level);
fire_preload();
if(!gamestate().start_event_fired_)
{

View file

@ -285,10 +285,10 @@ protected:
void init_managers();
///preload events cannot be synced
void fire_preload(const config& level);
void fire_preload();
void fire_prestart();
void fire_start();
void start_game(const config& level);
void start_game();
virtual void init_gui();
void finish_side_turn();
void finish_turn(); //this should not throw an end turn or end level exception

View file

@ -133,12 +133,13 @@ void playsingle_controller::init_gui(){
}
void playsingle_controller::play_scenario_init(const config& level) {
void playsingle_controller::play_scenario_init()
{
// At the beginning of the scenario, save a snapshot as replay_start
if(saved_game_.replay_start().empty()){
saved_game_.replay_start() = to_config();
}
start_game(level);
start_game();
if( saved_game_.classification().random_mode != "" && (network::nconnections() != 0)) {
// This won't cause errors later but we should notify the user about it in case he didn't knew it.
gui2::show_transient_message(
@ -190,7 +191,7 @@ void playsingle_controller::play_scenario_main_loop()
for(size_t i = 0; i < local_players.size(); ++i) {
(*resources::teams)[i].set_local(local_players[i]);
}
play_scenario_init(*ex.level);
play_scenario_init();
mp_replay_.reset(new replay_controller(*this, false, ex.level));
mp_replay_->play_replay();
}
@ -226,7 +227,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
}
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks()) << "\n";
try {
play_scenario_init(level);
play_scenario_init();
// clears level config;
this->saved_game_.remove_snapshot();

View file

@ -41,7 +41,7 @@ public:
virtual ~playsingle_controller();
LEVEL_RESULT play_scenario(const config& level);
void play_scenario_init(const config& level);
void play_scenario_init();
void play_scenario_main_loop();
virtual void handle_generic_event(const std::string& name);