Mercurial > hg > early-roguelike
view arogue5/chase.c @ 159:44a0fce4b168
arogue7, xrogue: fix configure's wizardmode and limitscore options.
WIZARD and LIMITSCORE, when set by options to './configure', are no
longer overridden in mach_dep.h.
| author | John "Elwin" Edwards |
|---|---|
| date | Fri, 05 Jun 2015 13:57:38 -0400 |
| parents | 0ed67132cf10 |
| children | 56e748983fa8 |
line wrap: on
line source
/* * Code for one object to chase another * * Advanced Rogue * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T * All rights reserved. * * Based on "Rogue: Exploring the Dungeons of Doom" * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman * All rights reserved. * * See the file LICENSE.TXT for full copyright and licensing information. */ #include <ctype.h> #include <limits.h> #include "curses.h" #include "rogue.h" #define MAXINT INT_MAX #define MININT INT_MIN coord ch_ret; /* Where chasing takes you */ /* * Canblink checks if the monster can teleport (blink). If so, it will * try to blink the monster next to the player. */ bool can_blink(tp) register struct thing *tp; { register int y, x, index=9; coord tryp; /* To hold the coordinates for use in diag_ok */ bool spots[9], found_one=FALSE; /* * First, can the monster even blink? And if so, there is only a 50% * chance that it will do so. And it won't blink if it is running or * held. */ if (off(*tp, CANBLINK) || (on(*tp, ISHELD)) || on(*tp, ISFLEE) || (on(*tp, ISSLOW) && off(*tp, ISHASTE) && !(tp->t_turn)) || tp->t_no_move || (rnd(12) < 6)) return(FALSE); /* Initialize the spots as illegal */ do { spots[--index] = FALSE; } while (index > 0); /* Find a suitable spot next to the player */ for (y=hero.y-1; y<hero.y+2; y++) for (x=hero.x-1; x<hero.x+2; x++, index++) { /* Make sure x coordinate is in range and that we are * not at the player's position */ if (x<0 || x >= COLS || index == 4) continue; /* Is it OK to move there? */ if (step_ok(y, x, NOMONST, tp) && (!isatrap(mvwinch(cw, y, x)) || rnd(10) >= tp->t_stats.s_intel || on(*tp, ISFLY))) { /* OK, we can go here. But don't go there if * monster can't get at player from there */ tryp.y = y; tryp.x = x; if (diag_ok(&tryp, &hero, tp)) { spots[index] = TRUE; found_one = TRUE; } } } /* If we found one, go to it */ if (found_one) { char rch; /* What's really where the creatures moves to */ /* Find a legal spot */ while (spots[index=rnd(9)] == FALSE) continue; /* Get the coordinates */ y = hero.y + (index/3) - 1; x = hero.x + (index % 3) - 1; /* Move the monster from the old space */ mvwaddch(cw, tp->t_pos.y, tp->t_pos.x, tp->t_oldch); /* Move it to the new space */ tp->t_oldch = CCHAR( mvwinch(cw, y, x) ); /* Display the creature if our hero can see it */ if (cansee(y, x) && off(*tp, ISINWALL) && !invisible(tp)) mvwaddch(cw, y, x, tp->t_type); /* Fix the monster window */ mvwaddch(mw, tp->t_pos.y, tp->t_pos.x, ' '); /* Clear old position */ mvwaddch(mw, y, x, tp->t_type); /* Record the new position */ tp->t_pos.y = y; tp->t_pos.x = x; /* If the monster is on a trap, trap it */ rch = CCHAR( mvinch(y, x) ); if (isatrap(rch)) { if (cansee(y, x)) tp->t_oldch = rch; be_trapped(tp, &(tp->t_pos)); } } return(found_one); } /* * Can_shoot determines if the monster (er) has a direct line of shot * at the player (ee). If so, it returns the direction in which to shoot. */ coord * can_shoot(er, ee) register coord *er, *ee; { static coord shoot_dir; /* Make sure we are chasing the player */ if (!ce((*ee), hero)) return(NULL); /* * They must be in the same room or very close (at door) */ if (roomin(er) != roomin(&hero) && DISTANCE(er->y,er->x,ee->y,ee->x) > 1) return(NULL); /* Do we have a straight shot? */ if (!straight_shot(er->y, er->x, ee->y, ee->x, &shoot_dir)) return(NULL); else return(&shoot_dir); } /* * chase: * Find the spot for the chaser(er) to move closer to the * chasee(ee). Returns TRUE if we want to keep on chasing later * FALSE if we reach the goal. */ chase(tp, ee, flee, mdead) register struct thing *tp; register coord *ee; bool flee; /* True if destination (ee) is player and monster is running away * or the player is in a wall and the monster can't get to it */ bool *mdead; { int damage, dist, thisdist, monst_dist = MAXINT; struct linked_list *weapon; register coord *er = &tp->t_pos; coord *shoot_dir; char ch, mch; bool next_player = FALSE; if (mdead != NULL) *mdead = 0; /*
