diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-29 18:56:02 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-29 19:00:40 +0100 |
commit | 7e52c55e707e2fbb848ed1b12a17c8a85b134024 (patch) | |
tree | e2e98b0eccaa8975d63700f8d91fca73663af5dd | |
parent | 142509155d84c040fda2d18e5d848240c17bfd72 (diff) | |
download | crawl-ref-7e52c55e707e2fbb848ed1b12a17c8a85b134024.tar.gz crawl-ref-7e52c55e707e2fbb848ed1b12a17c8a85b134024.zip |
Rewrite _set_nearest_monster_foe.
With the previous one_chance_ins, it was failing quite often with
enemies in view.
-rw-r--r-- | crawl-ref/source/monstuff.cc | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 6688f48177..5977a64d7c 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -4816,8 +4816,8 @@ static void _handle_behaviour(monsters *mon) } } -static bool _mons_check_set_foe(monsters *mon, const coord_def& p, - bool friendly, bool neutral) +static bool _mons_check_foe(monsters *mon, const coord_def& p, + bool friendly, bool neutral) { if (!inside_level_bounds(p)) return (false); @@ -4825,7 +4825,6 @@ static bool _mons_check_set_foe(monsters *mon, const coord_def& p, if (!friendly && !neutral && p == you.pos() && you.visible_to(mon) && !is_sanctuary(p)) { - mon->foe = MHITYOU; return (true); } @@ -4837,7 +4836,6 @@ static bool _mons_check_set_foe(monsters *mon, const coord_def& p, && (mons_friendly(foe) != friendly || (neutral && !mons_neutral(foe)))) { - mon->foe = foe->mindex(); return (true); } } @@ -4852,21 +4850,23 @@ void _set_nearest_monster_foe(monsters *mon) for (int k = 1; k <= LOS_RADIUS; ++k) { - int count = 0; - bool success = false; + std::vector<coord_def> monster_pos; for (int i = -k; i <= k; ++i) for (int j = -k; j <= k; (abs(i) == k ? j++ : j += 2*k)) { const coord_def p = mon->pos() + coord_def(i, j); - if (one_chance_in(++count) - && _mons_check_set_foe(mon, p, friendly, neutral)) - { - success = true; - } + if (_mons_check_foe(mon, p, friendly, neutral)) + monster_pos.push_back(p); } + if (monster_pos.empty()) + continue; - if (success) - break; + const coord_def mpos = monster_pos[random2(monster_pos.size())]; + if (mpos == you.pos()) + mon->foe = MHITYOU; + else + mon->foe = env.mgrid(mpos); + return; } } |