From b09e4598beef0e8fa7d923bdb33962b85e1c15b1 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 6 Jul 2007 11:35:06 +0000 Subject: [1748743] Fixed followers being misplaced. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1771 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/externs.h | 5 +++- crawl-ref/source/files.cc | 3 ++- crawl-ref/source/mon-util.cc | 62 ++++++++++++++++++++++++++++++-------------- crawl-ref/source/mtransit.cc | 6 ++--- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index d1ad65f870..777d91c33f 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1034,7 +1034,7 @@ public: void set_transit(const level_id &destination); bool find_place_to_live(bool near_player = false); bool find_place_near_player(); - bool find_home_in(coord_def s, coord_def e); + bool find_home_around(const coord_def &c, int radius); bool find_home_anywhere(); void set_ghost(const ghost_demon &ghost); @@ -1166,6 +1166,9 @@ private: bool wants_weapon(const item_def &item) const; bool can_throw_rocks() const; void lose_pickup_energy(); + bool check_set_valid_home(const coord_def &place, + coord_def &chosen, + int &nvalid) const; }; struct cloud_struct diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index e774f3c08b..a0450e8caa 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -928,7 +928,8 @@ static void grab_followers() continue; #if DEBUG_DIAGNOSTICS - mprf( "%s is following.", str_monam(*fmenv, DESC_CAP_THE).c_str()); + mprf(MSGCH_DIAGNOSTICS, "%s is following.", + str_monam(*fmenv, DESC_CAP_THE).c_str()); #endif fmenv->set_transit(level_id::current()); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 9806f99895..bd1cc4da2c 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -3192,36 +3192,60 @@ void monsters::ghost_init() find_place_to_live(); } -bool monsters::find_home_in(coord_def s, coord_def e) +bool monsters::check_set_valid_home(const coord_def &place, + coord_def &chosen, + int &nvalid) const { - for (int iy = s.y; iy <= e.y; ++iy) - { - for (int ix = s.x; ix <= e.x; ++ix) - { - if (!in_bounds(ix, iy)) - continue; + if (!in_bounds(place)) + return (false); - if (ix == you.x_pos && iy == you.y_pos) - continue; + if (place == you.pos()) + return (false); - if (mgrd[ix][iy] != NON_MONSTER || grd[ix][iy] < DNGN_FLOOR) - continue; + if (mgrd(place) != NON_MONSTER || grd(place) < DNGN_FLOOR) + return (false); - x = ix; - y = iy; - return (true); - } + if (one_chance_in(++nvalid)) + chosen = place; + + return (true); +} + +bool monsters::find_home_around(const coord_def &c, int radius) +{ + coord_def place(-1, -1); + int nvalid = 0; + for (int yi = -radius; yi <= radius; ++yi) + { + const coord_def c1(c.x - radius, c.y + yi); + const coord_def c2(c.x + radius, c.y + yi); + check_set_valid_home(c1, place, nvalid); + check_set_valid_home(c2, place, nvalid); + } + + for (int xi = -radius + 1; xi < radius; ++xi) + { + const coord_def c1(c.x + xi, c.y - radius); + const coord_def c2(c.x + xi, c.y + radius); + check_set_valid_home(c1, place, nvalid); + check_set_valid_home(c2, place, nvalid); } + if (nvalid) + { + x = place.x; + y = place.y; + return (true); + } return (false); } bool monsters::find_place_near_player() { - return (find_home_in( you.pos() - coord_def(1, 1), - you.pos() + coord_def(1, 1) ) - || find_home_in( you.pos() - coord_def(6, 6), - you.pos() + coord_def(6, 6) )); + for (int radius = 1; radius < 7; ++radius) + if (find_home_around(you.pos(), radius)) + return (true); + return (false); } bool monsters::find_home_anywhere() diff --git a/crawl-ref/source/mtransit.cc b/crawl-ref/source/mtransit.cc index 3cab171bc8..483e6327f1 100644 --- a/crawl-ref/source/mtransit.cc +++ b/crawl-ref/source/mtransit.cc @@ -154,10 +154,8 @@ bool follower::place(bool near_player) #endif m.target_x = m.target_y = 0; - if (m.flags & MF_TAKING_STAIRS) - m.flags &= ~MF_TAKING_STAIRS; - else - m.flags |= MF_JUST_SUMMONED; + m.flags &= ~MF_TAKING_STAIRS; + m.flags |= MF_JUST_SUMMONED; restore_mons_items(m); return (true); -- cgit v1.2.3-54-g00ecf