summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-23 20:32:37 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-23 20:32:37 +0000
commit6f00e679d1f90041599c50c3cc86ab4e499c9ba1 (patch)
tree2e1ceeed3d328f639166d0ca53dddbd6fba6cdcf /crawl-ref
parent0b1e914465f3e3f1f4c73f63cf2346c3f2253861 (diff)
downloadcrawl-ref-6f00e679d1f90041599c50c3cc86ab4e499c9ba1.tar.gz
crawl-ref-6f00e679d1f90041599c50c3cc86ab4e499c9ba1.zip
More cleanups and fixes.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6648 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/abl-show.cc6
-rw-r--r--crawl-ref/source/abyss.cc366
-rw-r--r--crawl-ref/source/acr.cc49
-rw-r--r--crawl-ref/source/cloud.cc15
-rw-r--r--crawl-ref/source/debug.cc39
-rw-r--r--crawl-ref/source/decks.cc63
-rw-r--r--crawl-ref/source/delay.cc39
-rw-r--r--crawl-ref/source/directn.cc14
-rw-r--r--crawl-ref/source/effects.cc35
-rw-r--r--crawl-ref/source/files.cc31
-rw-r--r--crawl-ref/source/it_use3.cc2
-rw-r--r--crawl-ref/source/item_use.cc19
-rw-r--r--crawl-ref/source/items.cc8
-rw-r--r--crawl-ref/source/items.h2
-rw-r--r--crawl-ref/source/message.cc2
-rw-r--r--crawl-ref/source/misc.cc19
-rw-r--r--crawl-ref/source/mon-util.cc2
-rw-r--r--crawl-ref/source/monspeak.cc6
-rw-r--r--crawl-ref/source/monstuff.cc4
-rw-r--r--crawl-ref/source/mstuff2.cc10
-rw-r--r--crawl-ref/source/player.cc5
-rw-r--r--crawl-ref/source/religion.cc4
-rw-r--r--crawl-ref/source/spells1.cc14
-rw-r--r--crawl-ref/source/spells3.cc6
-rw-r--r--crawl-ref/source/spells4.cc4
-rw-r--r--crawl-ref/source/spl-cast.cc24
-rw-r--r--crawl-ref/source/stuff.cc76
-rw-r--r--crawl-ref/source/stuff.h30
-rw-r--r--crawl-ref/source/traps.cc2
-rw-r--r--crawl-ref/source/view.cc4
30 files changed, 437 insertions, 463 deletions
diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index f0e01f7ed8..858e5ceed9 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -1738,7 +1738,7 @@ static bool _do_ability(const ability_def& abil)
if (!spell_direction(spd, beam, DIR_NONE, TARG_ENEMY))
return (false);
- if (beam.target_x == you.x_pos && beam.target_y == you.y_pos)
+ if (beam.target() == you.pos())
{
mpr("You cannot banish yourself!");
return (false);
@@ -2159,7 +2159,7 @@ std::vector<talent> your_talents( bool check_confused )
// Gods take abilities away until penance completed. -- bwr
// God abilities generally don't work while silenced (they require
// invoking the god), but Nemelex is an exception.
- if (!player_under_penance() && (!silenced(you.x_pos, you.y_pos)
+ if (!player_under_penance() && (!silenced(you.pos())
|| you.religion == GOD_NEMELEX_XOBEH))
{
for (int i = 0; i < MAX_GOD_ABILITIES; ++i)
@@ -2174,7 +2174,7 @@ std::vector<talent> your_talents( bool check_confused )
}
// And finally, the ability to opt-out of your faith {dlb}:
- if (you.religion != GOD_NO_GOD && !silenced( you.x_pos, you.y_pos ))
+ if (you.religion != GOD_NO_GOD && !silenced( you.pos() ))
_add_talent(talents, ABIL_RENOUNCE_RELIGION, check_confused );
//jmf: Check for breath weapons -- they're exclusive of each other, I hope!
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc
index b7af7c07a2..0b497f6cc0 100644
--- a/crawl-ref/source/abyss.cc
+++ b/crawl-ref/source/abyss.cc
@@ -42,6 +42,8 @@
#include "view.h"
#include "xom.h"
+const coord_def abyss_center(45,35);
+
// If not_seen is true, don't place the feature where it can be seen from
// the centre.
static bool _place_feature_near( const coord_def &centre,
@@ -82,25 +84,23 @@ static bool _place_feature_near( const coord_def &centre,
// Public for abyss generation.
void generate_abyss()
{
- int i, j; // loop variables
- int temp_rand; // probability determination {dlb}
-
#ifdef DEBUG_ABYSS
mprf(MSGCH_DIAGNOSTICS,
"generate_abyss(); turn_on_level: %d", env.turns_on_level);
#endif
- for (i = 5; i < (GXM - 5); i++)
- for (j = 5; j < (GYM - 5); j++)
- {
- temp_rand = random2(4000);
+ for ( rectangle_iterator ri(5); ri; ++ri )
+ {
+ grd(*ri) =
+ static_cast<dungeon_feature_type>(
+ random_choose_weighted(3000, DNGN_FLOOR,
+ 600, DNGN_ROCK_WALL,
+ 300, DNGN_STONE_WALL,
+ 100, DNGN_METAL_WALL,
+ 1, DNGN_CLOSED_DOOR,
+ 0));
+ }
- grd[i][j] = ((temp_rand > 999) ? DNGN_FLOOR : // 75.0%
- (temp_rand > 400) ? DNGN_ROCK_WALL : // 15.0%
- (temp_rand > 100) ? DNGN_STONE_WALL : // 7.5%
- (temp_rand > 0) ? DNGN_METAL_WALL // 2.5%
- : DNGN_CLOSED_DOOR); // 1 in 4000
- }
// If we're starting out in the Abyss, make sure the starting grid is
// an altar to Lugonu and there's an exit near-by.
@@ -108,16 +108,16 @@ void generate_abyss()
// altar near-by.
if (you.char_direction == GDT_GAME_START)
{
- grd[45][35] = DNGN_ALTAR_LUGONU;
- _place_feature_near( coord_def(45, 35), LOS_RADIUS + 2,
+ grd(abyss_center) = DNGN_ALTAR_LUGONU;
+ _place_feature_near( abyss_center, LOS_RADIUS + 2,
DNGN_FLOOR, DNGN_EXIT_ABYSS, 50, true );
}
else
{
- grd[45][35] = DNGN_FLOOR;
+ grd(abyss_center) = DNGN_FLOOR;
if (one_chance_in(5))
{
- _place_feature_near( coord_def(45, 35), LOS_RADIUS,
+ _place_feature_near( abyss_center, LOS_RADIUS,
DNGN_FLOOR, DNGN_ALTAR_LUGONU, 50 );
}
}
@@ -155,8 +155,8 @@ static int _abyssal_rune_roll()
return (odds);
}
-static void _generate_area(int gx1, int gy1, int gx2, int gy2,
- bool spatter = false)
+static void _generate_area(const coord_def& topleft,
+ const coord_def& bottomright, bool spatter = false)
{
// Any rune on the floor prevents the abyssal rune from being generated.
bool placed_abyssal_rune =
@@ -173,7 +173,7 @@ static void _generate_area(int gx1, int gy1, int gx2, int gy2,
const int thickness = random2(70) + 30;
int thing_created;
- FixedVector<dungeon_feature_type, 5> replaced;
+ dungeon_feature_type replaced[5];
// Nuke map.
env.map.init(map_cell());
@@ -194,33 +194,29 @@ static void _generate_area(int gx1, int gy1, int gx2, int gy2,
if (one_chance_in(3))
{
+ // Place some number of rooms.
int rooms_to_do = 1 + random2(10);
- for (int rooms_done = 0; rooms_done < rooms_to_do; ++rooms_done)
+ for (int i = 0; i < rooms_to_do; ++i)
{
- const int x1 = 10 + random2(GXM - 20);
- const int y1 = 10 + random2(GYM - 20);
- const int x2 = x1 + 1 + random2(10);
- const int y2 = y1 + 1 + random2(10);
+ // Pick the corners
+ coord_def tl( 10 + random2(GXM - 20), 10 + random2(GYM - 20) );
+ coord_def br( tl.x + 1 + random2(10), tl.y + 1 + random2(10) );
if (one_chance_in(100))
break;
bool room_ok = true;
- for (int i = x1; room_ok && i < x2; i++)
- for (int j = y1; room_ok && j < y2; j++)
- {
- if (grd[i][j] != DNGN_UNSEEN)
- room_ok = false;
- }
+ // Check if the room is taken.
+ for ( rectangle_iterator ri(tl, br); ri && room_ok; ++ri )
+ if (grd(*ri) != DNGN_UNSEEN)
+ room_ok = false;
+ // Make the room.
if (room_ok)
- {
- for (int i = x1; i < x2; i++)
- for (int j = y1; j < y2; j++)
- grd[i][j] = DNGN_FLOOR;
- }
+ for ( rectangle_iterator ri(tl,br); ri; ++ri )
+ grd(*ri) = DNGN_FLOOR;
}
}
@@ -233,92 +229,90 @@ static void _generate_area(int gx1, int gy1, int gx2, int gy2,
items_level = 0;
}
- for (int i = gx1; i <= gx2; i++)
- for (int j = gy1; j <= gy2; j++)
+ for ( rectangle_iterator ri(topleft, bottomright); ri; ++ri )
+ {
+ if (grd(*ri) == DNGN_UNSEEN && x_chance_in_y(thickness + 1, 100))
{
- if (grd[i][j] == DNGN_UNSEEN && x_chance_in_y(thickness + 1, 100))
- {
- grd[i][j] = DNGN_FLOOR;
+ grd(*ri) = DNGN_FLOOR;
- if (items_placed < num_items && one_chance_in(200))
+ if (items_placed < num_items && one_chance_in(200))
+ {
+ if (!placed_abyssal_rune && abyssal_rune_roll != -1
+ && you.char_direction != GDT_GAME_START
+ && one_chance_in(abyssal_rune_roll))
{
- if (!placed_abyssal_rune && abyssal_rune_roll != -1
- && you.char_direction != GDT_GAME_START
- && one_chance_in(abyssal_rune_roll))
- {
- thing_created = items(1, OBJ_MISCELLANY,
- MISC_RUNE_OF_ZOT, true, 51, 51);
- placed_abyssal_rune = true;
+ thing_created = items(1, OBJ_MISCELLANY,
+ MISC_RUNE_OF_ZOT, true, 51, 51);
+ placed_abyssal_rune = true;
#ifdef DEBUG_ABYSS
- mpr("Placing an Abyssal rune.", MSGCH_DIAGNOSTICS);
+ mpr("Placing an Abyssal rune.", MSGCH_DIAGNOSTICS);
#endif
- }
- else
- {
- thing_created = items(1, OBJ_RANDOM, OBJ_RANDOM,
- true, items_level, 250);
- }
+ }
+ else
+ {
+ thing_created = items(1, OBJ_RANDOM, OBJ_RANDOM,
+ true, items_level, 250);
+ }
- move_item_to_grid( &thing_created, coord_def(i, j) );
+ move_item_to_grid( &thing_created, *ri );
- if (thing_created != NON_ITEM)
- items_placed++;
- }
+ if (thing_created != NON_ITEM)
+ items_placed++;
}
}
+ }
int exits_wanted = 0;
int altars_wanted = 0;
- for (int i = gx1; i <= gx2; i++)
- for (int j = gy1; j <= gy2; j++)
- {
- if (grd[i][j] == DNGN_UNSEEN)
- grd[i][j] = replaced[random2(5)];
+ for ( rectangle_iterator ri(topleft, bottomright); ri; ++ri )
+ {
+ if (grd(*ri) == DNGN_UNSEEN)
+ grd(*ri) = replaced[random2(5)];
- if (one_chance_in(7500)) // place an exit
- exits_wanted++;
+ if (one_chance_in(7500)) // place an exit
+ exits_wanted++;
- // Don't place exit under items.
- if (exits_wanted > 0 && igrd[i][j] == NON_ITEM)
- {
- grd[i][j] = DNGN_EXIT_ABYSS;
- exits_wanted--;
+ // Don't place exit under items.
+ if (exits_wanted > 0 && igrd(*ri) == NON_ITEM)
+ {
+ grd(*ri) = DNGN_EXIT_ABYSS;
+ exits_wanted--;
#ifdef DEBUG_ABYSS
- mpr("Placing Abyss exit.", MSGCH_DIAGNOSTICS);
+ mpr("Placing Abyss exit.", MSGCH_DIAGNOSTICS);
#endif
- }
+ }
- // Except for the altar on the starting position, don't place
- // any altars.
- if (you.char_direction != GDT_GAME_START)
- {
- if (one_chance_in(10000)) // Place an altar.
- altars_wanted++;
+ // Except for the altar on the starting position, don't place
+ // any altars.
+ if (you.char_direction != GDT_GAME_START)
+ {
+ if (one_chance_in(10000)) // Place an altar.
+ altars_wanted++;
- // Don't place altars under items.
- if (altars_wanted > 0 && igrd[i][j] == NON_ITEM)
+ // Don't place altars under items.
+ if (altars_wanted > 0 && igrd(*ri) == NON_ITEM)
+ {
+ do
{
- do
- {
- grd[i][j] = static_cast<dungeon_feature_type>(
- DNGN_ALTAR_ZIN + random2(NUM_GODS-1) );
- }
- while (grd[i][j] == DNGN_ALTAR_ZIN
- || grd[i][j] == DNGN_ALTAR_SHINING_ONE
- || grd[i][j] == DNGN_ALTAR_ELYVILON);
-
- // Lugonu has a flat 50% chance of corrupting the altar.
- if (coinflip())
- grd[i][j] = DNGN_ALTAR_LUGONU;
-
- altars_wanted--;
+ grd(*ri) = static_cast<dungeon_feature_type>(
+ DNGN_ALTAR_ZIN + random2(NUM_GODS-1) );
+ }
+ while (grd(*ri) == DNGN_ALTAR_ZIN
+ || grd(*ri) == DNGN_ALTAR_SHINING_ONE
+ || grd(*ri) == DNGN_ALTAR_ELYVILON);
+
+ // Lugonu has a flat 50% chance of corrupting the altar.
+ if (coinflip())
+ grd(*ri) = DNGN_ALTAR_LUGONU;
+
+ altars_wanted--;
#ifdef DEBUG_ABYSS
- mpr("Placing altar.", MSGCH_DIAGNOSTICS);
+ mpr("Placing altar.", MSGCH_DIAGNOSTICS);
#endif
- }
}
}
+ }
generate_random_blood_spatter_on_level();
@@ -418,7 +412,7 @@ void area_shift(void)
//
// Also shift sanctuary center if it's close.
bool sanct_shifted = false;
- coord_def sanct_pos(0, 0);
+ coord_def sanct_pos;
FixedArray<unsigned short, LOS_DIAMETER, LOS_DIAMETER> fprops;
const coord_def los_delta(LOS_RADIUS, LOS_RADIUS);
@@ -435,21 +429,8 @@ void area_shift(void)
// If sanctuary centre is outside of preserved area then just get
// rid of it.
if (env.sanctuary_time > 0 && !sanct_shifted)
- {
remove_sanctuary(false);
- coord_def pos;
- for (pos.x = 0; pos.x < LOS_DIAMETER; pos.x++)
- for (pos.y = 0; pos.y < LOS_DIAMETER; pos.y++)
- {
- if (fprops(pos) == FPROP_SANCTUARY_1
- || fprops(pos) == FPROP_SANCTUARY_2)
- {
- fprops(pos) = FPROP_NONE;
- }
- }
- }
-
_xom_check_nearness_setup();
for (unsigned int i = 0; i < MAX_MONSTERS; i++)
@@ -464,31 +445,30 @@ void area_shift(void)
_abyss_lose_monster(m);
}
- for (int i = 5; i < (GXM - 5); i++)
- for (int j = 5; j < (GYM - 5); j++)
- {
- // Don't modify terrain by player.
- if (grid_distance(i, j, you.x_pos, you.y_pos) <= 10)
- continue;
+ for (rectangle_iterator ri(5); ri; ++ri )
+ {
+ // Don't modify terrain by player.
+ if (grid_distance(*ri, you.pos()) <= 10)
+ continue;
- // Nuke terrain otherwise.
- grd[i][j] = DNGN_UNSEEN;
+ // Nuke terrain otherwise.
+ grd(*ri) = DNGN_UNSEEN;
- // Nuke items.
+ // Nuke items.
#ifdef DEBUG_ABYSS
- if (igrd[i][j] != NON_ITEM)
- mprf(MSGCH_DIAGNOSTICS, "Nuke item stack at (%d, %d)", i, j);
+ if (igrd(*ri) != NON_ITEM)
+ mprf(MSGCH_DIAGNOSTICS, "Nuke item stack at (%d, %d)", i, j);
#endif
- lose_item_stack( i, j );
+ lose_item_stack( *ri );
- if (mgrd[i][j] != NON_MONSTER)
- _abyss_lose_monster( menv[ mgrd[i][j] ] );
- }
+ if (mgrd(*ri) != NON_MONSTER)
+ _abyss_lose_monster( menv[ mgrd(*ri) ] );
+ }
// Shift all monsters & items to new area.
for (radius_iterator ri(you.pos(), 10, true, false); ri; ++ri)
{
- const coord_def newpos = coord_def(45,35) + *ri - you.pos();
+ const coord_def newpos = abyss_center + *ri - you.pos();
// Move terrain.
grd(newpos) = grd(*ri);
@@ -518,22 +498,19 @@ void area_shift(void)
move_cloud( env.cgrid(*ri), newpos );
}
- for (unsigned int i = 0; i < MAX_CLOUDS; i++)
+ for (int i = 0; i < MAX_CLOUDS; i++)
{
if (env.cloud[i].type == CLOUD_NONE)
continue;
- if (env.cloud[i].x < 35 || env.cloud[i].x > 55
- || env.cloud[i].y < 25 || env.cloud[i].y > 45)
- {
+ if ( grid_distance(abyss_center, env.cloud[i].pos()) > 10 )
delete_cloud( i );
- }
}
- you.moveto(45, 35);
+ you.moveto(abyss_center);
- _generate_area(MAPGEN_BORDER, MAPGEN_BORDER,
- GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER, true);
+ _generate_area(coord_def(MAPGEN_BORDER, MAPGEN_BORDER),
+ coord_def(GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER), true);
_xom_check_nearness();
@@ -543,6 +520,7 @@ void area_shift(void)
if (sanct_shifted)
env.sanctuary_pos = sanct_pos + you.pos();
+ // Place some number of monsters.
mgen_data mons;
mons.level_type = LEVEL_ABYSS;
mons.proximity = PROX_AWAY_FROM_PLAYER;
@@ -566,35 +544,34 @@ void save_abyss_uniques()
}
void abyss_teleport( bool new_area )
-/**********************************/
{
_xom_check_nearness_setup();
- int x, y, i, j, k;
-
if (!new_area)
{
+ coord_def newspot;
+ bool found = false;
// Try to find a good spot within the shift zone.
- for (i = 0; i < 100; i++)
+ for (int i = 0; i < 100 && !found; i++)
{
- x = 16 + random2( GXM - 32 );
- y = 16 + random2( GYM - 32 );
+ newspot.x = 16 + random2( GXM - 32 );
+ newspot.y = 16 + random2( GYM - 32 );
- if ((grd[x][y] == DNGN_FLOOR
- || grd[x][y] == DNGN_SHALLOW_WATER)
- && mgrd[x][y] == NON_MONSTER
- && env.cgrid[x][y] == EMPTY_CLOUD)
+ if ((grd(newspot) == DNGN_FLOOR
+ || grd(newspot) == DNGN_SHALLOW_WATER)
+ && mgrd(newspot) == NON_MONSTER
+ && env.cgrid(newspot) == EMPTY_CLOUD)
{
- break;
+ found = true;
}
}
- if (i < 100)
+ if (found)
{
#ifdef DEBUG_ABYSS
mpr("Non-new area Abyss teleport.", MSGCH_DIAGNOSTICS);
#endif
- you.moveto(x, y);
+ you.moveto(newspot);
_xom_check_nearness();
return;
}
@@ -614,42 +591,41 @@ void abyss_teleport( bool new_area )
tile_init_flavor();
#endif
- for (i = 0; i < MAX_MONSTERS; ++i)
+ for (int i = 0; i < MAX_MONSTERS; ++i)
if (menv[i].alive())
_abyss_lose_monster(menv[i]);
// Orbs and fixed artefacts are marked as "lost in the abyss".
- for (k = 0; k < MAX_ITEMS; ++k)
+ for (int i = 0; i < MAX_ITEMS; ++i)
{
- if (is_valid_item( mitm[k] ))
+ if (is_valid_item( mitm[i] ))
{
- item_was_lost( mitm[k] );
- destroy_item( k );
+ item_was_lost( mitm[i] );
+ destroy_item( i );
}
}
- for (i = 0; i < MAX_CLOUDS; i++)
+ for (int i = 0; i < MAX_CLOUDS; i++)
delete_cloud( i );
- for (i = 10; i < (GXM - 9); i++)
- for (j = 10; j < (GYM - 9); j++)
- {
- grd[i][j] = DNGN_UNSEEN; // So generate_area will pick it up.
- igrd[i][j] = NON_ITEM;
- mgrd[i][j] = NON_MONSTER;
- env.cgrid[i][j] = EMPTY_CLOUD;
- }
+ for ( rectangle_iterator ri(10); ri; ++ri )
+ {
+ grd(*ri) = DNGN_UNSEEN; // So generate_area will pick it up.
+ igrd(*ri) = NON_ITEM;
+ mgrd(*ri) = NON_MONSTER;
+ env.cgrid(*ri) = EMPTY_CLOUD;
+ }
ASSERT( env.cloud_no == 0 );
- you.moveto(45, 35);
+ you.moveto(abyss_center);
- _generate_area(MAPGEN_BORDER, MAPGEN_BORDER,
- GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER, true);
+ _generate_area(coord_def(MAPGEN_BORDER, MAPGEN_BORDER),
+ coord_def(GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER), true);
_xom_check_nearness();
- grd[you.x_pos][you.y_pos] = DNGN_FLOOR;
+ grd(you.pos()) = DNGN_FLOOR;
if (one_chance_in(5))
{
_place_feature_near( you.pos(), LOS_RADIUS,
@@ -816,19 +792,9 @@ static bool _is_crowded_square(const coord_def &c)
// Returns true if the square has all opaque neighbours.
static bool _is_sealed_square(const coord_def &c)
{
- for (int xi = -1; xi <= 1; ++xi)
- for (int yi = -1; yi <= 1; ++yi)
- {
- if (!xi && !yi)
- continue;
-
- const coord_def n(c.x + xi, c.y + yi);
- if (!in_bounds(n))
- continue;
-
- if (!grid_is_opaque(grd(n)))
- return (false);
- }
+ for (adjacent_iterator ai(c); ai; ++ai)
+ if ( !grid_is_opaque(grd(c)) )
+ return (false);
return (true);
}
@@ -874,12 +840,12 @@ static void _corrupt_square(const crawl_environment &oenv, const coord_def &c)
#ifdef USE_TILE
if (feat == DNGN_ROCK_WALL)
{
- env.tile_flv[c.x][c.y].wall = tile_DNGN_start[IDX_WALL_UNDEAD]
+ env.tile_flv(c).wall = tile_DNGN_start[IDX_WALL_UNDEAD]
+ random2(tile_DNGN_count[IDX_WALL_UNDEAD]);
}
else if (feat == DNGN_FLOOR)
{
- env.tile_flv[c.x][c.y].floor = tile_DNGN_start[IDX_FLOOR_NERVES]
+ env.tile_flv(c).floor = tile_DNGN_start[IDX_FLOOR_NERVES]
+ random2(tile_DNGN_count[IDX_FLOOR_NERVES]);
}
#endif
@@ -893,25 +859,23 @@ static void _corrupt_level_features(const crawl_environment &oenv)
for (int i = 0, size = corrupt_markers.size(); i < size; ++i)
corrupt_seeds.push_back(corrupt_markers[i]->pos);
-
- for (int y = MAPGEN_BORDER; y < GYM - MAPGEN_BORDER; ++y)
- for (int x = MAPGEN_BORDER; x < GXM - MAPGEN_BORDER; ++x)
+
+ for ( rectangle_iterator ri(MAPGEN_BORDER); ri; ++ri )
+ {
+ int distance = GXM * GXM + GYM * GYM;
+ for (int i = 0, size = corrupt_seeds.size(); i < size; ++i)
{
- const coord_def c(x, y);
- int distance = GXM * GXM + GYM * GYM;
- for (int i = 0, size = corrupt_seeds.size(); i < size; ++i)
- {
- const int dist = (c - corrupt_seeds[i]).rdist();
- if (dist < distance)
- distance = dist;
- }
-
- if ((distance < 6 || one_chance_in(1 + distance - 6))
- && _is_grid_corruptible(c))
- {
- _corrupt_square(oenv, c);
- }
+ const int dist = (*ri - corrupt_seeds[i]).rdist();
+ if (dist < distance)
+ distance = dist;
}
+
+ if ((distance < 6 || one_chance_in(1 + distance - 6))
+ && _is_grid_corruptible(*ri))
+ {
+ _corrupt_square(oenv, *ri);
+ }
+ }
}
static bool _is_level_corrupted()
@@ -971,8 +935,8 @@ bool lugonu_corrupt_level(int power)
std::auto_ptr<crawl_environment> backup(new crawl_environment(env));
generate_abyss();
- _generate_area(MAPGEN_BORDER, MAPGEN_BORDER,
- GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER, false);
+ _generate_area(coord_def(MAPGEN_BORDER, MAPGEN_BORDER),
+ coord_def(GXM - MAPGEN_BORDER, GYM - MAPGEN_BORDER), false);
_corrupt_choose_colours();
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 593bb26375..52baa4b73d 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -822,7 +822,7 @@ static void _handle_wizard_command( void )
break;
case 'p':
- grd[you.x_pos][you.y_pos] = DNGN_ENTER_PANDEMONIUM;
+ grd(you.pos()) = DNGN_ENTER_PANDEMONIUM;
break;
case 'P':
@@ -849,7 +849,7 @@ static void _handle_wizard_command( void )
break;
}
- grd[you.x_pos][you.y_pos] = DNGN_ENTER_PORTAL_VAULT;
+ grd(you.pos()) = DNGN_ENTER_PORTAL_VAULT;
map_wiz_props_marker *marker = new map_wiz_props_marker(you.pos());
marker->set_property("dst", dst);
marker->set_property("desc", "wizard portal, dest = " + dst);
@@ -858,7 +858,7 @@ static void _handle_wizard_command( void )
}
case 'l':
- grd[you.x_pos][you.y_pos] = DNGN_ENTER_LABYRINTH;
+ grd(you.pos()) = DNGN_ENTER_LABYRINTH;
break;
case 'L':
@@ -939,11 +939,9 @@ static void _handle_wizard_command( void )
get_input_line( specs, sizeof( specs ) );
if (specs[0] != '\0')
- {
if (const int feat = atoi(specs))
- grd[you.x_pos][you.y_pos] =
- static_cast<dungeon_feature_type>( feat );
- }
+ grd(you.pos()) = static_cast<dungeon_feature_type>( feat );
+
break;
case ')':
@@ -3101,7 +3099,7 @@ static void _world_reacts()
you_teleport_now( false, true ); // to new area of the Abyss
}
- if (env.cgrid[you.x_pos][you.y_pos] != EMPTY_CLOUD)
+ if (env.cgrid(you.pos()) != EMPTY_CLOUD)
in_a_cloud();
if (you.level_type == LEVEL_DUNGEON && you.duration[DUR_TELEPATHY])
@@ -3436,21 +3434,15 @@ static keycode_type _get_next_keycode()
static int _check_adjacent(dungeon_feature_type feat, int &dx, int &dy)
{
int num = 0;
- int _dx = 0, _dy = 0;
- for (int x = -1; x <= 1; x++)
- for (int y = -1; y <= 1; y++)
- if (grd[you.x_pos + x][you.y_pos + y] == feat)
- {
- num++;
- _dx = x;
- _dy = y;
- }
-
- if (num == 1)
+ for ( adjacent_iterator ai(you.pos(), false); ai; ++ai )
{
- dx = _dx;
- dy = _dy;
+ if ( grd(*ai) == feat )
+ {
+ num++;
+ dx = ai->x - you.x_pos;
+ dy = ai->y - you.y_pos;
+ }
}
return num;
@@ -3579,7 +3571,7 @@ static void _open_door(int move_x, int move_y, bool check_confused)
if (you.duration[DUR_BERSERKER])
{
// XXX: Better flavour for larger doors?
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
mprf("The %s%s flies open!", adj, noun);
else
{
@@ -3696,16 +3688,15 @@ static void _close_door(int door_x, int door_y)
const char *adj, *noun;
get_door_description(all_door.size(), &adj, &noun);
- const coord_def you_coord(you.x_pos, you.y_pos);
for (std::set<coord_def>::iterator i = all_door.begin();
i != all_door.end(); ++i)
{
const coord_def& dc = *i;
- if (mgrd[dc.x][dc.y] != NON_MONSTER)
+ if (mgrd(dc) != NON_MONSTER)
{
// Need to make sure that turn_is_over is set if creature is
// invisible.
- if (!player_monster_visible(&menv[mgrd[dc.x][dc.y]]))
+ if (!player_monster_visible(&menv[mgrd(dc)]))
{
mprf("Something is blocking the %sway!", noun);
you.turn_is_over = true;
@@ -3718,7 +3709,7 @@ static void _close_door(int door_x, int door_y)
return;
}
- if (igrd[dc.x][dc.y] != NON_ITEM)
+ if (igrd(dc) != NON_ITEM)
{
mprf("There's something blocking the %sway.", noun);
door_move.dx = 0;
@@ -3726,7 +3717,7 @@ static void _close_door(int door_x, int door_y)
return;
}
- if (you_coord == dc)
+ if (you.pos() == dc)
{
mprf("There's a thickheaded creature in the %sway!", noun);
return;
@@ -3737,7 +3728,7 @@ static void _close_door(int door_x, int door_y)
if (you.duration[DUR_BERSERKER])
{
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
{
mprf("You slam the %s%s shut!", adj, noun);
}
@@ -3748,7 +3739,7 @@ static void _close_door(int door_x, int door_y)
noisy(25, you.pos());
}
}
- else if (one_chance_in(skill) && !silenced(you.x_pos, you.y_pos))
+ else if (one_chance_in(skill) && !silenced(you.pos()))
{
mprf(MSGCH_SOUND, "As you close the %s%s, it creaks loudly!",
adj, noun);
diff --git a/crawl-ref/source/cloud.cc b/crawl-ref/source/cloud.cc
index b38e43525b..2e5c912bb7 100644
--- a/crawl-ref/source/cloud.cc
+++ b/crawl-ref/source/cloud.cc
@@ -85,16 +85,15 @@ static int _spread_cloud(const cloud_struct &cloud)
cloud.decay > 20? 50 :
30;
int extra_decay = 0;
- radius_iterator ri(coord_def(cloud.x, cloud.y), 1, true, false, true);
- for ( ; ri; ++ri )
+ for ( adjacent_iterator ai(cloud.pos()); ai; ++ai )
{
if (random2(100) >= spreadch)
continue;
- if (!in_bounds(*ri)
- || env.cgrid(*ri) != EMPTY_CLOUD
- || grid_is_solid(grd(*ri))
- || is_sanctuary(*ri) && !is_harmless_cloud(cloud.type))
+ if (!in_bounds(*ai)
+ || env.cgrid(*ai) != EMPTY_CLOUD
+ || grid_is_solid(grd(*ai))
+ || is_sanctuary(*ai) && !is_harmless_cloud(cloud.type))
{
continue;
}
@@ -103,7 +102,7 @@ static int _spread_cloud(const cloud_struct &cloud)
if (newdecay >= cloud.decay)
newdecay = cloud.decay - 1;
- _place_new_cloud( cloud.type, *ri, newdecay, cloud.whose,
+ _place_new_cloud( cloud.type, *ai, newdecay, cloud.whose,
cloud.spread_rate );
extra_decay += 8;
@@ -395,7 +394,7 @@ beam_type cloud2beam(cloud_type flavour)
void in_a_cloud()
{
- int cl = env.cgrid[you.x_pos][you.y_pos];
+ int cl = env.cgrid(you.pos());
int hurted = 0;
int resist;
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 0de57979bd..84c992a030 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -497,27 +497,19 @@ void wizard_create_spec_monster_name()
return;
}
- int x = you.x_pos;
- int y = you.y_pos;
-
int type = mspec.mid;
if (mons_class_is_zombified(mspec.mid))
type = mspec.monbase;
- coord_def place = find_newmons_square(type, coord_def(x, y));
+ coord_def place = find_newmons_square(type, you.pos());
if (!in_bounds(place))
{
// Try again with habitat HT_LAND.
// (Will be changed to the necessary terrain type in dgn_place_monster.)
- place = find_newmons_square(MONS_PROGRAM_BUG, coord_def(x,y));
+ place = find_newmons_square(MONS_PROGRAM_BUG, you.pos());
}
- if (in_bounds(place))
- {
- x = place.x;
- y = place.y;
- }
- else
+ if (!in_bounds(place))
{
mpr("Found no space to place monster.", MSGCH_DIAGNOSTICS);
return;
@@ -528,7 +520,8 @@ void wizard_create_spec_monster_name()
if (mons_is_unique(mspec.mid) && you.unique_creatures[mspec.mid])
you.unique_creatures[mspec.mid] = false;
- if (!dgn_place_monster(mspec, you.your_level, x, y, true, false))
+ if (!dgn_place_monster(mspec, you.your_level,
+ place.x, place.y, true, false))
{
mpr("Unable to place monster.", MSGCH_DIAGNOSTICS);
return;
@@ -537,7 +530,7 @@ void wizard_create_spec_monster_name()
// Need to set a name for the player ghost.
if (mspec.mid == MONS_PLAYER_GHOST)
{
- unsigned short mid = mgrd[x][y];
+ unsigned short mid = mgrd(place);
if (mid >= MAX_MONSTERS || menv[mid].type != MONS_PLAYER_GHOST)
{
@@ -693,7 +686,7 @@ void wizard_place_stairs( bool down )
if (stairs == DNGN_UNSEEN)
return;
- grd[you.x_pos][you.y_pos] = stairs;
+ grd(you.pos()) = stairs;
}
#endif
@@ -1988,7 +1981,7 @@ void debug_item_scan( void )
#ifdef WIZARD
static void _debug_acquirement_stats(FILE *ostat)
{
- if (grid_destroys_items(grd[you.x_pos][you.y_pos]))
+ if (grid_destroys_items(grd(you.pos())))
{
mpr("You must stand on a square which doesn't destroy items "
"in order to do this.");
@@ -2814,7 +2807,7 @@ void wizard_get_religion(void)
mpr( "That god doesn't seem to be taking followers today." );
else
{
- grd[you.x_pos][you.y_pos] =
+ grd(you.pos()) =
static_cast<dungeon_feature_type>( DNGN_ALTAR_FIRST_GOD + god - 1 );
pray();
@@ -3406,7 +3399,7 @@ void debug_make_trap()
char requested_trap[80];
int trap_slot = find_trap_slot();
trap_type trap = TRAP_UNASSIGNED;
- int gridch = grd[you.x_pos][you.y_pos];
+ int gridch = grd(you.pos());
if (trap_slot == -1)
{
@@ -3472,7 +3465,7 @@ void debug_make_trap()
void debug_make_shop()
{
char requested_shop[80];
- int gridch = grd[you.x_pos][you.y_pos];
+ int gridch = grd(you.pos());
bool have_shop_slots = false;
int new_shop_type = SHOP_UNASSIGNED;
bool representative = false;
@@ -3832,9 +3825,9 @@ void debug_make_monster_shout(monsters* mon)
if (type == 's')
{
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
mpr("You are silenced and likely won't hear any shouts.");
- else if (silenced(mon->x, mon->y))
+ else if (silenced(mon->pos()))
mpr("The monster is silenced and likely won't give any shouts.");
for (int i = 0; i < num_times; i++)
@@ -3845,14 +3838,14 @@ void debug_make_monster_shout(monsters* mon)
if (mon->invisible())
mpr("The monster is invisible and likely won't speak.");
- if (silenced(you.x_pos, you.y_pos) && !silenced(mon->x, mon->y))
+ if (silenced(you.pos()) && !silenced(mon->pos()))
{
mpr("You are silenced but the monster isn't; you will "
"probably hear/see nothing.");
}
- else if (!silenced(you.x_pos, you.y_pos) && silenced(mon->x, mon->y))
+ else if (!silenced(you.pos()) && silenced(mon->pos()))
mpr("The monster is silenced and likely won't say anything.");
- else if (silenced(you.x_pos, you.y_pos) && silenced(mon->x, mon->y))
+ else if (silenced(you.pos()) && silenced(mon->pos()))
{
mpr("Both you and the monster are silenced, so you likely "
"won't hear anything.");
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index 71bdc6fcfd..0629fc1c3d 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -1545,29 +1545,20 @@ static void _minefield_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const int radius = power_level * 2 + 2;
- for (int dx = -radius; dx <= radius; ++dx)
- for (int dy = -radius; dy <= radius; ++dy)
- {
- if (dx == 0 && dy == 0)
- continue;
-
- if (dx*dx + dy*dy > radius*radius + 1)
- continue;
-
- const int rx = you.x_pos + dx;
- const int ry = you.y_pos + dy;
- if (!in_bounds(rx, ry))
- continue;
+ for (radius_iterator ri(you.pos(), radius, false, false, false); ri; ++ri)
+ {
+ if ( *ri == you.pos() )
+ continue;
- if (grd[rx][ry] == DNGN_FLOOR && trap_at_xy(coord_def(rx,ry)) == -1
- && one_chance_in(4 - power_level))
- {
- if (you.level_type == LEVEL_ABYSS)
- grd[rx][ry] = coinflip() ? DNGN_DEEP_WATER : DNGN_LAVA;
- else
- place_specific_trap(rx, ry, TRAP_RANDOM);
- }
+ if (grd(*ri) == DNGN_FLOOR && trap_at_xy(*ri) == -1
+ && one_chance_in(4 - power_level))
+ {
+ if (you.level_type == LEVEL_ABYSS)
+ grd(*ri) = coinflip() ? DNGN_DEEP_WATER : DNGN_LAVA;
+ else
+ place_specific_trap(ri->x, ri->y, TRAP_RANDOM);
}
+ }
}
static int _drain_monsters(int x, int y, int pow, int garbage)
@@ -2193,8 +2184,7 @@ static void _sage_card(int power, deck_rarity_type rarity)
static void _create_pond(const coord_def& center, int radius, bool allow_deep)
{
- radius_iterator ri(center, radius, false);
- for ( ; ri; ++ri )
+ for ( radius_iterator ri(center, radius, false); ri; ++ri )
{
const coord_def p = *ri;
if (p != you.pos() && coinflip())
@@ -2216,8 +2206,7 @@ static void _create_pond(const coord_def& center, int radius, bool allow_deep)
static void _deepen_water(const coord_def& center, int radius)
{
- radius_iterator ri(center, radius, false);
- for ( ; ri; ++ri )
+ for ( radius_iterator ri(center, radius, false); ri; ++ri )
{
// FIXME The iteration shouldn't affect the later squares in the
// same iteration, i.e., a newly-flooded square shouldn't count
@@ -2258,8 +2247,7 @@ static void _water_card(int power, deck_rarity_type rarity)
mpr("Water floods your area!");
// Flood all visible squares.
- radius_iterator ri( you.pos(), LOS_RADIUS, false );
- for ( ; ri; ++ri )
+ for ( radius_iterator ri( you.pos(), LOS_RADIUS, false ); ri; ++ri )
{
coord_def p = *ri;
destroy_trap(p);
@@ -2311,7 +2299,7 @@ static void _dowsing_card(int power, deck_rarity_type rarity)
static bool _trowel_card(int power, deck_rarity_type rarity)
{
// Early exit: don't clobber important features.
- if (is_critical_feature(grd[you.x_pos][you.y_pos]))
+ if (is_critical_feature(grd(you.pos())))
{
mpr("The dungeon trembles momentarily.");
return (false);
@@ -2388,7 +2376,7 @@ static bool _trowel_card(int power, deck_rarity_type rarity)
DNGN_GRANITE_STATUE, DNGN_ORCISH_IDOL
};
// We leave the items on the square
- grd[pos.x][pos.y] = RANDOM_ELEMENT(statfeat);
+ grd(pos) = RANDOM_ELEMENT(statfeat);
mpr("A statue takes form beside you.");
done_stuff = true;
}
@@ -2397,13 +2385,13 @@ static bool _trowel_card(int power, deck_rarity_type rarity)
else
{
// Generate an altar.
- if (grd[you.x_pos][you.y_pos] == DNGN_FLOOR)
+ if (grd(you.pos()) == DNGN_FLOOR)
{
// Might get GOD_NO_GOD and no altar.
god_type rgod = static_cast<god_type>(random2(NUM_GODS));
- grd[you.x_pos][you.y_pos] = altar_for_god(rgod);
+ grd(you.pos()) = altar_for_god(rgod);
- if (grd[you.x_pos][you.y_pos] != DNGN_FLOOR)
+ if (grd(you.pos()) != DNGN_FLOOR)
{
done_stuff = true;
mprf("An altar to %s grows from the floor before you!",
@@ -2543,7 +2531,7 @@ static void _summon_any_monster(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
monster_type mon_chosen = NUM_MONSTERS;
- int chosen_x = 0, chosen_y = 0;
+ coord_def chosen_spot;
int num_tries;
if (power_level == 0)
@@ -2563,10 +2551,12 @@ static void _summon_any_monster(int power, deck_rarity_type rarity)
}
while (dx == 0 && dy == 0);
+ coord_def delta(dx,dy);
+
monster_type cur_try;
do
{
- cur_try = random_monster_at_grid(you.pos() + coord_def(dx,dy));
+ cur_try = random_monster_at_grid(you.pos() + delta);
}
while (mons_is_unique(cur_try));
@@ -2574,8 +2564,7 @@ static void _summon_any_monster(int power, deck_rarity_type rarity)
|| mons_power(mon_chosen) < mons_power(cur_try))
{
mon_chosen = cur_try;
- chosen_x = you.x_pos;
- chosen_y = you.y_pos;
+ chosen_spot = you.pos();
}
}
@@ -2587,7 +2576,7 @@ static void _summon_any_monster(int power, deck_rarity_type rarity)
create_monster(
mgen_data(mon_chosen,
friendly ? BEH_FRIENDLY : BEH_HOSTILE,
- 3, coord_def(chosen_x, chosen_y),
+ 3, chosen_spot,
friendly ? you.pet_target : MHITYOU));
}
diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc
index 0aec0b4f44..e4ee95d88e 100644
--- a/crawl-ref/source/delay.cc
+++ b/crawl-ref/source/delay.cc
@@ -591,38 +591,27 @@ bool is_vampire_feeding()
// Returns -1, if entire audience already affected or too dumb to understand.
int check_recital_audience()
{
- int mid;
- monsters *mons;
bool found_monsters = false;
- for (int x = you.x_pos - 8; x <= you.x_pos + 8; x++)
- for (int y = you.y_pos - 8; y <= you.y_pos + 8; y++)
- {
- if (!in_bounds(x,y) || !see_grid(x, y))
- continue;
-
- mid = mgrd[x][y];
- if (mid == NON_MONSTER)
- continue;
-
- mons = &menv[mid];
- if (!found_monsters)
- found_monsters = true;
+ for ( radius_iterator ri(you.pos(), 8); ri; ++ri )
+ {
+ if ( mgrd(*ri) == NON_MONSTER )
+ continue;
- // Can not be affected in these states.
- if (_recite_mons_useless(mons))
- continue;
+ found_monsters = true;
+ // Check if audience can listen.
+ if (!_recite_mons_useless( &menv[mgrd(*ri)] ) )
return (1);
- }
-
+ }
+
#ifdef DEBUG_DIAGNOSTICS
- if (!found_monsters)
- mprf(MSGCH_DIAGNOSTICS, "No audience found!");
- else
- mprf(MSGCH_DIAGNOSTICS, "No sensible audience found!");
+ if (!found_monsters)
+ mprf(MSGCH_DIAGNOSTICS, "No audience found!");
+ else
+ mprf(MSGCH_DIAGNOSTICS, "No sensible audience found!");
#endif
-
+
// No use preaching to the choir, nor to common animals.
if (found_monsters)
return (-1);
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index e1bf61f6e4..31ea6df734 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -667,7 +667,7 @@ void direction(dist& moves, targeting_type restricts,
}
#endif
- if (target_unshifted && moves.tx == you.x_pos && moves.ty == you.y_pos
+ if (target_unshifted && moves.target() == you.pos()
&& restricts != DIR_TARGET)
{
key_command = shift_direction(key_command);
@@ -685,7 +685,7 @@ void direction(dist& moves, targeting_type restricts,
if (key_command == CMD_TARGET_MAYBE_PREV_TARGET)
{
- if (moves.tx == you.x_pos && moves.ty == you.y_pos)
+ if (moves.target() == you.pos())
key_command = CMD_TARGET_PREV_TARGET;
else
key_command = CMD_TARGET_SELECT;
@@ -929,7 +929,7 @@ void direction(dist& moves, targeting_type restricts,
if (mid != NON_MONSTER)
you.prev_targ = mid;
- else if (moves.tx == you.x_pos && moves.ty == you.y_pos)
+ else if (moves.target() == you.pos())
you.prev_targ = MHITYOU;
else
you.prev_grd_targ = coord_def(moves.tx, moves.ty);
@@ -1105,7 +1105,7 @@ void direction(dist& moves, targeting_type restricts,
// Confirm self-targeting on TARG_ENEMY (option-controlled.)
// Conceivably we might want to confirm on TARG_ANY too.
if (moves.isTarget
- && moves.tx == you.x_pos && moves.ty == you.y_pos
+ && moves.target() == you.pos()
&& mode == TARG_ENEMY
&& (cancel_at_self
|| Options.allow_self_target == CONFIRM_CANCEL
@@ -1213,7 +1213,7 @@ void direction(dist& moves, targeting_type restricts,
}
skip_iter = false; // Only skip one iteration at most.
}
- moves.isMe = (moves.tx == you.x_pos && moves.ty == you.y_pos);
+ moves.isMe = (moves.target() == you.pos());
mesclr();
// We need this for directional explosions, otherwise they'll explode one
@@ -1866,8 +1866,8 @@ void describe_floor()
msg_channel_type channel = MSGCH_EXAMINE;
// Water is not terribly important if you don't mind it-
- if ((grd[you.x_pos][you.y_pos] == DNGN_DEEP_WATER
- || grd[you.x_pos][you.y_pos] == DNGN_SHALLOW_WATER)
+ if ((grd(you.pos()) == DNGN_DEEP_WATER
+ || grd(you.pos()) == DNGN_SHALLOW_WATER)
&& player_likes_water())
{
channel = MSGCH_EXAMINE_FILTER;
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 06f85b3318..3534df0588 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1860,7 +1860,7 @@ void yell(bool force)
else if (shout_verb == "scream")
noise_level = 16;
- if (silenced(you.x_pos, you.y_pos) || you.cannot_speak())
+ if (silenced(you.pos()) || you.cannot_speak())
noise_level = 0;
if (noise_level == 0)
@@ -2072,27 +2072,22 @@ bool vitrify_area(int radius)
if (radius < 2)
return (false);
- const int radius2 = radius * radius;
// This hinges on clear wall types having the same order as non-clear ones!
const int clear_plus = DNGN_CLEAR_ROCK_WALL - DNGN_ROCK_WALL;
bool something_happened = false;
- for (int x = X_BOUND_1; x <= X_BOUND_2; ++x)
- for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
+ for ( radius_iterator ri(you.pos(), radius, false, false); ri; ++ri )
+ {
+ const dungeon_feature_type grid = grd(*ri);
+
+ if (grid == DNGN_ROCK_WALL
+ || grid == DNGN_STONE_WALL
+ || grid == DNGN_PERMAROCK_WALL )
{
- if (distance(x,y,you.x_pos,you.y_pos) < radius2)
- {
- dungeon_feature_type grid = grd[x][y];
-
- if (grid == DNGN_ROCK_WALL
- || grid == DNGN_STONE_WALL
- || grid == DNGN_PERMAROCK_WALL )
- {
- grd[x][y]
- = static_cast<dungeon_feature_type>(grid + clear_plus);
- something_happened = true;
- }
- }
+ grd(*ri)
+ = static_cast<dungeon_feature_type>(grid + clear_plus);
+ something_happened = true;
}
+ }
return (something_happened);
}
@@ -2710,14 +2705,14 @@ static void _catchup_monster_moves(monsters *mon, int turns)
// ranged attack (missile or spell), then the monster will
// flee to gain distance if its "too close", else it will
// just shift its position rather than charge the player. -- bwr
- if (grid_distance(mon->x, mon->y, mon->target_x, mon->target_y) < 3)
+ if (grid_distance(mon->pos(), mon->target_pos()) < 3)
{
mon->behaviour = BEH_FLEE;
// If the monster is on the target square, fleeing won't work.
- if (mon->x == mon->target_x && mon->y == mon->target_y)
+ if (mon->pos() == mon->target_pos())
{
- if (you.x_pos != mon->x || you.y_pos != mon->y)
+ if (you.pos() != mon->pos())
{
// Flee from player's position if different.
mon->target_x = you.x_pos;
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 3a25835dde..f0f7c041c2 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -977,25 +977,22 @@ static bool _grab_follower_at(const coord_def &pos)
static void _grab_followers()
{
const bool can_follow = level_type_allows_followers(you.level_type);
- for (int i = you.x_pos - 1; i < you.x_pos + 2; i++)
- for (int j = you.y_pos - 1; j < you.y_pos + 2; j++)
- {
- if (i == you.x_pos && j == you.y_pos)
- continue;
- if (mgrd[i][j] == NON_MONSTER)
- continue;
+ // Handle nearby ghosts.
+ for ( adjacent_iterator ai; ai; ++ai )
+ {
+ if (mgrd(*ai) == NON_MONSTER)
+ continue;
- monsters *fmenv = &menv[mgrd[i][j]];
+ monsters *fmenv = &menv[mgrd(*ai)];
- if (fmenv->type == MONS_PLAYER_GHOST
- && fmenv->hit_points < fmenv->max_hit_points / 2)
- {
- mpr("The ghost fades into the shadows.");
- monster_teleport(fmenv, true);
- continue;
- }
+ if (fmenv->type == MONS_PLAYER_GHOST
+ && fmenv->hit_points < fmenv->max_hit_points / 2)
+ {
+ mpr("The ghost fades into the shadows.");
+ monster_teleport(fmenv, true);
}
+ }
if (can_follow)
{
@@ -1218,8 +1215,8 @@ bool load( dungeon_feature_type stair_taken, load_mode_type load_mode,
crawl_view.set_player_at(you.pos(), load_mode != LOAD_VISITOR);
// This should fix the "monster occurring under the player" bug?
- if (make_changes && mgrd[you.x_pos][you.y_pos] != NON_MONSTER)
- monster_teleport(&menv[mgrd[you.x_pos][you.y_pos]], true, true);
+ if (make_changes && mgrd(you.pos()) != NON_MONSTER)
+ monster_teleport(&menv[mgrd(you.pos())], true, true);
// Actually "move" the followers if applicable.
if (level_type_allows_followers(you.level_type)
diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc
index 4508cc3952..180922e03c 100644
--- a/crawl-ref/source/it_use3.cc
+++ b/crawl-ref/source/it_use3.cc
@@ -76,7 +76,7 @@ void special_wielded()
case SPWLD_SING:
case SPWLD_NOISE:
{
- makes_noise = (one_chance_in(20) && !silenced(you.x_pos, you.y_pos));
+ makes_noise = (one_chance_in(20) && !silenced(you.pos()));
if (makes_noise)
{
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index d34fed28a2..9e7c67f718 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -568,7 +568,7 @@ void wield_effects(int item_wield_2, bool showMsgs)
break;
case SPWPN_ELECTROCUTION:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
{
mpr("You hear the crackle of electricity.",
MSGCH_SOUND);
@@ -3503,8 +3503,7 @@ void zap_wand( int slot )
beam.source_y = you.y_pos;
beam.set_target(zap_wand);
- beam.aimed_at_feet =
- (beam.target_x == you.x_pos && beam.target_y == you.y_pos);
+ beam.aimed_at_feet = (beam.target() == you.pos());
// Check whether we may hit friends, use "safe" values for random effects
// and unknown wands (highest possible range, and unresistable beam
@@ -3610,8 +3609,8 @@ void drink( int slot )
if (slot == -1)
{
- if (grd[you.x_pos][you.y_pos] >= DNGN_FOUNTAIN_BLUE
- && grd[you.x_pos][you.y_pos] <= DNGN_FOUNTAIN_BLOOD)
+ if (grd(you.pos()) >= DNGN_FOUNTAIN_BLUE
+ && grd(you.pos()) <= DNGN_FOUNTAIN_BLOOD)
{
if (_drink_fountain())
return;
@@ -3709,7 +3708,7 @@ void drink( int slot )
bool _drink_fountain()
{
- const dungeon_feature_type feat = grd[you.x_pos][you.y_pos];
+ const dungeon_feature_type feat = grd(you.pos());
if (feat < DNGN_FOUNTAIN_BLUE || feat > DNGN_FOUNTAIN_BLOOD)
return (false);
@@ -3801,7 +3800,7 @@ bool _drink_fountain()
{
// Turn fountain into a normal fountain without any message
// but the glyph colour gives it away (lightblue vs. blue).
- grd[you.x_pos][you.y_pos] = DNGN_FOUNTAIN_BLUE;
+ grd(you.pos()) = DNGN_FOUNTAIN_BLUE;
set_terrain_changed(you.x_pos, you.y_pos);
}
}
@@ -3810,7 +3809,7 @@ bool _drink_fountain()
{
mpr("The fountain dries up!");
- grd[you.x_pos][you.y_pos] = static_cast<dungeon_feature_type>(feat
+ grd(you.pos()) = static_cast<dungeon_feature_type>(feat
+ DNGN_DRY_FOUNTAIN_BLUE - DNGN_FOUNTAIN_BLUE);
set_terrain_changed(you.x_pos, you.y_pos);
@@ -4120,7 +4119,7 @@ static void handle_read_book( int item_slot )
if (book.sub_type == BOOK_DESTRUCTION)
{
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
mpr("This book does not work if you cannot read it aloud!");
else
tome_of_power(item_slot);
@@ -4267,7 +4266,7 @@ void read_scroll( int slot )
return;
}
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
{
mpr("Magic scrolls do not work when you're silenced!");
crawl_state.zero_turns_taken();
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 9825a3dbd4..4d0d619b24 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -585,9 +585,9 @@ void item_was_destroyed(const item_def &item, int cause)
xom_check_destroyed_item( item, cause );
}
-void lose_item_stack( int x, int y )
+void lose_item_stack( const coord_def& where )
{
- for ( stack_iterator si(coord_def(x,y)); si; ++si )
+ for ( stack_iterator si(where); si; ++si )
{
if (is_valid_item( *si )) // FIXME is this check necessary?
{
@@ -595,7 +595,7 @@ void lose_item_stack( int x, int y )
si->clear();
}
}
- igrd[x][y] = NON_ITEM;
+ igrd(where) = NON_ITEM;
}
void destroy_item_stack( int x, int y, int cause )
@@ -1925,7 +1925,7 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer )
if (try_offer
&& you.religion != GOD_NO_GOD
&& you.duration[DUR_PRAYER]
- && grid_altar_god(grd[you.x_pos][you.y_pos]) == you.religion)
+ && grid_altar_god(grd(you.pos())) == you.religion)
{
offer_items();
}
diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h
index f1b8d14d3e..831e3e4430 100644
--- a/crawl-ref/source/items.h
+++ b/crawl-ref/source/items.h
@@ -75,7 +75,7 @@ void unlink_item(int dest);
void destroy_item( item_def &item, bool never_created = false );
void destroy_item(int dest, bool never_created = false);
void destroy_item_stack( int x, int y, int cause = -1 );
-void lose_item_stack( int x, int y );
+void lose_item_stack( const coord_def& where );
// last updated: 08jun2000 {dlb}
/* ***********************************************************************
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index 32360e6477..49ab2b229f 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -674,7 +674,7 @@ static void base_mpr(const char *inf, msg_channel_type channel, int param)
if (colour == MSGCOL_MUTED)
return;
- if (silenced(you.x_pos, you.y_pos)
+ if (silenced(you.pos())
&& (channel == MSGCH_SOUND || channel == MSGCH_TALK))
{
return;
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 2394fa650d..0c105aa9b3 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -1151,16 +1151,13 @@ static void maybe_bloodify_square(const coord_def& where, int amount,
if (spatter)
{
// Smaller chance of spattering surrounding squares.
- for ( radius_iterator ri(where, 1, true, false); ri; ++ri )
+ for ( adjacent_iterator ai(where); ai; ++ai )
{
- if ( *ri == where ) // current square
- continue;
-
// Spattering onto walls etc. less likely.
- if (grd(*ri) < DNGN_MINMOVE && !one_chance_in(3))
+ if (grd(*ai) < DNGN_MINMOVE && !one_chance_in(3))
continue;
- maybe_bloodify_square(*ri, amount/15);
+ maybe_bloodify_square(*ai, amount/15);
}
}
}
@@ -1181,18 +1178,18 @@ void bleed_onto_floor(const coord_def& where, int montype,
static void _spatter_neighbours(const coord_def& where, int chance)
{
- for ( radius_iterator ri(where, 1, true, false); ri; ++ri )
+ for ( adjacent_iterator ai(where, false); ai; ++ai )
{
- if (!allow_bleeding_on_square(*ri))
+ if (!allow_bleeding_on_square(*ai))
continue;
- if (grd(*ri) < DNGN_MINMOVE && !one_chance_in(3))
+ if (grd(*ai) < DNGN_MINMOVE && !one_chance_in(3))
continue;
if (one_chance_in(chance))
{
- env.map(*ri).property = FPROP_BLOODY;
- _spatter_neighbours(*ri, chance+1);
+ env.map(*ai).property = FPROP_BLOODY;
+ _spatter_neighbours(*ai, chance+1);
}
}
}
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index a1a557e002..372204f9c1 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -4386,7 +4386,7 @@ bool monsters::fumbles_attack(bool verbose)
mprf("%s splashes around in the water.",
this->name(DESC_CAP_THE).c_str());
}
- else if (!silenced(you.pos()) && !silenced(x, y))
+ else if (player_can_hear(this->pos()))
mpr("You hear a splashing noise.", MSGCH_SOUND);
}
return (true);
diff --git a/crawl-ref/source/monspeak.cc b/crawl-ref/source/monspeak.cc
index de5db2b641..d5795abeb7 100644
--- a/crawl-ref/source/monspeak.cc
+++ b/crawl-ref/source/monspeak.cc
@@ -222,7 +222,7 @@ bool mons_speaks(const monsters *monster)
// unless they're normally silent (S_SILENT). Use
// get_monster_data(monster->type) to bypass mon_shouts()
// replacing S_RANDOM with a random value.
- if (silenced(monster->x, monster->y)
+ if (silenced(monster->pos())
&& get_monster_data(monster->type)->shouts != S_SILENT)
{
if (!one_chance_in(3))
@@ -258,8 +258,8 @@ bool mons_speaks(const monsters *monster)
if (mons_is_fleeing(monster))
prefixes.push_back("fleeing");
- bool silence = silenced(you.x_pos, you.y_pos);
- if (silenced(monster->x, monster->y))
+ bool silence = silenced(you.pos());
+ if (silenced(monster->pos()))
{
silence = true;
prefixes.push_back("silenced");
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 571eda7fba..f1aeaccf6e 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -1379,11 +1379,11 @@ static bool _jelly_divide(monsters *parent)
child->x = parent->x + jex;
child->y = parent->y + jey;
- mgrd[child->x][child->y] = k;
+ mgrd(child->pos()) = k;
if (!simple_monster_message(parent, " splits in two!"))
{
- if (!silenced(parent->x, parent->y) || !silenced(child->x, child->y))
+ if (!silenced(parent->pos()) || !silenced(child->pos()))
mpr("You hear a squelching noise.", MSGCH_SOUND);
}
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index f34e00c9b6..77aeaeb7ff 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -147,10 +147,9 @@ void mons_trap(monsters *monster)
// Alarm traps aren't set off by hostile monsters, because that would
// be way too nasty for the player.
case TRAP_ALARM:
- if (!mons_friendly(monster) || silenced(monster->x, monster->y))
+ if (!mons_friendly(monster) || silenced(monster->pos()))
{
- if (trapKnown && you.can_see(monster)
- && !silenced(you.x_pos, you.y_pos))
+ if (trapKnown && you.can_see(monster) && !silenced(you.pos()))
{
mpr("The alarm trap makes no noise.");
}
@@ -296,8 +295,7 @@ void mons_trap(monsters *monster)
}
// output triggering message to player, where appropriate: {dlb}
- if (!silenced(monster->x, monster->y)
- && !silenced(you.x_pos, you.y_pos))
+ if (!silenced(monster->pos()) && !silenced(you.pos()))
{
if (monsterNearby)
mpr("You hear a loud \"Zot\"!", MSGCH_SOUND);
@@ -2471,7 +2469,7 @@ bool orc_battle_cry(monsters *chief)
if (foe
&& (foe != &you || !mons_friendly(chief))
- && !silenced(chief->x, chief->y)
+ && !silenced(chief->pos())
&& chief->can_see(foe)
&& coinflip())
{
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 274cb05794..57da963f84 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -2641,8 +2641,7 @@ void update_beholders(const monsters *mon, bool force)
// Is an update even necessary?
if (force || !mons_near(mon) || mons_friendly(mon) || mon->submerged()
|| mon->has_ench(ENCH_CONFUSION) || mons_cannot_move(mon)
- || mon->asleep() || silenced(you.x_pos, you.y_pos)
- || silenced(mon->x, mon->y))
+ || mon->asleep() || silenced(you.pos()) || silenced(mon->pos()))
{
const std::vector<int> help = you.beheld_by;
you.beheld_by.clear();
@@ -5826,7 +5825,7 @@ int player::total_weight() const
bool player::cannot_speak() const
{
- if (silenced(x_pos, y_pos))
+ if (silenced(this->pos()))
return (true);
if (you.cannot_move()) // we allow talking during sleep ;)
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 2b280e49f2..f3409195a3 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -1983,7 +1983,7 @@ static bool _god_accepts_prayer(god_type type)
void pray()
{
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
{
mpr("You are unable to make a sound!");
return;
@@ -5501,7 +5501,7 @@ void god_pitch(god_type which_god)
mpr("Your evil allies forsake you.", MSGCH_MONSTER_ENCHANT);
if (you.religion == GOD_ZIN && _chaotic_beings_attitude_change())
mpr("Your chaotic allies forsake you.", MSGCH_MONSTER_ENCHANT);
- else if (you.religion == GOD_TROG && _magic_users_attitude_change())
+ if (you.religion == GOD_TROG && _magic_users_attitude_change())
mpr("Your magic-using allies forsake you.", MSGCH_MONSTER_ENCHANT);
if (you.religion == GOD_ELYVILON)
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index d4e5d520e0..cf793e20d3 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -1691,19 +1691,15 @@ bool cast_sure_blade(int power)
return (success);
}
-void manage_fire_shield(void)
+void manage_fire_shield()
{
you.duration[DUR_FIRE_SHIELD]--;
if (!you.duration[DUR_FIRE_SHIELD])
return;
- for ( radius_iterator ri(you.pos(), 1); ri; ++ri )
- {
- if ( *ri == you.pos() )
- continue;
-
- if (!grid_is_solid(grd(*ri)) && env.cgrid(*ri) == EMPTY_CLOUD)
- place_cloud( CLOUD_FIRE, *ri, 1 + random2(6), KC_YOU );
- }
+ // Place fire clouds all around you
+ for ( adjacent_iterator ai; ai; ++ai )
+ if (!grid_is_solid(grd(*ai)) && env.cgrid(*ai) == EMPTY_CLOUD)
+ place_cloud( CLOUD_FIRE, *ai, 1 + random2(6), KC_YOU );
}
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index 93adf4b69e..cc3a436b99 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -1630,7 +1630,7 @@ bool cast_sanctuary(const int power)
return (false);
// Yes, shamelessly stolen from NetHack...
- if (!silenced(you.x_pos, you.y_pos)) // How did you manage that?
+ if (!silenced(you.pos())) // How did you manage that?
mpr("You hear a choir sing!", MSGCH_SOUND);
else
mpr("You are suddenly bathed in radiance!");
@@ -1860,12 +1860,12 @@ bool project_noise(void)
success = true;
}
- if (!silenced( you.x_pos, you.y_pos ))
+ if (!silenced( you.pos() ))
{
if (success)
{
mprf(MSGCH_SOUND, "You hear a %svoice call your name.",
- (!see_grid( pos.x, pos.y ) ? "distant " : "") );
+ (!see_grid( pos ) ? "distant " : "") );
}
else
mprf(MSGCH_SOUND, "You hear a dull thud.");
diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc
index a9688cd558..c32d0c1578 100644
--- a/crawl-ref/source/spells4.cc
+++ b/crawl-ref/source/spells4.cc
@@ -228,7 +228,7 @@ static int _shatter_items(int x, int y, int pow, int garbage)
if (broke_stuff)
{
- if (!silenced(x, y) && !silenced(you.x_pos, you.y_pos))
+ if (!silenced(coord_def(x, y)) && !silenced(you.pos()))
mpr("You hear glass break.", MSGCH_SOUND);
return 1;
@@ -305,7 +305,7 @@ static int _shatter_walls(int x, int y, int pow, int garbage)
void cast_shatter(int pow)
{
int damage = 0;
- const bool silence = silenced(you.x_pos, you.y_pos);
+ const bool silence = silenced(you.pos());
if (silence)
mpr("The dungeon shakes!");
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 368efb48bf..3833cbf483 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -599,7 +599,7 @@ bool cast_a_spell()
return (false);
}
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
{
mpr("You cannot cast spells when silenced!");
crawl_state.zero_turns_taken();
@@ -2377,7 +2377,7 @@ static void _miscast_enchantment(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 9:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear something strange.", MSGCH_SOUND);
else if (you.attribute[ATTR_TRANSFORMATION] != TRAN_AIR)
mpr("Your skull vibrates slightly.");
@@ -2606,7 +2606,7 @@ static void _miscast_summoning(int severity, const char* cause)
mpr("Shadowy shapes form in the air around you, then vanish.");
break;
case 1:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear strange voices.", MSGCH_SOUND);
else
mpr("You feel momentarily dizzy.");
@@ -2802,7 +2802,7 @@ static void _miscast_divination(int severity, const char* cause)
mpr("Weird images run through your mind.");
break;
case 1:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear strange voices.", MSGCH_SOUND);
else
mpr("Your nose twitches.");
@@ -2927,7 +2927,7 @@ static void _miscast_necromancy(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 1:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear strange and distant voices.", MSGCH_SOUND);
else
mpr("You feel homesick.");
@@ -3242,7 +3242,7 @@ static void _miscast_fire(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 9:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a sizzling sound.", MSGCH_SOUND);
else
mpr("You feel like you have heartburn.");
@@ -3381,7 +3381,7 @@ static void _miscast_ice(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 9:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a crackling sound.", MSGCH_SOUND);
else
mpr("A snowflake lands on your nose.");
@@ -3484,7 +3484,7 @@ static void _miscast_earth(int severity, const char* cause)
mpr("You feel a surge of energy from the ground.");
break;
case 4:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a distant rumble.", MSGCH_SOUND);
else
mpr("You sympathise with the stones.");
@@ -3604,7 +3604,7 @@ static void _miscast_air(int severity, const char* cause)
mpr("You are blasted with air!");
break;
case 7:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a whooshing sound.", MSGCH_SOUND);
else if (player_can_smell())
mpr("You smell ozone.");
@@ -3617,7 +3617,7 @@ static void _miscast_air(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 9:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a crackling sound.", MSGCH_SOUND);
else if (player_can_smell())
mpr("You smell something musty.");
@@ -3637,7 +3637,7 @@ static void _miscast_air(int severity, const char* cause)
break;
case 1:
mprf("The wind %s around you!",
- silenced(you.x_pos, you.y_pos) ? "whips" : "howls");
+ silenced(you.pos()) ? "whips" : "howls");
break;
}
break;
@@ -3727,7 +3727,7 @@ static void _miscast_poison(int severity, const char* cause)
canned_msg(MSG_NOTHING_HAPPENS);
break;
case 9:
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a slurping sound.", MSGCH_SOUND);
else if (you.species != SP_MUMMY)
mpr("You taste almonds.");
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 1a56d27866..335df71169 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -132,6 +132,61 @@ stack_iterator stack_iterator::operator++(int dummy)
return copy;
}
+rectangle_iterator::rectangle_iterator( const coord_def& corner1,
+ const coord_def& corner2 )
+{
+ topleft.x = std::min(corner1.x, corner2.x);
+ topleft.y = std::min(corner1.y, corner2.y); // not really necessary
+ bottomright.x = std::max(corner1.x, corner2.x);
+ bottomright.y = std::max(corner1.y, corner2.y);
+ current = topleft;
+}
+
+rectangle_iterator::rectangle_iterator( int x_border_dist, int y_border_dist )
+{
+ if ( y_border_dist < 0 )
+ y_border_dist = x_border_dist;
+ topleft.set( x_border_dist, y_border_dist );
+ bottomright.set( GXM - x_border_dist, GYM - y_border_dist );
+ current = topleft;
+}
+
+rectangle_iterator::operator bool() const
+{
+ return current.y > bottomright.y;
+}
+
+coord_def rectangle_iterator::operator *() const
+{
+ return current;
+}
+
+const coord_def* rectangle_iterator::operator->() const
+{
+ return &current;
+}
+
+rectangle_iterator& rectangle_iterator::operator ++()
+{
+ if ( current.x == bottomright.x )
+ {
+ current.x = topleft.x;
+ current.y++;
+ }
+ else
+ {
+ current.x++;
+ }
+ return *this;
+}
+
+rectangle_iterator rectangle_iterator::operator++( int dummy )
+{
+ const rectangle_iterator copy = *this;
+ ++(*this);
+ return (copy);
+}
+
radius_iterator::radius_iterator( const coord_def& _center, int _radius,
bool _roguelike_metric, bool _require_los,
bool _exclude_center )
@@ -1176,28 +1231,15 @@ bool adjacent( const coord_def& p1, const coord_def& p2 )
return grid_distance(p1, p2) <= 1;
}
-bool silenced(int x, int y)
+bool silenced(const coord_def& p)
{
- if (you.duration[DUR_SILENCE] > 0
- && distance(x, y, you.x_pos, you.y_pos) <= 36) // (6 * 6)
- {
- return (true);
- }
- else
- {
- //else // FIXME: implement, and let monsters cast, too
- // for (int i = 0; i < MAX_SILENCES; i++)
- // {
- // if (distance(x, y, silencer[i].x, silencer[i].y) <= 36)
- // return (true);
- // }
- return (false);
- }
+ // FIXME: implement for monsters
+ return (you.duration[DUR_SILENCE] > 0 && distance(p, you.pos()) <= 6*6);
}
bool player_can_hear(int x, int y)
{
- return (!silenced(x, y) && !silenced(you.x_pos, you.y_pos));
+ return (!silenced(coord_def(x, y)) && !silenced(you.pos()));
}
// Returns true if inside the area the player can move and dig (ie exclusive).
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index b43bb63cb3..7a7183b60a 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -49,6 +49,9 @@ int roll_dice( int num, int size );
int roll_dice( const struct dice_def &dice );
void scale_dice( dice_def &dice, int threshold = 24 );
+
+// Various ways to iterate over things.
+
// stack_iterator guarantees validity so long as you don't manually
// mess with item_def.link: i.e., you can kill the item you're
// examining but you can't kill the item linked to it.
@@ -71,6 +74,22 @@ private:
int next_link;
};
+class rectangle_iterator :
+ public std::iterator<std::forward_iterator_tag, coord_def>
+{
+public:
+ rectangle_iterator( const coord_def& corner1, const coord_def& corner2 );
+ explicit rectangle_iterator( int x_border_dist, int y_border_dist = -1 );
+ operator bool() const;
+ coord_def operator *() const;
+ const coord_def* operator->() const;
+
+ rectangle_iterator& operator ++ ();
+ rectangle_iterator operator ++ (int);
+private:
+ coord_def current, topleft, bottomright;
+};
+
class radius_iterator : public std::iterator<std::bidirectional_iterator_tag,
coord_def>
{
@@ -100,6 +119,14 @@ private:
bool iter_done;
};
+class adjacent_iterator : public radius_iterator
+{
+public:
+ adjacent_iterator( const coord_def& pos = you.pos(),
+ bool _exclude_center = true ) :
+ radius_iterator(pos, 1, true, false, _exclude_center) {}
+};
+
int random2limit(int max, int limit);
int stepdown_value(int base_value, int stepping, int first_step,
int last_step, int ceiling_value);
@@ -153,8 +180,7 @@ int distance( const coord_def& p1, const coord_def& p2 );
int distance( int x, int y, int x2, int y2);
bool adjacent( const coord_def& p1, const coord_def& p2 );
-bool silenced(int x, int y);
-inline bool silenced(const coord_def &p) { return silenced(p.x, p.y); }
+bool silenced(const coord_def& p);
bool player_can_hear(int x, int y);
inline bool player_can_hear(const coord_def &p)
diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc
index a448f9bb8f..6eea6729fd 100644
--- a/crawl-ref/source/traps.cc
+++ b/crawl-ref/source/traps.cc
@@ -403,7 +403,7 @@ void handle_traps(trap_type trt, int i, bool trap_known)
break;
case TRAP_ALARM:
- if (silenced(you.x_pos, you.y_pos))
+ if (silenced(you.pos()))
{
if (trap_known)
mpr("The alarm is silenced.");
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 82e6108f00..66ad912d8f 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -927,8 +927,8 @@ void handle_monster_shouts(monsters* monster, bool force)
// Silent monsters can give noiseless "visual shouts" if the
// player can see them, in which case silence isn't checked for.
if (s_type == S_SILENT && !player_monster_visible(monster)
- || s_type != S_SILENT && (silenced(you.x_pos, you.y_pos)
- || silenced(monster->x, monster->y)))
+ || s_type != S_SILENT && (silenced(you.pos())
+ || silenced(monster->pos())))
{
return;
}