home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume14
/
dunnet
/
part02
/
dun-util.el
< prev
next >
Wrap
Lisp/Scheme
|
1992-08-31
|
8KB
|
259 lines
(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))