Source:NetHack 3.4.3/src/dbridge.c

From NetHackWiki
(Redirected from Source:Ref/set entity)
Jump to: navigation, search

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

Top of file

  1. /*	SCCS Id: @(#)dbridge.c	3.4	2003/02/08	*/
  2. /*	Copyright (c) 1989 by Jean-Christophe Collet		  */
  3. /* 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.

  1. /*
  2. * This file contains the drawbridge manipulation (create, open, close,
  3. * destroy).
  4. *
  5. * Added comprehensive monster-handling, and the "entity" structure to
  6. * deal with players as well. - 11/89
  7. */
  8.  
  9. #include "hack.h"
  10.  
  11. #ifdef OVLB
  12. STATIC_DCL void FDECL(get_wall_for_db, (int *, int *));
  13. STATIC_DCL struct entity *FDECL(e_at, (int, int));
  14. STATIC_DCL void FDECL(m_to_e, (struct monst *, int, int, struct entity *));
  15. STATIC_DCL void FDECL(u_to_e, (struct entity *));
  16. STATIC_DCL void FDECL(set_entity, (int, int, struct entity *));
  17. STATIC_DCL const char *FDECL(e_nam, (struct entity *));
  18. #ifdef D_DEBUG
  19. static const char *FDECL(Enam, (struct entity *)); /* unused */
  20. #endif
  21. STATIC_DCL const char *FDECL(E_phrase, (struct entity *, const char *));
  22. STATIC_DCL boolean FDECL(e_survives_at, (struct entity *, int, int));
  23. STATIC_DCL void FDECL(e_died, (struct entity *, int, int));
  24. STATIC_DCL boolean FDECL(automiss, (struct entity *));
  25. STATIC_DCL boolean FDECL(e_missed, (struct entity *, BOOLEAN_P));
  26. STATIC_DCL boolean FDECL(e_jumps, (struct entity *));
  27. STATIC_DCL void FDECL(do_entity, (struct entity *));
  28. #endif /* OVLB */

is_pool

is_pool() takes two numbers, an x,y coordinate, and returns TRUE if the terrain at that coordinate is pool of water (even if it is under a drawbridge), FALSE otherwise.

  1. #ifdef OVL0
  2.  
  3. boolean
  4. is_pool(x,y)
  5. int x,y;
  6. {
  7. schar ltyp;
  8.  
  9. if (!isok(x,y)) return FALSE;
  10. ltyp = levl[x][y].typ;
  11. if (ltyp == POOL || ltyp == MOAT || ltyp == WATER) return TRUE;
  12. if (ltyp == DRAWBRIDGE_UP &&
  13. 	(levl[x][y].drawbridgemask & DB_UNDER) == DB_MOAT) return TRUE;
  14. return FALSE;
  15. }

is_lava

  1. boolean
  2. is_lava(x,y)
  3. int x,y;
  4. {
  5. schar ltyp;
  6.  
  7. if (!isok(x,y)) return FALSE;
  8. ltyp = levl[x][y].typ;
  9. if (ltyp == LAVAPOOL
  10. 	|| (ltyp == DRAWBRIDGE_UP
  11. 	    && (levl[x][y].drawbridgemask & DB_UNDER) == DB_LAVA)) return TRUE;
  12. return FALSE;
  13. }

is_ice

  1. boolean
  2. is_ice(x,y)
  3. int x,y;
  4. {
  5. schar ltyp;
  6.  
  7. if (!isok(x,y)) return FALSE;
  8. ltyp = levl[x][y].typ;
  9. if (ltyp == ICE
  10. 	|| (ltyp == DRAWBRIDGE_UP
  11. 	    && (levl[x][y].drawbridgemask & DB_UNDER) == DB_ICE)) return TRUE;
  12. return FALSE;
  13. }
  14.  
  15. #endif /* OVL0 */

is_drawbridge_wall

  1. #ifdef OVL1
  2.  
  3. /*
  4. * We want to know whether a wall (or a door) is the portcullis (passageway)
  5. * of an eventual drawbridge.
  6. *
  7. * Return value:  the direction of the drawbridge.
  8. */
  9.  
  10. int
  11. is_drawbridge_wall(x,y)
  12. int x,y;
  13. {
  14. 	struct rm *lev;
  15.  
  16. 	lev = &levl[x][y];
  17. 	if (lev->typ != DOOR && lev->typ != DBWALL)
  18. 		return (-1);
  19.  
  20. 	if (IS_DRAWBRIDGE(levl[x+1][y].typ) &&
  21. 	    (levl[x+1][y].drawbridgemask & DB_DIR) == DB_WEST)
  22. 		return (DB_WEST);
  23. 	if (IS_DRAWBRIDGE(levl[x-1][y].typ) &&
  24. 	    (levl[x-1][y].drawbridgemask & DB_DIR) == DB_EAST)
  25. 		return (DB_EAST);
  26. 	if (IS_DRAWBRIDGE(levl[x][y-1].typ) &&
  27. 	    (levl[x][y-1].drawbridgemask & DB_DIR) == DB_SOUTH)
  28. 		return (DB_SOUTH);
  29. 	if (IS_DRAWBRIDGE(levl[x][y+1].typ) &&
  30. 	    (levl[x][y+1].drawbridgemask & DB_DIR) == DB_NORTH)
  31. 		return (DB_NORTH);
  32.  
  33. 	return (-1);
  34. }

