Source:NetHack 3.4.3/src/dungeon.c

From NetHackWiki
(Redirected from Source:Ref/Is botlevel)
Jump to: navigation, search

Below is the full text to src/dungeon.c from NetHack 3.4.3. To link to a particular line, write [[dungeon.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)dungeon.c	3.4	1999/10/30	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2. #include "dgn_file.h"
  3. #include "dlb.h"
  4.  
  5. #ifdef OVL1
  6.  
  7. #define DUNGEON_FILE	"dungeon"
  8.  
  9. #define X_START		"x-strt"
  10. #define X_LOCATE	"x-loca"
  11. #define X_GOAL		"x-goal"
  12.  
  13. struct proto_dungeon {
  14. 	struct	tmpdungeon tmpdungeon[MAXDUNGEON];
  15. 	struct	tmplevel   tmplevel[LEV_LIMIT];
  16. 	s_level *final_lev[LEV_LIMIT];	/* corresponding level pointers */
  17. 	struct	tmpbranch  tmpbranch[BRANCH_LIMIT];
  18.  
  19. 	int	start;	/* starting index of current dungeon sp levels */
  20. 	int	n_levs;	/* number of tmplevel entries */
  21. 	int	n_brs;	/* number of tmpbranch entries */
  22. };
  23.  
  24. int n_dgns;				/* number of dungeons (used here,  */
  25. 					/*   and mklev.c)		   */
  26. static branch *branches = (branch *) 0;	/* dungeon branch list		   */
  27.  
  28. struct lchoice {
  29. 	int idx;
  30. 	schar lev[MAXLINFO];
  31. 	schar playerlev[MAXLINFO];
  32. 	xchar dgn[MAXLINFO];
  33. 	char menuletter;
  34. };
  35.  
  36. static void FDECL(Fread, (genericptr_t, int, int, dlb *));
  37. STATIC_DCL xchar FDECL(dname_to_dnum, (const char *));
  38. STATIC_DCL int FDECL(find_branch, (const char *, struct proto_dungeon *));
  39. STATIC_DCL xchar FDECL(parent_dnum, (const char *, struct proto_dungeon *));
  40. STATIC_DCL int FDECL(level_range, (XCHAR_P,int,int,int,struct proto_dungeon *,int *));
  41. STATIC_DCL xchar FDECL(parent_dlevel, (const char *, struct proto_dungeon *));
  42. STATIC_DCL int FDECL(correct_branch_type, (struct tmpbranch *));
  43. STATIC_DCL branch *FDECL(add_branch, (int, int, struct proto_dungeon *));
  44. STATIC_DCL void FDECL(add_level, (s_level *));
  45. STATIC_DCL void FDECL(init_level, (int,int,struct proto_dungeon *));
  46. STATIC_DCL int FDECL(possible_places, (int, boolean *, struct proto_dungeon *));
  47. STATIC_DCL xchar FDECL(pick_level, (boolean *, int));
  48. STATIC_DCL boolean FDECL(place_level, (int, struct proto_dungeon *));
  49. #ifdef WIZARD
  50. STATIC_DCL const char *FDECL(br_string, (int));
  51. STATIC_DCL void FDECL(print_branch, (winid, int, int, int, BOOLEAN_P, struct lchoice *));
  52. #endif

dumpit[edit]

  1. #ifdef DEBUG
  2. #define DD	dungeons[i]
  3. STATIC_DCL void NDECL(dumpit);
  4.  
  5. STATIC_OVL void
  6. dumpit()
  7. {
  8. 	int	i;
  9. 	s_level	*x;
  10. 	branch *br;
  11.  
  12. 	for(i = 0; i < n_dgns; i++)  {
  13. 	    fprintf(stderr, "\n#%d \"%s\" (%s):\n", i,
  14. 				DD.dname, DD.proto);
  15. 	    fprintf(stderr, "    num_dunlevs %d, dunlev_ureached %d\n",
  16. 				DD.num_dunlevs, DD.dunlev_ureached);
  17. 	    fprintf(stderr, "    depth_start %d, ledger_start %d\n",
  18. 				DD.depth_start, DD.ledger_start);
  19. 	    fprintf(stderr, "    flags:%s%s%s\n",
  20. 		    DD.flags.rogue_like ? " rogue_like" : "",
  21. 		    DD.flags.maze_like  ? " maze_like"  : "",
  22. 		    DD.flags.hellish    ? " hellish"    : "");
  23. 	    getchar();
  24. 	}
  25. 	fprintf(stderr,"\nSpecial levels:\n");
  26. 	for(x = sp_levchn; x; x = x->next) {
  27. 	    fprintf(stderr, "%s (%d): ", x->proto, x->rndlevs);
  28. 	    fprintf(stderr, "on %d, %d; ", x->dlevel.dnum, x->dlevel.dlevel);
  29. 	    fprintf(stderr, "flags:%s%s%s%s\n",
  30. 		    x->flags.rogue_like	? " rogue_like" : "",
  31. 		    x->flags.maze_like  ? " maze_like"  : "",
  32. 		    x->flags.hellish    ? " hellish"    : "",
  33. 		    x->flags.town       ? " town"       : "");
  34. 	    getchar();
  35. 	}
  36. 	fprintf(stderr,"\nBranches:\n");
  37. 	for (br = branches; br; br = br->next) {
  38. 	    fprintf(stderr, "%d: %s, end1 %d %d, end2 %d %d, %s\n",
  39. 		br->id,
  40. 		br->type == BR_STAIR ? "stair" :
  41. 		    br->type == BR_NO_END1 ? "no end1" :
  42. 		    br->type == BR_NO_END2 ? "no end2" :
  43. 		    br->type == BR_PORTAL  ? "portal"  :
  44. 					     "unknown",
  45. 		br->end1.dnum, br->end1.dlevel,
  46. 		br->end2.dnum, br->end2.dlevel,
  47. 		br->end1_up ? "end1 up" : "end1 down");
  48. 	}
  49. 	getchar();
  50. 	fprintf(stderr,"\nDone\n");
  51. 	getchar();
  52. }
  53. #endif

save_dungeon[edit]

  1. /* Save the dungeon structures. */
  2. void
  3. save_dungeon(fd, perform_write, free_data)
  4. int fd;
  5. boolean perform_write, free_data;
  6. {
  7. branch *curr, *next;
  8. int    count;
  9.  
  10. if (perform_write) {
  11. 	bwrite(fd, (genericptr_t) &n_dgns, sizeof n_dgns);
  12. 	bwrite(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned)n_dgns);
  13. 	bwrite(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology);
  14. 	bwrite(fd, (genericptr_t) tune, sizeof tune);
  15.  
  16. 	for (count = 0, curr = branches; curr; curr = curr->next)
  17. 	    count++;
  18. 	bwrite(fd, (genericptr_t) &count, sizeof(count));
  19.  
  20. 	for (curr = branches; curr; curr = curr->next)
  21. 	    bwrite(fd, (genericptr_t) curr, sizeof (branch));
  22.  
  23. 	count = maxledgerno();
  24. 	bwrite(fd, (genericptr_t) &count, sizeof count);
  25. 	bwrite(fd, (genericptr_t) level_info,
  26. 			(unsigned)count * sizeof (struct linfo));
  27. 	bwrite(fd, (genericptr_t) &inv_pos, sizeof inv_pos);
  28. }
  29.  
  30. if (free_data) {
  31. 	for (curr = branches; curr; curr = next) {
  32. 	    next = curr->next;
  33. 	    free((genericptr_t) curr);
  34. 	}
  35. 	branches = 0;
  36. }
  37. }

restore_dungeon[edit]

  1. /* Restore the dungeon structures. */
  2. void
  3. restore_dungeon(fd)
  4. int fd;
  5. {
  6. branch *curr, *last;
  7. int    count, i;
  8.  
  9. mread(fd, (genericptr_t) &n_dgns, sizeof(n_dgns));
  10. mread(fd, (genericptr_t) dungeons, sizeof(dungeon) * (unsigned)n_dgns);
  11. mread(fd, (genericptr_t) &dungeon_topology, sizeof dungeon_topology);
  12. mread(fd, (genericptr_t) tune, sizeof tune);
  13.  
  14. last = branches = (branch *) 0;
  15.  
  16. mread(fd, (genericptr_t) &count, sizeof(count));
  17. for (i = 0; i < count; i++) {
  18. 	curr = (branch *) alloc(sizeof(branch));
  19. 	mread(fd, (genericptr_t) curr, sizeof(branch));
  20. 	curr->next = (branch *) 0;
  21. 	if (last)
  22. 	    last->next = curr;
  23. 	else
  24. 	    branches = curr;
  25. 	last = curr;
  26. }
  27.  
  28. mread(fd, (genericptr_t) &count, sizeof(count));
  29. if (count >= MAXLINFO)
  30. 	panic("level information count larger (%d) than allocated size", count);
  31. mread(fd, (genericptr_t) level_info, (unsigned)count*sizeof(struct linfo));
  32. mread(fd, (genericptr_t) &inv_pos, sizeof inv_pos);
  33. }

Fread[edit]

  1. static void
  2. Fread(ptr, size, nitems, stream)
  3. 	genericptr_t	ptr;
  4. 	int	size, nitems;
  5. 	dlb	*stream;
  6. {
  7. 	int cnt;
  8.  
  9. 	if((cnt = dlb_fread(ptr, size, nitems, stream)) != nitems) {
  10. 	    panic(
  11. "Premature EOF on dungeon description file!\r\nExpected %d bytes - got %d.",
  12. 		  (size * nitems), (size * cnt));
  13. 	    terminate(EXIT_FAILURE);
  14. 	}
  15. }

