|
@@ -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)))
|