summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-22 20:21:15 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-22 20:21:15 +0000
commit9a160b380b94ce9b89c93214fe7b9de3f36ed01f (patch)
tree53d1992a132d6e3178b427bbaca2510120233173 /crawl-ref
parent23e8c7a07f9ea71e683fa748940cc7447e5a8aa1 (diff)
downloadcrawl-ref-9a160b380b94ce9b89c93214fe7b9de3f36ed01f.tar.gz
crawl-ref-9a160b380b94ce9b89c93214fe7b9de3f36ed01f.zip
Massive change from using x and y to using coord_defs(). Not quite tested,
most likely broken in some places and might break tiles. Will fix in the near future. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6636 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/abyss.cc62
-rw-r--r--crawl-ref/source/acr.cc131
-rw-r--r--crawl-ref/source/beam.cc390
-rw-r--r--crawl-ref/source/beam.h11
-rw-r--r--crawl-ref/source/cloud.cc92
-rw-r--r--crawl-ref/source/cloud.h6
-rw-r--r--crawl-ref/source/debug.cc4
-rw-r--r--crawl-ref/source/decks.cc16
-rw-r--r--crawl-ref/source/delay.cc30
-rw-r--r--crawl-ref/source/describe.cc2
-rw-r--r--crawl-ref/source/directn.cc230
-rw-r--r--crawl-ref/source/directn.h5
-rw-r--r--crawl-ref/source/effects.cc27
-rw-r--r--crawl-ref/source/externs.h8
-rw-r--r--crawl-ref/source/fight.cc19
-rw-r--r--crawl-ref/source/it_use3.cc2
-rw-r--r--crawl-ref/source/item_use.cc22
-rw-r--r--crawl-ref/source/item_use.h3
-rw-r--r--crawl-ref/source/items.cc121
-rw-r--r--crawl-ref/source/items.h6
-rw-r--r--crawl-ref/source/luadgn.cc7
-rw-r--r--crawl-ref/source/makeitem.cc2
-rw-r--r--crawl-ref/source/misc.cc133
-rw-r--r--crawl-ref/source/misc.h7
-rw-r--r--crawl-ref/source/mon-util.cc51
-rw-r--r--crawl-ref/source/mon-util.h2
-rw-r--r--crawl-ref/source/monplace.cc16
-rw-r--r--crawl-ref/source/monstuff.cc574
-rw-r--r--crawl-ref/source/monstuff.h4
-rw-r--r--crawl-ref/source/mstuff2.cc73
-rw-r--r--crawl-ref/source/mstuff2.h72
-rw-r--r--crawl-ref/source/mtransit.cc2
-rw-r--r--crawl-ref/source/ouch.cc7
-rw-r--r--crawl-ref/source/ouch.h3
-rw-r--r--crawl-ref/source/overmap.cc2
-rw-r--r--crawl-ref/source/player.cc67
-rw-r--r--crawl-ref/source/player.h2
-rw-r--r--crawl-ref/source/religion.cc32
-rw-r--r--crawl-ref/source/shopping.cc25
-rw-r--r--crawl-ref/source/shopping.h6
-rw-r--r--crawl-ref/source/spells1.cc102
-rw-r--r--crawl-ref/source/spells2.cc55
-rw-r--r--crawl-ref/source/spells3.cc50
-rw-r--r--crawl-ref/source/spells4.cc57
-rw-r--r--crawl-ref/source/spl-cast.cc4
-rw-r--r--crawl-ref/source/stash.cc6
-rw-r--r--crawl-ref/source/stuff.cc6
-rw-r--r--crawl-ref/source/stuff.h2
-rw-r--r--crawl-ref/source/terrain.cc24
-rw-r--r--crawl-ref/source/terrain.h4
-rw-r--r--crawl-ref/source/transfor.cc8
-rw-r--r--crawl-ref/source/traps.cc79
-rw-r--r--crawl-ref/source/traps.h12
-rw-r--r--crawl-ref/source/travel.cc4
-rw-r--r--crawl-ref/source/tutorial.cc4
-rw-r--r--crawl-ref/source/view.cc147
-rw-r--r--crawl-ref/source/view.h20
-rw-r--r--crawl-ref/source/xom.cc2
58 files changed, 1307 insertions, 1553 deletions
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc
index ce0fba4011..b7af7c07a2 100644
--- a/crawl-ref/source/abyss.cc
+++ b/crawl-ref/source/abyss.cc
@@ -60,7 +60,7 @@ static bool _place_feature_near( const coord_def &centre,
if (cp == centre || (cp - centre).abs() > radius2 || !in_bounds(cp))
continue;
- if (not_seen && grid_see_grid(cp.x, cp.y, centre.x, centre.y))
+ if (not_seen && grid_see_grid(cp, centre))
continue;
if (grd(cp) == candidate)
@@ -259,7 +259,7 @@ static void _generate_area(int gx1, int gy1, int gx2, int gy2,
true, items_level, 250);
}
- move_item_to_grid( &thing_created, i, j );
+ move_item_to_grid( &thing_created, coord_def(i, j) );
if (thing_created != NON_ITEM)
items_placed++;
@@ -486,46 +486,36 @@ void area_shift(void)
}
// Shift all monsters & items to new area.
- for (int i = you.x_pos - 10; i <= you.x_pos + 10; i++)
+ for (radius_iterator ri(you.pos(), 10, true, false); ri; ++ri)
{
- if (i < 0 || i >= GXM)
- continue;
-
- for (int j = you.y_pos - 10; j <= you.y_pos + 10; j++)
- {
- if (j < 0 || j >= GYM)
- continue;
-
- const int ipos = 45 + i - you.x_pos;
- const int jpos = 35 + j - you.y_pos;
+ const coord_def newpos = coord_def(45,35) + *ri - you.pos();
- // Move terrain.
- grd[ipos][jpos] = grd[i][j];
-
- // Move item.
+ // Move terrain.
+ grd(newpos) = grd(*ri);
+
+ // Move item.
#ifdef DEBUG_ABYSS
- if (igrd[i][j] != NON_ITEM)
- {
- mprf(MSGCH_DIAGNOSTICS,
- "Move item stack from (%d, %d) to (%d, %d)",
- i, j, ipos, jpos);
- }
+ if (igrd(*ri) != NON_ITEM)
+ {
+ mprf(MSGCH_DIAGNOSTICS,
+ "Move item stack from (%d, %d) to (%d, %d)",
+ ri->x, ri->y, newpos.x, newpos.y);
+ }
#endif
- move_item_stack_to_grid( i, j, ipos, jpos );
-
- // Move monster.
- mgrd[ipos][jpos] = mgrd[i][j];
- if (mgrd[i][j] != NON_MONSTER)
- {
- menv[mgrd[ipos][jpos]].x = ipos;
- menv[mgrd[ipos][jpos]].y = jpos;
- mgrd[i][j] = NON_MONSTER;
- }
+ move_item_stack_to_grid( *ri, newpos );
- // Move cloud,
- if (env.cgrid[i][j] != EMPTY_CLOUD)
- move_cloud( env.cgrid[i][j], ipos, jpos );
+ // Move monster.
+ mgrd(newpos) = mgrd(*ri);
+ if (mgrd(*ri) != NON_MONSTER)
+ {
+ menv[mgrd(newpos)].x = newpos.x;
+ menv[mgrd(newpos)].y = newpos.y;
+ mgrd(*ri) = NON_MONSTER;
}
+
+ // Move cloud,
+ if (env.cgrid(*ri) != EMPTY_CLOUD)
+ move_cloud( env.cgrid(*ri), newpos );
}
for (unsigned int i = 0; i < MAX_CLOUDS; i++)
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 0880bc8dbc..593bb26375 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -178,6 +178,7 @@ static void _do_berserk_no_combat_penalty(void);
static bool _initialise(void);
static void _input(void);
static void _move_player(int move_x, int move_y);
+static void _move_player(coord_def move);
static int _check_adjacent(dungeon_feature_type feat, int &dx, int &dy);
static void _open_door(int move_x, int move_y, bool check_confused = true);
static void _close_door(int move_x, int move_y);
@@ -633,7 +634,7 @@ static void _handle_wizard_command( void )
<< mitm[islot].name(DESC_NOCAP_A)
<< std::endl;
- move_item_to_grid( &islot, you.x_pos, you.y_pos );
+ move_item_to_grid( &islot, you.pos() );
}
// Create all fixed artefacts.
@@ -650,7 +651,7 @@ static void _handle_wizard_command( void )
item_colour( mitm[ islot ] );
set_ident_flags( mitm[ islot ], ISFLAG_IDENT_MASK );
- move_item_to_grid( &islot, you.x_pos, you.y_pos );
+ move_item_to_grid( &islot, you.pos() );
msg::streams(MSGCH_DIAGNOSTICS) <<
"Made " << mitm[islot].name(DESC_NOCAP_A) << std::endl;
@@ -672,7 +673,7 @@ static void _handle_wizard_command( void )
mitm[islot].quantity = 1;
set_ident_flags( mitm[ islot ], ISFLAG_IDENT_MASK );
- move_item_to_grid( &islot, you.x_pos, you.y_pos );
+ move_item_to_grid( &islot, you.pos() );
msg::streams(MSGCH_DIAGNOSTICS) << "Made "
<< mitm[islot].name(DESC_NOCAP_A)
@@ -1692,8 +1693,8 @@ static void _go_upstairs()
static void _go_downstairs()
{
- bool shaft = (trap_type_at_xy(you.x_pos, you.y_pos) == TRAP_SHAFT
- && grd[you.x_pos][you.y_pos] != DNGN_UNDISCOVERED_TRAP);
+ bool shaft = (trap_type_at_xy(you.pos()) == TRAP_SHAFT
+ && grd(you.pos()) != DNGN_UNDISCOVERED_TRAP);
if (_stairs_check_beheld())
@@ -2906,7 +2907,7 @@ static void _decrement_durations()
// Landing kills controlled flight.
you.duration[DUR_CONTROLLED_FLIGHT] = 0;
// Re-enter the terrain.
- move_player_to_grid( you.x_pos, you.y_pos, false, true, true );
+ move_player_to_grid( you.pos(), false, true, true );
}
}
@@ -3036,9 +3037,9 @@ static void _check_shafts()
if (trap.type != TRAP_SHAFT)
continue;
- ASSERT(in_bounds(trap.x, trap.y));
+ ASSERT(in_bounds(trap.pos()));
- handle_items_on_shaft(trap.x, trap.y, true);
+ handle_items_on_shaft(trap.pos(), true);
}
}
@@ -3584,14 +3585,14 @@ static void _open_door(int move_x, int move_y, bool check_confused)
{
mprf(MSGCH_SOUND, "The %s%s flies open with a bang!",
adj, noun);
- noisy(15, you.x_pos, you.y_pos);
+ noisy(15, 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 open the %s%s, it creaks loudly!",
adj, noun);
- noisy(10, you.x_pos, you.y_pos);
+ noisy(10, you.pos());
}
else
{
@@ -3613,11 +3614,11 @@ static void _open_door(int move_x, int move_y, bool check_confused)
#ifdef USE_TILE
tile_place_tile_bk(dc.x, dc.y, TILE_DNGN_OPEN_DOOR);
#endif
- if (!seen_secret && grd[dc.x][dc.y] == DNGN_SECRET_DOOR)
+ if (!seen_secret && grd(dc) == DNGN_SECRET_DOOR)
{
seen_secret = true;
dungeon_feature_type secret
- = grid_secret_door_appearance(dc.x, dc.y);
+ = grid_secret_door_appearance(dc);
mprf("That %s was a secret door!",
feature_description(secret, NUM_TRAPS, false,
DESC_PLAIN, false).c_str());
@@ -3744,14 +3745,14 @@ static void _close_door(int door_x, int door_y)
{
mprf(MSGCH_SOUND, "You slam the %s%s shut with an echoing bang!",
adj, noun);
- noisy(25, you.x_pos, you.y_pos);
+ noisy(25, you.pos());
}
}
else if (one_chance_in(skill) && !silenced(you.x_pos, you.y_pos))
{
mprf(MSGCH_SOUND, "As you close the %s%s, it creaks loudly!",
adj, noun);
- noisy(10, you.x_pos, you.y_pos);
+ noisy(10, you.pos());
}
else
{
@@ -4036,10 +4037,14 @@ static void _do_berserk_no_combat_penalty(void)
// function etc when necessary.
static void _move_player(int move_x, int move_y)
{
+ _move_player( coord_def(move_x, move_y) );
+}
+
+static void _move_player(coord_def move)
+{
bool attacking = false;
bool moving = true; // used to prevent eventual movement (swap)
bool swap = false;
- monsters *beholder = NULL; // beholding monster preventing movement
if (you.attribute[ATTR_HELD])
{
@@ -4048,19 +4053,18 @@ static void _move_player(int move_x, int move_y)
return;
}
+ // When confused, sometimes make a random move
if (you.duration[DUR_CONF])
{
if (!one_chance_in(3))
{
- move_x = random2(3) - 1;
- move_y = random2(3) - 1;
+ move.x = random2(3) - 1;
+ move.y = random2(3) - 1;
you.reset_prev_move();
}
-
- const int new_targ_x = you.x_pos + move_x;
- const int new_targ_y = you.y_pos + move_y;
- if (!in_bounds(new_targ_x, new_targ_y)
- || !you.can_pass_through(new_targ_x, new_targ_y))
+
+ const coord_def& new_targ = you.pos() + move;
+ if (!in_bounds(new_targ) || !you.can_pass_through(new_targ))
{
you.turn_is_over = true;
mpr("Ouch!");
@@ -4069,13 +4073,12 @@ static void _move_player(int move_x, int move_y)
return;
}
- } // end of if you.duration[DUR_CONF]
+ }
- const int targ_x = you.x_pos + move_x;
- const int targ_y = you.y_pos + move_y;
- const dungeon_feature_type targ_grid = grd[ targ_x ][ targ_y ];
- const unsigned short targ_monst = mgrd[ targ_x ][ targ_y ];
- const bool targ_pass = you.can_pass_through(targ_x, targ_y);
+ const coord_def& targ = you.pos() + move;
+ const dungeon_feature_type targ_grid = grd(targ);
+ const unsigned short targ_monst = mgrd(targ);
+ const bool targ_pass = you.can_pass_through(targ);
// You can swap places with a friendly or good neutral monster if
// you're not confused, or if both of you are inside a sanctuary.
@@ -4083,33 +4086,30 @@ static void _move_player(int move_x, int move_y)
&& !mons_is_stationary(&menv[targ_monst])
&& (mons_wont_attack(&menv[targ_monst])
&& !you.duration[DUR_CONF]
- || is_sanctuary(you.x_pos, you.y_pos)
- && is_sanctuary(targ_x, targ_y));
+ || is_sanctuary(you.pos())
+ && is_sanctuary(targ));
// You cannot move away from a mermaid but you CAN fight monsters on
// neighbouring squares.
+ monsters *beholder = NULL;
if (you.duration[DUR_BEHELD] && !you.duration[DUR_CONF])
{
for (unsigned int i = 0; i < you.beheld_by.size(); i++)
{
- monsters* mon = &menv[you.beheld_by[i]];
- coord_def pos = mon->pos();
- int olddist = grid_distance(you.x_pos, you.y_pos, pos.x, pos.y);
- int newdist = grid_distance(you.x_pos + move_x, you.y_pos + move_y,
- pos.x, pos.y);
+ monsters& mon = menv[you.beheld_by[i]];
+ int olddist = grid_distance(you.pos(), mon.pos());
+ int newdist = grid_distance(targ, mon.pos());
if (olddist < newdist)
{
- beholder = mon;
+ beholder = &mon;
break;
}
}
- } // end of beholding check
+ }
if (you.running.check_stop_running())
{
- move_x = 0;
- move_y = 0;
// [ds] Do we need this? Shouldn't it be false to start with?
you.turn_is_over = false;
return;
@@ -4151,48 +4151,35 @@ static void _move_player(int move_x, int move_y)
{
you.time_taken *= player_movement_speed();
you.time_taken /= 10;
- if (!move_player_to_grid(targ_x, targ_y, true, false, swap, swap))
+ if (!move_player_to_grid(targ, true, false, swap, swap))
return;
if (swap)
swap_places(&menv[targ_monst], mon_swap_dest);
- you.prev_move_x = move_x;
- you.prev_move_y = move_y;
-
- move_x = 0;
- move_y = 0;
-
+ you.prev_move = move;
+ move.reset();
you.turn_is_over = true;
- // item_check( false );
request_autopickup();
-
}
// BCR - Easy doors single move
if (targ_grid == DNGN_CLOSED_DOOR && Options.easy_open && !attacking)
{
- _open_door(move_x, move_y, false);
- you.prev_move_x = move_x;
- you.prev_move_y = move_y;
+ _open_door(move.x, move.y, false);
+ you.prev_move = move;
}
else if (!targ_pass && !attacking)
{
stop_running();
-
- move_x = 0;
- move_y = 0;
-
- you.turn_is_over = 0;
+ move.reset();
+ you.turn_is_over = false;
crawl_state.cancel_cmd_repeat();
}
else if (beholder && !attacking)
{
mprf("You cannot move away from %s!",
beholder->name(DESC_NOCAP_THE, true).c_str());
-
- move_x = 0;
- move_y = 0;
return;
}
@@ -4209,27 +4196,25 @@ static void _move_player(int move_x, int move_y)
#if DEBUG_DIAGNOSTICS
mpr( "Shifting.", MSGCH_DIAGNOSTICS );
- int igly = 0;
- int ig2 = 0;
-
- for (igly = 0; igly < MAX_ITEMS; igly++)
- if (is_valid_item( mitm[igly] ))
- ig2++;
+ int j = 0;
+ for (int i = 0; i < MAX_ITEMS; i++)
+ if (is_valid_item( mitm[i] ))
+ ++j;
- mprf( MSGCH_DIAGNOSTICS, "Number of items present: %d", ig2 );
+ mprf( MSGCH_DIAGNOSTICS, "Number of items present: %d", j );
- ig2 = 0;
- for (igly = 0; igly < MAX_MONSTERS; igly++)
- if (menv[igly].type != -1)
- ig2++;
+ j = 0;
+ for (int i = 0; i < MAX_MONSTERS; i++)
+ if (menv[i].type != -1)
+ ++j;
- mprf( MSGCH_DIAGNOSTICS, "Number of monsters present: %d", ig2);
+ mprf( MSGCH_DIAGNOSTICS, "Number of monsters present: %d", j);
mprf( MSGCH_DIAGNOSTICS, "Number of clouds present: %d", env.cloud_no);
#endif
}
apply_berserk_penalty = !attacking;
-} // end move_player()
+}
static int _get_num_and_char_keyfun(int &ch)
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index 9df1cd06e1..746c0e5883 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -77,9 +77,6 @@
#define MON_AFFECTED 2 // monster was affected
#define MON_OTHER 3 // monster unaffected, but for other reasons
-static int spreadx[] = { 0, 0, 1, -1 };
-static int spready[] = { -1, 1, 0, 0 };
-static int opdir[] = { 2, 1, 4, 3 };
static FixedArray < bool, 19, 19 > explode_map;
// Helper functions (some of these should probably be public).
@@ -88,11 +85,11 @@ static bool _affects_wall(const bolt &beam, int wall_feature);
static bool _isBouncy(bolt &beam, unsigned char gridtype);
static int _beam_source(const bolt &beam);
static std::string _beam_zapper(const bolt &beam);
-static bool _beam_term_on_target(bolt &beam, int x, int y);
-static void _beam_explodes(bolt &beam, int x, int y);
-static int _affect_wall(bolt &beam, int x, int y);
-static int _affect_place_clouds(bolt &beam, int x, int y);
-static void _affect_place_explosion_clouds(bolt &beam, int x, int y);
+static bool _beam_term_on_target(bolt &beam, const coord_def& p);
+static void _beam_explodes(bolt &beam, const coord_def& p);
+static int _affect_wall(bolt &beam, const coord_def& p);
+static int _affect_place_clouds(bolt &beam, const coord_def& p);
+static void _affect_place_explosion_clouds(bolt &beam, const coord_def& p);
static int _affect_player(bolt &beam, item_def *item = NULL);
static int _affect_monster(bolt &beam, monsters *mon, item_def *item = NULL);
static int _affect_monster_enchantment(bolt &beam, monsters *mon);
@@ -100,9 +97,9 @@ static void _beam_paralyses_monster( bolt &pbolt, monsters *monster );
static void _beam_petrifies_monster( bolt &pbolt, monsters *monster );
static int _range_used_on_hit(bolt &beam);
static void _explosion1(bolt &pbolt);
-static void _explosion_map(bolt &beam, int x, int y,
+static void _explosion_map(bolt &beam, const coord_def& p,
int count, int dir, int r);
-static void _explosion_cell(bolt &beam, int x, int y, bool drawOnly);
+static void _explosion_cell(bolt &beam, const coord_def& p, bool drawOnly);
static void _ench_animation(int flavour, const monsters *mon = NULL,
bool force = false);
@@ -167,7 +164,7 @@ static kill_category _whose_kill(const bolt &beam)
// generic).
void zap_animation(int colour, const monsters *mon, bool force)
{
- int x = you.x_pos, y = you.y_pos;
+ coord_def p = you.pos();
// Default to whatever colour magic is today.
if (colour == -1)
@@ -178,24 +175,22 @@ void zap_animation(int colour, const monsters *mon, bool force)
if (!force && !player_monster_visible( mon ))
return;
- x = mon->x;
- y = mon->y;
+ p = mon->pos();
}
- if (!see_grid( x, y ))
+ if (!see_grid(p))
return;
- const int drawx = grid2viewX(x);
- const int drawy = grid2viewY(y);
+ const coord_def drawp = grid2view(p);
- if (in_los_bounds(drawx, drawy))
+ if (in_los_bounds(drawp))
{
#ifdef USE_TILE
// TODO enne - fixme!
- TileDrawBolt(drawx-1, drawy-1, tileidx_zap(colour));
+ TileDrawBolt(drawp.x-1, drawp.y-1, tileidx_zap(colour));
#else
view_update();
- cgotoxy(drawx, drawy, GOTO_DNGN);
+ cgotoxy(drawp.x, drawp.y, GOTO_DNGN);
put_colour_ch(colour, dchar_glyph(DCHAR_FIRED_ZAP));
#endif
@@ -273,7 +268,7 @@ bool zapping(zap_type ztype, int power, bolt &pbolt, bool needs_tracer,
if (ztype == ZAP_LIGHTNING)
{
// XXX: Needs to check silenced at other location, too. {dlb}
- noisy(25, you.x_pos, you.y_pos, "You hear a mighty clap of thunder!");
+ noisy(25, you.pos(), "You hear a mighty clap of thunder!");
}
else if (ztype == ZAP_DIGGING)
pbolt.aimed_at_spot = false;
@@ -1708,18 +1703,19 @@ static void _zappy( zap_type z_type, int power, bolt &pbolt )
// The wall will always shield the monster if the beam bounces off the
// wall, and a monster can't use a metal wall to shield itself from
// electricity.
-static bool _affect_mon_in_wall(bolt &pbolt, item_def *item, int tx, int ty)
+static bool _affect_mon_in_wall(bolt &pbolt, item_def *item,
+ const coord_def& where)
{
UNUSED(item);
- int mid = mgrd[tx][ty];
+ int mid = mgrd(where);
if (mid == NON_MONSTER)
return (false);
if (pbolt.is_enchant
|| (!pbolt.is_explosion && !pbolt.is_big_cloud
- && (grd[tx][ty] == DNGN_METAL_WALL
+ && (grd(where) == DNGN_METAL_WALL
|| pbolt.flavour != BEAM_ELECTRICITY)))
{
monsters *mon = &menv[mid];
@@ -1756,7 +1752,7 @@ static bool _affect_mon_in_wall(bolt &pbolt, item_def *item, int tx, int ty)
void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
{
bool beamTerminate; // Has beam been 'stopped' by something?
- int &tx(pbolt.pos.x), &ty(pbolt.pos.y); // test(new) x,y - integer
+ coord_def &testpos(pbolt.pos);
int rangeRemaining;
bool did_bounce = false;
cursor_control coff(false);
@@ -1804,9 +1800,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
else
{
ray.fullray_idx = -1; // to quiet valgrind
- find_ray( pbolt.source_x, pbolt.source_y,
- pbolt.target_x, pbolt.target_y, true, ray,
- 0, true );
+ find_ray( pbolt.source(), pbolt.target(), true, ray, 0, true );
}
if (!pbolt.aimed_at_feet)
@@ -1833,37 +1827,36 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
#endif
while (!beamTerminate)
- {
- tx = ray.x();
- ty = ray.y();
+ {
+ testpos = ray.pos();
// Shooting through clouds affects accuracy.
- if (env.cgrid[tx][ty] != EMPTY_CLOUD)
+ if (env.cgrid(testpos) != EMPTY_CLOUD)
pbolt.hit = std::max(pbolt.hit - 2, 0);
// See if tx, ty is blocked by something.
- if (grid_is_solid(grd[tx][ty]))
+ if (grid_is_solid(grd(testpos)))
{
// First, check to see if this beam affects walls.
- if (_affects_wall(pbolt, grd[tx][ty]))
+ if (_affects_wall(pbolt, grd(testpos)))
{
// Should we ever get a tracer with a wall-affecting
// beam (possible I suppose), we'll quit tracing now.
if (!pbolt.is_tracer)
- rangeRemaining -= affect(pbolt, tx, ty, item);
+ rangeRemaining -= affect(pbolt, testpos, item);
// If it's still a wall, quit.
- if (grid_is_solid(grd[tx][ty]))
+ if (grid_is_solid(grd(testpos)))
break; // breaks from line tracing
}
else
{
// BEGIN bounce case. Bouncing protects any monster
// in the wall.
- if (!_isBouncy(pbolt, grd[tx][ty]))
+ if (!_isBouncy(pbolt, grd(testpos)))
{
// Affect any monster that might be in the wall.
- rangeRemaining -= affect(pbolt, tx, ty, item);
+ rangeRemaining -= affect(pbolt, testpos, item);
do
{
@@ -1871,8 +1864,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
}
while (grid_is_solid(grd(ray.pos())));
- tx = ray.x();
- ty = ray.y();
+ testpos = ray.pos();
break; // breaks from line tracing
}
@@ -1888,20 +1880,18 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
ray.advance_and_bounce();
--rangeRemaining;
}
- while (rangeRemaining > 0
- && grid_is_solid(grd[ray.x()][ray.y()]));
+ while (rangeRemaining > 0 && grid_is_solid(grd(ray.pos())));
if (rangeRemaining < 1)
break;
- tx = ray.x();
- ty = ray.y();
+ testpos = ray.pos();
} // end else - beam doesn't affect walls
- } // endif - is tx, ty wall?
+ } // endif - are we in a wall wall?
- // At this point, if grd[tx][ty] is still a wall, we
+ // At this point, if grd(testpos) is still a wall, we
// couldn't find any path: bouncy, fuzzy, or not - so break.
- if (grid_is_solid(grd[tx][ty]))
+ if (grid_is_solid(grd(testpos)))
break;
// Check for "target termination"
@@ -1912,8 +1902,8 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
// In this case, don't affect the cell - players and
// monsters have no chance to dodge or block such
// a beam, and we want to avoid silly messages.
- if (tx == pbolt.target_x && ty == pbolt.target_y)
- beamTerminate = _beam_term_on_target(pbolt, tx, ty);
+ if (testpos == pbolt.target())
+ beamTerminate = _beam_term_on_target(pbolt, testpos);
// Affect the cell, except in the special case noted
// above -- affect() will early out if something gets
@@ -1930,7 +1920,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
}
if (!pbolt.affects_nothing)
- rangeRemaining -= affect(pbolt, tx, ty, item);
+ rangeRemaining -= affect(pbolt, testpos, item);
if (random_beam)
{
@@ -1955,7 +1945,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
// Actually draw the beam/missile/whatever,
// if the player can see the cell.
- if (!pbolt.is_tracer && pbolt.name[0] != '0' && see_grid(tx,ty))
+ if (!pbolt.is_tracer && pbolt.name[0] != '0' && see_grid(testpos))
{
// We don't clean up the old position.
// First, most people like to see the full path,
@@ -1963,26 +1953,25 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
// respect to killed monsters, cloud trails, etc.
// Draw new position.
- int drawx = grid2viewX(tx);
- int drawy = grid2viewY(ty);
+ coord_def drawpos = grid2view(testpos);
#ifdef USE_TILE
if (tile_beam == -1)
tile_beam = tileidx_bolt(pbolt);
- if (tile_beam != -1 && in_los_bounds(drawx, drawy)
- && (tx != you.x_pos || ty != you.y_pos))
+ if (tile_beam != -1 && in_los_bounds(drawpos)
+ && (testpos != you.pos()))
{
- TileDrawBolt(drawx-1, drawy-1, tile_beam);
+ TileDrawBolt(drawpos.x-1, drawpos.y-1, tile_beam);
delay(15);
}
else
#endif
// bounds check
- if (in_los_bounds(drawx, drawy))
+ if (in_los_bounds(drawpos))
{
#ifndef USE_TILE
- cgotoxy(drawx, drawy);
+ cgotoxy(drawpos.x, drawpos.y);
put_colour_ch(
pbolt.colour == BLACK ? random_colour() : pbolt.colour,
pbolt.type );
@@ -2011,22 +2000,21 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item)
// Leave an object, if applicable.
if (drop_item && item)
- beam_drop_object(pbolt, item, tx, ty);
+ beam_drop_object(pbolt, item, testpos);
ASSERT(!drop_item || item);
// Check for explosion. NOTE that for tracers, we have to make a copy
// of target co-ords and then reset after calling this -- tracers should
// never change any non-tracers fields in the beam structure. -- GDL
- int ox = pbolt.target_x;
- int oy = pbolt.target_y;
+ coord_def targetcopy = pbolt.target();
- _beam_explodes(pbolt, tx, ty);
+ _beam_explodes(pbolt, testpos);
if (pbolt.is_tracer)
{
- pbolt.target_x = ox;
- pbolt.target_y = oy;
+ pbolt.target_x = targetcopy.x;
+ pbolt.target_y = targetcopy.y;
}
// Canned msg for enchantments that affected no-one, but only if the
@@ -2858,9 +2846,9 @@ void fire_tracer(const monsters *monster, bolt &pbolt, bool explode_only)
pbolt.is_tracer = false;
}
-bool check_line_of_sight( int sx, int sy, int tx, int ty )
+bool check_line_of_sight( const coord_def& source, const coord_def& target )
{
- const int dist = grid_distance( sx, sy, tx, ty );
+ const int dist = grid_distance( source, target );
// Can always see one square away.
if (dist <= 1)
@@ -2873,7 +2861,7 @@ bool check_line_of_sight( int sx, int sy, int tx, int ty )
// Note that we are guaranteed to be within the player LOS range,
// so fallback is unnecessary.
ray_def ray;
- return find_ray( sx, sy, tx, ty, false, ray );
+ return find_ray( source, target, false, ray );
}
// When a mimic is hit by a ranged attack, it teleports away (the slow
@@ -2921,15 +2909,15 @@ static bool _isBouncy(bolt &beam, unsigned char gridtype)
return (false);
}
-static void _beam_explodes(bolt &beam, int x, int y)
+static void _beam_explodes(bolt &beam, const coord_def& p)
{
cloud_type cl_type;
// This will be the last thing this beam does. Set target_x
// and target_y to hold explosion co'ords.
- beam.target_x = x;
- beam.target_y = y;
+ beam.target_x = p.x;
+ beam.target_y = p.y;
// Generic explosion.
if (beam.is_explosion) // beam.flavour == BEAM_EXPLOSION || beam.flavour == BEAM_HOLY)
@@ -2994,7 +2982,7 @@ static void _beam_explodes(bolt &beam, int x, int y)
// cloud producer -- POISON BLAST
if (beam.name == "blast of poison")
{
- big_cloud( CLOUD_POISON, _whose_kill(beam), x, y, 0, 7 + random2(5) );
+ big_cloud(CLOUD_POISON, _whose_kill(beam), p.x, p.y, 0, 7 + random2(5));
return;
}
@@ -3002,13 +2990,13 @@ static void _beam_explodes(bolt &beam, int x, int y)
if (beam.name == "foul vapour")
{
cl_type = (beam.flavour == BEAM_MIASMA) ? CLOUD_MIASMA : CLOUD_STINK;
- big_cloud( cl_type, _whose_kill(beam), x, y, 0, 9 );
+ big_cloud( cl_type, _whose_kill(beam), p.x, p.y, 0, 9 );
return;
}
if (beam.name == "freezing blast")
{
- big_cloud( CLOUD_COLD, _whose_kill(beam), x, y,
+ big_cloud( CLOUD_COLD, _whose_kill(beam), p.x, p.y,
random_range(10, 15), 9 );
return;
}
@@ -3030,7 +3018,7 @@ static void _beam_explodes(bolt &beam, int x, int y)
}
}
-static bool _beam_term_on_target(bolt &beam, int x, int y)
+static bool _beam_term_on_target(bolt &beam, const coord_def& p)
{
if (beam.flavour == BEAM_LINE_OF_SIGHT)
{
@@ -3059,13 +3047,13 @@ static bool _beam_term_on_target(bolt &beam, int x, int y)
if (beam.name == "ball of vapour")
return (true);
- if (beam.aimed_at_spot && x == beam.target_x && y == beam.target_y)
+ if (beam.aimed_at_spot && p == beam.target())
return (true);
return (false);
}
-void beam_drop_object( bolt &beam, item_def *item, int x, int y )
+void beam_drop_object( bolt &beam, item_def *item, const coord_def& p )
{
ASSERT( item != NULL );
@@ -3074,40 +3062,39 @@ void beam_drop_object( bolt &beam, item_def *item, int x, int y )
return;
if (YOU_KILL(beam.thrower)
- && !thrown_object_destroyed(item, x, y, false)
+ && !thrown_object_destroyed(item, p, false)
|| MON_KILL(beam.thrower)
- && !mons_thrown_object_destroyed(item, x, y, false,
- beam.beam_source))
+ && !mons_thrown_object_destroyed(item, p, false, beam.beam_source))
{
if (item->sub_type == MI_THROWING_NET)
{
// Player or monster on position is caught in net.
- if (you.x_pos == x && you.y_pos == y && you.attribute[ATTR_HELD]
- || mgrd[x][y] != NON_MONSTER &&
- mons_is_caught(&menv[mgrd[x][y]]))
+ if (you.pos() == p && you.attribute[ATTR_HELD]
+ || mgrd(p) != NON_MONSTER &&
+ mons_is_caught(&menv[mgrd(p)]))
{
// If no trapping net found mark this one.
- if (get_trapping_net(x,y, true) == NON_ITEM)
+ if (get_trapping_net(p, true) == NON_ITEM)
set_item_stationary(*item);
}
}
- copy_item_to_grid( *item, x, y, 1 );
+ copy_item_to_grid( *item, p, 1 );
}
}
// Returns true if the beam hits the player, fuzzing the beam if necessary
// for monsters without see invis firing tracers at the player.
-static bool _found_player(const bolt &beam, int x, int y)
+static bool _found_player(const bolt &beam, const coord_def& p)
{
const bool needs_fuzz = (beam.is_tracer && !beam.can_see_invis
&& you.invisible() && !YOU_KILL(beam.thrower));
const int dist = needs_fuzz? 2 : 0;
- return (grid_distance(x, y, you.x_pos, you.y_pos) <= dist);
+ return (grid_distance(p, you.pos()) <= dist);
}
-int affect(bolt &beam, int x, int y, item_def *item)
+int affect(bolt &beam, const coord_def& p, item_def *item)
{
// Extra range used by hitting something.
int rangeUsed = 0;
@@ -3116,25 +3103,25 @@ int affect(bolt &beam, int x, int y, item_def *item)
if (beam.flavour == BEAM_LINE_OF_SIGHT)
return (0);
- if (grid_is_solid(grd[x][y]))
+ if (grid_is_solid(grd(p)))
{
if (beam.is_tracer) // Tracers always stop on walls.
return (BEAM_STOP);
- if (_affects_wall(beam, grd[x][y]))
- rangeUsed += _affect_wall(beam, x, y);
+ if (_affects_wall(beam, grd(p)))
+ rangeUsed += _affect_wall(beam, p);
// If it's still a wall, quit - we can't do anything else to a
// wall (but we still might be able to do something to any
// monster inside the wall). Otherwise effects (like clouds,
// etc.) are still possible.
- if (grid_is_solid(grd[x][y]))
+ if (grid_is_solid(grd(p)))
{
- int mid = mgrd[x][y];
+ int mid = mgrd(p);
if (mid != NON_MONSTER)
{
monsters *mon = &menv[mid];
- if (_affect_mon_in_wall(beam, NULL, x, y))
+ if (_affect_mon_in_wall(beam, NULL, p))
rangeUsed += _affect_monster( beam, mon, item );
else if (you.can_see(mon))
{
@@ -3148,7 +3135,7 @@ int affect(bolt &beam, int x, int y, item_def *item)
}
}
- // grd[x][y] will NOT be a wall for the remainder of this function.
+ // grd(p) will NOT be a wall for the remainder of this function.
// If not a tracer, affect items and place clouds.
if (!beam.is_tracer)
@@ -3156,12 +3143,12 @@ int affect(bolt &beam, int x, int y, item_def *item)
const int burn_power = (beam.is_explosion) ? 5 :
(beam.is_beam) ? 3 : 2;
- expose_items_to_element(beam.flavour, x, y, burn_power);
- rangeUsed += _affect_place_clouds(beam, x, y);
+ expose_items_to_element(beam.flavour, p, burn_power);
+ rangeUsed += _affect_place_clouds(beam, p);
}
// If player is at this location, try to affect unless term_on_target.
- if (_found_player(beam, x, y))
+ if (_found_player(beam, p))
{
// Done this way so that poison blasts affect the target once (via
// place_cloud) and explosion spells only affect the target once
@@ -3173,13 +3160,13 @@ int affect(bolt &beam, int x, int y, item_def *item)
rangeUsed += _affect_player( beam, item );
}
- if (_beam_term_on_target(beam, x, y))
+ if (_beam_term_on_target(beam, p))
return (BEAM_STOP);
}
// If there is a monster at this location, affect it.
// Submerged monsters aren't really there. -- bwr
- int mid = mgrd[x][y];
+ int mid = mgrd(p);
if (mid != NON_MONSTER)
{
monsters *mon = &menv[mid];
@@ -3197,7 +3184,7 @@ int affect(bolt &beam, int x, int y, item_def *item)
rangeUsed += _affect_monster( beam, &menv[mid], item );
}
- if (_beam_term_on_target(beam, x, y))
+ if (_beam_term_on_target(beam, p))
return (BEAM_STOP);
}
}
@@ -3244,34 +3231,34 @@ static bool _affects_wall(const bolt &beam, int wall)
}
// Returns amount of extra range used up by affectation of this wall.
-static int _affect_wall(bolt &beam, int x, int y)
+static int _affect_wall(bolt &beam, const coord_def& p)
{
int rangeUsed = 0;
// DIGGING
if (beam.flavour == BEAM_DIGGING)
{
- if (grd[x][y] == DNGN_STONE_WALL
- || grd[x][y] == DNGN_METAL_WALL
- || grd[x][y] == DNGN_PERMAROCK_WALL
- || grd[x][y] == DNGN_CLEAR_STONE_WALL
- || grd[x][y] == DNGN_CLEAR_PERMAROCK_WALL
- || !in_bounds(x, y))
+ if (grd(p) == DNGN_STONE_WALL
+ || grd(p) == DNGN_METAL_WALL
+ || grd(p) == DNGN_PERMAROCK_WALL
+ || grd(p) == DNGN_CLEAR_STONE_WALL
+ || grd(p) == DNGN_CLEAR_PERMAROCK_WALL
+ || !in_bounds(p))
{
return (0);
}
- if (grd[x][y] == DNGN_ROCK_WALL || grd[x][y] == DNGN_CLEAR_ROCK_WALL)
+ if (grd(p) == DNGN_ROCK_WALL || grd(p) == DNGN_CLEAR_ROCK_WALL)
{
- grd[x][y] = DNGN_FLOOR;
+ grd(p) = DNGN_FLOOR;
// Blood does not transfer onto floor.
- if (is_bloodcovered(x,y))
- env.map[x][y].property = FPROP_NONE;
+ if (is_bloodcovered(p))
+ env.map(p).property = FPROP_NONE;
if (!beam.msg_generated)
{
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
{
mpr("You hear a grinding noise.", MSGCH_SOUND);
beam.obvious_effect = true;
@@ -3288,7 +3275,7 @@ static int _affect_wall(bolt &beam, int x, int y)
// FIRE effect
if (_is_fiery(beam))
{
- const int wgrd = grd[x][y];
+ const int wgrd = grd(p);
if (wgrd != DNGN_WAX_WALL)
return (0);
@@ -3296,7 +3283,7 @@ static int _affect_wall(bolt &beam, int x, int y)
{
if (beam.flavour != BEAM_HELLFIRE)
{
- if (see_grid(x, y))
+ if (see_grid(p))
_beam_mpr(MSGCH_PLAIN,
"The wax appears to soften slightly.");
else if (player_can_smell())
@@ -3306,13 +3293,13 @@ static int _affect_wall(bolt &beam, int x, int y)
return (BEAM_STOP);
}
- grd[x][y] = DNGN_FLOOR;
- if (see_grid(x, y))
+ grd(p) = DNGN_FLOOR;
+ if (see_grid(p))
_beam_mpr(MSGCH_PLAIN, "The wax bubbles and burns!");
else if (player_can_smell())
_beam_mpr(MSGCH_PLAIN, "You smell burning wax.");
- place_cloud(CLOUD_FIRE, x, y, random2(10) + 15, _whose_kill(beam));
+ place_cloud(CLOUD_FIRE, p, random2(10) + 15, _whose_kill(beam));
beam.obvious_effect = true;
@@ -3322,14 +3309,14 @@ static int _affect_wall(bolt &beam, int x, int y)
// NUKE / DISRUPT
if (beam.flavour == BEAM_DISINTEGRATION || beam.flavour == BEAM_NUKE)
{
- int targ_grid = grd[x][y];
+ int targ_grid = grd(p);
if ((targ_grid == DNGN_ROCK_WALL || targ_grid == DNGN_WAX_WALL
|| targ_grid == DNGN_CLEAR_ROCK_WALL)
- && in_bounds(x, y))
+ && in_bounds(p))
{
- grd[ x ][ y ] = DNGN_FLOOR;
- if (!silenced(you.x_pos, you.y_pos))
+ grd(p) = DNGN_FLOOR;
+ if (!silenced(you.pos()))
{
mpr("You hear a grinding noise.", MSGCH_SOUND);
beam.obvious_effect = true;
@@ -3339,15 +3326,15 @@ static int _affect_wall(bolt &beam, int x, int y)
if (targ_grid == DNGN_ORCISH_IDOL
|| targ_grid == DNGN_GRANITE_STATUE)
{
- grd[x][y] = DNGN_FLOOR;
+ grd(p) = DNGN_FLOOR;
// Blood does not transfer onto floor.
- if (is_bloodcovered(x,y))
- env.map[x][y].property = FPROP_NONE;
+ if (is_bloodcovered(p))
+ env.map(p).property = FPROP_NONE;
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
{
- if (!see_grid( x, y ))
+ if (!see_grid( p ))
mpr("You hear a hideous screaming!", MSGCH_SOUND);
else
{
@@ -3355,7 +3342,7 @@ static int _affect_wall(bolt &beam, int x, int y)
MSGCH_SOUND);
}
}
- else if (see_grid(x,y))
+ else if (see_grid(p))
mpr("The statue twists and shakes as its substance crumbles away!");
if (targ_grid == DNGN_ORCISH_IDOL
@@ -3372,21 +3359,21 @@ static int _affect_wall(bolt &beam, int x, int y)
return (rangeUsed);
}
-static int _affect_place_clouds(bolt &beam, int x, int y)
+static int _affect_place_clouds(bolt &beam, const coord_def& p)
{
if (beam.in_explosion_phase)
{
- _affect_place_explosion_clouds( beam, x, y );
+ _affect_place_explosion_clouds( beam, p );
return (0); // return value irrelevant for explosions
}
// check for CLOUD HITS
- if (env.cgrid[x][y] != EMPTY_CLOUD) // hit a cloud
+ if (env.cgrid(p) != EMPTY_CLOUD) // hit a cloud
{
// polymorph randomly changes clouds in its path
if (beam.flavour == BEAM_POLYMORPH)
{
- env.cloud[ env.cgrid[x][y] ].type =
+ env.cloud[ env.cgrid(p) ].type =
static_cast<cloud_type>(1 + random2(8));
}
@@ -3394,7 +3381,7 @@ static int _affect_place_clouds(bolt &beam, int x, int y)
if (beam.name[0] == '0')
return (0);
- int clouty = env.cgrid[x][y];
+ int clouty = env.cgrid(p);
// fire cancelling cold & vice versa
if ((env.cloud[clouty].type == CLOUD_COLD
@@ -3403,8 +3390,8 @@ static int _affect_place_clouds(bolt &beam, int x, int y)
|| (env.cloud[clouty].type == CLOUD_FIRE
&& beam.flavour == BEAM_COLD))
{
- if (!silenced(x, y)
- && !silenced(you.x_pos, you.y_pos))
+ if (!silenced(p)
+ && !silenced(you.pos()))
{
mpr("You hear a sizzling sound!", MSGCH_SOUND);
}
@@ -3416,47 +3403,47 @@ static int _affect_place_clouds(bolt &beam, int x, int y)
// POISON BLAST
if (beam.name == "blast of poison")
- place_cloud( CLOUD_POISON, x, y, random2(4) + 2, _whose_kill(beam) );
+ place_cloud( CLOUD_POISON, p, random2(4) + 2, _whose_kill(beam) );
// FIRE/COLD over water/lava
- if (grd[x][y] == DNGN_LAVA && beam.flavour == BEAM_COLD
- || grid_is_watery(grd[x][y]) && _is_fiery(beam))
+ if (grd(p) == DNGN_LAVA && beam.flavour == BEAM_COLD
+ || grid_is_watery(grd(p)) && _is_fiery(beam))
{
- place_cloud( CLOUD_STEAM, x, y, 2 + random2(5), _whose_kill(beam) );
+ place_cloud( CLOUD_STEAM, p, 2 + random2(5), _whose_kill(beam) );
}
- if (beam.flavour == BEAM_COLD && grid_is_watery(grd[x][y]))
- place_cloud( CLOUD_COLD, x, y, 2 + random2(5), _whose_kill(beam) );
+ if (beam.flavour == BEAM_COLD && grid_is_watery(grd(p)))
+ place_cloud( CLOUD_COLD, p, 2 + random2(5), _whose_kill(beam) );
// GREAT BLAST OF COLD
if (beam.name == "great blast of cold")
- place_cloud( CLOUD_COLD, x, y, random2(5) + 3, _whose_kill(beam) );
+ place_cloud( CLOUD_COLD, p, random2(5) + 3, _whose_kill(beam) );
// BALL OF STEAM
if (beam.name == "ball of steam")
- place_cloud( CLOUD_STEAM, x, y, random2(5) + 2, _whose_kill(beam) );
+ place_cloud( CLOUD_STEAM, p, random2(5) + 2, _whose_kill(beam) );
if (beam.flavour == BEAM_MIASMA)
- place_cloud( CLOUD_MIASMA, x, y, random2(5) + 2, _whose_kill(beam) );
+ place_cloud( CLOUD_MIASMA, p, random2(5) + 2, _whose_kill(beam) );
// POISON GAS
if (beam.name == "poison gas")
- place_cloud( CLOUD_POISON, x, y, random2(4) + 3, _whose_kill(beam) );
+ place_cloud( CLOUD_POISON, p, random2(4) + 3, _whose_kill(beam) );
return (0);
}
-static void _affect_place_explosion_clouds(bolt &beam, int x, int y)
+static void _affect_place_explosion_clouds(bolt &beam, const coord_def& p)
{
cloud_type cl_type;
int duration;
// First check: FIRE/COLD over water/lava.
- if (grd[x][y] == DNGN_LAVA && beam.flavour == BEAM_COLD
- || grid_is_watery(grd[x][y]) && _is_fiery(beam))
+ if (grd(p) == DNGN_LAVA && beam.flavour == BEAM_COLD
+ || grid_is_watery(grd(p)) && _is_fiery(beam))
{
- place_cloud( CLOUD_STEAM, x, y, 2 + random2(5), _whose_kill(beam) );
+ place_cloud( CLOUD_STEAM, p, 2 + random2(5), _whose_kill(beam) );
return;
}
@@ -3500,17 +3487,17 @@ static void _affect_place_explosion_clouds(bolt &beam, int x, int y)
break;
}
- place_cloud( cl_type, x, y, duration, _whose_kill(beam) );
+ place_cloud( cl_type, p, duration, _whose_kill(beam) );
}
// then check for more specific explosion cloud types.
if (beam.name == "ice storm")
- place_cloud( CLOUD_COLD, x, y, 2 + random2avg(5, 2), _whose_kill(beam) );
+ place_cloud( CLOUD_COLD, p, 2 + random2avg(5, 2), _whose_kill(beam) );
if (beam.name == "stinking cloud")
{
duration = 1 + random2(4) + random2( (beam.ench_power / 50) + 1 );
- place_cloud( CLOUD_STINK, x, y, duration, _whose_kill(beam) );
+ place_cloud( CLOUD_STINK, p, duration, _whose_kill(beam) );
}
if (beam.name == "great blast of fire")
@@ -3520,9 +3507,9 @@ static void _affect_place_explosion_clouds(bolt &beam, int x, int y)
if (duration > 20)
duration = 20 + random2(4);
- place_cloud( CLOUD_FIRE, x, y, duration, _whose_kill(beam) );
+ place_cloud( CLOUD_FIRE, p, duration, _whose_kill(beam) );
- if (grd[x][y] == DNGN_FLOOR && mgrd[x][y] == NON_MONSTER
+ if (grd(p) == DNGN_FLOOR && mgrd(p) == NON_MONSTER
&& one_chance_in(4))
{
const god_type god =
@@ -3530,8 +3517,7 @@ static void _affect_place_explosion_clouds(bolt &beam, int x, int y)
: GOD_NO_GOD;
mons_place(
- mgen_data::hostile_at(
- MONS_FIRE_VORTEX, coord_def(x, y), 0, 0, false, god));
+ mgen_data::hostile_at(MONS_FIRE_VORTEX, p, 0, 0, false, god));
}
}
}
@@ -3571,8 +3557,7 @@ static void _beam_ouch(int dam, bolt &beam)
static bool _fuzz_invis_tracer(bolt &beem)
{
// Did the monster have a rough idea of where you are?
- int dist = grid_distance(beem.target_x, beem.target_y,
- you.x_pos, you.y_pos);
+ int dist = grid_distance(beem.target(), you.pos());
// No, ditch this.
if (dist > 2)
@@ -4191,7 +4176,7 @@ static int _affect_player( bolt &beam, item_def *item )
if (blood > you.hp)
blood = you.hp;
- bleed_onto_floor(you.x_pos, you.y_pos, -1, blood, true);
+ bleed_onto_floor(you.pos(), -1, blood, true);
}
hurted = check_your_resists( hurted, beam.flavour );
@@ -4406,7 +4391,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
else if ((beam.flavour == BEAM_DISINTEGRATION || beam.flavour == BEAM_NUKE)
&& mons_is_statue(mons_type) && !mons_is_icy(mons_type))
{
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
{
if (!see_grid( mon->x, mon->y ))
mpr("You hear a hideous screaming!", MSGCH_SOUND);
@@ -4472,11 +4457,8 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
{
if (YOU_KILL(beam.thrower))
{
- if (is_sanctuary(mon->x, mon->y)
- || is_sanctuary(you.x_pos, you.y_pos))
- {
+ if (is_sanctuary(mon->pos()) || is_sanctuary(you.pos()))
remove_sanctuary(true);
- }
set_attack_conducts(conducts, mon, player_monster_visible(mon));
@@ -4665,11 +4647,8 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
|| beam.aux_source == "reading a scroll of immolation"
&& !beam.effect_known);
- if (is_sanctuary(mon->x, mon->y)
- || is_sanctuary(you.x_pos, you.y_pos))
- {
+ if (is_sanctuary(mon->pos()) || is_sanctuary(you.pos()))
remove_sanctuary(true);
- }
set_attack_conducts(conducts, mon, !okay);
}
@@ -4743,7 +4722,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
{
// The player might hear something, if _they_ fired a missile
// (not beam).
- if (!silenced(you.x_pos, you.y_pos) && beam.flavour == BEAM_MISSILE
+ if (!silenced(you.pos()) && beam.flavour == BEAM_MISSILE
&& YOU_KILL(beam.thrower))
{
mprf(MSGCH_SOUND, "The %s hits something.", beam.name.c_str());
@@ -4773,7 +4752,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
if (blood > mon->hit_points)
blood = mon->hit_points;
- bleed_onto_floor(mon->x, mon->y, mon->type, blood, true);
+ bleed_onto_floor(mon->pos(), mon->type, blood, true);
}
// Now hurt monster.
@@ -5200,8 +5179,7 @@ static void _explosion1(bolt &pbolt)
{
int ex_size = 1;
// convenience
- int x = pbolt.target_x;
- int y = pbolt.target_y;
+ coord_def p = pbolt.target();
const char *seeMsg = NULL;
const char *hearMsg = NULL;
@@ -5305,11 +5283,11 @@ static void _explosion1(bolt &pbolt)
if (!pbolt.is_tracer && *seeMsg && *hearMsg)
{
// Check for see/hear/no msg.
- if (see_grid(x,y) || x == you.x_pos && y == you.y_pos)
+ if (see_grid(p) || p == you.pos())
mpr(seeMsg);
else
{
- if (silenced(x,y) || silenced(you.x_pos, you.y_pos))
+ if (silenced(p) || silenced(you.pos()))
pbolt.msg_generated = false;
else
mpr(hearMsg, MSGCH_SOUND);
@@ -5342,11 +5320,10 @@ int explosion( bolt &beam, bool hole_in_the_middle,
beam.target_x, beam.target_y);
ray.fullray_idx = -1; // to quiet valgrind
- find_ray( beam.source_x, beam.source_y, beam.target_x, beam.target_y,
- true, ray, 0, true );
+ find_ray( beam.source(), beam.target(), true, ray, 0, true );
// Can cast explosions out from statues or walls.
- if (ray.x() == beam.source_x && ray.y() == beam.source_y)
+ if (ray.pos() == beam.source())
{
max_dist--;
ray.advance(true);
@@ -5423,7 +5400,7 @@ int explosion( bolt &beam, bool hole_in_the_middle,
// Beam is now an explosion.
beam.in_explosion_phase = true;
- if (is_sanctuary(beam.target_x, beam.target_y))
+ if (is_sanctuary(beam.target()))
{
if (!beam.is_tracer && see_grid(beam.target()) && !beam.name.empty())
{
@@ -5446,7 +5423,7 @@ int explosion( bolt &beam, bool hole_in_the_middle,
r = MAX_EXPLOSION_RADIUS;
// make a noise
- noisy(10 + 5 * r, beam.target_x, beam.target_y);
+ noisy(10 + 5 * r, beam.target());
// set map to false
explode_map.init(false);
@@ -5456,7 +5433,7 @@ int explosion( bolt &beam, bool hole_in_the_middle,
// corners where a simple 'line of sight' isn't quite
// enough. This might be slow for really big explosions,
// as the recursion runs approximately as R^2.
- _explosion_map(beam, 0, 0, 0, 0, r);
+ _explosion_map(beam, coord_def(0, 0), 0, 0, r);
// Go through affected cells, drawing effect and
// calling affect() for each. Now, we get a bit
@@ -5477,7 +5454,7 @@ int explosion( bolt &beam, bool hole_in_the_middle,
{
// do center -- but only if its affected
if (!hole_in_the_middle)
- _explosion_cell(beam, 0, 0, drawing);
+ _explosion_cell(beam, coord_def(0, 0), drawing);
// do the rest of it
for (int rad = 1; rad <= r; rad ++)
@@ -5486,20 +5463,20 @@ int explosion( bolt &beam, bool hole_in_the_middle,
for (int ay = 1 - rad; ay <= rad - 1; ay += 1)
{
if (explode_map[-rad+9][ay+9])
- _explosion_cell(beam, -rad, ay, drawing);
+ _explosion_cell(beam, coord_def(-rad, ay), drawing);
if (explode_map[rad+9][ay+9])
- _explosion_cell(beam, rad, ay, drawing);
+ _explosion_cell(beam, coord_def(rad, ay), drawing);
}
// do top & bottom
for (int ax = -rad; ax <= rad; ax += 1)
{
if (explode_map[ax+9][-rad+9])
- _explosion_cell(beam, ax, -rad, drawing);
+ _explosion_cell(beam, coord_def(ax, -rad), drawing);
if (explode_map[ax+9][rad+9])
- _explosion_cell(beam, ax, rad, drawing);
+ _explosion_cell(beam, coord_def(ax, rad), drawing);
}
// new-- delay after every 'ring' {gdl}
@@ -5539,11 +5516,10 @@ int explosion( bolt &beam, bool hole_in_the_middle,
return (cells_seen);
}
-static void _explosion_cell(bolt &beam, int x, int y, bool drawOnly)
+static void _explosion_cell(bolt &beam, const coord_def& p, bool drawOnly)
{
bool random_beam = false;
- int realx = beam.target_x + x;
- int realy = beam.target_y + y;
+ coord_def realpos = beam.target() + p;
if (!drawOnly)
{
@@ -5555,7 +5531,7 @@ static void _explosion_cell(bolt &beam, int x, int y, bool drawOnly)
random_range(BEAM_FIRE, BEAM_ACID) );
}
- affect(beam, realx, realy);
+ affect(beam, realpos);
if (random_beam)
beam.flavour = BEAM_RANDOM;
@@ -5567,19 +5543,19 @@ static void _explosion_cell(bolt &beam, int x, int y, bool drawOnly)
if (drawOnly)
{
- int drawx = grid2viewX(realx);
- int drawy = grid2viewY(realy);
+ const coord_def drawpos = grid2view(realpos);
- if (see_grid(realx, realy) || realx == you.x_pos && realy == you.y_pos)
+ // XXX Don't you always see your own grid?
+ if (see_grid(realpos) || realpos == you.pos())
{
#ifdef USE_TILE
- if (in_los_bounds(drawx, drawy))
- TileDrawBolt(drawx-1, drawy-1, tileidx_bolt(beam));
+ if (in_los_bounds(drawpos))
+ TileDrawBolt(drawpos.x-1, drawpos.y-1, tileidx_bolt(beam));
#else
// bounds check
- if (in_los_bounds(drawx, drawy))
+ if (in_los_bounds(drawpos))
{
- cgotoxy(drawx, drawy, GOTO_DNGN);
+ cgotoxy(drawpos.x, drawpos.y, GOTO_DNGN);
put_colour_ch(
beam.colour == BLACK ? random_colour() : beam.colour,
dchar_glyph( DCHAR_EXPLOSION ) );
@@ -5589,54 +5565,58 @@ static void _explosion_cell(bolt &beam, int x, int y, bool drawOnly)
}
}
-static void _explosion_map( bolt &beam, int x, int y,
+static void _explosion_map( bolt &beam, const coord_def& p,
int count, int dir, int r )
{
// Check to see out of range.
- if (x*x + y*y > r*r + r)
+ if (p.x*p.x + p.y*p.y > r*r + r)
return;
// Check count.
if (count > 10*r)
return;
- const coord_def loc(beam.target_x + x, beam.target_y + y);
+ const coord_def loc(beam.target() + p);
// Make sure we haven't run off the map.
if (!map_bounds(loc))
return;
// Check sanctuary.
- if (is_sanctuary(loc.x, loc.y))
+ if (is_sanctuary(loc))
return;
// Check to see if we're blocked by something specifically, we're blocked
// by WALLS. Not statues, idols, etc.
- const int dngn_feat = grd(loc);
+ const dungeon_feature_type dngn_feat = grd(loc);
// Special case: Explosion originates from rock/statue
// (e.g. Lee's rapid deconstruction) - in this case, ignore
// solid cells at the center of the explosion.
if (dngn_feat <= DNGN_MAXWALL
- && (x != 0 || y != 0) && !_affects_wall(beam, dngn_feat))
+ && (p.x != 0 || p.y != 0) && !_affects_wall(beam, dngn_feat))
{
return;
}
// Hmm, I think we're ok.
- explode_map[x+9][y+9] = true;
+ explode_map(p + coord_def(9,9)) = true;
+
+ const coord_def spread[] = { coord_def(0, -1), coord_def( 0, 1),
+ coord_def(1, 0), coord_def(-1, 0) };
+ const int opdir[] = { 2, 1, 4, 3 };
// Now recurse in every direction except the one we came from.
- for (int i = 0; i < 4; i++)
+ const int spreadsize = ARRAYSZ(spread);
+ for (int i = 0; i < spreadsize; i++)
{
if (i+1 != dir)
{
int cadd = 5;
- if (x * spreadx[i] < 0 || y * spready[i] < 0)
+ if (p.x * spread[i].x < 0 || p.y * spread[i].y < 0)
cadd = 17;
- _explosion_map( beam, x + spreadx[i], y + spready[i],
- count + cadd, opdir[i], r );
+ _explosion_map( beam, p + spread[i], count + cadd, opdir[i], r );
}
}
}
diff --git a/crawl-ref/source/beam.h b/crawl-ref/source/beam.h
index 969d3199db..4f35b43bc8 100644
--- a/crawl-ref/source/beam.h
+++ b/crawl-ref/source/beam.h
@@ -172,6 +172,11 @@ public:
{
return (coord_def(target_x, target_y));
}
+
+ coord_def source() const
+ {
+ return (coord_def(source_x, source_y));
+ }
};
dice_def calc_dice( int num_dice, int max_damage );
@@ -230,7 +235,7 @@ bool poison_monster( monsters *monster, kill_category who,
void fire_tracer( const monsters *monster, struct bolt &pbolt,
bool explode_only = false );
-bool check_line_of_sight( int sx, int sy, int tx, int ty );
+bool check_line_of_sight( const coord_def& source, const coord_def& target );
/* ***********************************************************************
* called from: monstuff
@@ -244,8 +249,8 @@ bool zapping( zap_type ztype, int power, struct bolt &pbolt,
bool player_tracer( zap_type ztype, int power, struct bolt &pbolt,
int range = 0 );
-int affect(bolt &beam, int x, int y, item_def *item = NULL);
+int affect(bolt &beam, const coord_def& p, item_def *item = NULL);
-void beam_drop_object( bolt &beam, item_def *item, int x, int y );
+void beam_drop_object( bolt &beam, item_def *item, const coord_def& where );
#endif
diff --git a/crawl-ref/source/cloud.cc b/crawl-ref/source/cloud.cc
index 0aef61b1f0..b38e43525b 100644
--- a/crawl-ref/source/cloud.cc
+++ b/crawl-ref/source/cloud.cc
@@ -46,22 +46,23 @@ static unsigned char _actual_spread_rate(cloud_type type, int spread_rate)
}
}
-static void _new_cloud( int cloud, cloud_type type, int x, int y, int decay,
- kill_category whose, unsigned char spread_rate )
+static void _new_cloud( int cloud, cloud_type type, const coord_def& p,
+ int decay, kill_category whose,
+ unsigned char spread_rate )
{
ASSERT( env.cloud[ cloud ].type == CLOUD_NONE );
env.cloud[ cloud ].type = type;
env.cloud[ cloud ].decay = decay;
- env.cloud[ cloud ].x = x;
- env.cloud[ cloud ].y = y;
+ env.cloud[ cloud ].x = p.x;
+ env.cloud[ cloud ].y = p.y;
env.cloud[ cloud ].whose = whose;
env.cloud[ cloud ].spread_rate = spread_rate;
- env.cgrid[ x ][ y ] = cloud;
+ env.cgrid(p) = cloud;
env.cloud_no++;
}
-static void _place_new_cloud(cloud_type cltype, int x, int y, int decay,
+static void _place_new_cloud(cloud_type cltype, const coord_def& p, int decay,
kill_category whose, int spread_rate)
{
if (env.cloud_no >= MAX_CLOUDS)
@@ -72,7 +73,7 @@ static void _place_new_cloud(cloud_type cltype, int x, int y, int decay,
{
if (env.cloud[ci].type == CLOUD_NONE) // i.e., is empty
{
- _new_cloud( ci, cltype, x, y, decay, whose, spread_rate );
+ _new_cloud( ci, cltype, p, decay, whose, spread_rate );
break;
}
}
@@ -84,32 +85,28 @@ static int _spread_cloud(const cloud_struct &cloud)
cloud.decay > 20? 50 :
30;
int extra_decay = 0;
-
- for (int yi = -1; yi <= 1; ++yi)
+ radius_iterator ri(coord_def(cloud.x, cloud.y), 1, true, false, true);
+ for ( ; ri; ++ri )
{
- for (int xi = -1; xi <= 1; ++xi)
- {
- if ((!xi && !yi) || random2(100) >= spreadch)
- continue;
-
- const int x = cloud.x + xi;
- const int y = cloud.y + yi;
-
- if (!in_bounds(x, y)
- || env.cgrid[x][y] != EMPTY_CLOUD
- || grid_is_solid(grd[x][y])
- || is_sanctuary(x, y) && !is_harmless_cloud(cloud.type))
- continue;
+ if (random2(100) >= spreadch)
+ continue;
- int newdecay = cloud.decay / 2 + 1;
- if (newdecay >= cloud.decay)
- newdecay = cloud.decay - 1;
+ if (!in_bounds(*ri)
+ || env.cgrid(*ri) != EMPTY_CLOUD
+ || grid_is_solid(grd(*ri))
+ || is_sanctuary(*ri) && !is_harmless_cloud(cloud.type))
+ {
+ continue;
+ }
- _place_new_cloud( cloud.type, x, y, newdecay, cloud.whose,
- cloud.spread_rate );
+ int newdecay = cloud.decay / 2 + 1;
+ if (newdecay >= cloud.decay)
+ newdecay = cloud.decay - 1;
+
+ _place_new_cloud( cloud.type, *ri, newdecay, cloud.whose,
+ cloud.spread_rate );
- extra_decay += 8;
- }
+ extra_decay += 8;
}
return (extra_decay);
@@ -157,7 +154,7 @@ void manage_clouds(void)
}
expose_items_to_element(cloud2beam(env.cloud[cc].type),
- env.cloud[cc].x, env.cloud[cc].y, 2);
+ env.cloud[cc].pos(), 2);
_dissipate_cloud(cc, env.cloud[cc], dissipate);
}
@@ -167,8 +164,7 @@ void delete_cloud( int cloud )
{
if (env.cloud[ cloud ].type != CLOUD_NONE)
{
- const int cloud_x = env.cloud[ cloud ].x;
- const int cloud_y = env.cloud[ cloud ].y;
+ const coord_def cloud_pos = env.cloud[ cloud ].pos();
env.cloud[ cloud ].type = CLOUD_NONE;
env.cloud[ cloud ].decay = 0;
@@ -176,36 +172,36 @@ void delete_cloud( int cloud )
env.cloud[ cloud ].y = 0;
env.cloud[ cloud ].whose = KC_OTHER;
env.cloud[ cloud ].spread_rate = 0;
- env.cgrid[ cloud_x ][ cloud_y ] = EMPTY_CLOUD;
+ env.cgrid(cloud_pos) = EMPTY_CLOUD;
env.cloud_no--;
}
}
// The current use of this function is for shifting in the abyss, so
// that clouds get moved along with the rest of the map.
-void move_cloud( int cloud, int new_x, int new_y )
+void move_cloud( int cloud, const coord_def& newpos )
{
if (cloud != EMPTY_CLOUD)
{
const int old_x = env.cloud[ cloud ].x;
const int old_y = env.cloud[ cloud ].y;
- env.cgrid[ new_x ][ new_y ] = cloud;
- env.cloud[ cloud ].x = new_x;
- env.cloud[ cloud ].y = new_y;
+ env.cgrid(newpos) = cloud;
+ env.cloud[ cloud ].x = newpos.x;
+ env.cloud[ cloud ].y = newpos.y;
env.cgrid[ old_x ][ old_y ] = EMPTY_CLOUD;
}
}
// Places a cloud with the given stats assuming one doesn't already
// exist at that point.
-void check_place_cloud( cloud_type cl_type, int x, int y, int lifetime,
+void check_place_cloud( cloud_type cl_type, const coord_def& p, int lifetime,
kill_category whose, int spread_rate )
{
- if (!in_bounds(x, y) || env.cgrid[x][y] != EMPTY_CLOUD)
+ if (!in_bounds(p) || env.cgrid(p) != EMPTY_CLOUD)
return;
- place_cloud( cl_type, x, y, lifetime, whose, spread_rate );
+ place_cloud( cl_type, p, lifetime, whose, spread_rate );
}
int steam_cloud_damage(const cloud_struct &cloud)
@@ -223,17 +219,15 @@ int steam_cloud_damage(const cloud_struct &cloud)
// Places a cloud with the given stats. May delete old clouds to
// make way if there are too many on level. Will overwrite an old
// cloud under some circumstances.
-void place_cloud(cloud_type cl_type, int ctarget_x,
- int ctarget_y, int cl_range,
+void place_cloud(cloud_type cl_type, const coord_def& ctarget, int cl_range,
kill_category whose, int _spread_rate)
{
- if (is_sanctuary(ctarget_x, ctarget_y) && !is_harmless_cloud(cl_type))
+ if (is_sanctuary(ctarget) && !is_harmless_cloud(cl_type))
return;
int cl_new = -1;
- // more compact {dlb}
- const int target_cgrid = env.cgrid[ctarget_x][ctarget_y];
+ const int target_cgrid = env.cgrid(ctarget);
// that is, another cloud already there {dlb}
if (target_cgrid != EMPTY_CLOUD)
@@ -245,8 +239,8 @@ void place_cloud(cloud_type cl_type, int ctarget_x,
|| env.cloud[ target_cgrid ].type == CLOUD_MIST
|| env.cloud[ target_cgrid ].decay <= 20) //soon gone
{
- cl_new = env.cgrid[ ctarget_x ][ ctarget_y ];
- delete_cloud( env.cgrid[ ctarget_x ][ ctarget_y ] );
+ cl_new = env.cgrid(ctarget);
+ delete_cloud( env.cgrid(ctarget) );
}
else
{
@@ -283,7 +277,7 @@ void place_cloud(cloud_type cl_type, int ctarget_x,
// Create new cloud.
if (cl_new != -1)
{
- _new_cloud( cl_new, cl_type, ctarget_x, ctarget_y, cl_range * 10,
+ _new_cloud( cl_new, cl_type, ctarget, cl_range * 10,
whose, spread_rate );
}
else
@@ -293,7 +287,7 @@ void place_cloud(cloud_type cl_type, int ctarget_x,
{
if (env.cloud[ci].type == CLOUD_NONE) // ie is empty
{
- _new_cloud( ci, cl_type, ctarget_x, ctarget_y, cl_range * 10,
+ _new_cloud( ci, cl_type, ctarget, cl_range * 10,
whose, spread_rate );
break;
}
diff --git a/crawl-ref/source/cloud.h b/crawl-ref/source/cloud.h
index ff64583ea9..b4e5d229bf 100644
--- a/crawl-ref/source/cloud.h
+++ b/crawl-ref/source/cloud.h
@@ -38,11 +38,11 @@ cloud_type random_smoke_type();
cloud_type cloud_type_at(const coord_def &pos);
void delete_cloud( int cloud );
-void move_cloud( int cloud, int new_x, int new_y );
+void move_cloud( int cloud, const coord_def& newpos );
-void check_place_cloud( cloud_type cl_type, int x, int y, int lifetime,
+void check_place_cloud( cloud_type cl_type, const coord_def& p, int lifetime,
kill_category whose, int spread_rate = -1 );
-void place_cloud( cloud_type cl_type, int ctarget_x, int ctarget_y,
+void place_cloud( cloud_type cl_type, const coord_def& ctarget,
int cl_range, kill_category whose, int spread_rate = -1 );
void manage_clouds(void);
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 4ce700daa2..0de57979bd 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -1418,7 +1418,7 @@ void wizard_create_spec_object()
if (!is_deck(mitm[thing_created]))
item_colour( mitm[thing_created] );
- move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
+ move_item_to_grid( &thing_created, you.pos() );
if (thing_created != NON_ITEM)
{
@@ -4101,7 +4101,7 @@ static void _move_player(int x, int y)
if (!you.can_pass_through_feat(grd[x][y]))
grd[x][y] = DNGN_FLOOR;
- move_player_to_grid(x, y, false, true, true);
+ move_player_to_grid(coord_def(x, y), false, true, true);
}
static void _move_monster(int x, int y, int mid1)
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index ed25476877..71bdc6fcfd 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -1385,7 +1385,7 @@ static void _swap_monster_card(int power, deck_rarity_type rarity)
{
mpr("The net rips apart!");
you.attribute[ATTR_HELD] = 0;
- int net = get_trapping_net(you.x_pos, you.y_pos);
+ int net = get_trapping_net(you.pos());
if (net != NON_ITEM)
destroy_item(net);
}
@@ -1477,7 +1477,7 @@ static void _warpwright_card(int power, deck_rarity_type rarity)
const int rx = you.x_pos + dx;
const int ry = you.y_pos + dy;
- if (grd[rx][ry] == DNGN_FLOOR && trap_at_xy(rx,ry) == -1
+ if (grd[rx][ry] == DNGN_FLOOR && trap_at_xy(coord_def(rx,ry)) == -1
&& one_chance_in(++count))
{
fx = rx;
@@ -1492,7 +1492,7 @@ static void _warpwright_card(int power, deck_rarity_type rarity)
// Mark it discovered if enough power.
if (get_power_level(power, rarity) >= 1)
{
- const int i = trap_at_xy(fx, fy);
+ const int i = trap_at_xy(coord_def(fx, fy));
if (i != -1) // should always happen
grd[fx][fy] = trap_category(env.trap[i].type);
}
@@ -1525,12 +1525,12 @@ static void _flight_card(int power, deck_rarity_type rarity)
if (power_level == 2) // Stacks with the above.
{
- if (is_valid_shaft_level() && grd[you.x_pos][you.y_pos] == DNGN_FLOOR)
+ if (is_valid_shaft_level() && grd(you.pos()) == DNGN_FLOOR)
{
if (place_specific_trap(you.x_pos, you.y_pos, TRAP_SHAFT))
{
- const int i = trap_at_xy(you.x_pos, you.y_pos);
- grd[you.x_pos][you.y_pos] = trap_category(env.trap[i].type);
+ const int i = trap_at_xy(you.pos());
+ grd(you.pos()) = trap_category(env.trap[i].type);
mpr("A shaft materialises beneath you!");
}
}
@@ -1559,7 +1559,7 @@ static void _minefield_card(int power, deck_rarity_type rarity)
if (!in_bounds(rx, ry))
continue;
- if (grd[rx][ry] == DNGN_FLOOR && trap_at_xy(rx,ry) == -1
+ 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)
@@ -2566,7 +2566,7 @@ static void _summon_any_monster(int power, deck_rarity_type rarity)
monster_type cur_try;
do
{
- cur_try = random_monster_at_grid(you.x_pos + dx, you.y_pos + dy);
+ cur_try = random_monster_at_grid(you.pos() + coord_def(dx,dy));
}
while (mons_is_unique(cur_try));
diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc
index 7bc95d1429..0aec0b4f44 100644
--- a/crawl-ref/source/delay.cc
+++ b/crawl-ref/source/delay.cc
@@ -480,8 +480,7 @@ void stop_delay( bool stop_stair_travel )
else
{
mpr("All blood oozes out of the corpse!");
- bleed_onto_floor(you.x_pos, you.y_pos, corpse.plus, delay.duration,
- false);
+ bleed_onto_floor(you.pos(), corpse.plus, delay.duration, false);
turn_corpse_into_skeleton(corpse, 90);
}
did_god_conduct(DID_DRINK_BLOOD, 8);
@@ -1049,38 +1048,35 @@ static void _finish_delay(const delay_queue_item &delay)
mpr( "You finish merging with the rock." );
more(); // or the above message won't be seen
- const int pass_x = delay.parm1;
- const int pass_y = delay.parm2;
+ const coord_def pass(delay.parm1, delay.parm2);
- if (pass_x != 0 && pass_y != 0)
+ if (pass.x != 0 && pass.y != 0)
{
- switch (grd[ pass_x ][ pass_y ])
+ switch (grd(pass))
{
default:
- if (!you.can_pass_through_feat(grd[pass_x][pass_y]))
+ if (!you.can_pass_through_feat(grd(pass)))
ouch(1 + you.hp, 0, KILLED_BY_PETRIFICATION);
break;
case DNGN_SECRET_DOOR: // oughtn't happen
case DNGN_CLOSED_DOOR: // open the door
- grd[ pass_x ][ pass_y ] = DNGN_OPEN_DOOR;
+ grd(pass) = DNGN_OPEN_DOOR;
break;
}
// Move any monsters out of the way:
- int mon = mgrd[ pass_x ][ pass_y ];
+ int mon = mgrd(pass);
if (mon != NON_MONSTER)
{
+ monsters* m = &menv[mon];
// One square, a few squares, anywhere...
- if (!shift_monster(&menv[mon])
- && !monster_blink(&menv[mon]))
- {
- monster_teleport( &menv[mon], true, true );
- }
+ if (!shift_monster(m) && !monster_blink(m))
+ monster_teleport( m, true, true );
}
- move_player_to_grid(pass_x, pass_y, false, true, true);
+ move_player_to_grid(pass, false, true, true);
redraw_screen();
}
break;
@@ -1217,7 +1213,7 @@ static void _finish_delay(const delay_queue_item &delay)
}
if (!copy_item_to_grid( you.inv[ delay.parm1 ],
- you.x_pos, you.y_pos, delay.parm2,
+ you.pos(), delay.parm2,
true ))
{
mpr("Too many items on this level, not dropping the item.");
@@ -1772,7 +1768,7 @@ bool interrupt_activity( activity_interrupt_type ai,
{
// no monster will attack you inside a sanctuary,
// so presence of monsters won't matter
- if (is_sanctuary(you.x_pos, you.y_pos))
+ if (is_sanctuary(you.pos()))
return (false);
_monster_warning(ai, at, item.type);
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index b2f4a2d1cb..1e72b06d1f 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -1934,7 +1934,7 @@ static std::string _get_feature_description_wide(int feat)
void describe_feature_wide(int x, int y)
{
- std::string desc = feature_description(x, y);
+ std::string desc = feature_description(coord_def(x, y));
desc += "$$";
// Get rid of trailing .$$ before lookup
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index 00f1a45d5e..9c5fec135d 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -85,32 +85,32 @@ enum LOSSelect
LOS_NONE = 0xFFFF
};
-static void _describe_feature(int mx, int my, bool oos);
-static void _describe_cell(int mx, int my);
+static void _describe_feature(const coord_def& where, bool oos);
+static void _describe_cell(const coord_def& where);
-static bool _find_object( int x, int y, int mode, bool need_path, int range );
-static bool _find_monster( int x, int y, int mode, bool need_path, int range );
-static bool _find_feature( int x, int y, int mode, bool need_path, int range );
+static bool _find_object( const coord_def& where, int mode, bool need_path, int range );
+static bool _find_monster( const coord_def& where, int mode, bool need_path, int range );
+static bool _find_feature( const coord_def& where, int mode, bool need_path, int range );
#ifndef USE_TILE
-static bool _find_mlist( int x, int y, int mode, bool need_path, int range );
+static bool _find_mlist( const coord_def& where, int mode, bool need_path, int range );
#endif
-static char _find_square_wrapper( int tx, int ty,
+static char _find_square_wrapper( const coord_def& targ,
FixedVector<char, 2> &mfp, char direction,
- bool (*targ)(int, int, int, bool, int),
+ bool (*targ)(const coord_def&, int, bool, int),
bool need_path = false, int mode = TARG_ANY,
int range = -1, bool wrap = false,
int los = LOS_ANY);
-static char _find_square( int xps, int yps,
+static char _find_square( const coord_def& where,
FixedVector<char, 2> &mfp, int direction,
- bool (*targ)(int, int, int, bool, int),
+ bool (*targ)(const coord_def&, int, bool, int),
bool need_path, int mode = TARG_ANY, int range = -1,
bool wrap = false, int los = LOS_ANY);
static int _targeting_cmd_to_compass( command_type command );
-static void _describe_oos_square(int x, int y);
+static void _describe_oos_square(const coord_def& where);
static void _extend_move_to_edge(dist &moves);
void direction_choose_compass( dist& moves, targeting_behaviour *beh)
@@ -292,13 +292,13 @@ static bool _mon_submerged_in_water(const monsters *mon)
&& !mons_flies(mon));
}
-static bool _is_target_in_range(int x, int y, int range)
+static bool _is_target_in_range(const coord_def& where, int range)
{
// Range doesn't matter.
if (range == -1)
return (true);
- return (grid_distance(you.x_pos, you.y_pos, x, y) <= range);
+ return (grid_distance(you.pos(), where) <= range);
}
// We handle targeting for repeating commands and re-doing the
@@ -382,8 +382,7 @@ static void _direction_again(dist& moves, targeting_type restricts,
"square.");
return;
}
- else if (!_is_target_in_range(you.prev_grd_targ.x, you.prev_grd_targ.y,
- range))
+ else if (!_is_target_in_range(you.prev_grd_targ, range))
{
moves.isCancel = true;
@@ -396,8 +395,7 @@ static void _direction_again(dist& moves, targeting_type restricts,
moves.ty = you.prev_grd_targ.y;
ray_def ray;
- find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty, true, ray,
- 0, true);
+ find_ray(you.pos(), moves.target(), true, ray, 0, true);
moves.ray = ray;
}
else if (you.prev_targ == MHITYOU)
@@ -423,8 +421,7 @@ static void _direction_again(dist& moves, targeting_type restricts,
return;
}
- else if (!_is_target_in_range(you.prev_grd_targ.x, you.prev_grd_targ.y,
- range))
+ else if (!_is_target_in_range(you.prev_grd_targ, range))
{
moves.isCancel = true;
@@ -437,8 +434,7 @@ static void _direction_again(dist& moves, targeting_type restricts,
moves.ty = montarget->y;
ray_def ray;
- find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty, true, ray,
- 0, true);
+ find_ray(you.pos(), moves.target(), true, ray, 0, true);
moves.ray = ray;
}
@@ -560,7 +556,7 @@ void direction(dist& moves, targeting_type restricts,
// If we show the beam on startup, we have to initialise it.
if (show_beam)
- find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty, true, ray);
+ find_ray(you.pos(), moves.target(), true, ray);
bool skip_iter = false;
bool found_autotarget = false;
@@ -575,7 +571,7 @@ void direction(dist& moves, targeting_type restricts,
const monsters *montarget = &menv[you.prev_targ];
if (mons_near(montarget) && player_monster_visible(montarget)
&& !mons_friendly(montarget) // not made friendly since then
- && _is_target_in_range(montarget->x, montarget->y, range))
+ && _is_target_in_range(montarget->pos(), range))
{
found_autotarget = true;
moves.tx = montarget->x;
@@ -689,7 +685,7 @@ void direction(dist& moves, targeting_type restricts,
&& key_command <= CMD_TARGET_CYCLE_MLIST_END)
{
const int idx = key_command - CMD_TARGET_CYCLE_MLIST;
- if (_find_square_wrapper(moves.tx, moves.ty, monsfind_pos, 1,
+ if (_find_square_wrapper(moves.target(), monsfind_pos, 1,
_find_mlist, needs_path, idx, range,
Options.target_wrap))
{
@@ -785,7 +781,7 @@ void direction(dist& moves, targeting_type restricts,
#ifdef WIZARD
case CMD_TARGET_CYCLE_BEAM:
- show_beam = find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty,
+ show_beam = find_ray(you.pos(), moves.target(),
true, ray, (show_beam ? 1 : 0));
need_beam_redraw = true;
break;
@@ -806,7 +802,7 @@ void direction(dist& moves, targeting_type restricts,
break;
}
- show_beam = find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty,
+ show_beam = find_ray(you.pos(), moves.target(),
true, ray, 0, true);
need_beam_redraw = show_beam;
}
@@ -826,7 +822,7 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_FIND_DOWNSTAIR:
{
const int thing_to_find = _targeting_cmd_to_feature(key_command);
- if (_find_square_wrapper(moves.tx, moves.ty, objfind_pos, 1,
+ if (_find_square_wrapper(moves.target(), objfind_pos, 1,
_find_feature, needs_path, thing_to_find,
range, true, Options.target_los_first ?
LOS_FLIPVH : LOS_ANY))
@@ -925,7 +921,7 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_OBJ_CYCLE_BACK:
case CMD_TARGET_OBJ_CYCLE_FORWARD:
dir = (key_command == CMD_TARGET_OBJ_CYCLE_BACK) ? -1 : 1;
- if (_find_square_wrapper( moves.tx, moves.ty, objfind_pos, dir,
+ if (_find_square_wrapper( moves.target(), objfind_pos, dir,
_find_object, needs_path, TARG_ANY, range,
true, Options.target_los_first ?
(dir == 1? LOS_FLIPVH : LOS_FLIPHV)
@@ -942,7 +938,7 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_CYCLE_FORWARD:
case CMD_TARGET_CYCLE_BACK:
dir = (key_command == CMD_TARGET_CYCLE_BACK) ? -1 : 1;
- if (_find_square_wrapper( moves.tx, moves.ty, monsfind_pos, dir,
+ if (_find_square_wrapper( moves.target(), monsfind_pos, dir,
_find_monster, needs_path, mode, range,
Options.target_wrap))
{
@@ -1132,8 +1128,8 @@ void direction(dist& moves, targeting_type restricts,
if (old_tx != moves.tx || old_ty != moves.ty)
{
have_moved = true;
- show_beam = show_beam && find_ray(you.x_pos, you.y_pos, moves.tx,
- moves.ty, true, ray, 0, true);
+ show_beam = show_beam && find_ray(you.pos(), moves.target(),
+ true, ray, 0, true);
}
if (force_redraw)
@@ -1154,7 +1150,7 @@ void direction(dist& moves, targeting_type restricts,
#ifdef USE_TILE
// Tiles always need a beam redraw if show_beam is true (and valid...)
if (need_beam_redraw
- || show_beam && find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty,
+ || show_beam && find_ray(you.pos(), moves.target(),
true, ray, 0, true) )
{
#else
@@ -1174,7 +1170,7 @@ void direction(dist& moves, targeting_type restricts,
if (raycopy.pos() != you.pos())
{
// Sanity: don't loop forever if the ray is problematic
- if (!in_los(raycopy.x(), raycopy.y()))
+ if (!in_los(raycopy.pos()))
break;
draw_ray_glyph(raycopy.pos(), MAGENTA, '*',
@@ -1205,10 +1201,10 @@ void direction(dist& moves, targeting_type restricts,
void terse_describe_square(const coord_def &c)
{
- if (!see_grid(c.x, c.y))
- _describe_oos_square(c.x, c.y);
+ if (!see_grid(c))
+ _describe_oos_square(c);
else if (in_bounds(c) )
- _describe_cell(c.x, c.y);
+ _describe_cell(c);
}
void full_describe_square(const coord_def &c)
@@ -1273,32 +1269,36 @@ static void _extend_move_to_edge(dist &moves)
// there's a stash on the square, announces the top item and number
// of items, otherwise, if there's a stair that's in the travel
// cache and noted in the Dungeon (O)verview, names the stair.
-static void _describe_oos_square(int x, int y)
+static void _describe_oos_square(const coord_def& where)
{
mpr("You can't see that place.", MSGCH_EXAMINE_FILTER);
- if (!in_bounds(x, y) || !is_terrain_seen(x, y))
+ if (!in_bounds(where) || !is_terrain_seen(where))
return;
- describe_stash(x, y);
- _describe_feature(x, y, true);
+ describe_stash(where.x, where.y);
+ _describe_feature(where, true);
}
bool in_vlos(int x, int y)
{
- return (in_los_bounds(x, y)
- && (env.show(view2show(coord_def(x, y)))
- || coord_def(x, y) == grid2view(you.pos())));
+ return in_vlos(coord_def(x,y));
}
bool in_vlos(const coord_def &pos)
{
- return (in_vlos(pos.x, pos.y));
+ return (in_los_bounds(pos) && (env.show(view2show(pos))
+ || pos == grid2view(you.pos())));
}
bool in_los(int x, int y)
{
- return (in_vlos(grid2view(coord_def(x, y))));
+ return in_los(coord_def(x,y));
+}
+
+bool in_los(const coord_def& pos)
+{
+ return (in_vlos(grid2view(pos)));
}
static bool _mons_is_valid_target(monsters *mon, int mode, int range)
@@ -1326,15 +1326,15 @@ static bool _mons_is_valid_target(monsters *mon, int mode, int range)
}
#ifndef USE_TILE
-static bool _find_mlist( int x, int y, int idx, bool need_path, int range = -1)
+static bool _find_mlist( const coord_def& where, int idx, bool need_path, int range = -1)
{
if ((int) mlist.size() <= idx)
return (false);
- if (!_is_target_in_range(x, y, range) || !in_los(x,y))
+ if (!_is_target_in_range(where, range) || !in_los(where))
return (false);
- const int targ_mon = mgrd[ x ][ y ];
+ const int targ_mon = mgrd(where);
if (targ_mon == NON_MONSTER)
return (false);
@@ -1385,28 +1385,25 @@ static bool _find_mlist( int x, int y, int idx, bool need_path, int range = -1)
}
#endif
-static bool _find_monster( int x, int y, int mode, bool need_path,
+static bool _find_monster( const coord_def& where, int mode, bool need_path,
int range = -1)
{
// Target the player for friendly and general spells.
- if ((mode == TARG_FRIEND || mode == TARG_ANY)
- && x == you.x_pos && y == you.y_pos)
- {
+ if ((mode == TARG_FRIEND || mode == TARG_ANY) && where == you.pos())
return (true);
- }
// Don't target out of range.
- if (!_is_target_in_range(x, y, range))
+ if (!_is_target_in_range(where, range))
return (false);
- const int targ_mon = mgrd[ x ][ y ];
+ const int targ_mon = mgrd(where);
// No monster or outside LOS.
- if (targ_mon == NON_MONSTER || !in_los(x,y))
+ if (targ_mon == NON_MONSTER || !in_los(where))
return (false);
// Monster in LOS but only via glass walls, so no direct path.
- if (need_path && !see_grid_no_trans(x,y))
+ if (need_path && !see_grid_no_trans(where))
return (false);
monsters *mon = &menv[targ_mon];
@@ -1430,22 +1427,22 @@ static bool _find_monster( int x, int y, int mode, bool need_path,
|| !mons_class_flag( menv[targ_mon].type, M_NO_EXP_GAIN ));
}
-static bool _find_feature( int x, int y, int mode,
+static bool _find_feature( const coord_def& where, int mode,
bool /* need_path */, int /* range */)
{
// The stair need not be in LOS if the square is mapped.
- if (!in_los(x, y) && (!Options.target_oos || !is_terrain_seen(x, y)))
+ if (!in_los(where) && (!Options.target_oos || !is_terrain_seen(where)))
return (false);
- return is_feature(mode, x, y);
+ return is_feature(mode, where);
}
-static bool _find_object(int x, int y, int mode,
+static bool _find_object(const coord_def& where, int mode,
bool /* need_path */, int /* range */)
{
// First, check for mimics.
bool is_mimic = false;
- const int mons = mgrd[ x ][ y ];
+ const int mons = mgrd(where);
if (mons != NON_MONSTER
&& player_monster_visible( &(menv[mons]) )
&& mons_is_mimic(menv[mons].type)
@@ -1454,12 +1451,12 @@ static bool _find_object(int x, int y, int mode,
is_mimic = true;
}
- const int item = igrd[x][y];
+ const int item = igrd(where);
if (item == NON_ITEM && !is_mimic)
return (false);
- return (in_los(x, y) || Options.target_oos && is_terrain_seen(x, y)
- && (is_stash(x, y) || is_mimic));
+ return (in_los(where) || Options.target_oos && is_terrain_seen(where)
+ && (is_stash(where.x,where.y) || is_mimic));
}
static int _next_los(int dir, int los, bool wrap)
@@ -1513,9 +1510,9 @@ bool in_viewport_bounds(int x, int y)
return crawl_view.in_view_viewport(coord_def(x, y));
}
-bool in_los_bounds(int x, int y)
+bool in_los_bounds(const coord_def& p)
{
- return crawl_view.in_view_los(coord_def(x, y));
+ return crawl_view.in_view_los(p);
}
//---------------------------------------------------------------
@@ -1532,9 +1529,9 @@ bool in_los_bounds(int x, int y)
// monsters will be targeted.
//
//---------------------------------------------------------------
-static char _find_square( int xps, int yps,
+static char _find_square( const coord_def& where,
FixedVector<char, 2> &mfp, int direction,
- bool (*find_targ)( int x, int y, int mode,
+ bool (*find_targ)( const coord_def& wh, int mode,
bool need_path, int range ),
bool need_path, int mode, int range, bool wrap,
int los )
@@ -1542,8 +1539,8 @@ static char _find_square( int xps, int yps,
// the day will come when [unsigned] chars will be consigned to
// the fires of Gehenna. Not quite yet, though.
- int temp_xps = xps;
- int temp_yps = yps;
+ int temp_xps = where.x;
+ int temp_yps = where.y;
int x_change = 0;
int y_change = 0;
@@ -1556,12 +1553,12 @@ static char _find_square( int xps, int yps,
if (los == LOS_FLIPVH || los == LOS_FLIPHV)
{
- if (in_los_bounds(xps, yps))
+ if (in_los_bounds(where))
{
// We've been told to flip between visible/hidden, so we
// need to find what we're currently on.
- const bool vis = (env.show(view2show(coord_def(xps, yps)))
- || view2grid(coord_def(xps, yps)) == you.pos());
+ const bool vis = (env.show(view2show(where))
+ || view2grid(where) == you.pos());
if (wrap && (vis != (los == LOS_FLIPVH)) == (direction == 1))
{
@@ -1601,20 +1598,20 @@ static char _find_square( int xps, int yps,
{
if (direction == 1 && temp_xps == minx && temp_yps == maxy)
{
- if (find_targ(you.x_pos, you.y_pos, mode, need_path, range))
+ if (find_targ(you.pos(), mode, need_path, range))
{
mfp[0] = ctrx;
mfp[1] = ctry;
return (1);
}
- return _find_square(ctrx, ctry, mfp, direction, find_targ,
- need_path, mode, range, false,
+ return _find_square(coord_def(ctrx, ctry), mfp, direction,
+ find_targ, need_path, mode, range, false,
_next_los(direction, los, wrap));
}
if (direction == -1 && temp_xps == ctrx && temp_yps == ctry)
{
- return _find_square(minx, maxy, mfp, direction, find_targ,
- need_path, mode, range, false,
+ return _find_square(coord_def(minx, maxy), mfp, direction,
+ find_targ, need_path, mode, range, false,
_next_los(direction, los, wrap));
}
@@ -1739,7 +1736,7 @@ static char _find_square( int xps, int yps,
if ((onlyVis || onlyHidden) && onlyVis != in_los(targ_x, targ_y))
continue;
- if (find_targ(targ_x, targ_y, mode, need_path, range))
+ if (find_targ(coord_def(targ_x, targ_y), mode, need_path, range))
{
mfp[0] = temp_xps;
mfp[1] = temp_yps;
@@ -1748,23 +1745,24 @@ static char _find_square( int xps, int yps,
}
return (direction == 1?
- _find_square(ctrx, ctry, mfp, direction, find_targ, need_path, mode,
- range, false, _next_los(direction, los, wrap))
- : _find_square(minx, maxy, mfp, direction, find_targ, need_path, mode,
- range, false, _next_los(direction, los, wrap)));
+ _find_square(coord_def(ctrx, ctry), mfp, direction, find_targ, need_path,
+ mode, range, false, _next_los(direction, los, wrap))
+ : _find_square(coord_def(minx, maxy), mfp, direction, find_targ,
+ need_path, mode, range, false,
+ _next_los(direction, los, wrap)));
}
// XXX Unbelievably hacky. And to think that my goal was to clean up the code.
// Identical to find_square, except that input (tx, ty) and output
// (mfp) are in grid coordinates rather than view coordinates.
-static char _find_square_wrapper( int tx, int ty,
+static char _find_square_wrapper( const coord_def& targ,
FixedVector<char, 2> &mfp, char direction,
- bool (*find_targ)(int x, int y, int mode,
+ bool (*find_targ)(const coord_def& where, int mode,
bool need_path, int range),
bool need_path, int mode, int range,
bool wrap, int los )
{
- const char r = _find_square(grid2viewX(tx), grid2viewY(ty), mfp,
+ const char r = _find_square(grid2view(targ), mfp,
direction, find_targ, need_path, mode, range,
wrap, los);
mfp[0] = view2gridX(mfp[0]);
@@ -1772,14 +1770,14 @@ static char _find_square_wrapper( int tx, int ty,
return r;
}
-static void _describe_feature(int mx, int my, bool oos)
+static void _describe_feature(const coord_def& where, bool oos)
{
- if (oos && !is_terrain_seen(mx, my))
+ if (oos && !is_terrain_seen(where))
return;
- dungeon_feature_type grid = grd[mx][my];
+ dungeon_feature_type grid = grd(where);
if ( grid == DNGN_SECRET_DOOR )
- grid = grid_secret_door_appearance(mx, my);
+ grid = grid_secret_door_appearance(where);
std::string desc = feature_description(grid);
if (desc.length())
@@ -1837,8 +1835,7 @@ void describe_floor()
break;
}
- feat = feature_description(you.x_pos, you.y_pos,
- is_bloodcovered(you.x_pos, you.y_pos),
+ feat = feature_description(you.pos(), is_bloodcovered(you.pos()),
DESC_NOCAP_A, false);
if (feat.empty())
return;
@@ -2156,17 +2153,17 @@ static bool _interesting_feature(dungeon_feature_type feat)
}
#endif
-std::string feature_description(int mx, int my, bool bloody,
+std::string feature_description(const coord_def& where, bool bloody,
description_level_type dtype, bool add_stop)
{
- dungeon_feature_type grid = grd[mx][my];
+ dungeon_feature_type grid = grd(where);
if ( grid == DNGN_SECRET_DOOR )
- grid = grid_secret_door_appearance(mx, my);
+ grid = grid_secret_door_appearance(where);
if ( grid == DNGN_OPEN_DOOR || grid == DNGN_CLOSED_DOOR )
{
std::set<coord_def> all_door;
- find_connected_identical(coord_def(mx, my), grd[mx][my], all_door);
+ find_connected_identical(where, grd(where), all_door);
const char *adj, *noun;
get_door_description(all_door.size(), &adj, &noun);
@@ -2185,15 +2182,15 @@ std::string feature_description(int mx, int my, bool bloody,
case DNGN_TRAP_MECHANICAL:
case DNGN_TRAP_MAGICAL:
case DNGN_TRAP_NATURAL:
- return (feature_description(grid, trap_type_at_xy(mx, my), bloody,
+ return (feature_description(grid, trap_type_at_xy(where), bloody,
dtype, add_stop));
case DNGN_ENTER_SHOP:
- return (shop_name(mx, my, add_stop));
+ return (shop_name(where, add_stop));
case DNGN_ENTER_PORTAL_VAULT:
return (_feature_do_grammar(
dtype, add_stop, false,
- _marker_feature_description(coord_def(mx, my))));
+ _marker_feature_description(where)));
default:
return (feature_description(grid, NUM_TRAPS, bloody, dtype, add_stop));
}
@@ -2510,19 +2507,19 @@ std::string get_monster_desc(const monsters *mon, bool full_desc,
return desc;
}
-static void _describe_cell(int mx, int my)
+static void _describe_cell(const coord_def& where)
{
bool mimic_item = false;
bool monster_described = false;
bool cloud_described = false;
bool item_described = false;
- if (mx == you.x_pos && my == you.y_pos)
+ if (where == you.pos())
mpr("You.", MSGCH_EXAMINE_FILTER);
- if (mgrd[mx][my] != NON_MONSTER)
+ if (mgrd(where) != NON_MONSTER)
{
- int i = mgrd[mx][my];
+ int i = mgrd(where);
if (_mon_submerged_in_water(&menv[i]))
{
@@ -2568,12 +2565,12 @@ static void _describe_cell(int mx, int my)
look_clouds:
#endif
- if (is_sanctuary(mx, my))
+ if (is_sanctuary(where))
mpr("This square lies inside a sanctuary.");
- if (env.cgrid[mx][my] != EMPTY_CLOUD)
+ if (env.cgrid(where) != EMPTY_CLOUD)
{
- const int cloud_inspected = env.cgrid[mx][my];
+ const int cloud_inspected = env.cgrid(where);
const cloud_type ctype = (cloud_type) env.cloud[cloud_inspected].type;
mprf(MSGCH_EXAMINE, "There is a cloud of %s here.",
@@ -2582,7 +2579,7 @@ static void _describe_cell(int mx, int my)
cloud_described = true;
}
- int targ_item = igrd[ mx ][ my ];
+ int targ_item = igrd(where);
if (targ_item != NON_ITEM)
{
@@ -2609,24 +2606,23 @@ static void _describe_cell(int mx, int my)
}
bool bloody = false;
- if (is_bloodcovered(mx, my))
+ if (is_bloodcovered(where))
bloody = true;
- std::string feature_desc = feature_description(mx, my, bloody);
+ std::string feature_desc = feature_description(where, bloody);
#ifdef DEBUG_DIAGNOSTICS
std::string marker;
- if (map_marker *mark = env.markers.find(coord_def(mx, my), MAT_ANY))
+ if (map_marker *mark = env.markers.find(where, MAT_ANY))
{
std::string desc = mark->debug_describe();
if (desc.empty())
desc = "?";
marker = " (" + desc + ")";
}
- const std::string traveldest =
- _stair_destination_description(coord_def(mx, my));
- const dungeon_feature_type feat = grd[mx][my];
- mprf(MSGCH_DIAGNOSTICS, "(%d,%d): %s - %s (%d/%s)%s%s", mx, my,
- stringize_glyph(get_screen_glyph(mx, my)).c_str(),
+ const std::string traveldest = _stair_destination_description(where);
+ const dungeon_feature_type feat = grd(where);
+ mprf(MSGCH_DIAGNOSTICS, "(%d,%d): %s - %s (%d/%s)%s%s", where.x, where.y,
+ stringize_glyph(get_screen_glyph(where)).c_str(),
feature_desc.c_str(),
feat,
dungeon_feature_name(feat),
@@ -2644,7 +2640,7 @@ static void _describe_cell(int mx, int my)
}
else
{
- const dungeon_feature_type feat = grd[mx][my];
+ const dungeon_feature_type feat = grd(where);
if (_interesting_feature(feat))
{
diff --git a/crawl-ref/source/directn.h b/crawl-ref/source/directn.h
index 557962186f..ed0bfd2484 100644
--- a/crawl-ref/source/directn.h
+++ b/crawl-ref/source/directn.h
@@ -153,9 +153,10 @@ void direction( dist &moves, targeting_type restricts = DIR_NONE,
bool may_target_monster = true, const char *prompt = NULL,
targeting_behaviour *mod = NULL, bool cancel_at_self = false );
-bool in_los_bounds(int x, int y);
+bool in_los_bounds(const coord_def& p);
bool in_viewport_bounds(int x, int y);
bool in_los(int x, int y);
+bool in_los(const coord_def &pos);
bool in_vlos(int x, int y);
bool in_vlos(const coord_def &pos);
@@ -168,7 +169,7 @@ std::string get_monster_desc(const monsters *mon,
int dos_direction_unmunge(int doskey);
-std::string feature_description(int mx, int my, bool bloody = false,
+std::string feature_description(const coord_def& where, bool bloody = false,
description_level_type dtype = DESC_CAP_A,
bool add_stop = true);
std::string raw_feature_description(dungeon_feature_type grid,
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 86df6e4b0f..06f85b3318 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1677,7 +1677,7 @@ bool acquirement(object_class_type class_wanted, int agent,
randart_name(thing, false);
}
}
- move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
+ move_item_to_grid( &thing_created, you.pos() );
// This should never actually be NON_ITEM because of the way
// move_item_to_grid works (doesn't create a new item ever),
@@ -1890,7 +1890,7 @@ void yell(bool force)
if (force)
{
mprf("A %s rips itself from your throat!", shout_verb.c_str());
- noisy(noise_level, you.x_pos, you.y_pos);
+ noisy(noise_level, you.pos());
return;
}
@@ -1926,7 +1926,7 @@ void yell(bool force)
case '!': // for players using the old keyset
case 't':
mprf(MSGCH_SOUND, "You %s for attention!", shout_verb.c_str());
- noisy(noise_level, you.x_pos, you.y_pos);
+ noisy(noise_level, you.pos());
you.turn_is_over = true;
return;
@@ -2011,7 +2011,7 @@ void yell(bool force)
if (mons_targd != MHITNOT && mons_targd != MHITYOU)
mpr("Attack!");
- noisy(10, you.x_pos, you.y_pos);
+ noisy(10, you.pos());
} // end yell()
bool forget_inventory(bool quiet)
@@ -2099,7 +2099,7 @@ bool vitrify_area(int radius)
static void _hell_effects()
{
- if (is_sanctuary(you.x_pos, you.y_pos))
+ if (is_sanctuary(you.pos()))
{
mpr("Zin's power protects you from Hell's scourges!", MSGCH_GOD);
return;
@@ -2475,7 +2475,7 @@ void handle_time(long time_delta)
// the original roll of 150 for 4.1.2, but I think players are
// sufficiently used to beta 26's unkindness that we can use a lower
// roll.)
- if (is_sanctuary(you.x_pos, you.y_pos)
+ if (is_sanctuary(you.pos())
&& you.magic_contamination >= 5
&& x_chance_in_y(you.magic_contamination + 1, 25))
{
@@ -2890,20 +2890,21 @@ static void _maybe_restart_fountain_flow(const int x, const int y,
set_envmap_obj(x, y, grd[x][y]);
// Clean bloody floor.
- if (is_bloodcovered(x,y))
+ if (is_bloodcovered(coord_def(x,y)))
env.map[x][y].property = FPROP_NONE;
// Chance of cleaning adjacent squares.
for (int i = -1; i <= 1; i++)
+ {
for (int j = -1; j <= 1; j++)
{
- if (is_bloodcovered(x+i,y+j)
- && one_chance_in(5))
- {
- env.map[x+i][y+j].property = FPROP_NONE;
- }
+ if (is_bloodcovered(coord_def(x+i,y+j))
+ && one_chance_in(5))
+ {
+ env.map[x+i][y+j].property = FPROP_NONE;
+ }
}
-
+ }
return;
}
}
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index a144cc871b..9953838a19 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -590,8 +590,7 @@ public:
int x_pos;
int y_pos;
- int prev_move_x;
- int prev_move_y;
+ coord_def prev_move;
int hunger;
FixedVector<char, NUM_EQUIP> equip;
@@ -787,7 +786,6 @@ public:
void moveto(int x, int y);
void moveto(const coord_def &c);
- coord_def prev_move() const;
void reset_prev_move();
bool in_water() const;
@@ -1318,6 +1316,7 @@ struct cloud_struct
kill_category whose;
killer_type beam_thrower() const;
+ coord_def pos() const { return coord_def(x,y); }
};
struct shop_struct
@@ -1329,6 +1328,7 @@ struct shop_struct
unsigned char level;
FixedVector<unsigned char, 3> keeper_name;
+ coord_def pos() const { return coord_def(x,y); }
};
struct trap_struct
@@ -1336,6 +1336,8 @@ struct trap_struct
unsigned char x;
unsigned char y;
trap_type type;
+
+ coord_def pos() const { return coord_def(x,y); }
};
struct map_cell
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index 5f6b47c671..5fe29481fd 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -639,11 +639,7 @@ bool melee_attack::attack()
if (env.sanctuary_time > 0 && retval && !cancel_attack
&& attacker != defender && !attacker->confused())
{
- const coord_def atk_pos = attacker->pos();
- const coord_def def_pos = defender->pos();
-
- if (is_sanctuary(atk_pos.x, atk_pos.y)
- || is_sanctuary(def_pos.x, def_pos.y))
+ if (is_sanctuary(attacker->pos()) || is_sanctuary(defender->pos()))
{
if (attacker->atype() == ACT_PLAYER || mons_friendly(atk))
remove_sanctuary(true);
@@ -826,7 +822,7 @@ bool melee_attack::player_attack()
if (blood > defender->stat_hp())
blood = defender->stat_hp();
- bleed_onto_floor(where.x, where.y, defender->id(), blood, true);
+ bleed_onto_floor(where, defender->id(), blood, true);
}
if (damage_done > 0 || !defender_visible && !shield_blocked)
@@ -2428,10 +2424,7 @@ bool melee_attack::chop_hydra_head( int dam,
coord_def pos = defender->pos();
if (!mons_is_summoned(def))
- {
- bleed_onto_floor(pos.x, pos.y, defender->id(),
- def->hit_points, true);
- }
+ bleed_onto_floor(pos, defender->id(), def->hit_points, true);
defender->hurt(attacker, def->hit_points);
}
@@ -3125,9 +3118,7 @@ bool melee_attack::mons_attack_mons()
const coord_def def_pos = def->pos();
// Self-attacks never violate sanctuary.
- if ((is_sanctuary(atk_pos.x, atk_pos.y)
- || is_sanctuary(def_pos.x, def_pos.y))
- && atk != def)
+ if ((is_sanctuary(atk_pos) || is_sanctuary(def_pos)) && atk != def)
{
// Friendly monsters should only violate sanctuary if explicitly
// ordered to do so by the player.
@@ -3950,7 +3941,7 @@ void melee_attack::mons_perform_attack_rounds()
if (blood > defender->stat_hp())
blood = defender->stat_hp();
- bleed_onto_floor(pos.x, pos.y, type, blood, true);
+ bleed_onto_floor(pos, type, blood, true);
}
if (decapitate_hydra(damage_done,
attacker->damage_type(attack_number)))
diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc
index 19eb0173e7..4508cc3952 100644
--- a/crawl-ref/source/it_use3.cc
+++ b/crawl-ref/source/it_use3.cc
@@ -240,7 +240,7 @@ void special_wielded()
}
if (makes_noise)
- noisy(25, you.x_pos, you.y_pos);
+ noisy(25, you.pos());
if (old_plus != you.inv[wpn].plus
|| old_plus2 != you.inv[wpn].plus2
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 643c115589..d34fed28a2 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -2580,9 +2580,9 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
if (teleport)
{
// Violating encapsulation somewhat...oh well.
- hit = (affect(pbolt, pbolt.target_x, pbolt.target_y, &item) != 0);
+ hit = (affect(pbolt, pbolt.target(), &item) != 0);
if (acc_bonus != DEBUG_COOKIE)
- beam_drop_object(pbolt, &item, pbolt.target_x, pbolt.target_y);
+ beam_drop_object(pbolt, &item, pbolt.target());
}
else
{
@@ -2593,11 +2593,8 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
fire_beam(pbolt, &item, !did_return);
// The item can be destroyed before returning.
- if (did_return && thrown_object_destroyed(&item, pbolt.target_x,
- pbolt.target_y, true))
- {
+ if (did_return && thrown_object_destroyed(&item, pbolt.target(), true))
did_return = false;
- }
}
if (did_return)
@@ -2632,7 +2629,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
// Throwing and blowguns are silent...
if (projected == LRET_LAUNCHED && lnchType != WPN_BLOWGUN)
- noisy(6, you.x_pos, you.y_pos);
+ noisy(6, you.pos());
// ...but any monster nearby can see that something has been thrown.
alert_nearby_monsters();
@@ -2642,7 +2639,8 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
return (hit);
}
-bool thrown_object_destroyed( item_def *item, int x, int y, bool returning )
+bool thrown_object_destroyed( item_def *item, const coord_def& where,
+ bool returning )
{
ASSERT( item != NULL );
@@ -2675,7 +2673,7 @@ bool thrown_object_destroyed( item_def *item, int x, int y, bool returning )
}
destroyed = (chance == 0) ? false : one_chance_in(chance);
- hostile_grid = grid_destroys_items(grd[x][y]);
+ hostile_grid = grid_destroys_items(grd(where));
// Non-returning items thrown into item-destroying grids are always
// destroyed. Returning items are only destroyed if they would have
@@ -2685,8 +2683,8 @@ bool thrown_object_destroyed( item_def *item, int x, int y, bool returning )
if (hostile_grid)
{
- if (player_can_hear(x, y))
- mprf(MSGCH_SOUND, grid_item_destruction_message(grd[x][y]));
+ if (player_can_hear(where))
+ mprf(MSGCH_SOUND, grid_item_destruction_message(grd(where)));
item_was_destroyed(*item, NON_MONSTER);
destroyed = true;
@@ -4366,7 +4364,7 @@ void read_scroll( int slot )
}
case SCR_NOISE:
- noisy(25, you.x_pos, you.y_pos, "You hear a loud clanging noise!");
+ noisy(25, you.pos(), "You hear a loud clanging noise!");
break;
case SCR_SUMMONING:
diff --git a/crawl-ref/source/item_use.h b/crawl-ref/source/item_use.h
index c2c0c0aced..5243a522d3 100644
--- a/crawl-ref/source/item_use.h
+++ b/crawl-ref/source/item_use.h
@@ -166,7 +166,8 @@ bool enchant_armour( int &ac_change, bool quiet, item_def &arm );
bool throw_it(bolt &pbolt, int throw_2, bool teleport = false,
int acc_bonus = 0, dist *target = NULL);
-bool thrown_object_destroyed( item_def *item, int x, int y, bool returning );
+bool thrown_object_destroyed( item_def *item, const coord_def& where,
+ bool returning );
void prompt_inscribe_item();
int launcher_shield_slowdown(const item_def &launcher,
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 5b2293f0bd..9825a3dbd4 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -1630,74 +1630,76 @@ void mark_items_non_pickup_at(const coord_def &pos)
}
}
-// Moves mitm[obj] to (x,y)... will modify the value of obj to
+// Moves mitm[obj] to p... will modify the value of obj to
// be the index of the final object (possibly different).
//
// Done this way in the hopes that it will be obvious from
// calling code that "obj" is possibly modified.
-bool move_item_to_grid( int *const obj, int x, int y )
+bool move_item_to_grid( int *const obj, const coord_def& p )
{
+ int& ob(*obj);
// Must be a valid reference to a valid object.
- if (*obj == NON_ITEM || !is_valid_item( mitm[*obj] ))
+ if (ob == NON_ITEM || !is_valid_item( mitm[ob] ))
return (false);
+ item_def& item(mitm[ob]);
+
// If it's a stackable type...
- if (is_stackable_item( mitm[*obj] ))
+ if (is_stackable_item( item ))
{
// Look for similar item to stack:
- for (int i = igrd[x][y]; i != NON_ITEM; i = mitm[i].link)
+ for (stack_iterator si(p); si; ++si)
{
// Check if item already linked here -- don't want to unlink it.
- if (*obj == i)
+ if (ob == si->index())
return (false);
- if (items_stack( mitm[*obj], mitm[i] ))
+ if (items_stack( item, *si ))
{
// Add quantity to item already here, and dispose
// of obj, while returning the found item. -- bwr
- inc_mitm_item_quantity( i, mitm[*obj].quantity );
- destroy_item( *obj );
- *obj = i;
+ inc_mitm_item_quantity( si->index(), item.quantity );
+ destroy_item( ob );
+ ob = si->index();
return (true);
}
}
}
// Non-stackable item that's been fudge-stacked (monster throwing weapons).
// Explode the stack when dropped. We have to special case chunks, ew.
- else if (mitm[*obj].quantity > 1
- && (mitm[*obj].base_type != OBJ_FOOD
- || mitm[*obj].sub_type != FOOD_CHUNK))
+ else if (item.quantity > 1
+ && (item.base_type != OBJ_FOOD
+ || item.sub_type != FOOD_CHUNK))
{
- while (mitm[*obj].quantity > 1)
+ while (item.quantity > 1)
{
// If we can't copy the items out, we lose the surplus.
- if (copy_item_to_grid(mitm[*obj], x, y, 1, false))
- --mitm[*obj].quantity;
+ if (copy_item_to_grid(item, p, 1, false))
+ --item.quantity;
else
- mitm[*obj].quantity = 1;
+ item.quantity = 1;
}
}
- ASSERT( *obj != NON_ITEM );
+ ASSERT( ob != NON_ITEM );
// Need to actually move object, so first unlink from old position.
- unlink_item( *obj );
+ unlink_item( ob );
// Move item to coord.
- mitm[*obj].x = x;
- mitm[*obj].y = y;
+ item.x = p.x;
+ item.y = p.y;
// Link item to top of list.
- mitm[*obj].link = igrd[x][y];
- igrd[x][y] = *obj;
+ item.link = igrd(p);
+ igrd(p) = ob;
- if (is_rune(mitm[*obj]))
+ if (is_rune(item))
{
if (player_in_branch(BRANCH_HALL_OF_ZOT))
- you.attribute[ATTR_RUNES_IN_ZOT] += mitm[*obj].quantity;
+ you.attribute[ATTR_RUNES_IN_ZOT] += item.quantity;
}
- else if (mitm[*obj].base_type == OBJ_ORBS
- && you.level_type == LEVEL_DUNGEON)
+ else if (item.base_type == OBJ_ORBS && you.level_type == LEVEL_DUNGEON)
{
set_branch_flags(BFLAG_HAS_ORB);
}
@@ -1705,32 +1707,32 @@ bool move_item_to_grid( int *const obj, int x, int y )
return (true);
}
-void move_item_stack_to_grid( int x, int y, int targ_x, int targ_y )
+void move_item_stack_to_grid( const coord_def& from, const coord_def& to )
{
- if (igrd[x][y] == NON_ITEM)
+ if (igrd(from) == NON_ITEM)
return;
// Tell all items in stack what the new coordinate is.
- for (int o = igrd[x][y]; o != NON_ITEM; o = mitm[o].link)
+ for (stack_iterator si(from); si; ++si)
{
- mitm[o].x = targ_x;
- mitm[o].y = targ_y;
+ si->x = to.x;
+ si->y = to.y;
// Link last of the stack to the top of the old stack.
- if (mitm[o].link == NON_ITEM && igrd[targ_x][targ_y] != NON_ITEM)
+ if (si->link == NON_ITEM && igrd(to) != NON_ITEM)
{
- mitm[o].link = igrd[targ_x][targ_y];
+ si->link = igrd(to);
break;
}
}
- igrd[targ_x][targ_y] = igrd[x][y];
- igrd[x][y] = NON_ITEM;
+ igrd(to) = igrd(from);
+ igrd(from) = NON_ITEM;
}
// Returns quantity dropped.
-bool copy_item_to_grid( const item_def &item, int x_plos, int y_plos,
+bool copy_item_to_grid( const item_def &item, const coord_def& p,
int quant_drop, bool mark_dropped )
{
if (quant_drop == 0)
@@ -1743,56 +1745,57 @@ bool copy_item_to_grid( const item_def &item, int x_plos, int y_plos,
// Loop through items at current location.
if (is_stackable_item( item ))
{
- for (int i = igrd[x_plos][y_plos]; i != NON_ITEM; i = mitm[i].link)
+ for (stack_iterator si(p); si; ++si)
{
- if (items_stack( item, mitm[i] ))
+ if (items_stack( item, *si ))
{
- inc_mitm_item_quantity( i, quant_drop );
+ inc_mitm_item_quantity( si->index(), quant_drop );
if (is_blood_potion(item))
{
item_def help = item;
- drop_blood_potions_stack(help, quant_drop, x_plos, y_plos);
+ drop_blood_potions_stack(help, quant_drop, p);
}
// If the items on the floor already have a nonzero slot,
// leave it as such, otherwise set the slot.
- if (mark_dropped && !mitm[i].slot)
- mitm[i].slot = index_to_letter(item.link);
+ if (mark_dropped && !si->slot)
+ si->slot = index_to_letter(item.link);
return (true);
}
}
}
// Item not found in current stack, add new item to top.
- int new_item = get_item_slot(10);
- if (new_item == NON_ITEM)
+ int new_item_idx = get_item_slot(10);
+ if (new_item_idx == NON_ITEM)
return (false);
+ item_def& new_item = mitm[new_item_idx];
// Copy item.
- mitm[new_item] = item;
+ new_item = item;
// Set quantity, and set the item as unlinked.
- mitm[new_item].quantity = quant_drop;
- mitm[new_item].x = 0;
- mitm[new_item].y = 0;
- mitm[new_item].link = NON_ITEM;
+ new_item.quantity = quant_drop;
+ new_item.x = 0;
+ new_item.y = 0;
+ new_item.link = NON_ITEM;
if (mark_dropped)
{
- mitm[new_item].slot = index_to_letter(item.link);
- mitm[new_item].flags |= ISFLAG_DROPPED;
- mitm[new_item].flags &= ~ISFLAG_THROWN;
- origin_set_unknown(mitm[new_item]);
+ new_item.slot = index_to_letter(item.link);
+ new_item.flags |= ISFLAG_DROPPED;
+ new_item.flags &= ~ISFLAG_THROWN;
+ origin_set_unknown(new_item);
}
- move_item_to_grid( &new_item, x_plos, y_plos );
+ move_item_to_grid( &new_item_idx, p );
if (is_blood_potion(item)
&& item.quantity != quant_drop) // partial drop only
{
// Since only the oldest potions have been dropped,
// remove the newest ones.
- remove_newest_blood_potion(mitm[new_item]);
+ remove_newest_blood_potion(new_item);
}
return (true);
@@ -1815,7 +1818,7 @@ bool move_top_item( const coord_def &pos, const coord_def &dest )
dgn_event(DET_ITEM_MOVED, pos, 0, item, -1, dest), pos);
// Now move the item to its new possition...
- move_item_to_grid( &item, dest.x, dest.y );
+ move_item_to_grid( &item, dest );
return (true);
}
@@ -1886,11 +1889,11 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer )
canned_msg( MSG_EMPTY_HANDED );
}
- const dungeon_feature_type my_grid = grd[you.x_pos][you.y_pos];
+ const dungeon_feature_type my_grid = grd(you.pos());
if (!grid_destroys_items(my_grid)
&& !copy_item_to_grid( you.inv[item_dropped],
- you.x_pos, you.y_pos, quant_drop, true ))
+ you.pos(), quant_drop, true ))
{
mpr("Too many items on this level, not dropping the item.");
return (false);
diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h
index bdccd3bc43..f1b8d14d3e 100644
--- a/crawl-ref/source/items.h
+++ b/crawl-ref/source/items.h
@@ -37,8 +37,8 @@ bool dec_mitm_item_quantity( int obj, int amount );
void inc_inv_item_quantity( int obj, int amount );
void inc_mitm_item_quantity( int obj, int amount );
-bool move_item_to_grid( int *const obj, int x, int y );
-void move_item_stack_to_grid( int x, int y, int targ_x, int targ_y );
+bool move_item_to_grid( int *const obj, const coord_def& p );
+void move_item_stack_to_grid( const coord_def& from, const coord_def& to );
int move_item_to_player( int obj, int quant_got, bool quiet = false );
void mark_items_non_pickup_at(const coord_def &pos);
bool is_stackable_item( const item_def &item );
@@ -95,7 +95,7 @@ void pickup(void);
/* ***********************************************************************
* called from: beam - items - transfor
* *********************************************************************** */
-bool copy_item_to_grid( const item_def &item, int x_plos, int y_plos,
+bool copy_item_to_grid( const item_def &item, const coord_def& p,
int quant_drop = -1, // item.quantity by default
bool mark_dropped = false);
diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc
index 02e25d5b13..b72ecbf038 100644
--- a/crawl-ref/source/luadgn.cc
+++ b/crawl-ref/source/luadgn.cc
@@ -1297,8 +1297,9 @@ static int dgn_feature_desc_at(lua_State *ls)
description_type_by_name(lua_tostring(ls, 3));
const bool need_stop = lua_isboolean(ls, 4)? lua_toboolean(ls, 4) : false;
const std::string s =
- feature_description(luaL_checkint(ls, 1), luaL_checkint(ls, 2), false,
- dtype, need_stop);
+ feature_description(coord_def(luaL_checkint(ls, 1),
+ luaL_checkint(ls, 2)),
+ false, dtype, need_stop);
lua_pushstring(ls, s.c_str());
return (1);
}
@@ -1577,7 +1578,7 @@ static int make_a_lua_cloud(int x, int y, int garbage, int spread_rate,
const int pow = random_range(lua_cloud_pow_min,
lua_cloud_pow_max,
lua_cloud_pow_rolls);
- place_cloud( ctype, x, y, pow, whose, spread_rate );
+ place_cloud( ctype, coord_def(x, y), pow, whose, spread_rate );
return 1;
}
diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc
index 2e777d4500..95b1ec5d08 100644
--- a/crawl-ref/source/makeitem.cc
+++ b/crawl-ref/source/makeitem.cc
@@ -2859,7 +2859,7 @@ int items( int allow_uniques, // not just true-false,
while (grd[x_pos][y_pos] != DNGN_FLOOR
|| !unforbidden(coord_def(x_pos, y_pos), mapmask));
- move_item_to_grid( &p, x_pos, y_pos );
+ move_item_to_grid( &p, coord_def(x_pos, y_pos) );
}
// Note that item might be invalidated now, since p could have changed.
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 719e2fea0d..2394fa650d 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -135,7 +135,7 @@ static void create_monster_hide(int mons_class)
break;
}
- move_item_to_grid( &o, you.x_pos, you.y_pos );
+ move_item_to_grid( &o, you.pos() );
}
// Vampire draining corpses currently leaves them a time of 90, while the
@@ -171,7 +171,7 @@ void turn_corpse_into_chunks( item_def &item )
// Only fresh corpses bleed enough to colour the ground.
if (!food_is_rotten(item))
- bleed_onto_floor(you.x_pos, you.y_pos, mons_class, max_chunks, true);
+ bleed_onto_floor(you.pos(), mons_class, max_chunks, true);
item.base_type = OBJ_FOOD;
item.sub_type = FOOD_CHUNK;
@@ -392,7 +392,7 @@ void maybe_coagulate_blood_potions_floor(int obj)
ASSERT(timer_new.size() == coag_count);
props_new.assert_validity();
- move_item_to_grid( &o, blood.x, blood.y );
+ move_item_to_grid( &o, coord_def(blood.x, blood.y) );
dec_mitm_item_quantity(obj, rot_count + coag_count);
ASSERT(timer.size() == blood.quantity);
@@ -722,7 +722,7 @@ bool maybe_coagulate_blood_potions_inv(item_def &blood)
ASSERT(timer_new.size() == coag_count);
props_new.assert_validity();
- move_item_to_grid( &o, you.x_pos, you.y_pos );
+ move_item_to_grid( &o, you.pos() );
blood.quantity -= rot_count + coag_count;
if (blood.quantity < 1)
@@ -801,7 +801,7 @@ void remove_newest_blood_potion(item_def &stack, int quant)
// Called from copy_item_to_grid.
// NOTE: Quantities are set afterwards, so don't ASSERT for those.
-void drop_blood_potions_stack(item_def &stack, int quant, int x, int y)
+void drop_blood_potions_stack(item_def &stack, int quant, const coord_def& p)
{
if (!is_valid_item(stack))
return;
@@ -817,7 +817,7 @@ void drop_blood_potions_stack(item_def &stack, int quant, int x, int y)
ASSERT(!timer.empty());
// First check whether we can merge with an existing stack on the floor.
- int o = igrd[x][y];
+ int o = igrd[p.x][p.y];
while (o != NON_ITEM)
{
if (mitm[o].base_type == OBJ_POTIONS
@@ -1067,7 +1067,7 @@ void split_potions_into_decay( int obj, int amount, bool need_msg )
potion2.flags = 0;
potion2.special = 0;
- copy_item_to_grid( potion2, you.x_pos, you.y_pos );
+ copy_item_to_grid( potion2, you.pos() );
}
// Is decreased even if the decay stack goes splat.
dec_inv_item_quantity(obj, amount);
@@ -1098,34 +1098,38 @@ bool victim_can_bleed(int montype)
return (mons_has_blood(montype));
}
-static bool allow_bleeding_on_square(int x, int y)
+static bool allow_bleeding_on_square(const coord_def& where)
{
// No bleeding onto sanctuary ground, please.
// Also not necessary if already covered in blood.
- if (env.map[x][y].property != FPROP_NONE)
+ if (env.map(where).property != FPROP_NONE)
return (false);
// No spattering into lava or water.
- if (grd[x][y] >= DNGN_LAVA && grd[x][y] < DNGN_FLOOR)
+ if (grd(where) >= DNGN_LAVA && grd(where) < DNGN_FLOOR)
return (false);
// No spattering into fountains (other than blood).
- if (grd[x][y] == DNGN_FOUNTAIN_BLUE || grd[x][y] == DNGN_FOUNTAIN_SPARKLING)
+ if (grd(where) == DNGN_FOUNTAIN_BLUE
+ || grd(where) == DNGN_FOUNTAIN_SPARKLING)
+ {
return (false);
+ }
// The good gods like to keep their altars pristine.
- if (is_good_god(grid_altar_god(grd[x][y])))
+ if (is_good_god(grid_altar_god(grd(where))))
return (false);
return (true);
}
-static void maybe_bloodify_square(int x, int y, int amount, bool spatter = false)
+static void maybe_bloodify_square(const coord_def& where, int amount,
+ bool spatter = false)
{
if (amount < 1)
return;
- if (!spatter && !allow_bleeding_on_square(x,y))
+ if (!spatter && !allow_bleeding_on_square(where))
return;
if (x_chance_in_y(amount, 20))
@@ -1133,32 +1137,31 @@ static void maybe_bloodify_square(int x, int y, int amount, bool spatter = false
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS,
"might bleed now; square: (%d, %d); amount = %d",
- x, y, amount);
+ where.x, where.y, amount);
#endif
- if (allow_bleeding_on_square(x,y))
- env.map[x][y].property = FPROP_BLOODY;
+ if (allow_bleeding_on_square(where))
+ env.map(where).property = FPROP_BLOODY;
// If old or new blood on square, the smell reaches further.
- if (env.map[x][y].property == FPROP_BLOODY)
- blood_smell(12, x, y);
+ if (env.map(where).property == FPROP_BLOODY)
+ blood_smell(12, where);
else // Still allow a lingering smell.
- blood_smell(7, x, y);
+ blood_smell(7, where);
if (spatter)
{
// Smaller chance of spattering surrounding squares.
- for (int i = -1; i <= 1; i++)
- for (int j = -1; j <= 1; j++)
- {
- if (i == 0 && j == 0) // current square
- continue;
+ for ( radius_iterator ri(where, 1, true, false); ri; ++ri )
+ {
+ if ( *ri == where ) // current square
+ continue;
- // Spattering onto walls etc. less likely.
- if (grd[x+i][y+j] < DNGN_MINMOVE && !one_chance_in(3))
- continue;
+ // Spattering onto walls etc. less likely.
+ if (grd(*ri) < DNGN_MINMOVE && !one_chance_in(3))
+ continue;
- maybe_bloodify_square(x+i, y+j, amount/15);
- }
+ maybe_bloodify_square(*ri, amount/15);
+ }
}
}
}
@@ -1166,43 +1169,36 @@ static void maybe_bloodify_square(int x, int y, int amount, bool spatter = false
// Currently flavour only: colour ground (and possibly adjacent squares) red.
// "damage" depends on damage taken (or hitpoints, if damage higher),
// or, for sacrifices, on the number of chunks possible to get out of a corpse.
-void bleed_onto_floor(int x, int y, int montype, int damage, bool spatter)
+void bleed_onto_floor(const coord_def& where, int montype,
+ int damage, bool spatter)
{
- ASSERT(in_bounds(x,y));
+ ASSERT(in_bounds(where));
if (!victim_can_bleed(montype))
return;
- maybe_bloodify_square(x, y, damage, spatter);
+ maybe_bloodify_square(where, damage, spatter);
}
-static void _spatter_neighbours(int cx, int cy, int chance)
+static void _spatter_neighbours(const coord_def& where, int chance)
{
- int posx, posy;
- for (int x = -1; x <= 1; x++)
- for (int y = -1; y <= 1; y++)
- {
- posx = cx + x;
- posy = cy + y;
- if (!in_bounds(posx, posy))
- continue;
-
- if (!allow_bleeding_on_square(posx, posy))
- continue;
+ for ( radius_iterator ri(where, 1, true, false); ri; ++ri )
+ {
+ if (!allow_bleeding_on_square(*ri))
+ continue;
- if (grd[posx][posy] < DNGN_MINMOVE && !one_chance_in(3))
- continue;
+ if (grd(*ri) < DNGN_MINMOVE && !one_chance_in(3))
+ continue;
- if (one_chance_in(chance))
- {
- env.map[posx][posy].property = FPROP_BLOODY;
- _spatter_neighbours(posx, posy, chance+1);
- }
+ if (one_chance_in(chance))
+ {
+ env.map(*ri).property = FPROP_BLOODY;
+ _spatter_neighbours(*ri, chance+1);
}
+ }
}
void generate_random_blood_spatter_on_level()
{
- int cx, cy;
int startprob;
// startprob is used to initialize the chance for neighbours being
@@ -1230,13 +1226,14 @@ void generate_random_blood_spatter_on_level()
for (int i = 0; i < max_cluster; i++)
{
- cx = 10 + random2(GXM - 10);
- cy = 10 + random2(GYM - 10);
+ coord_def c;
+ c.x = 10 + random2(GXM - 10);
+ c.y = 10 + random2(GYM - 10);
startprob = min_prob + random2(max_prob);
- if (allow_bleeding_on_square(cx, cy))
- env.map[cx][cy].property = FPROP_BLOODY;
- _spatter_neighbours(cx, cy, startprob);
+ if (allow_bleeding_on_square(c))
+ env.map(c).property = FPROP_BLOODY;
+ _spatter_neighbours(c, startprob);
}
}
@@ -1281,7 +1278,7 @@ void search_around( bool only_adjacent )
else if (grd[srx][sry] == DNGN_UNDISCOVERED_TRAP
&& x_chance_in_y(effective + 1, 17))
{
- i = trap_at_xy(srx, sry);
+ i = trap_at_xy(coord_def(srx, sry));
if (i != -1)
{
@@ -1737,7 +1734,7 @@ void down_stairs( int old_level, dungeon_feature_type force_stair,
branch_type old_where = you.where_are_you;
bool shaft = (!force_stair
- && trap_type_at_xy(you.x_pos, you.y_pos) == TRAP_SHAFT
+ && trap_type_at_xy(you.pos()) == TRAP_SHAFT
|| force_stair == DNGN_TRAP_NATURAL);
level_id shaft_dest;
int shaft_level = -1;
@@ -2017,7 +2014,7 @@ void down_stairs( int old_level, dungeon_feature_type force_stair,
{
if (you.flight_mode() == FL_FLY && !force_stair)
mpr("You dive down through the shaft.");
- handle_items_on_shaft(you.x_pos, you.y_pos, false);
+ handle_items_on_shaft(you.pos(), false);
}
else
climb_message(stair_find, false, old_level_type);
@@ -2410,7 +2407,7 @@ bool i_feel_safe(bool announce, bool want_move, bool just_monsters, int range)
// No monster will attack you inside a sanctuary,
// so presence of monsters won't matter -- until it starts shrinking...
- if (is_sanctuary(you.x_pos, you.y_pos) && env.sanctuary_time >= 5)
+ if (is_sanctuary(you.pos()) && env.sanctuary_time >= 5)
return (true);
}
@@ -2563,11 +2560,9 @@ static void apply_environment_effect(const coord_def &c)
{
const dungeon_feature_type grid = grd(c);
if (grid == DNGN_LAVA)
- check_place_cloud( CLOUD_BLACK_SMOKE,
- c.x, c.y, random_range( 4, 8 ), KC_OTHER );
+ check_place_cloud(CLOUD_BLACK_SMOKE, c, random_range(4, 8), KC_OTHER);
else if (grid == DNGN_SHALLOW_WATER)
- check_place_cloud( CLOUD_MIST,
- c.x, c.y, random_range( 2, 5 ), KC_OTHER );
+ check_place_cloud(CLOUD_MIST, c, random_range(2, 5), KC_OTHER);
}
static const int Base_Sfx_Chance = 5;
@@ -2654,7 +2649,7 @@ void reveal_secret_door(int x, int y)
{
ASSERT(grd[x][y] == DNGN_SECRET_DOOR);
- dungeon_feature_type door = grid_secret_door_appearance(x, y);
+ dungeon_feature_type door = grid_secret_door_appearance(coord_def(x, y));
grd[x][y] = grid_is_opaque(door) ?
DNGN_CLOSED_DOOR : DNGN_OPEN_DOOR;
viewwindow(true, false);
@@ -2709,8 +2704,8 @@ bool stop_attack_prompt(const monsters *mon, bool beam_attack,
bool retval = false;
bool prompt = false;
- const bool inSanctuary = (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(mon->x, mon->y));
+ const bool inSanctuary = (is_sanctuary(you.pos())
+ || is_sanctuary(mon->pos()));
const bool wontAttack = mons_wont_attack(mon);
const bool isFriendly = mons_friendly(mon);
const bool isNeutral = mons_neutral(mon);
diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h
index 2177da622c..3b82c02c6c 100644
--- a/crawl-ref/source/misc.h
+++ b/crawl-ref/source/misc.h
@@ -66,8 +66,8 @@ void maybe_coagulate_blood_potions_floor( int obj );
bool maybe_coagulate_blood_potions_inv( item_def &blood );
long remove_oldest_blood_potion( item_def &stack );
void remove_newest_blood_potion( item_def &stack, int quant = -1 );
-void drop_blood_potions_stack( item_def &stack, int quant, int x = you.x_pos,
- int y = you.y_pos );
+void drop_blood_potions_stack( item_def &stack, int quant,
+ const coord_def& p = you.pos() );
void pick_up_blood_potions_stack( item_def &stack, int quant );
bool can_bottle_blood_from_corpse( int mons_type );
@@ -75,7 +75,8 @@ void turn_corpse_into_blood_potions ( item_def &item );
void split_potions_into_decay( int obj, int amount, bool need_msg = true );
bool victim_can_bleed(int montype);
-void bleed_onto_floor(int x, int y, int mon, int damage, bool spatter = false);
+void bleed_onto_floor(const coord_def& where, int mon, int damage,
+ bool spatter = false);
void generate_random_blood_spatter_on_level();
// last updated 12may2000 {dlb}
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index 6a7bc6f653..a1a557e002 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -145,9 +145,9 @@ static void _initialize_randmons()
initialized_randmons = true;
}
-monster_type random_monster_at_grid(int x, int y)
+monster_type random_monster_at_grid(const coord_def& p)
{
- return (random_monster_at_grid(grd[x][y]));
+ return (random_monster_at_grid(grd(p)));
}
monster_type random_monster_at_grid(dungeon_feature_type grid)
@@ -2292,11 +2292,8 @@ bool mons_should_fire(struct bolt &beam)
if (beam.foe_count == 0)
return (false);
- if (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(beam.source_x, beam.source_y))
- {
+ if (is_sanctuary(you.pos()) || is_sanctuary(beam.source()))
return (false);
- }
// If we either hit no friends, or monster too dumb to care.
if (beam.fr_count == 0 || !beam.smart_monster)
@@ -2350,16 +2347,16 @@ bool ms_low_hitpoint_cast( const monsters *mon, spell_type monspell )
if (mon->foe == MHITYOU || mon->foe == MHITNOT)
{
- if (adjacent(you.x_pos, you.y_pos, mon->x, mon->y))
+ if (adjacent(you.pos(), mon->pos()))
targ_adj = true;
- if (is_sanctuary(you.x_pos, you.y_pos))
+ if (is_sanctuary(you.pos()))
targ_sanct = true;
}
else
{
- if (adjacent( menv[mon->foe].x, menv[mon->foe].y, mon->x, mon->y ))
- targ_adj = true;
- if (is_sanctuary( menv[mon->foe].x, menv[mon->foe].y ))
+ if (adjacent(menv[mon->foe].pos(), mon->pos()))
+ targ_adj = true;
+ if (is_sanctuary(menv[mon->foe].pos()))
targ_sanct = true;
}
@@ -2440,11 +2437,8 @@ bool ms_waste_of_time( const monsters *mon, spell_type monspell )
if (spell_harms_area(monspell) && env.sanctuary_time > 0)
return (true);
- if (spell_harms_target(monspell)
- && is_sanctuary(mon->target_x, mon->target_y))
- {
+ if (spell_harms_target(monspell) && is_sanctuary(mon->target_pos()))
return (true);
- }
}
// Eventually, we'll probably want to be able to have monsters
@@ -3599,7 +3593,7 @@ bool monsters::drop_item(int eslot, int near)
}
const std::string iname = mitm[item_index].name(DESC_NOCAP_A);
- if (!move_item_to_grid(&item_index, x, y))
+ if (!move_item_to_grid(&item_index, pos()))
{
// Re-equip item if we somehow failed to drop it.
if (was_unequipped)
@@ -4392,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.x_pos, you.y_pos) && !silenced(x, y))
+ else if (!silenced(you.pos()) && !silenced(x, y))
mpr("You hear a splashing noise.", MSGCH_SOUND);
}
return (true);
@@ -5184,7 +5178,7 @@ static bool _prepare_del_ench(monsters* mon, const mon_enchant &me)
if (in_bounds(pos) && mgrd(pos) == NON_MONSTER
&& monster_habitable_grid(mon, grd(pos))
- && trap_type_at_xy(pos.x, pos.y) == NUM_TRAPS)
+ && trap_type_at_xy(pos) == NUM_TRAPS)
{
if (one_chance_in(++okay_squares))
target_square = pos;
@@ -5375,7 +5369,7 @@ void monsters::remove_enchantment_effect(const mon_enchant &me, bool quiet)
case ENCH_HELD:
{
- int net = get_trapping_net(x,y);
+ int net = get_trapping_net(this->pos());
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
@@ -5681,7 +5675,7 @@ void monsters::apply_enchantment(const mon_enchant &me)
break;
}
- int net = get_trapping_net(x,y,true);
+ int net = get_trapping_net(this->pos(), true);
if (net == NON_ITEM) // Really shouldn't happen!
{
@@ -6191,7 +6185,7 @@ bool monsters::mon_see_grid(const coord_def& p, bool reach) const
max_disallowed = DNGN_MAX_NONREACH;
// XXX: Ignoring clouds for now.
- return (!num_feats_between(x, y, p.x, p.y, DNGN_UNSEEN, max_disallowed,
+ return (!num_feats_between(pos(), p, DNGN_UNSEEN, max_disallowed,
true, true));
}
@@ -6276,21 +6270,18 @@ void monsters::apply_location_effects()
bool monsters::move_to_pos(const coord_def &newpos)
{
- if (mgrd[newpos.x][newpos.y] != NON_MONSTER
- || you.x_pos == newpos.x && you.y_pos == newpos.y)
- {
+ if (mgrd(newpos) != NON_MONSTER || you.pos() == newpos )
return (false);
- }
// Clear old cell pointer.
- mgrd[x][y] = NON_MONSTER;
+ mgrd(pos()) = NON_MONSTER;
// Set monster x,y to new value.
x = newpos.x;
y = newpos.y;
// set new monster grid pointer to this monster.
- mgrd[x][y] = monster_index(this);
+ mgrd(newpos) = monster_index(this);
return (true);
}
@@ -6303,7 +6294,7 @@ bool monsters::do_shaft()
// Handle instances of do_shaft() being invoked magically when
// the monster isn't standing over a shaft.
- if (trap_type_at_xy(x, y) != TRAP_SHAFT)
+ if (trap_type_at_xy(this->pos()) != TRAP_SHAFT)
{
switch(grd[x][y])
{
@@ -6333,7 +6324,7 @@ bool monsters::do_shaft()
mpr("A shaft briefly opens up in the floor!");
}
- handle_items_on_shaft(this->x, this->y, false);
+ handle_items_on_shaft(this->pos(), false);
return (false);
}
}
@@ -6351,7 +6342,7 @@ bool monsters::do_shaft()
const bool reveal =
simple_monster_message(this, " falls through a shaft!");
- handle_items_on_shaft(this->x, this->y, false);
+ handle_items_on_shaft(this->pos(), false);
// Monster is no longer on this level.
destroy_inventory();
diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h
index c37b6f1cc4..e4dd300dd9 100644
--- a/crawl-ref/source/mon-util.h
+++ b/crawl-ref/source/mon-util.h
@@ -751,7 +751,7 @@ monster_type draco_subspecies( const monsters *mon );
std::string draconian_colour_name(monster_type mtype);
monster_type draconian_colour_by_name(const std::string &colour);
-monster_type random_monster_at_grid(int x, int y);
+monster_type random_monster_at_grid(const coord_def& p);
monster_type random_monster_at_grid(dungeon_feature_type grid);
void init_mon_name_cache();
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc
index 3b0bf92364..24103129a3 100644
--- a/crawl-ref/source/monplace.cc
+++ b/crawl-ref/source/monplace.cc
@@ -159,7 +159,7 @@ bool monster_habitable_grid(int monster_class,
bool monster_can_submerge(const monsters *mons, dungeon_feature_type grid)
{
if (mons->type == MONS_TRAPDOOR_SPIDER && grid == DNGN_FLOOR)
- return (trap_type_at_xy(mons->x, mons->y) == NUM_TRAPS);
+ return (trap_type_at_xy(mons->pos()) == NUM_TRAPS);
// Zombies of watery critters can not submerge.
switch (mons_habitat(mons))
@@ -462,7 +462,7 @@ static monster_type _resolve_monster_type(monster_type mon_type,
continue;
// Don't generate monsters on top of teleport traps.
- int trap = trap_at_xy(pos.x, pos.y);
+ int trap = trap_at_xy(pos);
if (trap >= 0)
{
if (!_can_place_on_trap(mon_type, env.trap[trap].type))
@@ -566,12 +566,12 @@ static bool _valid_monster_location(const mgen_data &mg,
if (!grid_compatible(grid_wanted, grd(mg_pos), true))
return (false);
- if (mg.behaviour != BEH_FRIENDLY && is_sanctuary(mg_pos.x, mg_pos.y))
+ if (mg.behaviour != BEH_FRIENDLY && is_sanctuary(mg_pos))
return (false);
// Don't generate monsters on top of teleport traps.
// (How did they get there?)
- int trap = trap_at_xy(mg_pos.x, mg_pos.y);
+ int trap = trap_at_xy(mg_pos);
if (trap >= 0)
{
if (!_can_place_on_trap(mg.cls, env.trap[trap].type))
@@ -837,7 +837,7 @@ static int _place_monster_aux( const mgen_data &mg,
// Setup habitat and placement.
// If the space is occupied, try some neighbouring square instead.
if (first_band_member && in_bounds(mg.pos)
- && (mg.behaviour == BEH_FRIENDLY || !is_sanctuary(mg.pos.x, mg.pos.y))
+ && (mg.behaviour == BEH_FRIENDLY || !is_sanctuary(mg.pos))
&& mgrd(mg.pos) == NON_MONSTER && mg.pos != you.pos()
&& (force_pos || monster_habitable_grid(htype, grd(mg.pos))))
{
@@ -2637,7 +2637,7 @@ std::vector<coord_def> monster_pathfind::calc_waypoints()
#endif
for (unsigned int i = 1; i < path.size(); i++)
{
- if (grid_see_grid(pos.x, pos.y, path[i].x, path[i].y, can_move))
+ if (grid_see_grid(pos, path[i], can_move))
continue;
else
{
@@ -2684,7 +2684,7 @@ bool monster_pathfind::traversable(coord_def p)
return (false);
}
- const int trap = trap_at_xy(p.x, p.y);
+ const int trap = trap_at_xy(p);
if (trap >= 0)
{
trap_type tt = env.trap[trap].type;
@@ -2730,7 +2730,7 @@ int monster_pathfind::travel_cost(coord_def npos)
}
// Try to avoid (known) traps.
- const int trap = trap_at_xy(npos.x, npos.y);
+ const int trap = trap_at_xy(npos);
if (trap >= 0)
{
// A monster can be considered to know a trap if
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index cbe9adf425..a560c32151 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -79,16 +79,17 @@ static bool _handle_pickup(monsters *monster);
static void _handle_behaviour(monsters *monster);
static void _set_nearest_monster_foe(monsters *monster);
static void _mons_in_cloud(monsters *monster);
-static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
- const int count_y, bool just_check = false);
-static bool _is_trap_safe(const monsters *monster, const int trap_x,
- const int trap_y, bool just_check = false);
+static bool _mon_can_move_to_pos(const monsters *monster,
+ const coord_def& delta,
+ bool just_check = false);
+static bool _is_trap_safe(const monsters *monster, const coord_def& where,
+ bool just_check = false);
static bool _monster_move(monsters *monster);
static bool _plant_spit(monsters *monster, bolt &pbolt);
static spell_type _map_wand_to_mspell(int wand_type);
// [dshaligram] Doesn't need to be extern.
-static int mmov_x, mmov_y;
+static coord_def mmov;
static int compass_x[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };
static int compass_y[8] = { -1, -1, -1, 0, 1, 1, 1, 0 };
@@ -294,7 +295,7 @@ static void _monster_drop_ething(monsters *monster,
if (mons_friendly(monster) && is_valid_item(mitm[item]))
mitm[item].flags |= ISFLAG_DROPPED_BY_ALLY;
- move_item_to_grid( &item, monster->x, monster->y );
+ move_item_to_grid( &item, monster->pos() );
if (mark_item_origins && is_valid_item(mitm[item]))
origin_set_monster(mitm[item], monster);
@@ -349,8 +350,8 @@ static void _place_monster_corpse(const monsters *monster)
origin_set_monster(mitm[o], monster);
// Don't care if 'o' is changed, and it shouldn't be (corpses don't stack).
- move_item_to_grid( &o, monster->x, monster->y );
- if (see_grid(monster->x, monster->y))
+ move_item_to_grid( &o, monster->pos() );
+ if (see_grid(monster->pos()))
{
const bool poison = (mons_corpse_effect(monster->type) == CE_POISONOUS
&& player_res_poison() <= 0);
@@ -800,7 +801,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
if (monster->type == MONS_FIRE_VORTEX)
{
- place_cloud(CLOUD_FIRE, monster->x, monster->y, 2 + random2(4),
+ place_cloud(CLOUD_FIRE, monster->pos(), 2 + random2(4),
monster->kill_alignment());
}
@@ -817,7 +818,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
silent = true;
}
- place_cloud(CLOUD_COLD, monster->x, monster->y, 2 + random2(4),
+ place_cloud(CLOUD_COLD, monster->pos(), 2 + random2(4),
monster->kill_alignment());
if (killer == KILL_RESET)
@@ -1169,7 +1170,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
}
place_cloud( random_smoke_type(),
- monster->x, monster->y, 1 + random2(3),
+ monster->pos(), 1 + random2(3),
monster->kill_alignment() );
// KILL_RESET monsters no longer lose their whole inventory, only
@@ -1276,7 +1277,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
"'s corpse disappears in a puff of smoke!");
place_cloud( random_smoke_type(),
- monster->x, monster->y, 1 + random2(3),
+ monster->pos(), 1 + random2(3),
monster->kill_alignment() );
}
}
@@ -1511,7 +1512,7 @@ bool monster_polymorph(monsters *monster, monster_type targetc,
do
{
// Pick a monster that's guaranteed happy at this grid.
- targetc = random_monster_at_grid(monster->x, monster->y);
+ targetc = random_monster_at_grid(monster->pos());
// Valid targets are always base classes ([ds] which is unfortunate
// in that well-populated monster classes will dominate polymorphs).
@@ -1640,13 +1641,13 @@ bool monster_polymorph(monsters *monster, monster_type targetc,
bool monster_blink(monsters *monster)
{
- int nx, ny;
+ coord_def near;
{
unwind_var<env_show_grid> visible_grid( env.show );
- losight(env.show, grd, monster->x, monster->y, true);
+ losight(env.show, grd, monster->pos(), true);
- if (!random_near_space(monster->x, monster->y, nx, ny,
+ if (!random_near_space(monster->pos(), near,
false, true,
!mons_wont_attack(monster)))
{
@@ -1656,13 +1657,13 @@ bool monster_blink(monsters *monster)
mons_clear_trapping_net(monster);
- mgrd[monster->x][monster->y] = NON_MONSTER;
-
+ mgrd(monster->pos()) = NON_MONSTER;
const coord_def oldplace = monster->pos();
- monster->x = nx;
- monster->y = ny;
- mgrd[nx][ny] = monster_index(monster);
+ // FIXME Shouldn't this use monsters::move_to_pos() ?
+ monster->x = near.x;
+ monster->y = near.y;
+ mgrd(near) = monster_index(monster);
if (player_monster_visible(monster) && mons_near(monster))
seen_monster(monster);
@@ -1675,8 +1676,9 @@ bool monster_blink(monsters *monster)
// allow_adjacent: allow target to be adjacent to origin.
// restrict_LOS: restrict target to be within PLAYER line of sight.
-bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
- bool restrict_LOS, bool forbid_sanctuary)
+bool random_near_space(const coord_def& origin, coord_def& target,
+ bool allow_adjacent, bool restrict_LOS,
+ bool forbid_sanctuary)
{
// This might involve ray tracing (via num_feats_between()), so
// cache results to avoid duplicating ray traces.
@@ -1684,14 +1686,14 @@ bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
tried.init(false);
// Is the monster on the other side of a transparent wall?
- bool trans_wall_block = trans_wall_blocking(ox, oy);
- bool origin_is_player = (you.pos() == coord_def(ox, oy));
- int min_walls_between = 0;
+ const bool trans_wall_block = trans_wall_blocking(origin);
+ const bool origin_is_player = (you.pos() == origin);
+ int min_walls_between = 0;
// Skip ray tracing if possible.
if (trans_wall_block)
{
- min_walls_between = num_feats_between(ox, oy, you.x_pos, you.y_pos,
+ min_walls_between = num_feats_between(origin, you.pos(),
DNGN_CLEAR_ROCK_WALL,
DNGN_CLEAR_PERMAROCK_WALL);
}
@@ -1699,28 +1701,26 @@ bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
int tries = 0;
while (tries++ < 150)
{
- int dx = random2(14);
- int dy = random2(14);
+ coord_def delta( random2(14), random2(14) );
- tx = ox - 6 + dx;
- ty = oy - 6 + dy;
+ target = origin - coord_def(6,6) + delta;
// Origin is not 'near'.
- if (tx == ox && ty == oy)
+ if (target == origin)
continue;
- if (tried[dx][dy])
+ if (tried(delta))
continue;
- tried[dx][dy] = true;
+ tried(delta) = true;
- if (!in_bounds(tx, ty)
- || restrict_LOS && !see_grid(tx, ty)
- || grd[tx][ty] < DNGN_SHALLOW_WATER
- || mgrd[tx][ty] != NON_MONSTER
- || tx == you.x_pos && ty == you.y_pos
- || !allow_adjacent && distance(ox, oy, tx, ty) <= 2
- || forbid_sanctuary && is_sanctuary(tx, ty))
+ if (!in_bounds(target)
+ || restrict_LOS && !see_grid(target)
+ || grd(target) < DNGN_SHALLOW_WATER
+ || mgrd(target) != NON_MONSTER
+ || target == you.pos()
+ || !allow_adjacent && distance(origin, target) <= 2
+ || forbid_sanctuary && is_sanctuary(target))
{
continue;
}
@@ -1738,19 +1738,19 @@ bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
// away from the player, since in the absence of translucent
// walls monsters can blink to places which are not in either
// the monster's nor the player's LOS.
- if (!origin_is_player && !see_grid(tx, ty))
+ if (!origin_is_player && !see_grid(target))
return (true);
// Player can't randomly pass through translucent walls.
if (origin_is_player)
{
- if (see_grid_no_trans(tx, ty))
+ if (see_grid_no_trans(target))
return (true);
continue;
}
- int walls_passed = num_feats_between(tx, ty, ox, oy,
+ int walls_passed = num_feats_between(target, origin,
DNGN_CLEAR_ROCK_WALL,
DNGN_CLEAR_PERMAROCK_WALL,
true, true);
@@ -1761,7 +1761,7 @@ bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
if (origin_is_player)
continue;
- int walls_between = num_feats_between(tx, ty, you.x_pos, you.y_pos,
+ int walls_between = num_feats_between(target, you.pos(),
DNGN_CLEAR_ROCK_WALL,
DNGN_CLEAR_PERMAROCK_WALL);
@@ -1990,7 +1990,7 @@ static bool _wounded_damaged(int monster_type)
//
//---------------------------------------------------------------
void behaviour_event(monsters *mon, int event, int src,
- int src_x, int src_y)
+ coord_def src_pos)
{
beh_type old_behaviour = mon->behaviour;
@@ -2022,8 +2022,8 @@ void behaviour_event(monsters *mon, int event, int src,
if (mon->is_patrolling())
break;
- mon->target_x = src_x;
- mon->target_y = src_y;
+ mon->target_x = src_pos.x;
+ mon->target_y = src_pos.y;
}
break;
@@ -2079,7 +2079,7 @@ void behaviour_event(monsters *mon, int event, int src,
case ME_SCARE:
{
const bool flee_sanct = !mons_wont_attack(mon)
- && is_sanctuary(mon->x, mon->y);
+ && is_sanctuary(mon->pos());
// Stationary monsters can't flee, even from sanctuary.
if (mons_is_stationary(mon))
@@ -2106,7 +2106,7 @@ void behaviour_event(monsters *mon, int event, int src,
// Assume monsters know where to run from, even if player is
// invisible.
setTarget = true;
- if (see_grid(mon->x, mon->y))
+ if (see_grid(mon->pos()))
learned_something_new(TUT_FLEEING_MONSTER);
break;
}
@@ -2117,7 +2117,7 @@ void behaviour_event(monsters *mon, int event, int src,
break;
// Don't stop fleeing from sanctuary.
- if (!mons_wont_attack(mon) && is_sanctuary(mon->x, mon->y))
+ if (!mons_wont_attack(mon) && is_sanctuary(mon->pos()))
break;
// Just set behaviour... foe doesn't change.
@@ -2388,18 +2388,19 @@ static void _find_all_level_exits(std::vector<level_exit> &e)
{
for (int x = 0; x < GXM; ++x)
{
- if (in_bounds(x, y))
+ coord_def p(x,y);
+ if (in_bounds(p))
{
- const dungeon_feature_type gridc = grd[x][y];
+ const dungeon_feature_type gridc = grd(p);
// All types of stairs.
if (is_stair(gridc))
- e.push_back(level_exit(coord_def(x, y), false));
+ e.push_back(level_exit(p, false));
// Teleportation and shaft traps.
- const trap_type tt = trap_type_at_xy(x, y);
+ const trap_type tt = trap_type_at_xy(p);
if (tt == TRAP_TELEPORT || tt == TRAP_SHAFT)
- e.push_back(level_exit(coord_def(x, y), false));
+ e.push_back(level_exit(p, false));
}
}
}
@@ -2421,8 +2422,7 @@ static int _mons_find_nearest_level_exit(const monsters *mon,
if (e[i].unreachable)
continue;
- int dist = grid_distance(mon->x, mon->y, e[i].target.x,
- e[i].target.y);
+ int dist = grid_distance(mon->pos(), e[i].target);
if (old_dist == -1 || old_dist >= dist)
{
@@ -2496,7 +2496,7 @@ static void _handle_behaviour(monsters *mon)
bool isNeutral = mons_neutral(mon);
bool wontAttack = mons_wont_attack(mon);
bool proxPlayer = mons_near(mon);
- bool trans_wall_block = trans_wall_blocking(mon->x, mon->y);
+ bool trans_wall_block = trans_wall_blocking(mon->pos());
#ifdef WIZARD
// If stealth is greater than actually possible (wizmode level)
@@ -2540,13 +2540,13 @@ static void _handle_behaviour(monsters *mon)
if (!mons_player_visible( mon ))
proxPlayer = false;
// Must be able to see each other.
- else if (!see_grid(mon->x, mon->y))
+ else if (!see_grid(mon->pos()))
proxPlayer = false;
const int intel = mons_intel(mon->type);
// Now, the corollary to that is that sometimes, if a
// player is right next to a monster, they will 'see'.
- if (grid_distance( you.x_pos, you.y_pos, mon->x, mon->y ) == 1
+ if (grid_distance( you.pos(), mon->pos() ) == 1
&& one_chance_in(3))
{
proxPlayer = true;
@@ -2808,7 +2808,7 @@ static void _handle_behaviour(monsters *mon)
// is already adjacent to you.
if (potentially_blocking && mons_intel(mon->type) >= I_NORMAL
&& mons_has_los_ability(mon->type)
- || grid_distance(mon->x, mon->y, you.x_pos, you.y_pos) == 1)
+ || grid_distance(mon->pos(), you.pos()) == 1)
{
potentially_blocking = false;
}
@@ -2839,7 +2839,7 @@ static void _handle_behaviour(monsters *mon)
}
if (!potentially_blocking
- || grid_see_grid(mon->x, mon->y, you.x_pos, you.y_pos,
+ || grid_see_grid(mon->pos(), you.pos(),
can_move))
{
if (mon->travel_target != MTRAV_PATROL
@@ -2862,8 +2862,7 @@ static void _handle_behaviour(monsters *mon)
{
int len = mon->travel_path.size();
coord_def targ = mon->travel_path[len - 1];
- if (grid_see_grid(targ.x, targ.y, you.x_pos, you.y_pos,
- can_move))
+ if (grid_see_grid(targ, you.pos(), can_move))
{
// Current target still valid?
if (mon->x == mon->travel_path[0].x
@@ -2880,9 +2879,8 @@ static void _handle_behaviour(monsters *mon)
break;
}
}
- else if (grid_see_grid(mon->x, mon->y,
- mon->travel_path[0].x,
- mon->travel_path[0].y,
+ else if (grid_see_grid(mon->pos(),
+ mon->travel_path[0],
can_move))
{
mon->target_x = mon->travel_path[0].x;
@@ -2893,8 +2891,8 @@ static void _handle_behaviour(monsters *mon)
}
// Use pathfinding to find a (new) path to the player.
- const int dist = grid_distance(mon->x, mon->y,
- you.x_pos, you.y_pos);
+ const int dist = grid_distance(mon->pos(),
+ you.pos());
#ifdef DEBUG_PATHFIND
mprf("Need to calculate a path... (dist = %d)", dist);
@@ -2943,8 +2941,8 @@ static void _handle_behaviour(monsters *mon)
#ifdef DEBUG_PATHFIND
mprf("Need a path for %s from (%d, %d) to (%d, %d), "
"max. dist = %d",
- mon->name(DESC_PLAIN).c_str(), mon->x, mon->y,
- you.x_pos, you.y_pos, range);
+ mon->name(DESC_PLAIN).c_str(), mon->pos(),
+ you.pos(), range);
#endif
monster_pathfind mp;
if (range > 0)
@@ -3065,7 +3063,7 @@ static void _handle_behaviour(monsters *mon)
// If a pacified monster is far enough away from the
// player, make it leave the level.
- if (grid_distance(mon->x, mon->y, you.x_pos, you.y_pos)
+ if (grid_distance(mon->pos(), you.pos())
>= LOS_RADIUS * 4)
{
make_mons_leave_level(mon);
@@ -3133,9 +3131,8 @@ static void _handle_behaviour(monsters *mon)
#endif
}
}
- else if (!grid_see_grid(mon->x, mon->y,
- mon->travel_path[0].x,
- mon->travel_path[0].y, can_move))
+ else if (!grid_see_grid(mon->pos(), mon->travel_path[0],
+ can_move))
{
#ifdef DEBUG_PATHFIND
mpr("Can't see waypoint grid.");
@@ -3154,9 +3151,8 @@ static void _handle_behaviour(monsters *mon)
int erase = -1; // Erase how many waypoints?
for (int i = mon->travel_path.size() - 1; i >= 0; --i)
{
- if (grid_see_grid(mon->x, mon->y,
- mon->travel_path[i].x,
- mon->travel_path[i].y, can_move))
+ if (grid_see_grid(mon->pos(), mon->travel_path[i],
+ can_move))
{
mon->target_x = mon->travel_path[i].x;
mon->target_y = mon->travel_path[i].y;
@@ -3242,12 +3238,12 @@ static void _handle_behaviour(monsters *mon)
{
// Your ally was told to wait, and wait it will!
// (Though possibly not where you told it to.)
- mon->patrol_point = coord_def(mon->x, mon->y);
+ mon->patrol_point = mon->pos();
}
else
{
// Stop patrolling.
- mon->patrol_point = coord_def(0, 0);
+ mon->patrol_point.reset();
mon->travel_target = MTRAV_NONE;
need_target = true;
}
@@ -3410,30 +3406,30 @@ static void _handle_behaviour(monsters *mon)
}
}
-static bool _mons_check_set_foe(monsters *mon, int x, int y,
+static bool _mons_check_set_foe(monsters *mon, const coord_def& p,
bool friendly, bool neutral)
{
- if (!inside_level_bounds(x, y))
+ if (!inside_level_bounds(p))
return (false);
- if (!friendly && !neutral && x == you.x_pos && y == you.y_pos
- && mons_player_visible(mon) && !is_sanctuary(x, y))
+ if (!friendly && !neutral && p == you.pos()
+ && mons_player_visible(mon) && !is_sanctuary(p))
{
mon->foe = MHITYOU;
return (true);
}
- if (mgrd[x][y] != NON_MONSTER)
+ if (mgrd(p) != NON_MONSTER)
{
- monsters *foe = &menv[mgrd[x][y]];
+ monsters *foe = &menv[mgrd(p)];
if (foe != mon
&& mon_can_see_monster(mon, foe)
- && (friendly || !is_sanctuary(x, y))
+ && (friendly || !is_sanctuary(p))
&& (mons_friendly(foe) != friendly
|| (neutral && !mons_neutral(foe))))
{
- mon->foe = mgrd[x][y];
+ mon->foe = mgrd(p);
return (true);
}
}
@@ -3452,15 +3448,15 @@ void _set_nearest_monster_foe(monsters *mon)
for (int k = 1; k <= LOS_RADIUS; ++k)
{
for (int x = mx - k; x <= mx + k; ++x)
- if (_mons_check_set_foe(mon, x, my - k, friendly, neutral)
- || _mons_check_set_foe(mon, x, my + k, friendly, neutral))
+ if (_mons_check_set_foe(mon, coord_def(x, my - k), friendly, neutral)
+ || _mons_check_set_foe(mon, coord_def(x, my + k), friendly, neutral))
{
return;
}
for (int y = my - k + 1; y < my + k; ++y)
- if (_mons_check_set_foe(mon, mx - k, y, friendly, neutral)
- || _mons_check_set_foe(mon, mx + k, y, friendly, neutral))
+ if (_mons_check_set_foe(mon, coord_def(mx - k, y), friendly, neutral)
+ || _mons_check_set_foe(mon, coord_def(mx + k, y), friendly, neutral))
{
return;
}
@@ -3624,7 +3620,7 @@ static void _maybe_set_patrol_route(monsters *monster)
&& !monster->is_patrolling()
&& _mon_on_interesting_grid(monster))
{
- monster->patrol_point = coord_def(monster->x, monster->y);
+ monster->patrol_point = monster->pos();
}
}
@@ -3642,14 +3638,14 @@ static void _handle_movement(monsters *monster)
_maybe_set_patrol_route(monster);
// Monsters will try to flee out of a sanctuary.
- if (is_sanctuary(monster->x, monster->y) && !mons_friendly(monster)
+ if (is_sanctuary(monster->pos()) && !mons_friendly(monster)
&& !mons_is_fleeing(monster)
&& monster->add_ench(mon_enchant(ENCH_FEAR, 0, KC_YOU)))
{
- behaviour_event(monster, ME_SCARE, MHITNOT, monster->x, monster->y);
+ behaviour_event(monster, ME_SCARE, MHITNOT, monster->pos());
}
else if (mons_is_fleeing(monster) && inside_level_bounds(env.sanctuary_pos)
- && !is_sanctuary(monster->x, monster->y)
+ && !is_sanctuary(monster->pos())
&& monster->target_pos() == env.sanctuary_pos)
{
// Once outside there's a chance they'll regain their courage.
@@ -3677,38 +3673,35 @@ static void _handle_movement(monsters *monster)
}
// Move the monster.
- mmov_x = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
- mmov_y = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
+ mmov.x = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
+ mmov.y = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
if (mons_is_fleeing(monster)
&& (!mons_friendly(monster)
- || monster->target_x != you.x_pos
- || monster->target_y != you.y_pos))
+ || monster->target_pos() != you.pos()))
{
- mmov_x *= -1;
- mmov_y *= -1;
+ mmov.x *= -1;
+ mmov.y *= -1;
}
// Don't allow monsters to enter a sanctuary
// or attack you inside a sanctuary even if you're right next to them.
- if (is_sanctuary(monster->x + mmov_x, monster->y + mmov_y)
- && (!is_sanctuary(monster->x, monster->y)
- || monster->x + mmov_x == you.x_pos
- && monster->y + mmov_y == you.y_pos))
+ if (is_sanctuary(monster->pos() + mmov)
+ && (!is_sanctuary(monster->pos())
+ || monster->pos() + mmov == you.pos()))
{
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
}
// Bounds check: don't let fleeing monsters try to run off the map.
- if (monster->target_x + mmov_x < 0 || monster->target_x + mmov_x >= GXM)
- mmov_x = 0;
+ if (monster->target_x + mmov.x < 0 || monster->target_x + mmov.x >= GXM)
+ mmov.x = 0;
- if (monster->target_y + mmov_y < 0 || monster->target_y + mmov_y >= GYM)
- mmov_y = 0;
+ if (monster->target_y + mmov.y < 0 || monster->target_y + mmov.y >= GYM)
+ mmov.y = 0;
// now quit if we can't move
- if (mmov_x == 0 && mmov_y == 0)
+ if (mmov == coord_def(0,0))
return;
// Reproduced here is some semi-legacy code that makes monsters
@@ -3723,14 +3716,14 @@ static void _handle_movement(monsters *monster)
{
// Sometimes we'll just move parallel the x axis.
if (coinflip())
- mmov_y = 0;
+ mmov.y = 0;
}
if (abs(dy) > abs(dx))
{
// Sometimes we'll just move parallel the y axis.
if (coinflip())
- mmov_x = 0;
+ mmov.x = 0;
}
}
} // end handle_movement()
@@ -3743,8 +3736,8 @@ static void _make_mons_stop_fleeing(monsters *mon)
static bool _is_player_or_mon_sanct(const monsters* monster)
{
- return (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(monster->x, monster->y));
+ return (is_sanctuary(you.pos())
+ || is_sanctuary(monster->pos()));
}
//---------------------------------------------------------------
@@ -3799,8 +3792,8 @@ static void _handle_nearby_ability(monsters *monster)
&& !player_beheld_by(monster) // No submerging if player entranced.
&& !mons_is_lurking(monster) // Handled elsewhere.
&& (one_chance_in(5)
- || grid_distance(monster->x, monster->y,
- you.x_pos, you.y_pos) > 1
+ || grid_distance(monster->pos(),
+ you.pos()) > 1
// FIXME This is better expressed as a
// function such as
// monster_has_ranged_attack:
@@ -3901,7 +3894,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
{
case MONS_ORC_KNIGHT:
case MONS_ORC_WARLORD:
- if (is_sanctuary(monster->x, monster->y))
+ if (is_sanctuary(monster->pos()))
break;
used = orc_battle_cry(monster);
@@ -3923,11 +3916,11 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
break;
case MONS_BALL_LIGHTNING:
- if (is_sanctuary(monster->x, monster->y))
+ if (is_sanctuary(monster->pos()))
break;
if (monster->attitude == ATT_HOSTILE
- && distance(you.x_pos, you.y_pos, monster->x, monster->y) <= 5)
+ && distance(you.pos(), monster->pos()) <= 5)
{
monster->hit_points = -1;
used = true;
@@ -3941,7 +3934,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
if (targ->type == -1 || targ->type == NON_MONSTER)
continue;
- if (distance(monster->x, monster->y, targ->x, targ->y) >= 5)
+ if (distance(monster->pos(), targ->pos()) >= 5)
continue;
if (mons_atts_aligned(monster->attitude, targ->attitude))
@@ -4135,8 +4128,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
break;
}
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
}
break;
@@ -4239,8 +4231,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
_make_mons_stop_fleeing(monster);
simple_monster_message(monster, " breathes.", spl);
fire_beam(beem);
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
used = true;
}
}
@@ -4269,8 +4260,8 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
|| mons_is_fleeing(monster)
|| mons_is_pacified(monster)
|| mons_friendly(monster)
- || silenced(monster->x, monster->y)
- || silenced(you.x_pos, you.y_pos))
+ || silenced(monster->pos())
+ || silenced(you.pos()))
{
break;
}
@@ -4292,9 +4283,8 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
if (one_chance_in(5)
|| monster->foe == MHITYOU && !already_beheld && coinflip())
{
- int walls = num_feats_between(you.x_pos, you.y_pos,
- monster->x, monster->y, DNGN_UNSEEN,
- DNGN_MAXWALL);
+ int walls = num_feats_between(you.pos(), monster->pos(),
+ DNGN_UNSEEN, DNGN_MAXWALL);
if (walls > 0)
{
@@ -4788,7 +4778,7 @@ static bool _handle_wand(monsters *monster, bolt &beem)
if (!simple_monster_message(monster, " zaps a wand."))
{
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a zap.", MSGCH_SOUND);
}
@@ -4908,7 +4898,7 @@ static bool _mons_announce_cast(monsters *monster, bool nearby,
// Handle monsters within range of player.
if (monster->type == MONS_GERYON)
{
- if (silenced(monster->x, monster->y))
+ if (silenced(monster->pos()))
return (false);
simple_monster_message( monster, " winds a great silver horn.",
@@ -4927,8 +4917,8 @@ static bool _mons_announce_cast(monsters *monster, bool nearby,
{
if (!simple_monster_message(monster, " breathes.", spl))
{
- if (!silenced(monster->x, monster->y)
- && !silenced(you.x_pos, you.y_pos))
+ if (!silenced(monster->pos())
+ && !silenced(you.pos()))
{
mpr("You hear a roar.", MSGCH_SOUND);
}
@@ -4936,7 +4926,7 @@ static bool _mons_announce_cast(monsters *monster, bool nearby,
break;
}
- if (silenced(monster->x, monster->y))
+ if (silenced(monster->pos()))
return (false);
if (mons_class_flag(monster->type, M_PRIEST))
@@ -5003,8 +4993,8 @@ static bool _mons_announce_cast(monsters *monster, bool nearby,
case MONS_IRON_DRAGON:
if (!simple_monster_message(monster, " breathes.", spl))
{
- if (!silenced(monster->x, monster->y)
- && !silenced(you.x_pos, you.y_pos))
+ if (!silenced(monster->pos())
+ && !silenced(you.pos()))
{
mpr("You hear a roar.", MSGCH_SOUND);
}
@@ -5046,7 +5036,7 @@ static bool _mons_announce_cast(monsters *monster, bool nearby,
{
// Handle far-away monsters.
if (monster->type == MONS_GERYON
- && !silenced(you.x_pos, you.y_pos))
+ && !silenced(you.pos()))
{
mpr("You hear a weird and mournful sound.", MSGCH_SOUND);
}
@@ -5069,7 +5059,7 @@ static bool _handle_spell(monsters *monster, bolt &beem)
bool finalAnswer = false; // as in: "Is that your...?" {dlb}
const spell_type draco_breath = _get_draconian_breath_spell(monster);
- if (is_sanctuary(monster->x, monster->y)
+ if (is_sanctuary(monster->pos())
&& !mons_wont_attack(monster))
{
return (false);
@@ -5381,8 +5371,7 @@ static bool _handle_spell(monsters *monster, bolt &beem)
_make_mons_stop_fleeing(monster);
mons_cast(monster, beem, spell_cast);
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
monster->lose_energy(EUT_SPELL);
}
} // end "if mons_class_flag(monster->type, M_SPELLCASTER) ...
@@ -5490,11 +5479,8 @@ static bool _handle_throw(monsters *monster, bolt & beem)
// Monsters won't shoot in melee range, largely for balance reasons.
// Specialist archers are an exception to this rule.
- if (!archer
- && adjacent( beem.target_x, beem.target_y, monster->x, monster->y ))
- {
+ if (!archer && adjacent(beem.target(), monster->pos()))
return (false);
- }
// Greatly lowered chances if the monster is fleeing or pacified and
// leaving the level.
@@ -5667,7 +5653,7 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx)
return (false);
// Right now just happens in sanctuary.
- if (!is_sanctuary(mover->x, mover->y) || !is_sanctuary(moved->x, moved->y))
+ if (!is_sanctuary(mover->pos()) || !is_sanctuary(moved->pos()))
return (false);
// A friendly or good-neutral monster moving past a fleeing hostile
@@ -5964,7 +5950,7 @@ static void _handle_monster_move(int i, monsters *monster)
}
else if (!mons_is_petrified(monster))
{
- // Calculates mmov_x, mmov_y based on monster target.
+ // Calculates mmov based on monster target.
_handle_movement(monster);
brkk = false;
@@ -5983,38 +5969,34 @@ static void _handle_monster_move(int i, monsters *monster)
if (in_bounds(c) && monster->can_pass_through(c)
&& one_chance_in(++pfound))
{
- mmov_x = xi;
- mmov_y = yi;
+ mmov.x = xi;
+ mmov.y = yi;
}
}
if (x_chance_in_y(2, 2 + pfound))
- mmov_x = mmov_y = 0;
+ mmov.reset();
// Bounds check: don't let confused monsters try to run
// off the map.
- if (monster->x + mmov_x < 0 || monster->x + mmov_x >= GXM)
- mmov_x = 0;
+ if (monster->x + mmov.x < 0 || monster->x + mmov.x >= GXM)
+ mmov.x = 0;
- if (monster->y + mmov_y < 0 || monster->y + mmov_y >= GYM)
- mmov_y = 0;
+ if (monster->y + mmov.y < 0 || monster->y + mmov.y >= GYM)
+ mmov.y = 0;
- if (!monster->can_pass_through(monster->x + mmov_x,
- monster->y + mmov_y))
- {
- mmov_x = mmov_y = 0;
- }
+ if (!monster->can_pass_through(monster->pos() + mmov))
+ mmov.reset();
- int enemy = mgrd[monster->x + mmov_x][monster->y + mmov_y];
+ int enemy = mgrd(monster->pos() + mmov);
if (enemy != NON_MONSTER
- && !is_sanctuary(monster->x, monster->y)
- && (mmov_x != 0 || mmov_y != 0))
+ && !is_sanctuary(monster->pos())
+ && (mmov.x != 0 || mmov.y != 0))
{
if (monsters_fight(i, enemy))
{
brkk = true;
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
DEBUG_ENERGY_USE("monsters_fight()");
}
else
@@ -6024,8 +6006,7 @@ static void _handle_monster_move(int i, monsters *monster)
if (monster->add_ench(mon_enchant(ENCH_FEAR)))
{
behaviour_event(monster, ME_SCARE, MHITNOT,
- monster->x + mmov_x,
- monster->y + mmov_y);
+ monster->pos() + mmov);
}
break;
}
@@ -6099,7 +6080,7 @@ static void _handle_monster_move(int i, monsters *monster)
if (!mons_is_caught(monster))
{
// See if we move into (and fight) an unfriendly monster.
- int targmon = mgrd[monster->x + mmov_x][monster->y + mmov_y];
+ int targmon = mgrd(monster->pos() + mmov);
if (targmon != NON_MONSTER
&& targmon != i
&& !mons_aligned(i, targmon))
@@ -6121,8 +6102,7 @@ static void _handle_monster_move(int i, monsters *monster)
// monster->speed_increment -= monster->speed;
}
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
brkk = true;
DEBUG_ENERGY_USE("monsters_fight()");
}
@@ -6131,8 +6111,7 @@ static void _handle_monster_move(int i, monsters *monster)
if (brkk)
continue;
- if (monster->x + mmov_x == you.x_pos
- && monster->y + mmov_y == you.y_pos)
+ if (monster->pos() + mmov == you.pos())
{
bool isFriendly = mons_friendly(monster);
bool attacked = false;
@@ -6166,9 +6145,8 @@ static void _handle_monster_move(int i, monsters *monster)
if (attacked)
{
- mmov_x = 0;
- mmov_y = 0;
- continue; //break;
+ mmov.reset();
+ continue;
}
}
@@ -6379,8 +6357,8 @@ static bool _handle_pickup(monsters *monster)
if (monster->max_hit_points < monster->hit_points)
monster->max_hit_points = monster->hit_points;
- if (!silenced(you.x_pos, you.y_pos)
- && !silenced(monster->x, monster->y))
+ if (!silenced(you.pos())
+ && !silenced(monster->pos()))
{
mprf(MSGCH_SOUND, "You hear a%s slurping noise.",
monsterNearby ? "" : " distant");
@@ -6421,8 +6399,8 @@ static bool _handle_pickup(monsters *monster)
static void _jelly_grows(monsters *monster)
{
- if (!silenced(you.x_pos, you.y_pos)
- && !silenced(monster->x, monster->y))
+ if (!silenced(you.pos())
+ && !silenced(monster->pos()))
{
mprf(MSGCH_SOUND, "You hear a%s slurping noise.",
mons_near(monster) ? "" : " distant");
@@ -6482,12 +6460,12 @@ static bool _mons_can_displace(const monsters *mpusher, const monsters *mpushee)
return (true);
}
-static bool _monster_swaps_places( monsters *mon, int mx, int my )
+static bool _monster_swaps_places( monsters *mon, const coord_def& delta )
{
- if (!mx && !my)
+ if (delta.x == 0 && delta.y)
return (false);
- int targmon = mgrd[mon->x + mx][mon->y + my];
+ int targmon = mgrd(mon->pos() + delta);
if (targmon == MHITNOT || targmon == MHITYOU)
return (false);
@@ -6510,77 +6488,71 @@ static bool _monster_swaps_places( monsters *mon, int mx, int my )
}
// Check that both monsters will be happy at their proposed new locations.
- const int cx = mon->x, cy = mon->y,
- nx = mon->x + mx, ny = mon->y + my;
+ const coord_def c = mon->pos();
+ const coord_def n = mon->pos() + delta;
- if (!_habitat_okay(mon, grd[nx][ny])
- || !_habitat_okay(m2, grd[cx][cy]))
- {
+ if (!_habitat_okay(mon, grd(n)) || !_habitat_okay(m2, grd(c)))
return (false);
- }
// Okay, do the swap!
_swim_or_move_energy(mon);
- mon->x = nx;
- mon->y = ny;
- mgrd[nx][ny] = monster_index(mon);
+ mon->x = n.x;
+ mon->y = n.y;
+ mgrd(n) = monster_index(mon);
- m2->x = cx;
- m2->y = cy;
+ m2->x = c.x;
+ m2->y = c.y;
const int m2i = monster_index(m2);
ASSERT(m2i >= 0 && m2i < MAX_MONSTERS);
- mgrd[cx][cy] = m2i;
+ mgrd(c) = m2i;
immobile_monster[m2i] = true;
- mon->check_redraw(coord_def(cx, cy));
+ mon->check_redraw(c);
mon->apply_location_effects();
m2->apply_location_effects();
return (false);
}
-static bool _do_move_monster(monsters *monster, int xi, int yi)
+static bool _do_move_monster(monsters *monster, const coord_def& delta)
{
- const int fx = monster->x + xi,
- fy = monster->y + yi;
+ const coord_def f = monster->pos() + delta;
- if (!in_bounds(fx, fy))
+ if (!in_bounds(f))
return (false);
- if (fx == you.x_pos && fy == you.y_pos)
+ if (f == you.pos())
{
monster_attack( monster_index(monster) );
return (true);
}
- if (!xi && !yi)
+ // XXX Is this necessary? Isn't it handled by the next case?
+ if (f == monster->pos())
{
const int mx = monster_index(monster);
monsters_fight( mx, mx );
return (true);
}
- if (mgrd[fx][fy] != NON_MONSTER)
+ if (mgrd(f) != NON_MONSTER)
{
- monsters_fight( monster_index(monster), mgrd[fx][fy] );
+ monsters_fight( monster_index(monster), mgrd(f) );
return (true);
}
- if (!xi && !yi)
- return (false);
-
// This appears to be the real one, ie where the movement occurs:
_swim_or_move_energy(monster);
- mgrd[monster->x][monster->y] = NON_MONSTER;
+ mgrd(monster->pos()) = NON_MONSTER;
- monster->x = fx;
- monster->y = fy;
+ monster->x = f.x;
+ monster->y = f.y;
- mgrd[monster->x][monster->y] = monster_index(monster);
+ mgrd(monster->pos()) = monster_index(monster);
- monster->check_redraw(monster->pos() - coord_def(xi, yi));
+ monster->check_redraw(monster->pos() - delta);
monster->apply_location_effects();
return (true);
@@ -6675,8 +6647,8 @@ static int _estimated_trap_damage(trap_type trap)
// regarded as safe. Takes into account monster intelligence and
// allegiance. (just_check is used for intelligent monsters trying to
// avoid traps.)
-static bool _is_trap_safe(const monsters *monster, const int trap_x,
- const int trap_y, bool just_check)
+static bool _is_trap_safe(const monsters *monster, const coord_def& where,
+ bool just_check)
{
const int intel = mons_intel(monster->type);
@@ -6684,7 +6656,7 @@ static bool _is_trap_safe(const monsters *monster, const int trap_x,
if (intel == I_PLANT)
return (true);
- const trap_struct &trap = env.trap[trap_at_xy(trap_x,trap_y)];
+ const trap_struct &trap = env.trap[trap_at_xy(where)];
if (trap.type == TRAP_SHAFT && monster->will_trigger_shaft())
{
@@ -6701,7 +6673,7 @@ static bool _is_trap_safe(const monsters *monster, const int trap_x,
// checks for them here.
const bool mechanical = trap_category(trap.type) == DNGN_TRAP_MECHANICAL;
- const bool player_knows_trap = (grd[trap_x][trap_y] != DNGN_UNDISCOVERED_TRAP);
+ const bool player_knows_trap = (grd(where) != DNGN_UNDISCOVERED_TRAP);
// Smarter trap handling for intelligent monsters
// * monsters native to a branch can be assumed to know the trap
@@ -6721,8 +6693,8 @@ static bool _is_trap_safe(const monsters *monster, const int trap_x,
else
{
// Test for corridor-like environment.
- const int x = trap_x - monster->x;
- const int y = trap_y - monster->y;
+ const int x = where.x - monster->x;
+ const int y = where.y - monster->y;
// The question is whether the monster (m) can easily reach its
// presumable destination (x) without stepping on the trap. Traps
@@ -6744,10 +6716,10 @@ static bool _is_trap_safe(const monsters *monster, const int trap_x,
// If a monster still gets stuck in a corridor it will usually be
// because it has less than half its maximum hp.
- if ((_mon_can_move_to_pos(monster, x-1, y, true)
- || _mon_can_move_to_pos(monster, x+1,y, true))
- && (_mon_can_move_to_pos(monster, x,y-1, true)
- || _mon_can_move_to_pos(monster, x,y+1, true)))
+ if ((_mon_can_move_to_pos(monster, coord_def(x-1, y), true)
+ || _mon_can_move_to_pos(monster, coord_def(x+1,y), true))
+ && (_mon_can_move_to_pos(monster, coord_def(x,y-1), true)
+ || _mon_can_move_to_pos(monster, coord_def(x,y+1), true)))
{
return (false);
}
@@ -6796,7 +6768,7 @@ static void _mons_open_door(monsters* monster, const coord_def &pos)
const coord_def& dc = *i;
if (grd(dc) == DNGN_SECRET_DOOR && see_grid(dc))
{
- grid = grid_secret_door_appearance(dc.x, dc.y);
+ grid = grid_secret_door_appearance(dc);
was_secret = true;
}
@@ -6845,32 +6817,30 @@ static void _mons_open_door(monsters* monster, const coord_def &pos)
// Check whether a monster can move to given square (described by its relative
// coordinates to the current monster position). just_check is true only for
// calls from is_trap_safe when checking the surrounding squares of a trap.
-static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
- const int count_y, bool just_check)
+static bool _mon_can_move_to_pos(const monsters *monster,
+ const coord_def& delta, bool just_check)
{
- const int targ_x = monster->x + count_x;
- const int targ_y = monster->y + count_y;
+ const coord_def targ = monster->pos() + delta;
// Bounds check - don't consider moving out of grid!
- if (!inside_level_bounds(targ_x, targ_y))
+ if (!inside_level_bounds(targ))
return (false);
// Non-friendly and non-good neutral monsters won't enter sanctuaries.
if (!mons_wont_attack(monster)
- && is_sanctuary(targ_x, targ_y)
- && !is_sanctuary(monster->x, monster->y))
+ && is_sanctuary(targ)
+ && !is_sanctuary(monster->pos()))
{
return (false);
}
// Inside a sanctuary don't attack anything!
- if (is_sanctuary(monster->x, monster->y)
- && (targ_x == you.x_pos && targ_y == you.y_pos
- || mgrd[targ_x][targ_y] != NON_MONSTER))
+ if (is_sanctuary(monster->pos())
+ && (targ == you.pos() || mgrd(targ) != NON_MONSTER))
{
return (false);
}
- const dungeon_feature_type target_grid = grd[targ_x][targ_y];
+ const dungeon_feature_type target_grid = grd(targ);
const habitat_type habitat = mons_habitat(monster);
// Effectively slows down monster movement across water.
@@ -6879,12 +6849,12 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
if (monster->type == MONS_FIRE_ELEMENTAL || one_chance_in(5))
no_water = true;
- const int targ_cloud_num = env.cgrid[ targ_x ][ targ_y ];
+ const int targ_cloud_num = env.cgrid(targ);
const int targ_cloud_type =
targ_cloud_num == EMPTY_CLOUD ? CLOUD_NONE
: env.cloud[targ_cloud_num].type;
- const int curr_cloud_num = env.cgrid[ monster->x ][ monster->y ];
+ const int curr_cloud_num = env.cgrid(monster->pos());
const int curr_cloud_type =
curr_cloud_num == EMPTY_CLOUD ? CLOUD_NONE
: env.cloud[curr_cloud_num].type;
@@ -6894,16 +6864,11 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
|| target_grid == DNGN_CLEAR_ROCK_WALL))
{
// Don't burrow out of bounds.
- // XXX: Are these bounds still valid? (jpeg)
- // We should probably use in_bounds() instead.
- if (targ_x <= 7 || targ_x >= (GXM - 8)
- || targ_y <= 7 || targ_y >= (GYM - 8))
- {
+ if (!in_bounds(targ))
return (false);
- }
// Don't burrow at an angle (legacy behaviour).
- if (count_x != 0 && count_y != 0)
+ if (delta.x != 0 && delta.y != 0)
return (false);
}
else if (!monster->can_pass_through_feat(target_grid)
@@ -6917,7 +6882,7 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
return (false);
}
- if (monster->type == MONS_WANDERING_MUSHROOM && see_grid(targ_x, targ_y))
+ if (monster->type == MONS_WANDERING_MUSHROOM && see_grid(targ))
return (false);
// Water elementals avoid fire and heat.
@@ -6943,9 +6908,9 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
// they're low on hitpoints. No point in hiding if they want a
// fight.
if (habitat == HT_WATER
- && (targ_x != you.x_pos || targ_y != you.y_pos)
+ && targ != you.pos()
&& target_grid != DNGN_DEEP_WATER
- && grd[monster->x][monster->y] == DNGN_DEEP_WATER
+ && grd(monster->pos()) == DNGN_DEEP_WATER
&& monster->hit_points < (monster->max_hit_points * 3) / 4)
{
return (false);
@@ -6958,18 +6923,18 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
// Smacking another monster is good, if the monsters
// are aligned differently.
- if (mgrd[targ_x][targ_y] != NON_MONSTER)
+ if (mgrd(targ) != NON_MONSTER)
{
if (just_check)
{
- if (targ_x == monster->x && targ_y == monster->y)
+ if (targ == monster->pos())
return (true);
return (false); // blocks square
}
const int thismonster = monster_index(monster),
- targmonster = mgrd[targ_x][targ_y];
+ targmonster = mgrd(targ);
if (mons_aligned(thismonster, targmonster)
&& targmonster != MHITNOT
@@ -6985,16 +6950,15 @@ static bool _mon_can_move_to_pos(const monsters *monster, const int count_x,
if (mons_wont_attack(monster)
&& monster->foe != MHITYOU
&& (monster->foe != MHITNOT || monster->is_patrolling())
- && targ_x == you.x_pos
- && targ_y == you.y_pos)
+ && targ == you.pos())
{
return (false);
}
// Wandering through a trap is OK if we're pretty healthy,
// really stupid, or immune to the trap.
- const int which_trap = trap_at_xy(targ_x,targ_y);
- if (which_trap >= 0 && !_is_trap_safe(monster, targ_x, targ_y, just_check))
+ const int which_trap = trap_at_xy(targ);
+ if (which_trap >= 0 && !_is_trap_safe(monster, targ, just_check))
return (false);
if (targ_cloud_num != EMPTY_CLOUD)
@@ -7116,35 +7080,35 @@ static bool _monster_move(monsters *monster)
mprf(MSGCH_TALK_VISUAL, "%s rages.",
monster->name(DESC_CAP_THE).c_str());
}
- noisy(noise_level, monster->x, monster->y);
+ noisy(noise_level, monster->pos());
}
else if (one_chance_in(5))
handle_monster_shouts(monster, true);
else
{
// Just be noisy without messaging the player.
- noisy(noise_level, monster->x, monster->y);
+ noisy(noise_level, monster->pos());
}
}
}
if (monster->confused())
{
- if (mmov_x || mmov_y || one_chance_in(15))
+ if (mmov.x || mmov.y || one_chance_in(15))
{
- coord_def newpos = monster->pos() + coord_def(mmov_x, mmov_y);
+ const coord_def newpos = monster->pos() + mmov;
if (in_bounds(newpos)
&& (habitat == HT_LAND
|| monster_habitable_grid(monster, grd(newpos))))
{
- return _do_move_monster(monster, mmov_x, mmov_y);
+ return _do_move_monster(monster, mmov);
}
}
return (false);
}
- // Let's not even bother with this if mmov_x and mmov_y are zero.
- if (mmov_x == 0 && mmov_y == 0)
+ // Let's not even bother with this if mmov.x and mmov.y are zero.
+ if (mmov.x == 0 && mmov.y == 0)
return (false);
for (count_x = 0; count_x < 3; count_x++)
@@ -7166,12 +7130,12 @@ static bool _monster_move(monsters *monster)
const monsters* mons = dynamic_cast<const monsters*>(monster);
good_move[count_x][count_y] =
- _mon_can_move_to_pos(mons, count_x-1, count_y-1);
+ _mon_can_move_to_pos(mons, coord_def(count_x-1, count_y-1));
}
// Now we know where we _can_ move.
- const coord_def newpos = monster->pos() + coord_def(mmov_x, mmov_y);
+ const coord_def newpos = monster->pos() + mmov;
// Normal/smart monsters know about secret doors
// (they _live_ in the dungeon!)
if (grd(newpos) == DNGN_CLOSED_DOOR
@@ -7195,15 +7159,14 @@ static bool _monster_move(monsters *monster)
} // endif - secret/closed doors
// Jellies eat doors. Yum!
- if ((grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_CLOSED_DOOR
- || grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_OPEN_DOOR)
+ if ((grd(newpos) == DNGN_CLOSED_DOOR || grd(newpos) == DNGN_OPEN_DOOR)
&& mons_itemuse(monster->type) == MONUSE_EATS_ITEMS)
{
- grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_FLOOR;
+ grd(newpos) = DNGN_FLOOR;
_jelly_grows(monster);
- if (see_grid(monster->x + mmov_x, monster->y + mmov_y))
+ if (see_grid(newpos))
{
viewwindow(true, false);
@@ -7221,10 +7184,9 @@ static bool _monster_move(monsters *monster)
// is in good health.
if (habitat == HT_WATER
&& deep_water_available
- && grd[monster->x][monster->y] != DNGN_DEEP_WATER
- && grd[monster->x + mmov_x][monster->y + mmov_y] != DNGN_DEEP_WATER
- && (monster->x + mmov_x != you.x_pos
- || monster->y + mmov_y != you.y_pos)
+ && grd(monster->pos()) != DNGN_DEEP_WATER
+ && grd(newpos) != DNGN_DEEP_WATER
+ && newpos != you.pos()
&& (one_chance_in(3)
|| monster->hit_points <= (monster->max_hit_points * 3) / 4))
{
@@ -7241,8 +7203,8 @@ static bool _monster_move(monsters *monster)
if (one_chance_in( count ))
{
- mmov_x = count_x - 1;
- mmov_y = count_y - 1;
+ mmov.x = count_x - 1;
+ mmov.y = count_y - 1;
}
}
}
@@ -7252,18 +7214,17 @@ static bool _monster_move(monsters *monster)
// either side. If they're both good, move in whichever dir
// gets it closer (farther for fleeing monsters) to its target.
// If neither does, do nothing.
- if (good_move[mmov_x + 1][mmov_y + 1] == false)
+ if (good_move[mmov.x + 1][mmov.y + 1] == false)
{
- int current_distance = grid_distance(monster->x, monster->y,
- monster->target_x,
- monster->target_y);
+ int current_distance = grid_distance(monster->pos(),
+ monster->target_pos());
int dir = -1;
int i, mod, newdir;
for (i = 0; i < 8; i++)
{
- if (compass_x[i] == mmov_x && compass_y[i] == mmov_y)
+ if (compass_x[i] == mmov.x && compass_y[i] == mmov.y)
{
dir = i;
break;
@@ -7318,14 +7279,14 @@ static bool _monster_move(monsters *monster)
{
if (dist[0] >= dist[1] && dist[0] >= current_distance)
{
- mmov_x = compass_x[((dir+8)+sdir)%8];
- mmov_y = compass_y[((dir+8)+sdir)%8];
+ mmov.x = compass_x[((dir+8)+sdir)%8];
+ mmov.y = compass_y[((dir+8)+sdir)%8];
break;
}
if (dist[1] >= dist[0] && dist[1] >= current_distance)
{
- mmov_x = compass_x[((dir+8)-sdir)%8];
- mmov_y = compass_y[((dir+8)-sdir)%8];
+ mmov.x = compass_x[((dir+8)-sdir)%8];
+ mmov.y = compass_y[((dir+8)-sdir)%8];
break;
}
}
@@ -7333,14 +7294,14 @@ static bool _monster_move(monsters *monster)
{
if (dist[0] <= dist[1] && dist[0] <= current_distance)
{
- mmov_x = compass_x[((dir+8)+sdir)%8];
- mmov_y = compass_y[((dir+8)+sdir)%8];
+ mmov.x = compass_x[((dir+8)+sdir)%8];
+ mmov.y = compass_y[((dir+8)+sdir)%8];
break;
}
if (dist[1] <= dist[0] && dist[1] <= current_distance)
{
- mmov_x = compass_x[((dir+8)-sdir)%8];
- mmov_y = compass_y[((dir+8)-sdir)%8];
+ mmov.x = compass_x[((dir+8)-sdir)%8];
+ mmov.y = compass_y[((dir+8)-sdir)%8];
break;
}
}
@@ -7356,29 +7317,26 @@ forget_it:
// Take care of beetle burrowing.
if (monster->type == MONS_BORING_BEETLE)
{
- dungeon_feature_type feat =
- grd[monster->x + mmov_x][monster->y + mmov_y];
+ const dungeon_feature_type feat = grd(monster->pos() + mmov);
if ((feat == DNGN_ROCK_WALL || feat == DNGN_ROCK_WALL)
- && good_move[mmov_x + 1][mmov_y + 1] == true)
+ && good_move[mmov.x + 1][mmov.y + 1] == true)
{
- grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_FLOOR;
- set_terrain_changed(monster->pos() + coord_def(mmov_x, mmov_y));
+ grd(monster->pos() + mmov) = DNGN_FLOOR;
+ set_terrain_changed(monster->pos() + mmov);
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
mpr("You hear a grinding noise.", MSGCH_SOUND);
}
}
bool ret = false;
- if (good_move[mmov_x + 1][mmov_y + 1] && !(mmov_x == 0 && mmov_y == 0))
+ if (good_move[mmov.x + 1][mmov.y + 1] && !(mmov.x == 0 && mmov.y == 0))
{
// Check for attacking player.
- if (monster->x + mmov_x == you.x_pos
- && monster->y + mmov_y == you.y_pos)
+ if (monster->pos() + mmov == you.pos())
{
ret = monster_attack( monster_index(monster) );
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
}
// If we're following the player through stairs, the only valid
@@ -7400,8 +7358,7 @@ forget_it:
else
{
ret = true;
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
#if DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS,
@@ -7412,11 +7369,11 @@ forget_it:
}
// Check for attacking another monster.
- int targmon = mgrd[monster->x + mmov_x][monster->y + mmov_y];
+ int targmon = mgrd(monster->pos() + mmov);
if (targmon != NON_MONSTER)
{
if (mons_aligned(monster_index(monster), targmon))
- ret = _monster_swaps_places(monster, mmov_x, mmov_y);
+ ret = _monster_swaps_places(monster, mmov);
else
{
monsters_fight(monster_index(monster), targmon);
@@ -7424,35 +7381,34 @@ forget_it:
}
// If the monster swapped places, the work's already done.
- mmov_x = 0;
- mmov_y = 0;
+ mmov.reset();
}
if (monster->type == MONS_EFREET
|| monster->type == MONS_FIRE_ELEMENTAL)
{
- place_cloud( CLOUD_FIRE, monster->x, monster->y,
+ place_cloud( CLOUD_FIRE, monster->pos(),
2 + random2(4), monster->kill_alignment() );
}
if (monster->type == MONS_ROTTING_DEVIL
|| monster->type == MONS_CURSE_TOE)
{
- place_cloud( CLOUD_MIASMA, monster->x, monster->y,
+ place_cloud( CLOUD_MIASMA, monster->pos(),
2 + random2(3), monster->kill_alignment() );
}
}
else
{
- mmov_x = mmov_y = 0;
+ mmov.reset();
// Fleeing monsters that can't move will panic and possibly
// turn to face their attacker.
_make_mons_stop_fleeing(monster);
}
- if (mmov_x || mmov_y || (monster->confused() && one_chance_in(6)))
- return _do_move_monster(monster, mmov_x, mmov_y);
+ if (mmov.x || mmov.y || (monster->confused() && one_chance_in(6)))
+ return _do_move_monster(monster, mmov);
return ret;
} // end monster_move()
@@ -7636,7 +7592,7 @@ static void _mons_in_cloud(monsters *monster)
{
// We have no good coords to give the monster as the source of the
// disturbance other than the cloud itself.
- behaviour_event(monster, ME_DISTURB, MHITNOT, monster->x, monster->y);
+ behaviour_event(monster, ME_DISTURB, MHITNOT, monster->pos());
}
hurted = std::max(0, hurted);
diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h
index b9ac6c99d3..ab5eabbc14 100644
--- a/crawl-ref/source/monstuff.h
+++ b/crawl-ref/source/monstuff.h
@@ -105,7 +105,7 @@ void monster_cleanup(monsters *monster);
* called from: monstuff beam effects fight view
* *********************************************************************** */
void behaviour_event(monsters *mon, int event_type, int src = MHITNOT,
- int src_x = 0, int src_y = 0);
+ coord_def src_pos = coord_def() );
/* ***********************************************************************
* called from: fight - it_use3 - spells
@@ -124,7 +124,7 @@ bool monster_blink(monsters *monster);
* defaults are set up for player blink; monster blink should call with
* false, false
* *********************************************************************** */
-bool random_near_space( int ox, int oy, int &tx, int &ty,
+bool random_near_space( const coord_def& origin, coord_def& target,
bool allow_adjacent = false, bool restrict_LOS = true,
bool forbid_sanctuary = false);
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index 2a95359d18..f34e00c9b6 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -65,7 +65,7 @@ void mons_trap(monsters *monster)
bool monsterNearby = mons_near(monster);
// new function call {dlb}
- int which_trap = trap_at_xy(monster->x, monster->y);
+ int which_trap = trap_at_xy(monster->pos());
if (which_trap == -1)
return;
@@ -157,9 +157,9 @@ void mons_trap(monsters *monster)
return;
}
- noisy(12, monster->x, monster->y);
+ noisy(12, monster->pos());
- if (!silenced(you.x_pos, you.y_pos))
+ if (!silenced(you.pos()))
{
if (monsterNearby)
{
@@ -221,7 +221,7 @@ void mons_trap(monsters *monster)
if (!mons_is_summoned(monster))
{
- bleed_onto_floor(monster->x, monster->y, monster->type,
+ bleed_onto_floor(monster->pos(), monster->type,
damage_taken, true);
}
}
@@ -268,12 +268,12 @@ void mons_trap(monsters *monster)
}
}
trap_item( OBJ_MISSILES, MI_THROWING_NET,
- env.trap[which_trap].x, env.trap[which_trap].y );
+ env.trap[which_trap].pos() );
if (mons_is_caught(monster))
- mark_net_trapping(monster->x, monster->y);
+ mark_net_trapping(monster->pos());
- grd[env.trap[which_trap].x][env.trap[which_trap].y] = DNGN_FLOOR;
+ grd(env.trap[which_trap].pos()) = DNGN_FLOOR;
env.trap[which_trap].type = TRAP_UNASSIGNED;
break;
}
@@ -810,8 +810,7 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast)
case SPELL_CANTRIP:
{
const bool friendly = mons_friendly(monster);
- const bool buff_only = !friendly && is_sanctuary(you.x_pos,
- you.y_pos);
+ const bool buff_only = !friendly && is_sanctuary(you.pos());
bool need_friendly_stub = false;
const msg_channel_type channel = (friendly) ? MSGCH_FRIEND_ENCHANT
: MSGCH_MONSTER_ENCHANT;
@@ -1035,30 +1034,27 @@ void monster_teleport(monsters *monster, bool instan, bool silent)
mons_clear_trapping_net(monster);
- int newx, newy;
+ coord_def newpos;
while (true)
{
- newx = 10 + random2(GXM - 20);
- newy = 10 + random2(GYM - 20);
+ newpos.x = 10 + random2(GXM - 20);
+ newpos.y = 10 + random2(GYM - 20);
// Don't land on top of another monster.
- if (mgrd[newx][newy] != NON_MONSTER
- || newx == you.x_pos && newy == you.y_pos)
- {
+ if (mgrd(newpos) != NON_MONSTER || newpos == you.pos())
continue;
- }
- if (is_sanctuary(newx, newy) && !mons_wont_attack(monster))
+ if (is_sanctuary(newpos) && !mons_wont_attack(monster))
continue;
- if (monster_habitable_grid(monster, grd[newx][newy]))
+ if (monster_habitable_grid(monster, grd(newpos)))
break;
}
- monster->x = newx;
- monster->y = newy;
+ monster->x = newpos.x;
+ monster->y = newpos.y;
- mgrd[monster->x][monster->y] = monster_index(monster);
+ mgrd(monster->pos()) = monster_index(monster);
// Mimics change form/colour when teleported.
if (mons_is_mimic( monster->type ))
@@ -1564,9 +1560,8 @@ bool mons_throw(struct monsters *monster, struct bolt &pbolt, int hand_used)
fire_beam( pbolt, &item, !really_returns );
// The item can be destroyed before returning.
- if (really_returns && mons_thrown_object_destroyed(&item, pbolt.target_x,
- pbolt.target_y, true,
- pbolt.beam_source))
+ if (really_returns && mons_thrown_object_destroyed(&item, pbolt.target(),
+ true, pbolt.beam_source))
{
really_returns = false;
}
@@ -1598,14 +1593,14 @@ bool mons_throw(struct monsters *monster, struct bolt &pbolt, int hand_used)
return (true);
} // end mons_throw()
-bool mons_thrown_object_destroyed( item_def *item, int x, int y,
+bool mons_thrown_object_destroyed( item_def *item, const coord_def& where,
bool returning, int midx )
{
ASSERT( item != NULL );
bool destroyed = (item->base_type == OBJ_MISSILES
&& item->sub_type != MI_THROWING_NET && coinflip());
- bool hostile_grid = grid_destroys_items(grd[x][y]);
+ bool hostile_grid = grid_destroys_items(grd(where));
// Non-returning items thrown into item-destroying grids are always
// destroyed. Returning items are only destroyed if they would have
@@ -1675,13 +1670,13 @@ void spore_goes_pop(monsters *monster)
if (you.can_see(monster))
{
viewwindow(true, false);
- if (is_sanctuary(monster->x, monster->y))
+ if (is_sanctuary(monster->pos()))
mpr(sanct_msg, MSGCH_GOD);
else
mpr(msg);
}
- if (is_sanctuary(monster->x, monster->y))
+ if (is_sanctuary(monster->pos()))
return;
explosion(beam, false, false, true, true, mons_near(monster));
@@ -2357,7 +2352,7 @@ static int _monster_abjure_square(const coord_def &pos,
if (pow < abj.duration)
simple_god_message(" shields your ally from puny magic!");
}
- else if (is_sanctuary(target->x, target->y))
+ else if (is_sanctuary(target->pos()))
{
mpr("Zin's power protects your fellow warrior from evil magic!",
MSGCH_GOD);
@@ -2519,24 +2514,21 @@ bool orc_battle_cry(monsters *chief)
seen_affected.push_back(mon);
if (mon->asleep())
- {
- behaviour_event(mon, ME_DISTURB, MHITNOT,
- chief->x, chief->y);
- }
+ behaviour_event(mon, ME_DISTURB, MHITNOT, chief->pos());
}
}
}
if (affected)
{
- if (you.can_see(chief) && player_can_hear(chief->x, chief->y))
+ if (you.can_see(chief) && player_can_hear(chief->pos()))
{
mprf(MSGCH_SOUND, "%s roars a battle-cry!",
chief->name(DESC_CAP_THE).c_str());
}
// The yell happens whether you happen to see it or not.
- noisy(15, chief->x, chief->y);
+ noisy(15, chief->pos());
// Disabling detailed frenzy announcement because it's so spammy.
const msg_channel_type channel =
@@ -2619,11 +2611,8 @@ static bool _make_monster_angry(const monsters *mon, monsters *targ)
bool moth_incite_monsters(const monsters *mon)
{
- if (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(mon->x, mon->y))
- {
- return 0;
- }
+ if (is_sanctuary(you.pos()) || is_sanctuary(mon->pos()))
+ return false;
int goaded = 0;
for (int i = 0; i < MAX_MONSTERS; ++i)
@@ -2635,7 +2624,7 @@ bool moth_incite_monsters(const monsters *mon)
if (mon->pos().distance_from(targ->pos()) > 3)
continue;
- if (is_sanctuary(targ->x, targ->y))
+ if (is_sanctuary(targ->pos()))
continue;
// Cannot goad other moths of wrath!
@@ -2654,7 +2643,7 @@ void mons_clear_trapping_net(monsters *mon)
if (!mons_is_caught(mon))
return;
- const int net = get_trapping_net(mon->x, mon->y);
+ const int net = get_trapping_net(mon->pos());
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
diff --git a/crawl-ref/source/mstuff2.h b/crawl-ref/source/mstuff2.h
index 6c364f8eeb..d84cd2f435 100644
--- a/crawl-ref/source/mstuff2.h
+++ b/crawl-ref/source/mstuff2.h
@@ -22,79 +22,17 @@
struct bolt;
-/*
- beam_colour = _pass[0];
- beam_range = _pass[1];
- beam_damage = _pass[2];
- beam_hit = _pass[3];
- beam_type = _pass[4];
- beam_flavour = _pass[5];
- thing_thrown = _pass[6];
- */
-
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: monstuff - mstuff2
- * *********************************************************************** */
bolt mons_spells(monsters *mons, spell_type spell_cast, int power);
-
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
-void setup_dragon(monsters *monster, struct bolt &pbolt);
-
-
-// last updated 13feb2001 {gdl}
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
+void setup_dragon(monsters *monster, bolt &pbolt);
void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast);
-
-// last updated 7jan2001 {gdl}
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
-void setup_mons_cast(monsters *monster, bolt &pbolt,
- spell_type spell_cast);
-
-// last updated 28july2000 (gdl)
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
-bool mons_throw(monsters *monster, struct bolt &pbolt, int hand_used);
-
-bool mons_thrown_object_destroyed( item_def *item, int x, int y,
+void setup_mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast);
+bool mons_throw(monsters *monster, bolt &pbolt, int hand_used);
+bool mons_thrown_object_destroyed( item_def *item, const coord_def& where,
bool returning, int midx );
-
-// last updated 07jan2001 (gdl)
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
-void setup_generic_throw(monsters *monster, struct bolt &pbolt);
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
+void setup_generic_throw(monsters *monster, bolt &pbolt);
void mons_trap(monsters *monster);
-
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: beam - fight - files - monstuff - mstuff2 - spells4
- * *********************************************************************** */
void monster_teleport(monsters *monster, bool instan, bool silent = false);
-
-
-// last updated Dec17,2000 -- gdl
-/* ***********************************************************************
- * called from: monstuff
- * *********************************************************************** */
void spore_goes_pop(monsters *monster);
-
bool orc_battle_cry(monsters *chief);
bool orange_statue_effects(monsters *mons);
bool silver_statue_effects(monsters *mons);
diff --git a/crawl-ref/source/mtransit.cc b/crawl-ref/source/mtransit.cc
index ab19b6f819..d76b3e13c3 100644
--- a/crawl-ref/source/mtransit.cc
+++ b/crawl-ref/source/mtransit.cc
@@ -216,7 +216,7 @@ void place_transiting_items()
= dgn_find_nearby_stair(DNGN_ESCAPE_HATCH_DOWN, pos, true);
// List of items we couldn't place
- if (!copy_item_to_grid(*item, where_to_go.x, where_to_go.y))
+ if (!copy_item_to_grid(*item, where_to_go))
keep.push_back(*item);
}
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 4e0df5df79..9e2de8619c 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -540,7 +540,8 @@ static void _expose_invent_to_element(beam_type flavour, int strength)
}
}
-void expose_items_to_element(beam_type flavour, int x, int y, int strength)
+void expose_items_to_element(beam_type flavour, const coord_def& where,
+ int strength)
{
int num_dest = 0;
@@ -548,7 +549,7 @@ void expose_items_to_element(beam_type flavour, int x, int y, int strength)
if (target_class == OBJ_UNASSIGNED)
return;
- for (stack_iterator si(coord_def(x,y)); si; ++si)
+ for (stack_iterator si(where); si; ++si)
{
if (!is_valid_item(*si))
continue;
@@ -570,7 +571,7 @@ void expose_items_to_element(beam_type flavour, int x, int y, int strength)
if (num_dest)
{
- if (see_grid(x, y))
+ if (see_grid(where))
{
switch (target_class)
{
diff --git a/crawl-ref/source/ouch.h b/crawl-ref/source/ouch.h
index 18ca77f210..9408b60a6c 100644
--- a/crawl-ref/source/ouch.h
+++ b/crawl-ref/source/ouch.h
@@ -107,7 +107,8 @@ void lose_level(void);
* *********************************************************************** */
void drain_exp(bool announce_full = true);
-void expose_items_to_element(beam_type flavour, int x, int y, int strength = 0);
+void expose_items_to_element(beam_type flavour, const coord_def& where,
+ int strength = 0);
void expose_player_to_element(beam_type flavour, int strength = 0);
#endif
diff --git a/crawl-ref/source/overmap.cc b/crawl-ref/source/overmap.cc
index 580c7b9426..cd121b4e1c 100644
--- a/crawl-ref/source/overmap.cc
+++ b/crawl-ref/source/overmap.cc
@@ -561,7 +561,7 @@ void seen_other_thing( dungeon_feature_type which_thing, const coord_def& pos )
{
case DNGN_ENTER_SHOP:
shops_present[where] =
- static_cast<shop_type>(get_shop(pos.x, pos.y)->type);
+ static_cast<shop_type>(get_shop(pos)->type);
break;
default:
const portal_type portal = feature_to_portal(which_thing);
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index d8a70c7848..274cb05794 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -107,34 +107,32 @@ static void _attribute_increase();
// allow_shift - allowed to scramble in any direction out of lava/water
// force - ignore safety checks, move must happen (traps, lava/water).
// swapping - player is swapping with a monster at (x,y)
-bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
+bool move_player_to_grid( const coord_def& p, bool stepped, bool allow_shift,
bool force, bool swapping )
{
- ASSERT( in_bounds( x, y ) );
+ ASSERT( in_bounds( p ) );
- int id;
// assuming that entering the same square means coming from above (levitate)
- const bool from_above = (you.x_pos == x && you.y_pos == y);
- const dungeon_feature_type old_grid = (from_above) ? DNGN_FLOOR
- : grd[you.x_pos][you.y_pos];
- const dungeon_feature_type new_grid = grd[x][y];
+ const bool from_above = (you.pos() == p);
+ const dungeon_feature_type old_grid = (from_above) ? DNGN_FLOOR : grd(p);
+ const dungeon_feature_type new_grid = grd(p);
// Really must be clear.
ASSERT( you.can_pass_through_feat( new_grid ) );
// Better not be an unsubmerged monster either.
- ASSERT(swapping && mgrd[x][y] != NON_MONSTER ||
- !swapping && (mgrd[x][y] == NON_MONSTER
- || mons_is_submerged( &menv[ mgrd[x][y] ])));
+ ASSERT(swapping && mgrd(p) != NON_MONSTER ||
+ !swapping && (mgrd(p) == NON_MONSTER
+ || mons_is_submerged( &menv[ mgrd(p) ])));
- const int cloud = env.cgrid[x][y];
+ const int cloud = env.cgrid(p);
if (cloud != EMPTY_CLOUD)
{
const cloud_type ctype = env.cloud[ cloud ].type;
// Don't prompt if already in a cloud of the same type.
if (is_damaging_cloud(ctype, false)
- && (env.cgrid[you.x_pos][you.y_pos] == EMPTY_CLOUD
- || ctype != env.cloud[ env.cgrid[you.x_pos][you.y_pos] ].type))
+ && (env.cgrid(you.pos()) == EMPTY_CLOUD
+ || ctype != env.cloud[ env.cgrid(you.pos()) ].type))
{
std::string prompt = make_stringf(
"Really step into that cloud of %s?",
@@ -160,9 +158,9 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
if (random2( skill ) > 6)
{
- id = trap_at_xy( x, y );
+ const int id = trap_at_xy( p );
if (id != -1)
- grd[x][y] = trap_category( env.trap[id].type );
+ grd(p) = trap_category( env.trap[id].type );
viewwindow(true, false);
@@ -187,7 +185,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
#endif
|| new_grid == DNGN_TRAP_NATURAL)
{
- const trap_type type = trap_type_at_xy(x,y);
+ const trap_type type = trap_type_at_xy(p);
if (type == TRAP_ZOT)
{
if (!yes_or_no("Do you really want to step into the Zot trap"))
@@ -208,7 +206,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
// as defined in init.txt (see trapwalk.lua)
if (new_grid != DNGN_TRAP_MECHANICAL
|| !clua.callbooleanfn(false, "ch_cross_trap",
- "s", trap_name(x, y)))
+ "s", trap_name(p.x, p.y)))
#endif
{
std::string prompt = make_stringf(
@@ -236,8 +234,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
if (is_grid_dangerous(new_grid))
{
// lava and dangerous deep water (ie not merfolk)
- int entry_x = (stepped) ? you.x_pos : x;
- int entry_y = (stepped) ? you.y_pos : y;
+ const coord_def entry = (stepped) ? you.pos() : p;
if (stepped && !force && !you.duration[DUR_CONF])
{
@@ -246,12 +243,12 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
}
// Have to move now so fall_into_a_pool will work.
- you.moveto(x, y);
+ you.moveto(p);
viewwindow( true, false );
// If true, we were shifted and so we're done.
- if (fall_into_a_pool( entry_x, entry_y, allow_shift, new_grid ))
+ if (fall_into_a_pool( entry, allow_shift, new_grid ))
return (true);
}
else if (new_grid == DNGN_SHALLOW_WATER || new_grid == DNGN_DEEP_WATER)
@@ -275,7 +272,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
ASSERT( new_grid != DNGN_DEEP_WATER );
if (!stepped)
- noisy(SL_SPLASH, you.x_pos, you.y_pos, "Splash!");
+ noisy(SL_SPLASH, you.pos(), "Splash!");
you.time_taken *= 13 + random2(8);
you.time_taken /= 10;
@@ -300,7 +297,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
}
// Move the player to new location.
- you.moveto(x, y);
+ you.moveto(p);
viewwindow( true, false );
@@ -316,7 +313,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
// Traps go off.
if (new_grid >= DNGN_TRAP_MECHANICAL && new_grid <= DNGN_UNDISCOVERED_TRAP)
{
- id = trap_at_xy( you.x_pos, you.y_pos );
+ int id = trap_at_xy( you.pos() );
if (id != -1)
{
@@ -328,7 +325,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
const dungeon_feature_type type =
trap_category( env.trap[id].type );
- grd[you.x_pos][you.y_pos] = type;
+ grd(you.pos()) = type;
set_envmap_obj(you.x_pos, you.y_pos, type);
}
@@ -2690,9 +2687,8 @@ void check_beholders()
continue;
}
const coord_def pos = mon->pos();
- int walls = num_feats_between(you.x_pos, you.y_pos,
- pos.x, pos.y, DNGN_UNSEEN,
- DNGN_MAXWALL);
+ int walls = num_feats_between(you.pos(), pos,
+ DNGN_UNSEEN, DNGN_MAXWALL);
if (walls > 0)
{
@@ -5546,8 +5542,7 @@ void player::init()
x_pos = 0;
y_pos = 0;
- prev_move_x = 0;
- prev_move_y = 0;
+ prev_move = coord_def(0,0);
running.clear();
travel_x = 0;
@@ -6667,15 +6662,9 @@ void player::moveto(const coord_def &c)
}
}
-coord_def player::prev_move() const
-{
- return coord_def(prev_move_x, prev_move_y);
-}
-
void player::reset_prev_move()
{
- prev_move_x = 0;
- prev_move_y = 0;
+ prev_move = coord_def(0,0);
}
bool player::asleep() const
@@ -6957,7 +6946,7 @@ bool player::do_shaft()
// Handle instances of do_shaft() being invoked magically when
// the player isn't standing over a shaft.
- if (trap_type_at_xy(x_pos, y_pos) != TRAP_SHAFT)
+ if (trap_type_at_xy(this->pos()) != TRAP_SHAFT)
{
switch(grd[x_pos][y_pos])
{
@@ -6977,7 +6966,7 @@ bool player::do_shaft()
if (airborne() || total_weight() == 0)
{
mpr("A shaft briefly opens up underneath you!");
- handle_items_on_shaft(you.x_pos, you.y_pos, false);
+ handle_items_on_shaft(you.pos(), false);
return (true);
}
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index b5c3a0bc39..e1e40054f1 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -27,7 +27,7 @@ enum genus_type
GENPC_OGRE
};
-bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
+bool move_player_to_grid( const coord_def& p, bool stepped, bool allow_shift,
bool force, bool swapping = false );
bool player_in_mappable_area(void);
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 5a2b02235e..705830d21e 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -803,10 +803,7 @@ static void _inc_penance(god_type god, int val)
you.penance[god] += val;
if (god == GOD_BEOGH && _need_water_walking() && !beogh_water_walk())
- {
- fall_into_a_pool( you.x_pos, you.y_pos, true,
- grd[you.x_pos][you.y_pos] );
- }
+ fall_into_a_pool( you.pos(), true, grd(you.pos()) );
}
static void _inc_penance(int val)
@@ -1059,7 +1056,7 @@ static void _give_nemelex_gift()
deck.colour = deck_rarity_to_color(rarity);
deck.inscription = "god gift";
- move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
+ move_item_to_grid( &thing_created, you.pos() );
origin_acquired(deck, you.religion);
simple_god_message(" grants you a gift!");
@@ -1885,7 +1882,7 @@ static void _do_god_gift(bool prayed_for)
if (thing_created == NON_ITEM)
return;
- move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
+ move_item_to_grid( &thing_created, you.pos() );
if (thing_created != NON_ITEM)
{
@@ -3277,7 +3274,7 @@ bool trog_burn_books()
if (durat > 23)
durat = 23;
- place_cloud( CLOUD_FIRE, ri->x, ri->y, durat, KC_YOU );
+ place_cloud( CLOUD_FIRE, *ri, durat, KC_YOU );
mpr(count == 1 ? "The book bursts into flames."
: "The books burst into flames.", MSGCH_GOD);
@@ -3354,10 +3351,7 @@ void lose_piety(int pgn)
}
if (_need_water_walking() && !beogh_water_walk())
- {
- fall_into_a_pool(you.x_pos, you.y_pos, true,
- grd[you.x_pos][you.y_pos]);
- }
+ fall_into_a_pool(you.pos(), true, grd(you.pos()));
}
}
}
@@ -3433,7 +3427,7 @@ static bool _tso_retribution()
if (coinflip())
{
simple_god_message(" booms out: \"Take the path of righteousness! REPENT!\"", god);
- noisy(25, you.x_pos, you.y_pos); // same as scroll of noise
+ noisy(25, you.pos()); // same as scroll of noise
}
else
{
@@ -3536,7 +3530,7 @@ static bool _zin_retribution()
break;
case 9: // noisiness (10%)
simple_god_message(" booms out: \"Turn to the light! REPENT!\"", god);
- noisy(25, you.x_pos, you.y_pos); // same as scroll of noise
+ noisy(25, you.pos()); // same as scroll of noise
break;
}
return (false);
@@ -4854,10 +4848,7 @@ void excommunication(god_type new_god)
// You might have lost water walking at a bad time...
if (_need_water_walking())
- {
- fall_into_a_pool(you.x_pos, you.y_pos, true,
- grd[you.x_pos][you.y_pos]);
- }
+ fall_into_a_pool(you.pos(), true, grd(you.pos()));
// Penance has to come before retribution to prevent "mollify"
_inc_penance(old_god, 50);
@@ -5014,8 +5005,9 @@ static bool _bless_weapon( god_type god, int brand, int colour )
for (int i = -3; i <= 3; ++i)
for (int j = -3; j <= 3; j++)
{
- if (is_bloodcovered(you.x_pos+i, you.y_pos+j))
- env.map[you.x_pos+i][you.y_pos+j].property = FPROP_NONE;
+ coord_def tmp = you.pos() + coord_def(i,j);
+ if (is_bloodcovered(tmp))
+ env.map(tmp).property = FPROP_NONE;
}
}
@@ -5719,7 +5711,7 @@ void offer_corpse(int corpse)
// ritual sacrifice can also bloodify the ground
const int mons_class = mitm[corpse].plus;
const int max_chunks = mons_weight( mons_class ) / 150;
- bleed_onto_floor(you.x_pos, you.y_pos, mons_class, max_chunks, true);
+ bleed_onto_floor(you.pos(), mons_class, max_chunks, true);
destroy_item(corpse);
}
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 2d8a89827d..b383b1e548 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -232,7 +232,7 @@ static void _in_a_shop( int shopidx )
clrscr();
- const std::string hello = "Welcome to " + shop_name(shop.x, shop.y) + "!";
+ const std::string hello = "Welcome to " + shop_name(shop.pos()) + "!";
bool first = true;
int total_cost = 0;
@@ -494,7 +494,8 @@ static bool _purchase( int shop, int item_got, int cost, bool id )
// Shopkeepers will now place goods you can't carry outside the shop.
if (num < quant)
{
- move_item_to_grid( &item_got, env.shop[shop].x, env.shop[shop].y );
+ move_item_to_grid( &item_got,
+ coord_def(env.shop[shop].x, env.shop[shop].y) );
return (false);
}
return (true);
@@ -1649,7 +1650,7 @@ void shop()
if ( _shop_get_stock(i).empty() )
{
const shop_struct& shop = env.shop[i];
- mprf("%s appears to be closed.", shop_name(shop.x, shop.y).c_str());
+ mprf("%s appears to be closed.", shop_name(shop.pos()).c_str());
return;
}
@@ -1658,16 +1659,16 @@ void shop()
redraw_screen();
} // end shop()
-shop_struct *get_shop(int sx, int sy)
+shop_struct *get_shop(const coord_def& where)
{
- if (grd[sx][sy] != DNGN_ENTER_SHOP)
+ if (grd(where) != DNGN_ENTER_SHOP)
return (NULL);
// find shop
for (int shoppy = 0; shoppy < MAX_SHOPS; shoppy ++)
{
// find shop index plus a little bit of paranoia
- if (env.shop[shoppy].x == sx && env.shop[shoppy].y == sy &&
+ if (env.shop[shoppy].pos() == where &&
env.shop[shoppy].type != SHOP_UNASSIGNED)
{
return (&env.shop[shoppy]);
@@ -1676,20 +1677,20 @@ shop_struct *get_shop(int sx, int sy)
return (NULL);
}
-std::string shop_name(int sx, int sy, bool add_stop)
+std::string shop_name(const coord_def& where, bool add_stop)
{
- std::string name(shop_name(sx, sy));
+ std::string name(shop_name(where));
if (add_stop)
name += ".";
return (name);
}
-std::string shop_name(int sx, int sy)
+std::string shop_name(const coord_def& where)
{
- const shop_struct *cshop = get_shop(sx, sy);
+ const shop_struct *cshop = get_shop(where);
// paranoia
- if (grd[sx][sy] != DNGN_ENTER_SHOP)
+ if (grd(where) != DNGN_ENTER_SHOP)
return ("");
if (!cshop)
@@ -1729,7 +1730,7 @@ std::string shop_name(int sx, int sy)
if (shop_type != SHOP_GENERAL
&& shop_type != SHOP_GENERAL_ANTIQUE && shop_type != SHOP_DISTILLERY)
{
- int temp = sx + sy % 4;
+ int temp = where.x + where.y % 4;
sh_name += (temp == 0) ? " Shoppe" :
(temp == 1) ? " Boutique" :
(temp == 2) ? " Emporium"
diff --git a/crawl-ref/source/shopping.h b/crawl-ref/source/shopping.h
index 48ad569d6a..f434cf31ce 100644
--- a/crawl-ref/source/shopping.h
+++ b/crawl-ref/source/shopping.h
@@ -24,10 +24,10 @@ int randart_value( const item_def &item );
unsigned int item_value( item_def item, bool ident = false );
void shop();
-shop_struct *get_shop(int sx, int sy);
+shop_struct *get_shop(const coord_def& where);
-std::string shop_name(int sx, int sy);
-std::string shop_name(int sx, int sy, bool add_stop);
+std::string shop_name(const coord_def& where);
+std::string shop_name(const coord_def& where, bool add_stop);
bool shoptype_identifies_stock(shop_type type);
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index 5f9b8a3f4c..d4e5d520e0 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -106,7 +106,7 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink)
direction(beam, DIR_TARGET, TARG_ANY, -1, false, false, false,
"Blink to where?");
- if (!beam.isValid || coord_def(beam.tx, beam.ty) == you.pos())
+ if (!beam.isValid || coord_def(beam.target()) == you.pos())
{
if (!wizard_blink
&& !yesno("Are you sure you want to cancel this blink?",
@@ -120,9 +120,9 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink)
}
// Wizard blink can move past translucent walls.
- if (see_grid_no_trans(beam.tx, beam.ty))
+ if (see_grid_no_trans(beam.target()))
break;
- else if (trans_wall_blocking( beam.tx, beam.ty ))
+ else if (trans_wall_blocking( beam.target() ))
{
// Wizard blink can move past translucent walls.
if (wizard_blink)
@@ -160,7 +160,7 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink)
// no longer held in net
clear_trapping_net();
- move_player_to_grid(beam.tx, beam.ty, false, true, true);
+ move_player_to_grid(beam.target(), false, true, true);
// controlling teleport contaminates the player -- bwr
if (!wizard_blink)
@@ -182,7 +182,7 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink)
void random_blink(bool allow_partial_control, bool override_abyss)
{
- int tx, ty;
+ coord_def target;
bool succ = false;
if (scan_randarts(RAP_PREVENT_TELEPORTATION))
@@ -194,8 +194,8 @@ void random_blink(bool allow_partial_control, bool override_abyss)
}
// First try to find a random square not adjacent to the player,
// then one adjacent if that fails.
- else if (!random_near_space(you.x_pos, you.y_pos, tx, ty)
- && !random_near_space(you.x_pos, you.y_pos, tx, ty, true))
+ else if (!random_near_space(you.pos(), target)
+ && !random_near_space(you.pos(), target, true))
{
mpr("You feel jittery for a moment.");
}
@@ -219,7 +219,7 @@ void random_blink(bool allow_partial_control, bool override_abyss)
clear_trapping_net();
succ = true;
- you.moveto(tx, ty);
+ you.moveto(target);
if (you.level_type == LEVEL_ABYSS)
{
@@ -234,8 +234,6 @@ void random_blink(bool allow_partial_control, bool override_abyss)
you.duration[DUR_CONDENSATION_SHIELD] = 0;
you.redraw_armour_class = true;
}
-
- return;
}
bool fireball(int pow, bolt &beam)
@@ -293,13 +291,9 @@ void cast_chain_lightning(int pow)
beam.is_explosion = false;
beam.is_tracer = false;
- int sx, sy;
- int tx, ty;
- int i;
+ coord_def source, target;
- for (sx = you.x_pos, sy = you.y_pos;
- pow > 0;
- pow -= 8 + random2(13), sx = tx, sy = ty)
+ for (source = you.pos(); pow > 0; pow -= 8 + random2(13), source = target)
{
// infinity as far as this spell is concerned
// (Range - 1) is used because the distance is randomized and
@@ -309,17 +303,17 @@ void cast_chain_lightning(int pow)
int dist;
int count = 0;
- tx = -1;
- ty = -1;
+ target.x = -1;
+ target.y = -1;
- for (i = 0; i < MAX_MONSTERS; i++)
+ for (int i = 0; i < MAX_MONSTERS; i++)
{
- struct monsters *monster = &menv[i];
+ monsters *monster = &menv[i];
- if (monster->type == -1)
+ if (invalid_monster(monster))
continue;
- dist = grid_distance( sx, sy, monster->x, monster->y );
+ dist = grid_distance( source, monster->pos() );
// check for the source of this arc
if (!dist)
@@ -332,7 +326,7 @@ void cast_chain_lightning(int pow)
if (dist > min_dist)
continue;
- if (!check_line_of_sight( sx, sy, monster->x, monster->y ))
+ if (!check_line_of_sight( source, monster->pos() ))
continue;
count++;
@@ -343,16 +337,14 @@ void cast_chain_lightning(int pow)
if (!one_chance_in(10))
{
min_dist = dist;
- tx = monster->x;
- ty = monster->y;
+ target = monster->pos();
count = 0;
}
}
- else if (tx == -1 || one_chance_in(count))
+ else if (target.x == -1 || one_chance_in(count))
{
// either first target, or new selected target at min_dist
- tx = monster->x;
- ty = monster->y;
+ target = monster->pos();
// need to set min_dist for first target case
dist = std::max(dist, min_dist);
@@ -360,7 +352,7 @@ void cast_chain_lightning(int pow)
}
// now check if the player is a target
- dist = grid_distance(sx, sy, you.x_pos, you.y_pos);
+ dist = grid_distance(source, you.pos());
if (dist) // i.e., player was not the source
{
@@ -368,20 +360,19 @@ void cast_chain_lightning(int pow)
dist += (random2(3) - 1);
// select player if only, closest, or randomly selected
- if ((tx == -1
+ if ((target.x == -1
|| dist < min_dist
|| (dist == min_dist && one_chance_in(count + 1)))
- && check_line_of_sight(sx, sy, you.x_pos, you.y_pos))
+ && check_line_of_sight(source, you.pos()))
{
- tx = you.x_pos;
- ty = you.y_pos;
+ target = you.pos();
}
}
- const bool see_source = see_grid( sx, sy );
- const bool see_targ = see_grid( tx, ty );
+ const bool see_source = see_grid( source );
+ const bool see_targ = see_grid( target );
- if (tx == -1)
+ if (target.x == -1)
{
if (see_source)
mpr("The lightning grounds out.");
@@ -392,28 +383,28 @@ void cast_chain_lightning(int pow)
// Trying to limit message spamming here so we'll only mention
// the thunder when it's out of LoS.
if (!see_source)
- noisy(25, sx, sy, "You hear a mighty clap of thunder!");
+ noisy(25, source, "You hear a mighty clap of thunder!");
if (see_source && !see_targ)
mpr("The lightning arcs out of your line of sight!");
else if (!see_source && see_targ)
mpr("The lightning arc suddenly appears!");
- if (!see_grid_no_trans( tx, ty ))
+ if (!see_grid_no_trans( target ))
{
// It's no longer in the caster's LOS and influence.
pow = pow / 2 + 1;
}
- beam.source_x = sx;
- beam.source_y = sy;
- beam.target_x = tx;
- beam.target_y = ty;
+ beam.source_x = source.x;
+ beam.source_y = source.y;
+ beam.target_x = target.x;
+ beam.target_y = target.y;
beam.colour = LIGHTBLUE;
beam.damage = calc_dice(5, 12 + pow * 2 / 3);
// Be kinder to the player.
- if (tx == you.x_pos && ty == you.y_pos)
+ if (target == you.pos())
{
if (!(beam.damage.num /= 2))
beam.damage.num = 1;
@@ -558,7 +549,7 @@ bool conjure_flame(int pow)
if (durat > 23)
durat = 23;
- place_cloud( CLOUD_FIRE, spelld.tx, spelld.ty, durat, KC_YOU );
+ place_cloud( CLOUD_FIRE, spelld.target(), durat, KC_YOU );
return (true);
}
@@ -1707,21 +1698,12 @@ void manage_fire_shield(void)
if (!you.duration[DUR_FIRE_SHIELD])
return;
- char stx = 0, sty = 0;
-
- for (stx = -1; stx < 2; stx++)
- for (sty = -1; sty < 2; sty++)
- {
- if (sty == 0 && stx == 0)
- continue;
-
- //if ( one_chance_in(3) ) beam.range ++;
+ for ( radius_iterator ri(you.pos(), 1); ri; ++ri )
+ {
+ if ( *ri == you.pos() )
+ continue;
- if (!grid_is_solid(grd[you.x_pos + stx][you.y_pos + sty])
- && env.cgrid[you.x_pos + stx][you.y_pos + sty] == EMPTY_CLOUD)
- {
- place_cloud( CLOUD_FIRE, you.x_pos + stx, you.y_pos + sty,
- 1 + random2(6), KC_YOU );
- }
- }
+ if (!grid_is_solid(grd(*ri)) && env.cgrid(*ri) == EMPTY_CLOUD)
+ place_cloud( CLOUD_FIRE, *ri, 1 + random2(6), KC_YOU );
+ }
}
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index 7993961ffb..47101e47e0 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -242,8 +242,7 @@ int detect_creatures( int pow, bool telepathic )
if (mons_intel( mon->type ) == I_HIGH
&& mons_class_flag( mon->type, M_SPELLCASTER ))
{
- behaviour_event( mon, ME_DISTURB, MHITYOU,
- you.x_pos, you.y_pos );
+ behaviour_event( mon, ME_DISTURB, MHITYOU, you.pos() );
}
}
}
@@ -282,35 +281,29 @@ int corpse_rot(int power)
for (adx = minx; adx != maxx; adx += xinc)
for (ady = miny; ady != maxy; ady += yinc)
{
- if (see_grid_no_trans(adx, ady) && !is_sanctuary(adx, ady))
+ coord_def ad(adx, ady);
+ if (see_grid_no_trans(ad) && !is_sanctuary(ad))
{
- if (igrd[adx][ady] == NON_ITEM
- || env.cgrid[adx][ady] != EMPTY_CLOUD)
- {
+ if (igrd(ad) == NON_ITEM || env.cgrid(ad) != EMPTY_CLOUD)
continue;
- }
- int objl = igrd[adx][ady];
- int hrg = 0;
-
- while (objl != NON_ITEM)
+ for ( stack_iterator si(ad); si; ++si )
{
- if (mitm[objl].base_type == OBJ_CORPSES
- && mitm[objl].sub_type == CORPSE_BODY)
+ if (si->base_type == OBJ_CORPSES
+ && si->sub_type == CORPSE_BODY)
{
- if (!mons_skeleton(mitm[objl].plus))
- destroy_item(objl);
+ // Found a corpse. Skeletify it if possible.
+ if (!mons_skeleton(si->plus))
+ destroy_item(si->index());
else
- turn_corpse_into_skeleton(mitm[objl]);
+ turn_corpse_into_skeleton(*si);
- place_cloud(CLOUD_MIASMA, adx, ady,
+ place_cloud(CLOUD_MIASMA, ad,
4 + random2avg(16, 3), KC_YOU);
// Don't look for more corpses here.
break;
}
- hrg = mitm[objl].link;
- objl = hrg;
}
}
}
@@ -416,7 +409,7 @@ bool brand_weapon(brand_type which_brand, int power)
// Well, in theory, we could be silenced, but then how are
// we casting the brand spell?
msg += " shrieks in agony.";
- noisy(15, you.x_pos, you.y_pos);
+ noisy(15, you.pos());
duration_affected = 8;
break;
@@ -801,7 +794,7 @@ void drain_life(int pow)
hurted = 3 + random2(7) + random2(pow);
- behaviour_event(monster, ME_WHACK, MHITYOU, you.x_pos, you.y_pos);
+ behaviour_event(monster, ME_WHACK, MHITYOU, you.pos());
hurt_monster(monster, hurted);
@@ -1838,34 +1831,30 @@ bool cast_conjure_ball_lightning(int pow, god_type god)
for (int i = 0; i < how_many; ++i)
{
- int tx = -1, ty = -1;
-
+ coord_def target;
+ bool found = false;
for (int j = 0; j < 10; ++j)
{
- if (!random_near_space(you.x_pos, you.y_pos, tx, ty, true, true)
- && distance(you.x_pos, you.y_pos, tx, ty) <= 5)
+ if (!random_near_space(you.pos(), target, true, true)
+ && distance(you.pos(), target) <= 5)
{
+ found = true;
break;
}
}
// If we fail, we'll try the ol' summon next to player trick.
- if (tx == -1 || ty == -1)
- {
- tx = you.x_pos;
- ty = you.y_pos;
- }
+ if ( !found )
+ target = you.pos();
int monster =
mons_place(
mgen_data(MONS_BALL_LIGHTNING, BEH_FRIENDLY, 0,
- coord_def(tx, ty), MHITNOT,
- 0, god));
+ target, MHITNOT, 0, god));
if (monster != -1)
{
success = true;
-
menv[monster].add_ench(ENCH_SHORT_LIVED);
}
}
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index 2a2aee8b14..93adf4b69e 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -868,7 +868,7 @@ bool animate_a_corpse(const coord_def &a, corpse_type class_allowed,
god_type god, bool actual,
bool quiet)
{
- if (is_sanctuary(a.x, a.y))
+ if (is_sanctuary(a))
return (false);
bool success = false;
@@ -939,7 +939,7 @@ int animate_dead(actor *caster, int pow, beh_type beha, unsigned short hitting,
}
if (caster != &you)
- losight(losgrid, grd, c.x, c.y, true);
+ losight(losgrid, grd, c, true);
env_show_grid &los(caster == &you? env.no_trans_show : losgrid);
@@ -1475,7 +1475,7 @@ bool entomb(int powc)
// mechanical traps are destroyed {dlb}:
int which_trap;
- if ((which_trap = trap_at_xy(srx, sry)) != -1)
+ if ((which_trap = trap_at_xy(coord_def(srx, sry))) != -1)
{
if (trap_category(env.trap[which_trap].type)
== DNGN_TRAP_MECHANICAL)
@@ -1498,10 +1498,9 @@ bool entomb(int powc)
for (int i = you.beheld_by.size() - 1; i >= 0; i--)
{
const monsters* mon = &menv[you.beheld_by[i]];
- const coord_def pos = mon->pos();
- int walls = num_feats_between(you.x_pos, you.y_pos,
- pos.x, pos.y, DNGN_UNSEEN,
- DNGN_MAXWALL, true, true);
+ int walls = num_feats_between(you.pos(), mon->pos(),
+ DNGN_UNSEEN, DNGN_MAXWALL,
+ true, true);
if (walls > 0)
{
@@ -1530,7 +1529,7 @@ static int _inside_circle(int posx, int posy, int radius)
return -1;
const coord_def ep = grid2view(coord_def(posx, posy));
- if (!in_los_bounds(ep.x, ep.y))
+ if (!in_los_bounds(ep))
return -1;
int dist = distance(posx, posy, you.x_pos, you.y_pos);
@@ -1550,22 +1549,15 @@ bool remove_sanctuary(bool did_attack)
const int radius = 5;
bool seen_change = false;
- for (int x = -radius; x <= radius; x++)
- for (int y = -radius; y <= radius; y++)
- {
- int posx = env.sanctuary_pos.x + x;
- int posy = env.sanctuary_pos.y + y;
-
- if (posx <= 0 || posx > GXM || posy <= 0 || posy > GYM)
- continue;
-
- if (is_sanctuary(posx, posy))
- {
- env.map[posx][posy].property = FPROP_NONE;
- if (see_grid(coord_def(posx,posy)))
- seen_change = true;
- }
- }
+ for (radius_iterator ri(env.sanctuary_pos, radius, true, false); ri; ++ri)
+ {
+ if (is_sanctuary(*ri))
+ {
+ env.map(*ri).property = FPROP_NONE;
+ if (see_grid(*ri))
+ seen_change = true;
+ }
+ }
// do not reset so as to allow monsters to see if their fleeing source
// used to be the centre of a sanctuary
@@ -1597,7 +1589,7 @@ void decrease_sanctuary_radius()
if (size >= radius)
return;
- if (you.running && is_sanctuary(you.x_pos, you.y_pos))
+ if (you.running && is_sanctuary(you.pos()))
{
mpr("The sanctuary starts shrinking.", MSGCH_DURATION);
stop_running();
@@ -1684,11 +1676,11 @@ bool cast_sanctuary(const int power)
blood_count++;
}
- if (trap_type_at_xy(posx, posy) != NUM_TRAPS
+ if (trap_type_at_xy(pos) != NUM_TRAPS
&& grd(pos) == DNGN_UNDISCOVERED_TRAP)
{
const dungeon_feature_type type =
- trap_category( trap_type_at_xy(posx, posy) );
+ trap_category( trap_type_at_xy(pos) );
grd(pos) = type;
set_envmap_obj(posx, posy, type);
trap_count++;
@@ -1860,11 +1852,11 @@ bool project_noise(void)
mprf(MSGCH_DIAGNOSTICS, "Target square (%d,%d)", pos.x, pos.y );
#endif
- if (!silenced( pos.x, pos.y ))
+ if (!silenced( pos ))
{
if (in_bounds(pos) && !grid_is_solid(grd(pos)))
{
- noisy(30, pos.x, pos.y);
+ noisy(30, pos);
success = true;
}
diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc
index ae095ebe9a..a9688cd558 100644
--- a/crawl-ref/source/spells4.cc
+++ b/crawl-ref/source/spells4.cc
@@ -293,7 +293,7 @@ static int _shatter_walls(int x, int y, int pow, int garbage)
if (x_chance_in_y(chance, 100))
{
- noisy(30, x, y);
+ noisy(30, coord_def(x, y));
grd[x][y] = DNGN_FLOOR;
return (1);
@@ -311,7 +311,7 @@ void cast_shatter(int pow)
mpr("The dungeon shakes!");
else
{
- noisy(30, you.x_pos, you.y_pos);
+ noisy(30, you.pos());
mpr("The dungeon rumbles!", MSGCH_SOUND);
}
@@ -558,8 +558,8 @@ static int _ignite_poison_objects(int x, int y, int pow, int garbage)
if (strength > 0)
{
- place_cloud(CLOUD_FIRE, x, y, strength + roll_dice(3, strength / 4),
- KC_YOU);
+ place_cloud(CLOUD_FIRE, coord_def(x, y),
+ strength + roll_dice(3, strength / 4), KC_YOU);
}
return (strength);
@@ -743,7 +743,7 @@ void cast_ignite_poison(int pow)
if (totalstrength)
{
place_cloud(
- CLOUD_FIRE, you.x_pos, you.y_pos,
+ CLOUD_FIRE, you.pos(),
random2(totalstrength / 4 + 1) + random2(totalstrength / 4 + 1) +
random2(totalstrength / 4 + 1) + random2(totalstrength / 4 + 1) + 1,
KC_YOU);
@@ -1085,31 +1085,22 @@ void cast_swap(int pow)
static int _make_a_rot_cloud(int x, int y, int pow, cloud_type ctype)
{
- int next = 0, obj = mgrd[x][y];
-
- if (obj == NON_MONSTER)
- return 0;
-
- while (obj != NON_ITEM)
+ for ( stack_iterator si(coord_def(x,y)); si; ++si )
{
- next = mitm[obj].link;
-
- if (mitm[obj].base_type == OBJ_CORPSES
- && mitm[obj].sub_type == CORPSE_BODY)
+ if (si->base_type == OBJ_CORPSES
+ && si->sub_type == CORPSE_BODY)
{
- if (!mons_skeleton(mitm[obj].plus))
- destroy_item(obj);
+ if (!mons_skeleton(si->plus))
+ destroy_item(si->index());
else
- turn_corpse_into_skeleton(mitm[obj]);
+ turn_corpse_into_skeleton(*si);
- place_cloud(ctype, x, y,
+ place_cloud(ctype, coord_def(x,y),
(3 + random2(pow / 4) + random2(pow / 4) +
random2(pow / 4)),
KC_YOU);
return 1;
}
-
- obj = next;
}
return 0;
@@ -1118,7 +1109,7 @@ static int _make_a_rot_cloud(int x, int y, int pow, cloud_type ctype)
int make_a_normal_cloud(int x, int y, int pow, int spread_rate,
cloud_type ctype, kill_category whose)
{
- place_cloud( ctype, x, y,
+ place_cloud( ctype, coord_def(x, y),
(3 + random2(pow / 4) + random2(pow / 4) + random2(pow / 4)),
whose, spread_rate );
@@ -2022,7 +2013,7 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike
case DNGN_UNDISCOVERED_TRAP:
case DNGN_TRAP_MECHANICAL:
- trap = trap_at_xy(spd.tx, spd.ty);
+ trap = trap_at_xy(spd.target());
if (trap != -1
&& trap_category(env.trap[trap].type) != DNGN_TRAP_MECHANICAL)
{
@@ -2529,32 +2520,30 @@ static int _quadrant_blink(int x, int y, int pow, int garbage)
pow = 100;
const int dist = random2(6) + 2; // 2-7
- const int ox = you.x_pos + (x - you.x_pos) * dist;
- const int oy = you.y_pos + (y - you.y_pos) * dist;
+ coord_def orig;
+ orig.x = you.x_pos + (x - you.x_pos) * dist;
+ orig.y = you.y_pos + (y - you.y_pos) * dist;
// This can take a while if pow is high and there's lots of translucent
// walls nearby.
- int tx, ty;
+ coord_def target;
bool found = false;
for ( int i = 0; i < (pow*pow) / 500 + 1; ++i )
{
// Find a space near our target...
// First try to find a random square not adjacent to the player,
// then one adjacent if that fails.
- if (!random_near_space(ox, oy, tx, ty)
- && !random_near_space(ox, oy, tx, ty, true))
+ if (!random_near_space(orig, target)
+ && !random_near_space(orig, target, true))
{
return 0;
}
// ... which is close enough, and also far enough from us.
- if (distance(ox, oy, tx, ty) > 10
- && distance(you.x_pos, you.y_pos, tx, ty) < 8)
- {
+ if (distance(orig, target) > 10 && distance(you.pos(), target) < 8)
continue;
- }
- if (!see_grid_no_trans(tx, ty))
+ if (!see_grid_no_trans(target))
continue;
found = true;
@@ -2564,7 +2553,7 @@ static int _quadrant_blink(int x, int y, int pow, int garbage)
if (!found)
return(0);
- you.moveto(tx, ty);
+ you.moveto(target);
return 1;
}
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index ed711ad7a1..368efb48bf 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -2047,7 +2047,7 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail)
break;
case SPELL_CREATE_NOISE: // Unused, the player can shout to do this. - bwr
- noisy(25, you.x_pos, you.y_pos, "You hear a voice calling your name!");
+ noisy(25, you.pos(), "You hear a voice calling your name!");
break;
case SPELL_PROJECTED_NOISE:
@@ -3753,7 +3753,7 @@ static void _miscast_poison(int severity, const char* cause)
case 1:
msg::stream << "Noxious gasses pour from your "
<< your_hand(true) << "!" << std::endl;
- place_cloud(CLOUD_STINK, you.x_pos, you.y_pos,
+ place_cloud(CLOUD_STINK, you.pos(),
2 + random2(4), (cause ? KC_OTHER : KC_YOU) );
break;
}
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index 0ec9592511..9dc98a5779 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -270,7 +270,7 @@ void Stash::update()
feat = DNGN_FLOOR;
if (grid_is_trap(feat))
- trap = trap_type_at_xy(x, y);
+ trap = trap_type_at_xy(coord_def(x, y));
int objl = igrd[x][y];
// If this is your position, you know what's on this square
@@ -769,7 +769,7 @@ ShopInfo::ShopInfo(int xp, int yp) : x(xp), y(yp), name(), shoptype(-1),
{
// Most of our initialization will be done externally; this class is really
// a mildly glorified struct.
- const shop_struct *sh = get_shop(x, y);
+ const shop_struct *sh = get_shop(coord_def(x, y));
if (sh)
shoptype = sh->type;
}
@@ -1094,7 +1094,7 @@ ShopInfo &LevelStashes::get_shop(int x, int y)
return m_shops[i];
}
ShopInfo si(x, y);
- si.set_name(shop_name(x, y));
+ si.set_name(shop_name(coord_def(x, y)));
m_shops.push_back(si);
return get_shop(x, y);
}
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index e5d84a7e4b..1a56d27866 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -1171,9 +1171,9 @@ int distance( int x, int y, int x2, int y2 )
return ((dx * dx) + (dy * dy));
} // end distance()
-bool adjacent( int x, int y, int x2, int y2 )
+bool adjacent( const coord_def& p1, const coord_def& p2 )
{
- return (abs(x - x2) <= 1 && abs(y - y2) <= 1);
+ return grid_distance(p1, p2) <= 1;
}
bool silenced(int x, int y)
@@ -1577,7 +1577,7 @@ bool is_trap_square(dungeon_feature_type grid)
// applied to new games.
void zap_los_monsters()
{
- losight(env.show, grd, you.x_pos, you.y_pos);
+ losight(env.show, grd, you.pos());
for (int y = crawl_view.vlos1.y; y <= crawl_view.vlos2.y; ++y)
for (int x = crawl_view.vlos1.x; x <= crawl_view.vlos2.x; ++x)
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index d1eea67525..b43bb63cb3 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -151,7 +151,7 @@ int grid_distance( const coord_def& p1, const coord_def& p2 );
int grid_distance( int x, int y, int x2, int y2 );
int distance( const coord_def& p1, const coord_def& p2 );
int distance( int x, int y, int x2, int y2);
-bool adjacent( 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); }
diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc
index c9fd96f293..7ca50696e5 100644
--- a/crawl-ref/source/terrain.cc
+++ b/crawl-ref/source/terrain.cc
@@ -301,7 +301,7 @@ void get_door_description(int door_size, const char** adjective, const char** no
*noun = descriptions[idx+1];
}
-dungeon_feature_type grid_secret_door_appearance( int gx, int gy )
+dungeon_feature_type grid_secret_door_appearance( const coord_def& where )
{
dungeon_feature_type ret = DNGN_FLOOR;
@@ -312,7 +312,7 @@ dungeon_feature_type grid_secret_door_appearance( int gx, int gy )
if ((abs(dx) + abs(dy)) % 2 == 0)
continue;
- const dungeon_feature_type targ = grd[gx + dx][gy + dy];
+ const dungeon_feature_type targ = grd[where.x + dx][where.y + dy];
if (!grid_is_wall( targ ))
continue;
@@ -394,7 +394,7 @@ static bool _dgn_shift_item(const coord_def &pos, item_def &item)
if (in_bounds(np) && np != pos)
{
int index = item.index();
- move_item_to_grid(&index, np.x, np.y);
+ move_item_to_grid(&index, np);
return (true);
}
return (false);
@@ -426,7 +426,7 @@ static bool _dgn_shift_feature(const coord_def &pos)
if (dfeat == DNGN_ENTER_SHOP)
{
- if (shop_struct *s = get_shop(pos.x, pos.y))
+ if (shop_struct *s = get_shop(pos))
{
s->x = dest.x;
s->y = dest.y;
@@ -553,7 +553,7 @@ void dungeon_terrain_changed(const coord_def &pos,
{
monster_teleport( &menv[ mgrd(you.pos()) ], true, false);
}
- move_player_to_grid(pos.x, pos.y, false, true, false);
+ move_player_to_grid(pos, false, true, false);
}
}
else
@@ -564,7 +564,7 @@ void dungeon_terrain_changed(const coord_def &pos,
}
// Returns true if we manage to scramble free.
-bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift,
+bool fall_into_a_pool( const coord_def& entry, bool allow_shift,
unsigned char terrain )
{
bool escape = false;
@@ -627,13 +627,13 @@ bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift,
else
{
// back out the way we came in, if possible
- if (grid_distance( you.x_pos, you.y_pos, entry_x, entry_y ) == 1
- && (entry_x != empty[0] || entry_y != empty[1])
- && mgrd[entry_x][entry_y] == NON_MONSTER)
+ if (grid_distance( you.pos(), entry ) == 1
+ && (entry.x != empty[0] || entry.y != empty[1])
+ && mgrd(entry) == NON_MONSTER)
{
escape = true;
- empty[0] = entry_x;
- empty[1] = entry_y;
+ empty[0] = entry.x;
+ empty[1] = entry.y;
}
else // zero or two or more squares away, with no way back
{
@@ -655,7 +655,7 @@ bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift,
if (in_bounds(pos) && !is_grid_dangerous(grd(pos)))
{
mpr("You manage to scramble free!");
- move_player_to_grid( empty[0], empty[1], false, false, true );
+ move_player_to_grid( pos, false, false, true );
if (terrain == DNGN_LAVA)
expose_player_to_element( BEAM_LAVA, 14 );
diff --git a/crawl-ref/source/terrain.h b/crawl-ref/source/terrain.h
index 375778dd10..aad1a080e0 100644
--- a/crawl-ref/source/terrain.h
+++ b/crawl-ref/source/terrain.h
@@ -21,7 +21,7 @@ struct coord_def;
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
-bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift,
+bool fall_into_a_pool( const coord_def& entry, bool allow_shift,
unsigned char terrain );
@@ -50,7 +50,7 @@ void find_connected_range(coord_def d, dungeon_feature_type ft_min,
dungeon_feature_type ft_max,
std::set<coord_def>& out);
void get_door_description(int door_size, const char** adjective, const char** noun);
-dungeon_feature_type grid_secret_door_appearance( int gx, int gy );
+dungeon_feature_type grid_secret_door_appearance( const coord_def& where );
bool grid_destroys_items( dungeon_feature_type grid );
const char *grid_item_destruction_message( dungeon_feature_type grid );
diff --git a/crawl-ref/source/transfor.cc b/crawl-ref/source/transfor.cc
index 77a578a875..3818915442 100644
--- a/crawl-ref/source/transfor.cc
+++ b/crawl-ref/source/transfor.cc
@@ -521,7 +521,7 @@ bool transform(int pow, transformation_type which_trans, bool quiet)
{
mpr("The net rips apart!");
you.attribute[ATTR_HELD] = 0;
- int net = get_trapping_net(you.x_pos, you.y_pos);
+ int net = get_trapping_net(you.pos());
if (net != NON_ITEM)
destroy_item(net);
}
@@ -602,7 +602,7 @@ bool transform(int pow, transformation_type which_trans, bool quiet)
{
mpr("You drift through the net!");
you.attribute[ATTR_HELD] = 0;
- int net = get_trapping_net(you.x_pos, you.y_pos);
+ int net = get_trapping_net(you.pos());
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
}
@@ -750,7 +750,7 @@ void untransform(void)
}
// Re-check terrain now that be may no longer be flying.
- move_player_to_grid(you.x_pos, you.y_pos, false, true, true);
+ move_player_to_grid(you.pos(), false, true, true);
if (transform_can_butcher_barehanded(old_form))
stop_butcher_delay();
@@ -873,7 +873,7 @@ void drop_everything(void)
{
if (is_valid_item( you.inv[i] ))
{
- copy_item_to_grid( you.inv[i], you.x_pos, you.y_pos );
+ copy_item_to_grid( you.inv[i], you.pos() );
you.inv[i].quantity = 0;
}
}
diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc
index 0b726a678f..a448f9bb8f 100644
--- a/crawl-ref/source/traps.cc
+++ b/crawl-ref/source/traps.cc
@@ -47,9 +47,9 @@ static void dart_trap(bool trap_known, int trapped, bolt &pbolt, bool poison);
// Returns the number of a net on a given square.
// If trapped only stationary ones are counted
// otherwise the first net found is returned.
-int get_trapping_net(int x, int y, bool trapped)
+int get_trapping_net(const coord_def& where, bool trapped)
{
- for (stack_iterator si(coord_def(x,y)); si; ++si)
+ for (stack_iterator si(where); si; ++si)
{
if (si->base_type == OBJ_MISSILES
&& si->sub_type == MI_THROWING_NET
@@ -63,7 +63,7 @@ int get_trapping_net(int x, int y, bool trapped)
// If there are more than one net on this square
// split off one of them for checking/setting values.
-static void maybe_split_nets(item_def &item, int x, int y)
+static void maybe_split_nets(item_def &item, const coord_def& where)
{
if (item.quantity == 1)
{
@@ -85,17 +85,17 @@ static void maybe_split_nets(item_def &item, int x, int y)
item.quantity = 1;
set_item_stationary(item);
- copy_item_to_grid( it, x, y );
+ copy_item_to_grid( it, where );
}
-void mark_net_trapping(int x, int y)
+void mark_net_trapping(const coord_def& where)
{
- int net = get_trapping_net(x,y);
+ int net = get_trapping_net(where);
if (net == NON_ITEM)
{
- net = get_trapping_net(x,y, false);
+ net = get_trapping_net(where, false);
if (net != NON_ITEM)
- maybe_split_nets(mitm[net], x, y);
+ maybe_split_nets(mitm[net], where);
}
}
@@ -168,7 +168,7 @@ void player_caught_in_net()
if (you.flight_mode() == FL_FLY)
{
mpr("You fall like a stone!");
- fall_into_a_pool(you.x_pos, you.y_pos, false, grd(you.pos()));
+ fall_into_a_pool(you.pos(), false, grd(you.pos()));
}
stop_delay(true); // even stair delays
@@ -179,11 +179,11 @@ void check_net_will_hold_monster(monsters *mons)
{
if (mons->body_size(PSIZE_BODY) >= SIZE_GIANT)
{
- int net = get_trapping_net(mons->x, mons->y);
+ int net = get_trapping_net(mons->pos());
if (net != NON_ITEM)
destroy_item(net);
- if (see_grid(mons->x, mons->y))
+ if (see_grid(mons->pos()))
{
if (player_monster_visible(mons))
{
@@ -198,7 +198,7 @@ void check_net_will_hold_monster(monsters *mons)
|| mons->type == MONS_OOZE
|| mons->type == MONS_PULSATING_LUMP)
{
- const int net = get_trapping_net(mons->x, mons->y);
+ const int net = get_trapping_net(mons->pos());
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
@@ -287,7 +287,7 @@ static void dart_trap(bool trap_known, int trapped, bolt &pbolt, bool poison)
// itrap takes location from target_x, target_y of bolt strcture.
//
-void itrap( struct bolt &pbolt, int trapped )
+void itrap( bolt &pbolt, int trapped )
{
object_class_type base_type = OBJ_MISSILES;
int sub_type = MI_DART;
@@ -326,10 +326,10 @@ void itrap( struct bolt &pbolt, int trapped )
return;
}
- trap_item( base_type, sub_type, pbolt.target_x, pbolt.target_y );
+ trap_item( base_type, sub_type, pbolt.target() );
return;
-} // end itrap()
+}
void handle_traps(trap_type trt, int i, bool trap_known)
{
@@ -412,7 +412,7 @@ void handle_traps(trap_type trt, int i, bool trap_known)
return;
}
- noisy(12, you.x_pos, you.y_pos, "An alarm trap emits a blaring wail!");
+ noisy(12, you.pos(), "An alarm trap emits a blaring wail!");
break;
@@ -430,7 +430,7 @@ void handle_traps(trap_type trt, int i, bool trap_known)
int damage = (you.your_level * 2) + random2avg(29, 2)
- random2(1 + player_AC());
ouch( damage, 0, KILLED_BY_TRAP, " blade" );
- bleed_onto_floor(you.x_pos, you.y_pos, -1, damage, true);
+ bleed_onto_floor(you.pos(), -1, damage, true);
}
break;
@@ -450,11 +450,11 @@ void handle_traps(trap_type trt, int i, bool trap_known)
player_caught_in_net();
}
- trap_item( OBJ_MISSILES, MI_THROWING_NET, env.trap[i].x, env.trap[i].y );
+ trap_item( OBJ_MISSILES, MI_THROWING_NET, env.trap[i].pos());
if (you.attribute[ATTR_HELD])
- mark_net_trapping(you.x_pos, you.y_pos);
+ mark_net_trapping(you.pos());
- grd[env.trap[i].x][env.trap[i].y] = DNGN_FLOOR;
+ grd(env.trap[i].pos()) = DNGN_FLOOR;
env.trap[i].type = TRAP_UNASSIGNED;
}
break;
@@ -577,7 +577,8 @@ void disarm_trap( struct dist &disa )
return;
mpr("You stumble into the trap!");
- move_player_to_grid( env.trap[i].x, env.trap[i].y, true, false, true);
+ move_player_to_grid( coord_def(env.trap[i].x, env.trap[i].y),
+ true, false, true);
}
else
handle_traps(env.trap[i].type, i, false);
@@ -597,7 +598,7 @@ void disarm_trap( struct dist &disa )
beam.target_y = you.y_pos + disa.dy;
if (env.trap[i].type == TRAP_NET)
- trap_item( OBJ_MISSILES, MI_THROWING_NET, beam.target_x, beam.target_y );
+ trap_item( OBJ_MISSILES, MI_THROWING_NET, beam.target() );
else if (env.trap[i].type != TRAP_BLADE
&& trap_category(env.trap[i].type) == DNGN_TRAP_MECHANICAL)
{
@@ -625,7 +626,7 @@ void remove_net_from(monsters *mon)
{
you.turn_is_over = true;
- int net = get_trapping_net(mon->x, mon->y);
+ int net = get_trapping_net(mon->pos());
if (net == NON_ITEM)
{
@@ -772,7 +773,7 @@ static int damage_or_escape_net(int hold)
// becomes feasible (for size etc.), so it may take even longer.
void free_self_from_net()
{
- int net = get_trapping_net(you.x_pos, you.y_pos);
+ int net = get_trapping_net(you.pos());
if (net == NON_ITEM) // really shouldn't happen!
{
@@ -886,7 +887,7 @@ void clear_trapping_net()
if (!you.attribute[ATTR_HELD])
return;
- const int net = get_trapping_net(you.x_pos, you.y_pos);
+ const int net = get_trapping_net(you.pos());
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
@@ -894,7 +895,7 @@ void clear_trapping_net()
}
bool trap_item(object_class_type base_type, char sub_type,
- char beam_x, char beam_y)
+ const coord_def& where)
{
item_def item;
item.base_type = base_type;
@@ -919,24 +920,24 @@ bool trap_item(object_class_type base_type, char sub_type,
item_colour(item);
- if (igrd[beam_x][beam_y] != NON_ITEM)
+ if (igrd(where) != NON_ITEM)
{
- if (items_stack( item, mitm[ igrd[beam_x][beam_y] ] ))
+ if (items_stack( item, mitm[ igrd(where) ] ))
{
- inc_mitm_item_quantity( igrd[beam_x][beam_y], 1 );
+ inc_mitm_item_quantity( igrd(where), 1 );
return (false);
}
// don't want to go overboard here. Will only generate up to three
// separate trap items, or less if there are other items present.
- if (mitm[ igrd[beam_x][beam_y] ].link != NON_ITEM
+ if (mitm[ igrd(where) ].link != NON_ITEM
&& (item.base_type != OBJ_MISSILES
|| item.sub_type != MI_THROWING_NET))
{
- if (mitm[ mitm[ igrd[beam_x][beam_y] ].link ].link != NON_ITEM)
+ if (mitm[ mitm[ igrd(where) ].link ].link != NON_ITEM)
return (false);
}
- } // end of if igrd != NON_ITEM
+ }
// give appropriate racial flag for Orcish Mines and Elven Halls
// should we ever allow properties of dungeon features, we could use that
@@ -945,7 +946,7 @@ bool trap_item(object_class_type base_type, char sub_type,
else if (you.where_are_you == BRANCH_ELVEN_HALLS)
set_equip_race( item, ISFLAG_ELVEN );
- return (!copy_item_to_grid( item, beam_x, beam_y, 1 ));
+ return (!copy_item_to_grid( item, where, 1 ));
} // end trap_item()
// returns appropriate trap symbol for a given trap type {dlb}
@@ -975,12 +976,11 @@ dungeon_feature_type trap_category(trap_type type)
} // end trap_category()
// Returns index of the trap for a given (x,y) coordinate pair {dlb}
-int trap_at_xy(int which_x, int which_y)
+int trap_at_xy(const coord_def& xy)
{
for (int which_trap = 0; which_trap < MAX_TRAPS; which_trap++)
{
- if (env.trap[which_trap].x == which_x
- && env.trap[which_trap].y == which_y
+ if (env.trap[which_trap].pos() == xy
&& env.trap[which_trap].type != TRAP_UNASSIGNED)
{
return (which_trap);
@@ -991,9 +991,9 @@ int trap_at_xy(int which_x, int which_y)
return (-1);
}
-trap_type trap_type_at_xy(int x, int y)
+trap_type trap_type_at_xy(const coord_def& xy)
{
- const int idx = trap_at_xy(x, y);
+ const int idx = trap_at_xy(xy);
return (idx == -1 ? NUM_TRAPS : env.trap[idx].type);
}
@@ -1075,12 +1075,11 @@ level_id generic_shaft_dest(coord_def pos)
return generic_shaft_dest(level_pos(level_id::current(), pos));
}
-void handle_items_on_shaft(int x, int y, bool open_shaft)
+void handle_items_on_shaft(const coord_def& pos, bool open_shaft)
{
if (!is_valid_shaft_level())
return;
- coord_def pos(x, y);
level_id dest = generic_shaft_dest(pos);
if (dest == level_id::current())
diff --git a/crawl-ref/source/traps.h b/crawl-ref/source/traps.h
index 2604e3de28..4ba99a6212 100644
--- a/crawl-ref/source/traps.h
+++ b/crawl-ref/source/traps.h
@@ -21,7 +21,7 @@ struct bolt;
class monsters;
bool trap_item(object_class_type base_type, char sub_type,
- char beam_x, char beam_y);
+ const coord_def& where);
// last updated 12may2000 {dlb}
/* ***********************************************************************
@@ -36,8 +36,8 @@ void free_self_from_net(void);
* called from: acr - misc
* *********************************************************************** */
void handle_traps(trap_type trt, int i, bool trap_known);
-int get_trapping_net(int x, int y, bool trapped = true);
-void mark_net_trapping(int x, int y);
+int get_trapping_net(const coord_def& where, bool trapped = true);
+void mark_net_trapping(const coord_def& where);
void monster_caught_in_net(monsters *mon, bolt &pbolt);
void player_caught_in_net(void);
void clear_trapping_net(void);
@@ -46,12 +46,12 @@ void check_net_will_hold_monster(monsters *mon);
void itrap(struct bolt &pbolt, int trapped);
void destroy_trap( const coord_def& pos );
dungeon_feature_type trap_category(trap_type type);
-int trap_at_xy(int x, int y);
-trap_type trap_type_at_xy(int x, int y);
+int trap_at_xy(const coord_def& xy);
+trap_type trap_type_at_xy(const coord_def& xy);
bool is_valid_shaft_level(const level_id &place = level_id::current());
level_id generic_shaft_dest(coord_def pos);
-void handle_items_on_shaft(int x, int y, bool open_shaft);
+void handle_items_on_shaft(const coord_def& where, bool open_shaft);
int num_traps_for_place(int level_number = -1,
const level_id &place = level_id::current());
diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc
index b95cd72dc1..83048d6868 100644
--- a/crawl-ref/source/travel.cc
+++ b/crawl-ref/source/travel.cc
@@ -435,7 +435,7 @@ bool is_travelsafe_square(int x, int y, bool ignore_hostile,
&& is_terrain_changed(x, y))
{
const int c = get_envmap_obj(x, y);
- const int secret_door = grid_secret_door_appearance(x, y);
+ const int secret_door = grid_secret_door_appearance(coord_def(x, y));
return (c != secret_door);
}
@@ -3933,7 +3933,7 @@ void explore_discoveries::found_feature(const coord_def &pos,
{
if (grid == DNGN_ENTER_SHOP && ES_shop)
{
- shops.push_back( named_thing<int>( shop_name(pos.x, pos.y), grid ) );
+ shops.push_back( named_thing<int>( shop_name(pos), grid ) );
es_flags |= ES_SHOP;
}
else if (is_stair(grid) && ES_stair)
diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc
index 0da644b00b..2d6cae2aa4 100644
--- a/crawl-ref/source/tutorial.cc
+++ b/crawl-ref/source/tutorial.cc
@@ -1203,7 +1203,7 @@ void tutorial_first_monster(const monsters &mon)
// (highlighting is an unnecessary complication).
if (_mons_is_highlighted(&mon))
{
- noisy(1, mon.x, mon.y);
+ noisy(1, mon.pos());
viewwindow(true, false);
}
@@ -1938,7 +1938,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y)
case TUT_SEEN_SHOP:
#ifdef USE_TILE
tiles.place_cursor(CURSOR_TUTORIAL, gc);
- tiles.add_text_tag(TAG_TUTORIAL, shop_name(gc.x, gc.y), gc);
+ tiles.add_text_tag(TAG_TUTORIAL, shop_name(gc), gc);
#endif
text << "That "
#ifndef USE_TILE
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 1b226af0e0..82e6108f00 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -152,7 +152,7 @@ bool inside_level_bounds(int x, int y)
return (x > 0 && x < GXM && y > 0 && y < GYM);
}
-bool inside_level_bounds(coord_def &p)
+bool inside_level_bounds(const coord_def &p)
{
return (inside_level_bounds(p.x, p.y));
}
@@ -244,15 +244,15 @@ void set_envmap_prop( int x, int y, int prop )
env.map[x][y].property = prop;
}
-bool is_sanctuary(int x, int y)
+bool is_sanctuary(const coord_def& p)
{
- return (env.map[x][y].property == FPROP_SANCTUARY_1
- || env.map[x][y].property == FPROP_SANCTUARY_2);
+ return (env.map(p).property == FPROP_SANCTUARY_1
+ || env.map(p).property == FPROP_SANCTUARY_2);
}
-bool is_bloodcovered(int x, int y)
+bool is_bloodcovered(const coord_def& p)
{
- return (env.map[x][y].property == FPROP_BLOODY);
+ return (env.map(p).property == FPROP_BLOODY);
}
bool is_envmap_item(int x, int y)
@@ -414,7 +414,7 @@ static int _view_emphasised_colour(int x, int y, dungeon_feature_type feat,
static bool _show_bloodcovered(int x, int y)
{
- if (!is_bloodcovered(x,y))
+ if (!is_bloodcovered(coord_def(x,y)))
return (false);
dungeon_feature_type grid = grd[x][y];
@@ -441,8 +441,8 @@ static void _get_symbol( int x, int y,
{
const int colmask = *colour & COLFLAG_MASK;
- if (object < NUM_REAL_FEATURES
- && is_sanctuary(x,y) && object >= DNGN_MINMOVE)
+ if (object < NUM_REAL_FEATURES && object >= DNGN_MINMOVE
+ && is_sanctuary(coord_def(x,y)) )
{
if (env.map[x][y].property == FPROP_SANCTUARY_1)
*colour = YELLOW | colmask;
@@ -1103,7 +1103,7 @@ void handle_monster_shouts(monsters* monster, bool force)
const int noise_level = get_shout_noise_level(s_type);
if (noise_level > 0)
- noisy(noise_level, monster->x, monster->y);
+ noisy(noise_level, monster->pos());
}
#ifdef WIZARD
@@ -1532,21 +1532,19 @@ void cloud_grid(void)
// player is appropriate.
//
// Returns true if the PC heard the noise.
-bool noisy(int loudness, int nois_x, int nois_y, const char *msg)
+bool noisy(int loudness, const coord_def& where, const char *msg)
{
- struct monsters *monster = 0; // NULL {dlb}
bool ret = false;
// If the origin is silenced there is no noise.
- if (silenced(nois_x, nois_y))
+ if (silenced(where))
return (false);
const int dist = loudness * loudness;
+ const int player_distance = distance( you.pos(), where );
- const int player_distance =
- distance( you.x_pos, you.y_pos, nois_x, nois_y );
// message the player
- if (player_distance <= dist && player_can_hear( nois_x, nois_y ))
+ if (player_distance <= dist && player_can_hear( where ))
{
if (msg)
mpr( msg, MSGCH_SOUND );
@@ -1567,20 +1565,20 @@ bool noisy(int loudness, int nois_x, int nois_y, const char *msg)
for (int p = 0; p < MAX_MONSTERS; p++)
{
- monster = &menv[p];
+ monsters* monster = &menv[p];
if (monster->type < 0)
continue;
- if (distance(monster->x, monster->y, nois_x, nois_y) <= dist
- && !silenced(monster->x, monster->y))
+ if (distance(monster->pos(), where) <= dist
+ && !silenced(monster->pos()))
{
// If the noise came from the character, any nearby monster
// will be jumping on top of them.
- if (nois_x == you.x_pos && nois_y == you.y_pos)
+ if (where == you.pos())
behaviour_event( monster, ME_ALERT, MHITYOU );
else
- behaviour_event( monster, ME_DISTURB, MHITNOT, nois_x, nois_y );
+ behaviour_event( monster, ME_DISTURB, MHITNOT, where );
}
}
@@ -1603,15 +1601,15 @@ static const char* _player_vampire_smells_blood(int dist)
return "";
}
-void blood_smell( int strength, int blood_x, int blood_y )
+void blood_smell( int strength, const coord_def& where )
{
- struct monsters *monster = 0; // NULL {dlb}
+ monsters *monster = NULL;
const int range = strength * strength;
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS,
"blood stain at (%d, %d), range of smell = %d",
- blood_x, blood_y, range);
+ where.x, where.y, range);
#endif
// Of the player species, only Vampires can smell blood.
@@ -1623,8 +1621,7 @@ void blood_smell( int strength, int blood_x, int blood_y )
{
int vamp_range = vamp_strength * vamp_strength;
- const int player_distance
- = distance( you.x_pos, you.y_pos, blood_x, blood_y );
+ const int player_distance = distance( you.pos(), where );
if (player_distance <= vamp_range)
{
@@ -1635,7 +1632,7 @@ void blood_smell( int strength, int blood_x, int blood_y )
#endif
you.check_awaken(range - player_distance);
// Don't message if you can see the square.
- if (!see_grid(blood_x, blood_y))
+ if (!see_grid(where))
{
mprf("You smell fresh blood%s.",
_player_vampire_smells_blood(player_distance));
@@ -1654,7 +1651,7 @@ void blood_smell( int strength, int blood_x, int blood_y )
if (!mons_class_flag(monster->type, M_BLOOD_SCENT))
continue;
- if (distance(monster->x, monster->y, blood_x, blood_y) <= range)
+ if (distance(monster->pos(), where) <= range)
{
// Let sleeping hounds lie.
if (mons_is_sleeping(monster)
@@ -1672,8 +1669,7 @@ void blood_smell( int strength, int blood_x, int blood_y )
monster->name(DESC_PLAIN).c_str(),
monster->x, monster->y);
#endif
- behaviour_event( monster, ME_DISTURB, MHITNOT,
- blood_x, blood_y );
+ behaviour_event(monster, ME_DISTURB, MHITNOT, where);
}
continue;
}
@@ -1682,10 +1678,10 @@ void blood_smell( int strength, int blood_x, int blood_y )
mprf(MSGCH_DIAGNOSTICS, "alerting %s (%d, %d)",
monster->name(DESC_PLAIN).c_str(), monster->x, monster->y);
#endif
- behaviour_event( monster, ME_ALERT, MHITNOT, blood_x, blood_y );
+ behaviour_event( monster, ME_ALERT, MHITNOT, where );
}
}
-} // end blood_smell()
+}
// The LOS code now uses raycasting -- haranp
@@ -2348,7 +2344,7 @@ static bool _superior_ray(int shortest, int imbalance,
return (slope_diff > ray_slope_diff);
}
-// Find a nonblocked ray from sx, sy to tx, ty. Return false if no
+// Find a nonblocked ray from source to target. Return false if no
// such ray could be found, otherwise return true and fill ray
// appropriately.
// If allow_fallback is true, fall back to a center-to-center ray
@@ -2359,15 +2355,22 @@ static bool _superior_ray(int shortest, int imbalance,
// If find_shortest is true, examine all rays that hit the target and
// take the shortest (starting at ray.fullray_idx).
-bool find_ray( int sourcex, int sourcey, int targetx, int targety,
+bool find_ray( const coord_def& source, const coord_def& target,
bool allow_fallback, ray_def& ray, int cycle_dir,
bool find_shortest, bool ignore_solid )
{
int cellray, inray;
+
+ const int sourcex = source.x;
+ const int sourcey = source.y;
+ const int targetx = target.x;
+ const int targety = target.y;
+
const int signx = ((targetx - sourcex >= 0) ? 1 : -1);
const int signy = ((targety - sourcey >= 0) ? 1 : -1);
const int absx = signx * (targetx - sourcex);
const int absy = signy * (targety - sourcey);
+
int cur_offset = 0;
int shortest = INFINITE_DISTANCE;
int imbalance = INFINITE_DISTANCE;
@@ -2526,21 +2529,21 @@ bool find_ray( int sourcex, int sourcey, int targetx, int targety,
// By default, it excludes end points from the count.
// If just_check is true, the function will return early once one
// such feature is encountered.
-int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
+int num_feats_between(const coord_def& source, const coord_def& target,
dungeon_feature_type min_feat,
dungeon_feature_type max_feat,
bool exclude_endpoints, bool just_check)
{
ray_def ray;
int count = 0;
- int max_dist = grid_distance(sourcex, sourcey, targetx, targety);
+ int max_dist = grid_distance(source, target);
ray.fullray_idx = -1; // to quiet valgrind
// We don't need to find the shortest beam, any beam will suffice.
- find_ray( sourcex, sourcey, targetx, targety, true, ray, 0, false, true );
+ find_ray( source, target, true, ray, 0, false, true );
- if (exclude_endpoints && ray.x() == sourcex && ray.y() == sourcey)
+ if (exclude_endpoints && ray.pos() == source)
{
ray.advance(true);
max_dist--;
@@ -2550,9 +2553,9 @@ int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
bool reached_target = false;
while (dist++ <= max_dist)
{
- dungeon_feature_type feat = grd[ray.x()][ray.y()];
+ const dungeon_feature_type feat = grd(ray.pos());
- if (ray.x() == targetx && ray.y() == targety)
+ if (ray.pos() == target)
reached_target = true;
if (feat >= min_feat && feat <= max_feat
@@ -2611,10 +2614,12 @@ int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
// Smoke will now only block LOS after two cells of smoke. This is
// done by updating with a second array.
void losight(env_show_grid &sh,
- feature_grid &gr, int x_p, int y_p,
+ feature_grid &gr, const coord_def& center,
bool clear_walls_block)
{
raycast();
+ const int x_p = center.x;
+ const int y_p = center.y;
// go quadrant by quadrant
const int quadrant_x[4] = { 1, -1, -1, 1 };
const int quadrant_y[4] = { 1, 1, -1, -1 };
@@ -2649,7 +2654,7 @@ void losight(env_show_grid &sh,
dungeon_feature_type dfeat = gr[realx][realy];
if (dfeat == DNGN_SECRET_DOOR)
- dfeat = grid_secret_door_appearance(realx, realy);
+ dfeat = grid_secret_door_appearance(coord_def(realx, realy));
// if this cell is opaque...
if ( grid_is_opaque(dfeat)
@@ -2713,24 +2718,24 @@ void losight(env_show_grid &sh,
// 3. '^' for traps
// 4. '_' for altars
// 5. Anything else will look for the exact same character in the level map.
-bool is_feature(int feature, int x, int y)
+bool is_feature(int feature, const coord_def& where)
{
- if (!env.map[x][y].object)
+ if (!env.map(where).object)
return (false);
// 'grid' can fit in an unsigned char, but making this a short shuts up
// warnings about out-of-range case values.
- short grid = grd[x][y];
+ short grid = grd(where);
switch (feature)
{
case 'X':
- return (travel_point_distance[x][y] == PD_EXCLUDED);
+ return (travel_point_distance[where.x][where.y] == PD_EXCLUDED);
case 'F':
case 'W':
- return is_waypoint(x, y);
+ return is_waypoint(where.x, where.y);
case 'I':
- return is_stash(x, y);
+ return is_stash(where.x, where.y);
case '_':
switch (grid)
{
@@ -2838,21 +2843,21 @@ bool is_feature(int feature, int x, int y)
return (false);
}
default:
- return get_envmap_char(x, y) == (unsigned) feature;
+ return get_envmap_char(where.x, where.y) == (unsigned) feature;
}
}
-static bool _is_feature_fudged(int feature, int x, int y)
+static bool _is_feature_fudged(int feature, const coord_def& where)
{
- if (!env.map[x][y].object)
+ if (!env.map(where).object)
return (false);
- if (is_feature(feature, x, y))
+ if (is_feature(feature, where))
return (true);
// 'grid' can fit in an unsigned char, but making this a short shuts up
// warnings about out-of-range case values.
- short grid = grd[x][y];
+ short grid = grd(where);
if (feature == '<')
{
@@ -2918,7 +2923,7 @@ static int _find_feature(int feature, int curs_x, int curs_y,
int x = cx + dx, y = cy + dy;
if (!in_bounds(x, y))
continue;
- if (_is_feature_fudged(feature, x, y))
+ if (_is_feature_fudged(feature, coord_def(x, y)))
{
++matchcount;
if (!ignore_count--)
@@ -2953,7 +2958,7 @@ void find_features(const std::vector<coord_def>& features,
for (unsigned feat = 0; feat < features.size(); ++feat)
{
const coord_def& coord = features[feat];
- if (is_feature(feature, coord.x, coord.y))
+ if (is_feature(feature, coord))
found->push_back(coord);
}
}
@@ -2972,7 +2977,7 @@ static int _find_feature( const std::vector<coord_def>& features,
{
const coord_def& coord = features[feat];
- if (_is_feature_fudged(feature, coord.x, coord.y))
+ if (_is_feature_fudged(feature, coord))
{
++matchcount;
if (forward? !ignore_count-- : --ignore_count == 1)
@@ -3806,10 +3811,10 @@ bool trans_wall_blocking( const coord_def &p )
// Yes, this ignores lava-loving monsters.
// XXX: It turns out the beams are not symmetrical, i.e. switching
// pos1 and pos2 may result in small variations.
-bool grid_see_grid(int posx_1, int posy_1, int posx_2, int posy_2,
+bool grid_see_grid(const coord_def& p1, const coord_def& p2,
dungeon_feature_type allowed)
{
- if (distance(posx_1, posy_1, posx_2, posy_2) > LOS_RADIUS * LOS_RADIUS)
+ if (distance(p1, p2) > LOS_RADIUS * LOS_RADIUS)
return (false);
dungeon_feature_type max_disallowed = DNGN_MAXOPAQUE;
@@ -3817,8 +3822,8 @@ bool grid_see_grid(int posx_1, int posy_1, int posx_2, int posy_2,
max_disallowed = static_cast<dungeon_feature_type>(allowed - 1);
// XXX: Ignoring clouds for now.
- return (!num_feats_between(posx_1, posy_1, posx_2, posy_2, DNGN_UNSEEN,
- max_disallowed, true, true));
+ return (!num_feats_between(p1, p2, DNGN_UNSEEN, max_disallowed,
+ true, true));
}
static const unsigned dchar_table[ NUM_CSET ][ NUM_DCHAR_TYPES ] =
@@ -4607,7 +4612,7 @@ unsigned get_screen_glyph( int x, int y )
return get_envmap_char(x, y);
if (object == DNGN_SECRET_DOOR)
- object = grid_secret_door_appearance( x, y );
+ object = grid_secret_door_appearance(coord_def(x, y));
_get_symbol( x, y, object, &ch, &colour );
return (ch);
@@ -4673,7 +4678,7 @@ std::string screenshot( bool fullscreen )
unsigned short glycol = 0;
if (object == DNGN_SECRET_DOOR)
- object = grid_secret_door_appearance( gc.x, gc.y );
+ object = grid_secret_door_appearance( gc );
_get_symbol( gc.x, gc.y, object, &glych, &glycol );
ch = glych;
@@ -4772,7 +4777,7 @@ void view_update_at(const coord_def &pos)
unsigned ch = 0;
if (object == DNGN_SECRET_DOOR)
- object = grid_secret_door_appearance( pos.x, pos.y );
+ object = grid_secret_door_appearance( pos );
_get_symbol( pos.x, pos.y, object, &ch, &colour );
@@ -4857,11 +4862,11 @@ void viewwindow(bool draw_it, bool do_updates)
int count_x, count_y;
- losight( env.show, grd, you.x_pos, you.y_pos ); // Must be done first.
+ losight( env.show, grd, you.pos() ); // Must be done first.
// What would be visible, if all of the translucent walls were
// made opaque.
- losight( env.no_trans_show, grd, you.x_pos, you.y_pos, true );
+ losight( env.no_trans_show, grd, you.pos(), true );
#ifdef USE_TILE
tile_draw_floor();
@@ -4917,11 +4922,11 @@ void viewwindow(bool draw_it, bool do_updates)
}
else if (grid_is_branch_stairs(grd(gc)))
learned_something_new(TUT_SEEN_BRANCH, gc.x, gc.y);
- else if (is_feature('>', gc.x, gc.y))
+ else if (is_feature('>', gc))
{
learned_something_new(TUT_SEEN_STAIRS, gc.x, gc.y);
}
- else if (is_feature('_', gc.x, gc.y))
+ else if (is_feature('_', gc))
learned_something_new(TUT_SEEN_ALTAR, gc.x, gc.y);
else if (grd(gc) == DNGN_CLOSED_DOOR)
learned_something_new(TUT_SEEN_DOOR, gc.x, gc.y);
@@ -4930,8 +4935,7 @@ void viewwindow(bool draw_it, bool do_updates)
if (igrd[gc.x][gc.y] != NON_ITEM
&& Options.feature_item_brand != CHATTR_NORMAL
- && (is_feature('>', gc.x, gc.y)
- || is_feature('<', gc.x, gc.y)))
+ && (is_feature('>', gc) || is_feature('<', gc)))
{
learned_something_new(TUT_STAIR_BRAND, gc.x, gc.y);
}
@@ -5020,7 +5024,7 @@ void viewwindow(bool draw_it, bool do_updates)
unsigned ch;
if (object == DNGN_SECRET_DOOR)
- object = grid_secret_door_appearance( gc.x, gc.y );
+ object = grid_secret_door_appearance( gc );
_get_symbol( gc.x, gc.y, object, &ch, &colour );
@@ -5887,7 +5891,8 @@ void monster_los::check_los_beam(int dx, int dy)
dist = 0;
ray.fullray_idx = -1; // to quiet valgrind
- find_ray( gridx, gridy, tx, ty, true, ray, 0, true, true );
+ find_ray( coord_def(gridx, gridy), coord_def(tx, ty),
+ true, ray, 0, true, true );
if (ray.x() == gridx && ray.y() == gridy)
ray.advance(true);
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index e108e839fc..59a7fe9379 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -93,7 +93,7 @@ void find_features(const std::vector<coord_def>& features,
* called from: direct - monstufff - view
* *********************************************************************** */
void losight(env_show_grid &sh, feature_grid &gr,
- int x_p, int y_p, bool clear_walls_block = false);
+ const coord_def& center, bool clear_walls_block = false);
bool magic_mapping(int map_radius, int proportion, bool suppress_msg,
@@ -105,8 +105,8 @@ bool magic_mapping(int map_radius, int proportion, bool suppress_msg,
* called from: acr - effects - it_use2 - it_use3 - item_use - spell -
* spells - spells3 - spells4
* *********************************************************************** */
-bool noisy(int loudness, int nois_x, int nois_y, const char *msg = NULL);
-void blood_smell( int strength, int blood_x, int blood_y);
+bool noisy(int loudness, const coord_def& where, const char *msg = NULL);
+void blood_smell( int strength, const coord_def& where);
void handle_monster_shouts(monsters* monster, bool force = false);
// last updated 12may2000 {dlb}
@@ -131,7 +131,7 @@ int count_detected_mons(void);
void clear_map(bool clear_items = true, bool clear_mons = true);
-bool is_feature(int feature, int x, int y);
+bool is_feature(int feature, const coord_def& where);
void get_item_glyph(const item_def *item, unsigned *glych,
unsigned short *glycol);
@@ -154,15 +154,15 @@ const feature_def &get_feature_def(dungeon_feature_type feat);
void set_envmap_obj( int x, int y, int object );
unsigned get_envmap_char(int x, int y);
bool inside_level_bounds(int x, int y);
-bool inside_level_bounds(coord_def &p);
+bool inside_level_bounds(const coord_def &p);
int get_envmap_obj(int x, int y);
void set_envmap_detected_item(int x, int y, bool detected = true);
void set_envmap_detected_mons(int x, int y, bool detected = true);
void set_envmap_col( int x, int y, int colour, int flags );
void set_envmap_col( int x, int y, int colour );
void set_envmap_prop( int x, int y, int prop );
-bool is_sanctuary( int x, int y );
-bool is_bloodcovered( int x, int y );
+bool is_sanctuary( const coord_def& p );
+bool is_bloodcovered( const coord_def& p );
bool is_envmap_detected_item(int x, int y);
bool is_envmap_detected_mons(int x, int y);
@@ -197,7 +197,7 @@ bool see_grid( const env_show_grid &show,
bool see_grid(const coord_def &p);
bool see_grid_no_trans( const coord_def &p );
bool trans_wall_blocking( const coord_def &p );
-bool grid_see_grid(int posx_1, int posy_1, int posx_2, int posy_2,
+bool grid_see_grid(const coord_def& p1, const coord_def& p2,
dungeon_feature_type allowed = DNGN_UNSEEN);
inline bool see_grid( int grx, int gry )
@@ -232,11 +232,11 @@ void init_minimap();
#endif
struct ray_def;
-bool find_ray( int sourcex, int sourcey, int targetx, int targety,
+bool find_ray( const coord_def& source, const coord_def& target,
bool allow_fallback, ray_def& ray, int cycle_dir = 0,
bool find_shortest = false, bool ignore_solid = false );
-int num_feats_between(int sourcex, int sourcey, int targetx, int targety,
+int num_feats_between(const coord_def& source, const coord_def& target,
dungeon_feature_type min_feat,
dungeon_feature_type max_feat,
bool exclude_endpoints = true,
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index e67afa4598..d91f1e42a8 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -214,7 +214,7 @@ static void _xom_make_item(object_class_type base, int subtype, int power)
god_acting gdact(GOD_XOM);
- move_item_to_grid(&thing_created, you.x_pos, you.y_pos);
+ move_item_to_grid(&thing_created, you.pos());
mitm[thing_created].inscription = "god gift";
canned_msg(MSG_SOMETHING_APPEARS);
stop_running();