is_db_wall

  1. /*
  2. * Use is_db_wall where you want to verify that a
  3. * drawbridge "wall" is UP in the location x, y
  4. * (instead of UP or DOWN, as with is_drawbridge_wall).
  5. */
  6. boolean
  7. is_db_wall(x,y)
  8. int x,y;
  9. {
  10. 	return((boolean)( levl[x][y].typ == DBWALL ));
  11. }

find_drawbridge

  1. /*
  2. * Return true with x,y pointing to the drawbridge if x,y initially indicate
  3. * a drawbridge or drawbridge wall.
  4. */
  5. boolean
  6. find_drawbridge(x,y)
  7. int *x,*y;
  8. {
  9. 	int dir;
  10.  
  11. 	if (IS_DRAWBRIDGE(levl[*x][*y].typ))
  12. 		return TRUE;
  13. 	dir = is_drawbridge_wall(*x,*y);
  14. 	if (dir >= 0) {
  15. 		switch(dir) {
  16. 			case DB_NORTH: (*y)++; break;
  17. 			case DB_SOUTH: (*y)--; break;
  18. 			case DB_EAST:  (*x)--; break;
  19. 			case DB_WEST:  (*x)++; break;
  20. 		}
  21. 		return TRUE;
  22. 	}
  23. 	return FALSE;
  24. }
  25.  
  26. #endif /* OVL1 */

get_wall_for_db

  1. #ifdef OVLB
  2.  
  3. /*
  4. * Find the drawbridge wall associated with a drawbridge.
  5. */
  6. STATIC_OVL void
  7. get_wall_for_db(x,y)
  8. int *x,*y;
  9. {
  10. 	switch (levl[*x][*y].drawbridgemask & DB_DIR) {
  11. 		case DB_NORTH: (*y)--; break;
  12. 		case DB_SOUTH: (*y)++; break;
  13. 		case DB_EAST:  (*x)++; break;
  14. 		case DB_WEST:  (*x)--; break;
  15. 	}
  16. }

create_drawbridge

  1. /*
  2. * Creation of a drawbridge at pos x,y.
  3. *     dir is the direction.
  4. *     flag must be put to TRUE if we want the drawbridge to be opened.
  5. */
  6.  
  7. boolean
  8. create_drawbridge(x,y,dir,flag)
  9. int x,y,dir;
  10. boolean flag;
  11. {
  12. 	int x2,y2;
  13. 	boolean horiz;
  14. 	boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */
  15.  
  16. 	x2 = x; y2 = y;
  17. 	switch(dir) {
  18. 		case DB_NORTH:
  19. 			horiz = TRUE;
  20. 			y2--;
  21. 			break;
  22. 		case DB_SOUTH:
  23. 			horiz = TRUE;
  24. 			y2++;
  25. 			break;
  26. 		case DB_EAST:
  27. 			horiz = FALSE;
  28. 			x2++;
  29. 			break;
  30. 		default:
  31. 			impossible("bad direction in create_drawbridge");
  32. 			/* fall through */
  33. 		case DB_WEST:
  34. 			horiz = FALSE;
  35. 			x2--;
  36. 			break;
  37. 	}
  38. 	if (!IS_WALL(levl[x2][y2].typ))
  39. 		return(FALSE);
  40. 	if (flag) {             /* We want the bridge open */
  41. 		levl[x][y].typ = DRAWBRIDGE_DOWN;
  42. 		levl[x2][y2].typ = DOOR;
  43. 		levl[x2][y2].doormask = D_NODOOR;
  44. 	} else {
  45. 		levl[x][y].typ = DRAWBRIDGE_UP;
  46. 		levl[x2][y2].typ = DBWALL;
  47. 		/* Drawbridges are non-diggable. */
  48. 		levl[x2][y2].wall_info = W_NONDIGGABLE;
  49. 	}
  50. 	levl[x][y].horizontal = !horiz;
  51. 	levl[x2][y2].horizontal = horiz;
  52. 	levl[x][y].drawbridgemask = dir;
  53. 	if(lava) levl[x][y].drawbridgemask |= DB_LAVA;
  54. 	return(TRUE);
  55. }

e_at

  1. struct entity {
  2. 	struct monst *emon;	  /* youmonst for the player */
  3. 	struct permonst *edata;   /* must be non-zero for record to be valid */
  4. 	int ex, ey;
  5. };
  6.  
  7. #define ENTITIES 2
  8.  
  9. static NEARDATA struct entity occupants[ENTITIES];
  10.  
  11. STATIC_OVL
  12. struct entity *
  13. e_at(x, y)
  14. int x, y;
  15. {
  16. 	int entitycnt;
  17.  
  18. 	for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++)
  19. 		if ((occupants[entitycnt].edata) &&
  20. 		    (occupants[entitycnt].ex == x) &&
  21. 		    (occupants[entitycnt].ey == y))
  22. 			break;
  23. #ifdef D_DEBUG
  24. 	pline("entitycnt = %d", entitycnt);
  25. 	wait_synch();
  26. #endif
  27. 	return((entitycnt == ENTITIES)?
  28. 	       (struct entity *)0 : &(occupants[entitycnt]));
  29. }

