Page 1 of 1

[SOLVED]Updating research not working

Posted: Mon Jul 04, 2016 1:44 pm
by vlczero
Hi,
For my mod Tankwerkz i am adding additional effects to vanilla research and this works when starting a new game, but does not for a existing save that already has the research unlocked.

Adding additional effect to bullet-damage-1:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
Migration file:

Code: Select all

game.reload_script()

for index, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()
end
I also tested

Code: Select all

game.reload_script()

for index, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()
  
  local technologies = force.technologies;

  technologies["bullet-damage-1"].reload()
end
But this is also not working.

Does anyone know what i am doing wrong here?

Re: Updating research not working

Posted: Mon Jul 04, 2016 2:10 pm
by prg
Maybe you could just see if the technology is already researched, then run set_ammo_damage_modifier manually.

Also,
vlczero wrote:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
if another mod did the same thing, one would overwrite the other one's changes, better use table.insert() here.

Re: Updating research not working

Posted: Mon Jul 04, 2016 4:24 pm
by vlczero
prg wrote:Maybe you could just see if the technology is already researched, then run set_ammo_damage_modifier manually.

Also,
vlczero wrote:

Code: Select all

data.raw["technology"]["bullet-damage-1"].effects[2] = 
{
  type = "ammo-damage",
  ammo_category = "heavy-mg",
  modifier = "0.1"
}
if another mod did the same thing, one would overwrite the other one's changes, better use table.insert() here.

Thx for the tip on set_ammo_damage_modifier and table.insert

The working migration:

Code: Select all

for index, force in pairs(game.forces) do
  local technologies = force.technologies;

  local researchList = {
    { research_name = "bullet-damage", ammo_category = "heavy-mg", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2, 0.4 }},
    { research_name = "rocket-damage", ammo_category = "hydra-rocket", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2 }},
    { research_name = "flamethrower-damage", ammo_category = "tank-flame-thrower", modifiers = {0.1, 0.1, 0.2, 0.2, 0.2, 0.4 }}
  }

  for v, item in pairs(researchList) do
    for k, modifier in ipairs(item.modifiers) do
      name = item.research_name .. "-" .. k
      if technologies[name].researched then
        force.set_ammo_damage_modifier(item.ammo_category , force.get_ammo_damage_modifier(item.ammo_category) + modifier)
      end
    end
  end

end