Source:NetHack 3.4.3/src/lock.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)lock.c	3.4	2000/02/06	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  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. #include "hack.h"
  2.  
  3. STATIC_PTR int NDECL(picklock);
  4. STATIC_PTR int NDECL(forcelock);
  5.  
  6. /* at most one of `door' and `box' should be non-null at any given time */
  7. STATIC_VAR NEARDATA struct xlock_s {
  8. 	struct rm  *door;
  9. 	struct obj *box;
  10. 	int picktyp, chance, usedtime;
  11. } xlock;
  12.  
  13. #ifdef OVLB
  14.  
  15. STATIC_DCL const char *NDECL(lock_action);
  16. STATIC_DCL boolean FDECL(obstructed,(int,int));
  17. STATIC_DCL void FDECL(chest_shatter_msg, (struct obj *));

picking_lock[edit]

  1. boolean
  2. picking_lock(x, y)
  3. 	int *x, *y;
  4. {
  5. 	if (occupation == picklock) {
  6. 	    *x = u.ux + u.dx;
  7. 	    *y = u.uy + u.dy;
  8. 	    return TRUE;
  9. 	} else {
  10. 	    *x = *y = 0;
  11. 	    return FALSE;
  12. 	}
  13. }

picking_at[edit]

  1. boolean
  2. picking_at(x, y)
  3. int x, y;
  4. {
  5. 	return (boolean)(occupation == picklock && xlock.door == &levl[x][y]);
  6. }

lock_action[edit]

  1. /* produce an occupation string appropriate for the current activity */
  2. STATIC_OVL const char *
  3. lock_action()
  4. {
  5. 	/* "unlocking"+2 == "locking" */
  6. 	static const char *actions[] = {
  7. 		/* [0] */	"unlocking the door",
  8. 		/* [1] */	"unlocking the chest",
  9. 		/* [2] */	"unlocking the box",
  10. 		/* [3] */	"picking the lock"
  11. 	};
  12.  
  13. 	/* if the target is currently unlocked, we're trying to lock it now */
  14. 	if (xlock.door && !(xlock.door->doormask & D_LOCKED))
  15. 		return actions[0]+2;	/* "locking the door" */
  16. 	else if (xlock.box && !xlock.box->olocked)
  17. 		return xlock.box->otyp == CHEST ? actions[1]+2 : actions[2]+2;
  18. 	/* otherwise we're trying to unlock it */
  19. 	else if (xlock.picktyp == LOCK_PICK)
  20. 		return actions[3];	/* "picking the lock" */
  21. #ifdef TOURIST
  22. 	else if (xlock.picktyp == CREDIT_CARD)
  23. 		return actions[3];	/* same as lock_pick */
  24. #endif
  25. 	else if (xlock.door)
  26. 		return actions[0];	/* "unlocking the door" */
  27. 	else
  28. 		return xlock.box->otyp == CHEST ? actions[1] : actions[2];
  29. }

picklock[edit]

  1. STATIC_PTR
  2. int
  3. picklock()	/* try to open/close a lock */
  4. {
  5.  
  6. 	if (xlock.box) {
  7. 	    if((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy)) {
  8. 		return((xlock.usedtime = 0));		/* you or it moved */
  9. 	    }
  10. 	} else {		/* door */
  11. 	    if(xlock.door != &(levl[u.ux+u.dx][u.uy+u.dy])) {
  12. 		return((xlock.usedtime = 0));		/* you moved */
  13. 	    }
  14. 	    switch (xlock.door->doormask) {
  15. 		case D_NODOOR:
  16. 		    pline("This doorway has no door.");
  17. 		    return((xlock.usedtime = 0));
  18. 		case D_ISOPEN:
  19. 		    You("cannot lock an open door.");
  20. 		    return((xlock.usedtime = 0));
  21. 		case D_BROKEN:
  22. 		    pline("This door is broken.");
  23. 		    return((xlock.usedtime = 0));
  24. 	    }
  25. 	}
  26.  
  27. 	if (xlock.usedtime++ >= 50 || nohands(youmonst.data)) {
  28. 	    You("give up your attempt at %s.", lock_action());
  29. 	    exercise(A_DEX, TRUE);	/* even if you don't succeed */
  30. 	    return((xlock.usedtime = 0));
  31. 	}
  32.  
  33. 	if(rn2(100) >= xlock.chance) return(1);		/* still busy */
  34.  
  35. 	You("succeed in %s.", lock_action());
  36. 	if (xlock.door) {
  37. 	    if(xlock.door->doormask & D_TRAPPED) {
  38. 		    b_trapped("door", FINGER);
  39. 		    xlock.door->doormask = D_NODOOR;
  40. 		    unblock_point(u.ux+u.dx, u.uy+u.dy);
  41. 		    if (*in_rooms(u.ux+u.dx, u.uy+u.dy, SHOPBASE))
  42. 			add_damage(u.ux+u.dx, u.uy+u.dy, 0L);
  43. 		    newsym(u.ux+u.dx, u.uy+u.dy);
  44. 	    } else if (xlock.door->doormask & D_LOCKED)
  45. 		xlock.door->doormask = D_CLOSED;
  46. 	    else xlock.door->doormask = D_LOCKED;
  47. 	} else {
  48. 	    xlock.box->olocked = !xlock.box->olocked;
  49. 	    if(xlock.box->otrapped)	
  50. 		(void) chest_trap(xlock.box, FINGER, FALSE);
  51. 	}
  52. 	exercise(A_DEX, TRUE);
  53. 	return((xlock.usedtime = 0));
  54. }

