Delete old README
[minetest_treasurer.git] / README.md
blobb2bdb7e0ddcf74a2e39041b2833591e7bf12038c
1 = Treasurer’s README file for Treasurer version 0.2.0 =
2 == Overview ==
3 * Name: Treasurer
4 * Technical name: `treasurer`
5 * Purpose: To provide an interface for mods which want to spawn ItemStacks randomly and an interface for mods which create new items.
6 * Version: 0.2.0
7 * Dependencies: none
8 * License: WTFPL
10 == Introduction ==
11 Problem:
12 There are a bunch of mods which have cool items but they won’t appear in the world by
13 themselves.
14 There are some mods which randomly distribute treasures into the world. Sadly, these only
15 distribute the items they know—which are just the items of the mod “default” most of the
16 time. The items of the other mods are completely missed.
18 The reason for this is that the distributing mods can’t know what sort of items are available
19 unless they explicitly depend on the mods that defines these. Viewed the other way round,
20 the item-defining mods that also distribute these items into the world are limited in the
21 sense that they only know one means of distributing items.
23 There is a gap between defining items and distributing them. Every time a mod does both,
24 flexibility is limited and expansion becomes difficult.
26 To bridge this gap, Treasurer has been written. Treasurer makes it possible a) for mods to define
27 treasures without bothering _how_ these are distributed into the world and b) for mods to distribute
28 treasures around the world without knowledge about _what_ treasures exactly are distributed.
30 == Technical side of Treasurer ==
31 === technical overview ===
32 To get a working Treasurer architecture and actually get some treasures into the world,
33 you need:
34 * Treasurer
35 * at least one treasure registration mod
36 * at least one treasure spawning mod
38 === treasurer registration mod ===
39 Firstly, there are the treasure registration mods (TRMs). The task of TRMs is to tell
40 Treasurer which items does it have to offer, which relative appearance probabilities these
41 treasures should have, how “precious” the treasure is considered (on a scale from 0 to 10)
42 , optionally how big the stack of items should be and optionally how much worn out it is.
43 TRMs must depend on at least two mods: On treasurer and on the mod or mods
44 where the items are defined. Technically, a TRM consists of nothing more than a long
45 list of “registration” function calls. While this seems trivial, the task of balancing
46 out probabilties and balancing out preciousness levels of treasures is not trivial
47 and it may take a long time to get right.
49 It is strongly recommended that a TRM really does nothing
50 more than registering treasures (and not defining items, for example). If you want
51 to make your mod compatible to Treasurer, don’t change your mod, write a TRM for
52 it instead.
54 There is an example TRM, called “`trm_default_example`”. It registers some items
55 of the default as treasures. Unsurprisingly, it depends on `treasurer` and `default`.
57 === treasurer spawning mods ===
58 Secondly, there are the treasure spawning mods (TSMs). The task of a TSM is to somehow
59 distribute the available treasures into the world. This is also called “treasure
60 spawning”. How exactly the TSM spawns the treasures is completely up the TSM. But a
61 TSM has to request Treasurer to get some random treasures to distribute. A TSM may
62 optionally request to filter out treasures outside certain preciousness levels, so
63 it can be 
64 Treasurer can not guarantee to return the requestet amount of treasures, it may
65 return an empty table, for two reasons:
67 * There is no TRM activated. There must be at least one to work
68 * The preciousness filter filtered out. This problem can be fixed by installing more
69 TRMs or by balancing the existing TRMs to cover as many preciousness levels as
70 possible. It also may be that the range specified by the TSM was too small. It is
71 recommended to keep the requested range at least of a size of 1.
72 Treasurer does, however, guarantee that the returned treasures are always in the
73 requested boundsa.
75 A TSM has to at least depend on Treasurer.
76 Like for TRMs, it is strongly recommended that a TSM does nothing more than spawning
77 treasures. This does not exclude the possibility that a TSM does not depend
78 on any other mod.
80 There are two example TSMs. The first one is a very basic one and called “`tsm_gift_example`”.
81 It gives a “welcome gift” (1 random treasure) to players who just joined the server
82 or who respawn. The preciousness filter is not used. It does only depend on Treasurer.
83 The second one is called “`tsm_chests_example`” and pretty advanced for an example.
84 It places chests of the mod “default” between 20 and 200 node lenghts below the water
85 surface and puts 1-6 random treasures into these. The lower the chest, the higher
86 the preciousness. It depends on treasurer and default (for the chests, of course).
88 === Recap ===
89 TRMs define treasures, TSMs spawn them. Treasurer manages the pool of available treasures.
90 TRMs and TSMs do not have to know anything from each other.
91 TRMs and TSMs do not neccessarily have to change any line of code of other mods to function.
92 Treasurer depends on nothing.
94 Important: It should always only be neccessary for TRMs and TSMs to depend on Treasurer.
95 All other mods do NOT HAVE TO and SHOULD NOT depend on Treasurer.
99 === On rarity and preciousness ===
100 ==== rarity ====
101 Rarity in Treasurer works in a pretty primitive way: The relative rarities of all
102 treasures from the treasure pool are simply all added up. The probabilitiy of one
103 certain treasure is then simply the rarity value divided by the sum.
105 ==== preciousness ====
106 How “precious” an item is, is highly subjective and also not always easy to categorize.
107 Preciousness in Treasurer’s terms should be therefore viewed as “utility” or as
108 “reward level” or “strength” or even “beauty” or whatever positive attributes you can
109 think of for items.
110 So, if you create a TRM and your treasure is something you want the player work
111 hard for, assign it a high preciousness. Everyday items that are already easy to
112 obtain in normal gameplay certainly deserve a lower precious than items that are
113 expensive to craft.
114 If your treasure consists of a powerful
115 item, assign it a high preciousness. When in doubt, try to value gameplay over
116 personal taste. Remember that TSMs can (and will!) filter out treasures based
117 on their preciousness.
118 For TSM authors, consider preciousness this way: If the trouble the player has
119 to get through to in order to obtain the treasure is high, better filter
120 out unprecious treasures. If your TSM distributes many treasures all over the world and these
121 are easy to obtain, filter out precious treasures.
123 TSMs also can just completely ignore preciousness, then the given treasures base
124 on sheer luck.
126 ==== Recap ====
127 Rarity determines the chance of a treasure, whereas preciousness determines
128 the difficulty to obtain it.
130 == Overview of examples ==
131 - `trm_default_example` - registers items of default mod
132 - `tsm_chests_example` - spawns chests (from the default mod)
133 - `tsm_gift_example` - gives one treasure as a “welcome gift” to joined or respawned players
135 == Treasurer API documentation ==
136 === API documentation for treasure registration mods ===
137 The API consists of one function, which is called “`treasurer.register_treasure`”.
139 ==== `treasurer.register_treasure` ====
140 Registers a new treasure (this means the treasure will be ready to be spawned by treasure spawning mods).
142 This function does some basic parameter checking to catch the most obvious
143 mistakes. If invalid parameters have been passed, the input is rejected and
144 the function returns false. However, it does not cover every possible
145 mistake, so some invalid treasures may slip through.
146                 
147 Rarity does not imply preciousness. A rare treasure may not neccessarily a
148 very precious one. A treasure chest with scorched stuff inside may be very
149 rare, but it’s certainly also very unprecious.
151 ===== Parameters =====
152 * `name`: name of resulting `ItemStack`, e.g. “`mymod:item`”
153 * `rarity`: rarity of treasure on a scale from 0 to 1 (inclusive). lower = rarer
154 * `preciousness` : subjective preciousness on a scale from 0 to 10 (inclusive). higher = more precious.
155 * `count`: optional value which specifies the multiplicity of the item. Default is 1. See `count` syntax help in this file.
156 * `wear`: optional value which specifies the wear of the item. Default is 0, which disables the wear. See `wear` syntax help in this file.
158 ===== Return value =====                
159 `true` on success, `false` on failure.
161 === data formats ===
162 format of count type:
163 ==== `count` ====
164 A `count` can be a number or a table 
166 * `number`: it’s always so many times
167 * `{min, max}`: it’s pseudorandomly between `min` and `max` times, `math.random` will be used to chose the value
168 * `{min, max, prob_func}`: it’s between `min` and `max` times, and the value is given by `prob_func` (see below)
170 ==== `wear` ====
171 Completely analogous to `count`.
173 ==== Format of `prob_func` function ====
174 There are no parameters.
176 It returns a random or pseudorandom number between 0 (inclusive) and 1 (exclusive).
178 `prob_func` is entirely optional, if it’s not used, treasurer will
179 default to using `math.random`. You can use `prob_func` to define your own
180 “randomness” function, in case you don’t wish your values to be evenly
181 distributed.
183 === API documentation for treasure spawning mods ===
184 The API consists of one function, called “`treasurer.select_random_treasures`”.
186 ==== `treasurer.select_random_treasures` ====
187 Request some treasures from treasurer.
189 ===== Parameters =====
190 * `count`: (optional) amount of treasures. If this value is `nil`, Treasurer assumes a default of 1.
191 * `minimal_preciousness`: (optional) don’t consider treasures with a lower preciousness. If `nil`, there’s no lower bound.
192 * `maximum_preciousness`: (optional) don’t consider treasures with a higher preciousness. If `nil`, there’s no upper bound.
194 ===== Return value =====
195 A table of `ItemStacks` (the requested treasures). It may be empty.