dname_to_dnum[edit]

  1. STATIC_OVL xchar
  2. dname_to_dnum(s)
  3. const char	*s;
  4. {
  5. 	xchar	i;
  6.  
  7. 	for (i = 0; i < n_dgns; i++)
  8. 	    if (!strcmp(dungeons[i].dname, s)) return i;
  9.  
  10. 	panic("Couldn't resolve dungeon number for name \"%s\".", s);
  11. 	/*NOT REACHED*/
  12. 	return (xchar)0;
  13. }

find_level[edit]

  1. s_level *
  2. find_level(s)
  3. 	const char *s;
  4. {
  5. 	s_level *curr;
  6. 	for(curr = sp_levchn; curr; curr = curr->next)
  7. 	    if (!strcmpi(s, curr->proto)) break;
  8. 	return curr;
  9. }

find_branch[edit]

  1. /* Find the branch that links the named dungeon. */
  2. STATIC_OVL int
  3. find_branch(s, pd)
  4. 	const char *s;		/* dungeon name */
  5. 	struct proto_dungeon *pd;
  6. {
  7. 	int i;
  8.  
  9. 	if (pd) {
  10. 	    for (i = 0; i < pd->n_brs; i++)
  11. 		if (!strcmp(pd->tmpbranch[i].name, s)) break;
  12. 	    if (i == pd->n_brs) panic("find_branch: can't find %s", s);
  13. 	} else {
  14. 	    /* support for level tport by name */
  15. 	    branch *br;
  16. 	    const char *dnam;
  17.  
  18. 	    for (br = branches; br; br = br->next) {
  19. 		dnam = dungeons[br->end2.dnum].dname;
  20. 		if (!strcmpi(dnam, s) ||
  21. 			(!strncmpi(dnam, "The ", 4) && !strcmpi(dnam + 4, s)))
  22. 		    break;
  23. 	    }
  24. 	    i = br ? ((ledger_no(&br->end1) << 8) | ledger_no(&br->end2)) : -1;
  25. 	}
  26. 	return i;
  27. }

parent_dnum[edit]

  1. /*
  2. * Find the "parent" by searching the prototype branch list for the branch
  3. * listing, then figuring out to which dungeon it belongs.
  4. */
  5. STATIC_OVL xchar
  6. parent_dnum(s, pd)
  7. const char	   *s;	/* dungeon name */
  8. struct proto_dungeon *pd;
  9. {
  10. 	int	i;
  11. 	xchar	pdnum;
  12.  
  13. 	i = find_branch(s, pd);
  14. 	/*
  15. 	 * Got branch, now find parent dungeon.  Stop if we have reached
  16. 	 * "this" dungeon (if we haven't found it by now it is an error).
  17. 	 */
  18. 	for (pdnum = 0; strcmp(pd->tmpdungeon[pdnum].name, s); pdnum++)
  19. 	    if ((i -= pd->tmpdungeon[pdnum].branches) < 0)
  20. 		return(pdnum);
  21.  
  22. 	panic("parent_dnum: couldn't resolve branch.");
  23. 	/*NOT REACHED*/
  24. 	return (xchar)0;
  25. }

level_range[edit]

  1. /*
  2. * Return a starting point and number of successive positions a level
  3. * or dungeon entrance can occupy.
  4. *
  5. * Note: This follows the acouple (instead of the rcouple) rules for a
  6. *	 negative random component (rand < 0).  These rules are found
  7. *	 in dgn_comp.y.  The acouple [absolute couple] section says that
  8. *	 a negative random component means from the (adjusted) base to the
  9. *	 end of the dungeon.
  10. */
  11. STATIC_OVL int
  12. level_range(dgn, base, rand, chain, pd, adjusted_base)
  13. 	xchar	dgn;
  14. 	int	base, rand, chain;
  15. 	struct proto_dungeon *pd;
  16. 	int *adjusted_base;
  17. {
  18. 	int lmax = dungeons[dgn].num_dunlevs;
  19.  
  20. 	if (chain >= 0) {		 /* relative to a special level */
  21. 	    s_level *levtmp = pd->final_lev[chain];
  22. 	    if (!levtmp) panic("level_range: empty chain level!");
  23.  
  24. 	    base += levtmp->dlevel.dlevel;
  25. 	} else {			/* absolute in the dungeon */
  26. 	    /* from end of dungeon */
  27. 	    if (base < 0) base = (lmax + base + 1);
  28. 	}
  29.  
  30. 	if (base < 1 || base > lmax)
  31. 	    panic("level_range: base value out of range");
  32.  
  33. 	*adjusted_base = base;
  34.  
  35. 	if (rand == -1) {	/* from base to end of dungeon */
  36. 	    return (lmax - base + 1);
  37. 	} else if (rand) {
  38. 	    /* make sure we don't run off the end of the dungeon */
  39. 	    return (((base + rand - 1) > lmax) ? lmax-base+1 : rand);
  40. 	} /* else only one choice */
  41. 	return 1;
  42. }

parent_dlevel[edit]

  1. STATIC_OVL xchar
  2. parent_dlevel(s, pd)
  3. 	const char	*s;
  4. 	struct proto_dungeon *pd;
  5. {
  6. 	int i, j, num, base, dnum = parent_dnum(s, pd);
  7. 	branch *curr;
  8.  
  9.  
  10. 	i = find_branch(s, pd);
  11. 	num = level_range(dnum, pd->tmpbranch[i].lev.base,
  12. 					      pd->tmpbranch[i].lev.rand,
  13. 					      pd->tmpbranch[i].chain,
  14. 					      pd, &base);
  15.  
  16. 	/* KMH -- Try our best to find a level without an existing branch */
  17. 	i = j = rn2(num);
  18. 	do {
  19. 		if (++i >= num) i = 0;
  20. 		for (curr = branches; curr; curr = curr->next)
  21. 			if ((curr->end1.dnum == dnum && curr->end1.dlevel == base+i) ||
  22. 				(curr->end2.dnum == dnum && curr->end2.dlevel == base+i))
  23. 				break;
  24. 	} while (curr && i != j);
  25. 	return (base + i);
  26. }

correct_branch_type[edit]

  1. /* Convert from the temporary branch type to the dungeon branch type. */
  2. STATIC_OVL int
  3. correct_branch_type(tbr)
  4. struct tmpbranch *tbr;
  5. {
  6. switch (tbr->type) {
  7. 	case TBR_STAIR:		return BR_STAIR;
  8. 	case TBR_NO_UP:		return tbr->up ? BR_NO_END1 : BR_NO_END2;
  9. 	case TBR_NO_DOWN:	return tbr->up ? BR_NO_END2 : BR_NO_END1;
  10. 	case TBR_PORTAL:	return BR_PORTAL;
  11. }
  12. impossible("correct_branch_type: unknown branch type");
  13. return BR_STAIR;
  14. }

insert_branch[edit]

  1. /*
  2. * Add the given branch to the branch list.  The branch list is ordered
  3. * by end1 dungeon and level followed by end2 dungeon and level.  If
  4. * extract_first is true, then the branch is already part of the list
  5. * but needs to be repositioned.
  6. */
  7. void
  8. insert_branch(new_branch, extract_first)
  9. branch *new_branch;
  10. boolean extract_first;
  11. {
  12. branch *curr, *prev;
  13. long new_val, curr_val, prev_val;
  14.  
  15. if (extract_first) {
  16. 	for (prev = 0, curr = branches; curr; prev = curr, curr = curr->next)
  17. 	    if (curr == new_branch) break;
  18.  
  19. 	if (!curr) panic("insert_branch: not found");
  20. 	if (prev)
  21. 	    prev->next = curr->next;
  22. 	else
  23. 	    branches = curr->next;
  24. }
  25. new_branch->next = (branch *) 0;
  26.  
  27. /* Convert the branch into a unique number so we can sort them. */
  28. #define branch_val(bp) \
  29. 	((((long)(bp)->end1.dnum * (MAXLEVEL+1) + \
  30. 	  (long)(bp)->end1.dlevel) * (MAXDUNGEON+1) * (MAXLEVEL+1)) + \
  31. 	 ((long)(bp)->end2.dnum * (MAXLEVEL+1) + (long)(bp)->end2.dlevel))
  32.  
  33. /*
  34. * Insert the new branch into the correct place in the branch list.
  35. */
  36. prev = (branch *) 0;
  37. prev_val = -1;
  38. new_val = branch_val(new_branch);
  39. for (curr = branches; curr;
  40. 		    prev_val = curr_val, prev = curr, curr = curr->next) {
  41. 	curr_val = branch_val(curr);
  42. 	if (prev_val < new_val && new_val <= curr_val) break;
  43. }
  44. if (prev) {
  45. 	new_branch->next = curr;
  46. 	prev->next = new_branch;
  47. } else {
  48. 	new_branch->next = branches;
  49. 	branches = new_branch;
  50. }
  51. }