forcelock[edit]

  1. STATIC_PTR
  2. int
  3. forcelock()	/* try to force a locked chest */
  4. {
  5.  
  6. 	register struct obj *otmp;
  7.  
  8. 	if((xlock.box->ox != u.ux) || (xlock.box->oy != u.uy))
  9. 		return((xlock.usedtime = 0));		/* you or it moved */
  10.  
  11. 	if (xlock.usedtime++ >= 50 || !uwep || nohands(youmonst.data)) {
  12. 	    You("give up your attempt to force the lock.");
  13. 	    if(xlock.usedtime >= 50)		/* you made the effort */
  14. 	      exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE);
  15. 	    return((xlock.usedtime = 0));
  16. 	}
  17.  
  18. 	if(xlock.picktyp) {	/* blade */
  19.  
  20. 	    if(rn2(1000-(int)uwep->spe) > (992-greatest_erosion(uwep)*10) &&
  21. 	       !uwep->cursed && !obj_resists(uwep, 0, 99)) {
  22. 		/* for a +0 weapon, probability that it survives an unsuccessful
  23. 		 * attempt to force the lock is (.992)^50 = .67
  24. 		 */
  25. 		pline("%sour %s broke!",
  26. 		      (uwep->quan > 1L) ? "One of y" : "Y", xname(uwep));
  27. 		useup(uwep);
  28. 		You("give up your attempt to force the lock.");
  29. 		exercise(A_DEX, TRUE);
  30. 		return((xlock.usedtime = 0));
  31. 	    }
  32. 	} else			/* blunt */
  33. 	    wake_nearby();	/* due to hammering on the container */
  34.  
  35. 	if(rn2(100) >= xlock.chance) return(1);		/* still busy */
  36.  
  37. 	You("succeed in forcing the lock.");
  38. 	xlock.box->olocked = 0;
  39. 	xlock.box->obroken = 1;
  40. 	if(!xlock.picktyp && !rn2(3)) {
  41. 	    struct monst *shkp;
  42. 	    boolean costly;
  43. 	    long loss = 0L;
  44.  
  45. 	    costly = (*u.ushops && costly_spot(u.ux, u.uy));
  46. 	    shkp = costly ? shop_keeper(*u.ushops) : 0;
  47.  
  48. 	    pline("In fact, you've totally destroyed %s.",
  49. 		  the(xname(xlock.box)));
  50.  
  51. 	    /* Put the contents on ground at the hero's feet. */
  52. 	    while ((otmp = xlock.box->cobj) != 0) {
  53. 		obj_extract_self(otmp);
  54. 		if(!rn2(3) || otmp->oclass == POTION_CLASS) {
  55. 		    chest_shatter_msg(otmp);
  56. 		    if (costly)
  57. 		        loss += stolen_value(otmp, u.ux, u.uy,
  58. 					     (boolean)shkp->mpeaceful, TRUE);
  59. 		    if (otmp->quan == 1L) {
  60. 			obfree(otmp, (struct obj *) 0);
  61. 			continue;
  62. 		    }
  63. 		    useup(otmp);
  64. 		}
  65. 		if (xlock.box->otyp == ICE_BOX && otmp->otyp == CORPSE) {
  66. 		    otmp->age = monstermoves - otmp->age; /* actual age */
  67. 		    start_corpse_timeout(otmp);
  68. 		}
  69. 		place_object(otmp, u.ux, u.uy);
  70. 		stackobj(otmp);
  71. 	    }
  72.  
  73. 	    if (costly)
  74. 		loss += stolen_value(xlock.box, u.ux, u.uy,
  75. 					     (boolean)shkp->mpeaceful, TRUE);
  76. 	    if(loss) You("owe %ld %s for objects destroyed.", loss, currency(loss));
  77. 	    delobj(xlock.box);
  78. 	}
  79. 	exercise((xlock.picktyp) ? A_DEX : A_STR, TRUE);
  80. 	return((xlock.usedtime = 0));
  81. }
  82.  
  83. #endif /* OVLB */

reset_pick[edit]

  1. #ifdef OVL0
  2.  
  3. void
  4. reset_pick()
  5. {
  6. 	xlock.usedtime = xlock.chance = xlock.picktyp = 0;
  7. 	xlock.door = 0;
  8. 	xlock.box = 0;
  9. }
  10.  
  11. #endif /* OVL0 */

