diff --git a/naledi.lisp b/naledi.lisp index 5c5f380..332c7ec 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -128,7 +128,8 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." (let* ((p (coord (first me) (second me))) - (descr (when p (describe-patch p)))) + (descr (when p (break-lines (describe-patch p) + (- (.width win) 2))))) (clear win) (box win) (move win 1 1) @@ -158,13 +159,14 @@ (make-instance 'dialog-window :input-blocking t :items (mapcar - #'(lambda (n) (string-from-list (list "*" n) " ")) + #'(lambda (n) (break-lines + (string-from-list (list "*" n)) 50) news) :center t :border t :layout nil :title "Game messages" - :max-item-length 50))) + :max-item-length 50)))) ;:scrolled-layout '(10 1) ;; :message-height 2 ;; :message-text "Press b to go back." diff --git a/naledi.lisp b/naledi.lisp index 5c5f380..332c7ec 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -128,7 +128,8 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." (let* ((p (coord (first me) (second me))) - (descr (when p (describe-patch p)))) + (descr (when p (break-lines (describe-patch p) + (- (.width win) 2))))) (clear win) (box win) (move win 1 1) @@ -158,13 +159,14 @@ (make-instance 'dialog-window :input-blocking t :items (mapcar - #'(lambda (n) (string-from-list (list "*" n) " ")) + #'(lambda (n) (break-lines + (string-from-list (list "*" n)) 50) news) :center t :border t :layout nil :title "Game messages" - :max-item-length 50))) + :max-item-length 50)))) ;:scrolled-layout '(10 1) ;; :message-height 2 ;; :message-text "Press b to go back." diff --git a/util.lisp b/util.lisp index d7bb60d..a54ce64 100644 --- a/util.lisp +++ b/util.lisp @@ -114,7 +114,7 @@ ;; TODO change &optional to &key (and figure out why the heck that doesn't ;; work - clisp bug?), add null-filler keyword -(defun string-from-list (lst &optional (separator " - ")) +(defun string-from-list (lst &optional (separator #\space)) "Put all elements of lst into a single string, separated by the separator" (cond ((null lst) "") ((= (length lst) 1) (to-string (car lst))) @@ -161,6 +161,19 @@ (if (member (char noun 0) '(#\a #\e #\i #\o #\u)) "an" "a") noun)) +(defun break-lines (lines width &optional (indent "")) + "Take a list of lines and break any that are too long." + (do* ((ls lines (cdr ls)) (l (car ls) (car ls)) (result NIL)) + ((null ls) result) + (if (<= (length l) width) + (setf result (append result (list l))) + (progn + (setf result + (append result (list (first (cut-string l width))))) + (setf ls (cons NIL (cons (concatenate 'string (to-string indent) + (second (cut-string l width))) + (cdr ls)))))))) + (defun extract-elements (str) "Extract all Lisp elements (strings, symbols, numbers, etc.) from str" (multiple-value-bind (next-element i) (read-from-string str nil) diff --git a/naledi.lisp b/naledi.lisp index 5c5f380..332c7ec 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -128,7 +128,8 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." (let* ((p (coord (first me) (second me))) - (descr (when p (describe-patch p)))) + (descr (when p (break-lines (describe-patch p) + (- (.width win) 2))))) (clear win) (box win) (move win 1 1) @@ -158,13 +159,14 @@ (make-instance 'dialog-window :input-blocking t :items (mapcar - #'(lambda (n) (string-from-list (list "*" n) " ")) + #'(lambda (n) (break-lines + (string-from-list (list "*" n)) 50) news) :center t :border t :layout nil :title "Game messages" - :max-item-length 50))) + :max-item-length 50)))) ;:scrolled-layout '(10 1) ;; :message-height 2 ;; :message-text "Press b to go back." diff --git a/util.lisp b/util.lisp index d7bb60d..a54ce64 100644 --- a/util.lisp +++ b/util.lisp @@ -114,7 +114,7 @@ ;; TODO change &optional to &key (and figure out why the heck that doesn't ;; work - clisp bug?), add null-filler keyword -(defun string-from-list (lst &optional (separator " - ")) +(defun string-from-list (lst &optional (separator #\space)) "Put all elements of lst into a single string, separated by the separator" (cond ((null lst) "") ((= (length lst) 1) (to-string (car lst))) @@ -161,6 +161,19 @@ (if (member (char noun 0) '(#\a #\e #\i #\o #\u)) "an" "a") noun)) +(defun break-lines (lines width &optional (indent "")) + "Take a list of lines and break any that are too long." + (do* ((ls lines (cdr ls)) (l (car ls) (car ls)) (result NIL)) + ((null ls) result) + (if (<= (length l) width) + (setf result (append result (list l))) + (progn + (setf result + (append result (list (first (cut-string l width))))) + (setf ls (cons NIL (cons (concatenate 'string (to-string indent) + (second (cut-string l width))) + (cdr ls)))))))) + (defun extract-elements (str) "Extract all Lisp elements (strings, symbols, numbers, etc.) from str" (multiple-value-bind (next-element i) (read-from-string str nil) diff --git a/world.lisp b/world.lisp index d46cdb6..8d788db 100644 --- a/world.lisp +++ b/world.lisp @@ -136,7 +136,7 @@ seeds))) (debugging "~&~S" seeds) ;;For each patch, calculate the closest seed and set to that biome - (dotimes (x wsize) + (dotimes (x wsize seeds) (dotimes (y wsize) (let ((p (coord x y)) (b (third (closest-coords (list x y) seeds T)))) @@ -152,16 +152,18 @@ (setf (patch-biome patch) (get-biome 'stream)) (setf (patch-occupant patch) NIL))) -;;TODO create animal herds +(defun generate-herds (biome-seeds) + ;;TODO + ) (defun create-world (size) (set-world (init-matrix size)) ;;XXX magic numbers - (generate-biomes 10) + (generate-herds (generate-biomes 10)) (dotimes (s (round (/ (expt size 2) 2000))) (generate-stream (random size) (random size)))) -(defun describe-patch (p) ;;FIXME needs a line width parameter +(defun describe-patch (p) "Return a list of lines describing this patch." (list (string-upcase (biome-name (patch-biome p))) "" (format NIL "~A / ~A" (first (patch-pos p)) (second (patch-pos p))) ""