Source:NetHack 3.4.3/src/mkroom.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to src/mkroom.c from NetHack 3.4.3. To link to a particular line, write [[mkroom.c#line123]], for example. This file deals with the creation of special rooms, like shops, temples, zoos, leprechaun halls, etc..

Top of file[edit]

  1. /*	SCCS Id: @(#)mkroom.c	3.4	2001/09/06	*/
  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. /*
  2. * Entry points:
  3. *	mkroom() -- make and stock a room of a given type
  4. *	nexttodoor() -- return TRUE if adjacent to a door
  5. *	has_dnstairs() -- return TRUE if given room has a down staircase
  6. *	has_upstairs() -- return TRUE if given room has an up staircase
  7. *	courtmon() -- generate a court monster
  8. *	save_rooms() -- save rooms into file fd
  9. *	rest_rooms() -- restore rooms from file fd
  10. */
  11.  
  12. #include "hack.h"
  13.  
  14. #ifdef OVLB
  15. STATIC_DCL boolean FDECL(isbig, (struct mkroom *));
  16. STATIC_DCL struct mkroom * FDECL(pick_room,(BOOLEAN_P));
  17. STATIC_DCL void NDECL(mkshop), FDECL(mkzoo,(int)), NDECL(mkswamp);
  18. STATIC_DCL void NDECL(mktemple);
  19. STATIC_DCL coord * FDECL(shrine_pos, (int));
  20. STATIC_DCL struct permonst * NDECL(morguemon);
  21. STATIC_DCL struct permonst * NDECL(antholemon);
  22. STATIC_DCL struct permonst * NDECL(squadmon);
  23. STATIC_DCL void FDECL(save_room, (int,struct mkroom *));
  24. STATIC_DCL void FDECL(rest_room, (int,struct mkroom *));
  25. #endif /* OVLB */
  26.  
  27. #define sq(x) ((x)*(x))
  28.  
  29. extern const struct shclass shtypes[];	/* defined in shknam.c */
  30.  
  31. #ifdef OVLB

isbig[edit]

  1. STATIC_OVL boolean
  2. isbig(sroom)
  3. register struct mkroom *sroom;
  4. {
  5. 	register int area = (sroom->hx - sroom->lx + 1)
  6. 			   * (sroom->hy - sroom->ly + 1);
  7. 	return((boolean)( area > 20 ));
  8. }

mkroom[edit]

  1. void
  2. mkroom(roomtype)
  3. /* make and stock a room of a given type */
  4. int	roomtype;
  5. {
  6. if (roomtype >= SHOPBASE)
  7. 	mkshop();	/* someday, we should be able to specify shop type */
  8. else switch(roomtype) {
  9. 	case COURT:	mkzoo(COURT); break;
  10. 	case ZOO:	mkzoo(ZOO); break;
  11. 	case BEEHIVE:	mkzoo(BEEHIVE); break;
  12. 	case MORGUE:	mkzoo(MORGUE); break;
  13. 	case BARRACKS:	mkzoo(BARRACKS); break;
  14. 	case SWAMP:	mkswamp(); break;
  15. 	case TEMPLE:	mktemple(); break;
  16. 	case LEPREHALL:	mkzoo(LEPREHALL); break;
  17. 	case COCKNEST:	mkzoo(COCKNEST); break;
  18. 	case ANTHOLE:	mkzoo(ANTHOLE); break;
  19. 	default:	impossible("Tried to make a room of type %d.", roomtype);
  20. }
  21. }

mkshop[edit]

  1. STATIC_OVL void
  2. mkshop()
  3. {
  4. 	register struct mkroom *sroom;
  5. 	int i = -1;
  6. #ifdef WIZARD
  7. 	char *ep = (char *)0;	/* (init == lint suppression) */
  8.  
  9. 	/* first determine shoptype */
  10. 	if(wizard){
  11. #ifndef MAC
  12. 		ep = nh_getenv("SHOPTYPE");
  13. 		if(ep){
  14. 			if(*ep == 'z' || *ep == 'Z'){
  15. 				mkzoo(ZOO);
  16. 				return;
  17. 			}
  18. 			if(*ep == 'm' || *ep == 'M'){
  19. 				mkzoo(MORGUE);
  20. 				return;
  21. 			}
  22. 			if(*ep == 'b' || *ep == 'B'){
  23. 				mkzoo(BEEHIVE);
  24. 				return;
  25. 			}
  26. 			if(*ep == 't' || *ep == 'T' || *ep == '\\'){
  27. 				mkzoo(COURT);
  28. 				return;
  29. 			}
  30. 			if(*ep == 's' || *ep == 'S'){
  31. 				mkzoo(BARRACKS);
  32. 				return;
  33. 			}
  34. 			if(*ep == 'a' || *ep == 'A'){
  35. 				mkzoo(ANTHOLE);
  36. 				return;
  37. 			}
  38. 			if(*ep == 'c' || *ep == 'C'){
  39. 				mkzoo(COCKNEST);
  40. 				return;
  41. 			}
  42. 			if(*ep == 'l' || *ep == 'L'){
  43. 				mkzoo(LEPREHALL);
  44. 				return;
  45. 			}
  46. 			if(*ep == '_'){
  47. 				mktemple();
  48. 				return;
  49. 			}
  50. 			if(*ep == '}'){
  51. 				mkswamp();
  52. 				return;
  53. 			}
  54. 			for(i=0; shtypes[i].name; i++)
  55. 				if(*ep == def_oc_syms[(int)shtypes[i].symb])
  56. 				    goto gottype;
  57. 			if(*ep == 'g' || *ep == 'G')
  58. 				i = 0;
  59. 			else
  60. 				i = -1;
  61. 		}
  62. #endif
  63. 	}
  64. #ifndef MAC
  65. gottype:
  66. #endif
  67. #endif
  68. 	for(sroom = &rooms[0]; ; sroom++){
  69. 		if(sroom->hx < 0) return;
  70. 		if(sroom - rooms >= nroom) {
  71. 			pline("rooms not closed by -1?");
  72. 			return;
  73. 		}
  74. 		if(sroom->rtype != OROOM) continue;
  75. 		if(has_dnstairs(sroom) || has_upstairs(sroom))
  76. 			continue;
  77. 		if(
  78. #ifdef WIZARD
  79. 		   (wizard && ep && sroom->doorct != 0) ||
  80. #endif
  81. 			sroom->doorct == 1) break;
  82. 	}
  83. 	if (!sroom->rlit) {
  84. 		int x, y;
  85.  
  86. 		for(x = sroom->lx - 1; x <= sroom->hx + 1; x++)
  87. 		for(y = sroom->ly - 1; y <= sroom->hy + 1; y++)
  88. 			levl[x][y].lit = 1;
  89. 		sroom->rlit = 1;
  90. 	}
  91.  
  92. 	if(i < 0) {			/* shoptype not yet determined */
  93. 	    register int j;
  94.  
  95. 	    /* pick a shop type at random */
  96. 	    for (j = rnd(100), i = 0; (j -= shtypes[i].prob) > 0; i++)
  97. 		continue;
  98.  
  99. 	    /* big rooms cannot be wand or book shops,
  100. 	     * - so make them general stores
  101. 	     */
  102. 	    if(isbig(sroom) && (shtypes[i].symb == WAND_CLASS
  103. 				|| shtypes[i].symb == SPBOOK_CLASS)) i = 0;
  104. 	}
  105. 	sroom->rtype = SHOPBASE + i;
  106.  
  107. 	/* set room bits before stocking the shop */
  108. #ifdef SPECIALIZATION
  109. 	topologize(sroom, FALSE); /* doesn't matter - this is a special room */
  110. #else
  111. 	topologize(sroom);
  112. #endif
  113.  
  114. 	/* stock the room with a shopkeeper and artifacts */
  115. 	stock_room(i, sroom);
  116. }

pick_room[edit]

  1. STATIC_OVL struct mkroom *
  2. pick_room(strict)
  3. register boolean strict;
  4. /* pick an unused room, preferably with only one door */
  5. {
  6. 	register struct mkroom *sroom;
  7. 	register int i = nroom;
  8.  
  9. 	for(sroom = &rooms[rn2(nroom)]; i--; sroom++) {
  10. 		if(sroom == &rooms[nroom])
  11. 			sroom = &rooms[0];
  12. 		if(sroom->hx < 0)
  13. 			return (struct mkroom *)0;
  14. 		if(sroom->rtype != OROOM)	continue;
  15. 		if(!strict) {
  16. 		    if(has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3)))
  17. 			continue;
  18. 		} else if(has_upstairs(sroom) || has_dnstairs(sroom))
  19. 			continue;
  20. 		if(sroom->doorct == 1 || !rn2(5)
  21. #ifdef WIZARD
  22. 						|| wizard
  23. #endif
  24. 							)
  25. 			return sroom;
  26. 	}
  27. 	return (struct mkroom *)0;
  28. }