pick_lock[edit]

  1. #ifdef OVLB
  2.  
  3. int
  4. pick_lock(pick) /* pick a lock with a given object */
  5. 	register struct	obj	*pick;
  6. {
  7. 	int picktyp, c, ch;
  8. 	coord cc;
  9. 	struct rm	*door;
  10. 	struct obj	*otmp;
  11. 	char qbuf[QBUFSZ];
  12.  
  13. 	picktyp = pick->otyp;
  14.  
  15. 	/* check whether we're resuming an interrupted previous attempt */
  16. 	if (xlock.usedtime && picktyp == xlock.picktyp) {
  17. 	    static char no_longer[] = "Unfortunately, you can no longer %s %s.";
  18.  
  19. 	    if (nohands(youmonst.data)) {
  20. 		const char *what = (picktyp == LOCK_PICK) ? "pick" : "key";
  21. #ifdef TOURIST
  22. 		if (picktyp == CREDIT_CARD) what = "card";
  23. #endif
  24. 		pline(no_longer, "hold the", what);
  25. 		reset_pick();
  26. 		return 0;
  27. 	    } else if (xlock.box && !can_reach_floor()) {
  28. 		pline(no_longer, "reach the", "lock");
  29. 		reset_pick();
  30. 		return 0;
  31. 	    } else {
  32. 		const char *action = lock_action();
  33. 		You("resume your attempt at %s.", action);
  34. 		set_occupation(picklock, action, 0);
  35. 		return(1);
  36. 	    }
  37. 	}
  38.  
  39. 	if(nohands(youmonst.data)) {
  40. 		You_cant("hold %s -- you have no hands!", doname(pick));
  41. 		return(0);
  42. 	}
  43.  
  44. 	if((picktyp != LOCK_PICK &&
  45. #ifdef TOURIST
  46. 	    picktyp != CREDIT_CARD &&
  47. #endif
  48. 	    picktyp != SKELETON_KEY)) {
  49. 		impossible("picking lock with object %d?", picktyp);
  50. 		return(0);
  51. 	}
  52. 	ch = 0;		/* lint suppression */
  53.  
  54. 	if(!get_adjacent_loc((char *)0, "Invalid location!", u.ux, u.uy, &cc)) return 0;
  55. 	if (cc.x == u.ux && cc.y == u.uy) {	/* pick lock on a container */
  56. 	    const char *verb;
  57. 	    boolean it;
  58. 	    int count;
  59.  
  60. 	    if (u.dz < 0) {
  61. 		There("isn't any sort of lock up %s.",
  62. 		      Levitation ? "here" : "there");
  63. 		return 0;
  64. 	    } else if (is_lava(u.ux, u.uy)) {
  65. 		pline("Doing that would probably melt your %s.",
  66. 		      xname(pick));
  67. 		return 0;
  68. 	    } else if (is_pool(u.ux, u.uy) && !Underwater) {
  69. 		pline_The("water has no lock.");
  70. 		return 0;
  71. 	    }
  72.  
  73. 	    count = 0;
  74. 	    c = 'n';			/* in case there are no boxes here */
  75. 	    for(otmp = level.objects[cc.x][cc.y]; otmp; otmp = otmp->nexthere)
  76. 		if (Is_box(otmp)) {
  77. 		    ++count;
  78. 		    if (!can_reach_floor()) {
  79. 			You_cant("reach %s from up here.", the(xname(otmp)));
  80. 			return 0;
  81. 		    }
  82. 		    it = 0;
  83. 		    if (otmp->obroken) verb = "fix";
  84. 		    else if (!otmp->olocked) verb = "lock", it = 1;
  85. 		    else if (picktyp != LOCK_PICK) verb = "unlock", it = 1;
  86. 		    else verb = "pick";
  87. 		    Sprintf(qbuf, "There is %s here, %s %s?",
  88. 		    	    safe_qbuf("", sizeof("There is  here, unlock its lock?"),
  89. 			    	doname(otmp), an(simple_typename(otmp->otyp)), "a box"),
  90. 			    verb, it ? "it" : "its lock");
  91.  
  92. 		    c = ynq(qbuf);
  93. 		    if(c == 'q') return(0);
  94. 		    if(c == 'n') continue;
  95.  
  96. 		    if (otmp->obroken) {
  97. 			You_cant("fix its broken lock with %s.", doname(pick));
  98. 			return 0;
  99. 		    }
  100. #ifdef TOURIST
  101. 		    else if (picktyp == CREDIT_CARD && !otmp->olocked) {
  102. 			/* credit cards are only good for unlocking */
  103. 			You_cant("do that with %s.", doname(pick));
  104. 			return 0;
  105. 		    }
  106. #endif
  107. 		    switch(picktyp) {
  108. #ifdef TOURIST
  109. 			case CREDIT_CARD:
  110. 			    ch = ACURR(A_DEX) + 20*Role_if(PM_ROGUE);
  111. 			    break;
  112. #endif
  113. 			case LOCK_PICK:
  114. 			    ch = 4*ACURR(A_DEX) + 25*Role_if(PM_ROGUE);
  115. 			    break;
  116. 			case SKELETON_KEY:
  117. 			    ch = 75 + ACURR(A_DEX);
  118. 			    break;
  119. 			default:	ch = 0;
  120. 		    }
  121. 		    if(otmp->cursed) ch /= 2;
  122.  
  123. 		    xlock.picktyp = picktyp;
  124. 		    xlock.box = otmp;
  125. 		    xlock.door = 0;
  126. 		    break;
  127. 		}
  128. 	    if (c != 'y') {
  129. 		if (!count)
  130. 		    There("doesn't seem to be any sort of lock here.");
  131. 		return(0);		/* decided against all boxes */
  132. 	    }
  133. 	} else {			/* pick the lock in a door */
  134. 	    struct monst *mtmp;
  135.  
  136. 	    if (u.utrap && u.utraptype == TT_PIT) {
  137. 		You_cant("reach over the edge of the pit.");
  138. 		return(0);
  139. 	    }
  140.  
  141. 	    door = &levl[cc.x][cc.y];
  142. 	    if ((mtmp = m_at(cc.x, cc.y)) && canseemon(mtmp)
  143. 			&& mtmp->m_ap_type != M_AP_FURNITURE
  144. 			&& mtmp->m_ap_type != M_AP_OBJECT) {
  145. #ifdef TOURIST
  146. 		if (picktyp == CREDIT_CARD &&
  147. 		    (mtmp->isshk || mtmp->data == &mons[PM_ORACLE]))
  148. 		    verbalize("No checks, no credit, no problem.");
  149. 		else
  150. #endif
  151. 		    pline("I don't think %s would appreciate that.", mon_nam(mtmp));
  152. 		return(0);
  153. 	    }
  154. 	    if(!IS_DOOR(door->typ)) {
  155. 		if (is_drawbridge_wall(cc.x,cc.y) >= 0)
  156. 		    You("%s no lock on the drawbridge.",
  157. 				Blind ? "feel" : "see");
  158. 		else
  159. 		    You("%s no door there.",
  160. 				Blind ? "feel" : "see");
  161. 		return(0);
  162. 	    }
  163. 	    switch (door->doormask) {
  164. 		case D_NODOOR:
  165. 		    pline("This doorway has no door.");
  166. 		    return(0);
  167. 		case D_ISOPEN:
  168. 		    You("cannot lock an open door.");
  169. 		    return(0);
  170. 		case D_BROKEN:
  171. 		    pline("This door is broken.");
  172. 		    return(0);
  173. 		default:
  174. #ifdef TOURIST
  175. 		    /* credit cards are only good for unlocking */
  176. 		    if(picktyp == CREDIT_CARD && !(door->doormask & D_LOCKED)) {
  177. 			You_cant("lock a door with a credit card.");
  178. 			return(0);
  179. 		    }
  180. #endif
  181.  
  182. 		    Sprintf(qbuf,"%sock it?",
  183. 			(door->doormask & D_LOCKED) ? "Unl" : "L" );
  184.  
  185. 		    c = yn(qbuf);
  186. 		    if(c == 'n') return(0);
  187.  
  188. 		    switch(picktyp) {
  189. #ifdef TOURIST
  190. 			case CREDIT_CARD:
  191. 			    ch = 2*ACURR(A_DEX) + 20*Role_if(PM_ROGUE);
  192. 			    break;
  193. #endif
  194. 			case LOCK_PICK:
  195. 			    ch = 3*ACURR(A_DEX) + 30*Role_if(PM_ROGUE);
  196. 			    break;
  197. 			case SKELETON_KEY:
  198. 			    ch = 70 + ACURR(A_DEX);
  199. 			    break;
  200. 			default:    ch = 0;
  201. 		    }
  202. 		    xlock.door = door;
  203. 		    xlock.box = 0;
  204. 	    }
  205. 	}
  206. 	flags.move = 0;
  207. 	xlock.chance = ch;
  208. 	xlock.picktyp = picktyp;
  209. 	xlock.usedtime = 0;
  210. 	set_occupation(picklock, lock_action(), 0);
  211. 	return(1);
  212. }

