소스 검색

More on the CLOS conversion

Quite a bit of work figuring out how I wanted result-slots to work.

In short, it's sorted, and mainly just progress converting everything
to CLOS.
spesk 1 년 전
부모
커밋
9400cbc309
5개의 변경된 파일15개의 추가작업 그리고 18개의 파일을 삭제
  1. 1 0
      clwars.lisp
  2. 3 3
      game.lisp
  3. 1 1
      plumbing.lisp
  4. 8 11
      ship.lisp
  5. 2 3
      structs.lisp

+ 1 - 0
clwars.lisp

@@ -1,3 +1,4 @@
+(ql:quickload "closer-mop")
 (load "~/Repos/clwars/game.lisp")
 
 (defun reload()

+ 3 - 3
game.lisp

@@ -70,9 +70,9 @@ Actions:
 (defparameter *top-level-opt-lookup* (list (cons 'sector-info 'sector-info)
 				 (cons '1 'sector-info)
 				 (cons 'sei 'sector-info)
-				 (cons 'ship-info 'ship-info)
-				 (cons 'si 'ship-info)
-				 (cons '2 'ship-info)
+				 (cons 'ship-info (cons 'ship-info *player-ship*))
+				 (cons 'si (cons 'ship-info *player-ship*))
+				 (cons '2 (cons 'ship-info *player-ship*))
 				 (cons 'trade 'trade-menu)
 				 (cons 't 'trade-menu)
 				 (cons '3 'trade-menu)

+ 1 - 1
plumbing.lisp

@@ -62,4 +62,4 @@
   "When given a string and a list 'lookup table' call the
    function associated with the opt used"
   (let ((handler (cdr (assoc opt lookup-table))))
-    (if handler (funcall handler) (format t "Invalid opt~%~%"))))
+    (if handler (funcall (car handler) (cdr handler)) (format t "Invalid opt~%~%"))))

+ 8 - 11
ship.lisp

@@ -8,19 +8,16 @@
     (format T "~%")
     (format-table T crew-names :column-label '("Name" "Buff" "Buff Amount"))))
 
-(defun display-inventory ()
-  (let ((inventory-list (list
-			 (list "Credits" (player-ship-credits *player-ship*))
-			 (list "Petrofuel" (player-inventory-petrofuel (player-ship-inventory *player-ship*)))
-			 (list "Gruel" (player-inventory-gruel (player-ship-inventory *player-ship*)))
-			 (list "Spice" (player-inventory-spice (player-ship-inventory *player-ship*)))
-			 (list "Ammo" (player-inventory-ammo (player-ship-inventory *player-ship*)))
-			 (list "Archeotech" (player-inventory-archeotech (player-ship-inventory *player-ship*))))))
+(defun display-inventory (player-ship-obj)
+  (let* ((inventory (inventory player-ship-obj))
+	(inventory-list (loop for slot in (return-slots inventory)
+			     collect (list
+				      slot (slot-value inventory slot))))) 
     (format T "~%INVENTORY~%")
     (format-table T inventory-list :column-label '("Resource" "Amount"))))
 
 
-(defun ship-info ()
-  (display-crew)
-  (display-inventory))
+(defun ship-info (player-ship-obj)
+  (display-crew player-ship-obj)
+  (display-inventory player-ship-obj))
 ;;; SHIP INFO END ;;;

+ 2 - 3
structs.lisp

@@ -69,9 +69,8 @@
     :accessor crew-members)))
 
 ;; "Given an object, return the names of it's slots"
-(defgeneric return-slots (obj))
-(defmethod return-slots ((market market))
-  (map 'list #'closer-mop:slot-definition-name (closer-mop:class-slots (class-of market))))
+(defun return-slots (obj)
+  (map 'list #'closer-mop:slot-definition-name (closer-mop:class-slots (class-of obj))))
 
 ;;; Unique crew member that can provide an abstract buff
 ;;; or nerf to some internal game system