1 /* $NetBSD: hack.pri.c,v 1.11 2009/06/07 20:13:18 dholland 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.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.pri.c,v 1.11 2009/06/07 20:13:18 dholland Exp $");
71 xchar scrlx
, scrhx
, scrly
, scrhy
; /* corners of new area on
81 curs(u
.ux
- 1, u
.uy
+ 1);
82 fputs("/-\\", stdout
);
84 curs(u
.ux
- 1, u
.uy
+ 2);
87 curs(u
.ux
- 1, u
.uy
+ 3);
88 fputs("\\-/", stdout
);
100 panic(const char *fmt
, ...)
106 exit(1); /* avoid loops - this should never happen */
108 puts(" Suddenly, the dungeon collapses.");
109 fputs(" ERROR: ", stdout
);
115 abort(); /* generate core dump */
118 more(); /* contains a fflush() */
123 atl(int x
, int y
, int ch
)
125 struct rm
*crm
= &levl
[x
][y
];
127 if (x
< 0 || x
> COLNO
- 1 || y
< 0 || y
> ROWNO
- 1) {
128 impossible("atl(%d,%d,%c)", x
, y
, ch
);
131 if (crm
->seen
&& crm
->scrsym
== ch
)
152 * call: (x,y) - display (-1,0) - close (leave last symbol) (-1,-1)- close
153 * (undo last symbol) (-1,let)-open: initialize symbol (-2,let)-change let
157 tmp_at(schar x
, schar y
)
159 static schar prevx
, prevy
;
161 if ((int) x
== -2) { /* change let call */
165 if ((int) x
== -1 && (int) y
>= 0) { /* open or close call */
170 if (prevx
>= 0 && cansee(prevx
, prevy
)) {
172 prl(prevx
, prevy
); /* in case there was a monster */
173 at(prevx
, prevy
, levl
[prevx
][prevy
].scrsym
);
175 if (x
>= 0) { /* normal call */
180 } else { /* close call */
186 /* like the previous, but the symbols are first erased on completion */
188 Tmp_at(schar x
, schar y
)
192 static coord tc
[COLNO
]; /* but watch reflecting beams! */
195 if (y
> 0) { /* open call */
200 /* close call (do not distinguish y==0 and y==-1) */
205 at(xx
, yy
, levl
[xx
][yy
].scrsym
);
207 cnt
= let
= 0; /* superfluous */
210 if ((int) x
== -2) { /* change let call */
222 panic("Tmp_at overflow?");
223 levl
[x
][y
].new = 0; /* prevent pline-nscr erasing --- */
230 error("Hack needs a screen of size at least %d by %d.\n",
235 at(xchar x
, xchar y
, int ch
)
238 /* if xchar is unsigned, lint will complain about if(x < 0) */
239 if (x
< 0 || x
> COLNO
- 1 || y
< 0 || y
> ROWNO
- 1) {
240 impossible("At gets 0%o at %d %d.", ch
, x
, y
);
245 impossible("At gets null at %d %d.", x
, y
);
258 at(u
.ux
, u
.uy
, u
.usym
);
282 * Some ridiculous code to get display of @ and monsters (almost)
286 levl
[(u
.udisx
= u
.ux
)][(u
.udisy
= u
.uy
)].scrsym
= u
.usym
;
287 levl
[u
.udisx
][u
.udisy
].seen
= 1;
292 seemons(); /* reset old positions */
293 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
295 seemons(); /* force new positions to be shown */
297 * This nonsense should disappear soon
298 * ---------------------------------
301 for (y
= 0; y
< ROWNO
; y
++)
302 for (x
= 0; x
< COLNO
; x
++)
303 if ((room
= &levl
[x
][y
])->new) {
305 at(x
, y
, room
->scrsym
);
306 } else if (room
->seen
)
307 at(x
, y
, room
->scrsym
);
316 docorner(int xmin
, int ymax
)
322 if (u
.uswallow
) { /* Can be done more efficiently */
326 seemons(); /* reset old positions */
327 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
328 if (mtmp
->mx
>= xmin
&& mtmp
->my
< ymax
)
330 seemons(); /* force new positions to be shown */
332 for (y
= 0; y
< ymax
; y
++) {
338 for (x
= xmin
; x
< COLNO
; x
++) {
339 if ((room
= &levl
[x
][y
])->new) {
341 at(x
, y
, room
->scrsym
);
342 } else if (room
->seen
)
343 at(x
, y
, room
->scrsym
);
349 if (ymax
> ROWNO
+ 1 && CD
) {
359 curs(u
.ux
, u
.uy
+ 2);
365 if (u
.udispl
&& (Invisible
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
))
366 /* if(! levl[u.udisx][u.udisy].new) */
367 if (!vism_at(u
.udisx
, u
.udisy
))
368 newsym(u
.udisx
, u
.udisy
);
372 } else if (!u
.udispl
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
) {
373 atl(u
.ux
, u
.uy
, u
.usym
);
378 levl
[u
.ux
][u
.uy
].seen
= 1;
382 #include "def.wseg.h"
385 /* print a position that is visible for @ */
393 if (x
== u
.ux
&& y
== u
.uy
&& (!Invisible
)) {
401 (IS_ROCK(room
->typ
) && levl
[u
.ux
][u
.uy
].typ
== CORR
))
403 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mhide
&&
404 (!mtmp
->minvis
|| See_invisible
)) {
411 } else if ((otmp
= o_at(x
, y
)) && room
->typ
!= POOL
)
412 atl(x
, y
, otmp
->olet
);
413 else if (mtmp
&& (!mtmp
->minvis
|| See_invisible
)) {
414 /* must be a hiding monster, but not hiding right now */
415 /* assume for the moment that long worms do not hide */
417 } else if (g_at(x
, y
) && room
->typ
!= POOL
)
419 else if (!room
->seen
|| room
->scrsym
== ' ') {
420 room
->new = room
->seen
= 1;
428 news0(xchar x
, xchar y
)
438 else if (room
->typ
== POOL
)
440 else if (!Blind
&& (otmp
= o_at(x
, y
)))
442 else if (!Blind
&& g_at(x
, y
))
444 else if (x
== xupstair
&& y
== yupstair
)
446 else if (x
== xdnstair
&& y
== ydnstair
)
448 else if ((ttmp
= t_at(x
, y
)) && ttmp
->tseen
)
454 tmp
= room
->scrsym
; /* %% wrong after killing
471 if (room
->lit
|| cansee(x
, y
) || Blind
)
490 atl(x
, y
, news0(x
, y
));
493 /* used with wand of digging (or pick-axe): fill scrsym and force display */
494 /* also when a POOL evaporates */
496 mnewsym(int x
, int y
)
501 if (!vism_at(x
, y
)) {
503 newscrsym
= news0(x
, y
);
504 if (room
->scrsym
!= newscrsym
) {
505 room
->scrsym
= newscrsym
;
519 if (room
->scrsym
== '.' && !room
->lit
&& !Blind
) {
532 prl(x
- (2 * u
.dx
), y
);
536 prl(x
, y
- (2 * u
.dy
));
555 nosee(x
, u
.uy
- u
.dy
);
557 nosee(u
.ux
- u
.dx
, y
);
573 vism_at(int x
, int y
)
577 return ((x
== u
.ux
&& y
== u
.uy
&& !Invisible
)
580 ? ((Blind
&& Telepat
) || canseemon(mtmp
)) :
586 pobj(struct obj
*obj
)
588 int show
= (!obj
->oinvis
|| See_invisible
) &&
589 cansee(obj
->ox
, obj
->oy
);
591 if (obj
->odx
!= obj
->ox
|| obj
->ody
!= obj
->oy
|| !show
)
592 if (!vism_at(obj
->odx
, obj
->ody
)) {
593 newsym(obj
->odx
, obj
->ody
);
597 if (show
&& !vism_at(obj
->ox
, obj
->oy
)) {
598 atl(obj
->ox
, obj
->oy
, obj
->olet
);
607 unpobj(struct obj
*obj
)
610 * if(obj->odispl){ if(!vism_at(obj->odx, obj->ody)) newsym(obj->odx,
611 * obj->ody); obj->odispl = 0; }
613 if (!vism_at(obj
->ox
, obj
->oy
))
614 newsym(obj
->ox
, obj
->oy
);
620 struct obj
*obj
, *obj2
;
621 for (obj
= fobj
; obj
; obj
= obj2
) {
623 if (obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
624 && obj
->age
+ 250 < moves
)
627 for (obj
= invent
; obj
; obj
= obj2
) {
629 if (obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
630 && obj
->age
+ 250 < moves
)
639 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
640 if (mtmp
->data
->mlet
== ';')
641 mtmp
->minvis
= (u
.ustuck
!= mtmp
&&
642 levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
646 wormsee(mtmp
->wormno
);
652 pmon(struct monst
*mon
)
654 int show
= (Blind
&& Telepat
) || canseemon(mon
);
656 if (mon
->mdx
!= mon
->mx
|| mon
->mdy
!= mon
->my
|| !show
)
659 if (show
&& !mon
->mdispl
) {
660 atl(mon
->mx
, mon
->my
,
662 || u
.uprops
[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS
)].p_flgs
663 ) ? mon
->data
->mlet
: mon
->mappearance
);
671 unpmon(struct monst
*mon
)
674 newsym(mon
->mdx
, mon
->mdy
);
685 if (u
.uswallow
|| u
.ux
== FAR
|| flags
.nscrinh
)
688 for (y
= scrly
; y
<= scrhy
; y
++)
689 for (x
= scrlx
; x
<= scrhx
; x
++)
690 if ((room
= &levl
[x
][y
])->new) {
692 at(x
, y
, room
->scrsym
);
699 /* 100 suffices for bot(); no relation with COLNO */
700 char oldbot
[100], newbot
[100];
704 if ((unsigned)lth
< sizeof(oldbot
)) {
713 char *ob
= oldbot
, *nb
= newbot
;
719 flags
.botl
= flags
.botlx
= 0;
721 (void) snprintf(newbot
, sizeof(newbot
),
722 "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ",
723 dlevel
, u
.ugold
, u
.uhp
, u
.uhpmax
, u
.uac
);
725 (void) snprintf(newbot
, sizeof(newbot
),
726 "Level %-2d Hp %3d(%d) Ac %-2d Str ",
727 dlevel
, u
.uhp
, u
.uhpmax
, u
.uac
);
728 #endif /* GOLD_ON_BOTL */
731 (void) strlcat(newbot
, "18/**", sizeof(newbot
));
733 pos
= strlen(newbot
);
734 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
735 "18/%02d", u
.ustr
- 18);
738 pos
= strlen(newbot
);
739 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
742 pos
= strlen(newbot
);
744 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
745 " Exp %2d/%-5lu ", u
.ulevel
, u
.uexp
);
747 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
748 " Exp %2u ", u
.ulevel
);
749 #endif /* EXP_ON_BOTL */
750 (void) strlcat(newbot
, hu_stat
[u
.uhs
], sizeof(newbot
));
752 pos
= strlen(newbot
);
753 (void) snprintf(newbot
+pos
, sizeof(newbot
)-pos
,
756 if (strlen(newbot
) >= COLNO
) {
760 if (*bp0
!= ' ' || bp0
[1] != ' ' || bp0
[2] != ' ')
764 for (i
= 1; i
< COLNO
; i
++) {
767 (void) putchar(*nb
? *nb
: ' ');
775 (void) strcpy(oldbot
, newbot
);
780 mstatusline(struct monst
*mtmp
)
782 pline("Status of %s: ", monnam(mtmp
));
783 pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d",
784 mtmp
->data
->mlevel
, mtmp
->mgold
, mtmp
->mhp
, mtmp
->mhpmax
,
785 mtmp
->data
->ac
, (mtmp
->data
->damn
+ 1) * (mtmp
->data
->damd
+ 1));
787 #endif /* WAN_PROBING */
792 if (flags
.toplin
== 1)