combat.lisp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ;;; Combat systems implemented here
  2. (defvar *combat-menu-options-display* NIL)
  3. (defvar *combat-opt-lookup NIL)
  4. ;; Combat options:
  5. ;; Attack (with specific weapon)
  6. ;; Regen shields
  7. ;; - (add value to rep-shield-val at cost of overcharing
  8. ;; - (overcharing can cause warp field to go into low-power)
  9. ;; Overcharge gun at cost of overcharing reactor
  10. ;; Attempt to flee into the warp
  11. ;; - (requires full power / overcharged
  12. ;; - (can also cause reactor to go low power, which removes ability to regen/overcharge)
  13. (defun combat-loop (sector)
  14. "The main loop responsbile for resolving combat situations")
  15. ;; Select weapon
  16. ;; Determine if hit (% chance?)
  17. ;; If hit resolve shield
  18. ;; -- IF Shields down (ie shield damage causes target shield value to be 0)
  19. ;; -- Apply hull damage
  20. ;; ELSE
  21. ;; -- Decrement shield value per value of shield dmg
  22. (defun calculate-shield-damage (attacker-obj target-obj attacker-weapon)
  23. "Given a target and a weapon, return a value that the
  24. targets shield value should now be set as"
  25. (let ((new-shield-value (- (rep-shield-val target-obj) (shield-dmg attacker-weapon))))
  26. (setf (ammo (inventory attacker-obj)) (- (ammo (inventory attacker-obj)) (ammo-cost attacker-weapon)))
  27. (if (>= 0 new-shield-value)
  28. (return-from calculate-shield-damage 0)
  29. (return-from calculate-shield-damage new-shield-value))))
  30. (defun calculate-hull-damage (attacker-obj target-obj attacker-weapon)
  31. "Given a target and a weapon, return a value that the
  32. targets hull value should now be set as"
  33. (let ((new-hull-value (- (armor-val target-obj) (hull-dmg attacker-weapon))))
  34. (setf (ammo (inventory attacker-obj)) (- (ammo (inventory attacker-obj)) (ammo-cost attacker-weapon)))
  35. (if (>= 0 new-hull-value)
  36. (return-from calculate-hull-damage 0)
  37. (return-from calculate-hull-damage new-hull-value))))
  38. (defun player-ship-attack (player-ship-obj target-obj attacker-weapon)
  39. "Given a target and the attackers chosen weapon resolve the combat by
  40. calculating shield/hull damage and resolving resources. If the target
  41. is reduced to 0 hull points, return the target-obj and end combat"
  42. (if (> (ammo-cost attacker-weapon) (ammo (inventory player-ship-obj)))
  43. (progn
  44. (format T "You don't have enough ammo to fire your ~A gun!~%" (name attacker-weapon))
  45. (return-from player-ship-attack NIL)))
  46. (let ((calculated-shield-damage (calculate-shield-damage player-ship-obj target-obj attacker-weapon))
  47. (calculated-hull-damage (calculate-hull-damage player-ship-obj target-obj attacker-weapon)))
  48. (setf (rep-shield-val target-obj) calculated-shield-damage) ;; Resolve shield hit
  49. (format T "You hit their repulsor shields for ~A !~%" (shield-dmg attacker-weapon))
  50. (if (= 0 calculated-shield-damage)
  51. (progn
  52. (setf (armor-val target-obj) calculated-hull-damage)
  53. (format T "You hit their hull for ~A !~%" (hull-dmg attacker-weapon))))
  54. (if (= 0 calculated-hull-damage)
  55. (progn
  56. (format T "Their hulls been breached! You've won the exchange!~%")
  57. (return-from player-ship-attack target-obj))
  58. NIL)))