m_to_e

  1. STATIC_OVL void
  2. m_to_e(mtmp, x, y, etmp)
  3. struct monst *mtmp;
  4. int x, y;
  5. struct entity *etmp;
  6. {
  7. 	etmp->emon = mtmp;
  8. 	if (mtmp) {
  9. 		etmp->ex = x;
  10. 		etmp->ey = y;
  11. 		if (mtmp->wormno && (x != mtmp->mx || y != mtmp->my))
  12. 			etmp->edata = &mons[PM_LONG_WORM_TAIL];
  13. 		else
  14. 			etmp->edata = mtmp->data;
  15. 	} else
  16. 		etmp->edata = (struct permonst *)0;
  17. }

u_to_e

  1. STATIC_OVL void
  2. u_to_e(etmp)
  3. struct entity *etmp;
  4. {
  5. 	etmp->emon = &youmonst;
  6. 	etmp->ex = u.ux;
  7. 	etmp->ey = u.uy;
  8. 	etmp->edata = youmonst.data;
  9. }

set_entity

  1. STATIC_OVL void
  2. set_entity(x, y, etmp)
  3. int x, y;
  4. struct entity *etmp;
  5. {
  6. 	if ((x == u.ux) && (y == u.uy))
  7. 		u_to_e(etmp);
  8. 	else if (MON_AT(x, y))
  9. 		m_to_e(m_at(x, y), x, y, etmp);
  10. 	else
  11. 		etmp->edata = (struct permonst *)0;
  12. }

e_nam

  1. #define is_u(etmp) (etmp->emon == &youmonst)
  2. #define e_canseemon(etmp) (is_u(etmp) ? (boolean)TRUE : canseemon(etmp->emon))
  3.  
  4. /*
  5. * e_strg is a utility routine which is not actually in use anywhere, since
  6. * the specialized routines below suffice for all current purposes.
  7. */
  8.  
  9. /* #define e_strg(etmp, func) (is_u(etmp)? (char *)0 : func(etmp->emon)) */
  10.  
  11. STATIC_OVL const char *
  12. e_nam(etmp)
  13. struct entity *etmp;
  14. {
  15. 	return(is_u(etmp)? "you" : mon_nam(etmp->emon));
  16. }

Enam

  1. #ifdef D_DEBUG
  2. /*
  3. * Enam is another unused utility routine:  E_phrase is preferable.
  4. */
  5.  
  6. static const char *
  7. Enam(etmp)
  8. struct entity *etmp;
  9. {
  10. 	return(is_u(etmp)? "You" : Monnam(etmp->emon));
  11. }
  12. #endif /* D_DEBUG */

E_phrase

  1. /*
  2. * Generates capitalized entity name, makes 2nd -> 3rd person conversion on
  3. * verb, where necessary.
  4. */
  5.  
  6. STATIC_OVL const char *
  7. E_phrase(etmp, verb)
  8. struct entity *etmp;
  9. const char *verb;
  10. {
  11. 	static char wholebuf[80];
  12.  
  13. 	Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon));
  14. 	if (!*verb) return(wholebuf);
  15. 	Strcat(wholebuf, " ");
  16. 	if (is_u(etmp))
  17. 	    Strcat(wholebuf, verb);
  18. 	else
  19. 	    Strcat(wholebuf, vtense((char *)0, verb));
  20. 	return(wholebuf);
  21. }

e_survives_at

  1. /*
  2. * Simple-minded "can it be here?" routine
  3. */
  4.  
  5. STATIC_OVL boolean
  6. e_survives_at(etmp, x, y)
  7. struct entity *etmp;
  8. int x, y;
  9. {
  10. 	if (noncorporeal(etmp->edata))
  11. 		return(TRUE);
  12. 	if (is_pool(x, y))
  13. 		return (boolean)((is_u(etmp) &&
  14. 				(Wwalking || Amphibious || Swimming ||
  15. 				Flying || Levitation)) ||
  16. 			is_swimmer(etmp->edata) || is_flyer(etmp->edata) ||
  17. 			is_floater(etmp->edata));
  18. 	/* must force call to lava_effects in e_died if is_u */
  19. 	if (is_lava(x, y))
  20. 		return (boolean)((is_u(etmp) && (Levitation || Flying)) ||
  21. 			    likes_lava(etmp->edata) || is_flyer(etmp->edata));
  22. 	if (is_db_wall(x, y))
  23. 		return((boolean)(is_u(etmp) ? Passes_walls :
  24. 			passes_walls(etmp->edata)));
  25. 	return(TRUE);
  26. }