mkzoo[edit]

  1. STATIC_OVL void
  2. mkzoo(type)
  3. int type;
  4. {
  5. 	register struct mkroom *sroom;
  6.  
  7. 	if ((sroom = pick_room(FALSE)) != 0) {
  8. 		sroom->rtype = type;
  9. 		fill_zoo(sroom);
  10. 	}
  11. }

fill_zoo[edit]

  1. void
  2. fill_zoo(sroom)
  3. struct mkroom *sroom;
  4. {
  5. 	struct monst *mon;
  6. 	register int sx,sy,i;
  7. 	int sh, tx, ty, goldlim, type = sroom->rtype;
  8. 	int rmno = (sroom - rooms) + ROOMOFFSET;
  9. 	coord mm;
  10.  
  11. #ifdef GCC_WARN
  12. 	tx = ty = goldlim = 0;
  13. #endif
  14.  
  15. 	sh = sroom->fdoor;
  16. 	switch(type) {
  17. 	    case COURT:
  18. 		if(level.flags.is_maze_lev) {
  19. 		    for(tx = sroom->lx; tx <= sroom->hx; tx++)
  20. 			for(ty = sroom->ly; ty <= sroom->hy; ty++)
  21. 			    if(IS_THRONE(levl[tx][ty].typ))
  22. 				goto throne_placed;
  23. 		}
  24. 		i = 100;
  25. 		do {	/* don't place throne on top of stairs */
  26. 			(void) somexy(sroom, &mm);
  27. 			tx = mm.x; ty = mm.y;
  28. 		} while (occupied((xchar)tx, (xchar)ty) && --i > 0);
  29. 	    throne_placed:
  30. 		/* TODO: try to ensure the enthroned monster is an M2_PRINCE */
  31. 		break;
  32. 	    case BEEHIVE:
  33. 		tx = sroom->lx + (sroom->hx - sroom->lx + 1)/2;
  34. 		ty = sroom->ly + (sroom->hy - sroom->ly + 1)/2;
  35. 		if(sroom->irregular) {
  36. 		    /* center might not be valid, so put queen elsewhere */
  37. 		    if ((int) levl[tx][ty].roomno != rmno ||
  38. 			    levl[tx][ty].edge) {
  39. 			(void) somexy(sroom, &mm);
  40. 			tx = mm.x; ty = mm.y;
  41. 		    }
  42. 		}
  43. 		break;
  44. 	    case ZOO:
  45. 	    case LEPREHALL:
  46. 		goldlim = 500 * level_difficulty();
  47. 		break;
  48. 	}
  49. 	for(sx = sroom->lx; sx <= sroom->hx; sx++)
  50. 	    for(sy = sroom->ly; sy <= sroom->hy; sy++) {
  51. 		if(sroom->irregular) {
  52. 		    if ((int) levl[sx][sy].roomno != rmno ||
  53. 			  levl[sx][sy].edge ||
  54. 			  (sroom->doorct &&
  55. 			   distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1))
  56. 			continue;
  57. 		} else if(!SPACE_POS(levl[sx][sy].typ) ||
  58. 			  (sroom->doorct &&
  59. 			   ((sx == sroom->lx && doors[sh].x == sx-1) ||
  60. 			    (sx == sroom->hx && doors[sh].x == sx+1) ||
  61. 			    (sy == sroom->ly && doors[sh].y == sy-1) ||
  62. 			    (sy == sroom->hy && doors[sh].y == sy+1))))
  63. 		    continue;
  64. 		/* don't place monster on explicitly placed throne */
  65. 		if(type == COURT && IS_THRONE(levl[sx][sy].typ))
  66. 		    continue;
  67. 		mon = makemon(
  68. 		    (type == COURT) ? courtmon() :
  69. 		    (type == BARRACKS) ? squadmon() :
  70. 		    (type == MORGUE) ? morguemon() :
  71. 		    (type == BEEHIVE) ?
  72. 			(sx == tx && sy == ty ? &mons[PM_QUEEN_BEE] :
  73. 			 &mons[PM_KILLER_BEE]) :
  74. 		    (type == LEPREHALL) ? &mons[PM_LEPRECHAUN] :
  75. 		    (type == COCKNEST) ? &mons[PM_COCKATRICE] :
  76. 		    (type == ANTHOLE) ? antholemon() :
  77. 		    (struct permonst *) 0,
  78. 		   sx, sy, NO_MM_FLAGS);
  79. 		if(mon) {
  80. 			mon->msleeping = 1;
  81. 			if (type==COURT && mon->mpeaceful) {
  82. 				mon->mpeaceful = 0;
  83. 				set_malign(mon);
  84. 			}
  85. 		}
  86. 		switch(type) {
  87. 		    case ZOO:
  88. 		    case LEPREHALL:
  89. 			if(sroom->doorct)
  90. 			{
  91. 			    int distval = dist2(sx,sy,doors[sh].x,doors[sh].y);
  92. 			    i = sq(distval);
  93. 			}
  94. 			else
  95. 			    i = goldlim;
  96. 			if(i >= goldlim) i = 5*level_difficulty();
  97. 			goldlim -= i;
  98. 			(void) mkgold((long) rn1(i, 10), sx, sy);
  99. 			break;
  100. 		    case MORGUE:
  101. 			if(!rn2(5))
  102. 			    (void) mk_tt_object(CORPSE, sx, sy);
  103. 			if(!rn2(10))	/* lots of treasure buried with dead */
  104. 			    (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST,
  105. 					     sx, sy, TRUE, FALSE);
  106. 			if (!rn2(5))
  107. 			    make_grave(sx, sy, (char *)0);
  108. 			break;
  109. 		    case BEEHIVE:
  110. 			if(!rn2(3))
  111. 			    (void) mksobj_at(LUMP_OF_ROYAL_JELLY,
  112. 					     sx, sy, TRUE, FALSE);
  113. 			break;
  114. 		    case BARRACKS:
  115. 			if(!rn2(20))	/* the payroll and some loot */
  116. 			    (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST,
  117. 					     sx, sy, TRUE, FALSE);
  118. 			break;
  119. 		    case COCKNEST:
  120. 			if(!rn2(3)) {
  121. 			    struct obj *sobj = mk_tt_object(STATUE, sx, sy);
  122.  
  123. 			    if (sobj) {
  124. 				for (i = rn2(5); i; i--)
  125. 				    (void) add_to_container(sobj,
  126. 						mkobj(RANDOM_CLASS, FALSE));
  127. 				sobj->owt = weight(sobj);
  128. 			    }
  129. 			}
  130. 			break;
  131. 		    case ANTHOLE:
  132. 			if(!rn2(3))
  133. 			    (void) mkobj_at(FOOD_CLASS, sx, sy, FALSE);
  134. 			break;
  135. 		}
  136. 	    }
  137. 	switch (type) {
  138. 	      case COURT:
  139. 		{
  140. 		  struct obj *chest;
  141. 		  levl[tx][ty].typ = THRONE;
  142. 		  (void) somexy(sroom, &mm);
  143. 		  (void) mkgold((long) rn1(50 * level_difficulty(),10), mm.x, mm.y);
  144. 		  /* the royal coffers */
  145. 		  chest = mksobj_at(CHEST, mm.x, mm.y, TRUE, FALSE);
  146. 		  chest->spe = 2; /* so it can be found later */
  147. 		  level.flags.has_court = 1;
  148. 		  break;
  149. 		}
  150. 	      case BARRACKS:
  151. 		  level.flags.has_barracks = 1;
  152. 		  break;
  153. 	      case ZOO:
  154. 		  level.flags.has_zoo = 1;
  155. 		  break;
  156. 	      case MORGUE:
  157. 		  level.flags.has_morgue = 1;
  158. 		  break;
  159. 	      case SWAMP:
  160. 		  level.flags.has_swamp = 1;
  161. 		  break;
  162. 	      case BEEHIVE:
  163. 		  level.flags.has_beehive = 1;
  164. 		  break;
  165. 	}
  166. }

