diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-07 23:25:16 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-07 23:25:16 +0000 |
commit | 99578a522dbdc7ae3b19a6ec06c61193bcd08e65 (patch) | |
tree | 5fe01979ad2537458dd1ce059275747be311ee60 /crawl-ref/source/effects.cc | |
parent | e8a014fe9b602a577e9497ab1b3ef1dd4f50a600 (diff) | |
download | crawl-ref-99578a522dbdc7ae3b19a6ec06c61193bcd08e65.tar.gz crawl-ref-99578a522dbdc7ae3b19a6ec06c61193bcd08e65.zip |
Change floor_property (blood, sanctuary) to flags, and add two new
settings: vault and highlight.
Vault means a grid is part of a vault (set in dungeon.cc), and currently
used to exempt vault grids when shifting labyrinths.
Highlight is a meta flag currently only used to highlight labyrinth
changes on the 'X' map in wizard mode, but I can think of a couple of
other uses, mostly for debugging purposes.
Also replace a few for loops in the lab shift function with
rectangle_iterators.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7414 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/effects.cc')
-rw-r--r-- | crawl-ref/source/effects.cc | 191 |
1 files changed, 105 insertions, 86 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index d0002e8f22..c4666583f4 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -2409,47 +2409,46 @@ void change_labyrinth(bool msg) int size = random_range(12, 24); // size of the shifted area (square) coord_def c1, c2; // upper left, lower right corners of the shifted area + std::vector<coord_def> targets; + // Try 10 times for an area that is little mapped. for (int tries = 10; tries > 0; tries--) { + targets.clear(); + int x = random_range(LABYRINTH_BORDER, GXM - LABYRINTH_BORDER - size); int y = random_range(LABYRINTH_BORDER, GYM - LABYRINTH_BORDER - size); c1 = coord_def(x,y); c2 = coord_def(x + size, y + size); int count_known = 0; - for (int xi = c1.x; xi <= c2.x; xi++) - for (int yi = c1.y; yi <= c2.y; yi++) - { - if (is_terrain_seen(xi, yi)) - count_known++; - } - - if (count_known < size*size/6) - break; - } + for (rectangle_iterator ri(c1, c2); ri; ++ri) + if (is_terrain_seen(*ri)) + count_known++; - if (msg) - { - mprf(MSGCH_DIAGNOSTICS, "Changing labyrinth from (%d, %d) to (%d, %d)", - c1.x, c1.y, c2.x, c2.y); - } + if (tries > 1 && count_known > size*size/6) + continue; - // Fill a vector with wall grids that are potential targets for swapping - // against floor, i.e. are flanked by walls to two cardinal directions, - // and by floor on the two remaining sides. - std::vector<coord_def> targets; - for (int xi = c1.x; xi <= c2.x; xi++) - for (int yi = c1.y; yi <= c2.y; yi++) + // Fill a vector with wall grids that are potential targets for + // swapping against floor, i.e. are flanked by walls to two cardinal + // directions, and by floor on the two remaining sides. + for (rectangle_iterator ri(c1, c2); ri; ++ri) { - const coord_def c(xi, yi); - if (is_terrain_seen(xi, yi) || !grid_is_wall(grd(c))) + if (is_terrain_seen(*ri) || !grid_is_wall(grd(*ri))) continue; - if (_grid_is_flanked_by_walls(c) && _deadend_check_floor(c)) - targets.push_back(c); + // Skip on grids inside vaults so as not to disrupt them. + if (testbits(env.map(*ri).property, FPROP_VAULT)) + continue; + + if (_grid_is_flanked_by_walls(*ri) && _deadend_check_floor(*ri)) + targets.push_back(*ri); } + if (targets.size() >= 8) + break; + } + if (targets.empty()) { if (msg) @@ -2459,6 +2458,12 @@ void change_labyrinth(bool msg) if (msg) { + mprf(MSGCH_DIAGNOSTICS, "Changing labyrinth from (%d, %d) to (%d, %d)", + c1.x, c1.y, c2.x, c2.y); + } + + if (msg) + { std::string path_str = ""; mpr("Here's the list of targets: ", MSGCH_DIAGNOSTICS); for (unsigned int i = 0; i < targets.size(); i++) @@ -2470,6 +2475,10 @@ void change_labyrinth(bool msg) mprf(MSGCH_DIAGNOSTICS, "-> #targets = %d", targets.size()); } + for (rectangle_iterator ri(1); ri; ++ri) + env.map(*ri).property &= ~(FPROP_HIGHLIGHT); + + // How many switches we'll be doing. const int max_targets = random_range(std::min((int) targets.size(), 12), std::min((int) targets.size(), 45)); @@ -2562,6 +2571,8 @@ void change_labyrinth(bool msg) mprf(MSGCH_DIAGNOSTICS, "Switch %d (%d, %d) with %d (%d, %d).", (int) old_grid, c.x, c.y, (int) grd(p), p.x, p.y); } + env.map(c).property |= FPROP_HIGHLIGHT; + env.map(p).property |= FPROP_HIGHLIGHT; // Rather than use old_grid directly, replace with the adjacent // wall type. @@ -2578,6 +2589,16 @@ void change_labyrinth(bool msg) } old_grid = DNGN_STONE_WALL; } + else if (old_grid != DNGN_ROCK_WALL && old_grid != DNGN_STONE_WALL + && old_grid != DNGN_METAL_WALL) + { + old_grid = grd[p.x][p.y+1]; + } + } + else if (old_grid != DNGN_ROCK_WALL && old_grid != DNGN_STONE_WALL + && old_grid != DNGN_METAL_WALL) + { + old_grid = grd[p.x+1][p.y]; } grd(p) = old_grid; } @@ -2597,59 +2618,57 @@ void change_labyrinth(bool msg) // Search the entire shifted area for stacks of items now stuck in walls // and move them to a random adjacent non-wall grid. - for (int xi = c1.x; xi <= c2.x; xi++) - for (int yi = c1.y; yi <= c2.y; yi++) + for (rectangle_iterator ri(c1, c2); ri; ++ri) + { + if (!grid_is_wall(grd(*ri)) || igrd(*ri) == NON_ITEM) + continue; + + if (msg) + { + mprf(MSGCH_DIAGNOSTICS, + "Need to move around some items at pos (%d, %d)...", + ri->x, ri->y); + } + // Search the eight possible directions in random order. + std::random_shuffle(dirs.begin(), dirs.end(), random2); + for (unsigned int i = 0; i < dirs.size(); i++) { - const coord_def c(xi, yi); - if (!grid_is_wall(grd(c)) || igrd(c) == NON_ITEM) + const coord_def p = *ri + dirs[i]; + if (!in_bounds(p)) continue; - if (msg) + if (_is_floor(grd(p))) { - mprf(MSGCH_DIAGNOSTICS, - "Need to move around some items at pos (%d, %d)...", - xi, yi); - } - // Search the eight possible directions in random order. - std::random_shuffle(dirs.begin(), dirs.end(), random2); - for (unsigned int i = 0; i < dirs.size(); i++) - { - const coord_def p = c + dirs[i]; - if (!in_bounds(p)) - continue; - - if (_is_floor(grd(p))) + // Once a valid grid is found, move all items from the + // stack onto it. + int it = igrd(*ri); + while (it != NON_ITEM) { - // Once a valid grid is found, move all items from the - // stack onto it. - int it = igrd(c); - while (it != NON_ITEM) + mitm[it].pos.x = p.x; + mitm[it].pos.y = p.y; + if (mitm[it].link == NON_ITEM) { - mitm[it].pos.x = p.x; - mitm[it].pos.y = p.y; - if (mitm[it].link == NON_ITEM) - { - // Link to the stack on the target grid p, - // or NON_ITEM, if empty. - mitm[it].link = igrd(p); - break; - } - it = mitm[it].link; + // Link to the stack on the target grid p, + // or NON_ITEM, if empty. + mitm[it].link = igrd(p); + break; } + it = mitm[it].link; + } - // Move entire stack over to p. - igrd(p) = igrd(c); - igrd(c) = NON_ITEM; + // Move entire stack over to p. + igrd(p) = igrd(*ri); + igrd(*ri) = NON_ITEM; - if (msg) - { - mprf(MSGCH_DIAGNOSTICS, "Moved items over to (%d, %d)", - p.x, p.y); - } - break; + if (msg) + { + mprf(MSGCH_DIAGNOSTICS, "Moved items over to (%d, %d)", + p.x, p.y); } + break; } } + } // Recheck item coordinates, to make totally sure. fix_item_coordinates(); @@ -3318,35 +3337,35 @@ void update_level(double elapsedTime) static void _maybe_restart_fountain_flow(const coord_def& where, const int tries) { - dungeon_feature_type grid = grd(where); + dungeon_feature_type grid = grd(where); - if (grid < DNGN_DRY_FOUNTAIN_BLUE || grid > DNGN_DRY_FOUNTAIN_BLOOD) - return; + if (grid < DNGN_DRY_FOUNTAIN_BLUE || grid > DNGN_DRY_FOUNTAIN_BLOOD) + return; - for ( int i = 0; i < tries; ++i ) - { - if (!one_chance_in(100)) - continue; + for (int i = 0; i < tries; ++i) + { + if (!one_chance_in(100)) + continue; - // Make it start flowing again. - grd(where) = static_cast<dungeon_feature_type> (grid + // Make it start flowing again. + grd(where) = static_cast<dungeon_feature_type> (grid - (DNGN_DRY_FOUNTAIN_BLUE - DNGN_FOUNTAIN_BLUE)); - if (is_terrain_seen(where)) - set_envmap_obj(where, grd(where)); + if (is_terrain_seen(where)) + set_envmap_obj(where, grd(where)); - // Clean bloody floor. - if (is_bloodcovered(where)) - env.map(where).property = FPROP_NONE; + // Clean bloody floor. + if (is_bloodcovered(where)) + env.map(where).property &= ~(FPROP_BLOODY); - // Chance of cleaning adjacent squares. - for ( adjacent_iterator ai(where); ai; ++ai ) - if (is_bloodcovered(*ai) && one_chance_in(5)) - env.map(*ai).property = FPROP_NONE; + // Chance of cleaning adjacent squares. + for (adjacent_iterator ai(where); ai; ++ai) + if (is_bloodcovered(*ai) && one_chance_in(5)) + env.map(*ai).property &= ~(FPROP_BLOODY); - break; - } + break; + } } //--------------------------------------------------------------- |