abstract
| - Below is the full text to hack.apply.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.apply.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2. 3. #include "hack.h" 4. extern struct monst *bchit(); 5. extern struct obj *addinv(); 6. extern char pl_character[]; 7. 8. doapply() { 9. register struct obj *obj; 10. obj = getobj("(", "use or apply"); 11. if(!obj) return(0); 12. switch(obj->otyp){ 13. case EXPENSIVE_CAMERA: 14. use_camera(obj); break; 15. case ICE_BOX: 16. use_ice_box(obj); break; 17. case MAGIC_WHISTLE: 18. if(pl_character[0] == 'W' || u.ulevel > 9) { 19. use_magic_whistle(obj); 20. break; 21. } 22. /* fall into next case */ 23. case WHISTLE: 24. use_whistle(obj); break; 25. default: 26. pline("Sorry, I don't know how to use that."); 27. return(0); 28. } 29. return(1); 30. } 31. 32. /* ARGSUSED */ 33. use_camera(obj) /* register */ struct obj *obj; { 34. register struct monst *mtmp; 35. if(!getdir()){ 36. flags.move = multi = 0; 37. return; 38. } 39. if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) { 40. if(mtmp->msleep){ 41. mtmp->msleep = 0; 42. pline("The flash awakens the %s.", monnam(mtmp)); 43. } else 44. if(mtmp->data->mlet != 'y') 45. if(mtmp->mcansee || mtmp->mblinded){ 46. register int tmp = dist(mtmp->mx,mtmp->my); 47. register int tmp2; 48. /* if(cansee(mtmp->mx,mtmp->my)) */ 49. pline("%s is blinded by the flash!",Monnam(mtmp)); 50. setmangry(mtmp); 51. if(tmp < 9 && !mtmp->isshk && !rn2(4)) 52. mtmp->mflee = 1; 53. if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0; 54. else { 55. tmp2 = mtmp->mblinded; 56. tmp2 += rnd(1 + 50/tmp); 57. if(tmp2 > 127) tmp2 = 127; 58. mtmp->mblinded = tmp2; 59. mtmp->mcansee = 0; 60. } 61. } 62. } 63. } 64. 65. struct obj *current_ice_box; /* a local variable of use_ice_box, to be 66. used by its local procedures in/ck_ice_box */ 67. in_ice_box(obj) register struct obj *obj; { 68. if(obj == current_ice_box || 69. (Punished && (obj == uball || obj == uchain))){ 70. pline("You must be kidding."); 71. return(0); 72. } 73. if(obj->owornmask & (W_ARMOR | W_RING)) { 74. pline("You cannot refrigerate something you are wearing."); 75. return(0); 76. } 77. if(obj->owt + current_ice_box->owt > 70) { 78. pline("It won't fit."); 79. return(1); /* be careful! */ 80. } 81. if(obj == uwep) { 82. if(uwep->cursed) { 83. pline("Your weapon is welded to your hand!"); 84. return(0); 85. } 86. setuwep((struct obj *) 0); 87. } 88. current_ice_box->owt += obj->owt; 89. freeinv(obj); 90. obj->o_cnt_id = current_ice_box->o_id; 91. obj->nobj = fcobj; 92. fcobj = obj; 93. obj->age = moves - obj->age; /* actual age */ 94. return(1); 95. } 96. 97. ck_ice_box(obj) register struct obj *obj; { 98. return(obj->o_cnt_id == current_ice_box->o_id); 99. } 100. 101. out_ice_box(obj) register struct obj *obj; { 102. register struct obj *otmp; 103. if(obj == fcobj) fcobj = fcobj->nobj; 104. else { 105. for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj) 106. if(!otmp->nobj) panic("out_ice_box"); 107. otmp->nobj = obj->nobj; 108. } 109. current_ice_box->owt -= obj->owt; 110. obj->age = moves - obj->age; /* simulated point of time */ 111. (void) addinv(obj); 112. } 113. 114. use_ice_box(obj) register struct obj *obj; { 115. register int cnt = 0; 116. register struct obj *otmp; 117. current_ice_box = obj; /* for use by in/out_ice_box */ 118. for(otmp = fcobj; otmp; otmp = otmp->nobj) 119. if(otmp->o_cnt_id == obj->o_id) 120. cnt++; 121. if(!cnt) pline("Your ice-box is empty."); 122. else { 123. pline("Do you want to take something out of the ice-box? [yn] "); 124. if(readchar() == 'y') 125. if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0)) 126. return; 127. pline("That was all. Do you wish to put something in? [yn] "); 128. if(readchar() != 'y') return; 129. } 130. /* call getobj: 0: allow cnt; #: allow all types; %: expect food */ 131. otmp = getobj("0#%", "put in"); 132. if(!otmp || !in_ice_box(otmp)) 133. flags.move = multi = 0; 134. } 135. 136. struct monst * 137. bchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; { 138. register struct monst *mtmp = (struct monst *) 0; 139. register int bchx = u.ux, bchy = u.uy; 140. 141. if(sym) Tmp_at(-1, sym); /* open call */ 142. while(range--) { 143. bchx += ddx; 144. bchy += ddy; 145. if(mtmp = m_at(bchx,bchy)) 146. break; 147. if(levl[bchx][bchy].typ < CORR) { 148. bchx -= ddx; 149. bchy -= ddy; 150. break; 151. } 152. if(sym) Tmp_at(bchx, bchy); 153. } 154. if(sym) Tmp_at(-1, -1); 155. return(mtmp); 156. } 157. 158. #include "def.edog.h" 159. /* ARGSUSED */ 160. use_whistle(obj) struct obj *obj; { 161. register struct monst *mtmp = fmon; 162. pline("You produce a high whistling sound."); 163. while(mtmp) { 164. if(dist(mtmp->mx,mtmp->my) < u.ulevel*10) { 165. if(mtmp->msleep) 166. mtmp->msleep = 0; 167. if(mtmp->mtame) 168. EDOG(mtmp)->whistletime = moves; 169. } 170. mtmp = mtmp->nmon; 171. } 172. } 173. 174. /* ARGSUSED */ 175. use_magic_whistle(obj) struct obj *obj; { 176. register struct monst *mtmp = fmon; 177. pline("You produce a strange whistling sound."); 178. while(mtmp) { 179. if(mtmp->mtame) mnexto(mtmp); 180. mtmp = mtmp->nmon; 181. } 182. }
|