mkundead[edit]

  1. /* make a swarm of undead around mm */
  2. void
  3. mkundead(mm, revive_corpses, mm_flags)
  4. coord *mm;
  5. boolean revive_corpses;
  6. int mm_flags;
  7. {
  8. 	int cnt = (level_difficulty() + 1)/10 + rnd(5);
  9. 	struct permonst *mdat;
  10. 	struct obj *otmp;
  11. 	coord cc;
  12.  
  13. 	while (cnt--) {
  14. 	    mdat = morguemon();
  15. 	    if (enexto(&cc, mm->x, mm->y, mdat) &&
  16. 		    (!revive_corpses ||
  17. 		     !(otmp = sobj_at(CORPSE, cc.x, cc.y)) ||
  18. 		     !revive(otmp)))
  19. 		(void) makemon(mdat, cc.x, cc.y, mm_flags);
  20. 	}
  21. 	level.flags.graveyard = TRUE;	/* reduced chance for undead corpse */
  22. }

morguemon[edit]

  1. STATIC_OVL struct permonst *
  2. morguemon()
  3. {
  4. 	register int i = rn2(100), hd = rn2(level_difficulty());
  5.  
  6. 	if(hd > 10 && i < 10)
  7. 		return((Inhell || In_endgame(&u.uz)) ? mkclass(S_DEMON,0) :
  8. 						       &mons[ndemon(A_NONE)]);
  9. 	if(hd > 8 && i > 85)
  10. 		return(mkclass(S_VAMPIRE,0));
  11.  
  12. 	return((i < 20) ? &mons[PM_GHOST]
  13. 			: (i < 40) ? &mons[PM_WRAITH] : mkclass(S_ZOMBIE,0));
  14. }

