Skip to content

Commit

Permalink
Frozen (#50)
Browse files Browse the repository at this point in the history
* pyPP better error messaging

* Fix crash

* Error handling v2

* Disable dev & cache mode that was accidentally enabled

* Error handling v3

* Error handling v4

* Stop ftmk compaining

* volcanoes

---------

Co-authored-by: Alex ten Brink <alextenbrink@gmail.com>
  • Loading branch information
notnotmelon and Septiple authored May 28, 2024
1 parent 5ce7623 commit fe101cc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 39 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 0.2.24
Date: 2024-??-??
Bugfixes:
Changes:
- Whenever pyPP encounters a dependency cycle, it will now print the items involved in the cycle to the logs.
- Fix productivity blacklist being overly general and including recipes like empty barrels
---------------------------------------------------------------------------------------------------
Version: 0.2.23
Expand Down
34 changes: 21 additions & 13 deletions data-final-fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,26 @@ if dev_mode then
science_packs[pack.name or pack[1]] = true
end

add_science_pack_dep(tech, 'utility-science-pack', 'military-science-pack')

if mods['pyalienlife'] then
add_science_pack_dep(tech, 'utility-science-pack', 'py-science-pack-4')
add_science_pack_dep(tech, 'production-science-pack', 'py-science-pack-3')
add_science_pack_dep(tech, 'chemical-science-pack', 'py-science-pack-2')
add_science_pack_dep(tech, 'logistic-science-pack', 'py-science-pack-1')
add_science_pack_dep(tech, 'py-science-pack-4', 'military-science-pack')
end

if mods['pyalternativeenergy'] then
add_science_pack_dep(tech, 'production-science-pack', 'military-science-pack')
if mods.pystellarexpedition then
for i = 1, #config.SCIENCE_PACKS - 1 do
local pack = config.SCIENCE_PACKS[i]
local next = config.SCIENCE_PACKS[i + 1]
add_science_pack_dep(tech, next, pack)
end
else
add_science_pack_dep(tech, 'utility-science-pack', 'military-science-pack')

if mods['pyalienlife'] then
add_science_pack_dep(tech, 'utility-science-pack', 'py-science-pack-4')
add_science_pack_dep(tech, 'production-science-pack', 'py-science-pack-3')
add_science_pack_dep(tech, 'chemical-science-pack', 'py-science-pack-2')
add_science_pack_dep(tech, 'logistic-science-pack', 'py-science-pack-1')
add_science_pack_dep(tech, 'py-science-pack-4', 'military-science-pack')
end

if mods['pyalternativeenergy'] then
add_science_pack_dep(tech, 'production-science-pack', 'military-science-pack')
end
end
end

Expand Down Expand Up @@ -298,7 +306,7 @@ for _, tech in pairs(data.raw.technology) do
tech_ingredients_to_use[pack] = ingredient.amount or ingredient[2]
end
end

-- Add any missing ingredients that we want present
for _, ingredient in pairs(config.TC_TECH_INGREDIENTS_PER_LEVEL[highest_science_pack]) do
tech_ingredients_to_use[ingredient.name or ingredient[1]] = ingredient.amount or ingredient[2]
Expand Down
2 changes: 1 addition & 1 deletion data.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pypp_registered_cache_files = {}
_G.pypp_registered_cache_files = {}

-- Usage example (add in data-updates phase):
-- register_cache_file({"pycoalprocessing", "pyfusionenergy"}, "__pyfusionenergy__/cached-configs/pycoalprocessing+pyfusionenergy.lua")
Expand Down
2 changes: 2 additions & 0 deletions prototypes/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ if mods.pystellarexpedition then
end
config.STARTING_ITEMS:add('ice')
config.STARTING_ITEMS:add('silicate-stone')
config.STARTING_ITEMS:add('cobalt-ore')
config.STARTING_ITEMS:add('organic-nexelit')
end

if mods['pyalternativeenergy'] then
Expand Down
37 changes: 18 additions & 19 deletions prototypes/functions/auto_tech.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,30 @@ function auto_tech:run()
sp_ts:run()

local fg2 = fg:copy()
local error_found
local error_message

error_found, ts = self:topo_sort_with_sp(fg, spg, parser.science_packs)
error_message, ts = self:topo_sort_with_sp(fg, spg, parser.science_packs)

if error_message then
local msg = '\n\nERROR: Dependency loop detected\n' .. error_message
local msg = "\n\nERROR: Dependency loop detected\n" .. error_message
error(msg)
end

self:add_original_prerequisites(fg, fg2, ts.level)

error_found, ts = self:topo_sort_with_sp(fg2, spg, parser.science_packs)
error_message, ts = self:topo_sort_with_sp(fg2, spg, parser.science_packs)

if error_message then
local msg = '\n\nERROR: Dependency loop detected\n' .. error_message
local msg = "\n\nERROR: Dependency loop detected\n" .. error_message
error(msg)
end

local tg = self:extract_tech_graph(fg2)
local tech_ts = fz_topo.create(tg)
error_found = tech_ts:run(false, false)
error_message = tech_ts:run(false, false)

if error_message then
local msg = '\n\nERROR: Dependency loop detected\n' .. error_message
local msg = "\n\nERROR: Dependency loop detected\n" .. error_message
error(msg)
end

Expand All @@ -154,11 +154,11 @@ function auto_tech:run()

-- Set science pack order
for _, node in pairs(spg.nodes) do
science_pack_order(node.name, string.format('%03d-%06d', sp_ts.level[node.key] or 0, ts.level[node.key]))
science_pack_order(node.name, string.format("%03d-%06d", sp_ts.level[node.key] or 0, ts.level[node.key]))
local sp = data.raw.tool[node.name]

sp.subgroup = 'science-pack'
sp.order = string.format('%03d-%06d', sp_ts.level[node.key] or 0, ts.level[node.key])
sp.subgroup = "science-pack"
sp.order = string.format("%03d-%06d", sp_ts.level[node.key] or 0, ts.level[node.key])
sp_level[node.name] = sp_ts.level[node.key] or 0

if sp_level[sp.name] > max_level then
Expand Down Expand Up @@ -305,23 +305,22 @@ function auto_tech:topo_sort_with_sp(fg, sp_graph, science_packs)
end

local ts = fz_topo.create(fg)
local error_found = ts:run(false, self.verbose_logging)

for _, link in pairs(sp_links) do
fg:remove_link(link.from, link.to, link.from.name)
end
local error_found, errors = ts:run(false, self.verbose_logging)

if error_found then
log("RESTARTING without SP links")
log('RESTARTING WITHOUT SP LINKS')
for _, link in pairs(sp_links) do
fg:remove_link(link.from, link.to, link.from.name)
end
ts = fz_topo.create(fg)
error_found = ts:run(false, self.verbose_logging)
error_found, errors = ts:run(false, self.verbose_logging)
end

local error_message
if error_found then
error_message = ''
error_message = ""
for key, _ in pairs(errors) do
error_message = error_message .. key .. '\n'
error_message = error_message .. key .. "\n"
end
end

Expand Down
16 changes: 11 additions & 5 deletions prototypes/functions/fz_topo_sort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ end
function fz_topo:run(check_ancestry, logging)
self.queue(self.work_graph.start_node)
self.level[self.work_graph.start_node.key] = 1
local recipes_with_issues = {}

while not queue.is_empty(self.queue) do
local node = self.queue()
Expand Down Expand Up @@ -88,16 +89,21 @@ function fz_topo:run(check_ancestry, logging)
self.queue(to_node)
self.level[to_node.key] = self.level[node.key] + 1
if logging then log(" - Queued: " .. to_key) end
elseif logging then
log(" - Not queued: " .. to_key)
for _, e in self.work_graph:iter_links_to(to_node) do
log(" - " .. e:from() .. " : " .. e.label)
recipes_with_issues[to_key] = nil
else
recipes_with_issues[to_key] = true
if logging then
log(" - Not queued: " .. to_key)
for _, e in self.work_graph:iter_links_to(to_node) do
log(" - " .. e:from() .. " : " .. e.label)
end
end
end
end
end

return table.any(self.graph.nodes, function (n) return not n.ignore_for_dependencies and not self.sorted[n.key] end)
local has_error = table.any(self.graph.nodes, function (n) return not n.ignore_for_dependencies and not self.sorted[n.key] end)
return has_error, recipes_with_issues
end


Expand Down

0 comments on commit fe101cc

Please sign in to comment.