diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9535c08..ebdb743 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -17,3 +17,18 @@ (monsters NIL) (npcs NIL)) +;;; Temporary, just so I have the structs >>> + +(defstruct npc + (name "") + (says "")) + +(defstruct monster + (name "") + (description "") + (strength 0)) + +(defstruct item + (name "") + (description "") + (functions NIL)) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9535c08..ebdb743 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -17,3 +17,18 @@ (monsters NIL) (npcs NIL)) +;;; Temporary, just so I have the structs >>> + +(defstruct npc + (name "") + (says "")) + +(defstruct monster + (name "") + (description "") + (strength 0)) + +(defstruct item + (name "") + (description "") + (functions NIL)) diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index c3a76c5..f7912e6 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -11,15 +11,22 @@ (load 'util.lisp) (load 'game-objects.lisp) +(load 'player.lisp) (load 'world.lisp) +(defun load-atl (atl-file) + ;not yet defined + NIL + ) + (defun define-place (name) (format t "~&Making place ~A" name) (make-place :name name)) (defun start-place (place) ;not yet defined + NIL ) (defun load-atl-file (file-name) @@ -28,13 +35,22 @@ (line (nth line-nr source) (nth line-nr source)) (current-object NIL)) ((= line-nr (length source)) NIL) - (unless (or (zerop (length line)) - (eql (aref line 0) #\;)) - (eql (aref line 0) #\SPACE) - (eql (aref line 0) #\TAB)) + (cond ((zerop (length line)) (setf current-object NIL)) ; interpret a define command - (funcall (symbol-function (read-from-string line)) - ; here follows is a kludge to work around a clisp bug (the - ; :start keyword in read-from-string is not recognized) - (read-from-string - (second (cut-string line (find-char #\space line))))))) + ((not (or (eql (aref line 0) #\;) + (eql (aref line 0) #\SPACE) + (eql (aref line 0) #\TAB))) + (setf current-object (funcall (symbol-function + (read-from-string line)) + ; here follows is a kludge to work around a clisp bug (the + ; :start keyword in read-from-string is not recognized) + (read-from-string + (second (cut-string line (find-char #\space line))))))) + ; interpret an option command + ((not (eql (aref line 0) #\;)) + (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))))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9535c08..ebdb743 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -17,3 +17,18 @@ (monsters NIL) (npcs NIL)) +;;; Temporary, just so I have the structs >>> + +(defstruct npc + (name "") + (says "")) + +(defstruct monster + (name "") + (description "") + (strength 0)) + +(defstruct item + (name "") + (description "") + (functions NIL)) diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index c3a76c5..f7912e6 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -11,15 +11,22 @@ (load 'util.lisp) (load 'game-objects.lisp) +(load 'player.lisp) (load 'world.lisp) +(defun load-atl (atl-file) + ;not yet defined + NIL + ) + (defun define-place (name) (format t "~&Making place ~A" name) (make-place :name name)) (defun start-place (place) ;not yet defined + NIL ) (defun load-atl-file (file-name) @@ -28,13 +35,22 @@ (line (nth line-nr source) (nth line-nr source)) (current-object NIL)) ((= line-nr (length source)) NIL) - (unless (or (zerop (length line)) - (eql (aref line 0) #\;)) - (eql (aref line 0) #\SPACE) - (eql (aref line 0) #\TAB)) + (cond ((zerop (length line)) (setf current-object NIL)) ; interpret a define command - (funcall (symbol-function (read-from-string line)) - ; here follows is a kludge to work around a clisp bug (the - ; :start keyword in read-from-string is not recognized) - (read-from-string - (second (cut-string line (find-char #\space line))))))) + ((not (or (eql (aref line 0) #\;) + (eql (aref line 0) #\SPACE) + (eql (aref line 0) #\TAB))) + (setf current-object (funcall (symbol-function + (read-from-string line)) + ; here follows is a kludge to work around a clisp bug (the + ; :start keyword in read-from-string is not recognized) + (read-from-string + (second (cut-string line (find-char #\space line))))))) + ; interpret an option command + ((not (eql (aref line 0) #\;)) + (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))))) diff --git a/lisp/player.lisp b/lisp/player.lisp new file mode 100644 index 0000000..220e23b --- /dev/null +++ b/lisp/player.lisp @@ -0,0 +1,21 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file represents a single player. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 15/05/2015 +;;; + +(defstruct player + (name "") + (race NIL) + (class NIL) + (strength 0) + (dexterity 0) + (constitution 0) + (intelligence 0) + (items NIL) + (weapons NIL)) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9535c08..ebdb743 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -17,3 +17,18 @@ (monsters NIL) (npcs NIL)) +;;; Temporary, just so I have the structs >>> + +(defstruct npc + (name "") + (says "")) + +(defstruct monster + (name "") + (description "") + (strength 0)) + +(defstruct item + (name "") + (description "") + (functions NIL)) diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index c3a76c5..f7912e6 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -11,15 +11,22 @@ (load 'util.lisp) (load 'game-objects.lisp) +(load 'player.lisp) (load 'world.lisp) +(defun load-atl (atl-file) + ;not yet defined + NIL + ) + (defun define-place (name) (format t "~&Making place ~A" name) (make-place :name name)) (defun start-place (place) ;not yet defined + NIL ) (defun load-atl-file (file-name) @@ -28,13 +35,22 @@ (line (nth line-nr source) (nth line-nr source)) (current-object NIL)) ((= line-nr (length source)) NIL) - (unless (or (zerop (length line)) - (eql (aref line 0) #\;)) - (eql (aref line 0) #\SPACE) - (eql (aref line 0) #\TAB)) + (cond ((zerop (length line)) (setf current-object NIL)) ; interpret a define command - (funcall (symbol-function (read-from-string line)) - ; here follows is a kludge to work around a clisp bug (the - ; :start keyword in read-from-string is not recognized) - (read-from-string - (second (cut-string line (find-char #\space line))))))) + ((not (or (eql (aref line 0) #\;) + (eql (aref line 0) #\SPACE) + (eql (aref line 0) #\TAB))) + (setf current-object (funcall (symbol-function + (read-from-string line)) + ; here follows is a kludge to work around a clisp bug (the + ; :start keyword in read-from-string is not recognized) + (read-from-string + (second (cut-string line (find-char #\space line))))))) + ; interpret an option command + ((not (eql (aref line 0) #\;)) + (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))))) diff --git a/lisp/player.lisp b/lisp/player.lisp new file mode 100644 index 0000000..220e23b --- /dev/null +++ b/lisp/player.lisp @@ -0,0 +1,21 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file represents a single player. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 15/05/2015 +;;; + +(defstruct player + (name "") + (race NIL) + (class NIL) + (strength 0) + (dexterity 0) + (constitution 0) + (intelligence 0) + (items NIL) + (weapons NIL)) diff --git a/lisp/world.lisp b/lisp/world.lisp index bff9d90..43ecfa5 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -8,3 +8,40 @@ ;;; author: Daniel Vedder ;;; date: 15/05/2015 ;;; + + +(defvar *world*) + + +;; The world is basically a list of struct instances representing +;; each game object + +(defstruct world + (players NIL) + (places NIL) + (monsters NIL) + (npcs NIL) + (items NIL)) + + +;; (defmacro add-game-object (game-object) +;; "Add a game-object to the *world*" +;; (let ((object-function +;; (cond ((playerp game-object) 'world-players) +;; ((place-p game-object) 'world-places) +;; ((monster-p game-object) 'world-monsters) +;; ((npc-p game-object) 'world-npcs) +;; ((itemp-p game-object) 'world-items)))) +;; `(setf (,object-function *world*) +;; (append (,object-function *world*) ,game-object)))) + + +(defmacro add-game-object (game-object) + "Add a game-object to the *world*" + (let ((attribute-list + (cond ((player-p game-object) '(world-players *world*)) + ((place-p game-object) '(world-places *world*)) + ((monster-p game-object) '(world-monsters *world*)) + ((npc-p game-object) '(world-npcs *world*)) + ((item-p game-object) '(world-items *world*))))) + `(setf ,attribute-list (append ,attribute-list ,game-object))))