Browse Source

Successfully split everything "mostly" into it's own files

Simon Watson 1 year ago
parent
commit
2daedebc2a
8 changed files with 75 additions and 69 deletions
  1. 4 4
      README.md
  2. 3 0
      ascii-assets.lisp
  3. 0 6
      clwars.lisp
  4. 23 20
      economy.lisp
  5. 9 39
      game.lisp
  6. 8 0
      sector.lisp
  7. 27 0
      ship.lisp
  8. 1 0
      structs.lisp

+ 4 - 4
README.md

@@ -44,9 +44,9 @@ NOTE: This 'game' is just a playground for me to play with Lisp. It is not a ref
 - Money/Economy/Items
   - TODO
     - [X] Basic buy/sell mechanics
-      - [ ] Overhaul buy/sell interface for archeotech specific information
-	- [ ] Random $x*$x ASCII image to represent archeotech
-    - [ ] Variable economy between sectors ('random' prices)
+    - [ ] Overhaul buy/sell interface for archeotech specific information
+    - [ ] Random $x*$x ASCII image to represent archeotech
+    - [X] Variable economy between sectors ('random' prices)
     - [ ] Define how archeotech works (random buffs/characteristics)
       - [ ] Archeotech display menu
   - Notes
@@ -55,7 +55,7 @@ NOTE: This 'game' is just a playground for me to play with Lisp. It is not a ref
     - Can trade archeotech (AT has characteristics that may be desireable to different planetary systems)
 - Crew Systems
   - TODO:
-    - [ ] Crew consumes grew on some regular cadence (per action/jump/etc)
+    - [ ] Crew consumes gruel on some regular cadence (per action/jump/etc)
     - [ ] Crew will consume spice (if available)
       - Spice increases moral but can be destabilizing to sanity
     - [ ] Implementation of crew member buff charateristics

+ 3 - 0
ascii-assets.lisp

@@ -33,3 +33,6 @@
               ▔     ▕▅▅▅▆████▛▔▔▔
                        ╺▛▀▔▔
 ")
+
+;; Used for archeotech art generation
+(defvar *ascii-chars* "█*|")

+ 0 - 6
clwars.lisp

@@ -1,10 +1,4 @@
-(load "~/Repos/clwars/ascii-assets.lisp")
-(load "~/Repos/clwars/structs.lisp")
 (load "~/Repos/clwars/game.lisp")
-(load "~/Repos/clwars/plumbing.lisp")
-
-;;; TODO use quicklisp
-(load "~/quicklisp/local-projects/lazy/lazy.lisp") ; Not needed, using for fun/learning
 
 (defun reload()
   (load "~/Repos/clwars/clwars.lisp"))

+ 23 - 20
economy.lisp

@@ -3,17 +3,14 @@
 				       (cons 'b 'buy-menu)
 				       (cons '2 'sell-menu)
 				       (cons 's 'sell-menu)
