diff --git a/src/debug.cpp b/src/debug.cpp index b463b5e1ec837..9ce27abf1e393 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -386,7 +386,7 @@ static void debug_error_prompt( inp_mngr.set_timeout( 50 ); input_event ievent = inp_mngr.get_input_event(); if( ievent.type == input_event_t::timeout ) { - if( g && g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { g->query_exit_to_OS(); } continue; diff --git a/src/do_turn.cpp b/src/do_turn.cpp index e6022764b54a7..a017882f17f2c 100644 --- a/src/do_turn.cpp +++ b/src/do_turn.cpp @@ -103,7 +103,7 @@ namespace turn_handler bool cleanup_at_end() { avatar &u = get_avatar(); - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return true; } if( g->uquit == QUIT_DIED || g->uquit == QUIT_SUICIDE ) { diff --git a/src/game.cpp b/src/game.cpp index 1bc13973b5354..fa9dc06cd8978 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2818,7 +2818,7 @@ bool game::query_exit_to_OS() bool game::is_game_over() { - if( uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return query_exit_to_OS(); } if( uquit == QUIT_DIED || uquit == QUIT_WATCH ) { @@ -14009,3 +14009,8 @@ global_variables &get_globals() { return g->global_variables_instance; } + +bool are_we_quitting() +{ + return g && ( g->uquit == QUIT_EXIT || g->uquit == QUIT_EXIT_PENDING ); +} diff --git a/src/game.h b/src/game.h index 54af2ea866a01..ddd7078c9a681 100644 --- a/src/game.h +++ b/src/game.h @@ -1347,4 +1347,6 @@ namespace cata_event_dispatch void avatar_moves( const tripoint &old_abs_pos, const avatar &u, const map &m ); } // namespace cata_event_dispatch +bool are_we_quitting(); + #endif // CATA_SRC_GAME_H diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 555153e8751b2..27fefdaf1e496 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -334,7 +334,7 @@ input_context game::get_player_input( std::string &action ) creature_tracker &creatures = get_creature_tracker(); do { - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { break; } if( bWeatherEffect && get_option( "ANIMATION_RAIN" ) ) { @@ -3118,7 +3118,7 @@ bool game::handle_action() // of location clicked. std::optional mouse_target; - if( uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return false; } diff --git a/src/input_context.cpp b/src/input_context.cpp index 3bf40e2704bae..ca46cf9f47f71 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -447,6 +447,7 @@ const std::string &input_context::handle_input( const int timeout ) } if( g->uquit == QUIT_EXIT ) { + g->uquit = QUIT_EXIT_PENDING; result = &QUIT; break; } diff --git a/src/main_menu.cpp b/src/main_menu.cpp index a539cd06a7507..4a33433a8ae4c 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -793,7 +793,7 @@ bool main_menu::opening_screen() #endif while( !start ) { - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return false; } diff --git a/src/ui.cpp b/src/ui.cpp index e2bab96796d51..81daf214fa376 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1044,7 +1044,7 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys ) ret = entries[selected].retval; } } else if( ( allow_cancel && ret_act == "UILIST.QUIT" ) || - ( g->uquit == QUIT_EXIT && ret_act == "QUIT" ) ) { + ( are_we_quitting() && ret_act == "QUIT" ) ) { ret = UILIST_CANCEL; } else if( ret_act == "TIMEOUT" ) { ret = UILIST_WAIT_INPUT;