summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/directn.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-04 21:43:17 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-04 21:43:17 +0000
commit24c7f48b5401889a28462a809303545a7f4933df (patch)
tree3cb82bce72ee8146e817dc45021d78883f5a013e /crawl-ref/source/directn.cc
parente422b1baa5ffb05c2b938e2ca5a8490f4c8bfe83 (diff)
downloadcrawl-ref-24c7f48b5401889a28462a809303545a7f4933df.tar.gz
crawl-ref-24c7f48b5401889a28462a809303545a7f4933df.zip
Implement pathfinding for monsters, using the A* algorithm.
It's not actually used anywhere yet, but I've implemented a wizmode testing function (x on monster, then 'w') that calculates the shortest path to any playerchosen destination on the level, and it seems to work quite well. The monsters tend to take zigzag paths but that should be easy enough to smooth out and in any case doesn't matter all that much since the player usually won't witness this. Oh, and though I tested the whole thing in a labyrinth, it went ridiculously fast! I'd rather doubted that but Darshan was completely right, as usually. :p Please don't remove the debugging output yet, I still need them. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5476 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/directn.cc')
-rw-r--r--crawl-ref/source/directn.cc37
1 files changed, 23 insertions, 14 deletions
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index feb805e7dc..2933230868 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -915,8 +915,17 @@ void direction(dist& moves, targeting_type restricts,
skip_iter = true;
break;
-#endif
+ case CMD_TARGET_WIZARD_PATHFIND:
+ if (!you.wizard || !in_bounds(moves.tx, moves.ty))
+ break;
+ mid = mgrd[moves.tx][moves.ty];
+ if (mid == NON_MONSTER)
+ break;
+
+ debug_pathfind(mid);
+ break;
+#endif
case CMD_TARGET_DESCRIBE:
full_describe_square(moves.target());
force_redraw = true;
@@ -947,10 +956,10 @@ void direction(dist& moves, targeting_type restricts,
// Confirm self-targeting on TARG_ENEMY.
// Conceivably we might want to confirm on TARG_ANY too.
- if ( moves.isTarget
- && moves.tx == you.x_pos && moves.ty == you.y_pos
- && mode == TARG_ENEMY
- && !yesno("Really target yourself?", false, 'n'))
+ if (moves.isTarget
+ && moves.tx == you.x_pos && moves.ty == you.y_pos
+ && mode == TARG_ENEMY
+ && !yesno("Really target yourself?", false, 'n'))
{
mesclr();
show_prompt = true;
@@ -983,18 +992,17 @@ void direction(dist& moves, targeting_type restricts,
bool have_moved = false;
- if ( old_tx != moves.tx || old_ty != moves.ty )
+ if (old_tx != moves.tx || old_ty != moves.ty)
{
have_moved = true;
- show_beam = show_beam &&
- find_ray(you.x_pos, you.y_pos, moves.tx, moves.ty, true, ray,
- 0, true);
+ show_beam = show_beam && find_ray(you.x_pos, you.y_pos, moves.tx,
+ moves.ty, true, ray, 0, true);
}
- if ( force_redraw )
+ if (force_redraw)
have_moved = true;
- if ( have_moved )
+ if (have_moved)
{
// If the target x,y has changed, the beam must have changed.
if ( show_beam )
@@ -1017,9 +1025,9 @@ void direction(dist& moves, targeting_type restricts,
{
viewwindow(true, false);
#endif
- if ( show_beam
- && in_vlos(grid2viewX(moves.tx), grid2viewY(moves.ty))
- && moves.target() != you.pos() )
+ if (show_beam
+ && in_vlos(grid2viewX(moves.tx), grid2viewY(moves.ty))
+ && moves.target() != you.pos() )
{
// Draw the new ray with magenta '*'s, not including
// your square or the target square.
@@ -2494,6 +2502,7 @@ command_type targeting_behaviour::get_command(int key)
case 's': return CMD_TARGET_WIZARD_MAKE_SHOUT;
case 'g': return CMD_TARGET_WIZARD_GIVE_ITEM;
case 'm': return CMD_TARGET_WIZARD_MOVE;
+ case 'w': return CMD_TARGET_WIZARD_PATHFIND;
#endif
case 'v': return CMD_TARGET_DESCRIBE;
case '?': return CMD_TARGET_HELP;