doforce[edit]

  1. int
  2. doforce()		/* try to force a chest with your weapon */
  3. {
  4. 	register struct obj *otmp;
  5. 	register int c, picktyp;
  6. 	char qbuf[QBUFSZ];
  7.  
  8. 	if(!uwep ||	/* proper type test */
  9. 	   (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep) &&
  10. 	    uwep->oclass != ROCK_CLASS) ||
  11. 	   (objects[uwep->otyp].oc_skill < P_DAGGER) ||
  12. 	   (objects[uwep->otyp].oc_skill > P_LANCE) ||
  13. 	   uwep->otyp == FLAIL || uwep->otyp == AKLYS
  14. #ifdef KOPS
  15. 	   || uwep->otyp == RUBBER_HOSE
  16. #endif
  17. 	  ) {
  18. 	    You_cant("force anything without a %sweapon.",
  19. 		  (uwep) ? "proper " : "");
  20. 	    return(0);
  21. 	}
  22.  
  23. 	picktyp = is_blade(uwep);
  24. 	if(xlock.usedtime && xlock.box && picktyp == xlock.picktyp) {
  25. 	    You("resume your attempt to force the lock.");
  26. 	    set_occupation(forcelock, "forcing the lock", 0);
  27. 	    return(1);
  28. 	}
  29.  
  30. 	/* A lock is made only for the honest man, the thief will break it. */
  31. 	xlock.box = (struct obj *)0;
  32. 	for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
  33. 	    if(Is_box(otmp)) {
  34. 		if (otmp->obroken || !otmp->olocked) {
  35. 		    There("is %s here, but its lock is already %s.",
  36. 			  doname(otmp), otmp->obroken ? "broken" : "unlocked");
  37. 		    continue;
  38. 		}
  39. 		Sprintf(qbuf,"There is %s here, force its lock?",
  40. 			safe_qbuf("", sizeof("There is  here, force its lock?"),
  41. 				doname(otmp), an(simple_typename(otmp->otyp)),
  42. 				"a box"));
  43.  
  44. 		c = ynq(qbuf);
  45. 		if(c == 'q') return(0);
  46. 		if(c == 'n') continue;
  47.  
  48. 		if(picktyp)
  49. 		    You("force your %s into a crack and pry.", xname(uwep));
  50. 		else
  51. 		    You("start bashing it with your %s.", xname(uwep));
  52. 		xlock.box = otmp;
  53. 		xlock.chance = objects[uwep->otyp].oc_wldam * 2;
  54. 		xlock.picktyp = picktyp;
  55. 		xlock.usedtime = 0;
  56. 		break;
  57. 	    }
  58.  
  59. 	if(xlock.box)	set_occupation(forcelock, "forcing the lock", 0);
  60. 	else		You("decide not to force the issue.");
  61. 	return(1);
  62. }

