Source:NetHack 3.4.3/src/display.c

From NetHackWiki
(Redirected from Source:Ref/vobj at)
Jump to: navigation, search

Below is the full text to src/display.c from NetHack 3.4.3. To link to a particular line, write [[display.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)display.c	3.4	2003/02/19	*/
  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. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

The New Display Code[edit]

  1. /*
  2. *			THE NEW DISPLAY CODE
  3. *
  4. * The old display code has been broken up into three parts: vision, display,
  5. * and drawing.  Vision decides what locations can and cannot be physically
  6. * seen by the hero.  Display decides _what_ is displayed at a given location.
  7. * Drawing decides _how_ to draw a monster, fountain, sword, etc.
  8. *
  9. * The display system uses information from the vision system to decide
  10. * what to draw at a given location.  The routines for the vision system
  11. * can be found in vision.c and vision.h.  The routines for display can
  12. * be found in this file (display.c) and display.h.  The drawing routines
  13. * are part of the window port.  See doc/window.doc for the drawing
  14. * interface.
  15. *
  16. * The display system deals with an abstraction called a glyph.  Anything
  17. * that could possibly be displayed has a unique glyph identifier.
  18. *
  19. * What is seen on the screen is a combination of what the hero remembers
  20. * and what the hero currently sees.  Objects and dungeon features (walls
  21. * doors, etc) are remembered when out of sight.  Monsters and temporary
  22. * effects are not remembered.  Each location on the level has an
  23. * associated glyph.  This is the hero's _memory_ of what he or she has
  24. * seen there before.
  25. *
  26. * Display rules:
  27. *
  28. *	If the location is in sight, display in order:
  29. *		visible (or sensed) monsters
  30. *		visible objects
  31. *		known traps
  32. *		background
  33. *
  34. *	If the location is out of sight, display in order:
  35. *		sensed monsters (telepathy)
  36. *		memory
  37. *
  38. *
  39. *
  40. * Here is a list of the major routines in this file to be used externally:
  41. *
  42. * newsym
  43. *
  44. * Possibly update the screen location (x,y).  This is the workhorse routine.
  45. * It is always correct --- where correct means following the in-sight/out-
  46. * of-sight rules.  **Most of the code should use this routine.**  This
  47. * routine updates the map and displays monsters.
  48. *
  49. *
  50. * map_background
  51. * map_object
  52. * map_trap
  53. * map_invisible
  54. * unmap_object
  55. *
  56. * If you absolutely must override the in-sight/out-of-sight rules, there
  57. * are two possibilities.  First, you can mess with vision to force the
  58. * location in sight then use newsym(), or you can  use the map_* routines.
  59. * The first has not been tried [no need] and the second is used in the
  60. * detect routines --- detect object, magic mapping, etc.  The map_*
  61. * routines *change* what the hero remembers.  All changes made by these
  62. * routines will be sticky --- they will survive screen redraws.  Do *not*
  63. * use these for things that only temporarily change the screen.  These
  64. * routines are also used directly by newsym().  unmap_object is used to
  65. * clear a remembered object when/if detection reveals it isn't there.
  66. *
  67. *
  68. * show_glyph
  69. *
  70. * This is direct (no processing in between) buffered access to the screen.
  71. * Temporary screen effects are run through this and its companion,
  72. * flush_screen().  There is yet a lower level routine, print_glyph(),
  73. * but this is unbuffered and graphic dependent (i.e. it must be surrounded
  74. * by graphic set-up and tear-down routines).  Do not use print_glyph().
  75. *
  76. *
  77. * see_monsters
  78. * see_objects
  79. * see_traps
  80. *
  81. * These are only used when something affects all of the monsters or
  82. * objects or traps.  For objects and traps, the only thing is hallucination.
  83. * For monsters, there are hallucination and changing from/to blindness, etc.
  84. *
  85. *
  86. * tmp_at
  87. *
  88. * This is a useful interface for displaying temporary items on the screen.
  89. * Its interface is different than previously, so look at it carefully.
  90. *
  91. *
  92. *
  93. * Parts of the rm structure that are used:
  94. *
  95. *	typ	- What is really there.
  96. *	glyph	- What the hero remembers.  This will never be a monster.
  97. *		  Monsters "float" above this.
  98. *	lit	- True if the position is lit.  An optimization for
  99. *		  lit/unlit rooms.
  100. *	waslit	- True if the position was *remembered* as lit.
  101. *	seenv	- A vector of bits representing the directions from which the
  102. *		  hero has seen this position.  The vector's primary use is
  103. *		  determining how walls are seen.  E.g. a wall sometimes looks
  104. *		  like stone on one side, but is seen as a wall from the other.
  105. *		  Other uses are for unmapping detected objects and felt
  106. *		  locations, where we need to know if the hero has ever
  107. *		  seen the location.
  108. *	flags   - Additional information for the typ field.  Different for
  109. *		  each typ.
  110. *	horizontal - Indicates whether the wall or door is horizontal or
  111. *		     vertical.
  112. */
  113. #include "hack.h"
  114. #include "region.h"
  115.  
  116. STATIC_DCL void FDECL(display_monster,(XCHAR_P,XCHAR_P,struct monst *,int,XCHAR_P));
  117. STATIC_DCL int FDECL(swallow_to_glyph, (int, int));
  118. STATIC_DCL void FDECL(display_warning,(struct monst *));
  119.  
  120. STATIC_DCL int FDECL(check_pos, (int, int, int));
  121. #ifdef WA_VERBOSE
  122. STATIC_DCL boolean FDECL(more_than_one, (int, int, int, int, int));
  123. #endif
  124. STATIC_DCL int FDECL(set_twall, (int,int, int,int, int,int, int,int));
  125. STATIC_DCL int FDECL(set_wall, (int, int, int));
  126. STATIC_DCL int FDECL(set_corn, (int,int, int,int, int,int, int,int));
  127. STATIC_DCL int FDECL(set_crosswall, (int, int));
  128. STATIC_DCL void FDECL(set_seenv, (struct rm *, int, int, int, int));
  129. STATIC_DCL void FDECL(t_warn, (struct rm *));
  130. STATIC_DCL int FDECL(wall_angle, (struct rm *));

vobj_at[edit]

  1. #ifdef INVISIBLE_OBJECTS
  2. /*
  3. * vobj_at()
  4. *
  5. * Returns a pointer to an object if the hero can see an object at the
  6. * given location.  This takes care of invisible objects.  NOTE, this
  7. * assumes that the hero is not blind and on top of the object pile.
  8. * It does NOT take into account that the location is out of sight, or,
  9. * say, one can see blessed, etc.
  10. */
  11. struct obj *
  12. vobj_at(x,y)
  13. xchar x,y;
  14. {
  15. register struct obj *obj = level.objects[x][y];
  16.  
  17. while (obj) {
  18. 	if (!obj->oinvis || See_invisible) return obj;
  19. 	obj = obj->nexthere;
  20. }
  21. return ((struct obj *) 0);
  22. }
  23. #endif	/* else vobj_at() is defined in display.h */

magic_map_background[edit]

  1. /*
  2. * magic_map_background()
  3. *
  4. * This function is similar to map_background (see below) except we pay
  5. * attention to and correct unexplored, lit ROOM and CORR spots.
  6. */
  7. void
  8. magic_map_background(x, y, show)
  9. xchar x,y;
  10. int  show;
  11. {
  12. int glyph = back_to_glyph(x,y);	/* assumes hero can see x,y */
  13. struct rm *lev = &levl[x][y];
  14.  
  15. /*
  16. * Correct for out of sight lit corridors and rooms that the hero
  17. * doesn't remember as lit.
  18. */
  19. if (!cansee(x,y) && !lev->waslit) {
  20. 	/* Floor spaces are dark if unlit.  Corridors are dark if unlit. */
  21. 	if (lev->typ == ROOM && glyph == cmap_to_glyph(S_room))
  22. 	    glyph = cmap_to_glyph(S_stone);
  23. 	else if (lev->typ == CORR && glyph == cmap_to_glyph(S_litcorr))
  24. 	    glyph = cmap_to_glyph(S_corr);
  25. }
  26. if (level.flags.hero_memory)
  27. 	lev->glyph = glyph;
  28. if (show) show_glyph(x,y, glyph);
  29. }

map_background[edit]

  1. /*
  2. * The routines map_background(), map_object(), and map_trap() could just
  3. * as easily be:
  4. *
  5. *	map_glyph(x,y,glyph,show)
  6. *
  7. * Which is called with the xx_to_glyph() in the call.  Then I can get
  8. * rid of 3 routines that don't do very much anyway.  And then stop
  9. * having to create fake objects and traps.  However, I am reluctant to
  10. * make this change.
  11. */
  12. /* FIXME: some of these use xchars for x and y, and some use ints.  Make
  13. * this consistent.
  14. */
  15.  
  16. /*
  17. * map_background()
  18. *
  19. * Make the real background part of our map.  This routine assumes that
  20. * the hero can physically see the location.  Update the screen if directed.
  21. */
  22. void
  23. map_background(x, y, show)
  24. register xchar x,y;
  25. register int  show;
  26. {
  27. register int glyph = back_to_glyph(x,y);
  28.  
  29. if (level.flags.hero_memory)
  30. 	levl[x][y].glyph = glyph;
  31. if (show) show_glyph(x,y, glyph);
  32. }

map_trap[edit]

  1. /*
  2. * map_trap()
  3. *
  4. * Map the trap and print it out if directed.  This routine assumes that the
  5. * hero can physically see the location.
  6. */
  7. void
  8. map_trap(trap, show)
  9. register struct trap *trap;
  10. register int	 show;
  11. {
  12. register int x = trap->tx, y = trap->ty;
  13. register int glyph = trap_to_glyph(trap);
  14.  
  15. if (level.flags.hero_memory)
  16. 	levl[x][y].glyph = glyph;
  17. if (show) show_glyph(x, y, glyph);
  18. }

map_object[edit]

  1. /*
  2. * map_object()
  3. *
  4. * Map the given object.  This routine assumes that the hero can physically
  5. * see the location of the object.  Update the screen if directed.
  6. */
  7. void
  8. map_object(obj, show)
  9. register struct obj *obj;
  10. register int	show;
  11. {
  12. register int x = obj->ox, y = obj->oy;
  13. register int glyph = obj_to_glyph(obj);
  14.  
  15. if (level.flags.hero_memory)
  16. 	levl[x][y].glyph = glyph;
  17. if (show) show_glyph(x, y, glyph);
  18. }

map_invisible[edit]

  1. /*
  2. * map_invisible()
  3. *
  4. * Make the hero remember that a square contains an invisible monster.
  5. * This is a special case in that the square will continue to be displayed
  6. * this way even when the hero is close enough to see it.  To get rid of
  7. * this and display the square's actual contents, use unmap_object() followed
  8. * by newsym() if necessary.
  9. */
  10. void
  11. map_invisible(x, y)
  12. register xchar x, y;
  13. {
  14. if (x != u.ux || y != u.uy) { /* don't display I at hero's location */
  15. 	if (level.flags.hero_memory)
  16. 	    levl[x][y].glyph = GLYPH_INVISIBLE;
  17. 	show_glyph(x, y, GLYPH_INVISIBLE);
  18. }
  19. }

unmap_object[edit]

  1. /*
  2. * unmap_object()
  3. *
  4. * Remove something from the map when the hero realizes it's not there any
  5. * more.  Replace it with background or known trap, but not with any other
  6. * If this is used for detection, a full screen update is imminent anyway;
  7. * if this is used to get rid of an invisible monster notation, we might have
  8. * to call newsym().
  9. */
  10. void
  11. unmap_object(x, y)
  12. register int x, y;
  13. {
  14. register struct trap *trap;
  15.  
  16. if (!level.flags.hero_memory) return;
  17.  
  18. if ((trap = t_at(x,y)) != 0 && trap->tseen && !covers_traps(x,y))
  19. 	map_trap(trap, 0);
  20. else if (levl[x][y].seenv) {
  21. 	struct rm *lev = &levl[x][y];
  22.  
  23. 	map_background(x, y, 0);
  24.  
  25. 	/* turn remembered dark room squares dark */
  26. 	if (!lev->waslit && lev->glyph == cmap_to_glyph(S_room) &&
  27. 							    lev->typ == ROOM)
  28. 	    lev->glyph = cmap_to_glyph(S_stone);
  29. } else
  30. 	levl[x][y].glyph = cmap_to_glyph(S_stone);	/* default val */
  31. }

map_location[edit]

  1. /*
  2. * map_location()
  3. *
  4. * Make whatever at this location show up.  This is only for non-living
  5. * things.  This will not handle feeling invisible objects correctly.
  6. *
  7. * Internal to display.c, this is a #define for speed.
  8. */
  9. #define _map_location(x,y,show)						\
  10. {									\
  11. register struct obj   *obj;						\
  12. register struct trap  *trap;					\
  13. 									\
  14. if ((obj = vobj_at(x,y)) && !covers_objects(x,y))			\
  15. 	map_object(obj,show);						\
  16. else if ((trap = t_at(x,y)) && trap->tseen && !covers_traps(x,y))	\
  17. 	map_trap(trap,show);						\
  18. else								\
  19. 	map_background(x,y,show);					\
  20. }
  21.  
  22. void
  23. map_location(x,y,show)
  24. int x, y, show;
  25. {
  26. _map_location(x,y,show);
  27. }
  28.  
  29. #define DETECTED 	2
  30. #define PHYSICALLY_SEEN 1
  31. #define is_worm_tail(mon)	((mon) && ((x != (mon)->mx)  || (y != (mon)->my)))

display_monster[edit]

  1. /*
  2. * display_monster()
  3. *
  4. * Note that this is *not* a map_XXXX() function!  Monsters sort of float
  5. * above everything.
  6. *
  7. * Yuck.  Display body parts by recognizing that the display position is
  8. * not the same as the monster position.  Currently the only body part is
  9. * a worm tail.
  10. *
  11. */
  12. STATIC_OVL void
  13. display_monster(x, y, mon, sightflags, worm_tail)
  14. register xchar x, y;	/* display position */
  15. register struct monst *mon;	/* monster to display */
  16. int sightflags;		/* 1 if the monster is physically seen */
  17. 				/* 2 if detected using Detect_monsters */
  18. register xchar worm_tail;	/* mon is actually a worm tail */
  19. {
  20. register boolean mon_mimic = (mon->m_ap_type != M_AP_NOTHING);
  21. register int sensed = mon_mimic &&
  22. 	(Protection_from_shape_changers || sensemon(mon));
  23. /*
  24. * We must do the mimic check first.  If the mimic is mimicing something,
  25. * and the location is in sight, we have to change the hero's memory
  26. * so that when the position is out of sight, the hero remembers what
  27. * the mimic was mimicing.
  28. */
  29.  
  30. if (mon_mimic && (sightflags == PHYSICALLY_SEEN)) {
  31. 	switch (mon->m_ap_type) {
  32. 	    default:
  33. 		impossible("display_monster:  bad m_ap_type value [ = %d ]",
  34. 							(int) mon->m_ap_type);
  35. 	    case M_AP_NOTHING:
  36. 		show_glyph(x, y, mon_to_glyph(mon));
  37. 		break;
  38.  
  39. 	    case M_AP_FURNITURE: {
  40. 		/*
  41. 		 * This is a poor man's version of map_background().  I can't
  42. 		 * use map_background() because we are overriding what is in
  43. 		 * the 'typ' field.  Maybe have map_background()'s parameters
  44. 		 * be (x,y,glyph) instead of just (x,y).
  45. 		 *
  46. 		 * mappearance is currently set to an S_ index value in
  47. 		 * makemon.c.
  48. 		 */
  49. 		register int glyph = cmap_to_glyph(mon->mappearance);
  50. 		levl[x][y].glyph = glyph;
  51. 		if (!sensed) show_glyph(x,y, glyph);
  52. 		break;
  53. 	    }
  54.  
  55. 	    case M_AP_OBJECT: {
  56. 		struct obj obj;	/* Make a fake object to send	*/
  57. 				/* to map_object().		*/
  58. 		obj.ox = x;
  59. 		obj.oy = y;
  60. 		obj.otyp = mon->mappearance;
  61. 		obj.corpsenm = PM_TENGU;	/* if mimicing a corpse */
  62. 		map_object(&obj,!sensed);
  63. 		break;
  64. 	    }
  65.  
  66. 	    case M_AP_MONSTER:
  67. 		show_glyph(x,y, monnum_to_glyph(what_mon((int)mon->mappearance)));
  68. 		break;
  69. 	}
  70.  
  71. }
  72.  
  73. /* If the mimic is unsucessfully mimicing something, display the monster */
  74. if (!mon_mimic || sensed) {
  75. 	int num;
  76.  
  77. 	/* [ALI] Only use detected glyphs when monster wouldn't be
  78. 	 * visible by any other means.
  79. 	 */
  80. 	if (sightflags == DETECTED) {
  81. 	    if (worm_tail)
  82. 		num = detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
  83. 	    else
  84. 		num = detected_mon_to_glyph(mon);
  85. 	} else if (mon->mtame && !Hallucination) {
  86. 	    if (worm_tail)
  87. 		num = petnum_to_glyph(PM_LONG_WORM_TAIL);
  88. 	    else
  89. 		num = pet_to_glyph(mon);
  90. 	} else {
  91. 	    if (worm_tail)
  92. 		num = monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
  93. 	    else
  94. 		num = mon_to_glyph(mon);
  95. 	}
  96. 	show_glyph(x,y,num);
  97. }
  98. }

display_warning[edit]

  1. /*
  2. * display_warning()
  3. *
  4. * This is also *not* a map_XXXX() function!  Monster warnings float
  5. * above everything just like monsters do, but only if the monster
  6. * is not showing.
  7. *
  8. * Do not call for worm tails.
  9. */
  10. STATIC_OVL void
  11. display_warning(mon)
  12. register struct monst *mon;
  13. {
  14. int x = mon->mx, y = mon->my;
  15. int wl = (int) (mon->m_lev / 4);
  16. int glyph;
  17.  
  18. if (mon_warning(mon)) {
  19. if (wl > WARNCOUNT - 1) wl = WARNCOUNT - 1;
  20. 	/* 3.4.1: this really ought to be rn2(WARNCOUNT), but value "0"
  21. 	   isn't handled correctly by the what_is routine so avoid it */
  22. 	if (Hallucination) wl = rn1(WARNCOUNT-1,1);
  23. glyph = warning_to_glyph(wl);
  24. } else if (MATCH_WARN_OF_MON(mon)) {
  25. 	glyph = mon_to_glyph(mon);
  26. } else {
  27. 	impossible("display_warning did not match warning type?");
  28. return;
  29. }
  30. show_glyph(x, y, glyph);
  31. }

feel_location[edit]

  1. /*
  2. * feel_location()
  3. *
  4. * Feel the given location.  This assumes that the hero is blind and that
  5. * the given position is either the hero's or one of the eight squares
  6. * adjacent to the hero (except for a boulder push).
  7. * If an invisible monster has gone away, that will be discovered.  If an
  8. * invisible monster has appeared, this will _not_ be discovered since
  9. * searching only finds one monster per turn so we must check that separately.
  10. */
  11. void
  12. feel_location(x, y)
  13. xchar x, y;
  14. {
  15. struct rm *lev = &(levl[x][y]);
  16. struct obj *boulder;
  17. register struct monst *mon;
  18.  
  19. /* If the hero's memory of an invisible monster is accurate, we want to keep
  20. * him from detecting the same monster over and over again on each turn.
  21. * We must return (so we don't erase the monster).  (We must also, in the
  22. * search function, be sure to skip over previously detected 'I's.)
  23. */
  24. if (glyph_is_invisible(levl[x][y].glyph) && m_at(x,y)) return;
  25.  
  26. /* The hero can't feel non pool locations while under water. */
  27. if (Underwater && !Is_waterlevel(&u.uz) && ! is_pool(x,y))
  28. 	return;
  29.  
  30. /* Set the seen vector as if the hero had seen it.  It doesn't matter */
  31. /* if the hero is levitating or not.				  */
  32. set_seenv(lev, u.ux, u.uy, x, y);
  33.  
  34. if (Levitation && !Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz)) {
  35. 	/*
  36. 	 * Levitation Rules.  It is assumed that the hero can feel the state
  37. 	 * of the walls around herself and can tell if she is in a corridor,
  38. 	 * room, or doorway.  Boulders are felt because they are large enough.
  39. 	 * Anything else is unknown because the hero can't reach the ground.
  40. 	 * This makes things difficult.
  41. 	 *
  42. 	 * Check (and display) in order:
  43. 	 *
  44. 	 *	+ Stone, walls, and closed doors.
  45. 	 *	+ Boulders.  [see a boulder before a doorway]
  46. 	 *	+ Doors.
  47. 	 *	+ Room/water positions
  48. 	 *	+ Everything else (hallways!)
  49. 	 */
  50. 	if (IS_ROCK(lev->typ) || (IS_DOOR(lev->typ) &&
  51. 				(lev->doormask & (D_LOCKED | D_CLOSED)))) {
  52. 	    map_background(x, y, 1);
  53. 	} else if ((boulder = sobj_at(BOULDER,x,y)) != 0) {
  54. 	    map_object(boulder, 1);
  55. 	} else if (IS_DOOR(lev->typ)) {
  56. 	    map_background(x, y, 1);
  57. 	} else if (IS_ROOM(lev->typ) || IS_POOL(lev->typ)) {
  58. 	    /*
  59. 	     * An open room or water location.  Normally we wouldn't touch
  60. 	     * this, but we have to get rid of remembered boulder symbols.
  61. 	     * This will only occur in rare occations when the hero goes
  62. 	     * blind and doesn't find a boulder where expected (something
  63. 	     * came along and picked it up).  We know that there is not a
  64. 	     * boulder at this location.  Show fountains, pools, etc.
  65. 	     * underneath if already seen.  Otherwise, show the appropriate
  66. 	     * floor symbol.
  67. 	     *
  68. 	     * Similarly, if the hero digs a hole in a wall or feels a location
  69. 	     * that used to contain an unseen monster.  In these cases,
  70. 	     * there's no reason to assume anything was underneath, so
  71. 	     * just show the appropriate floor symbol.  If something was
  72. 	     * embedded in the wall, the glyph will probably already
  73. 	     * reflect that.  Don't change the symbol in this case.
  74. 	     *
  75. 	     * This isn't quite correct.  If the boulder was on top of some
  76. 	     * other objects they should be seen once the boulder is removed.
  77. 	     * However, we have no way of knowing that what is there now
  78. 	     * was there then.  So we let the hero have a lapse of memory.
  79. 	     * We could also just display what is currently on the top of the
  80. 	     * object stack (if anything).
  81. 	     */
  82. 	    if (lev->glyph == objnum_to_glyph(BOULDER)) {
  83. 		if (lev->typ != ROOM && lev->seenv) {
  84. 		    map_background(x, y, 1);
  85. 		} else {
  86. 		    lev->glyph = lev->waslit ? cmap_to_glyph(S_room) :
  87. 					       cmap_to_glyph(S_stone);
  88. 		    show_glyph(x,y,lev->glyph);
  89. 		}
  90. 	    } else if ((lev->glyph >= cmap_to_glyph(S_stone) &&
  91. 			lev->glyph < cmap_to_glyph(S_room)) ||
  92. 		       glyph_is_invisible(levl[x][y].glyph)) {
  93. 		lev->glyph = lev->waslit ? cmap_to_glyph(S_room) :
  94. 					   cmap_to_glyph(S_stone);
  95. 		show_glyph(x,y,lev->glyph);
  96. 	    }
  97. 	} else {
  98. 	    /* We feel it (I think hallways are the only things left). */
  99. 	    map_background(x, y, 1);
  100. 	    /* Corridors are never felt as lit (unless remembered that way) */
  101. 	    /* (lit_corridor only).					    */
  102. 	    if (lev->typ == CORR &&
  103. 		    lev->glyph == cmap_to_glyph(S_litcorr) && !lev->waslit)
  104. 		show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
  105. 	}
  106. } else {
  107. 	_map_location(x, y, 1);
  108.  
  109. 	if (Punished) {
  110. 	    /*
  111. 	     * A ball or chain is only felt if it is first on the object
  112. 	     * location list.  Otherwise, we need to clear the felt bit ---
  113. 	     * something has been dropped on the ball/chain.  If the bit is
  114. 	     * not cleared, then when the ball/chain is moved it will drop
  115. 	     * the wrong glyph.
  116. 	     */
  117. 	    if (uchain->ox == x && uchain->oy == y) {
  118. 		if (level.objects[x][y] == uchain)
  119. 		    u.bc_felt |= BC_CHAIN;
  120. 		else
  121. 		    u.bc_felt &= ~BC_CHAIN;	/* do not feel the chain */
  122. 	    }
  123. 	    if (!carried(uball) && uball->ox == x && uball->oy == y) {
  124. 		if (level.objects[x][y] == uball)
  125. 		    u.bc_felt |= BC_BALL;
  126. 		else
  127. 		    u.bc_felt &= ~BC_BALL;	/* do not feel the ball */
  128. 	    }
  129. 	}
  130.  
  131. 	/* Floor spaces are dark if unlit.  Corridors are dark if unlit. */
  132. 	if (lev->typ == ROOM &&
  133. 		    lev->glyph == cmap_to_glyph(S_room) && !lev->waslit)
  134. 	    show_glyph(x,y, lev->glyph = cmap_to_glyph(S_stone));
  135. 	else if (lev->typ == CORR &&
  136. 		    lev->glyph == cmap_to_glyph(S_litcorr) && !lev->waslit)
  137. 	    show_glyph(x,y, lev->glyph = cmap_to_glyph(S_corr));
  138. }
  139. /* draw monster on top if we can sense it */
  140. if ((x != u.ux || y != u.uy) && (mon = m_at(x,y)) && sensemon(mon))
  141. 	display_monster(x, y, mon,
  142. 		(tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)) ? PHYSICALLY_SEEN : DETECTED,
  143. 		is_worm_tail(mon));
  144. }