add_branch[edit]

  1. /* Add a dungeon branch to the branch list. */
  2. STATIC_OVL branch *
  3. add_branch(dgn, child_entry_level, pd)
  4. int dgn;
  5. int child_entry_level;
  6. struct proto_dungeon *pd;
  7. {
  8. static int branch_id = 0;
  9. int branch_num;
  10. branch *new_branch;
  11.  
  12. branch_num = find_branch(dungeons[dgn].dname,pd);
  13. new_branch = (branch *) alloc(sizeof(branch));
  14. new_branch->next = (branch *) 0;
  15. new_branch->id = branch_id++;
  16. new_branch->type = correct_branch_type(&pd->tmpbranch[branch_num]);
  17. new_branch->end1.dnum = parent_dnum(dungeons[dgn].dname, pd);
  18. new_branch->end1.dlevel = parent_dlevel(dungeons[dgn].dname, pd);
  19. new_branch->end2.dnum = dgn;
  20. new_branch->end2.dlevel = child_entry_level;
  21. new_branch->end1_up = pd->tmpbranch[branch_num].up ? TRUE : FALSE;
  22.  
  23. insert_branch(new_branch, FALSE);
  24. return new_branch;
  25. }

add_level[edit]

  1. /*
  2. * Add new level to special level chain.  Insert it in level order with the
  3. * other levels in this dungeon.  This assumes that we are never given a
  4. * level that has a dungeon number less than the dungeon number of the
  5. * last entry.
  6. */
  7. STATIC_OVL void
  8. add_level(new_lev)
  9. s_level *new_lev;
  10. {
  11. 	s_level *prev, *curr;
  12.  
  13. 	prev = (s_level *) 0;
  14. 	for (curr = sp_levchn; curr; curr = curr->next) {
  15. 	    if (curr->dlevel.dnum == new_lev->dlevel.dnum &&
  16. 		    curr->dlevel.dlevel > new_lev->dlevel.dlevel)
  17. 		break;
  18. 	    prev = curr;
  19. 	}
  20. 	if (!prev) {
  21. 	    new_lev->next = sp_levchn;
  22. 	    sp_levchn = new_lev;
  23. 	} else {
  24. 	    new_lev->next = curr;
  25. 	    prev->next = new_lev;
  26. 	}
  27. }

init_level[edit]

  1. STATIC_OVL void
  2. init_level(dgn, proto_index, pd)
  3. 	int dgn, proto_index;
  4. 	struct proto_dungeon *pd;
  5. {
  6. 	s_level	*new_level;
  7. 	struct tmplevel *tlevel = &pd->tmplevel[proto_index];
  8.  
  9. 	pd->final_lev[proto_index] = (s_level *) 0; /* no "real" level */
  10. #ifdef WIZARD
  11. 	if (!wizard)
  12. #endif
  13. 	    if (tlevel->chance <= rn2(100)) return;
  14.  
  15. 	pd->final_lev[proto_index] = new_level =
  16. 					(s_level *) alloc(sizeof(s_level));
  17. 	/* load new level with data */
  18. 	Strcpy(new_level->proto, tlevel->name);
  19. 	new_level->boneid = tlevel->boneschar;
  20. 	new_level->dlevel.dnum = dgn;
  21. 	new_level->dlevel.dlevel = 0;	/* for now */
  22.  
  23. 	new_level->flags.town = !!(tlevel->flags & TOWN);
  24. 	new_level->flags.hellish = !!(tlevel->flags & HELLISH);
  25. 	new_level->flags.maze_like = !!(tlevel->flags & MAZELIKE);
  26. 	new_level->flags.rogue_like = !!(tlevel->flags & ROGUELIKE);
  27. 	new_level->flags.align = ((tlevel->flags & D_ALIGN_MASK) >> 4);
  28. 	if (!new_level->flags.align) 
  29. 	    new_level->flags.align =
  30. 		((pd->tmpdungeon[dgn].flags & D_ALIGN_MASK) >> 4);
  31.  
  32. 	new_level->rndlevs = tlevel->rndlevs;
  33. 	new_level->next    = (s_level *) 0;
  34. }

possible_places[edit]

  1. STATIC_OVL int
  2. possible_places(idx, map, pd)
  3. int idx;		/* prototype index */
  4. boolean *map;	/* array MAXLEVEL+1 in length */
  5. struct proto_dungeon *pd;
  6. {
  7. int i, start, count;
  8. s_level *lev = pd->final_lev[idx];
  9.  
  10. /* init level possibilities */
  11. for (i = 0; i <= MAXLEVEL; i++) map[i] = FALSE;
  12.  
  13. /* get base and range and set those entried to true */
  14. count = level_range(lev->dlevel.dnum, pd->tmplevel[idx].lev.base,
  15. 					pd->tmplevel[idx].lev.rand,
  16. 					pd->tmplevel[idx].chain,
  17. 					pd, &start);
  18. for (i = start; i < start+count; i++)
  19. 	map[i] = TRUE;
  20.  
  21. /* mark off already placed levels */
  22. for (i = pd->start; i < idx; i++) {
  23. 	if (pd->final_lev[i] && map[pd->final_lev[i]->dlevel.dlevel]) {
  24. 	    map[pd->final_lev[i]->dlevel.dlevel] = FALSE;
  25. 	    --count;
  26. 	}
  27. }
  28.  
  29. return count;
  30. }

pick_level[edit]

  1. /* Pick the nth TRUE entry in the given boolean array. */
  2. STATIC_OVL xchar
  3. pick_level(map, nth)
  4. boolean *map;	/* an array MAXLEVEL+1 in size */
  5. int nth;
  6. {
  7. int i;
  8. for (i = 1; i <= MAXLEVEL; i++)
  9. 	if (map[i] && !nth--) return (xchar) i;
  10. panic("pick_level:  ran out of valid levels");
  11. return 0;
  12. }

indent[edit]

  1. #ifdef DDEBUG
  2. static void FDECL(indent,(int));
  3.  
  4. static void
  5. indent(d)
  6. int d;
  7. {
  8. while (d-- > 0) fputs("    ", stderr);
  9. }
  10. #endif

place_level[edit]

  1. /*
  2. * Place a level.  First, find the possible places on a dungeon map
  3. * template.  Next pick one.  Then try to place the next level.  If
  4. * sucessful, we're done.  Otherwise, try another (and another) until
  5. * all possible places have been tried.  If all possible places have
  6. * been exausted, return false.
  7. */
  8. STATIC_OVL boolean
  9. place_level(proto_index, pd)
  10. int proto_index;
  11. struct proto_dungeon *pd;
  12. {
  13. boolean map[MAXLEVEL+1];	/* valid levels are 1..MAXLEVEL inclusive */
  14. s_level *lev;
  15. int npossible;
  16. #ifdef DDEBUG
  17. int i;
  18. #endif
  19.  
  20. if (proto_index == pd->n_levs) return TRUE;	/* at end of proto levels */
  21.  
  22. lev = pd->final_lev[proto_index];
  23.  
  24. /* No level created for this prototype, goto next. */
  25. if (!lev) return place_level(proto_index+1, pd);
  26.  
  27. npossible = possible_places(proto_index, map, pd);
  28.  
  29. for (; npossible; --npossible) {
  30. 	lev->dlevel.dlevel = pick_level(map, rn2(npossible));
  31. #ifdef DDEBUG
  32. 	indent(proto_index-pd->start);
  33. 	fprintf(stderr,"%s: trying %d [ ", lev->proto, lev->dlevel.dlevel);
  34. 	for (i = 1; i <= MAXLEVEL; i++)
  35. 	    if (map[i]) fprintf(stderr,"%d ", i);
  36. 	fprintf(stderr,"]\n");
  37. #endif
  38. 	if (place_level(proto_index+1, pd)) return TRUE;
  39. 	map[lev->dlevel.dlevel] = FALSE;	/* this choice didn't work */
  40. }
  41. #ifdef DDEBUG
  42. indent(proto_index-pd->start);
  43. fprintf(stderr,"%s: failed\n", lev->proto);
  44. #endif
  45. return FALSE;
  46. }

level_map[edit]

  1. struct level_map {
  2. 	const char *lev_name;
  3. 	d_level *lev_spec;
  4. } level_map[] = {
  5. 	{ "air",	&air_level },
  6. 	{ "asmodeus",	&asmodeus_level },
  7. 	{ "astral",	&astral_level },
  8. 	{ "baalz",	&baalzebub_level },
  9. 	{ "bigroom",	&bigroom_level },
  10. 	{ "castle",	&stronghold_level },
  11. 	{ "earth",	&earth_level },
  12. 	{ "fakewiz1",	&portal_level },
  13. 	{ "fire",	&fire_level },
  14. 	{ "juiblex",	&juiblex_level },
  15. 	{ "knox",	&knox_level },
  16. 	{ "medusa",	&medusa_level },
  17. 	{ "oracle",	&oracle_level },
  18. 	{ "orcus",	&orcus_level },
  19. #ifdef REINCARNATION
  20. 	{ "rogue",	&rogue_level },
  21. #endif
  22. 	{ "sanctum",	&sanctum_level },
  23. 	{ "valley",	&valley_level },
  24. 	{ "water",	&water_level },
  25. 	{ "wizard1",	&wiz1_level },
  26. 	{ "wizard2",	&wiz2_level },
  27. 	{ "wizard3",	&wiz3_level },
  28. 	{ X_START,	&qstart_level },
  29. 	{ X_LOCATE,	&qlocate_level },
  30. 	{ X_GOAL,	&nemesis_level },
  31. 	{ "",		(d_level *)0 }
  32. };

