1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- ;;; Combat systems implemented here
- (defvar *combat-menu-options-display* NIL)
- (defvar *combat-opt-lookup NIL)
- ;; 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)
- ;; Overcharge gun at cost of overcharing reactor
- ;; Attempt to flee into the warp
- ;; - (requires full power / overcharged
- ;; - (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")
- ;; 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 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)))
|