hack.do_wear.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /* $NetBSD: hack.do_wear.c,v 1.5 2003/04/02 18:36:36 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.do_wear.c,v 1.5 2003/04/02 18:36:36 jsm Exp $");
  64. #endif /* not lint */
  65. #include "hack.h"
  66. #include "extern.h"
  67. void
  68. off_msg(otmp)
  69. struct obj *otmp;
  70. {
  71. pline("You were wearing %s.", doname(otmp));
  72. }
  73. int
  74. doremarm()
  75. {
  76. struct obj *otmp;
  77. if (!uarm && !uarmh && !uarms && !uarmg) {
  78. pline("Not wearing any armor.");
  79. return (0);
  80. }
  81. otmp = (!uarmh && !uarms && !uarmg) ? uarm :
  82. (!uarms && !uarm && !uarmg) ? uarmh :
  83. (!uarmh && !uarm && !uarmg) ? uarms :
  84. (!uarmh && !uarm && !uarms) ? uarmg :
  85. getobj("[", "take off");
  86. if (!otmp)
  87. return (0);
  88. if (!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
  89. pline("You can't take that off.");
  90. return (0);
  91. }
  92. if (otmp == uarmg && uwep && uwep->cursed) { /* myers@uwmacc */
  93. pline("You seem not able to take off the gloves while holding your weapon.");
  94. return (0);
  95. }
  96. (void) armoroff(otmp);
  97. return (1);
  98. }
  99. int
  100. doremring()
  101. {
  102. if (!uleft && !uright) {
  103. pline("Not wearing any ring.");
  104. return (0);
  105. }
  106. if (!uleft)
  107. return (dorr(uright));
  108. if (!uright)
  109. return (dorr(uleft));
  110. if (uleft && uright)
  111. while (1) {
  112. char answer;
  113. pline("What ring, Right or Left? [ rl?]");
  114. if (strchr(quitchars, (answer = readchar())))
  115. return (0);
  116. switch (answer) {
  117. case 'l':
  118. case 'L':
  119. return (dorr(uleft));
  120. case 'r':
  121. case 'R':
  122. return (dorr(uright));
  123. case '?':
  124. (void) doprring();
  125. /* might look at morc here %% */
  126. }
  127. }
  128. /* NOTREACHED */
  129. return (0);
  130. }
  131. int
  132. dorr(otmp)
  133. struct obj *otmp;
  134. {
  135. if (cursed(otmp))
  136. return (0);
  137. ringoff(otmp);
  138. off_msg(otmp);
  139. return (1);
  140. }
  141. int
  142. cursed(otmp)
  143. struct obj *otmp;
  144. {
  145. if (otmp->cursed) {
  146. pline("You can't. It appears to be cursed.");
  147. return (1);
  148. }
  149. return (0);
  150. }
  151. int
  152. armoroff(otmp)
  153. struct obj *otmp;
  154. {
  155. int delay = -objects[otmp->otyp].oc_delay;
  156. if (cursed(otmp))
  157. return (0);
  158. setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
  159. if (delay) {
  160. nomul(delay);
  161. switch (otmp->otyp) {
  162. case HELMET:
  163. nomovemsg = "You finished taking off your helmet.";
  164. break;
  165. case PAIR_OF_GLOVES:
  166. nomovemsg = "You finished taking off your gloves";
  167. break;
  168. default:
  169. nomovemsg = "You finished taking off your suit.";
  170. }
  171. } else {
  172. off_msg(otmp);
  173. }
  174. return (1);
  175. }
  176. int
  177. doweararm()
  178. {
  179. struct obj *otmp;
  180. int delay;
  181. int err = 0;
  182. long mask = 0;
  183. otmp = getobj("[", "wear");
  184. if (!otmp)
  185. return (0);
  186. if (otmp->owornmask & W_ARMOR) {
  187. pline("You are already wearing that!");
  188. return (0);
  189. }
  190. if (otmp->otyp == HELMET) {
  191. if (uarmh) {
  192. pline("You are already wearing a helmet.");
  193. err++;
  194. } else
  195. mask = W_ARMH;
  196. } else if (otmp->otyp == SHIELD) {
  197. if (uarms)
  198. pline("You are already wearing a shield."), err++;
  199. if (uwep && uwep->otyp == TWO_HANDED_SWORD)
  200. pline("You cannot wear a shield and wield a two-handed sword."), err++;
  201. if (!err)
  202. mask = W_ARMS;
  203. } else if (otmp->otyp == PAIR_OF_GLOVES) {
  204. if (uarmg) {
  205. pline("You are already wearing gloves.");
  206. err++;
  207. } else if (uwep && uwep->cursed) {
  208. pline("You cannot wear gloves over your weapon.");
  209. err++;
  210. } else
  211. mask = W_ARMG;
  212. } else {
  213. if (uarm) {
  214. if (otmp->otyp != ELVEN_CLOAK || uarm2) {
  215. pline("You are already wearing some armor.");
  216. err++;
  217. }
  218. }
  219. if (!err)
  220. mask = W_ARM;
  221. }
  222. if (otmp == uwep && uwep->cursed) {
  223. if (!err++)
  224. pline("%s is welded to your hand.", Doname(uwep));
  225. }
  226. if (err)
  227. return (0);
  228. setworn(otmp, mask);
  229. if (otmp == uwep)
  230. setuwep((struct obj *) 0);
  231. delay = -objects[otmp->otyp].oc_delay;
  232. if (delay) {
  233. nomul(delay);
  234. nomovemsg = "You finished your dressing manoeuvre.";
  235. }
  236. otmp->known = 1;
  237. return (1);
  238. }
  239. int
  240. dowearring()
  241. {
  242. struct obj *otmp;
  243. long mask = 0;
  244. long oldprop;
  245. if (uleft && uright) {
  246. pline("There are no more ring-fingers to fill.");
  247. return (0);
  248. }
  249. otmp = getobj("=", "wear");
  250. if (!otmp)
  251. return (0);
  252. if (otmp->owornmask & W_RING) {
  253. pline("You are already wearing that!");
  254. return (0);
  255. }
  256. if (otmp == uleft || otmp == uright) {
  257. pline("You are already wearing that.");
  258. return (0);
  259. }
  260. if (otmp == uwep && uwep->cursed) {
  261. pline("%s is welded to your hand.", Doname(uwep));
  262. return (0);
  263. }
  264. if (uleft)
  265. mask = RIGHT_RING;
  266. else if (uright)
  267. mask = LEFT_RING;
  268. else
  269. do {
  270. char answer;
  271. pline("What ring-finger, Right or Left? ");
  272. if (strchr(quitchars, (answer = readchar())))
  273. return (0);
  274. switch (answer) {
  275. case 'l':
  276. case 'L':
  277. mask = LEFT_RING;
  278. break;
  279. case 'r':
  280. case 'R':
  281. mask = RIGHT_RING;
  282. break;
  283. }
  284. } while (!mask);
  285. setworn(otmp, mask);
  286. if (otmp == uwep)
  287. setuwep((struct obj *) 0);
  288. oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
  289. u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
  290. switch (otmp->otyp) {
  291. case RIN_LEVITATION:
  292. if (!oldprop)
  293. float_up();
  294. break;
  295. case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
  296. rescham();
  297. break;
  298. case RIN_GAIN_STRENGTH:
  299. u.ustr += otmp->spe;
  300. u.ustrmax += otmp->spe;
  301. if (u.ustr > 118)
  302. u.ustr = 118;
  303. if (u.ustrmax > 118)
  304. u.ustrmax = 118;
  305. flags.botl = 1;
  306. break;
  307. case RIN_INCREASE_DAMAGE:
  308. u.udaminc += otmp->spe;
  309. break;
  310. }
  311. prinv(otmp);
  312. return (1);
  313. }
  314. void
  315. ringoff(obj)
  316. struct obj *obj;
  317. {
  318. long mask;
  319. mask = obj->owornmask & W_RING;
  320. setworn((struct obj *) 0, obj->owornmask);
  321. if (!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
  322. impossible("Strange... I didnt know you had that ring.");
  323. u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
  324. switch (obj->otyp) {
  325. case RIN_FIRE_RESISTANCE:
  326. /* Bad luck if the player is in hell... --jgm */
  327. if (!Fire_resistance && dlevel >= 30) {
  328. pline("The flames of Hell burn you to a crisp.");
  329. killer = "stupidity in hell";
  330. done("burned");
  331. }
  332. break;
  333. case RIN_LEVITATION:
  334. if (!Levitation) { /* no longer floating */
  335. float_down();
  336. }
  337. break;
  338. case RIN_GAIN_STRENGTH:
  339. u.ustr -= obj->spe;
  340. u.ustrmax -= obj->spe;
  341. if (u.ustr > 118)
  342. u.ustr = 118;
  343. if (u.ustrmax > 118)
  344. u.ustrmax = 118;
  345. flags.botl = 1;
  346. break;
  347. case RIN_INCREASE_DAMAGE:
  348. u.udaminc -= obj->spe;
  349. break;
  350. }
  351. }
  352. void
  353. find_ac()
  354. {
  355. int uac = 10;
  356. if (uarm)
  357. uac -= ARM_BONUS(uarm);
  358. if (uarm2)
  359. uac -= ARM_BONUS(uarm2);
  360. if (uarmh)
  361. uac -= ARM_BONUS(uarmh);
  362. if (uarms)
  363. uac -= ARM_BONUS(uarms);
  364. if (uarmg)
  365. uac -= ARM_BONUS(uarmg);
  366. if (uleft && uleft->otyp == RIN_PROTECTION)
  367. uac -= uleft->spe;
  368. if (uright && uright->otyp == RIN_PROTECTION)
  369. uac -= uright->spe;
  370. if (uac != u.uac) {
  371. u.uac = uac;
  372. flags.botl = 1;
  373. }
  374. }
  375. void
  376. glibr()
  377. {
  378. struct obj *otmp;
  379. int xfl = 0;
  380. if (!uarmg)
  381. if (uleft || uright) {
  382. /* Note: at present also cursed rings fall off */
  383. pline("Your %s off your fingers.",
  384. (uleft && uright) ? "rings slip" : "ring slips");
  385. xfl++;
  386. if ((otmp = uleft) != Null(obj)) {
  387. ringoff(uleft);
  388. dropx(otmp);
  389. }
  390. if ((otmp = uright) != Null(obj)) {
  391. ringoff(uright);
  392. dropx(otmp);
  393. }
  394. }
  395. if ((otmp = uwep) != Null(obj)) {
  396. /* Note: at present also cursed weapons fall */
  397. setuwep((struct obj *) 0);
  398. dropx(otmp);
  399. pline("Your weapon %sslips from your hands.",
  400. xfl ? "also " : "");
  401. }
  402. }
  403. struct obj *
  404. some_armor()
  405. {
  406. struct obj *otmph = uarm;
  407. if (uarmh && (!otmph || !rn2(4)))
  408. otmph = uarmh;
  409. if (uarmg && (!otmph || !rn2(4)))
  410. otmph = uarmg;
  411. if (uarms && (!otmph || !rn2(4)))
  412. otmph = uarms;
  413. return (otmph);
  414. }
  415. void
  416. corrode_armor()
  417. {
  418. struct obj *otmph = some_armor();
  419. if (otmph) {
  420. if (otmph->rustfree ||
  421. otmph->otyp == ELVEN_CLOAK ||
  422. otmph->otyp == LEATHER_ARMOR ||
  423. otmph->otyp == STUDDED_LEATHER_ARMOR) {
  424. pline("Your %s not affected!",
  425. aobjnam(otmph, "are"));
  426. return;
  427. }
  428. pline("Your %s!", aobjnam(otmph, "corrode"));
  429. otmph->spe--;
  430. }
  431. }