e_died

  1. STATIC_OVL void
  2. e_died(etmp, dest, how)
  3. struct entity *etmp;
  4. int dest, how;
  5. {
  6. 	if (is_u(etmp)) {
  7. 		if (how == DROWNING) {
  8. 			killer = 0;	/* drown() sets its own killer */
  9. 			(void) drown();
  10. 		} else if (how == BURNING) {
  11. 			killer = 0;	/* lava_effects() sets its own killer */
  12. 			(void) lava_effects();
  13. 		} else {
  14. 			coord xy;
  15.  
  16. 			/* use more specific killer if specified */
  17. 			if (!killer) {
  18. 			    killer_format = KILLED_BY_AN;
  19. 			    killer = "falling drawbridge";
  20. 			}
  21. 			done(how);
  22. 			/* So, you didn't die */
  23. 			if (!e_survives_at(etmp, etmp->ex, etmp->ey)) {
  24. 			    if (enexto(&xy, etmp->ex, etmp->ey, etmp->edata)) {
  25. 				pline("A %s force teleports you away...",
  26. 				      Hallucination ? "normal" : "strange");
  27. 				teleds(xy.x, xy.y, FALSE);
  28. 			    }
  29. 			    /* otherwise on top of the drawbridge is the
  30. 			     * only viable spot in the dungeon, so stay there
  31. 			     */
  32. 			}
  33. 		}
  34. 		/* we might have crawled out of the moat to survive */
  35. 		etmp->ex = u.ux,  etmp->ey = u.uy;
  36. 	} else {
  37. 		int entitycnt;
  38.  
  39. 		killer = 0;
  40. 		/* fake "digested to death" damage-type suppresses corpse */
  41. #define mk_message(dest) ((dest & 1) ? "" : (char *)0)
  42. #define mk_corpse(dest)  ((dest & 2) ? AD_DGST : AD_PHYS)
  43. 		/* if monsters are moving, one of them caused the destruction */
  44. 		if (flags.mon_moving)
  45. 		    monkilled(etmp->emon, mk_message(dest), mk_corpse(dest));
  46. 		else		/* you caused it */
  47. 		    xkilled(etmp->emon, dest);
  48. 		etmp->edata = (struct permonst *)0;
  49.  
  50. 		/* dead long worm handling */
  51. 		for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) {
  52. 		    if (etmp != &(occupants[entitycnt]) &&
  53. 			etmp->emon == occupants[entitycnt].emon)
  54. 			occupants[entitycnt].edata = (struct permonst *)0;
  55. 		}
  56. #undef mk_message
  57. #undef mk_corpse
  58. 	}
  59. }

automiss

  1. /*
  2. * These are never directly affected by a bridge or portcullis.
  3. */
  4.  
  5. STATIC_OVL boolean
  6. automiss(etmp)
  7. struct entity *etmp;
  8. {
  9. 	return (boolean)((is_u(etmp) ? Passes_walls :
  10. 			passes_walls(etmp->edata)) || noncorporeal(etmp->edata));
  11. }

e_missed

  1. /*
  2. * Does falling drawbridge or portcullis miss etmp?
  3. */
  4.  
  5. STATIC_OVL boolean
  6. e_missed(etmp, chunks)
  7. struct entity *etmp;
  8. boolean chunks;
  9. {
  10. 	int misses;
  11.  
  12. #ifdef D_DEBUG
  13. 	if (chunks)
  14. 		pline("Do chunks miss?");
  15. #endif
  16. 	if (automiss(etmp))
  17. 		return(TRUE);
  18.  
  19. 	if (is_flyer(etmp->edata) &&
  20. 	    (is_u(etmp)? !Sleeping :
  21. 	     (etmp->emon->mcanmove && !etmp->emon->msleeping)))
  22. 						 /* flying requires mobility */
  23. 		misses = 5;	/* out of 8 */
  24. 	else if (is_floater(etmp->edata) ||
  25. 		    (is_u(etmp) && Levitation))	 /* doesn't require mobility */
  26. 		misses = 3;
  27. 	else if (chunks && is_pool(etmp->ex, etmp->ey))
  28. 		misses = 2;				    /* sitting ducks */
  29. 	else
  30. 		misses = 0;
  31.  
  32. 	if (is_db_wall(etmp->ex, etmp->ey))
  33. 		misses -= 3;				    /* less airspace */
  34.  
  35. #ifdef D_DEBUG
  36. 	pline("Miss chance = %d (out of 8)", misses);
  37. #endif
  38.  
  39. 	return((boolean)((misses >= rnd(8))? TRUE : FALSE));
  40. }

