mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
commit
2312139494
@ -282,7 +282,7 @@ local Config = {
|
||||
|
||||
-- add or remove a table entry to add or remove a unlockable item from the mall.
|
||||
-- format: {unlock_at_level, price, prototype_name},
|
||||
unlockables = require('map_gen.Diggy.FormatMarketItems').initalize_unlockables(
|
||||
unlockables = require('map_gen.Diggy.FormatMarketItems').initialize_unlockables(
|
||||
{
|
||||
{level = 1, price = 50, name = 'raw-fish'},
|
||||
{level = 1, price = 50, name = 'steel-axe'},
|
||||
@ -312,7 +312,7 @@ local Config = {
|
||||
},
|
||||
|
||||
-- controls the formula for calculating level up costs in stone sent to surface
|
||||
difficulity_scale = 25, -- Diggy default 25. Higher increases difficulity, lower decreases (Only affects the stone requirement/cost to level up) (Only integers has been tested succesful)
|
||||
difficulty_scale = 25, -- Diggy default 25. Higher increases difficulity, lower decreases (Only affects the stone requirement/cost to level up) (Only integers has been tested succesful)
|
||||
start_stone = 50, -- Diggy default 50. This sets the price for the first level.
|
||||
cost_precision = 2, -- Diggy default 2. This sets the precision of the stone requirements to level up. E.g. 1234 becomes 1200 with precision 2 and 1230 with precision 3.
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ end
|
||||
-- @field price number of the price in the configured currency_item to buy the item in the market
|
||||
-- @field name string of the factorio prototype-name for the entity to be unlocked
|
||||
--
|
||||
function FormatMarketItems.initalize_unlockables(items)
|
||||
function FormatMarketItems.initialize_unlockables(items)
|
||||
local unlockables = {}
|
||||
for _, item in ipairs(items) do
|
||||
add(item.level, item.price, item.name)
|
||||
|
@ -1,10 +1,8 @@
|
||||
-- dependencies
|
||||
local Config = require 'map_gen.Diggy.config'.features.MarketExchange
|
||||
local Config = require 'map_gen.Diggy.Config'.features.MarketExchange
|
||||
|
||||
-- this
|
||||
local MarketUnlockables = {}
|
||||
local marked_prototype_items = {}
|
||||
local insert = table.insert
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
local log10 = math.log10
|
||||
@ -17,37 +15,37 @@ local log10 = math.log10
|
||||
--
|
||||
local function truncate(precision, precise_number)
|
||||
local number = precise_number
|
||||
local numberlen = floor(log10(number)+1)
|
||||
precision = (numberlen >= 8) and (precision+1) or precision
|
||||
local exponent = numberlen-precision
|
||||
local number_length = floor(log10(number)+1)
|
||||
precision = (number_length >= 8) and (precision+1) or precision
|
||||
local exponent = number_length -precision
|
||||
number = number/10^exponent
|
||||
number = floor(number)*10^exponent
|
||||
return number, numberlen
|
||||
return number, number_length
|
||||
end
|
||||
|
||||
--- Handles the level requirement to stone sent. Calculates based on a forumla one number corresponding to that levels cost
|
||||
-- You can configure this in Diggy.Config.lua under features.MarketExhange
|
||||
--- Handles the level requirement to stone sent. Calculates based on a formula one number corresponding to that levels cost
|
||||
-- You can configure this in Diggy.Config.lua under features.MarketExchange
|
||||
-- @param level number of a level
|
||||
-- @returns number of cost corresponding to the level based on a calculation
|
||||
--
|
||||
function MarketUnlockables.calculate_level(level) -- all configurable variables must be integers.
|
||||
local b = floor(Config.difficulity_scale) or 25 -- Default 25 <-- Controls how much stone is needed.
|
||||
local b = floor(Config.difficulty_scale) or 25 -- Default 25 <-- Controls how much stone is needed.
|
||||
local start_value = floor(Config.start_stone) or 50 -- The start value/the first level cost
|
||||
local formula = b*(level^3)+(start_value-b)
|
||||
|
||||
local precision = floor(Config.cost_precision) or 2 -- Sets the precision
|
||||
|
||||
-- Truncates to the precision and prevents dublicates by incrementing with 5 in the third highest place.
|
||||
-- First evaluates loosly if the previous level requirement would return same number after truncating.
|
||||
-- Truncates to the precision and prevents duplicates by incrementing with 5 in the third highest place.
|
||||
-- First evaluates loosely if the previous level requirement would return same number after truncating.
|
||||
-- If true evaluates down all levels to level 1 for the precise number
|
||||
-- (In case itself got incremented)
|
||||
-- Only useful if three or more values turns out to be the same after truncating, thus the loosly evaluation to save an expensive recursive function
|
||||
local number, numberlen = truncate(precision, formula)
|
||||
-- Only useful if three or more values turns out to be the same after truncating, thus the loosely evaluation to save an expensive recursive function
|
||||
local number, number_lenght = truncate(precision, formula)
|
||||
local prev_number = truncate(precision, b*((level-1)^3)+(start_value-b))
|
||||
if (level ~= 1 and number == prev_number) then
|
||||
local prev_number = MarketUnlockables.calculate_level((level-1))
|
||||
while (prev_number >= number) do
|
||||
number = (prev_number < number) and number or ceil(number + (5*10^(numberlen-3)))
|
||||
number = (prev_number < number) and number or ceil(number + (5*10^(number_lenght -3)))
|
||||
end
|
||||
end
|
||||
return number
|
||||
|
Loading…
x
Reference in New Issue
Block a user