init_dungeons[edit]

  1. void
  2. init_dungeons()		/* initialize the "dungeon" structs */
  3. {
  4. 	dlb	*dgn_file;
  5. 	register int i, cl = 0, cb = 0;
  6. 	register s_level *x;
  7. 	struct proto_dungeon pd;
  8. 	struct level_map *lev_map;
  9. 	struct version_info vers_info;
  10.  
  11. 	pd.n_levs = pd.n_brs = 0;
  12.  
  13. 	dgn_file = dlb_fopen(DUNGEON_FILE, RDBMODE);
  14. 	if (!dgn_file) {
  15. 	    char tbuf[BUFSZ];
  16. 	    Sprintf(tbuf, "Cannot open dungeon description - \"%s",
  17. 		DUNGEON_FILE);
  18. #ifdef DLBRSRC /* using a resource from the executable */
  19. 	    Strcat(tbuf, "\" resource!");
  20. #else /* using a file or DLB file */
  21. # if defined(DLB)
  22. 	    Strcat(tbuf, "\" from ");
  23. #  ifdef PREFIXES_IN_USE
  24. 	    Strcat(tbuf, "\n\"");
  25. 	    if (fqn_prefix[DATAPREFIX]) Strcat(tbuf, fqn_prefix[DATAPREFIX]);
  26. #  else
  27. 	    Strcat(tbuf, "\"");
  28. #  endif
  29. 	    Strcat(tbuf, DLBFILE);
  30. # endif
  31. 	    Strcat(tbuf, "\" file!");
  32. #endif
  33. #ifdef WIN32
  34. 	    interject_assistance(1, INTERJECT_PANIC, (genericptr_t)tbuf,
  35. 				 (genericptr_t)fqn_prefix[DATAPREFIX]);
  36. #endif
  37. 	    panic(tbuf);
  38. 	}
  39.  
  40. 	/* validate the data's version against the program's version */
  41. 	Fread((genericptr_t) &vers_info, sizeof vers_info, 1, dgn_file);
  42. 	/* we'd better clear the screen now, since when error messages come from
  43. 	 * check_version() they will be printed using pline(), which doesn't
  44. 	 * mix with the raw messages that might be already on the screen
  45. 	 */
  46. 	if (iflags.window_inited) clear_nhwindow(WIN_MAP);
  47. 	if (!check_version(&vers_info, DUNGEON_FILE, TRUE))
  48. 	    panic("Dungeon description not valid.");
  49.  
  50. 	/*
  51. 	 * Read in each dungeon and transfer the results to the internal
  52. 	 * dungeon arrays.
  53. 	 */
  54. 	sp_levchn = (s_level *) 0;
  55. 	Fread((genericptr_t)&n_dgns, sizeof(int), 1, dgn_file);
  56. 	if (n_dgns >= MAXDUNGEON)
  57. 	    panic("init_dungeons: too many dungeons");
  58.  
  59. 	for (i = 0; i < n_dgns; i++) {
  60. 	    Fread((genericptr_t)&pd.tmpdungeon[i],
  61. 				    sizeof(struct tmpdungeon), 1, dgn_file);
  62. #ifdef WIZARD
  63. 	    if(!wizard)
  64. #endif
  65. 	      if(pd.tmpdungeon[i].chance && (pd.tmpdungeon[i].chance <= rn2(100))) {
  66. 		int j;
  67.  
  68. 		/* skip over any levels or branches */
  69. 		for(j = 0; j < pd.tmpdungeon[i].levels; j++)
  70. 		    Fread((genericptr_t)&pd.tmplevel[cl], sizeof(struct tmplevel),
  71. 							1, dgn_file);
  72.  
  73. 		for(j = 0; j < pd.tmpdungeon[i].branches; j++)
  74. 		    Fread((genericptr_t)&pd.tmpbranch[cb],
  75. 					sizeof(struct tmpbranch), 1, dgn_file);
  76. 		n_dgns--; i--;
  77. 		continue;
  78. 	      }
  79.  
  80. 	    Strcpy(dungeons[i].dname, pd.tmpdungeon[i].name);
  81. 	    Strcpy(dungeons[i].proto, pd.tmpdungeon[i].protoname);
  82. 	    dungeons[i].boneid = pd.tmpdungeon[i].boneschar;
  83.  
  84. 	    if(pd.tmpdungeon[i].lev.rand)
  85. 		dungeons[i].num_dunlevs = (xchar)rn1(pd.tmpdungeon[i].lev.rand,
  86. 						     pd.tmpdungeon[i].lev.base);
  87. 	    else dungeons[i].num_dunlevs = (xchar)pd.tmpdungeon[i].lev.base;
  88.  
  89. 	    if(!i) {
  90. 		dungeons[i].ledger_start = 0;
  91. 		dungeons[i].depth_start = 1;
  92. 		dungeons[i].dunlev_ureached = 1;
  93. 	    } else {
  94. 		dungeons[i].ledger_start = dungeons[i-1].ledger_start +
  95. 					      dungeons[i-1].num_dunlevs;
  96. 		dungeons[i].dunlev_ureached = 0;
  97. 	    }
  98.  
  99. 	    dungeons[i].flags.hellish = !!(pd.tmpdungeon[i].flags & HELLISH);
  100. 	    dungeons[i].flags.maze_like = !!(pd.tmpdungeon[i].flags & MAZELIKE);
  101. 	    dungeons[i].flags.rogue_like = !!(pd.tmpdungeon[i].flags & ROGUELIKE);
  102. 	    dungeons[i].flags.align = ((pd.tmpdungeon[i].flags & D_ALIGN_MASK) >> 4);
  103. 	    /*
  104. 	     * Set the entry level for this dungeon.  The pd.tmpdungeon entry
  105. 	     * value means:
  106. 	     *		< 0	from bottom (-1 == bottom level)
  107. 	     *		  0	default (top)
  108. 	     *		> 0	actual level (1 = top)
  109. 	     *
  110. 	     * Note that the entry_lev field in the dungeon structure is
  111. 	     * redundant.  It is used only here and in print_dungeon().
  112. 	     */
  113. 	    if (pd.tmpdungeon[i].entry_lev < 0) {
  114. 		dungeons[i].entry_lev = dungeons[i].num_dunlevs +
  115. 						pd.tmpdungeon[i].entry_lev + 1;
  116. 		if (dungeons[i].entry_lev <= 0) dungeons[i].entry_lev = 1;
  117. 	    } else if (pd.tmpdungeon[i].entry_lev > 0) {
  118. 		dungeons[i].entry_lev = pd.tmpdungeon[i].entry_lev;
  119. 		if (dungeons[i].entry_lev > dungeons[i].num_dunlevs)
  120. 		    dungeons[i].entry_lev = dungeons[i].num_dunlevs;
  121. 	    } else { /* default */
  122. 		dungeons[i].entry_lev = 1;	/* defaults to top level */
  123. 	    }
  124.  
  125. 	    if (i) {	/* set depth */
  126. 		branch *br;
  127. 		schar from_depth;
  128. 		boolean from_up;
  129.  
  130. 		br = add_branch(i, dungeons[i].entry_lev, &pd);
  131.  
  132. 		/* Get the depth of the connecting end. */
  133. 		if (br->end1.dnum == i) {
  134. 		    from_depth = depth(&br->end2);
  135. 		    from_up = !br->end1_up;
  136. 		} else {
  137. 		    from_depth = depth(&br->end1);
  138. 		    from_up = br->end1_up;
  139. 		}
  140.  
  141. 		/*
  142. 		 * Calculate the depth of the top of the dungeon via
  143. 		 * its branch.  First, the depth of the entry point:
  144. 		 *
  145. 		 *	depth of branch from "parent" dungeon
  146. 		 *	+ -1 or 1 depending on a up or down stair or
  147. 		 *	  0 if portal
  148. 		 *
  149. 		 * Followed by the depth of the top of the dungeon:
  150. 		 *
  151. 		 *	- (entry depth - 1)
  152. 		 *
  153. 		 * We'll say that portals stay on the same depth.
  154. 		 */
  155. 		dungeons[i].depth_start = from_depth
  156. 					+ (br->type == BR_PORTAL ? 0 :
  157. 							(from_up ? -1 : 1))
  158. 					- (dungeons[i].entry_lev - 1);
  159. 	    }
  160.  
  161. 	    /* this is redundant - it should have been flagged by dgn_comp */
  162. 	    if(dungeons[i].num_dunlevs > MAXLEVEL)
  163. 		dungeons[i].num_dunlevs = MAXLEVEL;
  164.  
  165. 	    pd.start = pd.n_levs;	/* save starting point */
  166. 	    pd.n_levs += pd.tmpdungeon[i].levels;
  167. 	    if (pd.n_levs > LEV_LIMIT)
  168. 		panic("init_dungeon: too many special levels");
  169. 	    /*
  170. 	     * Read in the prototype special levels.  Don't add generated
  171. 	     * special levels until they are all placed.
  172. 	     */
  173. 	    for(; cl < pd.n_levs; cl++) {
  174. 		Fread((genericptr_t)&pd.tmplevel[cl],
  175. 					sizeof(struct tmplevel), 1, dgn_file);
  176. 		init_level(i, cl, &pd);
  177. 	    }
  178. 	    /*
  179. 	     * Recursively place the generated levels for this dungeon.  This
  180. 	     * routine will attempt all possible combinations before giving
  181. 	     * up.
  182. 	     */
  183. 	    if (!place_level(pd.start, &pd))
  184. 		panic("init_dungeon:  couldn't place levels");
  185. #ifdef DDEBUG
  186. 	    fprintf(stderr, "--- end of dungeon %d ---\n", i);
  187. 	    fflush(stderr);
  188. 	    getchar();
  189. #endif
  190. 	    for (; pd.start < pd.n_levs; pd.start++)
  191. 		if (pd.final_lev[pd.start]) add_level(pd.final_lev[pd.start]);
  192.  
  193.  
  194. 	    pd.n_brs += pd.tmpdungeon[i].branches;
  195. 	    if (pd.n_brs > BRANCH_LIMIT)
  196. 		panic("init_dungeon: too many branches");
  197. 	    for(; cb < pd.n_brs; cb++)
  198. 		Fread((genericptr_t)&pd.tmpbranch[cb],
  199. 					sizeof(struct tmpbranch), 1, dgn_file);
  200. 	}
  201. 	(void) dlb_fclose(dgn_file);
  202.  
  203. 	for (i = 0; i < 5; i++) tune[i] = 'A' + rn2(7);
  204. 	tune[5] = 0;
  205.  
  206. 	/*
  207. 	 * Find most of the special levels and dungeons so we can access their
  208. 	 * locations quickly.
  209. 	 */
  210. 	for (lev_map = level_map; lev_map->lev_name[0]; lev_map++) {
  211. 		x = find_level(lev_map->lev_name);
  212. 		if (x) {
  213. 			assign_level(lev_map->lev_spec, &x->dlevel);
  214. 			if (!strncmp(lev_map->lev_name, "x-", 2)) {
  215. 				/* This is where the name substitution on the
  216. 				 * levels of the quest dungeon occur.
  217. 				 */
  218. 				Sprintf(x->proto, "%s%s", urole.filecode, &lev_map->lev_name[1]);
  219. 			} else if (lev_map->lev_spec == &knox_level) {
  220. 				branch *br;
  221. 				/*
  222. 				 * Kludge to allow floating Knox entrance.  We
  223. 				 * specify a floating entrance by the fact that
  224. 				 * its entrance (end1) has a bogus dnum, namely
  225. 				 * n_dgns.
  226. 				 */
  227. 				for (br = branches; br; br = br->next)
  228. 				    if (on_level(&br->end2, &knox_level)) break;
  229.  
  230. 				if (br) br->end1.dnum = n_dgns;
  231. 				/* adjust the branch's position on the list */
  232. 				insert_branch(br, TRUE);
  233. 			}
  234. 		}
  235. 	}
  236. /*
  237. *	I hate hardwiring these names. :-(
  238. */
  239. 	quest_dnum = dname_to_dnum("The Quest");
  240. 	sokoban_dnum = dname_to_dnum("Sokoban");
  241. 	mines_dnum = dname_to_dnum("The Gnomish Mines");
  242. 	tower_dnum = dname_to_dnum("Vlad's Tower");
  243.  
  244. 	/* one special fixup for dummy surface level */
  245. 	if ((x = find_level("dummy")) != 0) {
  246. 	    i = x->dlevel.dnum;
  247. 	    /* the code above puts earth one level above dungeon level #1,
  248. 	       making the dummy level overlay level 1; but the whole reason
  249. 	       for having the dummy level is to make earth have depth -1
  250. 	       instead of 0, so adjust the start point to shift endgame up */
  251. 	    if (dunlevs_in_dungeon(&x->dlevel) > 1 - dungeons[i].depth_start)
  252. 		dungeons[i].depth_start -= 1;
  253. 	    /* TO DO: strip "dummy" out all the way here,
  254. 	       so that it's hidden from <ctrl/O> feedback. */
  255. 	}
  256.  
  257. #ifdef DEBUG
  258. 	dumpit();
  259. #endif
  260. }