doopen[edit]

  1. int
  2. doopen()		/* try to open a door */
  3. {
  4. 	coord cc;
  5. 	register struct rm *door;
  6. 	struct monst *mtmp;
  7.  
  8. 	if (nohands(youmonst.data)) {
  9. 	    You_cant("open anything -- you have no hands!");
  10. 	    return 0;
  11. 	}
  12.  
  13. 	if (u.utrap && u.utraptype == TT_PIT) {
  14. 	    You_cant("reach over the edge of the pit.");
  15. 	    return 0;
  16. 	}
  17.  
  18. 	if(!get_adjacent_loc((char *)0, (char *)0, u.ux, u.uy, &cc)) return(0);
  19.  
  20. 	if((cc.x == u.ux) && (cc.y == u.uy)) return(0);
  21.  
  22. 	if ((mtmp = m_at(cc.x,cc.y))			&&
  23. 		mtmp->m_ap_type == M_AP_FURNITURE	&&
  24. 		(mtmp->mappearance == S_hcdoor ||
  25. 			mtmp->mappearance == S_vcdoor)	&&
  26. 		!Protection_from_shape_changers)	 {
  27.  
  28. 	    stumble_onto_mimic(mtmp);
  29. 	    return(1);
  30. 	}
  31.  
  32. 	door = &levl[cc.x][cc.y];
  33.  
  34. 	if(!IS_DOOR(door->typ)) {
  35. 		if (is_db_wall(cc.x,cc.y)) {
  36. 		    There("is no obvious way to open the drawbridge.");
  37. 		    return(0);
  38. 		}
  39. 		You("%s no door there.",
  40. 				Blind ? "feel" : "see");
  41. 		return(0);
  42. 	}
  43.  
  44. 	if (!(door->doormask & D_CLOSED)) {
  45. 	    const char *mesg;
  46.  
  47. 	    switch (door->doormask) {
  48. 	    case D_BROKEN: mesg = " is broken"; break;
  49. 	    case D_NODOOR: mesg = "way has no door"; break;
  50. 	    case D_ISOPEN: mesg = " is already open"; break;
  51. 	    default:	   mesg = " is locked"; break;
  52. 	    }
  53. 	    pline("This door%s.", mesg);
  54. 	    if (Blind) feel_location(cc.x,cc.y);
  55. 	    return(0);
  56. 	}
  57.  
  58. 	if(verysmall(youmonst.data)) {
  59. 	    pline("You're too small to pull the door open.");
  60. 	    return(0);
  61. 	}
  62.  
  63. 	/* door is known to be CLOSED */
  64. 	if (rnl(20) < (ACURRSTR+ACURR(A_DEX)+ACURR(A_CON))/3) {
  65. 	    pline_The("door opens.");
  66. 	    if(door->doormask & D_TRAPPED) {
  67. 		b_trapped("door", FINGER);
  68. 		door->doormask = D_NODOOR;
  69. 		if (*in_rooms(cc.x, cc.y, SHOPBASE)) add_damage(cc.x, cc.y, 0L);
  70. 	    } else
  71. 		door->doormask = D_ISOPEN;
  72. 	    if (Blind)
  73. 		feel_location(cc.x,cc.y);	/* the hero knows she opened it  */
  74. 	    else
  75. 		newsym(cc.x,cc.y);
  76. 	    unblock_point(cc.x,cc.y);		/* vision: new see through there */
  77. 	} else {
  78. 	    exercise(A_STR, TRUE);
  79. 	    pline_The("door resists!");
  80. 	}
  81.  
  82. 	return(1);
  83. }

