game.lisp 2.5 KB

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