z_mirror/Krastorio2

git clone https://git.raiguard.me/z_mirror/Krastorio2

Caleb HeuerFix that numerous technologies were missing science pack prerequisitescd1a2400

k2so-fixes
1.6 KiB53 linesraw
1local data_util = require("data-util")
2
3--- @param technology data.TechnologyPrototype
4--- @param target_prerequisite_name data.TechnologyID
5--- @return boolean found
6local function find_prerequisite(technology, target_prerequisite_name)
7  for _, prerequisite_name in pairs(technology.prerequisites or {}) do
8    if prerequisite_name == target_prerequisite_name then
9      return true
10    end
11    local prerequisite = data.raw.technology[prerequisite_name]
12    assert(prerequisite, "Prerequisite " .. prerequisite_name .. "is not a valid technology.")
13    if find_prerequisite(prerequisite, target_prerequisite_name) then
14      return true
15    end
16  end
17  return false
18end
19
20for _, technology in pairs(data.raw.technology) do
21  local unit = technology.unit
22  if not unit then
23    goto continue
24  end
25
26  local ingredients = unit.ingredients
27  if not ingredients then
28    goto continue
29  end
30
31  local highest_pack = ingredients[#ingredients]
32  if not highest_pack then
33    goto continue
34  end
35
36  local highest_pack_name = highest_pack[1]
37  if not highest_pack_name then
38    goto continue
39  end
40
41  -- This assumes that there will either be an exact matching technology or that the science pack has a recipe with its same name.
42  local science_pack_tech = data.raw.technology[highest_pack_name]
43    or data_util.get_technology_for_recipe(highest_pack_name)
44  if not science_pack_tech or science_pack_tech.name == technology.name then
45    goto continue
46  end
47
48  if not find_prerequisite(technology, science_pack_tech.name) then
49    log(technology.name .. ": " .. science_pack_tech.name)
50  end
51
52  ::continue::
53end