newsym[edit]

  1. /*
  2. * newsym()
  3. *
  4. * Possibly put a new glyph at the given location.
  5. */
  6. void
  7. newsym(x,y)
  8. register int x,y;
  9. {
  10. register struct monst *mon;
  11. register struct rm *lev = &(levl[x][y]);
  12. register int see_it;
  13. register xchar worm_tail;
  14.  
  15. if (in_mklev) return;
  16.  
  17. /* only permit updating the hero when swallowed */
  18. if (u.uswallow) {
  19. 	if (x == u.ux && y == u.uy) display_self();
  20. 	return;
  21. }
  22. if (Underwater && !Is_waterlevel(&u.uz)) {
  23. 	/* don't do anything unless (x,y) is an adjacent underwater position */
  24. 	int dx, dy;
  25. 	if (!is_pool(x,y)) return;
  26. 	dx = x - u.ux;	if (dx < 0) dx = -dx;
  27. 	dy = y - u.uy;	if (dy < 0) dy = -dy;
  28. 	if (dx > 1 || dy > 1) return;
  29. }
  30.  
  31. /* Can physically see the location. */
  32. if (cansee(x,y)) {
  33. NhRegion* reg = visible_region_at(x,y);
  34. 	/*
  35. 	 * Don't use templit here:  E.g.
  36. 	 *
  37. 	 *	lev->waslit = !!(lev->lit || templit(x,y));
  38. 	 *
  39. 	 * Otherwise we have the "light pool" problem, where non-permanently
  40. 	 * lit areas just out of sight stay remembered as lit.  They should
  41. 	 * re-darken.
  42. 	 *
  43. 	 * Perhaps ALL areas should revert to their "unlit" look when
  44. 	 * out of sight.
  45. 	 */
  46. 	lev->waslit = (lev->lit!=0);	/* remember lit condition */
  47.  
  48. 	if (reg != NULL && ACCESSIBLE(lev->typ)) {
  49. 	    show_region(reg,x,y);
  50. 	    return;
  51. 	}
  52. 	if (x == u.ux && y == u.uy) {
  53. 	    if (senseself()) {
  54. 		_map_location(x,y,0);	/* map *under* self */
  55. 		display_self();
  56. 	    } else
  57. 		/* we can see what is there */
  58. 		_map_location(x,y,1);
  59. 	}
  60. 	else {
  61. 	    mon = m_at(x,y);
  62. 	    worm_tail = is_worm_tail(mon);
  63. 	    see_it = mon && (worm_tail
  64. 		? (!mon->minvis || See_invisible)
  65. 		: (mon_visible(mon)) || tp_sensemon(mon) || MATCH_WARN_OF_MON(mon));
  66. 	    if (mon && (see_it || (!worm_tail && Detect_monsters))) {
  67. 		if (mon->mtrapped) {
  68. 		    struct trap *trap = t_at(x, y);
  69. 		    int tt = trap ? trap->ttyp : NO_TRAP;
  70.  
  71. 		    /* if monster is in a physical trap, you see the trap too */
  72. 		    if (tt == BEAR_TRAP || tt == PIT ||
  73. 			tt == SPIKED_PIT ||tt == WEB) {
  74. 			trap->tseen = TRUE;
  75. 		    }
  76. 		}
  77. 		_map_location(x,y,0);	/* map under the monster */
  78. 		/* also gets rid of any invisibility glyph */
  79. 		display_monster(x, y, mon, see_it ? PHYSICALLY_SEEN : DETECTED, worm_tail);
  80. 	    }
  81. 	    else if (mon && mon_warning(mon) && !is_worm_tail(mon))
  82. 	        display_warning(mon);
  83. 	    else if (glyph_is_invisible(levl[x][y].glyph))
  84. 		map_invisible(x, y);
  85. 	    else
  86. 		_map_location(x,y,1);	/* map the location */
  87. 	}
  88. }
  89.  
  90. /* Can't see the location. */
  91. else {
  92. 	if (x == u.ux && y == u.uy) {
  93. 	    feel_location(u.ux, u.uy);		/* forces an update */
  94.  
  95. 	    if (senseself()) display_self();
  96. 	}
  97. 	else if ((mon = m_at(x,y))
  98. 		&& ((see_it = (tp_sensemon(mon) || MATCH_WARN_OF_MON(mon)
  99. 		    		|| (see_with_infrared(mon) && mon_visible(mon))))
  100. 		    || Detect_monsters)
  101. 		&& !is_worm_tail(mon)) {
  102. 	    /* Monsters are printed every time. */
  103. 	    /* This also gets rid of any invisibility glyph */
  104. 	    display_monster(x, y, mon, see_it ? 0 : DETECTED, 0);
  105. 	}
  106. 	else if ((mon = m_at(x,y)) && mon_warning(mon) &&
  107. 		 !is_worm_tail(mon)) {
  108. 	        display_warning(mon);
  109. 	}		
  110.  
  111. 	/*
  112. 	 * If the location is remembered as being both dark (waslit is false)
  113. 	 * and lit (glyph is a lit room or lit corridor) then it was either:
  114. 	 *
  115. 	 *	(1) A dark location that the hero could see through night
  116. 	 *	    vision.
  117. 	 *
  118. 	 *	(2) Darkened while out of the hero's sight.  This can happen
  119. 	 *	    when cursed scroll of light is read.
  120. 	 *
  121. 	 * In either case, we have to manually correct the hero's memory to
  122. 	 * match waslit.  Deciding when to change waslit is non-trivial.
  123. 	 *
  124. 	 *  Note:  If flags.lit_corridor is set, then corridors act like room
  125. 	 *	   squares.  That is, they light up if in night vision range.
  126. 	 *	   If flags.lit_corridor is not set, then corridors will
  127. 	 *	   remain dark unless lit by a light spell and may darken
  128. 	 *	   again, as discussed above.
  129. 	 *
  130. 	 * These checks and changes must be here and not in back_to_glyph().
  131. 	 * They are dependent on the position being out of sight.
  132. 	 */
  133. 	else if (!lev->waslit) {
  134. 	    if (lev->glyph == cmap_to_glyph(S_litcorr) && lev->typ == CORR)
  135. 		show_glyph(x, y, lev->glyph = cmap_to_glyph(S_corr));
  136. 	    else if (lev->glyph == cmap_to_glyph(S_room) && lev->typ == ROOM)
  137. 		show_glyph(x, y, lev->glyph = cmap_to_glyph(S_stone));
  138. 	    else
  139. 		goto show_mem;
  140. 	} else {
  141. show_mem:
  142. 	    show_glyph(x, y, lev->glyph);
  143. 	}
  144. }
  145. }
  146.  
  147. #undef is_worm_tail

