diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-08-01 11:19:07 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-08-01 11:19:07 +0000 |
commit | 02d35dea33a54081bb57272737646e1acb684919 (patch) | |
tree | 2555ad0d275b6c10eff40fb16498e500a25c19bc | |
parent | af03dc9c1dfd431269fecd7dee8f27a7292ba3f0 (diff) | |
download | crawl-ref-02d35dea33a54081bb57272737646e1acb684919.tar.gz crawl-ref-02d35dea33a54081bb57272737646e1acb684919.zip |
More minor fixes.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6747 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/monplace.cc | 4 | ||||
-rw-r--r-- | crawl-ref/source/monstuff.cc | 37 | ||||
-rw-r--r-- | crawl-ref/source/stuff.cc | 117 |
3 files changed, 70 insertions, 88 deletions
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index 0d51992a83..a2c3bbe336 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -2684,7 +2684,7 @@ bool monster_pathfind::traversable(coord_def p) // (Checked by traversable().) int monster_pathfind::travel_cost(coord_def npos) { - ASSERT(grid_distance(pos.x, pos.y, npos.x, npos.y) <= 1); + ASSERT(grid_distance(pos, npos) <= 1); // Doors need to be opened. if (grd(npos) == DNGN_CLOSED_DOOR || grd(npos) == DNGN_SECRET_DOOR) @@ -2743,7 +2743,7 @@ int monster_pathfind::travel_cost(coord_def npos) // The estimated cost to reach a grid is simply max(dx, dy). int monster_pathfind::estimated_cost(coord_def p) { - return (grid_distance(p.x, p.y, target.x, target.y)); + return (grid_distance(p, target)); } void monster_pathfind::add_new_pos(coord_def npos, int total) diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 9565aae201..fd453e7069 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -91,8 +91,10 @@ static spell_type _map_wand_to_mspell(int wand_type); // [dshaligram] Doesn't need to be extern. static coord_def mmov; -static int compass_x[8] = { -1, 0, 1, 1, 1, 0, -1, -1 }; -static int compass_y[8] = { -1, -1, -1, 0, 1, 1, 1, 0 }; +static const coord_def mon_compass[8] = { + coord_def(-1,-1), coord_def(0,-1), coord_def(1,-1), coord_def(1,0), + coord_def( 1, 1), coord_def(0, 1), coord_def(-1,1), coord_def(-1,0) +}; static bool immobile_monster[MAX_MONSTERS]; @@ -6104,7 +6106,7 @@ static void _handle_monster_move(int i, monsters *monster) // This is the routine that controls monster AI. // //--------------------------------------------------------------- -void handle_monsters(void) +void handle_monsters() { // Keep track of monsters that have already moved and don't allow // them to move again. @@ -7120,11 +7122,10 @@ static bool _monster_move(monsters *monster) int current_distance = grid_distance(monster->pos(), monster->target); int dir = -1; - int i, mod, newdir; - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { - if (compass_x[i] == mmov.x && compass_y[i] == mmov.y) + if (mon_compass[i] == mmov) { dir = i; break; @@ -7153,15 +7154,13 @@ static bool _monster_move(monsters *monster) } // Try both directions. - for (mod = sdir, i = 0; i < 2; mod += inc, i++) + for (int mod = sdir, i = 0; i < 2; mod += inc, i++) { - newdir = (dir + 8 + mod) % 8; - if (good_move[compass_x[newdir] + 1][compass_y[newdir] + 1]) + int newdir = (dir + 8 + mod) % 8; + if (good_move[mon_compass[newdir].x+1][mon_compass[newdir].y+1]) { - dist[i] = grid_distance(monster->pos().x + compass_x[newdir], - monster->pos().y + compass_y[newdir], - monster->target.x, - monster->target.y); + dist[i] = grid_distance(monster->pos()+mon_compass[newdir], + monster->target); } else { @@ -7179,14 +7178,12 @@ static bool _monster_move(monsters *monster) { if (dist[0] >= dist[1] && dist[0] >= current_distance) { - mmov.x = compass_x[((dir+8)+sdir)%8]; - mmov.y = compass_y[((dir+8)+sdir)%8]; + mmov = mon_compass[((dir+8)+sdir)%8]; break; } if (dist[1] >= dist[0] && dist[1] >= current_distance) { - mmov.x = compass_x[((dir+8)-sdir)%8]; - mmov.y = compass_y[((dir+8)-sdir)%8]; + mmov = mon_compass[((dir+8)-sdir)%8]; break; } } @@ -7194,14 +7191,12 @@ static bool _monster_move(monsters *monster) { if (dist[0] <= dist[1] && dist[0] <= current_distance) { - mmov.x = compass_x[((dir+8)+sdir)%8]; - mmov.y = compass_y[((dir+8)+sdir)%8]; + mmov = mon_compass[((dir+8)+sdir)%8]; break; } if (dist[1] <= dist[0] && dist[1] <= current_distance) { - mmov.x = compass_x[((dir+8)-sdir)%8]; - mmov.y = compass_y[((dir+8)-sdir)%8]; + mmov = mon_compass[((dir+8)-sdir)%8]; break; } } diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index ad112415f9..8346cb4764 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -1560,42 +1560,32 @@ int fuzz_value(int val, int lowfuzz, int highfuzz, int naverage) int near_stairs(const coord_def &p, int max_dist, dungeon_char_type &stair_type, branch_type &branch) { - coord_def inc; - - for (inc.x = -max_dist; inc.x <= max_dist; ++inc.x) + for (radius_iterator ri(p, max_dist, true, false); ri; ++ri) { - for (inc.y = -max_dist; inc.y <= max_dist; ++inc.y) + const dungeon_feature_type feat = grd(*ri); + if (is_stair(feat)) { - const coord_def np(p + inc); - - if (!in_bounds(np)) + // Shouldn't happen for escape hatches. + if (grid_is_escape_hatch(feat)) continue; - - const dungeon_feature_type feat = grd(np); - if (is_stair(feat)) + + stair_type = get_feature_dchar(feat); + + // Is it a branch stair? + for (int i = 0; i < NUM_BRANCHES; ++i) { - // Shouldn't happen for escape hatches. - if (grid_is_escape_hatch(feat)) - continue; - - stair_type = get_feature_dchar(feat); - - // Is it a branch stair? - for (int i = 0; i < NUM_BRANCHES; ++i) + if (branches[i].entry_stairs == feat) { - if (branches[i].entry_stairs == feat) - { - branch = branches[i].id; - break; - } - else if (branches[i].exit_stairs == feat) - { - branch = branches[i].parent_branch; - break; - } + branch = branches[i].id; + break; + } + else if (branches[i].exit_stairs == feat) + { + branch = branches[i].parent_branch; + break; } - return (np == you.pos()) ? 2 : 1; } + return (*ri == you.pos()) ? 2 : 1; } } @@ -1604,8 +1594,7 @@ int near_stairs(const coord_def &p, int max_dist, bool is_trap_square(dungeon_feature_type grid) { - return (grid >= DNGN_TRAP_MECHANICAL - && grid <= DNGN_UNDISCOVERED_TRAP); + return (grid >= DNGN_TRAP_MECHANICAL && grid <= DNGN_UNDISCOVERED_TRAP); } // Does the equivalent of KILL_RESET on all monsters in LOS. Should only be @@ -1614,50 +1603,48 @@ void zap_los_monsters() { losight(env.show, grd, you.pos()); - for (int y = crawl_view.vlos1.y; y <= crawl_view.vlos2.y; ++y) - for (int x = crawl_view.vlos1.x; x <= crawl_view.vlos2.x; ++x) - { - if (!in_vlos(x, y)) - continue; - - const int gx = view2gridX(x), - gy = view2gridY(y); - - if (!map_bounds(gx, gy)) - continue; + for (rectangle_iterator ri(crawl_view.vlos1, crawl_view.vlos2); ri; ++ri ) + { + if (!in_vlos(*ri)) + continue; - if (gx == you.pos().x && gy == you.pos().y) - continue; + const coord_def g = view2grid(*ri); - int imon = mgrd[gx][gy]; + if (!map_bounds(g)) + continue; - // At tutorial beginning disallow items in line of sight. - if (Options.tutorial_events[TUT_SEEN_FIRST_OBJECT]) - { - int item = igrd[gx][gy]; + if (g == you.pos()) + continue; - if (item != NON_ITEM && is_valid_item(mitm[item]) ) - destroy_item(item); - } + int imon = mgrd(g); - if (imon == NON_MONSTER || imon == MHITYOU) - continue; + // At tutorial beginning disallow items in line of sight. + if (Options.tutorial_events[TUT_SEEN_FIRST_OBJECT]) + { + int item = igrd(g); + + if (item != NON_ITEM && is_valid_item(mitm[item]) ) + destroy_item(item); + } - // If we ever allow starting with a friendly monster, - // we'll have to check here. - monsters *mon = &menv[imon]; + if (imon == NON_MONSTER || imon == MHITYOU) + continue; - if (mons_class_flag( mon->type, M_NO_EXP_GAIN )) - continue; + // If we ever allow starting with a friendly monster, + // we'll have to check here. + monsters *mon = &menv[imon]; + + if (mons_class_flag( mon->type, M_NO_EXP_GAIN )) + continue; #ifdef DEBUG_DIAGNOSTICS - mprf(MSGCH_DIAGNOSTICS, "Dismissing %s", - mon->name(DESC_PLAIN, true).c_str() ); + mprf(MSGCH_DIAGNOSTICS, "Dismissing %s", + mon->name(DESC_PLAIN, true).c_str() ); #endif - // Mark as summoned so its items will also be discarded. - mon->mark_summoned(1, true); - monster_die(mon, KILL_DISMISSED, 0); - } + // Mark as summoned so its items will also be discarded. + mon->mark_summoned(1, true); + monster_die(mon, KILL_DISMISSED, 0); + } } ////////////////////////////////////////////////////////////////////////// |