create.c revision 1.5       1  1.2   mycroft #ifndef lint
      2  1.5  christos static char rcsid[] = "$NetBSD: create.c,v 1.5 1997/07/13 20:21:32 christos Exp $";
      3  1.2   mycroft #endif /* not lint */
      4  1.2   mycroft 
      5  1.1       cgd /*	create.c		Larn is copyrighted 1986 by Noah Morgan. */
      6  1.1       cgd #include "header.h"
      7  1.1       cgd extern char spelknow[],larnlevels[];
      8  1.4   thorpej extern char beenhere[],wizard;
      9  1.4   thorpej extern short level;
     10  1.1       cgd extern short oldx,oldy;
     11  1.1       cgd /*
     12  1.1       cgd 	makeplayer()
     13  1.1       cgd 
     14  1.1       cgd 	subroutine to create the player and the players attributes
     15  1.1       cgd 	this is called at the beginning of a game and at no other time
     16  1.1       cgd  */
     17  1.1       cgd makeplayer()
     18  1.1       cgd 	{
     19  1.1       cgd 	register int i;
     20  1.1       cgd 	scbr();  clear();
     21  1.1       cgd 	c[HPMAX]=c[HP]=10;		/*	start player off with 15 hit points	*/
     22  1.1       cgd 	c[LEVEL]=1;				/*	player starts at level one			*/
     23  1.1       cgd 	c[SPELLMAX]=c[SPELLS]=1;	/*	total # spells starts off as 3	*/
     24  1.1       cgd 	c[REGENCOUNTER]=16;		c[ECOUNTER]=96;	/*start regeneration correctly*/
     25  1.1       cgd 	c[SHIELD] = c[WEAR] = c[WIELD] = -1;
     26  1.1       cgd 	for (i=0; i<26; i++)  iven[i]=0;
     27  1.1       cgd 	spelknow[0]=spelknow[1]=1; /*he knows protection, magic missile*/
     28  1.1       cgd 	if (c[HARDGAME]<=0)
     29  1.1       cgd 		{
     30  1.1       cgd 		iven[0]=OLEATHER; iven[1]=ODAGGER;
     31  1.1       cgd 		ivenarg[1]=ivenarg[0]=c[WEAR]=0;  c[WIELD]=1;
     32  1.1       cgd 		}
     33  1.1       cgd 	playerx=rnd(MAXX-2);	playery=rnd(MAXY-2);
     34  1.1       cgd 	oldx=0;			oldy=25;
     35  1.5  christos 	gltime=0;			/*	time clock starts at zero	*/
     36  1.1       cgd 	cbak[SPELLS] = -50;
     37  1.1       cgd 	for (i=0; i<6; i++)  c[i]=12; /* make the attributes, ie str, int, etc.	*/
     38  1.1       cgd 	recalc();
     39  1.1       cgd 	}
     40  1.1       cgd 
     41  1.1       cgd /*
     43  1.1       cgd 	newcavelevel(level)
     44  1.1       cgd 	int level;
     45  1.1       cgd 
     46  1.1       cgd 	function to enter a new level.  This routine must be called anytime the
     47  1.1       cgd 	player changes levels.  If that level is unknown it will be created.
     48  1.1       cgd 	A new set of monsters will be created for a new level, and existing
     49  1.1       cgd 	levels will get a few more monsters.
     50  1.1       cgd 	Note that it is here we remove genocided monsters from the present level.
     51  1.1       cgd  */
     52  1.1       cgd newcavelevel(x)
     53  1.1       cgd 	register int x;
     54  1.1       cgd 	{
     55  1.1       cgd 	register int i,j;
     56  1.1       cgd 	if (beenhere[level]) savelevel();	/* put the level back into storage	*/
     57  1.1       cgd 	level = x;				/* get the new level and put in working storage */
     58  1.1       cgd 	if (beenhere[x]==0) for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) know[j][i]=mitem[j][i]=0;
     59  1.1       cgd 		else { getlevel(); sethp(0);  goto chgn; }
     60  1.1       cgd 	makemaze(x);	makeobject(x);	beenhere[x]=1;  sethp(1);
     61  1.1       cgd 
     62  1.1       cgd #if WIZID
     63  1.1       cgd 	if (wizard || x==0)
     64  1.1       cgd #else
     65  1.1       cgd 	if (x==0)
     66  1.1       cgd #endif
     67  1.1       cgd 
     68  1.1       cgd 		for (j=0; j<MAXY; j++)
     69  1.1       cgd 			for (i=0; i<MAXX; i++)
     70  1.1       cgd 				know[i][j]=1;
     71  1.1       cgd chgn: checkgen();	/* wipe out any genocided monsters */
     72  1.1       cgd 	}
     73  1.1       cgd 
     74  1.1       cgd /*
     75  1.1       cgd 	makemaze(level)
     76  1.1       cgd 	int level;
     77  1.1       cgd 
     78  1.1       cgd 	subroutine to make the caverns for a given level.  only walls are made.
     79  1.1       cgd  */
     80  1.1       cgd static int mx,mxl,mxh,my,myl,myh,tmp2;
     81  1.1       cgd  makemaze(k)
     82  1.1       cgd 	int k;
     83  1.1       cgd 	{
     84  1.1       cgd 	register int i,j,tmp;
     85  1.1       cgd 	int z;
     86  1.1       cgd 	if (k > 1 && (rnd(17)<=4 || k==MAXLEVEL-1 || k==MAXLEVEL+MAXVLEVEL-1))
     87  1.1       cgd 		{
     88  1.1       cgd 		if (cannedlevel(k));	return;		/* read maze from data file */
     89  1.1       cgd 		}
     90  1.1       cgd 	if (k==0)  tmp=0;  else tmp=OWALL;
     91  1.1       cgd 	for (i=0; i<MAXY; i++)	for (j=0; j<MAXX; j++)	item[j][i]=tmp;
     92  1.1       cgd 	if (k==0) return;		eat(1,1);
     93  1.1       cgd 	if (k==1) item[33][MAXY-1]=0;	/* exit from dungeon */
     94  1.1       cgd 
     95  1.1       cgd /*	now for open spaces -- not on level 10	*/
     96  1.1       cgd 	if (k != MAXLEVEL-1)
     97  1.1       cgd 		{
     98  1.1       cgd 		tmp2 = rnd(3)+3;
     99  1.1       cgd 		for (tmp=0; tmp<tmp2; tmp++)
    100  1.1       cgd 			{
    101  1.1       cgd 			my = rnd(11)+2;   myl = my - rnd(2);  myh = my + rnd(2);
    102  1.1       cgd 			if (k < MAXLEVEL)
    103  1.1       cgd 				{
    104  1.1       cgd 				mx = rnd(44)+5;  mxl = mx - rnd(4);  mxh = mx + rnd(12)+3;
    105  1.1       cgd 				z=0;
    106  1.1       cgd 				}
    107  1.1       cgd 		  	else
    108  1.1       cgd 				{
    109  1.1       cgd 				mx = rnd(60)+3;  mxl = mx - rnd(2);  mxh = mx + rnd(2);
    110  1.1       cgd 				z = makemonst(k);
    111  1.1       cgd 				}
    112  1.1       cgd 			for (i=mxl; i<mxh; i++)		for (j=myl; j<myh; j++)
    113  1.1       cgd 				{  item[i][j]=0;
    114  1.1       cgd 				   if ((mitem[i][j]=z)) hitp[i][j]=monster[z].hitpoints;
    115  1.1       cgd 				}
    116  1.1       cgd 			}
    117  1.1       cgd 		}
    118  1.1       cgd 	if (k!=MAXLEVEL-1) { my=rnd(MAXY-2);  for (i=1; i<MAXX-1; i++)	item[i][my] = 0; }
    119  1.1       cgd 	if (k>1)  treasureroom(k);
    120  1.1       cgd 	}
    121  1.1       cgd 
    122  1.1       cgd /*
    123  1.1       cgd 	function to eat away a filled in maze
    124  1.1       cgd  */
    125  1.1       cgd eat(xx,yy)
    126  1.1       cgd 	register int xx,yy;
    127  1.1       cgd 	{
    128  1.1       cgd 	register int dir,try;
    129  1.1       cgd 	dir = rnd(4);	try=2;
    130  1.1       cgd 	while (try)
    131  1.1       cgd 		{
    132  1.1       cgd 		switch(dir)
    133  1.1       cgd 			{
    134  1.1       cgd 			case 1:	if (xx <= 2) break;		/*	west	*/
    135  1.1       cgd 					if ((item[xx-1][yy]!=OWALL) || (item[xx-2][yy]!=OWALL))	break;
    136  1.1       cgd 					item[xx-1][yy] = item[xx-2][yy] = 0;
    137  1.1       cgd 					eat(xx-2,yy);	break;
    138  1.1       cgd 
    139  1.1       cgd 			case 2:	if (xx >= MAXX-3) break;	/*	east	*/
    140  1.1       cgd 					if ((item[xx+1][yy]!=OWALL) || (item[xx+2][yy]!=OWALL))	break;
    141  1.1       cgd 					item[xx+1][yy] = item[xx+2][yy] = 0;
    142  1.1       cgd 					eat(xx+2,yy);	break;
    143  1.1       cgd 
    144  1.1       cgd 			case 3:	if (yy <= 2) break;		/*	south	*/
    145  1.1       cgd 					if ((item[xx][yy-1]!=OWALL) || (item[xx][yy-2]!=OWALL))	break;
    146  1.1       cgd 					item[xx][yy-1] = item[xx][yy-2] = 0;
    147  1.1       cgd 					eat(xx,yy-2);	break;
    148  1.1       cgd 
    149  1.1       cgd 			case 4:	if (yy >= MAXY-3 ) break;	/*	north	*/
    150  1.1       cgd 					if ((item[xx][yy+1]!=OWALL) || (item[xx][yy+2]!=OWALL))	break;
    151  1.1       cgd 					item[xx][yy+1] = item[xx][yy+2] = 0;
    152  1.1       cgd 					eat(xx,yy+2);	break;
    153  1.1       cgd 			};
    154  1.1       cgd 		if (++dir > 4)	{ dir=1;  --try; }
    155  1.1       cgd 		}
    156  1.1       cgd 	}
    157  1.1       cgd 
    158  1.1       cgd /*
    159  1.1       cgd  *	function to read in a maze from a data file
    160  1.1       cgd  *
    161  1.1       cgd  *	Format of maze data file:  1st character = # of mazes in file (ascii digit)
    162  1.1       cgd  *				For each maze: 18 lines (1st 17 used) 67 characters per line
    163  1.1       cgd  *
    164  1.1       cgd  *	Special characters in maze data file:
    165  1.1       cgd  *
    166  1.1       cgd  *		#	wall			D	door			.	random monster
    167  1.1       cgd  *		~	eye of larn		!	cure dianthroritis
    168  1.1       cgd  *		-	random object
    169  1.1       cgd  */
    170  1.1       cgd cannedlevel(k)
    171  1.1       cgd 	int k;
    172  1.1       cgd 	{
    173  1.1       cgd 	char *row,*lgetl();
    174  1.1       cgd 	register int i,j;
    175  1.1       cgd 	int it,arg,mit,marg;
    176  1.1       cgd 	if (lopen(larnlevels)<0)
    177  1.1       cgd 		{
    178  1.1       cgd 		write(1,"Can't open the maze data file\n",30);	 died(-282); return(0);
    179  1.1       cgd 		}
    180  1.1       cgd 	i=lgetc();  if (i<='0') { died(-282); return(0); }
    181  1.1       cgd 	for (i=18*rund(i-'0'); i>0; i--)	lgetl();   /* advance to desired maze */
    182  1.1       cgd 	for (i=0; i<MAXY; i++)
    183  1.1       cgd 		{
    184  1.1       cgd 		row = lgetl();
    185  1.1       cgd 		for (j=0; j<MAXX; j++)
    186  1.1       cgd 			{
    187  1.1       cgd 			it = mit = arg = marg = 0;
    188  1.1       cgd 			switch(*row++)
    189  1.1       cgd 				{
    190  1.1       cgd 				case '#': it = OWALL;								break;
    191  1.1       cgd 				case 'D': it = OCLOSEDDOOR;  	arg = rnd(30);		break;
    192  1.1       cgd 				case '~': if (k!=MAXLEVEL-1) break;
    193  1.1       cgd 						  it = OLARNEYE;
    194  1.1       cgd 						  mit = rund(8)+DEMONLORD;
    195  1.1       cgd 						  marg = monster[mit].hitpoints;			break;
    196  1.1       cgd 				case '!': if (k!=MAXLEVEL+MAXVLEVEL-1)  break;
    197  1.1       cgd 						  it = OPOTION;			arg = 21;
    198  1.1       cgd 						  mit = DEMONLORD+7;
    199  1.1       cgd 						  marg = monster[mit].hitpoints;			break;
    200  1.1       cgd 				case '.': if (k<MAXLEVEL)  break;
    201  1.1       cgd 						  mit = makemonst(k+1);
    202  1.1       cgd 						  marg = monster[mit].hitpoints;			break;
    203  1.1       cgd 				case '-': it = newobject(k+1,&arg);					break;
    204  1.1       cgd 				};
    205  1.1       cgd 			item[j][i] = it;		iarg[j][i] = arg;
    206  1.1       cgd 			mitem[j][i] = mit;		hitp[j][i] = marg;
    207  1.1       cgd 
    208  1.1       cgd #if WIZID
    209  1.1       cgd 			know[j][i] = (wizard) ? 1 : 0;
    210  1.1       cgd #else
    211  1.1       cgd 			know[j][i] = 0;
    212  1.1       cgd #endif
    213  1.1       cgd 			}
    214  1.1       cgd 		}
    215  1.1       cgd 	lrclose();
    216  1.1       cgd 	return(1);
    217  1.1       cgd 	}
    218  1.1       cgd 
    219  1.1       cgd /*
    220  1.1       cgd 	function to make a treasure room on a level
    221  1.1       cgd 	level 10's treasure room has the eye in it and demon lords
    222  1.1       cgd 	level V3 has potion of cure dianthroritis and demon prince
    223  1.1       cgd  */
    224  1.1       cgd treasureroom(lv)
    225  1.1       cgd 	register int lv;
    226  1.1       cgd 	{
    227  1.1       cgd 	register int tx,ty,xsize,ysize;
    228  1.1       cgd 
    229  1.1       cgd 	for (tx=1+rnd(10);  tx<MAXX-10;  tx+=10)
    230  1.1       cgd 	  if ( (lv==MAXLEVEL-1) || (lv==MAXLEVEL+MAXVLEVEL-1) || rnd(13)==2)
    231  1.1       cgd 		{
    232  1.1       cgd 		xsize = rnd(6)+3;  	    ysize = rnd(3)+3;
    233  1.1       cgd 		ty = rnd(MAXY-9)+1;  /* upper left corner of room */
    234  1.1       cgd 		if (lv==MAXLEVEL-1 || lv==MAXLEVEL+MAXVLEVEL-1)
    235  1.1       cgd 			troom(lv,xsize,ysize,tx=tx+rnd(MAXX-24),ty,rnd(3)+6);
    236  1.1       cgd 			else troom(lv,xsize,ysize,tx,ty,rnd(9));
    237  1.1       cgd 		}
    238  1.1       cgd 	}
    239  1.1       cgd 
    240  1.1       cgd /*
    241  1.1       cgd  *	subroutine to create a treasure room of any size at a given location
    242  1.1       cgd  *	room is filled with objects and monsters
    243  1.1       cgd  *	the coordinate given is that of the upper left corner of the room
    244  1.1       cgd  */
    245  1.1       cgd troom(lv,xsize,ysize,tx,ty,glyph)
    246  1.1       cgd 	int lv,xsize,ysize,tx,ty,glyph;
    247  1.1       cgd 	{
    248  1.1       cgd 	register int i,j;
    249  1.1       cgd 	int tp1,tp2;
    250  1.1       cgd 	for (j=ty-1; j<=ty+ysize; j++)
    251  1.1       cgd 		for (i=tx-1; i<=tx+xsize; i++)			/* clear out space for room */
    252  1.1       cgd 			item[i][j]=0;
    253  1.1       cgd 	for (j=ty; j<ty+ysize; j++)
    254  1.1       cgd 		for (i=tx; i<tx+xsize; i++)				/* now put in the walls */
    255  1.1       cgd 			{
    256  1.1       cgd 			item[i][j]=OWALL; mitem[i][j]=0;
    257  1.1       cgd 			}
    258  1.1       cgd 	for (j=ty+1; j<ty+ysize-1; j++)
    259  1.1       cgd 		for (i=tx+1; i<tx+xsize-1; i++)			/* now clear out interior */
    260  1.1       cgd 			item[i][j]=0;
    261  1.1       cgd 
    262  1.1       cgd 	switch(rnd(2))		/* locate the door on the treasure room */
    263  1.1       cgd 		{
    264  1.1       cgd 		case 1:	item[i=tx+rund(xsize)][j=ty+(ysize-1)*rund(2)]=OCLOSEDDOOR;
    265  1.1       cgd 				iarg[i][j] = glyph;		/* on horizontal walls */
    266  1.1       cgd 				break;
    267  1.1       cgd 		case 2: item[i=tx+(xsize-1)*rund(2)][j=ty+rund(ysize)]=OCLOSEDDOOR;
    268  1.1       cgd 				iarg[i][j] = glyph;		/* on vertical walls */
    269  1.1       cgd 				break;
    270  1.1       cgd 		};
    271  1.1       cgd 
    272  1.1       cgd 	tp1=playerx;  tp2=playery;  playery=ty+(ysize>>1);
    273  1.1       cgd 	if (c[HARDGAME]<2)
    274  1.1       cgd 		for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2)
    275  1.1       cgd 			for (i=0, j=rnd(6); i<=j; i++)
    276  1.1       cgd 				{ something(lv+2); createmonster(makemonst(lv+1)); }
    277  1.1       cgd 	else
    278  1.1       cgd 		for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2)
    279  1.1       cgd 			for (i=0, j=rnd(4); i<=j; i++)
    280  1.1       cgd 				{ something(lv+2); createmonster(makemonst(lv+3)); }
    281  1.1       cgd 
    282  1.1       cgd 	playerx=tp1;  playery=tp2;
    283  1.1       cgd 	}
    284  1.1       cgd 
    285  1.1       cgd static void fillroom();
    287  1.1       cgd 
    288  1.1       cgd /*
    289  1.1       cgd 	***********
    290  1.1       cgd 	MAKE_OBJECT
    291  1.1       cgd 	***********
    292  1.1       cgd 	subroutine to create the objects in the maze for the given level
    293  1.1       cgd  */
    294  1.1       cgd makeobject(j)
    295  1.1       cgd 	register int j;
    296  1.1       cgd 	{
    297  1.1       cgd 	register int i;
    298  1.1       cgd 	if (j==0)
    299  1.1       cgd 		{
    300  1.1       cgd 		fillroom(OENTRANCE,0);		/*	entrance to dungeon			*/
    301  1.1       cgd 		fillroom(ODNDSTORE,0);		/*	the DND STORE				*/
    302  1.1       cgd 		fillroom(OSCHOOL,0);		/*	college of Larn				*/
    303  1.1       cgd 		fillroom(OBANK,0);			/*	1st national bank of larn 	*/
    304  1.1       cgd 		fillroom(OVOLDOWN,0);		/*	volcano shaft to temple 	*/
    305  1.1       cgd 		fillroom(OHOME,0);			/*	the players home & family 	*/
    306  1.1       cgd 		fillroom(OTRADEPOST,0);		/*  the trading post			*/
    307  1.1       cgd 		fillroom(OLRS,0);			/*  the larn revenue service 	*/
    308  1.1       cgd 		return;
    309  1.1       cgd 		}
    310  1.1       cgd 
    311  1.1       cgd 	if (j==MAXLEVEL) fillroom(OVOLUP,0); /* volcano shaft up from the temple */
    312  1.1       cgd 
    313  1.1       cgd /*	make the fixed objects in the maze STAIRS	*/
    314  1.1       cgd 	if ((j>0) && (j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1))
    315  1.1       cgd 		fillroom(OSTAIRSDOWN,0);
    316  1.1       cgd 	if ((j > 1) && (j != MAXLEVEL))			fillroom(OSTAIRSUP,0);
    317  1.1       cgd 
    318  1.1       cgd /*	make the random objects in the maze		*/
    319  1.1       cgd 
    320  1.1       cgd 	fillmroom(rund(3),OBOOK,j);				fillmroom(rund(3),OALTAR,0);
    321  1.1       cgd 	fillmroom(rund(3),OSTATUE,0);			fillmroom(rund(3),OPIT,0);
    322  1.1       cgd 	fillmroom(rund(3),OFOUNTAIN,0);			fillmroom( rnd(3)-2,OIVTELETRAP,0);
    323  1.1       cgd 	fillmroom(rund(2),OTHRONE,0);			fillmroom(rund(2),OMIRROR,0);
    324  1.1       cgd 	fillmroom(rund(2),OTRAPARROWIV,0);		fillmroom( rnd(3)-2,OIVDARTRAP,0);
    325  1.1       cgd 	fillmroom(rund(3),OCOOKIE,0);
    326  1.1       cgd 	if (j==1) fillmroom(1,OCHEST,j);
    327  1.1       cgd 		else fillmroom(rund(2),OCHEST,j);
    328  1.1       cgd 	if ((j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1))
    329  1.1       cgd 		fillmroom(rund(2),OIVTRAPDOOR,0);
    330  1.1       cgd 	if (j<=10)
    331  1.1       cgd 		{
    332  1.1       cgd 		fillmroom((rund(2)),ODIAMOND,rnd(10*j+1)+10);
    333  1.1       cgd 		fillmroom(rund(2),ORUBY,rnd(6*j+1)+6);
    334  1.1       cgd 		fillmroom(rund(2),OEMERALD,rnd(4*j+1)+4);
    335  1.1       cgd 		fillmroom(rund(2),OSAPPHIRE,rnd(3*j+1)+2);
    336  1.1       cgd 		}
    337  1.1       cgd 	for (i=0; i<rnd(4)+3; i++)
    338  1.1       cgd 		fillroom(OPOTION,newpotion());	/*	make a POTION	*/
    339  1.1       cgd 	for (i=0; i<rnd(5)+3; i++)
    340  1.1       cgd 		fillroom(OSCROLL,newscroll());	/*	make a SCROLL	*/
    341  1.1       cgd 	for (i=0; i<rnd(12)+11; i++)
    342  1.1       cgd 		fillroom(OGOLDPILE,12*rnd(j+1)+(j<<3)+10); /* make GOLD	*/
    343  1.1       cgd 	if (j==5)	fillroom(OBANK2,0);				/*	branch office of the bank */
    344  1.1       cgd 	froom(2,ORING,0);				/* a ring mail 			*/
    345  1.1       cgd 	froom(1,OSTUDLEATHER,0);		/* a studded leather	*/
    346  1.1       cgd 	froom(3,OSPLINT,0);				/* a splint mail		*/
    347  1.1       cgd 	froom(5,OSHIELD,rund(3));		/* a shield				*/
    348  1.1       cgd 	froom(2,OBATTLEAXE,rund(3));	/* a battle axe			*/
    349  1.1       cgd 	froom(5,OLONGSWORD,rund(3));	/* a long sword			*/
    350  1.1       cgd 	froom(5,OFLAIL,rund(3));		/* a flail				*/
    351  1.1       cgd 	froom(4,OREGENRING,rund(3));	/* ring of regeneration */
    352  1.1       cgd 	froom(1,OPROTRING,rund(3));	/* ring of protection	*/
    353  1.1       cgd 	froom(2,OSTRRING,4);   		/* ring of strength + 4 */
    354  1.1       cgd 	froom(7,OSPEAR,rnd(5));		/* a spear				*/
    355  1.1       cgd 	froom(3,OORBOFDRAGON,0);	/* orb of dragon slaying*/
    356  1.1       cgd 	froom(4,OSPIRITSCARAB,0);		/*scarab of negate spirit*/
    357  1.1       cgd 	froom(4,OCUBEofUNDEAD,0);		/* cube of undead control	*/
    358  1.1       cgd 	froom(2,ORINGOFEXTRA,0);	/* ring of extra regen		*/
    359  1.1       cgd 	froom(3,ONOTHEFT,0);			/* device of antitheft 		*/
    360  1.1       cgd 	froom(2,OSWORDofSLASHING,0); /* sword of slashing */
    361  1.1       cgd 	if (c[BESSMANN]==0)
    362  1.1       cgd 		{
    363  1.1       cgd 		froom(4,OHAMMER,0);/*Bessman's flailing hammer*/ c[BESSMANN]=1;
    364  1.1       cgd 		}
    365  1.1       cgd 	if (c[HARDGAME]<3 || (rnd(4)==3))
    366  1.1       cgd 		{
    367  1.1       cgd 		if (j>3)
    368  1.1       cgd 			{
    369  1.1       cgd 			froom(3,OSWORD,3); 		/* sunsword + 3  		*/
    370  1.1       cgd 			froom(5,O2SWORD,rnd(4));  /* a two handed sword	*/
    371  1.1       cgd 			froom(3,OBELT,4);			/* belt of striking		*/
    372  1.1       cgd 			froom(3,OENERGYRING,3);	/* energy ring			*/
    373  1.1       cgd 			froom(4,OPLATE,5);		/* platemail + 5 		*/
    374  1.1       cgd 			}
    375  1.1       cgd 		}
    376  1.1       cgd 	}
    377  1.1       cgd 
    378  1.1       cgd /*
    379  1.1       cgd 	subroutine to fill in a number of objects of the same kind
    380  1.1       cgd  */
    381  1.1       cgd 
    382  1.1       cgd fillmroom(n,what,arg)
    383  1.1       cgd 	int n,arg;
    384  1.1       cgd 	char what;
    385  1.1       cgd 	{
    386  1.1       cgd 	register int i;
    387  1.1       cgd 	for (i=0; i<n; i++)		fillroom(what,arg);
    388  1.1       cgd 	}
    389  1.1       cgd froom(n,itm,arg)
    390  1.1       cgd 	int n,arg;
    391  1.1       cgd 	char itm;
    392  1.1       cgd 	{	if (rnd(151) < n) fillroom(itm,arg);	}
    393  1.1       cgd 
    394  1.1       cgd /*
    395  1.1       cgd 	subroutine to put an object into an empty room
    396  1.1       cgd  *	uses a random walk
    397  1.1       cgd  */
    398  1.1       cgd static void
    399  1.1       cgd fillroom(what,arg)
    400  1.1       cgd 	int arg;
    401  1.1       cgd 	char what;
    402  1.1       cgd 	{
    403  1.1       cgd 	register int x,y;
    404  1.1       cgd 
    405  1.1       cgd #ifdef EXTRA
    406  1.1       cgd 	c[FILLROOM]++;
    407  1.1       cgd #endif
    408  1.1       cgd 
    409  1.1       cgd 	x=rnd(MAXX-2);  y=rnd(MAXY-2);
    410  1.1       cgd 	while (item[x][y])
    411  1.1       cgd 		{
    412  1.1       cgd 
    413  1.1       cgd #ifdef EXTRA
    414  1.1       cgd 		c[RANDOMWALK]++;	/* count up these random walks */
    415  1.1       cgd #endif
    416  1.1       cgd 
    417  1.1       cgd 		x += rnd(3)-2;		y += rnd(3)-2;
    418  1.1       cgd 		if (x > MAXX-2)  x=1;		if (x < 1)  x=MAXX-2;
    419  1.1       cgd 		if (y > MAXY-2)  y=1;		if (y < 1)  y=MAXY-2;
    420  1.1       cgd 		}
    421  1.1       cgd 	item[x][y]=what;		iarg[x][y]=arg;
    422  1.1       cgd 	}
    423  1.1       cgd 
    424  1.1       cgd /*
    425  1.1       cgd 	subroutine to put monsters into an empty room without walls or other
    426  1.1       cgd 	monsters
    427  1.1       cgd  */
    428  1.1       cgd fillmonst(what)
    429  1.1       cgd 	char what;
    430  1.1       cgd 	{
    431  1.1       cgd 	register int x,y,trys;
    432  1.1       cgd 	for (trys=5; trys>0; --trys) /* max # of creation attempts */
    433  1.1       cgd 	  {
    434  1.1       cgd 	  x=rnd(MAXX-2);  y=rnd(MAXY-2);
    435  1.1       cgd 	  if ((item[x][y]==0) && (mitem[x][y]==0) && ((playerx!=x) || (playery!=y)))
    436  1.1       cgd 	  	{
    437  1.1       cgd 		mitem[x][y] = what;  know[x][y]=0;
    438  1.1       cgd 		hitp[x][y] = monster[what].hitpoints;  return(0);
    439  1.1       cgd 		}
    440  1.1       cgd 	  }
    441  1.1       cgd 	return(-1); /* creation failure */
    442  1.1       cgd 	}
    443  1.1       cgd 
    444  1.1       cgd /*
    445  1.1       cgd 	creates an entire set of monsters for a level
    446  1.1       cgd 	must be done when entering a new level
    447  1.1       cgd 	if sethp(1) then wipe out old monsters else leave them there
    448  1.1       cgd  */
    449  1.1       cgd sethp(flg)
    450  1.1       cgd 	int flg;
    451  1.1       cgd 	{
    452  1.1       cgd 	register int i,j;
    453  1.1       cgd 	if (flg) for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) stealth[j][i]=0;
    454  1.1       cgd 	if (level==0) { c[TELEFLAG]=0; return; } /*	if teleported and found level 1 then know level we are on */
    455  1.1       cgd 	if (flg)   j = rnd(12) + 2 + (level>>1);   else   j = (level>>1) + 1;
    456  1.1       cgd 	for (i=0; i<j; i++)  fillmonst(makemonst(level));
    457  1.1       cgd 	positionplayer();
    458  1.1       cgd 	}
    459  1.1       cgd 
    460  1.1       cgd /*
    461  1.1       cgd  *	Function to destroy all genocided monsters on the present level
    462  1.1       cgd  */
    463  1.1       cgd checkgen()
    464  1.1       cgd 	{
    465  1.1       cgd 	register int x,y;
    466  1.1       cgd 	for (y=0; y<MAXY; y++)
    467  1.1       cgd 		for (x=0; x<MAXX; x++)
    468  1.1       cgd 			if (monster[mitem[x][y]].genocided)
    469                				mitem[x][y]=0; /* no more monster */
    470                	}
    471