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 pathmonster.lisp
More file actions
126 lines (118 loc) · 4.13 KB
/
Copy pathmonster.lisp
File metadata and controls
126 lines (118 loc) · 4.13 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
;;; monster.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 gen-monsters (leveldata map features items)
(let ((res ()))
(dolist (mp (leveldata-monsters leveldata))
(when mp
(setf res (append res
(apply #'gen-monsters*
:leveldata leveldata
:map map
:features features
:items items
mp)))))
res))
(defun gen-monsters* (&key leveldata map features items
typeid (cnt 1) (sickprob 0)
(name nil) (hp nil) (att nil) (def nil) (spe nil) (xp nil))
(let ((res ()))
(dotimes (i cnt res)
(let ((md (gethash typeid *monsterdata*))
(kord nil)
(sick (<= (get-rnd-number 0 100) sickprob))
)
(cond (md
(setf
kord (find-kord-for-monster leveldata map features items res)
res (append res
(list (make-lifeform
:name (if name name (monsterdata-name md))
:typeid typeid
:x (car kord) :y (cdr kord)
:state (if sick 'sick 'alive)
:thinkfunc #'monster-think
:turns 0
:role (monsterdata-rel md)
:hp (if hp hp (monsterdata-hp md))
:maxhp (if hp hp (monsterdata-hp md))
:att (if att att (monsterdata-att md))
:def (if def def (monsterdata-def md))
:spe (if spe spe (monsterdata-spe md))
:xp (if xp xp (monsterdata-xp md))
:alignment (monsterdata-rel md)))))
)
(t
(error "Monsterdata not found.")))
)
))
)
(defun find-kord-for-monster (leveldata map fea ite ml)
"lm - monsterlist so far by gen-monsters*"
(do ((x 0 (get-rnd-number 1 (1- (leveldata-w leveldata))))
(y 0 (get-rnd-number 1 (1- (leveldata-h leveldata)))))
((and (is-floor map x y)
(not (is-object-at x y fea)) ; feature there?
(not (is-object-at x y ite)) ; item there?
(not (is-object-at x y ml)) ; monster there?
) (cons x y))
;empty
))
(defun monster-think (monsta msg)
(cond ((equal 'update msg)
(when (equal (lifeform-alignment monsta) 'angry)
(when (>= 2 (get-rnd-number 0 100))
(add-msg (format nil "You hear some ~A noises." (lifeform-name monsta))))))))
(defun damage-monster (level monsta dmg)
(cond ((>= dmg (lifeform-hp monsta))
(setf (lifeform-hp monsta) 0
(lifeform-state monsta)
(if (equal (lifeform-state monsta) 'sick) 'sick-dead 'dead))
(deadmonster-to-corpse level monsta)
(add-msg (format nil "The ~A dies." (lifeform-name monsta)))
)
(t
(decf (lifeform-hp monsta) dmg)
(when (<= (lifeform-hp monsta) (/ (lifeform-maxhp monsta) 3))
(add-msg (format nil "The ~A is heavily wounded."
(lifeform-name monsta))))
)
)
)
(defun monsta-alive (monsta)
(not (or (equal (lifeform-state monsta) 'dead) (equal (lifeform-state monsta) 'sick-dead))))
(defun deadmonster-to-corpse (level monsta)
(setf
(level-monsters level)
(delete monsta (level-monsters level))
(level-items level)
(nconc (level-items level)
(list (make-objectwithrole
:name (format nil "~A corpse" (lifeform-name monsta))
:typeid (if (equal 'sick-dead (lifeform-state monsta))
"%sc" "%c")
:aktlevel 0
:x (lifeform-x monsta)
:y (lifeform-y monsta)
:state 'dead
:role "corpse"
:xp (floor (/ (lifeform-xp monsta) 2)))))))