diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index add4f71..c7becbb 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -73,6 +73,7 @@ (,command ,game-object))) (setf (,command ,game-object) NIL))))) +;;; XXX Is this needed? A quick grep doesn't find it anywhere in the code. (let ((list-function (make-list-function 'place NIL))) (defun list-place-objects (object-type place) "Get a list of the names of all the place's objects of this type." diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index add4f71..c7becbb 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -73,6 +73,7 @@ (,command ,game-object))) (setf (,command ,game-object) NIL))))) +;;; XXX Is this needed? A quick grep doesn't find it anywhere in the code. (let ((list-function (make-list-function 'place NIL))) (defun list-place-objects (object-type place) "Get a list of the names of all the place's objects of this type." diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index b0af3c7..211226a 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -13,7 +13,7 @@ (defun build-define-command (object-type) "Build a new define command function for the specified object type" #'(lambda (name) - (format t "~&Making ~A ~A" + (debugging "~&Making ~A ~A" (string-downcase (to-string object-type)) name) (funcall (build-symbol "make-" object-type) :name name))) @@ -31,7 +31,7 @@ (defcommand define-weapon weapon) (defun start-place (place) - (format t "~&Starting place is ~A" place) + (debugging "~&Starting place is ~A" place) (setf (world-starting-place *world*) place) NIL) @@ -88,6 +88,6 @@ (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (position #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + (T (error "~&ERROR: unrecognized syntax on line ~A: '~A'" ;; can't happen (1+ line-nr) line)))))) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index add4f71..c7becbb 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -73,6 +73,7 @@ (,command ,game-object))) (setf (,command ,game-object) NIL))))) +;;; XXX Is this needed? A quick grep doesn't find it anywhere in the code. (let ((list-function (make-list-function 'place NIL))) (defun list-place-objects (object-type place) "Get a list of the names of all the place's objects of this type." diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index b0af3c7..211226a 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -13,7 +13,7 @@ (defun build-define-command (object-type) "Build a new define command function for the specified object type" #'(lambda (name) - (format t "~&Making ~A ~A" + (debugging "~&Making ~A ~A" (string-downcase (to-string object-type)) name) (funcall (build-symbol "make-" object-type) :name name))) @@ -31,7 +31,7 @@ (defcommand define-weapon weapon) (defun start-place (place) - (format t "~&Starting place is ~A" place) + (debugging "~&Starting place is ~A" place) (setf (world-starting-place *world*) place) NIL) @@ -88,6 +88,6 @@ (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (position #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + (T (error "~&ERROR: unrecognized syntax on line ~A: '~A'" ;; can't happen (1+ line-nr) line)))))) diff --git a/lisp/ui.lisp b/lisp/ui.lisp index e7eeda8..7ca1edc 100644 --- a/lisp/ui.lisp +++ b/lisp/ui.lisp @@ -56,7 +56,8 @@ (setf (player-class player) (get-game-object 'character-class character-class)) ;; Set character attributes - (while (< (reduce #'+ character-points) 24) ; Warning: magic number! + (while (or (< (reduce #'+ character-points) 24) ; XXX magic number! + (not (set-p character-points))) (set-list (1+ (random 20)) a b c d) (setf character-points (list a b c d))) (setf text " @@ -74,7 +75,6 @@ (while (not (member val character-points)) (format t "~&Sorry, invalid number chosen. Please reenter:") (simple-input val (concatenate 'string (symbol-name attr) ":"))) - ;; FIXME Gives problems if two equal numbers are in char-points (let ((player-fn (build-symbol "player-" attr))) ;; XXX Kludge ?! (eval `(setf (,player-fn ,player) ,val))) @@ -157,7 +157,7 @@ (defun goto (player location) "Go to the specified location" - (format t "~&~A is going to ~A." (player-name player) location) + (debugging "~&~A is going to ~A." (player-name player) location) (when (symbolp location) (setf location (symbol-name location))) (when (not (member location (place-neighbour (get-game-object 'place diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index add4f71..c7becbb 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -73,6 +73,7 @@ (,command ,game-object))) (setf (,command ,game-object) NIL))))) +;;; XXX Is this needed? A quick grep doesn't find it anywhere in the code. (let ((list-function (make-list-function 'place NIL))) (defun list-place-objects (object-type place) "Get a list of the names of all the place's objects of this type." diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index b0af3c7..211226a 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -13,7 +13,7 @@ (defun build-define-command (object-type) "Build a new define command function for the specified object type" #'(lambda (name) - (format t "~&Making ~A ~A" + (debugging "~&Making ~A ~A" (string-downcase (to-string object-type)) name) (funcall (build-symbol "make-" object-type) :name name))) @@ -31,7 +31,7 @@ (defcommand define-weapon weapon) (defun start-place (place) - (format t "~&Starting place is ~A" place) + (debugging "~&Starting place is ~A" place) (setf (world-starting-place *world*) place) NIL) @@ -88,6 +88,6 @@ (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (position #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + (T (error "~&ERROR: unrecognized syntax on line ~A: '~A'" ;; can't happen (1+ line-nr) line)))))) diff --git a/lisp/ui.lisp b/lisp/ui.lisp index e7eeda8..7ca1edc 100644 --- a/lisp/ui.lisp +++ b/lisp/ui.lisp @@ -56,7 +56,8 @@ (setf (player-class player) (get-game-object 'character-class character-class)) ;; Set character attributes - (while (< (reduce #'+ character-points) 24) ; Warning: magic number! + (while (or (< (reduce #'+ character-points) 24) ; XXX magic number! + (not (set-p character-points))) (set-list (1+ (random 20)) a b c d) (setf character-points (list a b c d))) (setf text " @@ -74,7 +75,6 @@ (while (not (member val character-points)) (format t "~&Sorry, invalid number chosen. Please reenter:") (simple-input val (concatenate 'string (symbol-name attr) ":"))) - ;; FIXME Gives problems if two equal numbers are in char-points (let ((player-fn (build-symbol "player-" attr))) ;; XXX Kludge ?! (eval `(setf (,player-fn ,player) ,val))) @@ -157,7 +157,7 @@ (defun goto (player location) "Go to the specified location" - (format t "~&~A is going to ~A." (player-name player) location) + (debugging "~&~A is going to ~A." (player-name player) location) (when (symbolp location) (setf location (symbol-name location))) (when (not (member location (place-neighbour (get-game-object 'place diff --git a/lisp/util.lisp b/lisp/util.lisp index 16b4d49..379ef0d 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -20,6 +20,10 @@ syms) ,@body)) +(defmacro debugging (str &rest format-args) + "If *debugging* is true, print str" + `(when *debugging* (format t ,str ,@format-args))) + ;; TODO DEPRECATED - Needs to be replaced in the current code (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -96,7 +100,6 @@ ; Some of these functions are probably quite inefficient (lots of consing) - ;; XXX DEPRECATED Not actually needed anywhere (defun call-function (function-name &rest args) "Save myself some quoting when calling a function from a generated symbol" @@ -146,6 +149,12 @@ (when (funcall test search-term (elt search-sequence i)) (incf count))))) +(defun set-p (lst) + "Is lst a set (i.e. no elements occur more than once)?" + (cond ((null lst) T) + ((member (car lst) (cdr lst)) NIL) + (T (set-p (cdr lst))))) + (defun to-list (vector &optional (next-elt 0)) "Turn the vector into a list" (if (= next-elt (1- (length vector))) NIL diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index 083b01f..f0d1770 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -17,8 +17,11 @@ (load "ui.lisp") +(defvar *debugging* NIL) + (defun development () "A method to easily test whatever feature I am currently developing" + (setf *debugging* T) (load-file "../ATL/lisp-test.atl") (let ((player (make-player :name "Bilbo" :race (get-game-object 'race "Hobbit") @@ -34,12 +37,13 @@ (defun start-server () "Start a new game on a server" + ;; TODO Doesn't actually start a server yet (format t "~&What world file do you want to load?") (input-string world-file) (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 ~S on port ~A" world-file port) + (debugging "~&Loading file ~S on port ~A" world-file port) (load-file world-file)) (defun join-game () @@ -56,7 +60,7 @@ ;(setf (cassoc port *server-address*) server-port) (format t "~&What is your player name?") (input-string name) - (format t "~&Joining game on ~A:~A as ~A" server-ip server-port name) + (debugging "~&Joining game on ~A:~A as ~A" server-ip server-port name) (play-game name)) @@ -80,7 +84,7 @@ (2 (start-menu)))) (defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" + (format t "~&Atlantis ~A.~A.~A" (first ATLANTIS-VERSION) (second ATLANTIS-VERSION) (third ATLANTIS-VERSION)) @@ -114,32 +118,38 @@ (defun print-help () (print-version) - (format t "~&~%Commandline options:") - (let ((tab (string #\Tab))) - (format t "~&-v --version~AShow the version number and exit" tab) - (format t "~&-h --help~AShow this help text and exit" tab) - (format t "~&--license~AShow the license text" tab) - (format t "~&--server ~AStart a server on (requires --world)" tab) - (format t "~&--world ~AThe ATL file to load (requires --server)" tab) - (format t "~&--client :~AConnect to the game server at :" tab))) + (setf help-text " +Commandline options: +-v --version Show the version number and exit +-h --help Show this help text and exit +--license Show the license text +--debugging Switch on debug mode +--single-player Start a single-player game +--server Start a server on (requires --world) +--world The ATL file to load (requires --server) +--client : Connect to the game server at :") + (format t "~A" help-text)) (defun parse-commandline-args () ;; TODO clean this up? (should give error message with unknown params) - (when (or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) + (cond ((or (cmd-parameter "--version" T) (cmd-parameter "-v" T)) (print-version) (quit)) - (when (or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) - (print-help) (quit)) - (when (cmd-parameter "--license" T) - (dolist (line (load-text-file "../LICENSE")) - (unless (null line) (format t "~%~A" line))) - (quit)) + ((or (cmd-parameter "--help" T) (cmd-parameter "-h" T)) + (print-help) (quit)) + ((cmd-parameter "--license" T) + (dolist (line (load-text-file "../LICENSE")) + (unless (null line) (format t "~%~A" line))) + (quit)) + ((cmd-parameter "--debugging") + (setf *debugging* T)) + ((cmd-parameter "--single-player" T) + (single-player))) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) (unless (or server world-file client) (format t "~&Invalid commandline parameter!") (quit)) - ;; TODO change OR to AND, change function calls - (if (or world-file server) + (if (and world-file server) (load-file world-file) (join-game)))) diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index add4f71..c7becbb 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -73,6 +73,7 @@ (,command ,game-object))) (setf (,command ,game-object) NIL))))) +;;; XXX Is this needed? A quick grep doesn't find it anywhere in the code. (let ((list-function (make-list-function 'place NIL))) (defun list-place-objects (object-type place) "Get a list of the names of all the place's objects of this type." diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp index b0af3c7..211226a 100644 --- a/lisp/interpreter.lisp +++ b/lisp/interpreter.lisp @@ -13,7 +13,7 @@ (defun build-define-command (object-type) "Build a new define command function for the specified object type" #'(lambda (name) - (format t "~&Making ~A ~A" + (debugging "~&Making ~A ~A" (string-downcase (to-string object-type)) name) (funcall (build-symbol "make-" object-type) :name name))) @@ -31,7 +31,7 @@ (defcommand define-weapon weapon) (defun start-place (place) - (format t "~&Starting place is ~A" place) + (debugging "~&Starting place is ~A" place) (setf (world-starting-place *world*) place) NIL) @@ -88,6 +88,6 @@ (set-object-attribute current-object (read-from-string line) (read-from-string (second (cut-string line (position #\space line)))))) - (T (format t "~&ERROR: unrecognized syntax on line ~A: '~A'" + (T (error "~&ERROR: unrecognized syntax on line ~A: '~A'" ;; can't happen (1+ line-nr) line)))))) diff --git a/lisp/ui.lisp b/lisp/ui.lisp index e7eeda8..7ca1edc 100644 --- a/lisp/ui.lisp +++ b/lisp/ui.lisp @@ -56,7 +56,8 @@ (setf (player-class player) (get-game-object 'character-class character-class)) ;; Set character attributes - (while (< (reduce #'+ character-points) 24) ; Warning: magic number! + (while (or (< (reduce #'+ character-points) 24) ; XXX magic number! + (not (set-p character-points))) (set-list (1+ (random 20)) a b c d) (setf character-points (list a b c d))) (setf text " @@ -74,7 +75,6 @@ (while (not (member val character-points)) (format t "~&Sorry, invalid number chosen. Please reenter:") (simple-input val (concatenate 'string (symbol-name attr) ":"))) - ;; FIXME Gives problems if two equal numbers are in char-points (let ((player-fn (build-symbol "player-" attr))) ;; XXX Kludge ?! (eval `(setf (,player-fn ,player) ,val))) @@ -157,7 +157,7 @@ (defun goto (player location) "Go to the specified location" - (format t "~&~A is going to ~A." (player-name player) location) + (debugging "~&~A is going to ~A." (player-name player) location) (when (symbolp location) (setf location (symbol-name location))) (when (not (member location (place-neighbour (get-game-object 'place diff --git a/lisp/util.lisp b/lisp/util.lisp index 16b4d49..379ef0d 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -20,6 +20,10 @@ syms) ,@body)) +(defmacro debugging (str &rest format-args) + "If *debugging* is true, print str" + `(when *debugging* (format t ,str ,@format-args))) + ;; TODO DEPRECATED - Needs to be replaced in the current code (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" @@ -96,7 +100,6 @@ ; Some of these functions are probably quite inefficient (lots of consing) - ;; XXX DEPRECATED Not actually needed anywhere (defun call-function (function-name &rest args) "Save myself some quoting when calling a function from a generated symbol" @@ -146,6 +149,12 @@ (when (funcall test search-term (elt search-sequence i)) (incf count))))) +(defun set-p (lst) + "Is lst a set (i.e. no elements occur more than once)?" + (cond ((null lst) T) + ((member (car lst) (cdr lst)) NIL) + (T (set-p (cdr lst))))) + (defun to-list (vector &optional (next-elt 0)) "Turn the vector into a list" (if (= next-elt (1- (length vector))) NIL diff --git a/lisp/world.lisp b/lisp/world.lisp index 4694c78..c6f01fe 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -53,7 +53,7 @@ (defun name-world (name) "Set the name of the *world*" - (format t "~&The name of the world is ~A." name) + (debugging "~&The name of the world is ~A." name) (setf (world-name *world*) name) NIL) @@ -62,12 +62,9 @@ (with-open-file (g game-file) (let ((version-number (read g)) (loaded-world (read g))) - ;; XXX This introduces UI in a non-UI module... (when (!= version-number ATLANTIS-VERSION :test equal) - (format t "~&WARNING: The loaded world was saved by a different") - (format t " version of Atlantis!") - (unless (yes-or-no-p "Continue anyway?") - (start-menu))) + (format t "~&WARNING: The loaded game was saved by a ") + (format t "different version of Atlantis!")) (if (world-p loaded-world) (setf *world* loaded-world) (error "World file ~A is corrupted!" game-file)))))