shieldeff[edit]

  1. /*
  2. * shieldeff()
  3. *
  4. * Put magic shield pyrotechnics at the given location.  This *could* be
  5. * pulled into a platform dependent routine for fancier graphics if desired.
  6. */
  7. void
  8. shieldeff(x,y)
  9. xchar x,y;
  10. {
  11. register int i;
  12.  
  13. if (!flags.sparkle) return;
  14. if (cansee(x,y)) {	/* Don't see anything if can't see the location */
  15. 	for (i = 0; i < SHIELD_COUNT; i++) {
  16. 	    show_glyph(x, y, cmap_to_glyph(shield_static[i]));
  17. 	    flush_screen(1);	/* make sure the glyph shows up */
  18. 	    delay_output();
  19. 	}
  20. 	newsym(x,y);		/* restore the old information */
  21. }
  22. }

tmp_at[edit]

  1. /*
  2. * tmp_at()
  3. *
  4. * Temporarily place glyphs on the screen.  Do not call delay_output().  It
  5. * is up to the caller to decide if it wants to wait [presently, everyone
  6. * but explode() wants to delay].
  7. *
  8. * Call:
  9. *	(DISP_BEAM,   glyph)	open, initialize glyph
  10. *	(DISP_FLASH,  glyph)	open, initialize glyph
  11. *	(DISP_ALWAYS, glyph)	open, initialize glyph
  12. *	(DISP_CHANGE, glyph)	change glyph
  13. *	(DISP_END,    0)	close & clean up (second argument doesn't
  14. *				matter)
  15. *	(DISP_FREEMEM, 0)	only used to prevent memory leak during
  16. *				exit)
  17. *	(x, y)			display the glyph at the location
  18. *
  19. * DISP_BEAM  - Display the given glyph at each location, but do not erase
  20. *		any until the close call.
  21. * DISP_FLASH - Display the given glyph at each location, but erase the
  22. *		previous location's glyph.
  23. * DISP_ALWAYS- Like DISP_FLASH, but vision is not taken into account.
  24. */
  25.  
  26. static struct tmp_glyph {
  27. coord saved[COLNO];	/* previously updated positions */
  28. int sidx;		/* index of next unused slot in saved[] */
  29. int style;		/* either DISP_BEAM or DISP_FLASH or DISP_ALWAYS */
  30. int glyph;		/* glyph to use when printing */
  31. struct tmp_glyph *prev;
  32. } tgfirst;
  33.  
  34. void
  35. tmp_at(x, y)
  36. int x, y;
  37. {
  38. static struct tmp_glyph *tglyph = (struct tmp_glyph *)0;
  39. struct tmp_glyph *tmp;
  40.  
  41. switch (x) {
  42. 	case DISP_BEAM:
  43. 	case DISP_FLASH:
  44. 	case DISP_ALWAYS:
  45. 	    if (!tglyph)
  46. 		tmp = &tgfirst;
  47. 	    else	/* nested effect; we need dynamic memory */
  48. 		tmp = (struct tmp_glyph *)alloc(sizeof (struct tmp_glyph));
  49. 	    tmp->prev = tglyph;
  50. 	    tglyph = tmp;
  51. 	    tglyph->sidx = 0;
  52. 	    tglyph->style = x;
  53. 	    tglyph->glyph = y;
  54. 	    flush_screen(0);	/* flush buffered glyphs */
  55. 	    return;
  56.  
  57. 	case DISP_FREEMEM:  /* in case game ends with tmp_at() in progress */
  58. 	    while (tglyph) {
  59. 		tmp = tglyph->prev;
  60. 		if (tglyph != &tgfirst) free((genericptr_t)tglyph);
  61. 		tglyph = tmp;
  62. 	    }
  63. 	    return;
  64.  
  65. 	default:
  66. 	    break;
  67. }
  68.  
  69. if (!tglyph) panic("tmp_at: tglyph not initialized");
  70.  
  71. switch (x) {
  72. 	case DISP_CHANGE:
  73. 	    tglyph->glyph = y;
  74. 	    break;
  75.  
  76. 	case DISP_END:
  77. 	    if (tglyph->style == DISP_BEAM) {
  78. 		register int i;
  79.  
  80. 		/* Erase (reset) from source to end */
  81. 		for (i = 0; i < tglyph->sidx; i++)
  82. 		    newsym(tglyph->saved[i].x, tglyph->saved[i].y);
  83. 	    } else {		/* DISP_FLASH or DISP_ALWAYS */
  84. 		if (tglyph->sidx)	/* been called at least once */
  85. 		    newsym(tglyph->saved[0].x, tglyph->saved[0].y);
  86. 	    }
  87. 	 /* tglyph->sidx = 0; -- about to be freed, so not necessary */
  88. 	    tmp = tglyph->prev;
  89. 	    if (tglyph != &tgfirst) free((genericptr_t)tglyph);
  90. 	    tglyph = tmp;
  91. 	    break;
  92.  
  93. 	default:	/* do it */
  94. 	    if (tglyph->style == DISP_BEAM) {
  95. 		if (!cansee(x,y)) break;
  96. 		/* save pos for later erasing */
  97. 		tglyph->saved[tglyph->sidx].x = x;
  98. 		tglyph->saved[tglyph->sidx].y = y;
  99. 		tglyph->sidx += 1;
  100. 	    } else {	/* DISP_FLASH/ALWAYS */
  101. 		if (tglyph->sidx) { /* not first call, so reset previous pos */
  102. 		    newsym(tglyph->saved[0].x, tglyph->saved[0].y);
  103. 		    tglyph->sidx = 0;	/* display is presently up to date */
  104. 		}
  105. 		if (!cansee(x,y) && tglyph->style != DISP_ALWAYS) break;
  106. 		tglyph->saved[0].x = x;
  107. 		tglyph->saved[0].y = y;
  108. 		tglyph->sidx = 1;
  109. 	    }
  110.  
  111. 	    show_glyph(x, y, tglyph->glyph);	/* show it */
  112. 	    flush_screen(0);			/* make sure it shows up */
  113. 	    break;
  114. } /* end case */
  115. }