dunlev[edit]

  1. xchar
  2. dunlev(lev)	/* return the level number for lev in *this* dungeon */
  3. d_level	*lev;
  4. {
  5. 	return(lev->dlevel);
  6. }

dunlevs_in_dungeon[edit]

  1. xchar
  2. dunlevs_in_dungeon(lev)	/* return the lowest level number for *this* dungeon*/
  3. d_level	*lev;
  4. {
  5. 	return(dungeons[lev->dnum].num_dunlevs);
  6. }

deepest_lev_reached[edit]

  1. xchar
  2. deepest_lev_reached(noquest) /* return the lowest level explored in the game*/
  3. boolean noquest;
  4. {
  5. 	/* this function is used for three purposes: to provide a factor
  6. 	 * of difficulty in monster generation; to provide a factor of
  7. 	 * difficulty in experience calculations (botl.c and end.c); and
  8. 	 * to insert the deepest level reached in the game in the topten
  9. 	 * display.  the 'noquest' arg switch is required for the latter.
  10. 	 *
  11. 	 * from the player's point of view, going into the Quest is _not_
  12. 	 * going deeper into the dungeon -- it is going back "home", where
  13. 	 * the dungeon starts at level 1.  given the setup in dungeon.def,
  14. 	 * the depth of the Quest (thought of as starting at level 1) is
  15. 	 * never lower than the level of entry into the Quest, so we exclude
  16. 	 * the Quest from the topten "deepest level reached" display
  17. 	 * calculation.  _However_ the Quest is a difficult dungeon, so we
  18. 	 * include it in the factor of difficulty calculations.
  19. 	 */
  20. 	register int i;
  21. 	d_level tmp;
  22. 	register schar ret = 0;
  23.  
  24. 	for(i = 0; i < n_dgns; i++) {
  25. 	    if((tmp.dlevel = dungeons[i].dunlev_ureached) == 0) continue;
  26. 	    if(!strcmp(dungeons[i].dname, "The Quest") && noquest) continue;
  27.  
  28. 	    tmp.dnum = i;
  29. 	    if(depth(&tmp) > ret) ret = depth(&tmp);
  30. 	}
  31. 	return((xchar) ret);
  32. }

ledger_no[edit]

  1. /* return a bookkeeping level number for purpose of comparisons and
  2. * save/restore */
  3. xchar
  4. ledger_no(lev)
  5. d_level	*lev;
  6. {
  7. 	return((xchar)(lev->dlevel + dungeons[lev->dnum].ledger_start));
  8. }

maxledgerno[edit]

  1. /*
  2. * The last level in the bookkeeping list of level is the bottom of the last
  3. * dungeon in the dungeons[] array.
  4. *
  5. * Maxledgerno() -- which is the max number of levels in the bookkeeping
  6. * list, should not be confused with dunlevs_in_dungeon(lev) -- which
  7. * returns the max number of levels in lev's dungeon, and both should
  8. * not be confused with deepest_lev_reached() -- which returns the lowest
  9. * depth visited by the player.
  10. */
  11. xchar
  12. maxledgerno()
  13. {
  14. return (xchar) (dungeons[n_dgns-1].ledger_start +
  15. 				dungeons[n_dgns-1].num_dunlevs);
  16. }

ledger_to_dnum[edit]

  1. /* return the dungeon that this ledgerno exists in */
  2. xchar
  3. ledger_to_dnum(ledgerno)
  4. xchar	ledgerno;
  5. {
  6. 	register int i;
  7.  
  8. 	/* find i such that (i->base + 1) <= ledgerno <= (i->base + i->count) */
  9. 	for (i = 0; i < n_dgns; i++)
  10. 	    if (dungeons[i].ledger_start < ledgerno &&
  11. 		ledgerno <= dungeons[i].ledger_start + dungeons[i].num_dunlevs)
  12. 		return (xchar)i;
  13.  
  14. 	panic("level number out of range [ledger_to_dnum(%d)]", (int)ledgerno);
  15. 	/*NOT REACHED*/
  16. 	return (xchar)0;
  17. }

ledger_to_dlev[edit]

  1. /* return the level of the dungeon this ledgerno exists in */
  2. xchar
  3. ledger_to_dlev(ledgerno)
  4. xchar	ledgerno;
  5. {
  6. 	return((xchar)(ledgerno - dungeons[ledger_to_dnum(ledgerno)].ledger_start));
  7. }
  8.  
  9. #endif /* OVL1 */

depth[edit]

  1. #ifdef OVL0
  2.  
  3. /* returns the depth of a level, in floors below the surface	*/
  4. /* (note levels in different dungeons can have the same depth).	*/
  5. schar
  6. depth(lev)
  7. d_level	*lev;
  8. {
  9. 	return((schar)( dungeons[lev->dnum].depth_start + lev->dlevel - 1));
  10. }

on_level[edit]

  1. boolean
  2. on_level(lev1, lev2)	/* are "lev1" and "lev2" actually the same? */
  3. d_level	*lev1, *lev2;
  4. {
  5. 	return((boolean)((lev1->dnum == lev2->dnum) && (lev1->dlevel == lev2->dlevel)));
  6. }
  7.  
  8. #endif /* OVL0 */

Is_special[edit]

  1. #ifdef OVL1
  2.  
  3. /* is this level referenced in the special level chain? */
  4. s_level *
  5. Is_special(lev)
  6. d_level	*lev;
  7. {
  8. 	s_level *levtmp;
  9.  
  10. 	for (levtmp = sp_levchn; levtmp; levtmp = levtmp->next)
  11. 	    if (on_level(lev, &levtmp->dlevel)) return(levtmp);
  12.  
  13. 	return((s_level *)0);
  14. }

Is_branchlev[edit]

  1. /*
  2. * Is this a multi-dungeon branch level?  If so, return a pointer to the
  3. * branch.  Otherwise, return null.
  4. */
  5. branch *
  6. Is_branchlev(lev)
  7. 	d_level	*lev;
  8. {
  9. 	branch *curr;
  10.  
  11. 	for (curr = branches; curr; curr = curr->next) {
  12. 	    if (on_level(lev, &curr->end1) || on_level(lev, &curr->end2))
  13. 		return curr;
  14. 	}
  15. 	return (branch *) 0;
  16. }

