diff options
| author | Mark Oteiza | 2017-03-15 00:42:25 -0400 |
|---|---|---|
| committer | Mark Oteiza | 2017-03-15 00:42:25 -0400 |
| commit | d5260473dea4a86907614cf5fae9ec43f6cdccd4 (patch) | |
| tree | a887ffde3924f88d44775c89be98d7b7b1838106 | |
| parent | c66aaa61639e72a70a4f2c4bc73645048caebe53 (diff) | |
| download | emacs-d5260473dea4a86907614cf5fae9ec43f6cdccd4.tar.gz emacs-d5260473dea4a86907614cf5fae9ec43f6cdccd4.zip | |
Replace more nested ifs with cond
This is a continuation of 0db5ba4 "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.
| -rw-r--r-- | lisp/play/dunnet.el | 277 |
1 files changed, 130 insertions, 147 deletions
diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el index 8b9bb037e9d..677946262c5 100644 --- a/lisp/play/dunnet.el +++ b/lisp/play/dunnet.el | |||
| @@ -1227,72 +1227,65 @@ treasures for points?" "4" "four") | |||
| 1227 | ;;; or lack thereof, depends on certain conditions. | 1227 | ;;; or lack thereof, depends on certain conditions. |
| 1228 | 1228 | ||
| 1229 | (defun dun-special-object () | 1229 | (defun dun-special-object () |
| 1230 | (if (= dun-current-room computer-room) | 1230 | (cond |
| 1231 | (if dun-computer | 1231 | ((= dun-current-room computer-room) |
| 1232 | (dun-mprincl | 1232 | (if dun-computer |
| 1233 | "The panel lights are flashing in a seemingly organized pattern.") | 1233 | (dun-mprincl |
| 1234 | (dun-mprincl "The panel lights are steady and motionless."))) | 1234 | "The panel lights are flashing in a seemingly organized pattern.") |
| 1235 | (dun-mprincl "The panel lights are steady and motionless."))) | ||
| 1235 | 1236 | ||
| 1236 | (if (and (= dun-current-room red-room) | 1237 | ((and (= dun-current-room red-room) |
| 1237 | (not (member obj-towel (nth red-room dun-room-objects)))) | 1238 | (not (member obj-towel (nth red-room dun-room-objects)))) |
| 1238 | (dun-mprincl "There is a hole in the floor here.")) | 1239 | (dun-mprincl "There is a hole in the floor here.")) |
| 1239 | 1240 | ||
| 1240 | (if (and (= dun-current-room marine-life-area) dun-black) | 1241 | ((and (= dun-current-room marine-life-area) dun-black) |
| 1241 | (dun-mprincl | 1242 | (dun-mprincl |
| 1242 | "The room is lit by a black light, causing the fish, and some of | 1243 | "The room is lit by a black light, causing the fish, and some of |
| 1243 | your objects, to give off an eerie glow.")) | 1244 | your objects, to give off an eerie glow.")) |
| 1244 | (if (and (= dun-current-room fourth-vermont-intersection) dun-hole) | 1245 | ((and (= dun-current-room fourth-vermont-intersection) dun-hole) |
| 1245 | (progn | 1246 | (if (not dun-inbus) |
| 1246 | (if (not dun-inbus) | 1247 | (progn |
| 1247 | (progn | 1248 | (dun-mprincl "You fall into a hole in the ground.") |
| 1248 | (dun-mprincl "You fall into a hole in the ground.") | 1249 | (setq dun-current-room vermont-station) |
| 1249 | (setq dun-current-room vermont-station) | 1250 | (dun-describe-room vermont-station)) |
| 1250 | (dun-describe-room vermont-station)) | 1251 | (dun-mprincl "The bus falls down a hole in the ground and explodes.") |
| 1251 | (progn | 1252 | (dun-die "burning"))) |
| 1252 | (dun-mprincl | 1253 | |
| 1253 | "The bus falls down a hole in the ground and explodes.") | 1254 | ((> dun-current-room endgame-computer-room) |
| 1254 | (dun-die "burning"))))) | 1255 | (if (not dun-correct-answer) |
| 1255 | 1256 | (dun-endgame-question) | |
| 1256 | (if (> dun-current-room endgame-computer-room) | 1257 | (dun-mprincl "Your question is:") |
| 1257 | (progn | 1258 | (dun-mprincl dun-endgame-question))) |
| 1258 | (if (not dun-correct-answer) | ||
| 1259 | (dun-endgame-question) | ||
| 1260 | (dun-mprincl "Your question is:") | ||
| 1261 | (dun-mprincl dun-endgame-question)))) | ||
| 1262 | 1259 | ||
| 1263 | (if (= dun-current-room sauna) | 1260 | ((= dun-current-room sauna) |
| 1264 | (progn | 1261 | (dun-mprincl (nth dun-sauna-level '( |
| 1265 | (dun-mprincl (nth dun-sauna-level '( | ||
| 1266 | "It is normal room temperature in here." | 1262 | "It is normal room temperature in here." |
| 1267 | "It is luke warm in here." | 1263 | "It is luke warm in here." |
| 1268 | "It is comfortably hot in here." | 1264 | "It is comfortably hot in here." |
| 1269 | "It is refreshingly hot in here." | 1265 | "It is refreshingly hot in here." |
| 1270 | "You are dead now."))) | 1266 | "You are dead now."))) |
| 1271 | (if (= dun-sauna-level 3) | 1267 | (when (= dun-sauna-level 3) |
| 1272 | (progn | 1268 | (when (or (member obj-rms dun-inventory) |
| 1273 | (if (or (member obj-rms dun-inventory) | 1269 | (member obj-rms (nth dun-current-room dun-room-objects))) |
| 1274 | (member obj-rms (nth dun-current-room dun-room-objects))) | 1270 | (dun-mprincl |
| 1275 | (progn | 1271 | "You notice the wax on your statuette beginning to melt, until it completely |
| 1276 | (dun-mprincl | ||
| 1277 | "You notice the wax on your statuette beginning to melt, until it completely | ||
| 1278 | melts off. You are left with a beautiful diamond!") | 1272 | melts off. You are left with a beautiful diamond!") |
| 1279 | (if (member obj-rms dun-inventory) | 1273 | (if (member obj-rms dun-inventory) |
| 1280 | (progn | 1274 | (progn |
| 1281 | (dun-remove-obj-from-inven obj-rms) | 1275 | (dun-remove-obj-from-inven obj-rms) |
| 1282 | (setq dun-inventory (append dun-inventory | 1276 | (setq dun-inventory (append dun-inventory |
| 1283 | (list obj-diamond)))) | 1277 | (list obj-diamond)))) |
| 1284 | (dun-remove-obj-from-room dun-current-room obj-rms) | 1278 | (dun-remove-obj-from-room dun-current-room obj-rms) |
| 1285 | (dun-replace dun-room-objects dun-current-room | 1279 | (dun-replace dun-room-objects dun-current-room |
| 1286 | (append (nth dun-current-room dun-room-objects) | 1280 | (append (nth dun-current-room dun-room-objects) |
| 1287 | (list obj-diamond)))))) | 1281 | (list obj-diamond))))) |
| 1288 | (if (or (member obj-floppy dun-inventory) | 1282 | (when (or (member obj-floppy dun-inventory) |
| 1289 | (member obj-floppy (nth dun-current-room dun-room-objects))) | 1283 | (member obj-floppy (nth dun-current-room dun-room-objects))) |
| 1290 | (progn | 1284 | (dun-mprincl |
| 1291 | (dun-mprincl | 1285 | "You notice your floppy disk beginning to melt. As you grab for it, the |
| 1292 | "You notice your floppy disk beginning to melt. As you grab for it, the | ||
| 1293 | disk bursts into flames, and disintegrates.") | 1286 | disk bursts into flames, and disintegrates.") |
| 1294 | (dun-remove-obj-from-inven obj-floppy) | 1287 | (dun-remove-obj-from-inven obj-floppy) |
| 1295 | (dun-remove-obj-from-room dun-current-room obj-floppy)))))))) | 1288 | (dun-remove-obj-from-room dun-current-room obj-floppy)))))) |
| 1296 | 1289 | ||
| 1297 | 1290 | ||
| 1298 | (defun dun-die (murderer) | 1291 | (defun dun-die (murderer) |
| @@ -1312,14 +1305,12 @@ disk bursts into flames, and disintegrates.") | |||
| 1312 | (defun dun-inven (_args) | 1305 | (defun dun-inven (_args) |
| 1313 | (dun-mprincl "You currently have:") | 1306 | (dun-mprincl "You currently have:") |
| 1314 | (dolist (curobj dun-inventory) | 1307 | (dolist (curobj dun-inventory) |
| 1315 | (if curobj | 1308 | (when curobj |
| 1316 | (progn | 1309 | (dun-mprincl (cadr (nth curobj dun-objects))) |
| 1317 | (dun-mprincl (cadr (nth curobj dun-objects))) | 1310 | (when (and (= curobj obj-jar) dun-jar) |
| 1318 | (if (and (= curobj obj-jar) dun-jar) | 1311 | (dun-mprincl "The jar contains:") |
| 1319 | (progn | 1312 | (dolist (x dun-jar) |
| 1320 | (dun-mprincl "The jar contains:") | 1313 | (dun-mprincl " " (cadr (nth x dun-objects)))))))) |
| 1321 | (dolist (x dun-jar) | ||
| 1322 | (dun-mprincl " " (cadr (nth x dun-objects)))))))))) | ||
| 1323 | 1314 | ||
| 1324 | (defun dun-shake (obj) | 1315 | (defun dun-shake (obj) |
| 1325 | (let ((objnum (dun-objnum-from-args-std obj))) | 1316 | (let ((objnum (dun-objnum-from-args-std obj))) |
| @@ -1354,46 +1345,42 @@ on your head.") | |||
| 1354 | (when (setq objnum (dun-objnum-from-args-std obj)) | 1345 | (when (setq objnum (dun-objnum-from-args-std obj)) |
| 1355 | (if (not (member objnum dun-inventory)) | 1346 | (if (not (member objnum dun-inventory)) |
| 1356 | (dun-mprincl "You don't have that.") | 1347 | (dun-mprincl "You don't have that.") |
| 1357 | (progn | 1348 | (dun-remove-obj-from-inven objnum) |
| 1358 | (dun-remove-obj-from-inven objnum) | 1349 | (dun-replace dun-room-objects dun-current-room |
| 1359 | (dun-replace dun-room-objects dun-current-room | 1350 | (append (nth dun-current-room dun-room-objects) |
| 1360 | (append (nth dun-current-room dun-room-objects) | 1351 | (list objnum))) |
| 1361 | (list objnum))) | 1352 | (dun-mprincl "Done.") |
| 1362 | (dun-mprincl "Done.") | 1353 | (if (member objnum (list obj-food obj-weight obj-jar)) |
| 1363 | (if (member objnum (list obj-food obj-weight obj-jar)) | 1354 | (dun-drop-check objnum))))))) |
| 1364 | (dun-drop-check objnum)))))))) | ||
| 1365 | 1355 | ||
| 1366 | ;;; Dropping certain things causes things to happen. | 1356 | ;;; Dropping certain things causes things to happen. |
| 1367 | 1357 | ||
| 1368 | (defun dun-drop-check (objnum) | 1358 | (defun dun-drop-check (objnum) |
| 1369 | (if (and (= objnum obj-food) (= dun-room bear-hangout) | 1359 | (cond |
| 1370 | (member obj-bear (nth bear-hangout dun-room-objects))) | 1360 | ((and (= objnum obj-food) (= dun-room bear-hangout) |
| 1371 | (progn | 1361 | (member obj-bear (nth bear-hangout dun-room-objects))) |
| 1372 | (dun-mprincl | 1362 | (dun-mprincl |
| 1373 | "The bear takes the food and runs away with it. He left something behind.") | 1363 | "The bear takes the food and runs away with it. He left something behind.") |
| 1374 | (dun-remove-obj-from-room dun-current-room obj-bear) | 1364 | (dun-remove-obj-from-room dun-current-room obj-bear) |
| 1375 | (dun-remove-obj-from-room dun-current-room obj-food) | 1365 | (dun-remove-obj-from-room dun-current-room obj-food) |
| 1376 | (dun-replace dun-room-objects dun-current-room | 1366 | (dun-replace dun-room-objects dun-current-room |
| 1377 | (append (nth dun-current-room dun-room-objects) | 1367 | (append (nth dun-current-room dun-room-objects) |
| 1378 | (list obj-key))))) | 1368 | (list obj-key)))) |
| 1379 | 1369 | ||
| 1380 | (if (and (= objnum obj-jar) (member obj-nitric dun-jar) | 1370 | ((and (= objnum obj-jar) (member obj-nitric dun-jar) |
| 1381 | (member obj-glycerine dun-jar)) | 1371 | (member obj-glycerine dun-jar)) |
| 1382 | (progn | 1372 | (dun-mprincl "As the jar impacts the ground it explodes into many pieces.") |
| 1383 | (dun-mprincl | 1373 | (setq dun-jar nil) |
| 1384 | "As the jar impacts the ground it explodes into many pieces.") | 1374 | (dun-remove-obj-from-room dun-current-room obj-jar) |
| 1385 | (setq dun-jar nil) | 1375 | (when (= dun-current-room fourth-vermont-intersection) |
| 1386 | (dun-remove-obj-from-room dun-current-room obj-jar) | 1376 | (setq dun-hole t) |
| 1387 | (if (= dun-current-room fourth-vermont-intersection) | 1377 | (setq dun-current-room vermont-station) |
| 1388 | (progn | 1378 | (dun-mprincl |
| 1389 | (setq dun-hole t) | ||
| 1390 | (setq dun-current-room vermont-station) | ||
| 1391 | (dun-mprincl | ||
| 1392 | "The explosion causes a hole to open up in the ground, which you fall | 1379 | "The explosion causes a hole to open up in the ground, which you fall |
| 1393 | through."))))) | 1380 | through."))) |
| 1394 | 1381 | ||
| 1395 | (if (and (= objnum obj-weight) (= dun-current-room maze-button-room)) | 1382 | ((and (= objnum obj-weight) (= dun-current-room maze-button-room)) |
| 1396 | (dun-mprincl "A passageway opens."))) | 1383 | (dun-mprincl "A passageway opens.")))) |
| 1397 | 1384 | ||
| 1398 | ;;; Give long description of current room, or an object. | 1385 | ;;; Give long description of current room, or an object. |
| 1399 | 1386 | ||
| @@ -1416,7 +1403,7 @@ through."))))) | |||
| 1416 | ((>= objnum 0) | 1403 | ((>= objnum 0) |
| 1417 | (if (and (= objnum obj-bone) | 1404 | (if (and (= objnum obj-bone) |
| 1418 | (= dun-current-room marine-life-area) dun-black) | 1405 | (= dun-current-room marine-life-area) dun-black) |
| 1419 | (dun-mprincl | 1406 | (dun-mprincl |
| 1420 | "In this light you can see some writing on the bone. It says: | 1407 | "In this light you can see some writing on the bone. It says: |
| 1421 | For an explosive time, go to Fourth St. and Vermont.") | 1408 | For an explosive time, go to Fourth St. and Vermont.") |
| 1422 | (if (nth objnum dun-physobj-desc) | 1409 | (if (nth objnum dun-physobj-desc) |
| @@ -1942,18 +1929,18 @@ as you release it, the passageway closes.")) | |||
| 1942 | (setq dun-black t)))))) | 1929 | (setq dun-black t)))))) |
| 1943 | 1930 | ||
| 1944 | (defun dun-swim (_args) | 1931 | (defun dun-swim (_args) |
| 1945 | (if (not (member dun-current-room (list lakefront-north lakefront-south))) | 1932 | (cond |
| 1946 | (dun-mprincl "I see no water!") | 1933 | ((not (member dun-current-room (list lakefront-north lakefront-south))) |
| 1947 | (if (not (member obj-life dun-inventory)) | 1934 | (dun-mprincl "I see no water!")) |
| 1948 | (progn | 1935 | ((not (member obj-life dun-inventory)) |
| 1949 | (dun-mprincl | 1936 | (dun-mprincl |
| 1950 | "You dive in the water, and at first notice it is quite cold. You then | 1937 | "You dive in the water, and at first notice it is quite cold. You then |
| 1951 | start to get used to it as you realize that you never really learned how | 1938 | start to get used to it as you realize that you never really learned how |
| 1952 | to swim.") | 1939 | to swim.") |
| 1953 | (dun-die "drowning")) | 1940 | (dun-die "drowning")) |
| 1954 | (if (= dun-current-room lakefront-north) | 1941 | ((= dun-current-room lakefront-north) |
| 1955 | (setq dun-current-room lakefront-south) | 1942 | (setq dun-current-room lakefront-south)) |
| 1956 | (setq dun-current-room lakefront-north))))) | 1943 | (t (setq dun-current-room lakefront-north)))) |
| 1957 | 1944 | ||
| 1958 | 1945 | ||
| 1959 | (defun dun-score (_args) | 1946 | (defun dun-score (_args) |
| @@ -2043,46 +2030,43 @@ the ground, then putting some kind of treasure in it, and filling the hole | |||
| 2043 | with dirt again. After this, you immediately wake up."))) | 2030 | with dirt again. After this, you immediately wake up."))) |
| 2044 | 2031 | ||
| 2045 | (defun dun-break (obj) | 2032 | (defun dun-break (obj) |
| 2046 | (let (objnum) | 2033 | (if (not (member obj-axe dun-inventory)) |
| 2047 | (if (not (member obj-axe dun-inventory)) | 2034 | (dun-mprincl "You have nothing you can use to break things.") |
| 2048 | (dun-mprincl "You have nothing you can use to break things.") | 2035 | (let ((objnum (dun-objnum-from-args-std obj))) |
| 2049 | (when (setq objnum (dun-objnum-from-args-std obj)) | 2036 | (when objnum |
| 2050 | (if (member objnum dun-inventory) | 2037 | (cond |
| 2051 | (progn | 2038 | ((member objnum dun-inventory) |
| 2052 | (dun-mprincl | 2039 | (dun-mprincl |
| 2053 | "You take the object in your hands and swing the axe. Unfortunately, you miss | 2040 | "You take the object in your hands and swing the axe. Unfortunately, you miss |
| 2054 | the object and slice off your hand. You bleed to death.") | 2041 | the object and slice off your hand. You bleed to death.") |
| 2055 | (dun-die "an axe")) | 2042 | (dun-die "an axe")) |
| 2056 | (if (not (or (member objnum (nth dun-current-room dun-room-objects)) | 2043 | ((not (or (member objnum (nth dun-current-room dun-room-objects)) |
| 2057 | (member objnum | 2044 | (member objnum |
| 2058 | (nth dun-current-room dun-room-silents)))) | 2045 | (nth dun-current-room dun-room-silents)))) |
| 2059 | (dun-mprincl "I don't see that here.") | 2046 | (dun-mprincl "I don't see that here.")) |
| 2060 | (if (= objnum obj-cable) | 2047 | ((= objnum obj-cable) |
| 2061 | (progn | 2048 | (dun-mprincl |
| 2062 | (dun-mprincl | ||
| 2063 | "As you break the ethernet cable, everything starts to blur. You collapse | 2049 | "As you break the ethernet cable, everything starts to blur. You collapse |
| 2064 | for a moment, then straighten yourself up. | 2050 | for a moment, then straighten yourself up.\n") |
| 2065 | ") | 2051 | (dun-replace dun-room-objects gamma-computing-center |
| 2066 | (dun-replace dun-room-objects gamma-computing-center | 2052 | (append |
| 2067 | (append | 2053 | (nth gamma-computing-center dun-room-objects) |
| 2068 | (nth gamma-computing-center dun-room-objects) | 2054 | dun-inventory)) |
| 2069 | dun-inventory)) | 2055 | (if (member obj-key dun-inventory) |
| 2070 | (if (member obj-key dun-inventory) | 2056 | (progn |
| 2071 | (progn | 2057 | (setq dun-inventory (list obj-key)) |
| 2072 | (setq dun-inventory (list obj-key)) | 2058 | (dun-remove-obj-from-room gamma-computing-center obj-key)) |
| 2073 | (dun-remove-obj-from-room | 2059 | (setq dun-inventory nil)) |
| 2074 | gamma-computing-center obj-key)) | 2060 | (setq dun-current-room computer-room) |
| 2075 | (setq dun-inventory nil)) | 2061 | (setq dun-ethernet nil) |
| 2076 | (setq dun-current-room computer-room) | 2062 | (dun-mprincl "Connection closed.") |
| 2077 | (setq dun-ethernet nil) | 2063 | (dun-unix-interface)) |
| 2078 | (dun-mprincl "Connection closed.") | 2064 | ((< objnum 0) |
| 2079 | (dun-unix-interface)) | 2065 | (dun-mprincl "Your axe shatters into a million pieces.") |
| 2080 | (if (< objnum 0) | 2066 | (dun-remove-obj-from-inven obj-axe)) |
| 2081 | (progn | 2067 | (t |
| 2082 | (dun-mprincl "Your axe shatters into a million pieces.") | 2068 | (dun-mprincl "Your axe breaks it into a million pieces.") |
| 2083 | (dun-remove-obj-from-inven obj-axe)) | 2069 | (dun-remove-obj-from-room dun-current-room objnum))))))) |
| 2084 | (dun-mprincl "Your axe breaks it into a million pieces.") | ||
| 2085 | (dun-remove-obj-from-room dun-current-room objnum))))))))) | ||
| 2086 | 2070 | ||
| 2087 | (defun dun-drive (_args) | 2071 | (defun dun-drive (_args) |
| 2088 | (if (not dun-inbus) | 2072 | (if (not dun-inbus) |
| @@ -2178,8 +2162,7 @@ for a moment, then straighten yourself up. | |||
| 2178 | ;;; function associated with the verb, and passes along the other words. | 2162 | ;;; function associated with the verb, and passes along the other words. |
| 2179 | 2163 | ||
| 2180 | (defun dun-doverb (ignore verblist verb rest) | 2164 | (defun dun-doverb (ignore verblist verb rest) |
| 2181 | (if (not verb) | 2165 | (when verb |
| 2182 | nil | ||
| 2183 | (if (member (intern verb) ignore) | 2166 | (if (member (intern verb) ignore) |
| 2184 | (if (not (car rest)) -1 | 2167 | (if (not (car rest)) -1 |
| 2185 | (dun-doverb ignore verblist (car rest) (cdr rest))) | 2168 | (dun-doverb ignore verblist (car rest) (cdr rest))) |
| @@ -2250,9 +2233,9 @@ for a moment, then straighten yourself up. | |||
| 2250 | ;;; Read a line, in window mode | 2233 | ;;; Read a line, in window mode |
| 2251 | 2234 | ||
| 2252 | (defun dun-read-line () | 2235 | (defun dun-read-line () |
| 2253 | (let (line) | 2236 | (let ((line (read-string ""))) |
| 2254 | (setq line (read-string "")) | 2237 | (dun-mprinc line) |
| 2255 | (dun-mprinc line) line)) | 2238 | line)) |
| 2256 | 2239 | ||
| 2257 | ;;; Insert something into the window buffer | 2240 | ;;; Insert something into the window buffer |
| 2258 | 2241 | ||