-				       (cons '3 'display-prices)
-				       (cons 'd 'display-prices)
-				       (cons '4 'top-level-game-menu)
+				       (cons '3 'top-level-game-menu)
 				       (cons 'r 'top-level-game-menu)))
 
 (defvar *trade-menu-options-display* "
 Actions:
 1 | Buy | b
 2 | Sell | s
-3 | Display Prices | d
-4 | Return to top level | r
+3 | Return to top level | r
 ")
 
 (defun buy-transaction (resource quantity)
@@ -118,14 +115,15 @@ Actions:
 
 ;;; This is kept around in case I need it. I'm not sure
 ;;; this is any less 'bad' than how buy/sell-transaction
-;;; currently work
+;;; currently works
 (defmacro dynamic-slot-access (predicate slotname accessor)
   "Given a predicate where the predicate is a struct slot accessor like 'market-price-of-',
    a slotname like 'petrofuel', and a struct location, return the result of the slot accessor function"
   `(funcall ,(symbol-function (find-symbol (string-upcase (concatenate 'string predicate slotname)))) ,accessor))
 
-(defmacro dynamic-slot-setting (predicate slotname accessor value)
-  `(setf ,(funcall (symbol-function (find-symbol (string-upcase (concatenate 'string predicate slotname)))) accessor) ,value))
+;; Can't get this to work how I expect, need to experiment morex
+;; (defmacro dynamic-slot-setting (predicate slotname accessor value)
+;;   `(setf (funcall (symbol-function (find-symbol (string-upcase (concatenate 'string predicate slotname)))) accessor) ,value))
 
 (defun display-prices ()
   (let ((market-list (list
@@ -139,6 +137,8 @@ Actions:
     (format-table T market-list :column-label '("Resource" "Cost"))))
 
 (defun trade-menu ()
+  (display-prices)
+  (display-inventory)
   (format t *trade-menu-options-display*)
   (let ((option (prompt-read "Enter an option: ")))
     (format t "~%")
@@ -148,21 +148,24 @@ Actions:
 ;;; END TRADING ;;;
 
 ;;; MARKET ;;;
-(defun range (start end)
-  "Basic function to generate a list that
-   contains a range of ints"
-  (loop for i from start below end collect i))
 
 ;;; Use this parameter when randomizing market prices. Used to lookup how
 ;;; 'random' prices should really be."
 (defparameter *market-price-bounds*
-  (list (cons 'petrofuel (range 10 41))
-	(cons 'ammo (range 5 31))
-	(cons 'archeotech (range 750 2001))
-	(cons 'spice (range 5 101))
-	(cons 'gruel (range 1 16))))
+  (list (cons 'petrofuel '(10 41))
+	(cons 'ammo '(5 31))
+	(cons 'archeotech '(750 2001))
+	(cons 'spice '(5 101))
+	(cons 'gruel '(1 16))))
 
 (defun randomize-market-prices (market)
-  (loop for resource in *market-price-bounds*
-	do (progn
-	     (
+  (let ((get-random-val (lambda (resource-arg)
+			  (+ (cadr resource-arg)
+			     (random (caddr resource-arg))))))
+    (loop for resource in *market-price-bounds*
+	do (case (car resource)
+	     (gruel (setf (market-price-of-gruel market) (funcall get-random-val resource)))
+	     (ammo (setf (market-price-of-ammo market) (funcall get-random-val resource)))
+	     (spice (setf (market-price-of-spice market) (funcall get-random-val resource)))
+	     (archeotech (setf (market-price-of-archeotech market) (funcall get-random-val resource)))
+	     (petrofuel (setf (market-price-of-petrofuel market) (funcall get-random-val resource)))))))

+ 9 - 39
game.lisp

@@ -1,5 +1,10 @@
 (load "~/Repos/clwars/economy.lisp")
 (load "~/Repos/clwars/plumbing.lisp")
+(load "~/Repos/clwars/sector.lisp")
+(load "~/Repos/clwars/ship.lisp")
+(load "~/Repos/clwars/ascii-assets.lisp")
+(load "~/Repos/clwars/structs.lisp")
+
 
 (defvar *player-ship*)
 (defvar *sector*)
@@ -31,6 +36,7 @@
 								    :ammo-cost 3))
 					:credits 1000
 					:crew (make-crew :sanity-val 100
+							 :moral-val 100
 							 :crew-members (loop for x in '(1 2 3 4)
 									     collect (make-uniq-crew-mem :name (make-crew-mem-name))))
 					:inventory (make-player-inventory :petrofuel 20
@@ -62,48 +68,12 @@ Actions:
 2 | Ship info | si
 3 | Trade | t
 4 | Scout | s
-5 | Leave | l
+5 | Leave sector | l
 ")
 
-(defun sector-info ()
-  (format t "Called sector-info"))
-
-;;; SHIP INFO ;;;
-(defun display-crew ()
-  (let* ((crew-struct (crew-crew-members (player-ship-crew *player-ship*)))
-	 (crew-names 
-	   (loop for member in crew-struct
-		 collect (list (uniq-crew-mem-name member) NIL NIL))))
-    (format T "~%CREW DETAILS~%~%")
-    (format-table T (list (list (crew-sanity-val (player-ship-crew *player-ship*)))) :column-label '("Sanity"))
-    (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*))))))
-    (format T "~%INVENTORY~%")
-    (format-table T inventory-list :column-label '("Resource" "Amount"))))
-
-
-(defun ship-info ()
-  (display-crew)
-  (display-inventory))
-;;; SHIP INFO END ;;;
-
-(defun scout ()
-  (format t "Called scout"))
-(defun leave ()
-  (format t "Called leave"))
-
 ;; Use lookup table to handle top level loop arguments
 ;; See: https://dnaeon.github.io/common-lisp-lookup-tables-alists-and-plists/
-(defparameter *opt-lookup* (list (cons 'sector-info 'sector-info)
+(defparameter *top-level-opt-lookup* (list (cons 'sector-info 'sector-info)
 				 (cons '1 'sector-info)
 				 (cons 'sei 'sector-info)
 				 (cons 'ship-info 'ship-info)
@@ -124,6 +94,6 @@ Actions:
   (format t *top-level-options-display*)
   (let ((option (prompt-read "Enter an option: ")))
     (format t "~%")
-    (handle-opt (read-from-string option) *opt-lookup*))
+    (handle-opt (read-from-string option) *top-level-opt-lookup*))
   (top-level-game-menu))
 	  

+ 8 - 0
sector.lisp

@@ -0,0 +1,8 @@
+(defun sector-info ()
+  (format t "Called sector-info"))
+
+(defun scout ()
+  (format t "Called scout"))
+
+(defun leave ()
+  (format t "Called leave"))

+ 27 - 0
ship.lisp

@@ -0,0 +1,27 @@
+;;; SHIP INFO ;;;
+(defun display-crew ()
+  (let* ((crew-struct (crew-crew-members (player-ship-crew *player-ship*)))
+	 (crew-names 
+	   (loop for member in crew-struct
+		 collect (list (uniq-crew-mem-name member) NIL NIL))))
+    (format T "~%CREW DETAILS~%~%")
+    (format-table T (list (list (crew-sanity-val (player-ship-crew *player-ship*)))) :column-label '("Sanity"))
+    (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*))))))
+    (format T "~%INVENTORY~%")
+    (format-table T inventory-list :column-label '("Resource" "Amount"))))
+
+
+(defun ship-info ()
+  (display-crew)
+  (display-inventory))
+;;; SHIP INFO END ;;;

+ 1 - 0
structs.lisp

@@ -18,6 +18,7 @@
 
 (defstruct crew
   sanity-val ; Max 100
+  moral-val
   crew-members) ; List of *uniq-crew-mem*
 
 ;;; Unique crew member that can provide an abstract buff