dsub.for 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. C RESIDENT SUBROUTINES FOR DUNGEON
  2. C
  3. C COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142
  4. C ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED
  5. C WRITTEN BY R. M. SUPNIK
  6. C
  7. C RSPEAK-- OUTPUT RANDOM MESSAGE ROUTINE
  8. C
  9. C CALLED BY--
  10. C
  11. C CALL RSPEAK(MSGNUM)
  12. C
  13. SUBROUTINE RSPEAK(N)
  14. IMPLICIT INTEGER(A-Z)
  15. C
  16. CALL RSPSB2(N,0,0)
  17. RETURN
  18. END
  19. C RSPSUB-- OUTPUT RANDOM MESSAGE WITH SUBSTITUTABLE ARGUMENT
  20. C
  21. C CALLED BY--
  22. C
  23. C CALL RSPSUB(MSGNUM,SUBNUM)
  24. C
  25. SUBROUTINE RSPSUB(N,S1)
  26. IMPLICIT INTEGER(A-Z)
  27. C
  28. CALL RSPSB2(N,S1,0)
  29. RETURN
  30. END
  31. C RSPSB2-- OUTPUT RANDOM MESSAGE WITH UP TO TWO SUBSTITUTABLE ARGUMENTS
  32. C
  33. C CALLED BY--
  34. C
  35. C CALL RSPSB2(MSGNUM,SUBNUM1,SUBNUM2)
  36. C
  37. SUBROUTINE RSPSB2(N,S1,S2)
  38. IMPLICIT INTEGER(A-Z)
  39. CHARACTER*74 B1,B2,B3
  40. INTEGER*2 OLDREC,NEWREC,JREC
  41. C
  42. C DECLARATIONS
  43. C
  44. include 'gamestat.h'
  45. C
  46. include 'mindex.h'
  47. include 'io.h'
  48. C
  49. C CONVERT ALL ARGUMENTS FROM DICTIONARY NUMBERS (IF POSITIVE)
  50. C TO ABSOLUTE RECORD NUMBERS.
  51. C
  52. X=N
  53. C !SET UP WORK VARIABLES.
  54. Y=S1
  55. Z=S2
  56. IF(X.GT.0) X=RTEXT(X)
  57. C !IF >0, LOOK UP IN RTEXT.
  58. IF(Y.GT.0) Y=RTEXT(Y)
  59. IF(Z.GT.0) Z=RTEXT(Z)
  60. X=IABS(X)
  61. C !TAKE ABS VALUE.
  62. Y=IABS(Y)
  63. Z=IABS(Z)
  64. IF(X.EQ.0) RETURN
  65. C !ANYTHING TO DO?
  66. TELFLG=.TRUE.
  67. C !SAID SOMETHING.
  68. C
  69. READ(UNIT=DBCH,REC=X) OLDREC,B1
  70. C
  71. 100 DO 150 I=1,74
  72. X1=IAND(X,31)+I
  73. B1(I:I)=char(IEOR(ichar(B1(I:I)),X1))
  74. 150 CONTINUE
  75. C
  76. 200 IF(Y.EQ.0) GO TO 400
  77. C !ANY SUBSTITUTABLE?
  78. DO 300 I=1,74
  79. C !YES, LOOK FOR #.
  80. IF(B1(I:I).EQ.'#') GO TO 1000
  81. 300 CONTINUE
  82. C
  83. 400 DO 500 I=74,1,-1
  84. C !BACKSCAN FOR BLANKS.
  85. IF(B1(I:I).NE.' ') GO TO 600
  86. 500 CONTINUE
  87. C
  88. 600 WRITE(OUTCH,650) (B1(J:J),J=1,I)
  89. 650 FORMAT(1X,74A1)
  90. X=X+1
  91. C !ON TO NEXT RECORD.
  92. READ(UNIT=DBCH,REC=X) NEWREC,B1
  93. IF(OLDREC.EQ.NEWREC) GO TO 100
  94. C !CONTINUATION?
  95. RETURN
  96. C !NO, EXIT.
  97. C
  98. C SUBSTITUTION WITH SUBSTITUTABLE AVAILABLE.
  99. C I IS INDEX OF # IN B1.
  100. C Y IS NUMBER OF RECORD TO SUBSTITUTE.
  101. C
  102. C PROCEDURE:
  103. C 1) COPY REST OF B1 TO B2
  104. C 2) READ SUBSTITUTABLE OVER B1
  105. C 3) RESTORE TAIL OF ORIGINAL B1
  106. C
  107. C THE IMPLICIT ASSUMPTION HERE IS THAT THE SUBSTITUTABLE STRING
  108. C IS VERY SHORT (i.e. MUCH LESS THAN ONE RECORD).
  109. C
  110. 1000 K2=1
  111. C !TO
  112. DO 1100 K1=I+1,74
  113. C !COPY REST OF B1.
  114. B2(K2:K2)=B1(K1:K1)
  115. K2=K2+1
  116. 1100 CONTINUE
  117. C
  118. C READ SUBSTITUTE STRING INTO B3, AND DECRYPT IT:
  119. C
  120. READ(UNIT=DBCH,REC=Y) JREC,B3
  121. DO 1150 K1=1,74
  122. X1=IAND(Y,31)+K1
  123. B3(K1:K1)=char(IEOR(ICHAR(B3(K1:K1)),X1))
  124. 1150 CONTINUE
  125. C
  126. C FILL REMAINDER OF B1 WITH CHARACTERS FROM B3:
  127. C
  128. K2=1
  129. DO 1180 K1=I,74
  130. B1(K1:K1)=B3(K2:K2)
  131. K2=K2+1
  132. 1180 CONTINUE
  133. C
  134. C FIND END OF SUBSTITUTE STRING IN B1:
  135. C
  136. DO 1200 J=74,1,-1
  137. C !ELIM TRAILING BLANKS.
  138. IF(B1(J:J).NE.' ') GO TO 1300
  139. 1200 CONTINUE
  140. C
  141. C PUT TAIL END OF B1 (NOW IN B2) BACK INTO B1 AFTER SUBSTITUTE STRING:
  142. C
  143. 1300 K1=1
  144. C !FROM
  145. DO 1400 K2=J+1,74
  146. C !COPY REST OF B1 BACK.
  147. B1(K2:K2)=B2(K1:K1)
  148. K1=K1+1
  149. 1400 CONTINUE
  150. C
  151. Y=Z
  152. C !SET UP FOR NEXT
  153. Z=0
  154. C !SUBSTITUTION AND
  155. GO TO 200
  156. C !RECHECK LINE.
  157. C
  158. END
  159. C OBJACT-- APPLY OBJECTS FROM PARSE VECTOR
  160. C
  161. C DECLARATIONS
  162. C
  163. LOGICAL FUNCTION OBJACT(X)
  164. IMPLICIT INTEGER (A-Z)
  165. LOGICAL OAPPLI
  166. include 'parser.h'
  167. include 'objects.h'
  168. C
  169. OBJACT=.TRUE.
  170. C !ASSUME WINS.
  171. IF(PRSI.EQ.0) GO TO 100
  172. C !IND OBJECT?
  173. IF(OAPPLI(OACTIO(PRSI),0)) RETURN
  174. C !YES, LET IT HANDLE.
  175. C
  176. 100 IF(PRSO.EQ.0) GO TO 200
  177. C !DIR OBJECT?
  178. IF(OAPPLI(OACTIO(PRSO),0)) RETURN
  179. C !YES, LET IT HANDLE.
  180. C
  181. 200 OBJACT=.FALSE.
  182. C !LOSES.
  183. RETURN
  184. END
  185. C BUG-- REPORT FATAL SYSTEM ERROR
  186. C
  187. C CALLED BY--
  188. C
  189. C CALL BUG(NO,PAR)
  190. C
  191. SUBROUTINE BUG(A,B)
  192. IMPLICIT INTEGER(A-Z)
  193. include 'debug.h'
  194. C
  195. PRINT 100,A,B
  196. IF(DBGFLG.NE.0) RETURN
  197. CALL EXIT
  198. C
  199. 100 FORMAT(' PROGRAM ERROR ',I2,', PARAMETER=',I6)
  200. END
  201. C NEWSTA-- SET NEW STATUS FOR OBJECT
  202. C
  203. C CALLED BY--
  204. C
  205. C CALL NEWSTA(OBJECT,STRING,NEWROOM,NEWCON,NEWADV)
  206. C
  207. SUBROUTINE NEWSTA(O,R,RM,CN,AD)
  208. IMPLICIT INTEGER(A-Z)
  209. include 'objects.h'
  210. C
  211. CALL RSPEAK(R)
  212. OROOM(O)=RM
  213. OCAN(O)=CN
  214. OADV(O)=AD
  215. RETURN
  216. END
  217. C QHERE-- TEST FOR OBJECT IN ROOM
  218. C
  219. C DECLARATIONS
  220. C
  221. LOGICAL FUNCTION QHERE(OBJ,RM)
  222. IMPLICIT INTEGER (A-Z)
  223. include 'objects.h'
  224. C
  225. QHERE=.TRUE.
  226. IF(OROOM(OBJ).EQ.RM) RETURN
  227. C !IN ROOM?
  228. DO 100 I=1,R2LNT
  229. C !NO, SCH ROOM2.
  230. IF((OROOM2(I).EQ.OBJ).AND.(RROOM2(I).EQ.RM)) RETURN
  231. 100 CONTINUE
  232. QHERE=.FALSE.
  233. C !NOT PRESENT.
  234. RETURN
  235. END
  236. C QEMPTY-- TEST FOR OBJECT EMPTY
  237. C
  238. C DECLARATIONS
  239. C
  240. LOGICAL FUNCTION QEMPTY(OBJ)
  241. IMPLICIT INTEGER (A-Z)
  242. include 'objects.h'
  243. C
  244. QEMPTY=.FALSE.
  245. C !ASSUME LOSE.
  246. DO 100 I=1,OLNT
  247. IF(OCAN(I).EQ.OBJ) RETURN
  248. C !INSIDE TARGET?
  249. 100 CONTINUE
  250. QEMPTY=.TRUE.
  251. RETURN
  252. END
  253. C JIGSUP- YOU ARE DEAD
  254. C
  255. C DECLARATIONS
  256. C
  257. SUBROUTINE JIGSUP(DESC)
  258. IMPLICIT INTEGER (A-Z)
  259. LOGICAL YESNO,MOVETO,QHERE,F
  260. INTEGER RLIST(9)
  261. include 'parser.h'
  262. include 'gamestat.h'
  263. include 'state.h'
  264. include 'io.h'
  265. include 'debug.h'
  266. include 'rooms.h'
  267. include 'rflag.h'
  268. include 'rindex.h'
  269. include 'objects.h'
  270. include 'oflags.h'
  271. include 'oindex.h'
  272. include 'advers.h'
  273. include 'flags.h'
  274. C
  275. C FUNCTIONS AND DATA
  276. C
  277. DATA RLIST/8,6,36,35,34,4,34,6,5/
  278. C JIGSUP, PAGE 2
  279. C
  280. CALL RSPEAK(DESC)
  281. C !DESCRIBE SAD STATE.
  282. PRSCON=1
  283. C !STOP PARSER.
  284. IF(DBGFLG.NE.0) RETURN
  285. C !IF DBG, EXIT.
  286. AVEHIC(WINNER)=0
  287. C !GET RID OF VEHICLE.
  288. IF(WINNER.EQ.PLAYER) GO TO 100
  289. C !HIMSELF?
  290. CALL RSPSUB(432,ODESC2(AOBJ(WINNER)))
  291. C !NO, SAY WHO DIED.
  292. CALL NEWSTA(AOBJ(WINNER),0,0,0,0)
  293. C !SEND TO HYPER SPACE.
  294. RETURN
  295. C
  296. 100 IF(ENDGMF) GO TO 900
  297. C !NO RECOVERY IN END GAME.
  298. IF(DEATHS.GE.2) GO TO 1000
  299. C !DEAD TWICE? KICK HIM OFF.
  300. IF(.NOT.YESNO(10,9,8)) GO TO 1100
  301. C !CONTINUE?
  302. C
  303. DO 50 J=1,OLNT
  304. C !TURN OFF FIGHTING.
  305. IF(QHERE(J,HERE)) OFLAG2(J)=IAND(OFLAG2(J),not(FITEBT))
  306. 50 CONTINUE
  307. C
  308. DEATHS=DEATHS+1
  309. CALL SCRUPD(-10)
  310. C !CHARGE TEN POINTS.
  311. F=MOVETO(FORE1,WINNER)
  312. C !REPOSITION HIM.
  313. EGYPTF=.TRUE.
  314. C !RESTORE COFFIN.
  315. IF(OADV(COFFI).EQ.WINNER) CALL NEWSTA(COFFI,0,EGYPT,0,0)
  316. OFLAG2(DOOR)=IAND(OFLAG2(DOOR),not(TCHBT))
  317. OFLAG1(ROBOT)=IAND(IOR(OFLAG1(ROBOT),VISIBT),not(NDSCBT))
  318. IF((OROOM(LAMP).NE.0).OR.(OADV(LAMP).EQ.WINNER))
  319. & CALL NEWSTA(LAMP,0,LROOM,0,0)
  320. C
  321. C NOW REDISTRIBUTE HIS VALUABLES AND OTHER BELONGINGS.
  322. C
  323. C THE LAMP HAS BEEN PLACED IN THE LIVING ROOM.
  324. C THE FIRST 8 NON-VALUABLES ARE PLACED IN LOCATIONS AROUND THE HOUSE.
  325. C HIS VALUABLES ARE PLACED AT THE END OF THE MAZE.
  326. C REMAINING NON-VALUABLES ARE PLACED AT THE END OF THE MAZE.
  327. C
  328. I=1
  329. DO 200 J=1,OLNT
  330. C !LOOP THRU OBJECTS.
  331. IF((OADV(J).NE.WINNER).OR.(OTVAL(J).NE.0))
  332. & GO TO 200
  333. I=I+1
  334. IF(I.GT.9) GO TO 400
  335. C !MOVE TO RANDOM LOCATIONS.
  336. CALL NEWSTA(J,0,RLIST(I),0,0)
  337. 200 CONTINUE
  338. C
  339. 400 I=RLNT+1
  340. C !NOW MOVE VALUABLES.
  341. NONOFL=RAIR+RWATER+RSACRD+REND
  342. C !DONT MOVE HERE.
  343. DO 300 J=1,OLNT
  344. IF((OADV(J).NE.WINNER).OR.(OTVAL(J).EQ.0))
  345. & GO TO 300
  346. 250 I=I-1
  347. C !FIND NEXT ROOM.
  348. IF(IAND(RFLAG(I),NONOFL).NE.0) GO TO 250
  349. CALL NEWSTA(J,0,I,0,0)
  350. C !YES, MOVE.
  351. 300 CONTINUE
  352. C
  353. DO 500 J=1,OLNT
  354. C !NOW GET RID OF REMAINDER.
  355. IF(OADV(J).NE.WINNER) GO TO 500
  356. 450 I=I-1
  357. C !FIND NEXT ROOM.
  358. IF(IAND(RFLAG(I),NONOFL).NE.0) GO TO 450
  359. CALL NEWSTA(J,0,I,0,0)
  360. 500 CONTINUE
  361. RETURN
  362. C
  363. C CAN'T OR WON'T CONTINUE, CLEAN UP AND EXIT.
  364. C
  365. 900 CALL RSPEAK(625)
  366. C !IN ENDGAME, LOSE.
  367. GO TO 1100
  368. C
  369. 1000 CALL RSPEAK(7)
  370. C !INVOLUNTARY EXIT.
  371. 1100 CALL SCORE(.FALSE.)
  372. C !TELL SCORE.
  373. CLOSE(DBCH)
  374. CALL EXIT
  375. C
  376. END
  377. C OACTOR- GET ACTOR ASSOCIATED WITH OBJECT
  378. C
  379. C DECLARATIONS
  380. C
  381. INTEGER FUNCTION OACTOR(OBJ)
  382. IMPLICIT INTEGER(A-Z)
  383. include 'advers.h'
  384. C
  385. DO 100 I=1,ALNT
  386. C !LOOP THRU ACTORS.
  387. OACTOR=I
  388. C !ASSUME FOUND.
  389. IF(AOBJ(I).EQ.OBJ) RETURN
  390. C !FOUND IT?
  391. 100 CONTINUE
  392. CALL BUG(40,OBJ)
  393. C !NO, DIE.
  394. RETURN
  395. END
  396. C PROB- COMPUTE PROBABILITY
  397. C
  398. C DECLARATIONS
  399. C
  400. LOGICAL FUNCTION PROB(G,B)
  401. IMPLICIT INTEGER(A-Z)
  402. include 'flags.h'
  403. C
  404. I=G
  405. C !ASSUME GOOD LUCK.
  406. IF(BADLKF) I=B
  407. C !IF BAD, TOO BAD.
  408. PROB=RND(100).LT.I
  409. C !COMPUTE.
  410. RETURN
  411. END
  412. C RMDESC-- PRINT ROOM DESCRIPTION
  413. C
  414. C RMDESC PRINTS A DESCRIPTION OF THE CURRENT ROOM.
  415. C IT IS ALSO THE PROCESSOR FOR VERBS 'LOOK' AND 'EXAMINE'.
  416. C
  417. LOGICAL FUNCTION RMDESC(FULL)
  418. C
  419. C FULL= 0/1/2/3= SHORT/OBJ/ROOM/FULL
  420. C
  421. C DECLARATIONS
  422. C
  423. IMPLICIT INTEGER (A-Z)
  424. LOGICAL PROB,LIT,RAPPLI
  425. include 'parser.h'
  426. include 'gamestat.h'
  427. include 'screen.h'
  428. include 'rooms.h'
  429. include 'rflag.h'
  430. include 'xsrch.h'
  431. include 'objects.h'
  432. include 'advers.h'
  433. include 'verbs.h'
  434. include 'flags.h'
  435. C RMDESC, PAGE 2
  436. C
  437. RMDESC=.TRUE.
  438. C !ASSUME WINS.
  439. IF(PRSO.LT.XMIN) GO TO 50
  440. C !IF DIRECTION,
  441. FROMDR=PRSO
  442. C !SAVE AND
  443. PRSO=0
  444. C !CLEAR.
  445. 50 IF(HERE.EQ.AROOM(PLAYER)) GO TO 100
  446. C !PLAYER JUST MOVE?
  447. CALL RSPEAK(2)
  448. C !NO, JUST SAY DONE.
  449. PRSA=WALKIW
  450. C !SET UP WALK IN ACTION.
  451. RETURN
  452. C
  453. 100 IF(LIT(HERE)) GO TO 300
  454. C !LIT?
  455. CALL RSPEAK(430)
  456. C !WARN OF GRUE.
  457. RMDESC=.FALSE.
  458. RETURN
  459. C
  460. 300 RA=RACTIO(HERE)
  461. C !GET ROOM ACTION.
  462. IF(FULL.EQ.1) GO TO 600
  463. C !OBJ ONLY?
  464. I=RDESC2-HERE
  465. C !ASSUME SHORT DESC.
  466. IF((FULL.EQ.0)
  467. & .AND.(SUPERF.OR.(((IAND(RFLAG(HERE),RSEEN)).NE.0)
  468. & .AND.(BRIEFF.OR.PROB(80,80))))) GO TO 400
  469. I=RDESC1(HERE)
  470. C !USE LONG.
  471. IF((I.NE.0).OR.(RA.EQ.0)) GO TO 400
  472. C !IF GOT DESC, SKIP.
  473. PRSA=LOOKW
  474. C !PRETEND LOOK AROUND.
  475. IF(.NOT.RAPPLI(RA)) GO TO 100
  476. C !ROOM HANDLES, NEW DESC?
  477. PRSA=FOOW
  478. C !NOP PARSER.
  479. GO TO 500
  480. C
  481. 400 CALL RSPEAK(I)
  482. C !OUTPUT DESCRIPTION.
  483. 500 IF(AVEHIC(WINNER).NE.0) CALL RSPSUB(431,ODESC2(AVEHIC(WINNER)))
  484. C
  485. 600 IF(FULL.NE.2) CALL PRINCR(FULL.NE.0,HERE)
  486. RFLAG(HERE)=IOR(RFLAG(HERE),RSEEN)
  487. IF((FULL.NE.0).OR.(RA.EQ.0)) RETURN
  488. C !ANYTHING MORE?
  489. PRSA=WALKIW
  490. C !GIVE HIM A SURPISE.
  491. IF(.NOT.RAPPLI(RA)) GO TO 100
  492. C !ROOM HANDLES, NEW DESC?
  493. PRSA=FOOW
  494. RETURN
  495. C
  496. END
  497. C RAPPLI- ROUTING ROUTINE FOR ROOM APPLICABLES
  498. C
  499. C DECLARATIONS
  500. C
  501. LOGICAL FUNCTION RAPPLI(RI)
  502. IMPLICIT INTEGER(A-Z)
  503. LOGICAL RAPPL1,RAPPL2
  504. DATA NEWRMS/38/
  505. C
  506. RAPPLI=.TRUE.
  507. C !ASSUME WINS.
  508. IF(RI.EQ.0) RETURN
  509. C !IF ZERO, WIN.
  510. IF(RI.LT.NEWRMS) RAPPLI=RAPPL1(RI)
  511. C !IF OLD, PROCESSOR 1.
  512. IF(RI.GE.NEWRMS) RAPPLI=RAPPL2(RI)
  513. C !IF NEW, PROCESSOR 2.
  514. RETURN
  515. END