1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.pri.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.pri.c,v 1.5 1999/11/16 10:26:37 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.pri.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
8 xchar scrlx, scrhx, scrly, scrhy; /* corners of new area on screen */
13 static void pobj(struct obj *);
15 static void cornbot(int);
20 char ulook[] = { "|@|" };
25 curs(u.ux - 1, u.uy + 1);
26 fputs("/-\\", stdout);
28 curs(u.ux - 1, u.uy + 2);
31 curs(u.ux - 1, u.uy + 3);
32 fputs("\\-/", stdout);
43 panic(const char *str, ...)
47 if (panicking++) /* avoid loops - this should never happen*/
50 puts(" Suddenly, the dungeon collapses.");
51 fputs(" ERROR: ", stdout);
58 abort(); /* generate core dump */
61 more(); /* contains a fflush() */
66 atl(int x, int y, char ch)
68 struct rm *crm = &levl[x][y];
70 if (x < 0 || x > COLNO - 1 || y < 0 || y > ROWNO - 1) {
71 impossible("atl(%d,%d,%c)", x, y, ch);
74 if (crm->seen && crm->scrsym == ch)
94 /* call: (x,y) - display
95 * (-1,0) - close (leave last symbol)
96 * (-1,-1)- close (undo last symbol)
97 * (-1,let)-open: initialize symbol
102 tmp_at(schar x, schar y)
104 static schar prevx, prevy;
107 if ((int)x == -2) { /* change let call */
111 if ((int)x == -1 && (int)y >= 0) { /* open or close call */
116 if (prevx >= 0 && cansee(prevx, prevy)) {
118 prl(prevx, prevy); /* in case there was a monster */
119 at(prevx, prevy, levl[prevx][prevy].scrsym);
121 if (x >= 0) { /* normal call */
126 } else { /* close call */
132 /* like the previous, but the symbols are first erased on completion */
134 Tmp_at(schar x, schar y)
138 static coord tc[COLNO]; /* but watch reflecting beams! */
142 if (y > 0) { /* open call */
147 /* close call (do not distinguish y==0 and y==-1) */
152 at(xx, yy, levl[xx][yy].scrsym);
154 cnt = let = 0; /* superfluous */
157 if ((int)x == -2) { /* change let call */
169 panic("Tmp_at overflow?");
170 levl[x][y].new = 0; /* prevent pline-nscr erasing --- */
177 error("Hack needs a screen of size at least %d by %d.\n",
182 at(xchar x, xchar y, char ch)
185 /* if xchar is unsigned, lint will complain about if (x < 0) */
186 if (x < 0 || x > COLNO - 1 || y < 0 || y > ROWNO - 1) {
187 impossible("At gets 0%o at %d %d.", ch, x, y);
192 impossible("At gets null at %d %d.", x, y);
205 at(u.ux, u.uy, u.usym);
228 /* Some ridiculous code to get display of @ and monsters (almost) right */
230 levl[(u.udisx = u.ux)][(u.udisy = u.uy)].scrsym = u.usym;
231 levl[u.udisx][u.udisy].seen = 1;
236 seemons(); /* reset old positions */
237 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
239 seemons(); /* force new positions to be shown */
240 /* This nonsense should disappear soon --------------------------------- */
242 for (y = 0; y < ROWNO; y++)
243 for (x = 0; x < COLNO; x++)
244 if ((room = &levl[x][y])->new) {
246 at(x, y, room->scrsym);
247 } else if (room->seen)
248 at(x, y, room->scrsym);
257 docorner(int xmin, int ymax)
263 if (u.uswallow) { /* Can be done more efficiently */
267 seemons(); /* reset old positions */
268 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
269 if (mtmp->mx >= xmin && mtmp->my < ymax)
271 seemons(); /* force new positions to be shown */
273 for (y = 0; y < ymax; y++) {
279 for (x = xmin; x < COLNO; x++) {
280 if ((room = &levl[x][y])->new) {
282 at(x, y, room->scrsym);
283 } else if (room->seen)
284 at(x, y, room->scrsym);
290 if (ymax > ROWNO + 1 && CD) {
300 curs(u.ux, u.uy + 2);
306 if (u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
307 if (!vism_at(u.udisx, u.udisy))
308 newsym(u.udisx, u.udisy);
312 } else if (!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
313 atl(u.ux, u.uy, u.usym);
318 levl[u.ux][u.uy].seen = 1;
322 extern struct wseg *m_atseg;
325 /* print a position that is visible for @ */
333 if (x == u.ux && y == u.uy && (!Invisible)) {
341 (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR))
343 if ((mtmp = m_at(x, y)) && !mtmp->mhide &&
344 (!mtmp->minvis || See_invisible)) {
351 } else if ((otmp = o_at(x, y)) && room->typ != POOL)
352 atl(x, y, otmp->olet);
353 else if (mtmp && (!mtmp->minvis || See_invisible)) {
354 /* must be a hiding monster, but not hiding right now */
355 /* assume for the moment that long worms do not hide */
357 } else if (g_at(x, y) && room->typ != POOL)
359 else if (!room->seen || room->scrsym == ' ') {
360 room->new = room->seen = 1;
368 news0(xchar x, xchar y)
378 else if (room->typ == POOL)
380 else if (!Blind && (otmp = o_at(x, y)))
382 else if (!Blind && g_at(x, y))
384 else if (x == xupstair && y == yupstair)
386 else if (x == xdnstair && y == ydnstair)
388 else if ((ttmp = t_at(x, y)) && ttmp->tseen)
394 tmp = room->scrsym; /* %% wrong after killing mimic ! */
410 if (room->lit || cansee(x, y) || Blind)
424 atl(x, y, news0(x, y));
427 /* used with wand of digging (or pick-axe): fill scrsym and force display */
428 /* also when a POOL evaporates */
430 mnewsym(int x, int y)
435 if (!vism_at(x, y)) {
437 newscrsym = news0(x, y);
438 if (room->scrsym != newscrsym) {
439 room->scrsym = newscrsym;
453 if (room->scrsym == '.' && !room->lit && !Blind) {
466 prl(x - (2 * u.dx), y);
470 prl(x, y - (2 * u.dy));
489 nosee(x, u.uy - u.dy);
491 nosee(u.ux - u.dx, y);
507 vism_at(int x, int y)
511 return ((x == u.ux && y == u.uy && !Invisible)
514 ? ((Blind && Telepat) || canseemon(mtmp)) :
520 pobj(struct obj *obj)
522 int show = (!obj->oinvis || See_invisible) &&
523 cansee(obj->ox, obj->oy);
526 if (obj->odx != obj->ox || obj->ody != obj->oy || !show)
527 if (!vism_at(obj->odx, obj->ody)) {
528 newsym(obj->odx, obj->ody);
532 if (show && !vism_at(obj->ox, obj->oy)) {
533 atl(obj->ox, obj->oy, obj->olet);
542 unpobj(struct obj *obj)
544 if (!vism_at(obj->ox, obj->oy))
545 newsym(obj->ox, obj->oy);
551 struct obj *obj, *obj2;
553 for (obj = fobj; obj; obj = obj2) {
555 if (obj->olet == FOOD_SYM && obj->otyp >= CORPSE
556 && obj->age + 250 < moves)
559 for (obj = invent; obj; obj = obj2) {
561 if (obj->olet == FOOD_SYM && obj->otyp >= CORPSE
562 && obj->age + 250 < moves)
572 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
573 if (mtmp->data->mlet == ';')
574 mtmp->minvis = (u.ustuck != mtmp &&
575 levl[mtmp->mx][mtmp->my].typ == POOL);
579 wormsee(mtmp->wormno);
585 pmon(struct monst *mon)
587 int show = (Blind && Telepat) || canseemon(mon);
590 if (mon->mdx != mon->mx || mon->mdy != mon->my || !show)
593 if (show && !mon->mdispl) {
594 atl(mon->mx, mon->my,
596 || u.uprops[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS)].p_flgs
597 ) ? mon->data->mlet : mon->mappearance);
605 unpmon(struct monst *mon)
608 newsym(mon->mdx, mon->mdy);
619 if (u.uswallow || u.ux == FAR || flags.nscrinh)
622 for (y = scrly; y <= scrhy; y++)
623 for (x = scrlx; x <= scrhx; x++)
624 if ((room = &levl[x][y])->new) {
626 at(x, y, room->scrsym);
633 /* 100 suffices for bot(); no relation with COLNO */
634 char oldbot[100], newbot[100];
639 if (lth < (int)sizeof(oldbot)) {
648 char *ob = oldbot, *nb = newbot;
653 flags.botl = flags.botlx = 0;
656 "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ",
657 dlevel, u.ugold, u.uhp, u.uhpmax, u.uac);
660 "Level %-2d Hp %3d(%d) Ac %-2d Str ",
661 dlevel, u.uhp, u.uhpmax, u.uac);
662 #endif /* GOLD_ON_BOTL */
665 strcat(newbot, "18/**");
667 sprintf(eos(newbot), "18/%02d", u.ustr - 18);
669 sprintf(eos(newbot), "%-2d ", u.ustr);
671 sprintf(eos(newbot), " Exp %2d/%-5lu ", u.ulevel, u.uexp);
673 sprintf(eos(newbot), " Exp %2u ", u.ulevel);
674 #endif /* EXP_ON_BOTL */
675 strcat(newbot, hu_stat[u.uhs]);
677 sprintf(eos(newbot), " %ld", moves);
678 if (strlen(newbot) >= COLNO) {
682 if (*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ')
686 for (i = 1; i < COLNO; i++) {
689 putchar(*nb ? *nb : ' ');
697 strcpy(oldbot, newbot);
702 mstatusline(struct monst *mtmp)
704 pline("Status of %s: ", monnam(mtmp));
705 pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d",
706 mtmp->data->mlevel, mtmp->mgold, mtmp->mhp, mtmp->mhpmax,
707 mtmp->data->ac, (mtmp->data->damn + 1) * (mtmp->data->damd + 1));
709 #endif /* WAN_PROBING */
714 if (flags.toplin == 1)