Skip to content

Commit

Permalink
Integrated the 'Start' player construct into ATL.
Browse files Browse the repository at this point in the history
Also some refactoring.
  • Loading branch information
veddox committed Jul 8, 2015
1 parent 501ff5f commit 957959b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
3 changes: 1 addition & 2 deletions ATL/atl-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
;; define commands
'("define-place" "define-item" "define-monster" "define-npc"
"define-race" "define-place" "define-weapon"
"define-class" "name-world" "load-file"
"start-place" "start-money")
"define-class" "define-player" "name-world" "load-file")
'() ;; other commands (adjust this?)
'("\\.atl$") ;; files for which to activate this mode
'(linum-mode) ;; other functions to call
Expand Down
9 changes: 6 additions & 3 deletions ATL/lisp-test.atl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

name-world "Underworld"

define-player "Start"
money 200
place "Fields of Punishment"
max-health 50
health 50

define-place "Nowhere"
description "Welcome to Nowhere!
You are in the void, the space between the worlds. Around you is black.
Expand Down Expand Up @@ -43,6 +49,3 @@ load-file lisp-test.atl ;Testing whether recursive loading is prevented
load-file races-classes.atl
load-file game-objects.atl
load-file creator-test.atl

start-place "Styx"
start-money 50
11 changes: 1 addition & 10 deletions lisp/interpreter.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,12 @@
(defcommand define-place place)
(defcommand define-race race)
(defcommand define-class character-class)
(defcommand define-player player)
(defcommand define-monster monster)
(defcommand define-weapon weapon)
(defcommand define-item item)
(defcommand define-npc npc)

(defun start-place (place)
(debugging "~&Starting place is ~A" place)
(setf (world-starting-place *world*) place)
NIL)

(defun start-money (amount)
(debugging "~&Starting money is ~A gold pieces" amount)
(setf (world-starting-money *world*) amount)
NIL)


(let ((world-directory NIL)
(loaded-files NIL))
Expand Down
9 changes: 9 additions & 0 deletions lisp/player.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
(special-ability NIL))


(defun add-player (player)
"Add this player to the game world"
(when (null (list-world-objects 'player))
(setf (player-game-admin player) T))
(add-game-object player)
(set-object-attribute (get-game-object 'place (player-place player))
'player (player-name player))
(objectify-place-monsters (player-place player)))

;; XXX This function is probably superfluous, as the player struct should only
;; store names of game objects (the actual objects are stored in *world*)
(let ((list-function (make-list-function 'player NIL)))
Expand Down
45 changes: 21 additions & 24 deletions lisp/ui.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
;;; Atlantis is a framework for creating multi-user dungeon worlds.
;;; This is the Common Lisp implementation.
;;;
;;; The client module is responsible for the actual user interface presented
;;; to a player. (Warning: this will likely change significantly, currently
;;; I am only implementing a mock-up before I get the networking part working.)
;;; This module is responsible for the interactive user interface. All
;;; in-game UI should be done here. (Pre-game UI goes into atlantis.lisp.)
;;; Currently, it also does quite a bit of game logic - perhaps that should
;;; be changed later.
;;;
;;; Licensed under the terms of the MIT license.
;;; author: Daniel Vedder
;;; date: 21/05/2015
;;;

(let ((player NIL))
(defun play-game (player-name)
"The main game loop"

(defun play-game (player-name)
"The main game loop"
(let ((player (get-game-object 'player player-name)))
(clear-screen)
;; Initialize the player if necessary
(when (null player)
(setf player (get-game-object 'player player-name)))
(when (null player)
(setf player (create-player player-name))
(when (null (list-world-objects 'player))
(setf (player-game-admin player) T))
(add-game-object player)
(set-object-attribute (get-game-object 'place (player-place player))
'player (player-name player)))
(objectify-place-monsters (player-place player))
(add-player player))
;; The actual game loop
(clear-screen)
(let ((place (get-game-object 'place (player-place player))))
Expand All @@ -39,14 +34,15 @@
(defun create-player (player-name)
"The user creates a new player"
;; XXX This function feels somewhat ugly - any possibility of a cleanup?
(let ((player (make-player :name player-name
:place (world-starting-place *world*)
:money (world-starting-money *world*)))
(char-attr
'((strength 0) (dexterity 0)
(constitution 0) (intelligence 0)))
(items NIL) (weapon "")
(character-points NIL))
(let* ((start-player (get-game-object 'player "Start"))
(player (if start-player (copy-player start-player)
(make-player :name player-name
:place (random-elt (list-world-objects 'place)))))
(char-attr
'((strength 0) (dexterity 0)
(constitution 0) (intelligence 0)))
(items NIL) (weapon "")
(character-points NIL))
(format t "~&The name you have chosen is not registered on this game.")
(unless (y-or-n-p "~&Create a new player?") (start-menu))
;; Chose race and class
Expand All @@ -68,7 +64,7 @@ Now distribute your attribute points. Random numbers have been chosen,
you may assign one number to each of the following attributes:")
(format t "~&~A~%~A~%~%The numbers are:"
text (string-from-list (keys char-attr)))
;; TODO I should replace simple-input with something offering 'magic'
;; XXX I should replace simple-input with something offering 'magic' (?)
(do* ((i 0 (1+ i)) (attr (safe-nth i (keys char-attr))
(safe-nth i (keys char-attr)))
(val (cassoc attr char-attr) (cassoc attr char-attr)))
Expand Down Expand Up @@ -196,7 +192,7 @@ save <game-file> - Save the game to file")

(defun goto (player &optional location)
"Go to the specified location"
;; Look before you leap
;; Look before you leap ;-)
(unless location
(format t "~&Please specify a location!")
(return-from goto))
Expand Down Expand Up @@ -345,6 +341,7 @@ save <game-file> - Save the game to file")

(defun attack (player &optional opponent)
"The player launches an attack at a monster"
;; FIXME Still gives problems (usually, neither opponent hits)
(unless opponent
(format t "~&Please specify an opponent!")
(return-from attack))
Expand Down
4 changes: 4 additions & 0 deletions lisp/util.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@
(if (= next-elt (1- (length vector))) NIL
(cons (aref vector next-elt) (to-list vector (1+ next-elt)))))

(defun random-elt (seq)
"Return a random element of this sequence"
(elt seq (random (length seq))))

(defun load-text-file (file-name)
"Load a text file into a list of strings (representing the lines)"
(with-open-file (f file-name)
Expand Down

0 comments on commit 957959b

Please sign in to comment.