next_level[edit]

  1. /* goto the next level (or appropriate dungeon) */
  2. void
  3. next_level(at_stairs)
  4. boolean	at_stairs;
  5. {
  6. 	if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) {
  7. 		/* Taking a down dungeon branch. */
  8. 		goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE);
  9. 	} else {
  10. 		/* Going down a stairs or jump in a trap door. */
  11. 		d_level	newlevel;
  12.  
  13. 		newlevel.dnum = u.uz.dnum;
  14. 		newlevel.dlevel = u.uz.dlevel + 1;
  15. 		goto_level(&newlevel, at_stairs, !at_stairs, FALSE);
  16. 	}
  17. }

prev_level[edit]

  1. /* goto the previous level (or appropriate dungeon) */
  2. void
  3. prev_level(at_stairs)
  4. boolean	at_stairs;
  5. {
  6. 	if (at_stairs && u.ux == sstairs.sx && u.uy == sstairs.sy) {
  7. 		/* Taking an up dungeon branch. */
  8. 		/* KMH -- Upwards branches are okay if not level 1 */
  9. 		/* (Just make sure it doesn't go above depth 1) */
  10. 		if(!u.uz.dnum && u.uz.dlevel == 1 && !u.uhave.amulet) done(ESCAPED);
  11. 		else goto_level(&sstairs.tolev, at_stairs, FALSE, FALSE);
  12. 	} else {
  13. 		/* Going up a stairs or rising through the ceiling. */
  14. 		d_level	newlevel;
  15. 		newlevel.dnum = u.uz.dnum;
  16. 		newlevel.dlevel = u.uz.dlevel - 1;
  17. 		goto_level(&newlevel, at_stairs, FALSE, FALSE);
  18. 	}
  19. }

u_on_newpos[edit]

  1. void
  2. u_on_newpos(x, y)
  3. int x, y;
  4. {
  5. 	u.ux = x;
  6. 	u.uy = y;
  7. #ifdef CLIPPING
  8. 	cliparound(u.ux, u.uy);
  9. #endif
  10. #ifdef STEED
  11. 	/* ridden steed always shares hero's location */
  12. 	if (u.usteed) u.usteed->mx = u.ux, u.usteed->my = u.uy;
  13. #endif
  14. }

u_on_sstairs[edit]

  1. void
  2. u_on_sstairs() {	/* place you on the special staircase */
  3.  
  4. 	if (sstairs.sx) {
  5. 	    u_on_newpos(sstairs.sx, sstairs.sy);
  6. 	} else {
  7. 	    /* code stolen from goto_level */
  8. 	    int trycnt = 0;
  9. 	    xchar x, y;
  10. #ifdef DEBUG
  11. 	    pline("u_on_sstairs: picking random spot");
  12. #endif
  13. #define badspot(x,y) ((levl[x][y].typ != ROOM && levl[x][y].typ != CORR) || MON_AT(x, y))
  14. 	    do {
  15. 		x = rnd(COLNO-1);
  16. 		y = rn2(ROWNO);
  17. 		if (!badspot(x, y)) {
  18. 		    u_on_newpos(x, y);
  19. 		    return;
  20. 		}
  21. 	    } while (++trycnt <= 500);
  22. 	    panic("u_on_sstairs: could not relocate player!");
  23. #undef badspot
  24. 	}
  25. }

u_on_upstairs[edit]

  1. void
  2. u_on_upstairs()	/* place you on upstairs (or special equivalent) */
  3. {
  4. 	if (xupstair) {
  5. 		u_on_newpos(xupstair, yupstair);
  6. 	} else
  7. 		u_on_sstairs();
  8. }

u_on_dnstairs[edit]

  1. void
  2. u_on_dnstairs()	/* place you on dnstairs (or special equivalent) */
  3. {
  4. 	if (xdnstair) {
  5. 		u_on_newpos(xdnstair, ydnstair);
  6. 	} else
  7. 		u_on_sstairs();
  8. }

On_stairs[edit]

  1. boolean
  2. On_stairs(x, y)
  3. xchar x, y;
  4. {
  5. 	return((boolean)((x == xupstair && y == yupstair) ||
  6. 	       (x == xdnstair && y == ydnstair) ||
  7. 	       (x == xdnladder && y == ydnladder) ||
  8. 	       (x == xupladder && y == yupladder) ||
  9. 	       (x == sstairs.sx && y == sstairs.sy)));
  10. }

Is_botlevel[edit]

  1. boolean
  2. Is_botlevel(lev)
  3. d_level *lev;
  4. {
  5. 	return((boolean)(lev->dlevel == dungeons[lev->dnum].num_dunlevs));
  6. }

Can_dig_down[edit]

  1. boolean
  2. Can_dig_down(lev)
  3. d_level *lev;
  4. {
  5. 	return((boolean)(!level.flags.hardfloor
  6. 	    && !Is_botlevel(lev) && !Invocation_lev(lev)));
  7. }

Can_fall_thru[edit]

  1. /*
  2. * Like Can_dig_down (above), but also allows falling through on the
  3. * stronghold level.  Normally, the bottom level of a dungeon resists
  4. * both digging and falling.
  5. */
  6. boolean
  7. Can_fall_thru(lev)
  8. d_level *lev;
  9. {
  10. 	return((boolean)(Can_dig_down(lev) || Is_stronghold(lev)));
  11. }

Can_rise_up[edit]

  1. /*
  2. * True if one can rise up a level (e.g. cursed gain level).
  3. * This happens on intermediate dungeon levels or on any top dungeon
  4. * level that has a stairwell style branch to the next higher dungeon.
  5. * Checks for amulets and such must be done elsewhere.
  6. */
  7. boolean
  8. Can_rise_up(x, y, lev)
  9. int	x, y;
  10. d_level *lev;
  11. {
  12. /* can't rise up from inside the top of the Wizard's tower */
  13. /* KMH -- or in sokoban */
  14. if (In_endgame(lev) || In_sokoban(lev) ||
  15. 			(Is_wiz1_level(lev) && In_W_tower(x, y, lev)))
  16. 	return FALSE;
  17. return (boolean)(lev->dlevel > 1 ||
  18. 		(dungeons[lev->dnum].entry_lev == 1 && ledger_no(lev) != 1 &&
  19. 		 sstairs.sx && sstairs.up));
  20. }

get_level[edit]

  1. /*
  2. * It is expected that the second argument of get_level is a depth value,
  3. * either supplied by the user (teleport control) or randomly generated.
  4. * But more than one level can be at the same depth.  If the target level
  5. * is "above" the present depth location, get_level must trace "up" from
  6. * the player's location (through the ancestors dungeons) the dungeon
  7. * within which the target level is located.  With only one exception
  8. * which does not pass through this routine (see level_tele), teleporting
  9. * "down" is confined to the current dungeon.  At present, level teleport
  10. * in dungeons that build up is confined within them.
  11. */
  12. void
  13. get_level(newlevel, levnum)
  14. d_level *newlevel;
  15. int levnum;
  16. {
  17. 	branch *br;
  18. 	xchar dgn = u.uz.dnum;
  19.  
  20. 	if (levnum <= 0) {
  21. 	    /* can only currently happen in endgame */
  22. 	    levnum = u.uz.dlevel;
  23. 	} else if (levnum > dungeons[dgn].depth_start
  24. 			    + dungeons[dgn].num_dunlevs - 1) {
  25. 	    /* beyond end of dungeon, jump to last level */
  26. 	    levnum = dungeons[dgn].num_dunlevs;
  27. 	} else {
  28. 	    /* The desired level is in this dungeon or a "higher" one. */
  29.  
  30. 	    /*
  31. 	     * Branch up the tree until we reach a dungeon that contains the
  32. 	     * levnum.
  33. 	     */
  34. 	    if (levnum < dungeons[dgn].depth_start) {
  35.  
  36. 		do {
  37. 		    /*
  38. 		     * Find the parent dungeon of this dungeon.
  39. 		     *
  40. 		     * This assumes that end2 is always the "child" and it is
  41. 		     * unique.
  42. 		     */
  43. 		    for (br = branches; br; br = br->next)
  44. 			if (br->end2.dnum == dgn) break;
  45. 		    if (!br)
  46. 			panic("get_level: can't find parent dungeon");
  47.  
  48. 		    dgn = br->end1.dnum;
  49. 		} while (levnum < dungeons[dgn].depth_start);
  50. 	    }
  51.  
  52. 	    /* We're within the same dungeon; calculate the level. */
  53. 	    levnum = levnum - dungeons[dgn].depth_start + 1;
  54. 	}
  55.  
  56. 	newlevel->dnum = dgn;
  57. 	newlevel->dlevel = levnum;
  58. }
  59.  
  60. #endif /* OVL1 */

In_quest[edit]

  1. #ifdef OVL0
  2.  
  3. boolean
  4. In_quest(lev)	/* are you in the quest dungeon? */
  5. d_level *lev;
  6. {
  7. 	return((boolean)(lev->dnum == quest_dnum));
  8. }
  9.  
  10. #endif /* OVL0 */

In_mines[edit]

  1. #ifdef OVL1
  2.  
  3. boolean
  4. In_mines(lev)	/* are you in the mines dungeon? */
  5. d_level	*lev;
  6. {
  7. 	return((boolean)(lev->dnum == mines_dnum));
  8. }

