diff --git a/README.md b/README.md index 8e15d22..6284936 100755 --- a/README.md +++ b/README.md @@ -2,20 +2,15 @@ ![Ores Stats' screenshot](screenshot.png) **_Provides informations about ores' percentages collected on map generation._** -**Version:** 0.2.0 +**Version:** 1.0.0 **Source code's license:** [EUPL v1.2][1] or later. -**Dependencies:** default (found in [Minetest Game][2]) +**Dependencies:** default, sfinv (found in [Minetest Game][2]) +**NOTE:** To update the page's values switch to another tab. __Advanced option:__ -Settings -> All Settings -> Mods -> orestats - - -__How to use:__ -Open the chat window, type the command /orestats help -To show ores' statistics in the chat window: /orestats chat -To show ores' statistics in the console window: /orestats console +Settings -> All Settings -> Mods -> ores_stats ### Installation diff --git a/changelog.md b/changelog.md index e306d99..317b6dc 100755 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - No further features planned. +## [1.0.0] - 2020-07-23 +### Added + + - Inventory's page (switch tab to update). + - Ores' relative values. + - Option to change gold's value via Settings -> All settings -> Mods -> ores_stats + +### Changed + + - Code rewritten from scratch. + - Version updated to 1.x, non backward compatible. + +### Removed + + - Console and chat output. + + + ## [0.2.0] - 2019-10-29 ### Added diff --git a/core/formspec.lua b/core/formspec.lua index a968507..9113e01 100644 --- a/core/formspec.lua +++ b/core/formspec.lua @@ -34,42 +34,42 @@ sfinv.register_page('ores_stats:ores_stats', { title = 'Ores\' Stats', get = function(self, player, context) local s_oresPerc = - ',' .. - S("Ores' percentages") .. ',' .. - '========================' .. ',' .. + ',' .. ' ' .. + S("Ores' percentages") .. ',' .. ' ' .. + '========================' .. ',' .. ' ' .. S('Coal: ') .. string.format("%.3f", ores_stats.f_percCoal) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Copper: ') .. string.format("%.3f", ores_stats.f_percCopper) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Diamonds: ') .. string.format("%.3f", ores_stats.f_percDiamonds) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Gold: ') .. string.format("%.3f", ores_stats.f_percGold) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Iron: ') .. string.format("%.3f", ores_stats.f_percIron) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Mese: ') .. string.format("%.3f", ores_stats.f_percMese) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Tin: ') .. string.format("%.3f", ores_stats.f_percTin) .. '%' .. ',' local s_oresValue = - ',' .. - S("Ores' values") .. ',' .. - '========================' .. ',' .. + ',' .. ' ' .. + S("Ores' values") .. ',' .. ' ' .. + '========================' .. ',' .. ' ' .. S('Coal: ') .. string.format("%.3f", ores_stats.f_valueCoal) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Copper: ') .. string.format("%.3f", ores_stats.f_valueCopper) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Diamonds: ') .. string.format("%.3f", ores_stats.f_valueDiamonds) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Gold: ') .. string.format("%.3f", ores_stats.f_valueGold) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Iron: ') .. string.format("%.3f", ores_stats.f_valueIron) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Mese: ') .. string.format("%.3f", ores_stats.f_valueMese) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin) - .. '%' .. ',' + .. ',' return sfinv.make_formspec(player, context, 'textlist[0,0;7.8,9.2;;' .. @@ -87,44 +87,44 @@ ores_stats.pr_UpdateFormspec = function() title = 'Ores\' Stats', get = function(self, player, context) local s_oresPerc = - ',' .. - S("Ores' percentages") .. ',' .. - '========================' .. ',' .. + ',' .. ' ' .. + S("Ores' percentages") .. ',' .. ' ' .. + '========================' .. ',' .. ' ' .. S('Coal: ') .. string.format("%.3f", ores_stats.f_percCoal) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Copper: ') .. string.format("%.3f", ores_stats.f_percCopper) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Diamonds: ') .. string.format("%.3f", ores_stats.f_percDiamonds) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Gold: ') .. string.format("%.3f", ores_stats.f_percGold) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Iron: ') .. string.format("%.3f", ores_stats.f_percIron) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Mese: ') .. string.format("%.3f", ores_stats.f_percMese) - .. '%' .. ',' .. + .. '%' .. ',' .. ' ' .. S('Tin: ') .. string.format("%.3f", ores_stats.f_percTin) .. '%' .. ',' local s_oresValue = - ',' .. - S("Ores' values") .. ',' .. - '========================' .. ',' .. + ',' .. ' ' .. + S("Ores' values") .. ',' .. ' ' .. + '========================' .. ',' .. ' ' .. S('Coal: ') .. string.format("%.3f", ores_stats.f_valueCoal) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Copper: ') .. string.format("%.3f", ores_stats.f_valueCopper) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Diamonds: ') .. string.format("%.3f", ores_stats.f_valueDiamonds) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Gold: ') .. string.format("%.3f", ores_stats.f_valueGold) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Iron: ') .. string.format("%.3f", ores_stats.f_valueIron) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Mese: ') .. string.format("%.3f", ores_stats.f_valueMese) - .. '%' .. ',' .. + .. ',' .. ' ' .. S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin) - .. '%' .. ',' + .. ',' return sfinv.make_formspec(player, context, 'textlist[0,0;7.8,9.2;;' .. diff --git a/core/functions.lua b/core/functions.lua index 4c8cceb..b659fc7 100644 --- a/core/functions.lua +++ b/core/functions.lua @@ -36,3 +36,36 @@ ores_stats.fn_CalcPercentage = function(a_i_ore, a_i_total_ores) return f_percentage end + +-- Used to calculate an ore's value +ores_stats.fn_CalcValue = function(a_f_ore_percentage) + + -- Constants + local f_GOLD_PERC = 4.1 -- Average percentage + + -- Variables + local f_goldPerc, f_goldValue, f_oreRatio, f_oreValue + + f_goldPerc = ores_stats.f_percGold + + if (f_goldPerc == 0) then + f_goldPerc = f_GOLD_PERC + end + + f_goldValue = ores_stats.f_valueGold + + if (f_goldValue == 0) then + f_goldValue = ores_stats.f_GOLD_VALUE + end + + if (a_f_ore_percentage ~= 0) then + f_oreRatio = (a_f_ore_percentage / f_goldPerc) + f_oreValue = (f_goldValue / f_oreRatio) + + else + f_oreValue = 0.0 + + end + + return f_oreValue +end diff --git a/core/procedures.lua b/core/procedures.lua index 37df50b..609e8d0 100644 --- a/core/procedures.lua +++ b/core/procedures.lua @@ -243,3 +243,22 @@ ores_stats.pr_MTGupdateSaveDBvalue = function() ores_stats.t_MOD_DATABASE:set_float('f_valueTin', ores_stats.f_valueTin) end + +-- Used to calculate the Minetest Game's ores values +ores_stats.pr_CalcValues = function() + + ores_stats.f_valueCoal = ores_stats.fn_CalcValue(ores_stats.f_percCoal) + + ores_stats.f_valueCopper = ores_stats.fn_CalcValue(ores_stats.f_percCopper) + + ores_stats.f_valueDiamonds = + ores_stats.fn_CalcValue(ores_stats.f_percDiamonds) + + ores_stats.f_valueGold = ores_stats.fn_CalcValue(ores_stats.f_percGold) + + ores_stats.f_valueIron = ores_stats.fn_CalcValue(ores_stats.f_percIron) + + ores_stats.f_valueMese = ores_stats.fn_CalcValue(ores_stats.f_percMese) + + ores_stats.f_valueTin = ores_stats.fn_CalcValue(ores_stats.f_percTin) +end diff --git a/init.lua b/init.lua index fbb11a8..f9512be 100755 --- a/init.lua +++ b/init.lua @@ -32,6 +32,11 @@ ores_stats = {} -- Database handler ores_stats.t_MOD_DATABASE = minetest.get_mod_storage() +-- Default ore value +ores_stats.f_GOLD_VALUE = minetest.settings:get('ores_stats_gold_value') + or 50.0 + + -- -- Variables -- @@ -56,7 +61,7 @@ local pr_LogMessage = function() or (s_LOG_LEVEL == 'info') or (s_LOG_LEVEL == 'verbose') then - minetest.log('action', '[Mod] Ores Stats [v0.3.0] loaded.') + minetest.log('action', '[Mod] Ores Stats [v1.0.0] loaded.') end end @@ -84,6 +89,7 @@ pr_LoadSubFiles() ores_stats.pr_MTGupdateFromDB() ores_stats.pr_MTGupdateFromDBperc() +ores_stats.pr_MTGupdateFromDBvalue() -- Voxel manipulator minetest.register_on_generated(function() @@ -98,9 +104,11 @@ minetest.register_on_generated(function() ores_stats.pr_CalcTotalOres() ores_stats.pr_OresPercentages() + ores_stats.pr_CalcValues() ores_stats.pr_MTGupdateSaveDB() ores_stats.pr_MTGupdateSaveDBperc() + ores_stats.pr_MTGupdateSaveDBvalue() ores_stats.pr_UpdateFormspec() diff --git a/locale/ores_stats.it.tr b/locale/ores_stats.it.tr index b50b892..e581829 100644 --- a/locale/ores_stats.it.tr +++ b/locale/ores_stats.it.tr @@ -8,3 +8,4 @@ Gold: =Oro: Mese: =Mese: Diamonds: =Diamanti: Ores' percentages=Percentuali dei minerali +Ores' values=Valori dei minerali diff --git a/locale/template.txt b/locale/template.txt index 18467bd..9542d74 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -8,3 +8,4 @@ Gold: = Mese: = Diamonds: = Ores' percentages= +Ores' values= diff --git a/settingtypes.txt b/settingtypes.txt index 69aaf13..23f6745 100755 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,4 +1,4 @@ -# ENG: Enable the profiler? +# ENG: Default gold value. # -# ITA: Abilitare le informazioni statistiche? -ores_stats_profiler (Ores' Statistics profiler) bool false +# ITA: valore predefinito dell'oro. +ores_stats_gold_value (Gold value) float 50.0