Commit d5260473 authored by Mark Oteiza's avatar Mark Oteiza

Replace more nested ifs with cond

This is a continuation of 0db5ba48 "Replace nested ifs with cond".
* lisp/play/dunnet.el (dun-special-object, dun-inven, dun-drop):
(dun-drop-check, dun-swim, dun-break): Use when and cond where
appropriate.
(dun-examine): Fix indentation.
(dun-doverb): Use when.
(dun-read-line): Refactor.
parent c66aaa61
......@@ -1227,54 +1227,48 @@ treasures for points?" "4" "four")
;;; or lack thereof, depends on certain conditions.
(defun dun-special-object ()
(if (= dun-current-room computer-room)
(cond
((= dun-current-room computer-room)
(if dun-computer
(dun-mprincl
"The panel lights are flashing in a seemingly organized pattern.")
"The panel lights are flashing in a seemingly organized pattern.")
(dun-mprincl "The panel lights are steady and motionless.")))
(if (and (= dun-current-room red-room)
((and (= dun-current-room red-room)
(not (member obj-towel (nth red-room dun-room-objects))))
(dun-mprincl "There is a hole in the floor here."))
(if (and (= dun-current-room marine-life-area) dun-black)
((and (= dun-current-room marine-life-area) dun-black)
(dun-mprincl
"The room is lit by a black light, causing the fish, and some of
your objects, to give off an eerie glow."))
(if (and (= dun-current-room fourth-vermont-intersection) dun-hole)
(progn
((and (= dun-current-room fourth-vermont-intersection) dun-hole)
(if (not dun-inbus)
(progn
(dun-mprincl "You fall into a hole in the ground.")
(setq dun-current-room vermont-station)
(dun-describe-room vermont-station))
(progn
(dun-mprincl
"The bus falls down a hole in the ground and explodes.")
(dun-die "burning")))))
(dun-mprincl "The bus falls down a hole in the ground and explodes.")
(dun-die "burning")))
(if (> dun-current-room endgame-computer-room)
(progn
((> dun-current-room endgame-computer-room)
(if (not dun-correct-answer)
(dun-endgame-question)
(dun-mprincl "Your question is:")
(dun-mprincl dun-endgame-question))))
(dun-mprincl dun-endgame-question)))
(if (= dun-current-room sauna)
(progn
((= dun-current-room sauna)
(dun-mprincl (nth dun-sauna-level '(
"It is normal room temperature in here."
"It is luke warm in here."
"It is comfortably hot in here."
"It is refreshingly hot in here."
"You are dead now.")))
(if (= dun-sauna-level 3)
(progn
(if (or (member obj-rms dun-inventory)
(when (= dun-sauna-level 3)
(when (or (member obj-rms dun-inventory)
(member obj-rms (nth dun-current-room dun-room-objects)))
(progn
(dun-mprincl
"You notice the wax on your statuette beginning to melt, until it completely
"You notice the wax on your statuette beginning to melt, until it completely
melts off. You are left with a beautiful diamond!")
(if (member obj-rms dun-inventory)
(progn
......@@ -1284,15 +1278,14 @@ melts off. You are left with a beautiful diamond!")
(dun-remove-obj-from-room dun-current-room obj-rms)
(dun-replace dun-room-objects dun-current-room
(append (nth dun-current-room dun-room-objects)
(list obj-diamond))))))
(if (or (member obj-floppy dun-inventory)
(list obj-diamond)))))
(when (or (member obj-floppy dun-inventory)
(member obj-floppy (nth dun-current-room dun-room-objects)))
(progn
(dun-mprincl
"You notice your floppy disk beginning to melt. As you grab for it, the
"You notice your floppy disk beginning to melt. As you grab for it, the
disk bursts into flames, and disintegrates.")
(dun-remove-obj-from-inven obj-floppy)
(dun-remove-obj-from-room dun-current-room obj-floppy))))))))
(dun-remove-obj-from-room dun-current-room obj-floppy))))))
(defun dun-die (murderer)
......@@ -1312,14 +1305,12 @@ disk bursts into flames, and disintegrates.")
(defun dun-inven (_args)
(dun-mprincl "You currently have:")
(dolist (curobj dun-inventory)
(if curobj
(progn
(when curobj
(dun-mprincl (cadr (nth curobj dun-objects)))
(if (and (= curobj obj-jar) dun-jar)
(progn
(when (and (= curobj obj-jar) dun-jar)
(dun-mprincl "The jar contains:")
(dolist (x dun-jar)
(dun-mprincl " " (cadr (nth x dun-objects))))))))))
(dun-mprincl " " (cadr (nth x dun-objects))))))))
(defun dun-shake (obj)
(let ((objnum (dun-objnum-from-args-std obj)))
......@@ -1354,46 +1345,42 @@ on your head.")
(when (setq objnum (dun-objnum-from-args-std obj))
(if (not (member objnum dun-inventory))
(dun-mprincl "You don't have that.")
(progn
(dun-remove-obj-from-inven objnum)
(dun-replace dun-room-objects dun-current-room
(append (nth dun-current-room dun-room-objects)
(list objnum)))
(dun-mprincl "Done.")
(if (member objnum (list obj-food obj-weight obj-jar))
(dun-drop-check objnum))))))))
(dun-drop-check objnum)))))))
;;; Dropping certain things causes things to happen.
(defun dun-drop-check (objnum)
(if (and (= objnum obj-food) (= dun-room bear-hangout)
(cond
((and (= objnum obj-food) (= dun-room bear-hangout)
(member obj-bear (nth bear-hangout dun-room-objects)))
(progn
(dun-mprincl
"The bear takes the food and runs away with it. He left something behind.")
(dun-remove-obj-from-room dun-current-room obj-bear)
(dun-remove-obj-from-room dun-current-room obj-food)
(dun-replace dun-room-objects dun-current-room
(append (nth dun-current-room dun-room-objects)
(list obj-key)))))
(list obj-key))))
(if (and (= objnum obj-jar) (member obj-nitric dun-jar)
((and (= objnum obj-jar) (member obj-nitric dun-jar)
(member obj-glycerine dun-jar))
(progn
(dun-mprincl
"As the jar impacts the ground it explodes into many pieces.")
(dun-mprincl "As the jar impacts the ground it explodes into many pieces.")
(setq dun-jar nil)
(dun-remove-obj-from-room dun-current-room obj-jar)
(if (= dun-current-room fourth-vermont-intersection)
(progn
(when (= dun-current-room fourth-vermont-intersection)
(setq dun-hole t)
(setq dun-current-room vermont-station)
(dun-mprincl
"The explosion causes a hole to open up in the ground, which you fall
through.")))))
through.")))
(if (and (= objnum obj-weight) (= dun-current-room maze-button-room))
(dun-mprincl "A passageway opens.")))
((and (= objnum obj-weight) (= dun-current-room maze-button-room))
(dun-mprincl "A passageway opens."))))
;;; Give long description of current room, or an object.
......@@ -1942,18 +1929,18 @@ as you release it, the passageway closes."))
(setq dun-black t))))))
(defun dun-swim (_args)
(if (not (member dun-current-room (list lakefront-north lakefront-south)))
(dun-mprincl "I see no water!")
(if (not (member obj-life dun-inventory))
(progn
(cond
((not (member dun-current-room (list lakefront-north lakefront-south)))
(dun-mprincl "I see no water!"))
((not (member obj-life dun-inventory))
(dun-mprincl
"You dive in the water, and at first notice it is quite cold. You then
start to get used to it as you realize that you never really learned how
to swim.")
(dun-die "drowning"))
(if (= dun-current-room lakefront-north)
(setq dun-current-room lakefront-south)
(setq dun-current-room lakefront-north)))))
((= dun-current-room lakefront-north)
(setq dun-current-room lakefront-south))
(t (setq dun-current-room lakefront-north))))
(defun dun-score (_args)
......@@ -2043,26 +2030,24 @@ the ground, then putting some kind of treasure in it, and filling the hole
with dirt again. After this, you immediately wake up.")))
(defun dun-break (obj)
(let (objnum)
(if (not (member obj-axe dun-inventory))
(dun-mprincl "You have nothing you can use to break things.")
(when (setq objnum (dun-objnum-from-args-std obj))
(if (member objnum dun-inventory)
(progn
(let ((objnum (dun-objnum-from-args-std obj)))
(when objnum
(cond
((member objnum dun-inventory)
(dun-mprincl
"You take the object in your hands and swing the axe. Unfortunately, you miss
the object and slice off your hand. You bleed to death.")
(dun-die "an axe"))
(if (not (or (member objnum (nth dun-current-room dun-room-objects))
((not (or (member objnum (nth dun-current-room dun-room-objects))
(member objnum
(nth dun-current-room dun-room-silents))))
(dun-mprincl "I don't see that here.")
(if (= objnum obj-cable)
(progn
(dun-mprincl "I don't see that here."))
((= objnum obj-cable)
(dun-mprincl
"As you break the ethernet cable, everything starts to blur. You collapse
for a moment, then straighten yourself up.
")
for a moment, then straighten yourself up.\n")
(dun-replace dun-room-objects gamma-computing-center
(append
(nth gamma-computing-center dun-room-objects)
......@@ -2070,19 +2055,18 @@ for a moment, then straighten yourself up.
(if (member obj-key dun-inventory)
(progn
(setq dun-inventory (list obj-key))
(dun-remove-obj-from-room
gamma-computing-center obj-key))
(dun-remove-obj-from-room gamma-computing-center obj-key))
(setq dun-inventory nil))
(setq dun-current-room computer-room)
(setq dun-ethernet nil)
(dun-mprincl "Connection closed.")
(dun-unix-interface))
(if (< objnum 0)
(progn
((< objnum 0)
(dun-mprincl "Your axe shatters into a million pieces.")
(dun-remove-obj-from-inven obj-axe))
(t
(dun-mprincl "Your axe breaks it into a million pieces.")
(dun-remove-obj-from-room dun-current-room objnum)))))))))
(dun-remove-obj-from-room dun-current-room objnum)))))))
(defun dun-drive (_args)
(if (not dun-inbus)
......@@ -2178,8 +2162,7 @@ for a moment, then straighten yourself up.
;;; function associated with the verb, and passes along the other words.
(defun dun-doverb (ignore verblist verb rest)
(if (not verb)
nil
(when verb
(if (member (intern verb) ignore)
(if (not (car rest)) -1
(dun-doverb ignore verblist (car rest) (cdr rest)))
......@@ -2250,9 +2233,9 @@ for a moment, then straighten yourself up.
;;; Read a line, in window mode
(defun dun-read-line ()
(let (line)
(setq line (read-string ""))
(dun-mprinc line) line))
(let ((line (read-string "")))
(dun-mprinc line)
line))
;;; Insert something into the window buffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment