Procházet zdrojové kódy

WIP -- more features

Fleshing out the combat system more. Still much more work to do.
Simon Watson před 1 rokem
rodič
revize
f60ce10808
8 změnil soubory, kde provedl 148 přidání a 24 odebrání
  1. 8 1
      README.md
  2. 1 1
      clwars.asd
  3. 46 9
      combat.lisp
  4. 2 9
      crew.lisp
  5. 2 2
      game.lisp
  6. 15 1
      plumbing.lisp
  7. 63 0
      ship.lisp
  8. 11 1
      structs.lisp

+ 8 - 1
README.md

@@ -21,7 +21,6 @@ NOTE: This 'game' is just a playground for me to play with Lisp. It is not a ref
 - Ship Systems/Combat
   - TODO:
     - [ ] Basic combat system, perhaps like battleship
-    - [ ] Implemention of crew buffs
     - [ ] Basic 'move to new sector' system
   - Notes:
     - Hull Integrity
@@ -60,6 +59,14 @@ 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:
+    - [-] Implemention of crew buffs
+      - [X] Add buff objects
+      - [ ] Resolve buff integration into various systems
+	- [ ] Food
+	- [ ] Moral
+	- [ ] Weapons
+	  - [ ] These should be updated on insertion into crew?
+	- [ ] Shields
     - [ ] 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

+ 1 - 1
clwars.asd

@@ -3,11 +3,11 @@
   :depends-on (:closer-mop)
   :components ((:file "plumbing")
                (:file "structs")
-               (:file "clwars")
 	       (:file "crew")
 	       (:file "economy")
 	       (:file "sector")
 	       (:file "ship")
 	       (:file "combat")
 	       (:file "ascii-assets")
+               (:file "clwars")
 	       (:file "game")))

+ 46 - 9
combat.lisp

@@ -16,13 +16,50 @@
 (defun combat-loop (sector)
   "The main loop responsbile for resolving combat situations")
 
-(defun calculate-damage (attacker-obj target-obj attacker-weapon)
-  "Calculate damage attacker will do given attacker stats, target stats,
-   and weapon stats"
-  (let ((target-defense-value (+ (rep-shield-val target-obi) (armor-val target-obj))))))
+;; Select weapon
+;; Determine if hit (% chance?)
+;; If hit resolve shield
+;; -- IF Shields down (ie shield damage causes target shield value to be 0)
+;; -- Apply hull damage
+;; ELSE
+;; -- Decrement shield value per value of shield dmg
 
-(defun ship-attack (attacker-obj target-obj attacker-weapon)
-  "Given a ship thats attacking, a target, and the attackers chosen weapon
-   resolve the combat by calculating shield/hull damage and resolving resources."
-  (let ((calculated-damage- ; This value needs to resolve all buffs and debuffs
-	  NIL))))
+(defun calculate-shield-damage (attacker-obj target-obj attacker-weapon)
+  "Given a target and a weapon, return a value that the
+   targets shield value should now be set as"
+  (let ((new-shield-value (- (rep-shield-val target-obj) (shield-dmg attacker-weapon))))
+    (setf (ammo (inventory attacker-obj)) (- (ammo (inventory attacker-obj)) (ammo-cost attacker-weapon)))
+    (if (>= 0 new-shield-value)
+	(return-from calculate-shield-damage 0)
+	(return-from calculate-shield-damage new-shield-value))))
+
+(defun calculate-hull-damage (attacker-obj target-obj attacker-weapon)
+  "Given a target and a weapon, return a value that the
+   targets hull value should now be set as"
+  (let ((new-hull-value (- (armor-val target-obj) (hull-dmg attacker-weapon))))
+    (setf (ammo (inventory attacker-obj)) (- (ammo (inventory attacker-obj)) (ammo-cost attacker-weapon)))
+    (if (>= 0 new-hull-value)
+	(return-from calculate-hull-damage 0)
+	(return-from calculate-hull-damage new-hull-value))))
+
+(defun player-ship-attack (player-ship-obj target-obj attacker-weapon)
+  "Given a target and the attackers chosen weapon resolve the combat by
+   calculating shield/hull damage and resolving resources. If the target
+   is reduced to 0 hull points, return the target-obj and end combat"
+  (if (> (ammo-cost attacker-weapon) (ammo (inventory player-ship-obj)))
+      (progn
+	(format T "You don't have enough ammo to fire your ~A gun!~%" (name attacker-weapon))
+	(return-from player-ship-attack NIL)))
+  (let ((calculated-shield-damage (calculate-shield-damage player-ship-obj target-obj attacker-weapon))
+	(calculated-hull-damage (calculate-hull-damage player-ship-obj target-obj attacker-weapon)))
+    (setf (rep-shield-val target-obj) calculated-shield-damage) ;; Resolve shield hit
+    (format T "You hit their repulsor shields for ~A !~%" (shield-dmg attacker-weapon))
+    (if (= 0 calculated-shield-damage)
+	(progn
+	  (setf (armor-val target-obj) calculated-hull-damage)
+	  (format T "You hit their hull for ~A !~%" (hull-dmg attacker-weapon))))
+    (if (= 0 calculated-hull-damage)
+	(progn
+	  (format T "Their hulls been breached! You've won the exchange!~%")
+	  (return-from player-ship-attack target-obj))
+	NIL)))

