game.lisp 2.7 KB

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