e_jumps

  1. /*
  2. * Can etmp jump from death?
  3. */
  4.  
  5. STATIC_OVL boolean
  6. e_jumps(etmp)
  7. struct entity *etmp;
  8. {
  9. 	int tmp = 4;		/* out of 10 */
  10.  
  11. 	if (is_u(etmp)? (Sleeping || Fumbling) :
  12. 		        (!etmp->emon->mcanmove || etmp->emon->msleeping ||
  13. 			 !etmp->edata->mmove   || etmp->emon->wormno))
  14. 		return(FALSE);
  15.  
  16. 	if (is_u(etmp)? Confusion : etmp->emon->mconf)
  17. 		tmp -= 2;
  18.  
  19. 	if (is_u(etmp)? Stunned : etmp->emon->mstun)
  20. 		tmp -= 3;
  21.  
  22. 	if (is_db_wall(etmp->ex, etmp->ey))
  23. 		tmp -= 2;			    /* less room to maneuver */
  24.  
  25. #ifdef D_DEBUG
  26. 	pline("%s to jump (%d chances in 10)", E_phrase(etmp, "try"), tmp);
  27. #endif
  28. 	return((boolean)((tmp >= rnd(10))? TRUE : FALSE));
  29. }

do_entity

  1. STATIC_OVL void
  2. do_entity(etmp)
  3. struct entity *etmp;
  4. {
  5. 	int newx, newy, at_portcullis, oldx, oldy;
  6. 	boolean must_jump = FALSE, relocates = FALSE, e_inview;
  7. 	struct rm *crm;
  8.  
  9. 	if (!etmp->edata)
  10. 		return;
  11.  
  12. 	e_inview = e_canseemon(etmp);
  13. 	oldx = etmp->ex;
  14. 	oldy = etmp->ey;
  15. 	at_portcullis = is_db_wall(oldx, oldy);
  16. 	crm = &levl[oldx][oldy];
  17.  
  18. 	if (automiss(etmp) && e_survives_at(etmp, oldx, oldy)) {
  19. 		if (e_inview && (at_portcullis || IS_DRAWBRIDGE(crm->typ)))
  20. 			pline_The("%s passes through %s!",
  21. 			      at_portcullis ? "portcullis" : "drawbridge",
  22. 			      e_nam(etmp));
  23. 		if (is_u(etmp)) spoteffects(FALSE);
  24. 		return;
  25. 	}
  26. 	if (e_missed(etmp, FALSE)) {
  27. 		if (at_portcullis)
  28. 			pline_The("portcullis misses %s!",
  29. 			      e_nam(etmp));
  30. #ifdef D_DEBUG
  31. 		else
  32. 			pline_The("drawbridge misses %s!",
  33. 			      e_nam(etmp));
  34. #endif
  35. 		if (e_survives_at(etmp, oldx, oldy))
  36. 			return;
  37. 		else {
  38. #ifdef D_DEBUG
  39. 			pline("Mon can't survive here");
  40. #endif
  41. 			if (at_portcullis)
  42. 				must_jump = TRUE;
  43. 			else
  44. 				relocates = TRUE; /* just ride drawbridge in */
  45. 		}
  46. 	} else {
  47. 		if (crm->typ == DRAWBRIDGE_DOWN) {
  48. 			pline("%s crushed underneath the drawbridge.",
  49. 			      E_phrase(etmp, "are"));		  /* no jump */
  50. 			e_died(etmp, e_inview? 3 : 2, CRUSHING);/* no corpse */
  51. 			return;   /* Note: Beyond this point, we know we're  */
  52. 		}		  /* not at an opened drawbridge, since all  */
  53. 		must_jump = TRUE; /* *missable* creatures survive on the     */
  54. 	}			  /* square, and all the unmissed ones die.  */
  55. 	if (must_jump) {
  56. 	    if (at_portcullis) {
  57. 		if (e_jumps(etmp)) {
  58. 		    relocates = TRUE;
  59. #ifdef D_DEBUG
  60. 		    pline("Jump succeeds!");
  61. #endif
  62. 		} else {
  63. 		    if (e_inview)
  64. 			pline("%s crushed by the falling portcullis!",
  65. 			      E_phrase(etmp, "are"));
  66. 		    else if (flags.soundok)
  67. 			You_hear("a crushing sound.");
  68. 		    e_died(etmp, e_inview? 3 : 2, CRUSHING);
  69. 		    /* no corpse */
  70. 		    return;
  71. 		}
  72. 	    } else { /* tries to jump off bridge to original square */
  73. 		relocates = !e_jumps(etmp);
  74. #ifdef D_DEBUG
  75. 		pline("Jump %s!", (relocates)? "fails" : "succeeds");
  76. #endif
  77. 	    }
  78. 	}
  79.  
  80. /*
  81. * Here's where we try to do relocation.  Assumes that etmp is not arriving
  82. * at the portcullis square while the drawbridge is falling, since this square
  83. * would be inaccessible (i.e. etmp started on drawbridge square) or
  84. * unnecessary (i.e. etmp started here) in such a situation.
  85. */
  86. #ifdef D_DEBUG
  87. 	pline("Doing relocation.");
  88. #endif
  89. 	newx = oldx;
  90. 	newy = oldy;
  91. 	(void)find_drawbridge(&newx, &newy);
  92. 	if ((newx == oldx) && (newy == oldy))
  93. 		get_wall_for_db(&newx, &newy);
  94. #ifdef D_DEBUG
  95. 	pline("Checking new square for occupancy.");
  96. #endif
  97. 	if (relocates && (e_at(newx, newy))) {
  98.  
  99. /*
  100. * Standoff problem:  one or both entities must die, and/or both switch
  101. * places.  Avoid infinite recursion by checking first whether the other
  102. * entity is staying put.  Clean up if we happen to move/die in recursion.
  103. */
  104. 		struct entity *other;
  105.  
  106. 		other = e_at(newx, newy);
  107. #ifdef D_DEBUG
  108. 		pline("New square is occupied by %s", e_nam(other));
  109. #endif
  110. 		if (e_survives_at(other, newx, newy) && automiss(other)) {
  111. 			relocates = FALSE;	      /* "other" won't budge */
  112. #ifdef D_DEBUG
  113. 			pline("%s suicide.", E_phrase(etmp, "commit"));
  114. #endif
  115. 		} else {
  116.  
  117. #ifdef D_DEBUG
  118. 			pline("Handling %s", e_nam(other));
  119. #endif
  120. 			while ((e_at(newx, newy) != 0) &&
  121. 			       (e_at(newx, newy) != etmp))
  122. 				do_entity(other);
  123. #ifdef D_DEBUG
  124. 			pline("Checking existence of %s", e_nam(etmp));
  125. 			wait_synch();
  126. #endif
  127. 			if (e_at(oldx, oldy) != etmp) {
  128. #ifdef D_DEBUG
  129. 			    pline("%s moved or died in recursion somewhere",
  130. 				  E_phrase(etmp, "have"));
  131. 			    wait_synch();
  132. #endif
  133. 			    return;
  134. 			}
  135. 		}
  136. 	}
  137. 	if (relocates && !e_at(newx, newy)) {/* if e_at() entity = worm tail */
  138. #ifdef D_DEBUG
  139. 		pline("Moving %s", e_nam(etmp));
  140. #endif
  141. 		if (!is_u(etmp)) {
  142. 			remove_monster(etmp->ex, etmp->ey);
  143. 			place_monster(etmp->emon, newx, newy);
  144. 			update_monster_region(etmp->emon);
  145. 		} else {
  146. 			u.ux = newx;
  147. 			u.uy = newy;
  148. 		}
  149. 		etmp->ex = newx;
  150. 		etmp->ey = newy;
  151. 		e_inview = e_canseemon(etmp);
  152. 	}
  153. #ifdef D_DEBUG
  154. 	pline("Final disposition of %s", e_nam(etmp));
  155. 	wait_synch();
  156. #endif
  157. 	if (is_db_wall(etmp->ex, etmp->ey)) {
  158. #ifdef D_DEBUG
  159. 		pline("%s in portcullis chamber", E_phrase(etmp, "are"));
  160. 		wait_synch();
  161. #endif
  162. 		if (e_inview) {
  163. 			if (is_u(etmp)) {
  164. 				You("tumble towards the closed portcullis!");
  165. 				if (automiss(etmp))
  166. 					You("pass through it!");
  167. 				else
  168. 					pline_The("drawbridge closes in...");
  169. 			} else
  170. 				pline("%s behind the drawbridge.",
  171. 				      E_phrase(etmp, "disappear"));
  172. 		}
  173. 		if (!e_survives_at(etmp, etmp->ex, etmp->ey)) {
  174. 			killer_format = KILLED_BY_AN;
  175. 			killer = "closing drawbridge";
  176. 			e_died(etmp, 0, CRUSHING);	       /* no message */
  177. 			return;
  178. 		}
  179. #ifdef D_DEBUG
  180. 		pline("%s in here", E_phrase(etmp, "survive"));
  181. #endif
  182. 	} else {
  183. #ifdef D_DEBUG
  184. 		pline("%s on drawbridge square", E_phrase(etmp, "are"));
  185. #endif
  186. 		if (is_pool(etmp->ex, etmp->ey) && !e_inview)
  187. 			if (flags.soundok)
  188. 				You_hear("a splash.");
  189. 		if (e_survives_at(etmp, etmp->ex, etmp->ey)) {
  190. 			if (e_inview && !is_flyer(etmp->edata) &&
  191. 			    !is_floater(etmp->edata))
  192. 				pline("%s from the bridge.",
  193. 				      E_phrase(etmp, "fall"));
  194. 			return;
  195. 		}
  196. #ifdef D_DEBUG
  197. 		pline("%s cannot survive on the drawbridge square",Enam(etmp));
  198. #endif
  199. 		if (is_pool(etmp->ex, etmp->ey) || is_lava(etmp->ex, etmp->ey))
  200. 		    if (e_inview && !is_u(etmp)) {
  201. 			/* drown() will supply msgs if nec. */
  202. 			boolean lava = is_lava(etmp->ex, etmp->ey);
  203.  
  204. 			if (Hallucination)
  205. 			    pline("%s the %s and disappears.",
  206. 				  E_phrase(etmp, "drink"),
  207. 				  lava ? "lava" : "moat");
  208. 			else
  209. 			    pline("%s into the %s.",
  210. 				  E_phrase(etmp, "fall"),
  211. 				  lava ? "lava" : "moat");
  212. 		    }
  213. 		killer_format = NO_KILLER_PREFIX;
  214. 		killer = "fell from a drawbridge";
  215. 		e_died(etmp, e_inview ? 3 : 2,      /* CRUSHING is arbitrary */
  216. 		       (is_pool(etmp->ex, etmp->ey)) ? DROWNING :
  217. 		       (is_lava(etmp->ex, etmp->ey)) ? BURNING :
  218. 						       CRUSHING); /*no corpse*/
  219. 		return;
  220. 	}
  221. }