+ 2 - 9
crew.lisp

@@ -68,9 +68,9 @@
 		     :buff-type buff-type
 		     :buff-value (+ 1 (random 3))))))
 
-(defun get-random-buff ()
+(defun get-random-buff (buff-types)
   "Return a random 'crew-buff object"
-  (make-buff (nth (+ 1 (random (length *buff-types*))) *buff-types*)))
+  (make-buff (nth (+ 1 (random (length buff-types))) buff-types)))
 
 ;; Crew name generators
 (defvar *name-prefixes*
@@ -117,10 +117,3 @@
 	"Justus"
 	"Quintus"
 	"Decimus"))
-  
-(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)))

+ 2 - 2
game.lisp

@@ -26,11 +26,11 @@
 							   :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*)
+								 collect (make-instance 'uniq-crew-mem :name (make-name *name-prefixes* *name-values*)
 												       :buff (funcall
 													      (lambda ()
 														(if (= 1 (+ 1(random 5)))
-														    (get-random-buff)
+														    (get-random-buff *buff-types*)
 														    NIL))))))
 															     
 							   :inventory (make-instance 'player-inventory

+ 15 - 1
plumbing.lisp

@@ -64,6 +64,20 @@
   (let ((handler (cdr (assoc opt lookup-table))))
     (if handler (funcall handler) (format t "Invalid opt~%~%"))))
 
-;; "Given an object, return the names of it's slots"
 (defun return-slots (obj)
+  "Given an object, return the names of it's slots"
   (map 'list #'closer-mop:slot-definition-name (closer-mop:class-slots (class-of obj))))
+
+(defun simple-print-object (obj)
+  "Given an object, print it's slots and slot values"
+  (loop for slot in (return-slots obj)
+	do (format T "Slot: ~A Value: ~A~%" 
+		   slot
+		   (slot-value obj slot))))
+
+(defun make-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)))

+ 63 - 0
ship.lisp

@@ -1,3 +1,66 @@
+(defvar *ai-ship-name-prefixes*
+  (list
+    "The Eerie"
+    "The Sinister"
+    "The Macabre"
+    "The Gothic"
+    "The Morbid"
+    "The Haunting"
+    "The Foreboding"
+    "The Menacing"
+    "The Ominous"
+    "The Grim"
+    "The Mysterious"
+    "The Cryptic"
+    "The Unsettling"
+    "The Spooky"
+    "The Creepy"
+    "The Chilling"
+    "The Ghostly"
+    "The Shadowy"
+    "The Forensic"
+    "The Malevolent"))
+
+(defvar *ai-ship-name-suffixes*
+  (list
+    "Boat"
+    "Craft"
+    "Solarboat"
+    "Schooner"
+    "Clipper"
+    "Steamer"
+    "Freighter"
+    "Cargo ship"
+    "Liner"
+    "Cruiser"
+    "Ferry"
+    "Barge"
+    "Canoe"
+    "Kayak"
+    "Raft"
+    "Yacht"
+    "Catamaran"
+    "Submarine"
+    "Galleon"
+    "Spacecraft"
+    "Rocket"
+    "Starship"
+    "Interstellar"
+    "VTOL"
+    "Lunar Module"
+    "Shuttle"
+    "Cosmic Capsule"
+    "Orbital Craft"
+    "Extraterrestrial Transport"
+    "Astroplane"
+    "Celestial Cruiser"
+    "Galactic Explorer"
+    "Planetary Probe"
+    "Voyager"
+    "Astroship"
+    "Deep Space Explorer"
+    "Cosmonaut Craft"))
+
 ;;; SHIP INFO ;;;
 (defun ship-info (player-ship-obj)
   (display-crew player-ship-obj)

+ 11 - 1
structs.lisp

@@ -56,6 +56,16 @@
     :initarg :inventory
     :accessor inventory)))
 
+(defclass ai-ship (ship)
+  ((name
+    :initarg :name
+    :accessor name
+    :initform NIL)
+   (ai-type
+   :initarg :ai-type
+   :accessor ai-type
+   :initform NIL)))
+
 (defclass player-inventory ()
     ((petrofuel
       :initarg :petrofuel
@@ -121,7 +131,7 @@
     :accessor name)
    (shield-dmg
     :initarg :shield-dmg
-    :accessor sheild-dmg)
+    :accessor shield-dmg)
    (hull-dmg
     :initarg :hull-dmg
     :accessor hull-dmg)