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