swallowed[edit]

  1. /*
  2. * swallowed()
  3. *
  4. * The hero is swallowed.  Show a special graphics sequence for this.  This
  5. * bypasses all of the display routines and messes with buffered screen
  6. * directly.  This method works because both vision and display check for
  7. * being swallowed.
  8. */
  9. void
  10. swallowed(first)
  11. int first;
  12. {
  13. static xchar lastx, lasty;	/* last swallowed position */
  14. int swallower, left_ok, rght_ok;
  15.  
  16. if (first)
  17. 	cls();
  18. else {
  19. 	register int x, y;
  20.  
  21. 	/* Clear old location */
  22. 	for (y = lasty-1; y <= lasty+1; y++)
  23. 	    for (x = lastx-1; x <= lastx+1; x++)
  24. 		if (isok(x,y)) show_glyph(x,y,cmap_to_glyph(S_stone));
  25. }
  26.  
  27. swallower = monsndx(u.ustuck->data);
  28. /* assume isok(u.ux,u.uy) */
  29. left_ok = isok(u.ux-1,u.uy);
  30. rght_ok = isok(u.ux+1,u.uy);
  31. /*
  32. *  Display the hero surrounded by the monster's stomach.
  33. */
  34. if(isok(u.ux, u.uy-1)) {
  35. 	if (left_ok)
  36. 	show_glyph(u.ux-1, u.uy-1, swallow_to_glyph(swallower, S_sw_tl));
  37. 	show_glyph(u.ux  , u.uy-1, swallow_to_glyph(swallower, S_sw_tc));
  38. 	if (rght_ok)
  39. 	show_glyph(u.ux+1, u.uy-1, swallow_to_glyph(swallower, S_sw_tr));
  40. }
  41.  
  42. if (left_ok)
  43. show_glyph(u.ux-1, u.uy  , swallow_to_glyph(swallower, S_sw_ml));
  44. display_self();
  45. if (rght_ok)
  46. show_glyph(u.ux+1, u.uy  , swallow_to_glyph(swallower, S_sw_mr));
  47.  
  48. if(isok(u.ux, u.uy+1)) {
  49. 	if (left_ok)
  50. 	show_glyph(u.ux-1, u.uy+1, swallow_to_glyph(swallower, S_sw_bl));
  51. 	show_glyph(u.ux  , u.uy+1, swallow_to_glyph(swallower, S_sw_bc));
  52. 	if (rght_ok)
  53. 	show_glyph(u.ux+1, u.uy+1, swallow_to_glyph(swallower, S_sw_br));
  54. }
  55.  
  56. /* Update the swallowed position. */
  57. lastx = u.ux;
  58. lasty = u.uy;
  59. }

under_water[edit]

  1. /*
  2. * under_water()
  3. *
  4. * Similar to swallowed() in operation.  Shows hero when underwater
  5. * except when in water level.  Special routines exist for that.
  6. */
  7. void
  8. under_water(mode)
  9. int mode;
  10. {
  11. static xchar lastx, lasty;
  12. static boolean dela;
  13. register int x, y;
  14.  
  15. /* swallowing has a higher precedence than under water */
  16. if (Is_waterlevel(&u.uz) || u.uswallow) return;
  17.  
  18. /* full update */
  19. if (mode == 1 || dela) {
  20. 	cls();
  21. 	dela = FALSE;
  22. }
  23. /* delayed full update */
  24. else if (mode == 2) {
  25. 	dela = TRUE;
  26. 	return;
  27. }
  28. /* limited update */
  29. else {
  30. 	for (y = lasty-1; y <= lasty+1; y++)
  31. 	    for (x = lastx-1; x <= lastx+1; x++)
  32. 		if (isok(x,y))
  33. 		    show_glyph(x,y,cmap_to_glyph(S_stone));
  34. }
  35. for (x = u.ux-1; x <= u.ux+1; x++)
  36. 	for (y = u.uy-1; y <= u.uy+1; y++)
  37. 	    if (isok(x,y) && is_pool(x,y)) {
  38. 		if (Blind && !(x == u.ux && y == u.uy))
  39. 		    show_glyph(x,y,cmap_to_glyph(S_stone));
  40. 		else	
  41. 		    newsym(x,y);
  42. 	    }
  43. lastx = u.ux;
  44. lasty = u.uy;
  45. }

under_ground[edit]

  1. /*
  2. *	under_ground()
  3. *
  4. *	Very restricted display.  You can only see yourself.
  5. */
  6. void
  7. under_ground(mode)
  8. int mode;
  9. {
  10. static boolean dela;
  11.  
  12. /* swallowing has a higher precedence than under ground */
  13. if (u.uswallow) return;
  14.  
  15. /* full update */
  16. if (mode == 1 || dela) {
  17. 	cls();
  18. 	dela = FALSE;
  19. }
  20. /* delayed full update */
  21. else if (mode == 2) {
  22. 	dela = TRUE;
  23. 	return;
  24. }
  25. /* limited update */
  26. else
  27. 	newsym(u.ux,u.uy);
  28. }
  29.  
  30.  
  31. /* ========================================================================= */

see_monsters[edit]

  1. /*
  2. * Loop through all of the monsters and update them.  Called when:
  3. *	+ going blind & telepathic
  4. *	+ regaining sight & telepathic
  5. *      + getting and losing infravision 
  6. *	+ hallucinating
  7. *	+ doing a full screen redraw
  8. *	+ see invisible times out or a ring of see invisible is taken off
  9. *	+ when a potion of see invisible is quaffed or a ring of see
  10. *	  invisible is put on
  11. *	+ gaining telepathy when blind [givit() in eat.c, pleased() in pray.c]
  12. *	+ losing telepathy while blind [xkilled() in mon.c, attrcurse() in
  13. *	  sit.c]
  14. */
  15. void
  16. see_monsters()
  17. {
  18. register struct monst *mon;
  19.  
  20. for (mon = fmon; mon; mon = mon->nmon) {
  21. 	if (DEADMONSTER(mon)) continue;
  22. 	newsym(mon->mx,mon->my);
  23. 	if (mon->wormno) see_wsegs(mon);
  24. }
  25. #ifdef STEED
  26. /* when mounted, hero's location gets caught by monster loop */
  27. if (!u.usteed)
  28. #endif
  29. newsym(u.ux, u.uy);
  30. }

set_mimic_blocking[edit]

  1. /*
  2. * Block/unblock light depending on what a mimic is mimicing and if it's
  3. * invisible or not.  Should be called only when the state of See_invisible
  4. * changes.
  5. */
  6. void
  7. set_mimic_blocking()
  8. {
  9. register struct monst *mon;
  10.  
  11. for (mon = fmon; mon; mon = mon->nmon) {
  12. 	if (DEADMONSTER(mon)) continue;
  13. 	if (mon->minvis &&
  14. 	   ((mon->m_ap_type == M_AP_FURNITURE &&
  15. 	     (mon->mappearance == S_vcdoor || mon->mappearance == S_hcdoor)) ||
  16. 	    (mon->m_ap_type == M_AP_OBJECT && mon->mappearance == BOULDER))) {
  17. 	    if(See_invisible)
  18. 		block_point(mon->mx, mon->my);
  19. 	    else
  20. 		unblock_point(mon->mx, mon->my);
  21. 	}
  22. }
  23. }

