Преглед изворни кода

Barebones Combat

The most anemic and barebones 'combat' system now exists. Needs much
more fleshing out.
Simon Watson пре 1 година
родитељ
комит
9af2ed00fc
5 измењених фајлова са 78 додато и 20 уклоњено
  1. 4 1
      README.md
  2. 59 4
      combat.lisp
  3. 2 11
      crew.lisp
  4. 3 3
      game.lisp
  5. 10 1
      ship.lisp

+ 4 - 1
README.md

@@ -22,6 +22,8 @@ NOTE: This 'game' is just a playground for me to play with Lisp. It is not a ref
   - TODO:
     - [ ] Basic combat system, perhaps like battleship
     - [ ] Basic 'move to new sector' system
+    - [ ] Shields recharge after combat
+    - [ ] System for repairing hull
   - Notes:
     - Hull Integrity
       - When 0 game over
@@ -48,8 +50,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
+    - [ ] Stretch - trade interface for 'friendly' ships
     - [ ] Overhaul buy/sell interface for archeotech specific information
-    - [ ] Random $x*$x ASCII image to represent archeotech
+    - [ ] Stretch - 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

+ 59 - 4
combat.lisp

@@ -1,20 +1,46 @@
 ;;; Combat systems implemented here
 
-(defvar *combat-menu-options-display* NIL)
-(defvar *combat-opt-lookup NIL)
+(defvar *combat-menu-options-display* "
+Actions:
+1 | Attack | a
+2 | Regen. Shields | r
+3 | Overcharge Gun | o
+4 | Attempt to flee | f
+")
 
 ;; Combat options:
 ;; Attack (with specific weapon)
 ;; Regen shields
 ;; - (add value to rep-shield-val at cost of overcharing
 ;; - (overcharing can cause warp field to go into low-power)
+;; - (overcharging can cause hull damage)
 ;; Overcharge gun at cost of overcharing reactor
 ;; Attempt to flee into the warp
-;; - (requires full power / overcharged
+;; - (requires full power / overcharged reactor)
 ;; - (can also cause reactor to go low power, which removes ability to regen/overcharge)
 
 (defun combat-loop (sector)
-  "The main loop responsbile for resolving combat situations")
+  "The main loop responsbile for resolving combat situations"
+  (let ((combat-state T))
+    (loop
+      while combat-state
+      do (progn
+	   (format T *combat-menu-options-display*)
+	   (let ((top-level-selection (prompt-read "Enter a selection: ")))
+	     (case (read-from-string top-level-selection)
+	       (1 (progn ;; There is a way to collapse this progn into a single
+		         ;; function call, but it's arguably a lot less readable
+		    (let* ((weapon (weapon-select-menu (player-ship-obj sector)))
+			   (attack-result (player-ship-attack
+					   (player-ship-obj sector)
+					   (first (enemy-ships sector))
+					   weapon)))
+		      (if attack-result
+			  (progn
+			    (setf (enemy-ships sector) (delete attack-result (enemy-ships sector)))
+			    (format T "Your opponent has been vanquished!~%")
+			    (top-level-game-menu))))))))))))
+		
 
 ;; Select weapon
 ;; Determine if hit (% chance?)
@@ -24,6 +50,24 @@
 ;; ELSE
 ;; -- Decrement shield value per value of shield dmg
 
+(defun weapon-select-menu (player-ship-obj)
+  (let ((weapon-list (loop for weapon in (weapons player-ship-obj)
+			   for i from 0
+			   collect (list i
+					 (name weapon)
+					 (shield-dmg weapon)
+					 (hull-dmg weapon)
+					 (ammo-cost weapon)))))
+    (format T "~%Available Ammo: ~A~%~%" (ammo (inventory player-ship-obj)))
+    (format T "Available Weapons: ~%")
+    (format-table T weapon-list :column-label '("Number" "Name" "Shield Damage" "Hull Damage" "Ammo Cost"))
+    (let ((selection (prompt-read "Select a weapon to via the number column: ")))
+      (format t "Selection was number: ~A and weapon name: ~A~%~%"
+	      selection
+	      (second (nth (parse-integer selection) weapon-list)))
+      (return-from weapon-select-menu (nth (parse-integer selection) (weapons player-ship-obj))))))
+
+
 (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"
@@ -63,3 +107,14 @@
 	  (format T "Their hulls been breached! You've won the exchange!~%")
 	  (return-from player-ship-attack target-obj))
 	NIL)))
+
+(defun display-weapons (player-ship-obj)
+  "Given player ship, display weapons and associated attributes"
+  (let* ((weapons (weapons player-ship-obj))
+	 (weapon-list (loop for weapon in weapons
+			    collect (list (name weapon)
+					  (shield-dmg weapon)
+					  (hull-dmg weapon)
+					  (ammo-cost weapon)))))
+    (format T "~%WEAPON DETAILS~%")
+    (format-table T weapon-list :column-label '("Name" "Shield Damage" "Hull Damage" "Ammo Cost"))))

+ 2 - 11
crew.lisp

@@ -6,23 +6,14 @@
 			       (list (name member) (slot-value (buff member) 'buff-type) (slot-value (buff member) 'buff-value))
 			       (list (name member) NIL NIL))))))
 				    
-    (format T "~%CREW DETAILS~%~%")
+    (format T "~%CREW DETAILS~%")
     (format-table T
 		  (list
 		   (list
 		    (sanity-val (crew player-ship-obj))
 		    (moral-val (crew player-ship-obj)))) :column-label '("Sanity" "Moral"))
-    (format T "~%")
     (format-table T crew-names :column-label '("Name" "Buff" "Buff Amount"))))
 
-(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"))))
-
 (defparameter *buff-types*
   (list 'weapons-expert
 	'shields-expert
@@ -43,7 +34,7 @@
 		    :buff-value (+ 1 (random 50))))
     (warp-shaman
      (make-instance 'crew-buff
-		    :name "Warp Shaman" ; % change to ignore low power warp shield
+		    :name "Warp Shaman" ; % chance to ignore low power warp shield
 		    :buff-type buff-type
 		    :buff-value (+ 0.1 (random 0.6))))
     (machine-enchanter

+ 3 - 3
game.lisp

@@ -8,7 +8,7 @@
 		       (make-instance 'ship
 				      :weapons (list (make-instance 'weapon
 								    :name "Plamsa"
-								    :shield-dmg 3
+								    :shield-dmg 1
 								    :hull-dmg 3
 								    :ammo-cost 5)
 						     (make-instance 'weapon
@@ -18,8 +18,8 @@
 								    :ammo-cost 1)
 						     (make-instance 'weapon
 								    :name "Beam"
-								    :shield-dmg 1
-								    :hull-dmg 3
+								    :shield-dmg 3
+								    :hull-dmg 1
 								    :ammo-cost 3))
 				      :crew (make-instance 'crew
 							   :sanity-val 100

+ 10 - 1
ship.lisp

@@ -62,7 +62,16 @@
     "Cosmonaut Craft"))
 
 ;;; SHIP INFO ;;;
+(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 (player-ship-obj)
   (display-crew player-ship-obj)
-  (display-inventory player-ship-obj))
+  (display-inventory player-ship-obj)
+  (display-weapons player-ship-obj))
 ;;; SHIP INFO END ;;;