1 /* NetHack 3.6 display.c $NHDT-Date: 1446808439 2015/11/06 11:13:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.77 $ */
2 /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
3 /* and Dave Cohrs, 1990. */
4 /* NetHack may be freely redistributed. See license for details. */
9 * The old display code has been broken up into three parts: vision, display,
10 * and drawing. Vision decides what locations can and cannot be physically
11 * seen by the hero. Display decides _what_ is displayed at a given location.
12 * Drawing decides _how_ to draw a monster, fountain, sword, etc.
14 * The display system uses information from the vision system to decide
15 * what to draw at a given location. The routines for the vision system
16 * can be found in vision.c and vision.h. The routines for display can
17 * be found in this file (display.c) and display.h. The drawing routines
18 * are part of the window port. See doc/window.doc for the drawing
21 * The display system deals with an abstraction called a glyph. Anything
22 * that could possibly be displayed has a unique glyph identifier.
24 * What is seen on the screen is a combination of what the hero remembers
25 * and what the hero currently sees. Objects and dungeon features (walls
26 * doors, etc) are remembered when out of sight. Monsters and temporary
27 * effects are not remembered. Each location on the level has an
28 * associated glyph. This is the hero's _memory_ of what he or she has
33 * If the location is in sight, display in order:
34 * visible (or sensed) monsters
39 * If the location is out of sight, display in order:
40 * sensed monsters (telepathy)
45 * Here is a list of the major routines in this file to be used externally:
49 * Possibly update the screen location (x,y). This is the workhorse routine.
50 * It is always correct --- where correct means following the in-sight/out-
51 * of-sight rules. **Most of the code should use this routine.** This
52 * routine updates the map and displays monsters.
61 * If you absolutely must override the in-sight/out-of-sight rules, there
62 * are two possibilities. First, you can mess with vision to force the
63 * location in sight then use newsym(), or you can use the map_* routines.
64 * The first has not been tried [no need] and the second is used in the
65 * detect routines --- detect object, magic mapping, etc. The map_*
66 * routines *change* what the hero remembers. All changes made by these
67 * routines will be sticky --- they will survive screen redraws. Do *not*
68 * use these for things that only temporarily change the screen. These
69 * routines are also used directly by newsym(). unmap_object is used to
70 * clear a remembered object when/if detection reveals it isn't there.
75 * This is direct (no processing in between) buffered access to the screen.
76 * Temporary screen effects are run through this and its companion,
77 * flush_screen(). There is yet a lower level routine, print_glyph(),
78 * but this is unbuffered and graphic dependent (i.e. it must be surrounded
79 * by graphic set-up and tear-down routines). Do not use print_glyph().
86 * These are only used when something affects all of the monsters or
87 * objects or traps. For objects and traps, the only thing is hallucination.
88 * For monsters, there are hallucination and changing from/to blindness, etc.
93 * This is a useful interface for displaying temporary items on the screen.
94 * Its interface is different than previously, so look at it carefully.
98 * Parts of the rm structure that are used:
100 * typ - What is really there.
101 * glyph - What the hero remembers. This will never be a monster.
102 * Monsters "float" above this.
103 * lit - True if the position is lit. An optimization for
105 * waslit - True if the position was *remembered* as lit.
106 * seenv - A vector of bits representing the directions from which the
107 * hero has seen this position. The vector's primary use is
108 * determining how walls are seen. E.g. a wall sometimes looks
109 * like stone on one side, but is seen as wall from the other.
110 * Other uses are for unmapping detected objects and felt
111 * locations, where we need to know if the hero has ever
113 * flags - Additional information for the typ field. Different for
115 * horizontal - Indicates whether the wall or door is horizontal or
120 STATIC_DCL void FDECL(display_monster,
121 (XCHAR_P, XCHAR_P, struct monst *, int, XCHAR_P));
122 STATIC_DCL int FDECL(swallow_to_glyph, (int, int));
123 STATIC_DCL void FDECL(display_warning, (struct monst *));
125 STATIC_DCL int FDECL(check_pos, (int, int, int));
126 STATIC_DCL int FDECL(get_bk_glyph, (XCHAR_P, XCHAR_P));
128 /*#define WA_VERBOSE*/ /* give (x,y) locations for all "bad" spots */
130 STATIC_DCL boolean FDECL(more_than_one, (int, int, int, int, int));
133 STATIC_DCL int FDECL(set_twall, (int, int, int, int, int, int, int, int));
134 STATIC_DCL int FDECL(set_wall, (int, int, int));
135 STATIC_DCL int FDECL(set_corn, (int, int, int, int, int, int, int, int));
136 STATIC_DCL int FDECL(set_crosswall, (int, int));
137 STATIC_DCL void FDECL(set_seenv, (struct rm *, int, int, int, int));
138 STATIC_DCL void FDECL(t_warn, (struct rm *));
139 STATIC_DCL int FDECL(wall_angle, (struct rm *));
141 #define remember_topology(x, y) (lastseentyp[x][y] = levl[x][y].typ)
144 * magic_map_background()
146 * This function is similar to map_background (see below) except we pay
147 * attention to and correct unexplored, lit ROOM and CORR spots.
150 magic_map_background(x, y, show)
154 int glyph = back_to_glyph(x, y); /* assumes hero can see x,y */
155 struct rm *lev = &levl[x][y];
158 * Correct for out of sight lit corridors and rooms that the hero
159 * doesn't remember as lit.
161 if (!cansee(x, y) && !lev->waslit) {
162 /* Floor spaces are dark if unlit. Corridors are dark if unlit. */
163 if (lev->typ == ROOM && glyph == cmap_to_glyph(S_room))
164 glyph = cmap_to_glyph((flags.dark_room && iflags.use_color)
167 else if (lev->typ == CORR && glyph == cmap_to_glyph(S_litcorr))
168 glyph = cmap_to_glyph(S_corr);
170 if (level.flags.hero_memory)
173 show_glyph(x, y, glyph);
175 remember_topology(x, y);
179 * The routines map_background(), map_object(), and map_trap() could just
182 * map_glyph(x,y,glyph,show)
184 * Which is called with the xx_to_glyph() in the call. Then I can get
185 * rid of 3 routines that don't do very much anyway. And then stop
186 * having to create fake objects and traps. However, I am reluctant to
189 /* FIXME: some of these use xchars for x and y, and some use ints. Make
196 * Make the real background part of our map. This routine assumes that
197 * the hero can physically see the location. Update the screen if directed.
200 map_background(x, y, show)
204 register int glyph = back_to_glyph(x, y);
206 if (level.flags.hero_memory)
207 levl[x][y].glyph = glyph;
209 show_glyph(x, y, glyph);
215 * Map the trap and print it out if directed. This routine assumes that the
216 * hero can physically see the location.
220 register struct trap *trap;
223 register int x = trap->tx, y = trap->ty;
224 register int glyph = trap_to_glyph(trap);
226 if (level.flags.hero_memory)
227 levl[x][y].glyph = glyph;
229 show_glyph(x, y, glyph);
235 * Map the given object. This routine assumes that the hero can physically
236 * see the location of the object. Update the screen if directed.
239 map_object(obj, show)
240 register struct obj *obj;
243 register int x = obj->ox, y = obj->oy;
244 register int glyph = obj_to_glyph(obj);
246 if (level.flags.hero_memory) {
247 /* MRKR: While hallucinating, statues are seen as random monsters */
248 /* but remembered as random objects. */
250 if (Hallucination && obj->otyp == STATUE) {
251 levl[x][y].glyph = random_obj_to_glyph();
253 levl[x][y].glyph = glyph;
257 show_glyph(x, y, glyph);
263 * Make the hero remember that a square contains an invisible monster.
264 * This is a special case in that the square will continue to be displayed
265 * this way even when the hero is close enough to see it. To get rid of
266 * this and display the square's actual contents, use unmap_object() followed
267 * by newsym() if necessary.
273 if (x != u.ux || y != u.uy) { /* don't display I at hero's location */
274 if (level.flags.hero_memory)
275 levl[x][y].glyph = GLYPH_INVISIBLE;
276 show_glyph(x, y, GLYPH_INVISIBLE);
283 * Remove something from the map when the hero realizes it's not there any
284 * more. Replace it with background or known trap, but not with any other
285 * If this is used for detection, a full screen update is imminent anyway;
286 * if this is used to get rid of an invisible monster notation, we might have
293 register struct trap *trap;
295 if (!level.flags.hero_memory)
298 if ((trap = t_at(x, y)) != 0 && trap->tseen && !covers_traps(x, y))
300 else if (levl[x][y].seenv) {
301 struct rm *lev = &levl[x][y];
303 map_background(x, y, 0);
305 /* turn remembered dark room squares dark */
306 if (!lev->waslit && lev->glyph == cmap_to_glyph(S_room)
308 lev->glyph = cmap_to_glyph(S_stone);
310 levl[x][y].glyph = cmap_to_glyph(S_stone); /* default val */
316 * Make whatever at this location show up. This is only for non-living
317 * things. This will not handle feeling invisible objects correctly.
319 * Internal to display.c, this is a #define for speed.
321 #define _map_location(x, y, show) \
323 register struct obj *obj; \
324 register struct trap *trap; \
326 if ((obj = vobj_at(x, y)) && !covers_objects(x, y)) \
327 map_object(obj, show); \
328 else if ((trap = t_at(x, y)) && trap->tseen && !covers_traps(x, y)) \
329 map_trap(trap, show); \
331 map_background(x, y, show); \
333 remember_topology(x, y); \
337 map_location(x, y, show)
340 _map_location(x, y, show);
344 #define PHYSICALLY_SEEN 1
345 #define is_worm_tail(mon) ((mon) && ((x != (mon)->mx) || (y != (mon)->my)))
350 * Note that this is *not* a map_XXXX() function! Monsters sort of float
353 * Yuck. Display body parts by recognizing that the display position is
354 * not the same as the monster position. Currently the only body part is
359 display_monster(x, y, mon, sightflags, worm_tail)
360 register xchar x, y; /* display position */
361 register struct monst *mon; /* monster to display */
362 int sightflags; /* 1 if the monster is physically seen;
363 2 if detected using Detect_monsters */
364 xchar worm_tail; /* mon is actually a worm tail */
366 boolean mon_mimic = (mon->m_ap_type != M_AP_NOTHING);
367 int sensed = (mon_mimic && (Protection_from_shape_changers
370 * We must do the mimic check first. If the mimic is mimicing something,
371 * and the location is in sight, we have to change the hero's memory
372 * so that when the position is out of sight, the hero remembers what
373 * the mimic was mimicing.
376 if (mon_mimic && (sightflags == PHYSICALLY_SEEN)) {
377 switch (mon->m_ap_type) {
379 impossible("display_monster: bad m_ap_type value [ = %d ]",
380 (int) mon->m_ap_type);
382 show_glyph(x, y, mon_to_glyph(mon));
385 case M_AP_FURNITURE: {
387 * This is a poor man's version of map_background(). I can't
388 * use map_background() because we are overriding what is in
389 * the 'typ' field. Maybe have map_background()'s parameters
390 * be (x,y,glyph) instead of just (x,y).
392 * mappearance is currently set to an S_ index value in
395 int sym = mon->mappearance, glyph = cmap_to_glyph(sym);
397 levl[x][y].glyph = glyph;
399 show_glyph(x, y, glyph);
400 /* override real topology with mimic's fake one */
401 lastseentyp[x][y] = cmap_to_type(sym);
407 /* Make a fake object to send to map_object(). */
413 obj.otyp = mon->mappearance;
414 /* might be mimicing a corpse or statue */
415 obj.corpsenm = has_mcorpsenm(mon) ? MCORPSENM(mon) : PM_TENGU;
416 map_object(&obj, !sensed);
422 monnum_to_glyph(what_mon((int) mon->mappearance)));
427 /* If the mimic is unsuccessfully mimicing something, display the monster
429 if (!mon_mimic || sensed) {
432 /* [ALI] Only use detected glyphs when monster wouldn't be
433 * visible by any other means.
435 if (sightflags == DETECTED && !mon->mtame) {
437 num = detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
439 num = detected_mon_to_glyph(mon);
440 } else if (mon->mtame && !Hallucination) {
442 num = petnum_to_glyph(PM_LONG_WORM_TAIL);
444 num = pet_to_glyph(mon);
447 num = monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
449 num = mon_to_glyph(mon);
451 show_glyph(x, y, num);
458 * This is also *not* a map_XXXX() function! Monster warnings float
459 * above everything just like monsters do, but only if the monster
462 * Do not call for worm tails.
466 register struct monst *mon;
468 int x = mon->mx, y = mon->my;
469 int wl = (int) (mon->m_lev / 4);
472 if (mon_warning(mon)) {
473 if (wl > WARNCOUNT - 1)
475 /* 3.4.1: this really ought to be rn2(WARNCOUNT), but value "0"
476 isn't handled correctly by the what_is routine so avoid it */
478 wl = rn1(WARNCOUNT - 1, 1);
479 glyph = warning_to_glyph(wl);
480 } else if (MATCH_WARN_OF_MON(mon)) {
481 glyph = mon_to_glyph(mon);
483 impossible("display_warning did not match warning type?");
486 show_glyph(x, y, glyph);
493 * When hero knows what happened to location, even when blind.
509 * Feel the given location. This assumes that the hero is blind and that
510 * the given position is either the hero's or one of the eight squares
511 * adjacent to the hero (except for a boulder push).
512 * If an invisible monster has gone away, that will be discovered. If an
513 * invisible monster has appeared, this will _not_ be discovered since
514 * searching only finds one monster per turn so we must check that separately.
522 register struct monst *mon;
527 /* If the hero's memory of an invisible monster is accurate, we want to
529 * him from detecting the same monster over and over again on each turn.
530 * We must return (so we don't erase the monster). (We must also, in the
531 * search function, be sure to skip over previously detected 'I's.)
533 if (glyph_is_invisible(lev->glyph) && m_at(x, y))
536 /* The hero can't feel non pool locations while under water. */
537 if (Underwater && !Is_waterlevel(&u.uz) && !is_pool(x, y))
540 /* Set the seen vector as if the hero had seen it.
541 It doesn't matter if the hero is levitating or not. */
542 set_seenv(lev, u.ux, u.uy, x, y);
544 if (!can_reach_floor(FALSE)) {
546 * Levitation Rules. It is assumed that the hero can feel the state
547 * of the walls around herself and can tell if she is in a corridor,
548 * room, or doorway. Boulders are felt because they are large enough.
549 * Anything else is unknown because the hero can't reach the ground.
550 * This makes things difficult.
552 * Check (and display) in order:
554 * + Stone, walls, and closed doors.
555 * + Boulders. [see a boulder before a doorway]
557 * + Room/water positions
558 * + Everything else (hallways!)
560 if (IS_ROCK(lev->typ)
561 || (IS_DOOR(lev->typ)
562 && (lev->doormask & (D_LOCKED | D_CLOSED)))) {
563 map_background(x, y, 1);
564 } else if ((boulder = sobj_at(BOULDER, x, y)) != 0) {
565 map_object(boulder, 1);
566 } else if (IS_DOOR(lev->typ)) {
567 map_background(x, y, 1);
568 } else if (IS_ROOM(lev->typ) || IS_POOL(lev->typ)) {
570 * An open room or water location. Normally we wouldn't touch
571 * this, but we have to get rid of remembered boulder symbols.
572 * This will only occur in rare occasions when the hero goes
573 * blind and doesn't find a boulder where expected (something
574 * came along and picked it up). We know that there is not a
575 * boulder at this location. Show fountains, pools, etc.
576 * underneath if already seen. Otherwise, show the appropriate
579 * Similarly, if the hero digs a hole in a wall or feels a
581 * that used to contain an unseen monster. In these cases,
582 * there's no reason to assume anything was underneath, so
583 * just show the appropriate floor symbol. If something was
584 * embedded in the wall, the glyph will probably already
585 * reflect that. Don't change the symbol in this case.
587 * This isn't quite correct. If the boulder was on top of some
588 * other objects they should be seen once the boulder is removed.
589 * However, we have no way of knowing that what is there now
590 * was there then. So we let the hero have a lapse of memory.
591 * We could also just display what is currently on the top of the
592 * object stack (if anything).
594 if (lev->glyph == objnum_to_glyph(BOULDER)) {
595 if (lev->typ != ROOM && lev->seenv) {
596 map_background(x, y, 1);
598 lev->glyph = (flags.dark_room && iflags.use_color
599 && !Is_rogue_level(&u.uz))
600 ? cmap_to_glyph(S_darkroom)
601 : (lev->waslit ? cmap_to_glyph(S_room)
602 : cmap_to_glyph(S_stone));
603 show_glyph(x, y, lev->glyph);
605 } else if ((lev->glyph >= cmap_to_glyph(S_stone)
606 && lev->glyph < cmap_to_glyph(S_darkroom))
607 || glyph_is_invisible(levl[x][y].glyph)) {
608 lev->glyph = (flags.dark_room && iflags.use_color
609 && !Is_rogue_level(&u.uz))
610 ? cmap_to_glyph(S_darkroom)
611 : (lev->waslit ? cmap_to_glyph(S_room)
612 : cmap_to_glyph(S_stone));
613 show_glyph(x, y, lev->glyph);
616 /* We feel it (I think hallways are the only things left). */
617 map_background(x, y, 1);
618 /* Corridors are never felt as lit (unless remembered that way) */
619 /* (lit_corridor only). */
620 if (lev->typ == CORR && lev->glyph == cmap_to_glyph(S_litcorr)
622 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
623 else if (lev->typ == ROOM && flags.dark_room && iflags.use_color
624 && lev->glyph == cmap_to_glyph(S_room))
625 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_darkroom));
628 _map_location(x, y, 1);
632 * A ball or chain is only felt if it is first on the object
633 * location list. Otherwise, we need to clear the felt bit ---
634 * something has been dropped on the ball/chain. If the bit is
635 * not cleared, then when the ball/chain is moved it will drop
638 if (uchain->ox == x && uchain->oy == y) {
639 if (level.objects[x][y] == uchain)
640 u.bc_felt |= BC_CHAIN;
642 u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */
644 if (!carried(uball) && uball->ox == x && uball->oy == y) {
645 if (level.objects[x][y] == uball)
646 u.bc_felt |= BC_BALL;
648 u.bc_felt &= ~BC_BALL; /* do not feel the ball */
652 /* Floor spaces are dark if unlit. Corridors are dark if unlit. */
653 if (lev->typ == ROOM && lev->glyph == cmap_to_glyph(S_room)
654 && (!lev->waslit || (flags.dark_room && iflags.use_color)))
655 show_glyph(x, y, lev->glyph = cmap_to_glyph(
656 flags.dark_room ? S_darkroom : S_stone));
657 else if (lev->typ == CORR && lev->glyph == cmap_to_glyph(S_litcorr)
659 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
661 /* draw monster on top if we can sense it */
662 if ((x != u.ux || y != u.uy) && (mon = m_at(x, y)) && sensemon(mon))
663 display_monster(x, y, mon,
664 (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon))
673 * Possibly put a new glyph at the given location.
679 register struct monst *mon;
680 register struct rm *lev = &(levl[x][y]);
682 register xchar worm_tail;
686 #ifdef HANGUPHANDLING
687 if (program_state.done_hup)
691 /* only permit updating the hero when swallowed */
693 if (x == u.ux && y == u.uy)
697 if (Underwater && !Is_waterlevel(&u.uz)) {
698 /* don't do anything unless (x,y) is an adjacent underwater position
709 if (dx > 1 || dy > 1)
713 /* Can physically see the location. */
715 NhRegion *reg = visible_region_at(x, y);
717 * Don't use templit here: E.g.
719 * lev->waslit = !!(lev->lit || templit(x,y));
721 * Otherwise we have the "light pool" problem, where non-permanently
722 * lit areas just out of sight stay remembered as lit. They should
725 * Perhaps ALL areas should revert to their "unlit" look when
728 lev->waslit = (lev->lit != 0); /* remember lit condition */
730 /* normal region shown only on accessible positions, but poison clouds
731 * also shown above lava, pools and moats.
733 if (reg != NULL && (ACCESSIBLE(lev->typ)
734 || (reg->glyph == cmap_to_glyph(S_poisoncloud)
735 && (lev->typ == LAVAPOOL || lev->typ == POOL
736 || lev->typ == MOAT)))) {
737 show_region(reg, x, y);
740 if (x == u.ux && y == u.uy) {
742 _map_location(x, y, 0); /* map *under* self */
745 /* we can see what is there */
746 _map_location(x, y, 1);
749 worm_tail = is_worm_tail(mon);
751 mon && (worm_tail ? (!mon->minvis || See_invisible)
752 : (mon_visible(mon)) || tp_sensemon(mon)
753 || MATCH_WARN_OF_MON(mon));
754 if (mon && (see_it || (!worm_tail && Detect_monsters))) {
756 struct trap *trap = t_at(x, y);
757 int tt = trap ? trap->ttyp : NO_TRAP;
759 /* if monster is in a physical trap, you see the trap too
761 if (tt == BEAR_TRAP || tt == PIT || tt == SPIKED_PIT
766 _map_location(x, y, 0); /* map under the monster */
767 /* also gets rid of any invisibility glyph */
768 display_monster(x, y, mon,
769 see_it ? PHYSICALLY_SEEN : DETECTED,
771 } else if (mon && mon_warning(mon) && !is_worm_tail(mon)) {
772 display_warning(mon);
773 } else if (glyph_is_invisible(levl[x][y].glyph)) {
776 _map_location(x, y, 1); /* map the location */\
779 /* Can't see the location. */
781 if (x == u.ux && y == u.uy) {
782 feel_location(u.ux, u.uy); /* forces an update */
786 } else if ((mon = m_at(x, y))
787 && ((see_it = (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)
788 || (see_with_infrared(mon)
789 && mon_visible(mon))))
790 || Detect_monsters)) {
791 /* Monsters are printed every time. */
792 /* This also gets rid of any invisibility glyph */
793 display_monster(x, y, mon, see_it ? 0 : DETECTED,
794 is_worm_tail(mon) ? TRUE : FALSE);
795 } else if ((mon = m_at(x, y)) && mon_warning(mon)
796 && !is_worm_tail(mon)) {
797 display_warning(mon);
801 * If the location is remembered as being both dark (waslit is false)
802 * and lit (glyph is a lit room or lit corridor) then it was either:
804 * (1) A dark location that the hero could see through night
807 * (2) Darkened while out of the hero's sight. This can happen
808 * when cursed scroll of light is read.
810 * In either case, we have to manually correct the hero's memory to
811 * match waslit. Deciding when to change waslit is non-trivial.
813 * Note: If flags.lit_corridor is set, then corridors act like room
814 * squares. That is, they light up if in night vision range.
815 * If flags.lit_corridor is not set, then corridors will
816 * remain dark unless lit by a light spell and may darken
817 * again, as discussed above.
819 * These checks and changes must be here and not in back_to_glyph().
820 * They are dependent on the position being out of sight.
822 else if (Is_rogue_level(&u.uz)) {
823 if (lev->glyph == cmap_to_glyph(S_litcorr) && lev->typ == CORR)
824 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
825 else if (lev->glyph == cmap_to_glyph(S_room) && lev->typ == ROOM
827 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_stone));
831 else if (!lev->waslit || (flags.dark_room && iflags.use_color)) {
832 if (lev->glyph == cmap_to_glyph(S_litcorr) && lev->typ == CORR)
833 show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
834 else if (lev->glyph == cmap_to_glyph(S_room) && lev->typ == ROOM)
835 show_glyph(x, y, lev->glyph = cmap_to_glyph(DARKROOMSYM));
840 show_glyph(x, y, lev->glyph);
850 * Put magic shield pyrotechnics at the given location. This *could* be
851 * pulled into a platform dependent routine for fancier graphics if desired.
861 if (cansee(x, y)) { /* Don't see anything if can't see the location */
862 for (i = 0; i < SHIELD_COUNT; i++) {
863 show_glyph(x, y, cmap_to_glyph(shield_static[i]));
864 flush_screen(1); /* make sure the glyph shows up */
867 newsym(x, y); /* restore the old information */
874 * Temporarily place glyphs on the screen. Do not call delay_output(). It
875 * is up to the caller to decide if it wants to wait [presently, everyone
876 * but explode() wants to delay].
879 * (DISP_BEAM, glyph) open, initialize glyph
880 * (DISP_FLASH, glyph) open, initialize glyph
881 * (DISP_ALWAYS, glyph) open, initialize glyph
882 * (DISP_CHANGE, glyph) change glyph
883 * (DISP_END, 0) close & clean up (second argument doesn't
885 * (DISP_FREEMEM, 0) only used to prevent memory leak during
887 * (x, y) display the glyph at the location
889 * DISP_BEAM - Display the given glyph at each location, but do not erase
890 * any until the close call.
891 * DISP_FLASH - Display the given glyph at each location, but erase the
892 * previous location's glyph.
893 * DISP_ALWAYS- Like DISP_FLASH, but vision is not taken into account.
896 #define TMP_AT_MAX_GLYPHS (COLNO * 2)
898 static struct tmp_glyph {
899 coord saved[TMP_AT_MAX_GLYPHS]; /* previously updated positions */
900 int sidx; /* index of next unused slot in saved[] */
901 int style; /* either DISP_BEAM or DISP_FLASH or DISP_ALWAYS */
902 int glyph; /* glyph to use when printing */
903 struct tmp_glyph *prev;
910 static struct tmp_glyph *tglyph = (struct tmp_glyph *) 0;
911 struct tmp_glyph *tmp;
920 else /* nested effect; we need dynamic memory */
921 tmp = (struct tmp_glyph *) alloc(sizeof(struct tmp_glyph));
927 flush_screen(0); /* flush buffered glyphs */
930 case DISP_FREEMEM: /* in case game ends with tmp_at() in progress */
933 if (tglyph != &tgfirst)
934 free((genericptr_t) tglyph);
944 panic("tmp_at: tglyph not initialized");
952 if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
955 /* Erase (reset) from source to end */
956 for (i = 0; i < tglyph->sidx; i++)
957 newsym(tglyph->saved[i].x, tglyph->saved[i].y);
958 } else { /* DISP_FLASH or DISP_ALWAYS */
959 if (tglyph->sidx) /* been called at least once */
960 newsym(tglyph->saved[0].x, tglyph->saved[0].y);
962 /* tglyph->sidx = 0; -- about to be freed, so not necessary */
964 if (tglyph != &tgfirst)
965 free((genericptr_t) tglyph);
972 if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
973 if (tglyph->style != DISP_ALL && !cansee(x, y))
975 if (tglyph->sidx >= TMP_AT_MAX_GLYPHS)
976 break; /* too many locations */
977 /* save pos for later erasing */
978 tglyph->saved[tglyph->sidx].x = x;
979 tglyph->saved[tglyph->sidx].y = y;
981 } else { /* DISP_FLASH/ALWAYS */
982 if (tglyph->sidx) { /* not first call, so reset previous pos */
983 newsym(tglyph->saved[0].x, tglyph->saved[0].y);
984 tglyph->sidx = 0; /* display is presently up to date */
986 if (!cansee(x, y) && tglyph->style != DISP_ALWAYS)
988 tglyph->saved[0].x = x;
989 tglyph->saved[0].y = y;
993 show_glyph(x, y, tglyph->glyph); /* show it */
994 flush_screen(0); /* make sure it shows up */
1002 * The hero is swallowed. Show a special graphics sequence for this. This
1003 * bypasses all of the display routines and messes with buffered screen
1004 * directly. This method works because both vision and display check for
1011 static xchar lastx, lasty; /* last swallowed position */
1012 int swallower, left_ok, rght_ok;
1019 /* Clear old location */
1020 for (y = lasty - 1; y <= lasty + 1; y++)
1021 for (x = lastx - 1; x <= lastx + 1; x++)
1023 show_glyph(x, y, cmap_to_glyph(S_stone));
1026 swallower = monsndx(u.ustuck->data);
1027 /* assume isok(u.ux,u.uy) */
1028 left_ok = isok(u.ux - 1, u.uy);
1029 rght_ok = isok(u.ux + 1, u.uy);
1031 * Display the hero surrounded by the monster's stomach.
1033 if (isok(u.ux, u.uy - 1)) {
1035 show_glyph(u.ux - 1, u.uy - 1,
1036 swallow_to_glyph(swallower, S_sw_tl));
1037 show_glyph(u.ux, u.uy - 1, swallow_to_glyph(swallower, S_sw_tc));
1039 show_glyph(u.ux + 1, u.uy - 1,
1040 swallow_to_glyph(swallower, S_sw_tr));
1044 show_glyph(u.ux - 1, u.uy, swallow_to_glyph(swallower, S_sw_ml));
1047 show_glyph(u.ux + 1, u.uy, swallow_to_glyph(swallower, S_sw_mr));
1049 if (isok(u.ux, u.uy + 1)) {
1051 show_glyph(u.ux - 1, u.uy + 1,
1052 swallow_to_glyph(swallower, S_sw_bl));
1053 show_glyph(u.ux, u.uy + 1, swallow_to_glyph(swallower, S_sw_bc));
1055 show_glyph(u.ux + 1, u.uy + 1,
1056 swallow_to_glyph(swallower, S_sw_br));
1059 /* Update the swallowed position. */
1067 * Similar to swallowed() in operation. Shows hero when underwater
1068 * except when in water level. Special routines exist for that.
1074 static xchar lastx, lasty;
1075 static boolean dela;
1078 /* swallowing has a higher precedence than under water */
1079 if (Is_waterlevel(&u.uz) || u.uswallow)
1083 if (mode == 1 || dela) {
1087 /* delayed full update */
1088 } else if (mode == 2) {
1092 /* limited update */
1094 for (y = lasty - 1; y <= lasty + 1; y++)
1095 for (x = lastx - 1; x <= lastx + 1; x++)
1097 show_glyph(x, y, cmap_to_glyph(S_stone));
1100 for (x = u.ux - 1; x <= u.ux + 1; x++)
1101 for (y = u.uy - 1; y <= u.uy + 1; y++)
1102 if (isok(x, y) && is_pool(x, y)) {
1103 if (Blind && !(x == u.ux && y == u.uy))
1104 show_glyph(x, y, cmap_to_glyph(S_stone));
1115 * Very restricted display. You can only see yourself.
1121 static boolean dela;
1123 /* swallowing has a higher precedence than under ground */
1128 if (mode == 1 || dela) {
1132 /* delayed full update */
1133 } else if (mode == 2) {
1137 /* limited update */
1143 /* =========================================================================
1147 * Loop through all of the monsters and update them. Called when:
1148 * + going blind & telepathic
1149 * + regaining sight & telepathic
1150 * + getting and losing infravision
1152 * + doing a full screen redraw
1153 * + see invisible times out or a ring of see invisible is taken off
1154 * + when a potion of see invisible is quaffed or a ring of see
1155 * invisible is put on
1156 * + gaining telepathy when blind [givit() in eat.c, pleased() in pray.c]
1157 * + losing telepathy while blind [xkilled() in mon.c, attrcurse() in
1163 register struct monst *mon;
1164 int new_warn_obj_cnt = 0;
1166 if (defer_see_monsters)
1169 for (mon = fmon; mon; mon = mon->nmon) {
1170 if (DEADMONSTER(mon))
1172 newsym(mon->mx, mon->my);
1175 if (Warn_of_mon && (context.warntype.obj & mon->data->mflags2) != 0L)
1179 * Make Sting glow blue or stop glowing if required.
1181 if (new_warn_obj_cnt != warn_obj_cnt) {
1182 Sting_effects(new_warn_obj_cnt);
1183 warn_obj_cnt = new_warn_obj_cnt;
1186 /* when mounted, hero's location gets caught by monster loop */
1192 * Block/unblock light depending on what a mimic is mimicing and if it's
1193 * invisible or not. Should be called only when the state of See_invisible
1197 set_mimic_blocking()
1199 register struct monst *mon;
1201 for (mon = fmon; mon; mon = mon->nmon) {
1202 if (DEADMONSTER(mon))
1204 if (mon->minvis && (is_door_mappear(mon)
1205 || is_obj_mappear(mon,BOULDER))) {
1207 block_point(mon->mx, mon->my);
1209 unblock_point(mon->mx, mon->my);
1215 * Loop through all of the object *locations* and update them. Called when
1221 register struct obj *obj;
1222 for (obj = fobj; obj; obj = obj->nobj)
1223 if (vobj_at(obj->ox, obj->oy) == obj)
1224 newsym(obj->ox, obj->oy);
1228 * Update hallucinated traps.
1236 for (trap = ftrap; trap; trap = trap->ntrap) {
1237 glyph = glyph_at(trap->tx, trap->ty);
1238 if (glyph_is_trap(glyph))
1239 newsym(trap->tx, trap->ty);
1244 * Put the cursor on the hero. Flush all accumulated glyphs before doing it.
1249 flush_screen(1); /* Flush waiting glyphs & put cursor on hero */
1263 register struct rm *lev;
1266 return; /* display isn't ready yet */
1272 if (Underwater && !Is_waterlevel(&u.uz)) {
1281 /* shut down vision */
1285 * This routine assumes that cls() does the following:
1286 * + fills the physical screen with the symbol for rock
1287 * + clears the glyph buffer
1291 /* display memory */
1292 for (x = 1; x < COLNO; x++) {
1294 for (y = 0; y < ROWNO; y++, lev++)
1295 if (lev->glyph != cmap_to_glyph(S_stone))
1296 show_glyph(x, y, lev->glyph);
1299 /* see what is to be seen */
1302 /* overlay with monsters */
1305 context.botlx = 1; /* force a redraw of the bottom line */
1308 /* =========================================================================
1310 /* Glyph Buffering (3rd screen) ============================================
1314 xchar new; /* perhaps move this bit into the rm structure. */
1318 static gbuf_entry gbuf[ROWNO][COLNO];
1319 static char gbuf_start[ROWNO];
1320 static char gbuf_stop[ROWNO];
1323 * Store the glyph in the 3rd screen for later flushing.
1326 show_glyph(x, y, glyph)
1330 * Check for bad positions and glyphs.
1336 /* column 0 is invalid, but it's often used as a flag, so ignore it */
1341 * This assumes an ordering of the offsets. See display.h for
1345 if (glyph >= GLYPH_WARNING_OFF
1346 && glyph < GLYPH_STATUE_OFF) { /* a warning */
1348 offset = glyph - GLYPH_WARNING_OFF;
1349 } else if (glyph >= GLYPH_SWALLOW_OFF) { /* swallow border */
1350 text = "swallow border";
1351 offset = glyph - GLYPH_SWALLOW_OFF;
1352 } else if (glyph >= GLYPH_ZAP_OFF) { /* zap beam */
1354 offset = glyph - GLYPH_ZAP_OFF;
1355 } else if (glyph >= GLYPH_EXPLODE_OFF) { /* explosion */
1357 offset = glyph - GLYPH_EXPLODE_OFF;
1358 } else if (glyph >= GLYPH_CMAP_OFF) { /* cmap */
1359 text = "cmap_index";
1360 offset = glyph - GLYPH_CMAP_OFF;
1361 } else if (glyph >= GLYPH_OBJ_OFF) { /* object */
1363 offset = glyph - GLYPH_OBJ_OFF;
1364 } else if (glyph >= GLYPH_RIDDEN_OFF) { /* ridden mon */
1365 text = "ridden mon";
1366 offset = glyph - GLYPH_RIDDEN_OFF;
1367 } else if (glyph >= GLYPH_BODY_OFF) { /* a corpse */
1369 offset = glyph - GLYPH_BODY_OFF;
1370 } else if (glyph >= GLYPH_DETECT_OFF) { /* detected mon */
1371 text = "detected mon";
1372 offset = glyph - GLYPH_DETECT_OFF;
1373 } else if (glyph >= GLYPH_INVIS_OFF) { /* invisible mon */
1374 text = "invisible mon";
1375 offset = glyph - GLYPH_INVIS_OFF;
1376 } else if (glyph >= GLYPH_PET_OFF) { /* a pet */
1378 offset = glyph - GLYPH_PET_OFF;
1379 } else { /* a monster */
1384 impossible("show_glyph: bad pos %d %d with glyph %d [%s %d].", x, y,
1385 glyph, text, offset);
1389 if (glyph >= MAX_GLYPH) {
1390 impossible("show_glyph: bad glyph %d [max %d] at (%d,%d).", glyph,
1395 if (gbuf[y][x].glyph != glyph || iflags.use_background_glyph) {
1396 gbuf[y][x].glyph = glyph;
1398 if (gbuf_start[y] > x)
1400 if (gbuf_stop[y] < x)
1406 * Reset the changed glyph borders so that none of the 3rd screen has
1409 #define reset_glyph_bbox() \
1413 for (i = 0; i < ROWNO; i++) { \
1414 gbuf_start[i] = COLNO - 1; \
1419 static gbuf_entry nul_gbuf = { 0, cmap_to_glyph(S_stone) };
1421 * Turn the 3rd screen into stone.
1424 clear_glyph_buffer()
1427 register gbuf_entry *gptr;
1429 for (y = 0; y < ROWNO; y++) {
1431 for (x = COLNO; x; x--) {
1439 * Assumes that the indicated positions are filled with S_stone glyphs.
1442 row_refresh(start, stop, y)
1447 for (x = start; x <= stop; x++)
1448 if (gbuf[y][x].glyph != cmap_to_glyph(S_stone))
1449 print_glyph(WIN_MAP, x, y, gbuf[y][x].glyph, get_bk_glyph(x,y));
1455 static boolean in_cls = 0;
1460 display_nhwindow(WIN_MESSAGE, FALSE); /* flush messages */
1461 context.botlx = 1; /* force update of botl window */
1462 clear_nhwindow(WIN_MAP); /* clear physical screen */
1464 clear_glyph_buffer(); /* this is sort of an extra effort, but OK */
1469 * Synch the third screen with the display.
1472 flush_screen(cursor_on_u)
1475 /* Prevent infinite loops on errors:
1476 * flush_screen->print_glyph->impossible->pline->flush_screen
1478 static boolean flushing = 0;
1479 static boolean delay_flushing = 0;
1482 if (cursor_on_u == -1)
1483 delay_flushing = !delay_flushing;
1487 return; /* if already flushing then return */
1489 #ifdef HANGUPHANDLING
1490 if (program_state.done_hup)
1494 for (y = 0; y < ROWNO; y++) {
1495 register gbuf_entry *gptr = &gbuf[y][x = gbuf_start[y]];
1496 for (; x <= gbuf_stop[y]; gptr++, x++)
1498 print_glyph(WIN_MAP, x, y, gptr->glyph, get_bk_glyph(x, y));
1504 curs(WIN_MAP, u.ux, u.uy); /* move cursor to the hero */
1505 display_nhwindow(WIN_MAP, FALSE);
1508 if (context.botl || context.botlx)
1512 /* =========================================================================
1518 * Use the information in the rm structure at the given position to create
1519 * a glyph of a background.
1521 * I had to add a field in the rm structure (horizontal) so that we knew
1522 * if open doors and secret doors were horizontal or vertical. Previously,
1523 * the screen symbol had the horizontal/vertical information set at
1524 * level generation time.
1526 * I used the 'ladder' field (really doormask) for deciding if stairwells
1527 * were up or down. I didn't want to check the upstairs and dnstairs
1535 struct rm *ptr = &(levl[x][y]);
1540 idx = level.flags.arboreal ? S_tree : S_stone;
1546 idx = (ptr->waslit || flags.lit_corridor) ? S_litcorr : S_corr;
1560 idx = ptr->seenv ? wall_angle(ptr) : S_stone;
1563 if (ptr->doormask) {
1564 if (ptr->doormask & D_BROKEN)
1566 else if (ptr->doormask & D_ISOPEN)
1567 idx = (ptr->horizontal) ? S_hodoor : S_vodoor;
1568 else /* else is closed */
1569 idx = (ptr->horizontal) ? S_hcdoor : S_vcdoor;
1584 idx = (ptr->ladder & LA_DOWN) ? S_dnstair : S_upstair;
1587 idx = (ptr->ladder & LA_DOWN) ? S_dnladder : S_upladder;
1620 idx = (ptr->horizontal) ? S_hcdbridge : S_vcdbridge;
1623 switch (ptr->drawbridgemask & DB_UNDER) {
1637 impossible("Strange db-under: %d",
1638 ptr->drawbridgemask & DB_UNDER);
1639 idx = S_room; /* something is better than nothing */
1643 case DRAWBRIDGE_DOWN:
1644 idx = (ptr->horizontal) ? S_hodbridge : S_vodbridge;
1647 impossible("back_to_glyph: unknown level type [ = %d ]", ptr->typ);
1652 return cmap_to_glyph(idx);
1656 * swallow_to_glyph()
1658 * Convert a monster number and a swallow location into the correct glyph.
1659 * If you don't want a patchwork monster while hallucinating, decide on
1660 * a random monster in swallowed() and don't use what_mon() here.
1663 swallow_to_glyph(mnum, loc)
1667 if (loc < S_sw_tl || S_sw_br < loc) {
1668 impossible("swallow_to_glyph: bad swallow location");
1671 return ((int) (what_mon(mnum) << 3) | (loc - S_sw_tl)) + GLYPH_SWALLOW_OFF;
1677 * Change the given zap direction and beam type into a glyph. Each beam
1678 * type has four glyphs, one for each of the symbols below. The order of
1679 * the zap symbols [0-3] as defined in rm.h are:
1681 * | S_vbeam ( 0, 1) or ( 0,-1)
1682 * - S_hbeam ( 1, 0) or (-1, 0)
1683 * \ S_lslant ( 1, 1) or (-1,-1)
1684 * / S_rslant (-1, 1) or ( 1,-1)
1687 zapdir_to_glyph(dx, dy, beam_type)
1688 register int dx, dy;
1691 if (beam_type >= NUM_ZAP) {
1692 impossible("zapdir_to_glyph: illegal beam type");
1695 dx = (dx == dy) ? 2 : (dx && dy) ? 3 : dx ? 1 : 0;
1697 return ((int) ((beam_type << 2) | dx)) + GLYPH_ZAP_OFF;
1701 * Utility routine for dowhatis() used to find out the glyph displayed at
1702 * the location. This isn't necessarily the same as the glyph in the levl
1703 * structure, so we must check the "third screen".
1709 if (x < 0 || y < 0 || x >= COLNO || y >= ROWNO)
1710 return cmap_to_glyph(S_room); /* XXX */
1711 return gbuf[y][x].glyph;
1715 * This will be used to get the glyph for the background so that
1716 * it can potentially be merged into graphical window ports
1717 * to improve the appearance of stuff on dark room
1718 * squares and the plane of air etc.
1720 * Until that is working correctly in the branch, however, for now
1721 * we just return NO_GLYPH as an indicator to ignore it.
1728 int idx, bkglyph = NO_GLYPH;
1729 struct rm *lev = &levl[x][y];
1731 if (iflags.use_background_glyph) {
1735 idx = level.flags.arboreal ? S_tree : S_stone;
1741 idx = (lev->waslit || flags.lit_corridor) ? S_litcorr : S_corr;
1760 if (!cansee(x, y) && (!lev->waslit || flags.dark_room)) {
1761 /* Floor spaces are dark if unlit. Corridors are dark if unlit. */
1762 if (lev->typ == CORR && idx == S_litcorr)
1764 else if (idx == S_room)
1765 idx = (flags.dark_room && iflags.use_color)
1766 ? DARKROOMSYM : S_stone;
1770 bkglyph = cmap_to_glyph(idx);
1775 /* -------------------------------------------------------------------------
1777 /* Wall Angle --------------------------------------------------------------
1782 static const char *FDECL(type_to_name, (int));
1783 static void FDECL(error4, (int, int, int, int, int, int));
1785 static int bad_count[MAX_TYPE]; /* count of positions flagged as bad */
1786 static const char *type_names[MAX_TYPE] = {
1787 "STONE", "VWALL", "HWALL", "TLCORNER", "TRCORNER", "BLCORNER", "BRCORNER",
1788 "CROSSWALL", "TUWALL", "TDWALL", "TLWALL", "TRWALL", "DBWALL", "TREE",
1789 "SDOOR", "SCORR", "POOL", "MOAT", "WATER", "DRAWBRIDGE_UP", "LAVAPOOL",
1790 "IRON_BARS", "DOOR", "CORR", "ROOM", "STAIRS", "LADDER", "FOUNTAIN",
1791 "THRONE", "SINK", "GRAVE", "ALTAR", "ICE", "DRAWBRIDGE_DOWN", "AIR",
1799 return (type < 0 || type >= MAX_TYPE) ? "unknown" : type_names[type];
1803 error4(x, y, a, b, c, dd)
1804 int x, y, a, b, c, dd;
1806 pline("set_wall_state: %s @ (%d,%d) %s%s%s%s",
1807 type_to_name(levl[x][y].typ), x, y,
1808 a ? "1" : "", b ? "2" : "", c ? "3" : "", dd ? "4" : "");
1809 bad_count[levl[x][y].typ]++;
1811 #endif /* WA_VERBOSE */
1814 * Return 'which' if position is implies an unfinished exterior. Return
1815 * zero otherwise. Unfinished implies outer area is rock or a corridor.
1817 * Things that are ambiguous: lava
1820 check_pos(x, y, which)
1826 type = levl[x][y].typ;
1827 if (IS_ROCK(type) || type == CORR || type == SCORR)
1832 /* Return TRUE if more than one is non-zero. */
1836 more_than_one(x, y, a, b, c)
1839 if ((a && (b | c)) || (b && (a | c)) || (c && (a | b))) {
1840 error4(x, y, a, b, c, 0);
1846 #define more_than_one(x, y, a, b, c) \
1847 (((a) && ((b) | (c))) || ((b) && ((a) | (c))) || ((c) && ((a) | (b))))
1850 /* Return the wall mode for a T wall. */
1852 set_twall(x0, y0, x1, y1, x2, y2, x3, y3)
1853 int x0, y0; /* used #if WA_VERBOSE */
1854 int x1, y1, x2, y2, x3, y3;
1856 int wmode, is_1, is_2, is_3;
1861 is_1 = check_pos(x1, y1, WM_T_LONG);
1862 is_2 = check_pos(x2, y2, WM_T_BL);
1863 is_3 = check_pos(x3, y3, WM_T_BR);
1864 if (more_than_one(x0, y0, is_1, is_2, is_3)) {
1867 wmode = is_1 + is_2 + is_3;
1872 /* Return wall mode for a horizontal or vertical wall. */
1874 set_wall(x, y, horiz)
1877 int wmode, is_1, is_2;
1880 is_1 = check_pos(x, y - 1, WM_W_TOP);
1881 is_2 = check_pos(x, y + 1, WM_W_BOTTOM);
1883 is_1 = check_pos(x - 1, y, WM_W_LEFT);
1884 is_2 = check_pos(x + 1, y, WM_W_RIGHT);
1886 if (more_than_one(x, y, is_1, is_2, 0)) {
1889 wmode = is_1 + is_2;
1894 /* Return a wall mode for a corner wall. (x4,y4) is the "inner" position. */
1896 set_corn(x1, y1, x2, y2, x3, y3, x4, y4)
1897 int x1, y1, x2, y2, x3, y3, x4, y4;
1899 int wmode, is_1, is_2, is_3, is_4;
1901 is_1 = check_pos(x1, y1, 1);
1902 is_2 = check_pos(x2, y2, 1);
1903 is_3 = check_pos(x3, y3, 1);
1904 is_4 = check_pos(x4, y4, 1); /* inner location */
1907 * All 4 should not be true. So if the inner location is rock,
1908 * use it. If all of the outer 3 are true, use outer. We currently
1909 * can't cover the case where only part of the outer is rock, so
1910 * we just say that all the walls are finished (if not overridden
1911 * by the inner section).
1915 } else if (is_1 && is_2 && is_3)
1918 wmode = 0; /* finished walls on all sides */
1923 /* Return mode for a crosswall. */
1928 int wmode, is_1, is_2, is_3, is_4;
1930 is_1 = check_pos(x - 1, y - 1, 1);
1931 is_2 = check_pos(x + 1, y - 1, 1);
1932 is_3 = check_pos(x + 1, y + 1, 1);
1933 is_4 = check_pos(x - 1, y + 1, 1);
1935 wmode = is_1 + is_2 + is_3 + is_4;
1937 if (is_1 && is_3 && (is_2 + is_4 == 0)) {
1939 } else if (is_2 && is_4 && (is_1 + is_3 == 0)) {
1943 error4(x, y, is_1, is_2, is_3, is_4);
1959 /* Called from mklev. Scan the level and set the wall modes. */
1968 for (x = 0; x < MAX_TYPE; x++)
1972 for (x = 0; x < COLNO; x++)
1973 for (lev = &levl[x][0], y = 0; y < ROWNO; y++, lev++) {
1976 wmode = set_wall(x, y, (int) lev->horizontal);
1979 wmode = set_wall(x, y, 0);
1982 wmode = set_wall(x, y, 1);
1985 wmode = set_twall(x, y, x, y - 1, x - 1, y + 1, x + 1, y + 1);
1988 wmode = set_twall(x, y, x, y + 1, x + 1, y - 1, x - 1, y - 1);
1991 wmode = set_twall(x, y, x + 1, y, x - 1, y - 1, x - 1, y + 1);
1994 wmode = set_twall(x, y, x - 1, y, x + 1, y + 1, x + 1, y - 1);
1998 set_corn(x - 1, y - 1, x, y - 1, x - 1, y, x + 1, y + 1);
2002 set_corn(x, y - 1, x + 1, y - 1, x + 1, y, x - 1, y + 1);
2006 set_corn(x, y + 1, x - 1, y + 1, x - 1, y, x + 1, y - 1);
2010 set_corn(x + 1, y, x + 1, y + 1, x, y + 1, x - 1, y - 1);
2013 wmode = set_crosswall(x, y);
2017 wmode = -1; /* don't set wall info */
2022 lev->wall_info = (lev->wall_info & ~WM_MASK) | wmode;
2026 /* check if any bad positions found */
2027 for (x = y = 0; x < MAX_TYPE; x++)
2030 y = 1; /* only print once */
2031 pline("set_wall_type: wall mode problems with: ");
2033 pline("%s %d;", type_names[x], bad_count[x]);
2035 #endif /* WA_VERBOSE */
2038 /* -------------------------------------------------------------------------
2040 /* This matrix is used here and in vision.c. */
2041 unsigned char seenv_matrix[3][3] = { { SV2, SV1, SV0 },
2042 { SV3, SVALL, SV7 },
2043 { SV4, SV5, SV6 } };
2045 #define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0))
2047 /* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */
2049 set_seenv(lev, x0, y0, x, y)
2051 int x0, y0, x, y; /* from, to */
2053 int dx = x - x0, dy = y0 - y;
2055 lev->seenv |= seenv_matrix[sign(dy) + 1][sign(dx) + 1];
2058 /* Called by blackout(vault.c) when vault guard removes temporary corridor,
2059 turning spot <x0,y0> back into stone; <x1,y1> is an adjacent spot. */
2061 unset_seenv(lev, x0, y0, x1, y1)
2062 struct rm *lev; /* &levl[x1][y1] */
2063 int x0, y0, x1, y1; /* from, to; abs(x1-x0)==1 && abs(y0-y1)==1 */
2065 int dx = x1 - x0, dy = y0 - y1;
2067 lev->seenv &= ~seenv_matrix[dy + 1][dx + 1];
2070 /* -------------------------------------------------------------------------
2073 /* T wall types, one for each row in wall_matrix[][]. */
2080 * These are the column names of wall_matrix[][]. They are the "results"
2081 * of a tdwall pattern match. All T walls are rotated so they become
2082 * a tdwall. Then we do a single pattern match, but return the
2083 * correct result for the original wall by using different rows for
2084 * each of the wall types.
2092 static const int wall_matrix[4][5] = {
2093 { S_stone, S_tlcorn, S_trcorn, S_hwall, S_tdwall }, /* tdwall */
2094 { S_stone, S_trcorn, S_brcorn, S_vwall, S_tlwall }, /* tlwall */
2095 { S_stone, S_brcorn, S_blcorn, S_hwall, S_tuwall }, /* tuwall */
2096 { S_stone, S_blcorn, S_tlcorn, S_vwall, S_trwall }, /* trwall */
2099 /* Cross wall types, one for each "solid" quarter. Rows of cross_matrix[][].
2107 * These are the column names for cross_matrix[][]. They express results
2108 * in C_br (bottom right) terms. All crosswalls with a single solid
2109 * quarter are rotated so the solid section is at the bottom right.
2110 * We pattern match on that, but return the correct result depending
2111 * on which row we'ere looking at.
2120 static const int cross_matrix[4][6] = {
2121 { S_brcorn, S_blcorn, S_tlcorn, S_tuwall, S_trwall, S_crwall },
2122 { S_blcorn, S_tlcorn, S_trcorn, S_trwall, S_tdwall, S_crwall },
2123 { S_tlcorn, S_trcorn, S_brcorn, S_tdwall, S_tlwall, S_crwall },
2124 { S_trcorn, S_brcorn, S_blcorn, S_tlwall, S_tuwall, S_crwall },
2127 /* Print out a T wall warning and all interesting info. */
2132 static const char warn_str[] = "wall_angle: %s: case %d: seenv = 0x%x";
2135 if (lev->typ == TUWALL)
2137 else if (lev->typ == TLWALL)
2139 else if (lev->typ == TRWALL)
2141 else if (lev->typ == TDWALL)
2145 impossible(warn_str, wname, lev->wall_info & WM_MASK,
2146 (unsigned int) lev->seenv);
2150 * Return the correct graphics character index using wall type, wall mode,
2151 * and the seen vector. It is expected that seenv is non zero.
2153 * All T-wall vectors are rotated to be TDWALL. All single crosswall
2154 * blocks are rotated to bottom right. All double crosswall are rotated
2155 * to W_X_BLTR. All results are converted back.
2157 * The only way to understand this is to take out pen and paper and
2158 * draw diagrams. See rm.h for more details on the wall modes and
2165 register unsigned int seenv = lev->seenv & 0xff;
2169 #define only(sv, bits) (((sv) & (bits)) && !((sv) & ~(bits)))
2172 row = wall_matrix[T_u];
2173 seenv = (seenv >> 4 | seenv << 4) & 0xff; /* rotate to tdwall */
2176 row = wall_matrix[T_l];
2177 seenv = (seenv >> 2 | seenv << 6) & 0xff; /* rotate to tdwall */
2180 row = wall_matrix[T_r];
2181 seenv = (seenv >> 6 | seenv << 2) & 0xff; /* rotate to tdwall */
2184 row = wall_matrix[T_d];
2186 switch (lev->wall_info & WM_MASK) {
2190 } else if (seenv == SV6) {
2192 } else if (seenv & (SV3 | SV5 | SV7)
2193 || ((seenv & SV4) && (seenv & SV6))) {
2195 } else if (seenv & (SV0 | SV1 | SV2)) {
2196 col = (seenv & (SV4 | SV6) ? T_tdwall : T_hwall);
2203 if (seenv & (SV3 | SV4) && !(seenv & (SV5 | SV6 | SV7))) {
2205 } else if (seenv & (SV6 | SV7) && !(seenv & (SV3 | SV4 | SV5))) {
2207 } else if ((seenv & SV5)
2208 || ((seenv & (SV3 | SV4)) && (seenv & (SV6 | SV7)))) {
2211 /* only SV0|SV1|SV2 */
2212 if (!only(seenv, SV0 | SV1 | SV2))
2218 #if 0 /* older method, fixed */
2219 if (only(seenv, SV4|SV5)) {
2221 } else if ((seenv & (SV0|SV1|SV2))
2222 && only(seenv, SV0|SV1|SV2|SV6|SV7)) {
2224 } else if ((seenv & SV3)
2225 || ((seenv & (SV0|SV1|SV2)) && (seenv & (SV4|SV5)))) {
2233 if (only(seenv, SV4 | SV5))
2235 else if ((seenv & (SV0 | SV1 | SV2 | SV7))
2236 && !(seenv & (SV3 | SV4 | SV5)))
2238 else if (only(seenv, SV6))
2244 #if 0 /* older method, fixed */
2245 if (only(seenv, SV5|SV6)) {
2247 } else if ((seenv & (SV0|SV1|SV2))
2248 && only(seenv, SV0|SV1|SV2|SV3|SV4)) {
2250 } else if ((seenv & SV7)
2251 || ((seenv & (SV0|SV1|SV2)) && (seenv & (SV5|SV6)))) {
2259 if (only(seenv, SV5 | SV6))
2261 else if ((seenv & (SV0 | SV1 | SV2 | SV3))
2262 && !(seenv & (SV5 | SV6 | SV7)))
2264 else if (only(seenv, SV4))
2271 impossible("wall_angle: unknown T wall mode %d",
2272 lev->wall_info & WM_MASK);
2280 if (lev->horizontal)
2284 switch (lev->wall_info & WM_MASK) {
2286 idx = seenv ? S_vwall : S_stone;
2289 idx = seenv & (SV1 | SV2 | SV3 | SV4 | SV5) ? S_vwall : S_stone;
2292 idx = seenv & (SV0 | SV1 | SV5 | SV6 | SV7) ? S_vwall : S_stone;
2295 impossible("wall_angle: unknown vwall mode %d",
2296 lev->wall_info & WM_MASK);
2304 switch (lev->wall_info & WM_MASK) {
2306 idx = seenv ? S_hwall : S_stone;
2309 idx = seenv & (SV3 | SV4 | SV5 | SV6 | SV7) ? S_hwall : S_stone;
2312 idx = seenv & (SV0 | SV1 | SV2 | SV3 | SV7) ? S_hwall : S_stone;
2315 impossible("wall_angle: unknown hwall mode %d",
2316 lev->wall_info & WM_MASK);
2322 #define set_corner(idx, lev, which, outer, inner, name) \
2323 switch ((lev)->wall_info & WM_MASK) { \
2328 idx = seenv & (outer) ? which : S_stone; \
2331 idx = seenv & ~(inner) ? which : S_stone; \
2334 impossible("wall_angle: unknown %s mode %d", name, \
2335 (lev)->wall_info &WM_MASK); \
2341 set_corner(idx, lev, S_tlcorn, (SV3 | SV4 | SV5), SV4, "tlcorn");
2344 set_corner(idx, lev, S_trcorn, (SV5 | SV6 | SV7), SV6, "trcorn");
2347 set_corner(idx, lev, S_blcorn, (SV1 | SV2 | SV3), SV2, "blcorn");
2350 set_corner(idx, lev, S_brcorn, (SV7 | SV0 | SV1), SV0, "brcorn");
2354 switch (lev->wall_info & WM_MASK) {
2358 else if (seenv == SV2)
2360 else if (seenv == SV4)
2362 else if (seenv == SV6)
2364 else if (!(seenv & ~(SV0 | SV1 | SV2))
2365 && (seenv & SV1 || seenv == (SV0 | SV2)))
2367 else if (!(seenv & ~(SV2 | SV3 | SV4))
2368 && (seenv & SV3 || seenv == (SV2 | SV4)))
2370 else if (!(seenv & ~(SV4 | SV5 | SV6))
2371 && (seenv & SV5 || seenv == (SV4 | SV6)))
2373 else if (!(seenv & ~(SV0 | SV6 | SV7))
2374 && (seenv & SV7 || seenv == (SV0 | SV6)))
2381 row = cross_matrix[C_tl];
2382 seenv = (seenv >> 4 | seenv << 4) & 0xff;
2385 row = cross_matrix[C_tr];
2386 seenv = (seenv >> 6 | seenv << 2) & 0xff;
2389 row = cross_matrix[C_bl];
2390 seenv = (seenv >> 2 | seenv << 6) & 0xff;
2393 row = cross_matrix[C_br];
2398 seenv = seenv & ~SV4; /* strip SV4 */
2401 } else if (seenv & (SV2 | SV3)) {
2402 if (seenv & (SV5 | SV6 | SV7))
2404 else if (seenv & (SV0 | SV1))
2408 } else if (seenv & (SV5 | SV6)) {
2409 if (seenv & (SV1 | SV2 | SV3))
2411 else if (seenv & (SV0 | SV7))
2415 } else if (seenv & SV1) {
2416 col = seenv & SV7 ? C_crwall : C_tuwall;
2417 } else if (seenv & SV7) {
2418 col = seenv & SV1 ? C_crwall : C_tlwall;
2420 impossible("wall_angle: bottom of crwall check");
2429 if (only(seenv, SV1 | SV2 | SV3))
2431 else if (only(seenv, SV5 | SV6 | SV7))
2433 else if (only(seenv, SV0 | SV4))
2440 if (only(seenv, SV0 | SV1 | SV7))
2442 else if (only(seenv, SV3 | SV4 | SV5))
2444 else if (only(seenv, SV2 | SV6))
2451 impossible("wall_angle: unknown crosswall mode");
2458 impossible("wall_angle: unexpected wall type %d", lev->typ);