home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume18 / dunnet2 / part03 < prev    next >
Encoding:
Text File  |  1993-07-11  |  13.1 KB  |  451 lines

  1. Path: uunet!news.tek.com!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v18i013:  dunnet2 - emacs-lisp text adventure, Ver 2, Part03/03
  5. Date: 10 Jul 1993 22:59:05 GMT
  6. Organization: Tektronix, Inc, Redmond, OR, USA
  7. Lines: 438
  8. Approved: billr@saab.CNA.TEK.COM
  9. Message-ID: <21nhjp$q4i@ying.cna.tek.com>
  10. NNTP-Posting-Host: saab.cna.tek.com
  11. Xref: uunet comp.sources.games:1813
  12.  
  13. Submitted-by: ronnie@media.mit.edu
  14. Posting-number: Volume 18, Issue 13
  15. Archive-name: dunnet2/part03
  16. Supersedes: dunnet: Volume 14, Issue 28-29
  17. Environment: Emacs
  18.  
  19.  
  20.  
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of archive 3 (of 3)."
  28. # Contents:  COPYRIGHT LCD-entry dun-util.el dunnet dunnet.curdir
  29. #   dunnet.window dunnet.window.curdir
  30. # Wrapped by billr@saab on Sat Jul 10 15:54:31 1993
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  34. else
  35. echo shar: Extracting \"'COPYRIGHT'\" \(941 characters\)
  36. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  37. X
  38. X;; dunnet - elisp text adventure game.  The following applies to
  39. X;;           these files contained in this archive:
  40. X;;              dun-batch.el
  41. X;;              dun-commands.el
  42. X;;              dun-dos.el
  43. X;;              dun-globals.el
  44. X;;              dun-main.el
  45. X;;              dun-save.el
  46. X;;              dun-unix.el
  47. X;;              dun-util.el
  48. X
  49. X;; Copyright (C) 1992, 1993 by Ron Schnell
  50. X;; (ronnie@media.mit.edu)
  51. X
  52. X;; This software is not part of GNU Emacs.
  53. X
  54. X;; It is distributed in the hope that it will be fun.
  55. X;; It is without any warranty.  No author or distributor
  56. X;; accepts responsibility to anyone for the consequences of using it
  57. X;; or for whether it serves any particular purpose, or works at all.
  58. X
  59. X;; Everyone is granted permission to copy, modify, and redistribute
  60. X;; this software, but only so long as it is not for commercial
  61. X;; purposes.
  62. X
  63. X;; This file must be distributed along with all copies, in an unmodified
  64. X;; form.
  65. END_OF_FILE
  66. if test 941 -ne `wc -c <'COPYRIGHT'`; then
  67.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  68. fi
  69. # end of 'COPYRIGHT'
  70. fi
  71. if test -f 'LCD-entry' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'LCD-entry'\"
  73. else
  74. echo shar: Extracting \"'LCD-entry'\" \(133 characters\)
  75. sed "s/^X//" >'LCD-entry' <<'END_OF_FILE'
  76. X;; LCD Archive Entry:
  77. X;; dunnet|Ron Schnell|ronnie@media.mit.edu
  78. X;; |Text adventure.
  79. X;; |93-06-30|Version: 2.0|~/games/dunnet.tar.Z|
  80. END_OF_FILE
  81. if test 133 -ne `wc -c <'LCD-entry'`; then
  82.     echo shar: \"'LCD-entry'\" unpacked with wrong size!
  83. fi
  84. # end of 'LCD-entry'
  85. fi
  86. if test -f 'dun-util.el' -a "${1}" != "-c" ; then 
  87.   echo shar: Will not clobber existing file \"'dun-util.el'\"
  88. else
  89. echo shar: Extracting \"'dun-util.el'\" \(7561 characters\)
  90. sed "s/^X//" >'dun-util.el' <<'END_OF_FILE'
  91. X(require 'cl)
  92. X(require 'rnews)
  93. X
  94. X;;;;;;;;;;;;;;;;;;;;; Utility functions
  95. X
  96. X(if nil
  97. X    (eval-and-compile (setq byte-compile-warnings nil)))
  98. X
  99. X;;; Function which takes a verb and a list of other words.  Calls proper
  100. X;;; function associated with the verb, and passes along the other words.
  101. X
  102. X(defun doverb (ignore verblist verb rest)
  103. X  (if (not verb)
  104. X      nil
  105. X    (if (member (intern verb) ignore)
  106. X    (if (not (car rest)) -1
  107. X      (doverb ignore verblist (car rest) (cdr rest)))
  108. X      (if (not (cdr (assq (intern verb) verblist))) -1
  109. X    (setq numcmds (1+ numcmds))
  110. X    (eval (list (cdr (assq (intern verb) verblist)) (quote rest)))))))
  111. X
  112. X
  113. X;;; Function to take a string and change it into a list of lowercase words.
  114. X
  115. X(defun listify-string (strin)
  116. X  (let (pos ret-list end-pos)
  117. X    (setq pos 0)
  118. X    (setq ret-list nil)
  119. X    (while (setq end-pos (string-match "[ ,:;]" (substring strin pos)))
  120. X      (setq end-pos (+ end-pos pos))
  121. X      (if (not (= end-pos pos))
  122. X      (setq ret-list (append ret-list (list 
  123. X                       (downcase
  124. X                        (substring strin pos end-pos))))))
  125. X      (setq pos (+ end-pos 1))) ret-list))
  126. X
  127. X(defun listify-string2 (strin)
  128. X  (let (pos ret-list end-pos)
  129. X    (setq pos 0)
  130. X    (setq ret-list nil)
  131. X    (while (setq end-pos (string-match " " (substring strin pos)))
  132. X      (setq end-pos (+ end-pos pos))
  133. X      (if (not (= end-pos pos))
  134. X      (setq ret-list (append ret-list (list 
  135. X                       (downcase
  136. X                        (substring strin pos end-pos))))))
  137. X      (setq pos (+ end-pos 1))) ret-list))
  138. X
  139. X(defun replace (list n number)
  140. X  (rplaca (nthcdr n list) number))
  141. X
  142. X
  143. X;;; Get the first non-ignored word from a list.
  144. X
  145. X(defun firstword (list)
  146. X  (if (not (car list))
  147. X      nil
  148. X    (while (and list (member (intern (car list)) ignore))
  149. X      (setq list (cdr list)))
  150. X    (car list)))
  151. X
  152. X(defun firstwordl (list)
  153. X  (if (not (car list))
  154. X      nil
  155. X    (while (and list (member (intern (car list)) ignore))
  156. X      (setq list (cdr list)))
  157. X    list))
  158. X
  159. X;; parse a line passed in as a string  Call the proper verb with the
  160. X;; rest of the line passed in as a list.
  161. X
  162. X(defun parse (ignore verblist line)
  163. X  (mprinc "\n")
  164. X  (setq line-list (listify-string (concat line " ")))
  165. X  (doverb ignore verblist (car line-list) (cdr line-list)))
  166. X
  167. X(defun parse2 (ignore verblist line)
  168. X  (mprinc "\n")
  169. X  (setq line-list (listify-string2 (concat line " ")))
  170. X  (doverb ignore verblist (car line-list) (cdr line-list)))
  171. X
  172. X;; Read a line, in window mode
  173. X
  174. X(defun read-line ()
  175. X  (let (line)
  176. X    (setq line (read-string ""))
  177. X    (mprinc line) line))
  178. X
  179. X;; Insert something into the window buffer
  180. X
  181. X(defun minsert (string)
  182. X  (if (stringp string)
  183. X      (insert string)
  184. X    (insert (prin1-to-string string))))
  185. X
  186. X;; Print something out, in window mode
  187. X
  188. X(defun mprinc (string)
  189. X  (if (stringp string)
  190. X      (insert string)
  191. X    (insert (prin1-to-string string))))
  192. X
  193. X;; In window mode, keep screen from jumping by keeping last line at
  194. X;; the bottom of the screen.
  195. X
  196. X(defun fix-screen ()
  197. X  (interactive)
  198. X  (forward-line (- 0 (- (window-height) 2 )))
  199. X  (set-window-start (selected-window) (point))
  200. X  (end-of-buffer))
  201. X
  202. X;; Insert something into the buffer, followed by newline.
  203. X
  204. X(defun minsertl (string)
  205. X  (minsert string)
  206. X  (minsert "\n"))
  207. X
  208. X;; Print something, followed by a newline.
  209. X
  210. X(defun mprincl (string)
  211. X  (mprinc string)
  212. X  (mprinc "\n"))
  213. X
  214. X;;;; Function which will get an object number given the list of
  215. X;;;; words in the command, except for the verb.
  216. X
  217. X(defun objnum-from-args (obj)
  218. X  (let (objnum)
  219. X    (setq obj (firstword obj))
  220. X    (if (not obj)
  221. X    obj-special
  222. X      (setq objnum (cdr (assq (intern obj) objnames))))))
  223. X
  224. X(defun objnum-from-args-std (obj)
  225. X  (let (result)
  226. X  (if (eq (setq result (objnum-from-args obj)) obj-special)
  227. X      (mprincl "You must supply an object."))
  228. X  (if (eq result nil)
  229. X      (mprincl "I don't know what that is."))
  230. X  (if (eq result obj-special)
  231. X      nil
  232. X    result)))
  233. X
  234. X;; Take a short room description, and change spaces and slashes to dashes.
  235. X
  236. X(defun space-to-hyphen (string)
  237. X  (let (space)
  238. X    (if (setq space (string-match "[ /]" string))
  239. X    (progn
  240. X      (setq string (concat (substring string 0 space) "-"
  241. X                   (substring string (1+ space))))
  242. X      (space-to-hyphen string))
  243. X      string)))
  244. X
  245. X;; Given a unix style pathname, build a list of path components (recursive)
  246. X
  247. X(defun get-path (dirstring startlist)
  248. X  (let (slash pos)
  249. X    (if (= (length dirstring) 0)
  250. X    startlist
  251. X      (if (string= (substring dirstring 0 1) "/")
  252. X      (get-path (substring dirstring 1) (append startlist (list "/")))
  253. X    (if (not (setq slash (string-match "/" dirstring)))
  254. X        (append startlist (list dirstring))
  255. X      (get-path (substring dirstring (1+ slash))
  256. X            (append startlist
  257. X                (list (substring dirstring 0 slash)))))))))
  258. X
  259. X
  260. X;; Is a string a member of a string list?
  261. X
  262. X(defun members (string string-list)
  263. X  (let (found)
  264. X    (setq found nil)
  265. X    (dolist (x string-list)
  266. X      (if (string= x string)
  267. X      (setq found t))) found))
  268. X
  269. X;; Function to put objects in the treasure room.  Also prints current
  270. X;; score to let user know he has scored.
  271. X
  272. X(defun put-objs-in-treas (objlist)
  273. X  (let (oscore newscore)
  274. X    (setq oscore (reg-score))
  275. X    (replace room-objects 0 (append (nth 0 room-objects) objlist))
  276. X    (setq newscore (reg-score))
  277. X    (if (not (= oscore newscore))
  278. X    (score nil))))
  279. X
  280. X;; Load an encrypted file, and eval it.
  281. X
  282. X(defun load-d (filename)
  283. X  (let (old-buffer result)
  284. X    (setq result t)
  285. X    (setq old-buffer (current-buffer))
  286. X    (switch-to-buffer (get-buffer-create "*loadc*"))
  287. X    (erase-buffer)
  288. X    (condition-case nil
  289. X    (insert-file-contents filename)
  290. X      (error (setq result nil)))
  291. X    (unless (not result)
  292. X      (condition-case nil
  293. X      (dun-rot13)
  294. X    (error (yank)))
  295. X      (eval-current-buffer)
  296. X      (kill-buffer (current-buffer))
  297. X      (switch-to-buffer old-buffer))
  298. X    result))
  299. X
  300. X;; Rotate the globals file, and save it for later loading.
  301. X
  302. X(defun compile-globals ()
  303. X  (let
  304. X    (switch-to-buffer (get-buffer-create "*compd*"))
  305. X    (erase-buffer)
  306. X    (insert-file-contents "dun-globals.el")
  307. X    (dun-rot13)
  308. X    (goto-char (point-min))
  309. X    (write-region 1 (point-max) "dun-globals.dat")
  310. X    (kill-buffer (current-buffer))))
  311. X
  312. X;; Functions to remove an object either from a room, or from inventory.
  313. X
  314. X(defun remove-obj-from-room (room objnum)
  315. X  (let (newroom)
  316. X    (setq newroom nil)
  317. X    (dolist (x (nth room room-objects))
  318. X      (if (not (= x objnum))
  319. X      (setq newroom (append newroom (list x)))))
  320. X    (rplaca (nthcdr room room-objects) newroom)))
  321. X
  322. X(defun remove-obj-from-inven (objnum)
  323. X  (let (new-inven)
  324. X    (setq new-inven nil)
  325. X    (dolist (x inventory)
  326. X      (if (not (= x objnum))
  327. X      (setq new-inven (append new-inven (list x)))))
  328. X    (setq inventory new-inven)))
  329. X
  330. X;; Find the global data file.
  331. X
  332. X(defun get-glob-dat ()
  333. X  (let (result)
  334. X    (setq result nil)
  335. X    (dolist (x load-path)
  336. X        (if (file-exists-p (concat x "/dun-globals.dat"))
  337. X        (setq result (concat x "/dun-globals.dat"))))
  338. X    result))
  339. X
  340. X;; rotate current buffer 13 characters
  341. X(let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
  342. X  (setq translate-table (make-vector 256 0))
  343. X  (while (< i 256)
  344. X    (aset translate-table i i)
  345. X    (setq i (1+ i)))
  346. X  (setq lower (concat lower lower))
  347. X  (setq upper (upcase lower))
  348. X  (setq i 0)
  349. X  (while (< i 26)
  350. X    (aset translate-table (+ ?a i) (aref lower (+ i 13)))
  351. X    (aset translate-table (+ ?A i) (aref upper (+ i 13)))
  352. X      (setq i (1+ i))))
  353. X  
  354. X(defun dun-rot13 ()
  355. X  (let (str len (i 0))
  356. X    (setq str (buffer-substring (point-min) (point-max)))
  357. X    (setq len (length str))
  358. X    (while (< i len)
  359. X      (aset str i (aref translate-table (aref str i)))
  360. X      (setq i (1+ i)))
  361. X    (erase-buffer)
  362. X    (insert str)))
  363. END_OF_FILE
  364. if test 7561 -ne `wc -c <'dun-util.el'`; then
  365.     echo shar: \"'dun-util.el'\" unpacked with wrong size!
  366. fi
  367. chmod +x 'dun-util.el'
  368. # end of 'dun-util.el'
  369. fi
  370. if test -f 'dunnet' -a "${1}" != "-c" ; then 
  371.   echo shar: Will not clobber existing file \"'dunnet'\"
  372. else
  373. echo shar: Extracting \"'dunnet'\" \(55 characters\)
  374. sed "s/^X//" >'dunnet' <<'END_OF_FILE'
  375. X#! /bin/sh
  376. X
  377. X    emacs -batch -l dun-main -f batch-dungeon
  378. END_OF_FILE
  379. if test 55 -ne `wc -c <'dunnet'`; then
  380.     echo shar: \"'dunnet'\" unpacked with wrong size!
  381. fi
  382. chmod +x 'dunnet'
  383. # end of 'dunnet'
  384. fi
  385. if test -f 'dunnet.curdir' -a "${1}" != "-c" ; then 
  386.   echo shar: Will not clobber existing file \"'dunnet.curdir'\"
  387. else
  388. echo shar: Extracting \"'dunnet.curdir'\" \(61 characters\)
  389. sed "s/^X//" >'dunnet.curdir' <<'END_OF_FILE'
  390. X#! /bin/sh
  391. X
  392. X    emacs -batch -l `pwd`/dun-main -f batch-dungeon
  393. END_OF_FILE
  394. if test 61 -ne `wc -c <'dunnet.curdir'`; then
  395.     echo shar: \"'dunnet.curdir'\" unpacked with wrong size!
  396. fi
  397. chmod +x 'dunnet.curdir'
  398. # end of 'dunnet.curdir'
  399. fi
  400. if test -f 'dunnet.window' -a "${1}" != "-c" ; then 
  401.   echo shar: Will not clobber existing file \"'dunnet.window'\"
  402. else
  403. echo shar: Extracting \"'dunnet.window'\" \(50 characters\)
  404. sed "s/^X//" >'dunnet.window' <<'END_OF_FILE'
  405. X#! /bin/sh
  406. X
  407. X    emacs -l dun-main -f dungeon-start
  408. X
  409. X
  410. END_OF_FILE
  411. if test 50 -ne `wc -c <'dunnet.window'`; then
  412.     echo shar: \"'dunnet.window'\" unpacked with wrong size!
  413. fi
  414. chmod +x 'dunnet.window'
  415. # end of 'dunnet.window'
  416. fi
  417. if test -f 'dunnet.window.curdir' -a "${1}" != "-c" ; then 
  418.   echo shar: Will not clobber existing file \"'dunnet.window.curdir'\"
  419. else
  420. echo shar: Extracting \"'dunnet.window.curdir'\" \(56 characters\)
  421. sed "s/^X//" >'dunnet.window.curdir' <<'END_OF_FILE'
  422. X#! /bin/sh
  423. X
  424. X    emacs -l `pwd`/dun-main -f dungeon-start
  425. X
  426. X
  427. END_OF_FILE
  428. if test 56 -ne `wc -c <'dunnet.window.curdir'`; then
  429.     echo shar: \"'dunnet.window.curdir'\" unpacked with wrong size!
  430. fi
  431. chmod +x 'dunnet.window.curdir'
  432. # end of 'dunnet.window.curdir'
  433. fi
  434. echo shar: End of archive 3 \(of 3\).
  435. cp /dev/null ark3isdone
  436. MISSING=""
  437. for I in 1 2 3 ; do
  438.     if test ! -f ark${I}isdone ; then
  439.     MISSING="${MISSING} ${I}"
  440.     fi
  441. done
  442. if test "${MISSING}" = "" ; then
  443.     echo You have unpacked all 3 archives.
  444.     rm -f ark[1-9]isdone
  445. else
  446.     echo You still need to unpack the following archives:
  447.     echo "        " ${MISSING}
  448. fi
  449. ##  End of shell archive.
  450. exit 0
  451.