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