1 /* $NetBSD: hack.pri.c,v 1.13 2010/02/03 15:34:38 roy Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 static xchar scrlx
, scrhx
, scrly
, scrhy
; /* corners of new area on
70 static void cornbot(int);
79 curs(u
.ux
- 1, u
.uy
+ 1);
80 fputs("/-\\", stdout
);
82 curs(u
.ux
- 1, u
.uy
+ 2);
85 curs(u
.ux
- 1, u
.uy
+ 3);
86 fputs("\\-/", stdout
);
95 static boolean panicking
;
98 panic(const char *fmt
, ...)
104 exit(1); /* avoid loops - this should never happen */
106 puts(" Suddenly, the dungeon collapses.");
107 fputs(" ERROR: ", stdout
);
113 abort(); /* generate core dump */
116 more(); /* contains a fflush() */
121 atl(int x
, int y
, int ch
)
123 struct rm
*crm
= &levl
[x
][y
];
125 if (x
< 0 || x
> COLNO
- 1 || y
< 0 || y
> ROWNO
- 1) {
126 impossible("atl(%d,%d,%c)", x
, y
, ch
);
129 if (crm
->seen
&& crm
->scrsym
== ch
)
150 * call: (x,y) - display (-1,0) - close (leave last symbol) (-1,-1)- close
151 * (undo last symbol) (-1,let)-open: initialize symbol (-2,let)-change let
155 tmp_at(schar x
, schar y
)
157 static schar prevx
, prevy
;
159 if ((int) x
== -2) { /* change let call */
163 if ((int) x
== -1 && (int) y
>= 0) { /* open or close call */
168 if (prevx
>= 0 && cansee(prevx
, prevy
)) {
170 prl(prevx
, prevy
); /* in case there was a monster */
171 at(prevx
, prevy
, levl
[prevx
][prevy
].scrsym
);
173 if (x
>= 0) { /* normal call */
178 } else { /* close call */
184 /* like the previous, but the symbols are first erased on completion */
186 Tmp_at(schar x
, schar y
)
190 static coord tc
[COLNO
]; /* but watch reflecting beams! */
193 if (y
> 0) { /* open call */
198 /* close call (do not distinguish y==0 and y==-1) */
203 at(xx
, yy
, levl
[xx
][yy
].scrsym
);
205 cnt
= let
= 0; /* superfluous */
208 if ((int) x
== -2) { /* change let call */
220 panic("Tmp_at overflow?");
221 levl
[x
][y
].new = 0; /* prevent pline-nscr erasing --- */
228 error("Hack needs a screen of size at least %d by %d.\n",
233 at(xchar x
, xchar y
, int ch
)
236 /* if xchar is unsigned, lint will complain about if(x < 0) */
237 if (x
< 0 || x
> COLNO
- 1 || y
< 0 || y
> ROWNO
- 1) {
238 impossible("At gets 0%o at %d %d.", ch
, x
, y
);
243 impossible("At gets null at %d %d.", x
, y
);
256 at(u
.ux
, u
.uy
, u
.usym
);
280 * Some ridiculous code to get display of @ and monsters (almost)
284 levl
[(u
.udisx
= u
.ux
)][(u
.udisy
= u
.uy
)].scrsym
= u
.usym
;
285 levl
[u
.udisx
][u
.udisy
].seen
= 1;
290 seemons(); /* reset old positions */
291 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
293 seemons(); /* force new positions to be shown */
295 * This nonsense should disappear soon
296 * ---------------------------------
299 for (y
= 0; y
< ROWNO
; y
++)
300 for (x
= 0; x
< COLNO
; x
++)
301 if ((room
= &levl
[x
][y
])->new) {
303 at(x
, y
, room
->scrsym
);
304 } else if (room
->seen
)
305 at(x
, y
, room
->scrsym
);
314 docorner(int xmin
, int ymax
)
320 if (u
.uswallow
) { /* Can be done more efficiently */
324 seemons(); /* reset old positions */
325 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
326 if (mtmp
->mx
>= xmin
&& mtmp
->my
< ymax
)
328 seemons(); /* force new positions to be shown */
330 for (y
= 0; y
< ymax
; y
++) {
336 for (x
= xmin
; x
< COLNO
; x
++) {
337 if ((room
= &levl
[x
][y
])->new) {
339 at(x
, y
, room
->scrsym
);
340 } else if (room
->seen
)
341 at(x
, y
, room
->scrsym
);
347 if (ymax
> ROWNO
+ 1 && CD
) {
357 curs(u
.ux
, u
.uy
+ 2);
363 if (u
.udispl
&& (Invisible
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
))
364 /* if(! levl[u.udisx][u.udisy].new) */
365 if (!vism_at(u
.udisx
, u
.udisy
))
366 newsym(u
.udisx
, u
.udisy
);
370 } else if (!u
.udispl
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
) {
371 atl(u
.ux
, u
.uy
, u
.usym
);
376 levl
[u
.ux
][u
.uy
].seen
= 1;
380 #include "def.wseg.h"
383 /* print a position that is visible for @ */
391 if (x
== u
.ux
&& y
== u
.uy
&& (!Invisible
)) {
399 (IS_ROCK(room
->typ
) && levl
[u
.ux
][u
.uy
].typ
== CORR
))
401 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mhide
&&
402 (!mtmp
->minvis
|| See_invisible
)) {
409 } else if ((otmp
= o_at(x
, y
)) && room
->typ
!= POOL
)
410 atl(x
, y
, otmp
->olet
);
411 else if (mtmp
&& (!mtmp
->minvis
|| See_invisible
)) {
412 /* must be a hiding monster, but not hiding right now */
413 /* assume for the moment that long worms do not hide */
415 } else if (g_at(x
, y
) && room
->typ
!= POOL
)
417 else if (!room
->seen
|| room
->scrsym
== ' ') {
418 room
->new = room
->seen
= 1;
426 news0(xchar x
, xchar y
)
436 else if (room
->typ
== POOL
)
438 else if (!Blind
&& (otmp
= o_at(x
, y
)))
440 else if (!Blind
&& g_at(x
, y
))
442 else if (x
== xupstair
&& y
== yupstair
)
444 else if (x
== xdnstair
&& y
== ydnstair
)
446 else if ((ttmp
= t_at(x
, y
)) && ttmp
->tseen
)
452 tmp
= room
->scrsym
; /* %% wrong after killing
469 if (room
->lit
|| cansee(x
, y
) || Blind
)
488 atl(x
, y
, news0(x
, y
));
491 /* used with wand of digging (or pick-axe): fill scrsym and force display */
492 /* also when a POOL evaporates */
494 mnewsym(int x
, int y
)
499 if (!vism_at(x
, y
)) {
501 newscrsym
= news0(x
, y
);
502 if (room
->scrsym
!= newscrsym
) {
503 room
->scrsym
= newscrsym
;
517 if (room
->scrsym
== '.' && !room
->lit
&& !Blind
) {
530 prl(x
- (2 * u
.dx
), y
);
534 prl(x
, y
- (2 * u
.dy
));
553 nosee(x
, u
.uy
- u
.dy
);
555 nosee(u
.ux
- u
.dx
, y
);
571 vism_at(int x
, int y
)
575 return ((x
== u
.ux
&& y
== u
.uy
&& !Invisible
)
578 ? ((Blind
&& Telepat
) || canseemon(mtmp
)) :
584 pobj(struct obj
*obj
)
586 int show
= (!obj
->oinvis
|| See_invisible
) &&
587 cansee(obj
->ox
, obj
->oy
);
589 if (obj
->odx
!= obj
->ox
|| obj
->ody
!= obj
->oy
|| !show
)
590 if (!vism_at(obj
->odx
, obj
->ody
)) {
591 newsym(obj
->odx
, obj
->ody
);
595 if (show
&& !vism_at(obj
->ox
, obj
->oy
)) {
596 atl(obj
->ox
, obj
->oy
, obj
->olet
);
605 unpobj(struct obj
*obj
)
608 * if(obj->odispl){ if(!vism_at(obj->odx, obj->ody)) newsym(obj->odx,
609 * obj->ody); obj->odispl = 0; }
611 if (!vism_at(obj
->ox
, obj
->oy
))
612 newsym(obj
->ox
, obj
->oy
);
618 struct obj
*obj
, *obj2
;
619 for (obj
= fobj
; obj
; obj
= obj2
) {
621 if (obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
622 && obj
->age
+ 250 < moves
)
625 for (obj
= invent
; obj
; obj
= obj2
) {
627 if (obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
628 && obj
->age
+ 250 < moves
)
637 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
638 if (mtmp
->data
->mlet
== ';')
639 mtmp
->minvis
= (u
.ustuck
!= mtmp
&&
640 levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
644 wormsee(mtmp
->wormno
);
650 pmon(struct monst
*mon
)
652 int show
= (Blind
&& Telepat
) || canseemon(mon
);
654 if (mon
->mdx
!= mon
->mx
|| mon
->mdy
!= mon
->my
|| !show
)
657 if (show
&& !mon
->mdispl
) {
658 atl(mon
->mx
, mon
->my
,
660 || u
.uprops
[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS
)].p_flgs
661 ) ? mon
->data
->mlet
: mon
->mappearance
);
669 unpmon(struct monst
*mon
)
672 newsym(mon
->mdx
, mon
->mdy
);
683 if (u
.uswallow
|| u
.ux
== FAR
|| flags
.nscrinh
)
686 for (y
= scrly
; y
<= scrhy
; y
++)
687 for (x
= scrlx
; x
<= scrhx
; x
++)
688 if ((room
= &levl
[x
][y
])->new) {
690 at(x
, y
, room
->scrsym
);
697 /* 100 suffices for bot(); no relation with COLNO */
698 static char oldbot
[100], newbot
[100];
702 if ((unsigned)lth
< sizeof(oldbot
)) {
711 char *ob
= oldbot
, *nb
= newbot
;
717 flags
.botl
= flags
.botlx
= 0;
719 (void) snprintf(newbot
, sizeof(newbot
),
720 "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ",
721 dlevel
, u
.ugold
, u
.uhp
, u
.uhpmax
, u
.uac
);
723 (void) snprintf(newbot
, sizeof(newbot
),
724 "Level %-2d Hp %3d(%d) Ac %-2d Str ",
725 dlevel
, u
.uhp
, u
.uhpmax
, u
.uac
);
726 #endif /* GOLD_ON_BOTL */
729 (void) strlcat(newbot
, "18/**", sizeof(newbot
));
731 pos
= strlen(newbot
);
732 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
733 "18/%02d", u
.ustr
- 18);
736 pos
= strlen(newbot
);
737 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
740 pos
= strlen(newbot
);
742 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
743 " Exp %2d/%-5lu ", u
.ulevel
, u
.uexp
);
745 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
746 " Exp %2u ", u
.ulevel
);
747 #endif /* EXP_ON_BOTL */
748 (void) strlcat(newbot
, hu_stat
[u
.uhs
], sizeof(newbot
));
750 pos
= strlen(newbot
);
751 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
754 if (strlen(newbot
) >= COLNO
) {
758 if (*bp0
!= ' ' || bp0
[1] != ' ' || bp0
[2] != ' ')
762 for (i
= 1; i
< COLNO
; i
++) {
765 (void) putchar(*nb
? *nb
: ' ');
773 (void) strcpy(oldbot
, newbot
);
778 mstatusline(struct monst
*mtmp
)
780 pline("Status of %s: ", monnam(mtmp
));
781 pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d",
782 mtmp
->data
->mlevel
, mtmp
->mgold
, mtmp
->mhp
, mtmp
->mhpmax
,
783 mtmp
->data
->ac
, (mtmp
->data
->damn
+ 1) * (mtmp
->data
->damd
+ 1));
785 #endif /* WAN_PROBING */
790 if (flags
.toplin
== 1)