summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorHaran Pilpel <haranp@users.sourceforge.net>2010-01-15 11:08:31 +0200
committerHaran Pilpel <haranp@users.sourceforge.net>2010-01-15 11:08:31 +0200
commit03588849963bb625e961f4f256ed5f4fa0ed6cb3 (patch)
treec4372d8a4f2619f87a0a4d8ce1ff68372610641c /crawl-ref
parent317d05294c07c9ccca0f3682c39269cb8f8de938 (diff)
downloadcrawl-ref-03588849963bb625e961f4f256ed5f4fa0ed6cb3.tar.gz
crawl-ref-03588849963bb625e961f4f256ed5f4fa0ed6cb3.zip
Merge Firing and Aim lines, per dcss:messagespam.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/directn.cc260
-rw-r--r--crawl-ref/source/item_use.cc8
-rw-r--r--crawl-ref/source/mon-behv.h2
-rw-r--r--crawl-ref/source/mon-stuff.cc32
-rw-r--r--crawl-ref/source/mon-stuff.h3
-rw-r--r--crawl-ref/source/spl-util.cc3
6 files changed, 166 insertions, 142 deletions
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index 7104d98cb3..3ef43e4404 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -273,18 +273,55 @@ static command_type shift_direction(command_type cmd)
}
}
-static const char *target_mode_help_text(int mode)
+// Print the proper prompt while in targetting mode.
+// mode indicates the targetting mode we are in, and cell is where we are
+// currently looking at (so that we can describe it, if necessary.)
+static void _target_mode_prompt(const char* prompt_prefix,
+ targetting_type mode,
+ const coord_def& cell)
{
+ if (prompt_prefix == NULL)
+ prompt_prefix = "Aim"; // default if none given
+
+ // Find out what we're looking at.
+ const monsters* mon_in_cell = monster_at(cell);
+ if (mon_in_cell && !you.can_see(mon_in_cell))
+ mon_in_cell = NULL;
+
+ // Is it our target?
+ const bool looking_at_target = mon_in_cell
+ && (get_current_target() == mon_in_cell);
+
+ // Work out what keys we can use to hit this target (if any.)
+ std::string hint_string;
+ if (looking_at_target)
+ hint_string = ", p/t - " + mon_in_cell->name(DESC_PLAIN);
+ else if (mon_in_cell)
+ hint_string = ", t - " + mon_in_cell->name(DESC_PLAIN);
+
+
+ // All preparatory work done, build the prompt string.
+ std::string prompt = prompt_prefix;
+ prompt += " (? - help";
+
switch (mode)
{
case DIR_NONE:
- return (Options.target_unshifted_dirs ? "? - help" :
- "? - help, Shift-Dir - shoot in a straight line");
+ if (Options.target_unshifted_dirs)
+ prompt += ", Shift-Dir - straight line";
+ prompt += hint_string;
+ break;
case DIR_TARGET:
- return "? - help, Dir - move target cursor";
+ prompt += ", Dir - move target cursor";
+ prompt += hint_string;
+ break;
default:
- return "? - help";
+ break;
}
+ prompt += ")";
+
+ // Display the prompt.
+ mprf(MSGCH_PROMPT, "%s", prompt.c_str());
}
#ifndef USE_TILE
@@ -1001,6 +1038,96 @@ bool _init_mlist()
}
#endif
+// Find a good square to start targetting from.
+static coord_def _find_default_target(targetting_type restricts,
+ targ_mode_type mode,
+ int range,
+ bool needs_path)
+{
+ coord_def result = you.pos();
+ bool success = false;
+
+ if (restricts == DIR_TARGET_OBJECT)
+ {
+ // Try to find an object.
+ success = _find_square_wrapper(result, 1, _find_object,
+ needs_path, TARG_ANY, range, true,
+ LOS_FLIPVH);
+ }
+ else if (mode == TARG_ENEMY || mode == TARG_HOSTILE)
+ {
+ // Try to find an enemy monster.
+
+ // First try to pick our previous target.
+ const monsters *mon_target = get_current_target();
+ if (mon_target
+ // not made friendly since then
+ && (mons_attitude(mon_target) == ATT_HOSTILE
+ || mode == TARG_ENEMY && !mon_target->friendly())
+ // still in range
+ && _is_target_in_range(mon_target->pos(), range))
+ {
+ result = mon_target->pos();
+ success = true;
+ }
+ else
+ {
+ // The previous target is no good. Try to find one from scratch.
+ success = _find_square_wrapper(result, 1, _find_monster,
+ needs_path, mode, range, true);
+
+ // If we couldn't, maybe it was because of line-of-fire issues.
+ // Check if that's happening, and inform the user (because it's
+ // pretty confusing.)
+ if (!success
+ && needs_path
+ && _find_square_wrapper(result, 1, _find_monster,
+ false, mode, range, true))
+ {
+ mpr("All monsters which could be auto-targeted are covered by "
+ "a wall or statue which interrupts your line of fire, even "
+ "though it doesn't interrupt your line of sight.",
+ MSGCH_PROMPT);
+ }
+ }
+ }
+
+ if (!success)
+ result = you.pos();
+
+ return result;
+}
+
+static void _draw_beam(ray_def ray, const coord_def& beam_target, int range)
+{
+ // Draw the new ray with magenta '*'s, not including your square
+ // or the target square. Out-of-range cells get grey '*'s instead.
+ while (ray.pos() != beam_target)
+ {
+ if (ray.pos() != you.pos())
+ {
+ ASSERT(in_los(ray.pos()));
+
+ const bool in_range = (range < 0)
+ || grid_distance(ray.pos(), you.pos()) <= range;
+#ifdef USE_TILE
+ tile_place_ray(ray.pos(), in_range);
+#else
+ const int bcol = in_range ? MAGENTA : DARKGREY;
+ _draw_ray_glyph(ray.pos(), bcol, '*',
+ bcol | COLFLAG_REVERSE, in_range);
+#endif
+ }
+ ray.advance();
+ }
+ textcolor(LIGHTGREY);
+#ifdef USE_TILE
+ const bool in_range = (range < 0
+ || grid_distance(ray.pos(), you.pos()) <= range);
+ tile_place_ray(moves.target, in_range);
+#endif
+}
+
void direction(dist& moves, const targetting_type restricts,
targ_mode_type mode, const int range, const bool just_looking,
const bool needs_path, const bool may_target_monster,
@@ -1057,44 +1184,20 @@ void direction(dist& moves, const targetting_type restricts,
moves.delta.reset();
moves.target = objfind_pos = monsfind_pos = you.pos();
- // If we show the beam on startup, we have to initialise it.
+ // Find a default target.
+ if (Options.default_target)
+ moves.target = _find_default_target(restricts, mode, range, needs_path);
+
+ // If requested, show the beam on startup.
if (show_beam)
{
have_beam = find_ray(you.pos(), moves.target, ray);
beam_target = moves.target;
+ if (have_beam)
+ _draw_beam(ray, beam_target, range);
}
- bool skip_iter = false;
- bool found_autotarget = false;
bool target_unshifted = Options.target_unshifted_dirs;
-
- // Find a default target.
- if (Options.default_target)
- {
- if (restricts == DIR_TARGET_OBJECT)
- {
- skip_iter = true;
- found_autotarget = true;
- }
- else if (mode == TARG_ENEMY || mode == TARG_HOSTILE)
- {
- skip_iter = true; // Skip first iteration...XXX mega-hack
- if (you.prev_targ != MHITNOT && you.prev_targ != MHITYOU)
- {
- const monsters *montarget = &menv[you.prev_targ];
- if (you.can_see(montarget)
- // not made friendly since then
- && (mons_attitude(montarget) == ATT_HOSTILE
- || mode == TARG_ENEMY && !montarget->friendly())
- && _is_target_in_range(montarget->pos(), range))
- {
- found_autotarget = true;
- moves.target = montarget->pos();
- }
- }
- }
- }
-
bool show_prompt = true;
bool moved_with_keys = true;
@@ -1119,8 +1222,7 @@ void direction(dist& moves, const targetting_type restricts,
// We'll live with that.
if (!just_looking && (show_prompt || beh->should_redraw()))
{
- mprf(MSGCH_PROMPT, "%s (%s)", prompt ? prompt : "Aim",
- target_mode_help_text(restricts));
+ _target_mode_prompt(prompt, restricts, moves.target);
if ((mode == TARG_ANY || mode == TARG_FRIEND)
&& moves.target == you.pos())
@@ -1143,19 +1245,7 @@ void direction(dist& moves, const targetting_type restricts,
if (moved_with_keys)
cursorxy(grid2viewX(moves.target.x), grid2viewY(moves.target.y));
- command_type key_command;
-
- if (skip_iter)
- {
- if (restricts == DIR_TARGET_OBJECT)
- key_command = CMD_TARGET_OBJ_CYCLE_FORWARD;
- else if (found_autotarget)
- key_command = CMD_NO_CMD;
- else
- key_command = CMD_TARGET_CYCLE_FORWARD; // Find closest target.
- }
- else
- key_command = beh->get_command();
+ command_type key_command = beh->get_command();
#ifdef USE_TILE
// If a mouse command, update location to mouse position.
@@ -1210,8 +1300,6 @@ void direction(dist& moves, const targetting_type restricts,
bool loop_done = false;
coord_def old_target = moves.target;
- if (skip_iter)
- old_target.x += 500; // hmmm...hack
int i;
@@ -1228,8 +1316,10 @@ void direction(dist& moves, const targetting_type restricts,
{
moves.target = monsfind_pos;
}
- else if (!skip_iter)
+ else
+ {
flush_input_buffer(FLUSH_ON_FAILURE);
+ }
}
#endif
@@ -1280,8 +1370,7 @@ void direction(dist& moves, const targetting_type restricts,
break;
case CMD_TARGET_SHOW_PROMPT:
- mprf(MSGCH_PROMPT, "%s (%s)", prompt? prompt : "Aim",
- target_mode_help_text(restricts));
+ _target_mode_prompt(prompt, restricts, moves.target);
break;
#ifndef USE_TILE
@@ -1345,8 +1434,7 @@ void direction(dist& moves, const targetting_type restricts,
}
else
{
- if (!skip_iter)
- flush_input_buffer(FLUSH_ON_FAILURE);
+ flush_input_buffer(FLUSH_ON_FAILURE);
}
break;
}
@@ -1435,8 +1523,10 @@ void direction(dist& moves, const targetting_type restricts,
{
moves.target = objfind_pos;
}
- else if (!skip_iter)
+ else
+ {
flush_input_buffer(FLUSH_ON_FAILURE);
+ }
break;
@@ -1448,21 +1538,10 @@ void direction(dist& moves, const targetting_type restricts,
{
moves.target = monsfind_pos;
}
- else if (skip_iter)
- {
- if (needs_path && !just_looking
- && _find_square_wrapper(monsfind_pos, dir, _find_monster,
- false, mode, range, true))
- {
- mpr("All monsters which could be auto-targeted "
- "are covered by a wall or statue which interrupts "
- "your line of fire, even though it doesn't "
- "interrupt your line of sight.",
- MSGCH_PROMPT);
- }
- }
else
+ {
flush_input_buffer(FLUSH_ON_FAILURE);
+ }
break;
case CMD_TARGET_CANCEL:
@@ -1552,7 +1631,6 @@ void direction(dist& moves, const targetting_type restricts,
wizard_move_player_or_monster(moves.target);
loop_done = true;
- skip_iter = true;
break;
@@ -1666,8 +1744,7 @@ void direction(dist& moves, const targetting_type restricts,
if (have_moved || force_redraw)
{
- if (!skip_iter) // Don't clear before we get a chance to see.
- mesclr(true); // Maybe not completely necessary.
+ mesclr(true); // Maybe not completely necessary.
bool in_range = (range < 0
|| grid_distance(moves.target,you.pos()) <= range);
@@ -1687,43 +1764,12 @@ void direction(dist& moves, const targetting_type restricts,
viewwindow(false, false);
#endif
if (show_beam && have_beam)
- {
- // Draw the new ray with magenta '*'s, not including
- // your square or the target square.
- // Out-of-range cells get grey '*'s instead.
- ray_def raycopy = ray; // temporary copy to work with
- // XXX: should have moves.target == beam_target, but don't.
- while (raycopy.pos() != beam_target)
- {
- if (raycopy.pos() != you.pos())
- {
- ASSERT(in_los(raycopy.pos()));
+ _draw_beam(ray, beam_target, range);
- const bool in_range = (range < 0)
- || grid_distance(raycopy.pos(), you.pos()) <= range;
-#ifdef USE_TILE
- tile_place_ray(raycopy.pos(), in_range);
-#else
- const int bcol = in_range ? MAGENTA : DARKGREY;
- _draw_ray_glyph(raycopy.pos(), bcol, '*',
- bcol | COLFLAG_REVERSE, in_range);
-#endif
- }
- raycopy.advance();
- }
- textcolor(LIGHTGREY);
-#ifdef USE_TILE
- const bool in_range
- = (range < 0
- || grid_distance(raycopy.pos(), you.pos()) <= range);
- tile_place_ray(moves.target, in_range);
-#endif
- }
#ifdef USE_TILE
viewwindow(false, true);
#endif
}
- skip_iter = false; // Only skip one iteration at most.
}
moves.isMe = (moves.target == you.pos());
mesclr();
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index b161502515..ac4953d619 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -1390,10 +1390,8 @@ static bool _fire_choose_item_and_target(int& slot, dist& target,
beh.message_ammo_prompt();
- // XXX: This stuff should be done by direction()!
- message_current_target();
- direction( target, DIR_NONE, TARG_HOSTILE, -1, false, !teleport, true, false,
- NULL, &beh );
+ direction(target, DIR_NONE, TARG_HOSTILE, -1, false, !teleport, true, false,
+ NULL, &beh);
if (beh.m_slot == -1)
{
@@ -2496,7 +2494,6 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
thr = *target;
else
{
- message_current_target();
direction(thr, DIR_NONE, TARG_HOSTILE);
if (!thr.isValid)
@@ -4383,7 +4380,6 @@ void zap_wand(int slot)
int tracer_range = (alreadyknown && wand.sub_type != WAND_RANDOM_EFFECTS) ?
_wand_range(type_zapped) : _max_wand_range();
- message_current_target();
direction(zap_wand, DIR_NONE, targ_mode, tracer_range);
if (!zap_wand.isValid)
diff --git a/crawl-ref/source/mon-behv.h b/crawl-ref/source/mon-behv.h
index 9f3001657a..fc12f95425 100644
--- a/crawl-ref/source/mon-behv.h
+++ b/crawl-ref/source/mon-behv.h
@@ -37,8 +37,6 @@ void set_random_target(monsters* mon);
void make_mons_leave_level(monsters *mon);
-bool message_current_target(void);
-
bool monster_can_hit_monster(monsters *monster, const monsters *targ);
bool mons_avoids_cloud(const monsters *monster, cloud_type cl_type,
diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc
index 21a7f8dde9..2ade004e24 100644
--- a/crawl-ref/source/mon-stuff.cc
+++ b/crawl-ref/source/mon-stuff.cc
@@ -3522,32 +3522,16 @@ bool monster_descriptor(int which_class, mon_desc_type which_descriptor)
return (false);
}
-bool message_current_target()
+monsters *get_current_target()
{
- if (crawl_state.is_replaying_keys())
- {
- if (you.prev_targ == MHITNOT || you.prev_targ == MHITYOU)
- return (false);
-
- return (you.can_see(&menv[you.prev_targ]));
- }
-
- if (you.prev_targ != MHITNOT && you.prev_targ != MHITYOU)
- {
- const monsters *montarget = &menv[you.prev_targ];
-
- if (you.can_see(montarget))
- {
- mprf(MSGCH_PROMPT, "Current target: %s "
- "(use p or f to fire at it again.)",
- montarget->name(DESC_PLAIN).c_str());
- return (true);
- }
+ if (invalid_monster_index(you.prev_targ))
+ return NULL;
- mpr("You have no current target.");
- }
-
- return (false);
+ monsters* mon = &menv[you.prev_targ];
+ if (mon->alive() && you.can_see(mon))
+ return mon;
+ else
+ return NULL;
}
void seen_monster(monsters *monster)
diff --git a/crawl-ref/source/mon-stuff.h b/crawl-ref/source/mon-stuff.h
index 44cd442501..4b6af3fc82 100644
--- a/crawl-ref/source/mon-stuff.h
+++ b/crawl-ref/source/mon-stuff.h
@@ -136,6 +136,9 @@ std::string get_wounds_description(const monsters *monster);
void print_wounds(const monsters *monster);
bool monster_descriptor(int which_class, mon_desc_type which_descriptor);
+// Return your target, if it still exists and is visible to you.
+monsters *get_current_target();
+
void mons_get_damage_level(const monsters*, std::string& desc,
mon_dam_level_type&);
diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc
index 4e61296b5b..0d2e98d720 100644
--- a/crawl-ref/source/spl-util.cc
+++ b/crawl-ref/source/spl-util.cc
@@ -745,9 +745,6 @@ bool spell_direction( dist &spelld, bolt &pbolt,
bool may_target_self, const char *prompt,
bool cancel_at_self )
{
- if (restrict != DIR_DIR)
- message_current_target();
-
if (range < 1)
range = (pbolt.range < 1) ? LOS_RADIUS : pbolt.range;