Source:NetHack 3.0.0/worn.c
Jump to navigation
Jump to search
Below is the full text to worn.c from the source code of NetHack 3.0.0.
Warning! This is the source code from an old release. For newer releases, see Source code
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. /* SCCS Id: @(#)worn.c 3.0 88/12/23 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. static const char crispy[] = "The flames of Hell burn you to a crisp."; 8. static void set_armor_intrinsic P((struct obj *,boolean)); 9. 10. const struct worn { 11. long w_mask; 12. struct obj **w_obj; 13. } worn[] = { 14. { W_ARM, &uarm }, 15. { W_ARMC, &uarmc }, 16. { W_ARMH, &uarmh }, 17. { W_ARMS, &uarms }, 18. { W_ARMG, &uarmg }, 19. { W_ARMF, &uarmf }, 20. #ifdef SHIRT 21. { W_ARMU, &uarmu }, 22. #endif 23. { W_RINGL, &uleft }, 24. { W_RINGR, &uright }, 25. { W_WEP, &uwep }, 26. { W_AMUL, &uamul }, 27. { W_TOOL, &ublindf }, 28. { W_BALL, &uball }, 29. { W_CHAIN, &uchain }, 30. { 0, 0 } 31. }; 32. 33. void 34. setworn(obj, mask) 35. register struct obj *obj; 36. long mask; 37. { 38. register struct worn *wp; 39. register struct obj *oobj; 40. 41. for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) { 42. oobj = *(wp->w_obj); 43. if(oobj && !(oobj->owornmask & wp->w_mask)) 44. impossible("Setworn: mask = %ld.", wp->w_mask); 45. if(oobj) { 46. oobj->owornmask &= ~wp->w_mask; 47. /* leave as "x = x <op> y", here and below, for broken 48. * compilers */ 49. u.uprops[objects[oobj->otyp].oc_oprop].p_flgs = 50. u.uprops[objects[oobj->otyp].oc_oprop].p_flgs & 51. ~wp->w_mask; 52. set_armor_intrinsic(oobj, 0); 53. } 54. *(wp->w_obj) = obj; 55. if(obj) { 56. obj->owornmask |= wp->w_mask; 57. u.uprops[objects[obj->otyp].oc_oprop].p_flgs = 58. u.uprops[objects[obj->otyp].oc_oprop].p_flgs | 59. wp->w_mask; 60. set_armor_intrinsic(obj, 1); 61. } 62. } 63. /* A kludge to solve the problem of someone gaining fire resistance 64. * only from an item, then entering Hell and removing/unwielding it. 65. * Checking this every time setworn gets called is a bit of an 66. * overkill. --KAA 67. */ 68. if (Inhell && !Fire_resistance) { 69. pline(crispy); 70. killer = "loss of fire protection"; 71. done("burned"); 72. /* If we're here they survived with life saving, so put the 73. * weapon they just unwielded back in their hands... 74. */ 75. if (oobj->otyp != DRAGON_SCALE_MAIL 76. && oobj->otyp != RIN_FIRE_RESISTANCE 77. #ifdef NAMED_ITEMS 78. && !defends(AD_FIRE, oobj) 79. #endif 80. && oobj->corpsenm != PM_RED_DRAGON) 81. impossible("lost FR from a non-FR item?"); 82. setworn(oobj, mask); 83. } 84. } 85. 86. /* called e.g. when obj is destroyed */ 87. void 88. setnotworn(obj) 89. register struct obj *obj; 90. { 91. register struct worn *wp; 92. 93. if (!obj) return; 94. for(wp = worn; wp->w_mask; wp++) 95. if(obj == *(wp->w_obj)) { 96. *(wp->w_obj) = 0; 97. u.uprops[objects[obj->otyp].oc_oprop].p_flgs = 98. u.uprops[objects[obj->otyp].oc_oprop].p_flgs & 99. ~wp->w_mask; 100. obj->owornmask &= ~wp->w_mask; 101. set_armor_intrinsic(obj, 0); 102. } 103. /* See comments above in setworn(). The major difference is the 104. * need to check AMULET_SYM so if someone goes to Hell without 105. * being fire resistant, then dies, when their amulet saves them 106. * and disintegrates this code will not be triggered. --KAA 107. */ 108. if (Inhell && !Fire_resistance && obj->olet != AMULET_SYM) { 109. pline(crispy); 110. killer = "loss of fire protection"; 111. done("burned"); 112. /* Survived with lifesaving, etc...; there's no general way 113. * to undo the setnotworn()--we can't re-wear/wield the 114. * item since it might have been stolen, disintegrated, etc.... 115. */ 116. #if defined(WIZARD) || defined(EXPLORE_MODE) 117. while(1) { 118. /* keep doing it until they finally decide they really 119. * _do_ want to die, since we can't possibly continue 120. * the game from this point... 121. */ 122. #endif 123. You("are still burning and die again..."); 124. done("burned"); 125. #if defined(WIZARD) || defined(EXPLORE_MODE) 126. } 127. #endif 128. } 129. } 130. 131. static void 132. set_armor_intrinsic(obj,on) 133. register struct obj *obj; 134. boolean on; 135. { 136. long *mask; 137. 138. if (obj->otyp != DRAGON_SCALE_MAIL) return; 139. switch(obj->corpsenm) { 140. case PM_GREY_DRAGON: 141. mask = &Antimagic; 142. break; 143. case PM_RED_DRAGON: 144. mask = &HFire_resistance; 145. break; 146. case PM_WHITE_DRAGON: 147. mask = &HCold_resistance; 148. break; 149. case PM_BLUE_DRAGON: 150. mask = &HShock_resistance; 151. break; 152. case PM_GREEN_DRAGON: 153. mask = &HPoison_resistance; 154. break; 155. case PM_ORANGE_DRAGON: 156. mask = &HSleep_resistance; 157. break; 158. case PM_BLACK_DRAGON: 159. mask = &HDisint_resistance; 160. break; 161. case PM_YELLOW_DRAGON: 162. default: 163. return; 164. } 165. if (on) *mask |= WORN_ARMOR; 166. else *mask &= ~WORN_ARMOR; 167. }