antholemon[edit]

  1. STATIC_OVL struct permonst *
  2. antholemon()
  3. {
  4. 	int mtyp;
  5.  
  6. 	/* Same monsters within a level, different ones between levels */
  7. 	switch ((level_difficulty() + ((long)u.ubirthday)) % 3) {
  8. 	default:	mtyp = PM_GIANT_ANT; break;
  9. 	case 0:		mtyp = PM_SOLDIER_ANT; break;
  10. 	case 1:		mtyp = PM_FIRE_ANT; break;
  11. 	}
  12. 	return ((mvitals[mtyp].mvflags & G_GONE) ?
  13. 			(struct permonst *)0 : &mons[mtyp]);
  14. }

mkswamp[edit]

  1. STATIC_OVL void
  2. mkswamp()	/* Michiel Huisjes & Fred de Wilde */
  3. {
  4. 	register struct mkroom *sroom;
  5. 	register int sx,sy,i,eelct = 0;
  6.  
  7. 	for(i=0; i<5; i++) {		/* turn up to 5 rooms swampy */
  8. 		sroom = &rooms[rn2(nroom)];
  9. 		if(sroom->hx < 0 || sroom->rtype != OROOM ||
  10. 		   has_upstairs(sroom) || has_dnstairs(sroom))
  11. 			continue;
  12.  
  13. 		/* satisfied; make a swamp */
  14. 		sroom->rtype = SWAMP;
  15. 		for(sx = sroom->lx; sx <= sroom->hx; sx++)
  16. 		for(sy = sroom->ly; sy <= sroom->hy; sy++)
  17. 		if(!OBJ_AT(sx, sy) &&
  18. 		   !MON_AT(sx, sy) && !t_at(sx,sy) && !nexttodoor(sx,sy)) {
  19. 		    if((sx+sy)%2) {
  20. 			levl[sx][sy].typ = POOL;
  21. 			if(!eelct || !rn2(4)) {
  22. 			    /* mkclass() won't do, as we might get kraken */
  23. 			    (void) makemon(rn2(5) ? &mons[PM_GIANT_EEL]
  24. 						  : rn2(2) ? &mons[PM_PIRANHA]
  25. 						  : &mons[PM_ELECTRIC_EEL],
  26. 						sx, sy, NO_MM_FLAGS);
  27. 			    eelct++;
  28. 			}
  29. 		    } else
  30. 			if(!rn2(4))	/* swamps tend to be moldy */
  31. 			    (void) makemon(mkclass(S_FUNGUS,0),
  32. 						sx, sy, NO_MM_FLAGS);
  33. 		}
  34. 		level.flags.has_swamp = 1;
  35. 	}
  36. }

