1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
   2: /* hack.mklev.c - version 1.0.4 */
   3: 
   4: #include "hack.h"
   5: 
   6: extern struct monst *makemon();
   7: extern struct obj *mkobj_at();
   8: extern struct trap *maketrap();
   9: 
  10: #define somex() ((rand()%(croom->hx-croom->lx+1))+croom->lx)
  11: #define somey() ((rand()%(croom->hy-croom->ly+1))+croom->ly)
  12: 
  13: #include "def.mkroom.h"
  14: #define XLIM    4   /* define minimum required space around a room */
  15: #define YLIM    3
  16: boolean secret;     /* TRUE while making a vault: increase [XY]LIM */
  17: struct mkroom rooms[MAXNROFROOMS+1];
  18: int smeq[MAXNROFROOMS+1];
  19: coord doors[DOORMAX];
  20: int doorindex;
  21: struct rm zerorm;
  22: int comp();
  23: schar nxcor;
  24: boolean goldseen;
  25: int nroom;
  26: xchar xdnstair,xupstair,ydnstair,yupstair;
  27: 
  28: /* Definitions used by makerooms() and addrs() */
  29: #define MAXRS   50  /* max lth of temp rectangle table - arbitrary */
  30: struct rectangle {
  31:     xchar rlx,rly,rhx,rhy;
  32: } rs[MAXRS+1];
  33: int rscnt,rsmax;    /* 0..rscnt-1: currently under consideration */
  34:             /* rscnt..rsmax: discarded */
  35: 
  36: makelevel()
  37: {
  38:     register struct mkroom *croom, *troom;
  39:     register unsigned tryct;
  40:     register x,y;
  41: 
  42:     nroom = 0;
  43:     doorindex = 0;
  44:     rooms[0].hx = -1;   /* in case we are in a maze */
  45: 
  46:     for(x=0; x<COLNO; x++) for(y=0; y<ROWNO; y++)
  47:         levl[x][y] = zerorm;
  48: 
  49:     oinit();    /* assign level dependent obj probabilities */
  50: 
  51:     if(dlevel >= rn1(3, 26)) {  /* there might be several mazes */
  52:         makemaz();
  53:         return;
  54:     }
  55: 
  56:     /* construct the rooms */
  57:     nroom = 0;
  58:     secret = FALSE;
  59:     (void) makerooms();
  60: 
  61:     /* construct stairs (up and down in different rooms if possible) */
  62:     croom = &rooms[rn2(nroom)];
  63:     xdnstair = somex();
  64:     ydnstair = somey();
  65:     levl[xdnstair][ydnstair].scrsym ='>';
  66:     levl[xdnstair][ydnstair].typ = STAIRS;
  67:     if(nroom > 1) {
  68:         troom = croom;
  69:         croom = &rooms[rn2(nroom-1)];
  70:         if(croom >= troom) croom++;
  71:     }
  72:     xupstair = somex(); /* %% < and > might be in the same place */
  73:     yupstair = somey();
  74:     levl[xupstair][yupstair].scrsym ='<';
  75:     levl[xupstair][yupstair].typ = STAIRS;
  76: 
  77:     /* for each room: put things inside */
  78:     for(croom = rooms; croom->hx > 0; croom++) {
  79: 
  80:         /* put a sleeping monster inside */
  81:         /* Note: monster may be on the stairs. This cannot be
  82: 		   avoided: maybe the player fell through a trapdoor
  83: 		   while a monster was on the stairs. Conclusion:
  84: 		   we have to check for monsters on the stairs anyway. */
  85:         if(!rn2(3)) (void)
  86:             makemon((struct permonst *) 0, somex(), somey());
  87: 
  88:         /* put traps and mimics inside */
  89:         goldseen = FALSE;
  90:         while(!rn2(8-(dlevel/6))) mktrap(0,0,croom);
  91:         if(!goldseen && !rn2(3)) mkgold(0L,somex(),somey());
  92:         if(!rn2(3)) {
  93:             (void) mkobj_at(0, somex(), somey());
  94:             tryct = 0;
  95:             while(!rn2(5)) {
  96:                 if(++tryct > 100){
  97:                     printf("tryct overflow4\n");
  98:                     break;
  99:                 }
 100:                 (void) mkobj_at(0, somex(), somey());
 101:             }
 102:         }
 103:     }
 104: 
 105:     qsort((char *) rooms, nroom, sizeof(struct mkroom), comp);
 106:     makecorridors();
 107:     make_niches();
 108: 
 109:     /* make a secret treasure vault, not connected to the rest */
 110:     if(nroom <= (2*MAXNROFROOMS/3)) if(rn2(3)) {
 111:         troom = &rooms[nroom];
 112:         secret = TRUE;
 113:         if(makerooms()) {
 114:             troom->rtype = VAULT;       /* treasure vault */
 115:             for(x = troom->lx; x <= troom->hx; x++)
 116:             for(y = troom->ly; y <= troom->hy; y++)
 117:                 mkgold((long)(rnd(dlevel*100) + 50), x, y);
 118:             if(!rn2(3))
 119:                 makevtele();
 120:         }
 121:     }
 122: 
 123: #ifdef WIZARD
 124:     if(wizard && getenv("SHOPTYPE")) mkshop(); else
 125: #endif WIZARD
 126:     if(dlevel > 1 && dlevel < 20 && rn2(dlevel) < 3) mkshop();
 127:     else
 128:     if(dlevel > 6 && !rn2(7)) mkzoo(ZOO);
 129:     else
 130:     if(dlevel > 9 && !rn2(5)) mkzoo(BEEHIVE);
 131:     else
 132:     if(dlevel > 11 && !rn2(6)) mkzoo(MORGUE);
 133:     else
 134:     if(dlevel > 18 && !rn2(6)) mkswamp();
 135: }
 136: 
 137: makerooms() {
 138: register struct rectangle *rsp;
 139: register int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy;
 140: int tryct = 0, xlim, ylim;
 141: 
 142:     /* init */
 143:     xlim = XLIM + secret;
 144:     ylim = YLIM + secret;
 145:     if(nroom == 0) {
 146:         rsp = rs;
 147:         rsp->rlx = rsp->rly = 0;
 148:         rsp->rhx = COLNO-1;
 149:         rsp->rhy = ROWNO-1;
 150:         rsmax = 1;
 151:     }
 152:     rscnt = rsmax;
 153: 
 154:     /* make rooms until satisfied */
 155:     while(rscnt > 0 && nroom < MAXNROFROOMS-1) {
 156:         if(!secret && nroom > (MAXNROFROOMS/3) &&
 157:            !rn2((MAXNROFROOMS-nroom)*(MAXNROFROOMS-nroom)))
 158:             return(0);
 159: 
 160:         /* pick a rectangle */
 161:         rsp = &rs[rn2(rscnt)];
 162:         hx = rsp->rhx;
 163:         hy = rsp->rhy;
 164:         lx = rsp->rlx;
 165:         ly = rsp->rly;
 166: 
 167:         /* find size of room */
 168:         if(secret)
 169:             dx = dy = 1;
 170:         else {
 171:             dx = 2 + rn2((hx-lx-8 > 20) ? 12 : 8);
 172:             dy = 2 + rn2(4);
 173:             if(dx*dy > 50)
 174:                 dy = 50/dx;
 175:         }
 176: 
 177:         /* look whether our room will fit */
 178:         if(hx-lx < dx + dx/2 + 2*xlim || hy-ly < dy + dy/3 + 2*ylim) {
 179:                     /* no, too small */
 180:                     /* maybe we throw this area out */
 181:             if(secret || !rn2(MAXNROFROOMS+1-nroom-tryct)) {
 182:                 rscnt--;
 183:                 rs[rsmax] = *rsp;
 184:                 *rsp = rs[rscnt];
 185:                 rs[rscnt] = rs[rsmax];
 186:                 tryct = 0;
 187:             } else
 188:                 tryct++;
 189:             continue;
 190:         }
 191: 
 192:         lowx = lx + xlim + rn2(hx - lx - dx - 2*xlim + 1);
 193:         lowy = ly + ylim + rn2(hy - ly - dy - 2*ylim + 1);
 194:         hix = lowx + dx;
 195:         hiy = lowy + dy;
 196: 
 197:         if(maker(lowx, dx, lowy, dy)) {
 198:             if(secret)
 199:                 return(1);
 200:             addrs(lowx-1, lowy-1, hix+1, hiy+1);
 201:             tryct = 0;
 202:         } else
 203:             if(tryct++ > 100)
 204:                 break;
 205:     }
 206:     return(0);  /* failed to make vault - very strange */
 207: }
 208: 
 209: addrs(lowx,lowy,hix,hiy)
 210: register int lowx,lowy,hix,hiy;
 211: {
 212:     register struct rectangle *rsp;
 213:     register int lx,ly,hx,hy,xlim,ylim;
 214:     boolean discarded;
 215: 
 216:     xlim = XLIM + secret;
 217:     ylim = YLIM + secret;
 218: 
 219:     /* walk down since rscnt and rsmax change */
 220:     for(rsp = &rs[rsmax-1]; rsp >= rs; rsp--) {
 221: 
 222:         if((lx = rsp->rlx) > hix || (ly = rsp->rly) > hiy ||
 223:            (hx = rsp->rhx) < lowx || (hy = rsp->rhy) < lowy)
 224:             continue;
 225:         if((discarded = (rsp >= &rs[rscnt]))) {
 226:             *rsp = rs[--rsmax];
 227:         } else {
 228:             rsmax--;
 229:             rscnt--;
 230:             *rsp = rs[rscnt];
 231:             if(rscnt != rsmax)
 232:                 rs[rscnt] = rs[rsmax];
 233:         }
 234:         if(lowy - ly > 2*ylim + 4)
 235:             addrsx(lx,ly,hx,lowy-2,discarded);
 236:         if(lowx - lx > 2*xlim + 4)
 237:             addrsx(lx,ly,lowx-2,hy,discarded);
 238:         if(hy - hiy > 2*ylim + 4)
 239:             addrsx(lx,hiy+2,hx,hy,discarded);
 240:         if(hx - hix > 2*xlim + 4)
 241:             addrsx(hix+2,ly,hx,hy,discarded);
 242:     }
 243: }
 244: 
 245: addrsx(lx,ly,hx,hy,discarded)
 246: register int lx,ly,hx,hy;
 247: boolean discarded;      /* piece of a discarded area */
 248: {
 249:     register struct rectangle *rsp;
 250: 
 251:     /* check inclusions */
 252:     for(rsp = rs; rsp < &rs[rsmax]; rsp++) {
 253:         if(lx >= rsp->rlx && hx <= rsp->rhx &&
 254:            ly >= rsp->rly && hy <= rsp->rhy)
 255:             return;
 256:     }
 257: 
 258:     /* make a new entry */
 259:     if(rsmax >= MAXRS) {
 260: #ifdef WIZARD
 261:         if(wizard) pline("MAXRS may be too small.");
 262: #endif WIZARD
 263:         return;
 264:     }
 265:     rsmax++;
 266:     if(!discarded) {
 267:         *rsp = rs[rscnt];
 268:         rsp = &rs[rscnt];
 269:         rscnt++;
 270:     }
 271:     rsp->rlx = lx;
 272:     rsp->rly = ly;
 273:     rsp->rhx = hx;
 274:     rsp->rhy = hy;
 275: }
 276: 
 277: comp(x,y)
 278: register struct mkroom *x,*y;
 279: {
 280:     if(x->lx < y->lx) return(-1);
 281:     return(x->lx > y->lx);
 282: }
 283: 
 284: coord
 285: finddpos(xl,yl,xh,yh) {
 286:     coord ff;
 287:     register x,y;
 288: 
 289:     x = (xl == xh) ? xl : (xl + rn2(xh-xl+1));
 290:     y = (yl == yh) ? yl : (yl + rn2(yh-yl+1));
 291:     if(okdoor(x, y))
 292:         goto gotit;
 293: 
 294:     for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++)
 295:         if(okdoor(x, y))
 296:             goto gotit;
 297: 
 298:     for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++)
 299:         if(levl[x][y].typ == DOOR || levl[x][y].typ == SDOOR)
 300:             goto gotit;
 301:     /* cannot find something reasonable -- strange */
 302:     x = xl;
 303:     y = yh;
 304: gotit:
 305:     ff.x = x;
 306:     ff.y = y;
 307:     return(ff);
 308: }
 309: 
 310: /* see whether it is allowable to create a door at [x,y] */
 311: okdoor(x,y)
 312: register x,y;
 313: {
 314:     if(levl[x-1][y].typ == DOOR || levl[x+1][y].typ == DOOR ||
 315:        levl[x][y+1].typ == DOOR || levl[x][y-1].typ == DOOR ||
 316:        levl[x-1][y].typ == SDOOR || levl[x+1][y].typ == SDOOR ||
 317:        levl[x][y-1].typ == SDOOR || levl[x][y+1].typ == SDOOR ||
 318:        (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) ||
 319:        doorindex >= DOORMAX)
 320:         return(0);
 321:     return(1);
 322: }
 323: 
 324: dodoor(x,y,aroom)
 325: register x,y;
 326: register struct mkroom *aroom;
 327: {
 328:     if(doorindex >= DOORMAX) {
 329:         impossible("DOORMAX exceeded?");
 330:         return;
 331:     }
 332:     if(!okdoor(x,y) && nxcor)
 333:         return;
 334:     dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR);
 335: }
 336: 
 337: dosdoor(x,y,aroom,type)
 338: register x,y;
 339: register struct mkroom *aroom;
 340: register type;
 341: {
 342:     register struct mkroom *broom;
 343:     register tmp;
 344: 
 345:     if(!IS_WALL(levl[x][y].typ))    /* avoid SDOORs with '+' as scrsym */
 346:         type = DOOR;
 347:     levl[x][y].typ = type;
 348:     if(type == DOOR)
 349:         levl[x][y].scrsym = '+';
 350:     aroom->doorct++;
 351:     broom = aroom+1;
 352:     if(broom->hx < 0) tmp = doorindex; else
 353: for(tmp = doorindex; tmp > broom->fdoor; tmp--)
 354:         doors[tmp] = doors[tmp-1];
 355:     doorindex++;
 356:     doors[tmp].x = x;
 357:     doors[tmp].y = y;
 358:     for( ; broom->hx >= 0; broom++) broom->fdoor++;
 359: }
 360: 
 361: /* Only called from makerooms() */
 362: maker(lowx,ddx,lowy,ddy)
 363: schar lowx,ddx,lowy,ddy;
 364: {
 365:     register struct mkroom *croom;
 366:     register x, y, hix = lowx+ddx, hiy = lowy+ddy;
 367:     register xlim = XLIM + secret, ylim = YLIM + secret;
 368: 
 369:     if(nroom >= MAXNROFROOMS) return(0);
 370:     if(lowx < XLIM) lowx = XLIM;
 371:     if(lowy < YLIM) lowy = YLIM;
 372:     if(hix > COLNO-XLIM-1) hix = COLNO-XLIM-1;
 373:     if(hiy > ROWNO-YLIM-1) hiy = ROWNO-YLIM-1;
 374: chk:
 375:     if(hix <= lowx || hiy <= lowy) return(0);
 376: 
 377:     /* check area around room (and make room smaller if necessary) */
 378:     for(x = lowx - xlim; x <= hix + xlim; x++) {
 379:         for(y = lowy - ylim; y <= hiy + ylim; y++) {
 380:             if(levl[x][y].typ) {
 381: #ifdef WIZARD
 382:                 if(wizard && !secret)
 383:                 pline("Strange area [%d,%d] in maker().",x,y);
 384: #endif WIZARD
 385:                 if(!rn2(3)) return(0);
 386:                 if(x < lowx)
 387:                     lowx = x+xlim+1;
 388:                 else
 389:                     hix = x-xlim-1;
 390:                 if(y < lowy)
 391:                     lowy = y+ylim+1;
 392:                 else
 393:                     hiy = y-ylim-1;
 394:                 goto chk;
 395:             }
 396:         }
 397:     }
 398: 
 399:     croom = &rooms[nroom];
 400: 
 401:     /* on low levels the room is lit (usually) */
 402:     /* secret vaults are always lit */
 403:     if((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1)) {
 404:         for(x = lowx-1; x <= hix+1; x++)
 405:             for(y = lowy-1; y <= hiy+1; y++)
 406:                 levl[x][y].lit = 1;
 407:         croom->rlit = 1;
 408:     } else
 409:         croom->rlit = 0;
 410:     croom->lx = lowx;
 411:     croom->hx = hix;
 412:     croom->ly = lowy;
 413:     croom->hy = hiy;
 414:     croom->rtype = croom->doorct = croom->fdoor = 0;
 415: 
 416:     for(x = lowx-1; x <= hix+1; x++)
 417:         for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
 418:         levl[x][y].scrsym = '-';
 419:         levl[x][y].typ = HWALL;
 420:     }
 421:     for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
 422:         for(y = lowy; y <= hiy; y++) {
 423:         levl[x][y].scrsym = '|';
 424:         levl[x][y].typ = VWALL;
 425:     }
 426:     for(x = lowx; x <= hix; x++)
 427:         for(y = lowy; y <= hiy; y++) {
 428:         levl[x][y].scrsym = '.';
 429:         levl[x][y].typ = ROOM;
 430:     }
 431: 
 432:     smeq[nroom] = nroom;
 433:     croom++;
 434:     croom->hx = -1;
 435:     nroom++;
 436:     return(1);
 437: }
 438: 
 439: makecorridors() {
 440:     register a,b;
 441: 
 442:     nxcor = 0;
 443:     for(a = 0; a < nroom-1; a++)
 444:         join(a, a+1);
 445:     for(a = 0; a < nroom-2; a++)
 446:         if(smeq[a] != smeq[a+2])
 447:         join(a, a+2);
 448:     for(a = 0; a < nroom; a++)
 449:         for(b = 0; b < nroom; b++)
 450:         if(smeq[a] != smeq[b])
 451:             join(a, b);
 452:     if(nroom > 2)
 453:         for(nxcor = rn2(nroom) + 4; nxcor; nxcor--) {
 454:         a = rn2(nroom);
 455:         b = rn2(nroom-2);
 456:         if(b >= a) b += 2;
 457:         join(a, b);
 458:         }
 459: }
 460: 
 461: join(a,b)
 462: register a,b;
 463: {
 464:     coord cc,tt;
 465:     register tx, ty, xx, yy;
 466:     register struct rm *crm;
 467:     register struct mkroom *croom, *troom;
 468:     register dx, dy, dix, diy, cct;
 469: 
 470:     croom = &rooms[a];
 471:     troom = &rooms[b];
 472: 
 473:     /* find positions cc and tt for doors in croom and troom
 474: 	   and direction for a corridor between them */
 475: 
 476:     if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return;
 477:     if(troom->lx > croom->hx) {
 478:         dx = 1;
 479:         dy = 0;
 480:         xx = croom->hx+1;
 481:         tx = troom->lx-1;
 482:         cc = finddpos(xx,croom->ly,xx,croom->hy);
 483:         tt = finddpos(tx,troom->ly,tx,troom->hy);
 484:     } else if(troom->hy < croom->ly) {
 485:         dy = -1;
 486:         dx = 0;
 487:         yy = croom->ly-1;
 488:         cc = finddpos(croom->lx,yy,croom->hx,yy);
 489:         ty = troom->hy+1;
 490:         tt = finddpos(troom->lx,ty,troom->hx,ty);
 491:     } else if(troom->hx < croom->lx) {
 492:         dx = -1;
 493:         dy = 0;
 494:         xx = croom->lx-1;
 495:         tx = troom->hx+1;
 496:         cc = finddpos(xx,croom->ly,xx,croom->hy);
 497:         tt = finddpos(tx,troom->ly,tx,troom->hy);
 498:     } else {
 499:         dy = 1;
 500:         dx = 0;
 501:         yy = croom->hy+1;
 502:         ty = troom->ly-1;
 503:         cc = finddpos(croom->lx,yy,croom->hx,yy);
 504:         tt = finddpos(troom->lx,ty,troom->hx,ty);
 505:     }
 506:     xx = cc.x;
 507:     yy = cc.y;
 508:     tx = tt.x - dx;
 509:     ty = tt.y - dy;
 510:     if(nxcor && levl[xx+dx][yy+dy].typ)
 511:         return;
 512:     dodoor(xx,yy,croom);
 513: 
 514:     cct = 0;
 515:     while(xx != tx || yy != ty) {
 516:         xx += dx;
 517:         yy += dy;
 518: 
 519:         /* loop: dig corridor at [xx,yy] and find new [xx,yy] */
 520:         if(cct++ > 500 || (nxcor && !rn2(35)))
 521:         return;
 522: 
 523:         if(xx == COLNO-1 || xx == 0 || yy == 0 || yy == ROWNO-1)
 524:         return;     /* impossible */
 525: 
 526:         crm = &levl[xx][yy];
 527:         if(!(crm->typ)) {
 528:         if(rn2(100)) {
 529:             crm->typ = CORR;
 530:             crm->scrsym = CORR_SYM;
 531:             if(nxcor && !rn2(50))
 532:                 (void) mkobj_at(ROCK_SYM, xx, yy);
 533:         } else {
 534:             crm->typ = SCORR;
 535:             crm->scrsym = ' ';
 536:         }
 537:         } else
 538:         if(crm->typ != CORR && crm->typ != SCORR) {
 539:         /* strange ... */
 540:         return;
 541:         }
 542: 
 543:         /* find next corridor position */
 544:         dix = abs(xx-tx);
 545:         diy = abs(yy-ty);
 546: 
 547:         /* do we have to change direction ? */
 548:         if(dy && dix > diy) {
 549:         register ddx = (xx > tx) ? -1 : 1;
 550: 
 551:         crm = &levl[xx+ddx][yy];
 552:         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) {
 553:             dx = ddx;
 554:             dy = 0;
 555:             continue;
 556:         }
 557:         } else if(dx && diy > dix) {
 558:         register ddy = (yy > ty) ? -1 : 1;
 559: 
 560:         crm = &levl[xx][yy+ddy];
 561:         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) {
 562:             dy = ddy;
 563:             dx = 0;
 564:             continue;
 565:         }
 566:         }
 567: 
 568:         /* continue straight on? */
 569:         crm = &levl[xx+dx][yy+dy];
 570:         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
 571:         continue;
 572: 
 573:         /* no, what must we do now?? */
 574:         if(dx) {
 575:         dx = 0;
 576:         dy = (ty < yy) ? -1 : 1;
 577:         crm = &levl[xx+dx][yy+dy];
 578:         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
 579:             continue;
 580:         dy = -dy;
 581:         continue;
 582:         } else {
 583:         dy = 0;
 584:         dx = (tx < xx) ? -1 : 1;
 585:         crm = &levl[xx+dx][yy+dy];
 586:         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
 587:             continue;
 588:         dx = -dx;
 589:         continue;
 590:         }
 591:     }
 592: 
 593:     /* we succeeded in digging the corridor */
 594:     dodoor(tt.x, tt.y, troom);
 595: 
 596:     if(smeq[a] < smeq[b])
 597:         smeq[b] = smeq[a];
 598:     else
 599:         smeq[a] = smeq[b];
 600: }
 601: 
 602: make_niches()
 603: {
 604:     register int ct = rnd(nroom/2 + 1);
 605:     while(ct--) makeniche(FALSE);
 606: }
 607: 
 608: makevtele()
 609: {
 610:     makeniche(TRUE);
 611: }
 612: 
 613: makeniche(with_trap)
 614: boolean with_trap;
 615: {
 616:     register struct mkroom *aroom;
 617:     register struct rm *rm;
 618:     register int vct = 8;
 619:     coord dd;
 620:     register dy,xx,yy;
 621:     register struct trap *ttmp;
 622: 
 623:     if(doorindex < DOORMAX)
 624:       while(vct--) {
 625:         aroom = &rooms[rn2(nroom-1)];
 626:         if(aroom->rtype != 0) continue; /* not an ordinary room */
 627:         if(aroom->doorct == 1 && rn2(5)) continue;
 628:         if(rn2(2)) {
 629:         dy = 1;
 630:         dd = finddpos(aroom->lx,aroom->hy+1,aroom->hx,aroom->hy+1);
 631:         } else {
 632:         dy = -1;
 633:         dd = finddpos(aroom->lx,aroom->ly-1,aroom->hx,aroom->ly-1);
 634:         }
 635:         xx = dd.x;
 636:         yy = dd.y;
 637:         if((rm = &levl[xx][yy+dy])->typ) continue;
 638:         if(with_trap || !rn2(4)) {
 639:         rm->typ = SCORR;
 640:         rm->scrsym = ' ';
 641:         if(with_trap) {
 642:             ttmp = maketrap(xx, yy+dy, TELEP_TRAP);
 643:             ttmp->once = 1;
 644:             make_engr_at(xx, yy-dy, "ad ae?ar um");
 645:         }
 646:         dosdoor(xx, yy, aroom, SDOOR);
 647:         } else {
 648:         rm->typ = CORR;
 649:         rm->scrsym = CORR_SYM;
 650:         if(rn2(7))
 651:             dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR);
 652:         else {
 653:             mksobj_at(SCR_TELEPORTATION, xx, yy+dy);
 654:             if(!rn2(3)) (void) mkobj_at(0, xx, yy+dy);
 655:         }
 656:         }
 657:         return;
 658:     }
 659: }
 660: 
 661: /* make a trap somewhere (in croom if mazeflag = 0) */
 662: mktrap(num,mazeflag,croom)
 663: register num,mazeflag;
 664: register struct mkroom *croom;
 665: {
 666:     register struct trap *ttmp;
 667:     register int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0;
 668:     register xchar mx,my;
 669:     extern char fut_geno[];
 670: 
 671:     if(!num || num >= TRAPNUM) {
 672:         nopierc = (dlevel < 4) ? 1 : 0;
 673:         nomimic = (dlevel < 9 || goldseen ) ? 1 : 0;
 674:         if(index(fut_geno, 'M')) nomimic = 1;
 675:         kind = rn2(TRAPNUM - nopierc - nomimic);
 676:         /* note: PIERC = 7, MIMIC = 8, TRAPNUM = 9 */
 677:     } else kind = num;
 678: 
 679:     if(kind == MIMIC) {
 680:         register struct monst *mtmp;
 681: 
 682:         fakedoor = (!rn2(3) && !mazeflag);
 683:         fakegold = (!fakedoor && !rn2(2));
 684:         if(fakegold) goldseen = TRUE;
 685:         do {
 686:             if(++tryct > 200) return;
 687:             if(fakedoor) {
 688:                 /* note: fakedoor maybe on actual door */
 689:                 if(rn2(2)){
 690:                     if(rn2(2))
 691:                         mx = croom->hx+1;
 692:                     else mx = croom->lx-1;
 693:                     my = somey();
 694:                 } else {
 695:                     if(rn2(2))
 696:                         my = croom->hy+1;
 697:                     else my = croom->ly-1;
 698:                     mx = somex();
 699:                 }
 700:             } else if(mazeflag) {
 701:                 extern coord mazexy();
 702:                 coord mm;
 703:                 mm = mazexy();
 704:                 mx = mm.x;
 705:                 my = mm.y;
 706:             } else {
 707:                 mx = somex();
 708:                 my = somey();
 709:             }
 710:         } while(m_at(mx,my) || levl[mx][my].typ == STAIRS);
 711:         if(mtmp = makemon(PM_MIMIC,mx,my)) {
 712:             mtmp->mimic = 1;
 713:             mtmp->mappearance =
 714:             fakegold ? '$' : fakedoor ? '+' :
 715:             (mazeflag && rn2(2)) ? AMULET_SYM :
 716:             "=/)%?![<>" [ rn2(9) ];
 717:         }
 718:         return;
 719:     }
 720: 
 721:     do {
 722:         if(++tryct > 200)
 723:             return;
 724:         if(mazeflag){
 725:             extern coord mazexy();
 726:             coord mm;
 727:             mm = mazexy();
 728:             mx = mm.x;
 729:             my = mm.y;
 730:         } else {
 731:             mx = somex();
 732:             my = somey();
 733:         }
 734:     } while(t_at(mx, my) || levl[mx][my].typ == STAIRS);
 735:     ttmp = maketrap(mx, my, kind);
 736:     if(mazeflag && !rn2(10) && ttmp->ttyp < PIERC)
 737:         ttmp->tseen = 1;
 738: }