dungeon_branch[edit]

  1. /*
  2. * Return the branch for the given dungeon.
  3. *
  4. * This function assumes:
  5. *	+ This is not called with "Dungeons of Doom".
  6. *	+ There is only _one_ branch to a given dungeon.
  7. *	+ Field end2 is the "child" dungeon.
  8. */
  9. branch *
  10. dungeon_branch(s)
  11. const char *s;
  12. {
  13. branch *br;
  14. xchar  dnum;
  15.  
  16. dnum = dname_to_dnum(s);
  17.  
  18. /* Find the branch that connects to dungeon i's branch. */
  19. for (br = branches; br; br = br->next)
  20. 	if (br->end2.dnum == dnum) break;
  21.  
  22. if (!br) panic("dgn_entrance: can't find entrance to %s", s);
  23.  
  24. return br;
  25. }

at_dgn_entrance[edit]

  1. /*
  2. * This returns true if the hero is on the same level as the entrance to
  3. * the named dungeon.
  4. *
  5. * Called from do.c and mklev.c.
  6. *
  7. * Assumes that end1 is always the "parent".
  8. */
  9. boolean
  10. at_dgn_entrance(s)
  11. const char *s;
  12. {
  13. branch *br;
  14.  
  15. br = dungeon_branch(s);
  16. return((boolean)(on_level(&u.uz, &br->end1) ? TRUE : FALSE));
  17. }

In_V_tower[edit]

  1. boolean
  2. In_V_tower(lev)	/* is `lev' part of Vlad's tower? */
  3. d_level	*lev;
  4. {
  5. 	return((boolean)(lev->dnum == tower_dnum));
  6. }

On_W_tower_level[edit]

  1. boolean
  2. On_W_tower_level(lev)	/* is `lev' a level containing the Wizard's tower? */
  3. d_level	*lev;
  4. {
  5. 	return (boolean)(Is_wiz1_level(lev) ||
  6. 			 Is_wiz2_level(lev) ||
  7. 			 Is_wiz3_level(lev));
  8. }

In_W_tower[edit]

  1. boolean
  2. In_W_tower(x, y, lev)	/* is <x,y> of `lev' inside the Wizard's tower? */
  3. int	x, y;
  4. d_level	*lev;
  5. {
  6. 	if (!On_W_tower_level(lev)) return FALSE;
  7. 	/*
  8. 	 * Both of the exclusion regions for arriving via level teleport
  9. 	 * (from above or below) define the tower's boundary.
  10. 	 *	assert( updest.nIJ == dndest.nIJ for I={l|h},J={x|y} );
  11. 	 */
  12. 	if (dndest.nlx > 0)
  13. 	    return (boolean)within_bounded_area(x, y, dndest.nlx, dndest.nly,
  14. 						dndest.nhx, dndest.nhy);
  15. 	else
  16. 	    impossible("No boundary for Wizard's Tower?");
  17. 	return FALSE;
  18. }
  19.  
  20. #endif /* OVL1 */

In_hell[edit]

  1. #ifdef OVL0
  2.  
  3. boolean
  4. In_hell(lev)	/* are you in one of the Hell levels? */
  5. d_level	*lev;
  6. {
  7. 	return((boolean)(dungeons[lev->dnum].flags.hellish));
  8. }
  9.  
  10. #endif /* OVL0 */

find_hell[edit]

  1. #ifdef OVL1
  2.  
  3. void
  4. find_hell(lev)	/* sets *lev to be the gateway to Gehennom... */
  5. d_level *lev;
  6. {
  7. 	lev->dnum = valley_level.dnum;
  8. 	lev->dlevel = 1;
  9. }

goto_hell[edit]

  1. void
  2. goto_hell(at_stairs, falling)	/* go directly to hell... */
  3. boolean	at_stairs, falling;
  4. {
  5. 	d_level lev;
  6.  
  7. 	find_hell(&lev);
  8. 	goto_level(&lev, at_stairs, falling, FALSE);
  9. }

assign_level[edit]

  1. void
  2. assign_level(dest, src)		/* equivalent to dest = source */
  3. d_level	*dest, *src;
  4. {
  5. 	dest->dnum = src->dnum;
  6. 	dest->dlevel = src->dlevel;
  7. }

assign_rnd_level[edit]

  1. void
  2. assign_rnd_level(dest, src, range)	/* dest = src + rn1(range) */
  3. d_level	*dest, *src;
  4. int range;
  5. {
  6. 	dest->dnum = src->dnum;
  7. 	dest->dlevel = src->dlevel + ((range > 0) ? rnd(range) : -rnd(-range)) ;
  8.  
  9. 	if(dest->dlevel > dunlevs_in_dungeon(dest))
  10. 		dest->dlevel = dunlevs_in_dungeon(dest);
  11. 	else if(dest->dlevel < 1)
  12. 		dest->dlevel = 1;
  13. }
  14.  
  15. #endif /* OVL1 */

induced_align[edit]

  1. #ifdef OVL0
  2.  
  3. int
  4. induced_align(pct)
  5. int	pct;
  6. {
  7. 	s_level	*lev = Is_special(&u.uz);
  8. 	aligntyp al;
  9.  
  10. 	if (lev && lev->flags.align)
  11. 		if(rn2(100) < pct) return(lev->flags.align);
  12.  
  13. 	if(dungeons[u.uz.dnum].flags.align)
  14. 		if(rn2(100) < pct) return(dungeons[u.uz.dnum].flags.align);
  15.  
  16. 	al = rn2(3) - 1;
  17. 	return(Align2amask(al));
  18. }
  19.  
  20. #endif /* OVL0 */

Invocation_lev[edit]

  1. #ifdef OVL1
  2.  
  3. boolean
  4. Invocation_lev(lev)
  5. d_level *lev;
  6. {
  7. 	return((boolean)(In_hell(lev) &&
  8. 		lev->dlevel == (dungeons[lev->dnum].num_dunlevs - 1)));
  9. }

level_difficulty[edit]

  1. /* use instead of depth() wherever a degree of difficulty is made
  2. * dependent on the location in the dungeon (eg. monster creation).
  3. */
  4. xchar
  5. level_difficulty()
  6. {
  7. 	if (In_endgame(&u.uz))
  8. 		return((xchar)(depth(&sanctum_level) + u.ulevel/2));
  9. 	else
  10. 		if (u.uhave.amulet)
  11. 			return(deepest_lev_reached(FALSE));
  12. 		else
  13. 			return((xchar) depth(&u.uz));
  14. }

lev_by_name[edit]

  1. /* Take one word and try to match it to a level.
  2. * Recognized levels are as shown by print_dungeon().
  3. */
  4. schar
  5. lev_by_name(nam)
  6. const char *nam;
  7. {
  8. schar lev = 0;
  9. s_level *slev;
  10. d_level dlev;
  11. const char *p;
  12. int idx, idxtoo;
  13. char buf[BUFSZ];
  14.  
  15. /* allow strings like "the oracle level" to find "oracle" */
  16. if (!strncmpi(nam, "the ", 4)) nam += 4;
  17. if ((p = strstri(nam, " level")) != 0 && p == eos((char*)nam) - 6) {
  18. 	nam = strcpy(buf, nam);
  19. 	*(eos(buf) - 6) = '\0';
  20. }
  21. /* hell is the old name, and wouldn't match; gehennom would match its
  22. branch, yielding the castle level instead of the valley of the dead */
  23. if (!strcmpi(nam, "gehennom") || !strcmpi(nam, "hell")) {
  24. 	if (In_V_tower(&u.uz)) nam = " to Vlad's tower";  /* branch to... */
  25. 	else nam = "valley";
  26. }
  27.  
  28. if ((slev = find_level(nam)) != 0) {
  29. 	dlev = slev->dlevel;
  30. 	idx = ledger_no(&dlev);
  31. 	if ((dlev.dnum == u.uz.dnum ||
  32. 		/* within same branch, or else main dungeon <-> gehennom */
  33. 		(u.uz.dnum == valley_level.dnum &&
  34. 			dlev.dnum == medusa_level.dnum) ||
  35. 		(u.uz.dnum == medusa_level.dnum &&
  36. 			dlev.dnum == valley_level.dnum)) &&
  37. 	    (	/* either wizard mode or else seen and not forgotten */
  38. #ifdef WIZARD
  39. 	     wizard ||
  40. #endif
  41. 		(level_info[idx].flags & (FORGOTTEN|VISITED)) == VISITED)) {
  42. 	    lev = depth(&slev->dlevel);
  43. 	}
  44. } else {	/* not a specific level; try branch names */
  45. 	idx = find_branch(nam, (struct proto_dungeon *)0);
  46. 	/* "<branch> to Xyzzy" */
  47. 	if (idx < 0 && (p = strstri(nam, " to ")) != 0)
  48. 	    idx = find_branch(p + 4, (struct proto_dungeon *)0);
  49.  
  50. 	if (idx >= 0) {
  51. 	    idxtoo = (idx >> 8) & 0x00FF;
  52. 	    idx &= 0x00FF;
  53. 	    if (  /* either wizard mode, or else _both_ sides of branch seen */
  54. #ifdef WIZARD
  55. 		wizard ||
  56. #endif
  57. 		((level_info[idx].flags & (FORGOTTEN|VISITED)) == VISITED &&
  58. 		 (level_info[idxtoo].flags & (FORGOTTEN|VISITED)) == VISITED)) {
  59. 		if (ledger_to_dnum(idxtoo) == u.uz.dnum) idx = idxtoo;
  60. 		dlev.dnum = ledger_to_dnum(idx);
  61. 		dlev.dlevel = ledger_to_dlev(idx);
  62. 		lev = depth(&dlev);
  63. 	    }
  64. 	}
  65. }
  66. return lev;
  67. }

