diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/TODO b/TODO index 66c02b4..dc9ac89 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ * change world to 2D array * optimise world creation & map transfer + +* fix response to prolonged key presses * implement look/walk/attack modes @@ -24,6 +26,8 @@ * save & load games +* error handling! + * create help window * generate secondary seeds to smoothen landscape @@ -44,7 +48,7 @@ * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding - sb-impl::n" -> if several players log on? + sb-impl::n" -> if several players log on? / if one player quits? -> NON-SEVERE diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/TODO b/TODO index 66c02b4..dc9ac89 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ * change world to 2D array * optimise world creation & map transfer + +* fix response to prolonged key presses * implement look/walk/attack modes @@ -24,6 +26,8 @@ * save & load games +* error handling! + * create help window * generate secondary seeds to smoothen landscape @@ -44,7 +48,7 @@ * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding - sb-impl::n" -> if several players log on? + sb-impl::n" -> if several players log on? / if one player quits? -> NON-SEVERE diff --git a/naledi.lisp b/naledi.lisp index 0bf9c7a..2fe982b 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX change this as needed +(declaim (optimize (debug 3) (speed 1) (space 1) (safety 1))) + ;;XXX convenience functions during development, remove later (defun start () (nya:start-game)) diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/TODO b/TODO index 66c02b4..dc9ac89 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ * change world to 2D array * optimise world creation & map transfer + +* fix response to prolonged key presses * implement look/walk/attack modes @@ -24,6 +26,8 @@ * save & load games +* error handling! + * create help window * generate secondary seeds to smoothen landscape @@ -44,7 +48,7 @@ * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding - sb-impl::n" -> if several players log on? + sb-impl::n" -> if several players log on? / if one player quits? -> NON-SEVERE diff --git a/naledi.lisp b/naledi.lisp index 0bf9c7a..2fe982b 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX change this as needed +(declaim (optimize (debug 3) (speed 1) (space 1) (safety 1))) + ;;XXX convenience functions during development, remove later (defun start () (nya:start-game)) diff --git a/server/player.lisp b/server/player.lisp index c14ad45..b11a943 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -43,10 +43,13 @@ (case (call-next-method) ('OUT-OF-BOUNDS (msg-player p "Out of bounds.") NIL) ('PATCH-OCCUPIED - (msg-player p "This patch is blocked by ~A." - (leading-vowel (.name (patch-occupant - (patchindir (.x h) (.y h) dir))))) - NIL) + ;;It can happen that the occupant moves away between + ;; (call-next-method) above and the (patch-occupant) query below + (let ((o (patch-occupant (patchindir (.x h) (.y h) dir)))) + (if o (msg-player p "This patch is blocked by ~A." + (leading-vowel (.name o))) + (msg-player p "This patch is blocked."))) + NIL) (T T)))) (defun msg-player (player msg &rest format-args) diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/TODO b/TODO index 66c02b4..dc9ac89 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ * change world to 2D array * optimise world creation & map transfer + +* fix response to prolonged key presses * implement look/walk/attack modes @@ -24,6 +26,8 @@ * save & load games +* error handling! + * create help window * generate secondary seeds to smoothen landscape @@ -44,7 +48,7 @@ * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding - sb-impl::n" -> if several players log on? + sb-impl::n" -> if several players log on? / if one player quits? -> NON-SEVERE diff --git a/naledi.lisp b/naledi.lisp index 0bf9c7a..2fe982b 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX change this as needed +(declaim (optimize (debug 3) (speed 1) (space 1) (safety 1))) + ;;XXX convenience functions during development, remove later (defun start () (nya:start-game)) diff --git a/server/player.lisp b/server/player.lisp index c14ad45..b11a943 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -43,10 +43,13 @@ (case (call-next-method) ('OUT-OF-BOUNDS (msg-player p "Out of bounds.") NIL) ('PATCH-OCCUPIED - (msg-player p "This patch is blocked by ~A." - (leading-vowel (.name (patch-occupant - (patchindir (.x h) (.y h) dir))))) - NIL) + ;;It can happen that the occupant moves away between + ;; (call-next-method) above and the (patch-occupant) query below + (let ((o (patch-occupant (patchindir (.x h) (.y h) dir)))) + (if o (msg-player p "This patch is blocked by ~A." + (leading-vowel (.name o))) + (msg-player p "This patch is blocked."))) + NIL) (T T)))) (defun msg-player (player msg &rest format-args) diff --git a/server/server.lisp b/server/server.lisp index ac7ff87..ad1049f 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -44,34 +44,6 @@ (let ((p (get-player name))) (when p (player-online p)))) -;;; WORLD OBJECT - -(let ((world NIL)) - ;;XXX do we need to keep track of the current world map (i.e. patch chars - ;; and colours),or player map requests will take way too long to serve? - (defun set-world (w) (setf world w)) - - (defun world-size () (length world)) - - (defun save-topography (file-name) ;XXX (re)move this? - "Save the world topography as a text file" - (logf 3 "~&Saving world to file ~A" file-name) ;debug - (with-open-file (tf file-name :direction :output) - (dolist (row world) - (format stream "~&~A~%" - (string-from-list - (mapcar #'(lambda (p) - (biome-char (patch-biome p))) - row) ""))))) - - (defun save-world (&optional (file-name "naledi.save")) - ;;TODO - (save-players file-name)) - - (defun coord (x y) - "Return the patch at the given coordinates or NIL if out of bounds" - (unless (or (< x 0) (< y 0) (> x (length world)) (> y (length world))) - (nth x (nth y world))))) ;;; WORLD THREADS diff --git a/.gitignore b/.gitignore index 2117728..296b0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ naledi.log usocket_minimal.lisp heap.md +debug_cheatsheet.txt diff --git a/TODO b/TODO index 66c02b4..dc9ac89 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ * change world to 2D array * optimise world creation & map transfer + +* fix response to prolonged key presses * implement look/walk/attack modes @@ -24,6 +26,8 @@ * save & load games +* error handling! + * create help window * generate secondary seeds to smoothen landscape @@ -44,7 +48,7 @@ * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding - sb-impl::n" -> if several players log on? + sb-impl::n" -> if several players log on? / if one player quits? -> NON-SEVERE diff --git a/naledi.lisp b/naledi.lisp index 0bf9c7a..2fe982b 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;XXX change this as needed +(declaim (optimize (debug 3) (speed 1) (space 1) (safety 1))) + ;;XXX convenience functions during development, remove later (defun start () (nya:start-game)) diff --git a/server/player.lisp b/server/player.lisp index c14ad45..b11a943 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -43,10 +43,13 @@ (case (call-next-method) ('OUT-OF-BOUNDS (msg-player p "Out of bounds.") NIL) ('PATCH-OCCUPIED - (msg-player p "This patch is blocked by ~A." - (leading-vowel (.name (patch-occupant - (patchindir (.x h) (.y h) dir))))) - NIL) + ;;It can happen that the occupant moves away between + ;; (call-next-method) above and the (patch-occupant) query below + (let ((o (patch-occupant (patchindir (.x h) (.y h) dir)))) + (if o (msg-player p "This patch is blocked by ~A." + (leading-vowel (.name o))) + (msg-player p "This patch is blocked."))) + NIL) (T T)))) (defun msg-player (player msg &rest format-args) diff --git a/server/server.lisp b/server/server.lisp index ac7ff87..ad1049f 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -44,34 +44,6 @@ (let ((p (get-player name))) (when p (player-online p)))) -;;; WORLD OBJECT - -(let ((world NIL)) - ;;XXX do we need to keep track of the current world map (i.e. patch chars - ;; and colours),or player map requests will take way too long to serve? - (defun set-world (w) (setf world w)) - - (defun world-size () (length world)) - - (defun save-topography (file-name) ;XXX (re)move this? - "Save the world topography as a text file" - (logf 3 "~&Saving world to file ~A" file-name) ;debug - (with-open-file (tf file-name :direction :output) - (dolist (row world) - (format stream "~&~A~%" - (string-from-list - (mapcar #'(lambda (p) - (biome-char (patch-biome p))) - row) ""))))) - - (defun save-world (&optional (file-name "naledi.save")) - ;;TODO - (save-players file-name)) - - (defun coord (x y) - "Return the patch at the given coordinates or NIL if out of bounds" - (unless (or (< x 0) (< y 0) (> x (length world)) (> y (length world))) - (nth x (nth y world))))) ;;; WORLD THREADS diff --git a/server/world.lisp b/server/world.lisp index fb65c68..0b233e7 100644 --- a/server/world.lisp +++ b/server/world.lisp @@ -9,6 +9,8 @@ (in-package :naledi-ya-africa) +;;; PATCHES AND BIOMES + (defstruct patch (pos '(0 0)) ;position (biome NIL) @@ -23,8 +25,6 @@ (char #\.) ;default map display character (col ':white)) ;default map display colour -;; BIOME LIST - (let ((biome-list NIL)) (defun register-biome (symbol-name biome-object) (setf biome-list (cons (list symbol-name biome-object) biome-list))) @@ -41,11 +41,21 @@ :name ,(symbol-to-string name) ,@body))) -;; MATRIX FUNCTIONS +;;; MATRIX FUNCTIONS (defun init-matrix (size) "Create a square matrix of empty patches" - ;;XXX change this to arrays for performance + (logf 4 "~&Creating a ~S/~S matrix." size size) + (let ((world (make-array (list size size) + :element-type 'patch))) + (dotimes (y size world) + (dotimes (x size) + (setf (aref world y x) + (make-patch :pos (list x y))))))) + +(defun init-matrix-old (size) + "Create a square matrix of empty patches" + ;;TODO change this to arrays for performance (logf 4 "~&Creating a ~S/~S matrix." size size) (do ((y 0 (1+ y)) (world NIL) (row NIL NIL)) ((= y size) world) @@ -127,7 +137,7 @@ (patchindir (first (patch-pos p)) (second (patch-pos p)) dir)) -;; WORLD CREATION FUNCTIONS +;;; WORLD CREATION FUNCTIONS (defun get-patch-feature (patch) "Find a random feature (or none) to occupy this patch." @@ -174,7 +184,7 @@ (defun create-world (size) "Create a world of the specified size (square)" (set-world (init-matrix size)) - ;;XXX magic numbers + ;;TODO remove magic numbers (logf 3 "~&Generating biomes") (generate-biomes 10) (logf 3 "~&Generating streams") @@ -187,3 +197,36 @@ (logf 2 "~&~A~%Log level ~S" (time-stamp) *loglevel*) (setf *random-state* (make-random-state t)) (create-world *world-size*)) + + +;;; ADMINISTRATE THE WORLD OBJECT + +(let ((world NIL)) + ;;XXX do we need to keep track of the current world map (i.e. patch chars + ;; and colours),or player map requests will take way too long to serve? + (defun set-world (w) (setf world w)) + + (defun world-size () (first (array-dimensions world))) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (logf 3 "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun save-world (&optional (file-name "naledi.save")) + ;;TODO + (save-players file-name)) + + (defun coord (x y) + "Return the patch at the given coordinates or NIL if out of bounds" + (unless (or (< x 0) (< y 0) + ;;XXX not sure if first/second is right way round here... + (>= x (first (array-dimensions world))) + (>= y (second (array-dimensions world)))) + (aref world y x))))