Page 1 of 1

productivity_bonus loss problem

Posted: Thu Aug 20, 2026 11:04 am
by Xeon257
Hello. I am trying to implement a feature by controlling LuaRecipe's productivity_bonus as shown below.

Code: Select all

recipes["dps-ammo_apfsds-shell_"..i].productivity_bonus = probability_0001 * (total_probability - ptyp.main_product.shared_probability.max) * 100000
However, it seems there is an issue where this value is initialized based on specific conditions. Is there a special condition under which this value is initialized?

Re: productivity_bonus loss problem

Posted: Thu Aug 20, 2026 12:13 pm
by Rseding91
When technology effects are reset those values are reset to 0 and calculated using the technology effects.

Re: productivity_bonus loss problem

Posted: Thu Aug 20, 2026 1:22 pm
by Xeon257
I'm sorry. Could you please be a little more specific?

Re: productivity_bonus loss problem

Posted: Thu Aug 20, 2026 1:33 pm
by boskid
If you want more specific answers, please ask more specific questions and show more code that is not working. Right now this topic looks like a puzzle in itself and so do not expect precise answers.

Re: productivity_bonus loss problem

Posted: Thu Aug 20, 2026 1:42 pm
by Xeon257
The full text of the function is as follows.

Code: Select all

local function _research_update(e)
  if e.research.name == "dps-tech_advanced-apfsds-shell-enhancement-chance" or
      e.research.name == "dps-tech_advanced-apfsds-shell-destruction-protection" then
        
    local force = game.forces["player"]
    local tech = force.technologies
    local recipes = force.recipes

    local lv_ec = tech["dps-tech_advanced-apfsds-shell-enhancement-chance"].level - 1
    if tech["dps-tech_advanced-apfsds-shell-enhancement-chance"].researched then
      lv_ec = lv_ec + 1
    end

    local lv_dp = tech["dps-tech_advanced-apfsds-shell-destruction-protection"].level - 1
    if tech["dps-tech_advanced-apfsds-shell-destruction-protection"].researched then
      lv_dp = lv_dp + 1
    end

    local addition_probability = lv_ec * 0.01
    local protection_probability = lv_dp * 0.05

    for i = 6, 10, 1 do
      local ptyp = recipes["dps-ammo_apfsds-shell_"..i].prototype
      local probability = ptyp.main_product.shared_probability.max + addition_probability
      local total_probability = probability / (1 - (1 - probability) * protection_probability)

      local probability_0001 = 1.0 / (ptyp.main_product.shared_probability.max * 100000)

      recipes["dps-ammo_apfsds-shell_"..i].productivity_bonus = probability_0001 * (total_probability - ptyp.main_product.shared_probability.max) * 100000
    end
  end
end
I am not sure how to phrase this question. Currently, the recipe in question is not affected by the Technology Effect or other systems. It is possible that I simply failed to discover a bug in my code.

Therefore, if there are specific conditions under which that value is initialized or disabled, I would like to know them. Then, I think I will be able to determine for sure whether the problem is due to a bug or my failure to respond to the relevant conditions.

The mod currently causing the problem is Planet DPS.

Re: productivity_bonus loss problem

Posted: Thu Aug 20, 2026 2:04 pm
by Xeon257
I apologize. When I checked the Lua object with gvv, I found that the level of the referenced LuaTechnology object was initialized to 1. I have no idea what is modifying this or why... I will look into this further.