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 fputs("/-\\", stdout
);
31 fputs("\\-/", stdout
);
43 panic(const char *str
, ...)
47 if(panicking
++) exit(1); /* avoid loops - this should never happen*/
49 puts(" Suddenly, the dungeon collapses.");
50 fputs(" ERROR: ", stdout
);
57 abort(); /* generate core dump */
60 more(); /* contains a fflush() */
65 atl(int x
, int y
, char ch
)
67 struct rm
*crm
= &levl
[x
][y
];
69 if(x
<0 || x
>COLNO
-1 || y
<0 || y
>ROWNO
-1){
70 impossible("atl(%d,%d,%c)",x
,y
,ch
);
73 if(crm
->seen
&& crm
->scrsym
== ch
) return;
82 if(x
< scrlx
) scrlx
= x
;
83 if(x
> scrhx
) scrhx
= x
;
84 if(y
< scrly
) scrly
= y
;
85 if(y
> scrhy
) scrhy
= y
;
88 /* call: (x,y) - display
89 (-1,0) - close (leave last symbol)
90 (-1,-1)- close (undo last symbol)
91 (-1,let)-open: initialize symbol
96 tmp_at(schar x
, schar y
)
98 static schar prevx
, prevy
;
100 if((int)x
== -2){ /* change let call */
104 if((int)x
== -1 && (int)y
>= 0){ /* open or close call */
109 if(prevx
>= 0 && cansee(prevx
,prevy
)) {
111 prl(prevx
, prevy
); /* in case there was a monster */
112 at(prevx
, prevy
, levl
[prevx
][prevy
].scrsym
);
114 if(x
>= 0){ /* normal call */
115 if(cansee(x
,y
)) at(x
,y
,let
);
118 } else { /* close call */
124 /* like the previous, but the symbols are first erased on completion */
126 Tmp_at(schar x
, schar y
)
130 static coord tc
[COLNO
]; /* but watch reflecting beams! */
133 if(y
> 0) { /* open call */
138 /* close call (do not distinguish y==0 and y==-1) */
143 at(xx
, yy
, levl
[xx
][yy
].scrsym
);
145 cnt
= let
= 0; /* superfluous */
148 if((int)x
== -2) { /* change let call */
154 if(cnt
) delay_output(50);
158 if(++cnt
>= COLNO
) panic("Tmp_at overflow?");
159 levl
[x
][y
].new = 0; /* prevent pline-nscr erasing --- */
166 error("Hack needs a screen of size at least %d by %d.\n",
171 at(xchar x
, xchar y
, char ch
)
174 /* if xchar is unsigned, lint will complain about if(x < 0) */
175 if(x
< 0 || x
> COLNO
-1 || y
< 0 || y
> ROWNO
-1) {
176 impossible("At gets 0%o at %d %d.", ch
, x
, y
);
181 impossible("At gets null at %d %d.", x
, y
);
193 if(!Invisible
) at(u
.ux
,u
.uy
,u
.usym
);
216 /* Some ridiculous code to get display of @ and monsters (almost) right */
218 levl
[(u
.udisx
= u
.ux
)][(u
.udisy
= u
.uy
)].scrsym
= u
.usym
;
219 levl
[u
.udisx
][u
.udisy
].seen
= 1;
223 seemons(); /* reset old positions */
224 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
226 seemons(); /* force new positions to be shown */
227 /* This nonsense should disappear soon --------------------------------- */
229 for(y
= 0; y
< ROWNO
; y
++)
230 for(x
= 0; x
< COLNO
; x
++)
231 if((room
= &levl
[x
][y
])->new) {
233 at(x
,y
,room
->scrsym
);
234 } else if(room
->seen
)
235 at(x
,y
,room
->scrsym
);
244 docorner(int xmin
, int ymax
)
250 if(u
.uswallow
) { /* Can be done more efficiently */
255 seemons(); /* reset old positions */
256 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
257 if(mtmp
->mx
>= xmin
&& mtmp
->my
< ymax
)
259 seemons(); /* force new positions to be shown */
261 for(y
= 0; y
< ymax
; y
++) {
262 if(y
> ROWNO
&& CD
) break;
266 for(x
= xmin
; x
< COLNO
; x
++) {
267 if((room
= &levl
[x
][y
])->new) {
269 at(x
,y
,room
->scrsym
);
272 at(x
,y
,room
->scrsym
);
278 if(ymax
> ROWNO
+1 && CD
) {
294 if(u
.udispl
&& (Invisible
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
))
295 if(!vism_at(u
.udisx
, u
.udisy
))
296 newsym(u
.udisx
, u
.udisy
);
301 if(!u
.udispl
|| u
.udisx
!= u
.ux
|| u
.udisy
!= u
.uy
) {
302 atl(u
.ux
, u
.uy
, u
.usym
);
307 levl
[u
.ux
][u
.uy
].seen
= 1;
311 extern struct wseg
*m_atseg
;
314 /* print a position that is visible for @ */
322 if(x
== u
.ux
&& y
== u
.uy
&& (!Invisible
)) {
326 if(!isok(x
,y
)) return;
329 (IS_ROCK(room
->typ
) && levl
[u
.ux
][u
.uy
].typ
== CORR
))
331 if((mtmp
= m_at(x
,y
)) && !mtmp
->mhide
&&
332 (!mtmp
->minvis
|| See_invisible
)) {
340 else if((otmp
= o_at(x
,y
)) && room
->typ
!= POOL
)
342 else if(mtmp
&& (!mtmp
->minvis
|| See_invisible
)) {
343 /* must be a hiding monster, but not hiding right now */
344 /* assume for the moment that long worms do not hide */
347 else if(g_at(x
,y
) && room
->typ
!= POOL
)
349 else if(!room
->seen
|| room
->scrsym
== ' ') {
350 room
->new = room
->seen
= 1;
358 news0(xchar x
, xchar y
)
366 if(!room
->seen
) tmp
= ' ';
367 else if(room
->typ
== POOL
) tmp
= POOL_SYM
;
368 else if(!Blind
&& (otmp
= o_at(x
,y
))) tmp
= otmp
->olet
;
369 else if(!Blind
&& g_at(x
,y
)) tmp
= '$';
370 else if(x
== xupstair
&& y
== yupstair
) tmp
= '<';
371 else if(x
== xdnstair
&& y
== ydnstair
) tmp
= '>';
372 else if((ttmp
= t_at(x
,y
)) && ttmp
->tseen
) tmp
= '^';
373 else switch(room
->typ
) {
376 tmp
= room
->scrsym
; /* %% wrong after killing mimic ! */
392 if(room
->lit
|| cansee(x
,y
) || Blind
) tmp
= '.';
407 /* used with wand of digging (or pick-axe): fill scrsym and force display */
408 /* also when a POOL evaporates */
410 mnewsym(int x
, int y
)
417 newscrsym
= news0(x
,y
);
418 if(room
->scrsym
!= newscrsym
) {
419 room
->scrsym
= newscrsym
;
430 if(!isok(x
,y
)) return;
432 if(room
->scrsym
== '.' && !room
->lit
&& !Blind
) {
486 vism_at(int x
, int y
)
490 return((x
== u
.ux
&& y
== u
.uy
&& !Invisible
)
493 ? ((Blind
&& Telepat
) || canseemon(mtmp
)) :
499 pobj(struct obj
*obj
)
501 int show
= (!obj
->oinvis
|| See_invisible
) &&
502 cansee(obj
->ox
,obj
->oy
);
504 if(obj
->odx
!= obj
->ox
|| obj
->ody
!= obj
->oy
|| !show
)
505 if(!vism_at(obj
->odx
,obj
->ody
)){
506 newsym(obj
->odx
, obj
->ody
);
510 if(show
&& !vism_at(obj
->ox
,obj
->oy
)){
511 atl(obj
->ox
,obj
->oy
,obj
->olet
);
520 unpobj(struct obj
*obj
)
522 if(!vism_at(obj
->ox
,obj
->oy
))
523 newsym(obj
->ox
,obj
->oy
);
529 struct obj
*obj
, *obj2
;
530 for(obj
= fobj
; obj
; obj
= obj2
) {
532 if(obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
533 && obj
->age
+ 250 < moves
)
536 for(obj
= invent
; obj
; obj
= obj2
) {
538 if(obj
->olet
== FOOD_SYM
&& obj
->otyp
>= CORPSE
539 && obj
->age
+ 250 < moves
)
548 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
){
549 if(mtmp
->data
->mlet
== ';')
550 mtmp
->minvis
= (u
.ustuck
!= mtmp
&&
551 levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
554 if(mtmp
->wormno
) wormsee(mtmp
->wormno
);
560 pmon(struct monst
*mon
)
562 int show
= (Blind
&& Telepat
) || canseemon(mon
);
564 if(mon
->mdx
!= mon
->mx
|| mon
->mdy
!= mon
->my
|| !show
)
567 if(show
&& !mon
->mdispl
){
570 || u
.uprops
[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS
)].p_flgs
571 ) ? mon
->data
->mlet
: mon
->mappearance
);
579 unpmon(struct monst
*mon
)
582 newsym(mon
->mdx
, mon
->mdy
);
593 if(u
.uswallow
|| u
.ux
== FAR
|| flags
.nscrinh
) return;
595 for(y
= scrly
; y
<= scrhy
; y
++)
596 for(x
= scrlx
; x
<= scrhx
; x
++)
597 if((room
= &levl
[x
][y
])->new) {
599 at(x
,y
,room
->scrsym
);
606 /* 100 suffices for bot(); no relation with COLNO */
607 char oldbot
[100], newbot
[100];
612 if(lth
< (int)sizeof(oldbot
)) {
621 char *ob
= oldbot
, *nb
= newbot
;
623 if(flags
.botlx
) *ob
= 0;
624 flags
.botl
= flags
.botlx
= 0;
627 "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ",
628 dlevel
, u
.ugold
, u
.uhp
, u
.uhpmax
, u
.uac
);
631 "Level %-2d Hp %3d(%d) Ac %-2d Str ",
632 dlevel
, u
.uhp
, u
.uhpmax
, u
.uac
);
633 #endif /* GOLD_ON_BOTL */
636 strcat(newbot
,"18/**");
638 sprintf(eos(newbot
), "18/%02d",u
.ustr
-18);
640 sprintf(eos(newbot
), "%-2d ",u
.ustr
);
642 sprintf(eos(newbot
), " Exp %2d/%-5lu ", u
.ulevel
,u
.uexp
);
644 sprintf(eos(newbot
), " Exp %2u ", u
.ulevel
);
645 #endif /* EXP_ON_BOTL */
646 strcat(newbot
, hu_stat
[u
.uhs
]);
648 sprintf(eos(newbot
), " %ld", moves
);
649 if(strlen(newbot
) >= COLNO
) {
653 if(*bp0
!= ' ' || bp0
[1] != ' ' || bp0
[2] != ' ')
657 for(i
= 1; i
<COLNO
; i
++) {
660 putchar(*nb
? *nb
: ' ');
666 strcpy(oldbot
, newbot
);
671 mstatusline(struct monst
*mtmp
)
673 pline("Status of %s: ", monnam(mtmp
));
674 pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d",
675 mtmp
->data
->mlevel
, mtmp
->mgold
, mtmp
->mhp
, mtmp
->mhpmax
,
676 mtmp
->data
->ac
, (mtmp
->data
->damn
+ 1) * (mtmp
->data
->damd
+ 1));
678 #endif /* WAN_PROBING */
683 if(flags
.toplin
== 1)