1*98eb8895Sroy /* $NetBSD: hack.pri.c,v 1.13 2010/02/03 15:34:38 roy Exp $ */
23ea4a95cSchristos
3210cab45Smycroft /*
41c7f94e5Sjsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
51c7f94e5Sjsm * Amsterdam
61c7f94e5Sjsm * All rights reserved.
71c7f94e5Sjsm *
81c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
91c7f94e5Sjsm * modification, are permitted provided that the following conditions are
101c7f94e5Sjsm * met:
111c7f94e5Sjsm *
121c7f94e5Sjsm * - Redistributions of source code must retain the above copyright notice,
131c7f94e5Sjsm * this list of conditions and the following disclaimer.
141c7f94e5Sjsm *
151c7f94e5Sjsm * - Redistributions in binary form must reproduce the above copyright
161c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
171c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
181c7f94e5Sjsm *
191c7f94e5Sjsm * - Neither the name of the Stichting Centrum voor Wiskunde en
201c7f94e5Sjsm * Informatica, nor the names of its contributors may be used to endorse or
211c7f94e5Sjsm * promote products derived from this software without specific prior
221c7f94e5Sjsm * written permission.
231c7f94e5Sjsm *
241c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
251c7f94e5Sjsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
261c7f94e5Sjsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
271c7f94e5Sjsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
281c7f94e5Sjsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
291c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
301c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
311c7f94e5Sjsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
321c7f94e5Sjsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
331c7f94e5Sjsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
341c7f94e5Sjsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351c7f94e5Sjsm */
361c7f94e5Sjsm
371c7f94e5Sjsm /*
381c7f94e5Sjsm * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
391c7f94e5Sjsm * All rights reserved.
401c7f94e5Sjsm *
411c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
421c7f94e5Sjsm * modification, are permitted provided that the following conditions
431c7f94e5Sjsm * are met:
441c7f94e5Sjsm * 1. Redistributions of source code must retain the above copyright
451c7f94e5Sjsm * notice, this list of conditions and the following disclaimer.
461c7f94e5Sjsm * 2. Redistributions in binary form must reproduce the above copyright
471c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
481c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
491c7f94e5Sjsm * 3. The name of the author may not be used to endorse or promote products
501c7f94e5Sjsm * derived from this software without specific prior written permission.
511c7f94e5Sjsm *
521c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
531c7f94e5Sjsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
541c7f94e5Sjsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
551c7f94e5Sjsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
561c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
571c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
581c7f94e5Sjsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
591c7f94e5Sjsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
601c7f94e5Sjsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
611c7f94e5Sjsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62210cab45Smycroft */
63210cab45Smycroft
643ea4a95cSchristos #include <sys/cdefs.h>
65210cab45Smycroft #ifndef lint
66*98eb8895Sroy __RCSID("$NetBSD: hack.pri.c,v 1.13 2010/02/03 15:34:38 roy Exp $");
67210cab45Smycroft #endif /* not lint */
6861f28255Scgd
6961f28255Scgd #include "hack.h"
703ea4a95cSchristos #include "extern.h"
719b92b189Sdholland
729b92b189Sdholland static xchar scrlx, scrhx, scrly, scrhy; /* corners of new area on
733ea4a95cSchristos * screen */
7461f28255Scgd
759b92b189Sdholland static void cornbot(int);
769b92b189Sdholland
773ea4a95cSchristos void
swallowed(void)781fa8a9a6Sdholland swallowed(void)
7961f28255Scgd {
805559c73bSmycroft char ulook[] = "|@|";
8161f28255Scgd ulook[1] = u.usym;
8261f28255Scgd
8361f28255Scgd cls();
8461f28255Scgd curs(u.ux - 1, u.uy + 1);
8561f28255Scgd fputs("/-\\", stdout);
8661f28255Scgd curx = u.ux + 2;
8761f28255Scgd curs(u.ux - 1, u.uy + 2);
8861f28255Scgd fputs(ulook, stdout);
8961f28255Scgd curx = u.ux + 2;
9061f28255Scgd curs(u.ux - 1, u.uy + 3);
9161f28255Scgd fputs("\\-/", stdout);
9261f28255Scgd curx = u.ux + 2;
9361f28255Scgd u.udispl = 1;
9461f28255Scgd u.udisx = u.ux;
9561f28255Scgd u.udisy = u.uy;
9661f28255Scgd }
9761f28255Scgd
9861f28255Scgd
9961f28255Scgd /* VARARGS1 */
1009b92b189Sdholland static boolean panicking;
10161f28255Scgd
1023ea4a95cSchristos void
panic(const char * fmt,...)1033ea4a95cSchristos panic(const char *fmt, ...)
10461f28255Scgd {
1053ea4a95cSchristos va_list ap;
1067fd8f3dfSwiz
1073ea4a95cSchristos va_start(ap, fmt);
1083ea4a95cSchristos if (panicking++)
1093ea4a95cSchristos exit(1); /* avoid loops - this should never happen */
11061f28255Scgd home();
11161f28255Scgd puts(" Suddenly, the dungeon collapses.");
11261f28255Scgd fputs(" ERROR: ", stdout);
1133ea4a95cSchristos vprintf(fmt, ap);
1143ea4a95cSchristos va_end(ap);
11561f28255Scgd #ifdef DEBUG
11661f28255Scgd #ifdef UNIX
11761f28255Scgd if (!fork())
11861f28255Scgd abort(); /* generate core dump */
1193ea4a95cSchristos #endif /* UNIX */
1203ea4a95cSchristos #endif /* DEBUG */
12161f28255Scgd more(); /* contains a fflush() */
12261f28255Scgd done("panicked");
12361f28255Scgd }
12461f28255Scgd
1253ea4a95cSchristos void
atl(int x,int y,int ch)1261fa8a9a6Sdholland atl(int x, int y, int ch)
12761f28255Scgd {
1283ea4a95cSchristos struct rm *crm = &levl[x][y];
12961f28255Scgd
13061f28255Scgd if (x < 0 || x > COLNO - 1 || y < 0 || y > ROWNO - 1) {
13161f28255Scgd impossible("atl(%d,%d,%c)", x, y, ch);
13261f28255Scgd return;
13361f28255Scgd }
1343ea4a95cSchristos if (crm->seen && crm->scrsym == ch)
1353ea4a95cSchristos return;
13661f28255Scgd crm->scrsym = ch;
13761f28255Scgd crm->new = 1;
13861f28255Scgd on_scr(x, y);
13961f28255Scgd }
14061f28255Scgd
1413ea4a95cSchristos void
on_scr(int x,int y)1421fa8a9a6Sdholland on_scr(int x, int y)
14361f28255Scgd {
1443ea4a95cSchristos if (x < scrlx)
1453ea4a95cSchristos scrlx = x;
1463ea4a95cSchristos if (x > scrhx)
1473ea4a95cSchristos scrhx = x;
1483ea4a95cSchristos if (y < scrly)
1493ea4a95cSchristos scrly = y;
1503ea4a95cSchristos if (y > scrhy)
1513ea4a95cSchristos scrhy = y;
15261f28255Scgd }
15361f28255Scgd
1543ea4a95cSchristos /*
1553ea4a95cSchristos * call: (x,y) - display (-1,0) - close (leave last symbol) (-1,-1)- close
1563ea4a95cSchristos * (undo last symbol) (-1,let)-open: initialize symbol (-2,let)-change let
15761f28255Scgd */
15861f28255Scgd
1593ea4a95cSchristos void
tmp_at(schar x,schar y)1601fa8a9a6Sdholland tmp_at(schar x, schar y)
1613ea4a95cSchristos {
16261f28255Scgd static schar prevx, prevy;
16361f28255Scgd static char let;
16461f28255Scgd if ((int) x == -2) { /* change let call */
16561f28255Scgd let = y;
16661f28255Scgd return;
16761f28255Scgd }
16861f28255Scgd if ((int) x == -1 && (int) y >= 0) { /* open or close call */
16961f28255Scgd let = y;
17061f28255Scgd prevx = -1;
17161f28255Scgd return;
17261f28255Scgd }
17361f28255Scgd if (prevx >= 0 && cansee(prevx, prevy)) {
17461f28255Scgd delay_output();
17561f28255Scgd prl(prevx, prevy); /* in case there was a monster */
17661f28255Scgd at(prevx, prevy, levl[prevx][prevy].scrsym);
17761f28255Scgd }
17861f28255Scgd if (x >= 0) { /* normal call */
1793ea4a95cSchristos if (cansee(x, y))
1803ea4a95cSchristos at(x, y, let);
18161f28255Scgd prevx = x;
18261f28255Scgd prevy = y;
18361f28255Scgd } else { /* close call */
18461f28255Scgd let = 0;
18561f28255Scgd prevx = -1;
18661f28255Scgd }
18761f28255Scgd }
18861f28255Scgd
18961f28255Scgd /* like the previous, but the symbols are first erased on completion */
1903ea4a95cSchristos void
Tmp_at(schar x,schar y)1911fa8a9a6Sdholland Tmp_at(schar x, schar y)
1923ea4a95cSchristos {
19361f28255Scgd static char let;
19461f28255Scgd static xchar cnt;
19561f28255Scgd static coord tc[COLNO]; /* but watch reflecting beams! */
1963ea4a95cSchristos int xx, yy;
19761f28255Scgd if ((int) x == -1) {
19861f28255Scgd if (y > 0) { /* open call */
19961f28255Scgd let = y;
20061f28255Scgd cnt = 0;
20161f28255Scgd return;
20261f28255Scgd }
20361f28255Scgd /* close call (do not distinguish y==0 and y==-1) */
20461f28255Scgd while (cnt--) {
20561f28255Scgd xx = tc[cnt].x;
20661f28255Scgd yy = tc[cnt].y;
20761f28255Scgd prl(xx, yy);
20861f28255Scgd at(xx, yy, levl[xx][yy].scrsym);
20961f28255Scgd }
21061f28255Scgd cnt = let = 0; /* superfluous */
21161f28255Scgd return;
21261f28255Scgd }
21361f28255Scgd if ((int) x == -2) { /* change let call */
21461f28255Scgd let = y;
21561f28255Scgd return;
21661f28255Scgd }
21761f28255Scgd /* normal call */
21861f28255Scgd if (cansee(x, y)) {
2193ea4a95cSchristos if (cnt)
2203ea4a95cSchristos delay_output();
22161f28255Scgd at(x, y, let);
22261f28255Scgd tc[cnt].x = x;
22361f28255Scgd tc[cnt].y = y;
2243ea4a95cSchristos if (++cnt >= COLNO)
2253ea4a95cSchristos panic("Tmp_at overflow?");
22661f28255Scgd levl[x][y].new = 0; /* prevent pline-nscr erasing --- */
22761f28255Scgd }
22861f28255Scgd }
22961f28255Scgd
2303ea4a95cSchristos void
setclipped(void)2311fa8a9a6Sdholland setclipped(void)
2323ea4a95cSchristos {
23361f28255Scgd error("Hack needs a screen of size at least %d by %d.\n",
23461f28255Scgd ROWNO + 2, COLNO);
23561f28255Scgd }
23661f28255Scgd
2373ea4a95cSchristos void
at(xchar x,xchar y,int ch)2381fa8a9a6Sdholland at(xchar x, xchar y, int ch)
23961f28255Scgd {
24061f28255Scgd #ifndef lint
24161f28255Scgd /* if xchar is unsigned, lint will complain about if(x < 0) */
24261f28255Scgd if (x < 0 || x > COLNO - 1 || y < 0 || y > ROWNO - 1) {
24361f28255Scgd impossible("At gets 0%o at %d %d.", ch, x, y);
24461f28255Scgd return;
24561f28255Scgd }
2463ea4a95cSchristos #endif /* lint */
24761f28255Scgd if (!ch) {
24861f28255Scgd impossible("At gets null at %d %d.", x, y);
24961f28255Scgd return;
25061f28255Scgd }
25161f28255Scgd y += 2;
25261f28255Scgd curs(x, y);
25361f28255Scgd (void) putchar(ch);
25461f28255Scgd curx++;
25561f28255Scgd }
25661f28255Scgd
2573ea4a95cSchristos void
prme(void)2581fa8a9a6Sdholland prme(void)
2593ea4a95cSchristos {
2603ea4a95cSchristos if (!Invisible)
2613ea4a95cSchristos at(u.ux, u.uy, u.usym);
26261f28255Scgd }
26361f28255Scgd
2643ea4a95cSchristos int
doredraw(void)2651fa8a9a6Sdholland doredraw(void)
26661f28255Scgd {
26761f28255Scgd docrt();
26861f28255Scgd return (0);
26961f28255Scgd }
27061f28255Scgd
2713ea4a95cSchristos void
docrt(void)2721fa8a9a6Sdholland docrt(void)
27361f28255Scgd {
2743ea4a95cSchristos int x, y;
2753ea4a95cSchristos struct rm *room;
2763ea4a95cSchristos struct monst *mtmp;
27761f28255Scgd
27861f28255Scgd if (u.uswallow) {
27961f28255Scgd swallowed();
28061f28255Scgd return;
28161f28255Scgd }
28261f28255Scgd cls();
28361f28255Scgd
2843ea4a95cSchristos /*
2853ea4a95cSchristos * Some ridiculous code to get display of @ and monsters (almost)
2863ea4a95cSchristos * right
2873ea4a95cSchristos */
28861f28255Scgd if (!Invisible) {
28961f28255Scgd levl[(u.udisx = u.ux)][(u.udisy = u.uy)].scrsym = u.usym;
29061f28255Scgd levl[u.udisx][u.udisy].seen = 1;
29161f28255Scgd u.udispl = 1;
2923ea4a95cSchristos } else
2933ea4a95cSchristos u.udispl = 0;
29461f28255Scgd
29561f28255Scgd seemons(); /* reset old positions */
29661f28255Scgd for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
29761f28255Scgd mtmp->mdispl = 0;
29861f28255Scgd seemons(); /* force new positions to be shown */
2993ea4a95cSchristos /*
3003ea4a95cSchristos * This nonsense should disappear soon
3013ea4a95cSchristos * ---------------------------------
3023ea4a95cSchristos */
30361f28255Scgd
30461f28255Scgd for (y = 0; y < ROWNO; y++)
30561f28255Scgd for (x = 0; x < COLNO; x++)
30661f28255Scgd if ((room = &levl[x][y])->new) {
30761f28255Scgd room->new = 0;
30861f28255Scgd at(x, y, room->scrsym);
30961f28255Scgd } else if (room->seen)
31061f28255Scgd at(x, y, room->scrsym);
31161f28255Scgd scrlx = COLNO;
31261f28255Scgd scrly = ROWNO;
31361f28255Scgd scrhx = scrhy = 0;
31461f28255Scgd flags.botlx = 1;
31561f28255Scgd bot();
31661f28255Scgd }
31761f28255Scgd
3183ea4a95cSchristos void
docorner(int xmin,int ymax)3191fa8a9a6Sdholland docorner(int xmin, int ymax)
3203ea4a95cSchristos {
3213ea4a95cSchristos int x, y;
3223ea4a95cSchristos struct rm *room;
3233ea4a95cSchristos struct monst *mtmp;
32461f28255Scgd
32561f28255Scgd if (u.uswallow) { /* Can be done more efficiently */
32661f28255Scgd swallowed();
32761f28255Scgd return;
32861f28255Scgd }
32961f28255Scgd seemons(); /* reset old positions */
33061f28255Scgd for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
33161f28255Scgd if (mtmp->mx >= xmin && mtmp->my < ymax)
33261f28255Scgd mtmp->mdispl = 0;
33361f28255Scgd seemons(); /* force new positions to be shown */
33461f28255Scgd
33561f28255Scgd for (y = 0; y < ymax; y++) {
3363ea4a95cSchristos if (y > ROWNO && CD)
3373ea4a95cSchristos break;
33861f28255Scgd curs(xmin, y + 2);
33961f28255Scgd cl_end();
34061f28255Scgd if (y < ROWNO) {
34161f28255Scgd for (x = xmin; x < COLNO; x++) {
34261f28255Scgd if ((room = &levl[x][y])->new) {
34361f28255Scgd room->new = 0;
34461f28255Scgd at(x, y, room->scrsym);
3453ea4a95cSchristos } else if (room->seen)
34661f28255Scgd at(x, y, room->scrsym);
34761f28255Scgd }
34861f28255Scgd }
34961f28255Scgd }
35061f28255Scgd if (ymax > ROWNO) {
35161f28255Scgd cornbot(xmin - 1);
35261f28255Scgd if (ymax > ROWNO + 1 && CD) {
35361f28255Scgd curs(1, ROWNO + 3);
35461f28255Scgd cl_eos();
35561f28255Scgd }
35661f28255Scgd }
35761f28255Scgd }
35861f28255Scgd
3593ea4a95cSchristos void
curs_on_u(void)3601fa8a9a6Sdholland curs_on_u(void)
3613ea4a95cSchristos {
36261f28255Scgd curs(u.ux, u.uy + 2);
36361f28255Scgd }
36461f28255Scgd
3653ea4a95cSchristos void
pru(void)3661fa8a9a6Sdholland pru(void)
36761f28255Scgd {
36861f28255Scgd if (u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
36961f28255Scgd /* if(! levl[u.udisx][u.udisy].new) */
37061f28255Scgd if (!vism_at(u.udisx, u.udisy))
37161f28255Scgd newsym(u.udisx, u.udisy);
37261f28255Scgd if (Invisible) {
37361f28255Scgd u.udispl = 0;
37461f28255Scgd prl(u.ux, u.uy);
3753ea4a95cSchristos } else if (!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
37661f28255Scgd atl(u.ux, u.uy, u.usym);
37761f28255Scgd u.udispl = 1;
37861f28255Scgd u.udisx = u.ux;
37961f28255Scgd u.udisy = u.uy;
38061f28255Scgd }
38161f28255Scgd levl[u.ux][u.uy].seen = 1;
38261f28255Scgd }
38361f28255Scgd
38461f28255Scgd #ifndef NOWORM
38561f28255Scgd #include "def.wseg.h"
3863ea4a95cSchristos #endif /* NOWORM */
38761f28255Scgd
38861f28255Scgd /* print a position that is visible for @ */
3893ea4a95cSchristos void
prl(int x,int y)390ab8b6343Sjsm prl(int x, int y)
39161f28255Scgd {
3923ea4a95cSchristos struct rm *room;
3933ea4a95cSchristos struct monst *mtmp;
3943ea4a95cSchristos struct obj *otmp;
39561f28255Scgd
39661f28255Scgd if (x == u.ux && y == u.uy && (!Invisible)) {
39761f28255Scgd pru();
39861f28255Scgd return;
39961f28255Scgd }
4003ea4a95cSchristos if (!isok(x, y))
4013ea4a95cSchristos return;
40261f28255Scgd room = &levl[x][y];
40361f28255Scgd if ((!room->typ) ||
40461f28255Scgd (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR))
40561f28255Scgd return;
40661f28255Scgd if ((mtmp = m_at(x, y)) && !mtmp->mhide &&
40761f28255Scgd (!mtmp->minvis || See_invisible)) {
40861f28255Scgd #ifndef NOWORM
40961f28255Scgd if (m_atseg)
41061f28255Scgd pwseg(m_atseg);
41161f28255Scgd else
4123ea4a95cSchristos #endif /* NOWORM */
41361f28255Scgd pmon(mtmp);
4143ea4a95cSchristos } else if ((otmp = o_at(x, y)) && room->typ != POOL)
41561f28255Scgd atl(x, y, otmp->olet);
41661f28255Scgd else if (mtmp && (!mtmp->minvis || See_invisible)) {
41761f28255Scgd /* must be a hiding monster, but not hiding right now */
41861f28255Scgd /* assume for the moment that long worms do not hide */
41961f28255Scgd pmon(mtmp);
4203ea4a95cSchristos } else if (g_at(x, y) && room->typ != POOL)
42161f28255Scgd atl(x, y, '$');
42261f28255Scgd else if (!room->seen || room->scrsym == ' ') {
42361f28255Scgd room->new = room->seen = 1;
42461f28255Scgd newsym(x, y);
42561f28255Scgd on_scr(x, y);
42661f28255Scgd }
42761f28255Scgd room->seen = 1;
42861f28255Scgd }
42961f28255Scgd
43061f28255Scgd char
news0(xchar x,xchar y)4311fa8a9a6Sdholland news0(xchar x, xchar y)
43261f28255Scgd {
4333ea4a95cSchristos struct obj *otmp;
4343ea4a95cSchristos struct trap *ttmp;
43561f28255Scgd struct rm *room;
4363ea4a95cSchristos char tmp;
43761f28255Scgd
43861f28255Scgd room = &levl[x][y];
4393ea4a95cSchristos if (!room->seen)
4403ea4a95cSchristos tmp = ' ';
4413ea4a95cSchristos else if (room->typ == POOL)
4423ea4a95cSchristos tmp = POOL_SYM;
4433ea4a95cSchristos else if (!Blind && (otmp = o_at(x, y)))
4443ea4a95cSchristos tmp = otmp->olet;
4453ea4a95cSchristos else if (!Blind && g_at(x, y))
4463ea4a95cSchristos tmp = '$';
4473ea4a95cSchristos else if (x == xupstair && y == yupstair)
4483ea4a95cSchristos tmp = '<';
4493ea4a95cSchristos else if (x == xdnstair && y == ydnstair)
4503ea4a95cSchristos tmp = '>';
4513ea4a95cSchristos else if ((ttmp = t_at(x, y)) && ttmp->tseen)
4523ea4a95cSchristos tmp = '^';
4533ea4a95cSchristos else
4543ea4a95cSchristos switch (room->typ) {
45561f28255Scgd case SCORR:
45661f28255Scgd case SDOOR:
4573ea4a95cSchristos tmp = room->scrsym; /* %% wrong after killing
4583ea4a95cSchristos * mimic ! */
45961f28255Scgd break;
46061f28255Scgd case HWALL:
46161f28255Scgd tmp = '-';
46261f28255Scgd break;
46361f28255Scgd case VWALL:
46461f28255Scgd tmp = '|';
46561f28255Scgd break;
46661f28255Scgd case LDOOR:
46761f28255Scgd case DOOR:
46861f28255Scgd tmp = '+';
46961f28255Scgd break;
47061f28255Scgd case CORR:
47161f28255Scgd tmp = CORR_SYM;
47261f28255Scgd break;
47361f28255Scgd case ROOM:
4743ea4a95cSchristos if (room->lit || cansee(x, y) || Blind)
4753ea4a95cSchristos tmp = '.';
4763ea4a95cSchristos else
4773ea4a95cSchristos tmp = ' ';
47861f28255Scgd break;
47961f28255Scgd /*
48061f28255Scgd case POOL:
48161f28255Scgd tmp = POOL_SYM;
48261f28255Scgd break;
48361f28255Scgd */
48461f28255Scgd default:
48561f28255Scgd tmp = ERRCHAR;
48661f28255Scgd }
48761f28255Scgd return (tmp);
48861f28255Scgd }
48961f28255Scgd
4903ea4a95cSchristos void
newsym(int x,int y)4911fa8a9a6Sdholland newsym(int x, int y)
49261f28255Scgd {
49361f28255Scgd atl(x, y, news0(x, y));
49461f28255Scgd }
49561f28255Scgd
49661f28255Scgd /* used with wand of digging (or pick-axe): fill scrsym and force display */
49761f28255Scgd /* also when a POOL evaporates */
4983ea4a95cSchristos void
mnewsym(int x,int y)4991fa8a9a6Sdholland mnewsym(int x, int y)
50061f28255Scgd {
5013ea4a95cSchristos struct rm *room;
50261f28255Scgd char newscrsym;
50361f28255Scgd
50461f28255Scgd if (!vism_at(x, y)) {
50561f28255Scgd room = &levl[x][y];
50661f28255Scgd newscrsym = news0(x, y);
50761f28255Scgd if (room->scrsym != newscrsym) {
50861f28255Scgd room->scrsym = newscrsym;
50961f28255Scgd room->seen = 0;
51061f28255Scgd }
51161f28255Scgd }
51261f28255Scgd }
51361f28255Scgd
5143ea4a95cSchristos void
nosee(int x,int y)5151fa8a9a6Sdholland nosee(int x, int y)
51661f28255Scgd {
5173ea4a95cSchristos struct rm *room;
51861f28255Scgd
5193ea4a95cSchristos if (!isok(x, y))
5203ea4a95cSchristos return;
52161f28255Scgd room = &levl[x][y];
52261f28255Scgd if (room->scrsym == '.' && !room->lit && !Blind) {
52361f28255Scgd room->scrsym = ' ';
52461f28255Scgd room->new = 1;
52561f28255Scgd on_scr(x, y);
52661f28255Scgd }
52761f28255Scgd }
52861f28255Scgd
52961f28255Scgd #ifndef QUEST
5303ea4a95cSchristos void
prl1(int x,int y)5311fa8a9a6Sdholland prl1(int x, int y)
53261f28255Scgd {
53361f28255Scgd if (u.dx) {
53461f28255Scgd if (u.dy) {
53561f28255Scgd prl(x - (2 * u.dx), y);
53661f28255Scgd prl(x - u.dx, y);
53761f28255Scgd prl(x, y);
53861f28255Scgd prl(x, y - u.dy);
53961f28255Scgd prl(x, y - (2 * u.dy));
54061f28255Scgd } else {
54161f28255Scgd prl(x, y - 1);
54261f28255Scgd prl(x, y);
54361f28255Scgd prl(x, y + 1);
54461f28255Scgd }
54561f28255Scgd } else {
54661f28255Scgd prl(x - 1, y);
54761f28255Scgd prl(x, y);
54861f28255Scgd prl(x + 1, y);
54961f28255Scgd }
55061f28255Scgd }
55161f28255Scgd
5523ea4a95cSchristos void
nose1(int x,int y)5531fa8a9a6Sdholland nose1(int x, int y)
55461f28255Scgd {
55561f28255Scgd if (u.dx) {
55661f28255Scgd if (u.dy) {
55761f28255Scgd nosee(x, u.uy);
55861f28255Scgd nosee(x, u.uy - u.dy);
55961f28255Scgd nosee(x, y);
56061f28255Scgd nosee(u.ux - u.dx, y);
56161f28255Scgd nosee(u.ux, y);
56261f28255Scgd } else {
56361f28255Scgd nosee(x, y - 1);
56461f28255Scgd nosee(x, y);
56561f28255Scgd nosee(x, y + 1);
56661f28255Scgd }
56761f28255Scgd } else {
56861f28255Scgd nosee(x - 1, y);
56961f28255Scgd nosee(x, y);
57061f28255Scgd nosee(x + 1, y);
57161f28255Scgd }
57261f28255Scgd }
5733ea4a95cSchristos #endif /* QUEST */
57461f28255Scgd
5753ea4a95cSchristos int
vism_at(int x,int y)5761fa8a9a6Sdholland vism_at(int x, int y)
57761f28255Scgd {
5783ea4a95cSchristos struct monst *mtmp;
57961f28255Scgd
58061f28255Scgd return ((x == u.ux && y == u.uy && !Invisible)
58161f28255Scgd ? 1 :
58261f28255Scgd (mtmp = m_at(x, y))
58361f28255Scgd ? ((Blind && Telepat) || canseemon(mtmp)) :
58461f28255Scgd 0);
58561f28255Scgd }
58661f28255Scgd
58761f28255Scgd #ifdef NEWSCR
5883ea4a95cSchristos void
pobj(struct obj * obj)5891fa8a9a6Sdholland pobj(struct obj *obj)
5903ea4a95cSchristos {
5913ea4a95cSchristos int show = (!obj->oinvis || See_invisible) &&
59261f28255Scgd cansee(obj->ox, obj->oy);
59361f28255Scgd if (obj->odispl) {
59461f28255Scgd if (obj->odx != obj->ox || obj->ody != obj->oy || !show)
59561f28255Scgd if (!vism_at(obj->odx, obj->ody)) {
59661f28255Scgd newsym(obj->odx, obj->ody);
59761f28255Scgd obj->odispl = 0;
59861f28255Scgd }
59961f28255Scgd }
60061f28255Scgd if (show && !vism_at(obj->ox, obj->oy)) {
60161f28255Scgd atl(obj->ox, obj->oy, obj->olet);
60261f28255Scgd obj->odispl = 1;
60361f28255Scgd obj->odx = obj->ox;
60461f28255Scgd obj->ody = obj->oy;
60561f28255Scgd }
60661f28255Scgd }
6073ea4a95cSchristos #endif /* NEWSCR */
60861f28255Scgd
6093ea4a95cSchristos void
unpobj(struct obj * obj)6101fa8a9a6Sdholland unpobj(struct obj *obj)
6113ea4a95cSchristos {
6123ea4a95cSchristos /*
6133ea4a95cSchristos * if(obj->odispl){ if(!vism_at(obj->odx, obj->ody)) newsym(obj->odx,
6143ea4a95cSchristos * obj->ody); obj->odispl = 0; }
61561f28255Scgd */
61661f28255Scgd if (!vism_at(obj->ox, obj->oy))
61761f28255Scgd newsym(obj->ox, obj->oy);
61861f28255Scgd }
61961f28255Scgd
6203ea4a95cSchristos void
seeobjs(void)6211fa8a9a6Sdholland seeobjs(void)
6223ea4a95cSchristos {
6233ea4a95cSchristos struct obj *obj, *obj2;
62461f28255Scgd for (obj = fobj; obj; obj = obj2) {
62561f28255Scgd obj2 = obj->nobj;
62661f28255Scgd if (obj->olet == FOOD_SYM && obj->otyp >= CORPSE
62761f28255Scgd && obj->age + 250 < moves)
62861f28255Scgd delobj(obj);
62961f28255Scgd }
63061f28255Scgd for (obj = invent; obj; obj = obj2) {
63161f28255Scgd obj2 = obj->nobj;
63261f28255Scgd if (obj->olet == FOOD_SYM && obj->otyp >= CORPSE
63361f28255Scgd && obj->age + 250 < moves)
63461f28255Scgd useup(obj);
63561f28255Scgd }
63661f28255Scgd }
63761f28255Scgd
6383ea4a95cSchristos void
seemons(void)6391fa8a9a6Sdholland seemons(void)
6403ea4a95cSchristos {
6413ea4a95cSchristos struct monst *mtmp;
64261f28255Scgd for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
64361f28255Scgd if (mtmp->data->mlet == ';')
64461f28255Scgd mtmp->minvis = (u.ustuck != mtmp &&
64561f28255Scgd levl[mtmp->mx][mtmp->my].typ == POOL);
64661f28255Scgd pmon(mtmp);
64761f28255Scgd #ifndef NOWORM
6483ea4a95cSchristos if (mtmp->wormno)
6493ea4a95cSchristos wormsee(mtmp->wormno);
6503ea4a95cSchristos #endif /* NOWORM */
65161f28255Scgd }
65261f28255Scgd }
65361f28255Scgd
6543ea4a95cSchristos void
pmon(struct monst * mon)6551fa8a9a6Sdholland pmon(struct monst *mon)
6563ea4a95cSchristos {
6573ea4a95cSchristos int show = (Blind && Telepat) || canseemon(mon);
65861f28255Scgd if (mon->mdispl) {
65961f28255Scgd if (mon->mdx != mon->mx || mon->mdy != mon->my || !show)
66061f28255Scgd unpmon(mon);
66161f28255Scgd }
66261f28255Scgd if (show && !mon->mdispl) {
66361f28255Scgd atl(mon->mx, mon->my,
66461f28255Scgd (!mon->mappearance
66561f28255Scgd || u.uprops[PROP(RIN_PROTECTION_FROM_SHAPE_CHANGERS)].p_flgs
66661f28255Scgd ) ? mon->data->mlet : mon->mappearance);
66761f28255Scgd mon->mdispl = 1;
66861f28255Scgd mon->mdx = mon->mx;
66961f28255Scgd mon->mdy = mon->my;
67061f28255Scgd }
67161f28255Scgd }
67261f28255Scgd
6733ea4a95cSchristos void
unpmon(struct monst * mon)6741fa8a9a6Sdholland unpmon(struct monst *mon)
6753ea4a95cSchristos {
67661f28255Scgd if (mon->mdispl) {
67761f28255Scgd newsym(mon->mdx, mon->mdy);
67861f28255Scgd mon->mdispl = 0;
67961f28255Scgd }
68061f28255Scgd }
68161f28255Scgd
6823ea4a95cSchristos void
nscr(void)6831fa8a9a6Sdholland nscr(void)
68461f28255Scgd {
6853ea4a95cSchristos int x, y;
6863ea4a95cSchristos struct rm *room;
68761f28255Scgd
6883ea4a95cSchristos if (u.uswallow || u.ux == FAR || flags.nscrinh)
6893ea4a95cSchristos return;
69061f28255Scgd pru();
69161f28255Scgd for (y = scrly; y <= scrhy; y++)
69261f28255Scgd for (x = scrlx; x <= scrhx; x++)
69361f28255Scgd if ((room = &levl[x][y])->new) {
69461f28255Scgd room->new = 0;
69561f28255Scgd at(x, y, room->scrsym);
69661f28255Scgd }
69761f28255Scgd scrhx = scrhy = 0;
69861f28255Scgd scrlx = COLNO;
69961f28255Scgd scrly = ROWNO;
70061f28255Scgd }
70161f28255Scgd
70261f28255Scgd /* 100 suffices for bot(); no relation with COLNO */
7039b92b189Sdholland static char oldbot[100], newbot[100];
7043ea4a95cSchristos void
cornbot(int lth)7051fa8a9a6Sdholland cornbot(int lth)
70661f28255Scgd {
7073c439f43Sdholland if ((unsigned)lth < sizeof(oldbot)) {
70861f28255Scgd oldbot[lth] = 0;
70961f28255Scgd flags.botl = 1;
71061f28255Scgd }
71161f28255Scgd }
71261f28255Scgd
7133ea4a95cSchristos void
bot(void)7141fa8a9a6Sdholland bot(void)
71561f28255Scgd {
7163ea4a95cSchristos char *ob = oldbot, *nb = newbot;
7173ea4a95cSchristos int i;
718907fca1bSdholland size_t pos;
719907fca1bSdholland
7203ea4a95cSchristos if (flags.botlx)
7213ea4a95cSchristos *ob = 0;
72261f28255Scgd flags.botl = flags.botlx = 0;
72361f28255Scgd #ifdef GOLD_ON_BOTL
724907fca1bSdholland (void) snprintf(newbot, sizeof(newbot),
72561f28255Scgd "Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Str ",
72661f28255Scgd dlevel, u.ugold, u.uhp, u.uhpmax, u.uac);
72761f28255Scgd #else
728907fca1bSdholland (void) snprintf(newbot, sizeof(newbot),
72961f28255Scgd "Level %-2d Hp %3d(%d) Ac %-2d Str ",
73061f28255Scgd dlevel, u.uhp, u.uhpmax, u.uac);
7313ea4a95cSchristos #endif /* GOLD_ON_BOTL */
73261f28255Scgd if (u.ustr > 18) {
73361f28255Scgd if (u.ustr > 117)
734907fca1bSdholland (void) strlcat(newbot, "18/**", sizeof(newbot));
735907fca1bSdholland else {
736907fca1bSdholland pos = strlen(newbot);
737907fca1bSdholland (void) snprintf(newbot+pos, sizeof(newbot)-pos,
738907fca1bSdholland "18/%02d", u.ustr - 18);
739907fca1bSdholland }
740907fca1bSdholland } else {
741907fca1bSdholland pos = strlen(newbot);
742907fca1bSdholland (void) snprintf(newbot+pos, sizeof(newbot)-pos,
743907fca1bSdholland "%-2d ", u.ustr);
744907fca1bSdholland }
745907fca1bSdholland pos = strlen(newbot);
74661f28255Scgd #ifdef EXP_ON_BOTL
747907fca1bSdholland (void) snprintf(newbot+pos, sizeof(newbot)-pos,
748907fca1bSdholland " Exp %2d/%-5lu ", u.ulevel, u.uexp);
74961f28255Scgd #else
750907fca1bSdholland (void) snprintf(newbot+pos, sizeof(newbot)-pos,
751907fca1bSdholland " Exp %2u ", u.ulevel);
7523ea4a95cSchristos #endif /* EXP_ON_BOTL */
753907fca1bSdholland (void) strlcat(newbot, hu_stat[u.uhs], sizeof(newbot));
754907fca1bSdholland if (flags.time) {
755907fca1bSdholland pos = strlen(newbot);
756907fca1bSdholland (void) snprintf(newbot+pos, sizeof(newbot)-pos,
757907fca1bSdholland " %ld", moves);
758907fca1bSdholland }
75961f28255Scgd if (strlen(newbot) >= COLNO) {
7603ea4a95cSchristos char *bp0, *bp1;
76161f28255Scgd bp0 = bp1 = newbot;
76261f28255Scgd do {
76361f28255Scgd if (*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ')
76461f28255Scgd *bp1++ = *bp0;
76561f28255Scgd } while (*bp0++);
76661f28255Scgd }
76761f28255Scgd for (i = 1; i < COLNO; i++) {
76861f28255Scgd if (*ob != *nb) {
76961f28255Scgd curs(i, ROWNO + 2);
77061f28255Scgd (void) putchar(*nb ? *nb : ' ');
77161f28255Scgd curx++;
77261f28255Scgd }
7733ea4a95cSchristos if (*ob)
7743ea4a95cSchristos ob++;
7753ea4a95cSchristos if (*nb)
7763ea4a95cSchristos nb++;
77761f28255Scgd }
77861f28255Scgd (void) strcpy(oldbot, newbot);
77961f28255Scgd }
78061f28255Scgd
78161f28255Scgd #ifdef WAN_PROBING
7823ea4a95cSchristos void
mstatusline(struct monst * mtmp)7831fa8a9a6Sdholland mstatusline(struct monst *mtmp)
7843ea4a95cSchristos {
78561f28255Scgd pline("Status of %s: ", monnam(mtmp));
78661f28255Scgd pline("Level %-2d Gold %-5lu Hp %3d(%d) Ac %-2d Dam %d",
78761f28255Scgd mtmp->data->mlevel, mtmp->mgold, mtmp->mhp, mtmp->mhpmax,
78861f28255Scgd mtmp->data->ac, (mtmp->data->damn + 1) * (mtmp->data->damd + 1));
78961f28255Scgd }
7903ea4a95cSchristos #endif /* WAN_PROBING */
79161f28255Scgd
7923ea4a95cSchristos void
cls(void)7931fa8a9a6Sdholland cls(void)
7943ea4a95cSchristos {
79561f28255Scgd if (flags.toplin == 1)
79661f28255Scgd more();
79761f28255Scgd flags.toplin = 0;
79861f28255Scgd
799*98eb8895Sroy clearscreen();
80061f28255Scgd
80161f28255Scgd flags.botlx = 1;
80261f28255Scgd }
803