shrine_pos[edit]

  1. STATIC_OVL coord *
  2. shrine_pos(roomno)
  3. int roomno;
  4. {
  5. 	static coord buf;
  6. 	struct mkroom *troom = &rooms[roomno - ROOMOFFSET];
  7.  
  8. 	buf.x = troom->lx + ((troom->hx - troom->lx) / 2);
  9. 	buf.y = troom->ly + ((troom->hy - troom->ly) / 2);
  10. 	return(&buf);
  11. }

mktemple[edit]

  1. STATIC_OVL void
  2. mktemple()
  3. {
  4. 	register struct mkroom *sroom;
  5. 	coord *shrine_spot;
  6. 	register struct rm *lev;
  7.  
  8. 	if(!(sroom = pick_room(TRUE))) return;
  9.  
  10. 	/* set up Priest and shrine */
  11. 	sroom->rtype = TEMPLE;
  12. 	/*
  13. 	 * In temples, shrines are blessed altars
  14. 	 * located in the center of the room
  15. 	 */
  16. 	shrine_spot = shrine_pos((sroom - rooms) + ROOMOFFSET);
  17. 	lev = &levl[shrine_spot->x][shrine_spot->y];
  18. 	lev->typ = ALTAR;
  19. 	lev->altarmask = induced_align(80);
  20. 	priestini(&u.uz, sroom, shrine_spot->x, shrine_spot->y, FALSE);
  21. 	lev->altarmask |= AM_SHRINE;
  22. 	level.flags.has_temple = 1;
  23. }

