dsub.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /* RESIDENT SUBROUTINES FOR DUNGEON */
  2. /*COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142*/
  3. /* ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED */
  4. /* WRITTEN BY R. M. SUPNIK */
  5. #include <stdio.h>
  6. #include "funcs.h"
  7. #include "vars.h"
  8. #ifndef SEEK_SET
  9. #define SEEK_SET (0)
  10. #endif
  11. extern FILE *dbfile;
  12. static void rspsb2nl_ P((integer, integer, integer, logical));
  13. /* RSPEAK-- OUTPUT RANDOM MESSAGE ROUTINE */
  14. /* CALLED BY-- */
  15. /* CALL RSPEAK(MSGNUM) */
  16. void rspeak_(n)
  17. integer n;
  18. {
  19. rspsb2nl_(n, 0, 0, 1);
  20. } /* rspeak_ */
  21. /* RSPSUB-- OUTPUT RANDOM MESSAGE WITH SUBSTITUTABLE ARGUMENT */
  22. /* CALLED BY-- */
  23. /* CALL RSPSUB(MSGNUM,SUBNUM) */
  24. void rspsub_(n, s1)
  25. integer n;
  26. integer s1;
  27. {
  28. rspsb2nl_(n, s1, 0, 1);
  29. } /* rspsub_ */
  30. /* RSPSB2-- OUTPUT RANDOM MESSAGE WITH UP TO TWO SUBSTITUTABLE ARGUMENTS */
  31. /* CALLED BY-- */
  32. /* CALL RSPSB2(MSGNUM,SUBNUM1,SUBNUM2) */
  33. void rspsb2_(n, s1, s2)
  34. integer n;
  35. integer s1;
  36. integer s2;
  37. {
  38. rspsb2nl_(n, s1, s2, 1);
  39. } /* rspsb2_ */
  40. /* rspsb2nl_ Display a substitutable message with an optional newline */
  41. static void rspsb2nl_(n, y, z, nl)
  42. integer n;
  43. integer y;
  44. integer z;
  45. logical nl;
  46. {
  47. const char *zkey = "IanLanceTaylorJr";
  48. long x;
  49. x = (long)n;
  50. if (x > 0) {
  51. x = rmsg_1.rtext[x - 1];
  52. }
  53. /* !IF >0, LOOK UP IN RTEXT. */
  54. if (x == 0) {
  55. return;
  56. }
  57. /* !ANYTHING TO DO? */
  58. play_1.telflg = TRUE_;
  59. /* !SAID SOMETHING. */
  60. x = ((- x) - 1) * 8;
  61. if (fseek(dbfile, x + (long)rmsg_1.mrloc, SEEK_SET) == EOF) {
  62. fprintf(stderr, "Error seeking database loc %d\n", x);
  63. exit_();
  64. }
  65. if (nl)
  66. more_output(NULL);
  67. while (1) {
  68. integer i;
  69. i = getc(dbfile);
  70. if (i == EOF) {
  71. fprintf(stderr, "Error reading database loc %d\n", x);
  72. exit_();
  73. }
  74. i ^= zkey[x & 0xf] ^ (x & 0xff);
  75. x = x + 1;
  76. if (i == '\0')
  77. break;
  78. else if (i == '\n') {
  79. putchar('\n');
  80. if (nl)
  81. more_output(NULL);
  82. }
  83. else if (i == '#' && y != 0) {
  84. long iloc;
  85. iloc = ftell(dbfile);
  86. rspsb2nl_(y, 0, 0, 0);
  87. if (fseek(dbfile, iloc, SEEK_SET) == EOF) {
  88. fprintf(stderr, "Error seeking database loc %d\n", iloc);
  89. exit_();
  90. }
  91. y = z;
  92. z = 0;
  93. }
  94. else
  95. putchar(i);
  96. }
  97. if (nl)
  98. putchar('\n');
  99. }
  100. /* OBJACT-- APPLY OBJECTS FROM PARSE VECTOR */
  101. /* DECLARATIONS */
  102. logical objact_()
  103. {
  104. /* System generated locals */
  105. logical ret_val;
  106. ret_val = TRUE_;
  107. /* !ASSUME WINS. */
  108. if (prsvec_1.prsi == 0) {
  109. goto L100;
  110. }
  111. /* !IND OBJECT? */
  112. if (oappli_(objcts_1.oactio[prsvec_1.prsi - 1], 0)) {
  113. return ret_val;
  114. }
  115. /* !YES, LET IT HANDLE. */
  116. L100:
  117. if (prsvec_1.prso == 0) {
  118. goto L200;
  119. }
  120. /* !DIR OBJECT? */
  121. if (oappli_(objcts_1.oactio[prsvec_1.prso - 1], 0)) {
  122. return ret_val;
  123. }
  124. /* !YES, LET IT HANDLE. */
  125. L200:
  126. ret_val = FALSE_;
  127. /* !LOSES. */
  128. return ret_val;
  129. } /* objact_ */
  130. /* BUG-- REPORT FATAL SYSTEM ERROR */
  131. /* CALLED BY-- */
  132. /* CALL BUG(NO,PAR) */
  133. void bug_(a, b)
  134. integer a;
  135. integer b;
  136. {
  137. /* Local variables */
  138. more_output(NULL);
  139. printf("PROGRAM ERROR %d, PARAMETER=%d\n", a, b);
  140. if (debug_1.dbgflg != 0) {
  141. return;
  142. }
  143. exit_();
  144. } /* bug_ */
  145. /* NEWSTA-- SET NEW STATUS FOR OBJECT */
  146. /* CALLED BY-- */
  147. /* CALL NEWSTA(OBJECT,STRING,NEWROOM,NEWCON,NEWADV) */
  148. void newsta_(o, r, rm, cn, ad)
  149. integer o;
  150. integer r;
  151. integer rm;
  152. integer cn;
  153. integer ad;
  154. {
  155. rspeak_(r);
  156. objcts_1.oroom[o - 1] = rm;
  157. objcts_1.ocan[o - 1] = cn;
  158. objcts_1.oadv[o - 1] = ad;
  159. } /* newsta_ */
  160. /* QHERE-- TEST FOR OBJECT IN ROOM */
  161. /* DECLARATIONS */
  162. logical qhere_(obj, rm)
  163. integer obj;
  164. integer rm;
  165. {
  166. /* System generated locals */
  167. integer i__1;
  168. logical ret_val;
  169. /* Local variables */
  170. integer i;
  171. ret_val = TRUE_;
  172. if (objcts_1.oroom[obj - 1] == rm) {
  173. return ret_val;
  174. }
  175. /* !IN ROOM? */
  176. i__1 = oroom2_1.r2lnt;
  177. for (i = 1; i <= i__1; ++i) {
  178. /* !NO, SCH ROOM2. */
  179. if (oroom2_1.oroom2[i - 1] == obj && oroom2_1.rroom2[i - 1] == rm) {
  180. return ret_val;
  181. }
  182. /* L100: */
  183. }
  184. ret_val = FALSE_;
  185. /* !NOT PRESENT. */
  186. return ret_val;
  187. } /* qhere_ */
  188. /* QEMPTY-- TEST FOR OBJECT EMPTY */
  189. /* DECLARATIONS */
  190. logical qempty_(obj)
  191. integer obj;
  192. {
  193. /* System generated locals */
  194. integer i__1;
  195. logical ret_val;
  196. /* Local variables */
  197. integer i;
  198. ret_val = FALSE_;
  199. /* !ASSUME LOSE. */
  200. i__1 = objcts_1.olnt;
  201. for (i = 1; i <= i__1; ++i) {
  202. if (objcts_1.ocan[i - 1] == obj) {
  203. return ret_val;
  204. }
  205. /* !INSIDE TARGET? */
  206. /* L100: */
  207. }
  208. ret_val = TRUE_;
  209. return ret_val;
  210. } /* qempty_ */
  211. /* JIGSUP- YOU ARE DEAD */
  212. /* DECLARATIONS */
  213. void jigsup_(desc)
  214. integer desc;
  215. {
  216. /* Initialized data */
  217. static const integer rlist[9] = { 8,6,36,35,34,4,34,6,5 };
  218. /* System generated locals */
  219. integer i__1;
  220. /* Local variables */
  221. integer nonofl;
  222. logical f;
  223. integer i, j;
  224. rspeak_(desc);
  225. /* !DESCRIBE SAD STATE. */
  226. prsvec_1.prscon = 1;
  227. /* !STOP PARSER. */
  228. if (debug_1.dbgflg != 0) {
  229. return;
  230. }
  231. /* !IF DBG, EXIT. */
  232. advs_1.avehic[play_1.winner - 1] = 0;
  233. /* !GET RID OF VEHICLE. */
  234. if (play_1.winner == aindex_1.player) {
  235. goto L100;
  236. }
  237. /* !HIMSELF? */
  238. rspsub_(432, objcts_1.odesc2[advs_1.aobj[play_1.winner - 1] - 1]);
  239. /* !NO, SAY WHO DIED. */
  240. newsta_(advs_1.aobj[play_1.winner - 1], 0, 0, 0, 0);
  241. /* !SEND TO HYPER SPACE. */
  242. return;
  243. L100:
  244. if (findex_1.endgmf) {
  245. goto L900;
  246. }
  247. /* !NO RECOVERY IN END GAME. */
  248. // always exit for plopbot's purposes
  249. goto L1000;
  250. // if (state_1.deaths >= 2) {
  251. // goto L1000;
  252. // }
  253. /* !DEAD TWICE? KICK HIM OFF. */
  254. if (! yesno_(10, 9, 8)) {
  255. goto L1100;
  256. }
  257. /* !CONTINUE? */
  258. i__1 = objcts_1.olnt;
  259. for (j = 1; j <= i__1; ++j) {
  260. /* !TURN OFF FIGHTING. */
  261. if (qhere_(j, play_1.here)) {
  262. objcts_1.oflag2[j - 1] &= ~ FITEBT;
  263. }
  264. /* L50: */
  265. }
  266. ++state_1.deaths;
  267. scrupd_(- 10);
  268. /* !CHARGE TEN POINTS. */
  269. f = moveto_(rindex_1.fore1, play_1.winner);
  270. /* !REPOSITION HIM. */
  271. findex_1.egyptf = TRUE_;
  272. /* !RESTORE COFFIN. */
  273. if (objcts_1.oadv[oindex_1.coffi - 1] == play_1.winner) {
  274. newsta_(oindex_1.coffi, 0, rindex_1.egypt, 0, 0);
  275. }
  276. objcts_1.oflag2[oindex_1.door - 1] &= ~ TCHBT;
  277. objcts_1.oflag1[oindex_1.robot - 1] = (objcts_1.oflag1[oindex_1.robot - 1]
  278. | VISIBT) & ~ NDSCBT;
  279. if (objcts_1.oroom[oindex_1.lamp - 1] != 0 || objcts_1.oadv[oindex_1.lamp
  280. - 1] == play_1.winner) {
  281. newsta_(oindex_1.lamp, 0, rindex_1.lroom, 0, 0);
  282. }
  283. /* NOW REDISTRIBUTE HIS VALUABLES AND OTHER BELONGINGS. */
  284. /* THE LAMP HAS BEEN PLACED IN THE LIVING ROOM. */
  285. /* THE FIRST 8 NON-VALUABLES ARE PLACED IN LOCATIONS AROUND THE HOUSE. */
  286. /* HIS VALUABLES ARE PLACED AT THE END OF THE MAZE. */
  287. /* REMAINING NON-VALUABLES ARE PLACED AT THE END OF THE MAZE. */
  288. i = 1;
  289. i__1 = objcts_1.olnt;
  290. for (j = 1; j <= i__1; ++j) {
  291. /* !LOOP THRU OBJECTS. */
  292. if (objcts_1.oadv[j - 1] != play_1.winner || objcts_1.otval[j - 1] !=
  293. 0) {
  294. goto L200;
  295. }
  296. ++i;
  297. if (i > 9) {
  298. goto L400;
  299. }
  300. /* !MOVE TO RANDOM LOCATIONS. */
  301. newsta_(j, 0, rlist[i - 1], 0, 0);
  302. L200:
  303. ;
  304. }
  305. L400:
  306. i = rooms_1.rlnt + 1;
  307. /* !NOW MOVE VALUABLES. */
  308. nonofl = RAIR + RWATER + RSACRD + REND;
  309. /* !DONT MOVE HERE. */
  310. i__1 = objcts_1.olnt;
  311. for (j = 1; j <= i__1; ++j) {
  312. if (objcts_1.oadv[j - 1] != play_1.winner || objcts_1.otval[j - 1] ==
  313. 0) {
  314. goto L300;
  315. }
  316. L250:
  317. --i;
  318. /* !FIND NEXT ROOM. */
  319. if ((rooms_1.rflag[i - 1] & nonofl) != 0) {
  320. goto L250;
  321. }
  322. newsta_(j, 0, i, 0, 0);
  323. /* !YES, MOVE. */
  324. L300:
  325. ;
  326. }
  327. i__1 = objcts_1.olnt;
  328. for (j = 1; j <= i__1; ++j) {
  329. /* !NOW GET RID OF REMAINDER. */
  330. if (objcts_1.oadv[j - 1] != play_1.winner) {
  331. goto L500;
  332. }
  333. L450:
  334. --i;
  335. /* !FIND NEXT ROOM. */
  336. if ((rooms_1.rflag[i - 1] & nonofl) != 0) {
  337. goto L450;
  338. }
  339. newsta_(j, 0, i, 0, 0);
  340. L500:
  341. ;
  342. }
  343. return;
  344. /* CAN'T OR WON'T CONTINUE, CLEAN UP AND EXIT. */
  345. L900:
  346. rspeak_(625);
  347. /* !IN ENDGAME, LOSE. */
  348. goto L1100;
  349. L1000:
  350. rspeak_(7);
  351. /* !INVOLUNTARY EXIT. */
  352. L1100:
  353. score_(0);
  354. /* !TELL SCORE. */
  355. (void) fclose(dbfile);
  356. exit_();
  357. } /* jigsup_ */
  358. /* OACTOR- GET ACTOR ASSOCIATED WITH OBJECT */
  359. /* DECLARATIONS */
  360. integer oactor_(obj)
  361. integer obj;
  362. {
  363. /* System generated locals */
  364. integer ret_val = 1, i__1;
  365. /* Local variables */
  366. integer i;
  367. i__1 = advs_1.alnt;
  368. for (i = 1; i <= i__1; ++i) {
  369. /* !LOOP THRU ACTORS. */
  370. ret_val = i;
  371. /* !ASSUME FOUND. */
  372. if (advs_1.aobj[i - 1] == obj) {
  373. return ret_val;
  374. }
  375. /* !FOUND IT? */
  376. /* L100: */
  377. }
  378. bug_(40, obj);
  379. /* !NO, DIE. */
  380. return ret_val;
  381. } /* oactor_ */
  382. /* PROB- COMPUTE PROBABILITY */
  383. /* DECLARATIONS */
  384. logical prob_(g, b)
  385. integer g;
  386. integer b;
  387. {
  388. /* System generated locals */
  389. logical ret_val;
  390. /* Local variables */
  391. integer i;
  392. i = g;
  393. /* !ASSUME GOOD LUCK. */
  394. if (findex_1.badlkf) {
  395. i = b;
  396. }
  397. /* !IF BAD, TOO BAD. */
  398. ret_val = rnd_(100) < i;
  399. /* !COMPUTE. */
  400. return ret_val;
  401. } /* prob_ */
  402. /* RMDESC-- PRINT ROOM DESCRIPTION */
  403. /* RMDESC PRINTS A DESCRIPTION OF THE CURRENT ROOM. */
  404. /* IT IS ALSO THE PROCESSOR FOR VERBS 'LOOK' AND 'EXAMINE'. */
  405. logical rmdesc_(full)
  406. integer full;
  407. {
  408. /* System generated locals */
  409. logical ret_val, L__1;
  410. /* Local variables */
  411. integer i, ra;
  412. /* FULL= 0/1/2/3= SHORT/OBJ/ROOM/FULL */
  413. ret_val = TRUE_;
  414. /* !ASSUME WINS. */
  415. if (prsvec_1.prso < xsrch_1.xmin) {
  416. goto L50;
  417. }
  418. /* !IF DIRECTION, */
  419. screen_1.fromdr = prsvec_1.prso;
  420. /* !SAVE AND */
  421. prsvec_1.prso = 0;
  422. /* !CLEAR. */
  423. L50:
  424. if (play_1.here == advs_1.aroom[aindex_1.player - 1]) {
  425. goto L100;
  426. }
  427. /* !PLAYER JUST MOVE? */
  428. rspeak_(2);
  429. /* !NO, JUST SAY DONE. */
  430. prsvec_1.prsa = vindex_1.walkiw;
  431. /* !SET UP WALK IN ACTION. */
  432. return ret_val;
  433. L100:
  434. if (lit_(play_1.here)) {
  435. goto L300;
  436. }
  437. /* !LIT? */
  438. rspeak_(430);
  439. /* !WARN OF GRUE. */
  440. ret_val = FALSE_;
  441. return ret_val;
  442. L300:
  443. ra = rooms_1.ractio[play_1.here - 1];
  444. /* !GET ROOM ACTION. */
  445. if (full == 1) {
  446. goto L600;
  447. }
  448. /* !OBJ ONLY? */
  449. i = rooms_1.rdesc2[play_1.here - 1];
  450. /* !ASSUME SHORT DESC. */
  451. if (full == 0 && (findex_1.superf || (rooms_1.rflag[play_1.here - 1] &
  452. RSEEN) != 0 && findex_1.brieff)) {
  453. goto L400;
  454. }
  455. /* The next line means that when you request VERBOSE mode, you */
  456. /* only get long room descriptions 20% of the time. I don't either */
  457. /* like or understand this, so the mod. ensures VERBOSE works */
  458. /* all the time. jmh@ukc.ac.uk 22/10/87 */
  459. /* & .AND.(BRIEFF.OR.PROB(80,80))))) GO TO 400 */
  460. i = rooms_1.rdesc1[play_1.here - 1];
  461. /* !USE LONG. */
  462. if (i != 0 || ra == 0) {
  463. goto L400;
  464. }
  465. /* !IF GOT DESC, SKIP. */
  466. prsvec_1.prsa = vindex_1.lookw;
  467. /* !PRETEND LOOK AROUND. */
  468. if (! rappli_(ra)) {
  469. goto L100;
  470. }
  471. /* !ROOM HANDLES, NEW DESC? */
  472. prsvec_1.prsa = vindex_1.foow;
  473. /* !NOP PARSER. */
  474. goto L500;
  475. L400:
  476. rspeak_(i);
  477. /* !OUTPUT DESCRIPTION. */
  478. L500:
  479. if (advs_1.avehic[play_1.winner - 1] != 0) {
  480. rspsub_(431, objcts_1.odesc2[advs_1.avehic[play_1.winner - 1] -
  481. 1]);
  482. }
  483. L600:
  484. if (full != 2) {
  485. L__1 = full != 0;
  486. princr_(L__1, play_1.here);
  487. }
  488. rooms_1.rflag[play_1.here - 1] |= RSEEN;
  489. if (full != 0 || ra == 0) {
  490. return ret_val;
  491. }
  492. /* !ANYTHING MORE? */
  493. prsvec_1.prsa = vindex_1.walkiw;
  494. /* !GIVE HIM A SURPISE. */
  495. if (! rappli_(ra)) {
  496. goto L100;
  497. }
  498. /* !ROOM HANDLES, NEW DESC? */
  499. prsvec_1.prsa = vindex_1.foow;
  500. return ret_val;
  501. } /* rmdesc_ */
  502. /* RAPPLI- ROUTING ROUTINE FOR ROOM APPLICABLES */
  503. /* DECLARATIONS */
  504. logical rappli_(ri)
  505. integer ri;
  506. {
  507. /* Initialized data */
  508. const integer newrms = 38;
  509. /* System generated locals */
  510. logical ret_val;
  511. ret_val = TRUE_;
  512. /* !ASSUME WINS. */
  513. if (ri == 0) {
  514. return ret_val;
  515. }
  516. /* !IF ZERO, WIN. */
  517. if (ri < newrms) {
  518. ret_val = rappl1_(ri);
  519. }
  520. /* !IF OLD, PROCESSOR 1. */
  521. if (ri >= newrms) {
  522. ret_val = rappl2_(ri);
  523. }
  524. /* !IF NEW, PROCESSOR 2. */
  525. return ret_val;
  526. } /* rappli_ */