subr.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /* $NetBSD: subr.c,v 1.10 2003/08/07 09:36:51 agc Exp $ */
  2. /*-
  3. * Copyright (c) 1991, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * The game adventure was originally written in Fortran by Will Crowther
  7. * and Don Woods. It was later translated to C and enhanced by Jim
  8. * Gillogly. This code is derived from software contributed to Berkeley
  9. * by Jim Gillogly at The Rand Corporation.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. */
  35. #include <sys/cdefs.h>
  36. #ifndef lint
  37. #if 0
  38. static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
  39. #else
  40. __RCSID("$NetBSD: subr.c,v 1.10 2003/08/07 09:36:51 agc Exp $");
  41. #endif
  42. #endif /* not lint */
  43. /* Re-coding of advent in C: subroutines from main */
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include "hdr.h"
  47. #include "extern.h"
  48. /* Statement functions */
  49. int
  50. toting(objj)
  51. int objj;
  52. {
  53. if (place[objj] == -1)
  54. return (TRUE);
  55. else
  56. return (FALSE);
  57. }
  58. int
  59. here(objj)
  60. int objj;
  61. {
  62. if (place[objj] == loc || toting(objj))
  63. return (TRUE);
  64. else
  65. return (FALSE);
  66. }
  67. int
  68. at(objj)
  69. int objj;
  70. {
  71. if (place[objj] == loc || fixed[objj] == loc)
  72. return (TRUE);
  73. else
  74. return (FALSE);
  75. }
  76. int
  77. liq2(pbotl)
  78. int pbotl;
  79. {
  80. return ((1 - pbotl) * water + (pbotl / 2) * (water + oil));
  81. }
  82. int
  83. liq()
  84. {
  85. int i;
  86. i = prop[bottle];
  87. if (i > -1 - i)
  88. return (liq2(i));
  89. else
  90. return (liq2(-1 - i));
  91. }
  92. int
  93. liqloc(locc) /* may want to clean this one up a bit */
  94. int locc;
  95. {
  96. int i, j, l;
  97. i = cond[locc] / 2;
  98. j = ((i * 2) % 8) - 5;
  99. l = cond[locc] / 4;
  100. l = l % 2;
  101. return (liq2(j * l + 1));
  102. }
  103. int
  104. bitset(l, n)
  105. int l, n;
  106. {
  107. if (cond[l] & setbit[n])
  108. return (TRUE);
  109. return (FALSE);
  110. }
  111. int
  112. forced(locc)
  113. int locc;
  114. {
  115. if (cond[locc] == 2)
  116. return (TRUE);
  117. return (FALSE);
  118. }
  119. int
  120. dark()
  121. {
  122. if ((cond[loc] % 2) == 0 && (prop[lamp] == 0 || !here(lamp)))
  123. return (TRUE);
  124. return (FALSE);
  125. }
  126. int
  127. pct(n)
  128. int n;
  129. {
  130. if (ran(100) < n)
  131. return (TRUE);
  132. return (FALSE);
  133. }
  134. int
  135. fdwarf()
  136. { /* 71 */
  137. int i, j;
  138. struct travlist *kk;
  139. if (newloc != loc && !forced(loc) && !bitset(loc, 3)) {
  140. for (i = 1; i <= 5; i++) {
  141. if (odloc[i] != newloc || !dseen[i])
  142. continue;
  143. newloc = loc;
  144. rspeak(2);
  145. break;
  146. }
  147. }
  148. loc = newloc; /* 74 */
  149. if (loc == 0 || forced(loc) || bitset(newloc, 3))
  150. return (2000);
  151. if (dflag == 0) {
  152. if (loc >= 15)
  153. dflag = 1;
  154. return (2000);
  155. }
  156. if (dflag == 1) { /* 6000 */
  157. if (loc < 15 || pct(95))
  158. return (2000);
  159. dflag = 2;
  160. for (i = 1; i <= 2; i++) {
  161. j = 1 + ran(5);
  162. if (pct(50) && saved == -1)
  163. dloc[j] = 0; /* 6001 */
  164. }
  165. for (i = 1; i <= 5; i++) {
  166. if (dloc[i] == loc)
  167. dloc[i] = daltlc;
  168. odloc[i] = dloc[i]; /* 6002 */
  169. }
  170. rspeak(3);
  171. drop(axe, loc);
  172. return (2000);
  173. }
  174. dtotal = attack = stick = 0; /* 6010 */
  175. for (i = 1; i <= 6; i++) { /* loop to 6030 */
  176. if (dloc[i] == 0)
  177. continue;
  178. j = 1;
  179. for (kk = travel[dloc[i]]; kk != 0; kk = kk->next) {
  180. newloc = kk->tloc;
  181. if (newloc > 300 || newloc < 15 || newloc == odloc[i]
  182. || (j > 1 && newloc == tk[j - 1]) || j >= 20
  183. || newloc == dloc[i] || forced(newloc)
  184. || (i == 6 && bitset(newloc, 3))
  185. || kk->conditions == 100)
  186. continue;
  187. tk[j++] = newloc;
  188. }
  189. tk[j] = odloc[i]; /* 6016 */
  190. if (j >= 2)
  191. j--;
  192. j = 1 + ran(j);
  193. odloc[i] = dloc[i];
  194. dloc[i] = tk[j];
  195. dseen[i] = (dseen[i] && loc >= 15) || (dloc[i] == loc || odloc[i] == loc);
  196. if (!dseen[i])
  197. continue; /* i.e. goto 6030 */
  198. dloc[i] = loc;
  199. if (i == 6) { /* pirate's spotted him */
  200. if (loc == chloc || prop[chest] >= 0)
  201. continue;
  202. k = 0;
  203. for (j = 50; j <= maxtrs; j++) { /* loop to 6020 */
  204. if (j == pyram && (loc == plac[pyram]
  205. || loc == plac[emrald]))
  206. goto l6020;
  207. if (toting(j))
  208. goto l6022;
  209. l6020: if (here(j))
  210. k = 1;
  211. } /* 6020 */
  212. if (tally == tally2 + 1 && k == 0 && place[chest] == 0
  213. && here(lamp) && prop[lamp] == 1)
  214. goto l6025;
  215. if (odloc[6] != dloc[6] && pct(20))
  216. rspeak(127);
  217. continue; /* to 6030 */
  218. l6022: rspeak(128);
  219. if (place[messag] == 0)
  220. move(chest, chloc);
  221. move(messag, chloc2);
  222. for (j = 50; j <= maxtrs; j++) { /* loop to 6023 */
  223. if (j == pyram && (loc == plac[pyram]
  224. || loc == plac[emrald]))
  225. continue;
  226. if (at(j) && fixed[j] == 0)
  227. carry(j, loc);
  228. if (toting(j))
  229. drop(j, chloc);
  230. }
  231. l6024: dloc[6] = odloc[6] = chloc;
  232. dseen[6] = FALSE;
  233. continue;
  234. l6025: rspeak(186);
  235. move(chest, chloc);
  236. move(messag, chloc2);
  237. goto l6024;
  238. }
  239. dtotal++; /* 6027 */
  240. if (odloc[i] != dloc[i])
  241. continue;
  242. attack++;
  243. if (knfloc >= 0)
  244. knfloc = loc;
  245. if (ran(1000) < 95 * (dflag - 2))
  246. stick++;
  247. } /* 6030 */
  248. if (dtotal == 0)
  249. return (2000);
  250. if (dtotal != 1) {
  251. printf("There are %d threatening little dwarves ", dtotal);
  252. printf("in the room with you.\n");
  253. } else
  254. rspeak(4);
  255. if (attack == 0)
  256. return (2000);
  257. if (dflag == 2)
  258. dflag = 3;
  259. if (saved != -1)
  260. dflag = 20;
  261. if (attack != 1) {
  262. printf("%d of them throw knives at you!\n", attack);
  263. k = 6;
  264. l82: if (stick <= 1) { /* 82 */
  265. rspeak(k + stick);
  266. if (stick == 0)
  267. return (2000);
  268. } else
  269. printf("%d of them get you!\n", stick); /* 83 */
  270. oldlc2 = loc;
  271. return (99);
  272. }
  273. rspeak(5);
  274. k = 52;
  275. goto l82;
  276. }
  277. int
  278. march()
  279. { /* label 8 */
  280. int ll1, ll2;
  281. if ((tkk = travel[newloc = loc]) == 0)
  282. bug(26);
  283. if (k == null)
  284. return (2);
  285. if (k == cave) { /* 40 */
  286. if (loc < 8)
  287. rspeak(57);
  288. if (loc >= 8)
  289. rspeak(58);
  290. return (2);
  291. }
  292. if (k == look) { /* 30 */
  293. if (detail++ < 3)
  294. rspeak(15);
  295. wzdark = FALSE;
  296. abb[loc] = 0;
  297. return (2);
  298. }
  299. if (k == back) { /* 20 */
  300. switch (mback()) {
  301. case 2:
  302. return (2);
  303. case 9:
  304. goto l9;
  305. default:
  306. bug(100);
  307. }
  308. }
  309. oldlc2 = oldloc;
  310. oldloc = loc;
  311. l9:
  312. for (; tkk != 0; tkk = tkk->next)
  313. if (tkk->tverb == 1 || tkk->tverb == k)
  314. break;
  315. if (tkk == 0) {
  316. badmove();
  317. return (2);
  318. }
  319. l11: ll1 = tkk->conditions; /* 11 */
  320. ll2 = tkk->tloc;
  321. newloc = ll1; /* newloc=conditions */
  322. k = newloc % 100; /* k used for prob */
  323. if (newloc <= 300) {
  324. if (newloc <= 100) { /* 13 */
  325. if (newloc != 0 && !pct(newloc))
  326. goto l12; /* 14 */
  327. l16: newloc = ll2; /* newloc=location */
  328. if (newloc <= 300)
  329. return (2);
  330. if (newloc <= 500)
  331. switch (specials()) { /* to 30000 */
  332. case 2:
  333. return (2);
  334. case 12:
  335. goto l12;
  336. case 99:
  337. return (99);
  338. default:
  339. bug(101);
  340. }
  341. rspeak(newloc - 500);
  342. newloc = loc;
  343. return (2);
  344. }
  345. if (toting(k) || (newloc > 200 && at(k)))
  346. goto l16;
  347. goto l12;
  348. }
  349. if (prop[k] != (newloc / 100) - 3)
  350. goto l16; /* newloc still conditions */
  351. l12: /* alternative to probability move */
  352. for (; tkk != 0; tkk = tkk->next)
  353. if (tkk->tloc != ll2 || tkk->conditions != ll1)
  354. break;
  355. if (tkk == 0)
  356. bug(25);
  357. goto l11;
  358. }
  359. int
  360. mback()
  361. { /* 20 */
  362. struct travlist *tk2, *j;
  363. int ll;
  364. if (forced(k = oldloc))
  365. k = oldlc2; /* k=location */
  366. oldlc2 = oldloc;
  367. oldloc = loc;
  368. tk2 = 0;
  369. if (k == loc) {
  370. rspeak(91);
  371. return (2);
  372. }
  373. for (; tkk != 0; tkk = tkk->next) { /* 21 */
  374. ll = tkk->tloc;
  375. if (ll == k) {
  376. k = tkk->tverb; /* k back to verb */
  377. tkk = travel[loc];
  378. return (9);
  379. }
  380. if (ll <= 300) {
  381. j = travel[loc];
  382. if (forced(ll) && k == j->tloc)
  383. tk2 = tkk;
  384. }
  385. }
  386. tkk = tk2; /* 23 */
  387. if (tkk != 0) {
  388. k = tkk->tverb;
  389. tkk = travel[loc];
  390. return (9);
  391. }
  392. rspeak(140);
  393. return (2);
  394. }
  395. int
  396. specials()
  397. { /* 30000 */
  398. switch (newloc -= 300) {
  399. case 1: /* 30100 */
  400. newloc = 99 + 100 - loc;
  401. if (holdng == 0 || (holdng == 1 && toting(emrald)))
  402. return (2);
  403. newloc = loc;
  404. rspeak(117);
  405. return (2);
  406. case 2: /* 30200 */
  407. drop(emrald, loc);
  408. return (12);
  409. case 3: /* to 30300 */
  410. return (trbridge());
  411. default:
  412. bug(29);
  413. }
  414. }
  415. int
  416. trbridge()
  417. { /* 30300 */
  418. if (prop[troll] == 1) {
  419. pspeak(troll, 1);
  420. prop[troll] = 0;
  421. move(troll2, 0);
  422. move(troll2 + 100, 0);
  423. move(troll, plac[troll]);
  424. move(troll + 100, fixd[troll]);
  425. juggle(chasm);
  426. newloc = loc;
  427. return (2);
  428. }
  429. newloc = plac[troll] + fixd[troll] - loc; /* 30310 */
  430. if (prop[troll] == 0)
  431. prop[troll] = 1;
  432. if (!toting(bear))
  433. return (2);
  434. rspeak(162);
  435. prop[chasm] = 1;
  436. prop[troll] = 2;
  437. drop(bear, newloc);
  438. fixed[bear] = -1;
  439. prop[bear] = 3;
  440. if (prop[spices] < 0)
  441. tally2++;
  442. oldlc2 = newloc;
  443. return (99);
  444. }
  445. void
  446. badmove()
  447. { /* 20 */
  448. spk = 12;
  449. if (k >= 43 && k <= 50)
  450. spk = 9;
  451. if (k == 29 || k == 30)
  452. spk = 9;
  453. if (k == 7 || k == 36 || k == 37)
  454. spk = 10;
  455. if (k == 11 || k == 19)
  456. spk = 11;
  457. if (verb == find || verb == invent)
  458. spk = 59;
  459. if (k == 62 || k == 65)
  460. spk = 42;
  461. if (k == 17)
  462. spk = 80;
  463. rspeak(spk);
  464. }
  465. void
  466. bug(n)
  467. int n;
  468. {
  469. printf("Please tell jim@rand.org that fatal bug %d happened.\n", n);
  470. exit(1);
  471. }
  472. void
  473. checkhints()
  474. { /* 2600 &c */
  475. int hint;
  476. for (hint = 4; hint <= hntmax; hint++) {
  477. if (hinted[hint])
  478. continue;
  479. if (!bitset(loc, hint))
  480. hintlc[hint] = -1;
  481. hintlc[hint]++;
  482. if (hintlc[hint] < hints[hint][1])
  483. continue;
  484. switch (hint) {
  485. case 4: /* 40400 */
  486. if (prop[grate] == 0 && !here(keys))
  487. goto l40010;
  488. goto l40020;
  489. case 5: /* 40500 */
  490. if (here(bird) && toting(rod) && obj == bird)
  491. goto l40010;
  492. continue; /* i.e. goto l40030 */
  493. case 6: /* 40600 */
  494. if (here(snake) && !here(bird))
  495. goto l40010;
  496. goto l40020;
  497. case 7: /* 40700 */
  498. if (atloc[loc] == 0 && atloc[oldloc] == 0
  499. && atloc[oldlc2] == 0 && holdng > 1)
  500. goto l40010;
  501. goto l40020;
  502. case 8: /* 40800 */
  503. if (prop[emrald] != -1 && prop[pyram] == -1)
  504. goto l40010;
  505. goto l40020;
  506. case 9:
  507. goto l40010; /* 40900 */
  508. default:
  509. bug(27);
  510. }
  511. l40010: hintlc[hint] = 0;
  512. if (!yes(hints[hint][3], 0, 54))
  513. continue;
  514. printf("I am prepared to give you a hint, but it will ");
  515. printf("cost you %d points.\n", hints[hint][2]);
  516. hinted[hint] = yes(175, hints[hint][4], 54);
  517. l40020: hintlc[hint] = 0;
  518. }
  519. }
  520. int
  521. trsay()
  522. { /* 9030 */
  523. int i;
  524. if (*wd2 != 0)
  525. copystr(wd2, wd1);
  526. i = vocab(wd1, -1, 0);
  527. if (i == 62 || i == 65 || i == 71 || i == 2025) {
  528. *wd2 = 0;
  529. obj = 0;
  530. return (2630);
  531. }
  532. printf("\nOkay, \"%s\".\n", wd2);
  533. return (2012);
  534. }
  535. int
  536. trtake()
  537. { /* 9010 */
  538. if (toting(obj))
  539. return (2011); /* 9010 */
  540. spk = 25;
  541. if (obj == plant && prop[plant] <= 0)
  542. spk = 115;
  543. if (obj == bear && prop[bear] == 1)
  544. spk = 169;
  545. if (obj == chain && prop[bear] != 0)
  546. spk = 170;
  547. if (fixed[obj] != 0)
  548. return (2011);
  549. if (obj == water || obj == oil) {
  550. if (here(bottle) && liq() == obj) {
  551. obj = bottle;
  552. goto l9017;
  553. }
  554. obj = bottle;
  555. if (toting(bottle) && prop[bottle] == 1)
  556. return (9220);
  557. if (prop[bottle] != 1)
  558. spk = 105;
  559. if (!toting(bottle))
  560. spk = 104;
  561. return (2011);
  562. }
  563. l9017: if (holdng >= 7) {
  564. rspeak(92);
  565. return (2012);
  566. }
  567. if (obj == bird) {
  568. if (prop[bird] != 0)
  569. goto l9014;
  570. if (toting(rod)) {
  571. rspeak(26);
  572. return (2012);
  573. }
  574. if (!toting(cage)) { /* 9013 */
  575. rspeak(27);
  576. return (2012);
  577. }
  578. prop[bird] = 1; /* 9015 */
  579. }
  580. l9014: if ((obj == bird || obj == cage) && prop[bird] != 0)
  581. carry(bird + cage - obj, loc);
  582. carry(obj, loc);
  583. k = liq();
  584. if (obj == bottle && k != 0)
  585. place[k] = -1;
  586. return (2009);
  587. }
  588. int
  589. dropper()
  590. { /* 9021 */
  591. k = liq();
  592. if (k == obj)
  593. obj = bottle;
  594. if (obj == bottle && k != 0)
  595. place[k] = 0;
  596. if (obj == cage && prop[bird] != 0)
  597. drop(bird, loc);
  598. if (obj == bird)
  599. prop[bird] = 0;
  600. drop(obj, loc);
  601. return (2012);
  602. }
  603. int
  604. trdrop()
  605. { /* 9020 */
  606. if (toting(rod2) && obj == rod && !toting(rod))
  607. obj = rod2;
  608. if (!toting(obj))
  609. return (2011);
  610. if (obj == bird && here(snake)) {
  611. rspeak(30);
  612. if (closed)
  613. return (19000);
  614. dstroy(snake);
  615. prop[snake] = 1;
  616. return (dropper());
  617. }
  618. if (obj == coins && here(vend)) { /* 9024 */
  619. dstroy(coins);
  620. drop(batter, loc);
  621. pspeak(batter, 0);
  622. return (2012);
  623. }
  624. if (obj == bird && at(dragon) && prop[dragon] == 0) { /* 9025 */
  625. rspeak(154);
  626. dstroy(bird);
  627. prop[bird] = 0;
  628. if (place[snake] == plac[snake])
  629. tally2--;
  630. return (2012);
  631. }
  632. if (obj == bear && at(troll)) { /* 9026 */
  633. rspeak(163);
  634. move(troll, 0);
  635. move(troll + 100, 0);
  636. move(troll2, plac[troll]);
  637. move(troll2 + 100, fixd[troll]);
  638. juggle(chasm);
  639. prop[troll] = 2;
  640. return (dropper());
  641. }
  642. if (obj != vase || loc == plac[pillow]) { /* 9027 */
  643. rspeak(54);
  644. return (dropper());
  645. }
  646. prop[vase] = 2; /* 9028 */
  647. if (at(pillow))
  648. prop[vase] = 0;
  649. pspeak(vase, prop[vase] + 1);
  650. if (prop[vase] != 0)
  651. fixed[vase] = -1;
  652. return (dropper());
  653. }
  654. int
  655. tropen()
  656. { /* 9040 */
  657. if (obj == clam || obj == oyster) {
  658. k = 0; /* 9046 */
  659. if (obj == oyster)
  660. k = 1;
  661. spk = 124 + k;
  662. if (toting(obj))
  663. spk = 120 + k;
  664. if (!toting(tridnt))
  665. spk = 122 + k;
  666. if (verb == lock)
  667. spk = 61;
  668. if (spk != 124)
  669. return (2011);
  670. dstroy(clam);
  671. drop(oyster, loc);
  672. drop(pearl, 105);
  673. return (2011);
  674. }
  675. if (obj == door)
  676. spk = 111;
  677. if (obj == door && prop[door] == 1)
  678. spk = 54;
  679. if (obj == cage)
  680. spk = 32;
  681. if (obj == keys)
  682. spk = 55;
  683. if (obj == grate || obj == chain)
  684. spk = 31;
  685. if (spk != 31 || !here(keys))
  686. return (2011);
  687. if (obj == chain) {
  688. if (verb == lock) {
  689. spk = 172; /* 9049: lock */
  690. if (prop[chain] != 0)
  691. spk = 34;
  692. if (loc != plac[chain])
  693. spk = 173;
  694. if (spk != 172)
  695. return (2011);
  696. prop[chain] = 2;
  697. if (toting(chain))
  698. drop(chain, loc);
  699. fixed[chain] = -1;
  700. return (2011);
  701. }
  702. spk = 171;
  703. if (prop[bear] == 0)
  704. spk = 41;
  705. if (prop[chain] == 0)
  706. spk = 37;
  707. if (spk != 171)
  708. return (2011);
  709. prop[chain] = 0;
  710. fixed[chain] = 0;
  711. if (prop[bear] != 3)
  712. prop[bear] = 2;
  713. fixed[bear] = 2 - prop[bear];
  714. return (2011);
  715. }
  716. if (closng) {
  717. k = 130;
  718. if (!panic)
  719. clock2 = 15;
  720. panic = TRUE;
  721. return (2010);
  722. }
  723. k = 34 + prop[grate]; /* 9043 */
  724. prop[grate] = 1;
  725. if (verb == lock)
  726. prop[grate] = 0;
  727. k = k + 2 * prop[grate];
  728. return (2010);
  729. }
  730. int
  731. trkill()
  732. { /* 9120 */
  733. int i;
  734. for (i = 1; i <= 5; i++)
  735. if (dloc[i] == loc && dflag >= 2)
  736. break;
  737. if (i == 6)
  738. i = 0;
  739. if (obj == 0) { /* 9122 */
  740. if (i != 0)
  741. obj = dwarf;
  742. if (here(snake))
  743. obj = obj * 100 + snake;
  744. if (at(dragon) && prop[dragon] == 0)
  745. obj = obj * 100 + dragon;
  746. if (at(troll))
  747. obj = obj * 100 + troll;
  748. if (here(bear) && prop[bear] == 0)
  749. obj = obj * 100 + bear;
  750. if (obj > 100)
  751. return (8000);
  752. if (obj == 0) {
  753. if (here(bird) && verb != throw)
  754. obj = bird;
  755. if (here(clam) || here(oyster))
  756. obj = 100 * obj + clam;
  757. if (obj > 100)
  758. return (8000);
  759. }
  760. }
  761. if (obj == bird) { /* 9124 */
  762. spk = 137;
  763. if (closed)
  764. return (2011);
  765. dstroy(bird);
  766. prop[bird] = 0;
  767. if (place[snake] == plac[snake])
  768. tally2++;
  769. spk = 45;
  770. }
  771. if (obj == 0)
  772. spk = 44; /* 9125 */
  773. if (obj == clam || obj == oyster)
  774. spk = 150;
  775. if (obj == snake)
  776. spk = 46;
  777. if (obj == dwarf)
  778. spk = 49;
  779. if (obj == dwarf && closed)
  780. return (19000);
  781. if (obj == dragon)
  782. spk = 147;
  783. if (obj == troll)
  784. spk = 157;
  785. if (obj == bear)
  786. spk = 165 + (prop[bear] + 1) / 2;
  787. if (obj != dragon || prop[dragon] != 0)
  788. return (2011);
  789. rspeak(49);
  790. verb = 0;
  791. obj = 0;
  792. getin(&wd1, &wd2);
  793. if (!weq(wd1, "y") && !weq(wd1, "yes"))
  794. return (2608);
  795. pspeak(dragon, 1);
  796. prop[dragon] = 2;
  797. prop[rug] = 0;
  798. k = (plac[dragon] + fixd[dragon]) / 2;
  799. move(dragon + 100, -1);
  800. move(rug + 100, 0);
  801. move(dragon, k);
  802. move(rug, k);
  803. for (obj = 1; obj <= 100; obj++)
  804. if (place[obj] == plac[dragon] || place[obj] == fixd[dragon])
  805. move(obj, k);
  806. loc = k;
  807. k = null;
  808. return (8);
  809. }
  810. int
  811. trtoss()
  812. { /* 9170: throw */
  813. int i;
  814. if (toting(rod2) && obj == rod && !toting(rod))
  815. obj = rod2;
  816. if (!toting(obj))
  817. return (2011);
  818. if (obj >= 50 && obj <= maxtrs && at(troll)) {
  819. spk = 159; /* 9178 */
  820. drop(obj, 0);
  821. move(troll, 0);
  822. move(troll + 100, 0);
  823. drop(troll2, plac[troll]);
  824. drop(troll2 + 100, fixd[troll]);
  825. juggle(chasm);
  826. return (2011);
  827. }
  828. if (obj == food && here(bear)) {
  829. obj = bear; /* 9177 */
  830. return (9210);
  831. }
  832. if (obj != axe)
  833. return (9020);
  834. for (i = 1; i <= 5; i++) {
  835. if (dloc[i] == loc) {
  836. spk = 48; /* 9172 */
  837. if (ran(3) == 0 || saved != -1)
  838. l9175: {
  839. rspeak(spk);
  840. drop(axe, loc);
  841. k = null;
  842. return (8);
  843. }
  844. dseen[i] = FALSE;
  845. dloc[i] = 0;
  846. spk = 47;
  847. dkill++;
  848. if (dkill == 1)
  849. spk = 149;
  850. goto l9175;
  851. }
  852. }
  853. spk = 152;
  854. if (at(dragon) && prop[dragon] == 0)
  855. goto l9175;
  856. spk = 158;
  857. if (at(troll))
  858. goto l9175;
  859. if (here(bear) && prop[bear] == 0) {
  860. spk = 164;
  861. drop(axe, loc);
  862. fixed[axe] = -1;
  863. prop[axe] = 1;
  864. juggle(bear);
  865. return (2011);
  866. }
  867. obj = 0;
  868. return (9120);
  869. }
  870. int
  871. trfeed()
  872. { /* 9210 */
  873. if (obj == bird) {
  874. spk = 100;
  875. return (2011);
  876. }
  877. if (obj == snake || obj == dragon || obj == troll) {
  878. spk = 102;
  879. if (obj == dragon && prop[dragon] != 0)
  880. spk = 110;
  881. if (obj == troll)
  882. spk = 182;
  883. if (obj != snake || closed || !here(bird))
  884. return (2011);
  885. spk = 101;
  886. dstroy(bird);
  887. prop[bird] = 0;
  888. tally2++;
  889. return (2011);
  890. }
  891. if (obj == dwarf) {
  892. if (!here(food))
  893. return (2011);
  894. spk = 103;
  895. dflag++;
  896. return (2011);
  897. }
  898. if (obj == bear) {
  899. if (prop[bear] == 0)
  900. spk = 102;
  901. if (prop[bear] == 3)
  902. spk = 110;
  903. if (!here(food))
  904. return (2011);
  905. dstroy(food);
  906. prop[bear] = 1;
  907. fixed[axe] = 0;
  908. prop[axe] = 0;
  909. spk = 168;
  910. return (2011);
  911. }
  912. spk = 14;
  913. return (2011);
  914. }
  915. int
  916. trfill()
  917. { /* 9220 */
  918. if (obj == vase) {
  919. spk = 29;
  920. if (liqloc(loc) == 0)
  921. spk = 144;
  922. if (liqloc(loc) == 0 || !toting(vase))
  923. return (2011);
  924. rspeak(145);
  925. prop[vase] = 2;
  926. fixed[vase] = -1;
  927. return (9020); /* advent/10 goes to 9024 */
  928. }
  929. if (obj != 0 && obj != bottle)
  930. return (2011);
  931. if (obj == 0 && !here(bottle))
  932. return (8000);
  933. spk = 107;
  934. if (liqloc(loc) == 0)
  935. spk = 106;
  936. if (liq() != 0)
  937. spk = 105;
  938. if (spk != 107)
  939. return (2011);
  940. prop[bottle] = ((cond[loc] % 4) / 2) * 2;
  941. k = liq();
  942. if (toting(bottle))
  943. place[k] = -1;
  944. if (k == oil)
  945. spk = 108;
  946. return (2011);
  947. }
  948. void
  949. closing()
  950. { /* 10000 */
  951. int i;
  952. prop[grate] = prop[fissur] = 0;
  953. for (i = 1; i <= 6; i++) {
  954. dseen[i] = FALSE;
  955. dloc[i] = 0;
  956. }
  957. move(troll, 0);
  958. move(troll + 100, 0);
  959. move(troll2, plac[troll]);
  960. move(troll2 + 100, fixd[troll]);
  961. juggle(chasm);
  962. if (prop[bear] != 3)
  963. dstroy(bear);
  964. prop[chain] = 0;
  965. fixed[chain] = 0;
  966. prop[axe] = 0;
  967. fixed[axe] = 0;
  968. rspeak(129);
  969. clock1 = -1;
  970. closng = TRUE;
  971. }
  972. void
  973. caveclose()
  974. { /* 11000 */
  975. int i;
  976. prop[bottle] = put(bottle, 115, 1);
  977. prop[plant] = put(plant, 115, 0);
  978. prop[oyster] = put(oyster, 115, 0);
  979. prop[lamp] = put(lamp, 115, 0);
  980. prop[rod] = put(rod, 115, 0);
  981. prop[dwarf] = put(dwarf, 115, 0);
  982. loc = 115;
  983. oldloc = 115;
  984. newloc = 115;
  985. put(grate, 116, 0);
  986. prop[snake] = put(snake, 116, 1);
  987. prop[bird] = put(bird, 116, 1);
  988. prop[cage] = put(cage, 116, 0);
  989. prop[rod2] = put(rod2, 116, 0);
  990. prop[pillow] = put(pillow, 116, 0);
  991. prop[mirror] = put(mirror, 115, 0);
  992. fixed[mirror] = 116;
  993. for (i = 1; i <= 100; i++)
  994. if (toting(i))
  995. dstroy(i);
  996. rspeak(132);
  997. closed = TRUE;
  998. }