Differences From
Artifact [7230727dfc]:
1 1 -- liquid.lua
2 2 -- the liquid registry is used to keep track of abstract liquids,
3 3 -- their properties, and their representation in-game.
4 4
5 5 sorcery.registry.mk('liquid', false)
6 +local mkunit = function(unit,fac)
7 + return function(amt)
8 + -- allow division for more accurate results
9 + if fac >= 0 then
10 + amt = amt * fac
11 + else
12 + amt = amt / (-fac)
13 + end
14 + return string.format('%s %s%s', amt, unit, (amt == 1) and '' or 's')
15 + end
16 +end
6 17 sorcery.liquid = {
7 18 constants = {
8 19 drams_per_glass = 64;
20 + pints_per_glass = 0.5;
9 21 glasses_per_bottle = 3;
10 22 bottles_per_bucket = 3;
11 23 bottles_per_trough = 6;
12 - }
24 + };
25 + unit = mkunit;
13 26 }
14 27 local constants = sorcery.liquid.constants
28 +sorcery.liquid.units = {
29 + dram = mkunit('dram', constants.drams_per_glass);
30 + pint = mkunit('pint', constants.pints_per_glass);
31 + draught = mkunit('draught', -3);
32 + drink = mkunit('drink', 1);
33 +};
15 34
16 35 local L = sorcery.lib
17 36 local log = sorcery.logger('liquid')
18 37
19 38 sorcery.liquid.fill_from_basin = function(ctr, liquid, basin)
20 39 local liq = sorcery.register.liquid.db[liquid]
21 40 local filled
................................................................................
164 183 }
165 184 };
166 185 })
167 186 end
168 187 end
169 188 sorcery.liquid.mktrough()
170 189
171 -sorcery.liquid.measure_default = function(amt)
172 - return string.format('%s drams', amt*constants.drams_per_glass)
173 -end
190 +sorcery.liquid.measure_default = sorcery.liquid.units.dram
174 191
175 192 sorcery.liquid.container = function(liq, ctr)
176 193 return liq.containers[({
177 194 bottle = 'vessels:glass_bottle';
178 195 glass = 'vessels:drinking_glass';
179 196 keg = 'sorcery:keg';
180 197 trough = 'sorcery:trough';