summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 23:16:54 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 23:16:54 +0000
commitaefd04b12411ec9df4189696e375ebc2fc70572b (patch)
tree90fc90f9cba046b8288aa41d1d32ae772bc5010d
parent78b76a58e74a787481db68b1fabc7e978d21ca1b (diff)
downloadcrawl-ref-aefd04b12411ec9df4189696e375ebc2fc70572b.tar.gz
crawl-ref-aefd04b12411ec9df4189696e375ebc2fc70572b.zip
Bug 1902361: don't assert if something goes wrong with the book-keeping in
PlaceInfo. Instead, give a diagnostic message about the problem, and fix the problem so that the user doesn't get spammed with messages. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6675 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/externs.h4
-rw-r--r--crawl-ref/source/player.cc62
2 files changed, 54 insertions, 12 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 66c056c8a6..fdd48acfbb 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -530,7 +530,9 @@ public:
bool is_global() const;
void make_global();
- void assert_validity() const;
+ // Not const since it now tries to patch up problems instead of
+ // merely asserting.
+ void assert_validity();
const std::string short_name() const;
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 53641b7d8b..2f3ab09187 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -6765,7 +6765,7 @@ void PlaceInfo::make_global()
branch = -1;
}
-void PlaceInfo::assert_validity() const
+void PlaceInfo::assert_validity()
{
// Check that level_type and branch match up.
ASSERT(is_global()
@@ -6774,24 +6774,64 @@ void PlaceInfo::assert_validity() const
|| level_type > LEVEL_DUNGEON && level_type < NUM_LEVEL_AREA_TYPES
&& branch == -1);
+#if DEBUG
// Can't have visited a place without seeing any of its levels, and
// vice versa.
- ASSERT(num_visits == 0 && levels_seen == 0
- || num_visits > 0 && levels_seen > 0);
+ if(!(num_visits == 0 && levels_seen == 0
+ || num_visits > 0 && levels_seen > 0))
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: num_vists/levels_seen mismatch");
+ num_visits = std::max((unsigned long) 1, num_visits);
+ levels_seen = std::max((unsigned long) 1, levels_seen);
+ }
if (level_type == LEVEL_LABYRINTH || level_type == LEVEL_ABYSS)
- ASSERT(num_visits == levels_seen);
+ {
+ if (num_visits != levels_seen)
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: num_visits and levels_seen "
+ "not identical for labyrinth or abyss");
+ num_visits = std::max(num_visits, levels_seen);
+ levels_seen = std::max(num_visits, levels_seen);
+ }
+ }
else if (level_type == LEVEL_PANDEMONIUM)
- ASSERT(num_visits <= levels_seen);
+ {
+ if (num_visits > levels_seen)
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: Pandemonium visited more "
+ "times than the number of its levels that have been seen.");
+ num_visits = levels_seen;
+ }
+ }
else if (level_type == LEVEL_DUNGEON && branches[branch].depth > 0)
- ASSERT(levels_seen <= (unsigned long) branches[branch].depth);
+ {
+ if(levels_seen > (unsigned long) branches[branch].depth)
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: more levels of branch seen "
+ "than the branch actually has.");
+ levels_seen = branches[branch].depth;
+ }
+ }
- ASSERT(turns_total == (turns_explore + turns_travel + turns_interlevel
- + turns_resting + turns_other));
+ if(turns_total != (turns_explore + turns_travel + turns_interlevel
+ + turns_resting + turns_other))
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: turns breakdown doesn't sum "
+ "up properly.");
+ turns_total = (turns_explore + turns_travel + turns_interlevel
+ + turns_resting + turns_other);
+ }
- ASSERT(elapsed_total == (elapsed_explore + elapsed_travel
- + elapsed_interlevel + elapsed_resting
- + elapsed_other));
+ if(elapsed_total != (elapsed_explore + elapsed_travel + elapsed_interlevel
+ + elapsed_resting + elapsed_other))
+ {
+ mprf(MSGCH_DIAGNOSTICS, "PlaceInfo: elapsed time breakdown doesn't "
+ "sum up properly.");
+ elapsed_total = (elapsed_explore + elapsed_travel + elapsed_interlevel
+ + elapsed_resting + elapsed_other);
+ }
+#endif
}
const std::string PlaceInfo::short_name() const