game.lisp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. (load "~/Repos/clwars/structs.lisp")
  2. (load "~/Repos/clwars/plumbing.lisp")
  3. (load "~/Repos/clwars/crew.lisp")
  4. (load "~/Repos/clwars/economy.lisp")
  5. (load "~/Repos/clwars/sector.lisp")
  6. (load "~/Repos/clwars/ship.lisp")
  7. (load "~/Repos/clwars/ascii-assets.lisp")
  8. (defvar *sector* NIL)
  9. (defun init-game-state ()
  10. (setq *sector*
  11. (make-instance 'sector
  12. :market (make-instance 'market)
  13. :player-ship-obj
  14. (make-instance 'ship
  15. :weapons (list (make-instance 'weapon
  16. :name "Plamsa"
  17. :shield-dmg 3
  18. :hull-dmg 3
  19. :ammo-cost 5)
  20. (make-instance 'weapon
  21. :name "Mega Bolter"
  22. :shield-dmg 1
  23. :hull-dmg 2
  24. :ammo-cost 1)
  25. (make-instance 'weapon
  26. :name "Beam"
  27. :shield-dmg 1
  28. :hull-dmg 3
  29. :ammo-cost 3))
  30. :crew (make-instance 'crew
  31. :sanity-val 100
  32. :moral-val 100
  33. :crew-members
  34. (loop for x in '(1 2 3 4)
  35. collect (make-instance 'uniq-crew-mem :name (make-crew-mem-name *name-prefixes* *name-values*)
  36. :buff (funcall
  37. (lambda ()
  38. (if (= 1 (+ 1(random 5)))
  39. (get-random-buff)
  40. NIL))))))
  41. :inventory (make-instance 'player-inventory
  42. :petrofuel 20
  43. :gruel 20
  44. :spice 0
  45. :ammo 20
  46. :archeotech 0)))))
  47. (defun new-game ()
  48. (init-game-state)
  49. (game-intro)
  50. (top-level-game-menu))
  51. (defun game-intro ()
  52. (cls)
  53. (format t "In the grim darkness of the far future, there is only COMMERCE...~%")
  54. (sleep 2)
  55. (format t "You embark across a bleak galaxy to ply your wares and discover untold riches!~%")
  56. (sleep 2)
  57. (format t *intro-ship*)
  58. (prompt-read ""))
  59. ;; Options for top level menu
  60. ;; This is the main "gameplay" interface
  61. (defvar *top-level-options-display* "
  62. Actions:
  63. 1 | Sector info | sei
  64. 2 | Ship info | si
  65. 3 | Trade | t
  66. 4 | Scout | s
  67. 5 | Leave sector | l
  68. ")
  69. ;; Use lookup table to handle top level loop arguments
  70. ;; See: https://dnaeon.github.io/common-lisp-lookup-tables-alists-and-plists/
  71. (defparameter *top-level-opt-lookup* (list (cons 'sector-info 'sector-info)
  72. (cons '1 'sector-info)
  73. (cons '2 (lambda ()
  74. (ship-info (player-ship-obj *sector*))))
  75. (cons '3 (lambda ()
  76. (trade-menu *sector*)))
  77. (cons '4 'scout)
  78. (cons '5 'leave)))
  79. (defun top-level-game-menu ()
  80. (format t *top-level-options-display*)
  81. (let ((option (prompt-read "Enter an option: ")))
  82. (format t "~%")
  83. (handle-opt (read-from-string option) *top-level-opt-lookup*))
  84. (top-level-game-menu))