diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/lisp/util.lisp b/lisp/util.lisp new file mode 100644 index 0000000..062834a --- /dev/null +++ b/lisp/util.lisp @@ -0,0 +1,85 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file provides commonly used utility functions and macros. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + + +; potentially inefficient if called often +(defmacro set-list (value &rest var-list) + "Set each symbol in var-list to value" + (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) + ((null vl) expr) + (setf (cdr (last expr)) (list var)) + (setf (cdr (last expr)) (list value)))) + +(defmacro input (&rest vars) + "Take input from terminal and store each element in a passed variable" + ; Add a prompt parameter again? + `(progn + (format t "~&>>> ") + (set-list (read) ,@vars) + (magic (first (list ,@vars))))) + +(defmacro input-string (var) + "Read a string input line" + `(progn + (format t "~&>>> ") + (setf ,var (read-line)) + (magic (read-from-string ,var)))) + +(defmacro simple-input (var &optional (prompt ">>>")) + "Take input from terminal and store it in var" + `(progn + (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)) + + +(defun count-instances (search-term search-list) + "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))) + +; Probably quite inefficient, maybe remove this function later +(defun to-list (vector) + "Turn the vector into a list" + (do* ((i 0 (1+ i)) + (e (aref vector i) (aref vector i)) + (lst (list e) (cons e lst))) + ((= i (1- (length vector))) (reverse lst)))) + +(defun load-file (file-name) + "Load a file into a list of strings (representing the lines)" + (with-open-file (f file-name) + (do* ((line (read-line f nil nil) + (read-line f nil nil)) + (file-lines (list line) (append file-lines (list line)))) + ((null line) file-lines)))) + + +;; Intended for interactive sessions +;; Load automatically at any clisp start? +(let ((file-name 'util.lisp)) + (defun l (&optional new-file-name) + (when new-file-name (setf file-name new-file-name)) + (load file-name))) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/lisp/util.lisp b/lisp/util.lisp new file mode 100644 index 0000000..062834a --- /dev/null +++ b/lisp/util.lisp @@ -0,0 +1,85 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file provides commonly used utility functions and macros. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + + +; potentially inefficient if called often +(defmacro set-list (value &rest var-list) + "Set each symbol in var-list to value" + (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) + ((null vl) expr) + (setf (cdr (last expr)) (list var)) + (setf (cdr (last expr)) (list value)))) + +(defmacro input (&rest vars) + "Take input from terminal and store each element in a passed variable" + ; Add a prompt parameter again? + `(progn + (format t "~&>>> ") + (set-list (read) ,@vars) + (magic (first (list ,@vars))))) + +(defmacro input-string (var) + "Read a string input line" + `(progn + (format t "~&>>> ") + (setf ,var (read-line)) + (magic (read-from-string ,var)))) + +(defmacro simple-input (var &optional (prompt ">>>")) + "Take input from terminal and store it in var" + `(progn + (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)) + + +(defun count-instances (search-term search-list) + "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))) + +; Probably quite inefficient, maybe remove this function later +(defun to-list (vector) + "Turn the vector into a list" + (do* ((i 0 (1+ i)) + (e (aref vector i) (aref vector i)) + (lst (list e) (cons e lst))) + ((= i (1- (length vector))) (reverse lst)))) + +(defun load-file (file-name) + "Load a file into a list of strings (representing the lines)" + (with-open-file (f file-name) + (do* ((line (read-line f nil nil) + (read-line f nil nil)) + (file-lines (list line) (append file-lines (list line)))) + ((null line) file-lines)))) + + +;; Intended for interactive sessions +;; Load automatically at any clisp start? +(let ((file-name 'util.lisp)) + (defun l (&optional new-file-name) + (when new-file-name (setf file-name new-file-name)) + (load file-name))) diff --git a/src/atlantis.lisp b/src/atlantis.lisp deleted file mode 100644 index b6b0011..0000000 --- a/src/atlantis.lisp +++ /dev/null @@ -1,69 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; - -(defconstant ATLANTIS-VERSION '(0 0 1)) - -(load 'util.lisp) - - -(defun start-server () - "Start a new game on a server" - (format t "~&What world file do you want to load?") - ;Gonna have a problem with Lisp smashing case on the file name - (input 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 ~A on port ~A" (string world-file) port)) - -(defun join-game () - "Join a running game on the server" - (format t "~&What is the IP address of the server you want to join?") - (input ip) - (while (not (= (count-instances #\. (to-list (string ip))) 3)) - (format t "~&Not an IP address: ~A. Please reenter:" ip) - (input ip)) - (format t "~&What port does the game run on?") - (while (not (numberp (input port))) - (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) - - -(defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" - (first ATLANTIS-VERSION) - (second ATLANTIS-VERSION) - (third ATLANTIS-VERSION)) - (format t "~&Copyright (c)2015 Daniel Vedder") - (format t "~&Licensed under the terms of the GNU General Public License.")) - -(defun start-menu () - "Show the start menu and take a choice from the user" - ;; FIXME: Printing the banner file to screen doesn't work yet - ;; (with-open-file (logo "banner.txt") - ;; (do ((word (read logo) (read logo))) - ;; ((null word)) - ;; (format t "~A" word) - ;; (when (find-if (lambda (letter) (equalp letter "\n")) - ;; (symbol-name word)) - ;; (format t "~&")))) - (format t "~&~%Welcome! What do you want to do?") - (format t "~&-> (S)tart a server") - (format t "~&-> (J)oin a game") - (format t "~&-> (A)bout") - (format t "~&-> (E)xit") - (input choice) - (cond ((equalp choice 's) (start-server)) - ((equalp choice 'j) (join-game)) - ((equalp choice 'a) - (print-version) (start-menu)) - ((equalp choice 'e) - (format t "~&Goodbye!") (quit)))) - -(start-menu) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/lisp/util.lisp b/lisp/util.lisp new file mode 100644 index 0000000..062834a --- /dev/null +++ b/lisp/util.lisp @@ -0,0 +1,85 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file provides commonly used utility functions and macros. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + + +; potentially inefficient if called often +(defmacro set-list (value &rest var-list) + "Set each symbol in var-list to value" + (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) + ((null vl) expr) + (setf (cdr (last expr)) (list var)) + (setf (cdr (last expr)) (list value)))) + +(defmacro input (&rest vars) + "Take input from terminal and store each element in a passed variable" + ; Add a prompt parameter again? + `(progn + (format t "~&>>> ") + (set-list (read) ,@vars) + (magic (first (list ,@vars))))) + +(defmacro input-string (var) + "Read a string input line" + `(progn + (format t "~&>>> ") + (setf ,var (read-line)) + (magic (read-from-string ,var)))) + +(defmacro simple-input (var &optional (prompt ">>>")) + "Take input from terminal and store it in var" + `(progn + (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)) + + +(defun count-instances (search-term search-list) + "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))) + +; Probably quite inefficient, maybe remove this function later +(defun to-list (vector) + "Turn the vector into a list" + (do* ((i 0 (1+ i)) + (e (aref vector i) (aref vector i)) + (lst (list e) (cons e lst))) + ((= i (1- (length vector))) (reverse lst)))) + +(defun load-file (file-name) + "Load a file into a list of strings (representing the lines)" + (with-open-file (f file-name) + (do* ((line (read-line f nil nil) + (read-line f nil nil)) + (file-lines (list line) (append file-lines (list line)))) + ((null line) file-lines)))) + + +;; Intended for interactive sessions +;; Load automatically at any clisp start? +(let ((file-name 'util.lisp)) + (defun l (&optional new-file-name) + (when new-file-name (setf file-name new-file-name)) + (load file-name))) diff --git a/src/atlantis.lisp b/src/atlantis.lisp deleted file mode 100644 index b6b0011..0000000 --- a/src/atlantis.lisp +++ /dev/null @@ -1,69 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; - -(defconstant ATLANTIS-VERSION '(0 0 1)) - -(load 'util.lisp) - - -(defun start-server () - "Start a new game on a server" - (format t "~&What world file do you want to load?") - ;Gonna have a problem with Lisp smashing case on the file name - (input 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 ~A on port ~A" (string world-file) port)) - -(defun join-game () - "Join a running game on the server" - (format t "~&What is the IP address of the server you want to join?") - (input ip) - (while (not (= (count-instances #\. (to-list (string ip))) 3)) - (format t "~&Not an IP address: ~A. Please reenter:" ip) - (input ip)) - (format t "~&What port does the game run on?") - (while (not (numberp (input port))) - (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) - - -(defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" - (first ATLANTIS-VERSION) - (second ATLANTIS-VERSION) - (third ATLANTIS-VERSION)) - (format t "~&Copyright (c)2015 Daniel Vedder") - (format t "~&Licensed under the terms of the GNU General Public License.")) - -(defun start-menu () - "Show the start menu and take a choice from the user" - ;; FIXME: Printing the banner file to screen doesn't work yet - ;; (with-open-file (logo "banner.txt") - ;; (do ((word (read logo) (read logo))) - ;; ((null word)) - ;; (format t "~A" word) - ;; (when (find-if (lambda (letter) (equalp letter "\n")) - ;; (symbol-name word)) - ;; (format t "~&")))) - (format t "~&~%Welcome! What do you want to do?") - (format t "~&-> (S)tart a server") - (format t "~&-> (J)oin a game") - (format t "~&-> (A)bout") - (format t "~&-> (E)xit") - (input choice) - (cond ((equalp choice 's) (start-server)) - ((equalp choice 'j) (join-game)) - ((equalp choice 'a) - (print-version) (start-menu)) - ((equalp choice 'e) - (format t "~&Goodbye!") (quit)))) - -(start-menu) diff --git a/src/banner.txt b/src/banner.txt deleted file mode 100644 index 68d8ee8..0000000 --- a/src/banner.txt +++ /dev/null @@ -1,10 +0,0 @@ -==================================================== -|| \ / || -|| - O -MM _ MM ATLANTIS || -|| / \ ||_/.\_|| || -|| |*| |*| Lost worlds await || -|| ~~~~~| | A | |~~~~ || -|| ~~~~###########~~~ || -|| ~~~#############~~ (c) 2015 Daniel Vedder || -|| ~~~~~~~~~~~~~~~~~~ || -==================================================== diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/lisp/util.lisp b/lisp/util.lisp new file mode 100644 index 0000000..062834a --- /dev/null +++ b/lisp/util.lisp @@ -0,0 +1,85 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file provides commonly used utility functions and macros. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + + +; potentially inefficient if called often +(defmacro set-list (value &rest var-list) + "Set each symbol in var-list to value" + (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) + ((null vl) expr) + (setf (cdr (last expr)) (list var)) + (setf (cdr (last expr)) (list value)))) + +(defmacro input (&rest vars) + "Take input from terminal and store each element in a passed variable" + ; Add a prompt parameter again? + `(progn + (format t "~&>>> ") + (set-list (read) ,@vars) + (magic (first (list ,@vars))))) + +(defmacro input-string (var) + "Read a string input line" + `(progn + (format t "~&>>> ") + (setf ,var (read-line)) + (magic (read-from-string ,var)))) + +(defmacro simple-input (var &optional (prompt ">>>")) + "Take input from terminal and store it in var" + `(progn + (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)) + + +(defun count-instances (search-term search-list) + "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))) + +; Probably quite inefficient, maybe remove this function later +(defun to-list (vector) + "Turn the vector into a list" + (do* ((i 0 (1+ i)) + (e (aref vector i) (aref vector i)) + (lst (list e) (cons e lst))) + ((= i (1- (length vector))) (reverse lst)))) + +(defun load-file (file-name) + "Load a file into a list of strings (representing the lines)" + (with-open-file (f file-name) + (do* ((line (read-line f nil nil) + (read-line f nil nil)) + (file-lines (list line) (append file-lines (list line)))) + ((null line) file-lines)))) + + +;; Intended for interactive sessions +;; Load automatically at any clisp start? +(let ((file-name 'util.lisp)) + (defun l (&optional new-file-name) + (when new-file-name (setf file-name new-file-name)) + (load file-name))) diff --git a/src/atlantis.lisp b/src/atlantis.lisp deleted file mode 100644 index b6b0011..0000000 --- a/src/atlantis.lisp +++ /dev/null @@ -1,69 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; - -(defconstant ATLANTIS-VERSION '(0 0 1)) - -(load 'util.lisp) - - -(defun start-server () - "Start a new game on a server" - (format t "~&What world file do you want to load?") - ;Gonna have a problem with Lisp smashing case on the file name - (input 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 ~A on port ~A" (string world-file) port)) - -(defun join-game () - "Join a running game on the server" - (format t "~&What is the IP address of the server you want to join?") - (input ip) - (while (not (= (count-instances #\. (to-list (string ip))) 3)) - (format t "~&Not an IP address: ~A. Please reenter:" ip) - (input ip)) - (format t "~&What port does the game run on?") - (while (not (numberp (input port))) - (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) - - -(defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" - (first ATLANTIS-VERSION) - (second ATLANTIS-VERSION) - (third ATLANTIS-VERSION)) - (format t "~&Copyright (c)2015 Daniel Vedder") - (format t "~&Licensed under the terms of the GNU General Public License.")) - -(defun start-menu () - "Show the start menu and take a choice from the user" - ;; FIXME: Printing the banner file to screen doesn't work yet - ;; (with-open-file (logo "banner.txt") - ;; (do ((word (read logo) (read logo))) - ;; ((null word)) - ;; (format t "~A" word) - ;; (when (find-if (lambda (letter) (equalp letter "\n")) - ;; (symbol-name word)) - ;; (format t "~&")))) - (format t "~&~%Welcome! What do you want to do?") - (format t "~&-> (S)tart a server") - (format t "~&-> (J)oin a game") - (format t "~&-> (A)bout") - (format t "~&-> (E)xit") - (input choice) - (cond ((equalp choice 's) (start-server)) - ((equalp choice 'j) (join-game)) - ((equalp choice 'a) - (print-version) (start-menu)) - ((equalp choice 'e) - (format t "~&Goodbye!") (quit)))) - -(start-menu) diff --git a/src/banner.txt b/src/banner.txt deleted file mode 100644 index 68d8ee8..0000000 --- a/src/banner.txt +++ /dev/null @@ -1,10 +0,0 @@ -==================================================== -|| \ / || -|| - O -MM _ MM ATLANTIS || -|| / \ ||_/.\_|| || -|| |*| |*| Lost worlds await || -|| ~~~~~| | A | |~~~~ || -|| ~~~~###########~~~ || -|| ~~~#############~~ (c) 2015 Daniel Vedder || -|| ~~~~~~~~~~~~~~~~~~ || -==================================================== diff --git a/src/interpreter.lisp b/src/interpreter.lisp deleted file mode 100644 index 3a1fe40..0000000 --- a/src/interpreter.lisp +++ /dev/null @@ -1,10 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; The interpreter file loads an ATL source file and parses it. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49cb2b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +ATLANTIS + +Copyright (c) 2015 Daniel Vedder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lisp/atlantis.lisp b/lisp/atlantis.lisp new file mode 100644 index 0000000..acfa19c --- /dev/null +++ b/lisp/atlantis.lisp @@ -0,0 +1,65 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + +(defconstant ATLANTIS-VERSION '(0 0 1)) + +(load 'util.lisp) + + +(defun start-server () + "Start a new game on a server" + (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 ~A on port ~A" (string world-file) port)) + +(defun join-game () + "Join a running game on the server" + (format t "~&What is the IP address of the server you want to join?") + (input-string ip) + (while (not (= (count-instances #\. (to-list ip)) 3)) + (format t "~&Not an IP address: ~A. Please reenter:" ip) + (input ip)) + (format t "~&What port does the game run on?") + (while (not (numberp (input port))) + (format t "~&Not a number: ~A. Please reenter:" port)) + (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) + + +(defun print-version () + (format t "~&Lisp Atlantis ~A.~A.~A" + (first ATLANTIS-VERSION) + (second ATLANTIS-VERSION) + (third ATLANTIS-VERSION)) + (format t "~&Copyright (c)2015 Daniel Vedder") + (format t "~&Licensed under the terms of the MIT license.")) + +(defun start-menu () + "Show the start menu and take a choice from the user" + (with-open-file (logo "banner.txt") + (do ((line (read-line logo nil nil) + (read-line logo nil nil))) + ((null line)) + (format t "~&~A" line))) + (format t "~&~%Welcome! What do you want to do?") + (format t "~&-> (S)tart a server") + (format t "~&-> (J)oin a game") + (format t "~&-> (A)bout") + (format t "~&-> (E)xit") + (input choice) + (cond ((equalp choice 's) (start-server)) + ((equalp choice 'j) (join-game)) + ((equalp choice 'a) + (print-version) (start-menu)) + ((equalp choice 'e) + (format t "~&Goodbye!") (quit)))) + +(start-menu) diff --git a/lisp/banner.txt b/lisp/banner.txt new file mode 100644 index 0000000..68d8ee8 --- /dev/null +++ b/lisp/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| \ / || +|| - O -MM _ MM ATLANTIS || +|| / \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/lisp/interpreter.lisp b/lisp/interpreter.lisp new file mode 100644 index 0000000..8265344 --- /dev/null +++ b/lisp/interpreter.lisp @@ -0,0 +1,10 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; The interpreter file loads an ATL source file and parses it. +;;; +;;; Licensed under the terms of the MIT license +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; diff --git a/lisp/util.lisp b/lisp/util.lisp new file mode 100644 index 0000000..062834a --- /dev/null +++ b/lisp/util.lisp @@ -0,0 +1,85 @@ +;;; +;;; Atlantis is a framework for creating multi-user dungeon worlds. +;;; This is the Common Lisp implementation. +;;; +;;; This file provides commonly used utility functions and macros. +;;; +;;; Licensed under the terms of the MIT license. +;;; author: Daniel Vedder +;;; date: 09/05/2015 +;;; + + +; potentially inefficient if called often +(defmacro set-list (value &rest var-list) + "Set each symbol in var-list to value" + (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) + ((null vl) expr) + (setf (cdr (last expr)) (list var)) + (setf (cdr (last expr)) (list value)))) + +(defmacro input (&rest vars) + "Take input from terminal and store each element in a passed variable" + ; Add a prompt parameter again? + `(progn + (format t "~&>>> ") + (set-list (read) ,@vars) + (magic (first (list ,@vars))))) + +(defmacro input-string (var) + "Read a string input line" + `(progn + (format t "~&>>> ") + (setf ,var (read-line)) + (magic (read-from-string ,var)))) + +(defmacro simple-input (var &optional (prompt ">>>")) + "Take input from terminal and store it in var" + `(progn + (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)) + + +(defun count-instances (search-term search-list) + "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))) + +; Probably quite inefficient, maybe remove this function later +(defun to-list (vector) + "Turn the vector into a list" + (do* ((i 0 (1+ i)) + (e (aref vector i) (aref vector i)) + (lst (list e) (cons e lst))) + ((= i (1- (length vector))) (reverse lst)))) + +(defun load-file (file-name) + "Load a file into a list of strings (representing the lines)" + (with-open-file (f file-name) + (do* ((line (read-line f nil nil) + (read-line f nil nil)) + (file-lines (list line) (append file-lines (list line)))) + ((null line) file-lines)))) + + +;; Intended for interactive sessions +;; Load automatically at any clisp start? +(let ((file-name 'util.lisp)) + (defun l (&optional new-file-name) + (when new-file-name (setf file-name new-file-name)) + (load file-name))) diff --git a/src/atlantis.lisp b/src/atlantis.lisp deleted file mode 100644 index b6b0011..0000000 --- a/src/atlantis.lisp +++ /dev/null @@ -1,69 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; - -(defconstant ATLANTIS-VERSION '(0 0 1)) - -(load 'util.lisp) - - -(defun start-server () - "Start a new game on a server" - (format t "~&What world file do you want to load?") - ;Gonna have a problem with Lisp smashing case on the file name - (input 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 ~A on port ~A" (string world-file) port)) - -(defun join-game () - "Join a running game on the server" - (format t "~&What is the IP address of the server you want to join?") - (input ip) - (while (not (= (count-instances #\. (to-list (string ip))) 3)) - (format t "~&Not an IP address: ~A. Please reenter:" ip) - (input ip)) - (format t "~&What port does the game run on?") - (while (not (numberp (input port))) - (format t "~&Not a number: ~A. Please reenter:" port)) - (format t "~&Joining game on ~A:~A" (symbol-name ip) port)) - - -(defun print-version () - (format t "~&Lisp Atlantis ~A.~A.~A" - (first ATLANTIS-VERSION) - (second ATLANTIS-VERSION) - (third ATLANTIS-VERSION)) - (format t "~&Copyright (c)2015 Daniel Vedder") - (format t "~&Licensed under the terms of the GNU General Public License.")) - -(defun start-menu () - "Show the start menu and take a choice from the user" - ;; FIXME: Printing the banner file to screen doesn't work yet - ;; (with-open-file (logo "banner.txt") - ;; (do ((word (read logo) (read logo))) - ;; ((null word)) - ;; (format t "~A" word) - ;; (when (find-if (lambda (letter) (equalp letter "\n")) - ;; (symbol-name word)) - ;; (format t "~&")))) - (format t "~&~%Welcome! What do you want to do?") - (format t "~&-> (S)tart a server") - (format t "~&-> (J)oin a game") - (format t "~&-> (A)bout") - (format t "~&-> (E)xit") - (input choice) - (cond ((equalp choice 's) (start-server)) - ((equalp choice 'j) (join-game)) - ((equalp choice 'a) - (print-version) (start-menu)) - ((equalp choice 'e) - (format t "~&Goodbye!") (quit)))) - -(start-menu) diff --git a/src/banner.txt b/src/banner.txt deleted file mode 100644 index 68d8ee8..0000000 --- a/src/banner.txt +++ /dev/null @@ -1,10 +0,0 @@ -==================================================== -|| \ / || -|| - O -MM _ MM ATLANTIS || -|| / \ ||_/.\_|| || -|| |*| |*| Lost worlds await || -|| ~~~~~| | A | |~~~~ || -|| ~~~~###########~~~ || -|| ~~~#############~~ (c) 2015 Daniel Vedder || -|| ~~~~~~~~~~~~~~~~~~ || -==================================================== diff --git a/src/interpreter.lisp b/src/interpreter.lisp deleted file mode 100644 index 3a1fe40..0000000 --- a/src/interpreter.lisp +++ /dev/null @@ -1,10 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; The interpreter file loads an ATL source file and parses it. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; diff --git a/src/util.lisp b/src/util.lisp deleted file mode 100644 index 3a3fd4e..0000000 --- a/src/util.lisp +++ /dev/null @@ -1,63 +0,0 @@ -;;; -;;; Atlantis is a framework for creating multi-user dungeon worlds. -;;; This is the Common Lisp implementation. -;;; -;;; This file provides commonly used utility functions and macros. -;;; -;;; Licensed under the terms of the GPLv3 -;;; author: Daniel Vedder -;;; date: 09/05/2015 -;;; - - -; potentially inefficient if called often -(defmacro set-list (value &rest var-list) - "Set each symbol in var-list to value" - (do* ((expr (list 'setf)) (vl var-list (cdr vl)) (var (car vl) (car vl))) - ((null vl) expr) - (setf (cdr (last expr)) (list var)) - (setf (cdr (last expr)) (list value)))) - -(defmacro input (&rest vars) - "Take input from terminal and store each element in a passed variable" - ; Add a prompt parameter again? - `(progn - (format t "~&>>> ") - (set-list (read) ,@vars))) - -(defmacro simple-input (var &optional (prompt ">>>")) - "Take input from terminal and store it in var" - `(progn - (format t "~&~A " ,prompt) - (setf ,var (read)))) - -(defmacro while (condition &body body) - "An implementation of a while loop as found in other languages" - `(do () - ((not ,condition)) - ,@body)) - - -(defun count-instances (search-term search-list) - "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))) - -; Probably quite inefficient, maybe remove this function later -(defun to-list (vector) - "Turn the vector into a list" - (do* ((i 0 (1+ i)) - (e (aref vector i) (aref vector i)) - (lst (list e) (cons e lst))) - ((= i (1- (length vector))) (reverse lst)))) - -; Use this to develop the input macro further -(defun commandline () - "This function takes in a command together with its argument -from the commandline" - (format t "~&>>> ") - (setf command (read)) - (setf argument (read)) - (format t "~&Command = ~A~%Argument = ~A" command argument))