diff --git a/client/networking.lisp b/client/networking.lisp index bb61c87..7833f6a 100644 --- a/client/networking.lisp +++ b/client/networking.lisp @@ -39,7 +39,7 @@ ;; (eof (second raw-reply) (second raw-reply)) ;; (reply reply-line (sconc reply reply-line))) ;; ((or eof (null reply-line)) ;;FIXME - (logf 4 "CLIENT: received reply ~A" reply) + (logf 4 "CLIENT: received reply.") (if (search "ERROR" reply) (error reply) (read-from-string reply))))) diff --git a/client/networking.lisp b/client/networking.lisp index bb61c87..7833f6a 100644 --- a/client/networking.lisp +++ b/client/networking.lisp @@ -39,7 +39,7 @@ ;; (eof (second raw-reply) (second raw-reply)) ;; (reply reply-line (sconc reply reply-line))) ;; ((or eof (null reply-line)) ;;FIXME - (logf 4 "CLIENT: received reply ~A" reply) + (logf 4 "CLIENT: received reply.") (if (search "ERROR" reply) (error reply) (read-from-string reply))))) diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 9b9a9fe..2ea5445 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -98,8 +98,7 @@ (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" - (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) - (me (list (round (/ width 4)) (halve height)))) + (let ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr)))) (croatoan:clear scr) (croatoan:refresh scr) (croatoan:with-windows ((mapwin :position '(0 0) @@ -117,7 +116,7 @@ (newswin :input-blocking *framerate* :position (list height 0) :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) + (update-ui mapwin playerwin placewin newswin) ;;TODO (croatoan:event-case (scr event) (#\q (disconnect) @@ -128,25 +127,61 @@ (terminate)) (return-from croatoan:event-case)) (#\n (croatoan:draw-menu (message-window))) - ;;FIXME change directions to single letters - (:up (query-server "move north") - (update-ui mapwin playerwin placewin newswin me)) - (:down (query-server "move south") - (update-ui mapwin playerwin placewin newswin me)) - (:left (query-server "move west") - (update-ui mapwin playerwin placewin newswin me)) - (:right (query-server "move east") - (update-ui mapwin playerwin placewin newswin me)) - ((nil) (update-ui mapwin playerwin placewin newswin me)) + ;;XXX How about moving diagonally? + (:up (query-server "move n") + (update-ui mapwin playerwin placewin newswin)) + (:down (query-server "move s") + (update-ui mapwin playerwin placewin newswin)) + (:left (query-server "move w") + (update-ui mapwin playerwin placewin newswin)) + (:right (query-server "move e") + (update-ui mapwin playerwin placewin newswin)) + ((nil) (update-ui mapwin playerwin placewin newswin)) (otherwise (notify (string event))))))) -(defun update-ui (mapwin playerwin placewin newswin me) +(defun update-ui (mapwin playerwin placewin newswin) "Update all four UI elements" (draw-map mapwin) (draw-player-panel playerwin) - (draw-place-panel placewin me) + (draw-place-panel placewin) (draw-news-panel newswin)) +(defun draw-map-old (win me) + "Draw a portion of the game map in an ncurses window" + (setf (croatoan:.color-pair win) '(:white :black)) + (croatoan:box win) + (croatoan:move win 1 1) + (let ((x0 (- (first me) (round (/ (croatoan:.width win) 4)))) + (y0 (- (second me) (halve (croatoan:.height win))))) + ;; NB. x0 and w are calculated differently to y0 and h because we insert + ;; a space after each character + (dotimes (h (1- (croatoan:.height win))) + (dotimes (w (- (halve (croatoan:.width win) 'floor) 2)) + ;;TODO replace `coord' with `query-server' + (let ((p (coord (+ w x0 3) (+ h y0 1)))) + (if (null p) (croatoan:add-char win #\space) + (if (and (= (first (patch-pos p)) (first me)) + (= (second (patch-pos p)) (second me))) + (progn (setf (croatoan:.color-pair win) + '(:white :black)) + (croatoan:add-char win #\@)) + (if (patch-occupant p) + (progn + (setf (croatoan:.color-pair win) + (list (.color (patch-occupant p)) + :black)) + (croatoan:add-char win + (.char (patch-occupant p)))) + (progn + (setf (croatoan:.color-pair win) + (list (biome-col (patch-biome p)) + :black)) + (croatoan:add-char win + (biome-char (patch-biome p))))))) + (croatoan:add-char win #\space))) + (croatoan:move win (1+ h) 1)) + (croatoan:refresh win))) + (defun draw-map (win) "Draw a portion of the game map in an ncurses window" ;;FIXME request each patch char singly from the server - doing it all @@ -176,10 +211,9 @@ (croatoan:add-string win "This is the player panel.") (croatoan:refresh win)) -(defun draw-place-panel (win me) +(defun draw-place-panel (win) "Draw a panel with information about the player's current location." - ;;TODO replace `describe-patch' with `query-server' - (let ((descr (break-lines (describe-patch me) + (let ((descr (break-lines (query-server "describe-patch") (- (croatoan:.width win) 2)))) (croatoan:clear win) (croatoan:box win) diff --git a/client/networking.lisp b/client/networking.lisp index bb61c87..7833f6a 100644 --- a/client/networking.lisp +++ b/client/networking.lisp @@ -39,7 +39,7 @@ ;; (eof (second raw-reply) (second raw-reply)) ;; (reply reply-line (sconc reply reply-line))) ;; ((or eof (null reply-line)) ;;FIXME - (logf 4 "CLIENT: received reply ~A" reply) + (logf 4 "CLIENT: received reply.") (if (search "ERROR" reply) (error reply) (read-from-string reply))))) diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 9b9a9fe..2ea5445 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -98,8 +98,7 @@ (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" - (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) - (me (list (round (/ width 4)) (halve height)))) + (let ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr)))) (croatoan:clear scr) (croatoan:refresh scr) (croatoan:with-windows ((mapwin :position '(0 0) @@ -117,7 +116,7 @@ (newswin :input-blocking *framerate* :position (list height 0) :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) + (update-ui mapwin playerwin placewin newswin) ;;TODO (croatoan:event-case (scr event) (#\q (disconnect) @@ -128,25 +127,61 @@ (terminate)) (return-from croatoan:event-case)) (#\n (croatoan:draw-menu (message-window))) - ;;FIXME change directions to single letters - (:up (query-server "move north") - (update-ui mapwin playerwin placewin newswin me)) - (:down (query-server "move south") - (update-ui mapwin playerwin placewin newswin me)) - (:left (query-server "move west") - (update-ui mapwin playerwin placewin newswin me)) - (:right (query-server "move east") - (update-ui mapwin playerwin placewin newswin me)) - ((nil) (update-ui mapwin playerwin placewin newswin me)) + ;;XXX How about moving diagonally? + (:up (query-server "move n") + (update-ui mapwin playerwin placewin newswin)) + (:down (query-server "move s") + (update-ui mapwin playerwin placewin newswin)) + (:left (query-server "move w") + (update-ui mapwin playerwin placewin newswin)) + (:right (query-server "move e") + (update-ui mapwin playerwin placewin newswin)) + ((nil) (update-ui mapwin playerwin placewin newswin)) (otherwise (notify (string event))))))) -(defun update-ui (mapwin playerwin placewin newswin me) +(defun update-ui (mapwin playerwin placewin newswin) "Update all four UI elements" (draw-map mapwin) (draw-player-panel playerwin) - (draw-place-panel placewin me) + (draw-place-panel placewin) (draw-news-panel newswin)) +(defun draw-map-old (win me) + "Draw a portion of the game map in an ncurses window" + (setf (croatoan:.color-pair win) '(:white :black)) + (croatoan:box win) + (croatoan:move win 1 1) + (let ((x0 (- (first me) (round (/ (croatoan:.width win) 4)))) + (y0 (- (second me) (halve (croatoan:.height win))))) + ;; NB. x0 and w are calculated differently to y0 and h because we insert + ;; a space after each character + (dotimes (h (1- (croatoan:.height win))) + (dotimes (w (- (halve (croatoan:.width win) 'floor) 2)) + ;;TODO replace `coord' with `query-server' + (let ((p (coord (+ w x0 3) (+ h y0 1)))) + (if (null p) (croatoan:add-char win #\space) + (if (and (= (first (patch-pos p)) (first me)) + (= (second (patch-pos p)) (second me))) + (progn (setf (croatoan:.color-pair win) + '(:white :black)) + (croatoan:add-char win #\@)) + (if (patch-occupant p) + (progn + (setf (croatoan:.color-pair win) + (list (.color (patch-occupant p)) + :black)) + (croatoan:add-char win + (.char (patch-occupant p)))) + (progn + (setf (croatoan:.color-pair win) + (list (biome-col (patch-biome p)) + :black)) + (croatoan:add-char win + (biome-char (patch-biome p))))))) + (croatoan:add-char win #\space))) + (croatoan:move win (1+ h) 1)) + (croatoan:refresh win))) + (defun draw-map (win) "Draw a portion of the game map in an ncurses window" ;;FIXME request each patch char singly from the server - doing it all @@ -176,10 +211,9 @@ (croatoan:add-string win "This is the player panel.") (croatoan:refresh win)) -(defun draw-place-panel (win me) +(defun draw-place-panel (win) "Draw a panel with information about the player's current location." - ;;TODO replace `describe-patch' with `query-server' - (let ((descr (break-lines (describe-patch me) + (let ((descr (break-lines (query-server "describe-patch") (- (croatoan:.width win) 2)))) (croatoan:clear win) (croatoan:box win) diff --git a/server/player.lisp b/server/player.lisp index 02c9655..1b1eb7b 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -34,6 +34,10 @@ ;;TODO ) +(defmethod move ((h human) dir) + ;;TODO + ) + ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/client/networking.lisp b/client/networking.lisp index bb61c87..7833f6a 100644 --- a/client/networking.lisp +++ b/client/networking.lisp @@ -39,7 +39,7 @@ ;; (eof (second raw-reply) (second raw-reply)) ;; (reply reply-line (sconc reply reply-line))) ;; ((or eof (null reply-line)) ;;FIXME - (logf 4 "CLIENT: received reply ~A" reply) + (logf 4 "CLIENT: received reply.") (if (search "ERROR" reply) (error reply) (read-from-string reply))))) diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 9b9a9fe..2ea5445 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -98,8 +98,7 @@ (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" - (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) - (me (list (round (/ width 4)) (halve height)))) + (let ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr)))) (croatoan:clear scr) (croatoan:refresh scr) (croatoan:with-windows ((mapwin :position '(0 0) @@ -117,7 +116,7 @@ (newswin :input-blocking *framerate* :position (list height 0) :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) + (update-ui mapwin playerwin placewin newswin) ;;TODO (croatoan:event-case (scr event) (#\q (disconnect) @@ -128,25 +127,61 @@ (terminate)) (return-from croatoan:event-case)) (#\n (croatoan:draw-menu (message-window))) - ;;FIXME change directions to single letters - (:up (query-server "move north") - (update-ui mapwin playerwin placewin newswin me)) - (:down (query-server "move south") - (update-ui mapwin playerwin placewin newswin me)) - (:left (query-server "move west") - (update-ui mapwin playerwin placewin newswin me)) - (:right (query-server "move east") - (update-ui mapwin playerwin placewin newswin me)) - ((nil) (update-ui mapwin playerwin placewin newswin me)) + ;;XXX How about moving diagonally? + (:up (query-server "move n") + (update-ui mapwin playerwin placewin newswin)) + (:down (query-server "move s") + (update-ui mapwin playerwin placewin newswin)) + (:left (query-server "move w") + (update-ui mapwin playerwin placewin newswin)) + (:right (query-server "move e") + (update-ui mapwin playerwin placewin newswin)) + ((nil) (update-ui mapwin playerwin placewin newswin)) (otherwise (notify (string event))))))) -(defun update-ui (mapwin playerwin placewin newswin me) +(defun update-ui (mapwin playerwin placewin newswin) "Update all four UI elements" (draw-map mapwin) (draw-player-panel playerwin) - (draw-place-panel placewin me) + (draw-place-panel placewin) (draw-news-panel newswin)) +(defun draw-map-old (win me) + "Draw a portion of the game map in an ncurses window" + (setf (croatoan:.color-pair win) '(:white :black)) + (croatoan:box win) + (croatoan:move win 1 1) + (let ((x0 (- (first me) (round (/ (croatoan:.width win) 4)))) + (y0 (- (second me) (halve (croatoan:.height win))))) + ;; NB. x0 and w are calculated differently to y0 and h because we insert + ;; a space after each character + (dotimes (h (1- (croatoan:.height win))) + (dotimes (w (- (halve (croatoan:.width win) 'floor) 2)) + ;;TODO replace `coord' with `query-server' + (let ((p (coord (+ w x0 3) (+ h y0 1)))) + (if (null p) (croatoan:add-char win #\space) + (if (and (= (first (patch-pos p)) (first me)) + (= (second (patch-pos p)) (second me))) + (progn (setf (croatoan:.color-pair win) + '(:white :black)) + (croatoan:add-char win #\@)) + (if (patch-occupant p) + (progn + (setf (croatoan:.color-pair win) + (list (.color (patch-occupant p)) + :black)) + (croatoan:add-char win + (.char (patch-occupant p)))) + (progn + (setf (croatoan:.color-pair win) + (list (biome-col (patch-biome p)) + :black)) + (croatoan:add-char win + (biome-char (patch-biome p))))))) + (croatoan:add-char win #\space))) + (croatoan:move win (1+ h) 1)) + (croatoan:refresh win))) + (defun draw-map (win) "Draw a portion of the game map in an ncurses window" ;;FIXME request each patch char singly from the server - doing it all @@ -176,10 +211,9 @@ (croatoan:add-string win "This is the player panel.") (croatoan:refresh win)) -(defun draw-place-panel (win me) +(defun draw-place-panel (win) "Draw a panel with information about the player's current location." - ;;TODO replace `describe-patch' with `query-server' - (let ((descr (break-lines (describe-patch me) + (let ((descr (break-lines (query-server "describe-patch") (- (croatoan:.width win) 2)))) (croatoan:clear win) (croatoan:box win) diff --git a/server/player.lisp b/server/player.lisp index 02c9655..1b1eb7b 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -34,6 +34,10 @@ ;;TODO ) +(defmethod move ((h human) dir) + ;;TODO + ) + ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/server/server.lisp b/server/server.lisp index e6ce205..505a3fe 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -12,6 +12,8 @@ ;; TODO save and load functions ;; XXX Will probably require `make-load-form-saving-slots' +;; TODO split this file up? remove the networking code... + ;;; PLAYER LIST (let ((players NIL)) @@ -45,6 +47,8 @@ ;;; WORLD OBJECT (let ((world NIL)) + ;;TODO we need to keep track of the current world map (i.e. patch chars and colours), + ;; otherwise player map requests will take way too long to serve (defun set-world (w) (setf world w)) (defun world-size () (length world)) @@ -146,6 +150,8 @@ (update i)))) ;;Update all items each player has ;;TODO + ;;Update the world map + ;;FIXME ;;Do cleanup work (when (zerop (rem uptime 20)) (cleanup-player-threads)) ;;Save the world and start over @@ -234,6 +240,8 @@ (defun get-map (swidth sheight) "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" + ;;TODO It's too inefficient to compile a new map for every player at every + ;; request. Keep a central map? ;;FIXME exhausts the heap?! -> only return one patch char at a time ;;XXX implement of "field of view" for each player? (let* ((plr (player-human (get-player (thread-player)))) @@ -261,9 +269,11 @@ ;; so the client has to perform an additional call to `read-from-string` (string-from-list (split-string (to-string submap) #\newline) ""))) -(defun describe-patch (coords) +(defun describe-patch (&optional (x 0) (y 0)) "Return a list of lines describing the patch at these coordinates." - (let ((p (coord (first coords) (second coords)))) + ;;FIXME throws an out of bounds error somewhere on a string + (let* ((plr (player-human (get-player (thread-player)))) + (p (coord (+ x (.x plr)) (+ y (.y plr))))) (list (string-upcase (biome-name (patch-biome p))) "" (format NIL "~A / ~A" (first (patch-pos p)) (second (patch-pos p))) "" (format NIL "The ground here is ~A." (biome-ground (patch-biome p))) @@ -277,8 +287,16 @@ (defun move-player (dir) "Move a player in the given direction" - ;;TODO - ) + (let ((plr (player-human (get-player (thread-player))))) + (cond ((equalp d "n") (move plr 'n)) + ((equalp d "ne") (move plr 'ne)) + ((equalp d "e") (move plr 'e)) + ((equalp d "se") (move plr 'se)) + ((equalp d "s") (move plr 's)) + ((equalp d "sw") (move plr 'sw)) + ((equalp d "w") (move plr 'w)) + ((equalp d "nw") (move plr 'nw)) + (T "ERROR: Invalid move direction ~S" dir)))) (defparameter *API* ;; An alist of API commands and their corresponding functions diff --git a/client/networking.lisp b/client/networking.lisp index bb61c87..7833f6a 100644 --- a/client/networking.lisp +++ b/client/networking.lisp @@ -39,7 +39,7 @@ ;; (eof (second raw-reply) (second raw-reply)) ;; (reply reply-line (sconc reply reply-line))) ;; ((or eof (null reply-line)) ;;FIXME - (logf 4 "CLIENT: received reply ~A" reply) + (logf 4 "CLIENT: received reply.") (if (search "ERROR" reply) (error reply) (read-from-string reply))))) diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 9b9a9fe..2ea5445 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -98,8 +98,7 @@ (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" - (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) - (me (list (round (/ width 4)) (halve height)))) + (let ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr)))) (croatoan:clear scr) (croatoan:refresh scr) (croatoan:with-windows ((mapwin :position '(0 0) @@ -117,7 +116,7 @@ (newswin :input-blocking *framerate* :position (list height 0) :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) + (update-ui mapwin playerwin placewin newswin) ;;TODO (croatoan:event-case (scr event) (#\q (disconnect) @@ -128,25 +127,61 @@ (terminate)) (return-from croatoan:event-case)) (#\n (croatoan:draw-menu (message-window))) - ;;FIXME change directions to single letters - (:up (query-server "move north") - (update-ui mapwin playerwin placewin newswin me)) - (:down (query-server "move south") - (update-ui mapwin playerwin placewin newswin me)) - (:left (query-server "move west") - (update-ui mapwin playerwin placewin newswin me)) - (:right (query-server "move east") - (update-ui mapwin playerwin placewin newswin me)) - ((nil) (update-ui mapwin playerwin placewin newswin me)) + ;;XXX How about moving diagonally? + (:up (query-server "move n") + (update-ui mapwin playerwin placewin newswin)) + (:down (query-server "move s") + (update-ui mapwin playerwin placewin newswin)) + (:left (query-server "move w") + (update-ui mapwin playerwin placewin newswin)) + (:right (query-server "move e") + (update-ui mapwin playerwin placewin newswin)) + ((nil) (update-ui mapwin playerwin placewin newswin)) (otherwise (notify (string event))))))) -(defun update-ui (mapwin playerwin placewin newswin me) +(defun update-ui (mapwin playerwin placewin newswin) "Update all four UI elements" (draw-map mapwin) (draw-player-panel playerwin) - (draw-place-panel placewin me) + (draw-place-panel placewin) (draw-news-panel newswin)) +(defun draw-map-old (win me) + "Draw a portion of the game map in an ncurses window" + (setf (croatoan:.color-pair win) '(:white :black)) + (croatoan:box win) + (croatoan:move win 1 1) + (let ((x0 (- (first me) (round (/ (croatoan:.width win) 4)))) + (y0 (- (second me) (halve (croatoan:.height win))))) + ;; NB. x0 and w are calculated differently to y0 and h because we insert + ;; a space after each character + (dotimes (h (1- (croatoan:.height win))) + (dotimes (w (- (halve (croatoan:.width win) 'floor) 2)) + ;;TODO replace `coord' with `query-server' + (let ((p (coord (+ w x0 3) (+ h y0 1)))) + (if (null p) (croatoan:add-char win #\space) + (if (and (= (first (patch-pos p)) (first me)) + (= (second (patch-pos p)) (second me))) + (progn (setf (croatoan:.color-pair win) + '(:white :black)) + (croatoan:add-char win #\@)) + (if (patch-occupant p) + (progn + (setf (croatoan:.color-pair win) + (list (.color (patch-occupant p)) + :black)) + (croatoan:add-char win + (.char (patch-occupant p)))) + (progn + (setf (croatoan:.color-pair win) + (list (biome-col (patch-biome p)) + :black)) + (croatoan:add-char win + (biome-char (patch-biome p))))))) + (croatoan:add-char win #\space))) + (croatoan:move win (1+ h) 1)) + (croatoan:refresh win))) + (defun draw-map (win) "Draw a portion of the game map in an ncurses window" ;;FIXME request each patch char singly from the server - doing it all @@ -176,10 +211,9 @@ (croatoan:add-string win "This is the player panel.") (croatoan:refresh win)) -(defun draw-place-panel (win me) +(defun draw-place-panel (win) "Draw a panel with information about the player's current location." - ;;TODO replace `describe-patch' with `query-server' - (let ((descr (break-lines (describe-patch me) + (let ((descr (break-lines (query-server "describe-patch") (- (croatoan:.width win) 2)))) (croatoan:clear win) (croatoan:box win) diff --git a/server/player.lisp b/server/player.lisp index 02c9655..1b1eb7b 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -34,6 +34,10 @@ ;;TODO ) +(defmethod move ((h human) dir) + ;;TODO + ) + ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/server/server.lisp b/server/server.lisp index e6ce205..505a3fe 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -12,6 +12,8 @@ ;; TODO save and load functions ;; XXX Will probably require `make-load-form-saving-slots' +;; TODO split this file up? remove the networking code... + ;;; PLAYER LIST (let ((players NIL)) @@ -45,6 +47,8 @@ ;;; WORLD OBJECT (let ((world NIL)) + ;;TODO we need to keep track of the current world map (i.e. patch chars and colours), + ;; otherwise player map requests will take way too long to serve (defun set-world (w) (setf world w)) (defun world-size () (length world)) @@ -146,6 +150,8 @@ (update i)))) ;;Update all items each player has ;;TODO + ;;Update the world map + ;;FIXME ;;Do cleanup work (when (zerop (rem uptime 20)) (cleanup-player-threads)) ;;Save the world and start over @@ -234,6 +240,8 @@ (defun get-map (swidth sheight) "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" + ;;TODO It's too inefficient to compile a new map for every player at every + ;; request. Keep a central map? ;;FIXME exhausts the heap?! -> only return one patch char at a time ;;XXX implement of "field of view" for each player? (let* ((plr (player-human (get-player (thread-player)))) @@ -261,9 +269,11 @@ ;; so the client has to perform an additional call to `read-from-string` (string-from-list (split-string (to-string submap) #\newline) ""))) -(defun describe-patch (coords) +(defun describe-patch (&optional (x 0) (y 0)) "Return a list of lines describing the patch at these coordinates." - (let ((p (coord (first coords) (second coords)))) + ;;FIXME throws an out of bounds error somewhere on a string + (let* ((plr (player-human (get-player (thread-player)))) + (p (coord (+ x (.x plr)) (+ y (.y plr))))) (list (string-upcase (biome-name (patch-biome p))) "" (format NIL "~A / ~A" (first (patch-pos p)) (second (patch-pos p))) "" (format NIL "The ground here is ~A." (biome-ground (patch-biome p))) @@ -277,8 +287,16 @@ (defun move-player (dir) "Move a player in the given direction" - ;;TODO - ) + (let ((plr (player-human (get-player (thread-player))))) + (cond ((equalp d "n") (move plr 'n)) + ((equalp d "ne") (move plr 'ne)) + ((equalp d "e") (move plr 'e)) + ((equalp d "se") (move plr 'se)) + ((equalp d "s") (move plr 's)) + ((equalp d "sw") (move plr 'sw)) + ((equalp d "w") (move plr 'w)) + ((equalp d "nw") (move plr 'nw)) + (T "ERROR: Invalid move direction ~S" dir)))) (defparameter *API* ;; An alist of API commands and their corresponding functions diff --git a/server/world.lisp b/server/world.lisp index 1133ca9..548fafc 100644 --- a/server/world.lisp +++ b/server/world.lisp @@ -44,7 +44,7 @@ (defun init-matrix (size) "Create a square matrix of empty patches" - ;;TODO change this to arrays for performance + ;;FIXME 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)