Browse Source

WIP move to CLOS

WIP, moving everything over to CLOS
Simon Watson 1 year ago
parent
commit
69897bf195
3 changed files with 154 additions and 83 deletions
  1. 28 34
      game.lisp
  2. 1 1
      ship.lisp
  3. 125 48
      structs.lisp

+ 28 - 34
game.lisp

@@ -10,40 +10,34 @@
 (defvar *sector*)
 	
 (defun init-game-state ()
-  (setq *sector* (make-sector :market (make-market :price-of-petrofuel 20
-						   :price-of-ammo 10
-						   :price-of-archeotech 1000
-						   :price-of-spice 50
-						   :price-of-gruel 5)
-			      :hazards NIL
-			      :boons NIL))
-  (setq *player-ship* (make-player-ship :armor-val 10
-					:rep-shield-val 10
-					:warp-drive (list 1 5)
-					:reactor-str 1
-					:warp-field 1
-					:weapons (list (make-weapon :name "Plamsa"
-								    :shield-dmg 3
-								    :hull-dmg 3
-								    :ammo-cost 5)
-						       (make-weapon :name "Mega Bolter"
-								    :shield-dmg 1
-								    :hull-dmg 2
-								    :ammo-cost 1)
-						       (make-weapon :name "Beam"
-								    :shield-dmg 1
-								    :hull-dmg 3
-								    :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
-									  :gruel 20
-									  :spice 0
-									  :ammo 20
-									  :archeotech 0))))
+  (setq *sector* (make-instance 'sector :market (make-instance 'market)))
+  
+  (setq *player-ship* (make-instance 'player-ship :weapons (list (make-instance 'weapon
+										:name "Plamsa"
+										:shield-dmg 3
+										:hull-dmg 3
+										:ammo-cost 5)
+								 (make-instance 'weapon
+										:name "Mega Bolter"
+										:shield-dmg 1
+										:hull-dmg 2
+										:ammo-cost 1)
+								 (make-instance 'weapon
+										:name "Beam"
+										:shield-dmg 1
+										:hull-dmg 3
+										:ammo-cost 3))
+						  :crew (make-instance 'crew
+								       :sanity-val 100
+								       :moral-val 100
+								       :crew-members (loop for x in '(1 2 3 4)
+											   collect (make-instance 'uniq-crew-mem :name (make-crew-mem-name *name-prefixes* *name-values*))))
+						  :inventory (make-instance 'player-inventory
+									    :petrofuel 20
+									    :gruel 20
+									    :spice 0
+									    :ammo 20
+									    :archeotech 0))))
 
 
 (defun new-game ()

+ 1 - 1
ship.lisp

@@ -1,6 +1,6 @@
 ;;; SHIP INFO ;;;
 (defun display-crew ()
-  (let* ((crew-struct (crew-crew-members (player-ship-crew *player-ship*)))
+  (let* ((crew (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))))

+ 125 - 48
structs.lisp

@@ -1,40 +1,83 @@
-(defstruct player-ship
-  armor-val
-  rep-shield-val
-  warp-drive ; tuple, first ele is power state (0,1), second is fuel cost 
-  reactor-str ; 0 - low power, 1 - full power, 2 - overdrive
-  warp-field ; 0 - low power, 1 - full power
-  weapons
-  credits
-  crew
-  inventory)
+(defclass player-ship ()
+  ((armor-val
+    :initarg :armor-val
+    :accessor armor-val
+    :initform 10)
+   (rep-shield-val
+    :initarg :rep-shield-val
+    :accessor rep-shield-val
+    :initform 10)
+   (warp-drive-power ; 0 off, 1 on
+    :initarg :warp-drive-power
+    :accessor warp-drive-power
+    :initform 1)
+   (reactor-str ; 0 - low power, 1 - full power, 2 - overdrive
+    :initarg :reactor-str
+    :accessor reactor-str
+    :initform 1)
+   (warp-field ; 0 - low power, 1 - full power
+    :initarg :warp-field
+    :accessor warp-field
+    :initform 1)
+   (weapons
+    :initarg :weapons
+    :accessor weapons)
+   (credits
+    :initarg :credits
+    :accessor credits
+    :initform 1000)
+   (crew
+    :initarg :crew
+    :accessor crew)
+   (inventory
+    :initarg :inventory
+    :accessor inventory)))
 
-(defstruct player-inventory
-  petrofuel
-  gruel
-  spice
-  ammo
-  archeotech)
+(defclass player-inventory ()
+    ((petrofuel
+      :initarg :petrofuel
+      :accessor petrofuel
+      :initform 20)
+     (gruel
+      :initarg :gruel
+      :accessor gruel
+      :initform 20)
+     (spice
+      :initarg :spice
+      :accessor spice
+      :initform 0)
+     (ammo
+      :initarg :ammo
+      :accessor ammo
+      :initform 20)
+     (archeotech
+      :initarg :archeotech
+      :accessor archeotech
+      :initform 0)))
 
-(defstruct crew
-  sanity-val ; Max 100
-  moral-val
-  crew-members) ; List of *uniq-crew-mem*
+(defclass crew ()
+  ((sanity-val ; Max 100
+   :initarg :sanity-val
+   :accessor sanity-val
+   :initform 100)
+   (moral-val
+    :initarg :moral-val
+    :accessor moral-val
+    :initform 100)
+   (crew-members
+    :initarg :crew-members  ; List of *uniq-crew-mem*
+    :accessor crew-members)))
 
 ;;; Unique crew member that can provide an abstract buff
 ;;; or nerf to some internal game system
-(defstruct uniq-crew-mem
-  name
-  armor-buff
-  rep-shield-buff
-  sanity-buff
-  warp-drive-buff
-  reactor-str-buff
-  warp-field-buff
-  plasma-buff
-  expl-buff
-  beam-buff
-  credit-buff)
+(defclass uniq-crew-mem ()
+  ((name
+    :initarg :name
+    :accessor name)
+   (buff
+    :initarg :buff
+    :accessor buff
+    :initform NIL)))
 
 ;; Crew name generators
 (defvar *name-prefixes*
@@ -82,27 +125,61 @@
 	"Quintus"
 	"Decimus"))
   
-(defun make-crew-mem-name ()
+(defun make-crew-mem-name (name-prefixes name-values)
+  "Expects a list of strings to use as prefixes for a name, and a list
+   of possible names"
   (let ((name (nth (random (length *name-values*)) *name-values*))
 	(prefix (nth (random (length *name-prefixes*)) *name-prefixes*)))
     (concatenate 'string prefix " " name)))
 
-(defstruct weapon
-  name
-  shield-dmg
-  hull-dmg
-  ammo-cost)
+(defclass weapon ()
+  ((name
+    :initarg :name
+    :accessor name)
+   (shield-dmg
+    :initarg :shield-dmg
+    :accessor sheild-dmg)
+   (hull-dmg
+    :initarg :hull-dmg
+    :accessor hull-dmg)
+   (ammo-cost
+    :initarg :ammo-cost
+    :accessor ammo-cost)))
+
+(defclass market ()
+    ((price-of-petrofuel
+      :initarg :price-of-petrofuel
+      :accessor price-of-petrofuel
+      :initform 10)
+     (price-of-gruel
+      :initarg :gruel
+      :accessor price-of-gruel
+      :initform 5)
+     (price-of-spice
+      :initarg :spice
+      :accessor price-of-spice
+      :initform 100)
+     (price-of-ammo
+      :initarg :ammo
+      :accessor price-of-ammo
+      :initform 20)
+     (price-of-archeotech
+      :initarg :archeotech
+      :accessor price-of-archeotech
+      :initform 2000)))
 
-(defstruct market
-  price-of-petrofuel
-  price-of-ammo
-  price-of-archeotech
-  price-of-spice
-  price-of-gruel)
 
 ;; This gets created when travelling to a
 ;; new sector
-(defstruct sector
-  market ; contains market struct
-  hazards ; Contains hazard for sector
-  boons) ; Contains boon for sector
+(defclass sector ()
+  ((market
+    :initarg :market
+    :accessor market)
+   (hazards
+    :initarg :hazards
+    :accessor hazards
+    :initform NIL)
+   (boons
+    :initarg :boons
+    :accessor boons
+    :initform NIL)))