obstructed[edit]

  1. STATIC_OVL
  2. boolean
  3. obstructed(x,y)
  4. register int x, y;
  5. {
  6. 	register struct monst *mtmp = m_at(x, y);
  7.  
  8. 	if(mtmp && mtmp->m_ap_type != M_AP_FURNITURE) {
  9. 		if (mtmp->m_ap_type == M_AP_OBJECT) goto objhere;
  10. 		pline("%s stands in the way!", !canspotmon(mtmp) ?
  11. 			"Some creature" : Monnam(mtmp));
  12. 		if (!canspotmon(mtmp))
  13. 		    map_invisible(mtmp->mx, mtmp->my);
  14. 		return(TRUE);
  15. 	}
  16. 	if (OBJ_AT(x, y)) {
  17. objhere:	pline("%s's in the way.", Something);
  18. 		return(TRUE);
  19. 	}
  20. 	return(FALSE);
  21. }

doclose[edit]

  1. int
  2. doclose()		/* try to close a door */
  3. {
  4. 	register int x, y;
  5. 	register struct rm *door;
  6. 	struct monst *mtmp;
  7.  
  8. 	if (nohands(youmonst.data)) {
  9. 	    You_cant("close anything -- you have no hands!");
  10. 	    return 0;
  11. 	}
  12.  
  13. 	if (u.utrap && u.utraptype == TT_PIT) {
  14. 	    You_cant("reach over the edge of the pit.");
  15. 	    return 0;
  16. 	}
  17.  
  18. 	if(!getdir((char *)0)) return(0);
  19.  
  20. 	x = u.ux + u.dx;
  21. 	y = u.uy + u.dy;
  22. 	if((x == u.ux) && (y == u.uy)) {
  23. 		You("are in the way!");
  24. 		return(1);
  25. 	}
  26.  
  27. 	if ((mtmp = m_at(x,y))				&&
  28. 		mtmp->m_ap_type == M_AP_FURNITURE	&&
  29. 		(mtmp->mappearance == S_hcdoor ||
  30. 			mtmp->mappearance == S_vcdoor)	&&
  31. 		!Protection_from_shape_changers)	 {
  32.  
  33. 	    stumble_onto_mimic(mtmp);
  34. 	    return(1);
  35. 	}
  36.  
  37. 	door = &levl[x][y];
  38.  
  39. 	if(!IS_DOOR(door->typ)) {
  40. 		if (door->typ == DRAWBRIDGE_DOWN)
  41. 		    There("is no obvious way to close the drawbridge.");
  42. 		else
  43. 		    You("%s no door there.",
  44. 				Blind ? "feel" : "see");
  45. 		return(0);
  46. 	}
  47.  
  48. 	if(door->doormask == D_NODOOR) {
  49. 	    pline("This doorway has no door.");
  50. 	    return(0);
  51. 	}
  52.  
  53. 	if(obstructed(x, y)) return(0);
  54.  
  55. 	if(door->doormask == D_BROKEN) {
  56. 	    pline("This door is broken.");
  57. 	    return(0);
  58. 	}
  59.  
  60. 	if(door->doormask & (D_CLOSED | D_LOCKED)) {
  61. 	    pline("This door is already closed.");
  62. 	    return(0);
  63. 	}
  64.  
  65. 	if(door->doormask == D_ISOPEN) {
  66. 	    if(verysmall(youmonst.data)
  67. #ifdef STEED
  68. 		&& !u.usteed
  69. #endif
  70. 		) {
  71. 		 pline("You're too small to push the door closed.");
  72. 		 return(0);
  73. 	    }
  74. 	    if (
  75. #ifdef STEED
  76. 		 u.usteed ||
  77. #endif
  78. 		rn2(25) < (ACURRSTR+ACURR(A_DEX)+ACURR(A_CON))/3) {
  79. 		pline_The("door closes.");
  80. 		door->doormask = D_CLOSED;
  81. 		if (Blind)
  82. 		    feel_location(x,y);	/* the hero knows she closed it */
  83. 		else
  84. 		    newsym(x,y);
  85. 		block_point(x,y);	/* vision:  no longer see there */
  86. 	    }
  87. 	    else {
  88. 	        exercise(A_STR, TRUE);
  89. 	        pline_The("door resists!");
  90. 	    }
  91. 	}
  92.  
  93. 	return(1);
  94. }

