From 5f61c3caf7af3eee7467d860d4b284bbcd7b6f70 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 19 May 2008 19:01:25 +0000 Subject: Fix 1858979: Monsters being capable to reach through wallsl. (And some cleanup.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5136 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/enum.h | 17 ++++++++++------- crawl-ref/source/externs.h | 2 +- crawl-ref/source/mon-util.cc | 12 ++++++++---- crawl-ref/source/monstuff.cc | 23 ++++++++++++++--------- crawl-ref/source/travel.cc | 19 ++++++++++++------- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index b751effce0..c77ab2098b 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -860,9 +860,8 @@ enum dungeon_feature_type DNGN_CLEAR_ROCK_WALL, // 9 - Transparent DNGN_CLEAR_STONE_WALL, // 10 - Transparent DNGN_CLEAR_PERMAROCK_WALL, // 11 - Transparent - DNGN_ORCISH_IDOL, // 12 - Can see past - // XXX: lowest/highest grid value which is a wall + // lowest/highest grid value which is a wall DNGN_MINWALL = DNGN_WAX_WALL, DNGN_MAXWALL = DNGN_CLEAR_PERMAROCK_WALL, @@ -870,17 +869,21 @@ enum dungeon_feature_type DNGN_RNDWALL_MIN = DNGN_METAL_WALL, DNGN_RNDWALL_MAX = DNGN_STONE_WALL, - // XXX: highest grid value which is opaque + // highest grid value which is opaque DNGN_MAXOPAQUE = DNGN_PERMAROCK_WALL, - // XXX: lowest grid value which can be seen through + // lowest grid value which can be seen through DNGN_MINSEE = DNGN_CLEAR_ROCK_WALL, + // highest grid value which can't be reached through + DNGN_MAX_NONREACH = DNGN_CLEAR_PERMAROCK_WALL, + + // Can be seen through and reached past. + DNGN_ORCISH_IDOL = 12, DNGN_GRANITE_STATUE = 21, // 21 - DNGN_STATUE_RESERVED_1, - DNGN_STATUE_RESERVED_2, + DNGN_STATUE_RESERVED, - // XXX: lowest grid value which can be passed by walking etc. + // lowest grid value which can be passed by walking etc. DNGN_MINMOVE = 31, DNGN_LAVA = 61, // 61 diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 432b4eee52..5c70f5e1f5 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1209,7 +1209,7 @@ public: bool invisible() const; bool can_see_invisible() const; bool visible_to(const actor *looker) const; - bool mon_see_grid(int tx, int ty) const; + bool mon_see_grid(int tx, int ty, bool reach = false) const; bool can_see(const actor *target) const; bool is_icy() const; bool paralysed() const; diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 822f3f2416..1b4f701b60 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -5614,13 +5614,17 @@ bool monsters::visible_to(const actor *looker) const } } -bool monsters::mon_see_grid(int tx, int ty) const +bool monsters::mon_see_grid(int tx, int ty, bool reach) const { if (distance(x, y, tx, ty) > LOS_RADIUS * LOS_RADIUS) - return false; + return (false); + + dungeon_feature_type max_disallowed = DNGN_MAXOPAQUE; + if (reach) + max_disallowed = DNGN_MAX_NONREACH; - // Ignoring clouds for now. - return (num_feats_between(x, y, tx, ty, DNGN_UNSEEN, DNGN_MAXOPAQUE) == 0); + // XXX: Ignoring clouds for now. + return (num_feats_between(x, y, tx, ty, DNGN_UNSEEN, max_disallowed) == 0); } bool monsters::can_see(const actor *target) const diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 2973a9a4f3..ca3b976f16 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -3271,7 +3271,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem) break; } - if ((monster->type != MONS_HELL_HOUND && random2(13) < 3) + if (monster->type != MONS_HELL_HOUND && random2(13) < 3 || one_chance_in(10)) { setup_dragon(monster, beem); @@ -3546,7 +3546,7 @@ static bool _handle_reaching(monsters *monster) 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)) + if (dx == 2 && dy <= 2 || dy == 2 && dx <= 2) { ret = true; monster_attack( monster_index(monster) ); @@ -3555,13 +3555,16 @@ static bool _handle_reaching(monsters *monster) } else if (monster->foe != MHITNOT) { + int foe_x = menv[monster->foe].x; + int foe_y = menv[monster->foe].y; // same comments as to invisibility as above. - if (monster->target_x == menv[monster->foe].x - && monster->target_y == menv[monster->foe].y) + if (monster->target_x == foe_x && monster->target_y == foe_y + && monster->mon_see_grid(foe_x, foe_y, true)) { - int dx = abs(monster->x - menv[monster->foe].x); - int dy = abs(monster->y - menv[monster->foe].y); - if ((dx == 2 && dy <= 2) || (dy == 2 && dx <= 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 ); @@ -4864,8 +4867,10 @@ static void _handle_monster_move(int i, monsters *monster) } if (mons_is_caught(monster)) + { // Struggling against the net takes time. _swim_or_move_energy(monster); + } else { // calculates mmov_x, mmov_y based on monster target. @@ -4898,13 +4903,13 @@ 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) + || monster->x + mmov_x >= GXM) { mmov_x = 0; } if (monster->y + mmov_y < 0 - || monster->y + mmov_y >= GYM) + || monster->y + mmov_y >= GYM) { mmov_y = 0; } diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 5e6a845136..6c97a115b7 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -945,8 +945,10 @@ static void explore_find_target_square() anti_zigzag_dir = 0; } else + { anti_zigzag_dir = std::min(prev_travel_moves[0], prev_travel_moves[1]) + 1; + } } // anti_zigzag_dir might have just been set, or might have @@ -1133,7 +1135,7 @@ 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) + || you.running.x == you.x_pos && you.running.y == you.y_pos || !is_valid_explore_target(you.running.x, you.running.y)) { explore_find_target_square(); @@ -1488,13 +1490,14 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode) unexplored_place = greedy_place = coord_def(0, 0); unexplored_dist = greedy_dist = UNFOUND_DIST; - refdist = Options.explore_item_greed > 0? &unexplored_dist: &greedy_dist; + refdist = (Options.explore_item_greed > 0) ? &unexplored_dist + : &greedy_dist; // Abort run if we're trying to go someplace evil. Travel to traps is // specifically allowed here if the player insists on it. if (!floodout && !is_travelsafe_square(start.x, start.y, false) - && !is_trap(start.x, start.y)) // The player likes pain + && !is_trap(start.x, start.y)) // player likes pain { return coord_def(0, 0); } @@ -1532,8 +1535,8 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode) { if (path_examine_point(circumference[circ_index][i])) { - return (runmode == RMODE_TRAVEL? travel_move() - : explore_target()); + return (runmode == RMODE_TRAVEL ? travel_move() + : explore_target()); } } @@ -1573,14 +1576,16 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode) // An exclude - wherever it is - is always a feature. if (std::find(features->begin(), features->end(), exc.pos) == features->end()) + { features->push_back(exc.pos); + } fill_exclude_radius(exc); } } - return (rmode == RMODE_TRAVEL? travel_move() - : explore_target()); + return (rmode == RMODE_TRAVEL ? travel_move() + : explore_target()); } bool travel_pathfind::square_slows_movement(const coord_def &c) -- cgit v1.2.3-54-g00ecf