diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/pooh-extensions.lisp b/ATL/Pooh/pooh-extensions.lisp index 5dd9adc..3260bfb 100644 --- a/ATL/Pooh/pooh-extensions.lisp +++ b/ATL/Pooh/pooh-extensions.lisp @@ -60,14 +60,14 @@ (num-list '("one jar" "two jars" "three jars" "four jars" "five jars" "six jars" "seven jars" "eight jars" "nine jars" "ten jars" "eleven jars" "twelve jars")) - (current-jars (read-from-string (item-description (get-game-object 'item "Storage object"))))) + (current-jars (get-state 'HONEY-JARS))) + (unless current-jars (setf current-jars 0)) (if (member "Hunny" (player-item player) :test #'equalp) (unless (= current-jars 12) (format t "~&You deposit one jar of honey in your larder.") (remove-object-attribute player 'item "Hunny") (incf current-jars) - (setf (item-description (get-game-object 'item "Storage object")) - (to-string current-jars)) + (save-state 'HONEY-JARS current-jars) (setf (item-description (get-game-object 'item "Shelf")) (concatenate 'string base-descr (string #\Newline) "It contains " (nth (1- current-jars) num-list) " of honey.")) @@ -220,10 +220,10 @@ (goto player "Stream")) (progn (format t "~&You clamber up on the rock.") (let ((place (get-game-object 'place (player-place player)))) - (when (member "Hunny" (place-hidden place) :test #'equalp) + (unless (get-state 'ROCK-HONEY-FOUND) (format t "~&You find a pot of honey!") (set-object-attribute place 'item "Hunny") - (remove-object-attribute place 'hidden "Hunny")))))) + (save-state 'ROCK-HONEY-FOUND)))))) (defun stream-current (player &optional arg) "The stream sweeps the player on into the Floody place." @@ -238,42 +238,43 @@ (cond ((equalp place "Sandy pit") (build-sandcastle)) ((equalp place "Bridge") (poohsticks player))))) -(let ((sandcastle 0)) - (defun build-sandcastle () - "The player builds a sandcastle at the sandy pit." - (let ((place (get-game-object 'place "Sandy pit"))) - (when (member "Sandcastle" (place-item place) :test #'equalp) - (format t "~&You've already built a sandcastle here! And a fine one it is too...") - (return-from build-sandcastle)) - (case sandcastle - (0 (format t "~&You decide to build a sandcastle!") - (setf (place-description place) - (concatenate 'string (place-description place) - "Somebody has been building a sandcastle here." #\newline))) - (20 (format t "~&You dig a large moat and erect the walls.")) - (40 (format t "~&You build four towers, one at each corner.")) - (60 (format t "~&You pile up sand for a big strong keep in the center.")) - (80 (format t "~&You decorate the castle, adding pretty little details.")) - (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") - (set-object-attribute place 'item "Sandcastle"))) - (unless (= sandcastle 100) (incf sandcastle 20))))) +(defun build-sandcastle () + "The player builds a sandcastle at the sandy pit." + (let ((place (get-game-object 'place "Sandy pit")) + (sandcastle (get-state 'SANDCASTLE))) + (unless sandcastle (setf sandcastle 0)) + (case sandcastle + (0 (format t "~&You decide to build a sandcastle!") + (setf (place-description place) + (concatenate 'string (place-description place) (list #\newline) + "Somebody has been building a sandcastle here."))) + (20 (format t "~&You dig a large moat and erect the walls.")) + (40 (format t "~&You build four towers, one at each corner.")) + (60 (format t "~&You pile up sand for a big strong keep in the center.")) + (80 (format t "~&You decorate the castle, adding pretty little details.")) + (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") + (set-object-attribute place 'item "Sandcastle")) + (120 (format t "~&You've already built a sandcastle here! And a fine one it is too..."))) + (unless (= sandcastle 120) (save-state 'SANDCASTLE (+ sandcastle 20))))) -(let ((score 0)) - (defun poohsticks (player) - "Play Poohsticks" - (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) - (format t "~&You need at least two sticks to play Poohsticks!") - (progn (remove-object-attribute player 'item "Stick") - (remove-object-attribute player 'item "Stick") - (format t "~&Which stick do you think will win?") - (setf choice (choose-number-option '("Stick A" "Stick B"))) - (setf winner (random 2)) - (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) - (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) - (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) - (if (= winner choice) - (progn (incf score) (format t "~&You win! Your score is now ~A." score)) - (progn (decf score) (format t "~&You lose! Your score is now ~A." score))))))) +(defun poohsticks (player) + "Play Poohsticks" + (unless (get-state 'POOHSTICKS) (save-state 'POOHSTICKS 0)) + (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) + (format t "~&You need at least two sticks to play Poohsticks!") + (progn (remove-object-attribute player 'item "Stick") + (remove-object-attribute player 'item "Stick") + (format t "~&Which stick do you think will win?") + (setf choice (choose-number-option '("Stick A" "Stick B"))) + (setf winner (random 2)) + (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) + (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) + (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) + (if (= winner choice) + (progn (save-state 'POOHSTICKS (1+ (get-state 'POOHSTICKS))) + (format t "~&You win! Your score is now ~A." (get-state 'POOHSTICKS))) + (progn (save-state 'POOHSTICKS (1- (get-state 'POOHSTICKS))) + (format t "~&You lose! Your score is now ~A." (get-state 'POOHSTICKS))))))) (defun blow (player &optional arg) "Blow up a balloon." @@ -311,15 +312,13 @@ (if (member "Letter" (player-item player) :test #'equalp) (when (y-or-n-p "Deposit the letter for Owl?") (remove-object-attribute player 'item "Letter") - (set-object-attribute (get-game-object 'place "Owl's home") - 'hidden "Letter") + (save-state 'LETTER-DEPOSITED) (format t "~&You throw the letter into the letter box.")) (format t "~&You don't have a letter to deposit here!"))) (defun read-letter (player &optional arg) (let ((place (get-game-object 'place "Owl's home"))) - (when (or (member "Letter" (place-item place) :test #'equalp) - (member "Letter" (place-hidden place) :test #'equalp)) + (when (get-state 'LETTER-DEPOSITED) (narrate "../ATL/Pooh/dialogue/letter.txt" '(0 1 2 2 3 2 3 2 2 2 3 1))))) @@ -409,6 +408,7 @@ (defun daniel-says (player) "Leave a message for the real me" + ;;XXX Figure out how to read the host name (unless (y-or-n-p "~&~%Daniel has more to say to you. Do you want to hear it?") (return-from daniel-says)) (setf msg "~%DANIEL: @@ -427,3 +427,4 @@ (write-to-file message (string-from-list (list "../" name ".msg") "") T) (format t "~&Thank you very much :-)")))) + diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/pooh-extensions.lisp b/ATL/Pooh/pooh-extensions.lisp index 5dd9adc..3260bfb 100644 --- a/ATL/Pooh/pooh-extensions.lisp +++ b/ATL/Pooh/pooh-extensions.lisp @@ -60,14 +60,14 @@ (num-list '("one jar" "two jars" "three jars" "four jars" "five jars" "six jars" "seven jars" "eight jars" "nine jars" "ten jars" "eleven jars" "twelve jars")) - (current-jars (read-from-string (item-description (get-game-object 'item "Storage object"))))) + (current-jars (get-state 'HONEY-JARS))) + (unless current-jars (setf current-jars 0)) (if (member "Hunny" (player-item player) :test #'equalp) (unless (= current-jars 12) (format t "~&You deposit one jar of honey in your larder.") (remove-object-attribute player 'item "Hunny") (incf current-jars) - (setf (item-description (get-game-object 'item "Storage object")) - (to-string current-jars)) + (save-state 'HONEY-JARS current-jars) (setf (item-description (get-game-object 'item "Shelf")) (concatenate 'string base-descr (string #\Newline) "It contains " (nth (1- current-jars) num-list) " of honey.")) @@ -220,10 +220,10 @@ (goto player "Stream")) (progn (format t "~&You clamber up on the rock.") (let ((place (get-game-object 'place (player-place player)))) - (when (member "Hunny" (place-hidden place) :test #'equalp) + (unless (get-state 'ROCK-HONEY-FOUND) (format t "~&You find a pot of honey!") (set-object-attribute place 'item "Hunny") - (remove-object-attribute place 'hidden "Hunny")))))) + (save-state 'ROCK-HONEY-FOUND)))))) (defun stream-current (player &optional arg) "The stream sweeps the player on into the Floody place." @@ -238,42 +238,43 @@ (cond ((equalp place "Sandy pit") (build-sandcastle)) ((equalp place "Bridge") (poohsticks player))))) -(let ((sandcastle 0)) - (defun build-sandcastle () - "The player builds a sandcastle at the sandy pit." - (let ((place (get-game-object 'place "Sandy pit"))) - (when (member "Sandcastle" (place-item place) :test #'equalp) - (format t "~&You've already built a sandcastle here! And a fine one it is too...") - (return-from build-sandcastle)) - (case sandcastle - (0 (format t "~&You decide to build a sandcastle!") - (setf (place-description place) - (concatenate 'string (place-description place) - "Somebody has been building a sandcastle here." #\newline))) - (20 (format t "~&You dig a large moat and erect the walls.")) - (40 (format t "~&You build four towers, one at each corner.")) - (60 (format t "~&You pile up sand for a big strong keep in the center.")) - (80 (format t "~&You decorate the castle, adding pretty little details.")) - (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") - (set-object-attribute place 'item "Sandcastle"))) - (unless (= sandcastle 100) (incf sandcastle 20))))) +(defun build-sandcastle () + "The player builds a sandcastle at the sandy pit." + (let ((place (get-game-object 'place "Sandy pit")) + (sandcastle (get-state 'SANDCASTLE))) + (unless sandcastle (setf sandcastle 0)) + (case sandcastle + (0 (format t "~&You decide to build a sandcastle!") + (setf (place-description place) + (concatenate 'string (place-description place) (list #\newline) + "Somebody has been building a sandcastle here."))) + (20 (format t "~&You dig a large moat and erect the walls.")) + (40 (format t "~&You build four towers, one at each corner.")) + (60 (format t "~&You pile up sand for a big strong keep in the center.")) + (80 (format t "~&You decorate the castle, adding pretty little details.")) + (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") + (set-object-attribute place 'item "Sandcastle")) + (120 (format t "~&You've already built a sandcastle here! And a fine one it is too..."))) + (unless (= sandcastle 120) (save-state 'SANDCASTLE (+ sandcastle 20))))) -(let ((score 0)) - (defun poohsticks (player) - "Play Poohsticks" - (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) - (format t "~&You need at least two sticks to play Poohsticks!") - (progn (remove-object-attribute player 'item "Stick") - (remove-object-attribute player 'item "Stick") - (format t "~&Which stick do you think will win?") - (setf choice (choose-number-option '("Stick A" "Stick B"))) - (setf winner (random 2)) - (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) - (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) - (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) - (if (= winner choice) - (progn (incf score) (format t "~&You win! Your score is now ~A." score)) - (progn (decf score) (format t "~&You lose! Your score is now ~A." score))))))) +(defun poohsticks (player) + "Play Poohsticks" + (unless (get-state 'POOHSTICKS) (save-state 'POOHSTICKS 0)) + (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) + (format t "~&You need at least two sticks to play Poohsticks!") + (progn (remove-object-attribute player 'item "Stick") + (remove-object-attribute player 'item "Stick") + (format t "~&Which stick do you think will win?") + (setf choice (choose-number-option '("Stick A" "Stick B"))) + (setf winner (random 2)) + (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) + (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) + (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) + (if (= winner choice) + (progn (save-state 'POOHSTICKS (1+ (get-state 'POOHSTICKS))) + (format t "~&You win! Your score is now ~A." (get-state 'POOHSTICKS))) + (progn (save-state 'POOHSTICKS (1- (get-state 'POOHSTICKS))) + (format t "~&You lose! Your score is now ~A." (get-state 'POOHSTICKS))))))) (defun blow (player &optional arg) "Blow up a balloon." @@ -311,15 +312,13 @@ (if (member "Letter" (player-item player) :test #'equalp) (when (y-or-n-p "Deposit the letter for Owl?") (remove-object-attribute player 'item "Letter") - (set-object-attribute (get-game-object 'place "Owl's home") - 'hidden "Letter") + (save-state 'LETTER-DEPOSITED) (format t "~&You throw the letter into the letter box.")) (format t "~&You don't have a letter to deposit here!"))) (defun read-letter (player &optional arg) (let ((place (get-game-object 'place "Owl's home"))) - (when (or (member "Letter" (place-item place) :test #'equalp) - (member "Letter" (place-hidden place) :test #'equalp)) + (when (get-state 'LETTER-DEPOSITED) (narrate "../ATL/Pooh/dialogue/letter.txt" '(0 1 2 2 3 2 3 2 2 2 3 1))))) @@ -409,6 +408,7 @@ (defun daniel-says (player) "Leave a message for the real me" + ;;XXX Figure out how to read the host name (unless (y-or-n-p "~&~%Daniel has more to say to you. Do you want to hear it?") (return-from daniel-says)) (setf msg "~%DANIEL: @@ -427,3 +427,4 @@ (write-to-file message (string-from-list (list "../" name ".msg") "") T) (format t "~&Thank you very much :-)")))) + diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index 70ffe8a..452e590 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -23,4 +23,4 @@ ;TODO development - remove before release define-player "Christopher Robin" description "Christopher Robin is my game dev character." - place "Eastern woods" \ No newline at end of file + place "Owl's porch" \ No newline at end of file diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/pooh-extensions.lisp b/ATL/Pooh/pooh-extensions.lisp index 5dd9adc..3260bfb 100644 --- a/ATL/Pooh/pooh-extensions.lisp +++ b/ATL/Pooh/pooh-extensions.lisp @@ -60,14 +60,14 @@ (num-list '("one jar" "two jars" "three jars" "four jars" "five jars" "six jars" "seven jars" "eight jars" "nine jars" "ten jars" "eleven jars" "twelve jars")) - (current-jars (read-from-string (item-description (get-game-object 'item "Storage object"))))) + (current-jars (get-state 'HONEY-JARS))) + (unless current-jars (setf current-jars 0)) (if (member "Hunny" (player-item player) :test #'equalp) (unless (= current-jars 12) (format t "~&You deposit one jar of honey in your larder.") (remove-object-attribute player 'item "Hunny") (incf current-jars) - (setf (item-description (get-game-object 'item "Storage object")) - (to-string current-jars)) + (save-state 'HONEY-JARS current-jars) (setf (item-description (get-game-object 'item "Shelf")) (concatenate 'string base-descr (string #\Newline) "It contains " (nth (1- current-jars) num-list) " of honey.")) @@ -220,10 +220,10 @@ (goto player "Stream")) (progn (format t "~&You clamber up on the rock.") (let ((place (get-game-object 'place (player-place player)))) - (when (member "Hunny" (place-hidden place) :test #'equalp) + (unless (get-state 'ROCK-HONEY-FOUND) (format t "~&You find a pot of honey!") (set-object-attribute place 'item "Hunny") - (remove-object-attribute place 'hidden "Hunny")))))) + (save-state 'ROCK-HONEY-FOUND)))))) (defun stream-current (player &optional arg) "The stream sweeps the player on into the Floody place." @@ -238,42 +238,43 @@ (cond ((equalp place "Sandy pit") (build-sandcastle)) ((equalp place "Bridge") (poohsticks player))))) -(let ((sandcastle 0)) - (defun build-sandcastle () - "The player builds a sandcastle at the sandy pit." - (let ((place (get-game-object 'place "Sandy pit"))) - (when (member "Sandcastle" (place-item place) :test #'equalp) - (format t "~&You've already built a sandcastle here! And a fine one it is too...") - (return-from build-sandcastle)) - (case sandcastle - (0 (format t "~&You decide to build a sandcastle!") - (setf (place-description place) - (concatenate 'string (place-description place) - "Somebody has been building a sandcastle here." #\newline))) - (20 (format t "~&You dig a large moat and erect the walls.")) - (40 (format t "~&You build four towers, one at each corner.")) - (60 (format t "~&You pile up sand for a big strong keep in the center.")) - (80 (format t "~&You decorate the castle, adding pretty little details.")) - (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") - (set-object-attribute place 'item "Sandcastle"))) - (unless (= sandcastle 100) (incf sandcastle 20))))) +(defun build-sandcastle () + "The player builds a sandcastle at the sandy pit." + (let ((place (get-game-object 'place "Sandy pit")) + (sandcastle (get-state 'SANDCASTLE))) + (unless sandcastle (setf sandcastle 0)) + (case sandcastle + (0 (format t "~&You decide to build a sandcastle!") + (setf (place-description place) + (concatenate 'string (place-description place) (list #\newline) + "Somebody has been building a sandcastle here."))) + (20 (format t "~&You dig a large moat and erect the walls.")) + (40 (format t "~&You build four towers, one at each corner.")) + (60 (format t "~&You pile up sand for a big strong keep in the center.")) + (80 (format t "~&You decorate the castle, adding pretty little details.")) + (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") + (set-object-attribute place 'item "Sandcastle")) + (120 (format t "~&You've already built a sandcastle here! And a fine one it is too..."))) + (unless (= sandcastle 120) (save-state 'SANDCASTLE (+ sandcastle 20))))) -(let ((score 0)) - (defun poohsticks (player) - "Play Poohsticks" - (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) - (format t "~&You need at least two sticks to play Poohsticks!") - (progn (remove-object-attribute player 'item "Stick") - (remove-object-attribute player 'item "Stick") - (format t "~&Which stick do you think will win?") - (setf choice (choose-number-option '("Stick A" "Stick B"))) - (setf winner (random 2)) - (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) - (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) - (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) - (if (= winner choice) - (progn (incf score) (format t "~&You win! Your score is now ~A." score)) - (progn (decf score) (format t "~&You lose! Your score is now ~A." score))))))) +(defun poohsticks (player) + "Play Poohsticks" + (unless (get-state 'POOHSTICKS) (save-state 'POOHSTICKS 0)) + (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) + (format t "~&You need at least two sticks to play Poohsticks!") + (progn (remove-object-attribute player 'item "Stick") + (remove-object-attribute player 'item "Stick") + (format t "~&Which stick do you think will win?") + (setf choice (choose-number-option '("Stick A" "Stick B"))) + (setf winner (random 2)) + (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) + (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) + (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) + (if (= winner choice) + (progn (save-state 'POOHSTICKS (1+ (get-state 'POOHSTICKS))) + (format t "~&You win! Your score is now ~A." (get-state 'POOHSTICKS))) + (progn (save-state 'POOHSTICKS (1- (get-state 'POOHSTICKS))) + (format t "~&You lose! Your score is now ~A." (get-state 'POOHSTICKS))))))) (defun blow (player &optional arg) "Blow up a balloon." @@ -311,15 +312,13 @@ (if (member "Letter" (player-item player) :test #'equalp) (when (y-or-n-p "Deposit the letter for Owl?") (remove-object-attribute player 'item "Letter") - (set-object-attribute (get-game-object 'place "Owl's home") - 'hidden "Letter") + (save-state 'LETTER-DEPOSITED) (format t "~&You throw the letter into the letter box.")) (format t "~&You don't have a letter to deposit here!"))) (defun read-letter (player &optional arg) (let ((place (get-game-object 'place "Owl's home"))) - (when (or (member "Letter" (place-item place) :test #'equalp) - (member "Letter" (place-hidden place) :test #'equalp)) + (when (get-state 'LETTER-DEPOSITED) (narrate "../ATL/Pooh/dialogue/letter.txt" '(0 1 2 2 3 2 3 2 2 2 3 1))))) @@ -409,6 +408,7 @@ (defun daniel-says (player) "Leave a message for the real me" + ;;XXX Figure out how to read the host name (unless (y-or-n-p "~&~%Daniel has more to say to you. Do you want to hear it?") (return-from daniel-says)) (setf msg "~%DANIEL: @@ -427,3 +427,4 @@ (write-to-file message (string-from-list (list "../" name ".msg") "") T) (format t "~&Thank you very much :-)")))) + diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index 70ffe8a..452e590 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -23,4 +23,4 @@ ;TODO development - remove before release define-player "Christopher Robin" description "Christopher Robin is my game dev character." - place "Eastern woods" \ No newline at end of file + place "Owl's porch" \ No newline at end of file diff --git a/ATL/Pooh/woods.atl b/ATL/Pooh/woods.atl index f50e727..7b81805 100644 --- a/ATL/Pooh/woods.atl +++ b/ATL/Pooh/woods.atl @@ -165,6 +165,7 @@ requires "Key" define-place "Bridge" + ;;TODO Expand description to include Poohsticks description "A simple wooden bridge spans the stream that marks the edge of the 100 Acre Wood. For all practical purposes, the world ends here." neighbour "Southern woods" @@ -281,7 +282,6 @@ item "North Pole" item "Rock" item "Stone" - hidden "Hunny" neighbour "Northern woods" neighbour "Misty forest" neighbour "Stream" diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/pooh-extensions.lisp b/ATL/Pooh/pooh-extensions.lisp index 5dd9adc..3260bfb 100644 --- a/ATL/Pooh/pooh-extensions.lisp +++ b/ATL/Pooh/pooh-extensions.lisp @@ -60,14 +60,14 @@ (num-list '("one jar" "two jars" "three jars" "four jars" "five jars" "six jars" "seven jars" "eight jars" "nine jars" "ten jars" "eleven jars" "twelve jars")) - (current-jars (read-from-string (item-description (get-game-object 'item "Storage object"))))) + (current-jars (get-state 'HONEY-JARS))) + (unless current-jars (setf current-jars 0)) (if (member "Hunny" (player-item player) :test #'equalp) (unless (= current-jars 12) (format t "~&You deposit one jar of honey in your larder.") (remove-object-attribute player 'item "Hunny") (incf current-jars) - (setf (item-description (get-game-object 'item "Storage object")) - (to-string current-jars)) + (save-state 'HONEY-JARS current-jars) (setf (item-description (get-game-object 'item "Shelf")) (concatenate 'string base-descr (string #\Newline) "It contains " (nth (1- current-jars) num-list) " of honey.")) @@ -220,10 +220,10 @@ (goto player "Stream")) (progn (format t "~&You clamber up on the rock.") (let ((place (get-game-object 'place (player-place player)))) - (when (member "Hunny" (place-hidden place) :test #'equalp) + (unless (get-state 'ROCK-HONEY-FOUND) (format t "~&You find a pot of honey!") (set-object-attribute place 'item "Hunny") - (remove-object-attribute place 'hidden "Hunny")))))) + (save-state 'ROCK-HONEY-FOUND)))))) (defun stream-current (player &optional arg) "The stream sweeps the player on into the Floody place." @@ -238,42 +238,43 @@ (cond ((equalp place "Sandy pit") (build-sandcastle)) ((equalp place "Bridge") (poohsticks player))))) -(let ((sandcastle 0)) - (defun build-sandcastle () - "The player builds a sandcastle at the sandy pit." - (let ((place (get-game-object 'place "Sandy pit"))) - (when (member "Sandcastle" (place-item place) :test #'equalp) - (format t "~&You've already built a sandcastle here! And a fine one it is too...") - (return-from build-sandcastle)) - (case sandcastle - (0 (format t "~&You decide to build a sandcastle!") - (setf (place-description place) - (concatenate 'string (place-description place) - "Somebody has been building a sandcastle here." #\newline))) - (20 (format t "~&You dig a large moat and erect the walls.")) - (40 (format t "~&You build four towers, one at each corner.")) - (60 (format t "~&You pile up sand for a big strong keep in the center.")) - (80 (format t "~&You decorate the castle, adding pretty little details.")) - (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") - (set-object-attribute place 'item "Sandcastle"))) - (unless (= sandcastle 100) (incf sandcastle 20))))) +(defun build-sandcastle () + "The player builds a sandcastle at the sandy pit." + (let ((place (get-game-object 'place "Sandy pit")) + (sandcastle (get-state 'SANDCASTLE))) + (unless sandcastle (setf sandcastle 0)) + (case sandcastle + (0 (format t "~&You decide to build a sandcastle!") + (setf (place-description place) + (concatenate 'string (place-description place) (list #\newline) + "Somebody has been building a sandcastle here."))) + (20 (format t "~&You dig a large moat and erect the walls.")) + (40 (format t "~&You build four towers, one at each corner.")) + (60 (format t "~&You pile up sand for a big strong keep in the center.")) + (80 (format t "~&You decorate the castle, adding pretty little details.")) + (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") + (set-object-attribute place 'item "Sandcastle")) + (120 (format t "~&You've already built a sandcastle here! And a fine one it is too..."))) + (unless (= sandcastle 120) (save-state 'SANDCASTLE (+ sandcastle 20))))) -(let ((score 0)) - (defun poohsticks (player) - "Play Poohsticks" - (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) - (format t "~&You need at least two sticks to play Poohsticks!") - (progn (remove-object-attribute player 'item "Stick") - (remove-object-attribute player 'item "Stick") - (format t "~&Which stick do you think will win?") - (setf choice (choose-number-option '("Stick A" "Stick B"))) - (setf winner (random 2)) - (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) - (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) - (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) - (if (= winner choice) - (progn (incf score) (format t "~&You win! Your score is now ~A." score)) - (progn (decf score) (format t "~&You lose! Your score is now ~A." score))))))) +(defun poohsticks (player) + "Play Poohsticks" + (unless (get-state 'POOHSTICKS) (save-state 'POOHSTICKS 0)) + (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) + (format t "~&You need at least two sticks to play Poohsticks!") + (progn (remove-object-attribute player 'item "Stick") + (remove-object-attribute player 'item "Stick") + (format t "~&Which stick do you think will win?") + (setf choice (choose-number-option '("Stick A" "Stick B"))) + (setf winner (random 2)) + (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) + (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) + (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) + (if (= winner choice) + (progn (save-state 'POOHSTICKS (1+ (get-state 'POOHSTICKS))) + (format t "~&You win! Your score is now ~A." (get-state 'POOHSTICKS))) + (progn (save-state 'POOHSTICKS (1- (get-state 'POOHSTICKS))) + (format t "~&You lose! Your score is now ~A." (get-state 'POOHSTICKS))))))) (defun blow (player &optional arg) "Blow up a balloon." @@ -311,15 +312,13 @@ (if (member "Letter" (player-item player) :test #'equalp) (when (y-or-n-p "Deposit the letter for Owl?") (remove-object-attribute player 'item "Letter") - (set-object-attribute (get-game-object 'place "Owl's home") - 'hidden "Letter") + (save-state 'LETTER-DEPOSITED) (format t "~&You throw the letter into the letter box.")) (format t "~&You don't have a letter to deposit here!"))) (defun read-letter (player &optional arg) (let ((place (get-game-object 'place "Owl's home"))) - (when (or (member "Letter" (place-item place) :test #'equalp) - (member "Letter" (place-hidden place) :test #'equalp)) + (when (get-state 'LETTER-DEPOSITED) (narrate "../ATL/Pooh/dialogue/letter.txt" '(0 1 2 2 3 2 3 2 2 2 3 1))))) @@ -409,6 +408,7 @@ (defun daniel-says (player) "Leave a message for the real me" + ;;XXX Figure out how to read the host name (unless (y-or-n-p "~&~%Daniel has more to say to you. Do you want to hear it?") (return-from daniel-says)) (setf msg "~%DANIEL: @@ -427,3 +427,4 @@ (write-to-file message (string-from-list (list "../" name ".msg") "") T) (format t "~&Thank you very much :-)")))) + diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index 70ffe8a..452e590 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -23,4 +23,4 @@ ;TODO development - remove before release define-player "Christopher Robin" description "Christopher Robin is my game dev character." - place "Eastern woods" \ No newline at end of file + place "Owl's porch" \ No newline at end of file diff --git a/ATL/Pooh/woods.atl b/ATL/Pooh/woods.atl index f50e727..7b81805 100644 --- a/ATL/Pooh/woods.atl +++ b/ATL/Pooh/woods.atl @@ -165,6 +165,7 @@ requires "Key" define-place "Bridge" + ;;TODO Expand description to include Poohsticks description "A simple wooden bridge spans the stream that marks the edge of the 100 Acre Wood. For all practical purposes, the world ends here." neighbour "Southern woods" @@ -281,7 +282,6 @@ item "North Pole" item "Rock" item "Stone" - hidden "Hunny" neighbour "Northern woods" neighbour "Misty forest" neighbour "Stream" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index 3b8d635..a833122 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -69,7 +69,9 @@ (line (nth line-nr source) (nth line-nr source)) (trimmed-line (trim-whitespace line) (trim-whitespace line)) (current-object NIL)) - ((= line-nr (length source)) NIL) + ((= line-nr (length source)) + (when current-object (add-game-object current-object)) + NIL) ;; concatenate string arguments spanning several lines (while (= (count-instances #\" line) 1) (incf line-nr) diff --git a/ATL/Pooh/items.atl b/ATL/Pooh/items.atl index f03f30a..becf0a2 100644 --- a/ATL/Pooh/items.atl +++ b/ATL/Pooh/items.atl @@ -20,11 +20,6 @@ All the slots are empty!" fixed -define-item "Storage object" - ; This is a special item that I need to store state about the player's progress. - ; It never appears in the game. - description "0" - define-item "Key" description "This is the key to your larder. You smile. Life is good when you have plenty of honey!" diff --git a/ATL/Pooh/place_list.txt b/ATL/Pooh/place_list.txt index 5c0632a..1e5775e 100644 --- a/ATL/Pooh/place_list.txt +++ b/ATL/Pooh/place_list.txt @@ -12,6 +12,7 @@ Hill Galleons lap Bridge +Thoughtful spot Piglet's porch Piglet's home Kanga's house @@ -24,10 +25,10 @@ Rapids Stream Christopher Robin's house +Workshop Owl's porch Owl's home Floody place Eeyore's gloomy place Woozle hideout Misty forest -The World diff --git a/ATL/Pooh/pooh-extensions.lisp b/ATL/Pooh/pooh-extensions.lisp index 5dd9adc..3260bfb 100644 --- a/ATL/Pooh/pooh-extensions.lisp +++ b/ATL/Pooh/pooh-extensions.lisp @@ -60,14 +60,14 @@ (num-list '("one jar" "two jars" "three jars" "four jars" "five jars" "six jars" "seven jars" "eight jars" "nine jars" "ten jars" "eleven jars" "twelve jars")) - (current-jars (read-from-string (item-description (get-game-object 'item "Storage object"))))) + (current-jars (get-state 'HONEY-JARS))) + (unless current-jars (setf current-jars 0)) (if (member "Hunny" (player-item player) :test #'equalp) (unless (= current-jars 12) (format t "~&You deposit one jar of honey in your larder.") (remove-object-attribute player 'item "Hunny") (incf current-jars) - (setf (item-description (get-game-object 'item "Storage object")) - (to-string current-jars)) + (save-state 'HONEY-JARS current-jars) (setf (item-description (get-game-object 'item "Shelf")) (concatenate 'string base-descr (string #\Newline) "It contains " (nth (1- current-jars) num-list) " of honey.")) @@ -220,10 +220,10 @@ (goto player "Stream")) (progn (format t "~&You clamber up on the rock.") (let ((place (get-game-object 'place (player-place player)))) - (when (member "Hunny" (place-hidden place) :test #'equalp) + (unless (get-state 'ROCK-HONEY-FOUND) (format t "~&You find a pot of honey!") (set-object-attribute place 'item "Hunny") - (remove-object-attribute place 'hidden "Hunny")))))) + (save-state 'ROCK-HONEY-FOUND)))))) (defun stream-current (player &optional arg) "The stream sweeps the player on into the Floody place." @@ -238,42 +238,43 @@ (cond ((equalp place "Sandy pit") (build-sandcastle)) ((equalp place "Bridge") (poohsticks player))))) -(let ((sandcastle 0)) - (defun build-sandcastle () - "The player builds a sandcastle at the sandy pit." - (let ((place (get-game-object 'place "Sandy pit"))) - (when (member "Sandcastle" (place-item place) :test #'equalp) - (format t "~&You've already built a sandcastle here! And a fine one it is too...") - (return-from build-sandcastle)) - (case sandcastle - (0 (format t "~&You decide to build a sandcastle!") - (setf (place-description place) - (concatenate 'string (place-description place) - "Somebody has been building a sandcastle here." #\newline))) - (20 (format t "~&You dig a large moat and erect the walls.")) - (40 (format t "~&You build four towers, one at each corner.")) - (60 (format t "~&You pile up sand for a big strong keep in the center.")) - (80 (format t "~&You decorate the castle, adding pretty little details.")) - (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") - (set-object-attribute place 'item "Sandcastle"))) - (unless (= sandcastle 100) (incf sandcastle 20))))) +(defun build-sandcastle () + "The player builds a sandcastle at the sandy pit." + (let ((place (get-game-object 'place "Sandy pit")) + (sandcastle (get-state 'SANDCASTLE))) + (unless sandcastle (setf sandcastle 0)) + (case sandcastle + (0 (format t "~&You decide to build a sandcastle!") + (setf (place-description place) + (concatenate 'string (place-description place) (list #\newline) + "Somebody has been building a sandcastle here."))) + (20 (format t "~&You dig a large moat and erect the walls.")) + (40 (format t "~&You build four towers, one at each corner.")) + (60 (format t "~&You pile up sand for a big strong keep in the center.")) + (80 (format t "~&You decorate the castle, adding pretty little details.")) + (100 (format t "~&You stand back and admire your handiwork. What a fine castle!") + (set-object-attribute place 'item "Sandcastle")) + (120 (format t "~&You've already built a sandcastle here! And a fine one it is too..."))) + (unless (= sandcastle 120) (save-state 'SANDCASTLE (+ sandcastle 20))))) -(let ((score 0)) - (defun poohsticks (player) - "Play Poohsticks" - (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) - (format t "~&You need at least two sticks to play Poohsticks!") - (progn (remove-object-attribute player 'item "Stick") - (remove-object-attribute player 'item "Stick") - (format t "~&Which stick do you think will win?") - (setf choice (choose-number-option '("Stick A" "Stick B"))) - (setf winner (random 2)) - (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) - (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) - (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) - (if (= winner choice) - (progn (incf score) (format t "~&You win! Your score is now ~A." score)) - (progn (decf score) (format t "~&You lose! Your score is now ~A." score))))))) +(defun poohsticks (player) + "Play Poohsticks" + (unless (get-state 'POOHSTICKS) (save-state 'POOHSTICKS 0)) + (if (< (count-instances "Stick" (player-item player) :test #'equalp) 2) + (format t "~&You need at least two sticks to play Poohsticks!") + (progn (remove-object-attribute player 'item "Stick") + (remove-object-attribute player 'item "Stick") + (format t "~&Which stick do you think will win?") + (setf choice (choose-number-option '("Stick A" "Stick B"))) + (setf winner (random 2)) + (format t "~&You throw both sticks into the stream on one side of the bridge.") (sleep 1) + (format t "~&You run to the other side and lean over the railing.") (sleep (random 4)) + (format t "~&~A comes out first!" (nth winner '("Stick A" "Stick B"))) (sleep 1) + (if (= winner choice) + (progn (save-state 'POOHSTICKS (1+ (get-state 'POOHSTICKS))) + (format t "~&You win! Your score is now ~A." (get-state 'POOHSTICKS))) + (progn (save-state 'POOHSTICKS (1- (get-state 'POOHSTICKS))) + (format t "~&You lose! Your score is now ~A." (get-state 'POOHSTICKS))))))) (defun blow (player &optional arg) "Blow up a balloon." @@ -311,15 +312,13 @@ (if (member "Letter" (player-item player) :test #'equalp) (when (y-or-n-p "Deposit the letter for Owl?") (remove-object-attribute player 'item "Letter") - (set-object-attribute (get-game-object 'place "Owl's home") - 'hidden "Letter") + (save-state 'LETTER-DEPOSITED) (format t "~&You throw the letter into the letter box.")) (format t "~&You don't have a letter to deposit here!"))) (defun read-letter (player &optional arg) (let ((place (get-game-object 'place "Owl's home"))) - (when (or (member "Letter" (place-item place) :test #'equalp) - (member "Letter" (place-hidden place) :test #'equalp)) + (when (get-state 'LETTER-DEPOSITED) (narrate "../ATL/Pooh/dialogue/letter.txt" '(0 1 2 2 3 2 3 2 2 2 3 1))))) @@ -409,6 +408,7 @@ (defun daniel-says (player) "Leave a message for the real me" + ;;XXX Figure out how to read the host name (unless (y-or-n-p "~&~%Daniel has more to say to you. Do you want to hear it?") (return-from daniel-says)) (setf msg "~%DANIEL: @@ -427,3 +427,4 @@ (write-to-file message (string-from-list (list "../" name ".msg") "") T) (format t "~&Thank you very much :-)")))) + diff --git a/ATL/Pooh/pooh.atl b/ATL/Pooh/pooh.atl index 70ffe8a..452e590 100644 --- a/ATL/Pooh/pooh.atl +++ b/ATL/Pooh/pooh.atl @@ -23,4 +23,4 @@ ;TODO development - remove before release define-player "Christopher Robin" description "Christopher Robin is my game dev character." - place "Eastern woods" \ No newline at end of file + place "Owl's porch" \ No newline at end of file diff --git a/ATL/Pooh/woods.atl b/ATL/Pooh/woods.atl index f50e727..7b81805 100644 --- a/ATL/Pooh/woods.atl +++ b/ATL/Pooh/woods.atl @@ -165,6 +165,7 @@ requires "Key" define-place "Bridge" + ;;TODO Expand description to include Poohsticks description "A simple wooden bridge spans the stream that marks the edge of the 100 Acre Wood. For all practical purposes, the world ends here." neighbour "Southern woods" @@ -281,7 +282,6 @@ item "North Pole" item "Rock" item "Stone" - hidden "Hunny" neighbour "Northern woods" neighbour "Misty forest" neighbour "Stream" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index 3b8d635..a833122 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -69,7 +69,9 @@ (line (nth line-nr source) (nth line-nr source)) (trimmed-line (trim-whitespace line) (trim-whitespace line)) (current-object NIL)) - ((= line-nr (length source)) NIL) + ((= line-nr (length source)) + (when current-object (add-game-object current-object)) + NIL) ;; concatenate string arguments spanning several lines (while (= (count-instances #\" line) 1) (incf line-nr) diff --git a/lisp/world.lisp b/lisp/world.lisp index 0509ee7..77bb22e 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -78,3 +78,26 @@ (world-player-name *world*) ".world"))) (with-open-file (g game-file :direction :output) (format g "~S~%~S~%" ATLANTIS-VERSION *world*))) + +(defun save-state (var &optional (value T)) + "Save the value of a game variable in a special game item." + ;; This is intended for game developers who need to save + ;; state between game sessions. + (let ((aso (get-game-object 'item "Atlantis Storage Object"))) + (when (null aso) + (setf aso (make-item :name "Atlantis Storage Object" + :description '())) + (add-game-object aso)) + (if (member var (keys (item-description aso))) + (setf (cassoc var (item-description aso)) value) + (setf (item-description aso) + (append (item-description aso) (list (list var value))))))) + +(defun get-state (var) + "Return the saved value of the given variable." + ;; This is intended for game developers who need to save + ;; state between game sessions. + (let ((aso (get-game-object 'item "Atlantis Storage Object"))) + (unless (or (null aso) (not (member var (keys (item-description aso))))) + (cassoc var (item-description aso))))) +