br_string[edit]

  1. #ifdef WIZARD
  2.  
  3. /* Convert a branch type to a string usable by print_dungeon(). */
  4. STATIC_OVL const char *
  5. br_string(type)
  6. int type;
  7. {
  8. switch (type) {
  9. 	case BR_PORTAL:	 return "Portal";
  10. 	case BR_NO_END1: return "Connection";
  11. 	case BR_NO_END2: return "One way stair";
  12. 	case BR_STAIR:	 return "Stair";
  13. }
  14. return " (unknown)";
  15. }

print_branch[edit]

  1. /* Print all child branches between the lower and upper bounds. */
  2. STATIC_OVL void
  3. print_branch(win, dnum, lower_bound, upper_bound, bymenu, lchoices)
  4. winid win;
  5. int   dnum;
  6. int   lower_bound;
  7. int   upper_bound;
  8. boolean bymenu;
  9. struct lchoice *lchoices;
  10. {
  11. branch *br;
  12. char buf[BUFSZ];
  13. anything any;
  14.  
  15. /* This assumes that end1 is the "parent". */
  16. for (br = branches; br; br = br->next) {
  17. 	if (br->end1.dnum == dnum && lower_bound < br->end1.dlevel &&
  18. 					br->end1.dlevel <= upper_bound) {
  19. 	    Sprintf(buf,"   %s to %s: %d",
  20. 		    br_string(br->type),
  21. 		    dungeons[br->end2.dnum].dname,
  22. 		    depth(&br->end1));
  23. 	    if (bymenu) {
  24. 		lchoices->lev[lchoices->idx] = br->end1.dlevel;
  25. 		lchoices->dgn[lchoices->idx] = br->end1.dnum;
  26. 		lchoices->playerlev[lchoices->idx] = depth(&br->end1);
  27. 		any.a_void = 0;
  28. 		any.a_int = lchoices->idx + 1;
  29. 		add_menu(win, NO_GLYPH, &any, lchoices->menuletter,
  30. 				0, ATR_NONE, buf, MENU_UNSELECTED);
  31. 		if (lchoices->menuletter == 'z') lchoices->menuletter = 'A';
  32. 		else lchoices->menuletter++;
  33. 		lchoices->idx++;
  34. 	    } else
  35. 		putstr(win, 0, buf);
  36. 	}
  37. }
  38. }

print_dungeon[edit]

  1. /* Print available dungeon information. */
  2. schar
  3. print_dungeon(bymenu, rlev, rdgn)
  4. boolean bymenu;
  5. schar *rlev;
  6. xchar *rdgn;
  7. {
  8. int     i, last_level, nlev;
  9. char    buf[BUFSZ];
  10. boolean first;
  11. s_level *slev;
  12. dungeon *dptr;
  13. branch  *br;
  14. anything any;
  15. struct lchoice lchoices;
  16.  
  17. winid   win = create_nhwindow(NHW_MENU);
  18. if (bymenu) {
  19. 	start_menu(win);
  20. 	lchoices.idx = 0;
  21. 	lchoices.menuletter = 'a';
  22. }
  23.  
  24. for (i = 0, dptr = dungeons; i < n_dgns; i++, dptr++) {
  25. 	nlev = dptr->num_dunlevs;
  26. 	if (nlev > 1)
  27. 	    Sprintf(buf, "%s: levels %d to %d", dptr->dname, dptr->depth_start,
  28. 						dptr->depth_start + nlev - 1);
  29. 	else
  30. 	    Sprintf(buf, "%s: level %d", dptr->dname, dptr->depth_start);
  31.  
  32. 	/* Most entrances are uninteresting. */
  33. 	if (dptr->entry_lev != 1) {
  34. 	    if (dptr->entry_lev == nlev)
  35. 		Strcat(buf, ", entrance from below");
  36. 	    else
  37. 		Sprintf(eos(buf), ", entrance on %d",
  38. 			dptr->depth_start + dptr->entry_lev - 1);
  39. 	}
  40. 	if (bymenu) {
  41. 	    any.a_void = 0;
  42. 	    add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings, buf, MENU_UNSELECTED);
  43. 	} else
  44. 	    putstr(win, 0, buf);
  45.  
  46. 	/*
  47. 	 * Circle through the special levels to find levels that are in
  48. 	 * this dungeon.
  49. 	 */
  50. 	for (slev = sp_levchn, last_level = 0; slev; slev = slev->next) {
  51. 	    if (slev->dlevel.dnum != i) continue;
  52.  
  53. 	    /* print any branches before this level */
  54. 	    print_branch(win, i, last_level, slev->dlevel.dlevel, bymenu, &lchoices);
  55.  
  56. 	    Sprintf(buf, "   %s: %d", slev->proto, depth(&slev->dlevel));
  57. 	    if (Is_stronghold(&slev->dlevel))
  58. 		Sprintf(eos(buf), " (tune %s)", tune);
  59. 	    if (bymenu) {
  60. 	    	/* If other floating branches are added, this will need to change */
  61. 	    	if (i != knox_level.dnum) {
  62. 			lchoices.lev[lchoices.idx] = slev->dlevel.dlevel;
  63. 			lchoices.dgn[lchoices.idx] = i;
  64. 		} else {
  65. 			lchoices.lev[lchoices.idx] = depth(&slev->dlevel);
  66. 			lchoices.dgn[lchoices.idx] = 0;
  67. 		}
  68. 		lchoices.playerlev[lchoices.idx] = depth(&slev->dlevel);
  69. 		any.a_void = 0;
  70. 		any.a_int = lchoices.idx + 1;
  71. 		add_menu(win, NO_GLYPH, &any, lchoices.menuletter,
  72. 				0, ATR_NONE, buf, MENU_UNSELECTED);
  73. 		if (lchoices.menuletter == 'z') lchoices.menuletter = 'A';
  74. 		else lchoices.menuletter++;
  75. 		lchoices.idx++;
  76. 	    } else
  77. 		putstr(win, 0, buf);
  78.  
  79. 	    last_level = slev->dlevel.dlevel;
  80. 	}
  81. 	/* print branches after the last special level */
  82. 	print_branch(win, i, last_level, MAXLEVEL, bymenu, &lchoices);
  83. }
  84.  
  85. /* Print out floating branches (if any). */
  86. for (first = TRUE, br = branches; br; br = br->next) {
  87. 	if (br->end1.dnum == n_dgns) {
  88. 	    if (first) {
  89. 	    	if (!bymenu) {
  90. 		    putstr(win, 0, "");
  91. 		    putstr(win, 0, "Floating branches");
  92. 		}
  93. 		first = FALSE;
  94. 	    }
  95. 	    Sprintf(buf, "   %s to %s",
  96. 			br_string(br->type), dungeons[br->end2.dnum].dname);
  97. 	    if (!bymenu)
  98. 		putstr(win, 0, buf);
  99. 	}
  100. }
  101. if (bymenu) {
  102. 	int n;
  103. 	menu_item *selected;
  104. 	int idx;
  105.  
  106. 	end_menu(win, "Level teleport to where:");
  107. 	n = select_menu(win, PICK_ONE, &selected);
  108. 	destroy_nhwindow(win);
  109. 	if (n > 0) {
  110. 		idx = selected[0].item.a_int - 1;
  111. 		free((genericptr_t)selected);
  112. 		if (rlev && rdgn) {
  113. 			*rlev = lchoices.lev[idx];
  114. 			*rdgn = lchoices.dgn[idx];
  115. 			return lchoices.playerlev[idx];
  116. 		}
  117. 	}
  118. 	return 0;
  119. }
  120.  
  121. /* I hate searching for the invocation pos while debugging. -dean */
  122. if (Invocation_lev(&u.uz)) {
  123. 	putstr(win, 0, "");
  124. 	Sprintf(buf, "Invocation position @ (%d,%d), hero @ (%d,%d)",
  125. 		inv_pos.x, inv_pos.y, u.ux, u.uy);
  126. 	putstr(win, 0, buf);
  127. }
  128. /*
  129. * The following is based on the assumption that the inter-level portals
  130. * created by the level compiler (not the dungeon compiler) only exist
  131. * one per level (currently true, of course).
  132. */
  133. else if (Is_earthlevel(&u.uz) || Is_waterlevel(&u.uz)
  134. 				|| Is_firelevel(&u.uz) || Is_airlevel(&u.uz)) {
  135. 	struct trap *trap;
  136. 	for (trap = ftrap; trap; trap = trap->ntrap)
  137. 	    if (trap->ttyp == MAGIC_PORTAL) break;
  138.  
  139. 	putstr(win, 0, "");
  140. 	if (trap)
  141. 	    Sprintf(buf, "Portal @ (%d,%d), hero @ (%d,%d)",
  142. 		trap->tx, trap->ty, u.ux, u.uy);
  143. 	else
  144. 	    Sprintf(buf, "No portal found.");
  145. 	putstr(win, 0, buf);
  146. }
  147.  
  148. display_nhwindow(win, TRUE);
  149. destroy_nhwindow(win);
  150. return 0;
  151. }
  152. #endif /* WIZARD */
  153.  
  154. #endif /* OVL1 */
  155.  
  156. /*dungeon.c*/