summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/misc.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-04-17 21:28:56 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-04-17 21:28:56 +0000
commit12de33d2d95164e30a8a2ac960ad28b2a69383e3 (patch)
tree4b238a712c0c7f329eed44cc23832f6998c7b2ca /crawl-ref/source/misc.cc
parent46c7199d6ae8c006a78799a1c59dacf4e2d77c8f (diff)
downloadcrawl-ref-12de33d2d95164e30a8a2ac960ad28b2a69383e3.tar.gz
crawl-ref-12de33d2d95164e30a8a2ac960ad28b2a69383e3.zip
Another modification of autotargetting submerged monsters, based off
BR 1935715. * Targeting a square with a known submerged monster ("strange disturbance" description) always enforces '!' rather than '.' * Submerged monsters only get targetted if there are no other more viable targets (dangerous monsters, really) in sight. The latter uses a heavily modified i_feel_safe() that now draws on get_playervisible_monsters(), which got numerous new parameters to cover all possibilities. :p git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@4314 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/misc.cc')
-rw-r--r--crawl-ref/source/misc.cc150
1 files changed, 67 insertions, 83 deletions
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index bb1cba82f7..5f210c6ca7 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2537,10 +2537,10 @@ bool mons_is_safe(const struct monsters *mon, bool want_move)
|| mons_class_flag(mon->type, M_NO_EXP_GAIN);
#ifdef CLUA_BINDINGS
- bool moving = ((!you.delay_queue.empty() &&
- is_run_delay(you.delay_queue.front().type) &&
- you.delay_queue.front().type != DELAY_REST) ||
- you.running < RMODE_NOT_RUNNING || want_move);
+ bool moving = ((!you.delay_queue.empty()
+ && is_run_delay(you.delay_queue.front().type)
+ && you.delay_queue.front().type != DELAY_REST)
+ || you.running < RMODE_NOT_RUNNING || want_move);
int dist = grid_distance(you.x_pos, you.y_pos,
mon->x, mon->y);
@@ -2559,113 +2559,97 @@ bool mons_is_safe(const struct monsters *mon, bool want_move)
// Return all monsters in LOS that the player is able to see
// and recognize as being a monster.
-void get_playervisible_monsters(std::vector<monsters*>& mons)
+void get_playervisible_monsters(std::vector<monsters*> &mons, bool want_move,
+ bool just_check, bool dangerous, int range)
{
- const int ystart = MAX(0, you.y_pos - LOS_RADIUS);
- const int yend = MIN(GYM, you.y_pos + LOS_RADIUS);
- const int xstart = MAX(0, you.x_pos - LOS_RADIUS);
- const int xend = MIN(GXM, you.x_pos + LOS_RADIUS);
+ if (range == -1)
+ range = LOS_RADIUS;
+
+ const int ystart = MAX(0, you.y_pos - range);
+ const int yend = MIN(GYM, you.y_pos + range);
+ const int xstart = MAX(0, you.x_pos - range);
+ const int xend = MIN(GXM, you.x_pos + range);
// monster check
for ( int y = ystart; y < yend; ++y )
- for ( int x = xstart; x < xend; ++x )
- {
- const unsigned short targ_monst = env.mgrid[x][y];
- if ( targ_monst != NON_MONSTER )
+ for ( int x = xstart; x < xend; ++x )
{
- if ( see_grid(x,y) )
+ const unsigned short targ_monst = env.mgrid[x][y];
+ if ( targ_monst != NON_MONSTER )
{
- monsters *mon = &env.mons[targ_monst];
- if ( player_monster_visible(mon) &&
- !mons_is_submerged(mon) &&
- (!mons_is_mimic(mon->type) || mons_is_known_mimic(mon))
- )
+ if ( see_grid(x,y) )
{
- mons.push_back(mon);
+ monsters *mon = &env.mons[targ_monst];
+ if ( player_monster_visible(mon)
+ && !mons_is_submerged(mon)
+ && (!mons_is_mimic(mon->type)
+ || mons_is_known_mimic(mon))
+ && (!dangerous || !mons_is_safe(mon, want_move)))
+ {
+ mons.push_back(mon);
+ if (just_check)
+ {
+ // one monster found, that's enough
+ return;
+ }
+ }
}
}
}
- }
}
-bool i_feel_safe(bool announce, bool want_move)
+bool i_feel_safe(bool announce, bool want_move, bool just_monsters, int range)
{
- int ystart = you.y_pos - 9, xstart = you.x_pos - 9;
- int yend = you.y_pos + 9, xend = you.x_pos + 9;
- if ( xstart < 0 ) xstart = 0;
- if ( ystart < 0 ) ystart = 0;
- if ( xend >= GXM ) xend = GXM;
- if ( yend >= GYM ) yend = GYM;
-
- if (in_bounds(you.x_pos, you.y_pos)
- && env.cgrid[you.x_pos][you.y_pos] != EMPTY_CLOUD)
- {
- const cloud_type type =
- env.cloud[ env.cgrid[you.x_pos][you.y_pos] ].type;
- if (is_damaging_cloud(type, false))
- {
- if (announce)
- mprf(MSGCH_WARN, "You're standing in a cloud of %s!",
- cloud_name(type).c_str());
- return (false);
- }
- }
-
- // no monster will attack you inside a sanctuary,
- // so presence of monsters won't matter
- if (is_sanctuary(you.x_pos, you.y_pos))
- return (true);
-
- std::vector<const monsters *> mons;
-
- // monster check
- // XXX: refactor this to make use of get_playervisible_monsters()
- for ( int y = ystart; y < yend; ++y )
+ if (!just_monsters)
{
- for ( int x = xstart; x < xend; ++x )
+ if (in_bounds(you.x_pos, you.y_pos)
+ && env.cgrid[you.x_pos][you.y_pos] != EMPTY_CLOUD)
{
- // if you can see an unfriendly monster, then you feel unsafe
- if ( see_grid(x,y) )
+ const cloud_type type =
+ env.cloud[ env.cgrid[you.x_pos][you.y_pos] ].type;
+ if (is_damaging_cloud(type, false))
{
- const unsigned short targ_monst = mgrd[x][y];
- if ( targ_monst != NON_MONSTER )
+ if (announce)
{
- const monsters *mon = &menv[targ_monst];
- if ( player_monster_visible(mon) &&
- !mons_is_submerged(mon) &&
- !mons_is_mimic(mon->type) &&
- !mons_is_safe(mon, want_move))
- {
- if (announce)
- mons.push_back(mon);
- else
- {
- tutorial_first_monster(*mon);
- return false;
- }
- }
+ mprf(MSGCH_WARN, "You're standing in a cloud of %s!",
+ cloud_name(type).c_str());
}
+ return (false);
}
}
+
+ // no monster will attack you inside a sanctuary,
+ // so presence of monsters won't matter
+ if (is_sanctuary(you.x_pos, you.y_pos))
+ return (true);
}
- if (announce)
+ // monster check
+ std::vector<monsters*> visible;
+ get_playervisible_monsters(visible, !announce, want_move, true, range);
+
+ // No monsters found.
+ if (visible.empty())
+ return true;
+
+ // Announce the presence of monsters (Eidolos).
+ if (visible.size() == 1)
{
- // Announce the presence of monsters (Eidolos).
- if (mons.size() == 1)
+ const monsters &m = *visible[0];
+ if (announce)
{
- const monsters &m = *mons[0];
mprf(MSGCH_WARN, "Not with %s in view!",
- m.name(DESC_NOCAP_A).c_str());
- }
- else if (mons.size() > 1)
- {
- mprf(MSGCH_WARN, "Not with these monsters around!");
+ m.name(DESC_NOCAP_A).c_str());
}
- return (mons.empty());
+ else
+ tutorial_first_monster(m);
+ }
+ else if (announce && visible.size() > 1)
+ {
+ mprf(MSGCH_WARN, "Not with these monsters around!");
}
- return true;
+ return (false);
}
static const char *shop_types[] = {