diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/client.lisp b/lisp/client.lisp index f952c34..730d9c6 100644 --- a/lisp/client.lisp +++ b/lisp/client.lisp @@ -19,7 +19,7 @@ (setf player (get-game-object 'player player-name))) (when (null player) (setf player (create-player player-name)) - (when (null (list-objects 'player)) + (when (null (list-world-objects 'player)) (setf (world-game-manager *world*) (player-name player))) (add-game-object player) (set-object-attribute (get-game-object 'place (player-place player)) @@ -49,18 +49,18 @@ (unless (y-or-n-p "~&Create a new player?") (start-menu)) ;; Chose race and class (format t "~&Please chose a race:") - (format t "~&Options: ~A" (string-from-list (list-objects 'race))) + (format t "~&Options: ~A" (string-from-list (list-world-objects 'race))) (setf race (input-string)) - (while (not (member race (list-objects 'race) :test #'equalp)) + (while (not (member race (list-world-objects 'race) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf race (input-string))) (setf (player-race player) (get-game-object 'race race)) (format t "~&Please chose a class:") (format t "~&Options: ~A" (string-from-list - (list-objects 'character-class))) + (list-world-objects 'character-class))) (setf character-class (input-string)) (while (not (member character-class - (list-objects 'character-class) :test #'equalp)) + (list-world-objects 'character-class) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf character-class (input-string))) (setf (player-class player) @@ -158,8 +158,7 @@ (player-constitution p) (string #\Tab) (player-dexterity p)) (format t "~&=====") (format t "~&Weapon: ~A" (player-weapon p)) - ;; XXX This last line might give problems (using items instead of names?) - (format t "~&Items: ~A" (string-from-list (player-items p)))) + (format t "~&Items: ~A" (string-from-list (list-player-items 'item p)))) ;;; These next functions have to take exactly two argument (the argument ;;; to the function and a player instance). diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/client.lisp b/lisp/client.lisp index f952c34..730d9c6 100644 --- a/lisp/client.lisp +++ b/lisp/client.lisp @@ -19,7 +19,7 @@ (setf player (get-game-object 'player player-name))) (when (null player) (setf player (create-player player-name)) - (when (null (list-objects 'player)) + (when (null (list-world-objects 'player)) (setf (world-game-manager *world*) (player-name player))) (add-game-object player) (set-object-attribute (get-game-object 'place (player-place player)) @@ -49,18 +49,18 @@ (unless (y-or-n-p "~&Create a new player?") (start-menu)) ;; Chose race and class (format t "~&Please chose a race:") - (format t "~&Options: ~A" (string-from-list (list-objects 'race))) + (format t "~&Options: ~A" (string-from-list (list-world-objects 'race))) (setf race (input-string)) - (while (not (member race (list-objects 'race) :test #'equalp)) + (while (not (member race (list-world-objects 'race) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf race (input-string))) (setf (player-race player) (get-game-object 'race race)) (format t "~&Please chose a class:") (format t "~&Options: ~A" (string-from-list - (list-objects 'character-class))) + (list-world-objects 'character-class))) (setf character-class (input-string)) (while (not (member character-class - (list-objects 'character-class) :test #'equalp)) + (list-world-objects 'character-class) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf character-class (input-string))) (setf (player-class player) @@ -158,8 +158,7 @@ (player-constitution p) (string #\Tab) (player-dexterity p)) (format t "~&=====") (format t "~&Weapon: ~A" (player-weapon p)) - ;; XXX This last line might give problems (using items instead of names?) - (format t "~&Items: ~A" (string-from-list (player-items p)))) + (format t "~&Items: ~A" (string-from-list (list-player-items 'item p)))) ;;; These next functions have to take exactly two argument (the argument ;;; to the function and a player instance). diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9382122..dd57e26 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -62,3 +62,8 @@ (remove-if #'(lambda (x) (equalp x ,value)) (,command ,game-object))) (setf (,command ,game-object) NIL))))) + +(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." + (funcall list-function object-type place))) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/client.lisp b/lisp/client.lisp index f952c34..730d9c6 100644 --- a/lisp/client.lisp +++ b/lisp/client.lisp @@ -19,7 +19,7 @@ (setf player (get-game-object 'player player-name))) (when (null player) (setf player (create-player player-name)) - (when (null (list-objects 'player)) + (when (null (list-world-objects 'player)) (setf (world-game-manager *world*) (player-name player))) (add-game-object player) (set-object-attribute (get-game-object 'place (player-place player)) @@ -49,18 +49,18 @@ (unless (y-or-n-p "~&Create a new player?") (start-menu)) ;; Chose race and class (format t "~&Please chose a race:") - (format t "~&Options: ~A" (string-from-list (list-objects 'race))) + (format t "~&Options: ~A" (string-from-list (list-world-objects 'race))) (setf race (input-string)) - (while (not (member race (list-objects 'race) :test #'equalp)) + (while (not (member race (list-world-objects 'race) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf race (input-string))) (setf (player-race player) (get-game-object 'race race)) (format t "~&Please chose a class:") (format t "~&Options: ~A" (string-from-list - (list-objects 'character-class))) + (list-world-objects 'character-class))) (setf character-class (input-string)) (while (not (member character-class - (list-objects 'character-class) :test #'equalp)) + (list-world-objects 'character-class) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf character-class (input-string))) (setf (player-class player) @@ -158,8 +158,7 @@ (player-constitution p) (string #\Tab) (player-dexterity p)) (format t "~&=====") (format t "~&Weapon: ~A" (player-weapon p)) - ;; XXX This last line might give problems (using items instead of names?) - (format t "~&Items: ~A" (string-from-list (player-items p)))) + (format t "~&Items: ~A" (string-from-list (list-player-items 'item p)))) ;;; These next functions have to take exactly two argument (the argument ;;; to the function and a player instance). diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9382122..dd57e26 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -62,3 +62,8 @@ (remove-if #'(lambda (x) (equalp x ,value)) (,command ,game-object))) (setf (,command ,game-object) NIL))))) + +(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." + (funcall list-function object-type place))) diff --git a/lisp/player.lisp b/lisp/player.lisp index 74757af..a004ff5 100644 --- a/lisp/player.lisp +++ b/lisp/player.lisp @@ -38,3 +38,9 @@ (description "") (special-item NIL) (special-ability NIL)) + + +(let ((list-function (make-list-function 'player NIL))) + (defun list-player-objects (object-type player) + "Get a list of the names of all the player's objects of this type." + (funcall list-function object-type player))) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/client.lisp b/lisp/client.lisp index f952c34..730d9c6 100644 --- a/lisp/client.lisp +++ b/lisp/client.lisp @@ -19,7 +19,7 @@ (setf player (get-game-object 'player player-name))) (when (null player) (setf player (create-player player-name)) - (when (null (list-objects 'player)) + (when (null (list-world-objects 'player)) (setf (world-game-manager *world*) (player-name player))) (add-game-object player) (set-object-attribute (get-game-object 'place (player-place player)) @@ -49,18 +49,18 @@ (unless (y-or-n-p "~&Create a new player?") (start-menu)) ;; Chose race and class (format t "~&Please chose a race:") - (format t "~&Options: ~A" (string-from-list (list-objects 'race))) + (format t "~&Options: ~A" (string-from-list (list-world-objects 'race))) (setf race (input-string)) - (while (not (member race (list-objects 'race) :test #'equalp)) + (while (not (member race (list-world-objects 'race) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf race (input-string))) (setf (player-race player) (get-game-object 'race race)) (format t "~&Please chose a class:") (format t "~&Options: ~A" (string-from-list - (list-objects 'character-class))) + (list-world-objects 'character-class))) (setf character-class (input-string)) (while (not (member character-class - (list-objects 'character-class) :test #'equalp)) + (list-world-objects 'character-class) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf character-class (input-string))) (setf (player-class player) @@ -158,8 +158,7 @@ (player-constitution p) (string #\Tab) (player-dexterity p)) (format t "~&=====") (format t "~&Weapon: ~A" (player-weapon p)) - ;; XXX This last line might give problems (using items instead of names?) - (format t "~&Items: ~A" (string-from-list (player-items p)))) + (format t "~&Items: ~A" (string-from-list (list-player-items 'item p)))) ;;; These next functions have to take exactly two argument (the argument ;;; to the function and a player instance). diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9382122..dd57e26 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -62,3 +62,8 @@ (remove-if #'(lambda (x) (equalp x ,value)) (,command ,game-object))) (setf (,command ,game-object) NIL))))) + +(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." + (funcall list-function object-type place))) diff --git a/lisp/player.lisp b/lisp/player.lisp index 74757af..a004ff5 100644 --- a/lisp/player.lisp +++ b/lisp/player.lisp @@ -38,3 +38,9 @@ (description "") (special-item NIL) (special-ability NIL)) + + +(let ((list-function (make-list-function 'player NIL))) + (defun list-player-objects (object-type player) + "Get a list of the names of all the player's objects of this type." + (funcall list-function object-type player))) diff --git a/lisp/util.lisp b/lisp/util.lisp index 97cd411..5934b14 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -20,6 +20,7 @@ syms) ,@body)) +;; DEPRECATED - Needs to be replaced in the current code (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" `(progn @@ -169,6 +170,18 @@ (setf (nth i comps) (symbol-name (nth i comps))))) (eval `(read-from-string (concatenate 'string ,@comps))))) +(defun make-list-function (container-type &optional (add-s t)) + "Return function to return a list of the names of all objects of the +specified type in the container struct" + #'(lambda (object-type container) + (let ((get-objects (build-symbol container-type "-" + object-type (if add-s "s" ""))) + (get-object-name (build-symbol object-type "-name")) + (name-list NIL)) + (dolist (object (eval `(,get-objects ,container)) name-list) + (setf name-list + (cons (eval `(,get-object-name ,object)) name-list)))))) + (defun repl () "Launch a read-eval-print loop" (let ((expr (simple-input expr "lisp >"))) diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp index d437250..8c5ea4c 100644 --- a/lisp/atlantis.lisp +++ b/lisp/atlantis.lisp @@ -7,14 +7,14 @@ ;;; date: 09/05/2015 ;;; -(defconstant ATLANTIS-VERSION '(0 1 0)) +(defconstant ATLANTIS-VERSION '(0 1 1)) -(load 'util.lisp) -(load 'game-objects.lisp) -(load 'player.lisp) -(load 'world.lisp) -(load 'interpreter.lisp) -(load 'client.lisp) +(load "util.lisp") +(load "game-objects.lisp") +(load "player.lisp") +(load "world.lisp") +(load "interpreter.lisp") +(load "client.lisp") (defun development () @@ -65,10 +65,6 @@ (format t "~&Copyright (c) 2015 Daniel Vedder") (format t "~&Licensed under the terms of the MIT license.~%")) -(defun print-help () - (print-version) - (format t "~%~%Sorry, the help is not yet available!")) - (defun start-menu () "Show the start menu and take a choice from the user" (dolist (line (load-text-file "banner.txt")) @@ -101,15 +97,35 @@ (second argument)) NIL))) +(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))) + (defun parse-commandline-args () - (when (cmd-parameter "--version" T) (print-version) (quit)) - (when (cmd-parameter "--help" T) (print-help) (quit)) + (when (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)) (let ((server (cmd-parameter "--server")) (world-file (cmd-parameter "--world")) (client (cmd-parameter "--client"))) - (if (or world-file server) ;TODO change OR to AND + (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) (load-file world-file) - (format t "~&Sorry, the client is not yet available!")))) + (join-game)))) ;; Initialize the random state (which would otherwise not be very random...) diff --git a/lisp/client.lisp b/lisp/client.lisp index f952c34..730d9c6 100644 --- a/lisp/client.lisp +++ b/lisp/client.lisp @@ -19,7 +19,7 @@ (setf player (get-game-object 'player player-name))) (when (null player) (setf player (create-player player-name)) - (when (null (list-objects 'player)) + (when (null (list-world-objects 'player)) (setf (world-game-manager *world*) (player-name player))) (add-game-object player) (set-object-attribute (get-game-object 'place (player-place player)) @@ -49,18 +49,18 @@ (unless (y-or-n-p "~&Create a new player?") (start-menu)) ;; Chose race and class (format t "~&Please chose a race:") - (format t "~&Options: ~A" (string-from-list (list-objects 'race))) + (format t "~&Options: ~A" (string-from-list (list-world-objects 'race))) (setf race (input-string)) - (while (not (member race (list-objects 'race) :test #'equalp)) + (while (not (member race (list-world-objects 'race) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf race (input-string))) (setf (player-race player) (get-game-object 'race race)) (format t "~&Please chose a class:") (format t "~&Options: ~A" (string-from-list - (list-objects 'character-class))) + (list-world-objects 'character-class))) (setf character-class (input-string)) (while (not (member character-class - (list-objects 'character-class) :test #'equalp)) + (list-world-objects 'character-class) :test #'equalp)) (format t "~&Invalid choice. Please reenter:") (setf character-class (input-string))) (setf (player-class player) @@ -158,8 +158,7 @@ (player-constitution p) (string #\Tab) (player-dexterity p)) (format t "~&=====") (format t "~&Weapon: ~A" (player-weapon p)) - ;; XXX This last line might give problems (using items instead of names?) - (format t "~&Items: ~A" (string-from-list (player-items p)))) + (format t "~&Items: ~A" (string-from-list (list-player-items 'item p)))) ;;; These next functions have to take exactly two argument (the argument ;;; to the function and a player instance). diff --git a/lisp/game-objects.lisp b/lisp/game-objects.lisp index 9382122..dd57e26 100644 --- a/lisp/game-objects.lisp +++ b/lisp/game-objects.lisp @@ -62,3 +62,8 @@ (remove-if #'(lambda (x) (equalp x ,value)) (,command ,game-object))) (setf (,command ,game-object) NIL))))) + +(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." + (funcall list-function object-type place))) diff --git a/lisp/player.lisp b/lisp/player.lisp index 74757af..a004ff5 100644 --- a/lisp/player.lisp +++ b/lisp/player.lisp @@ -38,3 +38,9 @@ (description "") (special-item NIL) (special-ability NIL)) + + +(let ((list-function (make-list-function 'player NIL))) + (defun list-player-objects (object-type player) + "Get a list of the names of all the player's objects of this type." + (funcall list-function object-type player))) diff --git a/lisp/util.lisp b/lisp/util.lisp index 97cd411..5934b14 100644 --- a/lisp/util.lisp +++ b/lisp/util.lisp @@ -20,6 +20,7 @@ syms) ,@body)) +;; DEPRECATED - Needs to be replaced in the current code (defmacro simple-input (var &optional (prompt ">>>")) "Take input from terminal and store it in var" `(progn @@ -169,6 +170,18 @@ (setf (nth i comps) (symbol-name (nth i comps))))) (eval `(read-from-string (concatenate 'string ,@comps))))) +(defun make-list-function (container-type &optional (add-s t)) + "Return function to return a list of the names of all objects of the +specified type in the container struct" + #'(lambda (object-type container) + (let ((get-objects (build-symbol container-type "-" + object-type (if add-s "s" ""))) + (get-object-name (build-symbol object-type "-name")) + (name-list NIL)) + (dolist (object (eval `(,get-objects ,container)) name-list) + (setf name-list + (cons (eval `(,get-object-name ,object)) name-list)))))) + (defun repl () "Launch a read-eval-print loop" (let ((expr (simple-input expr "lisp >"))) diff --git a/lisp/world.lisp b/lisp/world.lisp index 889ef0c..eec8780 100644 --- a/lisp/world.lisp +++ b/lisp/world.lisp @@ -46,13 +46,10 @@ (when (equalp (eval `(,get-object-name ,object)) object-name) (return object))))) -(defun list-objects (object-type) - "Return a list of the names of all objects of the specified type" - (let ((get-world-objects (build-symbol "world-" object-type "s")) - (get-object-name (build-symbol object-type "-name")) - (name-list NIL)) - (dolist (object (eval `(,get-world-objects *world*)) name-list) - (setf name-list (cons (eval `(,get-object-name ,object)) name-list))))) +(let ((list-function (make-list-function 'world))) + (defun list-world-objects (object-type) + "Get a list of the names of all the world objects of this type." + (funcall list-function object-type *world*))) (defun name-world (name) "Set the name of the *world*"