summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/view.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-10-06 14:32:58 +0200
committerAdam Borowski <kilobyte@angband.pl>2013-10-06 15:30:04 +0200
commitf844dbe31ff14cbd33b343a11a2c6587d80f79ef (patch)
treeb85b2479be266f4ee557bc8da8d8de4be2ef3cee /crawl-ref/source/view.cc
parent8b63c98e9b2e4cbb547b63ce0ae49d255280212d (diff)
downloadcrawl-ref-f844dbe31ff14cbd33b343a11a2c6587d80f79ef.tar.gz
crawl-ref-f844dbe31ff14cbd33b343a11a2c6587d80f79ef.zip
Use a hash rather than the RNG for deterministic passive mapping. Refactor.
Diffstat (limited to 'crawl-ref/source/view.cc')
-rw-r--r--crawl-ref/source/view.cc26
1 files changed, 13 insertions, 13 deletions
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 521e37a5bd..a25907df7d 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -380,26 +380,26 @@ static const FixedArray<uint8_t, GXM, GYM>& _tile_difficulties(bool random)
static FixedArray<uint8_t, GXM, GYM> cache;
static int cache_seed = -1;
- int seed = random ? -1 :
- (static_cast<int>(you.where_are_you) << 8) + you.depth - 1731813538;
-
- if (seed == cache_seed && !random)
- return cache;
-
- if (!random)
+ if (random)
{
- push_rng_state();
- seed_rng(cache_seed);
+ cache_seed = -1;
+ for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
+ for (int x = X_BOUND_1; x <= X_BOUND_2; ++x)
+ cache[x][y] = random2(100);
+ return cache;
}
+ // must not produce the magic value (-1)
+ int seed = (static_cast<int>(you.where_are_you) << 8) + you.depth;
+
+ if (seed == cache_seed)
+ return cache;
+
cache_seed = seed;
for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
for (int x = X_BOUND_1; x <= X_BOUND_2; ++x)
- cache[x][y] = random2(100);
-
- if (!random)
- pop_rng_state();
+ cache[x][y] = hash_rand(100, seed, y * GXM + x);
return cache;
}