see_objects[edit]

  1. /*
  2. * Loop through all of the object *locations* and update them.  Called when
  3. *	+ hallucinating.
  4. */
  5. void
  6. see_objects()
  7. {
  8. register struct obj *obj;
  9. for(obj = fobj; obj; obj = obj->nobj)
  10. 	if (vobj_at(obj->ox,obj->oy) == obj) newsym(obj->ox, obj->oy);
  11. }

see_traps[edit]

  1. /*
  2. * Update hallucinated traps.
  3. */
  4. void
  5. see_traps()
  6. {
  7. struct trap *trap;
  8. int glyph;
  9.  
  10. for (trap = ftrap; trap; trap = trap->ntrap) {
  11. 	glyph = glyph_at(trap->tx, trap->ty);
  12. 	if (glyph_is_trap(glyph))
  13. 	    newsym(trap->tx, trap->ty);
  14. }
  15. }

curs_on_u[edit]

  1. /*
  2. * Put the cursor on the hero.  Flush all accumulated glyphs before doing it.
  3. */
  4. void
  5. curs_on_u()
  6. {
  7. flush_screen(1);	/* Flush waiting glyphs & put cursor on hero */
  8. }

doredraw[edit]

  1. int
  2. doredraw()
  3. {
  4. docrt();
  5. return 0;
  6. }

docrt[edit]

  1. void
  2. docrt()
  3. {
  4. register int x,y;
  5. register struct rm *lev;
  6.  
  7. if (!u.ux) return; /* display isn't ready yet */
  8.  
  9. if (u.uswallow) {
  10. 	swallowed(1);
  11. 	return;
  12. }
  13. if (Underwater && !Is_waterlevel(&u.uz)) {
  14. 	under_water(1);
  15. 	return;
  16. }
  17. if (u.uburied) {
  18. 	under_ground(1);
  19. 	return;
  20. }
  21.  
  22. /* shut down vision */
  23. vision_recalc(2);
  24.  
  25. /*
  26. * This routine assumes that cls() does the following:
  27. *      + fills the physical screen with the symbol for rock
  28. *      + clears the glyph buffer
  29. */
  30. cls();
  31.  
  32. /* display memory */
  33. for (x = 1; x < COLNO; x++) {
  34. 	lev = &levl[x][0];
  35. 	for (y = 0; y < ROWNO; y++, lev++)
  36. 	    if (lev->glyph != cmap_to_glyph(S_stone))
  37. 		show_glyph(x,y,lev->glyph);
  38. }
  39.  
  40. /* see what is to be seen */
  41. vision_recalc(0);
  42.  
  43. /* overlay with monsters */
  44. see_monsters();
  45.  
  46. flags.botlx = 1;	/* force a redraw of the bottom line */
  47. }
  48.  
  49.  
  50. /* ========================================================================= */

show_glyph[edit]

  1. /* Glyph Buffering (3rd screen) ============================================ */
  2.  
  3. typedef struct {
  4. xchar new;		/* perhaps move this bit into the rm strucure. */
  5. int   glyph;
  6. } gbuf_entry;
  7.  
  8. static gbuf_entry gbuf[ROWNO][COLNO];
  9. static char gbuf_start[ROWNO];
  10. static char gbuf_stop[ROWNO];
  11.  
  12. /*
  13. * Store the glyph in the 3rd screen for later flushing.
  14. */
  15. void
  16. show_glyph(x,y,glyph)
  17. int x, y, glyph;
  18. {
  19. /*
  20. * Check for bad positions and glyphs.
  21. */
  22. if (!isok(x, y)) {
  23. 	const char *text;
  24. 	int  offset;
  25.  
  26. 	/* column 0 is invalid, but it's often used as a flag, so ignore it */
  27. 	if (x == 0) return;
  28.  
  29. 	/*
  30. 	 *  This assumes an ordering of the offsets.  See display.h for
  31. 	 *  the definition.
  32. 	 */
  33.  
  34. 	if (glyph >= GLYPH_WARNING_OFF) {	/* a warning */
  35. 	    text = "warning";		offset = glyph - GLYPH_WARNING_OFF;
  36. 	} else if (glyph >= GLYPH_SWALLOW_OFF) {	/* swallow border */
  37. 	    text = "swallow border";	offset = glyph - GLYPH_SWALLOW_OFF;
  38. 	} else if (glyph >= GLYPH_ZAP_OFF) {		/* zap beam */
  39. 	    text = "zap beam";		offset = glyph - GLYPH_ZAP_OFF;
  40. 	} else if (glyph >= GLYPH_EXPLODE_OFF) {	/* explosion */
  41. 	    text = "explosion";		offset = glyph - GLYPH_EXPLODE_OFF;
  42. 	} else if (glyph >= GLYPH_CMAP_OFF) {		/* cmap */
  43. 	    text = "cmap_index";	offset = glyph - GLYPH_CMAP_OFF;
  44. 	} else if (glyph >= GLYPH_OBJ_OFF) {		/* object */
  45. 	    text = "object";		offset = glyph - GLYPH_OBJ_OFF;
  46. 	} else if (glyph >= GLYPH_RIDDEN_OFF) {		/* ridden mon */
  47. 	    text = "ridden mon";	offset = glyph - GLYPH_RIDDEN_OFF;
  48. 	} else if (glyph >= GLYPH_BODY_OFF) {		/* a corpse */
  49. 	    text = "corpse";		offset = glyph - GLYPH_BODY_OFF;
  50. 	} else if (glyph >= GLYPH_DETECT_OFF) {		/* detected mon */
  51. 	    text = "detected mon";	offset = glyph - GLYPH_DETECT_OFF;
  52. 	} else if (glyph >= GLYPH_INVIS_OFF) {		/* invisible mon */
  53. 	    text = "invisible mon";	offset = glyph - GLYPH_INVIS_OFF;
  54. 	} else if (glyph >= GLYPH_PET_OFF) {		/* a pet */
  55. 	    text = "pet";		offset = glyph - GLYPH_PET_OFF;
  56. 	} else {					/* a monster */
  57. 	    text = "monster";		offset = glyph;
  58. 	}
  59.  
  60. 	impossible("show_glyph:  bad pos %d %d with glyph %d [%s %d].",
  61. 						x, y, glyph, text, offset);
  62. 	return;
  63. }
  64.  
  65. if (glyph >= MAX_GLYPH) {
  66. 	impossible("show_glyph:  bad glyph %d [max %d] at (%d,%d).",
  67. 					glyph, MAX_GLYPH, x, y);
  68. 	return;
  69. }
  70.  
  71. if (gbuf[y][x].glyph != glyph) {
  72. 	gbuf[y][x].glyph = glyph;
  73. 	gbuf[y][x].new   = 1;
  74. 	if (gbuf_start[y] > x) gbuf_start[y] = x;
  75. 	if (gbuf_stop[y]  < x) gbuf_stop[y]  = x;
  76. }
  77. }

clear_glyph_buffer[edit]

  1. /*
  2. * Reset the changed glyph borders so that none of the 3rd screen has
  3. * changed.
  4. */
  5. #define reset_glyph_bbox()			\
  6. {						\
  7. 	int i;					\
  8. 						\
  9. 	for (i = 0; i < ROWNO; i++) {		\
  10. 	    gbuf_start[i] = COLNO-1;		\
  11. 	    gbuf_stop[i]  = 0;			\
  12. 	}					\
  13. }
  14.  
  15.  
  16. static gbuf_entry nul_gbuf = { 0, cmap_to_glyph(S_stone) };
  17. /*
  18. * Turn the 3rd screen into stone.
  19. */
  20. void
  21. clear_glyph_buffer()
  22. {
  23. register int x, y;
  24. register gbuf_entry *gptr;
  25.  
  26. for (y = 0; y < ROWNO; y++) {
  27. 	gptr = &gbuf[y][0];
  28. 	for (x = COLNO; x; x--) {
  29. 	    *gptr++ = nul_gbuf;
  30. 	}
  31. }
  32. reset_glyph_bbox();
  33. }

row_refresh[edit]

  1. /*
  2. * Assumes that the indicated positions are filled with S_stone glyphs.
  3. */
  4. void
  5. row_refresh(start,stop,y)
  6. int start,stop,y;
  7. {
  8. register int x;
  9.  
  10. for (x = start; x <= stop; x++)
  11. 	if (gbuf[y][x].glyph != cmap_to_glyph(S_stone))
  12. 	    print_glyph(WIN_MAP,x,y,gbuf[y][x].glyph);
  13. }

cls[edit]

  1. void
  2. cls()
  3. {
  4. display_nhwindow(WIN_MESSAGE, FALSE); /* flush messages */
  5. flags.botlx = 1;		/* force update of botl window */
  6. clear_nhwindow(WIN_MAP);	/* clear physical screen */
  7.  
  8. clear_glyph_buffer();	/* this is sort of an extra effort, but OK */
  9. }

flush_screen[edit]

  1. /*
  2. * Synch the third screen with the display.
  3. */
  4. void
  5. flush_screen(cursor_on_u)
  6. int cursor_on_u;
  7. {
  8. /* Prevent infinite loops on errors:
  9. *	    flush_screen->print_glyph->impossible->pline->flush_screen
  10. */
  11. static   boolean flushing = 0;
  12. static   boolean delay_flushing = 0;
  13. register int x,y;
  14.  
  15. if (cursor_on_u == -1) delay_flushing = !delay_flushing;
  16. if (delay_flushing) return;
  17. if (flushing) return;	/* if already flushing then return */
  18. flushing = 1;
  19.  
  20. for (y = 0; y < ROWNO; y++) {
  21. 	register gbuf_entry *gptr = &gbuf[y][x = gbuf_start[y]];
  22. 	for (; x <= gbuf_stop[y]; gptr++, x++)
  23. 	    if (gptr->new) {
  24. 		print_glyph(WIN_MAP,x,y,gptr->glyph);
  25. 		gptr->new = 0;
  26. 	    }
  27. }
  28.  
  29. if (cursor_on_u) curs(WIN_MAP, u.ux,u.uy); /* move cursor to the hero */
  30. display_nhwindow(WIN_MAP, FALSE);
  31. reset_glyph_bbox();
  32. flushing = 0;
  33. if(flags.botl || flags.botlx) bot();
  34. }
  35.  
  36. /* ========================================================================= */