boxlock[edit]

  1. boolean			/* box obj was hit with spell effect otmp */
  2. boxlock(obj, otmp)	/* returns true if something happened */
  3. register struct obj *obj, *otmp;	/* obj *is* a box */
  4. {
  5. 	register boolean res = 0;
  6.  
  7. 	switch(otmp->otyp) {
  8. 	case WAN_LOCKING:
  9. 	case SPE_WIZARD_LOCK:
  10. 	    if (!obj->olocked) {	/* lock it; fix if broken */
  11. 		pline("Klunk!");
  12. 		obj->olocked = 1;
  13. 		obj->obroken = 0;
  14. 		res = 1;
  15. 	    } /* else already closed and locked */
  16. 	    break;
  17. 	case WAN_OPENING:
  18. 	case SPE_KNOCK:
  19. 	    if (obj->olocked) {		/* unlock; couldn't be broken */
  20. 		pline("Klick!");
  21. 		obj->olocked = 0;
  22. 		res = 1;
  23. 	    } else			/* silently fix if broken */
  24. 		obj->obroken = 0;
  25. 	    break;
  26. 	case WAN_POLYMORPH:
  27. 	case SPE_POLYMORPH:
  28. 	    /* maybe start unlocking chest, get interrupted, then zap it;
  29. 	       we must avoid any attempt to resume unlocking it */
  30. 	    if (xlock.box == obj)
  31. 		reset_pick();
  32. 	    break;
  33. 	}
  34. 	return res;
  35. }

