Module Deficit

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Module Deficit

Post by BraveCaperCat »

Hi! I'm BraveCaperCat, author of multiple mods. Most relevant of which is Quality Assurance. Currently I'm working on the 1.1.2 update, including a toggle for AMS machines. I'm trying to add a setting for how many modules are added to the AMS machines, but as AMS machines have a crafting speed deficit of 0.8 for their 2 additional modules - I have no idea how to calculate the crafting speed deficit for more/less modules. Crafting speed has to be above 0, and I'd like it if I could have better crafting speed if I remove modules (insert a negative value into the setting). In other words: a function to turn the difference in modules between the original machine and the AMS one, into a crafting speed multiplier. It should also be below 1 multiplier for more than 0 additional modules.

Your function will be added to the mod in the 1.2.0 update, when I'll add the module settings. You will also be credited as the creator of the function.
Last edited by BraveCaperCat on Tue Nov 12, 2024 11:57 am, edited 1 time in total.
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Module Deficit

Post by BraveCaperCat »

I guess I'll have to not make version 1.2.0 then. :(
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4581
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Module Deficit

Post by mmmPI »

what do you call AMS ?
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Module Deficit

Post by BraveCaperCat »

mmmPI wrote: Tue Nov 12, 2024 10:23 am what do you call AMS ?
Quality Assurance on the Mod Portal
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4581
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Module Deficit

Post by mmmPI »

If i understand correctly, this is the relevant piece of code you have :

Code: Select all

if AMSMachine.module_slots ~= nil then
                    AMSMachine.module_slots = AMSMachine.module_slots + 2
                else
                    AMSMachine.module_slots = 2
                end
                AMSMachine.crafting_speed = AMSMachine.crafting_speed * 0.8
                
And you need to replace the 0.8 which is hardcoded by a dynamic value, which depends on the settings which can change the number of module slots. For which you require a math function.

Is this correct ?
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Module Deficit

Post by BraveCaperCat »

mmmPI wrote: Tue Nov 12, 2024 2:20 pm If i understand correctly, this is the relevant piece of code you have :

Code: Select all

if AMSMachine.module_slots ~= nil then
                    AMSMachine.module_slots = AMSMachine.module_slots + 2
                else
                    AMSMachine.module_slots = 2
                end
                AMSMachine.crafting_speed = AMSMachine.crafting_speed * 0.8
                
And you need to replace the 0.8 which is hardcoded by a dynamic value, which depends on the settings which can change the number of module slots. For which you require a math function.

Is this correct ?
Yes. :)
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4581
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Module Deficit

Post by mmmPI »

I think the math you are looking for are something like a remap function. That would take as input 2 range of value, one being the number of module slots, from 0 to whatever integer, and the other range would be the crafting speed, from 0 to whatever value. Then picking any value from the first range, would have a corresponding value on the second. ( each number of module slot gets its crafting speed).

This should work :

low2 + (value - low1) * (high2 - low2) / (high1 - low1)

source

considering :

low1 is the minimum number of module slot
high1 is the maximum number of module slot

low2 the minimum crafting speed
high2 the maximum crafting speed

value being the number in settings.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Module Deficit

Post by BraveCaperCat »

mmmPI wrote: Wed Nov 13, 2024 6:14 am I think the math you are looking for are something like a remap function. That would take as input 2 range of value, one being the number of module slots, from 0 to whatever integer, and the other range would be the crafting speed, from 0 to whatever value. Then picking any value from the first range, would have a corresponding value on the second. ( each number of module slot gets its crafting speed).

This should work :

low2 + (value - low1) * (high2 - low2) / (high1 - low1)

source

considering :

low1 is the minimum number of module slot
high1 is the maximum number of module slot

low2 the minimum crafting speed
high2 the maximum crafting speed

value being the number in settings.
I implemented this feature:

Code: Select all

-- Above here is a single function which gets configuration values, as well as the new block-list.
local function GetCraftingSpeedMultiplier(ModuleSlotDifference)
    return 0.01 + (ModuleSlotDifference - ( -10 )) * (100 - 0.01) / ( 10 - ( -10 ))
end
-- More code stuff where this comment is.
local AddedModuleSlots = config("added-module-slots")
local CraftingSpeedMultiplier = 1
if AMSMachine.module_slots == nil then
    AMSMachine.module_slots = 0
end
if AMSMachine.module_slots + AddedModuleSlots < 0 then
    CraftingSpeedMultiplier = GetCraftingSpeedMultiplier(AMSMachine.module_slots)
    AMSMachine.module_slots = 0
elseif AddedModuleSlots ~= 0 then
    CraftingSpeedMultiplier = GetCraftingSpeedMultiplier(AddedModuleSlots)
    AMSMachine.module_slots = AMSMachine.module_slots + AddedModuleSlots
end
AMSMachine.crafting_speed = AMSMachine.crafting_speed * CraftingSpeedMultiplier
-- The code continues this way...
There is a problem though. This code doesn't work right as you can see here and this image:
sGXYFax.png
sGXYFax.png (633.74 KiB) Viewed 850 times
Which is linked on the issue page.
In the previous version of the mod, I expect the crafting speed of this machine to be 1.
How do I fix this (preferably, I want the crafting speed of this machine to be anywhere below 1.25.
(Also, the machine is supposed to be called "Assembling machine 3 AMS version")
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4581
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Module Deficit

Post by mmmPI »

At this point i feel you need precise understanding of the desired output to make the math function. I can only point at the general direction but the precise bound of what is allowed as number of slot of crafting, and what relation you expect between those, i have no clue.

What i pointed at was liner interpolation, maybe more explanation will help, because it is just a rough formula/technique but you need to apply it with some adjustments to make it fit your case well.

It may not fit the original description exactly with the "deficit" concept, but it can be used to fit the general usecase of giving a crafting speed to the machine based on the number of module slot in settings.


With

0.01 + (ModuleSlotDifference - ( -10 )) * (100 - 0.01) / ( 10 - ( -10 ))

considering :

low2 + (value - low1) * (high2 - low2) / (high1 - low1)

-10 => low1 is the minimum number of module slot
10 => high1 is the maximum number of module slot

0.01=> low2 the minimum crafting speed
100=> high2 the maximum crafting speed

You get 75, which is close to the max crafting speed of 100, 75% of it, this is because the number of module slot choosen is close to 10, regarding the range [-10 : 10], 75% of it, ( so around 5 ).

If you want the opposite relation, the crafting speed decrease when the number of module increase, you have to adapt the formula. You can switch the low and high value and tweak a bit the parameters but if you want 1.25 crafting speed to correspond to a certain specific number of module you will have to solve the equation to choose the parameters, or ask wolfram alpha to do it.

https://www.wolframalpha.com/input?i=+0 ... olve+for+m
Post Reply

Return to “Modding discussion”