back_to_glyph[edit]

  1. /*
  2. * back_to_glyph()
  3. *
  4. * Use the information in the rm structure at the given position to create
  5. * a glyph of a background.
  6. *
  7. * I had to add a field in the rm structure (horizontal) so that we knew
  8. * if open doors and secret doors were horizontal or vertical.  Previously,
  9. * the screen symbol had the horizontal/vertical information set at
  10. * level generation time.
  11. *
  12. * I used the 'ladder' field (really doormask) for deciding if stairwells
  13. * were up or down.  I didn't want to check the upstairs and dnstairs
  14. * variables.
  15. */
  16. int
  17. back_to_glyph(x,y)
  18. xchar x,y;
  19. {
  20. int idx;
  21. struct rm *ptr = &(levl[x][y]);
  22.  
  23. switch (ptr->typ) {
  24. 	case SCORR:
  25. 	case STONE:
  26. 	    idx = level.flags.arboreal ? S_tree : S_stone;
  27. 	    break;
  28. 	case ROOM:		idx = S_room;	  break;
  29. 	case CORR:
  30. 	    idx = (ptr->waslit || flags.lit_corridor) ? S_litcorr : S_corr;
  31. 	    break;
  32. 	case HWALL:
  33. 	case VWALL:
  34. 	case TLCORNER:
  35. 	case TRCORNER:
  36. 	case BLCORNER:
  37. 	case BRCORNER:
  38. 	case CROSSWALL:
  39. 	case TUWALL:
  40. 	case TDWALL:
  41. 	case TLWALL:
  42. 	case TRWALL:
  43. 	case SDOOR:
  44. 	    idx = ptr->seenv ? wall_angle(ptr) : S_stone;
  45. 	    break;
  46. 	case DOOR:
  47. 	    if (ptr->doormask) {
  48. 		if (ptr->doormask & D_BROKEN)
  49. 		    idx = S_ndoor;
  50. 		else if (ptr->doormask & D_ISOPEN)
  51. 		    idx = (ptr->horizontal) ? S_hodoor : S_vodoor;
  52. 		else			/* else is closed */
  53. 		    idx = (ptr->horizontal) ? S_hcdoor : S_vcdoor;
  54. 	    } else
  55. 		idx = S_ndoor;
  56. 	    break;
  57. 	case IRONBARS:	idx = S_bars;     break;
  58. 	case TREE:		idx = S_tree;     break;
  59. 	case POOL:
  60. 	case MOAT:		idx = S_pool;	  break;
  61. 	case STAIRS:
  62. 	    idx = (ptr->ladder & LA_DOWN) ? S_dnstair : S_upstair;
  63. 	    break;
  64. 	case LADDER:
  65. 	    idx = (ptr->ladder & LA_DOWN) ? S_dnladder : S_upladder;
  66. 	    break;
  67. 	case FOUNTAIN:		idx = S_fountain; break;
  68. 	case SINK:		idx = S_sink;     break;
  69. 	case ALTAR:		idx = S_altar;    break;
  70. 	case GRAVE:		idx = S_grave;    break;
  71. 	case THRONE:		idx = S_throne;   break;
  72. 	case LAVAPOOL:		idx = S_lava;	  break;
  73. 	case ICE:		idx = S_ice;      break;
  74. 	case AIR:		idx = S_air;	  break;
  75. 	case CLOUD:		idx = S_cloud;	  break;
  76. 	case WATER:		idx = S_water;	  break;
  77. 	case DBWALL:
  78. 	    idx = (ptr->horizontal) ? S_hcdbridge : S_vcdbridge;
  79. 	    break;
  80. 	case DRAWBRIDGE_UP:
  81. 	    switch(ptr->drawbridgemask & DB_UNDER) {
  82. 	    case DB_MOAT:  idx = S_pool; break;
  83. 	    case DB_LAVA:  idx = S_lava; break;
  84. 	    case DB_ICE:   idx = S_ice;  break;
  85. 	    case DB_FLOOR: idx = S_room; break;
  86. 	    default:
  87. 		impossible("Strange db-under: %d",
  88. 			   ptr->drawbridgemask & DB_UNDER);
  89. 		idx = S_room; /* something is better than nothing */
  90. 		break;
  91. 	    }
  92. 	    break;
  93. 	case DRAWBRIDGE_DOWN:
  94. 	    idx = (ptr->horizontal) ? S_hodbridge : S_vodbridge;
  95. 	    break;
  96. 	default:
  97. 	    impossible("back_to_glyph:  unknown level type [ = %d ]",ptr->typ);
  98. 	    idx = S_room;
  99. 	    break;
  100. }
  101.  
  102. return cmap_to_glyph(idx);
  103. }

swallow_to_glyph[edit]

  1. /*
  2. * swallow_to_glyph()
  3. *
  4. * Convert a monster number and a swallow location into the correct glyph.
  5. * If you don't want a patchwork monster while hallucinating, decide on
  6. * a random monster in swallowed() and don't use what_mon() here.
  7. */
  8. STATIC_OVL int
  9. swallow_to_glyph(mnum, loc)
  10. int mnum;
  11. int loc;
  12. {
  13. if (loc < S_sw_tl || S_sw_br < loc) {
  14. 	impossible("swallow_to_glyph: bad swallow location");
  15. 	loc = S_sw_br;
  16. }
  17. return ((int) (what_mon(mnum)<<3) | (loc - S_sw_tl)) + GLYPH_SWALLOW_OFF;
  18. }

zapdir_to_glyph[edit]

  1. /*
  2. * zapdir_to_glyph()
  3. *
  4. * Change the given zap direction and beam type into a glyph.  Each beam
  5. * type has four glyphs, one for each of the symbols below.  The order of
  6. * the zap symbols [0-3] as defined in rm.h are:
  7. *
  8. *	|  S_vbeam	( 0, 1) or ( 0,-1)
  9. *	-  S_hbeam	( 1, 0) or (-1,	0)
  10. *	\  S_lslant	( 1, 1) or (-1,-1)
  11. *	/  S_rslant	(-1, 1) or ( 1,-1)
  12. */
  13. int
  14. zapdir_to_glyph(dx, dy, beam_type)
  15. register int dx, dy;
  16. int beam_type;
  17. {
  18. if (beam_type >= NUM_ZAP) {
  19. 	impossible("zapdir_to_glyph:  illegal beam type");
  20. 	beam_type = 0;
  21. }
  22. dx = (dx == dy) ? 2 : (dx && dy) ? 3 : dx ? 1 : 0;
  23.  
  24. return ((int) ((beam_type << 2) | dx)) + GLYPH_ZAP_OFF;
  25. }

glyph_at[edit]

  1. /*
  2. * Utility routine for dowhatis() used to find out the glyph displayed at
  3. * the location.  This isn't necessarily the same as the glyph in the levl
  4. * structure, so we must check the "third screen".
  5. */
  6. int
  7. glyph_at(x, y)
  8. xchar x,y;
  9. {
  10. if(x < 0 || y < 0 || x >= COLNO || y >= ROWNO)
  11. 	return cmap_to_glyph(S_room);			/* XXX */
  12. return gbuf[y][x].glyph;
  13. }
  14.  
  15.  
  16. /* ------------------------------------------------------------------------- */

type_to_name[edit]

  1. /* Wall Angle -------------------------------------------------------------- */
  2.  
  3. /*#define WA_VERBOSE*/	/* give (x,y) locations for all "bad" spots */
  4.  
  5. #ifdef WA_VERBOSE
  6.  
  7. static const char *FDECL(type_to_name, (int));
  8. static void FDECL(error4, (int,int,int,int,int,int));
  9.  
  10. static int bad_count[MAX_TYPE]; /* count of positions flagged as bad */
  11. static const char *type_names[MAX_TYPE] = {
  12. 	"STONE",	"VWALL",	"HWALL",	"TLCORNER",
  13. 	"TRCORNER",	"BLCORNER",	"BRCORNER",	"CROSSWALL",
  14. 	"TUWALL",	"TDWALL",	"TLWALL",	"TRWALL",
  15. 	"DBWALL",	"SDOOR",	"SCORR",	"POOL",
  16. 	"MOAT",		"WATER",	"DRAWBRIDGE_UP","LAVAPOOL",
  17. 	"DOOR",		"CORR",		"ROOM",		"STAIRS",
  18. 	"LADDER",	"FOUNTAIN",	"THRONE",	"SINK",
  19. 	"ALTAR",	"ICE",		"DRAWBRIDGE_DOWN","AIR",
  20. 	"CLOUD"
  21. };
  22.  
  23.  
  24. static const char *
  25. type_to_name(type)
  26. int type;
  27. {
  28. return (type < 0 || type > MAX_TYPE) ? "unknown" : type_names[type];
  29. }

error4[edit]

  1. static void
  2. error4(x, y, a, b, c, dd)
  3. int x, y, a, b, c, dd;
  4. {
  5. pline("set_wall_state: %s @ (%d,%d) %s%s%s%s",
  6. 	type_to_name(levl[x][y].typ), x, y,
  7. 	a ? "1":"", b ? "2":"", c ? "3":"", dd ? "4":"");
  8. bad_count[levl[x][y].typ]++;
  9. }
  10. #endif /* WA_VERBOSE */

check_pos[edit]

  1. /*
  2. * Return 'which' if position is implies an unfinshed exterior.  Return
  3. * zero otherwise.  Unfinished implies outer area is rock or a corridor.
  4. *
  5. * Things that are ambigious: lava
  6. */
  7. STATIC_OVL int
  8. check_pos(x, y, which)
  9. int x, y, which;
  10. {
  11. int type;
  12. if (!isok(x,y)) return which;
  13. type = levl[x][y].typ;
  14. if (IS_ROCK(type) || type == CORR || type == SCORR) return which;
  15. return 0;
  16. }

more_than_one[edit]

  1. /* Return TRUE if more than one is non-zero. */
  2. /*ARGSUSED*/
  3. #ifdef WA_VERBOSE
  4. STATIC_OVL boolean
  5. more_than_one(x, y, a, b, c)
  6. int x, y, a, b, c;
  7. {
  8. if ((a && (b|c)) || (b && (a|c)) || (c && (a|b))) {
  9. 	error4(x,y,a,b,c,0);
  10. 	return TRUE;
  11. }
  12. return FALSE;
  13. }
  14. #else
  15. #define more_than_one(x, y, a, b, c) (((a) && ((b)|(c))) || ((b) && ((a)|(c))) || ((c) && ((a)|(b))))
  16. #endif

set_twall[edit]

  1. /* Return the wall mode for a T wall. */
  2. STATIC_OVL int
  3. set_twall(x0,y0, x1,y1, x2,y2, x3,y3)
  4. int x0,y0, x1,y1, x2,y2, x3,y3;
  5. {
  6. int wmode, is_1, is_2, is_3;
  7.  
  8. is_1 = check_pos(x1, y1, WM_T_LONG);
  9. is_2 = check_pos(x2, y2, WM_T_BL);
  10. is_3 = check_pos(x3, y3, WM_T_BR);
  11. if (more_than_one(x0, y0, is_1, is_2, is_3)) {
  12. 	wmode = 0;
  13. } else {
  14. 	wmode = is_1 + is_2 + is_3;
  15. }
  16. return wmode;
  17. }

set_wall[edit]

  1. /* Return wall mode for a horizontal or vertical wall. */
  2. STATIC_OVL int
  3. set_wall(x, y, horiz)
  4. int x, y, horiz;
  5. {
  6. int wmode, is_1, is_2;
  7.  
  8. if (horiz) {
  9. 	is_1 = check_pos(x,y-1, WM_W_TOP);
  10. 	is_2 = check_pos(x,y+1, WM_W_BOTTOM);
  11. } else {
  12. 	is_1 = check_pos(x-1,y, WM_W_LEFT);
  13. 	is_2 = check_pos(x+1,y, WM_W_RIGHT);
  14. }
  15. if (more_than_one(x, y, is_1, is_2, 0)) {
  16. 	wmode = 0;
  17. } else {
  18. 	wmode = is_1 + is_2;
  19. }
  20. return wmode;
  21. }

