diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/src/item-classes.lisp b/src/item-classes.lisp index 2eda5b8..0350cb9 100644 --- a/src/item-classes.lisp +++ b/src/item-classes.lisp @@ -63,9 +63,7 @@ ;; individual properties (id :reader .id :initarg :id :initform -1) (last-move :accessor .last-move :initform 0)) - (:default-initargs :destroy-with '(weapon) :movable T)) - -;;TODO (defclass player (feature) + (:default-initargs :destroy-with '(weapon))) ;; Create a new class for each item type (defmacro new-item (superclass name &body body) diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/src/item-classes.lisp b/src/item-classes.lisp index 2eda5b8..0350cb9 100644 --- a/src/item-classes.lisp +++ b/src/item-classes.lisp @@ -63,9 +63,7 @@ ;; individual properties (id :reader .id :initarg :id :initform -1) (last-move :accessor .last-move :initform 0)) - (:default-initargs :destroy-with '(weapon) :movable T)) - -;;TODO (defclass player (feature) + (:default-initargs :destroy-with '(weapon))) ;; Create a new class for each item type (defmacro new-item (superclass name &body body) diff --git a/src/item-methods.lisp b/src/item-methods.lisp index cf9b60a..2e6afbd 100644 --- a/src/item-methods.lisp +++ b/src/item-methods.lisp @@ -39,14 +39,11 @@ (patchindir (.x a) (.y a) dir)) (ttl 10 (1- ttl))) ((zerop ttl) - ;(logging "The ~A at ~S/~S didn't move." (.name a) (.x a) (.y a)) NIL) (when (and next-patch (null (patch-occupant next-patch)) (member (read-from-string (biome-name (patch-biome next-patch))) (.habitat a))) - ;; (logging "The ~A at ~S/~S is moving ~S." - ;; (.name a) (.x a) (.y a) dir) (setf (patch-occupant (coord (.x a) (.y a))) NIL) (setf (.x a) (first (patch-pos next-patch)) (.y a) (second (patch-pos next-patch))) diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/src/item-classes.lisp b/src/item-classes.lisp index 2eda5b8..0350cb9 100644 --- a/src/item-classes.lisp +++ b/src/item-classes.lisp @@ -63,9 +63,7 @@ ;; individual properties (id :reader .id :initarg :id :initform -1) (last-move :accessor .last-move :initform 0)) - (:default-initargs :destroy-with '(weapon) :movable T)) - -;;TODO (defclass player (feature) + (:default-initargs :destroy-with '(weapon))) ;; Create a new class for each item type (defmacro new-item (superclass name &body body) diff --git a/src/item-methods.lisp b/src/item-methods.lisp index cf9b60a..2e6afbd 100644 --- a/src/item-methods.lisp +++ b/src/item-methods.lisp @@ -39,14 +39,11 @@ (patchindir (.x a) (.y a) dir)) (ttl 10 (1- ttl))) ((zerop ttl) - ;(logging "The ~A at ~S/~S didn't move." (.name a) (.x a) (.y a)) NIL) (when (and next-patch (null (patch-occupant next-patch)) (member (read-from-string (biome-name (patch-biome next-patch))) (.habitat a))) - ;; (logging "The ~A at ~S/~S is moving ~S." - ;; (.name a) (.x a) (.y a) dir) (setf (patch-occupant (coord (.x a) (.y a))) NIL) (setf (.x a) (first (patch-pos next-patch)) (.y a) (second (patch-pos next-patch))) diff --git a/src/params.lisp b/src/params.lisp index b354c37..04b5fa4 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -22,7 +22,7 @@ (defparameter *framerate* 1000) ;;Localhost defaults -(defparameter *defaulthost* '("127.0.0.1" 21896)) ;default port: 21895 +(defparameter *defaulthost* '("127.0.0.1" 21895)) ;default port: 21895 ;;Host server address to connect to (defparameter *host* (first *defaulthost*)) diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/src/item-classes.lisp b/src/item-classes.lisp index 2eda5b8..0350cb9 100644 --- a/src/item-classes.lisp +++ b/src/item-classes.lisp @@ -63,9 +63,7 @@ ;; individual properties (id :reader .id :initarg :id :initform -1) (last-move :accessor .last-move :initform 0)) - (:default-initargs :destroy-with '(weapon) :movable T)) - -;;TODO (defclass player (feature) + (:default-initargs :destroy-with '(weapon))) ;; Create a new class for each item type (defmacro new-item (superclass name &body body) diff --git a/src/item-methods.lisp b/src/item-methods.lisp index cf9b60a..2e6afbd 100644 --- a/src/item-methods.lisp +++ b/src/item-methods.lisp @@ -39,14 +39,11 @@ (patchindir (.x a) (.y a) dir)) (ttl 10 (1- ttl))) ((zerop ttl) - ;(logging "The ~A at ~S/~S didn't move." (.name a) (.x a) (.y a)) NIL) (when (and next-patch (null (patch-occupant next-patch)) (member (read-from-string (biome-name (patch-biome next-patch))) (.habitat a))) - ;; (logging "The ~A at ~S/~S is moving ~S." - ;; (.name a) (.x a) (.y a) dir) (setf (patch-occupant (coord (.x a) (.y a))) NIL) (setf (.x a) (first (patch-pos next-patch)) (.y a) (second (patch-pos next-patch))) diff --git a/src/params.lisp b/src/params.lisp index b354c37..04b5fa4 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -22,7 +22,7 @@ (defparameter *framerate* 1000) ;;Localhost defaults -(defparameter *defaulthost* '("127.0.0.1" 21896)) ;default port: 21895 +(defparameter *defaulthost* '("127.0.0.1" 21895)) ;default port: 21895 ;;Host server address to connect to (defparameter *host* (first *defaulthost*)) diff --git a/src/player.lisp b/src/player.lisp index e4179c6..30c9a88 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -2,45 +2,52 @@ ;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game ;;;; set in Africa. ;;;; -;;;; This file is responsible for managing the player instance. +;;;; This file is responsible for managing player instances. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; (in-package :naledi-ya-africa) -(defparameter *player* NIL) ;;TODO replace with player-list - (defstruct player (name "") - (strength 0) - (dexterity 0) - (intelligence 0) - (experience 0) - (level 0) - (hunger 0) - (health 0) - (equipment NIL) - (inventory '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) - (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + (password "") + (online NIL) + (human NIL)) + +(defclass human (animal) + ;; A human player + ;;XXX add age? + ((experience :accessor .xp :initform 0) + (level :accessor .level :initform 0) + (dexterity :accessor .dex :initarg :dex :initform 1) + (intelligence :accessor .int :initarg :int :initform 1) + (hunger :accessor .hunger :initarg :hunger :initform 10) + (tool :accessor .tool :initarg :tool :initform NIL) + (inventory :accessor .inventory :initarg :inventory + :initform '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) + (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + (:default-initargs :habitat T)) ;; INVENTORY HANDLING FUNCTIONS -(defun stock-size (resource &optional (player *player*)) +;;TODO convert to methods + +(defun stock-size (resource player) "How many items of this resource type is the player carrying?" (dolist (i (player-inventory player) 0) (when (eq (item-name (first i)) resource) (return-from stock-size (second i))))) -(defun weight-carried (&optional (player *player*)) +(defun weight-carried (player) "Sum up the total weight of all items carried" (+ (item-weight (player-equipment player)) (reduce #'+ (mapcar #'(lambda (i) (* (second i) (item-weight (first i))))) (player-inventory player)))) -(defun pickup (item &optional (player *player*)) +(defun pickup (item player) "Add the item object to the inventory" ;;Can the item be picked up at all? (unless (item-movable item) @@ -69,7 +76,7 @@ ;;If nothing has worked, the inventory is full (notify "Your inventory is full.")) -(defun drop (inv-nr &optional (player *player)) +(defun drop (player inv-nr) "Drop an item from the given inventory index" ;;TODO add item back to patch (let* ((item-entry (nth inv-nr (player-inventory player))) diff --git a/TODO b/TODO index 5324f0f..d820d8f 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ -> NON-SEVERE * Lakes are created + -> still an issue? -> HEISENBUGS diff --git a/naledi.asd b/naledi.asd index f3174ad..734976d 100644 --- a/naledi.asd +++ b/naledi.asd @@ -28,6 +28,7 @@ (:file "util") (:file "item-classes") (:file "item-methods") + (:file "player") (:file "world") (:file "server") (:file "client") diff --git a/src/item-classes.lisp b/src/item-classes.lisp index 2eda5b8..0350cb9 100644 --- a/src/item-classes.lisp +++ b/src/item-classes.lisp @@ -63,9 +63,7 @@ ;; individual properties (id :reader .id :initarg :id :initform -1) (last-move :accessor .last-move :initform 0)) - (:default-initargs :destroy-with '(weapon) :movable T)) - -;;TODO (defclass player (feature) + (:default-initargs :destroy-with '(weapon))) ;; Create a new class for each item type (defmacro new-item (superclass name &body body) diff --git a/src/item-methods.lisp b/src/item-methods.lisp index cf9b60a..2e6afbd 100644 --- a/src/item-methods.lisp +++ b/src/item-methods.lisp @@ -39,14 +39,11 @@ (patchindir (.x a) (.y a) dir)) (ttl 10 (1- ttl))) ((zerop ttl) - ;(logging "The ~A at ~S/~S didn't move." (.name a) (.x a) (.y a)) NIL) (when (and next-patch (null (patch-occupant next-patch)) (member (read-from-string (biome-name (patch-biome next-patch))) (.habitat a))) - ;; (logging "The ~A at ~S/~S is moving ~S." - ;; (.name a) (.x a) (.y a) dir) (setf (patch-occupant (coord (.x a) (.y a))) NIL) (setf (.x a) (first (patch-pos next-patch)) (.y a) (second (patch-pos next-patch))) diff --git a/src/params.lisp b/src/params.lisp index b354c37..04b5fa4 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -22,7 +22,7 @@ (defparameter *framerate* 1000) ;;Localhost defaults -(defparameter *defaulthost* '("127.0.0.1" 21896)) ;default port: 21895 +(defparameter *defaulthost* '("127.0.0.1" 21895)) ;default port: 21895 ;;Host server address to connect to (defparameter *host* (first *defaulthost*)) diff --git a/src/player.lisp b/src/player.lisp index e4179c6..30c9a88 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -2,45 +2,52 @@ ;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game ;;;; set in Africa. ;;;; -;;;; This file is responsible for managing the player instance. +;;;; This file is responsible for managing player instances. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; (in-package :naledi-ya-africa) -(defparameter *player* NIL) ;;TODO replace with player-list - (defstruct player (name "") - (strength 0) - (dexterity 0) - (intelligence 0) - (experience 0) - (level 0) - (hunger 0) - (health 0) - (equipment NIL) - (inventory '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) - (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + (password "") + (online NIL) + (human NIL)) + +(defclass human (animal) + ;; A human player + ;;XXX add age? + ((experience :accessor .xp :initform 0) + (level :accessor .level :initform 0) + (dexterity :accessor .dex :initarg :dex :initform 1) + (intelligence :accessor .int :initarg :int :initform 1) + (hunger :accessor .hunger :initarg :hunger :initform 10) + (tool :accessor .tool :initarg :tool :initform NIL) + (inventory :accessor .inventory :initarg :inventory + :initform '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) + (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + (:default-initargs :habitat T)) ;; INVENTORY HANDLING FUNCTIONS -(defun stock-size (resource &optional (player *player*)) +;;TODO convert to methods + +(defun stock-size (resource player) "How many items of this resource type is the player carrying?" (dolist (i (player-inventory player) 0) (when (eq (item-name (first i)) resource) (return-from stock-size (second i))))) -(defun weight-carried (&optional (player *player*)) +(defun weight-carried (player) "Sum up the total weight of all items carried" (+ (item-weight (player-equipment player)) (reduce #'+ (mapcar #'(lambda (i) (* (second i) (item-weight (first i))))) (player-inventory player)))) -(defun pickup (item &optional (player *player*)) +(defun pickup (item player) "Add the item object to the inventory" ;;Can the item be picked up at all? (unless (item-movable item) @@ -69,7 +76,7 @@ ;;If nothing has worked, the inventory is full (notify "Your inventory is full.")) -(defun drop (inv-nr &optional (player *player)) +(defun drop (player inv-nr) "Drop an item from the given inventory index" ;;TODO add item back to patch (let* ((item-entry (nth inv-nr (player-inventory player))) diff --git a/src/server.lisp b/src/server.lisp index 255c47e..34a680d 100644 --- a/src/server.lisp +++ b/src/server.lisp @@ -16,6 +16,30 @@ ;; TODO save and load functions ;; XXX Will probably require `make-load-form-saving-slots' +;;; PLAYER LIST + +(let ((players NIL)) + (defun reset-players () (setf players NIL)) + + (defun get-player (name) + (first (member name players + :test #'(lambda (s p) (equalp (player-name p) s))))) + + (defun add-player (name passwd) + (let ((np (make-player :name name :password passwd :online NIL + :human (make-instance 'human + :x (random *world-size*) + :y (random *world-size*))))) + (setf players (cons np players)))) + + (defun save-players (file-name) + ;;TODO + )) + +(defun online-p (name) + (let ((p (get-player name))) + (when p (player-online p)))) + ;;; WORLD OBJECT (let ((world NIL)) @@ -34,9 +58,9 @@ (biome-char (patch-biome p))) row) ""))))) - (defun save-world () + (defun save-world (&optional (file-name "naledi.save")) ;;TODO - ) + (save-players file-name)) (defun coord (x y) "Return the patch at the given coordinates or NIL if out of bounds" @@ -149,6 +173,22 @@ ;;; COMMUNICATION FUNCTIONS +(defun login (name passwd) + "Log this player in" + (let ((p (get-player name))) + ;;TODO wrong password and non-existent player give the same return value + (when (and p (equalp passwd (player-password p))) + (setf (player-online p) T) + (setf (patch-occupant ;;TODO check for previous occupants + (coord (.x (player-human p)) (.y (player-human p)))) + (player-human p)) + name))) + +(defun create-player (name passwd) + "Create a new player" + (unless (get-player name) + (add-player name passwd) name)) + (defun get-map (player-name) "Return a 2d list of map places (each a list of a char and a colour)" ;;TODO