From c9bda0d87efaabba61def8217432a2d6b61836a8 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Thu, 12 Nov 2009 22:17:01 +0100 Subject: Extract and move file deletion on game end. This should prevent problems with the morgue dump from making a game unlosable, fixing 2782923. Note that the other problem in that bug report (crash of mons_type_name on invalid monster type) has already been fixed. --- crawl-ref/source/ouch.cc | 60 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'crawl-ref/source/ouch.cc') diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc index 5b6cf0a010..b3912a3e1f 100644 --- a/crawl-ref/source/ouch.cc +++ b/crawl-ref/source/ouch.cc @@ -1218,34 +1218,9 @@ static std::string morgue_name(time_t when_crawl_got_even) #endif // SHORT_FILE_NAMES } -void end_game( scorefile_entry &se ) +// Delete save files on game end. +static void delete_files() { - bool dead = true; - - for (int i = 0; i < ENDOFPACK; i++) - set_ident_flags( you.inv[i], ISFLAG_IDENT_MASK ); - - for (int i = 0; i < ENDOFPACK; i++) - { - if (you.inv[i].base_type != 0) - set_ident_type( you.inv[i], ID_KNOWN_TYPE ); - } - - if (!dump_char( morgue_name(se.death_time), !dead, true, &se )) - { - mpr("Char dump unsuccessful! Sorry about that."); - if (!crawl_state.seen_hups) - more(); - clrscr(); - } - - if (se.death_type == KILLED_BY_LEAVING - || se.death_type == KILLED_BY_QUITTING - || se.death_type == KILLED_BY_WINNING) - { - dead = false; - } - // clean all levels that we think we have ever visited for (level_id_set::const_iterator i = Generated_Levels.begin(); i != Generated_Levels.end(); ++i) @@ -1289,6 +1264,37 @@ void end_game( scorefile_entry &se ) std::string tmpname = basename + suffixes[i]; unlink( tmpname.c_str() ); } +} + +void end_game(scorefile_entry &se) +{ + bool dead = true; + + for (int i = 0; i < ENDOFPACK; i++) + set_ident_flags( you.inv[i], ISFLAG_IDENT_MASK ); + + for (int i = 0; i < ENDOFPACK; i++) + { + if (you.inv[i].base_type != 0) + set_ident_type( you.inv[i], ID_KNOWN_TYPE ); + } + + delete_files(); + + if (!dump_char( morgue_name(se.death_time), !dead, true, &se )) + { + mpr("Char dump unsuccessful! Sorry about that."); + if (!crawl_state.seen_hups) + more(); + clrscr(); + } + + if (se.death_type == KILLED_BY_LEAVING + || se.death_type == KILLED_BY_QUITTING + || se.death_type == KILLED_BY_WINNING) + { + dead = false; + } // death message if (dead) -- cgit v1.2.3-54-g00ecf