diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/lisp/world.lisp b/lisp/world.lisp index 43ecfa5..48a2dac 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -14,7 +14,7 @@ ;; The world is basically a list of struct instances representing -;; each game object +;; each object created in this game (defstruct world (players NIL) @@ -23,6 +23,7 @@ (npcs NIL) (items NIL)) +(setf *world* (make-world)) ;; (defmacro add-game-object (game-object) ;; "Add a game-object to the *world*" @@ -36,6 +37,7 @@ ;; (append (,object-function *world*) ,game-object)))) +;FIXME Needs work (defmacro add-game-object (game-object) "Add a game-object to the *world*" (let ((attribute-list @@ -45,3 +47,9 @@ ((npc-p game-object) '(world-npcs *world*)) ((item-p game-object) '(world-items *world*))))) `(setf ,attribute-list (append ,attribute-list ,game-object)))) + +; TODO +(defmacro get-game-object (object-name)) + +;TODO +(defmacro set-object-attribute (game-object property value)) diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/lisp/world.lisp b/lisp/world.lisp index 43ecfa5..48a2dac 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -14,7 +14,7 @@ ;; The world is basically a list of struct instances representing -;; each game object +;; each object created in this game (defstruct world (players NIL) @@ -23,6 +23,7 @@ (npcs NIL) (items NIL)) +(setf *world* (make-world)) ;; (defmacro add-game-object (game-object) ;; "Add a game-object to the *world*" @@ -36,6 +37,7 @@ ;; (append (,object-function *world*) ,game-object)))) +;FIXME Needs work (defmacro add-game-object (game-object) "Add a game-object to the *world*" (let ((attribute-list @@ -45,3 +47,9 @@ ((npc-p game-object) '(world-npcs *world*)) ((item-p game-object) '(world-items *world*))))) `(setf ,attribute-list (append ,attribute-list ,game-object)))) + +; TODO +(defmacro get-game-object (object-name)) + +;TODO +(defmacro set-object-attribute (game-object property value)) diff --git a/worlds/Example/example.atl b/worlds/Example/example.atl deleted file mode 100644 index 3101edd..0000000 --- a/worlds/Example/example.atl +++ /dev/null @@ -1,72 +0,0 @@ -# This is an example Atlantis file - I use it to explore what the language -# should end up looking like. - -load races.atl -load classes.atl - - -define-quest Kill hellhound - objective kill hellhound - reward gold 300 - - -define-spell Ray of death - type kill - min-intelligence 12 - success-rate 35 - - -define-npc Hades - say Oh, amazing, you actually got here! Who did you bribe? - sell 30 Ambrosia - quest Kill hellhound - - -define-item Scroll of light - value 80 - add-experience 20 - add-spell Ray of death - -define-item Ambrosia - category Food - add-health 5 - - -define-monster Hellhound - armor-class 8 - strength 10 - melee-weapon 2 claws - experience 50 - spawn 2 - aggression 60 - -define-monster Fury - armor-class 5 - strength 8 - melee-weapon 10 fire whip - experience 74 - spawn 0.8 - aggression 30 - - -define-place Nowhere - description Welcome to Nowhere! You are in the void, the space between \ -the worlds. Around you is black. Black, except for one tiny pin-prick of light \ -to the north. - neighbour Elysium - -define-place Elysium - description Congratulations! You have achieved Elysium! - neighbour Nowhere - neighbour Fields of punishment - npc Hades - item Scroll of light - -define-place Fields of punishment - description You really, really don't want to end up here... - neighbour Elysium - monster Hellhound - monster Fury - - -start-place Elysium \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/lisp/world.lisp b/lisp/world.lisp index 43ecfa5..48a2dac 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -14,7 +14,7 @@ ;; The world is basically a list of struct instances representing -;; each game object +;; each object created in this game (defstruct world (players NIL) @@ -23,6 +23,7 @@ (npcs NIL) (items NIL)) +(setf *world* (make-world)) ;; (defmacro add-game-object (game-object) ;; "Add a game-object to the *world*" @@ -36,6 +37,7 @@ ;; (append (,object-function *world*) ,game-object)))) +;FIXME Needs work (defmacro add-game-object (game-object) "Add a game-object to the *world*" (let ((attribute-list @@ -45,3 +47,9 @@ ((npc-p game-object) '(world-npcs *world*)) ((item-p game-object) '(world-items *world*))))) `(setf ,attribute-list (append ,attribute-list ,game-object)))) + +; TODO +(defmacro get-game-object (object-name)) + +;TODO +(defmacro set-object-attribute (game-object property value)) diff --git a/worlds/Example/example.atl b/worlds/Example/example.atl deleted file mode 100644 index 3101edd..0000000 --- a/worlds/Example/example.atl +++ /dev/null @@ -1,72 +0,0 @@ -# This is an example Atlantis file - I use it to explore what the language -# should end up looking like. - -load races.atl -load classes.atl - - -define-quest Kill hellhound - objective kill hellhound - reward gold 300 - - -define-spell Ray of death - type kill - min-intelligence 12 - success-rate 35 - - -define-npc Hades - say Oh, amazing, you actually got here! Who did you bribe? - sell 30 Ambrosia - quest Kill hellhound - - -define-item Scroll of light - value 80 - add-experience 20 - add-spell Ray of death - -define-item Ambrosia - category Food - add-health 5 - - -define-monster Hellhound - armor-class 8 - strength 10 - melee-weapon 2 claws - experience 50 - spawn 2 - aggression 60 - -define-monster Fury - armor-class 5 - strength 8 - melee-weapon 10 fire whip - experience 74 - spawn 0.8 - aggression 30 - - -define-place Nowhere - description Welcome to Nowhere! You are in the void, the space between \ -the worlds. Around you is black. Black, except for one tiny pin-prick of light \ -to the north. - neighbour Elysium - -define-place Elysium - description Congratulations! You have achieved Elysium! - neighbour Nowhere - neighbour Fields of punishment - npc Hades - item Scroll of light - -define-place Fields of punishment - description You really, really don't want to end up here... - neighbour Elysium - monster Hellhound - monster Fury - - -start-place Elysium \ No newline at end of file diff --git a/worlds/Example/lisp-test.atl b/worlds/Example/lisp-test.atl deleted file mode 100644 index fdb5416..0000000 --- a/worlds/Example/lisp-test.atl +++ /dev/null @@ -1,18 +0,0 @@ -; This is a simple test ATL file to test whatever I have implemented so far. -; @author Daniel Vedder -; @date 04/05/2015 - -define-place "Nowhere" - description "Welcome to Nowhere!" -;You are in the void, the space between -;the worlds. Around you is black. Black, except for one tiny pin-prick of -;light to the north. - neighbour "Elysium" - -define-place "Elysium" - description "This is where you want to be when you are six feet under..." - neighbour "Nowhere" - -;load test2.atl - -start-place "Nowhere" \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/lisp/world.lisp b/lisp/world.lisp index 43ecfa5..48a2dac 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -14,7 +14,7 @@ ;; The world is basically a list of struct instances representing -;; each game object +;; each object created in this game (defstruct world (players NIL) @@ -23,6 +23,7 @@ (npcs NIL) (items NIL)) +(setf *world* (make-world)) ;; (defmacro add-game-object (game-object) ;; "Add a game-object to the *world*" @@ -36,6 +37,7 @@ ;; (append (,object-function *world*) ,game-object)))) +;FIXME Needs work (defmacro add-game-object (game-object) "Add a game-object to the *world*" (let ((attribute-list @@ -45,3 +47,9 @@ ((npc-p game-object) '(world-npcs *world*)) ((item-p game-object) '(world-items *world*))))) `(setf ,attribute-list (append ,attribute-list ,game-object)))) + +; TODO +(defmacro get-game-object (object-name)) + +;TODO +(defmacro set-object-attribute (game-object property value)) diff --git a/worlds/Example/example.atl b/worlds/Example/example.atl deleted file mode 100644 index 3101edd..0000000 --- a/worlds/Example/example.atl +++ /dev/null @@ -1,72 +0,0 @@ -# This is an example Atlantis file - I use it to explore what the language -# should end up looking like. - -load races.atl -load classes.atl - - -define-quest Kill hellhound - objective kill hellhound - reward gold 300 - - -define-spell Ray of death - type kill - min-intelligence 12 - success-rate 35 - - -define-npc Hades - say Oh, amazing, you actually got here! Who did you bribe? - sell 30 Ambrosia - quest Kill hellhound - - -define-item Scroll of light - value 80 - add-experience 20 - add-spell Ray of death - -define-item Ambrosia - category Food - add-health 5 - - -define-monster Hellhound - armor-class 8 - strength 10 - melee-weapon 2 claws - experience 50 - spawn 2 - aggression 60 - -define-monster Fury - armor-class 5 - strength 8 - melee-weapon 10 fire whip - experience 74 - spawn 0.8 - aggression 30 - - -define-place Nowhere - description Welcome to Nowhere! You are in the void, the space between \ -the worlds. Around you is black. Black, except for one tiny pin-prick of light \ -to the north. - neighbour Elysium - -define-place Elysium - description Congratulations! You have achieved Elysium! - neighbour Nowhere - neighbour Fields of punishment - npc Hades - item Scroll of light - -define-place Fields of punishment - description You really, really don't want to end up here... - neighbour Elysium - monster Hellhound - monster Fury - - -start-place Elysium \ No newline at end of file diff --git a/worlds/Example/lisp-test.atl b/worlds/Example/lisp-test.atl deleted file mode 100644 index fdb5416..0000000 --- a/worlds/Example/lisp-test.atl +++ /dev/null @@ -1,18 +0,0 @@ -; This is a simple test ATL file to test whatever I have implemented so far. -; @author Daniel Vedder -; @date 04/05/2015 - -define-place "Nowhere" - description "Welcome to Nowhere!" -;You are in the void, the space between -;the worlds. Around you is black. Black, except for one tiny pin-prick of -;light to the north. - neighbour "Elysium" - -define-place "Elysium" - description "This is where you want to be when you are six feet under..." - neighbour "Nowhere" - -;load test2.atl - -start-place "Nowhere" \ No newline at end of file diff --git a/worlds/Example/test.atl b/worlds/Example/test.atl deleted file mode 100644 index 7c112b8..0000000 --- a/worlds/Example/test.atl +++ /dev/null @@ -1,18 +0,0 @@ -# This is a simple test ATL file to test whatever I have implemented so far. -# @author Daniel Vedder -# @date 04/05/2015 - -define-place Nowhere - description Welcome to Nowhere! -#You are in the void, the space between \ -#the worlds. Around you is black. Black, except for one tiny pin-prick of -#light \to the north. - neighbour Elysium - -define-place Elysium - description This is where you want to be when you are six feet under... - neighbour Nowhere - -load test2.atl - -start-place Nowhere \ No newline at end of file diff --git a/ATL/example.atl b/ATL/example.atl new file mode 100644 index 0000000..3101edd --- /dev/null +++ b/ATL/example.atl @@ -0,0 +1,72 @@ +# This is an example Atlantis file - I use it to explore what the language +# should end up looking like. + +load races.atl +load classes.atl + + +define-quest Kill hellhound + objective kill hellhound + reward gold 300 + + +define-spell Ray of death + type kill + min-intelligence 12 + success-rate 35 + + +define-npc Hades + say Oh, amazing, you actually got here! Who did you bribe? + sell 30 Ambrosia + quest Kill hellhound + + +define-item Scroll of light + value 80 + add-experience 20 + add-spell Ray of death + +define-item Ambrosia + category Food + add-health 5 + + +define-monster Hellhound + armor-class 8 + strength 10 + melee-weapon 2 claws + experience 50 + spawn 2 + aggression 60 + +define-monster Fury + armor-class 5 + strength 8 + melee-weapon 10 fire whip + experience 74 + spawn 0.8 + aggression 30 + + +define-place Nowhere + description Welcome to Nowhere! You are in the void, the space between \ +the worlds. Around you is black. Black, except for one tiny pin-prick of light \ +to the north. + neighbour Elysium + +define-place Elysium + description Congratulations! You have achieved Elysium! + neighbour Nowhere + neighbour Fields of punishment + npc Hades + item Scroll of light + +define-place Fields of punishment + description You really, really don't want to end up here... + neighbour Elysium + monster Hellhound + monster Fury + + +start-place Elysium \ No newline at end of file diff --git a/ATL/lisp-test.atl b/ATL/lisp-test.atl new file mode 100644 index 0000000..fdb5416 --- /dev/null +++ b/ATL/lisp-test.atl @@ -0,0 +1,18 @@ +; This is a simple test ATL file to test whatever I have implemented so far. +; @author Daniel Vedder +; @date 04/05/2015 + +define-place "Nowhere" + description "Welcome to Nowhere!" +;You are in the void, the space between +;the worlds. Around you is black. Black, except for one tiny pin-prick of +;light to the north. + neighbour "Elysium" + +define-place "Elysium" + description "This is where you want to be when you are six feet under..." + neighbour "Nowhere" + +;load test2.atl + +start-place "Nowhere" \ No newline at end of file diff --git a/ATL/test.atl b/ATL/test.atl new file mode 100644 index 0000000..7c112b8 --- /dev/null +++ b/ATL/test.atl @@ -0,0 +1,18 @@ +# This is a simple test ATL file to test whatever I have implemented so far. +# @author Daniel Vedder +# @date 04/05/2015 + +define-place Nowhere + description Welcome to Nowhere! +#You are in the void, the space between \ +#the worlds. Around you is black. Black, except for one tiny pin-prick of +#light \to the north. + neighbour Elysium + +define-place Elysium + description This is where you want to be when you are six feet under... + neighbour Nowhere + +load test2.atl + +start-place Nowhere \ No newline at end of file diff --git a/ATL/test2.atl b/ATL/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/ATL/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index acfa19c..e97a035 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,9 +7,10 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 0 1)) +(defconstant ATLANTIS-VERSION '(0 1 0)) (load 'util.lisp) +(load 'interpreter.lisp) (defun start-server () @@ -19,7 +20,8 @@ (format t "~&What port should the game run on?") (while (not (numberp (input port))) (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Loading file ~A on port ~A" (string world-file) port)) + (format t "~&Loading file ~S on port ~A" world-file port) + (load-atl-file world-file)) (defun join-game () "Join a running game on the server" diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index f7912e6..790105e 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -47,10 +47,13 @@ (read-from-string (second (cut-string line (find-char #\space line))))))) ; interpret an option command - ((not (eql (aref line 0) #\;)) + ((or (eql (aref line 0) #\Space) + (eql (aref line 0) #\Tab)) (setf line (string-left-trim '(#\Space #\Tab) line)) (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (find-char #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A~" - line-nr line))))) + ((eql (aref line 0) #\;)) ;Comments are ignored + (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + ;can't happen + (1+ line-nr) line))))) diff --git a/lisp/util.lisp b/lisp/util.lisp index c527654..e09ca2f 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -12,6 +12,13 @@ ;;; MACROS +(defmacro magic (var) + "Execute typed-in Lisp code" + (let ((expr (gensym))) + `(when (equalp ,var 'magic) + (progn (simple-input ,expr "[spell]>") + (eval ,expr))))) + ; potentially inefficient if called often (defmacro set-list (value &rest var-list) "Set each symbol in var-list to value" @@ -26,14 +33,16 @@ `(progn (format t "~&>>> ") (set-list (read) ,@vars) - (magic (first (list ,@vars))))) + (magic (first (list ,@vars))) + (first (list ,@vars)))) (defmacro input-string (var) "Read a string input line" `(progn (format t "~&>>> ") (setf ,var (read-line)) - (magic (read-from-string ,var)))) + (magic (read-from-string ,var)) + ,var)) (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -41,18 +50,11 @@ (format t "~&~A " ,prompt) (setf ,var (read)))) -(defmacro magic (var) - "Execute typed-in Lisp code" - (let ((expr (gensym))) - `(when (equalp ,var 'magic) - (progn (simple-input ,expr "[spell]>") - (eval ,expr))))) - (defmacro while (condition &body body) "An implementation of a while loop as found in other languages" `(do () - ((not ,condition)) - (,@body))) + ((not ,condition) NIL) + ,@body)) (defmacro != (object1 object2 &key (test 'eql)) "A not-equals macro to save some typing" @@ -102,20 +104,17 @@ (dotimes (letter (length s) NIL) (when (eql (char s letter) c) (return letter)))) -(defun count-instances (search-term search-list) +(defun count-instances (search-term search-list &key (test #'eql)) "Count the number of instances of search-term in search-list" - (do ((lst (cdr (member search-term search-list)) - (cdr (member search-term lst))) - (counter 0 (1+ counter))) - ((null lst) counter))) + (let ((count 0)) + (dolist (item search-list count) + (when (funcall test search-term item) (incf count))))) -(defun count-vector-instances (search-term search-vector) +(defun count-vector-instances (search-term search-vector &key (test #'eql)) "Count the number of instances of search-term in search-vector" - (do ((count 0) (item-nr 0 (1+ item-nr)) - (item (aref search-vector item-nr) (aref search-vector item-nr))) - ((= item-nr (1- (length search-vector))) count) - ;TODO - )) + (let ((count 0)) + (dovector (item search-vector count) + (when (funcall test search-term item) (incf count))))) (defun to-list (vector) "Turn the vector into a list" diff --git a/lisp/world.lisp b/lisp/world.lisp index 43ecfa5..48a2dac 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -14,7 +14,7 @@ ;; The world is basically a list of struct instances representing -;; each game object +;; each object created in this game (defstruct world (players NIL) @@ -23,6 +23,7 @@ (npcs NIL) (items NIL)) +(setf *world* (make-world)) ;; (defmacro add-game-object (game-object) ;; "Add a game-object to the *world*" @@ -36,6 +37,7 @@ ;; (append (,object-function *world*) ,game-object)))) +;FIXME Needs work (defmacro add-game-object (game-object) "Add a game-object to the *world*" (let ((attribute-list @@ -45,3 +47,9 @@ ((npc-p game-object) '(world-npcs *world*)) ((item-p game-object) '(world-items *world*))))) `(setf ,attribute-list (append ,attribute-list ,game-object)))) + +; TODO +(defmacro get-game-object (object-name)) + +;TODO +(defmacro set-object-attribute (game-object property value)) diff --git a/worlds/Example/example.atl b/worlds/Example/example.atl deleted file mode 100644 index 3101edd..0000000 --- a/worlds/Example/example.atl +++ /dev/null @@ -1,72 +0,0 @@ -# This is an example Atlantis file - I use it to explore what the language -# should end up looking like. - -load races.atl -load classes.atl - - -define-quest Kill hellhound - objective kill hellhound - reward gold 300 - - -define-spell Ray of death - type kill - min-intelligence 12 - success-rate 35 - - -define-npc Hades - say Oh, amazing, you actually got here! Who did you bribe? - sell 30 Ambrosia - quest Kill hellhound - - -define-item Scroll of light - value 80 - add-experience 20 - add-spell Ray of death - -define-item Ambrosia - category Food - add-health 5 - - -define-monster Hellhound - armor-class 8 - strength 10 - melee-weapon 2 claws - experience 50 - spawn 2 - aggression 60 - -define-monster Fury - armor-class 5 - strength 8 - melee-weapon 10 fire whip - experience 74 - spawn 0.8 - aggression 30 - - -define-place Nowhere - description Welcome to Nowhere! You are in the void, the space between \ -the worlds. Around you is black. Black, except for one tiny pin-prick of light \ -to the north. - neighbour Elysium - -define-place Elysium - description Congratulations! You have achieved Elysium! - neighbour Nowhere - neighbour Fields of punishment - npc Hades - item Scroll of light - -define-place Fields of punishment - description You really, really don't want to end up here... - neighbour Elysium - monster Hellhound - monster Fury - - -start-place Elysium \ No newline at end of file diff --git a/worlds/Example/lisp-test.atl b/worlds/Example/lisp-test.atl deleted file mode 100644 index fdb5416..0000000 --- a/worlds/Example/lisp-test.atl +++ /dev/null @@ -1,18 +0,0 @@ -; This is a simple test ATL file to test whatever I have implemented so far. -; @author Daniel Vedder -; @date 04/05/2015 - -define-place "Nowhere" - description "Welcome to Nowhere!" -;You are in the void, the space between -;the worlds. Around you is black. Black, except for one tiny pin-prick of -;light to the north. - neighbour "Elysium" - -define-place "Elysium" - description "This is where you want to be when you are six feet under..." - neighbour "Nowhere" - -;load test2.atl - -start-place "Nowhere" \ No newline at end of file diff --git a/worlds/Example/test.atl b/worlds/Example/test.atl deleted file mode 100644 index 7c112b8..0000000 --- a/worlds/Example/test.atl +++ /dev/null @@ -1,18 +0,0 @@ -# This is a simple test ATL file to test whatever I have implemented so far. -# @author Daniel Vedder -# @date 04/05/2015 - -define-place Nowhere - description Welcome to Nowhere! -#You are in the void, the space between \ -#the worlds. Around you is black. Black, except for one tiny pin-prick of -#light \to the north. - neighbour Elysium - -define-place Elysium - description This is where you want to be when you are six feet under... - neighbour Nowhere - -load test2.atl - -start-place Nowhere \ No newline at end of file diff --git a/worlds/Example/test2.atl b/worlds/Example/test2.atl deleted file mode 100644 index 41dda7a..0000000 --- a/worlds/Example/test2.atl +++ /dev/null @@ -1,6 +0,0 @@ -# This file is used to test the load command - -define-place Fields of Punishment - description You really, really don't want to be here! - neighbour Nowhere - neighbour Elysium \ No newline at end of file