doorlock[edit]

  1. boolean			/* Door/secret door was hit with spell effect otmp */
  2. doorlock(otmp,x,y)	/* returns true if something happened */
  3. struct obj *otmp;
  4. int x, y;
  5. {
  6. 	register struct rm *door = &levl[x][y];
  7. 	boolean res = TRUE;
  8. 	int loudness = 0;
  9. 	const char *msg = (const char *)0;
  10. 	const char *dustcloud = "A cloud of dust";
  11. 	const char *quickly_dissipates = "quickly dissipates";
  12.  
  13. 	if (door->typ == SDOOR) {
  14. 	    switch (otmp->otyp) {
  15. 	    case WAN_OPENING:
  16. 	    case SPE_KNOCK:
  17. 	    case WAN_STRIKING:
  18. 	    case SPE_FORCE_BOLT:
  19. 		door->typ = DOOR;
  20. 		door->doormask = D_CLOSED | (door->doormask & D_TRAPPED);
  21. 		newsym(x,y);
  22. 		if (cansee(x,y)) pline("A door appears in the wall!");
  23. 		if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK)
  24. 		    return TRUE;
  25. 		break;		/* striking: continue door handling below */
  26. 	    case WAN_LOCKING:
  27. 	    case SPE_WIZARD_LOCK:
  28. 	    default:
  29. 		return FALSE;
  30. 	    }
  31. 	}
  32.  
  33. 	switch(otmp->otyp) {
  34. 	case WAN_LOCKING:
  35. 	case SPE_WIZARD_LOCK:
  36. #ifdef REINCARNATION
  37. 	    if (Is_rogue_level(&u.uz)) {
  38. 	    	boolean vis = cansee(x,y);
  39. 		/* Can't have real locking in Rogue, so just hide doorway */
  40. 		if (vis) pline("%s springs up in the older, more primitive doorway.",
  41. 			dustcloud);
  42. 		else
  43. 			You_hear("a swoosh.");
  44. 		if (obstructed(x,y)) {
  45. 			if (vis) pline_The("cloud %s.",quickly_dissipates);
  46. 			return FALSE;
  47. 		}
  48. 		block_point(x, y);
  49. 		door->typ = SDOOR;
  50. 		if (vis) pline_The("doorway vanishes!");
  51. 		newsym(x,y);
  52. 		return TRUE;
  53. 	    }
  54. #endif
  55. 	    if (obstructed(x,y)) return FALSE;
  56. 	    /* Don't allow doors to close over traps.  This is for pits */
  57. 	    /* & trap doors, but is it ever OK for anything else? */
  58. 	    if (t_at(x,y)) {
  59. 		/* maketrap() clears doormask, so it should be NODOOR */
  60. 		pline(
  61. 		"%s springs up in the doorway, but %s.",
  62. 		dustcloud, quickly_dissipates);
  63. 		return FALSE;
  64. 	    }
  65.  
  66. 	    switch (door->doormask & ~D_TRAPPED) {
  67. 	    case D_CLOSED:
  68. 		msg = "The door locks!";
  69. 		break;
  70. 	    case D_ISOPEN:
  71. 		msg = "The door swings shut, and locks!";
  72. 		break;
  73. 	    case D_BROKEN:
  74. 		msg = "The broken door reassembles and locks!";
  75. 		break;
  76. 	    case D_NODOOR:
  77. 		msg =
  78. 		"A cloud of dust springs up and assembles itself into a door!";
  79. 		break;
  80. 	    default:
  81. 		res = FALSE;
  82. 		break;
  83. 	    }
  84. 	    block_point(x, y);
  85. 	    door->doormask = D_LOCKED | (door->doormask & D_TRAPPED);
  86. 	    newsym(x,y);
  87. 	    break;
  88. 	case WAN_OPENING:
  89. 	case SPE_KNOCK:
  90. 	    if (door->doormask & D_LOCKED) {
  91. 		msg = "The door unlocks!";
  92. 		door->doormask = D_CLOSED | (door->doormask & D_TRAPPED);
  93. 	    } else res = FALSE;
  94. 	    break;
  95. 	case WAN_STRIKING:
  96. 	case SPE_FORCE_BOLT:
  97. 	    if (door->doormask & (D_LOCKED | D_CLOSED)) {
  98. 		if (door->doormask & D_TRAPPED) {
  99. 		    if (MON_AT(x, y))
  100. 			(void) mb_trapped(m_at(x,y));
  101. 		    else if (flags.verbose) {
  102. 			if (cansee(x,y))
  103. 			    pline("KABOOM!!  You see a door explode.");
  104. 			else if (flags.soundok)
  105. 			    You_hear("a distant explosion.");
  106. 		    }
  107. 		    door->doormask = D_NODOOR;
  108. 		    unblock_point(x,y);
  109. 		    newsym(x,y);
  110. 		    loudness = 40;
  111. 		    break;
  112. 		}
  113. 		door->doormask = D_BROKEN;
  114. 		if (flags.verbose) {
  115. 		    if (cansee(x,y))
  116. 			pline_The("door crashes open!");
  117. 		    else if (flags.soundok)
  118. 			You_hear("a crashing sound.");
  119. 		}
  120. 		unblock_point(x,y);
  121. 		newsym(x,y);
  122. 		/* force vision recalc before printing more messages */
  123. 		if (vision_full_recalc) vision_recalc(0);
  124. 		loudness = 20;
  125. 	    } else res = FALSE;
  126. 	    break;
  127. 	default: impossible("magic (%d) attempted on door.", otmp->otyp);
  128. 	    break;
  129. 	}
  130. 	if (msg && cansee(x,y)) pline(msg);
  131. 	if (loudness > 0) {
  132. 	    /* door was destroyed */
  133. 	    wake_nearto(x, y, loudness);
  134. 	    if (*in_rooms(x, y, SHOPBASE)) add_damage(x, y, 0L);
  135. 	}
  136.  
  137. 	if (res && picking_at(x, y)) {
  138. 	    /* maybe unseen monster zaps door you're unlocking */
  139. 	    stop_occupation();
  140. 	    reset_pick();
  141. 	}
  142. 	return res;
  143. }

chest_shatter_msg[edit]

  1. STATIC_OVL void
  2. chest_shatter_msg(otmp)
  3. struct obj *otmp;
  4. {
  5. 	const char *disposition;
  6. 	const char *thing;
  7. 	long save_Blinded;
  8.  
  9. 	if (otmp->oclass == POTION_CLASS) {
  10. 		You("%s %s shatter!", Blind ? "hear" : "see", an(bottlename()));
  11. 		if (!breathless(youmonst.data) || haseyes(youmonst.data))
  12. 			potionbreathe(otmp);
  13. 		return;
  14. 	}
  15. 	/* We have functions for distant and singular names, but not one */
  16. 	/* which does _both_... */
  17. 	save_Blinded = Blinded;
  18. 	Blinded = 1;
  19. 	thing = singular(otmp, xname);
  20. 	Blinded = save_Blinded;
  21. 	switch (objects[otmp->otyp].oc_material) {
  22. 	case PAPER:	disposition = "is torn to shreds";
  23. 		break;
  24. 	case WAX:	disposition = "is crushed";
  25. 		break;
  26. 	case VEGGY:	disposition = "is pulped";
  27. 		break;
  28. 	case FLESH:	disposition = "is mashed";
  29. 		break;
  30. 	case GLASS:	disposition = "shatters";
  31. 		break;
  32. 	case WOOD:	disposition = "splinters to fragments";
  33. 		break;
  34. 	default:	disposition = "is destroyed";
  35. 		break;
  36. 	}
  37. 	pline("%s %s!", An(thing), disposition);
  38. }
  39.  
  40. #endif /* OVLB */
  41.  
  42. /*lock.c*/