set_corn[edit]

  1. /* Return a wall mode for a corner wall. (x4,y4) is the "inner" position. */
  2. STATIC_OVL int
  3. set_corn(x1,y1, x2,y2, x3,y3, x4,y4)
  4. 	int x1, y1, x2, y2, x3, y3, x4, y4;
  5. {
  6. int wmode, is_1, is_2, is_3, is_4;
  7.  
  8. is_1 = check_pos(x1, y1, 1);
  9. is_2 = check_pos(x2, y2, 1);
  10. is_3 = check_pos(x3, y3, 1);
  11. is_4 = check_pos(x4, y4, 1);	/* inner location */
  12.  
  13. /*
  14. * All 4 should not be true.  So if the inner location is rock,
  15. * use it.  If all of the outer 3 are true, use outer.  We currently
  16. * can't cover the case where only part of the outer is rock, so
  17. * we just say that all the walls are finished (if not overridden
  18. * by the inner section).
  19. */
  20. if (is_4) {
  21. 	wmode = WM_C_INNER;
  22. } else if (is_1 && is_2 && is_3)
  23. 	wmode = WM_C_OUTER;
  24. else
  25. 	wmode = 0;	/* finished walls on all sides */
  26.  
  27. return wmode;
  28. }

set_crosswall[edit]

  1. /* Return mode for a crosswall. */
  2. STATIC_OVL int
  3. set_crosswall(x, y)
  4. int x, y;
  5. {
  6. int wmode, is_1, is_2, is_3, is_4;
  7.  
  8. is_1 = check_pos(x-1, y-1, 1);
  9. is_2 = check_pos(x+1, y-1, 1);
  10. is_3 = check_pos(x+1, y+1, 1);
  11. is_4 = check_pos(x-1, y+1, 1);
  12.  
  13. wmode = is_1+is_2+is_3+is_4;
  14. if (wmode > 1) {
  15. 	if (is_1 && is_3 && (is_2+is_4 == 0)) {
  16. 	    wmode = WM_X_TLBR;
  17. 	} else if (is_2 && is_4 && (is_1+is_3 == 0)) {
  18. 	    wmode = WM_X_BLTR;
  19. 	} else {
  20. #ifdef WA_VERBOSE
  21. 	    error4(x,y,is_1,is_2,is_3,is_4);
  22. #endif
  23. 	    wmode = 0;
  24. 	}
  25. } else if (is_1)
  26. 	wmode = WM_X_TL;
  27. else if (is_2)
  28. 	wmode = WM_X_TR;
  29. else if (is_3)
  30. 	wmode = WM_X_BR;
  31. else if (is_4)
  32. 	wmode = WM_X_BL;
  33.  
  34. return wmode;
  35. }

set_wall_state[edit]

  1. /* Called from mklev.  Scan the level and set the wall modes. */
  2. void
  3. set_wall_state()
  4. {
  5. int x, y;
  6. int wmode;
  7. struct rm *lev;
  8.  
  9. #ifdef WA_VERBOSE
  10. for (x = 0; x < MAX_TYPE; x++) bad_count[x] = 0;
  11. #endif
  12.  
  13. for (x = 0; x < COLNO; x++)
  14. 	for (lev = &levl[x][0], y = 0; y < ROWNO; y++, lev++) {
  15. 	    switch (lev->typ) {
  16. 		case SDOOR:
  17. 		    wmode = set_wall(x, y, (int) lev->horizontal);
  18. 		    break;
  19. 		case VWALL:
  20. 		    wmode = set_wall(x, y, 0);
  21. 		    break;
  22. 		case HWALL:
  23. 		    wmode = set_wall(x, y, 1);
  24. 		    break;
  25. 		case TDWALL:
  26. 		    wmode = set_twall(x,y, x,y-1, x-1,y+1, x+1,y+1);
  27. 		    break;
  28. 		case TUWALL:
  29. 		    wmode = set_twall(x,y, x,y+1, x+1,y-1, x-1,y-1);
  30. 		    break;
  31. 		case TLWALL:
  32. 		    wmode = set_twall(x,y, x+1,y, x-1,y-1, x-1,y+1);
  33. 		    break;
  34. 		case TRWALL:
  35. 		    wmode = set_twall(x,y, x-1,y, x+1,y+1, x+1,y-1);
  36. 		    break;
  37. 		case TLCORNER:
  38. 		    wmode = set_corn(x-1,y-1, x,y-1, x-1,y, x+1,y+1);
  39. 		    break;
  40. 		case TRCORNER:
  41. 		    wmode = set_corn(x,y-1, x+1,y-1, x+1,y, x-1,y+1);
  42. 		    break;
  43. 		case BLCORNER:
  44. 		    wmode = set_corn(x,y+1, x-1,y+1, x-1,y, x+1,y-1);
  45. 		    break;
  46. 		case BRCORNER:
  47. 		    wmode = set_corn(x+1,y, x+1,y+1, x,y+1, x-1,y-1);
  48. 		    break;
  49. 		case CROSSWALL:
  50. 		    wmode = set_crosswall(x, y);
  51. 		    break;
  52.  
  53. 		default:
  54. 		    wmode = -1;	/* don't set wall info */
  55. 		    break;
  56. 	    }
  57.  
  58. 	if (wmode >= 0)
  59. 	    lev->wall_info = (lev->wall_info & ~WM_MASK) | wmode;
  60. 	}
  61.  
  62. #ifdef WA_VERBOSE
  63. /* check if any bad positions found */
  64. for (x = y = 0; x < MAX_TYPE; x++)
  65. 	if (bad_count[x]) {
  66. 	    if (y == 0) {
  67. 		y = 1;	/* only print once */
  68. 		pline("set_wall_type: wall mode problems with: ");
  69. 	    }
  70. 	    pline("%s %d;", type_names[x], bad_count[x]);
  71. 	}
  72. #endif /* WA_VERBOSE */
  73. }
  74.  
  75. /* ------------------------------------------------------------------------- */

set_seenv[edit]

  1. /* This matrix is used here and in vision.c. */
  2. unsigned char seenv_matrix[3][3] = { {SV2,   SV1, SV0},
  3. 				     {SV3, SVALL, SV7},
  4. 				     {SV4,   SV5, SV6} };
  5.  
  6. #define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0))
  7.  
  8. /* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */
  9. STATIC_OVL void
  10. set_seenv(lev, x0, y0, x, y)
  11. struct rm *lev;
  12. int x0, y0, x, y;	/* from, to */
  13. {
  14. int dx = x-x0, dy = y0-y;
  15. lev->seenv |= seenv_matrix[sign(dy)+1][sign(dx)+1];
  16. }
  17.  
  18. /* ------------------------------------------------------------------------- */

Wall types[edit]

  1. /* T wall types, one for each row in wall_matrix[][]. */
  2. #define T_d 0
  3. #define T_l 1
  4. #define T_u 2
  5. #define T_r 3
  6.  
  7. /*
  8. * These are the column names of wall_matrix[][].  They are the "results"
  9. * of a tdwall pattern match.  All T walls are rotated so they become
  10. * a tdwall.  Then we do a single pattern match, but return the
  11. * correct result for the original wall by using different rows for
  12. * each of the wall types.
  13. */
  14. #define T_stone  0
  15. #define T_tlcorn 1
  16. #define T_trcorn 2
  17. #define T_hwall  3
  18. #define T_tdwall 4
  19.  
  20. static const int wall_matrix[4][5] = {
  21. { S_stone, S_tlcorn, S_trcorn, S_hwall, S_tdwall },	/* tdwall */
  22. { S_stone, S_trcorn, S_brcorn, S_vwall, S_tlwall },	/* tlwall */
  23. { S_stone, S_brcorn, S_blcorn, S_hwall, S_tuwall },	/* tuwall */
  24. { S_stone, S_blcorn, S_tlcorn, S_vwall, S_trwall },	/* trwall */
  25. };
  26.  
  27.  
  28. /* Cross wall types, one for each "solid" quarter.  Rows of cross_matrix[][]. */
  29. #define C_bl 0
  30. #define C_tl 1
  31. #define C_tr 2
  32. #define C_br 3
  33.  
  34. /*
  35. * These are the column names for cross_matrix[][].  They express results
  36. * in C_br (bottom right) terms.  All crosswalls with a single solid
  37. * quarter are rotated so the solid section is at the bottom right.
  38. * We pattern match on that, but return the correct result depending
  39. * on which row we'ere looking at.
  40. */
  41. #define C_trcorn 0
  42. #define C_brcorn 1
  43. #define C_blcorn 2
  44. #define C_tlwall 3
  45. #define C_tuwall 4
  46. #define C_crwall 5
  47.  
  48. static const int cross_matrix[4][6] = {
  49. { S_brcorn, S_blcorn, S_tlcorn, S_tuwall, S_trwall, S_crwall },
  50. { S_blcorn, S_tlcorn, S_trcorn, S_trwall, S_tdwall, S_crwall },
  51. { S_tlcorn, S_trcorn, S_brcorn, S_tdwall, S_tlwall, S_crwall },
  52. { S_trcorn, S_brcorn, S_blcorn, S_tlwall, S_tuwall, S_crwall },
  53. };

t_warn[edit]

  1. /* Print out a T wall warning and all interesting info. */
  2. STATIC_OVL void
  3. t_warn(lev)
  4. struct rm *lev;
  5. {
  6. static const char warn_str[] = "wall_angle: %s: case %d: seenv = 0x%x";
  7. const char *wname;
  8.  
  9. if (lev->typ == TUWALL) wname = "tuwall";
  10. else if (lev->typ == TLWALL) wname = "tlwall";
  11. else if (lev->typ == TRWALL) wname = "trwall";
  12. else if (lev->typ == TDWALL) wname = "tdwall";
  13. else wname = "unknown";
  14. impossible(warn_str, wname, lev->wall_info & WM_MASK,
  15. 	(unsigned int) lev->seenv);
  16. }