close_drawbridge

  1. /*
  2. * Close the drawbridge located at x,y
  3. */
  4.  
  5. void
  6. close_drawbridge(x,y)
  7. int x,y;
  8. {
  9. 	register struct rm *lev1, *lev2;
  10. 	struct trap *t;
  11. 	int x2, y2;
  12.  
  13. 	lev1 = &levl[x][y];
  14. 	if (lev1->typ != DRAWBRIDGE_DOWN) return;
  15. 	x2 = x; y2 = y;
  16. 	get_wall_for_db(&x2,&y2);
  17. 	if (cansee(x,y) || cansee(x2,y2))
  18. 		You("see a drawbridge %s up!",
  19. 		    (((u.ux == x || u.uy == y) && !Underwater) ||
  20. 		     distu(x2,y2) < distu(x,y)) ? "coming" : "going");
  21. 	lev1->typ = DRAWBRIDGE_UP;
  22. 	lev2 = &levl[x2][y2];
  23. 	lev2->typ = DBWALL;
  24. 	switch (lev1->drawbridgemask & DB_DIR) {
  25. 		case DB_NORTH:
  26. 		case DB_SOUTH:
  27. 			lev2->horizontal = TRUE;
  28. 			break;
  29. 		case DB_WEST:
  30. 		case DB_EAST:
  31. 			lev2->horizontal = FALSE;
  32. 			break;
  33. 	}
  34. 	lev2->wall_info = W_NONDIGGABLE;
  35. 	set_entity(x, y, &(occupants[0]));
  36. 	set_entity(x2, y2, &(occupants[1]));
  37. 	do_entity(&(occupants[0]));		/* Do set_entity after first */
  38. 	set_entity(x2, y2, &(occupants[1]));	/* do_entity for worm tail */
  39. 	do_entity(&(occupants[1]));
  40. 	if(OBJ_AT(x,y) && flags.soundok)
  41. 	    You_hear("smashing and crushing.");
  42. 	(void) revive_nasty(x,y,(char *)0);
  43. 	(void) revive_nasty(x2,y2,(char *)0);
  44. 	delallobj(x, y);
  45. 	delallobj(x2, y2);
  46. 	if ((t = t_at(x, y)) != 0) deltrap(t);
  47. 	if ((t = t_at(x2, y2)) != 0) deltrap(t);
  48. 	newsym(x, y);
  49. 	newsym(x2, y2);
  50. 	block_point(x2,y2);	/* vision */
  51. }

