This repository was archived by the owner on Oct 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lisp
More file actions
96 lines (86 loc) · 3.44 KB
/
Copy pathutils.lisp
File metadata and controls
96 lines (86 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; utils.lisp
;; Copyright (c) 2014 Kalman Kiss, Zalaegerszeg Hungary
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;
;; Author and contact:
;; Kalman Kiss <kiskami@freemail.hu>
;; 8900 Zalaegerszeg, Hungary
;; Kakukkfu u. 4.
(in-package #:firstrl)
(defun split-by (string &optional (sepchar #\Space))
"Returns a list of substrings of string
divided by ONE separator char each.
http://cl-cookbook.sourceforge.net/strings.html"
(loop for i = 0 then (1+ j)
as j = (or (position sepchar string :start i))
collect (subseq string i j)
while j))
(defun find-dungeonfeatures-in-level (level typeid)
(remove-if-not #'(lambda (f) (equal typeid f)) (level-features level) :key #'object-typeid))
(defun get-player-level (dungeon)
(nth (lifeform-aktlevel (dungeon-player dungeon)) (dungeon-levels dungeon)))
(defun is-object-at (x y lst)
(dolist (o lst nil)
(if (and (= x (object-x o))
(= y (object-y o)))
(return-from is-object-at o))))
(defun is-a-monster (lifeform)
(gethash (lifeform-typeid lifeform) *monsterdata*))
(defun is-an-item (object)
(gethash (object-typeid object) *itemdata*))
(defun is-a-dungeonfeature (object)
(gethash (object-typeid object) *dungeonfeaturedata*))
(defun convert-test-level (name str)
"Convert character string level representation to data structs."
(let ((lines (split-by str #\Newline))
(maxlength 0))
(dolist (l lines)
(when (< maxlength (length l)) (setf maxlength (length l))))
(let ((map_ (make-array (list maxlength (length lines)) :element-type 'character
:initial-element #\Space))
(monsters ()) (items ()) (features ())
(x 0) (y 0))
(dolist (l lines)
(map nil #'(lambda (c)
(let ((monsta (gethash (string c) *monsterdata*))
(item (gethash (string c) *itemdata*))
(feature (gethash (string c) *dungeonfeaturedata*)))
(cond (monsta
; (format t "monsta ~A at ~A,~A~%" c x y)
(pushnew (make-lifeform :name "monsta"
:typeid (string c)
:x x :y y) monsters)
(setf (aref map_ x y) #\.))
(item
; (format t "item ~A at ~A,~A~%" c x y)
(pushnew (make-object :name "item"
:typeid (string c)
:x x :y y) items)
(setf (aref map_ x y) #\.))
(feature
; (format t "feature ~A at ~A,~A~%" c x y)
(pushnew (make-object :name "feature"
:typeid (string c)
:x x :y y) features)
(setf (aref map_ x y) c))))
(incf x))
l)
(incf y) (setf x 0))
(make-level :name name :parents nil :childs nil
:monsters monsters :items items :features features
:map map_))))
(defun get-rnd-number (min max)
(+ min (random (1+ (- max min)) *RNDSTATE*)))