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