wall_angle[edit]

  1. /*
  2. * Return the correct graphics character index using wall type, wall mode,
  3. * and the seen vector.  It is expected that seenv is non zero.
  4. *
  5. * All T-wall vectors are rotated to be TDWALL.  All single crosswall
  6. * blocks are rotated to bottom right.  All double crosswall are rotated
  7. * to W_X_BLTR.  All results are converted back.
  8. *
  9. * The only way to understand this is to take out pen and paper and
  10. * draw diagrams.  See rm.h for more details on the wall modes and
  11. * seen vector (SV).
  12. */
  13. STATIC_OVL int
  14. wall_angle(lev)
  15. struct rm *lev;
  16. {
  17. register unsigned int seenv = lev->seenv & 0xff;
  18. const int *row;
  19. int col, idx;
  20.  
  21. #define only(sv, bits)	(((sv) & (bits)) && ! ((sv) & ~(bits)))
  22. switch (lev->typ) {
  23. 	case TUWALL:
  24. 		row = wall_matrix[T_u];
  25. 		seenv = (seenv >> 4 | seenv << 4) & 0xff;/* rotate to tdwall */
  26. 		goto do_twall;
  27. 	case TLWALL:
  28. 		row = wall_matrix[T_l];
  29. 		seenv = (seenv >> 2 | seenv << 6) & 0xff;/* rotate to tdwall */
  30. 		goto do_twall;
  31. 	case TRWALL:
  32. 		row = wall_matrix[T_r];
  33. 		seenv = (seenv >> 6 | seenv << 2) & 0xff;/* rotate to tdwall */
  34. 		goto do_twall;
  35. 	case TDWALL:
  36. 		row = wall_matrix[T_d];
  37. do_twall:
  38. 		switch (lev->wall_info & WM_MASK) {
  39. 		    case 0:
  40. 			if (seenv == SV4) {
  41. 			    col = T_tlcorn;
  42. 			} else if (seenv == SV6) {
  43. 			    col = T_trcorn;
  44. 			} else if (seenv & (SV3|SV5|SV7) ||
  45. 					    ((seenv & SV4) && (seenv & SV6))) {
  46. 			    col = T_tdwall;
  47. 			} else if (seenv & (SV0|SV1|SV2)) {
  48. 			    col = (seenv & (SV4|SV6) ? T_tdwall : T_hwall);
  49. 			} else {
  50. 			    t_warn(lev);
  51. 			    col = T_stone;
  52. 			}
  53. 			break;
  54. 		    case WM_T_LONG:
  55. 			if (seenv & (SV3|SV4) && !(seenv & (SV5|SV6|SV7))) {
  56. 			    col = T_tlcorn;
  57. 			} else if (seenv&(SV6|SV7) && !(seenv&(SV3|SV4|SV5))) {
  58. 			    col = T_trcorn;
  59. 			} else if ((seenv & SV5) ||
  60. 				((seenv & (SV3|SV4)) && (seenv & (SV6|SV7)))) {
  61. 			    col = T_tdwall;
  62. 			} else {
  63. 			    /* only SV0|SV1|SV2 */
  64. 			    if (! only(seenv, SV0|SV1|SV2) )
  65. 				t_warn(lev);
  66. 			    col = T_stone;
  67. 			}
  68. 			break;
  69. 		    case WM_T_BL:
  70. #if 0	/* older method, fixed */
  71. 			if (only(seenv, SV4|SV5)) {
  72. 			    col = T_tlcorn;
  73. 			} else if ((seenv & (SV0|SV1|SV2)) &&
  74. 					only(seenv, SV0|SV1|SV2|SV6|SV7)) {
  75. 			    col = T_hwall;
  76. 			} else if (seenv & SV3 ||
  77. 			    ((seenv & (SV0|SV1|SV2)) && (seenv & (SV4|SV5)))) {
  78. 			    col = T_tdwall;
  79. 			} else {
  80. 			    if (seenv != SV6)
  81. 				t_warn(lev);
  82. 			    col = T_stone;
  83. 			}
  84. #endif	/* 0 */
  85. 			if (only(seenv, SV4|SV5))
  86. 			    col = T_tlcorn;
  87. 			else if ((seenv & (SV0|SV1|SV2|SV7)) &&
  88. 					!(seenv & (SV3|SV4|SV5)))
  89. 			    col = T_hwall;
  90. 			else if (only(seenv, SV6))
  91. 			    col = T_stone;
  92. 			else
  93. 			    col = T_tdwall;
  94. 			break;
  95. 		    case WM_T_BR:
  96. #if 0	/* older method, fixed */
  97. 			if (only(seenv, SV5|SV6)) {
  98. 			    col = T_trcorn;
  99. 			} else if ((seenv & (SV0|SV1|SV2)) &&
  100. 					    only(seenv, SV0|SV1|SV2|SV3|SV4)) {
  101. 			    col = T_hwall;
  102. 			} else if (seenv & SV7 ||
  103. 			    ((seenv & (SV0|SV1|SV2)) && (seenv & (SV5|SV6)))) {
  104. 			    col = T_tdwall;
  105. 			} else {
  106. 			    if (seenv != SV4)
  107. 				t_warn(lev);
  108. 			    col = T_stone;
  109. 			}
  110. #endif	/* 0 */
  111. 			if (only(seenv, SV5|SV6))
  112. 			    col = T_trcorn;
  113. 			else if ((seenv & (SV0|SV1|SV2|SV3)) &&
  114. 					!(seenv & (SV5|SV6|SV7)))
  115. 			    col = T_hwall;
  116. 			else if (only(seenv, SV4))
  117. 			    col = T_stone;
  118. 			else
  119. 			    col = T_tdwall;
  120.  
  121. 			break;
  122. 		    default:
  123. 			impossible("wall_angle: unknown T wall mode %d",
  124. 				lev->wall_info & WM_MASK);
  125. 			col = T_stone;
  126. 			break;
  127. 		}
  128. 		idx = row[col];
  129. 		break;
  130.  
  131. 	case SDOOR:
  132. 		if (lev->horizontal) goto horiz;
  133. 		/* fall through */
  134. 	case VWALL:
  135. 		switch (lev->wall_info & WM_MASK) {
  136. 		    case 0: idx = seenv ? S_vwall : S_stone; break;
  137. 		    case 1: idx = seenv & (SV1|SV2|SV3|SV4|SV5) ? S_vwall :
  138. 								  S_stone;
  139. 			    break;
  140. 		    case 2: idx = seenv & (SV0|SV1|SV5|SV6|SV7) ? S_vwall :
  141. 								  S_stone;
  142. 			    break;
  143. 		    default:
  144. 			impossible("wall_angle: unknown vwall mode %d",
  145. 				lev->wall_info & WM_MASK);
  146. 			idx = S_stone;
  147. 			break;
  148. 		}
  149. 		break;
  150.  
  151. 	case HWALL:
  152. horiz:
  153. 		switch (lev->wall_info & WM_MASK) {
  154. 		    case 0: idx = seenv ? S_hwall : S_stone; break;
  155. 		    case 1: idx = seenv & (SV3|SV4|SV5|SV6|SV7) ? S_hwall :
  156. 								  S_stone;
  157. 			    break;
  158. 		    case 2: idx = seenv & (SV0|SV1|SV2|SV3|SV7) ? S_hwall :
  159. 								  S_stone;
  160. 			    break;
  161. 		    default:
  162. 			impossible("wall_angle: unknown hwall mode %d",
  163. 				lev->wall_info & WM_MASK);
  164. 			idx = S_stone;
  165. 			break;
  166. 		}
  167. 		break;
  168.  
  169. #define set_corner(idx, lev, which, outer, inner, name)	\
  170. switch ((lev)->wall_info & WM_MASK) {				    \
  171. 	case 0:		 idx = which; break;				    \
  172. 	case WM_C_OUTER: idx = seenv &  (outer) ? which : S_stone; break;   \
  173. 	case WM_C_INNER: idx = seenv & ~(inner) ? which : S_stone; break;   \
  174. 	default:							    \
  175. 	    impossible("wall_angle: unknown %s mode %d", name,		    \
  176. 		(lev)->wall_info & WM_MASK);				    \
  177. 	    idx = S_stone;						    \
  178. 	    break;							    \
  179. }
  180.  
  181. 	case TLCORNER:
  182. 	    set_corner(idx, lev, S_tlcorn, (SV3|SV4|SV5), SV4, "tlcorn");
  183. 	    break;
  184. 	case TRCORNER:
  185. 	    set_corner(idx, lev, S_trcorn, (SV5|SV6|SV7), SV6, "trcorn");
  186. 	    break;
  187. 	case BLCORNER:
  188. 	    set_corner(idx, lev, S_blcorn, (SV1|SV2|SV3), SV2, "blcorn");
  189. 	    break;
  190. 	case BRCORNER:
  191. 	    set_corner(idx, lev, S_brcorn, (SV7|SV0|SV1), SV0, "brcorn");
  192. 	    break;
  193.  
  194.  
  195. 	case CROSSWALL:
  196. 		switch (lev->wall_info & WM_MASK) {
  197. 		    case 0:
  198. 			if (seenv == SV0)
  199. 			    idx = S_brcorn;
  200. 			else if (seenv == SV2)
  201. 			    idx = S_blcorn;
  202. 			else if (seenv == SV4)
  203. 			    idx = S_tlcorn;
  204. 			else if (seenv == SV6)
  205. 			    idx = S_trcorn;
  206. 			else if (!(seenv & ~(SV0|SV1|SV2)) &&
  207. 					(seenv & SV1 || seenv == (SV0|SV2)))
  208. 			    idx = S_tuwall;
  209. 			else if (!(seenv & ~(SV2|SV3|SV4)) &&
  210. 					(seenv & SV3 || seenv == (SV2|SV4)))
  211. 			    idx = S_trwall;
  212. 			else if (!(seenv & ~(SV4|SV5|SV6)) &&
  213. 					(seenv & SV5 || seenv == (SV4|SV6)))
  214. 			    idx = S_tdwall;
  215. 			else if (!(seenv & ~(SV0|SV6|SV7)) &&
  216. 					(seenv & SV7 || seenv == (SV0|SV6)))
  217. 			    idx = S_tlwall;
  218. 			else
  219. 			    idx = S_crwall;
  220. 			break;
  221.  
  222. 		    case WM_X_TL:
  223. 			row = cross_matrix[C_tl];
  224. 			seenv = (seenv >> 4 | seenv << 4) & 0xff;
  225. 			goto do_crwall;
  226. 		    case WM_X_TR:
  227. 			row = cross_matrix[C_tr];
  228. 			seenv = (seenv >> 6 | seenv << 2) & 0xff;
  229. 			goto do_crwall;
  230. 		    case WM_X_BL:
  231. 			row = cross_matrix[C_bl];
  232. 			seenv = (seenv >> 2 | seenv << 6) & 0xff;
  233. 			goto do_crwall;
  234. 		    case WM_X_BR:
  235. 			row = cross_matrix[C_br];
  236. do_crwall:
  237. 			if (seenv == SV4)
  238. 			    idx = S_stone;
  239. 			else {
  240. 			    seenv = seenv & ~SV4;	/* strip SV4 */
  241. 			    if (seenv == SV0) {
  242. 				col = C_brcorn;
  243. 			    } else if (seenv & (SV2|SV3)) {
  244. 				if (seenv & (SV5|SV6|SV7))
  245. 				    col = C_crwall;
  246. 				else if (seenv & (SV0|SV1))
  247. 				    col = C_tuwall;
  248. 				else
  249. 				    col = C_blcorn;
  250. 			    } else if (seenv & (SV5|SV6)) {
  251. 				if (seenv & (SV1|SV2|SV3))
  252. 				    col = C_crwall;
  253. 				else if (seenv & (SV0|SV7))
  254. 				    col = C_tlwall;
  255. 				else
  256. 				    col = C_trcorn;
  257. 			    } else if (seenv & SV1) {
  258. 				col = seenv & SV7 ? C_crwall : C_tuwall;
  259. 			    } else if (seenv & SV7) {
  260. 				col = seenv & SV1 ? C_crwall : C_tlwall;
  261. 			    } else {
  262. 				impossible(
  263. 				    "wall_angle: bottom of crwall check");
  264. 				col = C_crwall;
  265. 			    }
  266.  
  267. 			    idx = row[col];
  268. 			}
  269. 			break;
  270.  
  271. 		    case WM_X_TLBR:
  272. 			if ( only(seenv, SV1|SV2|SV3) )
  273. 			    idx = S_blcorn;
  274. 			else if ( only(seenv, SV5|SV6|SV7) )
  275. 			    idx = S_trcorn;
  276. 			else if ( only(seenv, SV0|SV4) )
  277. 			    idx = S_stone;
  278. 			else
  279. 			    idx = S_crwall;
  280. 			break;
  281.  
  282. 		    case WM_X_BLTR:
  283. 			if ( only(seenv, SV0|SV1|SV7) )
  284. 			    idx = S_brcorn;
  285. 			else if ( only(seenv, SV3|SV4|SV5) )
  286. 			    idx = S_tlcorn;
  287. 			else if ( only(seenv, SV2|SV6) )
  288. 			    idx = S_stone;
  289. 			else
  290. 			    idx = S_crwall;
  291. 			break;
  292.  
  293. 		    default:
  294. 			impossible("wall_angle: unknown crosswall mode");
  295. 			idx = S_stone;
  296. 			break;
  297. 		}
  298. 		break;
  299.  
  300. 	default:
  301. 	    impossible("wall_angle: unexpected wall type %d", lev->typ);
  302. 	    idx = S_stone;
  303. }
  304. return idx;
  305. }
  306.  
  307. /*display.c*/