hack.steal.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* $NetBSD: hack.steal.c,v 1.5 2003/04/02 18:36:40 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
  4. * Amsterdam
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * - Neither the name of the Stichting Centrum voor Wiskunde en
  19. * Informatica, nor the names of its contributors may be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  25. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  26. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  27. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /*
  36. * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. * 1. Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * 2. Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in the
  46. * documentation and/or other materials provided with the distribution.
  47. * 3. The name of the author may not be used to endorse or promote products
  48. * derived from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  51. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  52. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  53. * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  55. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  56. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  57. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  58. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  59. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. */
  61. #include <sys/cdefs.h>
  62. #ifndef lint
  63. __RCSID("$NetBSD: hack.steal.c,v 1.5 2003/04/02 18:36:40 jsm Exp $");
  64. #endif /* not lint */
  65. #include <stdlib.h>
  66. #include "hack.h"
  67. #include "extern.h"
  68. long /* actually returns something that fits in an
  69. * int */
  70. somegold()
  71. {
  72. return ((u.ugold < 100) ? u.ugold :
  73. (u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold));
  74. }
  75. void
  76. stealgold(mtmp)
  77. struct monst *mtmp;
  78. {
  79. struct gold *gold = g_at(u.ux, u.uy);
  80. long tmp;
  81. if (gold && (!u.ugold || gold->amount > u.ugold || !rn2(5))) {
  82. mtmp->mgold += gold->amount;
  83. freegold(gold);
  84. if (Invisible)
  85. newsym(u.ux, u.uy);
  86. pline("%s quickly snatches some gold from between your feet!",
  87. Monnam(mtmp));
  88. if (!u.ugold || !rn2(5)) {
  89. rloc(mtmp);
  90. mtmp->mflee = 1;
  91. }
  92. } else if (u.ugold) {
  93. u.ugold -= (tmp = somegold());
  94. pline("Your purse feels lighter.");
  95. mtmp->mgold += tmp;
  96. rloc(mtmp);
  97. mtmp->mflee = 1;
  98. flags.botl = 1;
  99. }
  100. }
  101. /* steal armor after he finishes taking it off */
  102. unsigned stealoid; /* object to be stolen */
  103. unsigned stealmid; /* monster doing the stealing */
  104. int
  105. stealarm()
  106. {
  107. struct monst *mtmp;
  108. struct obj *otmp;
  109. for (otmp = invent; otmp; otmp = otmp->nobj)
  110. if (otmp->o_id == stealoid) {
  111. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  112. if (mtmp->m_id == stealmid) {
  113. if (dist(mtmp->mx, mtmp->my) < 3) {
  114. freeinv(otmp);
  115. pline("%s steals %s!", Monnam(mtmp), doname(otmp));
  116. mpickobj(mtmp, otmp);
  117. mtmp->mflee = 1;
  118. rloc(mtmp);
  119. }
  120. break;
  121. }
  122. break;
  123. }
  124. stealoid = 0;
  125. return 0;
  126. }
  127. /* returns 1 when something was stolen */
  128. /* (or at least, when N should flee now) */
  129. /* avoid stealing the object stealoid */
  130. int
  131. steal(mtmp)
  132. struct monst *mtmp;
  133. {
  134. struct obj *otmp;
  135. int tmp;
  136. int named = 0;
  137. if (!invent) {
  138. if (Blind)
  139. pline("Somebody tries to rob you, but finds nothing to steal.");
  140. else
  141. pline("%s tries to rob you, but she finds nothing to steal!",
  142. Monnam(mtmp));
  143. return (1); /* let her flee */
  144. }
  145. tmp = 0;
  146. for (otmp = invent; otmp; otmp = otmp->nobj)
  147. if (otmp != uarm2)
  148. tmp += ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1);
  149. tmp = rn2(tmp);
  150. for (otmp = invent; otmp; otmp = otmp->nobj)
  151. if (otmp != uarm2)
  152. if ((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1))
  153. < 0)
  154. break;
  155. if (!otmp) {
  156. impossible("Steal fails!");
  157. return (0);
  158. }
  159. if (otmp->o_id == stealoid)
  160. return (0);
  161. if ((otmp->owornmask & (W_ARMOR | W_RING))) {
  162. switch (otmp->olet) {
  163. case RING_SYM:
  164. ringoff(otmp);
  165. break;
  166. case ARMOR_SYM:
  167. if (multi < 0 || otmp == uarms) {
  168. setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
  169. break;
  170. } {
  171. int curssv = otmp->cursed;
  172. otmp->cursed = 0;
  173. stop_occupation();
  174. pline("%s seduces you and %s off your %s.",
  175. Amonnam(mtmp, Blind ? "gentle" : "beautiful"),
  176. otmp->cursed ? "helps you to take"
  177. : "you start taking",
  178. (otmp == uarmg) ? "gloves" :
  179. (otmp == uarmh) ? "helmet" : "armor");
  180. named++;
  181. (void) armoroff(otmp);
  182. otmp->cursed = curssv;
  183. if (multi < 0) {
  184. /*
  185. multi = 0;
  186. nomovemsg = 0;
  187. afternmv = 0;
  188. */
  189. stealoid = otmp->o_id;
  190. stealmid = mtmp->m_id;
  191. afternmv = stealarm;
  192. return (0);
  193. }
  194. break;
  195. }
  196. default:
  197. impossible("Tried to steal a strange worn thing.");
  198. }
  199. } else if (otmp == uwep)
  200. setuwep((struct obj *) 0);
  201. if (otmp->olet == CHAIN_SYM) {
  202. impossible("How come you are carrying that chain?");
  203. }
  204. if (Punished && otmp == uball) {
  205. Punished = 0;
  206. freeobj(uchain);
  207. free((char *) uchain);
  208. uchain = (struct obj *) 0;
  209. uball->spe = 0;
  210. uball = (struct obj *) 0; /* superfluous */
  211. }
  212. freeinv(otmp);
  213. pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
  214. mpickobj(mtmp, otmp);
  215. return ((multi < 0) ? 0 : 1);
  216. }
  217. void
  218. mpickobj(mtmp, otmp)
  219. struct monst *mtmp;
  220. struct obj *otmp;
  221. {
  222. otmp->nobj = mtmp->minvent;
  223. mtmp->minvent = otmp;
  224. }
  225. int
  226. stealamulet(mtmp)
  227. struct monst *mtmp;
  228. {
  229. struct obj *otmp;
  230. for (otmp = invent; otmp; otmp = otmp->nobj) {
  231. if (otmp->olet == AMULET_SYM) {
  232. /* might be an imitation one */
  233. if (otmp == uwep)
  234. setuwep((struct obj *) 0);
  235. freeinv(otmp);
  236. mpickobj(mtmp, otmp);
  237. pline("%s stole %s!", Monnam(mtmp), doname(otmp));
  238. return (1);
  239. }
  240. }
  241. return (0);
  242. }
  243. /* release the objects the killed animal has stolen */
  244. void
  245. relobj(mtmp, show)
  246. struct monst *mtmp;
  247. int show;
  248. {
  249. struct obj *otmp, *otmp2;
  250. for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
  251. otmp->ox = mtmp->mx;
  252. otmp->oy = mtmp->my;
  253. otmp2 = otmp->nobj;
  254. otmp->nobj = fobj;
  255. fobj = otmp;
  256. stackobj(fobj);
  257. if (show & cansee(mtmp->mx, mtmp->my))
  258. atl(otmp->ox, otmp->oy, otmp->olet);
  259. }
  260. mtmp->minvent = (struct obj *) 0;
  261. if (mtmp->mgold || mtmp->data->mlet == 'L') {
  262. long tmp;
  263. tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold;
  264. mkgold((long) (tmp + d(dlevel, 30)), mtmp->mx, mtmp->my);
  265. if (show & cansee(mtmp->mx, mtmp->my))
  266. atl(mtmp->mx, mtmp->my, '$');
  267. }
  268. }