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