open_drawbridge

  1. /*
  2. * Open the drawbridge located at x,y
  3. */
  4.  
  5. void
  6. open_drawbridge(x,y)
  7. int x,y;
  8. {
  9. 	register struct rm *lev1, *lev2;
  10. 	struct trap *t;
  11. 	int x2, y2;
  12.  
  13. 	lev1 = &levl[x][y];
  14. 	if (lev1->typ != DRAWBRIDGE_UP) return;
  15. 	x2 = x; y2 = y;
  16. 	get_wall_for_db(&x2,&y2);
  17. 	if (cansee(x,y) || cansee(x2,y2))
  18. 		You("see a drawbridge %s down!",
  19. 		    (distu(x2,y2) < distu(x,y)) ? "going" : "coming");
  20. 	lev1->typ = DRAWBRIDGE_DOWN;
  21. 	lev2 = &levl[x2][y2];
  22. 	lev2->typ = DOOR;
  23. 	lev2->doormask = D_NODOOR;
  24. 	set_entity(x, y, &(occupants[0]));
  25. 	set_entity(x2, y2, &(occupants[1]));
  26. 	do_entity(&(occupants[0]));		/* do set_entity after first */
  27. 	set_entity(x2, y2, &(occupants[1]));	/* do_entity for worm tails */
  28. 	do_entity(&(occupants[1]));
  29. 	(void) revive_nasty(x,y,(char *)0);
  30. 	delallobj(x, y);
  31. 	if ((t = t_at(x, y)) != 0) deltrap(t);
  32. 	if ((t = t_at(x2, y2)) != 0) deltrap(t);
  33. 	newsym(x, y);
  34. 	newsym(x2, y2);
  35. 	unblock_point(x2,y2);	/* vision */
  36. 	if (Is_stronghold(&u.uz)) u.uevent.uopened_dbridge = TRUE;
  37. }

