summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-12-22 23:25:36 +0100
committerAki <please@ignore.pl>2021-12-22 23:25:36 +0100
commite617261dd12e3db9e2c547040147390a0135d6c5 (patch)
treecab67a2ccc98dc7e63328fc2794f1d091b4315df
downloadpi-calc-e617261dd12e3db9e2c547040147390a0135d6c5.zip
pi-calc-e617261dd12e3db9e2c547040147390a0135d6c5.tar.gz
pi-calc-e617261dd12e3db9e2c547040147390a0135d6c5.tar.bz2
Implemented a naive calculator for PI raw resourcesHEADmaster
-rw-r--r--Calculator.lua32
-rw-r--r--Material.lua90
-rw-r--r--Quantity.lua16
-rw-r--r--Recipe.lua173
-rwxr-xr-xpi-calc10
5 files changed, 321 insertions, 0 deletions
diff --git a/Calculator.lua b/Calculator.lua
new file mode 100644
index 0000000..aece972
--- /dev/null
+++ b/Calculator.lua
@@ -0,0 +1,32 @@
+local Recipe = require "Recipe"
+
+
+local
+function raw_materials_needed (quantity)
+ local recipe = Recipe[quantity.material]
+ if not recipe then
+ return {[quantity.material]=quantity.amount}
+ end
+ local total = {}
+ for _, input in pairs(recipe.input) do
+ local subtotal = raw_materials_needed(input)
+ for material, amount in pairs(subtotal) do
+ total[material] = (total[material] or 0) + amount * quantity.amount
+ end
+ end
+ return total
+end
+
+
+local
+function pretty_print (acc)
+ for material, amount in pairs(acc) do
+ print(("%d\t%q"):format(amount, material))
+ end
+end
+
+
+return {
+ raw_materials_needed=raw_materials_needed,
+ pretty_print=pretty_print,
+}
diff --git a/Material.lua b/Material.lua
new file mode 100644
index 0000000..62e4733
--- /dev/null
+++ b/Material.lua
@@ -0,0 +1,90 @@
+return {
+ -- P0
+ AqueousLiquids = "Aqueous Liquids",
+ Autotrophs = "Autotrophs",
+ BaseMetals = "Base Metals",
+ CarbonCompounds = "Carbon Compounds",
+ ComplexOrganisms = "Complex Organisms",
+ FelsicMagma = "Felsic Magma",
+ HeavyMetals = "Heavy Metals",
+ IonicSolutions = "Ionic Solutions",
+ MicroOrganisms = "Micro Organisms",
+ NobleGas = "Noble Gas",
+ NobleMetals = "Noble Metals",
+ NonCSCrystals = "Non-CS Crystals",
+ PlankticColonies = "Planktic Colonies",
+ ReactiveGas = "Reactive Gas",
+ SuspendedPlasma = "Suspended Plasma",
+ -- P1
+ Water = "Water",
+ IndustrialFibers = "Industrial Fibers",
+ ReactiveMetals = "Reactive Metals",
+ Biofuels = "Biofuels",
+ Proteins = "Proteins",
+ Silicon = "Silicon",
+ ToxicMetals = "Toxic Metals",
+ Electrolytes = "Electrolytes",
+ Bacteria = "Bacteria",
+ Oxygen = "Oxygen",
+ PreciousMetals = "Precious Metals",
+ ChiralStructures = "Chiral Structures",
+ Biomass = "Biomass",
+ OxidizingCompound = "Oxidizing Compound",
+ Plasmoids = "Plasmoids",
+ -- P2
+ Biocells = "Biocells",
+ ConstructionBlocks = "Construction Blocks",
+ ConsumerElectronics = "Consumer Electronics",
+ Coolant = "Coolant",
+ EnrichedUranium = "Enriched Uranium",
+ Fertilizer = "Fertilizer",
+ GenEnhancedLivestock = "Gen. Enhanced Livestock",
+ Livestock = "Livestock",
+ MechanicalParts = "Mechanical Parts",
+ MicrofiberShielding = "Microfiber Shielding",
+ MiniatureElectronics = "Miniature Electronics",
+ Nanites = "Nanites",
+ Oxides = "Oxides",
+ Polyaramids = "Polyaramids",
+ Polytextiles = "Polytextiles",
+ RocketFuel = "Rocket Fuel",
+ SilicateGlass = "Silicate Glass",
+ Superconductors = "Superconductors",
+ SupertensilePlastics = "Supertensile Plastics",
+ SyntheticOil = "Synthetic Oil",
+ TestCultures = "Test Cultures",
+ Transmitter = "Transmitter",
+ ViralAgent = "Viral Agent",
+ WaterCooledCPU = "Water-Cooled CPU",
+ -- P3
+ BiotechResearchReports = "Biotech Research Reports",
+ CameraDrones = "Camera Drones",
+ Condensates = "Condensates",
+ CryoprotectantSolution = "Cryoprotectant Solution",
+ DataChips = "Data Chips",
+ GelMatrixBiopaste = "Gel-Matrix Biopaste",
+ GuidanceSystems = "Guidance Systems",
+ HazmatDetectionSystems = "Hazmat Detection Systems",
+ HermeticMembranes = "Hermetic Membranes",
+ HighTechTransmitters = "High-Tech Transmitters",
+ IndustrialExplosives = "Industrial Explosives",
+ Neocoms = "Neocoms",
+ NuclearReactors = "Nuclear Reactors",
+ PlanetaryVehicles = "Planetary Vehicles",
+ Robotics = "Robotics",
+ SmartfabUnits = "Smartfab Units",
+ Supercomputers = "Supercomputers",
+ SyntheticSynapses = "Synthetic Synapses",
+ TranscranialMicrocontrollers = "Transcranial Microcontrollers",
+ UkomiSuperConductors = "Ukomi Super Conductors",
+ Vaccines = "Vaccines",
+ -- P4
+ BroadcastNode = "Broadcast Node",
+ IntegrityResponseDrones = "Integrity Response Drones",
+ NanoFactory = "Nano-Factory",
+ OrganicMortarApplicators = "Organic Mortar Applicators",
+ RecursiveComputingModule = "Recursive Computing Module",
+ SelfHarmonizingPowerCore = "Self-Harmonizing Power Core",
+ SterileConduits = "Sterile Conduits",
+ WetwareMainframe = "Wetware Mainframe",
+} \ No newline at end of file
diff --git a/Quantity.lua b/Quantity.lua
new file mode 100644
index 0000000..b0fbe81
--- /dev/null
+++ b/Quantity.lua
@@ -0,0 +1,16 @@
+local Quantity
+
+
+local metatable = {
+ __tostring = function (self)
+ return ("Quantity{%d, %q}"):format(self.amount, self.material)
+ end,
+}
+
+
+function Quantity (obj)
+ return setmetatable({amount=obj.amount or obj[1], material=obj.material or obj[2]}, metatable)
+end
+
+
+return Quantity
diff --git a/Recipe.lua b/Recipe.lua
new file mode 100644
index 0000000..ca62f62
--- /dev/null
+++ b/Recipe.lua
@@ -0,0 +1,173 @@
+local Material = require "Material"
+local Quantity = require "Quantity"
+
+
+local
+function inputs (amount, opt, ...)
+ local acc
+ local function _in (head, ...)
+ if head ~= nil then
+ table.insert(acc, Quantity{amount, head})
+ return _in(...)
+ end
+ return acc
+ end
+ if type(amount) == "table" then
+ acc = amount
+ amount = opt
+ return _in(...)
+ end
+ acc = {}
+ return _in(opt, ...)
+end
+
+
+local metatable = {
+ __tostring = function (self)
+ return ("Recipe[%q]"):format(self.output.material)
+ end
+}
+
+
+local
+function recipe (input, output, duration)
+ return setmetatable({input=input, output=output, duration=duration}, metatable)
+end
+
+
+local
+function p1 (basic, resource)
+ return recipe(
+ {Quantity{3000, resource}},
+ Quantity{20, basic},
+ 1800)
+end
+
+
+local
+function p2 (refined, first, second)
+ return recipe(
+ {Quantity{40, first}, Quantity{40, second}},
+ Quantity{5, refined},
+ 3600)
+end
+
+
+local
+function p3 (specialized, ...)
+ return recipe(
+ inputs(10, ...),
+ Quantity{3, specialized},
+ 3600)
+end
+
+
+local
+function p4_a (advanced, ...)
+ return recipe(
+ inputs(6, ...),
+ Quantity{1, advanced},
+ 3600)
+end
+
+
+local
+function p4_b (advanced, first, ...)
+ return recipe(
+ inputs({Quantity{40, first}}, 6, ...),
+ Quantity{1, advanced},
+ 3600)
+end
+
+
+local recipes = {
+ -- P1
+ p1(Material.Water, Material.AqueousLiquids),
+ p1(Material.IndustrialFibers, Material.Autotrophs),
+ p1(Material.ReactiveMetals, Material.BaseMetals),
+ p1(Material.Biofuels, Material.CarbonCompounds),
+ p1(Material.Proteins, Material.ComplexOrganisms),
+ p1(Material.Silicon, Material.FelsicMagma),
+ p1(Material.ToxicMetals, Material.HeavyMetals),
+ p1(Material.Electrolytes, Material.IonicSolutions),
+ p1(Material.Bacteria, Material.MicroOrganisms),
+ p1(Material.Oxygen, Material.NobleGas),
+ p1(Material.PreciousMetals, Material.NobleMetals),
+ p1(Material.ChiralStructures, Material.NonCSCrystals),
+ p1(Material.Biomass, Material.PlankticColonies),
+ p1(Material.OxidizingCompound, Material.ReactiveGas),
+ p1(Material.Plasmoids, Material.SuspendedPlasma),
+ -- P2
+ p2(Material.Biocells, Material.Biofuels, Material.PreciousMetals),
+ p2(Material.ConstructionBlocks, Material.ReactiveMetals, Material.ToxicMetals),
+ p2(Material.ConsumerElectronics, Material.ToxicMetals, Material.ChiralStructures),
+ p2(Material.Coolant, Material.Water, Material.Electrolytes),
+ p2(Material.EnrichedUranium, Material.ToxicMetals, Material.PreciousMetals),
+ p2(Material.Fertilizer, Material.Proteins, Material.Bacteria),
+ p2(Material.GenEnhancedLivestock, Material.Proteins, Material.Biomass),
+ p2(Material.Livestock, Material.Biofuels, Material.Proteins),
+ p2(Material.MechanicalParts, Material.ReactiveMetals, Material.PreciousMetals),
+ p2(Material.MicrofiberShielding, Material.IndustrialFibers, Material.Silicon),
+ p2(Material.MiniatureElectronics, Material.Silicon, Material.ChiralStructures),
+ p2(Material.Nanites, Material.ReactiveMetals, Material.Bacteria),
+ p2(Material.Oxides, Material.Oxygen, Material.OxidizingCompound),
+ p2(Material.Polyaramids, Material.IndustrialFibers, Material.OxidizingCompound),
+ p2(Material.Polytextiles, Material.IndustrialFibers, Material.Biofuels),
+ p2(Material.RocketFuel, Material.Electrolytes, Material.Plasmoids),
+ p2(Material.SilicateGlass, Material.Silicon, Material.OxidizingCompound),
+ p2(Material.Superconductors, Material.Water, Material.Plasmoids),
+ p2(Material.SupertensilePlastics, Material.Oxygen, Material.Biomass),
+ p2(Material.SyntheticOil, Material.Electrolytes, Material.Oxygen),
+ p2(Material.TestCultures, Material.Water, Material.Bacteria),
+ p2(Material.Transmitter, Material.ChiralStructures, Material.Plasmoids),
+ p2(Material.ViralAgent, Material.Bacteria, Material.Biomass),
+ p2(Material.WaterCooledCPU, Material.Water, Material.ReactiveMetals),
+ -- P3
+ p3(Material.BiotechResearchReports, Material.ConstructionBlocks, Material.Livestock, Material.Nanites),
+ p3(Material.CameraDrones, Material.RocketFuel, Material.SilicateGlass),
+ p3(Material.Condensates, Material.Coolant, Material.Oxides),
+ p3(Material.CryoprotectantSolution, Material.Fertilizer, Material.SyntheticOil, Material.TestCultures),
+ p3(Material.DataChips, Material.MicrofiberShielding, Material.SupertensilePlastics),
+ p3(Material.GelMatrixBiopaste, Material.Biocells, Material.Oxides, Material.Superconductors),
+ p3(Material.GuidanceSystems, Material.Transmitter, Material.WaterCooledCPU),
+ p3(Material.HazmatDetectionSystems, Material.Polytextiles, Material.Transmitter, Material.ViralAgent),
+ p3(Material.HermeticMembranes, Material.GenEnhancedLivestock, Material.Polyaramids),
+ p3(Material.HighTechTransmitters, Material.Polyaramids, Material.Transmitter),
+ p3(Material.IndustrialExplosives, Material.Fertilizer, Material.Polytextiles),
+ p3(Material.Neocoms, Material.Biocells, Material.SilicateGlass),
+ p3(Material.NuclearReactors, Material.EnrichedUranium, Material.MicrofiberShielding),
+ p3(
+ Material.PlanetaryVehicles,
+ Material.MechanicalParts, Material.MiniatureElectronics, Material.SupertensilePlastics),
+ p3(Material.Robotics, Material.ConsumerElectronics, Material.MechanicalParts),
+ p3(Material.SmartfabUnits, Material.ConstructionBlocks, Material.MiniatureElectronics),
+ p3(Material.Supercomputers, Material.ConsumerElectronics, Material.Coolant, Material.WaterCooledCPU),
+ p3(Material.SyntheticSynapses, Material.SupertensilePlastics, Material.TestCultures),
+ p3(Material.TranscranialMicrocontrollers, Material.Biocells, Material.Nanites),
+ p3(Material.UkomiSuperConductors, Material.Superconductors, Material.SyntheticOil),
+ p3(Material.Vaccines, Material.Livestock, Material.ViralAgent),
+ -- P4
+ p4_a(Material.BroadcastNode, Material.DataChips, Material.HighTechTransmitters, Material.Neocoms),
+ p4_a(
+ Material.IntegrityResponseDrones,
+ Material.GelMatrixBiopaste, Material.HazmatDetectionSystems, Material.PlanetaryVehicles),
+ p4_a(
+ Material.RecursiveComputingModule,
+ Material.GuidanceSystems, Material.SyntheticSynapses, Material.TranscranialMicrocontrollers),
+ p4_a(
+ Material.SelfHarmonizingPowerCore,
+ Material.CameraDrones, Material.HermeticMembranes, Material.NuclearReactors),
+ p4_a(
+ Material.WetwareMainframe,
+ Material.BiotechResearchReports, Material.CryoprotectantSolution, Material.Supercomputers),
+ p4_b(Material.NanoFactory, Material.ReactiveMetals, Material.IndustrialExplosives, Material.UkomiSuperConductors),
+ p4_b(Material.OrganicMortarApplicators, Material.Bacteria, Material.Condensates, Material.Robotics),
+ p4_b(Material.SterileConduits, Material.Water, Material.SmartfabUnits, Material.Vaccines),
+}
+
+
+local lookup = {}
+for _, recipe in pairs(recipes) do
+ lookup[recipe.output.material] = recipe
+end
+return lookup
diff --git a/pi-calc b/pi-calc
new file mode 100755
index 0000000..a108f4b
--- /dev/null
+++ b/pi-calc
@@ -0,0 +1,10 @@
+#!/usr/bin/env lua
+local C = require "Calculator"
+local M = require "Material"
+local Q = require "Quantity"
+local material, amount = ...
+if not material then
+ error("expected material name as an argument")
+end
+amount = tonumber(amount) or 1
+C.pretty_print(C.raw_materials_needed(Q{amount, material}))