nexttodoor[edit]

  1. boolean
  2. nexttodoor(sx,sy)
  3. register int sx, sy;
  4. {
  5. 	register int dx, dy;
  6. 	register struct rm *lev;
  7. 	for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) {
  8. 		if(!isok(sx+dx, sy+dy)) continue;
  9. 		if(IS_DOOR((lev = &levl[sx+dx][sy+dy])->typ) ||
  10. 		    lev->typ == SDOOR)
  11. 			return(TRUE);
  12. 	}
  13. 	return(FALSE);
  14. }

has_dnstairs[edit]

  1. boolean
  2. has_dnstairs(sroom)
  3. register struct mkroom *sroom;
  4. {
  5. 	if (sroom == dnstairs_room)
  6. 		return TRUE;
  7. 	if (sstairs.sx && !sstairs.up)
  8. 		return((boolean)(sroom == sstairs_room));
  9. 	return FALSE;
  10. }

has_upstairs[edit]

  1. boolean
  2. has_upstairs(sroom)
  3. register struct mkroom *sroom;
  4. {
  5. 	if (sroom == upstairs_room)
  6. 		return TRUE;
  7. 	if (sstairs.sx && sstairs.up)
  8. 		return((boolean)(sroom == sstairs_room));
  9. 	return FALSE;
  10. }
  11.  
  12. #endif /* OVLB */
  13. #ifdef OVL0

somex[edit]

  1. int
  2. somex(croom)
  3. register struct mkroom *croom;
  4. {
  5. 	return rn2(croom->hx-croom->lx+1) + croom->lx;
  6. }

somey[edit]

  1. int
  2. somey(croom)
  3. register struct mkroom *croom;
  4. {
  5. 	return rn2(croom->hy-croom->ly+1) + croom->ly;
  6. }

