1 /* $OpenBSD: hack.pri.c,v 1.4 2001/08/06 22:59:13 pjanzen Exp $ */ 2 3 /* 4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. 5 */ 6 7 #ifndef lint 8 static char rcsid[] = "$OpenBSD: hack.pri.c,v 1.4 2001/08/06 22:59:13 pjanzen Exp $"; 9 #endif /* not lint */ 10 11 #include "hack.h" 12 #include <stdio.h> 13 xchar scrlx, scrhx, scrly, scrhy; /* corners of new area on screen */ 14 15 extern char *hu_stat[]; /* in eat.c */ 16 extern char *CD; 17 18 swallowed() 19 { 20 char ulook[] = "|@|"; 21 ulook[1] = u.usym; 22 23 cls(); 24 curs(u.ux-1, u.uy+1); 25 fputs("/-\\", stdout); 26 curx = u.ux+2; 27 curs(u.ux-1, u.uy+2); 28 fputs(ulook, stdout); 29 curx = u.ux+2; 30 curs(u.ux-1, u.uy+3); 31 fputs("\\-/", stdout); 32 curx = u.ux+2; 33 u.udispl = 1; 34 u.udisx = u.ux; 35 u.udisy = u.uy; 36 } 37 38 39 /*VARARGS1*/ 40 boolean panicking; 41 42 panic(str,a1,a2,a3,a4,a5,a6) 43 char *str; 44 { 45 if(panicking++) exit(1); /* avoid loops - this should never happen*/ 46 home(); 47 puts(" Suddenly, the dungeon collapses."); 48 fputs(" ERROR: ", stdout); 49 printf(str,a1,a2,a3,a4,a5,a6); 50 #ifdef DEBUG 51 #ifdef UNIX 52 if(!fork()) 53 abort(); /* generate core dump */ 54 #endif /* UNIX */ 55 #endif /* DEBUG */ 56 more(); /* contains a fflush() */ 57 done("panicked"); 58 } 59 60 atl(x,y,ch) 61 register x,y; 62 { 63 register struct rm *crm = &levl[x][y]; 64 65 if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){ 66 impossible("atl(%d,%d,%c)",x,y,ch); 67 return; 68 } 69 if(crm->seen && crm->scrsym == ch) return; 70 crm->scrsym = ch; 71 crm->new = 1; 72 on_scr(x,y); 73 } 74 75 on_scr(x,y) 76 register x,y; 77 { 78 if(x < scrlx) scrlx = x; 79 if(x > scrhx) scrhx = x; 80 if(y < scrly) scrly = y; 81 if(y > scrhy) scrhy = y; 82 } 83 84 /* call: (x,y) - display 85 (-1,0) - close (leave last symbol) 86 (-1,-1)- close (undo last symbol) 87 (-1,let)-open: initialize symbol 88 (-2,let)-change let 89 */ 90 91 tmp_at(x,y) schar x,y; { 92 static schar prevx, prevy; 93 static char let; 94 if((int)x == -2){ /* change let call */ 95 let = y; 96 return; 97 } 98 if((int)x == -1 && (int)y >= 0){ /* open or close call */ 99 let = y; 100 prevx = -1; 101 return; 102 } 103 if(prevx >= 0 && cansee(prevx,prevy)) { 104 delay_output(50); 105 prl(prevx, prevy); /* in case there was a monster */ 106 at(prevx, prevy, levl[prevx][prevy].scrsym); 107 } 108 if(x >= 0){ /* normal call */ 109 if(cansee(x,y)) at(x,y,let); 110 prevx = x; 111 prevy = y; 112 } else { /* close call */ 113 let = 0; 114 prevx = -1; 115 } 116 } 117 118 /* like the previous, but the symbols are first erased on completion */ 119 Tmp_at(x,y) schar x,y; { 120 static char let; 121 static xchar cnt; 122 static coord tc[COLNO]; /* but watch reflecting beams! */ 123 register xx,yy; 124 if((int)x == -1) { 125 if(y > 0) { /* open call */ 126 let = y; 127 cnt = 0; 128 return; 129 } 130 /* close call (do not distinguish y==0 and y==-1) */ 131 while(cnt--) { 132 xx = tc[cnt].x; 133 yy = tc[cnt].y; 134 prl(xx, yy); 135 at(xx, yy, levl[xx][yy].scrsym); 136 } 137 cnt = let = 0; /* superfluous */ 138 return; 139 } 140 if((int)x == -2) { /* change let call */ 141 let = y; 142 return; 143 } 144 /* normal call */ 145 if(cansee(x,y)) { 146 if(cnt) delay_output(50); 147 at(x,y,let); 148 tc[cnt].x = x; 149 tc[cnt].y = y; 150 if(++cnt >= COLNO) panic("Tmp_at overflow?"); 151 levl[x][y].new = 0; /* prevent pline-nscr erasing --- */ 152 } 153 } 154 155 setclipped(){ 156 error("Hack needs a screen of size at least %d by %d.\n", 157 ROWNO+2, COLNO); 158 } 159 160 at(x,y,ch) 161 register xchar x,y; 162 char ch; 163 { 164 #ifndef lint 165 /* if xchar is unsigned, lint will complain about if(x < 0) */ 166 if(x < 0 || x > COLNO-1 || y < 0 || y > ROWNO-1) { 167 impossible("At gets 0%o at %d %d.", ch, x, y); 168 return; 169 } 170 #endif /* lint */ 171 if(!ch) { 172 impossible("At gets null at %d %d.", x, y); 173 return; 174 } 175 y += 2; 176 curs(x,y); 177 (void) putchar(ch); 178 curx++; 179 } 180 181 prme(){ 182 if(!Invisible) at(u.ux,u.uy,u.usym); 183 } 184 185 doredraw() 186 { 187 docrt(); 188 return(0); 189 } 190 191 docrt() 192 { 193 register x,y; 194 register struct rm *room; 195 register struct monst *mtmp; 196 197 if(u.uswallow) { 198 swallowed(); 199 return; 200 } 201 cls(); 202 203 /* Some ridiculous code to get display of @ and monsters (almost) right */ 204 if(!Invisible) { 205 levl[(u.udisx = u.ux)][(u.udisy = u.uy)].scrsym = u.usym; 206 levl[u.udisx][u.udisy].seen = 1; 207 u.udispl = 1; 208 } else u.udispl = 0; 209 210 seemons(); /* reset old positions */ 211 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 212 mtmp->mdispl = 0; 213 seemons(); /* force new positions to be shown */ 214 /* This nonsense should disappear soon --------------------------------- */ 215 216 for(y = 0; y < ROWNO; y++) 217 for(x = 0; x < COLNO; x++) 218 if((room = &levl[x][y])->new) { 219 room->new = 0; 220 at(x,y,room->scrsym); 221 } else if(room->seen) 222 at(x,y,room->scrsym); 223 scrlx = COLNO; 224 scrly = ROWNO; 225 scrhx = scrhy = 0; 226 flags.botlx = 1; 227 bot(); 228 } 229 230 docorner(xmin,ymax) register xmin,ymax; { 231 register x,y; 232 register struct rm *room; 233 register struct monst *mtmp; 234 235 if(u.uswallow) { /* Can be done more efficiently */ 236 swallowed(); 237 return; 238 } 239 240 seemons(); /* reset old positions */ 241 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 242 if(mtmp->mx >= xmin && mtmp->my < ymax) 243 mtmp->mdispl = 0; 244 seemons(); /* force new positions to be shown */ 245 246 for(y = 0; y < ymax; y++) { 247 if(y > ROWNO && CD) break; 248 curs(xmin,y+2); 249 cl_end(); 250 if(y < ROWNO) { 251 for(x = xmin; x < COLNO; x++) { 252 if((room = &levl[x][y])->new) { 253 room->new = 0; 254 at(x,y,room->scrsym); 255 } else 256 if(room->seen) 257 at(x,y,room->scrsym); 258 } 259 } 260 } 261 if(ymax > ROWNO) { 262 cornbot(xmin-1); 263 if(ymax > ROWNO+1 && CD) { 264 curs(1,ROWNO+3); 265 cl_eos(); 266 } 267 } 268 } 269 270 curs_on_u(){ 271 curs(u.ux, u.uy+2); 272 } 273 274 pru() 275 { 276 if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy)) 277 /* if(! levl[u.udisx][u.udisy].new) */ 278 if(!vism_at(u.udisx, u.udisy)) 279 newsym(u.udisx, u.udisy); 280 if(Invisible) { 281 u.udispl = 0; 282 prl(u.ux,u.uy); 283 } else 284 if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) { 285 atl(u.ux, u.uy, u.usym); 286 u.udispl = 1; 287 u.udisx = u.ux; 288 u.udisy = u.uy; 289 } 290 levl[u.ux][u.uy].seen = 1; 291 } 292 293 #ifndef NOWORM 294 #include "def.wseg.h" 295 extern struct wseg *m_atseg; 296 #endif /* NOWORM */ 297 298 /* print a position that is visible for @ */ 299 prl(x,y) 300 { 301 register struct rm *room; 302 register struct monst *mtmp; 303 register struct obj *otmp; 304 305 if(x == u.ux && y == u.uy && (!Invisible)) { 306 pru(); 307 return; 308 } 309 if(!isok(x,y)) return; 310 room = &levl[x][y]; 311 if((!room->typ) || 312 (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR)) 313 return; 314 if((mtmp = m_at(x,y)) && !mtmp->mhide && 315 (!mtmp->minvis || See_invisible)) { 316 #ifndef NOWORM 317 if(m_atseg) 318 pwseg(m_atseg); 319 else 320 #endif /* NOWORM */ 321 pmon(mtmp); 322 } 323 else if((otmp = o_at(x,y)) && room->typ != POOL) 324 atl(x,y,otmp->olet); 325 else if(mtmp && (!mtmp->minvis || See_invisible)) { 326 /* must be a hiding monster, but not hiding right now */ 327 /* assume for the moment that long worms do not hide */ 328 pmon(mtmp); 329 } 330 else if(g_at(x,y) && room->typ != POOL) 331 atl(x,y,'$'); 332 else if(!room->seen || room->scrsym == ' ') { 333 room->new = room->seen = 1; 334 newsym(x,y); 335 on_scr(x,y); 336 } 337 room->seen = 1; 338 } 339 340 char 341 news0(x,y) 342 register xchar x,y; 343 { 344 register struct obj *otmp; 345 register struct trap *ttmp; 346 struct rm *room; 347 register char tmp; 348 349 room = &levl[x][y]; 350 if(!room->seen) tmp = ' '; 351 else if(room->typ == POOL) tmp = POOL_SYM; 352 else if(!Blind && (otmp = o_at(x,y))) tmp = otmp->olet; 353 else if(!Blind && g_at(x,y)) tmp = '$'; 354 else if(x == xupstair && y == yupstair) tmp = '<'; 355 else if(x == xdnstair && y == ydnstair) tmp = '>'; 356 else if((ttmp = t_at(x,y)) && ttmp->tseen) tmp = '^'; 357 else switch(room->typ) { 358 case SCORR: 359 case SDOOR: 360 tmp = room->scrsym; /* %% wrong after killing mimic ! */ 361 break; 362 case HWALL: 363 tmp = '-'; 364 break; 365 case VWALL: 366 tmp = '|'; 367 break; 368 case LDOOR: 369 case DOOR: 370 tmp = '+'; 371 break; 372 case CORR: 373 tmp = CORR_SYM; 374 break; 375 case ROOM: 376 if(room->lit || cansee(x,y) || Blind) tmp = '.'; 377 else tmp = ' '; 378 break; 379 /* 380 case POOL: 381 tmp = POOL_SYM; 382 break; 383 */ 384 default: 385 tmp = ERRCHAR; 386 } 387 return(tmp); 388 } 389 390 newsym(x,y) 391 register x,y; 392 { 393 atl(x,y,news0(x,y)); 394 } 395 396 /* used with wand of digging (or pick-axe): fill scrsym and force display */ 397 /* also when a POOL evaporates */ 398 mnewsym(x,y) 399 register x,y; 400 { 401 register struct rm *room; 402 char newscrsym; 403 404 if(!vism_at(x,y)) { 405 room = &levl[x][y]; 406 newscrsym = news0(x,y); 407 if(room->scrsym != newscrsym) { 408 room->scrsym = newscrsym; 409 room->seen = 0; 410 } 411 } 412 } 413 414 nosee(x,y) 415 register x,y; 416 { 417 register struct rm *room; 418 419 if(!isok(x,y)) return; 420 room = &levl[x][y]; 421 if(room->scrsym == '.' && !room->lit && !Blind) { 422 room->scrsym = ' '; 423 room->new = 1; 424 on_scr(x,y); 425 } 426 } 427 428 #ifndef QUEST 429 prl1(x,y) 430 register x,y; 431 { 432 if(u.dx) { 433 if(u.dy) { 434 prl(x-(2*u.dx),y); 435 prl(x-u.dx,y); 436 prl(x,y); 437 prl(x,y-u.dy); 438 prl(x,y-(2*u.dy)); 439 } else { 440 prl(x,y-1); 441 prl(x,y); 442 prl(x,y+1); 443 } 444 } else { 445 prl(x-1,y); 446 prl(x,y); 447 prl(x+1,y); 448 } 449 } 450 451 nose1(x,y) 452 register x,y; 453 { 454 if(u.dx) { 455 if(u.dy) { 456 nosee(x,u.uy); 457 nosee(x,u.uy-u.dy); 458 nosee(x,y); 459 nosee(u.ux-u.dx,y); 460 nosee(u.ux,y); 461 } else { 462 nosee(x,y-1); 463 nosee(x,y); 464 nosee(x,y+1); 465 } 466 } else { 467 nosee(x-1,y); 468 nosee(x,y); 469 nosee(x+1,y); 470 } 471 } 472 #endif /* QUEST */ 473 474 vism_at(x,y) 475 register x,y; 476 { 477 register struct monst *mtmp; 478 479 return((x == u.ux && y == u.uy && !Invisible) 480 ? 1 : 481 (mtmp = m_at(x,y)) 482 ? ((Blind && Telepat) || canseemon(mtmp)) : 483 0); 484 } 485 486 #ifdef NEWSCR 487 pobj(obj) register struct obj *obj; { 488 register int show = (!obj->oinvis || See_invisible) && 489 cansee(obj->ox,obj->oy); 490 if(obj->odispl){ 491 if(obj->odx != obj->ox || obj->ody != obj->oy || !show) 492 if(!vism_at(obj->odx,obj->ody)){ 493 newsym(obj->odx, obj->ody); 494 obj->odispl = 0; 495 } 496 } 497 if(show && !vism_at(obj->ox,obj->oy)){ 498 atl(obj->ox,obj->oy,obj->olet); 499 obj->odispl = 1; 500 obj->odx = obj->ox; 501 obj->ody = obj->oy; 502 } 503 } 504 #endif /* NEWSCR */ 505 506 unpobj(obj) register struct obj *obj; { 507 /* if(obj->odispl){ 508 if(!vism_at(obj->odx, obj->ody)) 509 newsym(obj->odx, obj->ody); 510 obj->odispl = 0; 511 } 512 */ 513 if(!vism_at(obj->ox,obj->oy)) 514 newsym(obj->ox,obj->oy); 515 } 516 517 seeobjs(){ 518 register struct obj *obj, *obj2; 519 for(obj = fobj; obj; obj = obj2) { 520 obj2 = obj->nobj; 521 if(obj->olet == FOOD_SYM && obj->otyp >= CORPSE 522 && obj->age + 250 < moves) 523 delobj(obj); 524 } 525 for(obj = invent; obj; obj = obj2) { 526 obj2 = obj->nobj; 527 if(obj->olet == FOOD_SYM && obj->otyp >= CORPSE 528 && obj->age + 250 < moves) 529 useup(obj); 530 } 531 } 532 533 seemons(){ 534 register struct monst *mtmp; 535 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ 536 if(mtmp->data->mlet == ';') 537 mtmp->minvis = (u.ustuck != mtmp && 538 levl[mtmp->mx][mtmp->my].typ == POOL); 539 pmon(mtmp); 540 #ifndef NOWORM 541 if(mtmp->wormno) wormsee(mtmp->wormno); 542 #endif /* NOWORM */ 543 } 544 } 545 546 pmon(mon) register struct monst *mon; { 547 register int show = (Blind && Telepat) || canseemon(mon); 548 if(mon->mdispl){ 549 if(mon->mdx != mon->mx || mon->mdy != mon->my || !show) 550 unpmon(mon); 551 } 552 if(show && !mon->mdispl){ 553 atl(mon->mx,mon->my, 554 (!mon->mappearance 555 || u.uprops[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS)].p_flgs 556 ) ? mon->data->mlet : mon->mappearance); 557 mon->mdispl = 1; 558 mon->mdx = mon->mx; 559 mon->mdy = mon->my; 560 } 561 } 562 563 unpmon(mon) register struct monst *mon; { 564 if(mon->mdispl){ 565 newsym(mon->mdx, mon->mdy); 566 mon->mdispl = 0; 567 } 568 } 569 570 nscr() 571 { 572 register x,y; 573 register struct rm *room; 574 575 if(u.uswallow || u.ux == FAR || flags.nscrinh) return; 576 pru(); 577 for(y = scrly; y <= scrhy; y++) 578 for(x = scrlx; x <= scrhx; x++) 579 if((room = &levl[x][y])->new) { 580 room->new = 0; 581 at(x,y,room->scrsym); 582 } 583 scrhx = scrhy = 0; 584 scrlx = COLNO; 585 scrly = ROWNO; 586 } 587 588 /* 100 suffices for bot(); no relation with COLNO */ 589 char oldbot[100], newbot[100]; 590 cornbot(lth) 591 register int lth; 592 { 593 if(lth < sizeof(oldbot)) { 594 oldbot[lth] = 0; 595 flags.botl = 1; 596 } 597 } 598 599 bot() 600 { 601 register char *ob = oldbot, *nb = newbot; 602 register int i; 603 extern char *eos(); 604 if(flags.botlx) *ob = 0; 605 flags.botl = flags.botlx = 0; 606 #ifdef GOLD_ON_BOTL 607 (void) sprintf(newbot, 608 "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ", 609 dlevel, u.ugold, u.uhp, u.uhpmax, u.uac); 610 #else 611 (void) sprintf(newbot, 612 "Level %-2d Hp %3d(%d) Ac %-2d Str ", 613 dlevel, u.uhp, u.uhpmax, u.uac); 614 #endif /* GOLD_ON_BOTL */ 615 if(u.ustr>18) { 616 if(u.ustr>117) 617 (void) strcat(newbot,"18/**"); 618 else 619 (void) sprintf(eos(newbot), "18/%02d",u.ustr-18); 620 } else 621 (void) sprintf(eos(newbot), "%-2d ",u.ustr); 622 #ifdef EXP_ON_BOTL 623 (void) sprintf(eos(newbot), " Exp %2d/%-5lu ", u.ulevel,u.uexp); 624 #else 625 (void) sprintf(eos(newbot), " Exp %2u ", u.ulevel); 626 #endif /* EXP_ON_BOTL */ 627 (void) strcat(newbot, hu_stat[u.uhs]); 628 if(flags.time) 629 (void) sprintf(eos(newbot), " %ld", moves); 630 if(strlen(newbot) >= COLNO) { 631 register char *bp0, *bp1; 632 bp0 = bp1 = newbot; 633 do { 634 if(*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ') 635 *bp1++ = *bp0; 636 } while(*bp0++); 637 } 638 for(i = 1; i<COLNO; i++) { 639 if(*ob != *nb){ 640 curs(i,ROWNO+2); 641 (void) putchar(*nb ? *nb : ' '); 642 curx++; 643 } 644 if(*ob) ob++; 645 if(*nb) nb++; 646 } 647 (void) strcpy(oldbot, newbot); 648 } 649 650 #ifdef WAN_PROBING 651 mstatusline(mtmp) register struct monst *mtmp; { 652 pline("Status of %s: ", monnam(mtmp)); 653 pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d", 654 mtmp->data->mlevel, mtmp->mgold, mtmp->mhp, mtmp->mhpmax, 655 mtmp->data->ac, (mtmp->data->damn + 1) * (mtmp->data->damd + 1)); 656 } 657 #endif /* WAN_PROBING */ 658 659 cls(){ 660 if(flags.toplin == 1) 661 more(); 662 flags.toplin = 0; 663 664 clear_screen(); 665 666 flags.botlx = 1; 667 } 668