diff --git a/naledi.lisp b/naledi.lisp index 00d0114..7528d60 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -136,46 +136,26 @@ (defun update-ui (mapwin playerwin placewin newswin me) "Update all four UI elements" - (draw-map mapwin me) + (draw-map mapwin) (draw-player-panel playerwin) (draw-place-panel placewin me) (draw-news-panel newswin)) -(defun draw-map (win me) +(defun draw-map (win) "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))))))) + (let* ((map-width (- (halve (croatoan:.width win) 'floor) 2)) + (map-height (1- (croatoan:.height win))) + (submap (query-server "map" map-width map-height))) + (dotimes (h map-height) + (dotimes (w map-width) + (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) + (croatoan:add-char win pch :color-pair (list pcol black)) (croatoan:add-char win #\space))) - (croatoan:move win (1+ h) 1)) - (croatoan:refresh win))) + (croatoan:move win (1+ h) 1))) + (croatoan:refresh win)) (defun draw-player-panel (win) "Draw a panel with information about the player character." diff --git a/naledi.lisp b/naledi.lisp index 00d0114..7528d60 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -136,46 +136,26 @@ (defun update-ui (mapwin playerwin placewin newswin me) "Update all four UI elements" - (draw-map mapwin me) + (draw-map mapwin) (draw-player-panel playerwin) (draw-place-panel placewin me) (draw-news-panel newswin)) -(defun draw-map (win me) +(defun draw-map (win) "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))))))) + (let* ((map-width (- (halve (croatoan:.width win) 'floor) 2)) + (map-height (1- (croatoan:.height win))) + (submap (query-server "map" map-width map-height))) + (dotimes (h map-height) + (dotimes (w map-width) + (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) + (croatoan:add-char win pch :color-pair (list pcol black)) (croatoan:add-char win #\space))) - (croatoan:move win (1+ h) 1)) - (croatoan:refresh win))) + (croatoan:move win (1+ h) 1))) + (croatoan:refresh win)) (defun draw-player-panel (win) "Draw a panel with information about the player character." diff --git a/src/server.lisp b/src/server.lisp index 7982dac..f7472ae 100644 --- a/src/server.lisp +++ b/src/server.lisp @@ -208,6 +208,25 @@ (add-player name passwd) (login name passwd)))) +(defun get-map (width height) + "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" + (let* ((plr (player-human (get-player (thread-name (current-thread))))) + (x0 (- (.x plr) (halve width))) + (y0 (- (.y plr) (halve height))) + (submap (make-array (list width height 2)))) + (dotimes (h height) + (dotimes (w width) + (let ((p (coord (+ w x0 1) (+ h y0 1))) + (next-char #\space) (next-col :black)) + (if (and p (patch-occupant p)) + (setf next-char (.char (patch-occupant p)) + next-col (.color (patch-occupant p))) + (when p (setf next-char (biome-char (patch-biome p)) + next-col (biome-col (patch-biome p))))) + (setf (aref submap w h 0) next-char + (aref submap w h 1) next-col)))) + submap)) + (defun describe-patch (coords) "Return a list of lines describing the patch at these coordinates." (let ((p (coord (first coords) (second coords))))