inside_room[edit]

  1. boolean
  2. inside_room(croom, x, y)
  3. struct mkroom *croom;
  4. xchar x, y;
  5. {
  6. 	return((boolean)(x >= croom->lx-1 && x <= croom->hx+1 &&
  7. 		y >= croom->ly-1 && y <= croom->hy+1));
  8. }

somexy[edit]

  1. boolean
  2. somexy(croom, c)
  3. struct mkroom *croom;
  4. coord *c;
  5. {
  6. 	int try_cnt = 0;
  7. 	int i;
  8.  
  9. 	if (croom->irregular) {
  10. 	    i = (croom - rooms) + ROOMOFFSET;
  11.  
  12. 	    while(try_cnt++ < 100) {
  13. 		c->x = somex(croom);
  14. 		c->y = somey(croom);
  15. 		if (!levl[c->x][c->y].edge &&
  16. 			(int) levl[c->x][c->y].roomno == i)
  17. 		    return TRUE;
  18. 	    }
  19. 	    /* try harder; exhaustively search until one is found */
  20. 	    for(c->x = croom->lx; c->x <= croom->hx; c->x++)
  21. 		for(c->y = croom->ly; c->y <= croom->hy; c->y++)
  22. 		    if (!levl[c->x][c->y].edge &&
  23. 			    (int) levl[c->x][c->y].roomno == i)
  24. 			return TRUE;
  25. 	    return FALSE;
  26. 	}
  27.  
  28. 	if (!croom->nsubrooms) {
  29. 		c->x = somex(croom);
  30. 		c->y = somey(croom);
  31. 		return TRUE;
  32. 	}
  33.  
  34. 	/* Check that coords doesn't fall into a subroom or into a wall */
  35.  
  36. 	while(try_cnt++ < 100) {
  37. 		c->x = somex(croom);
  38. 		c->y = somey(croom);
  39. 		if (IS_WALL(levl[c->x][c->y].typ))
  40. 		    continue;
  41. 		for(i=0 ; i<croom->nsubrooms;i++)
  42. 		    if(inside_room(croom->sbrooms[i], c->x, c->y))
  43. 			goto you_lose;
  44. 		break;
  45. you_lose:	;
  46. 	}
  47. 	if (try_cnt >= 100)
  48. 	    return FALSE;
  49. 	return TRUE;
  50. }

search_special[edit]

  1. /*
  2. * Search for a special room given its type (zoo, court, etc...)
  3. *	Special values :
  4. *		- ANY_SHOP
  5. *		- ANY_TYPE
  6. */
  7.  
  8. struct mkroom *
  9. search_special(type)
  10. schar type;
  11. {
  12. 	register struct mkroom *croom;
  13.  
  14. 	for(croom = &rooms[0]; croom->hx >= 0; croom++)
  15. 	    if((type == ANY_TYPE && croom->rtype != OROOM) ||
  16. 	       (type == ANY_SHOP && croom->rtype >= SHOPBASE) ||
  17. 	       croom->rtype == type)
  18. 		return croom;
  19. 	for(croom = &subrooms[0]; croom->hx >= 0; croom++)
  20. 	    if((type == ANY_TYPE && croom->rtype != OROOM) ||
  21. 	       (type == ANY_SHOP && croom->rtype >= SHOPBASE) ||
  22. 	       croom->rtype == type)
  23. 		return croom;
  24. 	return (struct mkroom *) 0;
  25. }
  26.  
  27. #endif /* OVL0 */
  28. #ifdef OVLB

courtmon[edit]

  1. struct permonst *
  2. courtmon()
  3. {
  4. 	int     i = rn2(60) + rn2(3*level_difficulty());
  5. 	if (i > 100)		return(mkclass(S_DRAGON,0));
  6. 	else if (i > 95)	return(mkclass(S_GIANT,0));
  7. 	else if (i > 85)	return(mkclass(S_TROLL,0));
  8. 	else if (i > 75)	return(mkclass(S_CENTAUR,0));
  9. 	else if (i > 60)	return(mkclass(S_ORC,0));
  10. 	else if (i > 45)	return(&mons[PM_BUGBEAR]);
  11. 	else if (i > 30)	return(&mons[PM_HOBGOBLIN]);
  12. 	else if (i > 15)	return(mkclass(S_GNOME,0));
  13. 	else			return(mkclass(S_KOBOLD,0));
  14. }

