From 262b8e18ed8cb58afb40a816ac0fdedfe3a7db5f Mon Sep 17 00:00:00 2001 From: haranp Date: Wed, 30 Jul 2008 10:53:06 +0000 Subject: Massive overhaul to move towards coord_def(). This might have introduced some bugs: I now get intermittent crashes on startup (this might have to do with the changes to special_room.) Sorry about that - committing before I need to do any more big conflict resolutions. Fixes coming later. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6732 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 5 +- crawl-ref/source/abyss.cc | 11 +- crawl-ref/source/acr.cc | 155 ++++--- crawl-ref/source/beam.cc | 128 +++--- crawl-ref/source/beam.h | 16 +- crawl-ref/source/cloud.cc | 25 +- crawl-ref/source/clua.cc | 16 +- crawl-ref/source/debug.cc | 190 ++++----- crawl-ref/source/debug.h | 3 +- crawl-ref/source/decks.cc | 38 +- crawl-ref/source/delay.cc | 7 +- crawl-ref/source/describe.cc | 2 +- crawl-ref/source/directn.cc | 235 +++++----- crawl-ref/source/directn.h | 18 +- crawl-ref/source/dungeon.cc | 994 ++++++++++++++++++++----------------------- crawl-ref/source/dungeon.h | 22 +- crawl-ref/source/effects.cc | 95 ++--- crawl-ref/source/externs.h | 305 +++++++------ crawl-ref/source/files.cc | 4 +- crawl-ref/source/invent.cc | 4 +- crawl-ref/source/it_use3.cc | 41 +- crawl-ref/source/item_use.cc | 33 +- crawl-ref/source/itemname.cc | 2 +- crawl-ref/source/itemprop.cc | 5 +- crawl-ref/source/items.cc | 152 +++---- crawl-ref/source/items.h | 2 +- crawl-ref/source/luadgn.cc | 21 +- crawl-ref/source/makeitem.cc | 9 +- crawl-ref/source/misc.cc | 153 +++---- crawl-ref/source/misc.h | 37 +- crawl-ref/source/mon-util.cc | 132 +++--- crawl-ref/source/monplace.cc | 90 ++-- crawl-ref/source/monplace.h | 9 +- crawl-ref/source/monstuff.cc | 655 +++++++++++----------------- crawl-ref/source/monstuff.h | 2 +- crawl-ref/source/mstuff2.cc | 55 +-- crawl-ref/source/mtransit.cc | 6 +- crawl-ref/source/newgame.cc | 3 +- crawl-ref/source/output.cc | 2 +- crawl-ref/source/overmap.cc | 11 +- crawl-ref/source/overmap.h | 2 +- crawl-ref/source/player.cc | 31 +- crawl-ref/source/religion.cc | 88 ++-- crawl-ref/source/shopping.cc | 15 +- crawl-ref/source/spells1.cc | 73 ++-- crawl-ref/source/spells1.h | 60 +-- crawl-ref/source/spells2.cc | 228 +++++----- crawl-ref/source/spells2.h | 98 +---- crawl-ref/source/spells3.cc | 347 +++++++-------- crawl-ref/source/spells3.h | 2 +- crawl-ref/source/spells4.cc | 126 +++--- crawl-ref/source/spells4.h | 6 +- crawl-ref/source/spl-cast.cc | 41 +- crawl-ref/source/spl-util.cc | 216 ++-------- crawl-ref/source/spl-util.h | 9 +- crawl-ref/source/stash.cc | 15 +- crawl-ref/source/stash.h | 12 + crawl-ref/source/state.cc | 4 +- crawl-ref/source/stuff.cc | 23 +- crawl-ref/source/tags.cc | 60 +-- crawl-ref/source/terrain.cc | 31 +- crawl-ref/source/tilepick.cc | 14 +- crawl-ref/source/tilereg.cc | 6 +- crawl-ref/source/tilesdl.cc | 6 +- crawl-ref/source/traps.cc | 44 +- crawl-ref/source/travel.cc | 203 ++++----- crawl-ref/source/travel.h | 9 +- crawl-ref/source/tutorial.cc | 81 ++-- crawl-ref/source/tutorial.h | 3 +- crawl-ref/source/view.cc | 302 +++++++------ crawl-ref/source/view.h | 27 +- crawl-ref/source/xom.cc | 3 +- 72 files changed, 2452 insertions(+), 3426 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index e49ad38e76..85e255784c 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -1623,8 +1623,7 @@ static bool _do_ability(const ability_def& abil) beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.damage = dice_def(3, 30); beam.flavour = BEAM_ELECTRICITY; - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.name = "blast of lightning"; beam.colour = LIGHTCYAN; beam.thrower = KILL_YOU; @@ -1738,7 +1737,7 @@ static bool _do_ability(const ability_def& abil) if (!spell_direction(spd, beam, DIR_NONE, TARG_ENEMY)) return (false); - if (beam.target() == you.pos()) + if (beam.target == you.pos()) { mpr("You cannot banish yourself!"); return (false); diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc index e968f582b3..b6077ba081 100644 --- a/crawl-ref/source/abyss.cc +++ b/crawl-ref/source/abyss.cc @@ -488,13 +488,8 @@ void area_shift(void) move_item_stack_to_grid( *ri, newpos ); // 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; - } + if ( mgrd(*ri) != NON_MONSTER ) + menv[mgrd(*ri)].moveto(newpos); // Move cloud, if (env.cgrid(*ri) != EMPTY_CLOUD) @@ -506,7 +501,7 @@ void area_shift(void) if (env.cloud[i].type == CLOUD_NONE) continue; - if ( grid_distance(abyss_center, env.cloud[i].pos()) > 10 ) + if ( grid_distance(abyss_center, env.cloud[i].pos) > 10 ) delete_cloud( i ); } diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 87b970d8f4..522342ef84 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -179,9 +179,13 @@ 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); +static int _check_adjacent(dungeon_feature_type feat, coord_def& delta); +static void _open_door(coord_def move, bool check_confused = true); +static void _open_door(int x, int y, bool check_confused = true) +{ + _open_door(coord_def(x,y), check_confused); +} +static void _close_door(coord_def move); static void _start_running( int dir, int mode ); static void _prep_input(); @@ -993,7 +997,7 @@ static void _handle_wizard_command( void ) } mprf(MSGCH_DIAGNOSTICS, "Setting (%d,%d) to %s (%d)", - you.x_pos, you.y_pos, name.c_str(), feat); + you.pos().x, you.pos().y, name.c_str(), feat); grd(you.pos()) = feat; } break; @@ -1137,11 +1141,11 @@ static void _handle_wizard_command( void ) for (int i = 0; i < MAX_ITEMS; i++) { item_def &item(mitm[i]); - if (!is_valid_item(item) || item.x == 0 || item.y == 0) + if (!is_valid_item(item) || item.pos.x == 0 || item.pos.y == 0) continue; if (item.link != NON_ITEM) - mprf("(%2d,%2d): %s", item.x, item.y, + mprf("(%2d,%2d): %s", item.pos.x, item.pos.y, item.name(DESC_PLAIN, false, false, false).c_str() ); } @@ -1998,7 +2002,7 @@ void process_command( command_type cmd ) case CMD_GO_UPSTAIRS: _go_upstairs(); break; case CMD_GO_DOWNSTAIRS: _go_downstairs(); break; case CMD_OPEN_DOOR: _open_door(0, 0); break; - case CMD_CLOSE_DOOR: _close_door(0, 0); break; + case CMD_CLOSE_DOOR: _close_door(coord_def(0, 0)); break; case CMD_DROP: drop(); @@ -2162,7 +2166,7 @@ void process_command( command_type cmd ) struct dist lmove; // Will be initialized by direction(). direction(lmove, DIR_TARGET, TARG_ANY, -1, true); if (lmove.isValid && lmove.isTarget && !lmove.isCancel) - start_travel( lmove.tx, lmove.ty ); + start_travel( lmove.target ); break; } @@ -2210,12 +2214,12 @@ void process_command( command_type cmd ) if (!can_travel_interlevel()) { - if (you.running.x == you.x_pos && you.running.y == you.running.y) + if (you.running.pos == you.pos()) { mpr("You're already here."); break; } - else if (!you.running.x || !you.running.y) + else if (!you.running.pos.x || !you.running.pos.y) { mpr("Sorry, you can't auto-travel out of here."); break; @@ -2223,7 +2227,7 @@ void process_command( command_type cmd ) // Don't ask for a destination if you can only travel // within level anyway. - start_travel(you.running.x, you.running.y); + start_travel(you.running.pos); } else start_translevel_travel(); @@ -2269,7 +2273,7 @@ void process_command( command_type cmd ) mpr("Returning to the game..."); #endif if (pos.x > 0) - start_travel(pos.x, pos.y); + start_travel(pos); } break; @@ -2338,11 +2342,11 @@ void process_command( command_type cmd ) if (cme.left_clicked()) { if (in_bounds(dest)) - start_travel(dest.x, dest.y); + start_travel(dest); } else if (cme.right_clicked()) { - if (see_grid(dest.x, dest.y)) + if (see_grid(dest)) full_describe_square(dest); else mpr("You can't see that place."); @@ -3040,9 +3044,9 @@ static void _check_shafts() if (trap.type != TRAP_SHAFT) continue; - ASSERT(in_bounds(trap.pos())); + ASSERT(in_bounds(trap.pos)); - handle_items_on_shaft(trap.pos(), true); + handle_items_on_shaft(trap.pos, true); } } @@ -3441,7 +3445,7 @@ static keycode_type _get_next_keycode() // Check squares adjacent to player for given feature and return how // many there are. If there's only one, return the dx and dy. -static int _check_adjacent(dungeon_feature_type feat, int &dx, int &dy) +static int _check_adjacent(dungeon_feature_type feat, coord_def& delta) { int num = 0; @@ -3450,8 +3454,7 @@ static int _check_adjacent(dungeon_feature_type feat, int &dx, int &dy) if ( grd(*ai) == feat ) { num++; - dx = ai->x - you.x_pos; - dy = ai->y - you.y_pos; + delta = *ai - you.pos(); } } @@ -3461,11 +3464,8 @@ static int _check_adjacent(dungeon_feature_type feat, int &dx, int &dy) // Opens doors and handles some aspects of untrapping. If either move_x or // move_y are non-zero, the pair carries a specific direction for the door // to be opened (eg if you type ctrl + dir). -static void _open_door(int move_x, int move_y, bool check_confused) +static void _open_door(coord_def move, bool check_confused) { - struct dist door_move; - int dx, dy; // door x, door y - if (you.attribute[ATTR_HELD]) { free_self_from_net(); @@ -3474,10 +3474,9 @@ static void _open_door(int move_x, int move_y, bool check_confused) } // If there's only one door to open, don't ask. - if ((!check_confused || !you.duration[DUR_CONF]) - && !(move_x || move_y)) + if ((!check_confused || !you.duration[DUR_CONF]) && move.origin()) { - if (_check_adjacent(DNGN_CLOSED_DOOR, move_x, move_y) == 0) + if (_check_adjacent(DNGN_CLOSED_DOOR, move) == 0) { mpr("There's nothing to open."); return; @@ -3486,20 +3485,19 @@ static void _open_door(int move_x, int move_y, bool check_confused) if (check_confused && you.duration[DUR_CONF] && !one_chance_in(3)) { - move_x = random2(3) - 1; - move_y = random2(3) - 1; + move.x = random2(3) - 1; + move.y = random2(3) - 1; } - door_move.dx = move_x; - door_move.dy = move_y; + dist door_move; + door_move.delta = move; + coord_def doorpos; - if (move_x || move_y) + if (!move.origin()) { - // convenience - dx = you.x_pos + move_x; - dy = you.y_pos + move_y; + doorpos = you.pos() + move; - const int mon = mgrd[dx][dy]; + const int mon = mgrd(doorpos); if (mon != NON_MONSTER && player_can_hit_monster(&menv[mon])) { @@ -3518,7 +3516,7 @@ static void _open_door(int move_x, int move_y, bool check_confused) } you.turn_is_over = true; - you_attack(mgrd[dx][dy], true); + you_attack(mgrd(doorpos), true); if (you.berserk_penalty != NO_BERSERK_PENALTY) you.berserk_penalty = 0; @@ -3526,10 +3524,10 @@ static void _open_door(int move_x, int move_y, bool check_confused) return; } - if (grd[dx][dy] >= DNGN_TRAP_MECHANICAL - && grd[dx][dy] <= DNGN_TRAP_NATURAL) + if (grd(doorpos) >= DNGN_TRAP_MECHANICAL + && grd(doorpos) <= DNGN_TRAP_NATURAL) { - if (env.cgrid[dx][dy] != EMPTY_CLOUD) + if (env.cgrid(doorpos) != EMPTY_CLOUD) { mpr("You can't get to that trap right now."); return; @@ -3538,21 +3536,20 @@ static void _open_door(int move_x, int move_y, bool check_confused) disarm_trap(door_move); return; } - } else { mpr("Which direction?", MSGCH_PROMPT); direction( door_move, DIR_DIR ); + if (!door_move.isValid) return; - // convenience - dx = you.x_pos + door_move.dx; - dy = you.y_pos + door_move.dy; + doorpos = you.pos() + door_move.delta; const dungeon_feature_type feat = - in_bounds(dx, dy) ? grd[dx][dy] : DNGN_UNSEEN; + in_bounds(doorpos) ? grd(doorpos) : DNGN_UNSEEN; + if (feat != DNGN_CLOSED_DOOR) { switch (feat) @@ -3568,15 +3565,16 @@ static void _open_door(int move_x, int move_y, bool check_confused) } } - if (grd[dx][dy] == DNGN_CLOSED_DOOR) + if (grd(doorpos) == DNGN_CLOSED_DOOR) { std::set all_door; - find_connected_range(coord_def(dx,dy), DNGN_CLOSED_DOOR, + find_connected_range(doorpos, DNGN_CLOSED_DOOR, DNGN_SECRET_DOOR, all_door); const char *adj, *noun; get_door_description(all_door.size(), &adj, &noun); - int skill = you.dex + (you.skills[SK_TRAPS_DOORS] + you.skills[SK_STEALTH]) / 2; + int skill = you.dex + + (you.skills[SK_TRAPS_DOORS] + you.skills[SK_STEALTH]) / 2; if (you.duration[DUR_BERSERKER]) { @@ -3598,7 +3596,8 @@ static void _open_door(int move_x, int move_y, bool check_confused) } else { - const char* verb = player_is_airborne() ? "reach down and open" : "open"; + const char* verb = + player_is_airborne() ? "reach down and open" : "open"; mprf( "You %s the %s%s.", verb, adj, noun ); } @@ -3612,7 +3611,7 @@ static void _open_door(int move_x, int move_y, bool check_confused) // door! if (is_terrain_seen(dc)) { - set_envmap_obj(dc.x, dc.y, DNGN_OPEN_DOOR); + set_envmap_obj(dc, DNGN_OPEN_DOOR); #ifdef USE_TILE tile_place_tile_bk(dc.x, dc.y, TILE_DNGN_OPEN_DOOR); #endif @@ -3626,12 +3625,12 @@ static void _open_door(int move_x, int move_y, bool check_confused) DESC_PLAIN, false).c_str()); } } - grd[dc.x][dc.y] = DNGN_OPEN_DOOR; + grd(dc) = DNGN_OPEN_DOOR; } you.turn_is_over = true; } - else if (grd[dx][dy] == DNGN_OPEN_DOOR) - _close_door(move_x, move_y); // for convenience + else if (grd(doorpos) == DNGN_OPEN_DOOR) + _close_door(move); // for convenience else { mpr("You swing at nothing."); @@ -3640,21 +3639,21 @@ static void _open_door(int move_x, int move_y, bool check_confused) } } -static void _close_door(int door_x, int door_y) +static void _close_door(coord_def move) { - struct dist door_move; - int dx, dy; // door x, door y + dist door_move; + coord_def doorpos; // If there's only one door to close, don't ask. - if (!you.duration[DUR_CONF] && !(door_x || door_y)) + if (!you.duration[DUR_CONF] && move.origin()) { - int num = _check_adjacent(DNGN_OPEN_DOOR, door_x, door_y); + int num = _check_adjacent(DNGN_OPEN_DOOR, move); if (num == 0) { mpr("There's nothing to close."); return; } - else if (num == 1 && !(door_x || door_y)) + else if (num == 1 && move.origin()) { mpr("You can't close doors on yourself!"); return; @@ -3663,14 +3662,13 @@ static void _close_door(int door_x, int door_y) if (you.duration[DUR_CONF] && !one_chance_in(3)) { - door_x = random2(3) - 1; - door_y = random2(3) - 1; + move.x = random2(3) - 1; + move.y = random2(3) - 1; } - door_move.dx = door_x; - door_move.dy = door_y; + door_move.delta = move; - if (!door_x && !door_y) + if (move.origin()) { mpr("Which direction?", MSGCH_PROMPT); direction( door_move, DIR_DIR ); @@ -3678,27 +3676,25 @@ static void _close_door(int door_x, int door_y) return; } - if (door_move.dx == 0 && door_move.dy == 0) + if (door_move.delta.origin()) { mpr("You can't close doors on yourself!"); return; } - // convenience - dx = you.x_pos + door_move.dx; - dy = you.y_pos + door_move.dy; + doorpos = you.pos() + door_move.delta; const dungeon_feature_type feat = - in_bounds(dx, dy) ? grd[dx][dy] : DNGN_UNSEEN; + in_bounds(doorpos) ? grd(doorpos) : DNGN_UNSEEN; if (feat == DNGN_OPEN_DOOR) { std::set all_door; - find_connected_identical(coord_def(dx,dy), grd[dx][dy], all_door); + find_connected_identical(doorpos, grd(doorpos), all_door); const char *adj, *noun; get_door_description(all_door.size(), &adj, &noun); - for (std::set::iterator i = all_door.begin(); + for (std::set::const_iterator i = all_door.begin(); i != all_door.end(); ++i) { const coord_def& dc = *i; @@ -3713,17 +3709,12 @@ static void _close_door(int door_x, int door_y) } else mprf("There's a creature in the %sway!", noun); - - door_move.dx = 0; - door_move.dy = 0; return; } if (igrd(dc) != NON_ITEM) { mprf("There's something blocking the %sway.", noun); - door_move.dx = 0; - door_move.dy = 0; return; } @@ -3734,7 +3725,8 @@ static void _close_door(int door_x, int door_y) } } - int skill = you.dex + (you.skills[SK_TRAPS_DOORS] + you.skills[SK_STEALTH]) / 2; + int skill = you.dex + + (you.skills[SK_TRAPS_DOORS] + you.skills[SK_STEALTH]) / 2; if (you.duration[DUR_BERSERKER]) { @@ -3744,7 +3736,8 @@ static void _close_door(int door_x, int door_y) } else { - mprf(MSGCH_SOUND, "You slam the %s%s shut with an echoing bang!", + mprf(MSGCH_SOUND, + "You slam the %s%s shut with an echoing bang!", adj, noun); noisy(25, you.pos()); } @@ -3762,7 +3755,7 @@ static void _close_door(int door_x, int door_y) mprf( "You %s the %s%s.", verb, adj, noun ); } - for (std::set::iterator i = all_door.begin(); + for (std::set::const_iterator i = all_door.begin(); i != all_door.end(); ++i) { const coord_def& dc = *i; @@ -3772,7 +3765,7 @@ static void _close_door(int door_x, int door_y) // door to be updated. if (is_terrain_seen(dc)) { - set_envmap_obj(dc.x, dc.y, DNGN_CLOSED_DOOR); + set_envmap_obj(dc, DNGN_CLOSED_DOOR); #ifdef USE_TILE tile_place_tile_bk(dc.x, dc.y, TILE_DNGN_CLOSED_DOOR); #endif @@ -4188,8 +4181,8 @@ static void _move_player(coord_def move) you.running = RMODE_CONTINUE; if (you.level_type == LEVEL_ABYSS - && (you.x_pos <= 15 || you.x_pos >= (GXM - 16) - || you.y_pos <= 15 || you.y_pos >= (GYM - 16))) + && (you.pos().x <= 15 || you.pos().x >= (GXM - 16) + || you.pos().y <= 15 || you.pos().y >= (GYM - 16))) { area_shift(); if (you.pet_target != MHITYOU) diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index b6ce1d926a..f1dd762d5b 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -685,8 +685,7 @@ bool player_tracer( zap_type ztype, int power, bolt &pbolt, int range) pbolt.rangeMax = range; pbolt.is_tracer = true; - pbolt.source_x = you.x_pos; - pbolt.source_y = you.y_pos; + pbolt.source = you.pos(); pbolt.can_see_invis = player_see_invis(); pbolt.smart_monster = true; pbolt.attitude = ATT_FRIENDLY; @@ -1769,9 +1768,8 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item) if (item && !pbolt.is_tracer && pbolt.flavour == BEAM_MISSILE) { - tile_beam = tileidx_item_throw(*item, - pbolt.target_x - pbolt.source_x, - pbolt.target_y - pbolt.source_y); + const coord_def diff = pbolt.target - pbolt.source; + tile_beam = tileidx_item_throw(*item, diff.x, diff.y); } #endif @@ -1785,8 +1783,8 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item) (pbolt.is_big_cloud) ? "+" : "", (pbolt.is_tracer) ? " tracer" : "", pbolt.name.c_str(), - pbolt.source_x, pbolt.source_y, - pbolt.target_x, pbolt.target_y, + pbolt.source.x, pbolt.source.y, + pbolt.target.x, pbolt.target.y, pbolt.type, pbolt.colour, pbolt.flavour, pbolt.hit, pbolt.damage.num, pbolt.damage.size, pbolt.range); @@ -1794,8 +1792,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item) #endif // init - pbolt.aimed_at_feet = (pbolt.target_x == pbolt.source_x - && pbolt.target_y == pbolt.source_y); + pbolt.aimed_at_feet = (pbolt.target == pbolt.source); pbolt.msg_generated = false; ray_def ray; @@ -1805,11 +1802,11 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item) else { ray.fullray_idx = -1; // to quiet valgrind - find_ray( pbolt.source(), pbolt.target(), true, ray, 0, true ); + find_ray( pbolt.source, pbolt.target, true, ray, 0, true ); } if (!pbolt.aimed_at_feet) - ray.advance_through(pbolt.target()); + ray.advance_through(pbolt.target); // Give chance for beam to affect one cell even if aimed_at_feet. beamTerminate = false; @@ -1906,7 +1903,7 @@ 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 (testpos == pbolt.target()) + if (testpos == pbolt.target) beamTerminate = _beam_term_on_target(pbolt, testpos); // Affect the cell, except in the special case noted @@ -1995,7 +1992,7 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_item) } if (!did_bounce) - ray.advance_through(pbolt.target()); + ray.advance_through(pbolt.target); else ray.advance(true); } // end- while !beamTerminate @@ -2011,14 +2008,13 @@ void fire_beam(bolt &pbolt, item_def *item, bool drop_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 - coord_def targetcopy = pbolt.target(); + coord_def targetcopy = pbolt.target; _beam_explodes(pbolt, testpos); if (pbolt.is_tracer) { - pbolt.target_x = targetcopy.x; - pbolt.target_y = targetcopy.y; + pbolt.target = targetcopy; } // Canned msg for enchantments that affected no-one, but only if the @@ -2551,11 +2547,8 @@ int mons_ench_f2(monsters *monster, bolt &pbolt) case BEAM_HEALING: if (YOU_KILL(pbolt.thrower)) { - if (cast_healing(5 + roll_dice( pbolt.damage ), - monster->x, monster->y) > 0) - { + if (cast_healing(5 + roll_dice( pbolt.damage ), monster->pos()) > 0) pbolt.obvious_effect = true; - } pbolt.msg_generated = true; // to avoid duplicate "nothing happens" } else if (heal_monster( monster, 5 + roll_dice( pbolt.damage ), false )) @@ -2816,8 +2809,7 @@ void fire_tracer(const monsters *monster, bolt &pbolt, bool explode_only) { // Don't fiddle with any input parameters other than tracer stuff! pbolt.is_tracer = true; - pbolt.source_x = monster->x; // always safe to do. - pbolt.source_y = monster->y; + pbolt.source = monster->pos(); pbolt.beam_source = monster_index(monster); pbolt.can_see_invis = mons_see_invis(monster); pbolt.smart_monster = (mons_intel(monster->type) >= I_NORMAL); @@ -2924,8 +2916,7 @@ static void _beam_explodes(bolt &beam, const coord_def& p) // This will be the last thing this beam does. Set target_x // and target_y to hold explosion co'ords. - beam.target_x = p.x; - beam.target_y = p.y; + beam.target = p; // Generic explosion. if (beam.is_explosion) @@ -2990,7 +2981,7 @@ static void _beam_explodes(bolt &beam, const coord_def& p) // cloud producer -- POISON BLAST if (beam.name == "blast of poison") { - big_cloud(CLOUD_POISON, _whose_kill(beam), beam.killer(), p.x, p.y, + big_cloud(CLOUD_POISON, _whose_kill(beam), beam.killer(), p, 0, 7 + random2(5)); return; } @@ -2999,13 +2990,13 @@ static void _beam_explodes(bolt &beam, const coord_def& p) if (beam.name == "foul vapour") { cl_type = (beam.flavour == BEAM_MIASMA) ? CLOUD_MIASMA : CLOUD_STINK; - big_cloud( cl_type, _whose_kill(beam), beam.killer(), p.x, p.y, 0, 9 ); + big_cloud( cl_type, _whose_kill(beam), beam.killer(), p, 0, 9 ); return; } if (beam.name == "freezing blast") { - big_cloud( CLOUD_COLD, _whose_kill(beam), beam.killer(), p.x, p.y, + big_cloud( CLOUD_COLD, _whose_kill(beam), beam.killer(), p, random_range(10, 15), 9 ); return; } @@ -3056,7 +3047,7 @@ static bool _beam_term_on_target(bolt &beam, const coord_def& p) if (beam.name == "ball of vapour") return (true); - if (beam.aimed_at_spot && p == beam.target()) + if (beam.aimed_at_spot && p == beam.target) return (true); return (false); @@ -3184,7 +3175,7 @@ int affect(bolt &beam, const coord_def& p, item_def *item) // aimed at that spot. if (mon->alive() && (!mon->submerged() - || beam.aimed_at_spot && beam.target() == mon->pos() + || beam.aimed_at_spot && beam.target == mon->pos() && grd(mon->pos()) == DNGN_SHALLOW_WATER)) { if (!beam.is_big_cloud @@ -3577,7 +3568,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(), you.pos()); + int dist = grid_distance(beem.target, you.pos()); // No, ditch this. if (dist > 2) @@ -3593,19 +3584,11 @@ static bool _fuzz_invis_tracer(bolt &beem) } // Apply fuzz now. - int xfuzz = random_range(-2, 2), - yfuzz = random_range(-2, 2); + coord_def fuzz( random_range(-2, 2), random_range(-2, 2) ); + coord_def newtarget = beem.target + fuzz; - const int newx = beem.target_x + xfuzz, - newy = beem.target_y + yfuzz; - - if (in_bounds(newx, newy) - && (newx != beem.source_x - || newy != beem.source_y)) - { - beem.target_x = newx; - beem.target_y = newy; - } + if (in_bounds(newtarget)) + beem.target = newtarget; // Fire away! return (true); @@ -4361,7 +4344,7 @@ static void _update_hurt_or_helped(bolt &beam, monsters *mon) // Returns amount of range used up by affectation of this monster. static int _affect_monster(bolt &beam, monsters *mon, item_def *item) { - const int tid = mgrd[mon->x][mon->y]; + const int tid = mgrd(mon->pos()); const int mons_type = menv[tid].type; const int thrower = YOU_KILL(beam.thrower) ? KILL_YOU_MISSILE : KILL_MON_MISSILE; @@ -4386,7 +4369,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) { // Can we see this monster? if (!beam.can_see_invis && menv[tid].invisible() - || (thrower == KILL_YOU_MISSILE && !see_grid(mon->x, mon->y))) + || (thrower == KILL_YOU_MISSILE && !see_grid(mon->pos()))) { // Can't see this monster, ignore it. return 0; @@ -4413,7 +4396,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) { if (!silenced(you.pos())) { - if (!see_grid( mon->x, mon->y )) + if (!see_grid( mon->pos() )) mpr("You hear a hideous screaming!", MSGCH_SOUND); else { @@ -4421,7 +4404,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) MSGCH_SOUND); } } - else if (see_grid( mon->x, mon->y )) + else if (see_grid( mon->pos() )) { mpr("The statue twists and shakes as its substance " "crumbles away!"); @@ -4444,8 +4427,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) && (beam.fr_count == 1 && !beam.dont_stop_fr || beam.foe_count == 1 && !beam.dont_stop_foe)) { - const bool target = (beam.target_x == mon->x - && beam.target_y == mon->y); + const bool target = (beam.target == mon->pos()); if (stop_attack_prompt(mon, true, target)) { @@ -4551,7 +4533,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) // Can't hurt submerged water creatures with electricity. if (beam.flavour == BEAM_ELECTRICITY) { - if (see_grid(mon->x, mon->y) && !beam.is_tracer) + if (see_grid(mon->pos()) && !beam.is_tracer) { mprf("The %s arcs harmlessly into the water.", beam.name.c_str()); @@ -4603,8 +4585,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) && (beam.fr_count == 1 && !beam.dont_stop_fr || beam.foe_count == 1 && !beam.dont_stop_foe)) { - const bool target = (beam.target_x == mon->x - && beam.target_y == mon->y); + const bool target = (beam.target == mon->pos()); if (stop_attack_prompt(mon, true, target)) { @@ -5199,7 +5180,7 @@ static void _explosion1(bolt &pbolt) { int ex_size = 1; // convenience - coord_def p = pbolt.target(); + coord_def p = pbolt.target; const char *seeMsg = NULL; const char *hearMsg = NULL; @@ -5330,24 +5311,24 @@ int explosion( bolt &beam, bool hole_in_the_middle, bool explode_in_wall, bool stop_at_statues, bool stop_at_walls, bool show_more) { - if (in_bounds(beam.source()) && beam.source() != beam.target() + if (in_bounds(beam.source) && beam.source != beam.target && (!explode_in_wall || stop_at_statues || stop_at_walls)) { ray_def ray; - int max_dist = grid_distance(beam.source(), beam.target()); + int max_dist = grid_distance(beam.source, beam.target); ray.fullray_idx = -1; // to quiet valgrind - find_ray( beam.source(), beam.target(), true, ray, 0, true ); + find_ray( beam.source, beam.target, true, ray, 0, true ); // Can cast explosions out from statues or walls. - if (ray.pos() == beam.source()) + if (ray.pos() == beam.source) { max_dist--; ray.advance(true); } int dist = 0; - while (dist++ <= max_dist && ray.pos() != beam.target()) + while (dist++ <= max_dist && ray.pos() != beam.target) { if (grid_is_solid(ray.pos())) { @@ -5407,8 +5388,7 @@ int explosion( bolt &beam, bool hole_in_the_middle, old_x, old_y, ray.x(), ray.y()); #endif } - beam.target_x = ray.x(); - beam.target_y = ray.y(); + beam.target = ray.pos(); } // if (!explode_in_wall) int r = beam.ex_size; @@ -5416,9 +5396,9 @@ int explosion( bolt &beam, bool hole_in_the_middle, // Beam is now an explosion. beam.in_explosion_phase = true; - if (is_sanctuary(beam.target())) + if (is_sanctuary(beam.target)) { - if (!beam.is_tracer && see_grid(beam.target()) && !beam.name.empty()) + if (!beam.is_tracer && see_grid(beam.target) && !beam.name.empty()) { mprf(MSGCH_GOD, "By Zin's power, the %s is contained.", beam.name.c_str()); @@ -5429,7 +5409,7 @@ int explosion( bolt &beam, bool hole_in_the_middle, #if DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "explosion at (%d, %d) : t=%d c=%d f=%d hit=%d dam=%dd%d", - beam.target_x, beam.target_y, + beam.target.x, beam.target.y, beam.type, beam.colour, beam.flavour, beam.hit, beam.damage.num, beam.damage.size ); #endif @@ -5439,7 +5419,7 @@ int explosion( bolt &beam, bool hole_in_the_middle, r = MAX_EXPLOSION_RADIUS; // make a noise - noisy(10 + 5 * r, beam.target()); + noisy(10 + 5 * r, beam.target); // set map to false explode_map.init(false); @@ -5512,7 +5492,7 @@ int explosion( bolt &beam, bool hole_in_the_middle, for ( int i = -9; i <= 9; ++i ) for ( int j = -9; j <= 9; ++j ) if ( explode_map[i+9][j+9] - && see_grid(beam.target_x + i, beam.target_y + j) ) + && see_grid(beam.target + coord_def(i,j))) { cells_seen++; } @@ -5535,7 +5515,7 @@ int explosion( bolt &beam, bool hole_in_the_middle, static void _explosion_cell(bolt &beam, const coord_def& p, bool drawOnly) { bool random_beam = false; - coord_def realpos = beam.target() + p; + coord_def realpos = beam.target + p; if (!drawOnly) { @@ -5592,7 +5572,7 @@ static void _explosion_map( bolt &beam, const coord_def& p, if (count > 10*r) return; - const coord_def loc(beam.target() + p); + const coord_def loc(beam.target + p); // Make sure we haven't run off the map. if (!map_bounds(loc)) @@ -5710,8 +5690,8 @@ static bool _nice_beam(monsters *mon, bolt &beam) // (extended from setup_mons_cast() and zapping() which act as limited ones). bolt::bolt() : range(0), rangeMax(0), type('*'), colour(BLACK), - flavour(BEAM_MAGIC), source_x(0), source_y(0), damage(0,0), - ench_power(0), hit(0), target_x(0), target_y(0), pos(), + flavour(BEAM_MAGIC), source(), target(), pos(), damage(0,0), + ench_power(0), hit(0), thrower(KILL_MISC), ex_size(0), beam_source(MHITNOT), name(), is_beam(false), is_explosion(false), is_big_cloud(false), is_enchant(false), is_energy(false), is_launched(false), @@ -5757,8 +5737,7 @@ void bolt::set_target(const dist &d) if (!d.isValid) return; - target_x = d.tx; - target_y = d.ty; + target = d.target; chose_ray = d.choseRay; if (d.choseRay) @@ -5771,12 +5750,9 @@ void bolt::set_target(const dist &d) void bolt::setup_retrace() { if (pos.x && pos.y) - { - target_x = pos.x; - target_y = pos.y; - } - std::swap(source_x, target_x); - std::swap(source_y, target_y); + target = pos; + + std::swap(source, target); affects_nothing = true; aimed_at_spot = true; } diff --git a/crawl-ref/source/beam.h b/crawl-ref/source/beam.h index 4f35b43bc8..55ab6c6703 100644 --- a/crawl-ref/source/beam.h +++ b/crawl-ref/source/beam.h @@ -108,11 +108,11 @@ struct bolt unsigned type; // missile gfx int colour; beam_type flavour; - int source_x, source_y; // beam origin + coord_def source; // beam origin + coord_def target; // intended target + coord_def pos; // actual position dice_def damage; int ench_power, hit; - int target_x, target_y; // intended target - coord_def pos; // actual position killer_type thrower; // what kind of thing threw this? char ex_size; // explosion radius (0==none) int beam_source; // NON_MONSTER or monster index # @@ -167,16 +167,6 @@ public: // Returns YOU_KILL or MON_KILL, depending on the source of the beam. killer_type killer() const; - - coord_def target() const - { - 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 ); diff --git a/crawl-ref/source/cloud.cc b/crawl-ref/source/cloud.cc index 54348db5f0..1cc586688f 100644 --- a/crawl-ref/source/cloud.cc +++ b/crawl-ref/source/cloud.cc @@ -75,8 +75,7 @@ static void _new_cloud( int cloud, cloud_type type, const coord_def& p, env.cloud[ cloud ].type = type; env.cloud[ cloud ].decay = decay; - env.cloud[ cloud ].x = p.x; - env.cloud[ cloud ].y = p.y; + env.cloud[ cloud ].pos = p; env.cloud[ cloud ].whose = whose; env.cloud[ cloud ].killer = killer; env.cloud[ cloud ].spread_rate = spread_rate; @@ -108,7 +107,7 @@ static int _spread_cloud(const cloud_struct &cloud) cloud.decay > 20? 50 : 30; int extra_decay = 0; - for ( adjacent_iterator ai(cloud.pos()); ai; ++ai ) + for ( adjacent_iterator ai(cloud.pos); ai; ++ai ) { if (random2(100) >= spreadch) continue; @@ -165,18 +164,18 @@ void manage_clouds(void) // water -> flaming clouds: // lava -> freezing clouds: if (env.cloud[cc].type == CLOUD_FIRE - && grd[env.cloud[cc].x][env.cloud[cc].y] == DNGN_DEEP_WATER) + && grd(env.cloud[cc].pos) == DNGN_DEEP_WATER) { dissipate *= 4; } else if (env.cloud[cc].type == CLOUD_COLD - && grd[env.cloud[cc].x][env.cloud[cc].y] == DNGN_LAVA) + && grd(env.cloud[cc].pos) == DNGN_LAVA) { dissipate *= 4; } expose_items_to_element(cloud2beam(env.cloud[cc].type), - env.cloud[cc].pos(), 2); + env.cloud[cc].pos, 2); _dissipate_cloud(cc, env.cloud[cc], dissipate); } @@ -186,12 +185,11 @@ void delete_cloud( int cloud ) { if (env.cloud[ cloud ].type != CLOUD_NONE) { - const coord_def cloud_pos = env.cloud[ cloud ].pos(); + const coord_def cloud_pos = env.cloud[ cloud ].pos; env.cloud[ cloud ].type = CLOUD_NONE; env.cloud[ cloud ].decay = 0; - env.cloud[ cloud ].x = 0; - env.cloud[ cloud ].y = 0; + env.cloud[ cloud ].pos.reset(); env.cloud[ cloud ].whose = KC_OTHER; env.cloud[ cloud ].killer = KILL_NONE; env.cloud[ cloud ].spread_rate = 0; @@ -206,13 +204,10 @@ 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; - + const coord_def oldpos = env.cloud[cloud].pos; + env.cgrid(oldpos) = EMPTY_CLOUD; env.cgrid(newpos) = cloud; - env.cloud[ cloud ].x = newpos.x; - env.cloud[ cloud ].y = newpos.y; - env.cgrid[ old_x ][ old_y ] = EMPTY_CLOUD; + env.cloud[cloud].pos = newpos; } } diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 55659a1613..3edabd36f0 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -732,7 +732,7 @@ LUARET1(you_god_likes_butchery, boolean, god_likes_butchery(you.religion)) LUARET2(you_hp, number, you.hp, you.hp_max) LUARET2(you_mp, number, you.magic_points, you.max_magic_points) -LUARET2(you_pos, number, you.x_pos, you.y_pos) +LUARET2(you_pos, number, you.pos().x, you.pos().y) LUARET1(you_hunger, string, hunger_level()) LUARET2(you_strength, number, you.strength, you.max_strength) LUARET2(you_intelligence, number, you.intel, you.max_intel) @@ -1051,7 +1051,7 @@ static int l_item_drop(lua_State *ls) return (1); } -static int item_on_floor(const item_def &item, int x, int y); +static int item_on_floor(const item_def &item, const coord_def& where); static item_def *dmx_get_item(lua_State *ls, int ndx, int subndx) { @@ -1088,7 +1088,7 @@ static bool l_item_pickup2(item_def *item, int qty) if (!item || in_inventory(*item)) return (false); - int floor_link = item_on_floor(*item, you.x_pos, you.y_pos); + int floor_link = item_on_floor(*item, you.pos()); if (floor_link == NON_ITEM) return (false); @@ -1591,10 +1591,10 @@ static int food_can_eat(lua_State *ls) return (1); } -static int item_on_floor(const item_def &item, int x, int y) +static int item_on_floor(const item_def &item, const coord_def& where) { // Check if the item is on the floor and reachable - for (int link = igrd[x][y]; link != NON_ITEM; link = mitm[link].link) + for (int link = igrd(where); link != NON_ITEM; link = mitm[link].link) { if (&mitm[link] == &item) return (link); @@ -1614,7 +1614,7 @@ static bool eat_item(const item_def &item) } else { - int ilink = item_on_floor(item, you.x_pos, you.y_pos); + int ilink = item_on_floor(item, you.pos()); if (ilink != NON_ITEM) { @@ -2332,13 +2332,13 @@ static int l_mons_name(lua_State *ls, monsters *mons, const char *attr) static int l_mons_x(lua_State *ls, monsters *mons, const char *attr) { - lua_pushnumber(ls, int(mons->x) - int(you.x_pos)); + lua_pushnumber(ls, int(mons->pos().x) - int(you.pos().x)); return (1); } static int l_mons_y(lua_State *ls, monsters *mons, const char *attr) { - lua_pushnumber(ls, int(mons->y) - int(you.y_pos)); + lua_pushnumber(ls, int(mons->pos().y) - int(you.pos().y)); return (1); } diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index aea6851a9d..c9e235e1d9 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -521,8 +521,7 @@ void wizard_create_spec_monster_name() if (mons_is_unique(mspec.mid) && you.unique_creatures[mspec.mid]) you.unique_creatures[mspec.mid] = false; - if (!dgn_place_monster(mspec, you.your_level, - place.x, place.y, true, false)) + if (!dgn_place_monster(mspec, you.your_level, place, true, false)) { mpr("Unable to place monster.", MSGCH_DIAGNOSTICS); return; @@ -1691,8 +1690,9 @@ void wizard_tweak_object(void) // Prints a number of useful (for debugging, that is) stats on monsters. void debug_stethoscope(int mon) { - struct dist stth; - int steth_x, steth_y; + dist stth; + coord_def stethpos; + int i; if (mon != RANDOM_MONSTER) @@ -1707,59 +1707,55 @@ void debug_stethoscope(int mon) return; if (stth.isTarget) - { - steth_x = stth.tx; - steth_y = stth.ty; - } + stethpos = stth.target; else - { - steth_x = you.x_pos + stth.dx; - steth_y = you.x_pos + stth.dy; - } + stethpos = you.pos() + stth.delta; - if (env.cgrid[steth_x][steth_y] != EMPTY_CLOUD) + if (env.cgrid(stethpos) != EMPTY_CLOUD) { mprf(MSGCH_DIAGNOSTICS, "cloud type: %d delay: %d", - env.cloud[ env.cgrid[steth_x][steth_y] ].type, - env.cloud[ env.cgrid[steth_x][steth_y] ].decay ); + env.cloud[ env.cgrid(stethpos) ].type, + env.cloud[ env.cgrid(stethpos) ].decay ); } - if (mgrd[steth_x][steth_y] == NON_MONSTER) + if (mgrd(stethpos) == NON_MONSTER) { - mprf(MSGCH_DIAGNOSTICS, "item grid = %d", igrd[steth_x][steth_y] ); + mprf(MSGCH_DIAGNOSTICS, "item grid = %d", igrd(stethpos) ); return; } - i = mgrd[steth_x][steth_y]; + i = mgrd(stethpos); } + monsters& mons(menv[i]); + // Print type of monster. mprf(MSGCH_DIAGNOSTICS, "%s (id #%d; type=%d loc=(%d,%d) align=%s)", - menv[i].name(DESC_CAP_THE, true).c_str(), - i, menv[i].type, menv[i].x, menv[i].y, - ((menv[i].attitude == ATT_HOSTILE) ? "hostile" : - (menv[i].attitude == ATT_FRIENDLY) ? "friendly" : - (menv[i].attitude == ATT_NEUTRAL) ? "neutral" : - (menv[i].attitude == ATT_GOOD_NEUTRAL) ? "good neutral" + mons.name(DESC_CAP_THE, true).c_str(), + i, mons.type, mons.pos().x, mons.pos().y, + ((mons.attitude == ATT_HOSTILE) ? "hostile" : + (mons.attitude == ATT_FRIENDLY) ? "friendly" : + (mons.attitude == ATT_NEUTRAL) ? "neutral" : + (mons.attitude == ATT_GOOD_NEUTRAL) ? "good neutral" : "unknown alignment") ); // Print stats and other info. mprf(MSGCH_DIAGNOSTICS, "HD=%d (%lu) HP=%d/%d AC=%d EV=%d MR=%d SP=%d " "energy=%d%s%s num=%d flags=%04lx", - menv[i].hit_dice, - menv[i].experience, - menv[i].hit_points, menv[i].max_hit_points, - menv[i].ac, menv[i].ev, - mons_resist_magic( &menv[i] ), - menv[i].speed, menv[i].speed_increment, - menv[i].base_monster != MONS_PROGRAM_BUG ? " base=" : "", - menv[i].base_monster != MONS_PROGRAM_BUG ? - get_monster_data(menv[i].base_monster)->name : "", - menv[i].number, menv[i].flags ); + mons.hit_dice, + mons.experience, + mons.hit_points, mons.max_hit_points, + mons.ac, mons.ev, + mons_resist_magic( &mons ), + mons.speed, mons.speed_increment, + mons.base_monster != MONS_PROGRAM_BUG ? " base=" : "", + mons.base_monster != MONS_PROGRAM_BUG ? + get_monster_data(mons.base_monster)->name : "", + mons.number, mons.flags ); // Print habitat and behaviour information. - const habitat_type hab = mons_habitat( &menv[i] ); + const habitat_type hab = mons_habitat( &mons ); mprf(MSGCH_DIAGNOSTICS, "hab=%s beh=%s(%d) foe=%s(%d) mem=%d target=(%d,%d) god=%s", @@ -1768,40 +1764,40 @@ void debug_stethoscope(int mon) (hab == HT_ROCK) ? "rock" : (hab == HT_LAND) ? "floor" : "unknown"), - (mons_is_sleeping(&menv[i]) ? "sleep" : - mons_is_wandering(&menv[i]) ? "wander" : - mons_is_seeking(&menv[i]) ? "seek" : - mons_is_fleeing(&menv[i]) ? "flee" : - mons_is_cornered(&menv[i]) ? "cornered" : - mons_is_panicking(&menv[i]) ? "panic" : - mons_is_lurking(&menv[i]) ? "lurk" + (mons_is_sleeping(&mons) ? "sleep" : + mons_is_wandering(&mons) ? "wander" : + mons_is_seeking(&mons) ? "seek" : + mons_is_fleeing(&mons) ? "flee" : + mons_is_cornered(&mons) ? "cornered" : + mons_is_panicking(&mons) ? "panic" : + mons_is_lurking(&mons) ? "lurk" : "unknown"), - menv[i].behaviour, - ((menv[i].foe == MHITYOU) ? "you" : - (menv[i].foe == MHITNOT) ? "none" : - (menv[menv[i].foe].type == -1) ? "unassigned monster" - : menv[menv[i].foe].name(DESC_PLAIN, true).c_str()), - menv[i].foe, - menv[i].foe_memory, - menv[i].target_x, menv[i].target_y, - god_name(menv[i].god).c_str() ); + mons.behaviour, + ((mons.foe == MHITYOU) ? "you" : + (mons.foe == MHITNOT) ? "none" : + (menv[mons.foe].type == -1) ? "unassigned monster" + : menv[mons.foe].name(DESC_PLAIN, true).c_str()), + mons.foe, + mons.foe_memory, + mons.target.x, mons.target.y, + god_name(mons.god).c_str() ); // Print resistances. mprf(MSGCH_DIAGNOSTICS, "resist: fire=%d cold=%d elec=%d pois=%d neg=%d", - mons_res_fire( &menv[i] ), - mons_res_cold( &menv[i] ), - mons_res_elec( &menv[i] ), - mons_res_poison( &menv[i] ), - mons_res_negative_energy( &menv[i] ) ); + mons_res_fire( &mons ), + mons_res_cold( &mons ), + mons_res_elec( &mons ), + mons_res_poison( &mons ), + mons_res_negative_energy( &mons ) ); mprf(MSGCH_DIAGNOSTICS, "ench: %s", - menv[i].describe_enchantments().c_str()); + mons.describe_enchantments().c_str()); - if (menv[i].type == MONS_PLAYER_GHOST - || menv[i].type == MONS_PANDEMONIUM_DEMON) + if (mons.type == MONS_PLAYER_GHOST + || mons.type == MONS_PANDEMONIUM_DEMON) { - ASSERT(menv[i].ghost.get()); - const ghost_demon &ghost = *menv[i].ghost; + ASSERT(mons.ghost.get()); + const ghost_demon &ghost = *mons.ghost; mprf( MSGCH_DIAGNOSTICS, "Ghost damage: %d; brand: %d", ghost.damage, ghost.brand ); @@ -1822,7 +1818,7 @@ static void _dump_item( const char *name, int num, const item_def &item ) item.quantity, item.colour, item.flags, get_ident_type( item ) ); - mprf(" x: %d; y: %d; link: %d", item.x, item.y, item.link ); + mprf(" x: %d; y: %d; link: %d", item.pos.x, item.pos.y, item.link ); crawl_state.cancel_cmd_repeat(); } @@ -1862,7 +1858,7 @@ void debug_item_scan( void ) } // Check that item knows what stack it's in - if (mitm[obj].x != x || mitm[obj].y != y) + if (mitm[obj].pos.x != x || mitm[obj].pos.y != y) { mprf(MSGCH_ERROR,"Item position incorrect at (%d,%d)!",x,y); _dump_item( mitm[obj].name(DESC_PLAIN).c_str(), @@ -1891,13 +1887,13 @@ void debug_item_scan( void ) strcpy(name, mitm[i].name(DESC_PLAIN).c_str()); // Don't check (-1,-1) player items or (0,0) monster items - if ((mitm[i].x > 0 || mitm[i].y > 0) && !visited[i]) + if ((mitm[i].pos.x > 0 || mitm[i].pos.y > 0) && !visited[i]) { mpr( "Unlinked item:", MSGCH_ERROR ); _dump_item( name, i, mitm[i] ); mprf("igrd(%d,%d) = %d", - mitm[i].x, mitm[i].y, igrd[ mitm[i].x ][ mitm[i].y ] ); + mitm[i].pos.x, mitm[i].pos.y, igrd( mitm[i].pos )); // Let's check to see if it's an errant monster object: for (int j = 0; j < MAX_MONSTERS; j++) @@ -1907,7 +1903,7 @@ void debug_item_scan( void ) { mprf("Held by monster #%d: %s at (%d,%d)", j, menv[j].name(DESC_CAP_A, true).c_str(), - menv[j].x, menv[j].y ); + menv[j].pos().x, menv[j].pos().y ); } } } @@ -1968,7 +1964,7 @@ void debug_item_scan( void ) mprf( MSGCH_ERROR, "Program bug detected!" ); mprf( MSGCH_ERROR, "Buggy monster detected: monster #%d; position (%d,%d)", - i, monster.x, monster.y ); + i, monster.pos().x, monster.pos().y ); } } } @@ -1990,7 +1986,7 @@ void debug_mons_scan() mprf(MSGCH_WARN, "Bogosity: mgrd at %d,%d points at %s, " "but monster is at %d,%d", - x, y, m->name(DESC_PLAIN).c_str(), m->x, m->y); + x, y, m->name(DESC_PLAIN).c_str(), m->pos().x, m->pos().y); warned = true; } } @@ -2003,7 +1999,7 @@ void debug_mons_scan() if (mgrd(m->pos()) != i) { mprf(MSGCH_WARN, "Floating monster: %s at (%d,%d)", - m->name(DESC_PLAIN).c_str(), m->x, m->y); + m->name(DESC_PLAIN).c_str(), m->pos().x, m->pos().y); warned = true; } } @@ -2972,8 +2968,7 @@ static bool _fsim_ranged_combat(FILE *out, int wskill, int mi, // throw_it() will decrease quantity by 1 inc_inv_item_quantity(thrown, 1); - beam.target_x = mon.x; - beam.target_y = mon.y; + beam.target = mon.pos(); if (throw_it(beam, thrown, true, DEBUG_COOKIE)) hits++; @@ -3498,7 +3493,7 @@ void debug_make_trap() } } - place_specific_trap(you.x_pos, you.y_pos, trap); + place_specific_trap(you.pos(), trap); mprf("Created a %s trap, marked it undiscovered", trap_name(trap)); } @@ -3549,7 +3544,7 @@ void debug_make_shop() representative = !!strchr(requested_shop, '*'); - place_spec_shop(you.your_level, you.x_pos, you.y_pos, + place_spec_shop(you.your_level, you.pos(), new_shop_type, representative); link_items(); mprf("Done."); @@ -4105,8 +4100,7 @@ void wizard_give_monster_item(monsters *mon) item_def &new_item = mitm[index]; new_item = item; new_item.link = NON_ITEM; - new_item.x = 0; - new_item.y = 0; + new_item.pos.reset(); mon->inv[mon_slot] = index; @@ -4128,29 +4122,29 @@ void wizard_give_monster_item(monsters *mon) #endif #ifdef WIZARD -static void _move_player(int x, int y) +static void _move_player(const coord_def& where) { // no longer held in net clear_trapping_net(); - if (!you.can_pass_through_feat(grd[x][y])) - grd[x][y] = DNGN_FLOOR; - move_player_to_grid(coord_def(x, y), false, true, true); + if (!you.can_pass_through_feat(grd(where))) + grd(where) = DNGN_FLOOR; + move_player_to_grid(where, false, true, true); } -static void _move_monster(int x, int y, int mid1) +static void _move_monster(const coord_def& where, int mid1) { dist moves; direction(moves, DIR_NONE, TARG_ANY, -1, true, false, true, true, "Move monster to where?"); - if (!moves.isValid || !in_bounds(moves.tx, moves.ty)) + if (!moves.isValid || !in_bounds(moves.target)) return; monsters* mon1 = &menv[mid1]; mons_clear_trapping_net(mon1); - int mid2 = mgrd[moves.tx][moves.ty]; + int mid2 = mgrd(moves.target); monsters* mon2 = NULL; if (mid2 != NON_MONSTER) @@ -4159,23 +4153,20 @@ static void _move_monster(int x, int y, int mid1) mons_clear_trapping_net(mon2); } - mon1->x = moves.tx; - mon1->y = moves.ty; - mgrd[moves.tx][moves.ty] = mid1; - mon1->check_redraw(moves.target()); + mon1->moveto(moves.target); + mgrd(moves.target) = mid1; + mon1->check_redraw(moves.target); - mgrd[x][y] = mid2; + mgrd(where) = mid2; if (mon2 != NULL) { - mon2->x = x; - mon2->y = y; - - mon1->check_redraw(coord_def(x, y)); + mon2->moveto(where); + mon1->check_redraw(where); } } -void wizard_move_player_or_monster(int x, int y) +void wizard_move_player_or_monster(const coord_def& where) { crawl_state.cancel_cmd_again(); crawl_state.cancel_cmd_repeat(); @@ -4190,12 +4181,12 @@ void wizard_move_player_or_monster(int x, int y) already_moving = true; - int mid = mgrd[x][y]; + int mid = mgrd(where); if (mid == NON_MONSTER) - _move_player(x, y); + _move_player(where); else - _move_monster(x, y, mid); + _move_monster(where, mid); already_moving = false; } @@ -4220,7 +4211,7 @@ void debug_pathfind(int mid) monsters &mon = menv[mid]; mprf("Attempting to calculate a path from (%d, %d) to (%d, %d)...", - mon.x, mon.y, dest.x, dest.y); + mon.pos().x, mon.pos().y, dest.x, dest.y); monster_pathfind mp; bool success = mp.start_pathfind(&mon, dest, true); if (success) @@ -4600,9 +4591,10 @@ static bool mg_do_build_level(int niters) // Mapping would only have mapped squares that the player can // reach - explicitly map the full level. - for (int y = 0; y < GYM; ++y) - for (int x = 0; x < GXM; ++x) - set_envmap_obj(x, y, grd[x][y]); + coord_def c; + for (c.y = 0; c.y < GYM; ++c.y) + for (c.x = 0; c.x < GXM; ++c.x) + set_envmap_obj(c, grd(c)); dump_map(fp); diff --git a/crawl-ref/source/debug.h b/crawl-ref/source/debug.h index 1edf54f960..7902854eea 100644 --- a/crawl-ref/source/debug.h +++ b/crawl-ref/source/debug.h @@ -114,9 +114,10 @@ void debug_stethoscope(int mon); #endif class monsters; +class coord_def; void wizard_apply_monster_blessing(monsters* mon); void wizard_give_monster_item(monsters* mon); -void wizard_move_player_or_monster(int x, int y); +void wizard_move_player_or_monster(const coord_def& where); void debug_make_monster_shout(monsters* mon); void debug_pathfind(int mid); void debug_miscast( int target ); diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc index 46848623ef..f3889e35ae 100644 --- a/crawl-ref/source/decks.cc +++ b/crawl-ref/source/decks.cc @@ -1364,8 +1364,7 @@ static void _swap_monster_card(int power, deck_rarity_type rarity) // Pick the monster up. mgrd(newpos) = NON_MONSTER; - mon.x = you.x_pos; - mon.y = you.y_pos; + mon.moveto(you.pos()); // Plunk it down. mgrd(mon.pos()) = monster_index(mon_to_swap); @@ -1468,34 +1467,27 @@ static void _warpwright_card(int power, deck_rarity_type rarity) } int count = 0; - int fx = -1, fy = -1; - for (int dx = -1; dx <= 1; ++dx) - for (int dy = -1; dy <= 1; ++dy) + coord_def f; + for (adjacent_iterator ai; ai; ++ai) + { + if (grd(*ai) == DNGN_FLOOR + && trap_at_xy(*ai) == -1 + && one_chance_in(++count)) { - if ( dx == 0 && dy == 0 ) - continue; - - const int rx = you.x_pos + dx; - const int ry = you.y_pos + dy; - - if (grd[rx][ry] == DNGN_FLOOR && trap_at_xy(coord_def(rx,ry)) == -1 - && one_chance_in(++count)) - { - fx = rx; - fy = ry; - } + f = *ai; } + } - if (fx >= 0) // found a spot + if (count > 0) // found a spot { - if (place_specific_trap(fx, fy, TRAP_TELEPORT)) + if (place_specific_trap(f, TRAP_TELEPORT)) { // Mark it discovered if enough power. if (get_power_level(power, rarity) >= 1) { - const int i = trap_at_xy(coord_def(fx, fy)); + const int i = trap_at_xy(f); if (i != -1) // should always happen - grd[fx][fy] = trap_category(env.trap[i].type); + grd(f) = trap_category(env.trap[i].type); } } } @@ -1528,7 +1520,7 @@ static void _flight_card(int power, deck_rarity_type rarity) { if (is_valid_shaft_level() && grd(you.pos()) == DNGN_FLOOR) { - if (place_specific_trap(you.x_pos, you.y_pos, TRAP_SHAFT)) + if (place_specific_trap(you.pos(), TRAP_SHAFT)) { const int i = trap_at_xy(you.pos()); grd(you.pos()) = trap_category(env.trap[i].type); @@ -1557,7 +1549,7 @@ static void _minefield_card(int power, deck_rarity_type rarity) if (you.level_type == LEVEL_ABYSS) grd(*ri) = coinflip() ? DNGN_DEEP_WATER : DNGN_LAVA; else - place_specific_trap(ri->x, ri->y, TRAP_RANDOM); + place_specific_trap(*ri, TRAP_RANDOM); } } } diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index 861b68bb1e..99f27f96fa 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -222,7 +222,7 @@ static int _recite_to_monsters(coord_def where, int pow, int unused) static std::string _get_recite_speech(const std::string key, int weight) { - seed_rng( weight + you.x_pos + you.y_pos); + seed_rng( weight + you.pos().x + you.pos().y); const std::string str = getSpeakString("zin_recite_speech_" + key); if (!str.empty()) @@ -728,8 +728,7 @@ void handle_delay( void ) // original and that's why we do it this way. if (is_valid_item(mitm[ delay.parm1 ]) && mitm[ delay.parm1 ].base_type == OBJ_CORPSES - && mitm[ delay.parm1 ].x == you.x_pos - && mitm[ delay.parm1 ].y == you.y_pos) + && mitm[ delay.parm1 ].pos == you.pos()) { if (mitm[ delay.parm1 ].sub_type == CORPSE_SKELETON) { @@ -1421,7 +1420,7 @@ static command_type _get_running_command() else if (Options.travel_delay > 0) delay(Options.travel_delay); - return direction_to_command( you.running.x, you.running.y ); + return direction_to_command( you.running.pos.x, you.running.pos.y ); } static void _handle_run_delays(const delay_queue_item &delay) diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index eeadefbbd3..4dca3afa3e 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -1637,7 +1637,7 @@ std::string get_item_description( const item_def &item, bool verbose, << " colour: " << static_cast(item.colour) << " flags: " << std::hex << std::setw(8) << item.flags << std::dec << "$" - << "x: " << item.x << " y: " << item.y + << "x: " << item.pos.x << " y: " << item.pos.y << " link: " << item.link << " slot: " << item.slot << " ident_type: " diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 3ec1dd79d9..dc5240794a 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -104,14 +104,14 @@ static bool _find_mlist( const coord_def& where, int mode, bool need_path, #endif static char _find_square_wrapper( const coord_def& targ, - FixedVector &mfp, char direction, + coord_def &mfp, char direction, bool (*find_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( const coord_def& where, - FixedVector &mfp, int direction, + coord_def &mfp, int direction, bool (*find_targ)(const coord_def&, int, bool, int), bool need_path, int mode = TARG_ANY, int range = -1, bool wrap = false, int los = LOS_ANY); @@ -126,7 +126,7 @@ void direction_choose_compass( dist& moves, targeting_behaviour *beh) moves.isTarget = false; moves.isMe = false; moves.isCancel = false; - moves.dx = moves.dy = 0; + moves.delta.reset(); mouse_control mc(MOUSE_MODE_TARGET_DIR); @@ -160,16 +160,15 @@ void direction_choose_compass( dist& moves, targeting_behaviour *beh) continue; } - moves.dx = delta.x; - moves.dy = delta.y; - moves.isMe = (delta.x == 0) && (delta.y == 0); + moves.delta = delta; + moves.isMe = delta.origin(); break; } #endif if (key_command == CMD_TARGET_SELECT) { - moves.dx = moves.dy = 0; + moves.delta.reset(); moves.isMe = true; break; } @@ -177,8 +176,7 @@ void direction_choose_compass( dist& moves, targeting_behaviour *beh) const int i = _targeting_cmd_to_compass(key_command); if (i != -1) { - moves.dx = Compass[i].x; - moves.dy = Compass[i].y; + moves.delta = Compass[i]; } else if (key_command == CMD_TARGET_CANCEL) { @@ -186,7 +184,7 @@ void direction_choose_compass( dist& moves, targeting_behaviour *beh) moves.isValid = false; } } - while (!moves.isCancel && moves.dx == 0 && moves.dy == 0); + while (!moves.isCancel && moves.delta.origin()); } static int _targeting_cmd_to_compass( command_type command ) @@ -293,8 +291,8 @@ static bool _mon_submerged_in_water(const monsters *mon) if (!mon) return (false); - return (grd[mon->x][mon->y] == DNGN_SHALLOW_WATER - && see_grid(mon->x, mon->y) + return (grd(mon->pos()) == DNGN_SHALLOW_WATER + && see_grid(mon->pos()) && !player_monster_visible(mon) && !mons_flies(mon)); } @@ -379,8 +377,7 @@ static void _direction_again(dist& moves, targeting_type restricts, "square you previously targeted."); return; } - else if (you.prev_grd_targ.x == you.x_pos - && you.prev_grd_targ.y == you.y_pos) + else if (you.prev_grd_targ == you.pos()) { moves.isCancel = true; @@ -398,18 +395,16 @@ static void _direction_again(dist& moves, targeting_type restricts, return; } - moves.tx = you.prev_grd_targ.x; - moves.ty = you.prev_grd_targ.y; + moves.target = you.prev_grd_targ; ray_def ray; - find_ray(you.pos(), moves.target(), true, ray, 0, true); + find_ray(you.pos(), moves.target, true, ray, 0, true); moves.ray = ray; } else if (you.prev_targ == MHITYOU) { moves.isMe = true; - moves.tx = you.x_pos; - moves.ty = you.y_pos; + moves.target = you.pos(); // Discard 'Y' player gave to yesno() if (mode == TARG_ENEMY) @@ -437,11 +432,10 @@ static void _direction_again(dist& moves, targeting_type restricts, return; } - moves.tx = montarget->x; - moves.ty = montarget->y; + moves.target = montarget->pos(); ray_def ray; - find_ray(you.pos(), moves.target(), true, ray, 0, true); + find_ray(you.pos(), moves.target, true, ray, 0, true); moves.ray = ray; } @@ -571,17 +565,15 @@ void direction(dist& moves, targeting_type restricts, bool show_beam = Options.show_beam && !just_looking && needs_path; ray_def ray; - FixedVector < char, 2 > objfind_pos; - FixedVector < char, 2 > monsfind_pos; + coord_def objfind_pos, monsfind_pos; // init - moves.dx = moves.dy = 0; - moves.tx = you.x_pos; - moves.ty = you.y_pos; + moves.delta.reset(); + moves.target = you.pos(); // If we show the beam on startup, we have to initialise it. if (show_beam) - find_ray(you.pos(), moves.target(), true, ray); + find_ray(you.pos(), moves.target, true, ray); bool skip_iter = false; bool found_autotarget = false; @@ -599,8 +591,7 @@ void direction(dist& moves, targeting_type restricts, && _is_target_in_range(montarget->pos(), range)) { found_autotarget = true; - moves.tx = montarget->x; - moves.ty = montarget->y; + moves.target = montarget->pos(); } } } @@ -617,9 +608,9 @@ void direction(dist& moves, targeting_type restricts, target_mode_help_text(restricts)); if ((mode == TARG_ANY || mode == TARG_FRIEND) - && moves.tx == you.x_pos && moves.ty == you.y_pos) + && moves.target == you.pos()) { - terse_describe_square(moves.target()); + terse_describe_square(moves.target); } show_prompt = false; @@ -634,7 +625,7 @@ void direction(dist& moves, targeting_type restricts, moves.isEndpoint = false; moves.choseRay = false; - cursorxy( grid2viewX(moves.tx), grid2viewY(moves.ty) ); + cursorxy( grid2viewX(moves.target.x), grid2viewY(moves.target.y) ); command_type key_command; @@ -658,8 +649,7 @@ void direction(dist& moves, targeting_type restricts, const coord_def &gc = tiles.get_cursor(); if (gc != Region::NO_CURSOR) { - moves.tx = gc.x; - moves.ty = gc.y; + moves.target = gc; if (key_command == CMD_TARGET_MOUSE_SELECT) key_command = CMD_TARGET_SELECT; @@ -671,7 +661,7 @@ void direction(dist& moves, targeting_type restricts, } #endif - if (target_unshifted && moves.target() == you.pos() + if (target_unshifted && moves.target == you.pos() && restricts != DIR_TARGET) { key_command = shift_direction(key_command); @@ -689,7 +679,7 @@ void direction(dist& moves, targeting_type restricts, if (key_command == CMD_TARGET_MAYBE_PREV_TARGET) { - if (moves.target() == you.pos()) + if (moves.target == you.pos()) key_command = CMD_TARGET_PREV_TARGET; else key_command = CMD_TARGET_SELECT; @@ -699,8 +689,9 @@ void direction(dist& moves, targeting_type restricts, bool force_redraw = false; bool loop_done = false; - const int old_tx = moves.tx + (skip_iter ? 500 : 0); // hmmm...hack - const int old_ty = moves.ty; + coord_def old_target = moves.target; + if ( skip_iter ) + old_target.x += 500; // hmmm...hack int i, mid; @@ -711,12 +702,11 @@ void direction(dist& moves, targeting_type restricts, const int idx = _mlist_letter_to_index(key_command + 'a' - CMD_TARGET_CYCLE_MLIST); - if (_find_square_wrapper(moves.target(), monsfind_pos, 1, + if (_find_square_wrapper(moves.target, monsfind_pos, 1, _find_mlist, needs_path, idx, range, Options.target_wrap)) { - moves.tx = monsfind_pos[0]; - moves.ty = monsfind_pos[1]; + moves.target = monsfind_pos; } else if (!skip_iter) flush_input_buffer(FLUSH_ON_FAILURE); @@ -735,8 +725,7 @@ void direction(dist& moves, targeting_type restricts, case CMD_TARGET_UP: case CMD_TARGET_UP_RIGHT: i = _targeting_cmd_to_compass(key_command); - moves.tx += Compass[i].x; - moves.ty += Compass[i].y; + moves.target += Compass[i]; break; case CMD_TARGET_DIR_DOWN_LEFT: @@ -752,11 +741,9 @@ void direction(dist& moves, targeting_type restricts, if (restricts != DIR_TARGET) { // A direction is allowed, and we've selected it. - moves.dx = Compass[i].x; - moves.dy = Compass[i].y; + moves.delta = Compass[i]; // Needed for now...eventually shouldn't be necessary - moves.tx = you.x_pos + moves.dx; - moves.ty = you.y_pos + moves.dy; + moves.target = you.pos() + moves.delta; moves.isValid = true; moves.isTarget = false; show_beam = false; @@ -768,15 +755,9 @@ void direction(dist& moves, targeting_type restricts, // Direction not allowed, so just move in that direction. // Maybe make this a bigger jump? if (restricts == DIR_TARGET) - { - moves.tx += Compass[i].x * 3; - moves.ty += Compass[i].y * 3; - } + moves.target += Compass[i] * 3; else - { - moves.tx += Compass[i].x; - moves.ty += Compass[i].y; - } + moves.target += Compass[i]; } break; @@ -807,7 +788,7 @@ void direction(dist& moves, targeting_type restricts, #ifdef WIZARD case CMD_TARGET_CYCLE_BEAM: - show_beam = find_ray(you.pos(), moves.target(), + show_beam = find_ray(you.pos(), moves.target, true, ray, (show_beam ? 1 : 0)); need_beam_redraw = true; break; @@ -828,17 +809,15 @@ void direction(dist& moves, targeting_type restricts, break; } - show_beam = find_ray(you.pos(), moves.target(), + show_beam = find_ray(you.pos(), moves.target, true, ray, 0, true); need_beam_redraw = show_beam; } break; case CMD_TARGET_FIND_YOU: - moves.tx = you.x_pos; - moves.ty = you.y_pos; - moves.dx = 0; - moves.dy = 0; + moves.target = you.pos(); + moves.delta.reset(); break; case CMD_TARGET_FIND_TRAP: @@ -848,13 +827,12 @@ 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.target(), 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)) { - moves.tx = objfind_pos[0]; - moves.ty = objfind_pos[1]; + moves.target = objfind_pos; } else { @@ -895,8 +873,7 @@ void direction(dist& moves, targeting_type restricts, // We have all the information we need. moves.isValid = true; moves.isTarget = true; - moves.tx = montarget->x; - moves.ty = montarget->y; + moves.target = montarget->pos(); if (!just_looking) { // We have to turn off show_beam, because @@ -917,8 +894,8 @@ void direction(dist& moves, targeting_type restricts, // intentional fall-through case CMD_TARGET_SELECT: // finalize current choice if (!moves.isEndpoint - && mgrd[moves.tx][moves.ty] != NON_MONSTER - && _mon_submerged_in_water(&menv[mgrd[moves.tx][moves.ty]])) + && mgrd(moves.target) != NON_MONSTER + && _mon_submerged_in_water(&menv[mgrd(moves.target)])) { moves.isEndpoint = true; } @@ -926,17 +903,17 @@ void direction(dist& moves, targeting_type restricts, moves.isTarget = true; loop_done = true; - you.prev_grd_targ = coord_def(0, 0); + you.prev_grd_targ.reset(); // Maybe we should except just_looking here? - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid != NON_MONSTER) you.prev_targ = mid; - else if (moves.target() == you.pos()) + else if (moves.target == you.pos()) you.prev_targ = MHITYOU; else - you.prev_grd_targ = coord_def(moves.tx, moves.ty); + you.prev_grd_targ = moves.target; #ifndef USE_TILE if (Options.mlist_targetting == MLIST_TARGET_ON) @@ -947,14 +924,13 @@ 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.target(), 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) : LOS_ANY)) { - moves.tx = objfind_pos[0]; - moves.ty = objfind_pos[1]; + moves.target = objfind_pos; } else if (!skip_iter) flush_input_buffer(FLUSH_ON_FAILURE); @@ -964,12 +940,11 @@ 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.target(), monsfind_pos, dir, + if (_find_square_wrapper( moves.target, monsfind_pos, dir, _find_monster, needs_path, mode, range, Options.target_wrap)) { - moves.tx = monsfind_pos[0]; - moves.ty = monsfind_pos[1]; + moves.target = monsfind_pos; } else if (!skip_iter) flush_input_buffer(FLUSH_ON_FAILURE); @@ -989,10 +964,10 @@ void direction(dist& moves, targeting_type restricts, #ifdef WIZARD case CMD_TARGET_WIZARD_MAKE_FRIENDLY: // Maybe we can skip this check...but it can't hurt - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid == NON_MONSTER) // can put in terrain description here break; @@ -1028,9 +1003,9 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_WIZARD_BLESS_MONSTER: - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid == NON_MONSTER) // can put in terrain description here break; @@ -1039,9 +1014,9 @@ void direction(dist& moves, targeting_type restricts, case CMD_TARGET_WIZARD_MAKE_SHOUT: // Maybe we can skip this check...but it can't hurt - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid == NON_MONSTER) // can put in terrain description here break; @@ -1049,9 +1024,9 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_WIZARD_GIVE_ITEM: - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid == NON_MONSTER) // can put in terrain description here break; @@ -1059,9 +1034,9 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_WIZARD_MOVE: - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - wizard_move_player_or_monster(moves.tx, moves.ty); + wizard_move_player_or_monster(moves.target); loop_done = true; skip_iter = true; @@ -1069,9 +1044,9 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_WIZARD_PATHFIND: - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; + mid = mgrd(moves.target); if (mid == NON_MONSTER) break; @@ -1082,17 +1057,17 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_WIZARD_MISCAST: - if (!you.wizard || !in_bounds(moves.tx, moves.ty)) + if (!you.wizard || !in_bounds(moves.target)) break; - mid = mgrd[moves.tx][moves.ty]; - if (mid == NON_MONSTER && you.pos() != moves.target()) + mid = mgrd(moves.target); + if (mid == NON_MONSTER && you.pos() != moves.target) break; debug_miscast(mid); break; #endif case CMD_TARGET_DESCRIBE: - full_describe_square(moves.target()); + full_describe_square(moves.target); force_redraw = true; break; @@ -1122,7 +1097,7 @@ void direction(dist& moves, targeting_type restricts, // Confirm self-targeting on TARG_ENEMY (option-controlled.) // Conceivably we might want to confirm on TARG_ANY too. if (moves.isTarget - && moves.target() == you.pos() + && moves.target == you.pos() && mode == TARG_ENEMY && (cancel_at_self || Options.allow_self_target == CONFIRM_CANCEL @@ -1142,7 +1117,7 @@ void direction(dist& moves, targeting_type restricts, show_prompt = true; } - else if (moves.isTarget && !see_grid(moves.tx, moves.ty)) + else if (moves.isTarget && !see_grid(moves.target)) { mpr("Sorry, you can't target what you can't see.", MSGCH_EXAMINE_FILTER); @@ -1161,19 +1136,18 @@ void direction(dist& moves, targeting_type restricts, // We'll go on looping. Redraw whatever is necessary. - if ( !in_viewport_bounds(grid2viewX(moves.tx), grid2viewY(moves.ty)) ) + if ( !in_viewport_bounds(grid2view(moves.target)) ) { // Tried to step out of bounds - moves.tx = old_tx; - moves.ty = old_ty; + moves.target = old_target; } bool have_moved = false; - if (old_tx != moves.tx || old_ty != moves.ty) + if (old_target != moves.target) { have_moved = true; - show_beam = show_beam && find_ray(you.pos(), moves.target(), + show_beam = show_beam && find_ray(you.pos(), moves.target, true, ray, 0, true); } @@ -1189,13 +1163,13 @@ void direction(dist& moves, targeting_type restricts, if (!skip_iter) // Don't clear before we get a chance to see. mesclr(true); // Maybe not completely necessary. - terse_describe_square(moves.target()); + terse_describe_square(moves.target); } #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.pos(), moves.target(), + || show_beam && find_ray(you.pos(), moves.target, true, ray, 0, true) ) { #else @@ -1204,13 +1178,13 @@ void direction(dist& moves, targeting_type restricts, viewwindow(true, false); #endif if (show_beam - && in_vlos(grid2viewX(moves.tx), grid2viewY(moves.ty)) - && moves.target() != you.pos() ) + && in_vlos(grid2view(moves.target)) + && moves.target != you.pos() ) { // Draw the new ray with magenta '*'s, not including // your square or the target square. ray_def raycopy = ray; // temporary copy to work with - while (raycopy.pos() != moves.target()) + while (raycopy.pos() != moves.target) { if (raycopy.pos() != you.pos()) { @@ -1221,11 +1195,11 @@ void direction(dist& moves, targeting_type restricts, draw_ray_glyph(raycopy.pos(), MAGENTA, '*', MAGENTA | COLFLAG_REVERSE); } - raycopy.advance_through(moves.target()); + raycopy.advance_through(moves.target); } textcolor(LIGHTGREY); #ifdef USE_TILE - draw_ray_glyph(moves.target(), MAGENTA, '*', + draw_ray_glyph(moves.target, MAGENTA, '*', MAGENTA | COLFLAG_REVERSE); } viewwindow(true, false); @@ -1236,7 +1210,7 @@ void direction(dist& moves, targeting_type restricts, } skip_iter = false; // Only skip one iteration at most. } - moves.isMe = (moves.target() == you.pos()); + moves.isMe = (moves.target == you.pos()); mesclr(); // We need this for directional explosions, otherwise they'll explode one @@ -1349,21 +1323,21 @@ void full_describe_square(const coord_def &c) static void _extend_move_to_edge(dist &moves) { - if (!moves.dx && !moves.dy) + if ( moves.delta.origin() ) return; // Now the tricky bit - extend the target x,y out to map edge. int mx = 0, my = 0; - if (moves.dx > 0) - mx = (GXM - 1) - you.x_pos; - if (moves.dx < 0) - mx = you.x_pos; + if (moves.delta.x > 0) + mx = (GXM - 1) - you.pos().x; + if (moves.delta.x < 0) + mx = you.pos().x; - if (moves.dy > 0) - my = (GYM - 1) - you.y_pos; - if (moves.dy < 0) - my = you.y_pos; + if (moves.delta.y > 0) + my = (GYM - 1) - you.pos().y; + if (moves.delta.y < 0) + my = you.pos().y; if (!(mx == 0 || my == 0)) { @@ -1372,8 +1346,8 @@ static void _extend_move_to_edge(dist &moves) else mx = my; } - moves.tx = you.x_pos + moves.dx * mx; - moves.ty = you.y_pos + moves.dy * my; + moves.target.x = you.pos().x + moves.delta.x * mx; + moves.target.y = you.pos().y + moves.delta.y * my; } // Attempts to describe a square that's not in line-of-sight. If @@ -1642,7 +1616,7 @@ bool in_los_bounds(const coord_def& p) // //--------------------------------------------------------------- static char _find_square( const coord_def& where, - FixedVector &mfp, int direction, + coord_def &mfp, int direction, bool (*find_targ)( const coord_def& wh, int mode, bool need_path, int range ), bool need_path, int mode, int range, bool wrap, @@ -1712,11 +1686,10 @@ static char _find_square( const coord_def& where, { if (find_targ(you.pos(), mode, need_path, range)) { - mfp[0] = ctrx; - mfp[1] = ctry; + mfp = vyou; return (1); } - return _find_square(coord_def(ctrx, ctry), mfp, direction, + return _find_square(vyou, mfp, direction, find_targ, need_path, mode, range, false, _next_los(direction, los, wrap)); } @@ -1832,8 +1805,8 @@ static char _find_square( const coord_def& where, if (temp_yps + y_change <= maxy) // it can wrap, unfortunately temp_yps += y_change; - const int targ_x = you.x_pos + temp_xps - ctrx; - const int targ_y = you.y_pos + temp_yps - ctry; + const int targ_x = you.pos().x + temp_xps - ctrx; + const int targ_y = you.pos().y + temp_yps - ctry; // We don't want to be looking outside the bounds of the arrays: //if (!in_los_bounds(temp_xps, temp_yps)) @@ -1850,8 +1823,7 @@ static char _find_square( const coord_def& where, if (find_targ(coord_def(targ_x, targ_y), mode, need_path, range)) { - mfp[0] = temp_xps; - mfp[1] = temp_yps; + mfp.set(temp_xps, temp_yps); return (1); } } @@ -1868,7 +1840,7 @@ static char _find_square( const coord_def& where, // 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( const coord_def& targ, - FixedVector &mfp, char direction, + coord_def& mfp, char direction, bool (*find_targ)(const coord_def& where, int mode, bool need_path, int range), bool need_path, int mode, int range, @@ -1877,8 +1849,7 @@ static char _find_square_wrapper( const coord_def& targ, const char r = _find_square(grid2view(targ), mfp, direction, find_targ, need_path, mode, range, wrap, los); - mfp[0] = view2gridX(mfp[0]); - mfp[1] = view2gridY(mfp[1]); + mfp = view2grid(mfp); return r; } diff --git a/crawl-ref/source/directn.h b/crawl-ref/source/directn.h index b4f1811161..3fa688e27f 100644 --- a/crawl-ref/source/directn.h +++ b/crawl-ref/source/directn.h @@ -128,23 +128,16 @@ struct dist { bool isValid; // valid target chosen? bool isTarget; // target (true), or direction (false)? - bool isMe; // selected self (convenience: tx == you.x_pos, - // ty == you.y_pos) - bool isEndpoint; // Does the player want the attack to stop at (tx,ty)? + bool isMe; // selected self (convenience: target == you.pos()) + bool isEndpoint; // Does the player want the attack to stop at target? bool isCancel; // user cancelled (usually key) bool choseRay; // user wants a specific beam - int tx,ty; // target x,y or logical extension of beam to map edge - int dx,dy; // delta x and y if direction - always -1,0,1 + coord_def target; // target x,y or logical extension of beam to map edge + coord_def delta; // delta x and y if direction - always -1,0,1 ray_def ray; // ray chosen if necessary // internal use - ignore int prev_target; // previous target - - // target - source (source == you.pos()) - coord_def target() const - { - return coord_def(tx, ty); - } }; void direction( dist &moves, targeting_type restricts = DIR_NONE, @@ -156,6 +149,9 @@ void direction( dist &moves, targeting_type restricts = DIR_NONE, bool in_los_bounds(const coord_def& p); bool in_viewport_bounds(int x, int y); +inline bool in_viewport_bounds(const coord_def& pos) { + return in_viewport_bounds(pos.x, pos.y); +} bool in_los(int x, int y); bool in_los(const coord_def &pos); bool in_vlos(int x, int y); diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index e689a95188..df834925a1 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -94,6 +94,18 @@ struct dist_feat } }; +const struct coord_def OrthCompass[4] = +{ + coord_def(0, -1), coord_def(0, 1), coord_def(-1, 0), coord_def(1, 0) +}; + +// FIXME: maintaining previous behaviour, but why are we forbidding the +// last row and column? +coord_def spec_room::random_spot() const +{ + return coord_def( random_range(tl.x, br.x-1), random_range(tl.y, br.y-1) ); +} + // DUNGEON BUILDERS static void _build_dungeon_level(int level_number, int level_type); static void _reset_level(); @@ -105,10 +117,19 @@ static bool _make_box(int room_x1, int room_y1, int room_x2, int room_y2, dungeon_feature_type floor=DNGN_UNSEEN, dungeon_feature_type wall=DNGN_UNSEEN, dungeon_feature_type avoid=DNGN_UNSEEN); -static void _replace_area(int sx, int sy, int ex, int ey, +static void _replace_area(const coord_def& p1, const coord_def& p2, dungeon_feature_type replace, dungeon_feature_type feature, unsigned mmask = 0, bool needs_update = false); +static void _replace_area(int sx, int sy, int ex, int ey, + dungeon_feature_type replace, + dungeon_feature_type feature, + unsigned mmask = 0, bool needs_update = false) +{ + _replace_area( coord_def(sx, sy), coord_def(ex, ey), + replace, feature, mmask, needs_update ); +} + static builder_rc_type _builder_by_type(int level_number, char level_type); static builder_rc_type _builder_by_branch(int level_number); static builder_rc_type _builder_normal(int level_number, char level_type, @@ -207,7 +228,8 @@ static bool _build_minivaults(int level_number, int force_vault, bool make_no_exits = false, const coord_def &where = coord_def() ); static int _vault_grid( vault_placement &, - int level_number, int vx, int vy, int altar_count, + int level_number, const coord_def& where, + int altar_count, FixedVector < object_class_type, 7 > &acq_item_class, int vgrid, std::vector &targets, int &num_runes, int rune_subst = -1, bool foll = false); @@ -934,35 +956,35 @@ static void _fixup_misplaced_items() { for (int i = 0; i < MAX_ITEMS; i++) { - if (!is_valid_item(mitm[i]) || (mitm[i].x == 0)) + item_def& item(mitm[i]); + if (!is_valid_item(item) || (item.pos.x == 0)) continue; - coord_def gc(mitm[i].x, mitm[i].y); - - if (in_bounds(gc)) + if (in_bounds(item.pos)) { - dungeon_feature_type feat = grd(gc); + dungeon_feature_type feat = grd(item.pos); if (feat >= DNGN_MINITEM) continue; #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, - "Item buggily placed in feature at (%d, %d).", gc.x, gc.y); + "Item buggily placed in feature at (%d, %d).", + item.pos.x, item.pos.y); #endif } else { #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, - "Item buggily placed out of bounds at (%d, %d).", gc.x, gc.y); + "Item buggily placed out of bounds at (%d, %d).", + item.pos.x, item.pos.y); #endif } // Can't just unlink item because it might not have been linked yet. - mitm[i].base_type = OBJ_UNASSIGNED; - mitm[i].quantity = 0; - mitm[i].x = 0; - mitm[i].y = 0; + item.base_type = OBJ_UNASSIGNED; + item.quantity = 0; + item.pos.reset(); } } @@ -975,19 +997,15 @@ static void _fixup_branch_stairs() && you.level_type == LEVEL_DUNGEON) { const dungeon_feature_type exit = your_branch().exit_stairs; - for (int x = 1; x < GXM; x++) - for (int y = 1; y < GYM; y++) - { - if (grd[x][y] >= DNGN_STONE_STAIRS_UP_I - && grd[x][y] <= DNGN_ESCAPE_HATCH_UP) + for ( rectangle_iterator ri(1); ri; ++ri ) + { + if (grd(*ri) >= DNGN_STONE_STAIRS_UP_I + && grd(*ri) <= DNGN_ESCAPE_HATCH_UP) { - if (grd[x][y] == DNGN_STONE_STAIRS_UP_I) - { - env.markers.add( - new map_feature_marker(coord_def(x,y), - grd[x][y])); - } - grd[x][y] = exit; + if (grd(*ri) == DNGN_STONE_STAIRS_UP_I) + env.markers.add(new map_feature_marker(*ri, grd(*ri))); + + grd(*ri) = exit; } } } @@ -996,27 +1014,27 @@ static void _fixup_branch_stairs() // No down staircases, thanks! if (player_branch_depth() == 1 && at_branch_bottom()) { - for (int x = 1; x < GXM; x++) - for (int y = 1; y < GYM; y++) - if (grd[x][y] >= DNGN_STONE_STAIRS_DOWN_I - && grd[x][y] <= DNGN_ESCAPE_HATCH_UP) - { - grd[x][y] = DNGN_FLOOR; - } + for (rectangle_iterator ri(1); ri; ++ri) + { + if (grd(*ri) >= DNGN_STONE_STAIRS_DOWN_I + && grd(*ri) <= DNGN_ESCAPE_HATCH_UP) + { + grd(*ri) = DNGN_FLOOR; + } + } } - else if (at_branch_bottom() - && you.level_type == LEVEL_DUNGEON) + else if (at_branch_bottom() && you.level_type == LEVEL_DUNGEON) { // Bottom level of branch - replaces down stairs with up ladders. - for (int x = 1; x < GXM; x++) - for (int y = 1; y < GYM; y++) - if (grd[x][y] >= DNGN_STONE_STAIRS_DOWN_I - && grd[x][y] <= DNGN_ESCAPE_HATCH_DOWN) - { - grd[x][y] = DNGN_ESCAPE_HATCH_UP; - } + for (rectangle_iterator ri(1); ri; ++ri) + { + if (grd(*ri) >= DNGN_STONE_STAIRS_DOWN_I + && grd(*ri) <= DNGN_ESCAPE_HATCH_DOWN) + { + grd(*ri) = DNGN_ESCAPE_HATCH_UP; + } + } } - } static bool _fixup_stone_stairs(bool preserve_vault_stairs) @@ -2432,23 +2450,17 @@ static void _builder_extras( int level_number, int level_type ) // Used to nuke shafts placed in corridors on low levels - it's just too // nasty otherwise. -static bool _shaft_is_in_corridor(int x, int y) +static bool _shaft_is_in_corridor(const coord_def& c) { - // First check horizontal neighbouring squares. - if ((!inside_level_bounds(x-1, y) || grd[x-1][y] < DNGN_SHALLOW_WATER) - && (!inside_level_bounds(x+1, y) || grd[x+1][y] < DNGN_SHALLOW_WATER)) + const coord_def adjs[] = { coord_def(-1,0), coord_def(1,0), + coord_def(0,-1), coord_def(0,1) }; + + for ( unsigned int i = 0; i < ARRAYSZ(adjs); ++i ) { - return (true); - } - - // Now check vertical neighbouring squares. - if ((!inside_level_bounds(x, y-1) || grd[x][y-1] < DNGN_SHALLOW_WATER) - && (!inside_level_bounds(x, y+1) || grd[x][y+1] < DNGN_SHALLOW_WATER)) - { - return (true); + const coord_def spot = c + adjs[i]; + if ( !inside_level_bounds(spot) || grd(spot) < DNGN_SHALLOW_WATER ) + return (true); } - - // No corridor found. return (false); } @@ -2469,10 +2481,10 @@ static void _place_traps(int level_number) int tries = 200; do { - env.trap[i].x = random2(GXM); - env.trap[i].y = random2(GYM); + env.trap[i].pos.x = random2(GXM); + env.trap[i].pos.y = random2(GYM); } - while (grd[env.trap[i].x][env.trap[i].y] != DNGN_FLOOR + while (grd(env.trap[i].pos) != DNGN_FLOOR && --tries > 0); if (tries <= 0) @@ -2484,7 +2496,7 @@ static void _place_traps(int level_number) if (trap_type == TRAP_SHAFT && level_number <= 7) { // Disallow shaft construction in corridors! - if ( _shaft_is_in_corridor(env.trap[i].x, env.trap[i].y) ) + if ( _shaft_is_in_corridor(env.trap[i].pos) ) { // Choose again! trap_type = random_trap_for_place(level_number); @@ -2495,7 +2507,7 @@ static void _place_traps(int level_number) } } - grd[env.trap[i].x][env.trap[i].y] = DNGN_UNDISCOVERED_TRAP; + grd(env.trap[i].pos) = DNGN_UNDISCOVERED_TRAP; } } @@ -3159,113 +3171,109 @@ static void _builder_items(int level_number, char level_type, int items_wanted) // to pre-floor. static void _specr_2(spec_room &sr) { - int bkout = 0; - int cx = 0, cy = 0; - int sx = 0, sy = 0; - int dx = 0, dy = 0; - int i,j; + coord_def c, delta; + int i = 0; // Paranoia -- how did we get here if there's no actual special room?? if (!sr.created) return; - grolko: - - if (bkout > 100) - return; - - switch (random2(4)) - { - case 0: - // go up from north edge - cx = sr.x1 + (random2(sr.x2 - sr.x1)); - cy = sr.y1; - dx = 0; - dy = -1; - break; - case 1: - // go down from south edge - cx = sr.x1 + (random2(sr.x2 - sr.x1)); - cy = sr.y2; - dx = 0; - dy = 1; - break; - case 2: - // go left from west edge - cy = sr.y1 + (random2(sr.y2 - sr.y1)); - cx = sr.x1; - dx = -1; - dy = 0; - break; - case 3: - // go right from east edge - cy = sr.y1 + (random2(sr.y2 - sr.y1)); - cx = sr.x2; - dx = 1; - dy = 0; - break; - } - - sx = cx; - sy = cy; - - for (i = 0; i < 100; i++) + bool is_ok = false; + for ( int tries = 0; tries < 100 && !is_ok; ++tries ) { - sx += dx; - sy += dy; + is_ok = true; - // Quit if we run off the map before finding floor. - if (!in_bounds(sx, sy)) + // Set direction. + switch (random2(4)) { - bkout++; - goto grolko; + case 0: + // go up from north edge + c.set( random_range(sr.tl.x, sr.br.x - 1), sr.tl.y ); + delta.set(0, -1); + break; + case 1: + // go down from south edge + c.set( random_range(sr.tl.x, sr.br.x - 1), sr.br.y ); + delta.set(0, 1); + break; + case 2: + // go left from west edge + c.set( sr.tl.x, random_range(sr.tl.y, sr.br.y - 1) ); + delta.set(-1, 0); + break; + case 3: + // go right from east edge + c.set( sr.br.x, random_range(sr.tl.y, sr.br.y - 1) ); + delta.set( 1, 0); + break; } - // look around for floor - if (i > 0) + coord_def s = c; + + // Note that we need to remember the value of i when we break out. + for (i = 0; i < 100; i++) { - if (grd[sx + 1][sy] == DNGN_FLOOR) - break; - if (grd[sx][sy + 1] == DNGN_FLOOR) - break; - if (grd[sx - 1][sy] == DNGN_FLOOR) - break; - if (grd[sx][sy - 1] == DNGN_FLOOR) + s += delta; + + // Quit if we run off the map before finding floor. + if (!in_bounds(s)) + { + is_ok = false; break; + } + + if (i > 0) + { + // look around for floor + bool found_floor = false; + for ( int j = 0; j < 4; ++j ) + { + const coord_def spot = s + OrthCompass[j]; + if ( !in_bounds(spot) ) + is_ok = false; + else if ( grd(spot) == DNGN_FLOOR ) + found_floor = true; + } + + if ( found_floor ) + break; + } } } - sx = cx; - sy = cy; + if ( !is_ok ) + return; + + coord_def s = c; - for (j = 0; j < i + 2; j++) + for (int j = 0; j < i + 2; j++) { - if (grd[sx][sy] == DNGN_BUILDER_SPECIAL_WALL) - grd[sx][sy] = DNGN_CLOSED_DOOR; + if (grd(s) == DNGN_BUILDER_SPECIAL_WALL) + grd(s) = DNGN_CLOSED_DOOR; - if (j > 0 && grd[sx + dx][sy + dy] > DNGN_MINWALL - && grd[sx + dx][sy + dy] < DNGN_FLOOR) + if (j > 0 + && grd(s + delta) > DNGN_MINWALL + && grd(s + delta) < DNGN_FLOOR) { - grd[sx][sy] = DNGN_BUILDER_SPECIAL_FLOOR; + grd(s) = DNGN_BUILDER_SPECIAL_FLOOR; } - if (grd[sx][sy] == DNGN_ROCK_WALL) - grd[sx][sy] = DNGN_BUILDER_SPECIAL_FLOOR; + if (grd(s) == DNGN_ROCK_WALL) + grd(s) = DNGN_BUILDER_SPECIAL_FLOOR; - sx += dx; - sy += dy; + s += delta; } sr.hooked_up = true; -} // end specr_2() +} // Fill special room sr with monsters from the pit_list at density%... // then place a "lord of the pit" of lord_type at (lordx, lordy). static void _fill_monster_pit( spec_room &sr, FixedVector &pit_list, int density, - monster_type lord_type, int lordx, int lordy ) + monster_type lord_type, const coord_def& lordpos) { - int i, x, y; + int i; // Make distribution cumulative. for (i = 1; i < MAX_PIT_MONSTERS; ++i) @@ -3303,37 +3311,32 @@ static void _fill_monster_pit( spec_room &sr, FixedVector= rare_sum) - continue; + // Density skip (no need to iterate). + if (roll >= rare_sum) + continue; - // Run through the cumulative chances and place a monster. - for (i = 0; i < num_types; ++i) + // Run through the cumulative chances and place a monster. + for (i = 0; i < num_types; ++i) + { + if (roll < pit_list[i].rare) { - if (roll < pit_list[i].rare) - { - mons_place( - mgen_data::sleeper_at(pit_list[i].type, - coord_def(x, y))); - break; - } + mons_place( + mgen_data::sleeper_at(pit_list[i].type, *ri)); + break; } } } @@ -3344,15 +3347,13 @@ static void _special_room(int level_number, spec_room &sr) char spec_room_type = SROOM_LAIR_KOBOLD; int lev_mons; int thing_created = 0; - int x, y; object_class_type obj_type = OBJ_RANDOM; // used in calling items() {dlb} unsigned char i; // general purpose loop variable {dlb} - int temp_rand = 0; // probability determination {dlb} FixedVector < monster_type, 10 > mons_alloc; // was [20] {dlb} - char lordx = 0, lordy = 0; + coord_def lordpos; // Overwrites anything: this function better be called early on during // creation. @@ -3368,10 +3369,8 @@ static void _special_room(int level_number, spec_room &sr) // Set up passed in spec_room structure. sr.created = true; sr.hooked_up = false; - sr.x1 = room_x1 + 1; - sr.x2 = room_x2 - 1; - sr.y1 = room_y1 + 1; - sr.y2 = room_y2 - 1; + sr.tl.set(room_x1 + 1, room_y1 + 1); + sr.br.set(room_x2 - 1, room_y2 - 1); if (level_number < 7) spec_room_type = SROOM_LAIR_KOBOLD; @@ -3443,22 +3442,14 @@ static void _special_room(int level_number, spec_room &sr) } // Place monsters and give them items {dlb}: - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - { - if (one_chance_in(4)) - continue; - - mons_place( - mgen_data::sleeper_at( mons_alloc[random2(10)], - coord_def(x, y) )); - } + for (rectangle_iterator ri(sr.tl, sr.br); ri; ++ri) + if (!one_chance_in(4)) + mons_place(mgen_data::sleeper_at(mons_alloc[random2(10)], *ri)); break; case SROOM_LAIR_KOBOLD: - lordx = sr.x1 + random2(sr.x2 - sr.x1); - lordy = sr.y1 + random2(sr.y2 - sr.y1); + lordpos = sr.random_spot(); // Determine which monster array to generate {dlb}: lev_mons = ((level_number < 4) ? 0 : @@ -3474,64 +3465,44 @@ static void _special_room(int level_number, spec_room &sr) mons_alloc[i] = MONS_BIG_KOBOLD; // Place monsters and give them items {dlb}: - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - { - if (one_chance_in(4)) - continue; - - // We'll put the boss down later. - if (x == lordx && y == lordy) - continue; - - mons_place( - mgen_data::sleeper_at( mons_alloc[random2(10)], - coord_def(x, y) )); - } + for ( rectangle_iterator ri(sr.tl, sr.br); ri; ++ri ) + if ( *ri != lordpos && !one_chance_in(4) ) + mons_place(mgen_data::sleeper_at(mons_alloc[random2(10)], *ri)); // Put the boss monster down. - mons_place( - mgen_data::sleeper_at( MONS_BIG_KOBOLD, - coord_def(lordx, lordy) )); + mons_place(mgen_data::sleeper_at(MONS_BIG_KOBOLD, lordpos)); break; case SROOM_TREASURY: // Should only appear in deep levels, with a guardian. // Maybe have several types of treasure room? // place treasure {dlb}: - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - { - temp_rand = random2(11); - - obj_type = ((temp_rand > 8) ? OBJ_WEAPONS : // 2 in 11 - (temp_rand > 6) ? OBJ_ARMOUR : // 2 in 11 - (temp_rand > 5) ? OBJ_MISSILES : // 1 in 11 - (temp_rand > 4) ? OBJ_WANDS : // 1 in 11 - (temp_rand > 3) ? OBJ_SCROLLS : // 1 in 11 - (temp_rand > 2) ? OBJ_JEWELLERY : // 1 in 11 - (temp_rand > 1) ? OBJ_BOOKS : // 1 in 11 - (temp_rand > 0) ? OBJ_STAVES // 1 in 11 - : OBJ_POTIONS); // 1 in 11 - - thing_created = items( 1, obj_type, OBJ_RANDOM, true, - level_number * 3, MAKE_ITEM_RANDOM_RACE); - - if (thing_created != NON_ITEM) - { - mitm[thing_created].x = x; - mitm[thing_created].y = y; - } - } + for ( rectangle_iterator ri(sr.tl, sr.br); ri; ++ri ) + { + const int temp_rand = random2(11); + + obj_type = ((temp_rand > 8) ? OBJ_WEAPONS : // 2 in 11 + (temp_rand > 6) ? OBJ_ARMOUR : // 2 in 11 + (temp_rand > 5) ? OBJ_MISSILES : // 1 in 11 + (temp_rand > 4) ? OBJ_WANDS : // 1 in 11 + (temp_rand > 3) ? OBJ_SCROLLS : // 1 in 11 + (temp_rand > 2) ? OBJ_JEWELLERY : // 1 in 11 + (temp_rand > 1) ? OBJ_BOOKS : // 1 in 11 + (temp_rand > 0) ? OBJ_STAVES // 1 in 11 + : OBJ_POTIONS); // 1 in 11 + + thing_created = items( 1, obj_type, OBJ_RANDOM, true, + level_number * 3, MAKE_ITEM_RANDOM_RACE); + + if (thing_created != NON_ITEM) + mitm[thing_created].pos = *ri; + } // place guardian {dlb}: // If wandering, the guardian should return to the treasure room. mons_place( - mgen_data::sleeper_at( - MONS_GUARDIAN_NAGA, - coord_def(sr.x1 + random2( sr.x2 - sr.x1 ), - sr.y1 + random2( sr.y2 - sr.y1 )), - MG_PATROLLING )); + mgen_data::sleeper_at( MONS_GUARDIAN_NAGA, sr.random_spot(), + MG_PATROLLING )); break; case SROOM_BEEHIVE: @@ -3551,53 +3522,42 @@ static void _special_room(int level_number, spec_room &sr) // Fills a special room with bees. static void _beehive(spec_room &sr) { - int x,y; - - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - { - if (coinflip()) - continue; - - const int i = get_item_slot(); - if (i == NON_ITEM) - continue; - - mitm[i].quantity = 1; - mitm[i].base_type = OBJ_FOOD; - mitm[i].sub_type = (one_chance_in(25) ? FOOD_ROYAL_JELLY - : FOOD_HONEYCOMB); - mitm[i].x = x; - mitm[i].y = y; + for ( rectangle_iterator ri(sr.tl, sr.br); ri; ++ri ) + { + if (coinflip()) + continue; + + const int i = get_item_slot(); + if (i == NON_ITEM) + continue; - item_colour( mitm[i] ); - } + item_def& item(mitm[i]); + + item.quantity = 1; + item.base_type = OBJ_FOOD; + item.sub_type = (one_chance_in(25) ? FOOD_ROYAL_JELLY : FOOD_HONEYCOMB); + item.pos = *ri; + item_colour( item ); + } - const int queenx = sr.x1 + random2(sr.x2 - sr.x1); - const int queeny = sr.y1 + random2(sr.y2 - sr.y1); + const coord_def queenpos(sr.random_spot()); // Mark all kinds of bees at patrolling to make them return to their hive. - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - { - if (x == queenx && y == queeny) - continue; - - // The hive is chock full of bees! - - mons_place( - mgen_data::sleeper_at( - one_chance_in(7) ? MONS_KILLER_BEE_LARVA - : MONS_KILLER_BEE, - coord_def(x, y), - MG_PATROLLING)); - } + for ( rectangle_iterator ri(sr.tl, sr.br); ri; ++ri ) + { + if (*ri == queenpos) + continue; - mons_place( - mgen_data::sleeper_at( - MONS_QUEEN_BEE, - coord_def(queenx, queeny ), - MG_PATROLLING)); + // The hive is chock full of bees! + + mons_place( + mgen_data::sleeper_at( + one_chance_in(7) ? MONS_KILLER_BEE_LARVA + : MONS_KILLER_BEE, + *ri, MG_PATROLLING)); + } + + mons_place(mgen_data::sleeper_at(MONS_QUEEN_BEE, queenpos, MG_PATROLLING)); } // Used for placement of vaults. @@ -3694,7 +3654,7 @@ static bool _connected_minivault_place(int v1x, int v1y, } static bool _find_minivault_place(const vault_placement &place, - int &v1x, int &v1y, bool clobber) + coord_def& v1, bool clobber) { // [ds] The margin around the edges of the map where the minivault // won't be placed. Purely arbitrary as far as I can see. @@ -3703,13 +3663,13 @@ static bool _find_minivault_place(const vault_placement &place, // Find a target area which can be safely overwritten. for (int tries = 0; tries < 600; ++tries) { - v1x = random_range( margin, GXM - margin - place.size.x ); - v1y = random_range( margin, GYM - margin - place.size.y ); + v1.x = random_range( margin, GXM - margin - place.size.x ); + v1.y = random_range( margin, GYM - margin - place.size.y ); - if (!_safe_minivault_place( v1x, v1y, place, clobber )) + if (!_safe_minivault_place( v1.x, v1.y, place, clobber )) continue; - if (_connected_minivault_place(v1x, v1y, place)) + if (_connected_minivault_place(v1.x, v1.y, place)) return (true); } return (false); @@ -3737,20 +3697,19 @@ static bool _build_minivaults(int level_number, int force_vault, vault_placement place; vault_main(vgrid, place, force_vault); - int v1x, v1y; + coord_def v1; // Not map_bounds, minivaults should never touch edge. if (in_bounds(where)) { coord_def tl(where - place.size / 2); fit_region_into_map_bounds(tl, place.size); - v1x = tl.x; - v1y = tl.y; + v1 = tl; } - else if (!_find_minivault_place(place, v1x, v1y, clobber)) + else if (!_find_minivault_place(place, v1, clobber)) return (false); - place.pos = coord_def(v1x, v1y); + place.pos = v1; Level_Vaults.push_back(place); @@ -3766,30 +3725,34 @@ static bool _build_minivaults(int level_number, int force_vault, std::vector &target_connections = place.exits; // Paint the minivault onto the grid. - for (int vx = v1x; vx < v1x + place.size.x; vx++) - for (int vy = v1y; vy < v1y + place.size.y; vy++) + for (rectangle_iterator ri(v1, v1 + place.size); ri; ++ri) + { + const coord_def vdelta = *ri - v1; + + // FIXME: why the y and x swap? + const int feat = vgrid[vdelta.y][vdelta.x]; + + if (feat == ' ') + continue; + + const dungeon_feature_type oldgrid = grd(*ri); + altar_count = _vault_grid( place, + level_number, *ri, + altar_count, + acq_item_class, + feat, target_connections, + num_runes ); + if (!building_level) { - const int feat = vgrid[vy - v1y][vx - v1x]; - if (feat == ' ') - continue; - const dungeon_feature_type oldgrid = grd[vx][vy]; - altar_count = _vault_grid( place, - level_number, vx, vy, - altar_count, - acq_item_class, - feat, target_connections, - num_runes ); - if (!building_level) - { - link_items(); - const dungeon_feature_type newgrid = grd[vx][vy]; - grd[vx][vy] = oldgrid; - dungeon_terrain_changed(coord_def(vx, vy), newgrid, true, true); - env.markers.remove_markers_at(coord_def(vx, vy), MAT_ANY); - } + link_items(); + const dungeon_feature_type newgrid = grd(*ri); + grd(*ri) = oldgrid; + dungeon_terrain_changed(*ri, newgrid, true, true); + env.markers.remove_markers_at(*ri, MAT_ANY); } + } - place.map.map.apply_overlays(coord_def(v1x, v1y)); + place.map.map.apply_overlays(v1); if (!make_no_exits) { @@ -4324,38 +4287,34 @@ static bool _build_vaults(int level_number, int force_vault, int rune_subst, if (gluggy == MAP_NONE || !gluggy) return (false); - int vx, vy; int num_runes = 0; dgn_region this_vault(place.pos, place.size); // NOTE: assumes *no* previous item (I think) or monster (definitely) // placement. - for (vx = place.pos.x; vx < place.pos.x + place.size.x; vx++) - for (vy = place.pos.y; vy < place.pos.y + place.size.y; vy++) - { - if (vgrid[vy][vx] == ' ') - continue; + for ( rectangle_iterator ri(place.pos, place.pos + place.size); ri; ++ri ) + { + if (vgrid[ri->x][ri->y] == ' ') + continue; - const dungeon_feature_type oldgrid = grd[vx][vy]; - altar_count = _vault_grid( place, - level_number, vx, vy, altar_count, - acq_item_class, - vgrid[vy][vx], - target_connections, - num_runes, - rune_subst ); - if (!generating_level) - { - // Have to link items each square at a time, or - // dungeon_terrain_changed could blow up. - link_items(); - const dungeon_feature_type newgrid = grd[vx][vy]; - grd[vx][vy] = oldgrid; - dungeon_terrain_changed(coord_def(vx, vy), newgrid, - true, true); - env.markers.remove_markers_at(coord_def(vx, vy), MAT_ANY); - } + const dungeon_feature_type oldgrid = grd(*ri); + altar_count = _vault_grid( place, level_number, *ri, altar_count, + acq_item_class, + vgrid[ri->x][ri->y], + target_connections, + num_runes, + rune_subst ); + if (!generating_level) + { + // Have to link items each square at a time, or + // dungeon_terrain_changed could blow up. + link_items(); + const dungeon_feature_type newgrid = grd(*ri); + grd(*ri) = oldgrid; + dungeon_terrain_changed(*ri, newgrid, true, true); + env.markers.remove_markers_at(*ri, MAT_ANY); } + } place.map.map.apply_overlays(place.pos); _register_place(place); @@ -4477,7 +4436,7 @@ static bool _build_vaults(int level_number, int force_vault, int rune_subst, } // end build_vaults() static void _dgn_place_item_explicit(const item_spec &spec, - int x, int y, int level) + const coord_def& where, int level) { // Dummy object? if (spec.base_type == OBJ_UNASSIGNED) @@ -4504,29 +4463,28 @@ static void _dgn_place_item_explicit(const item_spec &spec, if (item_made != NON_ITEM && item_made != -1) { - mitm[item_made].x = x; - mitm[item_made].y = y; + mitm[item_made].pos = where; if (is_stackable_item(mitm[item_made]) && spec.qty > 0) mitm[item_made].quantity = spec.qty; } // Modify dungeon to ensure that the item is not on an invalid feature. - if (grd[x][y] == DNGN_DEEP_WATER) - grd[x][y] = DNGN_SHALLOW_WATER; - else if (grd[x][y] <= DNGN_MINMOVE || grd[x][y] == DNGN_LAVA) - grd[x][y] = DNGN_FLOOR; + if (grd(where) == DNGN_DEEP_WATER) + grd(where) = DNGN_SHALLOW_WATER; + else if (grd(where) <= DNGN_MINMOVE || grd(where) == DNGN_LAVA) + grd(where) = DNGN_FLOOR; } static void _dgn_place_multiple_items(item_list &list, - int x, int y, int level) + const coord_def& where, int level) { const int size = list.size(); for (int i = 0; i < size; ++i) - _dgn_place_item_explicit(list.get_item(i), x, y, level); + _dgn_place_item_explicit(list.get_item(i), where, level); } -static void _dgn_place_item_explicit(int index, int x, int y, +static void _dgn_place_item_explicit(int index, const coord_def& where, vault_placement &place, int level) { @@ -4542,7 +4500,7 @@ static void _dgn_place_item_explicit(int index, int x, int y, } const item_spec spec = sitems.get_item(index); - _dgn_place_item_explicit(spec, x, y, level); + _dgn_place_item_explicit(spec, where, level); } static void _dgn_give_mon_spec_items(mons_spec &mspec, @@ -4636,8 +4594,8 @@ static void _dgn_give_mon_spec_items(mons_spec &mspec, bool dgn_place_monster(mons_spec &mspec, - int monster_level, int vx, int vy, bool force_pos, - bool generate_awake, bool patrolling) + int monster_level, const coord_def& where, + bool force_pos, bool generate_awake, bool patrolling) { if (mspec.mid != -1) { @@ -4670,7 +4628,7 @@ bool dgn_place_monster(mons_spec &mspec, if (habitat != HT_LAND && (habitat != HT_WATER || !mons_class_amphibious(mid))) { - grd[vx][vy] = habitat2grid(habitat); + grd(where) = habitat2grid(habitat); } } @@ -4680,7 +4638,7 @@ bool dgn_place_monster(mons_spec &mspec, mg.base_type = mspec.monbase; mg.number = mspec.number; mg.colour = mspec.colour; - mg.pos = coord_def(vx, vy); + mg.pos = where; if (m_patrolling) mg.flags |= MG_PATROLLING; @@ -4697,7 +4655,7 @@ bool dgn_place_monster(mons_spec &mspec, } static bool _dgn_place_monster( const vault_placement &place, mons_spec &mspec, - int monster_level, int vx, int vy) + int monster_level, const coord_def& where) { const bool generate_awake = mspec.generate_awake || place.map.has_tag("generate_awake"); @@ -4705,18 +4663,18 @@ static bool _dgn_place_monster( const vault_placement &place, mons_spec &mspec, const bool patrolling = mspec.patrolling || place.map.has_tag("patrolling"); - return dgn_place_monster(mspec, monster_level, vx, vy, false, + return dgn_place_monster(mspec, monster_level, where, false, generate_awake, patrolling); } static bool _dgn_place_one_monster( const vault_placement &place, mons_list &mons, int monster_level, - int vx, int vy) + const coord_def& where) { for (int i = 0, size = mons.size(); i < size; ++i) { mons_spec spec = mons.get_monster(i); - if (_dgn_place_monster(place, spec, monster_level, vx, vy)) + if (_dgn_place_monster(place, spec, monster_level, where)) return (true); } return (false); @@ -4799,7 +4757,7 @@ dungeon_feature_type map_feature(map_def *map, const coord_def &c, int rawfeat) // temple - oh, well... {dlb} (XXX) static int _vault_grid( vault_placement &place, int level_number, - int vx, int vy, + const coord_def& where, int altar_count, FixedVector < object_class_type, 7 > &acq_item_class, int vgrid, @@ -4815,34 +4773,34 @@ static int _vault_grid( vault_placement &place, const feature_spec f = mapsp->get_feat(); if (f.feat >= 0) { - grd[vx][vy] = static_cast( f.feat ); + grd(where) = static_cast( f.feat ); vgrid = -1; } else if (f.glyph >= 0) { - altar_count = _vault_grid( place, level_number, vx, vy, + altar_count = _vault_grid( place, level_number, where, altar_count, acq_item_class, f.glyph, targets, num_runes, rune_subst, true ); } else if (f.shop >= 0) - place_spec_shop(level_number, vx, vy, f.shop); + place_spec_shop(level_number, where, f.shop); else if (f.trap >= 0) { const trap_type trap = (f.trap == TRAP_INDEPTH) ? random_trap_for_place(level_number) : static_cast(f.trap); - place_specific_trap(vx, vy, trap); + place_specific_trap(where, trap); } else - grd[vx][vy] = DNGN_FLOOR; + grd(where) = DNGN_FLOOR; mons_list &mons = mapsp->get_monsters(); - _dgn_place_one_monster(place, mons, level_number, vx, vy); + _dgn_place_one_monster(place, mons, level_number, where); item_list &items = mapsp->get_items(); - _dgn_place_multiple_items(items, vx, vy, level_number); + _dgn_place_multiple_items(items, where, level_number); return (altar_count); } @@ -4850,13 +4808,11 @@ static int _vault_grid( vault_placement &place, if (vgrid == 'F' && one_chance_in(100)) { vgrid = '.'; - create_monster( - mgen_data::hostile_at( - _random_evil_statue(), coord_def(vx, vy))); + create_monster(mgen_data::hostile_at( _random_evil_statue(), where)); } // First, set base tile for grids {dlb}: - grd[vx][vy] = ((vgrid == -1) ? grd[vx][vy] : + grd(where) = ((vgrid == -1) ? grd(where) : (vgrid == 'x') ? DNGN_ROCK_WALL : (vgrid == 'X') ? DNGN_PERMAROCK_WALL : (vgrid == 'c') ? DNGN_STONE_WALL : @@ -4901,22 +4857,22 @@ static int _vault_grid( vault_placement &place, altar_count++; break; case '@': - targets.push_back( coord_def(vx, vy) ); + targets.push_back( where ); break; case '^': - place_specific_trap(vx, vy, TRAP_RANDOM); + place_specific_trap(where, TRAP_RANDOM); break; case '~': - place_specific_trap(vx, vy, random_trap_for_place(level_number)); + place_specific_trap(where, random_trap_for_place(level_number)); break; } if ((vgrid == '=' || vgrid == '+') - && (vx == place.pos.x || vy == place.pos.y - || vx == place.pos.x + place.size.x - 1 - || vy == place.pos.y + place.size.y - 1)) + && (where.x == place.pos.x || where.y == place.pos.y + || where.x == place.pos.x + place.size.x - 1 + || where.y == place.pos.y + place.size.y - 1)) { - targets.push_back( coord_def(vx, vy) ); + targets.push_back( where ); } // Then, handle grids that place "stuff" {dlb}: @@ -4971,7 +4927,7 @@ static int _vault_grid( vault_placement &place, { if (rune_subst != -1) { - grd[vx][vy] = static_cast(rune_subst); + grd(where) = static_cast(rune_subst); break; } @@ -5009,8 +4965,7 @@ static int _vault_grid( vault_placement &place, if (item_made != NON_ITEM) { - mitm[item_made].x = vx; - mitm[item_made].y = vy; + mitm[item_made].pos = where; } } break; @@ -5018,17 +4973,16 @@ static int _vault_grid( vault_placement &place, // defghijk - items if (vgrid >= 'd' && vgrid <= 'k') - _dgn_place_item_explicit(vgrid - 'd', vx, vy, place, level_number); + _dgn_place_item_explicit(vgrid - 'd', where, place, level_number); if (vgrid == 'S' || vgrid == 'H') { const monster_type mtype = ((vgrid == 'H') ? MONS_ORANGE_STATUE : MONS_SILVER_STATUE); - grd[vx][vy] = DNGN_FLOOR; + grd(where) = DNGN_FLOOR; - create_monster( - mgen_data::hostile_at(mtype, coord_def(vx, vy))); + create_monster(mgen_data::hostile_at(mtype, where)); } // Finally, handle grids that place monsters {dlb}: @@ -5049,7 +5003,7 @@ static int _vault_grid( vault_placement &place, if (vgrid != '8' && vgrid != '9' && vgrid != '0') monster_type_thing = place.map.mons.get_monster(vgrid - '1'); - _dgn_place_monster(place, monster_type_thing, monster_level, vx, vy); + _dgn_place_monster(place, monster_type_thing, monster_level, where); } // Again, this seems odd, given that this is just one of many @@ -5067,27 +5021,25 @@ void replace_area_wrapper(dungeon_feature_type old_feat, _replace_area(0, 0, GXM-1, GYM-1, old_feat, new_feat, 0, false); } -static void _replace_area( int sx, int sy, int ex, int ey, +static void _replace_area( const coord_def& p1, const coord_def& p2, dungeon_feature_type replace, dungeon_feature_type feature, unsigned mapmask, bool needs_update) { - int x,y; - for (x = sx; x <= ex; x++) - for (y = sy; y <= ey; y++) + for ( rectangle_iterator ri(p1, p2); ri; ++ri ) + { + if (grd(*ri) == replace && unforbidden(*ri, mapmask)) { - if (grd[x][y] == replace && unforbidden(coord_def(x, y), mapmask)) + grd(*ri) = feature; + if (needs_update && is_terrain_seen(*ri)) { - grd[x][y] = feature; - if (needs_update && is_terrain_seen(coord_def(x,y))) - { - set_envmap_obj(x, y, feature); + set_envmap_obj(*ri, feature); #ifdef USE_TILE - tile_place_tile_bk(x, y, feature); + tile_place_tile_bk(ri->x, ri->y, feature); #endif - } } } + } } // With apologies to Metallica. @@ -5491,10 +5443,8 @@ static void _place_altar() static void _place_shops(int level_number, int nshops) { int temp_rand = 0; // probability determination {dlb} - int timeout = 0; - unsigned char shop_place_x = 0; - unsigned char shop_place_y = 0; + coord_def shop_place; bool allow_bazaars = false; @@ -5517,19 +5467,19 @@ static void _place_shops(int level_number, int nshops) for (int i = 0; i < nshops; i++) { - timeout = 0; - + int timeout = 0; + do { - shop_place_x = random_range(X_BOUND_1 + 1, X_BOUND_2 - 1); - shop_place_y = random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1); + shop_place.set(random_range(X_BOUND_1 + 1, X_BOUND_2 - 1), + random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1)); timeout++; if (timeout > 10000) return; } - while (grd[shop_place_x][shop_place_y] != DNGN_FLOOR); + while (grd(shop_place) != DNGN_FLOOR); if (allow_bazaars && level_number > 9 && level_number < 27 && one_chance_in(30 - level_number)) @@ -5539,12 +5489,9 @@ static void _place_shops(int level_number, int nshops) allow_bazaars = false; } else - { - place_spec_shop(level_number, - shop_place_x, shop_place_y, SHOP_RANDOM); - } + place_spec_shop(level_number, shop_place, SHOP_RANDOM); } -} // end place_shops() +} static bool _need_varied_selection(shop_type shop) { @@ -5552,7 +5499,7 @@ static bool _need_varied_selection(shop_type shop) } void place_spec_shop( int level_number, - int shop_x, int shop_y, + const coord_def& where, int force_s_type, bool representative ) { int orb = 0; @@ -5681,31 +5628,31 @@ void place_spec_shop( int level_number, if (orb == NON_ITEM) break; + item_def& item( mitm[orb] ); + // Increase stock of this subtype by 1, unless it is an artefact // (allow for several artefacts of the same underlying subtype) // - the latter is currently unused but would apply to e.g. jewellery. - if (_need_varied_selection(env.shop[i].type) && !is_artefact(mitm[orb])) - stocked[mitm[orb].sub_type]++; + if (_need_varied_selection(env.shop[i].type) && !is_artefact(item)) + stocked[item.sub_type]++; - if (representative && mitm[orb].base_type == OBJ_WANDS) - mitm[orb].plus = 7; + if (representative && item.base_type == OBJ_WANDS) + item.plus = 7; // Set object 'position' (gah!) & ID status. - mitm[orb].x = 0; - mitm[orb].y = 5 + i; + item.pos.set(0, 5+i); if (env.shop[i].type != SHOP_WEAPON_ANTIQUE && env.shop[i].type != SHOP_ARMOUR_ANTIQUE && env.shop[i].type != SHOP_GENERAL_ANTIQUE) { - set_ident_flags( mitm[orb], ISFLAG_IDENT_MASK ); + set_ident_flags( item, ISFLAG_IDENT_MASK ); } } - env.shop[i].x = shop_x; - env.shop[i].y = shop_y; + env.shop[i].pos = where; - grd[shop_x][shop_y] = DNGN_ENTER_SHOP; + grd(where) = DNGN_ENTER_SHOP; activate_notes(note_status); } // end place_spec_shop() @@ -6168,10 +6115,8 @@ static char _plan_4(char forbid_x1, char forbid_y1, char forbid_x2, if (forbid_x1 == 0 && one_chance_in(4)) // a market square { spec_room sr; - sr.x1 = 25; - sr.y1 = 25; - sr.x2 = 55; - sr.y2 = 45; + sr.tl.set(25,25); + sr.br.set(55,45); int oblique_max = 0; if (!one_chance_in(4)) @@ -6254,13 +6199,13 @@ bool octa_room(spec_room &sr, int oblique_max, int oblique = oblique_max; // Check octagonal room for special; avoid if exists. - for (x = sr.x1; x < sr.x2; x++) + for (x = sr.tl.x; x < sr.br.x; x++) { - for (y = sr.y1 + oblique; y < sr.y2 - oblique; y++) + for (y = sr.tl.y + oblique; y < sr.br.y - oblique; y++) if (grd[x][y] == DNGN_BUILDER_SPECIAL_WALL) return (false); - if (x > sr.x2 - oblique_max) + if (x > sr.tl.x - oblique_max) oblique += 2; if (oblique > 0) @@ -6270,9 +6215,9 @@ bool octa_room(spec_room &sr, int oblique_max, oblique = oblique_max; - for (x = sr.x1; x < sr.x2; x++) + for (x = sr.tl.x; x < sr.br.x; x++) { - for (y = sr.y1 + oblique; y < sr.y2 - oblique; y++) + for (y = sr.tl.y + oblique; y < sr.br.y - oblique; y++) { if (grd[x][y] == DNGN_ROCK_WALL) grd[x][y] = type_floor; @@ -6284,7 +6229,7 @@ bool octa_room(spec_room &sr, int oblique_max, grd[x][y] = DNGN_FLOOR; // ick } - if (x > sr.x2 - oblique_max) + if (x > sr.br.x - oblique_max) oblique += 2; if (oblique > 0) @@ -6380,10 +6325,7 @@ static void _labyrinth_place_items(const coord_def &end) MAKE_ITEM_RANDOM_RACE ); if (treasure_item != NON_ITEM) - { - mitm[treasure_item].x = end.x; - mitm[treasure_item].y = end.y; - } + mitm[treasure_item].pos = end; } } @@ -6844,10 +6786,6 @@ static bool _treasure_area(int level_number, unsigned char ta1_x, unsigned char ta2_x, unsigned char ta1_y, unsigned char ta2_y) { - int x_count = 0; - int y_count = 0; - int item_made = 0; - ta2_x++; ta2_y++; @@ -6857,22 +6795,22 @@ static bool _treasure_area(int level_number, unsigned char ta1_x, if ((ta2_x - ta1_x) * (ta2_y - ta1_y) >= 40) return (false); - for (x_count = ta1_x; x_count < ta2_x; x_count++) - for (y_count = ta1_y; y_count < ta2_y; y_count++) - { - if (grd[x_count][y_count] != DNGN_FLOOR || coinflip()) - continue; + // Gah. FIXME. + coord_def tl(ta1_x, ta1_y); + coord_def br(ta2_x-1, ta2_y-1); - item_made = items( 1, OBJ_RANDOM, OBJ_RANDOM, true, + for (rectangle_iterator ri(tl, br); ri; ++ri) + { + if (grd(*ri) != DNGN_FLOOR || coinflip()) + continue; + + int item_made = items( 1, OBJ_RANDOM, OBJ_RANDOM, true, random2( level_number * 2 ), MAKE_ITEM_RANDOM_RACE ); - - if (item_made != NON_ITEM) - { - mitm[item_made].x = x_count; - mitm[item_made].y = y_count; - } - } + + if (item_made != NON_ITEM) + mitm[item_made].pos = *ri; + } return (true); } @@ -6912,12 +6850,11 @@ static void _diamond_rooms(int level_number) { spec_room sr; - sr.x1 = 8 + random2(43); - sr.y1 = 8 + random2(35); - sr.x2 = sr.x1 + 5 + random2(15); - sr.y2 = sr.y1 + 5 + random2(10); + sr.tl.set(8 + random2(43), 8 + random2(35) ); + sr.br.set(5 + random2(15), 5 + random2(10) ); + sr.br += sr.tl; - oblique_max = (sr.x2 - sr.x1) / 2; //random2(20) + 5; + oblique_max = (sr.br.x - sr.tl.x) / 2; if (!octa_room(sr, oblique_max, type_floor)) { @@ -6946,10 +6883,9 @@ static void _big_room(int level_number) { oblique = 5 + random2(20); - sr.x1 = 8 + random2(30); - sr.y1 = 8 + random2(22); - sr.x2 = sr.x1 + 20 + random2(10); - sr.y2 = sr.y1 + 20 + random2(8); + sr.tl.set(8 + random2(30), 8 + random2(22)); + sr.br.set(20 + random2(10), 20 + random2(8)); + sr.br += sr.tl; // Usually floor, except at higher levels. if (!one_chance_in(5) || level_number < 8 + random2(8)) @@ -6971,13 +6907,12 @@ static void _big_room(int level_number) } // What now? - sr.x1 = 8 + random2(30); - sr.y1 = 8 + random2(22); - sr.x2 = sr.x1 + 20 + random2(10); - sr.y2 = sr.y1 + 20 + random2(8); + sr.tl.set(8 + random2(30), 8 + random2(22)); + sr.br.set(20 + random2(10), 20 + random2(8)); + sr.br += sr.tl; // Check for previous special. - if (_find_in_area(sr.x1, sr.y1, sr.x2, sr.y2, DNGN_BUILDER_SPECIAL_WALL)) + if (count_feature_in_box(sr.tl, sr.br, DNGN_BUILDER_SPECIAL_WALL) > 0) return; if (level_number > 7 && one_chance_in(4)) @@ -6987,8 +6922,8 @@ static void _big_room(int level_number) } // Make the big room. - _replace_area(sr.x1, sr.y1, sr.x2, sr.y2, DNGN_ROCK_WALL, type_floor); - _replace_area(sr.x1, sr.y1, sr.x2, sr.y2, DNGN_CLOSED_DOOR, type_floor); + _replace_area(sr.tl, sr.br, DNGN_ROCK_WALL, type_floor); + _replace_area(sr.tl, sr.br, DNGN_CLOSED_DOOR, type_floor); if (type_floor == DNGN_FLOOR) { @@ -7013,10 +6948,10 @@ static void _big_room(int level_number) // Sometimes make an inside room w/ stone wall. else if (one_chance_in(6)) { - i = sr.x1; - j = sr.y1; - k = sr.x2; - l = sr.y2; + i = sr.tl.x; + j = sr.tl.y; + k = sr.br.x; + l = sr.br.y; do { @@ -7043,17 +6978,12 @@ static void _chequerboard( spec_room &sr, dungeon_feature_type target, dungeon_feature_type floor1, dungeon_feature_type floor2 ) { - int i, j; - - if (sr.x2 < sr.x1 || sr.y2 < sr.y1) + if (sr.br.x < sr.tl.x || sr.br.y < sr.tl.y) return; - for (i = sr.x1; i <= sr.x2; i++) - for (j = sr.y1; j <= sr.y2; j++) - { - if (grd[i][j] == target) - grd[i][j] = (((i + j) % 2) ? floor2 : floor1); - } + for ( rectangle_iterator ri(sr.tl, sr.br); ri; ++ri ) + if (grd(*ri) == target) + grd(*ri) = ((ri->x + ri->y) % 2) ? floor2 : floor1; } static void _roguey_level(int level_number, spec_room &sr, bool make_stairs) @@ -7116,10 +7046,6 @@ static void _roguey_level(int level_number, spec_room &sr, bool make_stairs) } // Now, join them together: - FixedVector < char, 2 > pos; - FixedVector < char, 2 > jpos; - - char doing = 0; char last_room = 0; int bp; @@ -7133,48 +7059,58 @@ static void _roguey_level(int level_number, spec_room &sr, bool make_stairs) if (bp == 1 && i < 5) continue; + coord_def pos, jpos; + switch (bp) { case 0: last_room = i - 1; - pos[0] = rox1[i]; // - 1; - pos[1] = roy1[i] + random2(roy2[i] - roy1[i]); - jpos[0] = rox2[last_room]; // + 1; - jpos[1] = roy1[last_room] + pos.x = rox1[i]; // - 1; + pos.y = roy1[i] + random2(roy2[i] - roy1[i]); + jpos.x = rox2[last_room]; // + 1; + jpos.y = roy1[last_room] + random2(roy2[last_room] - roy1[last_room]); break; case 1: last_room = i - 5; - pos[1] = roy1[i]; // - 1; - pos[0] = rox1[i] + random2(rox2[i] - rox1[i]); - jpos[1] = roy2[last_room]; // + 1; - jpos[0] = rox1[last_room] + pos.y = roy1[i]; // - 1; + pos.x = rox1[i] + random2(rox2[i] - rox1[i]); + jpos.y = roy2[last_room]; // + 1; + jpos.x = rox1[last_room] + random2(rox2[last_room] - rox1[last_room]); break; } - while (pos[0] != jpos[0] || pos[1] != jpos[1]) + while (pos != jpos) { - doing = (coinflip()? 1 : 0); - - if (pos[doing] < jpos[doing]) - pos[doing]++; - else if (pos[doing] > jpos[doing]) - pos[doing]--; - - if (grd[pos[0]][pos[1]] == DNGN_ROCK_WALL) - grd[pos[0]][pos[1]] = DNGN_FLOOR; + // make a corridor + if ( coinflip() ) + { + if ( pos.x < jpos.x ) + pos.x++; + else if ( pos.x > jpos.x ) + pos.x--; + } + else + { + if ( pos.y < jpos.y ) + pos.y++; + else if ( pos.y > jpos.y ) + pos.y--; + } + if (grd(pos) == DNGN_ROCK_WALL) + grd(pos) = DNGN_FLOOR; } - if (grd[pos[0]][pos[1]] == DNGN_FLOOR) + if (grd(pos) == DNGN_FLOOR) { - if ((grd[pos[0] + 1][pos[1]] == DNGN_ROCK_WALL - && grd[pos[0] - 1][pos[1]] == DNGN_ROCK_WALL) - || (grd[pos[0]][pos[1] + 1] == DNGN_ROCK_WALL - && grd[pos[0]][pos[1] - 1] == DNGN_ROCK_WALL)) + if ((grd[pos.x + 1][pos.y] == DNGN_ROCK_WALL + && grd[pos.x - 1][pos.y] == DNGN_ROCK_WALL) + || (grd[pos.x][pos.y + 1] == DNGN_ROCK_WALL + && grd[pos.x][pos.y - 1] == DNGN_ROCK_WALL)) { - grd[pos[0]][pos[1]] = DNGN_GRANITE_STATUE; + grd(pos) = DNGN_GRANITE_STATUE; } } } // end "for bp, for i" @@ -7186,45 +7122,43 @@ static void _roguey_level(int level_number, spec_room &sr, bool make_stairs) sr.created = true; sr.hooked_up = true; - sr.x1 = rox1[spec_room_done]; - sr.x2 = rox2[spec_room_done]; - sr.y1 = roy1[spec_room_done]; - sr.y2 = roy2[spec_room_done]; + sr.tl.set( rox1[spec_room_done], roy1[spec_room_done] ); + sr.br.set( rox2[spec_room_done], roy2[spec_room_done] ); _special_room( level_number, sr ); // Make the room 'special' so it doesn't get overwritten // by something else (or put monsters in walls, etc...) // top - _replace_area(sr.x1-1, sr.y1-1, sr.x2+1,sr.y1-1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.br.x+1,sr.tl.y-1, DNGN_ROCK_WALL, DNGN_BUILDER_SPECIAL_WALL); - _replace_area(sr.x1-1, sr.y1-1, sr.x2+1,sr.y1-1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.br.x+1,sr.tl.y-1, DNGN_FLOOR, DNGN_BUILDER_SPECIAL_FLOOR); - _replace_area(sr.x1-1, sr.y1-1, sr.x2+1,sr.y1-1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.br.x+1,sr.tl.y-1, DNGN_CLOSED_DOOR, DNGN_BUILDER_SPECIAL_FLOOR); // bottom - _replace_area(sr.x1-1, sr.y2+1, sr.x2+1,sr.y2+1, + _replace_area(sr.tl.x-1, sr.br.y+1, sr.br.x+1,sr.br.y+1, DNGN_ROCK_WALL, DNGN_BUILDER_SPECIAL_WALL); - _replace_area(sr.x1-1, sr.y2+1, sr.x2+1,sr.y2+1, + _replace_area(sr.tl.x-1, sr.br.y+1, sr.br.x+1,sr.br.y+1, DNGN_FLOOR, DNGN_BUILDER_SPECIAL_FLOOR); - _replace_area(sr.x1-1, sr.y2+1, sr.x2+1,sr.y2+1, + _replace_area(sr.tl.x-1, sr.br.y+1, sr.br.x+1,sr.br.y+1, DNGN_CLOSED_DOOR, DNGN_BUILDER_SPECIAL_FLOOR); // left - _replace_area(sr.x1-1, sr.y1-1, sr.x1-1, sr.y2+1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.tl.x-1, sr.br.y+1, DNGN_ROCK_WALL, DNGN_BUILDER_SPECIAL_WALL); - _replace_area(sr.x1-1, sr.y1-1, sr.x1-1, sr.y2+1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.tl.x-1, sr.br.y+1, DNGN_FLOOR, DNGN_BUILDER_SPECIAL_FLOOR); - _replace_area(sr.x1-1, sr.y1-1, sr.x1-1, sr.y2+1, + _replace_area(sr.tl.x-1, sr.tl.y-1, sr.tl.x-1, sr.br.y+1, DNGN_CLOSED_DOOR, DNGN_BUILDER_SPECIAL_FLOOR); // right - _replace_area(sr.x2+1, sr.y1-1, sr.x2+1, sr.y2+1, + _replace_area(sr.br.x+1, sr.tl.y-1, sr.br.x+1, sr.br.y+1, DNGN_ROCK_WALL, DNGN_BUILDER_SPECIAL_WALL); - _replace_area(sr.x2+1, sr.y1-1, sr.x2+1, sr.y2+1, + _replace_area(sr.br.x+1, sr.tl.y-1, sr.br.x+1, sr.br.y+1, DNGN_FLOOR, DNGN_BUILDER_SPECIAL_FLOOR); - _replace_area(sr.x2+1, sr.y1-1, sr.x2+1, sr.y2+1, + _replace_area(sr.br.x+1, sr.tl.y-1, sr.br.x+1, sr.br.y+1, DNGN_CLOSED_DOOR, DNGN_BUILDER_SPECIAL_FLOOR); } @@ -7244,33 +7178,28 @@ static void _roguey_level(int level_number, spec_room &sr, bool make_stairs) static void _morgue(spec_room &sr) { - int temp_rand = 0; // probability determination {dlb} - int x,y; - - for (x = sr.x1; x <= sr.x2; x++) - for (y = sr.y1; y <= sr.y2; y++) - if (grd[x][y] == DNGN_FLOOR || grd[x][y] == DNGN_BUILDER_SPECIAL_FLOOR) - { - temp_rand = random2(24); - - const monster_type mon_type = - ((temp_rand > 11) ? MONS_ZOMBIE_SMALL : // 50.0% - (temp_rand > 7) ? MONS_WIGHT : // 16.7% - (temp_rand > 3) ? MONS_NECROPHAGE : // 16.7% - (temp_rand > 0) ? MONS_WRAITH // 12.5% - : MONS_VAMPIRE); // 4.2% + for (rectangle_iterator ri(sr.tl, sr.br); ri; ++ri) + { + if (grd(*ri) == DNGN_FLOOR || grd(*ri) == DNGN_BUILDER_SPECIAL_FLOOR) + { + const int temp_rand = random2(24); + + const monster_type mon_type = + ((temp_rand > 11) ? MONS_ZOMBIE_SMALL : // 50.0% + (temp_rand > 7) ? MONS_WIGHT : // 16.7% + (temp_rand > 3) ? MONS_NECROPHAGE : // 16.7% + (temp_rand > 0) ? MONS_WRAITH // 12.5% + : MONS_VAMPIRE); // 4.2% - mons_place( - mgen_data::sleeper_at( - mon_type, coord_def(x, y) )); - } + mons_place(mgen_data::sleeper_at(mon_type, *ri)); + } + } } static void _jelly_pit(int level_number, spec_room &sr) { FixedVector< pit_mons_def, MAX_PIT_MONSTERS > pit_list; - const int lordx = sr.x1 + random2(sr.x2 - sr.x1); - const int lordy = sr.y1 + random2(sr.y2 - sr.y1); + const coord_def lordpos = sr.random_spot(); for (int i = 0; i < MAX_PIT_MONSTERS; i++) { @@ -7305,10 +7234,10 @@ static void _jelly_pit(int level_number, spec_room &sr) pit_list[5].rare = 1 + (level_number - 15) / 4; } - _fill_monster_pit( sr, pit_list, 90, MONS_PROGRAM_BUG, lordx, lordy ); + _fill_monster_pit( sr, pit_list, 90, MONS_PROGRAM_BUG, lordpos ); } -bool place_specific_trap(int spec_x, int spec_y, trap_type spec_type) +bool place_specific_trap(const coord_def& where, trap_type spec_type) { if (spec_type == TRAP_RANDOM || spec_type == TRAP_NONTELEPORT) { @@ -7334,9 +7263,8 @@ bool place_specific_trap(int spec_x, int spec_y, trap_type spec_type) if (env.trap[tcount].type == TRAP_UNASSIGNED) { env.trap[tcount].type = spec_type; - env.trap[tcount].x = spec_x; - env.trap[tcount].y = spec_y; - grd[spec_x][spec_y] = DNGN_UNDISCOVERED_TRAP; + env.trap[tcount].pos = where; + grd(where) = DNGN_UNDISCOVERED_TRAP; return (true); } diff --git a/crawl-ref/source/dungeon.h b/crawl-ref/source/dungeon.h index be3c9d4cb3..4dfc976820 100644 --- a/crawl-ref/source/dungeon.h +++ b/crawl-ref/source/dungeon.h @@ -313,8 +313,8 @@ bool dgn_place_map(int map, bool generating_level, bool clobber, void level_clear_vault_memory(); void level_welcome_messages(); -bool place_specific_trap(int spec_x, int spec_y, trap_type spec_type); -void place_spec_shop(int level_number, int shop_x, int shop_y, +bool place_specific_trap(const coord_def& where, trap_type spec_type); +void place_spec_shop(int level_number, const coord_def& where, int force_s_type, bool representative = false); void replace_area_wrapper(dungeon_feature_type old_feat, dungeon_feature_type new_feat); @@ -324,7 +324,7 @@ coord_def dgn_find_nearby_stair(dungeon_feature_type stair_to_find, class mons_spec; bool dgn_place_monster(mons_spec &mspec, - int monster_level, int vx, int vy, + int monster_level, const coord_def& where, bool force_pos = false, bool generate_awake = false, bool patrolling = false); @@ -345,14 +345,15 @@ struct spec_room { bool created; bool hooked_up; - int x1; - int y1; - int x2; - int y2; + + coord_def tl; + coord_def br; - spec_room() : created(false), hooked_up(false), x1(0), y1(0), x2(0), y2(0) + spec_room() : created(false), hooked_up(false), tl(), br() { } + + coord_def random_spot() const; }; bool join_the_dots(const coord_def &from, const coord_def &to, @@ -368,6 +369,11 @@ bool octa_room(spec_room &sr, int oblique_max, int count_feature_in_box(int x0, int y0, int x1, int y1, dungeon_feature_type feat); +inline int count_feature_in_box( const coord_def& p1, const coord_def& p2, + dungeon_feature_type feat ) +{ + return count_feature_in_box(p1.x, p1.y, p2.x, p2.y, feat); +} int count_antifeature_in_box(int x0, int y0, int x1, int y1, dungeon_feature_type feat); int count_neighbours(int x, int y, dungeon_feature_type feat); diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index 03196f3c49..0ed4f0a843 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -1832,8 +1832,7 @@ static void _set_allies_patrol_point(bool clear = false) if (!mon->alive() || !mons_near(mon) || !mons_friendly(mon)) continue; - mon->patrol_point = (clear ? coord_def(0, 0) - : coord_def(mon->x, mon->y)); + mon->patrol_point = (clear ? coord_def(0, 0) : mon->pos()); if (!clear) mon->behaviour = BEH_WANDER; @@ -1995,14 +1994,14 @@ void yell(bool force) return; } - if (!targ.isValid || mgrd[targ.tx][targ.ty] == NON_MONSTER - || !player_monster_visible(&env.mons[mgrd[targ.tx][targ.ty]])) + if (!targ.isValid || mgrd(targ.target) == NON_MONSTER + || !player_monster_visible(&env.mons[mgrd(targ.target)])) { mpr("Yeah, whatever."); return; } - mons_targd = mgrd[targ.tx][targ.ty]; + mons_targd = mgrd(targ.target); break; default: @@ -2494,12 +2493,11 @@ void handle_time(long time_delta) // For particularly violent releases, make a little boom. if (you.magic_contamination >= 10 && coinflip()) { - struct bolt boom; + bolt boom; boom.type = dchar_glyph(DCHAR_FIRED_BURST); boom.colour = BLACK; boom.flavour = BEAM_RANDOM; - boom.target_x = you.x_pos; - boom.target_y = you.y_pos; + boom.target = you.pos(); // Undead enjoy extra contamination explosion damage because // the magical contamination has a harder time dissipating // through non-living flesh. :-) @@ -2680,8 +2678,8 @@ static void _catchup_monster_moves(monsters *mon, int turns) mprf(MSGCH_DIAGNOSTICS, "mon #%d: range %d; long %d; " "pos (%d,%d); targ %d(%d,%d); flags %ld", - monster_index(mon), range, long_time, mon->x, mon->y, - mon->foe, mon->target_x, mon->target_y, mon->flags ); + monster_index(mon), range, long_time, mon->pos().x, mon->pos().y, + mon->foe, mon->target.x, mon->target.y, mon->flags ); #endif if (range <= 0) @@ -2698,8 +2696,7 @@ static void _catchup_monster_moves(monsters *mon, int turns) { mon->behaviour = BEH_WANDER; mon->foe = MHITNOT; - mon->target_x = 10 + random2( GXM - 10 ); - mon->target_y = 10 + random2( GYM - 10 ); + mon->target.set(10 + random2(GXM - 10), 10 + random2(GYM - 10)); } else { @@ -2713,24 +2710,23 @@ static void _catchup_monster_moves(monsters *mon, int turns) // ranged attack (missile or spell), then the monster will // flee to gain distance if its "too close", else it will // just shift its position rather than charge the player. -- bwr - if (grid_distance(mon->pos(), mon->target_pos()) < 3) + if (grid_distance(mon->pos(), mon->target) < 3) { mon->behaviour = BEH_FLEE; // If the monster is on the target square, fleeing won't work. - if (mon->pos() == mon->target_pos()) + if (mon->pos() == mon->target) { if (you.pos() != mon->pos()) { // Flee from player's position if different. - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; + mon->target = you.pos(); } else { // Randomize the target so we have a direction to flee. - mon->target_x += (random2(3) - 1); - mon->target_y += (random2(3) - 1); + mon->target.x += (random2(3) - 1); + mon->target.y += (random2(3) - 1); } } @@ -2740,10 +2736,11 @@ static void _catchup_monster_moves(monsters *mon, int turns) } else { - shift_monster( mon, mon->x, mon->y ); + shift_monster( mon, mon->pos() ); #if DEBUG_DIAGNOSTICS - mprf(MSGCH_DIAGNOSTICS, "shifted to (%d,%d)", mon->x, mon->y); + mprf(MSGCH_DIAGNOSTICS, "shifted to (%d,%d)", + mon->pos().x, mon->pos().y); #endif return; } @@ -2753,7 +2750,7 @@ static void _catchup_monster_moves(monsters *mon, int turns) // dirt simple movement: for (int i = 0; i < moves; i++) { - coord_def inc(mon->target_pos() - pos); + coord_def inc(mon->target - pos); inc = coord_def(sgn(inc.x), sgn(inc.y)); if (mons_is_fleeing(mon)) @@ -2778,11 +2775,11 @@ static void _catchup_monster_moves(monsters *mon, int turns) pos = next; } - if (!shift_monster( mon, pos.x, pos.y )) - shift_monster( mon, mon->x, mon->y ); + if (!shift_monster( mon, pos )) + shift_monster( mon, mon->pos() ); #if DEBUG_DIAGNOSTICS - mprf(MSGCH_DIAGNOSTICS, "moved to (%d,%d)", mon->x, mon->y ); + mprf(MSGCH_DIAGNOSTICS, "moved to (%d,%d)", mon->pos().x, mon->pos().y ); #endif } @@ -2871,44 +2868,37 @@ void update_level(double elapsedTime) delete_cloud(i); } -static void _maybe_restart_fountain_flow(const int x, const int y, +static void _maybe_restart_fountain_flow(const coord_def& where, const int tries) { - dungeon_feature_type grid = grd[x][y]; + dungeon_feature_type grid = grd(where); if (grid < DNGN_DRY_FOUNTAIN_BLUE || grid > DNGN_DRY_FOUNTAIN_BLOOD) return; - int t = 0; - while (tries > t++) + + for ( int i = 0; i < tries; ++i ) { if (!one_chance_in(100)) continue; // Make it start flowing again. - grd[x][y] = static_cast (grid + grd(where) = static_cast (grid - (DNGN_DRY_FOUNTAIN_BLUE - DNGN_FOUNTAIN_BLUE)); - if (is_terrain_seen(coord_def(x,y))) - set_envmap_obj(x, y, grd[x][y]); + if (is_terrain_seen(where)) + set_envmap_obj(where, grd(where)); // Clean bloody floor. - if (is_bloodcovered(coord_def(x,y))) - env.map[x][y].property = FPROP_NONE; + if (is_bloodcovered(where)) + env.map(where).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(coord_def(x+i,y+j)) - && one_chance_in(5)) - { - env.map[x+i][y+j].property = FPROP_NONE; - } - } - } - return; + for ( adjacent_iterator ai(where); ai; ++ai ) + if (is_bloodcovered(*ai) && one_chance_in(5)) + env.map(*ai).property = FPROP_NONE; + + break; } } @@ -2923,8 +2913,6 @@ static void _maybe_restart_fountain_flow(const int x, const int y, //--------------------------------------------------------------- void update_corpses(double elapsedTime) { - int cx, cy; - if (elapsedTime <= 0.0) return; @@ -2973,14 +2961,13 @@ void update_corpses(double elapsedTime) // dry fountains may start flowing again if (fountain_checks > 0) { - for (cx = 0; cx < GXM; cx++) - for (cy = 0; cy < GYM; cy++) + for ( rectangle_iterator ri(1); ri; ++ri ) + { + if (grd(*ri) >= DNGN_DRY_FOUNTAIN_BLUE + && grd(*ri) < DNGN_PERMADRY_FOUNTAIN) { - if (grd[cx][cy] >= DNGN_DRY_FOUNTAIN_BLUE - && grd[cx][cy] < DNGN_PERMADRY_FOUNTAIN) - { - _maybe_restart_fountain_flow(cx, cy, fountain_checks); - } + _maybe_restart_fountain_flow(*ri, fountain_checks); } + } } } diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 3edf66accc..7a0556c495 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -81,6 +81,135 @@ struct coord_def; class level_id; class player_quiver; +struct coord_def +{ + int x; + int y; + + explicit coord_def( int x_in = 0, int y_in = 0 ) : x(x_in), y(y_in) { } + + void set(int xi, int yi) + { + x = xi; + y = yi; + } + + void reset() + { + set(0, 0); + } + + int distance_from(const coord_def &b) const; + + bool operator == (const coord_def &other) const + { + return x == other.x && y == other.y; + } + + bool operator != (const coord_def &other) const + { + return !operator == (other); + } + + bool operator < (const coord_def &other) const + { + return (x < other.x) || (x == other.x && y < other.y); + } + + const coord_def &operator += (const coord_def &other) + { + x += other.x; + y += other.y; + return (*this); + } + + const coord_def &operator += (int offset) + { + x += offset; + y += offset; + return (*this); + } + + const coord_def &operator -= (const coord_def &other) + { + x -= other.x; + y -= other.y; + return (*this); + } + + const coord_def &operator -= (int offset) + { + x -= offset; + y -= offset; + return (*this); + } + + const coord_def &operator /= (int div) + { + x /= div; + y /= div; + return (*this); + } + + const coord_def &operator *= (int mul) + { + x *= mul; + y *= mul; + return (*this); + } + + coord_def operator + (const coord_def &other) const + { + coord_def copy = *this; + return (copy += other); + } + + coord_def operator + (int other) const + { + coord_def copy = *this; + return (copy += other); + } + + coord_def operator - (const coord_def &other) const + { + coord_def copy = *this; + return (copy -= other); + } + + coord_def operator - (int other) const + { + coord_def copy = *this; + return (copy -= other); + } + + coord_def operator / (int div) const + { + coord_def copy = *this; + return (copy /= div); + } + + coord_def operator * (int mul) const + { + coord_def copy = *this; + return (copy *= mul); + } + + int abs() const + { + return (x * x + y * y); + } + + int rdist() const + { + return (std::max(std::abs(x), std::abs(y))); + } + + bool origin() const + { + return (!x && !y); + } +}; + class actor { public: @@ -95,7 +224,10 @@ public: virtual bool alive() const = 0; - virtual coord_def pos() const = 0; + virtual void moveto(const coord_def &c) = 0; + virtual const coord_def& pos() const { return position; } + virtual coord_def& pos() { return position; } + virtual bool swimming() const = 0; virtual bool submerged() const = 0; virtual bool floundering() const = 0; @@ -246,136 +378,10 @@ public: virtual bool will_trigger_shaft() const; virtual level_id shaft_dest() const; virtual bool do_shaft() = 0; -}; -struct coord_def -{ - int x; - int y; - - explicit coord_def( int x_in = 0, int y_in = 0 ) : x(x_in), y(y_in) { } - - void set(int xi, int yi) - { - x = xi; - y = yi; - } - - void reset() - { - set(0, 0); - } - - int distance_from(const coord_def &b) const; - - bool operator == (const coord_def &other) const - { - return x == other.x && y == other.y; - } - - bool operator != (const coord_def &other) const - { - return !operator == (other); - } - - bool operator < (const coord_def &other) const - { - return (x < other.x) || (x == other.x && y < other.y); - } - - const coord_def &operator += (const coord_def &other) - { - x += other.x; - y += other.y; - return (*this); - } - - const coord_def &operator += (int offset) - { - x += offset; - y += offset; - return (*this); - } - - const coord_def &operator -= (const coord_def &other) - { - x -= other.x; - y -= other.y; - return (*this); - } - - const coord_def &operator -= (int offset) - { - x -= offset; - y -= offset; - return (*this); - } - - const coord_def &operator /= (int div) - { - x /= div; - y /= div; - return (*this); - } - - const coord_def &operator *= (int mul) - { - x *= mul; - y *= mul; - return (*this); - } - - coord_def operator + (const coord_def &other) const - { - coord_def copy = *this; - return (copy += other); - } - - coord_def operator + (int other) const - { - coord_def copy = *this; - return (copy += other); - } - - coord_def operator - (const coord_def &other) const - { - coord_def copy = *this; - return (copy -= other); - } - - coord_def operator - (int other) const - { - coord_def copy = *this; - return (copy -= other); - } - - coord_def operator / (int div) const - { - coord_def copy = *this; - return (copy /= div); - } - - coord_def operator * (int mul) const - { - coord_def copy = *this; - return (copy *= mul); - } - - int abs() const - { - return (x * x + y * y); - } - - int rdist() const - { - return (std::max(std::abs(x), std::abs(y))); - } - - bool origin() const - { - return (!x && !y); - } + coord_def position; }; + typedef bool (*coord_predicate)(const coord_def &c); struct dice_def @@ -389,8 +395,7 @@ struct dice_def struct run_check_dir { dungeon_feature_type grid; - int dx; - int dy; + coord_def delta; }; @@ -415,8 +420,7 @@ struct item_def unsigned long flags; // item status flags short quantity; // number of items - short x; // x-location; for inventory items = -1 - short y; // y-location; for inventory items = -1 + coord_def pos; // for inventory items == (-1, -1) short link; // link to next item; for inventory items = slot short slot; // Inventory letter @@ -430,7 +434,7 @@ struct item_def public: item_def() : base_type(OBJ_UNASSIGNED), sub_type(0), plus(0), plus2(0), special(0L), colour(0), flags(0L), quantity(0), - x(0), y(0), link(NON_ITEM), slot(0), orig_place(0), + pos(), link(NON_ITEM), slot(0), orig_place(0), orig_monnum(0), inscription() { } @@ -471,7 +475,7 @@ public: int runmode; int mp; int hp; - int x, y; + coord_def pos; FixedVector run_check; // array of grids to check @@ -594,8 +598,7 @@ public: char max_level; - int x_pos; - int y_pos; + coord_def youpos; coord_def prev_move; @@ -788,9 +791,7 @@ public: void init(); - // Low-level move the player to (x, y). Use these functions instead of - // changing x_pos and y_pos directly. - void moveto(int x, int y); + // Low-level move the player. Use this instead of changing pos directly. void moveto(const coord_def &c); void reset_prev_move(); @@ -826,7 +827,6 @@ public: god_type deity() const; bool alive() const; - coord_def pos() const; bool swimming() const; bool submerged() const; bool floundering() const; @@ -1041,10 +1041,8 @@ public: int ev; int speed; int speed_increment; - unsigned char x; - unsigned char y; - unsigned char target_x; - unsigned char target_y; + + coord_def target; coord_def patrol_point; montravel_target_type travel_target; std::vector travel_path; @@ -1096,6 +1094,8 @@ public: bool has_action_energy() const; void check_redraw(const coord_def &oldpos) const; void apply_location_effects(); + + void moveto(const coord_def& c); bool move_to_pos(const coord_def &newpos); kill_category kill_alignment() const; @@ -1152,8 +1152,6 @@ public: int get_experience_level() const; god_type deity() const; bool alive() const; - coord_def pos() const; - coord_def target_pos() const; bool swimming() const; bool submerged() const; bool can_drown() const; @@ -1325,8 +1323,7 @@ private: struct cloud_struct { - int x; - int y; + coord_def pos; cloud_type type; int decay; unsigned char spread_rate; @@ -1339,28 +1336,22 @@ struct cloud_struct static kill_category killer_to_whose(killer_type killer); static killer_type whose_to_killer(kill_category whose); - coord_def pos() const { return coord_def(x,y); } }; struct shop_struct { - unsigned char x; - unsigned char y; + coord_def pos; unsigned char greed; shop_type type; unsigned char level; FixedVector keeper_name; - coord_def pos() const { return coord_def(x,y); } }; struct trap_struct { - unsigned char x; - unsigned char y; + coord_def pos; trap_type type; - - coord_def pos() const { return coord_def(x,y); } }; struct map_cell diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index a82fc65208..183ab171a5 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -1052,7 +1052,7 @@ static void _do_lost_items(level_area_type old_level_type) continue; // Item is in player intentory, so it's not lost. - if (item.x == -1 && item.y == -1) + if (item.pos.x == -1 && item.pos.y == -1) continue; item_was_lost(item); @@ -1216,7 +1216,7 @@ bool load( dungeon_feature_type stair_taken, load_mode_type load_mode, if (you.level_type != LEVEL_ABYSS) _place_player_on_stair(old_branch, stair_taken); else - you.moveto(45, 35); + you.moveto(coord_def(45, 35)); // FIXME: should be abyss_center } crawl_view.set_player_at(you.pos(), load_mode != LOAD_VISITOR); diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index 3d05ec4bf1..513a09685e 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -143,7 +143,7 @@ const bool InvEntry::is_item_art() const const bool InvEntry::is_item_equipped() const { - if (item->link == -1 || item->x != -1 || item->y != -1) + if (item->link == -1 || item->pos.x != -1 || item->pos.y != -1) return(false); for (int i = 0; i < NUM_EQUIP; i++) @@ -695,7 +695,7 @@ unsigned char InvMenu::getkey() const bool in_inventory( const item_def &i ) { - return i.x == -1 && i.y == -1; + return i.pos.x == -1 && i.pos.y == -1; } unsigned char get_invent( int invent_type ) diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc index 6d085b389e..6cb1db63e2 100644 --- a/crawl-ref/source/it_use3.cc +++ b/crawl-ref/source/it_use3.cc @@ -268,20 +268,21 @@ static bool _reaching_weapon_attack(const item_def& wpn) return (false); } - const int x_distance = abs(beam.tx - you.x_pos); - const int y_distance = abs(beam.ty - you.y_pos); + const coord_def delta = beam.target - you.pos(); + const int x_distance = abs(delta.x); + const int y_distance = abs(delta.y); if (x_distance > 2 || y_distance > 2) { mpr("Your weapon cannot reach that far!"); return (false); } - else if (!see_grid_no_trans(beam.tx, beam.ty)) + else if (!see_grid_no_trans(beam.target)) { mpr("There's a wall in the way."); return (false); } - else if (mgrd[beam.tx][beam.ty] == NON_MONSTER) + else if (mgrd(beam.target) == NON_MONSTER) { // Must return true, otherwise you get a free discovery // of invisible monsters. Maybe we shouldn't do practice @@ -298,13 +299,13 @@ static bool _reaching_weapon_attack(const item_def& wpn) // If we're attacking more than a space away... if (x_distance > 1 || y_distance > 1) { - const int x_middle = MAX(beam.tx, you.x_pos) - (x_distance / 2); - const int y_middle = MAX(beam.ty, you.y_pos) - (y_distance / 2); + const int x_middle = MAX(beam.target.x, you.pos().x) - (x_distance / 2); + const int y_middle = MAX(beam.target.y, you.pos().y) - (y_distance / 2); bool success = false; // If either the x or the y is the same, we should check for // a monster: - if ((beam.tx == you.x_pos || beam.ty == you.y_pos) + if ((beam.target.x == you.pos().x || beam.target.y == you.pos().y) && mgrd[x_middle][y_middle] != NON_MONSTER) { const int skill = weapon_skill( wpn.base_type, wpn.sub_type ); @@ -312,7 +313,7 @@ static bool _reaching_weapon_attack(const item_def& wpn) if (x_chance_in_y(5 + (3 * skill), 40)) { mpr("You reach to attack!"); - success = you_attack(mgrd[beam.tx][beam.ty], false); + success = you_attack(mgrd(beam.target), false); } else { @@ -323,22 +324,22 @@ static bool _reaching_weapon_attack(const item_def& wpn) else { mpr("You reach to attack!"); - success = you_attack(mgrd[beam.tx][beam.ty], false); + success = you_attack(mgrd(beam.target), false); } if (success) { - int mid = mgrd[beam.tx][beam.ty]; + int mid = mgrd(beam.target); if (mid != NON_MONSTER) { - monsters *mon = &menv[mgrd[beam.tx][beam.ty]]; + monsters *mon = &menv[mgrd(beam.target)]; if (mons_is_mimic( mon->type )) mimic_alert(mon); } } } else - you_attack(mgrd[beam.tx][beam.ty], false); + you_attack(mgrd(beam.target), false); return (true); } @@ -800,10 +801,8 @@ static bool disc_of_storms(void) (temp_rand > 0) ? ZAP_ELECTRICITY : ZAP_ORB_OF_ELECTRICITY); - beam.source_x = you.x_pos; - beam.source_y = you.y_pos; - beam.target_x = you.x_pos + random2(13) - 6; - beam.target_y = you.y_pos + random2(13) - 6; + beam.source = you.pos(); + beam.target = you.pos() + coord_def(random2(13)-6, random2(13)-6); // Non-controlleable, so no player tracer. zapping( which_zap, 30 + you.skills[SK_EVOCATIONS] * 2, beam ); @@ -846,20 +845,19 @@ void tome_of_power(int slot) { mpr("A cloud of weird smoke pours from the book's pages!"); big_cloud( random_smoke_type(), KC_YOU, - you.x_pos, you.y_pos, 20, 10 + random2(8) ); + you.pos(), 20, 10 + random2(8) ); xom_is_stimulated(16); } else if (x_chance_in_y(2, 43)) { mpr("A cloud of choking fumes pours from the book's pages!"); - big_cloud(CLOUD_POISON, KC_YOU, - you.x_pos, you.y_pos, 20, 7 + random2(5)); + big_cloud(CLOUD_POISON, KC_YOU, you.pos(), 20, 7 + random2(5)); xom_is_stimulated(64); } else if (x_chance_in_y(2, 41)) { mpr("A cloud of freezing gas pours from the book's pages!"); - big_cloud(CLOUD_COLD, KC_YOU, you.x_pos, you.y_pos, 20, 8 + random2(5)); + big_cloud(CLOUD_COLD, KC_YOU, you.pos(), 20, 8 + random2(5)); xom_is_stimulated(64); } else if (x_chance_in_y(3, 39)) @@ -875,8 +873,7 @@ void tome_of_power(int slot) beam.damage = dice_def( 3, 15 ); // unsure about this // BEAM_EXPLOSION instead? [dlb] beam.flavour = BEAM_FIRE; - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.name = "fiery explosion"; beam.colour = RED; // your explosion, (not someone else's explosion) diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 31955957f9..f92f31a01c 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -1843,8 +1843,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus, pbolt.name = item.name(DESC_PLAIN, false, false, false); pbolt.thrower = KILL_YOU_MISSILE; - pbolt.source_x = you.x_pos; - pbolt.source_y = you.y_pos; + pbolt.source = you.pos(); pbolt.colour = item.colour; pbolt.flavour = BEAM_MISSILE; pbolt.aux_source.clear(); @@ -1942,8 +1941,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus, if (you.duration[DUR_CONF]) { thr.isTarget = true; - thr.tx = you.x_pos + random2(13) - 6; - thr.ty = you.y_pos + random2(13) - 6; + thr.target = you.pos() + coord_def(random2(13)-6, random2(13)-6); } // Even though direction is allowed, we're throwing so we @@ -2581,9 +2579,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(), &item) != 0); + hit = (affect(pbolt, pbolt.target, &item) != 0); if (acc_bonus != DEBUG_COOKIE) - beam_drop_object(pbolt, &item, pbolt.target()); + beam_drop_object(pbolt, &item, pbolt.target); } else { @@ -2594,7 +2592,7 @@ 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(), true)) + if (did_return && thrown_object_destroyed(&item, pbolt.target, true)) did_return = false; } @@ -3492,19 +3490,17 @@ void zap_wand( int slot ) if (you.duration[DUR_CONF]) { - zap_wand.tx = you.x_pos + random2(13) - 6; - zap_wand.ty = you.y_pos + random2(13) - 6; + zap_wand.target = you.pos() + coord_def(random2(13)-6, random2(13)-6); } if (wand.sub_type == WAND_RANDOM_EFFECTS) beam.effect_known = false; zap_type type_zapped = static_cast(wand.zap()); - beam.source_x = you.x_pos; - beam.source_y = you.y_pos; + beam.source = you.pos(); beam.set_target(zap_wand); - beam.aimed_at_feet = (beam.target() == you.pos()); + beam.aimed_at_feet = (beam.target == you.pos()); // Check whether we may hit friends, use "safe" values for random effects // and unknown wands (highest possible range, and unresistable beam @@ -3802,7 +3798,7 @@ bool _drink_fountain() // Turn fountain into a normal fountain without any message // but the glyph colour gives it away (lightblue vs. blue). grd(you.pos()) = DNGN_FOUNTAIN_BLUE; - set_terrain_changed(you.x_pos, you.y_pos); + set_terrain_changed(you.pos()); } } @@ -3813,7 +3809,7 @@ bool _drink_fountain() grd(you.pos()) = static_cast(feat + DNGN_DRY_FOUNTAIN_BLUE - DNGN_FOUNTAIN_BLUE); - set_terrain_changed(you.x_pos, you.y_pos); + set_terrain_changed(you.pos()); crawl_state.cancel_cmd_repeat(); } @@ -3851,8 +3847,7 @@ static bool affix_weapon_enchantment() beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.damage = dice_def( 3, 10 ); beam.flavour = BEAM_FIRE; - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.colour = RED; beam.thrower = KILL_YOU; beam.ex_size = 2; @@ -4378,8 +4373,7 @@ void read_scroll( int slot ) case SCR_FOG: mpr("The scroll dissolves into smoke."); - big_cloud( random_smoke_type(), KC_YOU, you.x_pos, you.y_pos, - 50, 8 + random2(8)); + big_cloud(random_smoke_type(), KC_YOU, you.pos(), 50, 8 + random2(8)); break; case SCR_MAGIC_MAPPING: @@ -4415,8 +4409,7 @@ void read_scroll( int slot ) beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.damage = dice_def( 3, 10 ); - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.name = "fiery explosion"; beam.colour = RED; // your explosion, (not someone else's explosion) diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index daff922b71..c0cca7b5dd 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -196,7 +196,7 @@ std::string item_def::name(description_level_type descrip, buff << auxname; bool equipped = false; - if (descrip == DESC_INVENTORY_EQUIP && this->x == -1 && this->y == -1) + if (descrip == DESC_INVENTORY_EQUIP && in_inventory(*this)) { ASSERT( this->link != -1 ); diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index 2327307d4f..918add8ee3 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -26,6 +26,7 @@ #include "decks.h" #include "food.h" +#include "invent.h" #include "items.h" #include "itemprop.h" #include "it_use2.h" @@ -485,7 +486,7 @@ void do_curse_item( item_def &item, bool quiet ) // Xom is amused by the player's items being cursed, especially // if they're worn/equipped. - if (item.x == -1 && item.y == -1) + if (in_inventory(item)) { int amusement = 64; @@ -519,7 +520,7 @@ void do_curse_item( item_def &item, bool quiet ) void do_uncurse_item( item_def &item ) { - if (item.x == -1 && item.y == -1 && you.equip[EQ_WEAPON] == item.link) + if (in_inventory(item) && you.equip[EQ_WEAPON] == item.link) { // Redraw the weapon. you.wield_change = true; diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 4d0d619b24..7f735bb83a 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -93,7 +93,7 @@ static bool will_autoinscribe = false; // Used to be called "unlink_items", but all it really does is make // sure item coordinates are correct to the stack they're in. -- bwr -void fix_item_coordinates(void) +void fix_item_coordinates() { // Nails all items to the ground (i.e. sets x,y). for (int x = 0; x < GXM; x++) @@ -103,8 +103,8 @@ void fix_item_coordinates(void) while (i != NON_ITEM) { - mitm[i].x = x; - mitm[i].y = y; + mitm[i].pos.x = x; + mitm[i].pos.y = y; i = mitm[i].link; } } @@ -121,7 +121,7 @@ void link_items(void) for (int i = 0; i < MAX_ITEMS; i++) { - if (!is_valid_item(mitm[i]) || (mitm[i].x == 0 && mitm[i].y == 0)) + if (!is_valid_item(mitm[i]) || mitm[i].pos.origin()) { // Item is not assigned, or is monster item. Ignore. mitm[i].link = NON_ITEM; @@ -129,8 +129,8 @@ void link_items(void) } // link to top - mitm[i].link = igrd[ mitm[i].x ][ mitm[i].y ]; - igrd[ mitm[i].x ][ mitm[i].y ] = i; + mitm[i].link = igrd( mitm[i].pos ); + igrd( mitm[i].pos ) = i; } } @@ -174,48 +174,37 @@ static int _cull_items(void) // 2. Avoid shops by avoiding (0,5..9). // 3. Avoid monster inventory by iterating over the dungeon grid. - for (int x = 5; x < GXM; x++) - for (int y = 5; y < GYM; y++) - { - // 1. Not near player! - if (x > you.x_pos - 9 && x < you.x_pos + 9 - && y > you.y_pos - 9 && y < you.y_pos + 9) - { - continue; - } - - int next; + for ( rectangle_iterator ri(1); ri; ++ri ) + { + if ( grid_distance( you.pos(), *ri ) <= 9 ) + continue; - // Iterate through the grids list of items. - for (int item = igrd[x][y]; item != NON_ITEM; item = next) + for ( stack_iterator si(*ri); si; ++si ) + { + if (_item_ok_to_clean(si->index()) && x_chance_in_y(15, 100)) { - next = mitm[item].link; // in case we can't get it later. - - if (_item_ok_to_clean(item) && x_chance_in_y(15, 100)) + if (is_fixed_artefact(*si)) { - const item_def& obj(mitm[item]); - if (is_fixed_artefact(obj)) - { - // 7. Move uniques to abyss. - set_unique_item_status( OBJ_WEAPONS, obj.special, - UNIQ_LOST_IN_ABYSS ); - } - else if (is_unrandom_artefact(obj)) - { - // 9. Unmark unrandart. - const int z = find_unrandart_index(obj); - if (z != -1) - set_unrandart_exist(z, false); - } - - // POOF! - destroy_item( item ); - if (first_cleaned == NON_ITEM) - first_cleaned = item; + // 7. Move uniques to abyss. + set_unique_item_status( OBJ_WEAPONS, si->special, + UNIQ_LOST_IN_ABYSS ); } - } + else if (is_unrandom_artefact(*si)) + { + // 9. Unmark unrandart. + const int z = find_unrandart_index(*si); + if (z != -1) + set_unrandart_exist(z, false); + } + + if (first_cleaned == NON_ITEM) + first_cleaned = si->index(); - } + // POOF! + destroy_item( si->index() ); + } + } + } return (first_cleaned); } @@ -368,7 +357,7 @@ void unlink_item( int dest ) if (dest == NON_ITEM || !is_valid_item( mitm[dest] )) return; - if (mitm[dest].x == 0 && mitm[dest].y == 0) + if (mitm[dest].pos.origin()) { // (0,0) is where the monster items are (and they're unlinked by igrd), // although it also contains items that are not linked in yet. @@ -387,8 +376,7 @@ void unlink_item( int dest ) { monster->inv[cy] = NON_ITEM; - mitm[dest].x = 0; - mitm[dest].y = 0; + mitm[dest].pos.reset(); mitm[dest].link = NON_ITEM; // This causes problems when changing levels. -- bwr @@ -410,29 +398,25 @@ void unlink_item( int dest ) // the item should be linked. // First check the top: - if (igrd[ mitm[dest].x ][ mitm[dest].y ] == dest) + if (igrd(mitm[dest].pos) == dest) { // link igrd to the second item - igrd[ mitm[dest].x ][ mitm[dest].y ] = mitm[dest].link; + igrd(mitm[dest].pos) = mitm[dest].link; - mitm[dest].x = 0; - mitm[dest].y = 0; + mitm[dest].pos.reset(); mitm[dest].link = NON_ITEM; return; } // Okay, item is buried, find item that's on top of it. - for (int c = igrd[ mitm[dest].x ][ mitm[dest].y ]; c != NON_ITEM; - c = mitm[c].link) + for (stack_iterator si(mitm[dest].pos); si; ++si) { // Find item linking to dest item. - if (is_valid_item( mitm[c] ) && mitm[c].link == dest) + if (is_valid_item(*si) && si->link == dest) { // unlink dest - mitm[c].link = mitm[dest].link; - - mitm[dest].x = 0; - mitm[dest].y = 0; + si->link = mitm[dest].link; + mitm[dest].pos.reset(); mitm[dest].link = NON_ITEM; return; } @@ -442,7 +426,8 @@ void unlink_item( int dest ) #if DEBUG // Okay, the sane ways are gone... let's warn the player: mprf(MSGCH_ERROR, "BUG WARNING: Problems unlinking item '%s', (%d, %d)!!!", - mitm[dest].name(DESC_PLAIN).c_str(), mitm[dest].x, mitm[dest].y ); + mitm[dest].name(DESC_PLAIN).c_str(), + mitm[dest].pos.x, mitm[dest].pos.y ); // Okay, first we scan all items to see if we have something // linked to this item. We're not going to return if we find @@ -454,9 +439,8 @@ void unlink_item( int dest ) // Clean the relevant parts of the object. mitm[dest].base_type = OBJ_UNASSIGNED; mitm[dest].quantity = 0; - mitm[dest].x = 0; - mitm[dest].y = 0; mitm[dest].link = NON_ITEM; + mitm[dest].pos.reset(); mitm[dest].props.clear(); // Look through all items for links to this item. @@ -565,11 +549,8 @@ static void _handle_gone_item(const item_def &item) you.attribute[ATTR_DEMONIC_RUNES] -= item.quantity; } - if (player_in_branch(BRANCH_HALL_OF_ZOT) - && item.x != -1 && item.y != -1) - { + if (player_in_branch(BRANCH_HALL_OF_ZOT) && !in_inventory(item)) you.attribute[ATTR_RUNES_IN_ZOT] -= item.quantity; - } } } @@ -724,7 +705,7 @@ static int _item_name_specialness(const item_def& item) void item_check(bool verbose) { describe_floor(); - origin_set(you.x_pos, you.y_pos); + origin_set(you.pos()); std::ostream& strm = msg::streams(MSGCH_FLOOR_ITEMS); @@ -912,7 +893,7 @@ void origin_set_inventory(void (*oset)(item_def &item)) oset(you.inv[i]); } -static int _first_corpse_monnum(int x, int y) +static int _first_corpse_monnum(const coord_def& where) { // We could look for a corpse on this square and assume that the // items belonged to it, but that is unsatisfactory. @@ -963,11 +944,11 @@ static void _check_note_item(item_def &item) } } -void origin_set(int x, int y) +void origin_set(const coord_def& where) { - int monnum = _first_corpse_monnum(x, y); + int monnum = _first_corpse_monnum(where); unsigned short pplace = get_packed_place(); - for (stack_iterator si(coord_def(x,y)); si; ++si) + for (stack_iterator si(where); si; ++si) { if (origin_known( *si )) continue; @@ -982,17 +963,17 @@ void origin_set(int x, int y) } } -void origin_set_monstercorpse(item_def &item, int x, int y) +void origin_set_monstercorpse(item_def &item, const coord_def& where) { - item.orig_monnum = _first_corpse_monnum(x, y); + item.orig_monnum = _first_corpse_monnum(where); } -static void _origin_freeze(item_def &item, int x, int y) +static void _origin_freeze(item_def &item, const coord_def& where) { if (!origin_known(item)) { - if (!item.orig_monnum && x != -1 && y != -1) - origin_set_monstercorpse(item, x, y); + if (!item.orig_monnum && where.x != -1 && where.y != -1) + origin_set_monstercorpse(item, where); item.orig_place = get_packed_place(); _check_note_item(item); @@ -1549,16 +1530,15 @@ int move_item_to_player( int obj, int quant_got, bool quiet ) return (-1); } - coord_def pos(mitm[obj].x, mitm[obj].y); + coord_def p = mitm[obj].pos; dungeon_events.fire_position_event( - dgn_event(DET_ITEM_PICKUP, pos, 0, obj, -1), pos); + dgn_event(DET_ITEM_PICKUP, p, 0, obj, -1), p); item_def &item = you.inv[freeslot]; // Copy item. item = mitm[obj]; - item.x = -1; - item.y = -1; item.link = freeslot; + item.pos.set(-1, -1); // Remove "dropped by ally" flag. item.flags &= ~(ISFLAG_DROPPED_BY_ALLY); @@ -1567,7 +1547,7 @@ int move_item_to_player( int obj, int quant_got, bool quiet ) _autoinscribe_item( item ); - _origin_freeze(item, you.x_pos, you.y_pos); + _origin_freeze(item, you.pos()); _check_note_item(item); item.quantity = quant_got; @@ -1687,8 +1667,7 @@ bool move_item_to_grid( int *const obj, const coord_def& p ) unlink_item( ob ); // Move item to coord. - item.x = p.x; - item.y = p.y; + item.pos = p; // Link item to top of list. item.link = igrd(p); @@ -1715,8 +1694,7 @@ void move_item_stack_to_grid( const coord_def& from, const coord_def& to ) // Tell all items in stack what the new coordinate is. for (stack_iterator si(from); si; ++si) { - si->x = to.x; - si->y = to.y; + si->pos = to; // Link last of the stack to the top of the old stack. if (si->link == NON_ITEM && igrd(to) != NON_ITEM) @@ -1777,8 +1755,7 @@ bool copy_item_to_grid( const item_def &item, const coord_def& p, // Set quantity, and set the item as unlinked. new_item.quantity = quant_drop; - new_item.x = 0; - new_item.y = 0; + new_item.pos.reset(); new_item.link = NON_ITEM; if (mark_dropped) @@ -2131,8 +2108,7 @@ static void _autoinscribe_item( item_def& item ) // then the user explictly removed it because they // don't want to autopickup it again. std::string str = Options.autoinscriptions[i].second; - if ((item.flags & ISFLAG_DROPPED) - && (item.x != -1 || item.y != -1)) + if ((item.flags & ISFLAG_DROPPED) && !in_inventory(item)) { str = replace_all(str, "=g", ""); } @@ -2469,7 +2445,7 @@ item_def find_item_type(object_class_type base_type, std::string name) bool item_is_equipped(const item_def &item) { - if (item.x != -1 || item.y != -1) + if (!in_inventory(item)) return (false); for (int i = 0; i < NUM_EQUIP; i++) diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h index 831e3e4430..1693a16d08 100644 --- a/crawl-ref/source/items.h +++ b/crawl-ref/source/items.h @@ -123,7 +123,7 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer = false ); int get_equip_slot(const item_def *item); -void origin_set(int x, int y); +void origin_set(const coord_def& where); void origin_set_monster(item_def &item, const monsters *monster); bool origin_known(const item_def &item); bool origin_describable(const item_def &item); diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc index beab44ba13..e3b6459268 100644 --- a/crawl-ref/source/luadgn.cc +++ b/crawl-ref/source/luadgn.cc @@ -1571,7 +1571,7 @@ static int lua_cloud_pow_min; static int lua_cloud_pow_max; static int lua_cloud_pow_rolls; -static int make_a_lua_cloud(int x, int y, int garbage, int spread_rate, +static int make_a_lua_cloud(coord_def where, int garbage, int spread_rate, cloud_type ctype, kill_category whose, killer_type killer) { @@ -1580,8 +1580,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, coord_def(x, y), pow, whose, killer, spread_rate ); - + place_cloud( ctype, where, pow, whose, killer, spread_rate ); return 1; } @@ -1664,7 +1663,7 @@ static int dgn_apply_area_cloud(lua_State *ls) return (0); } - apply_area_cloud(make_a_lua_cloud, x, y, 0, size, + apply_area_cloud(make_a_lua_cloud, coord_def(x, y), 0, size, ctype, kc, cloud_struct::whose_to_killer(kc), spread_rate); @@ -1767,10 +1766,10 @@ static int dgn_octa_room(lua_State *ls) } spec_room sr; - sr.x1 = x1; - sr.x2 = x2; - sr.y1 = y1; - sr.y2 = y2; + sr.tl.x = x1; + sr.br.x = x2; + sr.tl.y = y1; + sr.br.y = y2; octa_room(sr, oblique, fill); @@ -2286,9 +2285,9 @@ static const struct luaL_reg file_lib[] = LUARET1(you_can_hear_pos, boolean, player_can_hear(coord_def(luaL_checkint(ls,1), luaL_checkint(ls, 2)))) -LUARET1(you_x_pos, number, you.x_pos) -LUARET1(you_y_pos, number, you.y_pos) -LUARET2(you_pos, number, you.x_pos, you.y_pos) +LUARET1(you_x_pos, number, you.pos().x) +LUARET1(you_y_pos, number, you.pos().y) +LUARET2(you_pos, number, you.pos().x, you.pos().y) static const struct luaL_reg you_lib[] = { diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc index c4b171508d..3351714bfa 100644 --- a/crawl-ref/source/makeitem.cc +++ b/crawl-ref/source/makeitem.cc @@ -2840,8 +2840,7 @@ int items( int allow_uniques, // not just true-false, if (dont_place) { - item.x = 0; - item.y = 0; + item.pos.reset(); item.link = NON_ITEM; } else @@ -2923,8 +2922,7 @@ static void _give_monster_item(monsters *mon, int thing, mon->name(DESC_PLAIN).c_str()); #endif - mthing.x = 0; - mthing.y = 0; + mthing.pos.reset(); mthing.link = NON_ITEM; unset_ident_flags(mthing, ISFLAG_IDENT_MASK); @@ -3647,8 +3645,7 @@ static item_make_species_type _give_weapon(monsters *mon, int level, if (item.base_type == OBJ_UNASSIGNED) return (item_race); - item.x = 0; - item.y = 0; + item.pos.reset(); item.link = NON_ITEM; if (!force_item && mons_is_unique( mon->type )) diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 0c105aa9b3..fe8243a43c 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -307,8 +307,8 @@ void maybe_coagulate_blood_potions_floor(int obj) ASSERT(blood.sub_type == POT_BLOOD); // Now that coagulating is necessary, check square for !coagulated blood. - ASSERT(blood.x >= 0 && blood.y >= 0); - for (int o = igrd[blood.x][blood.y]; o != NON_ITEM; o = mitm[o].link) + ASSERT(blood.pos.x >= 0 && blood.pos.y >= 0); + for (int o = igrd[blood.pos.x][blood.pos.y]; o != NON_ITEM; o = mitm[o].link) { if (mitm[o].base_type == OBJ_POTIONS && mitm[o].sub_type == POT_BLOOD_COAGULATED) @@ -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, coord_def(blood.x, blood.y) ); + move_item_to_grid( &o, blood.pos ); dec_mitm_item_quantity(obj, rot_count + coag_count); ASSERT(timer.size() == blood.quantity); @@ -617,13 +617,12 @@ bool maybe_coagulate_blood_potions_inv(item_def &blood) item.base_type = OBJ_POTIONS; item.sub_type = POT_BLOOD_COAGULATED; item.quantity = coag_count; - item.x = -1; - item.y = -1; item.plus = 0; item.plus2 = 0; item.special = 0; item.flags = 0; item.inscription = ""; + item.pos.set(-1, -1); item_colour(item); CrawlHashTable &props_new = item.props; @@ -654,7 +653,7 @@ bool maybe_coagulate_blood_potions_inv(item_def &blood) } // No space in inventory, check floor. - int o = igrd[you.x_pos][you.y_pos]; + int o = igrd(you.pos()); while (o != NON_ITEM) { if (mitm[o].base_type == OBJ_POTIONS @@ -1023,8 +1022,6 @@ void split_potions_into_decay( int obj, int amount, bool need_msg ) item.base_type = OBJ_POTIONS; item.sub_type = POT_DECAY; item.quantity = amount; - item.x = -1; - item.y = -1; // Keep description as it was. item.plus = potion.plus; item.plus2 = 0; @@ -1032,6 +1029,7 @@ void split_potions_into_decay( int obj, int amount, bool need_msg ) item.flags = 0; item.colour = potion.colour; item.inscription = ""; + item.pos.set(-1, -1); you.inv[obj].quantity -= amount; return; @@ -1039,22 +1037,19 @@ void split_potions_into_decay( int obj, int amount, bool need_msg ) // Okay, inventory is full. // Check whether we can merge with an existing stack on the floor. - int o = igrd[you.x_pos][you.y_pos]; - while (o != NON_ITEM) + for ( stack_iterator si(you.pos()); si; ++si ) { - if (mitm[o].base_type == OBJ_POTIONS - && mitm[o].sub_type == POT_DECAY) + if (si->base_type == OBJ_POTIONS && si->sub_type == POT_DECAY) { dec_inv_item_quantity(obj, amount); - inc_mitm_item_quantity(o, amount); + inc_mitm_item_quantity(si->index(), amount); return; } - o = mitm[o].link; } // Only bother creating a distinct stack of potions // if it won't get destroyed right away. - if (!grid_destroys_items(grd[you.x_pos][you.y_pos])) + if (!grid_destroys_items(grd(you.pos()))) { item_def potion2; potion2.base_type = OBJ_POTIONS; @@ -1236,8 +1231,6 @@ void generate_random_blood_spatter_on_level() void search_around( bool only_adjacent ) { - int i; - // Traps and doors stepdown skill: // skill/(2x-1) for squares at distance x int max_dist = (you.skills[SK_TRAPS_DOORS] + 1) / 2; @@ -1248,58 +1241,54 @@ void search_around( bool only_adjacent ) if ( max_dist < 1 ) max_dist = 1; - for (int srx = you.x_pos - max_dist; srx <= you.x_pos + max_dist; ++srx) - for (int sry = you.y_pos - max_dist; sry <= you.y_pos + max_dist; ++sry) + for (radius_iterator ri(you.pos(), max_dist); ri; ++ri ) + { + // Must have LOS, with no translucent walls in the way. + if (see_grid_no_trans(*ri)) { - // Must have LOS, with no translucent walls in the way. - if (see_grid_no_trans(srx, sry)) - { - // Maybe we want distance() instead of grid_distance()? - int dist = grid_distance(srx, sry, you.x_pos, you.y_pos); + // Maybe we want distance() instead of grid_distance()? + int dist = grid_distance(*ri, you.pos()); - // Don't exclude own square; may be levitating. - // XXX: Currently, levitating over a trap will always detect it. - if (dist == 0) - ++dist; + // Don't exclude own square; may be levitating. + // XXX: Currently, levitating over a trap will always detect it. + if (dist == 0) + ++dist; - // Making this harsher by removing the old +1... - int effective = you.skills[SK_TRAPS_DOORS] / (2*dist - 1); + // Making this harsher by removing the old +1... + int effective = you.skills[SK_TRAPS_DOORS] / (2*dist - 1); - if (grd[srx][sry] == DNGN_SECRET_DOOR - && x_chance_in_y(effective + 1, 17)) + if (grd(*ri) == DNGN_SECRET_DOOR && x_chance_in_y(effective+1, 17)) + { + mpr("You found a secret door!"); + reveal_secret_door(*ri); + exercise(SK_TRAPS_DOORS, (coinflip() ? 2 : 1)); + } + else if (grd(*ri) == DNGN_UNDISCOVERED_TRAP + && x_chance_in_y(effective + 1, 17)) + { + const int i = trap_at_xy(*ri); + + if (i != -1) { - mpr("You found a secret door!"); - reveal_secret_door(srx, sry); + grd(*ri) = trap_category(env.trap[i].type); + mpr("You found a trap!"); + learned_something_new(TUT_SEEN_TRAP, *ri); + exercise(SK_TRAPS_DOORS, (coinflip() ? 2 : 1)); } - else if (grd[srx][sry] == DNGN_UNDISCOVERED_TRAP - && x_chance_in_y(effective + 1, 17)) + else { - i = trap_at_xy(coord_def(srx, sry)); - - if (i != -1) - { - grd[srx][sry] = trap_category(env.trap[i].type); - mpr("You found a trap!"); - learned_something_new(TUT_SEEN_TRAP, srx, sry); - - exercise(SK_TRAPS_DOORS, (coinflip() ? 2 : 1)); - } - else - { - // Maybe we shouldn't kill the trap for debugging - // purposes - oh well. - grd[srx][sry] = DNGN_FLOOR; + // Maybe we shouldn't kill the trap for debugging + // purposes - oh well. + grd(*ri) = DNGN_FLOOR; #if DEBUG_DIAGNOSTICS - mpr("You found a buggy trap! It vanishes!", - MSGCH_DIAGNOSTICS); + mpr("You found a buggy trap! It vanishes!", + MSGCH_DIAGNOSTICS); #endif - } } } } - - return; + } } void curare_hits_player(int agent, int degree) @@ -1435,8 +1424,7 @@ static int runes_in_pack() bool check_annotation_exclusion_warning() { - coord_def pos(you.x_pos, you.y_pos); - level_id next_level_id = level_id::get_next_level_id(pos); + level_id next_level_id = level_id::get_next_level_id(you.pos()); crawl_state.level_annotation_shown = false; bool might_be_dangerous = false; @@ -1450,7 +1438,7 @@ bool check_annotation_exclusion_warning() might_be_dangerous = true; crawl_state.level_annotation_shown = true; } - else if (is_exclude_root(pos)) + else if (is_exclude_root(you.pos())) { mpr("This staircase is marked as excluded!", MSGCH_WARN); might_be_dangerous = true; @@ -1471,7 +1459,7 @@ void up_stairs(dungeon_feature_type force_stair, entry_cause_type entry_cause) { dungeon_feature_type stair_find = (force_stair ? force_stair - : grd[you.x_pos][you.y_pos]); + : grd(you.pos())); const branch_type old_where = you.where_are_you; const level_area_type old_level_type = you.level_type; @@ -1619,7 +1607,7 @@ void up_stairs(dungeon_feature_type force_stair, branches[you.where_are_you].longname); } - int stair_x = you.x_pos, stair_y = you.y_pos; + const coord_def stair_pos = you.pos(); #ifdef USE_TILE const bool newlevel = @@ -1677,9 +1665,8 @@ void up_stairs(dungeon_feature_type force_stair, // First we update the old level's stair. level_pos lp; - lp.id = new_level_id; - lp.pos.x = you.x_pos; - lp.pos.y = you.y_pos; + lp.id = new_level_id; + lp.pos = you.pos(); bool guess = false; // Ugly hack warning: @@ -1698,7 +1685,7 @@ void up_stairs(dungeon_feature_type force_stair, } else { - old_level_info.update_stair(stair_x, stair_y, lp, guess); + old_level_info.update_stair(stair_pos, lp, guess); } // We *guess* that going up a staircase lands us on a downstair, @@ -1711,9 +1698,8 @@ void up_stairs(dungeon_feature_type force_stair, // downstairs will land you on the same upstairs you took to // begin with (not necessarily true). lp.id = old_level_id; - lp.pos.x = stair_x; - lp.pos.y = stair_y; - new_level_info.update_stair(you.x_pos, you.y_pos, lp, true); + lp.pos = stair_pos; + new_level_info.update_stair(you.pos(), lp, true); } } } @@ -1858,7 +1844,7 @@ void down_stairs( int old_level, dungeon_feature_type force_stair, level_id old_level_id = level_id::current(); LevelInfo &old_level_info = travel_cache.get_level_info(old_level_id); - int stair_x = you.x_pos, stair_y = you.y_pos; + const coord_def stair_pos = you.pos(); if (collect_travel_data) old_level_info.update(); @@ -2129,7 +2115,7 @@ void down_stairs( int old_level, dungeon_feature_type force_stair, switch (you.level_type) { case LEVEL_ABYSS: - grd[you.x_pos][you.y_pos] = DNGN_FLOOR; + grd(you.pos()) = DNGN_FLOOR; init_pandemonium(); // colours only @@ -2206,19 +2192,17 @@ void down_stairs( int old_level, dungeon_feature_type force_stair, // First we update the old level's stair. level_pos lp; - lp.id = new_level_id; - lp.pos.x = you.x_pos; - lp.pos.y = you.y_pos; + lp.id = new_level_id; + lp.pos = you.pos(); - old_level_info.update_stair(stair_x, stair_y, lp); + old_level_info.update_stair(stair_pos, lp); // Then the new level's stair, assuming arbitrarily that going // upstairs will land you on the same downstairs you took to begin // with (not necessarily true). lp.id = old_level_id; - lp.pos.x = stair_x; - lp.pos.y = stair_y; - new_level_info.update_stair(you.x_pos, you.y_pos, lp, true); + lp.pos = stair_pos; + new_level_info.update_stair(you.pos(), lp, true); } } request_autopickup(); @@ -2309,7 +2293,7 @@ bool go_berserk(bool intentional) bool mons_is_safe(const struct monsters *mon, bool want_move) { - int dist = grid_distance(you.x_pos, you.y_pos, mon->x, mon->y); + int dist = grid_distance(you.pos(), mon->pos()); bool is_safe = (mons_wont_attack(mon) || mons_class_flag(mon->type, M_NO_EXP_GAIN) @@ -2318,7 +2302,7 @@ bool mons_is_safe(const struct monsters *mon, bool want_move) || you.skills[SK_STEALTH] > 27 && dist > 2 #endif // Only seen through glass walls? - || !see_grid_no_trans(mon->x, mon->y) + || !see_grid_no_trans(mon->pos()) && !mons_has_ranged_spell(mon) && !mons_has_los_ability(mon->type)); @@ -2642,15 +2626,14 @@ int speed_to_duration(int speed) return div_rand_round(100, speed); } -void reveal_secret_door(int x, int y) +void reveal_secret_door(const coord_def& p) { - ASSERT(grd[x][y] == DNGN_SECRET_DOOR); + ASSERT(grd(p) == DNGN_SECRET_DOOR); - 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; + dungeon_feature_type door = grid_secret_door_appearance(p); + grd(p) = grid_is_opaque(door) ? DNGN_CLOSED_DOOR : DNGN_OPEN_DOOR; viewwindow(true, false); - learned_something_new(TUT_SEEN_SECRET_DOOR, x, y); + learned_something_new(TUT_SEEN_SECRET_DOOR, p); } // A feeble attempt at Nethack-like completeness for cute messages. diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h index 3b82c02c6c..1837a02cc5 100644 --- a/crawl-ref/source/misc.h +++ b/crawl-ref/source/misc.h @@ -19,45 +19,14 @@ struct bolt; struct dist; struct activity_interrupt_data; -// last updated 08jan2001 {gdl} -/* *********************************************************************** - * called from: ability - decks - fight - it_use2 - spells1 - * *********************************************************************** */ bool go_berserk(bool intentional); - -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: acr - * *********************************************************************** */ void search_around( bool only_adjacent = false ); - - -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: acr - effects - spells3 - * *********************************************************************** */ void down_stairs(int old_level, dungeon_feature_type force_stair = DNGN_UNSEEN, entry_cause_type entry_cause = EC_UNKNOWN); - -// Created Sept 1, 2000 -- bwr -/* *********************************************************************** - * called from: acr misc - * *********************************************************************** */ -void merfolk_start_swimming(void); - -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: acr - misc - player - stuff - * *********************************************************************** */ -void new_level(void); - +void merfolk_start_swimming(); +void new_level(); void trackers_init_new_level(bool transit); - -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: delay - * *********************************************************************** */ void turn_corpse_into_skeleton(item_def &corpse, int time = 200); void turn_corpse_into_chunks( item_def &item ); @@ -134,7 +103,7 @@ bool scramble(void); bool interrupt_cmd_repeat( activity_interrupt_type ai, const activity_interrupt_data &at ); -void reveal_secret_door(int x, int y); +void reveal_secret_door(const coord_def& p); std::string your_hand(bool plural); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index cc156fd9e0..fa521232c7 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2302,7 +2302,7 @@ bool mons_should_fire(struct bolt &beam) if (beam.foe_count == 0) return (false); - if (is_sanctuary(you.pos()) || is_sanctuary(beam.source())) + if (is_sanctuary(you.pos()) || is_sanctuary(beam.source)) return (false); // If we either hit no friends, or monster too dumb to care. @@ -2447,7 +2447,7 @@ 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_pos())) + if (spell_harms_target(monspell) && is_sanctuary(mon->target)) return (true); } @@ -2859,8 +2859,8 @@ bool monster_senior(const monsters *m1, const monsters *m2) monsters::monsters() : type(-1), hit_points(0), max_hit_points(0), hit_dice(0), - ac(0), ev(0), speed(0), speed_increment(0), x(0), y(0), - target_x(0), target_y(0), patrol_point(0, 0), travel_target(MTRAV_NONE), + ac(0), ev(0), speed(0), speed_increment(0), + target(0,0), patrol_point(0, 0), travel_target(MTRAV_NONE), inv(NON_ITEM), spells(), attitude(ATT_HOSTILE), behaviour(BEH_WANDER), foe(MHITYOU), enchantments(), flags(0L), experience(0), number(0), colour(BLACK), foe_memory(0), shield_blocks(0), god(GOD_NO_GOD), ghost(), @@ -2908,11 +2908,11 @@ void monsters::reset() foe = MHITNOT; number = 0; - if (in_bounds(x, y)) - mgrd[x][y] = NON_MONSTER; + if (in_bounds(pos())) + mgrd(pos()) = NON_MONSTER; - x = y = 0; - patrol_point = coord_def(0, 0); + position.reset(); + patrol_point.reset(); travel_target = MTRAV_NONE; travel_path.clear(); ghost.reset(NULL); @@ -2930,10 +2930,8 @@ void monsters::init_with(const monsters &mon) ev = mon.ev; speed = mon.speed; speed_increment = mon.speed_increment; - x = mon.x; - y = mon.y; - target_x = mon.target_x; - target_y = mon.target_y; + position = mon.position; + target = mon.target; patrol_point = mon.patrol_point; travel_target = mon.travel_target; travel_path = mon.travel_path; @@ -2956,19 +2954,9 @@ void monsters::init_with(const monsters &mon) ghost.reset(NULL); } -coord_def monsters::pos() const -{ - return coord_def(x, y); -} - -coord_def monsters::target_pos() const -{ - return coord_def(target_x, target_y); -} - bool monsters::swimming() const { - const dungeon_feature_type grid = grd[x][y]; + const dungeon_feature_type grid = grd(pos()); return (grid_is_watery(grid) && mons_habitat(this) == HT_WATER); } @@ -2979,7 +2967,7 @@ bool monsters::submerged() const bool monsters::floundering() const { - const dungeon_feature_type grid = grd[x][y]; + const dungeon_feature_type grid = grd(pos()); return (grid_is_water(grid) // Can't use monster_habitable_grid because that'll return true // for non-water monsters in shallow water. @@ -4588,6 +4576,11 @@ int monsters::get_experience_level() const return (hit_dice); } +void monsters::moveto( const coord_def& c ) +{ + position = c; +} + bool monsters::fumbles_attack(bool verbose) { if (floundering() && one_chance_in(4)) @@ -4713,7 +4706,7 @@ bool monsters::backlit(bool check_haloed) const bool monsters::haloed() const { - return (inside_halo(x, y)); + return (inside_halo(pos())); } bool monsters::caught() const @@ -5071,8 +5064,7 @@ bool monsters::find_home_around(const coord_def &c, int radius) if (nvalid) { - x = place.x; - y = place.y; + moveto(place); return (true); } return (false); @@ -5092,10 +5084,9 @@ bool monsters::find_home_anywhere() int tries = 600; do { - x = random_range(6, GXM - 7); - y = random_range(6, GYM - 7); + position.set(random_range(6, GXM - 7), random_range(6, GYM - 7)); } - while ((grd[x][y] != DNGN_FLOOR || mgrd[x][y] != NON_MONSTER) + while ((grd(pos()) != DNGN_FLOOR || mgrd(pos()) != NON_MONSTER) && tries-- > 0); return (tries >= 0); @@ -5106,7 +5097,7 @@ bool monsters::find_place_to_live(bool near_player) if ((near_player && find_place_near_player()) || find_home_anywhere()) { - mgrd[x][y] = monster_index(this); + mgrd(pos()) = monster_index(this); return (true); } @@ -5335,15 +5326,14 @@ void monsters::add_enchantment_effect(const mon_enchant &ench, bool quiet) case ENCH_CHARM: behaviour = BEH_SEEK; - target_x = you.x_pos; - target_y = you.y_pos; + target = you.pos(); foe = MHITYOU; if (is_patrolling()) { // Enslaved monsters stop patrolling and forget their patrol point, // they're supposed to follow you now. - patrol_point = coord_def(0, 0); + patrol_point.reset(); } if (you.can_see(this)) learned_something_new(TUT_MONSTER_FRIENDLY); @@ -5365,22 +5355,13 @@ static bool _prepare_del_ench(monsters* mon, const mon_enchant &me) // Monster un-submerging while under player. Try to move to an // adjacent square in which the monster could have been submerged // and have it unusbmerge from there. - coord_def pos, target_square; + coord_def target_square; int okay_squares = 0; - for (pos.x = you.x_pos - 1; pos.x <= you.x_pos + 1; ++pos.x) - for (pos.y = you.y_pos - 1; pos.y <= you.y_pos + 1; ++pos.y) - { - if (pos == you.pos()) - continue; - - if (in_bounds(pos) && mgrd(pos) == NON_MONSTER - && monster_can_submerge(mon, grd(pos))) - { - if (one_chance_in(++okay_squares)) - target_square = pos; - } - } + for ( adjacent_iterator ai; ai; ++ai ) + if (mgrd(*ai) == NON_MONSTER && monster_can_submerge(mon, grd(*ai))) + if (one_chance_in(++okay_squares)) + target_square = *ai; if (okay_squares > 0) { @@ -5388,8 +5369,7 @@ static bool _prepare_del_ench(monsters* mon, const mon_enchant &me) mgrd(mon->pos()) = NON_MONSTER; mgrd(target_square) = mnum; - mon->x = target_square.x; - mon->y = target_square.y; + mon->moveto(target_square); return (true); } @@ -5401,20 +5381,16 @@ static bool _prepare_del_ench(monsters* mon, const mon_enchant &me) // The terrain changed and the monster can't remain submerged. // Try to move to an adjacent square where it would be happy. - for (pos.x = you.x_pos - 1; pos.x <= you.x_pos + 1; ++pos.x) - for (pos.y = you.y_pos - 1; pos.y <= you.y_pos + 1; ++pos.y) + for ( adjacent_iterator ai; ai; ++ai ) + { + if (mgrd(*ai) == NON_MONSTER + && monster_habitable_grid(mon, grd(*ai)) + && trap_type_at_xy(*ai) == NUM_TRAPS) { - if (pos == you.pos()) - continue; - - if (in_bounds(pos) && mgrd(pos) == NON_MONSTER - && monster_habitable_grid(mon, grd(pos)) - && trap_type_at_xy(pos) == NUM_TRAPS) - { - if (one_chance_in(++okay_squares)) - target_square = pos; - } + if (one_chance_in(++okay_squares)) + target_square = *ai; } + } if (okay_squares > 0) { @@ -5422,8 +5398,7 @@ static bool _prepare_del_ench(monsters* mon, const mon_enchant &me) mgrd(mon->pos()) = NON_MONSTER; mgrd(target_square) = mnum; - mon->x = target_square.x; - mon->y = target_square.y; + mon->moveto(target_square); } return (true); @@ -5664,7 +5639,7 @@ void monsters::remove_enchantment_effect(const mon_enchant &me, bool quiet) } } else if (mons_near(this) - && grid_compatible(grd[this->x][this->y], DNGN_DEEP_WATER)) + && grid_compatible(grd(pos()), DNGN_DEEP_WATER)) { mpr("Something invisible bursts forth from the water."); interrupt_activity( AI_FORCE_INTERRUPT ); @@ -6034,7 +6009,7 @@ void monsters::apply_enchantment(const mon_enchant &me) case ENCH_SUBMERGED: { // Not even air elementals unsubmerge into clouds. - if (env.cgrid[x][y] != EMPTY_CLOUD) + if (env.cgrid(pos()) != EMPTY_CLOUD) break; // Air elementals are a special case, as their @@ -6050,7 +6025,7 @@ void monsters::apply_enchantment(const mon_enchant &me) } // Now we handle the others: - const dungeon_feature_type grid = grd[x][y]; + const dungeon_feature_type grid = grd(pos()); // Badly injured monsters prefer to stay submerged... // electrical eels and lava snakes have ranged attacks @@ -6420,18 +6395,18 @@ bool monsters::mon_see_grid(const coord_def& p, bool reach) const true, true)); } -bool monsters::can_see(const actor *target) const +bool monsters::can_see(const actor *targ) const { - if (this == target) - return visible_to(target); + if (this == targ) + return visible_to(targ); - if (!target->visible_to(this)) + if (!targ->visible_to(this)) return (false); - if (target->atype() == ACT_PLAYER) + if (targ->atype() == ACT_PLAYER) return mons_near(this); - const monsters* mon = dynamic_cast(target); + const monsters* mon = dynamic_cast(targ); return mon_see_grid(mon->pos()); } @@ -6489,7 +6464,7 @@ void monsters::apply_location_effects() mons_check_pool(this); if (alive() && has_ench(ENCH_SUBMERGED) - && (!monster_can_submerge(this, grd[x][y]) + && (!monster_can_submerge(this, grd(pos())) || type == MONS_TRAPDOOR_SPIDER)) { del_ench(ENCH_SUBMERGED); @@ -6508,8 +6483,7 @@ bool monsters::move_to_pos(const coord_def &newpos) mgrd(pos()) = NON_MONSTER; // Set monster x,y to new value. - x = newpos.x; - y = newpos.y; + position = newpos; // set new monster grid pointer to this monster. mgrd(newpos) = monster_index(this); @@ -6527,7 +6501,7 @@ bool monsters::do_shaft() // the monster isn't standing over a shaft. if (trap_type_at_xy(this->pos()) != TRAP_SHAFT) { - switch(grd[x][y]) + switch(grd(pos())) { case DNGN_FLOOR: case DNGN_OPEN_DOOR: @@ -6993,9 +6967,9 @@ std::string do_mon_str_replacements(const std::string &in_msg, msg = replace_all(msg, "@The_monster@", "Your @the_monster@"); } - if (see_grid(monster->x, monster->y)) + if (see_grid(monster->pos())) { - dungeon_feature_type feat = grd[monster->x][monster->y]; + dungeon_feature_type feat = grd(monster->pos()); if (feat < DNGN_MINMOVE || feat >= NUM_REAL_FEATURES) msg = replace_all(msg, "@surface@", "buggy surface"); else if (feat == DNGN_LAVA) diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index f38c036414..0d51992a83 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -686,17 +686,13 @@ int place_monster(mgen_data mg, bool force_pos) switch (mg.proximity) { case PROX_ANYWHERE: - if (grid_distance( you.x_pos, you.y_pos, - mg.pos.x, mg.pos.y ) < 2 + random2(3)) - { + if (grid_distance( you.pos(), mg.pos ) < 2 + random2(3)) proxOK = false; - } break; case PROX_CLOSE_TO_PLAYER: case PROX_AWAY_FROM_PLAYER: - close_to_player = (distance(you.x_pos, you.y_pos, - mg.pos.x, mg.pos.y) < 64); + close_to_player = (distance(you.pos(), mg.pos) < 64); if (mg.proximity == PROX_CLOSE_TO_PLAYER && !close_to_player || mg.proximity == PROX_AWAY_FROM_PLAYER && close_to_player) @@ -753,10 +749,10 @@ int place_monster(mgen_data mg, bool force_pos) monsters *mon = &menv[id]; if (mg.needs_patrol_point()) { - mon->patrol_point = coord_def(mon->x, mon->y); + mon->patrol_point = mon->pos(); #ifdef DEBUG_PATHFIND mprf("Monster %s is patrolling around (%d, %d).", - mon->name(DESC_PLAIN).c_str(), mon->x, mon->y); + mon->name(DESC_PLAIN).c_str(), mon->pos().x, mon->pos().y); #endif } @@ -873,8 +869,7 @@ static int _place_monster_aux( const mgen_data &mg, menv[id].base_monster = mg.base_type; menv[id].number = mg.number; - menv[id].x = fpos.x; - menv[id].y = fpos.y; + menv[id].moveto(fpos); // Link monster into monster grid. mgrd(fpos) = id; @@ -2048,12 +2043,9 @@ coord_def find_newmons_square_contiguous(monster_type mons_class, coord_def find_newmons_square(int mons_class, const coord_def &p) { - FixedVector < char, 2 > empty; + coord_def empty; coord_def pos(-1, -1); - empty[0] = 0; - empty[1] = 0; - if (mons_class == WANDERING_MONSTER) mons_class = RANDOM_MONSTER; @@ -2062,11 +2054,8 @@ coord_def find_newmons_square(int mons_class, const coord_def &p) // Might be better if we chose a space and tried to match the monster // to it in the case of RANDOM_MONSTER, that way if the target square // is surrounded by water or lava this function would work. -- bwr - if (empty_surrounds( p.x, p.y, spcw, 2, true, empty )) - { - pos.x = empty[0]; - pos.y = empty[1]; - } + if (empty_surrounds( p, spcw, 2, true, empty )) + pos = empty; return (pos); } @@ -2174,54 +2163,35 @@ int create_monster( mgen_data mg, bool fail_msg ) } -bool empty_surrounds(int emx, int emy, dungeon_feature_type spc_wanted, - int radius, bool allow_centre, - FixedVector < char, 2 > &empty) +bool empty_surrounds(const coord_def& where, dungeon_feature_type spc_wanted, + int radius, bool allow_centre, coord_def& empty) { - bool success; - // Assume all player summoning originates from player x,y. - bool playerSummon = (emx == you.x_pos && emy == you.y_pos); + bool playerSummon = (where == you.pos()); int good_count = 0; - int count_x, count_y; - - for (count_x = -radius; count_x <= radius; count_x++) - for (count_y = -radius; count_y <= radius; count_y++) - { - success = false; - - if (!allow_centre && count_x == 0 && count_y == 0) - continue; - - int tx = emx + count_x; - int ty = emy + count_y; - - if (tx == you.x_pos && ty == you.y_pos) - continue; - if (!in_bounds(tx,ty)) - continue; - - if (mgrd[tx][ty] != NON_MONSTER) - continue; - - // Players won't summon out of LOS, or past transparent walls. - if (!see_grid_no_trans(tx, ty) && playerSummon) - continue; + for ( radius_iterator ri(where, radius, true, false, !allow_centre); + ri; ++ri) + { + bool success = false; - if (grd[tx][ty] == spc_wanted) - success = true; + if ( *ri == you.pos() ) + continue; + + if (mgrd(*ri) != NON_MONSTER) + continue; - if (grid_compatible(spc_wanted, grd[tx][ty])) - success = true; + // Players won't summon out of LOS, or past transparent walls. + if (!see_grid_no_trans(*ri) && playerSummon) + continue; - if (success && one_chance_in(++good_count)) - { - empty[0] = tx; - empty[1] = ty; - } - } + success = + (grd(*ri) == spc_wanted) || grid_compatible(spc_wanted, grd(*ri)); + + if (success && one_chance_in(++good_count)) + empty = *ri; + } return (good_count > 0); } @@ -2404,7 +2374,7 @@ bool monster_pathfind::start_pathfind(monsters *mon, coord_def dest, bool msg) // We're doing a reverse search from target to monster. start = dest; - target = coord_def(mon->x, mon->y); + target = mon->pos(); pos = start; // Easy enough. :P diff --git a/crawl-ref/source/monplace.h b/crawl-ref/source/monplace.h index ab03196433..8eebb1a5cb 100644 --- a/crawl-ref/source/monplace.h +++ b/crawl-ref/source/monplace.h @@ -273,13 +273,8 @@ bool player_will_anger_monster(monsters *mon, bool *holy = NULL, bool player_angers_monster(monsters *mon); -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: misc - monplace - spells3 - * *********************************************************************** */ -bool empty_surrounds( int emx, int emy, dungeon_feature_type spc_wanted, - int radius, - bool allow_centre, FixedVector& empty ); +bool empty_surrounds( const coord_def& where, dungeon_feature_type spc_wanted, + int radius, bool allow_centre, coord_def& empty ); // last updated 12may2000 {dlb} diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 2d4f98eae6..9565aae201 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -113,11 +113,10 @@ void get_mimic_item( const monsters *mimic, item_def &item ) item.quantity = 1; item.plus = 0; item.plus2 = 0; - item.x = mimic->x; - item.y = mimic->y; + item.pos = mimic->pos(); item.link = NON_ITEM; - int prop = 127 * mimic->x + 269 * mimic->y; + int prop = 127 * mimic->pos().x + 269 * mimic->pos().y; rng_save_excursion exc; seed_rng( prop ); @@ -126,7 +125,7 @@ void get_mimic_item( const monsters *mimic, item_def &item ) { case MONS_WEAPON_MIMIC: item.base_type = OBJ_WEAPONS; - item.sub_type = (59 * mimic->x + 79 * mimic->y) % NUM_WEAPONS; + item.sub_type = (59*mimic->pos().x + 79*mimic->pos().y) % NUM_WEAPONS; prop %= 100; @@ -146,7 +145,7 @@ void get_mimic_item( const monsters *mimic, item_def &item ) case MONS_ARMOUR_MIMIC: item.base_type = OBJ_ARMOUR; - item.sub_type = (59 * mimic->x + 79 * mimic->y) % NUM_ARMOURS; + item.sub_type = (59*mimic->pos().x + 79*mimic->pos().y) % NUM_ARMOURS; prop %= 100; @@ -341,7 +340,7 @@ static void _place_monster_corpse(const monsters *monster) if (mitm[o].colour == BLACK) mitm[o].colour = monster->colour; - if (grid_destroys_items(grd[monster->x][monster->y])) + if (grid_destroys_items(grd(monster->pos()))) { item_was_destroyed(mitm[o]); mitm[o].base_type = OBJ_UNASSIGNED; @@ -1367,37 +1366,30 @@ void monster_cleanup(monsters *monster) static bool _jelly_divide(monsters *parent) { - int jex = 0, jey = 0; // loop variables {dlb} - bool foundSpot = false; // to rid code of hideous goto {dlb} - monsters *child = NULL; // value determined with loop {dlb} + monsters *child = NULL; if (!mons_class_flag(parent->type, M_SPLITS) || parent->hit_points == 1) return (false); + coord_def child_spot; + int num_spots = 0; + // First, find a suitable spot for the child {dlb}: - for (jex = -1; jex < 3; jex++) + for ( adjacent_iterator ai(parent->pos()); ai; ++ai ) { - // Loop moves beyond those tiles contiguous to parent {dlb}: - if (jex > 1) - return (false); - - for (jey = -1; jey < 2; jey++) + if (mgrd(*ai) == NON_MONSTER + && parent->can_pass_through(*ai) + && (*ai != you.pos())) { - // 10-50 for now - must take clouds into account: - if (mgrd[parent->x + jex][parent->y + jey] == NON_MONSTER - && parent->can_pass_through(parent->x + jex, parent->y + jey) - && (parent->x + jex != you.x_pos || parent->y + jey != you.y_pos)) - { - foundSpot = true; - break; - } + if ( one_chance_in(++num_spots) ) + child_spot = *ai; } + } - if (foundSpot) - break; - } // end of for jex + if ( num_spots == 0 ) + return (false); - int k = 0; // must remain outside loop that follows {dlb} + int k = 0; // Now that we have a spot, find a monster slot {dlb}: for (k = 0; k < MAX_MONSTERS; k++) @@ -1425,8 +1417,7 @@ static bool _jelly_divide(monsters *parent) *child = *parent; child->max_hit_points = child->hit_points; child->speed_increment = 70 + random2(5); - child->x = parent->x + jex; - child->y = parent->y + jey; + child->moveto(child_spot); mgrd(child->pos()) = k; @@ -1464,7 +1455,7 @@ void alert_nearby_monsters(void) static bool _valid_morph( monsters *monster, int new_mclass ) { - const dungeon_feature_type current_tile = grd[monster->x][monster->y]; + const dungeon_feature_type current_tile = grd(monster->pos()); // 'morph targets are _always_ "base" classes, not derived ones. new_mclass = mons_species(new_mclass); @@ -1709,9 +1700,7 @@ bool monster_blink(monsters *monster) mgrd(monster->pos()) = NON_MONSTER; const coord_def oldplace = monster->pos(); - // FIXME Shouldn't this use monsters::move_to_pos() ? - monster->x = near.x; - monster->y = near.y; + monster->moveto(near); mgrd(near) = monster_index(monster); if (player_monster_visible(monster) && mons_near(monster)) @@ -1862,24 +1851,21 @@ bool swap_places(monsters *monster, const coord_def &loc) mpr("You swap places."); - mgrd[monster->x][monster->y] = NON_MONSTER; + mgrd(monster->pos()) = NON_MONSTER; - monster->x = loc.x; - monster->y = loc.y; + monster->moveto(loc); - mgrd[monster->x][monster->y] = monster_index(monster); + mgrd(monster->pos()) = monster_index(monster); return true; } // Returns true if this is a valid swap for this monster. If true, then -// the valid location is set in loc. +// the valid location is set in loc. (Otherwise loc becomes garbage.) bool swap_check(monsters *monster, coord_def &loc) { - int loc_x = you.x_pos; - int loc_y = you.y_pos; - - const int mgrid = grd[monster->x][monster->y]; + loc = you.pos(); + const dungeon_feature_type mgrid = grd(monster->pos()); if (mons_is_caught(monster)) { @@ -1887,7 +1873,7 @@ bool swap_check(monsters *monster, coord_def &loc) return (false); } - const bool mon_dest_okay = _habitat_okay( monster, grd[loc_x][loc_y] ); + const bool mon_dest_okay = _habitat_okay( monster, grd(you.pos()) ); const bool you_dest_okay = !is_grid_dangerous(mgrid) || yesno("Do you really want to step there?", false, 'n'); @@ -1901,48 +1887,17 @@ bool swap_check(monsters *monster, coord_def &loc) if (!swap) { int num_found = 0; - int temp_x, temp_y; - - for (int x = -1; x <= 1; x++) - { - temp_x = you.x_pos + x; - if (temp_x < 0 || temp_x >= GXM) - continue; - - for (int y = -1; y <= 1; y++) - { - if (x == 0 && y == 0) - continue; - - temp_y = you.y_pos + y; - if (temp_y < 0 || temp_y >= GYM) - continue; - if (mgrd[temp_x][temp_y] == NON_MONSTER - && _habitat_okay( monster, grd[temp_x][temp_y] )) - { - // Found an appropiate space... check if we - // switch the current choice to this one. - num_found++; - if (one_chance_in(num_found)) - { - loc_x = temp_x; - loc_y = temp_y; - } - } - } - } + for ( adjacent_iterator ai; ai; ++ai ) + if (mgrd(*ai) == NON_MONSTER && _habitat_okay( monster, grd(*ai))) + if (one_chance_in(++num_found)) + loc = *ai; if (num_found) swap = true; } - if (swap) - { - loc.x = loc_x; - loc.y = loc_y; - } - else + if (!swap) { // Might not be ideal, but it's better than insta-killing // the monster... maybe try for a short blink instead? -- bwr @@ -2071,8 +2026,7 @@ void behaviour_event(monsters *mon, int event, int src, if (mon->is_patrolling()) break; - mon->target_x = src_pos.x; - mon->target_y = src_pos.y; + mon->target = src_pos; } break; @@ -2185,14 +2139,12 @@ void behaviour_event(monsters *mon, int event, int src, { if (src == MHITYOU) { - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; + mon->target = you.pos(); mon->attitude = ATT_HOSTILE; } else if (src != MHITNOT) { - mon->target_x = menv[src].x; - mon->target_y = menv[src].y; + mon->target = menv[src].pos(); } } @@ -2332,10 +2284,7 @@ static bool _choose_random_patrol_target_grid(monsters *mon) set_target = true; if (set_target) - { - mon->target_x = ri->x; - mon->target_y = ri->y; - } + mon->target = *ri; } return (count_grids); @@ -2567,8 +2516,7 @@ static void _handle_behaviour(monsters *mon) // Check for confusion -- early out. if (mon->has_ench(ENCH_CONFUSION)) { - mon->target_x = 10 + random2(GXM - 10); - mon->target_y = 10 + random2(GYM - 10); + mon->target.set( 10 + random2(GXM - 10), 10 + random2(GYM - 10) ); return; } @@ -2674,8 +2622,7 @@ static void _handle_behaviour(monsters *mon) while (changed) { - int foe_x = you.x_pos; - int foe_y = you.y_pos; + coord_def foepos = you.pos(); // Evaluate these each time; they may change. if (mon->foe == MHITNOT) @@ -2684,8 +2631,7 @@ static void _handle_behaviour(monsters *mon) { if (mon->foe == MHITYOU) { - foe_x = you.x_pos; - foe_y = you.y_pos; + foepos = you.pos(); proxFoe = proxPlayer; // Take invis into account. } else @@ -2695,8 +2641,7 @@ static void _handle_behaviour(monsters *mon) if (!mon_can_see_monster(mon, &menv[mon->foe])) proxFoe = false; - foe_x = menv[mon->foe].x; - foe_y = menv[mon->foe].y; + foepos = menv[mon->foe].pos(); } } @@ -2709,8 +2654,7 @@ static void _handle_behaviour(monsters *mon) { case BEH_SLEEP: // default sleep state - mon->target_x = mon->x; - mon->target_y = mon->y; + mon->target = mon->pos(); new_foe = MHITNOT; break; @@ -2724,8 +2668,7 @@ static void _handle_behaviour(monsters *mon) else { new_foe = MHITYOU; - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; + mon->target = you.pos(); } break; } @@ -2754,8 +2697,7 @@ static void _handle_behaviour(monsters *mon) else { new_foe = MHITYOU; - mon->target_x = foe_x; - mon->target_y = foe_y; + mon->target = foepos; } break; } @@ -2769,25 +2711,19 @@ static void _handle_behaviour(monsters *mon) // but only for a few moves (smell and // intuition only go so far). - if (mon->x == mon->target_x && mon->y == mon->target_y) + if (mon->pos() == mon->target) { if (mon->foe == MHITYOU) { if (random2(you.skills[SK_STEALTH]/3)) - { - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; - } + mon->target = you.pos(); else mon->foe_memory = 1; } else { if (coinflip()) // XXX: cheesy! - { - mon->target_x = menv[mon->foe].x; - mon->target_y = menv[mon->foe].y; - } + mon->target = menv[mon->foe].pos(); else mon->foe_memory = 1; } @@ -2914,8 +2850,7 @@ static void _handle_behaviour(monsters *mon) if (grid_see_grid(targ, you.pos(), can_move)) { // Current target still valid? - if (mon->x == mon->travel_path[0].x - && mon->y == mon->travel_path[0].y) + if (mon->pos() == mon->travel_path[0]) { // Get next waypoint. mon->travel_path.erase( @@ -2923,8 +2858,7 @@ static void _handle_behaviour(monsters *mon) if (!mon->travel_path.empty()) { - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; break; } } @@ -2932,16 +2866,14 @@ static void _handle_behaviour(monsters *mon) mon->travel_path[0], can_move)) { - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; break; } } } // Use pathfinding to find a (new) path to the player. - const int dist = grid_distance(mon->pos(), - you.pos()); + const int dist = grid_distance(mon->pos(), you.pos()); #ifdef DEBUG_PATHFIND mprf("Need to calculate a path... (dist = %d)", dist); @@ -2997,15 +2929,13 @@ static void _handle_behaviour(monsters *mon) if (range > 0) mp.set_range(range); - if (mp.start_pathfind(mon, coord_def(you.x_pos, - you.y_pos))) + if (mp.start_pathfind(mon, you.pos())) { mon->travel_path = mp.calc_waypoints(); if (!mon->travel_path.empty()) { // Okay then, we found a path. Let's use it! - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; mon->travel_target = MTRAV_PLAYER; break; } @@ -3037,22 +2967,20 @@ static void _handle_behaviour(monsters *mon) // Sometimes, your friends will wander a bit. if (isFriendly && one_chance_in(8)) { - mon->target_x = 10 + random2(GXM - 10); - mon->target_y = 10 + random2(GYM - 10); + mon->target.set(10 + random2(GXM - 10), + 10 + random2(GYM - 10)); mon->foe = MHITNOT; new_beh = BEH_WANDER; } else { - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; + mon->target = you.pos(); } } else { // We have a foe but it's not the player. - mon->target_x = menv[mon->foe].x; - mon->target_y = menv[mon->foe].y; + mon->target = menv[mon->foe].pos(); } // Stupid monsters, plants or nonliving monsters cannot flee. @@ -3087,24 +3015,21 @@ static void _handle_behaviour(monsters *mon) mon->travel_target = MTRAV_PATROL; patrolling = true; mon->patrol_point = e[e_index].target; - mon->target_x = e[e_index].target.x; - mon->target_y = e[e_index].target.y; + mon->target = e[e_index].target; } else { mon->travel_target = MTRAV_NONE; patrolling = false; mon->patrol_point = coord_def(0, 0); - mon->target_x = 10 + random2(GXM - 10); - mon->target_y = 10 + random2(GYM - 10); + mon->target.set(10 + random2(GXM - 10), + 10 + random2(GYM - 10)); } } // If a pacified monster is leaving the level, and has // reached its goal, handle it here. - if (e_index != -1 - && mon->x == e[e_index].target.x - && mon->y == e[e_index].target.y) + if (e_index != -1 && mon->pos() == e[e_index].target) { make_mons_leave_level(mon); return; @@ -3139,7 +3064,7 @@ static void _handle_behaviour(monsters *mon) // direction to the left or right. We're changing this so // wandering monsters at least appear to have some sort of // attention span. -- bwr - if (mon->x == mon->target_x && mon->y == mon->target_y + if (mon->pos() == mon->target || mons_is_batty(mon) || !isPacified && one_chance_in(20)) { bool need_target = true; @@ -3152,8 +3077,7 @@ static void _handle_behaviour(monsters *mon) #endif need_target = false; - if (mon->x == mon->travel_path[0].x - && mon->y == mon->travel_path[0].y) + if (mon->pos() == mon->travel_path[0]) { #ifdef DEBUG_PATHFIND mpr("Arrived at first waypoint."); @@ -3172,11 +3096,10 @@ static void _handle_behaviour(monsters *mon) } else { - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; #ifdef DEBUG_PATHFIND mprf("Next waypoint: (%d, %d)", - mon->target_x, mon->target_y); + mon->target.x, mon->target.y); #endif } } @@ -3203,8 +3126,7 @@ static void _handle_behaviour(monsters *mon) 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; + mon->target = mon->travel_path[i]; erase = i; break; } @@ -3238,11 +3160,10 @@ static void _handle_behaviour(monsters *mon) mon->travel_path = mp.calc_waypoints(); if (!mon->travel_path.empty()) { - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; #ifdef DEBUG_PATHFIND mprf("Next waypoint: (%d, %d)", - mon->target_x, mon->target_y); + mon->target.x, mon->target.y); #endif } else @@ -3320,22 +3241,20 @@ static void _handle_behaviour(monsters *mon) mon->travel_path = mp.calc_waypoints(); if (!mon->travel_path.empty()) { - mon->target_x = mon->travel_path[0].x; - mon->target_y = mon->travel_path[0].y; + mon->target = mon->travel_path[0]; mon->travel_target = MTRAV_PATROL; } else { // We're so close we don't even need // a path. - mon->target_x = mon->patrol_point.x; - mon->target_y = mon->patrol_point.y; + mon->target = mon->patrol_point; } } else { // Stop patrolling. - mon->patrol_point = coord_def(0, 0); + mon->patrol_point.reset(); mon->travel_target = MTRAV_NONE; need_target = true; } @@ -3354,8 +3273,8 @@ static void _handle_behaviour(monsters *mon) if (need_target) { - mon->target_x = 10 + random2(GXM - 10); - mon->target_y = 10 + random2(GYM - 10); + mon->target.set(10 + random2(GXM - 10), + 10 + random2(GYM - 10)); } } @@ -3403,15 +3322,13 @@ static void _handle_behaviour(monsters *mon) if (isFriendly) { // Special-cased below so that it will flee *towards* you. - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; + mon->target = you.pos(); } else if (proxFoe) { // Special-cased below so that it will flee *from* the // correct position. - mon->target_x = foe_x; - mon->target_y = foe_y; + mon->target = foepos; } break; @@ -3436,8 +3353,7 @@ static void _handle_behaviour(monsters *mon) } else { - mon->target_x = foe_x; - mon->target_y = foe_y; + mon->target = foepos; } break; @@ -3491,8 +3407,8 @@ void _set_nearest_monster_foe(monsters *mon) const bool friendly = mons_friendly(mon); const bool neutral = mons_neutral(mon); - const int mx = mon->x; - const int my = mon->y; + const int mx = mon->pos().x; + const int my = mon->pos().y; for (int k = 1; k <= LOS_RADIUS; ++k) { @@ -3537,51 +3453,34 @@ monsters *choose_random_monster_on_level(int weight, bool prefer_named) { monsters *chosen = NULL; - int mons_count = weight; - - int ystart = 0; - int xstart = 0; - int yend = GXM - 1; - int xend = GYM - 1; - if (near_by) + // A radius_iterator with radius == max(GXM,GYM) will sweep the whole + // level. + radius_iterator ri(you.pos(), near_by ? 9 : std::max(GXM,GYM), + true, in_sight); + + for ( ; ri; ++ri ) { - ystart = MAX(0, you.y_pos - 9); - xstart = MAX(0, you.x_pos - 9); - yend = MIN(GYM - 1, you.y_pos + 9); - xend = MIN(GXM - 1, you.x_pos + 9); - } - - // Monster check. - for ( int y = ystart; y <= yend; ++y ) - { - for ( int x = xstart; x <= xend; ++x ) + if ( mgrd(*ri) != NON_MONSTER ) { - if ( mgrd[x][y] != NON_MONSTER && (!in_sight || see_grid(x,y)) ) + monsters *mon = &menv[mgrd(*ri)]; + if (suitable(mon)) { - monsters *mon = &menv[mgrd[x][y]]; - if (suitable(mon)) - { - // FIXME: if the intent is to favour monsters - // named by $DEITY, we should set a flag on the - // monster (something like MF_DEITY_PREFERRED) and - // use that instead of checking the name, given - // that other monsters can also have names. - - // True, but it's currently only used for orcs, and - // Blork and Urug also being preferred to non-named orcs - // is fine, I think. Once more gods name followers (and - // prefer them) that should be changed, of course. (jpeg) - if (prefer_named && mon->is_named()) - { - mons_count += 2; - // Named monsters have doubled chances. - if (x_chance_in_y(2, mons_count)) - chosen = mon; - } - else if (one_chance_in(++mons_count)) - chosen = mon; - } + // FIXME: if the intent is to favour monsters + // named by $DEITY, we should set a flag on the + // monster (something like MF_DEITY_PREFERRED) and + // use that instead of checking the name, given + // that other monsters can also have names. + + // True, but it's currently only used for orcs, and + // Blork and Urug also being preferred to non-named orcs + // is fine, I think. Once more gods name followers (and + // prefer them) that should be changed, of course. (jpeg) + + // Named monsters have doubled chances. + int mon_weight = ((prefer_named && mon->is_named()) ? 2 : 1); + if ( x_chance_in_y(mon_weight, (weight += mon_weight)) ) + chosen = mon; } } } @@ -3625,7 +3524,7 @@ static bool _mon_on_interesting_grid(monsters *mon) if (one_chance_in(4)) return (false); - const dungeon_feature_type feat = grd[mon->x][mon->y]; + const dungeon_feature_type feat = grd(mon->pos()); switch (feat) { @@ -3681,8 +3580,8 @@ static void _maybe_set_patrol_route(monsters *monster) // //--------------------------------------------------------------- static void _handle_movement(monsters *monster) -{ - int dx, dy; +{ + coord_def delta; _maybe_set_patrol_route(monster); @@ -3695,7 +3594,7 @@ static void _handle_movement(monsters *monster) } else if (mons_is_fleeing(monster) && inside_level_bounds(env.sanctuary_pos) && !is_sanctuary(monster->pos()) - && monster->target_pos() == env.sanctuary_pos) + && monster->target == env.sanctuary_pos) { // Once outside there's a chance they'll regain their courage. // Nonliving and berserking monsters always stop imediately, @@ -3712,25 +3611,20 @@ static void _handle_movement(monsters *monster) if (monster->type == MONS_BORING_BEETLE && monster->foe == MHITYOU) { // Boring beetles always move in a straight line in your direction. - dx = you.x_pos - monster->x; - dy = you.y_pos - monster->y; + delta = you.pos() - monster->pos(); } else - { - dx = monster->target_x - monster->x; - dy = monster->target_y - monster->y; - } + delta = monster->target - monster->pos(); // Move the monster. - mmov.x = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0); - mmov.y = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0); + mmov.x = (delta.x > 0) ? 1 : ((delta.x < 0) ? -1 : 0); + mmov.y = (delta.y > 0) ? 1 : ((delta.y < 0) ? -1 : 0); if (mons_is_fleeing(monster) && (!mons_friendly(monster) - || monster->target_pos() != you.pos())) + || monster->target != you.pos())) { - mmov.x *= -1; - mmov.y *= -1; + mmov *= -1; } // Don't allow monsters to enter a sanctuary @@ -3743,14 +3637,14 @@ static void _handle_movement(monsters *monster) } // 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) + const coord_def s = monster->target + mmov; + if (s.x < 0 || s.x >= GXM) mmov.x = 0; - - if (monster->target_y + mmov.y < 0 || monster->target_y + mmov.y >= GYM) + if (s.y < 0 || s.y >= GYM) mmov.y = 0; // now quit if we can't move - if (mmov == coord_def(0,0)) + if (mmov.origin()) return; // Reproduced here is some semi-legacy code that makes monsters @@ -3759,23 +3653,17 @@ static void _handle_movement(monsters *monster) // // Added a check so that oblique movement paths aren't used when // close to the target square. -- bwr - if (grid_distance(dx, dy, 0, 0) > 3) + if (delta.rdist() > 3) { - if (abs(dx) > abs(dy)) - { - // Sometimes we'll just move parallel the x axis. - if (coinflip()) - mmov.y = 0; - } + // Sometimes we'll just move parallel the x axis. + if (abs(delta.x) > abs(delta.y) && coinflip()) + mmov.y = 0; - if (abs(dy) > abs(dx)) - { - // Sometimes we'll just move parallel the y axis. - if (coinflip()) - mmov.x = 0; - } + // Sometimes we'll just move parallel the y axis. + if (abs(delta.y) > abs(delta.x) && coinflip()) + mmov.x = 0; } -} // end handle_movement() +} static void _make_mons_stop_fleeing(monsters *mon) { @@ -3837,7 +3725,7 @@ static void _handle_nearby_ability(monsters *monster) } // Okay then, don't speak. - if (monster_can_submerge(monster, grd[monster->x][monster->y]) + if (monster_can_submerge(monster, grd(monster->pos())) && !player_beheld_by(monster) // No submerging if player entranced. && !mons_is_lurking(monster) // Handled elsewhere. && (one_chance_in(5) @@ -3855,7 +3743,7 @@ static void _handle_nearby_ability(monsters *monster) && monster->seen_context != "bursts forth shouting" && !one_chance_in(20) || monster->hit_points <= monster->max_hit_points / 2 - || env.cgrid[monster->x][monster->y] != EMPTY_CLOUD)) + || env.cgrid(monster->pos()) != EMPTY_CLOUD)) { monster->add_ench(ENCH_SUBMERGED); update_beholders(monster); @@ -3990,16 +3878,14 @@ static bool _handle_special_ability(monsters *monster, bolt & beem) continue; // Faking LOS by checking the neighbouring square. - int dx = sgn(targ->x - monster->x); - int dy = sgn(targ->y - monster->y); - - const int tx = monster->x + dx; - const int ty = monster->y + dy; + coord_def diff = targ->pos() - monster->pos(); + coord_def sg(sgn(diff.x), sgn(diff.y)); + coord_def t = monster->pos() + sg; - if (!inside_level_bounds(tx, ty)) + if (!inside_level_bounds(t)) continue; - if (!grid_is_solid(grd[tx][ty])) + if (!grid_is_solid(grd(t))) { monster->hit_points = -1; used = true; @@ -4544,36 +4430,24 @@ static bool _handle_reaching(monsters *monster) if (monster->foe == MHITYOU) { // This check isn't redundant -- player may be invisible. - if (monster->target_pos() == you.pos() - && see_grid_no_trans(monster->pos())) + if (monster->target == you.pos() + && see_grid_no_trans(monster->pos()) + && grid_distance( monster->pos(), you.pos()) == 2) { - int dx = abs(monster->x - you.x_pos); - int dy = abs(monster->y - you.y_pos); - - if (dx == 2 && dy <= 2 || dy == 2 && dx <= 2) - { - ret = true; - monster_attack( monster_index(monster), false ); - } + ret = true; + monster_attack( monster_index(monster), false ); } } else if (monster->foe != MHITNOT) { - int foe_x = menv[monster->foe].x; - int foe_y = menv[monster->foe].y; - coord_def foe_pos = menv[monster->foe].pos(); + coord_def foepos = menv[monster->foe].pos(); // Same comments as to invisibility as above. - if (monster->target_x == foe_x && monster->target_y == foe_y - && monster->mon_see_grid(foe_pos, true)) + if (monster->target == foepos + && monster->mon_see_grid(foepos, true) + && grid_distance(monster->pos(), foepos) == 2) { - int dx = abs(monster->x - foe_x); - int dy = abs(monster->y - foe_y); - - if (dx == 2 && dy <= 2 || dy == 2 && dx <= 2) - { - ret = true; - monsters_fight(monster_index(monster), monster->foe, false); - } + ret = true; + monsters_fight(monster_index(monster), monster->foe, false); } } } @@ -4711,8 +4585,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) beem.name = theBeam.name; beem.beam_source = monster_index(monster); - beem.source_x = monster->x; - beem.source_y = monster->y; + beem.source = monster->pos(); beem.colour = theBeam.colour; beem.range = theBeam.range; beem.rangeMax = theBeam.rangeMax; @@ -4760,9 +4633,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) case WAND_HASTING: if (!monster->has_ench(ENCH_HASTE)) { - beem.target_x = monster->x; - beem.target_y = monster->y; - + beem.target = monster->pos(); niceWand = true; break; } @@ -4771,9 +4642,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) case WAND_HEALING: if (monster->hit_points <= monster->max_hit_points / 2) { - beem.target_x = monster->x; - beem.target_y = monster->y; - + beem.target = monster->pos(); niceWand = true; break; } @@ -4784,9 +4653,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) && !monster->has_ench(ENCH_SUBMERGED) && (!mons_friendly(monster) || player_see_invis(false))) { - beem.target_x = monster->x; - beem.target_y = monster->y; - + beem.target = monster->pos(); niceWand = true; break; } @@ -4799,9 +4666,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) if (!monster->has_ench(ENCH_TP) && !one_chance_in(20)) { - beem.target_x = monster->x; - beem.target_y = monster->y; - + beem.target = monster->pos(); niceWand = true; break; } @@ -5332,9 +5197,7 @@ static bool _handle_spell(monsters *monster, bolt &beem) // a measure of time instead of peeking to see // if the player is still there). -- bwr if (!mons_player_visible(monster) - && (monster->target_x != you.x_pos - || monster->target_y != you.y_pos - || coinflip())) + && (monster->target != you.pos() || coinflip())) { spellOK = false; } @@ -5528,7 +5391,7 @@ 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(), monster->pos())) + if (!archer && adjacent(beem.target, monster->pos())) return (false); // Greatly lowered chances if the monster is fleeing or pacified and @@ -5553,10 +5416,9 @@ static bool _handle_throw(monsters *monster, bolt & beem) // completely useless, so bail out. if (mitm[mon_item].base_type == OBJ_MISSILES && mitm[mon_item].sub_type == MI_THROWING_NET - && ( beem.target_x == you.x_pos && beem.target_y == you.y_pos - && you.caught() - || mgrd[beem.target_x][beem.target_y] != NON_MONSTER - && mons_is_caught(&menv[mgrd[beem.target_x][beem.target_y]]) )) + && ( beem.target == you.pos() && you.caught() + || mgrd(beem.target) != NON_MONSTER + && mons_is_caught(&menv[mgrd(beem.target)]))) { return (false); } @@ -5721,14 +5583,14 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx) return (false); } - if (!mover->can_pass_through(moved->x, moved->y) - || !moved->can_pass_through(mover->x, mover->y)) + if (!mover->can_pass_through(moved->pos()) + || !moved->can_pass_through(mover->pos())) { return (false); } - if (!monster_habitable_grid(mover, grd[moved->x][moved->y]) - || !monster_habitable_grid(moved, grd[mover->x][mover->y])) + if (!monster_habitable_grid(mover, grd(moved->pos())) + || !monster_habitable_grid(moved, grd(mover->pos()))) { return (false); } @@ -5737,11 +5599,9 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx) const coord_def mover_pos = mover->pos(); const coord_def moved_pos = moved->pos(); - mover->x = moved_pos.x; - mover->y = moved_pos.y; + mover->pos() = moved_pos; - moved->x = mover_pos.x; - moved->y = mover_pos.y; + moved->pos() = mover_pos; mgrd(mover->pos()) = mover_idx; mgrd(moved->pos()) = moved_idx; @@ -5757,7 +5617,7 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx) static void _swim_or_move_energy(monsters *mon) { - const dungeon_feature_type feat = grd[mon->x][mon->y]; + const dungeon_feature_type feat = grd(mon->pos()); // FIXME: Replace check with mons_is_swimming()? mon->lose_energy( (feat >= DNGN_LAVA && feat <= DNGN_SHALLOW_WATER @@ -5795,7 +5655,7 @@ static void _handle_monster_move(int i, monsters *monster) // Handle clouds on nonmoving monsters. if (monster->speed == 0 - && env.cgrid[monster->x][monster->y] != EMPTY_CLOUD + && env.cgrid(monster->pos()) != EMPTY_CLOUD && !monster->has_ench(ENCH_SUBMERGED)) { _mons_in_cloud( monster ); @@ -5880,7 +5740,7 @@ static void _handle_monster_move(int i, monsters *monster) monster->shield_blocks = 0; - if (env.cgrid[monster->x][monster->y] != EMPTY_CLOUD) + if (env.cgrid(monster->pos()) != EMPTY_CLOUD) { if (monster->has_ench(ENCH_SUBMERGED)) { @@ -5921,8 +5781,8 @@ static void _handle_monster_move(int i, monsters *monster) _handle_behaviour(monster); // Submerging monsters will hide from clouds. - if (monster_can_submerge(monster, grd[monster->x][monster->y]) - && env.cgrid[monster->x][monster->y] != EMPTY_CLOUD) + if (monster_can_submerge(monster, grd(monster->pos())) + && env.cgrid(monster->pos()) != EMPTY_CLOUD) { monster->add_ench(ENCH_SUBMERGED); } @@ -5939,7 +5799,7 @@ static void _handle_monster_move(int i, monsters *monster) monster->max_hit_points = monster->hit_points; } - if (igrd[monster->x][monster->y] != NON_ITEM + if (igrd(monster->pos()) != NON_ITEM && (mons_itemuse(monster->type) == MONUSE_WEAPONS_ARMOUR || mons_itemuse(monster->type) == MONUSE_EATS_ITEMS)) { @@ -5962,8 +5822,7 @@ static void _handle_monster_move(int i, monsters *monster) // Lurking monsters only stop lurking if their target is right // next to them, otherwise they just sit there. if (monster->foe != MHITNOT - && abs(monster->target_x - monster->x) <= 1 - && abs(monster->target_y - monster->y) <= 1) + && grid_distance(monster->target, monster->pos()) <= 1) { if (monster->has_ench(ENCH_SUBMERGED)) { @@ -6028,10 +5887,11 @@ static void _handle_monster_move(int i, monsters *monster) // Bounds check: don't let confused monsters try to run // off the map. - if (monster->x + mmov.x < 0 || monster->x + mmov.x >= GXM) + const coord_def s = monster->pos() + mmov; + if (s.x < 0 || s.x >= GXM) mmov.x = 0; - if (monster->y + mmov.y < 0 || monster->y + mmov.y >= GYM) + if (s.y < 0 || s.y >= GYM) mmov.y = 0; if (!monster->can_pass_through(monster->pos() + mmov)) @@ -6040,7 +5900,7 @@ static void _handle_monster_move(int i, monsters *monster) int enemy = mgrd(monster->pos() + mmov); if (enemy != NON_MONSTER && !is_sanctuary(monster->pos()) - && (mmov.x != 0 || mmov.y != 0)) + && !mmov.origin()) { if (monsters_fight(i, enemy)) { @@ -6067,8 +5927,7 @@ static void _handle_monster_move(int i, monsters *monster) } _handle_nearby_ability( monster ); - beem.target_x = monster->target_x; - beem.target_y = monster->target_y; + beem.target = monster->target; if (!mons_is_sleeping(monster) && !mons_is_wandering(monster) @@ -6146,8 +6005,8 @@ static void _handle_monster_move(int i, monsters *monster) if (mons_is_batty(monster)) { monster->behaviour = BEH_WANDER; - monster->target_x = 10 + random2(GXM - 10); - monster->target_y = 10 + random2(GYM - 10); + monster->target.set(10 + random2(GXM - 10), + 10 + random2(GYM - 10)); // monster->speed_increment -= monster->speed; } @@ -6173,8 +6032,8 @@ static void _handle_monster_move(int i, monsters *monster) if (mons_is_batty(monster)) { monster->behaviour = BEH_WANDER; - monster->target_x = 10 + random2(GXM - 10); - monster->target_y = 10 + random2(GYM - 10); + monster->target.set(10 + random2(GXM - 10), + 10 + random2(GYM - 10)); } DEBUG_ENERGY_USE("monster_attack()"); } @@ -6185,7 +6044,7 @@ static void _handle_monster_move(int i, monsters *monster) { // Detach monster from the grid first, so it // doesn't get hit by its own explosion. (GDL) - mgrd[monster->x][monster->y] = NON_MONSTER; + mgrd(monster->pos()) = NON_MONSTER; spore_goes_pop(monster); monster_cleanup(monster); @@ -6227,7 +6086,7 @@ static void _handle_monster_move(int i, monsters *monster) { // Detach monster from the grid first, so it // doesn't get hit by its own explosion. (GDL) - mgrd[monster->x][monster->y] = NON_MONSTER; + mgrd(monster->pos()) = NON_MONSTER; spore_goes_pop(monster); monster_cleanup(monster); @@ -6258,15 +6117,12 @@ void handle_monsters(void) if (monster->type == -1 || immobile_monster[i]) continue; - const int mx = monster->x, my = monster->y; + const coord_def oldpos = monster->pos(); _handle_monster_move(i, monster); - if (!invalid_monster(monster) - && (monster->x != mx || monster->y != my)) - { + if (!invalid_monster(monster) && (monster->pos() != oldpos)) immobile_monster[i] = true; - } // If the player got banished, discard pending monster actions. if (you.banished) @@ -6344,7 +6200,7 @@ static bool _handle_pickup(monsters *monster) int eaten = 0; bool eaten_net = false; - for (item = igrd[monster->x][monster->y]; + for (item = igrd(monster->pos()); item != NON_ITEM && eaten < max_eat && hps_gained < 50; item = mitm[item].link) { @@ -6359,7 +6215,7 @@ static bool _handle_pickup(monsters *monster) mitm[item].name(DESC_PLAIN).c_str()); #endif - if (mitm[igrd[monster->x][monster->y]].base_type != OBJ_GOLD) + if (mitm[igrd(monster->pos())].base_type != OBJ_GOLD) { if (quant > max_eat - eaten) quant = max_eat - eaten; @@ -6434,7 +6290,7 @@ static bool _handle_pickup(monsters *monster) // Monsters may now pick up several items in the same turn, though with // reducing chances. (jpeg) bool success = false; - for (item = igrd[monster->x][monster->y]; item != NON_ITEM; ) + for (item = igrd(monster->pos()); item != NON_ITEM; ) { item_def &topickup = mitm[item]; item = topickup.link; @@ -6529,7 +6385,7 @@ static bool _monster_swaps_places( monsters *mon, const coord_def& delta ) #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Alerting monster %s at (%d,%d)", - m2->name(DESC_PLAIN).c_str(), m2->x, m2->y); + m2->name(DESC_PLAIN).c_str(), m2->pos().x, m2->pos().y); #endif behaviour_event( m2, ME_ALERT, MHITNOT ); } @@ -6546,12 +6402,9 @@ static bool _monster_swaps_places( monsters *mon, const coord_def& delta ) // Okay, do the swap! _swim_or_move_energy(mon); - mon->x = n.x; - mon->y = n.y; + mon->moveto(n); mgrd(n) = monster_index(mon); - - m2->x = c.x; - m2->y = c.y; + m2->moveto(c); const int m2i = monster_index(m2); ASSERT(m2i >= 0 && m2i < MAX_MONSTERS); mgrd(c) = m2i; @@ -6596,8 +6449,7 @@ static bool _do_move_monster(monsters *monster, const coord_def& delta) mgrd(monster->pos()) = NON_MONSTER; - monster->x = f.x; - monster->y = f.y; + monster->pos() = f; mgrd(monster->pos()) = monster_index(monster); @@ -6742,8 +6594,8 @@ static bool _is_trap_safe(const monsters *monster, const coord_def& where, else { // Test for corridor-like environment. - const int x = where.x - monster->x; - const int y = where.y - monster->y; + const int x = where.x - monster->pos().x; + const int y = where.y - monster->pos().y; // The question is whether the monster (m) can easily reach its // presumable destination (x) without stepping on the trap. Traps @@ -6838,7 +6690,7 @@ static void _mons_open_door(monsters* monster, const coord_def &pos) mprf("%s was actually a secret door!", feature_description(grid, NUM_TRAPS, false, DESC_CAP_THE, false).c_str()); - learned_something_new(TUT_SEEN_SECRET_DOOR, pos.x, pos.y); + learned_something_new(TUT_SEEN_SECRET_DOOR, pos); } std::string open_str = "opens the "; @@ -7106,7 +6958,7 @@ static bool _monster_move(monsters *monster) else can_see = monster->can_see(&menv[monster->foe]); - if (monster_can_submerge(monster, grd[monster->x][monster->y]) + if (monster_can_submerge(monster, grd(monster->pos())) && !can_see && !mons_is_confused(monster) && !monster->has_ench(ENCH_BERSERK)) { @@ -7157,29 +7009,29 @@ static bool _monster_move(monsters *monster) } // Let's not even bother with this if mmov.x and mmov.y are zero. - if (mmov.x == 0 && mmov.y == 0) + if (mmov.origin()) return (false); for (count_x = 0; count_x < 3; count_x++) for (count_y = 0; count_y < 3; count_y++) { - const int targ_x = monster->x + count_x - 1; - const int targ_y = monster->y + count_y - 1; - - // Bounds check - don't consider moving out of grid! - if (targ_x < 0 || targ_x >= GXM || targ_y < 0 || targ_y >= GYM) - { - good_move[count_x][count_y] = false; - continue; - } - dungeon_feature_type target_grid = grd[targ_x][targ_y]; - - if (target_grid == DNGN_DEEP_WATER) - deep_water_available = true; + const int targ_x = monster->pos().x + count_x - 1; + const int targ_y = monster->pos().y + count_y - 1; + + // Bounds check - don't consider moving out of grid! + if (targ_x < 0 || targ_x >= GXM || targ_y < 0 || targ_y >= GYM) + { + good_move[count_x][count_y] = false; + continue; + } + dungeon_feature_type target_grid = grd[targ_x][targ_y]; - const monsters* mons = dynamic_cast(monster); - good_move[count_x][count_y] = - _mon_can_move_to_pos(mons, coord_def(count_x-1, count_y-1)); + if (target_grid == DNGN_DEEP_WATER) + deep_water_available = true; + + const monsters* mons = dynamic_cast(monster); + good_move[count_x][count_y] = + _mon_can_move_to_pos(mons, coord_def(count_x-1, count_y-1)); } // Now we know where we _can_ move. @@ -7245,7 +7097,7 @@ static bool _monster_move(monsters *monster) for (count_y = 0; count_y < 3; count_y++) { if (good_move[count_x][count_y] - && grd[monster->x + count_x - 1][monster->y + count_y - 1] + && grd[monster->pos().x + count_x - 1][monster->pos().y + count_y - 1] == DNGN_DEEP_WATER) { count++; @@ -7265,8 +7117,7 @@ static bool _monster_move(monsters *monster) // If neither does, do nothing. if (good_move[mmov.x + 1][mmov.y + 1] == false) { - int current_distance = grid_distance(monster->pos(), - monster->target_pos()); + int current_distance = grid_distance(monster->pos(), monster->target); int dir = -1; int i, mod, newdir; @@ -7307,10 +7158,10 @@ static bool _monster_move(monsters *monster) newdir = (dir + 8 + mod) % 8; if (good_move[compass_x[newdir] + 1][compass_y[newdir] + 1]) { - dist[i] = grid_distance(monster->x + compass_x[newdir], - monster->y + compass_y[newdir], - monster->target_x, - monster->target_y); + dist[i] = grid_distance(monster->pos().x + compass_x[newdir], + monster->pos().y + compass_y[newdir], + monster->target.x, + monster->target.y); } else { @@ -7492,7 +7343,7 @@ static bool _plant_spit(monsters *monster, bolt &pbolt) { _make_mons_stop_fleeing(monster); strcpy( spit_string, " spits" ); - if (pbolt.target_x == you.x_pos && pbolt.target_y == you.y_pos) + if (pbolt.target == you.pos()) strcat( spit_string, " at you" ); strcat( spit_string, "." ); @@ -7507,7 +7358,7 @@ static bool _plant_spit(monsters *monster, bolt &pbolt) static void _mons_in_cloud(monsters *monster) { - int wc = env.cgrid[monster->x][monster->y]; + int wc = env.cgrid(monster->pos()); int hurted = 0; bolt beam; @@ -7869,72 +7720,42 @@ void seen_monster(monsters *monster) // // shift_monster // -// Moves a monster to approximately (x, y) and returns true if +// Moves a monster to approximately p and returns true if // the monster was moved. // //--------------------------------------------------------------- -bool shift_monster( monsters *mon, int x, int y ) +bool shift_monster( monsters *mon, coord_def p ) { - bool found_move = false; - - int i, j; - int tx, ty; - int nx = 0, ny = 0; + coord_def result; int count = 0; - if (x == 0 && y == 0) - { - // Try and find a random floor space some distance away. - for (i = 0; i < 50; i++) - { - tx = 5 + random2( GXM - 10 ); - ty = 5 + random2( GYM - 10 ); - - int dist = grid_distance(x, y, tx, ty); - if (grd[tx][ty] == DNGN_FLOOR && dist > 10) - break; - } + if (p.origin()) + p = mon->pos(); - if (i == 50) - return (false); - } - - for (i = -1; i <= 1; i++) - for (j = -1; j <= 1; j++) - { - tx = x + i; - ty = y + j; - - if (!inside_level_bounds(tx, ty)) - continue; - - // Don't drop on anything but vanilla floor right now. - if (grd[tx][ty] != DNGN_FLOOR) - continue; + for ( adjacent_iterator ai(p); ai; ++ai ) + { + // Don't drop on anything but vanilla floor right now. + if (grd(*ai) != DNGN_FLOOR) + continue; - if (mgrd[tx][ty] != NON_MONSTER) - continue; + if (mgrd(*ai) != NON_MONSTER) + continue; - if (tx == you.x_pos && ty == you.y_pos) - continue; + if (*ai == you.pos()) + continue; - if (one_chance_in(++count)) - { - nx = tx; - ny = ty; - found_move = true; - } - } + if (one_chance_in(++count)) + result = *ai; + } - if (found_move) + if (count > 0) { - const int mon_index = mgrd[mon->x][mon->y]; - mgrd[mon->x][mon->y] = NON_MONSTER; - mgrd[nx][ny] = mon_index; - mon->x = nx; - mon->y = ny; + const int mon_index = mgrd(mon->pos()); + mgrd(mon->pos()) = NON_MONSTER; + mgrd(result) = mon_index; + mon->moveto(result); } - return (found_move); + return (count > 0); } diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h index eb3b90e846..6f92f2c519 100644 --- a/crawl-ref/source/monstuff.h +++ b/crawl-ref/source/monstuff.h @@ -195,7 +195,7 @@ bool heal_monster(monsters *patient, int health_boost, bool permit_growth); void seen_monster(monsters *monster); -bool shift_monster(monsters *mon, int x = 0, int y = 0 ); +bool shift_monster(monsters *mon, coord_def p = coord_def(0,0) ); int mons_weapon_damage_rating(const item_def &launcher); int mons_pick_best_missile(monsters *mons, item_def **launcher, diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index 5c83c00577..2a6587ab85 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -56,30 +56,31 @@ static int _monster_abjuration(const monsters *caster, bool actual); // to be some sort of trap prior to function call: {dlb} void mons_trap(monsters *monster) { - if (!is_trap_square(grd[monster->x][monster->y])) + if (!is_trap_square(grd(monster->pos()))) return; // single calculation permissible {dlb} bool monsterNearby = mons_near(monster); - // new function call {dlb} - int which_trap = trap_at_xy(monster->pos()); + const int which_trap = trap_at_xy(monster->pos()); if (which_trap == -1) return; + + trap_struct& trap(env.trap[which_trap]); - bool trapKnown = (grd[monster->x][monster->y] != DNGN_UNDISCOVERED_TRAP); + bool trapKnown = (grd(monster->pos()) != DNGN_UNDISCOVERED_TRAP); bool revealTrap = false; // more sophisticated trap uncovering {dlb} bool projectileFired = false; // I had to do it, I swear {dlb} int damage_taken = -1; // must initialize at -1 for this f(x) {dlb} - struct bolt beem; + bolt beem; // flying monsters neatly avoid mechanical traps // and may actually exit this function early: {dlb} if (mons_flies(monster)) { - if (trap_category(env.trap[which_trap].type) == DNGN_TRAP_MECHANICAL) + if (trap_category(trap.type) == DNGN_TRAP_MECHANICAL) { if (trapKnown) simple_monster_message(monster, " flies safely over a trap."); @@ -92,7 +93,7 @@ void mons_trap(monsters *monster) // are fairly stupid and tend to have fewer hp than players -- this // choice prevents traps from easily killing large monsters fairly // deep within the dungeon. - switch (env.trap[which_trap].type) + switch (trap.type) { case TRAP_DART: projectileFired = true; @@ -264,14 +265,13 @@ void mons_trap(monsters *monster) monster_caught_in_net(monster, beem); } } - trap_item( OBJ_MISSILES, MI_THROWING_NET, - env.trap[which_trap].pos() ); + trap_item( OBJ_MISSILES, MI_THROWING_NET, trap.pos ); if (mons_is_caught(monster)) mark_net_trapping(monster->pos()); - grd(env.trap[which_trap].pos()) = DNGN_FLOOR; - env.trap[which_trap].type = TRAP_UNASSIGNED; + grd(trap.pos) = DNGN_FLOOR; + trap.type = TRAP_UNASSIGNED; break; } // zot traps are out to get *the player*! Hostile monsters @@ -335,8 +335,8 @@ void mons_trap(monsters *monster) if (trapKnown && monsterNearby) mpr("The shaft disappears in a puff of logic!"); - grd[env.trap[which_trap].x][env.trap[which_trap].y] = DNGN_FLOOR; - env.trap[which_trap].type = TRAP_UNASSIGNED; + grd(trap.pos) = DNGN_FLOOR; + trap.type = TRAP_UNASSIGNED; return; } @@ -403,8 +403,7 @@ void mons_trap(monsters *monster) // Generate "fallen" projectile, where appropriate. {dlb} if (x_chance_in_y(7, 10)) { - beem.target_x = monster->x; - beem.target_y = monster->y; + beem.target = monster->pos(); itrap(beem, which_trap); } } @@ -412,10 +411,7 @@ void mons_trap(monsters *monster) // reveal undiscovered traps, where appropriate: {dlb} if (monsterNearby && !trapKnown && revealTrap) - { - grd[env.trap[which_trap].x][env.trap[which_trap].y] - = trap_category(env.trap[which_trap].type); - } + grd(trap.pos) = trap_category(trap.type); // apply damage and handle death, where appropriate: {dlb} if (damage_taken > 0) @@ -898,11 +894,8 @@ void setup_mons_cast(monsters *monster, bolt &pbolt, // Convenience for the hapless innocent who assumes that this // damn function does all possible setup. [ds] - if (!pbolt.target_x && !pbolt.target_y) - { - pbolt.target_x = monster->target_x; - pbolt.target_y = monster->target_y; - } + if (pbolt.target.origin()) + pbolt.target = monster->target; // set bolt type if (_los_free_spell(spell_cast)) @@ -973,8 +966,7 @@ void setup_mons_cast(monsters *monster, bolt &pbolt, pbolt.aux_source.clear(); pbolt.name = theBeam.name; pbolt.is_beam = theBeam.is_beam; - pbolt.source_x = monster->x; - pbolt.source_y = monster->y; + pbolt.source = monster->pos(); pbolt.is_tracer = false; pbolt.is_explosion = theBeam.is_explosion; pbolt.ex_size = theBeam.ex_size; @@ -991,8 +983,7 @@ void setup_mons_cast(monsters *monster, bolt &pbolt, || spell_cast == SPELL_LESSER_HEALING || spell_cast == SPELL_TELEPORT_SELF) { - pbolt.target_x = monster->x; - pbolt.target_y = monster->y; + pbolt.target = monster->pos(); } } @@ -1047,8 +1038,7 @@ void monster_teleport(monsters *monster, bool instan, bool silent) break; } - monster->x = newpos.x; - monster->y = newpos.y; + monster->moveto(newpos); mgrd(monster->pos()) = monster_index(monster); @@ -1556,7 +1546,7 @@ 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(), + if (really_returns && mons_thrown_object_destroyed(&item, pbolt.target, true, pbolt.beam_source)) { really_returns = false; @@ -1627,8 +1617,7 @@ void spore_goes_pop(monsters *monster) beam.is_explosion = true; beam.beam_source = monster_index(monster); beam.type = dchar_glyph(DCHAR_FIRED_BURST); - beam.target_x = monster->x; - beam.target_y = monster->y; + beam.target = monster->pos(); beam.thrower = KILL_MON; // someone else's explosion beam.aux_source.clear(); diff --git a/crawl-ref/source/mtransit.cc b/crawl-ref/source/mtransit.cc index d76b3e13c3..51ca767e98 100644 --- a/crawl-ref/source/mtransit.cc +++ b/crawl-ref/source/mtransit.cc @@ -204,7 +204,7 @@ void place_transiting_items() for (item = ilist.begin(); item != ilist.end(); item++) { - coord_def pos(item->x, item->y); + coord_def pos = item->pos; if (!in_bounds(pos)) { @@ -284,7 +284,7 @@ bool follower::place(bool near_player) mprf(MSGCH_DIAGNOSTICS, "Placed follower: %s", m.name(DESC_PLAIN).c_str()); #endif - m.target_x = m.target_y = 0; + m.target.reset(); m.flags &= ~MF_TAKING_STAIRS; m.flags |= MF_JUST_SUMMONED; @@ -315,7 +315,7 @@ void follower::restore_mons_items(monsters &m) item_def &it = mitm[islot]; it = items[i]; - it.x = it.y = 0; + it.pos.reset(); it.link = NON_ITEM; } } diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 6f55fc505c..3a32194a3e 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -1286,8 +1286,7 @@ game_start: // Identify all items in pack. set_ident_type( you.inv[i], ID_KNOWN_TYPE ); // link properly - you.inv[i].x = -1; - you.inv[i].y = -1; + you.inv[i].pos.set(-1, -1); you.inv[i].link = i; you.inv[i].slot = index_to_letter(you.inv[i].link); item_colour( you.inv[i] ); // set correct special and colour diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index d6263ac742..cf73bba4ca 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -563,7 +563,7 @@ static void _get_status_lights(std::vector& out) { static char static_pos_buf[80]; snprintf(static_pos_buf, sizeof(static_pos_buf), - "%2d,%2d", you.x_pos, you.y_pos ); + "%2d,%2d", you.pos().x, you.pos().y ); out.push_back(status_light(LIGHTGREY, static_pos_buf)); static char static_hunger_buf[80]; diff --git a/crawl-ref/source/overmap.cc b/crawl-ref/source/overmap.cc index cd121b4e1c..2286632ad0 100644 --- a/crawl-ref/source/overmap.cc +++ b/crawl-ref/source/overmap.cc @@ -59,16 +59,16 @@ static void seen_staircase(dungeon_feature_type which_staircase, static void seen_other_thing(dungeon_feature_type which_thing, const coord_def& pos); -void seen_notable_thing( dungeon_feature_type which_thing, int x, int y ) +void seen_notable_thing( dungeon_feature_type which_thing, + const coord_def& pos ) { // Tell the world first. - dungeon_events.fire_position_event(DET_PLAYER_IN_LOS, coord_def(x, y)); + dungeon_events.fire_position_event(DET_PLAYER_IN_LOS, pos); // Don't record in temporary terrain if (you.level_type != LEVEL_DUNGEON) return; - const coord_def pos(x, y); const god_type god = grid_altar_god(which_thing); if (god != GOD_NO_GOD) seen_altar( god, pos ); @@ -525,8 +525,7 @@ void seen_altar( god_type god, const coord_def& pos ) void unnotice_altar() { - const coord_def pos(you.x_pos, you.y_pos); - const level_pos curpos(level_id::current(), pos); + const level_pos curpos(level_id::current(), you.pos()); // Hmm, what happens when erasing a nonexistent key directly? if (altars_present.find(curpos) != altars_present.end()) altars_present.erase(curpos); @@ -613,7 +612,7 @@ void annotate_level() level_id li = level_id::current(); level_id li2 = level_id::current(); - if (is_stair(grd[you.x_pos][you.y_pos])) + if (is_stair(grd(you.pos()))) { li2 = level_id::get_next_level_id(you.pos()); diff --git a/crawl-ref/source/overmap.h b/crawl-ref/source/overmap.h index 0f0b05780c..ea29f032bd 100644 --- a/crawl-ref/source/overmap.h +++ b/crawl-ref/source/overmap.h @@ -17,7 +17,7 @@ #include "stash.h" #include -void seen_notable_thing( dungeon_feature_type which_thing, int x, int y ); +void seen_notable_thing(dungeon_feature_type which_thing, const coord_def& pos); bool overmap_knows_portal(dungeon_feature_type portal); void display_overmap(); bool unnotice_feature(const level_pos &pos); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 3b5e0d7d7d..668adb2e5a 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -326,7 +326,7 @@ bool move_player_to_grid( const coord_def& p, bool stepped, bool allow_shift, const dungeon_feature_type type = trap_category( env.trap[id].type ); grd(you.pos()) = type; - set_envmap_obj(you.x_pos, you.y_pos, type); + set_envmap_obj(you.pos(), type); } // It's not easy to blink onto a trap without setting it off. @@ -5547,12 +5547,9 @@ void player::init() prev_targ = MHITNOT; pet_target = MHITNOT; - prev_grd_targ = coord_def(0, 0); - - x_pos = 0; - y_pos = 0; - - prev_move = coord_def(0,0); + prev_grd_targ.reset(); + position.reset(); + prev_move.reset(); running.clear(); travel_x = 0; @@ -5608,8 +5605,7 @@ void player::init() inv[i].colour = 0; set_ident_flags( inv[i], ISFLAG_IDENT_MASK ); - inv[i].x = -1; - inv[i].y = -1; + inv[i].pos.set(-1, -1); inv[i].link = i; } @@ -5677,11 +5673,6 @@ player::~player() delete m_quiver; } -coord_def player::pos() const -{ - return coord_def(x_pos, y_pos); -} - bool player::is_levitating() const { return (duration[DUR_LEVITATION]); @@ -5690,7 +5681,7 @@ bool player::is_levitating() const bool player::in_water() const { return (!airborne() && !beogh_water_walk() - && grid_is_water(grd[you.x_pos][you.y_pos])); + && grid_is_water(grd(you.pos()))); } bool player::can_swim() const @@ -6702,16 +6693,10 @@ bool player::is_icy() const return (attribute[ATTR_TRANSFORMATION] == TRAN_ICE_BEAST); } -void player::moveto(int x, int y) -{ - moveto(coord_def(x, y)); -} - void player::moveto(const coord_def &c) { const bool real_move = (c != pos()); - x_pos = c.x; - y_pos = c.y; + position = c; crawl_view.set_player_at(c); if (real_move) @@ -7011,7 +6996,7 @@ bool player::do_shaft() // the player isn't standing over a shaft. if (trap_type_at_xy(this->pos()) != TRAP_SHAFT) { - switch(grd[x_pos][y_pos]) + switch (grd(you.pos())) { case DNGN_FLOOR: case DNGN_OPEN_DOOR: diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 0cc03f80bd..c323c5b680 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -754,7 +754,7 @@ bool beogh_water_walk() static bool _need_water_walking() { return (!player_is_airborne() && you.species != SP_MERFOLK - && grd[you.x_pos][you.y_pos] == DNGN_DEEP_WATER); + && grd(you.pos()) == DNGN_DEEP_WATER); } static void _inc_penance(god_type god, int val) @@ -902,7 +902,7 @@ static bool _need_missile_gift() const item_def *launcher = _find_missile_launcher(best_missile_skill); return (you.piety > 80 && random2( you.piety ) > 70 - && !grid_destroys_items( grd[you.x_pos][you.y_pos] ) + && !grid_destroys_items( grd(you.pos()) ) && one_chance_in(8) && you.skills[ best_missile_skill ] >= 8 && (launcher || best_missile_skill == SK_DARTS) @@ -991,7 +991,7 @@ static void _show_pure_deck_chances() static void _give_nemelex_gift() { - if (grid_destroys_items(grd[you.x_pos][you.y_pos])) + if (grid_destroys_items(grd(you.pos()))) return; // Nemelex will give at least one gift early. @@ -1751,7 +1751,7 @@ static void _do_god_gift(bool prayed_for) case GOD_TROG: if (you.piety > 130 && random2(you.piety) > 120 - && !grid_destroys_items(grd[you.x_pos][you.y_pos]) + && !grid_destroys_items(grd(you.pos())) && one_chance_in(4)) { if (you.religion == GOD_TROG @@ -1863,7 +1863,7 @@ static void _do_god_gift(bool prayed_for) } if (gift != NUM_BOOKS - && !(grid_destroys_items(grd[you.x_pos][you.y_pos]))) + && !(grid_destroys_items(grd(you.pos())))) { if (gift == OBJ_RANDOM) success = acquirement(OBJ_BOOKS, you.religion); @@ -1919,8 +1919,7 @@ static bool _is_risky_sacrifice(const item_def& item) static bool _confirm_pray_sacrifice() { - if (Options.stash_tracking == STM_EXPLICIT - && is_stash(you.x_pos, you.y_pos)) + if (Options.stash_tracking == STM_EXPLICIT && is_stash(you.pos())) { mpr("You can't sacrifice explicitly marked stashes."); return (false); @@ -1994,7 +1993,7 @@ void pray() const bool was_praying = !!you.duration[DUR_PRAYER]; - const god_type altar_god = grid_altar_god(grd[you.x_pos][you.y_pos]); + const god_type altar_god = grid_altar_god(grd(you.pos())); if (altar_god != GOD_NO_GOD) { if (you.flight_mode() == FL_LEVITATE) @@ -2016,7 +2015,7 @@ void pray() mpr("Sorry, a being of your status cannot worship here."); return; } - god_pitch( grid_altar_god(grd[you.x_pos][you.y_pos]) ); + god_pitch( grid_altar_god(grd(you.pos())) ); return; } } @@ -3402,8 +3401,7 @@ static bool _tso_retribution() beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.damage = calc_dice(3, 20 + (you.experience_level * 7) / 3); beam.flavour = BEAM_HOLY; - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.name = "golden flame"; beam.colour = YELLOW; beam.thrower = KILL_MISC; @@ -4536,49 +4534,39 @@ static bool _beogh_followers_abandon_you() } else { - const int ystart = MAX(0, you.y_pos - 9); - const int yend = MIN(GYM - 1, you.y_pos + 9); - const int xstart = MAX(0, you.x_pos - 9); - const int xend = MIN(GXM - 1, you.x_pos + 9); - - // monster check - for (int y = ystart; y <= yend; ++y) + for ( radius_iterator ri(you.pos(), 9); ri; ++ri ) { - for (int x = xstart; x <= xend; ++x) + if ( mgrd(*ri) == NON_MONSTER ) + continue; + + monsters *monster = &menv[mgrd(*ri)]; + if (is_orcish_follower(monster)) { - const unsigned short targ_monst = mgrd[x][y]; - if (targ_monst != NON_MONSTER) + num_followers++; + + if (mons_player_visible(monster) + && !mons_is_sleeping(monster) + && !mons_is_confused(monster) + && !mons_cannot_act(monster)) { - monsters *monster = &menv[targ_monst]; - if (is_orcish_follower(monster)) - { - num_followers++; - - if (mons_player_visible(monster) - && !mons_is_sleeping(monster) - && !mons_is_confused(monster) - && !mons_cannot_act(monster)) - { - const int hd = monster->hit_dice; + const int hd = monster->hit_dice; - // During penance followers get a saving throw. - if (random2((you.piety-you.penance[GOD_BEOGH])/18) + - random2(you.skills[SK_INVOCATIONS]-6) - > random2(hd) + hd + random2(5)) - { - continue; - } + // During penance followers get a saving throw. + if (random2((you.piety-you.penance[GOD_BEOGH])/18) + + random2(you.skills[SK_INVOCATIONS]-6) + > random2(hd) + hd + random2(5)) + { + continue; + } - monster->attitude = ATT_HOSTILE; - behaviour_event(monster, ME_ALERT, MHITYOU); - // For now CREATED_FRIENDLY stays. + monster->attitude = ATT_HOSTILE; + behaviour_event(monster, ME_ALERT, MHITYOU); + // For now CREATED_FRIENDLY stays. - if (player_monster_visible(monster)) - num_reconvert++; // only visible ones + if (player_monster_visible(monster)) + num_reconvert++; // only visible ones - reconvert = true; - } - } + reconvert = true; } } } @@ -4945,7 +4933,9 @@ void excommunication(god_type new_god) if (!is_good_god(new_god) && _holy_beings_attitude_change()) mpr("The divine host forsakes you.", MSGCH_MONSTER_ENCHANT); - learned_something_new(TUT_EXCOMMUNICATE, (int)new_god, old_piety); + // Evil hack. + learned_something_new(TUT_EXCOMMUNICATE, + coord_def((int)new_god, old_piety)); } static bool _bless_weapon( god_type god, int brand, int colour ) @@ -5253,7 +5243,7 @@ void offer_items() if (you.religion == GOD_NO_GOD) return; - int i = igrd[you.x_pos][you.y_pos]; + int i = igrd(you.pos()); if (!god_likes_items(you.religion) && i != NON_ITEM) { diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 8610e3c7ef..8e75799d31 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -156,7 +156,7 @@ static std::string _shop_print_stock( const std::vector& stock, const shop_struct& shop, int total_cost ) { - ShopInfo &si = StashTrack.get_shop(shop.x, shop.y); + ShopInfo &si = StashTrack.get_shop(shop.pos); const bool id = shoptype_identifies_stock(shop.type); std::string purchasable; for (unsigned int i = 0; i < stock.size(); ++i) @@ -232,7 +232,7 @@ static void _in_a_shop( int shopidx ) clrscr(); - const std::string hello = "Welcome to " + shop_name(shop.pos()) + "!"; + const std::string hello = "Welcome to " + shop_name(shop.pos) + "!"; bool first = true; int total_cost = 0; @@ -240,7 +240,7 @@ static void _in_a_shop( int shopidx ) std::vector selected; while (true) { - StashTrack.get_shop(shop.x, shop.y).reset(); + StashTrack.get_shop(shop.pos).reset(); std::vector stock = _shop_get_stock(shopidx); @@ -494,8 +494,7 @@ 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, - coord_def(env.shop[shop].x, env.shop[shop].y) ); + move_item_to_grid( &item_got, env.shop[shop].pos ); return (false); } return (true); @@ -1642,7 +1641,7 @@ void shop() int i; for (i = 0; i < MAX_SHOPS; i++) - if (env.shop[i].x == you.x_pos && env.shop[i].y == you.y_pos) + if (env.shop[i].pos == you.pos()) break; if (i == MAX_SHOPS) @@ -1655,7 +1654,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.pos()).c_str()); + mprf("%s appears to be closed.", shop_name(shop.pos).c_str()); return; } @@ -1673,7 +1672,7 @@ shop_struct *get_shop(const coord_def& where) for (int shoppy = 0; shoppy < MAX_SHOPS; shoppy ++) { // find shop index plus a little bit of paranoia - if (env.shop[shoppy].pos() == where && + if (env.shop[shoppy].pos == where && env.shop[shoppy].type != SHOP_UNASSIGNED) { return (&env.shop[shoppy]); diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index 4164092c1f..5741f679f6 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, false, "Blink to where?"); - if (!beam.isValid || coord_def(beam.target()) == you.pos()) + if (!beam.isValid || 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.target())) + if (see_grid_no_trans(beam.target)) break; - else if (trans_wall_blocking( beam.target() )) + else if (trans_wall_blocking( beam.target )) { // Wizard blink can move past translucent walls. if (wizard_blink) @@ -140,11 +140,11 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink) // Allow wizard blink to send player into walls, in case the // user wants to alter that grid to something else. - if (wizard_blink && grid_is_solid(grd[beam.tx][beam.ty])) - grd[beam.tx][beam.ty] = DNGN_FLOOR; + if (wizard_blink && grid_is_solid(grd(beam.target))) + grd(beam.target) = DNGN_FLOOR; - if (grid_is_solid(grd[beam.tx][beam.ty]) - || mgrd[beam.tx][beam.ty] != NON_MONSTER) + if (grid_is_solid(grd(beam.target)) + || mgrd(beam.target) != NON_MONSTER) { mpr("Oops! Maybe something was there already."); random_blink(false); @@ -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.target(), false, true, true); + move_player_to_grid(beam.target, false, true, true); // controlling teleport contaminates the player -- bwr if (!wizard_blink) @@ -396,10 +396,8 @@ void cast_chain_lightning(int pow) pow = pow / 2 + 1; } - beam.source_x = source.x; - beam.source_y = source.y; - beam.target_x = target.x; - beam.target_y = target.y; + beam.source = source; + beam.target = target; beam.colour = LIGHTBLUE; beam.damage = calc_dice(5, 12 + pow * 2 / 3); @@ -505,27 +503,27 @@ bool conjure_flame(int pow) return (false); } - if (trans_wall_blocking(spelld.tx, spelld.ty)) + if (trans_wall_blocking(spelld.target)) { mpr("A translucent wall is in the way."); return (false); } - else if (!see_grid(spelld.tx, spelld.ty)) + else if (!see_grid(spelld.target)) { mpr("You can't see that place!"); continue; } - if (spelld.tx == you.x_pos && spelld.ty == you.y_pos) + if (spelld.target == you.pos()) { mpr("You can't place the cloud here!"); continue; } - const int cloud = env.cgrid[spelld.tx][spelld.ty]; + const int cloud = env.cgrid(spelld.target); - if (grid_is_solid(grd[ spelld.tx ][ spelld.ty ]) || - mgrd[ spelld.tx ][ spelld.ty ] != NON_MONSTER || + if (grid_is_solid(grd(spelld.target)) || + mgrd(spelld.target) != NON_MONSTER || (cloud != EMPTY_CLOUD && env.cloud[cloud].type != CLOUD_FIRE)) { mpr( "There's already something there!" ); @@ -549,7 +547,7 @@ bool conjure_flame(int pow) if (durat > 23) durat = 23; - place_cloud( CLOUD_FIRE, spelld.target(), durat, KC_YOU ); + place_cloud( CLOUD_FIRE, spelld.target, durat, KC_YOU ); return (true); } @@ -569,11 +567,10 @@ bool stinking_cloud( int pow, bolt &beem ) beem.aux_source.clear(); // Don't bother tracing if you're targetting yourself. - if (beem.target_x != you.x_pos || beem.target_y != you.y_pos) + if (beem.target != you.pos()) { // Fire tracer. - beem.source_x = you.x_pos; - beem.source_y = you.y_pos; + beem.source = you.pos(); beem.can_see_invis = player_see_invis(); beem.smart_monster = true; beem.attitude = ATT_FRIENDLY; @@ -600,29 +597,28 @@ bool stinking_cloud( int pow, bolt &beem ) int cast_big_c(int pow, cloud_type cty, kill_category whose, bolt &beam) { - big_cloud( cty, whose, - beam.target_x, beam.target_y, pow, 8 + random2(3) ); + big_cloud( cty, whose, beam.target, pow, 8 + random2(3) ); return (1); } void big_cloud(cloud_type cl_type, kill_category whose, - int cl_x, int cl_y, int pow, int size, int spread_rate) + const coord_def& where, int pow, int size, int spread_rate) { big_cloud(cl_type, whose, cloud_struct::whose_to_killer(whose), - cl_x, cl_y, pow, size, spread_rate); + where, pow, size, spread_rate); } void big_cloud(cloud_type cl_type, killer_type killer, - int cl_x, int cl_y, int pow, int size, int spread_rate) + const coord_def& where, int pow, int size, int spread_rate) { big_cloud(cl_type, cloud_struct::killer_to_whose(killer), killer, - cl_x, cl_y, pow, size, spread_rate); + where, pow, size, spread_rate); } void big_cloud(cloud_type cl_type, kill_category whose, killer_type killer, - int cl_x, int cl_y, int pow, int size, int spread_rate) + const coord_def& where, int pow, int size, int spread_rate) { - apply_area_cloud(make_a_normal_cloud, cl_x, cl_y, pow, size, + apply_area_cloud(make_a_normal_cloud, where, pow, size, cl_type, whose, killer, spread_rate); } @@ -689,14 +685,14 @@ static bool _can_pacify_monster(const monsters *mon, const int healed) return (false); } -static int _healing_spell(int healed, int target_x = -1, int target_y = -1) +static int _healing_spell(int healed, const coord_def where = coord_def(0,0)) { ASSERT(healed >= 1); bolt beam; dist spd; - if (target_x == -1 || target_y == -1) + if (where.origin()) { spd.isValid = spell_direction(spd, beam, DIR_TARGET, you.religion == GOD_ELYVILON ? @@ -705,9 +701,8 @@ static int _healing_spell(int healed, int target_x = -1, int target_y = -1) } else { - spd.tx = target_x; - spd.ty = target_y; - spd.isValid = in_bounds(spd.tx, spd.ty); + spd.target = where; + spd.isValid = in_bounds(spd.target); } if (!spd.isValid) @@ -716,14 +711,14 @@ static int _healing_spell(int healed, int target_x = -1, int target_y = -1) return (0); } - if (spd.tx == you.x_pos && spd.ty == you.y_pos) + if (spd.target == you.pos()) { mpr("You are healed."); inc_hp(healed, false); return (1); } - const int mgr = mgrd[spd.tx][spd.ty]; + const int mgr = mgrd(spd.target); if (mgr == NON_MONSTER) { @@ -802,11 +797,11 @@ char cast_greatest_healing( int pow ) } #endif -int cast_healing(int pow, int target_x, int target_y) +int cast_healing(int pow, const coord_def& where) { pow = std::min(50, pow); - return (_healing_spell(pow + roll_dice(2, pow) - 2, target_x, target_y)); + return (_healing_spell(pow + roll_dice(2, pow) - 2, where)); } void vitalisation_chain(int amount) diff --git a/crawl-ref/source/spells1.h b/crawl-ref/source/spells1.h index d2a2af9246..3df4b0f847 100644 --- a/crawl-ref/source/spells1.h +++ b/crawl-ref/source/spells1.h @@ -30,7 +30,7 @@ bool cast_sure_blade(int power); /* *********************************************************************** * called from: ability - spell * *********************************************************************** */ -int cast_healing(int pow, int target_x = -1, int target_y = -1); +int cast_healing(int pow, const coord_def& where = coord_def(-1,1)); void vitalisation_chain(int amount); void reduce_vitalisation_chain(int amount); @@ -38,28 +38,15 @@ void remove_divine_robustness(); void remove_divine_stamina(); int cast_vitalisation(int pow); -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: beam - it_use3 - spells - spells1 - * *********************************************************************** */ -void big_cloud(cloud_type cl_type, kill_category whose, int cl_x, int cl_y, +void big_cloud(cloud_type cl_type, kill_category whose, const coord_def& where, int pow, int size, int spread_rate = -1); -void big_cloud(cloud_type cl_type, killer_type killer, int cl_x, int cl_y, +void big_cloud(cloud_type cl_type, killer_type killer, const coord_def& where, int pow, int size, int spread_rate = -1); void big_cloud(cloud_type cl_type, kill_category whose, killer_type killer, - int cl_x, int cl_y, int pow, int size, int spread_rate = -1); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: acr (WIZARD only) - item_use - spell - * *********************************************************************** */ -int blink(int pow, bool high_level_controlled_blink, - bool wizard_blink = false); + const coord_def& where, int pow, int size, int spread_rate = -1); +int blink(int pow, bool high_level_controlled_blink, bool wizard_blink = false); -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ int cast_big_c(int pow, cloud_type cty, kill_category whose, bolt &beam); void cast_confusing_touch(int power); void cast_cure_poison(int mabil); @@ -76,18 +63,8 @@ void extension(int pow); bool fireball(int pow, bolt &beam); bool stinking_cloud(int pow, bolt &beam); void abjuration(int pow); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - spells1 - * *********************************************************************** */ void cast_fly(int power); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - spells1 - * *********************************************************************** */ void cast_insulation(int power); void cast_regen(int pow); void cast_resist_poison(int power); @@ -98,37 +75,10 @@ void ice_armour(int pow, bool extending); void missile_prot(int pow); void stone_scales(int pow); -// last updated sept 18 -/* *********************************************************************** - * called from: religion - * *********************************************************************** */ void antimagic(); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: acr (WIZARD only) - item_use - spell - * *********************************************************************** */ void identify(int power, int item_slot = -1); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: acr - spells1 - * *********************************************************************** */ void manage_fire_shield(void); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ void purification(void); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - decks - fight - spell - spells - spells1 - * *********************************************************************** */ void random_blink(bool, bool override_abyss = false); diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 378832cd63..8e034b8f7f 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -58,75 +58,65 @@ #include "view.h" #include "xom.h" -unsigned char detect_traps( int pow ) +int detect_traps( int pow ) { - unsigned char traps_found = 0; + int traps_found = 0; if (pow > 50) pow = 50; const int range = 8 + random2(8) + pow; - for (int count_x = 0; count_x < MAX_TRAPS; count_x++) + for (int i = 0; i < MAX_TRAPS; i++) { - const int etx = env.trap[ count_x ].x; - const int ety = env.trap[ count_x ].y; + const coord_def p = env.trap[i].pos; - // Used to just be visible screen: - // if (etx > you.x_pos - 15 && etx < you.x_pos + 15 - // && ety > you.y_pos - 8 && ety < you.y_pos + 8) - - if (grid_distance( you.x_pos, you.y_pos, etx, ety ) < range) + if (grid_distance( you.pos(), p) < range + && grd(p) == DNGN_UNDISCOVERED_TRAP) { - if (grd[ etx ][ ety ] == DNGN_UNDISCOVERED_TRAP) - { - traps_found++; + traps_found++; - grd[ etx ][ ety ] = trap_category( env.trap[count_x].type ); - set_envmap_obj(etx, ety, grd[etx][ety]); - set_terrain_mapped(etx, ety); - } + grd(p) = trap_category( env.trap[i].type ); + set_envmap_obj(p, grd(p)); + set_terrain_mapped(p); } } return (traps_found); } -unsigned char detect_items( int pow ) +int detect_items( int pow ) { if (pow > 50) pow = 50; - unsigned char items_found = 0; - const int map_radius = 8 + random2(8) + pow; - - for (int i = you.x_pos - map_radius; i < you.x_pos + map_radius; i++) - for (int j = you.y_pos - map_radius; j < you.y_pos + map_radius; j++) - { - if (!in_bounds(i, j)) - continue; + int items_found = 0; + const int map_radius = 8 + random2(8) + pow; - // Don't expose new dug out areas: - // Note: assumptions are being made here about how - // terrain can change (eg it used to be solid, and - // thus item free). - if (is_terrain_changed(i, j)) - continue; + for ( radius_iterator ri(you.pos(), map_radius, true, false); ri; ++ri ) + { - if (igrd[i][j] != NON_ITEM - && (!get_envmap_obj(i, j) || !is_envmap_item(i, j))) - { - items_found++; + // Don't expose new dug out areas: + // Note: assumptions are being made here about how + // terrain can change (eg it used to be solid, and + // thus item free). + if (is_terrain_changed(*ri)) + continue; - set_envmap_obj(i, j, DNGN_ITEM_DETECTED); - set_envmap_detected_item(i, j); + if (igrd(*ri) != NON_ITEM + && (!get_envmap_obj(*ri) || !is_envmap_item(*ri))) + { + items_found++; + + set_envmap_obj(*ri, DNGN_ITEM_DETECTED); + set_envmap_detected_item(*ri); #ifdef USE_TILE - // Don't replace previously seen items with an unseen one. - if (!is_terrain_seen(i,j)) - tile_place_tile_bk(i, j, TILE_UNSEEN_ITEM); + // Don't replace previously seen items with an unseen one. + if (!is_terrain_seen(*ri)) + tile_place_tile_bk(ri->x, ri->y, TILE_UNSEEN_ITEM); #endif - } } + } return (items_found); } @@ -149,12 +139,12 @@ static void _fuzz_detect_creatures(int pow, int *fuzz_radius, int *fuzz_chance) *fuzz_chance = 10; } -static bool _mark_detected_creature(int gridx, int gridy, const monsters *mon, +static bool _mark_detected_creature(coord_def where, const monsters *mon, int fuzz_chance, int fuzz_radius) { #ifdef USE_TILE // Get monster index pre-fuzz - int idx = mgrd[gridx][gridy]; + int idx = mgrd(where); #endif bool found_good = false; @@ -162,28 +152,28 @@ static bool _mark_detected_creature(int gridx, int gridy, const monsters *mon, if (fuzz_radius && x_chance_in_y(fuzz_chance, 100)) { const int fuzz_diam = 2 * fuzz_radius + 1; - - int gx, gy; + + coord_def place; // Try five times to find a valid placement, else we attempt to place // the monster where it really is (and may fail). for (int itry = 0; itry < 5; ++itry) { - gx = gridx + random2(fuzz_diam) - fuzz_radius; - gy = gridy + random2(fuzz_diam) - fuzz_radius; + place.set( where.x + random2(fuzz_diam) - fuzz_radius, + where.y + random2(fuzz_diam) - fuzz_radius ); // If the player would be able to see a monster at this location // don't place it there. - if (see_grid(gx, gy)) + if (see_grid(place)) continue; // Try not to overwrite another detected monster. - if (is_envmap_detected_mons(gx, gy)) + if (is_envmap_detected_mons(place)) continue; // Don't print monsters on terrain they cannot pass through, // not even if said terrain has since changed. - if (map_bounds(gx, gy) && !is_terrain_changed(gx, gy) - && mon->can_pass_through_feat(grd[gx][gy])) + if (map_bounds(place) && !is_terrain_changed(place) + && mon->can_pass_through_feat(grd(place))) { found_good = true; break; @@ -191,17 +181,14 @@ static bool _mark_detected_creature(int gridx, int gridy, const monsters *mon, } if (found_good) - { - gridx = gx; - gridy = gy; - } + where = place; } - set_envmap_obj(gridx, gridy, mon->type + DNGN_START_OF_MONSTERS); - set_envmap_detected_mons(gridx, gridy); + set_envmap_obj(where, mon->type + DNGN_START_OF_MONSTERS); + set_envmap_detected_mons(where); #ifdef USE_TILE - tile_place_monster(gridx, gridy, idx, false, true); + tile_place_monster(where.x, where.y, idx, false, true); #endif return (found_good); @@ -224,28 +211,24 @@ int detect_creatures( int pow, bool telepathic ) if (!telepathic) clear_map(false); - for (int i = you.x_pos - map_radius; i < you.x_pos + map_radius; i++) - for (int j = you.y_pos - map_radius; j < you.y_pos + map_radius; j++) + for (radius_iterator ri(you.pos(), map_radius, true, false); ri; ++ri) + { + if (mgrd(*ri) != NON_MONSTER) { - if (!in_bounds(i, j)) - continue; - - if (mgrd[i][j] != NON_MONSTER) + monsters *mon = &menv[ mgrd(*ri) ]; + creatures_found++; + + _mark_detected_creature(*ri, mon, fuzz_chance, fuzz_radius); + + // Assuming that highly intelligent spellcasters can + // detect scrying. -- bwr + if (mons_intel( mon->type ) == I_HIGH + && mons_class_flag( mon->type, M_SPELLCASTER )) { - monsters *mon = &menv[ mgrd[i][j] ]; - creatures_found++; - - _mark_detected_creature(i, j, mon, fuzz_chance, fuzz_radius); - - // Assuming that highly intelligent spellcasters can - // detect scrying. -- bwr - if (mons_intel( mon->type ) == I_HIGH - && mons_class_flag( mon->type, M_SPELLCASTER )) - { - behaviour_event( mon, ME_DISTURB, MHITYOU, you.pos() ); - } + behaviour_event( mon, ME_DISTURB, MHITYOU, you.pos() ); } } + } return (creatures_found); } @@ -254,27 +237,27 @@ int corpse_rot(int power) { UNUSED( power ); - char adx = 0; - char ady = 0; + int adx = 0; + int ady = 0; - char minx = you.x_pos - 6; - char maxx = you.x_pos + 7; - char miny = you.y_pos - 6; - char maxy = you.y_pos + 7; - char xinc = 1; - char yinc = 1; + int minx = you.pos().x - 6; + int maxx = you.pos().x + 7; + int miny = you.pos().y - 6; + int maxy = you.pos().y + 7; + int xinc = 1; + int yinc = 1; if (coinflip()) { - minx = you.x_pos + 6; - maxx = you.x_pos - 7; + minx = you.pos().x + 6; + maxx = you.pos().x - 7; xinc = -1; } if (coinflip()) { - miny = you.y_pos + 6; - maxy = you.y_pos - 7; + miny = you.pos().y + 6; + maxy = you.pos().y - 7; yinc = -1; } @@ -284,7 +267,7 @@ int corpse_rot(int power) coord_def ad(adx, ady); if (see_grid_no_trans(ad) && !is_sanctuary(ad)) { - if (igrd(ad) == NON_ITEM || env.cgrid(ad) != EMPTY_CLOUD) + if (env.cgrid(ad) != EMPTY_CLOUD) continue; for ( stack_iterator si(ad); si; ++si ) @@ -823,7 +806,7 @@ void drain_life(int pow) bool vampiric_drain(int pow, const dist &vmove) { - int mgr = mgrd[you.x_pos + vmove.dx][you.y_pos + vmove.dy]; + int mgr = mgrd(you.pos() + vmove.delta); if (mgr == NON_MONSTER) { @@ -897,7 +880,7 @@ char burn_freeze(int pow, beam_type flavour) return (-1); } - const int mgr = mgrd[you.x_pos + spd.dx][you.y_pos + spd.dy]; + const int mgr = mgrd(you.pos() + spd.delta); // Yes, this is strange, but it does maintain the original // behaviour. Possibly to avoid giving information about invisible @@ -1410,15 +1393,10 @@ bool cast_summon_elemental(int pow, god_type god, { monster_type mon = MONS_PROGRAM_BUG; - struct dist smove; - - int dir_x; - int dir_y; - int targ_x; - int targ_y; + coord_def targ; + dist smove; const int dur = std::min(2 + (random2(pow) / 5), 6); - const bool any_elemental = (restricted_type == MONS_PROGRAM_BUG); while (true) @@ -1433,14 +1411,11 @@ bool cast_summon_elemental(int pow, god_type god, return (false); } - dir_x = smove.dx; - dir_y = smove.dy; - targ_x = you.x_pos + dir_x; - targ_y = you.y_pos + dir_y; + targ = you.pos() + smove.delta; - if (mgrd[targ_x][targ_y] != NON_MONSTER) + if (mgrd(targ) != NON_MONSTER) { - if (player_monster_visible(&menv[mgrd[targ_x][targ_y]])) + if (player_monster_visible(&menv[mgrd(targ)])) mpr("There's something there already!"); else { @@ -1448,13 +1423,17 @@ bool cast_summon_elemental(int pow, god_type god, return (false); } } - else if (dir_x == 0 && dir_y == 0) + else if (smove.delta.origin()) mpr("You can't summon an elemental from yourself!"); else if ((any_elemental || restricted_type == MONS_EARTH_ELEMENTAL) - && (grd[ targ_x ][ targ_y ] == DNGN_ROCK_WALL - || grd[ targ_x ][ targ_y ] == DNGN_CLEAR_ROCK_WALL)) + && (grd(targ) == DNGN_ROCK_WALL + || grd(targ) == DNGN_CLEAR_ROCK_WALL)) { - if (targ_x <= 6 || targ_x >= 74 || targ_y <= 6 || targ_y >= 64) + const int boundary = 6; + if (targ.x <= boundary + || targ.x >= GXM - boundary + || targ.y <= boundary + || targ.y >= GYM - boundary) { mpr("That wall won't yield to your beckoning."); // XXX: Should this cost a turn? @@ -1471,29 +1450,29 @@ bool cast_summon_elemental(int pow, god_type god, if (mon == MONS_EARTH_ELEMENTAL) { - grd[targ_x][targ_y] = DNGN_FLOOR; + grd(targ) = DNGN_FLOOR; } - else if (env.cgrid[targ_x][targ_y] != EMPTY_CLOUD - && env.cloud[env.cgrid[targ_x][targ_y]].type == CLOUD_FIRE + else if (env.cgrid(targ) != EMPTY_CLOUD + && env.cloud[env.cgrid(targ)].type == CLOUD_FIRE && (any_elemental || restricted_type == MONS_FIRE_ELEMENTAL)) { mon = MONS_FIRE_ELEMENTAL; - delete_cloud(env.cgrid[targ_x][targ_y]); + delete_cloud(env.cgrid(targ)); } - else if (grd[targ_x][targ_y] == DNGN_LAVA + else if (grd(targ) == DNGN_LAVA && (any_elemental || restricted_type == MONS_FIRE_ELEMENTAL)) { mon = MONS_FIRE_ELEMENTAL; } - else if ((grd[targ_x][targ_y] == DNGN_DEEP_WATER - || grd[targ_x][targ_y] == DNGN_SHALLOW_WATER - || grd[targ_x][targ_y] == DNGN_FOUNTAIN_BLUE) + else if ((grd(targ) == DNGN_DEEP_WATER + || grd(targ) == DNGN_SHALLOW_WATER + || grd(targ) == DNGN_FOUNTAIN_BLUE) && (any_elemental || restricted_type == MONS_WATER_ELEMENTAL)) { mon = MONS_WATER_ELEMENTAL; } - else if (grd[targ_x][targ_y] >= DNGN_FLOOR - && env.cgrid[targ_x][targ_y] == EMPTY_CLOUD + else if (grd(targ) >= DNGN_FLOOR + && env.cgrid(targ) == EMPTY_CLOUD && (any_elemental || restricted_type == MONS_AIR_ELEMENTAL)) { mon = MONS_AIR_ELEMENTAL; @@ -1530,11 +1509,9 @@ bool cast_summon_elemental(int pow, god_type god, && random2(100) >= unfriendly); if (create_monster( - mgen_data(mon, - friendly ? BEH_FRIENDLY : BEH_HOSTILE, - dur, coord_def(targ_x, targ_y), - friendly ? you.pet_target : MHITYOU, - 0, god)) == -1) + mgen_data(mon, friendly ? BEH_FRIENDLY : BEH_HOSTILE, + dur, targ, friendly ? you.pet_target : MHITYOU, 0, god)) + == -1) { canned_msg(MSG_NOTHING_HAPPENS); return (false); @@ -1803,8 +1780,7 @@ bool cast_tukimas_dance(int pow, god_type god, // Copy the unwielded item. mitm[i] = you.inv[wpn]; mitm[i].quantity = 1; - mitm[i].x = 0; - mitm[i].y = 0; + mitm[i].pos.reset(); mitm[i].link = NON_ITEM; // Mark the weapon as thrown, so that we'll autograb it when the diff --git a/crawl-ref/source/spells2.h b/crawl-ref/source/spells2.h index 3f7a3a32d3..aaed99ff4e 100644 --- a/crawl-ref/source/spells2.h +++ b/crawl-ref/source/spells2.h @@ -40,134 +40,40 @@ int corpse_rot(int power); struct dist; -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ bool vampiric_drain(int pow, const dist &vmove); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ int detect_creatures( int pow, bool telepathic = false ); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ -unsigned char detect_items( int pow ); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ -unsigned char detect_traps( int pow ); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: item_use - spell - * *********************************************************************** */ +int detect_items( int pow ); +int detect_traps( int pow ); void cast_refrigeration(int pow); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: item_use - spell - * *********************************************************************** */ void cast_toxic_radiance(void); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - * *********************************************************************** */ void drain_life(int pow); - - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - food - it_use2 - spell - * returns TRUE if a stat was restored. - * *********************************************************************** */ bool restore_stat(unsigned char which_stat, unsigned char stat_gain, bool suppress_msg, bool recovery = false); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: spell - * *********************************************************************** */ bool summon_animals(int pow); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ bool cast_summon_butterflies(int pow, god_type god = GOD_NO_GOD); bool cast_summon_small_mammals(int pow, god_type god = GOD_NO_GOD); bool cast_sticks_to_snakes(int pow, god_type god = GOD_NO_GOD); bool cast_summon_scorpions(int pow, god_type god = GOD_NO_GOD); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - religion - spell - * *********************************************************************** */ bool cast_summon_swarm(int pow, god_type god = GOD_NO_GOD, bool force_hostile = false); -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ bool cast_call_canine_familiar(int pow, god_type god = GOD_NO_GOD); -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: it_use3 - spell - * *********************************************************************** */ bool cast_summon_elemental(int pow, god_type god = GOD_NO_GOD, monster_type restricted_type = MONS_PROGRAM_BUG, int unfriendly = 2); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ bool cast_summon_ice_beast(int pow, god_type god = GOD_NO_GOD); bool cast_summon_ugly_thing(int pow, god_type god = GOD_NO_GOD); bool cast_summon_dragon(int pow, god_type god = GOD_NO_GOD); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ bool summon_berserker(int pow, god_type god = GOD_NO_GOD, bool force_hostile = false); bool summon_guardian(int pow, god_type god = GOD_NO_GOD, bool quiet = false); bool summon_daeva(int pow, god_type god = GOD_NO_GOD, bool quiet = false); -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - religion - spell - * *********************************************************************** */ bool cast_tukimas_dance(int pow, god_type god = GOD_NO_GOD, bool force_hostile = false); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ bool cast_conjure_ball_lightning(int pow, god_type god = GOD_NO_GOD); - -// last updated 24may2000 {dlb} -/* *********************************************************************** - * called from: ability - spell - * *********************************************************************** */ void turn_undead(int pow); // what should I use for pow? diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc index 333b66f08f..18bf5742e4 100644 --- a/crawl-ref/source/spells3.cc +++ b/crawl-ref/source/spells3.cc @@ -198,11 +198,11 @@ int cast_smiting(int power, dist &beam) { bool success = false; - if (mgrd[beam.tx][beam.ty] == NON_MONSTER || beam.isMe) + if (mgrd(beam.target) == NON_MONSTER || beam.isMe) canned_msg(MSG_SPELL_FIZZLES); else { - monsters *monster = &menv[mgrd[beam.tx][beam.ty]]; + monsters *monster = &menv[mgrd(beam.target)]; god_conduct_trigger conducts[3]; disable_attack_conducts(conducts); @@ -243,11 +243,11 @@ int airstrike(int power, dist &beam) { bool success = false; - if (mgrd[beam.tx][beam.ty] == NON_MONSTER || beam.isMe) + if (mgrd(beam.target) == NON_MONSTER || beam.isMe) canned_msg(MSG_SPELL_FIZZLES); else { - monsters *monster = &menv[mgrd[beam.tx][beam.ty]]; + monsters *monster = &menv[mgrd(beam.target)]; god_conduct_trigger conducts[3]; disable_attack_conducts(conducts); @@ -1324,15 +1324,15 @@ static bool _teleport_player( bool allow_control, bool new_abyss_area ) if (is_controlled) { // no longer held in net - if (pos.x != you.x_pos || pos.y != you.y_pos) + if (pos != you.pos()) clear_trapping_net(); - you.moveto(pos.x, pos.y); + you.moveto(pos); - if (grd[you.x_pos][you.y_pos] != DNGN_FLOOR - && grd[you.x_pos][you.y_pos] != DNGN_SHALLOW_WATER - || mgrd[you.x_pos][you.y_pos] != NON_MONSTER - || env.cgrid[you.x_pos][you.y_pos] != EMPTY_CLOUD) + if (grd(you.pos()) != DNGN_FLOOR + && grd(you.pos()) != DNGN_SHALLOW_WATER + || mgrd(you.pos()) != NON_MONSTER + || env.cgrid(you.pos()) != EMPTY_CLOUD) { is_controlled = false; } @@ -1346,31 +1346,30 @@ static bool _teleport_player( bool allow_control, bool new_abyss_area ) if (!is_controlled) { - int newx, newy; + coord_def newpos; do { - newx = random_range(X_BOUND_1 + 1, X_BOUND_2 - 1); - newy = random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1); + newpos.set( random_range(X_BOUND_1 + 1, X_BOUND_2 - 1), + random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1) ); } - while (grd[newx][newy] != DNGN_FLOOR - && grd[newx][newy] != DNGN_SHALLOW_WATER - || mgrd[newx][newy] != NON_MONSTER - || env.cgrid[newx][newy] != EMPTY_CLOUD); + while (grd(newpos) != DNGN_FLOOR + && grd(newpos) != DNGN_SHALLOW_WATER + || mgrd(newpos) != NON_MONSTER + || env.cgrid(newpos) != EMPTY_CLOUD); // no longer held in net - if (newx != you.x_pos || newy != you.y_pos) + if (newpos != you.pos()) clear_trapping_net(); - if ( newx == you.x_pos && newy == you.y_pos ) + if ( newpos == you.pos() ) mpr("Your surroundings flicker for a moment."); - else if ( see_grid(newx, newy) ) + else if ( see_grid(newpos) ) mpr("Your surroundings seem slightly different."); else mpr("Your surroundings suddenly seem different."); - you.x_pos = newx; - you.y_pos = newy; + you.position = newpos; // Necessary to update the view centre. you.moveto(you.pos()); @@ -1412,85 +1411,59 @@ bool entomb(int powc) DNGN_FLOOR_SPECIAL }; - for (int srx = you.x_pos - 1; srx < you.x_pos + 2; srx++) - for (int sry = you.y_pos - 1; sry < you.y_pos + 2; sry++) - { - // Tile already occupied by monster or yourself {dlb}: - if (mgrd[srx][sry] != NON_MONSTER - || srx == you.x_pos && sry == you.y_pos) - { - continue; - } - - if ( one_chance_in(powc/5) ) - continue; - - bool proceed = false; - for (unsigned int i = 0; i < ARRAYSZ(safe_to_overwrite); ++i) - { - if (grd[srx][sry] == safe_to_overwrite[i]) - { - proceed = true; - break; - } - } - - // checkpoint one - do we have a legitimate tile? {dlb} - if (!proceed) - continue; - - int objl = igrd[srx][sry]; - int hrg = 0; - - while (objl != NON_ITEM) - { - // hate to see the orb get destroyed by accident {dlb}: - if (mitm[objl].base_type == OBJ_ORBS) - { - proceed = false; - break; - } - - hrg = mitm[objl].link; - objl = hrg; - } + for ( adjacent_iterator ai; ai; ++ai ) + { + // Tile already occupied by monster + if (mgrd(*ai) != NON_MONSTER) + continue; - // checkpoint two - is the orb resting in the tile? {dlb}: - if (!proceed) - continue; + // This is where power comes in. + if ( one_chance_in(powc/5) ) + continue; - objl = igrd[srx][sry]; - hrg = 0; + bool proceed = false; + for (unsigned int i=0; i < ARRAYSZ(safe_to_overwrite) && !proceed; ++i) + if (grd(*ai) == safe_to_overwrite[i]) + proceed = true; - while (objl != NON_ITEM) - { - hrg = mitm[objl].link; - destroy_item(objl); - objl = hrg; - } + // checkpoint one - do we have a legitimate tile? {dlb} + if (!proceed) + continue; - // deal with clouds {dlb}: - if (env.cgrid[srx][sry] != EMPTY_CLOUD) - delete_cloud( env.cgrid[srx][sry] ); + // hate to see the orb get destroyed by accident {dlb}: + for ( stack_iterator si(*ai); si && proceed; ++si ) + if (si->base_type == OBJ_ORBS) + proceed = false; - // mechanical traps are destroyed {dlb}: - int which_trap; - if ((which_trap = trap_at_xy(coord_def(srx, sry))) != -1) + // checkpoint two - is the orb resting in the tile? {dlb}: + if (!proceed) + continue; + + // Destroy all items on the square. + for ( stack_iterator si(*ai); si; ++si ) + destroy_item(si->index()); + + // deal with clouds {dlb}: + if (env.cgrid(*ai) != EMPTY_CLOUD) + delete_cloud( env.cgrid(*ai) ); + + // mechanical traps are destroyed {dlb}: + int which_trap = trap_at_xy(*ai); + if ( which_trap != -1 ) + { + trap_struct& trap(env.trap[which_trap]); + if (trap_category(trap.type) == DNGN_TRAP_MECHANICAL) { - if (trap_category(env.trap[which_trap].type) - == DNGN_TRAP_MECHANICAL) - { - env.trap[which_trap].type = TRAP_UNASSIGNED; - env.trap[which_trap].x = 1; - env.trap[which_trap].y = 1; - } + trap.type = TRAP_UNASSIGNED; + trap.pos.set(1,1); } - - // Finally, place the wall {dlb}: - grd[srx][sry] = DNGN_ROCK_WALL; - number_built++; } + // Finally, place the wall {dlb}: + grd(*ai) = DNGN_ROCK_WALL; + number_built++; + } + if (number_built > 0) { mpr("Walls emerge from the floor!"); @@ -1518,21 +1491,21 @@ bool entomb(int powc) canned_msg(MSG_NOTHING_HAPPENS); return (number_built > 0); -} // end entomb() +} -// Is (posx, posy) inside a circle within LOS, with the given radius, +// Is where inside a circle within LOS, with the given radius, // centered on the player's position? If so, return the distance to it. // Otherwise, return -1. -static int _inside_circle(int posx, int posy, int radius) +static int _inside_circle(const coord_def& where, int radius) { - if (!inside_level_bounds(posx, posy)) + if (!inside_level_bounds(where)) return -1; - const coord_def ep = grid2view(coord_def(posx, posy)); + const coord_def ep = grid2view(where); if (!in_los_bounds(ep)) return -1; - int dist = distance(posx, posy, you.x_pos, you.y_pos); + const int dist = distance(where, you.pos()); if (dist > radius*radius) return -1; @@ -1642,8 +1615,7 @@ bool cast_sanctuary(const int power) delay(1000); #endif - env.sanctuary_pos.x = you.x_pos; - env.sanctuary_pos.y = you.y_pos; + env.sanctuary_pos = you.pos(); env.sanctuary_time = 7 + you.skills[SK_INVOCATIONS]/2; // Pets stop attacking and converge on you. @@ -1659,100 +1631,93 @@ bool cast_sanctuary(const int power) int cloud_count = 0; monsters *seen_mon = NULL; - for (int x = -radius; x <= radius; x++) - for (int y = -radius; y <= radius; y++) - { - int posx = you.x_pos + x; - int posy = you.y_pos + y; - int dist = _inside_circle(posx, posy, radius); - - if (dist == -1) - continue; - - coord_def pos(posx, posy); - if (env.map(pos).property == FPROP_BLOODY - && see_grid(pos)) - { - blood_count++; - } + for ( radius_iterator ri(you.pos(), radius, false, false); ri; ++ri ) + { + int dist = _inside_circle(*ri, radius); + + if (dist == -1) + continue; - if (trap_type_at_xy(pos) != NUM_TRAPS - && grd(pos) == DNGN_UNDISCOVERED_TRAP) - { - const dungeon_feature_type type = - trap_category( trap_type_at_xy(pos) ); - grd(pos) = type; - set_envmap_obj(posx, posy, type); - trap_count++; - } + const coord_def pos = *ri; + if (env.map(pos).property == FPROP_BLOODY && see_grid(pos)) + blood_count++; - // forming patterns - if (pattern == 0 // outward rays - && (x == 0 || y == 0 || x == y || x == -y) - || pattern == 1 // circles - && (dist >= (radius-1)*(radius-1) && dist <= radius*radius - || dist >= (radius/2-1)*(radius/2-1) - && dist <= radius*radius/4) - || pattern == 2 // latticed - && (x%2 == 0 || y%2 == 0) - || pattern == 3 // cross-like - && (abs(x)+abs(y) < 5 && x != y && x != -y)) + if (trap_type_at_xy(pos) != NUM_TRAPS + && grd(pos) == DNGN_UNDISCOVERED_TRAP) + { + const dungeon_feature_type type = + trap_category( trap_type_at_xy(pos) ); + grd(pos) = type; + set_envmap_obj(pos, type); + trap_count++; + } + + // forming patterns + const int x = pos.x - you.pos().x, y = pos.y - you.pos().y; + if (pattern == 0 // outward rays + && (x == 0 || y == 0 || x == y || x == -y) + || pattern == 1 // circles + && (dist >= (radius-1)*(radius-1) && dist <= radius*radius + || dist >= (radius/2-1)*(radius/2-1) + && dist <= radius*radius/4) + || pattern == 2 // latticed + && (x%2 == 0 || y%2 == 0) + || pattern == 3 // cross-like + && (abs(x)+abs(y) < 5 && x != y && x != -y)) + { + env.map(pos).property = FPROP_SANCTUARY_1; // yellow + } + else + env.map(pos).property = FPROP_SANCTUARY_2; // white + + // scare all attacking monsters inside sanctuary, and make + // all friendly monsters inside sanctuary stop attacking and + // move towards the player. + int monster = mgrd(pos); + if (monster != NON_MONSTER) + { + monsters* mon = &menv[monster]; + + if (mons_friendly(mon)) { - env.map[posx][posy].property = FPROP_SANCTUARY_1; // yellow + mon->foe = MHITYOU; + mon->target = you.pos(); + mon->behaviour = BEH_SEEK; + behaviour_event(mon, ME_EVAL, MHITYOU); } - else - env.map[posx][posy].property = FPROP_SANCTUARY_2; // white - - // scare all attacking monsters inside sanctuary, and make - // all friendly monsters inside sanctuary stop attacking and - // move towards the player. - int monster = mgrd[posx][posy]; - if (monster != NON_MONSTER) + else if (!mons_wont_attack(mon)) { - monsters* mon = &menv[monster]; - - if (mons_friendly(mon)) + if (mons_is_mimic(mon->type)) { - mon->foe = MHITYOU; - mon->target_x = you.x_pos; - mon->target_y = you.y_pos; - mon->behaviour = BEH_SEEK; - behaviour_event(mon, ME_EVAL, MHITYOU); - } - else if (!mons_wont_attack(mon)) - { - if (mons_is_mimic(mon->type)) + mimic_alert(mon); + if(you.can_see(mon)) { - mimic_alert(mon); - if(you.can_see(mon)) - { - scare_count++; - seen_mon = mon; - } + scare_count++; + seen_mon = mon; } - else if (mon->add_ench(mon_enchant(ENCH_FEAR, 0, - KC_YOU))) + } + else if (mon->add_ench(mon_enchant(ENCH_FEAR, 0, KC_YOU))) + { + behaviour_event(mon, ME_SCARE, MHITYOU); + + // Check to see that monster is actually fleeing, + // since plants can't flee. + if (mons_is_fleeing(mon) && you.can_see(mon)) { - behaviour_event(mon, ME_SCARE, MHITYOU); - - // Check to see that monster is actually fleeing, - // since plants can't flee. - if (mons_is_fleeing(mon) && you.can_see(mon)) - { - scare_count++; - seen_mon = mon; - } + scare_count++; + seen_mon = mon; } } - } // if (monster != NON_MONSTER) - - if (!is_harmless_cloud(cloud_type_at(pos))) - { - delete_cloud(env.cgrid[posx][posy]); - if (see_grid(pos)) - cloud_count++; } - } // radius loop + } // if (monster != NON_MONSTER) + + if (!is_harmless_cloud(cloud_type_at(pos))) + { + delete_cloud(env.cgrid(pos)); + if (see_grid(pos)) + cloud_count++; + } + } // radius loop if (trap_count > 0) { @@ -1796,15 +1761,15 @@ int halo_radius() return 0; } -bool inside_halo(int posx, int posy) +bool inside_halo(const coord_def& where) { if (!halo_radius()) return (false); - return (_inside_circle(posx, posy, halo_radius()) != -1); + return (_inside_circle(where, halo_radius()) != -1); } -void cast_poison_ammo(void) +void cast_poison_ammo() { const int ammo = you.equip[EQ_WEAPON]; @@ -1887,10 +1852,7 @@ bool recall(char type_recalled) int step_value = 1; int end_count = (MAX_MONSTERS - 1); - FixedVector < char, 2 > empty; - struct monsters *monster = 0; // NULL {dlb} - - empty[0] = empty[1] = 0; + monsters *monster = 0; // someone really had to make life difficult {dlb}: // sometimes goes through monster list backwards @@ -1929,8 +1891,9 @@ bool recall(char type_recalled) continue; } - if (empty_surrounds(you.x_pos, you.y_pos, DNGN_FLOOR, 3, false, empty) - && monster->move_to_pos( coord_def(empty[0], empty[1])) ) + coord_def empty; + if (empty_surrounds(you.pos(), DNGN_FLOOR, 3, false, empty) + && monster->move_to_pos( empty ) ) { // only informed if monsters recalled are visible {dlb}: if (simple_monster_message(monster, " is recalled.")) @@ -1955,7 +1918,7 @@ int portal() mpr("This spell doesn't work here."); return (-1); } - else if (grd[you.x_pos][you.y_pos] != DNGN_FLOOR) + else if (grd(you.pos()) != DNGN_FLOOR) { mpr("You must find a clear area in which to cast this spell."); return (-1); diff --git a/crawl-ref/source/spells3.h b/crawl-ref/source/spells3.h index a8485037c2..5878b014d1 100644 --- a/crawl-ref/source/spells3.h +++ b/crawl-ref/source/spells3.h @@ -63,7 +63,7 @@ bool remove_sanctuary(bool did_attack = false); void decrease_sanctuary_radius(void); bool cast_sanctuary(const int power); int halo_radius(void); -bool inside_halo(int posx, int posy); +bool inside_halo(const coord_def& where); // updated 24may2000 {dlb} /* *********************************************************************** diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index 4162e14e37..31b1ad7c4c 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -378,21 +378,12 @@ void cast_detect_secret_doors(int pow) { int found = 0; - for (int x = you.x_pos - 8; x <= you.x_pos + 8; x++) + for ( radius_iterator ri(you.pos(), 8); ri; ++ri ) { - for (int y = you.y_pos - 8; y <= you.y_pos + 8; y++) + if (grd(*ri) == DNGN_SECRET_DOOR && random2(pow) > random2(15)) { - if (x < 5 || x > GXM - 5 || y < 5 || y > GYM - 5) - continue; - - if (!see_grid(x, y)) - continue; - - if (grd[x][y] == DNGN_SECRET_DOOR && random2(pow) > random2(15)) - { - reveal_secret_door(x, y); - found++; - } + reveal_secret_door(*ri); + found++; } } @@ -1078,14 +1069,14 @@ static int _make_a_rot_cloud(const coord_def& where, int pow, cloud_type ctype) return 0; } -int make_a_normal_cloud(int x, int y, int pow, int spread_rate, +int make_a_normal_cloud(coord_def where, int pow, int spread_rate, cloud_type ctype, kill_category whose, killer_type killer) { if (killer == KILL_NONE) killer = cloud_struct::whose_to_killer(whose); - place_cloud( ctype, coord_def(x, y), + place_cloud( ctype, where, (3 + random2(pow / 4) + random2(pow / 4) + random2(pow / 4)), whose, killer, spread_rate ); @@ -1096,9 +1087,6 @@ static int _passwall(coord_def where, int pow, int garbage) { UNUSED( garbage ); - int x = where.x, y = where.y; - - int dx, dy, nx = x, ny = y; int howdeep = 0; bool done = false; int shallow = 1 + (you.skills[SK_EARTH_MAGIC] / 8); @@ -1109,27 +1097,27 @@ static int _passwall(coord_def where, int pow, int garbage) // are used for impassable walls... I'm not sure we should // even allow statues (should be contiguous rock). -- bwr // XXX: Allow statues as entry points? - if (grd[x][y] != DNGN_ROCK_WALL && grd[x][y] != DNGN_CLEAR_ROCK_WALL) + if (grd(where) != DNGN_ROCK_WALL && grd(where) != DNGN_CLEAR_ROCK_WALL) { mpr("That's not a passable wall."); return 0; } - dx = x - you.x_pos; - dy = y - you.y_pos; + coord_def delta = where - you.pos(); + coord_def n = where; while (!done) { - if (!in_bounds(nx, ny)) + if (!in_bounds(n)) { mpr("You sense an overwhelming volume of rock."); return 0; } - switch (grd[nx][ny]) + switch (grd(n)) { default: - if (grid_is_solid(grd[nx][ny])) + if (grid_is_solid(grd(n))) non_rock_barriers = true; done = true; break; @@ -1139,8 +1127,7 @@ static int _passwall(coord_def where, int pow, int garbage) case DNGN_ORCISH_IDOL: case DNGN_GRANITE_STATUE: case DNGN_SECRET_DOOR: - nx += dx; - ny += dy; + n += delta; howdeep++; break; } @@ -1172,7 +1159,7 @@ static int _passwall(coord_def where, int pow, int garbage) } // Passwall delay is reduced, and the delay cannot be interrupted. - start_delay( DELAY_PASSWALL, 1 + howdeep, nx, ny ); + start_delay( DELAY_PASSWALL, 1 + howdeep, n.x, n.y ); return 1; } // end passwall() @@ -1397,8 +1384,7 @@ bool cast_evaporate(int pow, bolt& beem, int potion) } // Fire tracer. - beem.source_x = you.x_pos; - beem.source_y = you.y_pos; + beem.source = you.pos(); beem.can_see_invis = player_see_invis(); beem.smart_monster = true; beem.attitude = ATT_FRIENDLY; @@ -1684,7 +1670,7 @@ void do_monster_rot(int mon) if (mons_holiness(&menv[mon]) == MH_UNDEAD && !one_chance_in(5)) { - apply_area_cloud(make_a_normal_cloud, menv[mon].x, menv[mon].y, + apply_area_cloud(make_a_normal_cloud, menv[mon].pos(), 10, 1, CLOUD_MIASMA, KC_YOU, KILL_YOU_MISSILE); } @@ -1744,8 +1730,7 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike beam.ex_size = 1; // default beam.type = '#'; beam.colour = 0; - beam.source_x = you.x_pos; - beam.source_y = you.y_pos; + beam.source = you.pos(); beam.flavour = BEAM_FRAG; beam.hit = AUTOMATIC_HIT; beam.is_tracer = false; @@ -1755,10 +1740,8 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike // Number of dice vary... 3 is easy/common, but it can get as high as 6. beam.damage = dice_def(0, 5 + pow / 10); - const int grid = grd[spd.tx][spd.ty]; - const int mon = mgrd[spd.tx][spd.ty]; - - const bool okay_to_dest = in_bounds(spd.target()); + const dungeon_feature_type grid = grd(spd.target); + const int mon = mgrd(spd.target); if (mon != NON_MONSTER) { @@ -1929,19 +1912,18 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike if (beam.colour == 0) beam.colour = LIGHTGREY; - if (okay_to_dest - && (grid == DNGN_ORCISH_IDOL - || grid == DNGN_GRANITE_STATUE - || pow >= 40 && grid == DNGN_ROCK_WALL && one_chance_in(3) - || pow >= 40 && grid == DNGN_CLEAR_ROCK_WALL - && one_chance_in(3) - || pow >= 60 && grid == DNGN_STONE_WALL && one_chance_in(10) - || pow >= 60 && grid == DNGN_CLEAR_STONE_WALL - && one_chance_in(10))) + if ((grid == DNGN_ORCISH_IDOL + || grid == DNGN_GRANITE_STATUE + || pow >= 40 && grid == DNGN_ROCK_WALL && one_chance_in(3) + || pow >= 40 && grid == DNGN_CLEAR_ROCK_WALL + && one_chance_in(3) + || pow >= 60 && grid == DNGN_STONE_WALL && one_chance_in(10) + || pow >= 60 && grid == DNGN_CLEAR_STONE_WALL + && one_chance_in(10))) { // terrain blew up real good: beam.ex_size = 2; - grd[spd.tx][spd.ty] = DNGN_FLOOR; + grd(spd.target) = DNGN_FLOOR; debris = DEBRIS_ROCK; } break; @@ -1957,10 +1939,10 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike beam.name = "blast of metal fragments"; beam.damage.num = 4; - if (okay_to_dest && pow >= 80 && x_chance_in_y(pow / 5, 500)) + if (pow >= 80 && x_chance_in_y(pow / 5, 500)) { beam.damage.num += 2; - grd[spd.tx][spd.ty] = DNGN_FLOOR; + grd(spd.target) = DNGN_FLOOR; debris = DEBRIS_METAL; } break; @@ -1977,10 +1959,10 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike beam.name = "blast of crystal shards"; beam.damage.num = 5; - if (okay_to_dest && grid == DNGN_GREEN_CRYSTAL_WALL && coinflip()) + if (grid == DNGN_GREEN_CRYSTAL_WALL && coinflip()) { beam.ex_size = coinflip() ? 3 : 2; - grd[spd.tx][spd.ty] = DNGN_FLOOR; + grd(spd.target) = DNGN_FLOOR; debris = DEBRIS_CRYSTAL; } break; @@ -1991,7 +1973,7 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike case DNGN_UNDISCOVERED_TRAP: case DNGN_TRAP_MECHANICAL: - trap = trap_at_xy(spd.target()); + trap = trap_at_xy(spd.target); if (trap != -1 && trap_category(env.trap[trap].type) != DNGN_TRAP_MECHANICAL) { @@ -2009,11 +1991,8 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike beam.damage.num = 2; // Exploded traps are nonfunctional, ammo is also ruined -- bwr - if (okay_to_dest) - { - grd[spd.tx][spd.ty] = DNGN_FLOOR; - env.trap[trap].type = TRAP_UNASSIGNED; - } + grd(spd.target) = DNGN_FLOOR; + env.trap[trap].type = TRAP_UNASSIGNED; break; // @@ -2023,8 +2002,7 @@ void cast_fragmentation(int pow) // jmf: ripped idea from airstrike case DNGN_OPEN_DOOR: case DNGN_CLOSED_DOOR: // Doors always blow up, stone arches never do (would cause problems). - if (okay_to_dest) - grd[spd.tx][spd.ty] = DNGN_FLOOR; + grd(spd.target) = DNGN_FLOOR; // fall-through case DNGN_STONE_ARCH: // Floor -- small explosion. @@ -2084,7 +2062,7 @@ void cast_twist(int pow) if (!spell_direction(targ, tmp, DIR_TARGET)) return; - const int mons = mgrd[ targ.tx ][ targ.ty ]; + const int mons = mgrd(targ.target); // Anything there? if (mons == NON_MONSTER || targ.isMe) @@ -2121,14 +2099,14 @@ bool cast_portal_projectile(int pow) if (item == -1) return (false); - if (grid_is_solid(target.tx, target.ty)) + if (grid_is_solid(target.target)) { mpr("You can't shoot at gazebos."); return (false); } // Can't use portal through walls. (That'd be just too cheap!) - if (trans_wall_blocking( target.tx, target.ty )) + if (trans_wall_blocking( target.target )) { mpr("A translucent wall is in the way."); return (false); @@ -2168,13 +2146,13 @@ void cast_far_strike(int pow) return; // Get the target monster... - if (mgrd[targ.tx][targ.ty] == NON_MONSTER || targ.isMe) + if (mgrd(targ.target) == NON_MONSTER || targ.isMe) { mpr("There is no monster there!"); return; } - if (trans_wall_blocking( targ.tx, targ.ty )) + if (trans_wall_blocking( targ.target )) { mpr("A translucent wall is in the way."); return; @@ -2241,7 +2219,7 @@ void cast_far_strike(int pow) damage *= dammod; damage /= 78; - monsters *monster = &menv[ mgrd[targ.tx][targ.ty] ]; + monsters *monster = &menv[ mgrd(targ.target) ]; // Apply monster's AC. if (monster->ac > 0) @@ -2290,14 +2268,14 @@ int cast_apportation(int pow) return (-1); } - if (trans_wall_blocking( beam.tx, beam.ty )) + if (trans_wall_blocking( beam.target )) { mpr("A translucent wall is in the way."); return (0); } // Protect the player from destroying the item - const dungeon_feature_type grid = grd[ you.x_pos ][ you.y_pos ]; + const dungeon_feature_type grid = grd(you.pos()); if (grid_destroys_items(grid)) { @@ -2315,17 +2293,17 @@ int cast_apportation(int pow) // of sight to the object first so it will only help a little // with snatching runes or the orb (although it can be quite // useful for getting items out of statue rooms or the abyss). -- bwr - if (!see_grid( beam.tx, beam.ty )) + if (!see_grid( beam.target )) { mpr( "You cannot see there!" ); return (0); } // Let's look at the top item in that square... - const int item = igrd[ beam.tx ][ beam.ty ]; + const int item = igrd(beam.target); if (item == NON_ITEM) { - const int mon = mgrd[ beam.tx ][ beam.ty ]; + const int mon = mgrd(beam.target); if (mon == NON_MONSTER) mpr( "There are no items there." ); @@ -2363,7 +2341,7 @@ int cast_apportation(int pow) // Failure should never really happen after all the above checking, // but we'll handle it anyways... - if (move_top_item( beam.target(), you.pos() )) + if (move_top_item( beam.target, you.pos() )) { if (max_units < mitm[ item ].quantity) { @@ -2383,11 +2361,11 @@ int cast_apportation(int pow) && mitm[item].sub_type == MI_THROWING_NET && item_is_stationary(mitm[item])) { - const int mon = mgrd[ beam.tx ][ beam.ty ]; - remove_item_stationary(mitm[item]); + const int mon = mgrd(beam.target); + remove_item_stationary(mitm[item]); - if (mon != NON_MONSTER) - (&menv[mon])->del_ench(ENCH_HELD, true); + if (mon != NON_MONSTER) + (&menv[mon])->del_ench(ENCH_HELD, true); } } else diff --git a/crawl-ref/source/spells4.h b/crawl-ref/source/spells4.h index a98d295e4e..74119aa1b4 100644 --- a/crawl-ref/source/spells4.h +++ b/crawl-ref/source/spells4.h @@ -19,15 +19,15 @@ struct bolt; bool backlight_monsters(coord_def where, int pow, int garbage); -int make_a_normal_cloud(int x, int y, int pow, int spread_rate, +int make_a_normal_cloud(coord_def where, int pow, int spread_rate, cloud_type ctype, kill_category, killer_type killer = KILL_NONE); int disperse_monsters(coord_def where, int pow, int message); void cast_bend(int pow); void cast_condensation_shield(int pow); -void remove_divine_shield(void); -void cast_divine_shield(void); +void remove_divine_shield(); +void cast_divine_shield(); void cast_detect_secret_doors(int pow); void cast_discharge(int pow); bool cast_evaporate(int pow, bolt& beem, int potion); diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index aebcbba27b..3997032251 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -958,14 +958,12 @@ static void _try_monster_cast(spell_type spell, int powc, | MF_WAS_IN_VIEW | MF_HARD_RESET); mon->hit_points = you.hp; mon->hit_dice = you.experience_level; - mon->x = you.x_pos; - mon->y = you.y_pos; - mon->target_x = spd.tx; - mon->target_y = spd.ty; + mon->pos() = you.pos(); + mon->target = spd.target; if (!spd.isTarget) mon->foe = MHITNOT; - else if (mgrd[spd.tx][spd.ty] == NON_MONSTER) + else if (mgrd(spd.target) == NON_MONSTER) { if (spd.isMe) mon->foe = MHITYOU; @@ -973,7 +971,7 @@ static void _try_monster_cast(spell_type spell, int powc, mon->foe = MHITNOT; } else - mon->foe = mgrd[spd.tx][spd.ty]; + mon->foe = mgrd(spd.target); mgrd(you.pos()) = midx; @@ -1702,7 +1700,7 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail) break; case SPELL_BANISHMENT: - if (beam.target_x == you.x_pos && beam.target_y == you.y_pos) + if (beam.target == you.pos()) { mpr("You cannot banish yourself!"); break; @@ -2504,11 +2502,9 @@ void MiscastEffect::do_miscast() // Do this here since multiple miscasts (wizmode testing) might move // the target around. - beam.source_x = target->pos().x; - beam.source_y = target->pos().y; - beam.target_x = target->pos().x; - beam.target_y = target->pos().y; - beam.pos = target->pos(); + beam.source = target->pos(); + beam.target = target->pos(); + beam.pos = target->pos(); all_msg = you_msg = mon_msg = mon_msg_seen = mon_msg_unseen = ""; msg_ch = MSGCH_PLAIN; @@ -2810,8 +2806,7 @@ void MiscastEffect::_conjuration(int severity) mon_msg_unseen = "Smoke appears from out of nowhere!"; do_msg(); - big_cloud( CLOUD_GREY_SMOKE, kc, kt, - target->pos().x, target->pos().y, + big_cloud( CLOUD_GREY_SMOKE, kc, kt, target->pos(), 20, 7 + random2(7) ); break; case 1: @@ -2839,7 +2834,6 @@ void MiscastEffect::_conjuration(int severity) beam.damage = dice_def( 3, 12 ); beam.flavour = BEAM_MISSILE; // unsure about this // BEAM_EXPLOSION instead? {dlb} - beam.name = "explosion"; beam.colour = random_colour(); @@ -3888,7 +3882,7 @@ void MiscastEffect::_fire(int severity) do_msg(); big_cloud( random_smoke_type(), kc, kt, - target->pos().x, target->pos().y, 20, 7 + random2(7) ); + target->pos(), 20, 7 + random2(7) ); break; case 1: @@ -4075,7 +4069,6 @@ void MiscastEffect::_ice(int severity) beam.flavour = BEAM_COLD; beam.name = "explosion"; beam.colour = WHITE; - _explosion(); break; } @@ -4099,7 +4092,7 @@ void MiscastEffect::_ice(int severity) do_msg(); big_cloud(CLOUD_COLD, kc, kt, - target->pos().x, target->pos().y, 20, 8 + random2(4)); + target->pos(), 20, 8 + random2(4)); break; } break; @@ -4343,8 +4336,7 @@ void MiscastEffect::_air(int severity) mon_msg_unseen = "Noxious gasses appear from out of thin air!"; do_msg(); - big_cloud(CLOUD_STINK, kc, kt, - target->pos().x, target->pos().y, 20, 9 + random2(4)); + big_cloud(CLOUD_STINK, kc, kt, target->pos(), 20, 9 + random2(4)); break; } break; @@ -4376,8 +4368,7 @@ void MiscastEffect::_air(int severity) mon_msg_unseen = "Venomous gasses pour forth from the thin air!"; do_msg(); - big_cloud( CLOUD_POISON, kc, kt, - target->pos().x, target->pos().y, 20, 8 + random2(5) ); + big_cloud(CLOUD_POISON, kc, kt, target->pos(), 20, 8 + random2(5)); break; } } @@ -4485,8 +4476,7 @@ void MiscastEffect::_poison(int severity) mon_msg_unseen = "Noxious gasses pour forth from the thin air!"; do_msg(); - big_cloud(CLOUD_STINK, kc, kt, - target->pos().x, target->pos().y, 20, 8 + random2(5)); + big_cloud(CLOUD_STINK, kc, kt, target->pos(), 20, 8 + random2(5)); break; case 2: @@ -4517,8 +4507,7 @@ void MiscastEffect::_poison(int severity) mon_msg_unseen = "Venomous gasses pour forth from the thin air!"; do_msg(); - big_cloud(CLOUD_POISON, kc, kt, - target->pos().x, target->pos().y, 20, 7 + random2(7)); + big_cloud(CLOUD_POISON, kc, kt, target->pos(), 20, 7 + random2(7)); break; case 2: if (player_res_poison()) diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index f86cc634c9..4197a53c0f 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -53,10 +53,10 @@ static int spell_list[NUM_SPELLS]; #define SPELLDATASIZE (sizeof(spelldata)/sizeof(struct spell_desc)) static struct spell_desc *_seekspell(spell_type spellid); -static bool _cloud_helper(int (*func)(int, int, int, int, cloud_type, - kill_category, killer_type), - int x, int y, int pow, int spread_rate, - cloud_type ctype, kill_category, killer_type ); +static bool _cloud_helper(cloud_func func, const coord_def& where, + int pow, int spread_rate, + cloud_type ctype, kill_category whose, + killer_type killer); // // BEGIN PUBLIC FUNCTIONS @@ -581,8 +581,7 @@ int apply_one_neighbouring_square(cell_func cf, int power) return (-1); } - int rv = cf(coord_def(you.x_pos + bmove.dx, you.y_pos + bmove.dy), - power, 1); + int rv = cf(you.pos() + bmove.delta, power, 1); if (rv == 0) canned_msg(MSG_NOTHING_HAPPENS); @@ -608,183 +607,64 @@ int apply_area_within_radius( cell_func cf, const coord_def& where, // We really need some sort of a queue structure, since ideally I'd like // to do a (shallow) breadth-first-search of the dungeon floor. // This ought to work okay for small clouds. -void apply_area_cloud( int (*func) (int, int, int, int, cloud_type, - kill_category, killer_type), - int x, int y, +void apply_area_cloud( cloud_func func, const coord_def& where, int pow, int number, cloud_type ctype, kill_category whose, killer_type killer, int spread_rate ) { - int spread, clouds_left = number; - int good_squares = 0, neighbours[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - int dx = 1, dy = 1; - bool x_first; + int good_squares = 0; + int neighbours[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - if (clouds_left && _cloud_helper(func, x, y, pow, spread_rate, - ctype, whose, killer)) - clouds_left--; + if (number && _cloud_helper(func, where, pow, spread_rate, ctype, whose, + killer)) + number--; - if (!clouds_left) + if (number == 0) return; - if (coinflip()) - dx *= -1; - if (coinflip()) - dy *= -1; + // These indices depend on the order in Compass (see acr.cc) + int compass_order_orth[4] = { 2, 6, 4, 0 }; + int compass_order_diag[4] = { 1, 3, 5, 7 }; - x_first = coinflip(); + int* const arrs[2] = { compass_order_orth, compass_order_diag }; - if (x_first) + for ( int m = 0; m < 2; ++m ) { - if (clouds_left && _cloud_helper(func, x + dx, y, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[0]++; - } - - if (clouds_left && _cloud_helper(func, x - dx, y, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[1]++; - } - - if (clouds_left && _cloud_helper(func, x, y + dy, pow, spread_rate, - ctype, whose, killer)) + // Randomise, but do orthogonals first and diagonals later. + std::random_shuffle( arrs[m], arrs[m] + 4 ); + for ( int i = 0; i < 4 && number; ++i ) { - clouds_left--; - good_squares++; - neighbours[2]++; - } - - if (clouds_left && _cloud_helper(func, x, y - dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[3]++; - } - } - else - { - if (clouds_left && _cloud_helper(func, x, y + dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[2]++; - } - - if (clouds_left && _cloud_helper(func, x, y - dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[3]++; - } - - if (clouds_left && _cloud_helper(func, x + dx, y, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[0]++; - } - - if (clouds_left && _cloud_helper(func, x - dx, y, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[1]++; + const int aux = arrs[m][i]; + if ( _cloud_helper(func, where + Compass[aux], + pow, spread_rate, ctype, whose, killer)) + { + number--; + good_squares++; + neighbours[aux]++; + } } } - // Mow diagonals; we could randomize dx & dy again here. - if (clouds_left && _cloud_helper(func, x + dx, y + dy, pow, spread_rate, - ctype, whose, killer)) + // Get a random permutation. + int perm[8]; + for ( int i = 0; i < 8; ++i ) + perm[i] = i; + std::random_shuffle(perm, perm+8); + for (int i = 0; i < 8 && number; i++) { - clouds_left--; - good_squares++; - neighbours[4]++; - } + // Spread (in random order.) + const int j = perm[i]; - if (clouds_left && _cloud_helper(func, x - dx, y + dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[5]++; - } - - if (clouds_left && _cloud_helper(func, x + dx, y - dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[6]++; - } - - if (clouds_left && _cloud_helper(func, x - dx, y - dy, pow, spread_rate, - ctype, whose, killer)) - { - clouds_left--; - good_squares++; - neighbours[7]++; - } - - if (!clouds_left || !good_squares) - return; - - for (int i = 0; i < 8 && clouds_left; i++) - { - if (neighbours[i] == 0) + if (neighbours[j] == 0) continue; - spread = clouds_left / good_squares; - clouds_left -= spread; + int spread = number / good_squares; + number -= spread; good_squares--; - - switch (i) - { - case 0: - apply_area_cloud(func, x + dx, y, pow, spread, ctype, whose, killer, - spread_rate); - break; - case 1: - apply_area_cloud(func, x - dx, y, pow, spread, ctype, whose, killer, - spread_rate); - break; - case 2: - apply_area_cloud(func, x, y + dy, pow, spread, ctype, whose, killer, - spread_rate); - break; - case 3: - apply_area_cloud(func, x, y - dy, pow, spread, ctype, whose, killer, - spread_rate); - break; - case 4: - apply_area_cloud(func, x + dx, y + dy, pow, spread, ctype, whose, - killer, spread_rate); - break; - case 5: - apply_area_cloud(func, x - dx, y + dy, pow, spread, ctype, whose, - killer, spread_rate); - break; - case 6: - apply_area_cloud(func, x + dx, y - dy, pow, spread, ctype, whose, - killer, spread_rate); - break; - case 7: - apply_area_cloud(func, x - dx, y - dy, pow, spread, ctype, whose, - killer, spread_rate); - break; - } + apply_area_cloud(func, where + Compass[j], pow, spread, ctype, whose, + killer, spread_rate); } -} // end apply_area_cloud() +} // Select a spell direction and fill dist and pbolt appropriately. // Return false if the user canceled, true otherwise. @@ -809,8 +689,7 @@ bool spell_direction( dist &spelld, bolt &pbolt, } pbolt.set_target(spelld); - pbolt.source_x = you.x_pos; - pbolt.source_y = you.y_pos; + pbolt.source = you.pos(); return (true); } @@ -972,15 +851,14 @@ bool is_valid_spell(spell_type spell) return (spell < NUM_SPELLS && spell_list[spell] != -1); } -static bool _cloud_helper(int (*func)(int, int, int, int, cloud_type, - kill_category, killer_type), - int x, int y, int pow, int spread_rate, +static bool _cloud_helper(cloud_func func, const coord_def& where, + int pow, int spread_rate, cloud_type ctype, kill_category whose, killer_type killer ) { - if (!grid_is_solid(grd[x][y]) && env.cgrid[x][y] == EMPTY_CLOUD) + if (!grid_is_solid(grd(where)) && env.cgrid(where) == EMPTY_CLOUD) { - func(x, y, pow, spread_rate, ctype, whose, killer); + func(where, pow, spread_rate, ctype, whose, killer); return (true); } diff --git a/crawl-ref/source/spl-util.h b/crawl-ref/source/spl-util.h index 3734b8d2d4..16c1bac4d0 100644 --- a/crawl-ref/source/spl-util.h +++ b/crawl-ref/source/spl-util.h @@ -100,6 +100,10 @@ const char* spelltype_short_name( int which_spelltype ); const char* spelltype_long_name( int which_spelltype ); typedef int cell_func(coord_def where, int pow, int aux); +typedef int cloud_func(coord_def where, int pow, int spreadrate, + cloud_type type, kill_category whose, + killer_type killer); + int apply_area_visible(cell_func cf, int power, bool pass_through_trans = false); @@ -122,9 +126,8 @@ bool spell_direction( dist &spelld, bolt &pbolt, bool may_target_self = false, const char *prompt = NULL, bool cancel_at_self = false ); -void apply_area_cloud(int (*func) (int, int, int, int, cloud_type, - kill_category, killer_type), - int x, int y, int pow, int number, cloud_type ctype, +void apply_area_cloud(cloud_func func, const coord_def& where, + int pow, int number, cloud_type ctype, kill_category kc, killer_type killer, int spread_rate = -1); diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 9dc98a5779..17104cdddb 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -146,8 +146,8 @@ Stash::Stash(int xp, int yp) : enabled(true), items() // First, fix what square we're interested in if (xp == -1) { - xp = you.x_pos; - yp = you.y_pos; + xp = you.pos().x; + yp = you.pos().y; } x = (unsigned char) xp; y = (unsigned char) yp; @@ -263,18 +263,19 @@ bool Stash::is_boring_feature(dungeon_feature_type feat) void Stash::update() { - feat = grd[x][y]; + coord_def p(x,y); + feat = grd(p); trap = NUM_TRAPS; if (is_boring_feature(feat)) feat = DNGN_FLOOR; if (grid_is_trap(feat)) - trap = trap_type_at_xy(coord_def(x, y)); + trap = trap_type_at_xy(p); int objl = igrd[x][y]; // If this is your position, you know what's on this square - if (x == you.x_pos && y == you.y_pos) + if (p == you.pos()) { // Zap existing items items.clear(); @@ -1054,8 +1055,8 @@ const Stash *LevelStashes::find_stash(int x, int y) const { if (x == -1 || y == -1) { - x = you.x_pos; - y = you.y_pos; + x = you.pos().x; + y = you.pos().y; } const int abspos = (GXM * y) + x; stashes_t::const_iterator st = m_stashes.find(abspos); diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h index 570a611257..40c0d31d5c 100644 --- a/crawl-ref/source/stash.h +++ b/crawl-ref/source/stash.h @@ -227,7 +227,13 @@ public: // Returns true if the square at (x,y) contains potentially interesting // swag that merits a personal visit (for EXPLORE_GREEDY). bool needs_visit(int x, int y) const; + bool needs_visit(const coord_def& c) const { + return needs_visit(c.x, c.y); + } bool shop_needs_visit(int x, int y) const; + bool shop_needs_visit(const coord_def& c) const { + return shop_needs_visit(c.x, c.y); + } // Add stash at (x,y), or player's current location if no parameters are // supplied @@ -293,6 +299,11 @@ public: return get_current_level().get_shop(x, y); } + ShopInfo &get_shop(const coord_def& p) + { + return get_shop(p.x, p.y); + } + void remove_level(const level_id &which = level_id::current()); enum stash_update_mode @@ -344,6 +355,7 @@ private: extern StashTracker StashTrack; bool is_stash(int x, int y); +inline bool is_stash( const coord_def& p ) { return is_stash(p.x, p.y); } void describe_stash(int x, int y); std::string userdef_annotate_item(const char *s, const item_def *item, diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc index ae00ab869a..2a94b2783f 100644 --- a/crawl-ref/source/state.cc +++ b/crawl-ref/source/state.cc @@ -196,8 +196,8 @@ bool interrupt_cmd_repeat( activity_interrupt_type ai, fs.cprintf("%s (", mon->name(DESC_PLAIN, true).c_str()); fs.add_glyph( mon ); fs.cprintf(") in view: (%d,%d), see_grid: %s", - mon->x, mon->y, - see_grid(mon->x, mon->y)? "yes" : "no"); + mon->pos().x, mon->pos().y, + see_grid(mon->pos())? "yes" : "no"); formatted_mpr(fs, MSGCH_WARN); #endif diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index c9f00ece2d..ad112415f9 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -399,18 +399,11 @@ static int follower_tag_radius2() { // If only friendlies are adjacent, we set a max radius of 6, otherwise // only adjacent friendlies may follow. - coord_def p; - for (p.x = you.x_pos - 1; p.x <= you.x_pos + 1; ++p.x) - for (p.y = you.y_pos - 1; p.y <= you.y_pos + 1; ++p.y) - { - if (p == you.pos()) - continue; - if (const monsters *mon = monster_at(p)) - { - if (!mons_friendly(mon)) - return (2); - } - } + for ( adjacent_iterator ai; ai; ++ai ) + if (const monsters *mon = monster_at(*ai)) + if (!mons_friendly(mon)) + return (2); + return (6 * 6); } @@ -1285,8 +1278,8 @@ void random_in_bounds( int &x_pos, int &y_pos, int terr, && grd[x_pos][y_pos] == DNGN_SHALLOW_WATER) done = true; else if (empty - && mgrd[x_pos][y_pos] != NON_MONSTER - && (x_pos != you.x_pos || y_pos != you.y_pos)) + && mgrd[x_pos][y_pos] != NON_MONSTER + && (coord_def(x_pos,y_pos) != you.pos())) { done = true; } @@ -1633,7 +1626,7 @@ void zap_los_monsters() if (!map_bounds(gx, gy)) continue; - if (gx == you.x_pos && gy == you.y_pos) + if (gx == you.pos().x && gy == you.pos().y) continue; int imon = mgrd[gx][gy]; diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index d165de7b09..5e6370795c 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -894,8 +894,8 @@ static void tag_construct_you(writer &th) marshallShort(th, you.base_magic_points); marshallShort(th, you.base_magic_points2); - marshallShort(th, you.x_pos); - marshallShort(th, you.y_pos); + marshallShort(th, you.pos().x); + marshallShort(th, you.pos().y); marshallString(th, you.class_name, 30); @@ -1282,7 +1282,7 @@ static void tag_read_you(reader &th, char minorVersion) const int x = unmarshallShort(th); const int y = unmarshallShort(th); - you.moveto(x, y); + you.moveto(coord_def(x, y)); unmarshallCString(th, you.class_name, 30); @@ -1643,8 +1643,8 @@ static void tag_construct_level(writer &th) marshallShort(th, MAX_CLOUDS); for (int i = 0; i < MAX_CLOUDS; i++) { - marshallByte(th, env.cloud[i].x); - marshallByte(th, env.cloud[i].y); + marshallByte(th, env.cloud[i].pos.x); + marshallByte(th, env.cloud[i].pos.y); marshallByte(th, env.cloud[i].type); marshallShort(th, env.cloud[i].decay); marshallByte(th, (char) env.cloud[i].spread_rate); @@ -1659,8 +1659,8 @@ static void tag_construct_level(writer &th) marshallByte(th, env.shop[i].keeper_name[0]); marshallByte(th, env.shop[i].keeper_name[1]); marshallByte(th, env.shop[i].keeper_name[2]); - marshallByte(th, env.shop[i].x); - marshallByte(th, env.shop[i].y); + marshallByte(th, env.shop[i].pos.x); + marshallByte(th, env.shop[i].pos.y); marshallByte(th, env.shop[i].greed); marshallByte(th, env.shop[i].type); marshallByte(th, env.shop[i].level); @@ -1682,15 +1682,15 @@ void marshallItem(writer &th, const item_def &item) marshallShort(th, item.quantity); marshallByte(th, item.colour); - marshallShort(th, item.x); - marshallShort(th, item.y); + marshallShort(th, item.pos.x); + marshallShort(th, item.pos.y); marshallLong(th, item.flags); marshallShort(th, item.link); // unused - if (item.x == -1 && item.y == -1) + if (item.pos.x == -1 && item.pos.y == -1) marshallShort(th, -1); // unused else - marshallShort(th, igrd[item.x][item.y]); // unused + marshallShort(th, igrd(item.pos)); // unused marshallByte(th, item.slot); @@ -1710,8 +1710,8 @@ void unmarshallItem(reader &th, item_def &item) item.special = unmarshallLong(th); item.quantity = unmarshallShort(th); item.colour = (unsigned char) unmarshallByte(th); - item.x = unmarshallShort(th); - item.y = unmarshallShort(th); + item.pos.x = unmarshallShort(th); + item.pos.y = unmarshallShort(th); item.flags = (unsigned long) unmarshallLong(th); unmarshallShort(th); // mitm[].link -- unused @@ -1734,8 +1734,8 @@ static void tag_construct_level_items(writer &th) for (int i = 0; i < MAX_TRAPS; ++i) { marshallByte(th, env.trap[i].type); - marshallByte(th, env.trap[i].x); - marshallByte(th, env.trap[i].y); + marshallByte(th, env.trap[i].pos.x); + marshallByte(th, env.trap[i].pos.y); } // how many items? @@ -1773,10 +1773,10 @@ static void marshall_monster(writer &th, const monsters &m) marshallByte(th, m.speed); marshallByte(th, m.speed_increment); marshallByte(th, m.behaviour); - marshallByte(th, m.x); - marshallByte(th, m.y); - marshallByte(th, m.target_x); - marshallByte(th, m.target_y); + marshallByte(th, m.pos().x); + marshallByte(th, m.pos().y); + marshallByte(th, m.target.x); + marshallByte(th, m.target.y); marshallCoord(th, m.patrol_point); int help = m.travel_target; marshallByte(th, help); @@ -1980,8 +1980,8 @@ static void tag_read_level( reader &th, char minorVersion ) const int num_clouds = unmarshallShort(th); for (int i = 0; i < num_clouds; i++) { - env.cloud[i].x = unmarshallByte(th); - env.cloud[i].y = unmarshallByte(th); + env.cloud[i].pos.x = unmarshallByte(th); + env.cloud[i].pos.y = unmarshallByte(th); env.cloud[i].type = static_cast(unmarshallByte(th)); env.cloud[i].decay = unmarshallShort(th); env.cloud[i].spread_rate = (unsigned char) unmarshallByte(th); @@ -1997,8 +1997,8 @@ static void tag_read_level( reader &th, char minorVersion ) env.shop[i].keeper_name[0] = unmarshallByte(th); env.shop[i].keeper_name[1] = unmarshallByte(th); env.shop[i].keeper_name[2] = unmarshallByte(th); - env.shop[i].x = unmarshallByte(th); - env.shop[i].y = unmarshallByte(th); + env.shop[i].pos.x = unmarshallByte(th); + env.shop[i].pos.y = unmarshallByte(th); env.shop[i].greed = unmarshallByte(th); env.shop[i].type = static_cast(unmarshallByte(th)); env.shop[i].level = unmarshallByte(th); @@ -2020,8 +2020,8 @@ static void tag_read_level_items(reader &th, char minorVersion) static_cast( static_cast(unmarshallByte(th)) ); - env.trap[i].x = unmarshallByte(th); - env.trap[i].y = unmarshallByte(th); + env.trap[i].pos.x = unmarshallByte(th); + env.trap[i].pos.y = unmarshallByte(th); } // how many items? @@ -2044,10 +2044,10 @@ static void unmarshall_monster(reader &th, monsters &m) // Avoid sign extension when loading files (Elethiomel's hang) m.speed_increment = (unsigned char) unmarshallByte(th); m.behaviour = static_cast(unmarshallByte(th)); - m.x = unmarshallByte(th); - m.y = unmarshallByte(th); - m.target_x = unmarshallByte(th); - m.target_y = unmarshallByte(th); + m.position.x = unmarshallByte(th); + m.position.y = unmarshallByte(th); + m.target.x = unmarshallByte(th); + m.target.y = unmarshallByte(th); if (_tag_minor_version >= TAG_MINOR_MPATROL) unmarshallCoord(th, m.patrol_point); @@ -2126,7 +2126,7 @@ static void tag_read_level_monsters(reader &th, char minorVersion) unmarshall_monster(th, m); // place monster if (m.type != -1) - mgrd[m.x][m.y] = i; + mgrd(m.pos()) = i; } } diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc index 95c2286643..13942db30e 100644 --- a/crawl-ref/source/terrain.cc +++ b/crawl-ref/source/terrain.cc @@ -445,13 +445,9 @@ static bool _dgn_shift_feature(const coord_def &pos) grd(dest) = dfeat; if (dfeat == DNGN_ENTER_SHOP) - { if (shop_struct *s = get_shop(pos)) - { - s->x = dest.x; - s->y = dest.y; - } - } + s->pos = dest; + env.markers.move(pos, dest); dungeon_events.move_listeners(pos, dest); } @@ -551,7 +547,7 @@ void dungeon_terrain_changed(const coord_def &pos, grd(pos) = nfeat; env.grid_colours(pos) = BLACK; if (is_notable_terrain(nfeat) && see_grid(pos)) - seen_notable_thing(nfeat, pos.x, pos.y); + seen_notable_thing(nfeat, pos); destroy_trap(pos); } @@ -588,7 +584,7 @@ bool fall_into_a_pool( const coord_def& entry, bool allow_shift, unsigned char terrain ) { bool escape = false; - FixedVector< char, 2 > empty; + coord_def empty; if (you.species == SP_MERFOLK && terrain == DNGN_DEEP_WATER) { @@ -634,26 +630,16 @@ bool fall_into_a_pool( const coord_def& entry, bool allow_shift, { if (allow_shift) { - if (empty_surrounds( you.x_pos, you.y_pos, DNGN_FLOOR, 1, - false, empty )) - { - escape = true; - } - else - { - escape = false; - } + escape = empty_surrounds(you.pos(), DNGN_FLOOR, 1, false, empty); } else { // back out the way we came in, if possible 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 = entry; } else // zero or two or more squares away, with no way back { @@ -671,11 +657,10 @@ bool fall_into_a_pool( const coord_def& entry, bool allow_shift, if (escape) { - const coord_def pos(empty[0], empty[1]); - if (in_bounds(pos) && !is_grid_dangerous(grd(pos))) + if (in_bounds(empty) && !is_grid_dangerous(grd(empty))) { mpr("You manage to scramble free!"); - move_player_to_grid( pos, false, false, true ); + move_player_to_grid( empty, false, false, true ); if (terrain == DNGN_LAVA) expose_player_to_element( BEAM_LAVA, 14 ); diff --git a/crawl-ref/source/tilepick.cc b/crawl-ref/source/tilepick.cc index f7d1bac148..e359502125 100644 --- a/crawl-ref/source/tilepick.cc +++ b/crawl-ref/source/tilepick.cc @@ -157,7 +157,7 @@ int tile_unseen_flag(const coord_def& gc) static int _tileidx_monster_base(int mon_idx, bool detected) { const monsters* mon = &menv[mon_idx]; - int grid = grd[mon->x][mon->y]; + int grid = grd(mon->pos()); bool in_water = (grid == DNGN_SHALLOW_WATER || grid == DNGN_DEEP_WATER); int type = mon->type; @@ -4251,8 +4251,8 @@ void tile_finish_dngn(unsigned int *tileb, int cx, int cy) for (x = 0; x < crawl_view.viewsz.x; x++) { // View coords are not centered on you, but on (cx,cy) - const int gx = view2gridX(x + 1) + cx - you.x_pos; - const int gy = view2gridY(y + 1) + cy - you.y_pos; + const int gx = view2gridX(x + 1) + cx - you.pos().x; + const int gy = view2gridY(y + 1) + cy - you.pos().y; unsigned char wall_flv = 0; unsigned char floor_flv = 0; @@ -4286,11 +4286,11 @@ void tile_finish_dngn(unsigned int *tileb, int cx, int cy) if (in_bounds) { bool print_blood = true; - if (inside_halo(gx, gy)) + if (inside_halo(gc)) { - if (see_grid(gx, gy) && mgrd[gx][gy] != NON_MONSTER) + if (see_grid(gc) && mgrd(gc) != NON_MONSTER) { - monsters* m = &menv[mgrd[gx][gy]]; + monsters* m = &menv[mgrd(gc)]; if (!mons_class_flag(m->type, M_NO_EXP_GAIN) && (!mons_is_mimic(m->type) || testbits(m->flags, MF_KNOWN_MIMIC))) @@ -4301,7 +4301,7 @@ void tile_finish_dngn(unsigned int *tileb, int cx, int cy) } } - if (print_blood && is_bloodcovered(coord_def(gx, gy))) + if (print_blood && is_bloodcovered(gc)) tileb[count+1] |= TILE_FLAG_BLOOD; if (is_sanctuary(coord_def(gx, gy))) diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index d320c2431b..fd8066aebb 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -366,7 +366,7 @@ void DungeonRegion::draw_player(unsigned int x, unsigned int y) result.parts[TILEP_PART_BASE] = default_doll.parts[TILEP_PART_BASE]; result.parts[TILEP_PART_DRCHEAD] = default_doll.parts[TILEP_PART_DRCHEAD]; result.parts[TILEP_PART_DRCWING] = default_doll.parts[TILEP_PART_DRCWING]; - bool halo = inside_halo(you.x_pos, you.y_pos); + bool halo = inside_halo(you.pos()); result.parts[TILEP_PART_HALO] = halo ? TILEP_HALO_TSO : 0; if (result.parts[TILEP_PART_HAND1] == TILEP_SHOW_EQUIP) @@ -1066,7 +1066,7 @@ int DungeonRegion::handle_mouse(MouseEvent &event) return 0; // Activate travel. - start_travel(gc.x, gc.y); + start_travel(gc); return CK_MOUSE_CMD; } @@ -2058,7 +2058,7 @@ int MapRegion::handle_mouse(MouseEvent &event) if (!in_bounds(gc)) return 0; - start_travel(gc.x, gc.y); + start_travel(gc); } else if (event.button == MouseEvent::RIGHT) { diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc index 4051416072..206831be25 100644 --- a/crawl-ref/source/tilesdl.cc +++ b/crawl-ref/source/tilesdl.cc @@ -864,7 +864,7 @@ static void _fill_item_info(InventoryTile &desc, const item_def &item) desc.flag |= TILEI_FLAG_CURSE; if (item_type_tried(item)) desc.flag |= TILEI_FLAG_TRIED; - if (item.x != -1) + if (item.pos.x != -1) desc.flag |= TILEI_FLAG_FLOOR; } @@ -932,7 +932,7 @@ void TilesFramework::update_inventory() // How many ground items do we have? unsigned int num_ground = 0; - for (int i = igrd[you.x_pos][you.y_pos]; i != NON_ITEM; i = mitm[i].link) + for (int i = igrd(you.pos()); i != NON_ITEM; i = mitm[i].link) num_ground++; // Add extra rows, if needed. @@ -959,7 +959,7 @@ void TilesFramework::update_inventory() continue; object_class_type type = (object_class_type)(find - obj_syms); - for (int i = igrd[you.x_pos][you.y_pos]; i != NON_ITEM; i = mitm[i].link) + for (int i = igrd(you.pos()); i != NON_ITEM; i = mitm[i].link) { if (inv.size() >= m_region_self_inv->mx * m_region_self_inv->my) break; diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index ce581054d5..c9faecad36 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -276,8 +276,7 @@ static void dart_trap(bool trap_known, int trapped, bolt &pbolt, bool poison) exercise( SK_DODGING, 1 ); } - pbolt.target_x = you.x_pos; - pbolt.target_y = you.y_pos; + pbolt.target = you.pos(); if (coinflip()) itrap( pbolt, trapped ); @@ -326,7 +325,7 @@ void itrap( bolt &pbolt, int trapped ) return; } - trap_item( base_type, sub_type, pbolt.target() ); + trap_item( base_type, sub_type, pbolt.target ); return; } @@ -408,7 +407,7 @@ void handle_traps(trap_type trt, int i, bool trap_known) if (trap_known) mpr("The alarm is silenced."); else - grd[you.x_pos][you.y_pos] = DNGN_UNDISCOVERED_TRAP; + grd(you.pos()) = DNGN_UNDISCOVERED_TRAP; return; } @@ -450,11 +449,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].pos()); + trap_item( OBJ_MISSILES, MI_THROWING_NET, env.trap[i].pos); if (you.attribute[ATTR_HELD]) mark_net_trapping(you.pos()); - grd(env.trap[i].pos()) = DNGN_FLOOR; + grd(env.trap[i].pos) = DNGN_FLOOR; env.trap[i].type = TRAP_UNASSIGNED; } break; @@ -469,7 +468,7 @@ void handle_traps(trap_type trt, int i, bool trap_known) mpr("You don't fall through the shaft."); if (!trap_known) - grd[you.x_pos][you.y_pos] = DNGN_UNDISCOVERED_TRAP; + grd(you.pos()) = DNGN_UNDISCOVERED_TRAP; return; } @@ -480,14 +479,14 @@ void handle_traps(trap_type trt, int i, bool trap_known) if (trap_known) mpr("The shaft disappears in a puff of logic!"); - grd[env.trap[i].x][env.trap[i].y] = DNGN_FLOOR; + grd(env.trap[i].pos) = DNGN_FLOOR; env.trap[i].type = TRAP_UNASSIGNED; return; } if (!you.do_shaft() && !trap_known) { - grd[you.x_pos][you.y_pos] = DNGN_UNDISCOVERED_TRAP; + grd(you.pos()) = DNGN_UNDISCOVERED_TRAP; return; } @@ -502,7 +501,7 @@ void handle_traps(trap_type trt, int i, bool trap_known) 3, "a Zot trap" ); break; } - learned_something_new(TUT_SEEN_TRAP, you.x_pos, you.y_pos); + learned_something_new(TUT_SEEN_TRAP, you.pos()); if (!trap_known) // Now you know... exercise(SK_TRAPS_DOORS, ((coinflip()) ? 2 : 1)); @@ -512,8 +511,7 @@ void destroy_trap( const coord_def& pos ) { for (int i = 0; i < MAX_TRAPS; ++i) { - if (env.trap[i].x == pos.x && env.trap[i].y == pos.y - && env.trap[i].type != TRAP_UNASSIGNED) + if (env.trap[i].pos == pos && env.trap[i].type != TRAP_UNASSIGNED) { grd(pos) = DNGN_FLOOR; env.trap[i].type = TRAP_UNASSIGNED; @@ -534,11 +532,8 @@ void disarm_trap( dist &disa ) for (i = 0; i < MAX_TRAPS; i++) { - if (env.trap[i].x == you.x_pos + disa.dx - && env.trap[i].y == you.y_pos + disa.dy) - { + if (env.trap[i].pos == you.pos() + disa.delta) break; - } if (i == MAX_TRAPS - 1) { @@ -570,15 +565,13 @@ void disarm_trap( dist &disa ) exercise(SK_TRAPS_DOORS, 1 + random2(you.your_level / 5)); else { - if (env.trap[i].type == TRAP_NET - && (env.trap[i].x != you.x_pos || env.trap[i].y != you.y_pos)) + if (env.trap[i].type == TRAP_NET && env.trap[i].pos != you.pos()) { if (coinflip()) return; mpr("You stumble into the trap!"); - move_player_to_grid( coord_def(env.trap[i].x, env.trap[i].y), - true, false, true); + move_player_to_grid( env.trap[i].pos, true, false, true); } else handle_traps(env.trap[i].type, i, false); @@ -592,13 +585,12 @@ void disarm_trap( dist &disa ) mpr("You have disarmed the trap."); - struct bolt beam; + bolt beam; - beam.target_x = you.x_pos + disa.dx; - beam.target_y = you.y_pos + disa.dy; + beam.target = you.pos() + disa.delta; if (env.trap[i].type == TRAP_NET) - trap_item( OBJ_MISSILES, MI_THROWING_NET, beam.target() ); + 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) { @@ -610,7 +602,7 @@ void disarm_trap( dist &disa ) } } - grd[you.x_pos + disa.dx][you.y_pos + disa.dy] = DNGN_FLOOR; + grd(you.pos() + disa.delta) = DNGN_FLOOR; env.trap[i].type = TRAP_UNASSIGNED; you.turn_is_over = true; @@ -980,7 +972,7 @@ int trap_at_xy(const coord_def& xy) { for (int which_trap = 0; which_trap < MAX_TRAPS; which_trap++) { - if (env.trap[which_trap].pos() == xy + if (env.trap[which_trap].pos == xy && env.trap[which_trap].type != TRAP_UNASSIGNED) { return (which_trap); diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 1d2c6d577a..aad9ca1d1c 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -186,8 +186,8 @@ static void _init_traps() memset(curr_traps, -1, sizeof curr_traps); for (int i = 0; i < MAX_TRAPS; ++i) { - int x = env.trap[i].x, - y = env.trap[i].y; + int x = env.trap[i].pos.x, + y = env.trap[i].pos.y; if (inside_level_bounds(x,y)) curr_traps[x][y] = i; @@ -593,10 +593,8 @@ void prevent_travel_to(const std::string &feature) traversable_terrain[feature_type] = FORBIDDEN; } -bool is_branch_stair(int gridx, int gridy) +bool is_branch_stair(const coord_def& pos) { - const coord_def pos(gridx, gridy); - const level_id curr = level_id::current(); const level_id next = level_id::get_next_level_id(pos); @@ -762,26 +760,17 @@ void stop_running() you.running.stop(); } -static bool _is_valid_explore_target(int x, int y) +static bool _is_valid_explore_target(const coord_def& where) { // If an adjacent square is unmapped, it's valid. - for (int yi = -1; yi <= 1; ++yi) - for (int xi = -1; xi <= 1; ++xi) - { - if (!xi && !yi) - continue; - - const int ax = x + xi, ay = y + yi; - if (!in_bounds(ax, ay)) - continue; - if (!is_terrain_seen(ax, ay)) - return (true); - } + for ( adjacent_iterator ai(where); ai; ++ai ) + if (!is_terrain_seen(*ai)) + return (true); if (you.running == RMODE_EXPLORE_GREEDY) { LevelStashes *lev = StashTrack.find_current_level(); - return (lev && lev->needs_visit(x, y)); + return (lev && lev->needs_visit(where)); } return (false); @@ -830,8 +819,7 @@ static void _reset_zigzag_info() static void _set_target_square(const coord_def &target) { - you.running.x = target.x; - you.running.y = target.y; + you.running.pos = target; } static void _explore_find_target_square() @@ -1046,11 +1034,11 @@ command_type travel() if (you.running.is_explore()) { // Exploring. - if (grd[you.x_pos][you.y_pos] == DNGN_ENTER_SHOP + if (grd(you.pos()) == DNGN_ENTER_SHOP && you.running == RMODE_EXPLORE_GREEDY) { LevelStashes *lev = StashTrack.find_current_level(); - if (lev && lev->shop_needs_visit(you.x_pos, you.y_pos)) + if (lev && lev->shop_needs_visit(you.pos())) { you.running = 0; return (CMD_GO_UPSTAIRS); @@ -1059,20 +1047,20 @@ command_type travel() // Speed up explore by not doing a double-floodfill if we have // a valid target. - if (!you.running.x - || you.running.x == you.x_pos && you.running.y == you.y_pos - || !_is_valid_explore_target(you.running.x, you.running.y)) + if (!you.running.pos.x + || you.running.pos == you.pos() + || !_is_valid_explore_target(you.running.pos)) { _explore_find_target_square(); } } - if (you.running == RMODE_INTERLEVEL && !you.running.x) + if (you.running == RMODE_INTERLEVEL && !you.running.pos.x) { // Interlevel travel. Since you.running.x is zero, we've either just // initiated travel, or we've just climbed or descended a staircase, // and we need to figure out where to travel to next. - if (!_find_transtravel_square(level_target.p) || !you.running.x) + if (!_find_transtravel_square(level_target.p) || !you.running.pos.x) stop_running(); } @@ -1084,7 +1072,7 @@ command_type travel() // Get the next step to make. If the travel command can't find a route, // we turn off travel (find_travel_pos does that automatically). - find_travel_pos(you.x_pos, you.y_pos, move_x, move_y); + find_travel_pos(you.pos(), move_x, move_y); if (you.running < 0 && (*move_x || *move_y)) { @@ -1104,14 +1092,13 @@ command_type travel() // check after reaching the item, because at that point the stash // tracker will have verified the stash and say "false" to // needs_visit. - const int new_x = you.x_pos + *move_x; - const int new_y = you.y_pos + *move_y; + const coord_def newpos = you.pos() + coord_def(*move_x, *move_y); - if (new_x == you.running.x && new_y == you.running.y) + if (newpos == you.running.pos) { const LevelStashes *lev = StashTrack.find_current_level(); - if (lev && lev->needs_visit(new_x, new_y) - && !lev->shop_needs_visit(new_x, new_y)) + if (lev && lev->needs_visit(newpos) + && !lev->shop_needs_visit(newpos)) { const int estop = (you.running == RMODE_EXPLORE_GREEDY) ? @@ -1120,7 +1107,7 @@ command_type travel() if ((Options.explore_stop & estop) && prompt_stop_explore(estop)) { - explore_stopped_pos = coord_def(new_x, new_y); + explore_stopped_pos = newpos; stop_running(); } return direction_to_command( *move_x, *move_y ); @@ -1135,7 +1122,7 @@ command_type travel() // should continue doing so (explore has its own end condition // upstairs); if we're traveling between levels and we've reached // our travel target, we're on a staircase and should take it. - if (you.x_pos == you.running.x && you.y_pos == you.running.y) + if (you.pos() == you.running.pos) { if (runmode == RMODE_EXPLORE || runmode == RMODE_EXPLORE_GREEDY) you.running = runmode; // Turn explore back on @@ -1191,7 +1178,7 @@ command_type travel() // valid on the new level. Setting running.x to zero forces // us to recalculate our travel target next turn (see // previous if block). - you.running.x = you.running.y = 0; + you.running.pos.reset(); } else { @@ -1743,19 +1730,16 @@ bool travel_pathfind::path_examine_point(const coord_def &c) ///////////////////////////////////////////////////////////////////////////// -void find_travel_pos(int youx, int youy, +void find_travel_pos(const coord_def& youpos, char *move_x, char *move_y, std::vector* features) { travel_pathfind tp; if (move_x && move_y) - { - tp.set_src_dst(coord_def(youx, youy), - coord_def(you.running.x, you.running.y)); - } + tp.set_src_dst(youpos, you.running.pos); else - tp.set_floodseed(coord_def(youx, youy)); + tp.set_floodseed(youpos); tp.set_feature_vector(features); @@ -1764,15 +1748,15 @@ void find_travel_pos(int youx, int youy, const coord_def dest = tp.pathfind( rmode ); - if (dest.x == 0 && dest.y == 0) + if (dest.origin()) { if (move_x && move_y) you.running = RMODE_NOT_RUNNING; } else if (move_x && move_y) { - *move_x = dest.x - youx; - *move_y = dest.y - youy; + *move_x = dest.x - youpos.x; + *move_y = dest.y - youpos.y; } } @@ -2387,7 +2371,7 @@ void start_translevel_travel(const travel_target &pos) if (!can_travel_interlevel()) { - start_travel(pos.p.pos.x, pos.p.pos.y); + start_travel(pos.p.pos); return; } @@ -2440,7 +2424,7 @@ void start_translevel_travel(bool prompt_for_destination) if (level_target.p.id.depth > 0) { you.running = RMODE_INTERLEVEL; - you.running.x = you.running.y = 0; + you.running.pos.reset(); last_stair.depth = -1; _start_running(); } @@ -2448,7 +2432,7 @@ void start_translevel_travel(bool prompt_for_destination) command_type _trans_negotiate_stairs() { - return grid_stair_direction(grd[you.x_pos][you.y_pos]); + return grid_stair_direction(grd(you.pos())); } static int _target_distance_from(const coord_def &pos) @@ -2516,11 +2500,8 @@ static int _find_transtravel_stair( const level_id &cur, // for a location on the same level. If that's the case, we can get // the distance off the travel_point_distance matrix. deltadist = travel_point_distance[target.pos.x][target.pos.y]; - if (!deltadist - && (stair.x != target.pos.x || stair.y != target.pos.y)) - { + if (!deltadist && stair != target.pos) deltadist = -1; - } } if (deltadist != -1) @@ -2537,11 +2518,8 @@ static int _find_transtravel_stair( const level_id &cur, // Note that even if this *is* degenerate, interlevel travel may // still be able to find a shorter route, since it can consider // routes that leave and reenter the current level. - if (player_level == target.id && stair.x == you.x_pos - && stair.y == you.y_pos) - { + if (player_level == target.id && stair == you.pos()) best_stair = target.pos; - } // The local_distance is already set, but there may actually be // stairs we can take that'll get us to the target faster than the @@ -2577,11 +2555,8 @@ static int _find_transtravel_stair( const level_id &cur, if (!this_stair) { deltadist = travel_point_distance[si.position.x][si.position.y]; - if (!deltadist - && (you.x_pos != si.position.x || you.y_pos != si.position.y)) - { + if (!deltadist && you.pos() != si.position) deltadist = -1; - } } // deltadist == 0 is legal (if this_stair is NULL), since the player @@ -2629,11 +2604,8 @@ static int _find_transtravel_stair( const level_id &cur, if (local_distance == -1 || local_distance > dist2stair) { local_distance = dist2stair; - if (cur == player_level && you.x_pos == stair.x - && you.y_pos == stair.y) - { + if (cur == player_level && you.pos() == stair) best_stair = si.position; - } } continue; } @@ -2674,11 +2646,8 @@ static int _find_transtravel_stair( const level_id &cur, && (local_distance == -1 || local_distance > newdist)) { local_distance = newdist; - if (cur == player_level && you.x_pos == stair.x - && you.y_pos == stair.y) - { + if (cur == player_level && you.pos() == stair) best_stair = si.position; - } } } } @@ -2717,7 +2686,7 @@ static bool _loadlev_populate_stair_distances(const level_pos &target) static void _populate_stair_distances(const level_pos &target) { // Populate travel_point_distance. - find_travel_pos(target.pos.x, target.pos.y, NULL, NULL, NULL); + find_travel_pos(target.pos, NULL, NULL, NULL); LevelInfo &li = travel_cache.get_level_info(target.id); const std::vector &stairs = li.get_stairs(); @@ -2742,13 +2711,13 @@ static bool _find_transtravel_square(const level_pos &target, bool verbose) level_id current = level_id::current(); coord_def best_stair(-1, -1); - coord_def cur_stair(you.x_pos, you.y_pos); + coord_def cur_stair(you.pos()); level_id closest_level; int best_level_distance = -1; travel_cache.clear_distances(); - find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, NULL); + find_travel_pos(you.pos(), NULL, NULL, NULL); const LevelInfo &target_level = travel_cache.get_level_info( target.id ); @@ -2760,8 +2729,7 @@ static bool _find_transtravel_square(const level_pos &target, bool verbose) if (best_stair.x != -1 && best_stair.y != -1) { - you.running.x = best_stair.x; - you.running.y = best_stair.y; + you.running.pos = best_stair; return (true); } else if (best_level_distance != -1 && closest_level != current @@ -2789,22 +2757,21 @@ static bool _find_transtravel_square(const level_pos &target, bool verbose) return (false); } -void start_travel(int x, int y) +void start_travel(const coord_def& p) { // Redundant target? - if (x == you.x_pos && y == you.y_pos) + if (p == you.pos()) return; // Remember where we're going so we can easily go back if interrupted. - you.travel_x = x; - you.travel_y = y; + you.travel_x = p.x; + you.travel_y = p.y; if (!i_feel_safe(true, true)) return; - you.running.x = x; - you.running.y = y; - level_target = level_pos(level_id::current(), coord_def(x, y)); + you.running.pos = p; + level_target = level_pos(level_id::current(), p); if (!can_travel_interlevel()) { @@ -2843,7 +2810,7 @@ void start_explore(bool grab_items) // Clone shadow array off map mapshadow = env.map; - you.running.x = you.running.y = 0; + you.running.pos.reset(); _start_running(); } @@ -3070,8 +3037,7 @@ void LevelInfo::update_stair_distances() { // For each stair, we need to ask travel to populate the distance // array. - find_travel_pos(stairs[s].position.x, stairs[s].position.y, - NULL, NULL, NULL); + find_travel_pos(stairs[s].position, NULL, NULL, NULL); for (int other = 0; other < end; ++other) { @@ -3090,9 +3056,10 @@ void LevelInfo::update_stair_distances() } } -void LevelInfo::update_stair(int x, int y, const level_pos &p, bool guess) +void LevelInfo::update_stair(const coord_def& stairpos, const level_pos &p, + bool guess) { - stair_info *si = get_stair(x, y); + stair_info *si = get_stair(stairpos); // What 'guess' signifies: whenever you take a stair from A to B, the // travel code knows that the stair takes you from A->B. In that case, @@ -3124,7 +3091,7 @@ void LevelInfo::update_stair(int x, int y, const level_pos &p, bool guess) sync_branch_stairs(si); } else if (!si && guess) - create_placeholder_stair(coord_def(x, y), p); + create_placeholder_stair(stairpos, p); } void LevelInfo::create_placeholder_stair(const coord_def &stair, @@ -3318,22 +3285,18 @@ int LevelInfo::distance_between(const stair_info *s1, const stair_info *s2) void LevelInfo::get_stairs(std::vector &st) { - for (int y = 0; y < GYM; ++y) - for (int x = 0; x < GXM; ++x) - { - dungeon_feature_type grid = grd[x][y]; - int envc = env.map[x][y].object; + for ( rectangle_iterator ri(1); ri; ++ri ) + { + const dungeon_feature_type grid = grd(*ri); + const int envc = env.map(*ri).object; - if ((x == you.x_pos && y == you.y_pos || envc) - && is_travelable_stair(grid) - && (is_terrain_seen(x, y) || !is_branch_stair(x, y))) - { - // Convert to grid coords, because that's what we use - // everywhere else. - const coord_def stair(x, y); - st.push_back(stair); - } + if ((*ri == you.pos() || envc) + && is_travelable_stair(grid) + && (is_terrain_seen(*ri) || !is_branch_stair(*ri))) + { + st.push_back(*ri); } + } } void LevelInfo::clear_distances() @@ -3582,12 +3545,10 @@ void TravelCache::add_waypoint(int x, int y) int waynum = keyin - '0'; + coord_def pos(x,y); if (x == -1 || y == -1) - { - x = you.x_pos; - y = you.y_pos; - } - const coord_def pos(x, y); + pos = you.pos(); + const level_id &lid = level_id::current(); waypoints[waynum].id = lid; @@ -3721,7 +3682,7 @@ bool can_travel_interlevel() // Shift-running and resting. runrest::runrest() - : runmode(0), mp(0), hp(0), x(0), y(0) + : runmode(0), mp(0), hp(0), pos(0,0) { } @@ -3735,16 +3696,14 @@ void runrest::initialise(int dir, int mode) if (dir == RDIR_REST) { - x = 0; - y = 0; + pos.reset(); runmode = mode; } else { ASSERT( dir >= 0 && dir <= 7 ); - x = Compass[dir].x; - y = Compass[dir].y; + pos = Compass[dir]; runmode = mode; // Get the compass point to the left/right of intended travel: @@ -3792,13 +3751,11 @@ static dungeon_feature_type _base_grid_type( dungeon_feature_type grid ) void runrest::set_run_check(int index, int dir) { - run_check[index].dx = Compass[dir].x; - run_check[index].dy = Compass[dir].y; + run_check[index].delta = Compass[dir]; - const int targ_x = you.x_pos + Compass[dir].x; - const int targ_y = you.y_pos + Compass[dir].y; + const coord_def targ = you.pos() + Compass[dir]; - run_check[index].grid = _base_grid_type( grd[ targ_x ][ targ_y ] ); + run_check[index].grid = _base_grid_type( grd(targ) ); } bool runrest::check_stop_running() @@ -3815,18 +3772,16 @@ bool runrest::check_stop_running() // traps and secret doors aren't running stopping points. bool runrest::run_grids_changed() const { - if (env.cgrid[you.x_pos + x][you.y_pos + y] != EMPTY_CLOUD) + if (env.cgrid(you.pos() + pos) != EMPTY_CLOUD) return (true); - if (mgrd[you.x_pos + x][you.y_pos + y] != NON_MONSTER) + if (mgrd(you.pos() + pos) != NON_MONSTER) return (true); for (int i = 0; i < 3; i++) { - const int targ_x = you.x_pos + run_check[i].dx; - const int targ_y = you.y_pos + run_check[i].dy; - const dungeon_feature_type targ_grid = - _base_grid_type( grd[ targ_x ][ targ_y ] ); + const coord_def targ = you.pos() + run_check[i].delta; + const dungeon_feature_type targ_grid = _base_grid_type(grd(targ)); if (run_check[i].grid != targ_grid) return (true); @@ -3854,7 +3809,7 @@ void runrest::stop() bool runrest::is_rest() const { - return (runmode > 0 && !x && !y); + return (runmode > 0 && pos.origin()); } bool runrest::is_explore() const @@ -3886,7 +3841,7 @@ void runrest::rest() void runrest::clear() { runmode = RMODE_NOT_RUNNING; - x = y = 0; + pos.reset(); mp = hp = 0; _reset_zigzag_info(); diff --git a/crawl-ref/source/travel.h b/crawl-ref/source/travel.h index 752c285044..95ede43a98 100644 --- a/crawl-ref/source/travel.h +++ b/crawl-ref/source/travel.h @@ -82,7 +82,7 @@ bool is_traversable(dungeon_feature_type grid); void explore_pickup_event(int did_pickup, int tried_pickup); bool is_excluded(const coord_def &p); -void find_travel_pos(int you_x, int you_y, char *move_x, char *move_y, +void find_travel_pos(const coord_def& youpos, char *move_x, char *move_y, std::vector* coords = NULL); bool is_travelsafe_square(int x, int y, bool ignore_hostile = false, @@ -109,7 +109,7 @@ void start_translevel_travel(const travel_target &pos); void start_translevel_travel(bool prompt_for_destination = true); -void start_travel(int x, int y); +void start_travel(const coord_def& p); command_type travel(); @@ -483,8 +483,9 @@ struct LevelInfo void update(); // Update LevelInfo to be correct for the // current level. - // Updates/creates a StairInfo for the stair at (x, y) in grid coordinates - void update_stair(int x, int y, const level_pos &p, bool guess = false); + // Updates/creates a StairInfo for the stair at stairpos in grid coordinates + void update_stair(const coord_def& stairpos, const level_pos &p, + bool guess = false); // Clears all stair info for stairs matching this grid type. void clear_stairs(dungeon_feature_type grid); diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index 2d6cae2aa4..32739407eb 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -267,15 +267,9 @@ static job_type _get_tutorial_job(unsigned int type) // position into normal closed doors. void tutorial_zap_secret_doors() { - for (int x = you.x_pos - 10; x <= you.x_pos + 10; x++) - for (int y = you.y_pos - 10; y <= you.y_pos + 10; y++) - { - if (!in_bounds(x,y)) - continue; - - if (grd[x][y] == DNGN_SECRET_DOOR) - grd[x][y] = DNGN_CLOSED_DOOR; - } + for ( radius_iterator ri(you.pos(), 10, true, false); ri; ++ri ) + if ( grd(*ri) == DNGN_SECRET_DOOR ) + grd(*ri) = DNGN_CLOSED_DOOR; } // Prints the tutorial welcome screen. @@ -1183,9 +1177,9 @@ void tutorial_first_monster(const monsters &mon) if (!Options.tutorial_events[TUT_SEEN_MONSTER]) { if (get_mons_colour(&mon) != mon.colour) - learned_something_new(TUT_MONSTER_BRAND, mon.x, mon.y); + learned_something_new(TUT_MONSTER_BRAND, mon.pos()); if (mons_friendly(&mon)) - learned_something_new(TUT_MONSTER_FRIENDLY, mon.x, mon.y); + learned_something_new(TUT_MONSTER_FRIENDLY, mon.pos()); if (!Options.tut_just_triggered && one_chance_in(4) @@ -1216,7 +1210,7 @@ void tutorial_first_monster(const monsters &mon) std::string text = "That "; #ifdef USE_TILE // need to highlight monster - const coord_def gc(mon.x, mon.y); + const coord_def gc = mon.pos(); tiles.place_cursor(CURSOR_TUTORIAL, gc); tiles.add_text_tag(TAG_TUTORIAL, mon.name(DESC_CAP_A), gc); @@ -1303,15 +1297,15 @@ void tutorial_first_monster(const monsters &mon) } if (get_mons_colour(&mon) != mon.colour) - learned_something_new(TUT_MONSTER_BRAND, mon.x, mon.y); + learned_something_new(TUT_MONSTER_BRAND, mon.pos()); if (mons_friendly(&mon)) - learned_something_new(TUT_MONSTER_FRIENDLY, mon.x, mon.y); + learned_something_new(TUT_MONSTER_FRIENDLY, mon.pos()); } void tutorial_first_item(const item_def &item) { // Happens if monster is standing on dropped corpse or item. - if (mgrd[item.x][item.y] != NON_MONSTER) + if (mgrd(item.pos) != NON_MONSTER) return; if (!Options.tutorial_events[TUT_SEEN_FIRST_OBJECT] @@ -1321,9 +1315,9 @@ void tutorial_first_item(const item_def &item) // corpse, TUT_SEEN_CARRION is done when a corpse is first seen. if (!Options.tut_just_triggered && item.base_type == OBJ_CORPSES - && mgrd[item.x][item.y] == NON_MONSTER) + && mgrd(item.pos) == NON_MONSTER) { - learned_something_new(TUT_SEEN_CARRION, item.x, item.y); + learned_something_new(TUT_SEEN_CARRION, item.pos); } return; } @@ -1343,7 +1337,7 @@ void tutorial_first_item(const item_def &item) text += _colourize_glyph(col, ch); text += " "; #else - const coord_def gc = coord_def(item.x, item.y); + const coord_def gc = item.pos; tiles.place_cursor(CURSOR_TUTORIAL, gc); tiles.add_text_tag(TAG_TUTORIAL, item.name(DESC_CAP_A), gc); #endif @@ -1439,7 +1433,7 @@ static void _new_god_conduct() } // Here most of the tutorial messages for various triggers are handled. -void learned_something_new(tutorial_event_type seen_what, int x, int y) +void learned_something_new(tutorial_event_type seen_what, coord_def gc) { // Already learned about that. if (!Options.tutorial_events[seen_what]) @@ -1452,13 +1446,10 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) std::ostringstream text; #ifndef USE_TILE - const int ex = x - you.x_pos + 9; - const int ey = y - you.y_pos + 9; + const coord_def e = gc - you.pos() + coord_def(9,9); unsigned ch; unsigned short colour; int object; -#else - const coord_def gc(x, y); #endif Options.tut_just_triggered = true; @@ -1645,11 +1636,11 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) // first picked up, since a new player might not think to pick // up a corpse. - if (x <= 0 || y <= 0) + if (gc.x <= 0 || gc.y <= 0) text << "Ah, a corpse!"; else { - int i = igrd[x][y]; + int i = igrd(gc); while (i != NON_ITEM) { if (mitm[i].base_type == OBJ_CORPSES) @@ -1784,11 +1775,11 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) text << "These "; #ifndef USE_TILE // Is a monster blocking the view? - if (mgrd[x][y] != NON_MONSTER) + if (mgrd(gc) != NON_MONSTER) DELAY_EVENT; - object = env.show[ex][ey]; - colour = env.show_col[ex][ey]; + object = env.show(e); + colour = env.show_col(e); { unsigned short dummy; get_item_symbol( object, &ch, &dummy ); } text << _colourize_glyph(colour, ch) << " "; @@ -1812,13 +1803,13 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) DELAY_EVENT; // monsters standing on stairs - if (mgrd[x][y] != NON_MONSTER) + if (mgrd(gc) != NON_MONSTER) DELAY_EVENT; text << "These "; #ifndef USE_TILE - object = env.show[ex][ey]; - colour = env.show_col[ex][ey]; + object = env.show(e); + colour = env.show_col(e); get_item_symbol( object, &ch, &colour ); text << _colourize_glyph(colour, ch); @@ -1841,12 +1832,12 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) text << "This "; #ifndef USE_TILE // Is a monster blocking the view? - if (mgrd[x][y] != NON_MONSTER) + if (mgrd(gc) != NON_MONSTER) DELAY_EVENT; // FIXME: Branch entrance character is not being colored yellow. - object = env.show[ex][ey]; - colour = env.show_col[ex][ey]; + object = env.show(e); + colour = env.show_col(e); { unsigned short dummy; get_item_symbol( object, &ch, &dummy ); } text << _colourize_glyph(colour, ch) << " "; @@ -1874,7 +1865,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) return; #else // Monster or player standing on stairs. - if (mgrd[x][y] != NON_MONSTER || (you.x_pos == x && you.y_pos == y)) + if (mgrd(gc) != NON_MONSTER || (you.pos() == gc)) DELAY_EVENT; text << "If any items are covering stairs or an escape hatch then " @@ -1885,7 +1876,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) break; case TUT_SEEN_TRAP: - if (x == you.x_pos && y == you.y_pos) + if (you.pos() == gc) text << "Oops... you just triggered a trap. "; else text << "You just discovered a trap. "; @@ -1893,8 +1884,8 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) text << "An unwary adventurer will occasionally stumble into one " "of these nasty constructions"; #ifndef USE_TILE - object = env.show[ex][ey]; - colour = env.show_col[ex][ey]; + object = env.show(e); + colour = env.show_col(e); get_item_symbol( object, &ch, &colour ); if (ch == ' ' || colour == BLACK) @@ -1910,8 +1901,8 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) case TUT_SEEN_ALTAR: text << "That "; #ifndef USE_TILE - object = env.show[ex][ey]; - colour = env.show_col[ex][ey]; + object = env.show(e); + colour = env.show_col(e); get_item_symbol( object, &ch, &colour ); text << _colourize_glyph(colour, ch) << " "; #else @@ -1942,7 +1933,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) #endif text << "That " #ifndef USE_TILE - << _colourize_glyph(YELLOW, get_screen_glyph(x,y)) << " " + << _colourize_glyph(YELLOW, get_screen_glyph(gc)) << " " #endif "is a shop. You can enter it by typing << " #ifdef USE_TILE @@ -1962,7 +1953,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) text << "That " #ifndef USE_TILE - << _colourize_glyph(WHITE, get_screen_glyph(x,y)) << " " + << _colourize_glyph(WHITE, get_screen_glyph(gc)) << " " #endif "is a closed door. You can open it by walking into it. " "Sometimes it is useful to close a door. Do so by pressing " @@ -1981,7 +1972,7 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) #endif text << "That " #ifndef USE_TILE - << _colourize_glyph(WHITE, get_screen_glyph(x,y)) << " " + << _colourize_glyph(WHITE, get_screen_glyph(gc)) << " " #endif "was a secret door. You can actively try to find secret " "doors by searching. To search for one turn, press s, " @@ -2498,8 +2489,8 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) case TUT_EXCOMMUNICATE: { - const god_type new_god = (god_type) x; - const int old_piety = y; + const god_type new_god = (god_type) gc.x; + const int old_piety = gc.y; god_type old_god = GOD_NO_GOD; for (int i = 0; i < MAX_NUM_GODS; i++) diff --git a/crawl-ref/source/tutorial.h b/crawl-ref/source/tutorial.h index 2b8d4e2f8f..5811ef5b8a 100644 --- a/crawl-ref/source/tutorial.h +++ b/crawl-ref/source/tutorial.h @@ -43,7 +43,8 @@ void taken_new_item(unsigned char item_type); void tut_gained_new_skill(int skill); void tutorial_first_monster(const monsters& mon); void tutorial_first_item(const item_def& item); -void learned_something_new(tutorial_event_type seen_what, int x = 0, int y = 0); +void learned_something_new(tutorial_event_type seen_what, + coord_def gc = coord_def(0,0)); formatted_string tut_abilities_info(void); void print_tut_skills_info(void); void print_tut_skills_description_info(void); diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 3a5e936481..b552a49215 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -114,7 +114,7 @@ screen_buffer_t colour_code_map( int x, int y, bool item_colour = false, void cloud_grid(void); void monster_grid(bool do_updates); -static void _get_symbol( int x, int y, +static void _get_symbol( const coord_def& where, int object, unsigned *ch, unsigned short *colour, bool magic_mapped = false ); @@ -203,11 +203,11 @@ void set_envmap_glyph(int x, int y, int object, int col) #endif } -void set_envmap_obj( int x, int y, int obj ) +void set_envmap_obj( const coord_def& where, int obj ) { - env.map[x][y].object = obj; + env.map(where).object = obj; #ifdef USE_TILE - tiles.update_minimap(x, y); + tiles.update_minimap(where.x, where.y); #endif } @@ -295,6 +295,11 @@ void set_terrain_seen( int x, int y ) env.map[x][y].flags |= MAP_SEEN_FLAG; } +void clear_envmap_grid( const coord_def& p ) +{ + env.map(p).clear(); +} + void clear_envmap_grid( int x, int y ) { env.map[x][y].clear(); @@ -376,14 +381,15 @@ static unsigned _get_symbol(int object, unsigned short *colour, bool magic_mapped) { unsigned ch; - _get_symbol(0, 0, object, &ch, NULL, magic_mapped); + _get_symbol(coord_def(0,0), object, &ch, NULL, magic_mapped); return (ch); } -static int _view_emphasised_colour(int x, int y, dungeon_feature_type feat, +static int _view_emphasised_colour(const coord_def& where, + dungeon_feature_type feat, int oldcolour, int newcolour) { - if (is_travelable_stair(feat) && !travel_cache.know_stair(coord_def(x, y))) + if (is_travelable_stair(feat) && !travel_cache.know_stair(where)) { if ((you.your_level || grid_stair_direction(feat) == CMD_GO_DOWNSTAIRS) && you.where_are_you != BRANCH_VESTIBULE_OF_HELL) @@ -392,18 +398,18 @@ static int _view_emphasised_colour(int x, int y, dungeon_feature_type feat, return (oldcolour); } -static bool _show_bloodcovered(int x, int y) +static bool _show_bloodcovered(const coord_def& where) { - if (!is_bloodcovered(coord_def(x,y))) + if (!is_bloodcovered(where)) return (false); - dungeon_feature_type grid = grd[x][y]; + dungeon_feature_type grid = grd(where); // Altars, stairs (of any kind) and traps should not be coloured red. return (!is_critical_feature(grid) && !grid_is_trap(grid)); } -static void _get_symbol( int x, int y, +static void _get_symbol( const coord_def& where, int object, unsigned *ch, unsigned short *colour, bool magic_mapped ) @@ -422,11 +428,11 @@ static void _get_symbol( int x, int y, const int colmask = *colour & COLFLAG_MASK; if (object < NUM_REAL_FEATURES && object >= DNGN_MINMOVE - && is_sanctuary(coord_def(x,y)) ) + && is_sanctuary(where) ) { - if (env.map[x][y].property == FPROP_SANCTUARY_1) + if (env.map(where).property == FPROP_SANCTUARY_1) *colour = YELLOW | colmask; - else if (env.map[x][y].property == FPROP_SANCTUARY_2) + else if (env.map(where).property == FPROP_SANCTUARY_2) { if (!one_chance_in(4)) *colour = WHITE | colmask; // 3/4 @@ -436,13 +442,13 @@ static void _get_symbol( int x, int y, *colour = LIGHTGREY | colmask; // 1/12 } } - else if (object < NUM_REAL_FEATURES && _show_bloodcovered(x,y)) + else if (object < NUM_REAL_FEATURES && _show_bloodcovered(where)) { *colour = RED | colmask; } - else if (object < NUM_REAL_FEATURES && env.grid_colours[x][y]) + else if (object < NUM_REAL_FEATURES && env.grid_colours(where)) { - *colour = env.grid_colours[x][y] | colmask; + *colour = env.grid_colours(where) | colmask; } else { @@ -454,11 +460,11 @@ static void _get_symbol( int x, int y, if (fdef.em_colour != fdef.colour && fdef.em_colour) *colour = _view_emphasised_colour( - x, y, static_cast(object), + where, static_cast(object), *colour, fdef.em_colour | colmask); } - if (object < NUM_REAL_FEATURES && inside_halo(x, y) + if (object < NUM_REAL_FEATURES && inside_halo(where) && ((object >= DNGN_FLOOR_MIN && object <= DNGN_FLOOR_MAX) || object == DNGN_UNDISCOVERED_TRAP)) { @@ -467,9 +473,9 @@ static void _get_symbol( int x, int y, } // Note anything we see that's notable - if ((x || y) && fdef.is_notable()) + if ((!where.origin()) && fdef.is_notable()) seen_notable_thing( static_cast(object), - x, y ); + where ); } else { @@ -646,7 +652,7 @@ screen_buffer_t colour_code_map( int x, int y, bool item_colour, && fdef.seen_em_colour) { feature_colour = - _view_emphasised_colour(x, y, grid_value, feature_colour, + _view_emphasised_colour(coord_def(x, y), grid_value, feature_colour, fdef.seen_em_colour); } @@ -693,6 +699,8 @@ void clear_map(bool clear_detected_items, bool clear_detected_monsters) for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y) for (int x = X_BOUND_1; x <= X_BOUND_2; ++x) { + // FIXME convert to using p everywhere. + const coord_def p(x,y); // Don't expose new dug out areas: // Note: assumptions are being made here about how // terrain can change (eg it used to be solid, and @@ -716,14 +724,14 @@ void clear_map(bool clear_detected_items, bool clear_detected_monsters) if (!clear_detected_monsters && is_envmap_detected_mons(x, y)) continue; - set_envmap_obj(x, y, is_terrain_known(x, y)? grd[x][y] : 0); + set_envmap_obj(p, is_terrain_known(p)? grd(p) : 0); set_envmap_detected_mons(x, y, false); set_envmap_detected_item(x, y, false); #ifdef USE_TILE - set_envmap_obj(x, y, is_terrain_known(x, y)? grd[x][y] : 0); + set_envmap_obj(p, is_terrain_known(p)? grd(p) : 0); env.tile_bk_fg[x][y] = 0; - env.tile_bk_bg[x][y] = is_terrain_known(x, y) ? + env.tile_bk_bg[x][y] = is_terrain_known(p) ? tile_idx_unseen_terrain(x, y, grd[x][y]) : tileidx_feature(DNGN_UNSEEN, x, y); #endif @@ -1094,29 +1102,28 @@ void force_monster_shout(monsters* monster) inline static bool _update_monster_grid(const monsters *monster) { - const int ex = monster->x - you.x_pos + 9; - const int ey = monster->y - you.y_pos + 9; + const coord_def e = monster->pos() - you.pos() + coord_def(9,9); if (!player_monster_visible( monster )) { // ripple effect? - if (grd[monster->x][monster->y] == DNGN_SHALLOW_WATER + if (grd(monster->pos()) == DNGN_SHALLOW_WATER && !mons_flies(monster) && env.cgrid(monster->pos()) == EMPTY_CLOUD) { - _set_show_backup(ex, ey); - env.show[ex][ey] = DNGN_INVIS_EXPOSED; - env.show_col[ex][ey] = BLUE; + _set_show_backup(e.x, e.y); + env.show[e.x][e.y] = DNGN_INVIS_EXPOSED; + env.show_col[e.x][e.y] = BLUE; } return (false); } // Mimics are always left on map. if (!mons_is_mimic( monster->type )) - _set_show_backup(ex, ey); + _set_show_backup(e.x, e.y); - env.show[ex][ey] = monster->type + DNGN_START_OF_MONSTERS; - env.show_col[ex][ey] = get_mons_colour( monster ); + env.show[e.x][e.y] = monster->type + DNGN_START_OF_MONSTERS; + env.show_col[e.x][e.y] = get_mons_colour( monster ); return (true); } @@ -1142,7 +1149,7 @@ void monster_grid(bool do_updates) // [enne] - It's possible that mgrd and monster->x/y are out of // sync because they are updated separately. If we can see this // monster, then make sure that the mgrd is set correctly. - if (mgrd[monster->x][monster->y] != s) + if (mgrd(monster->pos()) != s) { #ifdef DEBUG_DIAGNOSTICS // If this mprf triggers for you, please note any special @@ -1150,17 +1157,17 @@ void monster_grid(bool do_updates) // from. mprf(MSGCH_DIAGNOSTICS, "monster (%d) at (%d, %d) was " "improperly placed. Updating mgrd.", s, - monster->x, monster->y); + monster->pos().x, monster->pos().y); #endif - ASSERT(mgrd[monster->x][monster->y] == NON_MONSTER); - mgrd[monster->x][monster->y] = s; + ASSERT(mgrd(monster->pos()) == NON_MONSTER); + mgrd(monster->pos()) = s; } if (!_update_monster_grid(monster)) continue; #ifdef USE_TILE - tile_place_monster(monster->x, monster->y, s, true); + tile_place_monster(monster->pos().x, monster->pos().y, s, true); #endif if (player_monster_visible(monster) @@ -1386,38 +1393,36 @@ inline static void _update_item_grid(const coord_def &gp, const coord_def &ep) void item_grid() { - coord_def gp; - for (gp.y = (you.y_pos - 8); (gp.y < you.y_pos + 9); gp.y++) - for (gp.x = (you.x_pos - 8); (gp.x < you.x_pos + 9); gp.x++) + for (radius_iterator ri(you.pos(), LOS_RADIUS, true, false); ri; ++ri) + { + if (igrd(*ri) != NON_ITEM) { - if (in_bounds(gp) && igrd(gp) != NON_ITEM) - { - const coord_def ep = gp - you.pos() + coord_def(9, 9); - if (env.show(ep)) - _update_item_grid(gp, ep); - } + const coord_def ep = *ri - you.pos() + coord_def(9, 9); + if (env.show(ep)) + _update_item_grid(*ri, ep); } + } } void get_item_glyph( const item_def *item, unsigned *glych, unsigned short *glycol ) { *glycol = item->colour; - _get_symbol( 0, 0, _get_item_dngn_code( *item ), glych, glycol ); + _get_symbol( coord_def(0,0), _get_item_dngn_code( *item ), glych, glycol ); } void get_mons_glyph( const monsters *mons, unsigned *glych, unsigned short *glycol ) { *glycol = get_mons_colour( mons ); - _get_symbol( 0, 0, mons->type + DNGN_START_OF_MONSTERS, glych, glycol ); + _get_symbol( coord_def(0,0), mons->type + DNGN_START_OF_MONSTERS, + glych, glycol ); } inline static void _update_cloud_grid(int cloudno) { int which_colour = LIGHTGREY; - const int ex = env.cloud[cloudno].x - you.x_pos + 9; - const int ey = env.cloud[cloudno].y - you.y_pos + 9; + const coord_def e = env.cloud[cloudno].pos - you.pos() + coord_def(9,9); switch (env.cloud[cloudno].type) { @@ -1477,12 +1482,12 @@ inline static void _update_cloud_grid(int cloudno) break; } - _set_show_backup(ex, ey); - env.show[ex][ey] = DNGN_CLOUD; - env.show_col[ex][ey] = which_colour; + _set_show_backup(e.x, e.y); + env.show(e) = DNGN_CLOUD; + env.show_col(e) = which_colour; #ifdef USE_TILE - tile_place_cloud(ex, ey, env.cloud[cloudno].type, + tile_place_cloud(e.x, e.y, env.cloud[cloudno].type, env.cloud[cloudno].decay); #endif } @@ -1501,7 +1506,7 @@ void cloud_grid(void) if (env.cloud[s].type != CLOUD_NONE) { mnc++; - if (see_grid(env.cloud[s].x, env.cloud[s].y)) + if (see_grid(env.cloud[s].pos)) _update_cloud_grid(s); } } @@ -1607,7 +1612,7 @@ void blood_smell( int strength, const coord_def& where ) #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Player smells blood, pos: (%d, %d), dist = %d)", - you.x_pos, you.y_pos, player_distance); + you.pos().x, you.pos().y, player_distance); #endif you.check_awaken(range - player_distance); // Don't message if you can see the square. @@ -1646,7 +1651,7 @@ void blood_smell( int strength, const coord_def& where ) #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "disturbing %s (%d, %d)", monster->name(DESC_PLAIN).c_str(), - monster->x, monster->y); + monster->pos().x, monster->pos().y); #endif behaviour_event(monster, ME_DISTURB, MHITNOT, where); } @@ -1655,7 +1660,8 @@ void blood_smell( int strength, const coord_def& where ) } #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "alerting %s (%d, %d)", - monster->name(DESC_PLAIN).c_str(), monster->x, monster->y); + monster->name(DESC_PLAIN).c_str(), + monster->pos().x, monster->pos().y); #endif behaviour_event( monster, ME_ALERT, MHITNOT, where ); } @@ -3115,7 +3121,7 @@ static void _reset_travel_colours(std::vector &features) { // We now need to redo travel colours. features.clear(); - find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, &features); + find_travel_pos(you.pos(), NULL, NULL, &features); // Sort features into the order the player is likely to prefer. arrange_features(features); } @@ -3138,7 +3144,7 @@ void show_map( coord_def &spec_place, bool travel_mode ) { travel_cache.update(); - find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, &features); + find_travel_pos(you.pos(), NULL, NULL, &features); // Sort features into the order the player is likely to prefer. arrange_features(features); } @@ -3178,7 +3184,7 @@ void show_map( coord_def &spec_place, bool travel_mode ) const int block_step = Options.level_map_cursor_step; int start_y = 0; // y does scroll - int screen_y = you.y_pos; + int screen_y = you.pos().y; // If close to top of known map, put min_y on top // else if close to bottom of known map, put max_y on bottom. @@ -3195,8 +3201,8 @@ void show_map( coord_def &spec_place, bool travel_mode ) else if (screen_y + half_screen > max_y) screen_y = max_y - half_screen; - int curs_x = you.x_pos - start_x + 1; - int curs_y = you.y_pos - screen_y + half_screen + 1; + int curs_x = you.pos().x - start_x + 1; + int curs_y = you.pos().y - screen_y + half_screen + 1; int search_feat = 0, search_found = 0, anchor_x = -1, anchor_y = -1; bool map_alive = true; @@ -3263,7 +3269,7 @@ void show_map( coord_def &spec_place, bool travel_mode ) // We need to do this all over again so that the user can jump // to the waypoint he just created. features.clear(); - find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, &features); + find_travel_pos(you.pos(), NULL, NULL, &features); // Sort features into the order the player is likely to prefer. arrange_features(features); break; @@ -3475,7 +3481,7 @@ void show_map( coord_def &spec_place, bool travel_mode ) case ';': { int x = start_x + curs_x - 1, y = start_y + curs_y - 1; - if (travel_mode && x == you.x_pos && y == you.y_pos) + if (travel_mode && x == you.pos().x && y == you.pos().y) { if (you.travel_x > 0 && you.travel_y > 0) { @@ -3600,8 +3606,6 @@ bool magic_mapping(int map_radius, int proportion, bool suppress_msg, if (!suppress_msg) mpr( "You feel aware of your surroundings." ); - int i, j, k, l, empty_count; - if (map_radius > 50 && map_radius != 1000) map_radius = 50; else if (map_radius < 5) @@ -3612,84 +3616,71 @@ bool magic_mapping(int map_radius, int proportion, bool suppress_msg, const int very_far = (map_radius * 9) / 10; const bool wizard_map = map_radius == 1000 && you.wizard; - for (i = you.x_pos - map_radius; i < you.x_pos + map_radius; i++) - for (j = you.y_pos - map_radius; j < you.y_pos + map_radius; j++) - { - if (proportion < 100 && random2(100) >= proportion) - continue; // note that proportion can be over 100 - - if (!map_bounds(i, j)) - continue; - - const int dist = grid_distance( you.x_pos, you.y_pos, i, j ); + for ( radius_iterator ri(you.pos(), map_radius, true, false); ri; ++ri ) + { + if (proportion < 100 && random2(100) >= proportion) + continue; // note that proportion can be over 100 + + const int dist = grid_distance( you.pos(), *ri ); - if (dist > pfar && one_chance_in(3)) - continue; + if (dist > pfar && one_chance_in(3)) + continue; - if (dist > very_far && coinflip()) - continue; + if (dist > very_far && coinflip()) + continue; - if (is_terrain_changed(i, j)) - clear_envmap_grid(i, j); + if (is_terrain_changed(*ri)) + clear_envmap_grid(*ri); #ifdef USE_TILE - if (!wizard_map && is_terrain_known(i,j)) - { - // Can't use set_envmap_obj because that would - // overwrite the gmap. - env.tile_bk_bg[i][j] = tile_idx_unseen_terrain(i, j, grd[i][j]); - } + if (!wizard_map && is_terrain_known(*ri)) + { + // Can't use set_envmap_obj because that would + // overwrite the gmap. + env.tile_bk_bg(*ri) = tile_idx_unseen_terrain(ri->x, ri->y, + grd(*ri)); + } #endif + + if (!wizard_map && is_terrain_known(*ri)) + continue; - if (!wizard_map && is_terrain_known(i, j)) - continue; - - empty_count = 8; + bool open = true; - if (grid_is_solid(grd[i][j]) && grd[i][j] != DNGN_CLOSED_DOOR) + if (grid_is_solid(grd(*ri)) && grd(*ri) != DNGN_CLOSED_DOOR) + { + open = false; + for ( adjacent_iterator ai(*ri); ai; ++ai ) { - for (k = -1; k <= 1; k++) - for (l = -1; l <= 1; l++) - { - if (k == 0 && l == 0) - continue; - - if (!map_bounds( i + k, j + l )) - { - --empty_count; - continue; - } - - if (grid_is_opaque( grd[i + k][j + l] ) - && grd[i + k][j + l] != DNGN_CLOSED_DOOR) - { - empty_count--; - } - } + if (map_bounds(*ai) && (!grid_is_opaque(grd(*ai)) + || grd(*ai) == DNGN_CLOSED_DOOR)) + { + open = true; + break; + } } + } - if (empty_count > 0) + if (open > 0) + { + if (wizard_map || !get_envmap_obj(*ri)) + set_envmap_obj(*ri, grd(*ri)); + + // Hack to give demonspawn Pandemonium mutation the ability + // to detect exits magically. + if (wizard_map + || player_mutation_level(MUT_PANDEMONIUM) > 1 + && grd(*ri) == DNGN_EXIT_PANDEMONIUM) { - if (wizard_map || !get_envmap_obj(i, j)) - set_envmap_obj(i, j, grd[i][j]); - - // Hack to give demonspawn Pandemonium mutation the ability - // to detect exits magically. - if (wizard_map - || player_mutation_level(MUT_PANDEMONIUM) > 1 - && grd[i][j] == DNGN_EXIT_PANDEMONIUM) - { - set_terrain_seen( i, j ); - } - else - { - set_terrain_mapped( i, j ); - } + set_terrain_seen( *ri ); } + else + set_terrain_mapped( *ri ); } + } return (true); -} // end magic_mapping() +} // Realize that this is simply a repackaged version of // stuff::see_grid() -- make certain they correlate {dlb}: @@ -3701,10 +3692,10 @@ bool mons_near(const monsters *monster, unsigned short foe) if (foe == MHITYOU) { - if (monster->x > you.x_pos - 9 && monster->x < you.x_pos + 9 - && monster->y > you.y_pos - 9 && monster->y < you.y_pos + 9) + if ( grid_distance(monster->pos(), you.pos()) <= LOS_RADIUS ) { - if (env.show[monster->x - you.x_pos + 9][monster->y - you.y_pos + 9]) + const coord_def diff = monster->pos() - you.pos() + coord_def(9,9); + if (env.show(diff)) return (true); } return (false); @@ -3714,11 +3705,8 @@ bool mons_near(const monsters *monster, unsigned short foe) const monsters *myFoe = &menv[foe]; if (myFoe->type >= 0) { - if (monster->x > myFoe->x - 9 && monster->x < myFoe->x + 9 - && monster->y > myFoe->y - 9 && monster->y < myFoe->y + 9) - { + if ( grid_distance( monster->pos(), myFoe->pos() ) <= LOS_RADIUS ) return (true); - } } return (false); @@ -4569,23 +4557,23 @@ void init_feature_table( void ) } } -unsigned get_screen_glyph( const coord_def &p) +unsigned get_screen_glyph( int x, int y ) { - return get_screen_glyph(p.x, p.y); + return get_screen_glyph(coord_def(x,y)); } -unsigned get_screen_glyph( int x, int y ) +unsigned get_screen_glyph( const coord_def& p ) { - const coord_def ep = view2show(grid2view(coord_def(x,y))); + const coord_def ep = view2show(grid2view(p)); int object = show_appearance(ep); unsigned short colour = env.show_col(ep); unsigned ch; if (!object) - return get_envmap_char(x, y); + return get_envmap_char(p.x, p.y); - _get_symbol( x, y, object, &ch, &colour ); + _get_symbol( p, object, &ch, &colour ); return (ch); } @@ -4648,7 +4636,7 @@ std::string screenshot( bool fullscreen ) unsigned glych; unsigned short glycol = 0; - _get_symbol( gc.x, gc.y, object, &glych, &glycol ); + _get_symbol( gc, object, &glych, &glycol ); ch = glych; } @@ -4744,7 +4732,7 @@ void view_update_at(const coord_def &pos) unsigned short colour = env.show_col(ep); unsigned ch = 0; - _get_symbol( pos.x, pos.y, object, &ch, &colour ); + _get_symbol( pos, object, &ch, &colour ); int flash_colour = you.flash_colour; if (flash_colour == BLACK) @@ -4882,27 +4870,26 @@ void viewwindow(bool draw_it, bool do_updates) { if (grid_is_escape_hatch(grd(gc))) { - learned_something_new(TUT_SEEN_ESCAPE_HATCH, - gc.x, gc.y); + learned_something_new(TUT_SEEN_ESCAPE_HATCH, gc); } else if (grid_is_branch_stairs(grd(gc))) - learned_something_new(TUT_SEEN_BRANCH, gc.x, gc.y); + learned_something_new(TUT_SEEN_BRANCH, gc); else if (is_feature('>', gc)) { - learned_something_new(TUT_SEEN_STAIRS, gc.x, gc.y); + learned_something_new(TUT_SEEN_STAIRS, gc); } else if (is_feature('_', gc)) - learned_something_new(TUT_SEEN_ALTAR, gc.x, gc.y); + learned_something_new(TUT_SEEN_ALTAR, gc); else if (grd(gc) == DNGN_CLOSED_DOOR) - learned_something_new(TUT_SEEN_DOOR, gc.x, gc.y); + learned_something_new(TUT_SEEN_DOOR, gc); else if (grd(gc) == DNGN_ENTER_SHOP) - learned_something_new(TUT_SEEN_SHOP, gc.x, gc.y); + learned_something_new(TUT_SEEN_SHOP, gc); if (igrd[gc.x][gc.y] != NON_ITEM && Options.feature_item_brand != CHATTR_NORMAL && (is_feature('>', gc) || is_feature('<', gc))) { - learned_something_new(TUT_STAIR_BRAND, gc.x, gc.y); + learned_something_new(TUT_STAIR_BRAND, gc); } } } @@ -4947,7 +4934,7 @@ void viewwindow(bool draw_it, bool do_updates) int object = env.show(ep); unsigned short colour = env.show_col(ep); unsigned ch; - _get_symbol( gc.x, gc.y, object, &ch, &colour ); + _get_symbol( gc, object, &ch, &colour ); if (map) { @@ -4988,7 +4975,7 @@ void viewwindow(bool draw_it, bool do_updates) unsigned short colour = env.show_col(ep); unsigned ch; - _get_symbol( gc.x, gc.y, object, &ch, &colour ); + _get_symbol( gc, object, &ch, &colour ); buffy[bufcount] = ch; buffy[bufcount + 1] = colour; @@ -5045,8 +5032,7 @@ void viewwindow(bool draw_it, bool do_updates) if (Options.clean_map && Show_Backup(ep) && is_terrain_seen( gc.x, gc.y )) { - _get_symbol( gc.x, gc.y, - Show_Backup(ep), &ch, &colour ); + _get_symbol( gc, Show_Backup(ep), &ch, &colour ); set_envmap_glyph( gc.x, gc.y, Show_Backup(ep), colour ); } diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h index da934d372a..f4a7fdb807 100644 --- a/crawl-ref/source/view.h +++ b/crawl-ref/source/view.h @@ -151,13 +151,23 @@ int get_mons_colour(const monsters *mons); const feature_def &get_feature_def(dungeon_feature_type feat); -void set_envmap_obj( int x, int y, int object ); +void set_envmap_obj( const coord_def& where, int object ); unsigned get_envmap_char(int x, int y); bool inside_level_bounds(int x, int y); bool inside_level_bounds(const coord_def &p); int get_envmap_obj(int x, int y); +inline int get_envmap_obj(const coord_def& c) { + return get_envmap_obj(c.x, c.y); +} void set_envmap_detected_item(int x, int y, bool detected = true); +inline void set_envmap_detected_item(const coord_def& c, bool detected = true) { + set_envmap_detected_item(c.x, c.y, detected); +} + void set_envmap_detected_mons(int x, int y, bool detected = true); +inline void set_envmap_detected_mons(const coord_def& c, bool detected = true) { + set_envmap_detected_mons(c.x, c.y, detected); +} 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 ); @@ -166,13 +176,28 @@ 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); +inline bool is_envmap_detected_mons(const coord_def& c) { + return is_envmap_detected_mons(c.x, c.y); +} bool is_envmap_item(int x, int y); +inline bool is_envmap_item(const coord_def& c) { + return is_envmap_item(c.x, c.y); +} void set_terrain_mapped( int x, int y ); +inline void set_terrain_mapped( const coord_def& c ) { + set_terrain_mapped(c.x,c.y); +} void set_terrain_seen( int x, int y ); +inline void set_terrain_seen( const coord_def& c ) { + set_terrain_seen(c.x, c.y); +} void set_terrain_changed( int x, int y ); bool is_terrain_known( int x, int y ); bool is_terrain_seen( int x, int y ); bool is_terrain_changed( int x, int y ); +inline bool is_terrain_changed( const coord_def& c ) { + return is_terrain_changed(c.x,c.y); +} bool is_terrain_known(const coord_def &p); bool is_notable_terrain(dungeon_feature_type ftype); diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc index bd25195742..60140a8d1a 100644 --- a/crawl-ref/source/xom.cc +++ b/crawl-ref/source/xom.cc @@ -704,8 +704,7 @@ static bool _xom_is_good(int sever) beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.damage = dice_def(3, 30); beam.flavour = BEAM_ELECTRICITY; - beam.target_x = you.x_pos; - beam.target_y = you.y_pos; + beam.target = you.pos(); beam.name = "blast of lightning"; beam.colour = LIGHTCYAN; beam.thrower = KILL_MISC; -- cgit v1.2.3-54-g00ecf