OSDN Git Service

3e3b312f42f440d717eb27baf72d0c027407b783
[rulp/rulp.git] / layers / models.lisp
1 (in-package :layers)
2
3 (defgeneric create-entity (m))
4
5 (defclass model ()
6   ((name :initarg :name
7          :accessor name
8          :documentation "name of the model, it will be transfered to the entity when generated"
9          :initform "noname"
10          :type string)
11    (properties :accessor properties
12                :initarg :properties
13                :documentation "an a-list of the properties of the entity"
14                :initform nil)
15    (size :accessor size
16          :initarg :size
17          :documentation "the size of a model, it will be calculated with the grid for the dimension in board"
18          :type integer
19          :initform 1)
20    (interactions :initform '(pokep)
21                  :accessor interactions
22                  :documentation "interactions are function the entity can use, these are
23 associated with some property"
24                  :initarg :interactions)
25    ))
26
27 (defmethod create-entity ((m model))
28   "create an entity from the standard model"
29   (let* ((return-entity m))
30     (make-instance 'entity
31                    :name (name m)
32                    :propreties (propreties m)
33                    :size (size m)
34                    :interactions (interactions m))))
35
36 ;; the dice set, this has many uses, it is called by
37 ;; interactions when actions are done, it is called
38 ;; on entity creation for life randomization (the
39 ;; create-entity function eval the supplied data)
40 (defun dice (dice-type number-dices &key (plus 0))
41   "throw the dice-type n times based on number-dices"
42   (+ 1 plus (loop :for i :from 1 :to number-dices
43                   :sum (random dice-type))))
44
45 (defun d4 (number-dices &key (plus 0))
46   "shortcut for the dice function with d4"
47   (dice 4 number-dices :plus plus))
48 (defun d6 (number-dices &key (plus 0))
49   "shortcut for the dice function with d6"
50   (dice 6 number-dices :plus plus))
51 (defun d8 (number-dices &key (plus 0))
52   "shortcut for the dice function with d8"
53   (dice 8 number-dices :plus plus))
54 (defun d10 (number-dices &key (plus 0))
55   "shortcut for the dice function with d10"
56   (dice 10 number-dices :plus plus))
57 (defun d12 (number-dices &key (plus 0))
58   "shortcut for the dice function with d12"
59   (dice 12 number-dices :plus plus))
60 (defun d20 (number-dices &key (plus 0))
61   "shortcut for the dice function with d20"
62   (dice 20 number-dices :plus plus))
63 (defun d100 (number-dices &key (plus 0))
64   "shortcut for the dice function with d100"
65   (dice 100 number-dices :plus plus))
66
67 (defun dice-from-list (list-dices &key (plus 0))
68   "throw and sums all the dices from a list, the plus modificator
69 is added once at the end of the sum (Xd4+Yd6+Zd8+...+p)"
70   (+ 1 plus (loop :for i :in list-dices
71                   :sum (random i))))