squadmon[edit]

  1. #define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1)
  2.  
  3. static struct {
  4. unsigned	pm;
  5. unsigned	prob;
  6. } squadprob[NSTYPES] = {
  7. {PM_SOLDIER, 80}, {PM_SERGEANT, 15}, {PM_LIEUTENANT, 4}, {PM_CAPTAIN, 1}
  8. };
  9.  
  10. STATIC_OVL struct permonst *
  11. squadmon()		/* return soldier types. */
  12. {
  13. 	int sel_prob, i, cpro, mndx;
  14.  
  15. 	sel_prob = rnd(80+level_difficulty());
  16.  
  17. 	cpro = 0;
  18. 	for (i = 0; i < NSTYPES; i++) {
  19. 	    cpro += squadprob[i].prob;
  20. 	    if (cpro > sel_prob) {
  21. 		mndx = squadprob[i].pm;
  22. 		goto gotone;
  23. 	    }
  24. 	}
  25. 	mndx = squadprob[rn2(NSTYPES)].pm;
  26. gotone:
  27. 	if (!(mvitals[mndx].mvflags & G_GONE)) return(&mons[mndx]);
  28. 	else			    return((struct permonst *) 0);
  29. }

save_room[edit]

  1. /*
  2. * save_room : A recursive function that saves a room and its subrooms
  3. * (if any).
  4. */
  5.  
  6. STATIC_OVL void
  7. save_room(fd, r)
  8. int	fd;
  9. struct mkroom *r;
  10. {
  11. 	short i;
  12. 	/*
  13. 	 * Well, I really should write only useful information instead
  14. 	 * of writing the whole structure. That is I should not write
  15. 	 * the subrooms pointers, but who cares ?
  16. 	 */
  17. 	bwrite(fd, (genericptr_t) r, sizeof(struct mkroom));
  18. 	for(i=0; i<r->nsubrooms; i++)
  19. 	    save_room(fd, r->sbrooms[i]);
  20. }

save_rooms[edit]

  1. /*
  2. * save_rooms : Save all the rooms on disk!
  3. */
  4.  
  5. void
  6. save_rooms(fd)
  7. int fd;
  8. {
  9. 	short i;
  10.  
  11. 	/* First, write the number of rooms */
  12. 	bwrite(fd, (genericptr_t) &nroom, sizeof(nroom));
  13. 	for(i=0; i<nroom; i++)
  14. 	    save_room(fd, &rooms[i]);
  15. }

rest_room[edit]

  1. STATIC_OVL void
  2. rest_room(fd, r)
  3. int fd;
  4. struct mkroom *r;
  5. {
  6. 	short i;
  7.  
  8. 	mread(fd, (genericptr_t) r, sizeof(struct mkroom));
  9. 	for(i=0; i<r->nsubrooms; i++) {
  10. 		r->sbrooms[i] = &subrooms[nsubroom];
  11. 		rest_room(fd, &subrooms[nsubroom]);
  12. 		subrooms[nsubroom++].resident = (struct monst *)0;
  13. 	}
  14. }

rest_rooms[edit]

  1. /*
  2. * rest_rooms : That's for restoring rooms. Read the rooms structure from
  3. * the disk.
  4. */
  5.  
  6. void
  7. rest_rooms(fd)
  8. int	fd;
  9. {
  10. 	short i;
  11.  
  12. 	mread(fd, (genericptr_t) &nroom, sizeof(nroom));
  13. 	nsubroom = 0;
  14. 	for(i = 0; i<nroom; i++) {
  15. 	    rest_room(fd, &rooms[i]);
  16. 	    rooms[i].resident = (struct monst *)0;
  17. 	}
  18. 	rooms[nroom].hx = -1;		/* restore ending flags */
  19. 	subrooms[nsubroom].hx = -1;
  20. }
  21. #endif /* OVLB */
  22.  
  23. /*mkroom.c*/