mirror of
https://github.com/Xevion/research-multipliers.git
synced 2025-12-10 18:08:18 -06:00
optimized set-based representation
This commit is contained in:
@@ -6,8 +6,16 @@ local planet_discovery_research_multiplier = settings.startup["planet-discovery-
|
|||||||
|
|
||||||
local multiplier_mode = "override";
|
local multiplier_mode = "override";
|
||||||
|
|
||||||
|
function as_set(table)
|
||||||
|
local set = {}
|
||||||
|
for _, v in pairs(table) do
|
||||||
|
set[v] = true
|
||||||
|
end
|
||||||
|
return set
|
||||||
|
end
|
||||||
|
|
||||||
-- as defined by Factorio's technology tree; yes, some of this is redundant as they're trigger-based, but I would rather be technically correct
|
-- as defined by Factorio's technology tree; yes, some of this is redundant as they're trigger-based, but I would rather be technically correct
|
||||||
local essential_research = {
|
local essential_research = as_set({
|
||||||
"automation-science-pack",
|
"automation-science-pack",
|
||||||
"logistic-science-pack",
|
"logistic-science-pack",
|
||||||
"military-science-pack",
|
"military-science-pack",
|
||||||
@@ -25,7 +33,7 @@ local essential_research = {
|
|||||||
"planet-discovery-aquilo",
|
"planet-discovery-aquilo",
|
||||||
"cryogenic-science-pack",
|
"cryogenic-science-pack",
|
||||||
"promethium-science-pack",
|
"promethium-science-pack",
|
||||||
};
|
});
|
||||||
|
|
||||||
-- used for 'pack' multiplier mode
|
-- used for 'pack' multiplier mode
|
||||||
local science_packs = {
|
local science_packs = {
|
||||||
@@ -44,21 +52,26 @@ local science_packs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- used for detecting interplanetary research
|
-- used for detecting interplanetary research
|
||||||
local interplanetary_science_packs = {
|
local interplanetary_science_packs = as_set({
|
||||||
"metallurgic-science-pack",
|
"metallurgic-science-pack",
|
||||||
"electromagnetic-science-pack",
|
"electromagnetic-science-pack",
|
||||||
"agricultural-science-pack",
|
"agricultural-science-pack",
|
||||||
"cryogenic-science-pack",
|
"cryogenic-science-pack",
|
||||||
"promethium-science-pack",
|
"promethium-science-pack",
|
||||||
}
|
})
|
||||||
|
|
||||||
function is_essential_research(name)
|
function table.contains(table, element)
|
||||||
for _, essential_name in pairs(essential_research) do
|
for _, value in pairs(table) do
|
||||||
if (name == essential_name) then
|
if value == element then
|
||||||
return true;
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false;
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function is_essential_research(name)
|
||||||
|
return essential_research[name] == true;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- infinite research generally has a finite number of defined 'levels', ones that don't have a formula. this function does not account for them.
|
-- infinite research generally has a finite number of defined 'levels', ones that don't have a formula. this function does not account for them.
|
||||||
@@ -66,7 +79,13 @@ function is_infinite_research(name)
|
|||||||
return data.raw.technology[name].unit.count == nil;
|
return data.raw.technology[name].unit.count == nil;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
function is_interplanetary_research(name)
|
function is_interplanetary_research(name)
|
||||||
|
for _, ingredient in pairs(data.raw.technology[name].unit.ingredients) do
|
||||||
|
if interplanetary_science_packs[ingredient[1]] then
|
||||||
|
return true;
|
||||||
|
end
|
||||||
|
end
|
||||||
return false;
|
return false;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user