OSDN Git Service

layers/screens.lisp: created render and getscreen functions
[rulp/rulp.git] / layers / models.lisp
1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022  Zull
3 ;;;;
4 ;;;; This program is free software: you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation, either version 3 of the License, or
7 ;;;; (at your option) any later version.
8 ;;;;
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;;; GNU General Public License for more details.
13 ;;;;
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 (in-package :rulp.layers)
18
19 (defgeneric create-entity (m))
20
21 (defclass model ()
22   ((name :initarg :name
23          :accessor name
24          :documentation "name of the model, it will be transfered to the entity when generated"
25          :initform "noname"
26          :type string)
27    (properties :accessor properties
28                :initarg :properties
29                :documentation "an a-list of the properties of the entity"
30                :initform nil)
31    (size :accessor size
32          :initarg :size
33          :documentation "the size of a model, it will be calculated with the grid for the dimension in board"
34          :type integer
35          :initform 1)
36    (interactions :initform '(pokep)
37                  :accessor interactions
38                  :documentation "interactions are function the entity can use, these are
39 associated with some property"
40                  :initarg :interactions)
41    ))
42
43 (defmethod create-entity ((m model))
44   "create an entity from the standard model"
45   (let* ((return-entity m))
46     (make-instance 'entity
47                    :name (name m)
48                    :propreties (propreties m)
49                    :size (size m)
50                    :interactions (interactions m))))
51
52 ;; the dice set, this has many uses, it is called by
53 ;; interactions when actions are done, it is called
54 ;; on entity creation for life randomization (the
55 ;; create-entity function eval the supplied data)
56 (defun dice (dice-type number-dices &key (plus 0))
57   "throw the dice-type n times based on number-dices"
58   (+ 1 plus (loop :for i :from 1 :to number-dices
59                   :sum (random dice-type))))
60
61 (defun d4 (number-dices &key (plus 0))
62   "shortcut for the dice function with d4"
63   (dice 4 number-dices :plus plus))
64 (defun d6 (number-dices &key (plus 0))
65   "shortcut for the dice function with d6"
66   (dice 6 number-dices :plus plus))
67 (defun d8 (number-dices &key (plus 0))
68   "shortcut for the dice function with d8"
69   (dice 8 number-dices :plus plus))
70 (defun d10 (number-dices &key (plus 0))
71   "shortcut for the dice function with d10"
72   (dice 10 number-dices :plus plus))
73 (defun d12 (number-dices &key (plus 0))
74   "shortcut for the dice function with d12"
75   (dice 12 number-dices :plus plus))
76 (defun d20 (number-dices &key (plus 0))
77   "shortcut for the dice function with d20"
78   (dice 20 number-dices :plus plus))
79 (defun d100 (number-dices &key (plus 0))
80   "shortcut for the dice function with d100"
81   (dice 100 number-dices :plus plus))
82
83 (defun dice-from-list (list-dices &key (plus 0))
84   "throw and sums all the dices from a list, the plus modificator
85 is added once at the end of the sum (Xd4+Yd6+Zd8+...+p)"
86   (+ 1 plus (loop :for i :in list-dices
87                   :sum (random i))))