makstr.25 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <SETG GLOHI 1>
  2. <SETG STAR-BITS 0>
  3. <DEFINE CEVENT (TICK APP FLG NAME "AUX" (OBL <GET INITIAL OBLIST>) ATM)
  4. #DECL ((TICK) FIX (APP) <OR APPLICABLE OFFSET> (FLG) <OR ATOM FALSE>
  5. (NAME) <OR ATOM STRING> (ATM) <OR ATOM FALSE>)
  6. <COND (<TYPE? .NAME STRING>
  7. <COND (<SET ATM <LOOKUP .NAME .OBL>>)
  8. (T <SET ATM <INSERT .NAME .OBL>>)>)
  9. (<SET ATM .NAME>)>
  10. <SETG .ATM <CHTYPE [.TICK .APP .FLG .ATM] CEVENT>>>
  11. <DEFINE CEXIT (FLID RMID "OPTIONAL" (STR <>) (FLAG <>) (FUNCT <>) "AUX" (FVAL <>) ATM)
  12. #DECL ((STR) <OR FALSE STRING> (FLID RMID) <OR ATOM STRING>
  13. (ATM FUNCT) <OR ATOM FALSE> (FVAL) <OR APPLICABLE FALSE>
  14. (FLAG) <OR ATOM FALSE>)
  15. <COND (<TYPE? .FLID ATOM> <SET FLID <SPNAME .FLID>>)>
  16. <SET ATM <OR <LOOKUP .FLID <GET FLAG OBLIST>>
  17. <INSERT .FLID <GET FLAG OBLIST>>>>
  18. <SETG .ATM .FLAG>
  19. <CHTYPE <VECTOR .ATM <FIND-ROOM .RMID> .STR .FUNCT> CEXIT>>
  20. <DEFINE DOOR (OID RM1 RM2 "OPTIONAL" (STR <>) (FN <>) "AUX" (OBJ <FIND-OBJ .OID>))
  21. #DECL ((OID) STRING (STR) <OR STRING FALSE> (FN) <OR ATOM FALSE>
  22. (OBJ) OBJECT (RM1 RM2) <OR STRING ROOM>)
  23. <COND (<FIND-DOOR <SET RM1 <FIND-ROOM .RM1>> .OBJ>)
  24. (<FIND-DOOR <SET RM2 <FIND-ROOM .RM2>> .OBJ>)
  25. (<CHTYPE [.OBJ .RM1 .RM2 .STR .FN] DOOR>)>>
  26. <DEFINE EXIT ("TUPLE" PAIRS "AUX" (DOBL ,DIRECTIONS)
  27. (FROB <IVECTOR <LENGTH .PAIRS>>))
  28. #DECL ((PAIRS) <TUPLE [REST STRING <OR DOOR NEXIT CEXIT STRING ATOM>]>
  29. (DIR) <LIST [REST ATOM]> (FROB) VECTOR (DOBL) OBLIST)
  30. <REPEAT (ATM RM (F .FROB))
  31. #DECL ((ATM) <OR ATOM FALSE> (RM) <OR ROOM FALSE> (F) VECTOR)
  32. <COND (<OR
  33. <AND <SET ATM <LOOKUP <1 .PAIRS> .DOBL>>
  34. <GASSIGNED? .ATM>
  35. <TYPE? ,.ATM DIRECTION>>>
  36. <PUT .F 1 .ATM>
  37. <COND (<TYPE? <2 .PAIRS> STRING>
  38. <PUT .F 2 <FIND-ROOM <2 .PAIRS>>>)
  39. (<PUT .F 2 <2 .PAIRS>>)>
  40. <SET F <REST .F 2>>)
  41. (T
  42. <PUT .PAIRS 1 <ERROR ILLEGAL-DIRECTION <1 .PAIRS>>>)>
  43. <COND (<EMPTY? <SET PAIRS <REST .PAIRS 2>>>
  44. <RETURN>)>>
  45. <CHTYPE .FROB EXIT>>
  46. <DEFINE ROOM (ID D1 D2 LIT? EX "OPTIONAL" (OBJS ()) (APP <>) (VAL 0) (BIT ,RLANDBIT)
  47. (GLOB 0) "AUX" (RM <FIND-ROOM .ID>))
  48. #DECL ((ID) <OR STRING ATOM> (D1 D2) STRING (LIT?) <OR ATOM FORM FALSE>
  49. (EX) EXIT (APP) <OR FORM FALSE ATOM> (VAL BIT GLOB) FIX (RM) ROOM)
  50. <SETG SCORE-MAX <+ ,SCORE-MAX .VAL>>
  51. <PUT .RM ,RGLOBAL <+ .GLOB ,STAR-BITS>>
  52. <PUT .RM ,RVAL .VAL>
  53. <PUT .RM ,ROBJS .OBJS>
  54. <PUT .RM ,RDESC1 .D1>
  55. <PUT .RM ,RDESC2 .D2>
  56. <PUT .RM ,REXITS .EX>
  57. <PUT .RM ,RACTION <COND (<TYPE? .APP FALSE FORM> <>) (.APP)>>
  58. <COND (<TYPE? .LIT? FALSE FORM>) (ELSE <SET BIT <+ .BIT ,RLIGHTBIT>>)>
  59. <MAPF <>
  60. <FUNCTION (X) #DECL ((X) OBJECT)
  61. <PUT .X ,OROOM .RM>>
  62. <ROBJS .RM>>
  63. <PUT .RM ,RBITS .BIT>
  64. .RM>
  65. <DEFINE SOBJECT (ID STR "TUPLE" TUP)
  66. #DECL ((ID) STRING (TUP) TUPLE)
  67. <OBJECT .ID "" .STR %<> <> () <> <+ !.TUP>>>
  68. <DEFINE AOBJECT (ID STR APP "TUPLE" TUP)
  69. #DECL ((ID) STRING (TUP) TUPLE (APP) ATOM)
  70. <OBJECT .ID "" .STR %<> .APP () <> <+ !.TUP>>>
  71. <DEFINE GOBJECT (IDS STR APP NAM "TUPLE" TUP "AUX" (OBJOB ,OBJECT-OBL) OBJ)
  72. #DECL ((IDS) <VECTOR [REST STRING]> (STR) STRING (APP) <OR ATOM FALSE>
  73. (TUP) TUPLE (OBJ) OBJECT (OBJOB) OBLIST (NAM) <OR FALSE ATOM>)
  74. <SET OBJ <OBJECT <1 .IDS> "" .STR %<> .APP () <> <+ !.TUP>>>
  75. <PUT .OBJ ,OGLOBAL <SETG GLOHI <* ,GLOHI 2>>>
  76. <AND .NAM <SETG .NAM ,GLOHI>>
  77. <MAPF <>
  78. <FUNCTION (X)
  79. #DECL ((X) STRING)
  80. <SETG <OR <LOOKUP .X .OBJOB>
  81. <INSERT .X .OBJOB>> .OBJ>>
  82. <REST .IDS>>
  83. .OBJ>
  84. <DEFINE OBJECT (ID DESC1 DESC2 DESCO APP CONTS CAN FLAGS
  85. "OPTIONAL" (S1 0) (S2 0) (SIZE 5) (CAPAC 0)
  86. "AUX" (OBJ <FIND-OBJ .ID>))
  87. #DECL ((ID) <OR ATOM STRING> (DESC1 DESC2) STRING (APP) <OR FALSE FORM ATOM>
  88. (CONTS) <LIST [REST OBJECT]> (CAN) <OR FALSE OBJECT>
  89. (FLAGS) <PRIMTYPE WORD> (SIZE CAPAC) FIX (OBJ) OBJECT
  90. (S1 S2) FIX (DESCO) <OR STRING FALSE>)
  91. <SETG SCORE-MAX <+ ,SCORE-MAX .S1 .S2>>
  92. <PUT .OBJ ,ODESC1 .DESC1>
  93. <PUT .OBJ ,ODESC2 .DESC2>
  94. <PUT .OBJ ,ODESCO .DESCO>
  95. <PUT .OBJ ,OACTION <COND (<TYPE? .APP FALSE FORM> <>) (.APP)>>
  96. <PUT .OBJ ,OCONTENTS .CONTS>
  97. <PUT .OBJ ,OCAN .CAN>
  98. <PUT .OBJ ,OFLAGS .FLAGS>
  99. <PUT .OBJ ,OFVAL .S1>
  100. <PUT .OBJ ,OTVAL .S2>
  101. <PUT .OBJ ,OSIZE .SIZE>
  102. <PUT .OBJ ,OCAPAC .CAPAC>>
  103. <DEFINE FIND-PREP (STR "AUX" (ATM <ADD-WORD .STR>))
  104. #DECL ((STR) STRING (ATM) <OR FALSE ATOM>)
  105. <COND (<GASSIGNED? .ATM>
  106. <COND (<TYPE? ,.ATM PREP> ,.ATM)
  107. (<ERROR NO-PREP!-ERRORS>)>)
  108. (<SETG .ATM <CHTYPE .ATM PREP>>)>>
  109. <DEFINE ADD-ACTION (NAM STR "TUPLE" DECL
  110. "AUX" (ATM <OR <LOOKUP .NAM ,ACTIONS>
  111. <INSERT .NAM ,ACTIONS>>))
  112. #DECL ((NAM STR) STRING (DECL) <TUPLE [REST VECTOR]> (ATM) ATOM)
  113. <SETG .ATM <CHTYPE [.ATM <MAKE-ACTION !.DECL> .STR] ACTION>>
  114. .ATM>
  115. <DEFINE ADD-DIRECTIONS ("TUPLE" NMS "AUX" (DIR ,DIRECTIONS) ATM)
  116. #DECL ((NMS) <TUPLE [REST STRING]> (DIR) OBLIST (ATM) ATOM)
  117. <MAPF <> <FUNCTION (X) <SETG <SET ATM <OR <LOOKUP .X .DIR> <INSERT .X .DIR>>>
  118. <CHTYPE .ATM DIRECTION>>>
  119. .NMS>>
  120. <DEFINE DSYNONYM (STR "TUPLE" NMS "AUX" VAL (DIR ,DIRECTIONS) ATM)
  121. #DECL ((ATM) ATOM (STR) STRING (NMS) <TUPLE [REST STRING]>
  122. (VAL) DIRECTION (DIR) OBLIST)
  123. <SET VAL <ADD-DIRECTIONS .STR>>
  124. <MAPF <> <FUNCTION (X) <SETG <SET ATM <OR <LOOKUP .X .DIR> <INSERT .X .DIR>>>
  125. .VAL>>
  126. .NMS>>
  127. <DEFINE VSYNONYM (N1 "TUPLE" N2 "AUX" ATM VAL)
  128. #DECL ((N1) STRING (N2) <TUPLE [REST STRING]> (ATM) <OR FALSE ATOM>
  129. (VAL) ANY)
  130. <COND (<SET ATM <LOOKUP .N1 ,WORDS>>
  131. <SET VAL ,.ATM>
  132. <MAPF <> <FUNCTION (X) <SETG <ADD-WORD .X> .VAL>> .N2>)>
  133. <COND (<SET ATM <LOOKUP .N1 ,ACTIONS>>
  134. <SET VAL ,.ATM>
  135. <MAPF <> <FUNCTION (X) <SETG <OR <LOOKUP .X ,ACTIONS>
  136. <INSERT .X ,ACTIONS>>
  137. .VAL>> .N2>)>>
  138. "STUFF FOR ADDING TO VOCABULARY, ADDING TO LISTS (OF DEMONS, FOR EXAMPLE)."
  139. <DEFINE ADD-WORD (W)
  140. #DECL ((W) STRING)
  141. <OR <LOOKUP .W ,WORDS> <INSERT .W ,WORDS>>>
  142. <DEFINE ADD-BUZZ ("TUPLE" W)
  143. #DECL ((W) <TUPLE [REST STRING]>)
  144. <MAPF <>
  145. <FUNCTION (X)
  146. #DECL ((X) STRING)
  147. <SETG <ADD-WORD .X> <CHTYPE .X BUZZ>>>
  148. .W>>
  149. <DEFINE ADD-ZORK (NM "TUPLE" W)
  150. #DECL ((NM) ATOM (W) <TUPLE [REST STRING]>)
  151. <MAPF <>
  152. <FUNCTION (X "AUX" ATM)
  153. #DECL ((X) STRING (ATM) ATOM)
  154. <SETG <SET ATM <ADD-WORD .X>> <CHTYPE .ATM .NM>>>
  155. .W>>
  156. <DEFINE ADD-OBJECT (OBJ NAMES "OPTIONAL" (ADJ '[]) "AUX" (OBJS ,OBJECT-OBL))
  157. #DECL ((OBJ) OBJECT (NAMES ADJ) <VECTOR [REST STRING]> (OBJS) OBLIST)
  158. <PUT .OBJ
  159. ,ONAMES
  160. <MAPF ,UVECTOR
  161. <FUNCTION (X)
  162. #DECL ((X) STRING)
  163. <OR <LOOKUP .X .OBJS> <INSERT .X .OBJS>>>
  164. .NAMES>>
  165. <PUT .OBJ ,OADJS <MAPF ,UVECTOR <FUNCTION (W) <ADD-ZORK ADJECTIVE .W>> .ADJ>>
  166. <CHUTYPE <OADJS .OBJ> ADJECTIVE>
  167. .OBJ>
  168. <DEFINE SYNONYM (N1 "TUPLE" N2 "AUX" ATM VAL)
  169. #DECL ((N1) STRING (N2) <TUPLE [REST STRING]> (ATM) <OR FALSE ATOM>
  170. (VAL) ANY)
  171. <COND (<SET ATM <LOOKUP .N1 ,WORDS>>
  172. <SET VAL ,.ATM>
  173. <MAPF <> <FUNCTION (X) <SETG <ADD-WORD .X> .VAL>> .N2>)>>
  174. <DEFINE ADD-ABBREV (X Y "AUX")
  175. #DECL ((X Y) STRING)
  176. <SETG <ADD-WORD .X> <OR <LOOKUP .Y ,WORDS> <INSERT .Y ,WORDS>>>>
  177. <DEFINE ADD-DEMON (X) #DECL ((X) HACK)
  178. <COND (<MAPR <>
  179. <FUNCTION (Y) #DECL ((Y) <LIST [REST HACK]>)
  180. <COND (<==? <HACTION <1 .Y>> <HACTION .X>>
  181. <PUT .Y 1 .X>
  182. <MAPLEAVE T>)>>
  183. ,DEMONS>)
  184. (<SETG DEMONS (.X !,DEMONS)>)>>
  185. <DEFINE ADD-STAR (OBJ)
  186. <SETG STAR-BITS <+ ,STAR-BITS <OGLOBAL .OBJ>>>>
  187. <DEFINE ADD-ACTOR (ADV "AUX" (ACTORS ,ACTORS))
  188. #DECL ((ADV) ADV (ACTORS) <LIST [REST ADV]>)
  189. <COND (<MAPF <>
  190. <FUNCTION (X) #DECL ((X) ADV)
  191. <COND (<==? <AOBJ .X> <AOBJ .ADV>>
  192. <MAPLEAVE T>)>>
  193. .ACTORS>)
  194. (<SETG ACTORS (.ADV !.ACTORS)>)>
  195. .ADV>
  196. <DEFINE ADD-DESC (OBJ STR)
  197. #DECL ((OBJ) OBJECT (STR) STRING)
  198. <PUT .OBJ ,OREAD .STR>>
  199. <DEFINE SADD-ACTION (STR1 ATM)
  200. <ADD-ACTION .STR1 "" [[.STR1 .ATM]]>>
  201. <DEFINE 1ADD-ACTION (STR1 STR2 ATM)
  202. <ADD-ACTION .STR1 .STR2 [OBJ [.STR1 .ATM]]>>
  203. "MAKE-ACTION: Function for creating a verb. Takes;
  204. vspec => [objspec {\"prep\"} {objspec} [atom!-WORDS fcn] extras]
  205. objspec => OBJ | objlist
  206. objlist => ( objbits {fwimbits} {NO-TAKE} {MUST-HAVE} {TRY-TAKE} {=} )
  207. extras => DRIVER FLIP
  208. Creates a VSPEC.
  209. "
  210. <DEFINE MAKE-ACTION ("TUPLE" SPECS "AUX" VV SUM (PREP <>) ATM)
  211. #DECL ((SPECS) TUPLE (VV) <PRIMTYPE VECTOR> (SUM) FIX (PREP ATM) ANY)
  212. <CHTYPE
  213. <MAPF ,UVECTOR
  214. <FUNCTION (SP "AUX" (SYN <VECTOR <> <> <> 0>) (WHR 1))
  215. #DECL ((SP) VECTOR (SYN) VECTOR (WHR) FIX)
  216. <MAPF <>
  217. <FUNCTION (ITM)
  218. #DECL ((ITM) ANY)
  219. <COND (<TYPE? .ITM STRING> <SET PREP <FIND-PREP .ITM>>)
  220. (<AND <==? .ITM OBJ> <SET ITM '(-1 ROBJS AOBJS)> <>>)
  221. (<TYPE? .ITM LIST>
  222. <SET VV <IVECTOR 4>>
  223. <PUT .VV ,VBIT <1 .ITM>>
  224. <COND (<AND <NOT <LENGTH? .ITM 1>> <TYPE? <2 .ITM> FIX>>
  225. <PUT .VV ,VFWIM <2 .ITM>>)
  226. (ELSE
  227. <PUT .VV ,VBIT -1>
  228. <PUT .VV ,VFWIM <1 .ITM>>)>
  229. <AND <MEMQ = .ITM> <PUT .VV ,VBIT <VFWIM .VV>>>
  230. <PUT .VV ,VPREP .PREP>
  231. <SET SUM 0>
  232. <SET PREP <>>
  233. <AND <MEMQ AOBJS .ITM> <SET SUM <+ .SUM ,VABIT>>>
  234. <AND <MEMQ ROBJS .ITM> <SET SUM <+ .SUM ,VRBIT>>>
  235. <AND <MEMQ NO-TAKE .ITM> <SET SUM .SUM>>
  236. <AND <MEMQ HAVE .ITM> <SET SUM <+ .SUM ,VCBIT>>>
  237. <AND <MEMQ TRY .ITM> <SET SUM <+ .SUM ,VTBIT>>>
  238. <AND <MEMQ TAKE .ITM> <SET SUM <+ .SUM ,VTBIT ,VCBIT>>>
  239. <PUT .VV ,VWORD .SUM>
  240. <PUT .SYN .WHR <CHTYPE .VV VARG>>
  241. <SET WHR <+ .WHR 1>>)
  242. (<TYPE? .ITM VECTOR>
  243. <COND (<GASSIGNED? <SET ATM <ADD-WORD <1 .ITM>>>>
  244. <PUT .SYN ,SFCN ,.ATM>)
  245. (<PUT .SYN
  246. ,SFCN
  247. <SETG <SET ATM <ADD-WORD <1 .ITM>>>
  248. <CHTYPE [.ATM <2 .ITM>] VERB>>>)>)
  249. (<==? .ITM DRIVER>
  250. <PUT .SYN ,SFLAGS <CHTYPE <ORB <SFLAGS .SYN> ,SDRIVER> FIX>>)
  251. (<==? .ITM FLIP>
  252. <PUT .SYN ,SFLAGS <CHTYPE <ORB <SFLAGS .SYN> ,SFLIP> FIX>>)>>
  253. .SP>
  254. <OR <SYN1 .SYN> <PUT .SYN ,SYN1 ,EVARG>>
  255. <OR <SYN2 .SYN> <PUT .SYN ,SYN2 ,EVARG>>
  256. <CHTYPE .SYN SYNTAX>>
  257. .SPECS>
  258. VSPEC>>
  259. "Default value for syntax slots not specified"
  260. <SETG EVARG <CHTYPE [0 0 <> 0] VARG>>
  261. <GDECL (EVARG) VARG>
  262. ; "To add VERBs to the BUNCHERS list"
  263. <DEFINE ADD-BUNCHER ("TUPLE" STRS)
  264. #DECL ((STRS) <TUPLE [REST STRING]>)
  265. <MAPF <>
  266. <FUNCTION (STR)
  267. #DECL ((STR) STRING)
  268. <SETG BUNCHERS
  269. (,<LOOKUP .STR <GET WORDS OBLIST>> !,BUNCHERS)>>
  270. .STRS>>