destroy_drawbridge

  1. /*
  2. * Let's destroy the drawbridge located at x,y
  3. */
  4.  
  5. void
  6. destroy_drawbridge(x,y)
  7. int x,y;
  8. {
  9. 	register struct rm *lev1, *lev2;
  10. 	struct trap *t;
  11. 	int x2, y2;
  12. 	boolean e_inview;
  13. 	struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]);
  14.  
  15. 	lev1 = &levl[x][y];
  16. 	if (!IS_DRAWBRIDGE(lev1->typ))
  17. 		return;
  18. 	x2 = x; y2 = y;
  19. 	get_wall_for_db(&x2,&y2);
  20. 	lev2 = &levl[x2][y2];
  21. 	if ((lev1->drawbridgemask & DB_UNDER) == DB_MOAT ||
  22. 	    (lev1->drawbridgemask & DB_UNDER) == DB_LAVA) {
  23. 		struct obj *otmp;
  24. 		boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA;
  25. 		if (lev1->typ == DRAWBRIDGE_UP) {
  26. 			if (cansee(x2,y2))
  27. 			    pline_The("portcullis of the drawbridge falls into the %s!",
  28. 				  lava ? "lava" : "moat");
  29. 			else if (flags.soundok)
  30. 				You_hear("a loud *SPLASH*!");
  31. 		} else {
  32. 			if (cansee(x,y))
  33. 			    pline_The("drawbridge collapses into the %s!",
  34. 				  lava ? "lava" : "moat");
  35. 			else if (flags.soundok)
  36. 				You_hear("a loud *SPLASH*!");
  37. 		}
  38. 		lev1->typ = lava ? LAVAPOOL : MOAT;
  39. 		lev1->drawbridgemask = 0;
  40. 		if ((otmp = sobj_at(BOULDER,x,y)) != 0) {
  41. 		    obj_extract_self(otmp);
  42. 		    (void) flooreffects(otmp,x,y,"fall");
  43. 		}
  44. 	} else {
  45. 		if (cansee(x,y))
  46. 			pline_The("drawbridge disintegrates!");
  47. 		else
  48. 			You_hear("a loud *CRASH*!");
  49. 		lev1->typ =
  50. 			((lev1->drawbridgemask & DB_ICE) ? ICE : ROOM);
  51. 		lev1->icedpool =
  52. 			((lev1->drawbridgemask & DB_ICE) ? ICED_MOAT : 0);
  53. 	}
  54. 	wake_nearto(x, y, 500);
  55. 	lev2->typ = DOOR;
  56. 	lev2->doormask = D_NODOOR;
  57. 	if ((t = t_at(x, y)) != 0) deltrap(t);
  58. 	if ((t = t_at(x2, y2)) != 0) deltrap(t);
  59. 	newsym(x,y);
  60. 	newsym(x2,y2);
  61. 	if (!does_block(x2,y2,lev2)) unblock_point(x2,y2);	/* vision */
  62. 	if (Is_stronghold(&u.uz)) u.uevent.uopened_dbridge = TRUE;
  63.  
  64. 	set_entity(x2, y2, etmp2); /* currently only automissers can be here */
  65. 	if (etmp2->edata) {
  66. 		e_inview = e_canseemon(etmp2);
  67. 		if (!automiss(etmp2)) {
  68. 			if (e_inview)
  69. 				pline("%s blown apart by flying debris.",
  70. 				      E_phrase(etmp2, "are"));
  71. 			killer_format = KILLED_BY_AN;
  72. 			killer = "exploding drawbridge";
  73. 			e_died(etmp2, e_inview? 3 : 2, CRUSHING); /*no corpse*/
  74. 		}	     /* nothing which is vulnerable can survive this */
  75. 	}
  76. 	set_entity(x, y, etmp1);
  77. 	if (etmp1->edata) {
  78. 		e_inview = e_canseemon(etmp1);
  79. 		if (e_missed(etmp1, TRUE)) {
  80. #ifdef D_DEBUG
  81. 			pline("%s spared!", E_phrase(etmp1, "are"));
  82. #endif
  83. 		} else {
  84. 			if (e_inview) {
  85. 			    if (!is_u(etmp1) && Hallucination)
  86. 				pline("%s into some heavy metal!",
  87. 				      E_phrase(etmp1, "get"));
  88. 			    else
  89. 				pline("%s hit by a huge chunk of metal!",
  90. 				      E_phrase(etmp1, "are"));
  91. 			} else {
  92. 			    if (flags.soundok && !is_u(etmp1) && !is_pool(x,y))
  93. 				You_hear("a crushing sound.");
  94. #ifdef D_DEBUG
  95. 			    else
  96. 				pline("%s from shrapnel",
  97. 				      E_phrase(etmp1, "die"));
  98. #endif
  99. 			}
  100. 			killer_format = KILLED_BY_AN;
  101. 			killer = "collapsing drawbridge";
  102. 			e_died(etmp1, e_inview? 3 : 2, CRUSHING); /*no corpse*/
  103. 			if(lev1->typ == MOAT) do_entity(etmp1);
  104. 		}
  105. 	}
  106. }
  107.  
  108. #endif /* OVLB */
  109.  
  110. /*dbridge.c*/