Defined functions

addrs defined in line 209; used 1 times
addrsx defined in line 245; used 4 times
comp defined in line 277; used 2 times
dodoor defined in line 324; used 2 times
dosdoor defined in line 337; used 3 times
finddpos defined in line 284; used 10 times
join defined in line 461; used 4 times
make_niches defined in line 602; used 1 times
makecorridors defined in line 439; used 1 times
makelevel defined in line 36; used 1 times
makeniche defined in line 613; used 2 times
maker defined in line 362; used 1 times
makerooms defined in line 137; used 2 times
makevtele defined in line 608; used 1 times
mktrap defined in line 662; used 2 times
okdoor defined in line 311; used 3 times

Defined variables

doorindex defined in line 20; used 8 times
goldseen defined in line 24; used 4 times
nroom defined in line 25; used 34 times
nxcor defined in line 23; used 8 times
rooms defined in line 17; used 10 times
rs defined in line 32; used 17 times
rscnt defined in line 33; used 14 times
rsmax defined in line 33; used 12 times
secret defined in line 16; used 13 times
smeq defined in line 18; used 11 times
zerorm defined in line 21; used 1 times
  • in line 47

Defined struct's

rectangle defined in line 30; used 6 times

Defined macros

MAXRS defined in line 29; used 2 times
XLIM defined in line 14; used 7 times
YLIM defined in line 15; used 7 times
somex defined in line 10; used 9 times
somey defined in line 11; used 9 times
Last modified: 1997-10-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 4647
Valid CSS Valid XHTML 1.0 Strict