home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-28 | 28.7 KB | 1,046 lines |
- Path: sparky!uunet!olivea!news.bbn.com!micro-heart-of-gold.mit.edu!mit-eddie!eddie.mit.edu!ronnie
- From: ronnie@eddie.mit.edu (Ron Schnell)
- Newsgroups: gnu.emacs.sources
- Subject: dunnet - text adventure for e-lisp (3/3)
- Message-ID: <1992Jul29.012500.19123@eddie.mit.edu>
- Date: 29 Jul 92 01:25:00 GMT
- Sender: news@eddie.mit.edu (Usenet News)
- Reply-To: ronnie@eddie.mit.edu (Ron Schnell)
- Organization: MIT EECS/ECF Facility, Cambridge Mass
- Lines: 1034
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # dun-main.el
- # dun-save.el
- # dun-unix.el
- # dun-util.el
- # This archive created: Tue Jul 28 14:48:24 1992
- export PATH; PATH=/bin:$PATH
- if test -f 'dun-main.el'
- then
- echo shar: will not over-write existing file "'dun-main.el'"
- else
- cat << \SHAR_EOF > 'dun-main.el'
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; ;
- ; dunnet.el Version 1.0 ;
- ; ;
- ; Ron Schnell (ronnie@eddie.mit.edu) ;
- ; ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- ;; This is the startup file. It loads in the other files, and sets up
- ;; the functions to be bound to keys if you play in window-mode.
-
- ;;;;; The log file should be set for your system, and it must
- ;;;;; be writeable by all.
-
- (setq log-file "/user0/rschnell/score/score")
-
- (defun dungeon-mode ()
- "Major mode for running dungeon"
- (interactive)
- (text-mode)
- (use-local-map dungeon-mode-map)
- (setq major-mode 'dungeon-mode)
- (setq mode-name "Dungeon")
- )
-
- (defun dungeon-parse (arg)
- "foo"
- (interactive "*p")
- (beginning-of-line)
- (setq beg (+ (point) 1))
- (end-of-line)
- (if (and (not (= beg (point)))
- (string= ">" (buffer-substring (- beg 1) beg)))
- (progn
- (setq line (downcase (buffer-substring beg (point))))
- (princ line)
- (if (eq (parse ignore verblist line) -1)
- (mprinc "I don't understand that.\n")))
- (goto-char (point-max))
- (mprinc "\n"))
- (dungeon-messages))
-
- (defun dungeon-messages ()
- (if dead
- (text-mode)
- (if (eq dungeon-mode 'dungeon)
- (progn
- (if (not (= room current-room))
- (progn
- (describe-room current-room)
- (setq room current-room)))
- (mprinc ">")))))
-
- (defun dungeon-start ()
- (interactive)
- (switch-to-buffer "*dungeon*")
- (dungeon-mode)
- (setq dead nil)
- (setq room 0)
- (dungeon-messages))
-
- (require 'cl)
-
- (defun batch-dungeon ()
- (setq load-path (append load-path (list ".")))
- (load "dun-batch")
- (setq visited '(27))
- (mprinc "\n")
- (dungeon-batch-loop))
-
- (setq load-path (append load-path (list ".")))
-
- (load "dun-commands")
- (load "dun-util")
- (if (setq glob (get-glob-dat))
- (load-d glob)
- (load "dun-globals"))
-
- (load "dun-unix")
- (load "dun-save")
- (setq tloc (+ 60 (% (abs (random)) 18)))
- (replace room-objects tloc (append (nth tloc room-objects) (list 18)))
- (dungeon-start)
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'dun-save.el'
- then
- echo shar: will not over-write existing file "'dun-save.el'"
- else
- cat << \SHAR_EOF > 'dun-save.el'
-
- ;;;;;;;;;;;;;;;;;;;
- ;
- ;
- ; Save and restore
- ;
- ;
- ;;;;;;;;;;;;;;;;;;;
-
- (defun save-game (filename)
- (if (not (setq filename (car filename)))
- (mprincl "You must supply a filename for the save.")
- (if (file-exists-p filename)
- (mprincl "File already exists.")
- (setq numsaves (1+ numsaves))
- (make-save-buffer)
- (save-val "current-room")
- (save-val "computer")
- (save-val "door1")
- (save-val "visited")
- (save-val "diggables")
- (save-val "key-level")
- (save-val "numsaves")
- (save-val "numcmds")
- (save-val "logged-in")
- (save-val "dungeon-mode")
- (save-val "jar")
- (save-val "lastdir")
- (save-val "black")
- (save-val "nomail")
- (save-val "unix-verbs")
- (save-val "hole")
- (save-val "uncompressed")
- (save-val "ethernet")
- (save-val "sauna-level")
- (save-val "room-objects")
- (save-val "room-silents")
- (save-val "inventory")
- (save-val "endgame-question")
- (save-val "endgame")
- (save-val "endgame-questions")
- (save-val "cdroom")
- (save-val "cdpath")
- (save-val "correct-answer")
- (save-val "inbus")
- (compile-save-out filename)
- (do-logfile 'save nil)
- (switch-to-buffer "*dungeon*")
- (princ "")
- (mprincl "Done."))))
-
- (defun make-save-buffer ()
- (switch-to-buffer (get-buffer-create "*save-dungeon*"))
- (erase-buffer))
-
- ;; If you don't have the crypt program, rename this function to
- ;; compile-save-out, and get rid of the next function.
-
- (defun compile-save-out-nocrypt (filename)
- (write-region 1 (point-max) filename nil 1)
- (kill-buffer (current-buffer)))
-
- (defun compile-save-out (filename)
- (let (key dir ferror)
- (setq ferror nil)
- (if (< lastdir 10)
- (setq dir (+ lastdir 10))
- (setq dir lastdir))
- (setq key (prin1-to-string dir))
- (condition-case nil
- (crypt-buffer key)
- (error (setq ferror t)))
- (if (not ferror)
- (progn
- (goto-char (point-min))
- (insert key)))
- (write-region 1 (point-max) filename nil 1)
- (kill-buffer (current-buffer))))
-
- (defun save-val (varname)
- (let (value)
- (setq varname (intern varname))
- (setq value (eval varname))
- (minsert "(setq ")
- (minsert varname)
- (minsert " ")
- (if (or (listp value)
- (symbolp value))
- (minsert "'"))
- (if (stringp value)
- (minsert "\""))
- (minsert value)
- (if (stringp value)
- (minsert "\""))
- (minsertl ")")))
-
-
- ;; If you don't have the crypt program, rename this function to 'restore'
- ;; and get rid of the next function.
-
- (defun restore-nocrypt (args)
- (let (file ferrror)
- (setq ferr nil)
- (if (not (setq file (car args)))
- (mprincl "You must supply a filename.")
- (condition-case nil
- (load-file file)
- (error (setq ferror t)))
- (if ferror
- (mprinc "Could not load restore file.")
- (mprincl "Done.")
- (setq room 0)))))
-
- (defun restore (args)
- (let (file)
- (if (not (setq file (car args)))
- (mprincl "You must supply a filename.")
- (if (not (load-d file))
- (mprincl "Could not load restore file.")
- (mprincl "Done.")
- (setq room 0)))))
-
-
- (defun do-logfile (type how)
- (let (ferror)
- (setq ferror nil)
- (switch-to-buffer (get-buffer-create "*score*"))
- (erase-buffer)
- (condition-case nil
- (insert-file-contents log-file)
- (error (setq ferror t)))
- (unless ferror
- (goto-char (point-max))
- (minsert (user-login-name))
- (minsert " ")
- (if (eq type 'save)
- (minsert "saved ")
- (if (= (endgame-score) 110)
- (minsert "won ")
- (if (not how)
- (minsert "quit ")
- (minsert "killed by ")
- (minsert how)
- (minsert " "))))
- (minsert "at ")
- (minsert (cadr (nth (abs room) rooms)))
- (minsert ". score: ")
- (if (> (endgame-score) 0)
- (minsert (setq newscore (+ 90 (endgame-score))))
- (minsert (setq newscore (reg-score))))
- (minsert " saves: ")
- (minsert numsaves)
- (minsert " commands: ")
- (minsert numcmds)
- (minsert "\n")
- (write-region 1 (point-max) log-file nil 1))
- (kill-buffer (current-buffer))))
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'dun-unix.el'
- then
- echo shar: will not over-write existing file "'dun-unix.el'"
- else
- cat << \SHAR_EOF > 'dun-unix.el'
- ;;;;;;;;;;;;;;;;;;;
- ;;;;
- ;;;; UNIX
- ;;;;
- ;;;;;;;;;;;;;;;;;;;
-
- (defun unix-parse (args)
- (interactive "*p")
- (beginning-of-line)
- (let (beg esign)
- (setq beg (+ (point) 2))
- (end-of-line)
- (if (and (not (= beg (point)))
- (string= "$" (buffer-substring (- beg 2) (- beg 1))))
- (progn
- (setq line (downcase (buffer-substring beg (point))))
- (princ line)
- (if (eq (parse2 nil unix-verbs line) -1)
- (progn
- (if (setq esign (string-match "=" line))
- (doassign line)
- (mprinc (car line-list))
- (mprincl ": not found.")))))
- (goto-char (point-max))
- (mprinc "\n"))
- (if (eq dungeon-mode 'unix)
- (mprinc "$ "))))
-
- (defun doassign (line)
- (if (not wizard)
- (let (passwd)
- (mprinc "Enter wizard password: ")
- (setq passwd (read-line))
- (if (not batch-mode)
- (mprinc "\n"))
- (if (string= passwd "moby")
- (progn
- (setq wizard t)
- (doassign line))
- (mprincl "Incorrect.")))
-
- (let (varname epoint afterq i value)
- (setq varname (substring line 0 esign))
- (if (not (setq epoint (string-match ")" line)))
- (if (string= (substring line (1+ esign) (+ esign 2))
- "\"")
- (progn
- (setq afterq (substring line (+ esign 2)))
- (setq epoint (+
- (string-match "\"" afterq)
- (+ esign 3))))
-
- (if (not (setq epoint (string-match " " line)))
- (setq epoint (length line))))
- (setq epoint (1+ epoint))
- (while (and
- (not (= epoint (length line)))
- (setq i (string-match ")" (substring line epoint))))
- (setq epoint (+ epoint i 1))))
- (setq value (substring line (1+ esign) epoint))
- (dungeon-eval varname value))))
-
- (defun dungeon-eval (varname value)
- (let (eval-error)
- (switch-to-buffer (get-buffer-create "*dungeon-eval*"))
- (erase-buffer)
- (insert "(setq ")
- (insert varname)
- (insert " ")
- (insert value)
- (insert ")")
- (setq eval-error nil)
- (condition-case nil
- (eval-current-buffer)
- (error (setq eval-error t)))
- (kill-buffer (current-buffer))
- (switch-to-buffer "*dungeon*")
- (if eval-error
- (mprincl "Invalid syntax."))))
-
-
- (defun unix-interface ()
- (login)
- (if logged-in
- (progn
- (setq dungeon-mode 'unix)
- (define-key dungeon-mode-map "\r" 'unix-parse)
- (mprinc "$ "))))
-
-
-
- (defun login ()
- (let (tries username password)
- (setq tries 4)
- (while (and (not logged-in) (> (setq tries (- tries 1)) 0))
- (mprinc "\n\nUNIX System 5, Release 2.2 (pokey)\n\nlogin: ")
- (setq username (read-line))
- (if (not batch-mode)
- (mprinc "\n"))
- (mprinc "password: ")
- (setq password (read-line))
- (if (not batch-mode)
- (mprinc "\n"))
- (if (or (not (string= username "toukmond"))
- (not (string= password "robert")))
- (mprincl "login incorrect")
- (setq logged-in t)
- (mprincl "
- Welcome to Unix\n
- Please clean up your directories. The filesystem is getting full.
- Our tcp/ip link to gamma is a little flakey, but seems to work.
- The current version of ftp can only send files from the current
- directory, and deletes them after they are sent! Be careful.
-
- Note: Restricted bourne shell in use.\n")))
- (setq dungeon-mode 'dungeon)))
-
- (defun ls (args)
- (if (car args)
- (let (ocdpath ocdroom)
- (setq ocdpath cdpath)
- (setq ocdroom cdroom)
- (if (not (eq (cd args) -2))
- (ls nil))
- (setq cdpath ocdpath)
- (setq cdroom ocdroom))
- (if (= cdroom -10)
- (ls-inven))
- (if (= cdroom -2)
- (ls-rooms))
- (if (= cdroom -3)
- (ls-root))
- (if (= cdroom -4)
- (ls-usr))
- (if (> cdroom 0)
- (ls-room))))
-
- (defun ls-root ()
- (mprincl "total 4
- drwxr-xr-x 3 root staff 512 Jan 1 1970 .
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 usr
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 rooms"))
-
- (defun ls-usr ()
- (mprincl "total 4
- drwxr-xr-x 3 root staff 512 Jan 1 1970 .
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..
- drwxr-xr-x 3 toukmond restricted 512 Jan 1 1970 toukmond"))
-
- (defun ls-rooms ()
- (mprincl "total 16
- drwxr-xr-x 3 root staff 512 Jan 1 1970 .
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..")
- (dolist (x visited)
- (mprinc
- "drwxr-xr-x 3 root staff 512 Jan 1 1970 ")
- (mprincl (nth x room-shorts))))
-
- (defun ls-room ()
- (mprincl "total 4
- drwxr-xr-x 3 root staff 512 Jan 1 1970 .
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..
- -rwxr-xr-x 3 root staff 2048 Jan 1 1970 description")
- (dolist (x (nth cdroom room-objects))
- (if (and (>= x 0) (not (= x 255)))
- (progn
- (mprinc "-rwxr-xr-x 1 toukmond restricted 0 Jan 1 1970 ")
- (mprincl (nth x objfiles))))))
-
- (defun ls-inven ()
- (mprinc "total 467
- drwxr-xr-x 3 toukmond restricted 512 Jan 1 1970 .
- drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..")
- (dolist (x unix-verbs)
- (if (not (eq (car x) 'IMPOSSIBLE))
- (progn
- (mprinc"
- -rwxr-xr-x 1 toukmond restricted 10423 Jan 1 1970 ")
- (mprinc (car x)))))
- (mprinc "\n")
- (if (not uncompressed)
- (mprincl
- "-rwxr-xr-x 1 toukmond restricted 0 Jan 1 1970 paper.o.Z"))
- (dolist (x inventory)
- (mprinc
- "-rwxr-xr-x 1 toukmond restricted 0 Jan 1 1970 ")
- (mprincl (nth x objfiles))))
-
- (defun echo (args)
- (let (nomore var)
- (setq nomore nil)
- (dolist (x args)
- (if (not nomore)
- (progn
- (if (not (string= (substring x 0 1) "$"))
- (progn
- (mprinc x)
- (mprinc " "))
- (setq var (intern (substring x 1)))
- (if (not (boundp var))
- (mprinc " ")
- (if (member var restricted)
- (progn
- (mprinc var)
- (mprinc ": Permission denied")
- (setq nomore t))
- (eval (list 'mprinc var))
- (mprinc " ")))))))
- (mprinc "\n")))
-
-
- (defun ftp (args)
- (let (host username passwd)
- (if (not (car args))
- (mprincl "ftp: hostname required on command line.")
- (setq host (intern (car args)))
- (if (not (member host '(gamma endgame)))
- (mprincl "ftp: Unknown host.")
- (if (eq host 'endgame)
- (mprincl "ftp: connection to endgame not allowed")
- (if (not ethernet)
- (mprincl "ftp: host not responding.")
- (mprincl "Connected to gamma. FTP ver 0.9 00:00:00 01/01/70")
- (mprinc "Username: ")
- (setq username (read-line))
- (if (string= username "toukmond")
- (if batch-mode
- (mprincl "toukmond ftp access not allowed.")
- (mprincl "\ntoukmond ftp access not allowed."))
- (if (string= username "anonymous")
- (if batch-mode
- (mprincl
- "Guest login okay, send your user ident as password.")
- (mprincl
- "\nGuest login okay, send your user ident as password."))
- (if batch-mode
- (mprinc "Password required for ")
- (mprinc "\nPassword required for "))
- (mprincl username))
- (mprinc "Password: ")
- (setq ident (read-line))
- (if (not (string= username "anonymous"))
- (if batch-mode
- (mprincl "Login failed.")
- (mprincl "\nLogin failed."))
- (if batch-mode
- (mprincl "Guest login okay, user access restrictions apply.")
- (mprincl "\nGuest login okay, user access restrictions apply."))
- (ftp-commands)
- (setq newlist
- '("What password did you use during anonymous ftp to gamma?"))
- (setq newlist (append newlist (list ident)))
- (rplaca (nthcdr 1 endgame-questions) newlist)))))))))
-
- (defun ftp-commands ()
- (setq exitf nil)
- (let (line)
- (while (not exitf)
- (mprinc "ftp> ")
- (setq line (read-line))
- (if
- (eq
- (parse2 nil
- '((type . ftptype) (binary . bin) (bin . bin) (send . send)
- (put . send) (quit . ftpquit) (help . ftphelp)
- (ascii . fascii)
- ) line)
- -1)
- (mprincl "No such command. Try help.")))
- (setq ftptype 'ascii)))
-
- (defun ftptype (args)
- (if (not (car args))
- (mprincl "Usage: type [binary | ascii]")
- (setq args (intern (car args)))
- (if (eq args 'binary)
- (bin nil)
- (if (eq args 'ascii)
- (fascii 'nil)
- (mprincl "Unknown type.")))))
-
- (defun bin (args)
- (mprincl "Type set to binary.")
- (setq ftptype 'binary))
-
- (defun fascii (args)
- (mprincl "Type set to ascii.")
- (setq ftptype 'ascii))
-
- (defun ftpquit (args)
- (setq exitf t))
-
- (defun send (args)
- (if (not (car args))
- (mprincl "Usage: send <filename>")
- (setq args (car args))
- (let (counter foo)
- (setq foo nil)
- (setq counter 0)
-
- ;;; User can send commands! Stupid user.
-
-
- (if (assq (intern args) unix-verbs)
- (progn
- (rplaca (assq (intern args) unix-verbs) 'IMPOSSIBLE)
- (mprinc "Sending ")
- (mprinc ftptype)
- (mprinc " file for ")
- (mprincl args)
- (mprincl "Transfer complete."))
-
- (dolist (x objfiles)
- (if (string= args x)
- (progn
- (if (not (member counter inventory))
- (progn
- (mprincl "No such file.")
- (setq foo t))
- (mprinc "Sending ")
- (mprinc ftptype)
- (mprinc " file for ")
- (mprinc (downcase (cadr (nth counter objects))))
- (mprincl ", (0 bytes)")
- (if (not (eq ftptype 'binary))
- (progn
- (if (not (member -6 (nth 12 room-objects)))
- (replace room-objects 12
- (append (nth 12 room-objects) (list -6))))
- (remove-obj-from-inven counter))
- (remove-obj-from-inven counter)
- (replace room-objects 12
- (append (nth 12 room-objects) (list counter))))
- (setq foo t)
- (mprincl "Transfer complete."))))
- (setq counter (+ 1 counter)))
- (if (not foo)
- (mprincl "No such file."))))))
-
- (defun ftphelp (args)
- (mprincl
- "Possible commands are:\nsend quit type ascii binary help"))
-
- (defun uexit (args)
- (setq dungeon-mode 'dungeon)
- (mprincl "\nYou step back from the console.")
- (define-key dungeon-mode-map "\r" 'dungeon-parse)
- (if (not batch-mode)
- (dungeon-messages)))
-
- (defun pwd (args)
- (mprincl cdpath))
-
- (defun uncompress (args)
- (if (not (car args))
- (mprincl "Usage: uncompress <filename>")
- (setq args (car args))
- (if (or uncompressed
- (and (not (string= args "paper.o"))
- (not (string= args "paper.o.z"))))
- (mprincl "Uncompress command failed.")
- (setq uncompressed t)
- (setq inventory (append inventory (list 5))))))
-
- (defun rlogin (args)
- (if (not (car args))
- (mprincl "Usage: rlogin <hostname>")
- (setq args (car args))
- (if (string= args "endgame")
- (rlogin-endgame)
- (if (not (string= args "gamma"))
- (mprincl "No such host.")
- (if (not ethernet)
- (mprincl "Host not responding.")
- (mprinc "Password: ")
- (setq passwd (read-line))
- (if (not (string= passwd "worms"))
- (mprincl "\nlogin incorrect")
- (mprinc
- "\nYou begin to feel strange for a moment, and you lose your items."
- )
- (replace room-objects 10 (append (nth 0 room-objects) inventory))
- (setq inventory nil)
- (setq current-room 12)
- (uexit nil)))))))
-
- (defun cd (args)
- (if (not (car args))
- (mprincl "Usage: cd <path>")
- (setq tcdpath cdpath)
- (setq tcdroom cdroom)
- (setq badcd nil)
- (condition-case nil
- (setq path-elements (get-path (car args) nil))
- (error (mprincl "Invalid path.")
- (setq badcd t)))
- (dolist (pe path-elements)
- (unless badcd
- (if (not (string= pe "."))
- (if (string= pe "..")
- (progn
- (if (> tcdroom 0) ;In a room
- (progn
- (setq tcdpath "/rooms")
- (setq tcdroom -2))
- ;In /rooms,/usr,root
- (if (or (= tcdroom -2) (= tcdroom -4) (= tcdroom -3))
- (progn
- (setq tcdpath "/")
- (setq tcdroom -3))
- (if (= tcdroom -10) ;In /usr/toukmond
- (progn
- (setq tcdpath "/usr")
- (setq tcdroom -4))))))
- (if (string= pe "/")
- (progn
- (setq tcdpath "/")
- (setq tcdroom -3))
- (if (= tcdroom -4)
- (if (string= pe "toukmond")
- (progn
- (setq tcdpath "/usr/toukmond")
- (setq tcdroom -10))
- (nosuchdir))
- (if (= tcdroom -10)
- (nosuchdir)
- (if (> tcdroom 0)
- (nosuchdir)
- (if (= tcdroom -3)
- (progn
- (if (string= pe "rooms")
- (progn
- (setq tcdpath "/rooms")
- (setq tcdroom -2))
- (if (string= pe "usr")
- (progn
- (setq tcdpath "/usr")
- (setq tcdroom -4))
- (nosuchdir))))
- (if (= tcdroom -2)
- (progn
- (dolist (x visited)
- (setq room-check (nth x room-shorts))
- (if (string= room-check pe)
- (progn
- (setq tcdpath
- (concat "/rooms/" room-check))
- (setq tcdroom x))))
- (if (= tcdroom -2)
- (nosuchdir)))))))))))))
- (if (not badcd)
- (progn
- (setq cdpath tcdpath)
- (setq cdroom tcdroom)
- 0)
- -2)))
-
- (defun nosuchdir ()
- (mprincl "No such directory.")
- (setq badcd t))
-
- (defun cat (args)
- (if (not (setq args (car args)))
- (mprincl "Usage: cat <ascii-file-name>")
- (if (string-match "/" args)
- (mprincl "cat: only files in current directory allowed.")
- (if (and (> cdroom 0) (string= args "description"))
- (mprincl (car (nth cdroom rooms)))
- (if (setq doto (string-match "\\.o" args))
- (progn
- (if (= cdroom -10)
- (setq checklist inventory)
- (setq checklist (nth cdroom room-objects)))
- (if (not (member (cdr
- (assq (intern (substring args 0 doto)) objnames))
- checklist))
- (mprincl "File not found.")
- (mprincl "Ascii files only.")))
- (if (assq (intern args) unix-verbs)
- (mprincl "Ascii files only.")
- (mprincl "File not found.")))))))
-
- (defun zippy (args)
- (mprincl (yow)))
-
- (defun rlogin-endgame ()
- (if (not (= (score nil) 90))
- (mprincl "You have not achieved enough points to connect to endgame.")
- (mprincl"\nWelcome to the endgame. You are a truly noble adventurer.")
- (setq current-room 0)
- (setq endgame t)
- (replace room-objects 102 '(26))
- (uexit nil)))
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'dun-util.el'
- then
- echo shar: will not over-write existing file "'dun-util.el'"
- else
- cat << \SHAR_EOF > 'dun-util.el'
- (require 'cl)
-
- ;;;;;;;;;;;;;;;;;;;;; Utility functions
-
- ;;; Function which takes a verb and a list of other words. Calls proper
- ;;; function associated with the verb, and passes along the other words.
-
- (defun doverb (ignore verblist verb rest)
- (if (not verb)
- nil
- (if (member (intern verb) ignore)
- (if (not (car rest)) -1
- (doverb ignore verblist (car rest) (cdr rest)))
- (if (not (cdr (assq (intern verb) verblist))) -1
- (setq numcmds (1+ numcmds))
- (eval (list (cdr (assq (intern verb) verblist)) (quote rest)))))))
-
-
- ;;; Function to take a string and change it into a list of lowercase words.
-
- (defun listify-string (strin)
- (let (pos ret-list end-pos)
- (setq pos 0)
- (setq ret-list nil)
- (while (setq end-pos (string-match "[ ,:;]" (substring strin pos)))
- (setq end-pos (+ end-pos pos))
- (if (not (= end-pos pos))
- (setq ret-list (append ret-list (list
- (downcase
- (substring strin pos end-pos))))))
- (setq pos (+ end-pos 1))) ret-list))
-
- (defun listify-string2 (strin)
- (let (pos ret-list end-pos)
- (setq pos 0)
- (setq ret-list nil)
- (while (setq end-pos (string-match " " (substring strin pos)))
- (setq end-pos (+ end-pos pos))
- (if (not (= end-pos pos))
- (setq ret-list (append ret-list (list
- (downcase
- (substring strin pos end-pos))))))
- (setq pos (+ end-pos 1))) ret-list))
-
- (defun replace (list n number)
- (rplaca (nthcdr n list) number))
-
-
- ;;; Get the first non-ignored word from a list.
-
- (defun firstword (list)
- (if (not (car list))
- nil
- (while (and list (member (intern (car list)) ignore))
- (setq list (cdr list)))
- (car list)))
-
- (defun firstwordl (list)
- (if (not (car list))
- nil
- (while (and list (member (intern (car list)) ignore))
- (setq list (cdr list)))
- list))
-
- ;; parse a line passed in as a string Call the proper verb with the
- ;; rest of the line passed in as a list.
-
- (defun parse (ignore verblist line)
- (mprinc "\n")
- (setq line-list (listify-string (concat line " ")))
- (doverb ignore verblist (car line-list) (cdr line-list)))
-
- (defun parse2 (ignore verblist line)
- (mprinc "\n")
- (setq line-list (listify-string2 (concat line " ")))
- (doverb ignore verblist (car line-list) (cdr line-list)))
-
- (defun read-line ()
- (let (line)
- (setq line (read-string ""))
- (mprinc line) line))
-
- (defun minsert (string)
- (if (stringp string)
- (insert string)
- (insert (prin1-to-string string))))
-
- (defun mprinc (string)
- (if (stringp string)
- (insert string)
- (insert (prin1-to-string string))))
-
- (defun minsertl (string)
- (minsert string)
- (minsert "\n"))
-
- (defun mprincl (string)
- (mprinc string)
- (mprinc "\n"))
-
- ;;;; Function which will get an object number given the list of
- ;;;; words in the command, except for the verb.
-
- (defun objnum-from-args (obj)
- (let (objnum)
- (setq obj (firstword obj))
- (if (not obj)
- 255
- (setq objnum (cdr (assq (intern obj) objnames))))))
-
- (defun objnum-from-args-std (obj)
- (let (result)
- (if (eq (setq result (objnum-from-args obj)) 255)
- (mprincl "You must supply an object."))
- (if (eq result nil)
- (mprincl "I don't know what that is."))
- (if (eq result 255)
- nil
- result)))
-
- ;; Take a short room description, and change spaces and slashes to dashes.
-
- (defun space-to-hyphen (string)
- (let (space)
- (if (setq space (string-match "[ /]" string))
- (progn
- (setq string (concat (substring string 0 space) "-"
- (substring string (1+ space))))
- (space-to-hyphen string))
- string)))
-
- ;; Given a unix style pathname, build a list of path components (recursive)
-
- (defun get-path (dirstring startlist)
- (let (slash pos)
- (if (= (length dirstring) 0)
- startlist
- (if (string= (substring dirstring 0 1) "/")
- (get-path (substring dirstring 1) (append startlist (list "/")))
- (if (not (setq slash (string-match "/" dirstring)))
- (append startlist (list dirstring))
- (get-path (substring dirstring (1+ slash))
- (append startlist
- (list (substring dirstring 0 slash)))))))))
-
-
- (defun members (string string-list)
- (let (found)
- (setq found nil)
- (dolist (x string-list)
- (if (string= x string)
- (setq found t))) found))
-
- (defun put-objs-in-treas (objlist)
- (let (oscore newscore)
- (setq oscore (reg-score))
- (replace room-objects 0 (append (nth 0 room-objects) objlist))
- (setq newscore (reg-score))
- (if (not (= oscore newscore))
- (score nil))))
-
- (defun load-d (filename)
- (let (old-buffer key result)
- (setq result t)
- (setq old-buffer (current-buffer))
- (switch-to-buffer (get-buffer-create "*loadc*"))
- (erase-buffer)
- (condition-case nil
- (insert-file-contents filename)
- (error (setq result nil)))
- (unless (not result)
- (setq key (buffer-substring (point-min) (+ (point-min) 2)))
- (delete-char 2 t)
- (condition-case nil
- (crypt-buffer key)
- (error (yank)))
- (eval-current-buffer)
- (kill-buffer (current-buffer))
- (switch-to-buffer old-buffer))
- result))
-
- (defun compile-globals ()
- (switch-to-buffer (get-buffer-create "*compd*"))
- (erase-buffer)
- (insert-file-contents "dun-globals.el")
- (setq key (concat (prin1-to-string (% (abs (random)) 9))
- (prin1-to-string (% (abs (random)) 9))))
- (crypt-buffer key)
- (goto-char (point-min))
- (insert key)
- (write-region 1 (point-max) "dun-globals.dat")
- (kill-buffer (current-buffer)))
-
- ;; Functions to remove an object either from a room, or from inventory.
-
- (defun remove-obj-from-room (room objnum)
- (let (newroom)
- (setq newroom nil)
- (dolist (x (nth room room-objects))
- (if (not (= x objnum))
- (setq newroom (append newroom (list x)))))
- (rplaca (nthcdr room room-objects) newroom)))
-
- (defun remove-obj-from-inven (objnum)
- (let (new-inven)
- (setq new-inven nil)
- (dolist (x inventory)
- (if (not (= x objnum))
- (setq new-inven (append new-inven (list x)))))
- (setq inventory new-inven)))
-
- (defun get-glob-dat ()
- (let (result)
- (setq result nil)
- (dolist (x load-path)
- (if (file-exists-p (concat x "/dun-globals.dat"))
- (setq result (concat x "/dun-globals.dat"))))
- result))
-
- ;;;
- ;;; This is a small part copied from crypt.el by kyle@cs.odu.edu, with
- ;;; a small change.
-
-
- ;;; Compaction, compression and encryption for GNU Emacs
- ;;; Copyright (C) 1988, 1989, 1990 Kyle E. Jones
- ;;;
- ;;; This program is free software; you can redistribute it and/or modify
- ;;; it under the terms of the GNU General Public License as published by
- ;;; the Free Software Foundation; either version 1, or (at your option)
- ;;; any later version.
- ;;;
- ;;; This program is distributed in the hope that it will be useful,
- ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ;;; GNU General Public License for more details.
- ;;;
- ;;; A copy of the GNU General Public License can be obtained from this
- ;;; program's author (send electronic mail to kyle@cs.odu.edu) or from
- ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
- ;;; 02139, USA.
- ;;;
- ;;; Send bug reports to kyle@cs.odu.edu.
-
- ;;; Changes for dungeon -
- ;;; ronnie@eddie.mit.edu - changed shell to use /bin/sh explicitly.
- ;;; Otherwise user's 'rc' file might produce
- ;;; output that gets stuffed into buffer.
-
- (defun crypt-region (start end key)
- (let ((opoint-max (point-max)))
- (call-process-region start end "/bin/sh" t t nil "-c"
- (concat "crypt \"" key "\""))
- (if (not (= opoint-max (point-max)))
- (error "crypt command failed!"))))
-
- (defun crypt-buffer (key &optional buffer)
- (crypt-region (point-min) (point-max) key))
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-