"Total raw" calculation

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

"Total raw" calculation

Post by DaveMcW »

The raw resources calculation is inconsistent between buildings. I think it should always show the base resources (iron ore, copper ore, coal, oil, water, wood, alien artifact) wherever it is viewed.

Chemical Plant:
Note that the heavy oil icon is used instead of oil.
chemical_plant.jpg
chemical_plant.jpg (41.59 KiB) Viewed 45812 times
Assembler 2:
assembler2.jpg
assembler2.jpg (28.79 KiB) Viewed 45812 times
Assembler 1:
assembler1.jpg
assembler1.jpg (38.47 KiB) Viewed 45812 times
Last edited by DaveMcW on Sat Jun 28, 2014 8:41 pm, edited 1 time in total.

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: [0.9.8] "Total raw" calculation

Post by slpwnd »

This is not a bug. This is an intended behavior. It always shows the "lowest recipes" in the tree that this machine can craft. So the assembling machine doesn't know how to craft the battery, therefore the battery is "raw" resource for the assembling machine.

I am moving this to ideas & suggestions. If this is annoying to many people we can think about changing this. Though there are some tricky subtle technical issues with this :)

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [0.9.8] "Total raw" calculation

Post by ssilk »

I think we need both info: the gross and the net calculations (in German and many other languages "brutto" and "netto"). I suggest a tab with the current as default.

http://en.wikipedia.org/wiki/Gross_(economics)
http://en.wikipedia.org/wiki/Net_%28economics%29
http://en.wikipedia.org/wiki/Netto
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [0.9.8] "Total raw" calculation

Post by DaveMcW »

The current is almost useless. Maybe it is nice to see for manual crafting. But when I pick a recipe in an assembler I can only use the main ingredients. I don't care where the ingredients are made, it is just as easy to build another assembler or chemical plant.

I can see how there would be a problem picking between multiple recipes. There are 3 gas recipes (basic-oil-processing, advanced-oil-processing, light-oil-cracking). And an infinite loop with crude oil barrels. So you would need a variable to identify which should or should not be used.

I would say use basic-oil-processing for all 3 refinery products. It will give you the maximum crude oil needed, and players can decide whether to use advanced oil processing to reduce that number. Just like they can use productivity modules to reduce all numbers.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [0.9.8] "Total raw" calculation

Post by DaveMcW »

I wrote a lua script to do it.
Lua Script
Output

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [0.9.8] "Total raw" calculation

Post by ssilk »

I like those very praxis-orientated stuff. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
DerivePi
Filter Inserter
Filter Inserter
Posts: 505
Joined: Thu May 29, 2014 4:51 pm
Contact:

Re: [0.9.8] "Total raw" calculation

Post by DerivePi »

DaveMcW - I believe your crude oil numbers are a bit high. I also think that crude becomes problematic because you have two ways to produce it. For instance, if I need 2 units of lubrication for an electric engine unit, that can be considered 2 units of crude under basic refinery (10 crude in and 3 heavy, 3 light and 4 petro out) or 1.8 units of crude under advanced refinery (10 units of crude produce 11 items of Heavy, Light and Petro - 1, 4.5, 5.5).

I discovered the discrepancy because I can't find the published formula for the Electric Engine Unit. I'm getting 2 Lub, 1 engine unit and 2 ckts?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [0.9.8] "Total raw" calculation

Post by DaveMcW »

I think you're right. It's better to assume all refinery products are equally valuable, instead of only looking at a single product. If people use cracking the crude oil costs might be off by 20%, but that's closer than being off by 200% like I was.

I played around with the script some more, and managed to eliminate the hidden_from_recipe_tree variable. It now avoids infinite loops on its own, and picks the cheapest recipe. This should allow it to handle any new recipe with no effort on the part of the modder.

In practical terms, this means:
empty-crude-oil-barrel: ignored because of infinite loop
heavy-oil-cracking: ignored because basic-oil-processing is cheaper
light-oil-cracking: ignored because basic-oil-processing is cheaper
advanced-oil-processing: ignored because (10 crude)/10 is cheaper than (10 crude + 5 water)/11

You could argue that 1 oil is more valuable than 5 water, but we would need a custom database entry to teach the game that.
Lua Script
Output

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: "Total raw" calculation

Post by ownlyme »

Brilliant script, thank you!
works ingame too, and i added a "time" entry in the return table, which should be 100% correct
call it by rawingredients(recipe)
when you call it on "nuclear fuel reprocessing" it returns the entry ERROR_INFINITE_LOOP = "used-up-uranium-fuel-cell", otherwise it works like a charm

Code: Select all

local exclude = {
["used-up-uranium-fuel-cell"] = true,
}
function rawingredients(recipe)
ret = getRawIngredients(recipe,exclude)
ret.time = (ret.time or 0)+recipe.energy
return ret
end

function getIngredients(recipe)
	local ingredients = {}
	for i,ingredient in pairs(recipe.ingredients) do
		if (ingredient.name and ingredient.amount) then
			ingredients[ingredient.name] = ingredient.amount
		elseif (ingredient[1] and ingredient[2]) then
			ingredients[ingredient[1]] = ingredient[2]
		end
	end
	return ingredients
end

function getProducts(recipe)
	local products = {}
	if (recipe.products) then
		for i,product in pairs(recipe.products) do
			if (product.name and product.amount) then
				products[product.name] = product.amount
			end
		end
	elseif (recipe.products) then
		local amount = 1
		if (recipe.result_count) then
			amount = recipe.result_count
		end
		products[recipe.products] = amount
	end
	return products
end

function getRecipes(item)
	local recipes = {}
	for i,recipe in pairs(game.recipe_prototypes) do
		local products = getProducts(recipe)
		for product,amount in pairs(products) do
			if (product == item) then
				table.insert(recipes, recipe)
			end
		end
	end
	return recipes
end

function getRawIngredients(recipe,excluded)
	local raw_ingredients = {
	["time"] = 0,}
	for name,amount in pairs(getIngredients(recipe)) do
		-- Do not use an item as its own ingredient 
		if (excluded[name]) then
			return {ERROR_INFINITE_LOOP = name}
		end
		local excluded_ingredients = {[name] = true}
		for k,v in pairs(excluded) do
			excluded_ingredients[k] = true
		end

		-- Recursively find the sub-ingredients for each ingredient
		-- There might be more than one recipe to choose from
		local subrecipes = {}
		local loop_error = nil
		for i,subrecipe in pairs(getRecipes(name)) do
			local subingredients = getRawIngredients(subrecipe, excluded_ingredients)
			if (subingredients.ERROR_INFINITE_LOOP) then
				loop_error = subingredients.ERROR_INFINITE_LOOP
			else
				local value = 0
				for subproduct,subamount in pairs(getProducts(subrecipe)) do
					value = value + subamount
				end

				local divisor = 0
				for subingredient,subamount in pairs(subingredients) do
					divisor = divisor + subamount
				end

				if (divisor == 0) then divisor = 1 end

				table.insert(subrecipes, {recipe = subrecipe, ingredients = subingredients, value = value / divisor})
			end
		end
		
		if (#subrecipes == 0) then
			if (loop_error and loop_error ~= name) then
				-- This branch of the recipe tree is invalid
				return {ERROR_INFINITE_LOOP = loop_error}
			else
				-- This is a raw resource
				if (raw_ingredients[name]) then
					raw_ingredients[name] = raw_ingredients[name] + amount
				else 
					raw_ingredients[name] = amount
				end
				
			end
		else
			-- Pick the cheapest recipe
			local best_recipe = nil
			local best_value = 0
			for i,subrecipe in pairs(subrecipes) do
				if (best_value < subrecipe.value) then
					best_value = subrecipe.value
					best_recipe = subrecipe
				end
			end

			local multiple = 0
			for subname,subamount in pairs(getProducts(best_recipe.recipe)) do
				multiple = multiple + subamount
			end

			for subname,subamount in pairs(best_recipe.ingredients) do
				if (raw_ingredients[subname]) then
					raw_ingredients[subname] = raw_ingredients[subname] + amount * subamount / multiple
				else
					raw_ingredients[subname] = amount * subamount / multiple
				end
			end 
			raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)*amount/multiple
		end
	end

	return raw_ingredients	
end
Edit: NEW VERSION!
- Now calculates the time based on the most energy-efficient crafting machine
- Also provides information about the energy required
- Breaks down liquids into crude oil
- Takes into account probabilities of products (doesn't work well with covarex enrichment process - so 1 fuel cell will cost 200 uranium ore)

Code: Select all

exclude = {
["used-up-uranium-fuel-cell"] = true,
}
function rawingredients(recipe) -- call this function
	if not global.best_machine then
		global.best_machine = {}
		for name, proto in pairs(game.entity_prototypes) do
			if proto.crafting_categories and proto.name ~= "player" and proto.name ~= "escape-pod-assembler" and proto.energy_usage and proto.energy_usage > 0 then
				for cat, _ in pairs(proto.crafting_categories) do
					if not global.best_machine[cat] then
						global.best_machine[cat]={speed = proto.crafting_speed or 1, energy = (proto.energy_usage or 1), name = name}
					elseif (proto.crafting_speed or 1)/(proto.energy_usage or 1) > global.best_machine[cat].speed / global.best_machine[cat].energy then
						global.best_machine[cat]={speed = proto.crafting_speed or 1, energy = (proto.energy_usage or 1), name = name}
					end
				end
			end
		end
	end
	ret = getRawIngredients(recipe,exclude)
	ret.time = (ret.time or 0)+(recipe.energy or 1)/global.best_machine[recipe.category].speed
	--ret.time = (ret.time or 0)+(recipe.energy or 1)
	ret.energy = (ret.energy or 0)+(recipe.energy or 1)/global.best_machine[recipe.category].speed*global.best_machine[recipe.category].energy
	return ret
end

function getIngredients(recipe)
	local ingredients = {}
	for i,ingredient in pairs(recipe.ingredients) do
		if (ingredient.name and ingredient.amount) then
			ingredients[ingredient.name] = ingredient.amount
		elseif (ingredient[1] and ingredient[2]) then
			ingredients[ingredient[1]] = ingredient[2]
		end
	end
	return ingredients
end

function getProducts(recipe)
	local products = {}
	if (recipe.products) then
		for i,product in pairs(recipe.products) do
			if (product.name and product.amount) then
				products[product.name] = product.amount
			elseif product.amount_min and product.amount_max then
				products[product.name] =  (product.amount_min+product.amount_max)/2 * (product.probability or 1)
			end
		end
	end
	return products
end

function getRecipes(item)
	local recipes = {}
	for i,recipe in pairs(game.recipe_prototypes) do
		if i ~="coal-liquefaction" and not (string.sub(item,-7) ~= "-barrel" and string.sub(i,-7) == "-barrel" and (string.sub(i,1,5) == "fill-" or string.sub(i,1,6) == "empty-")) then
			local products = getProducts(recipe)
			for product,amount in pairs(products) do
				if (product == item) then
					table.insert(recipes, recipe)
				end
			end
		end
	end
	return recipes
end

function getRawIngredients(recipe,excluded)
	local raw_ingredients = {
	["time"] = 0,
	["energy"] = 0}
	for name,amount in pairs(getIngredients(recipe)) do
		-- Do not use an item as its own ingredient 
		if (excluded[name]) then
			return {ERROR_INFINITE_LOOP = name}
		end
		local excluded_ingredients = {[name] = true}
		for k,v in pairs(excluded) do
			excluded_ingredients[k] = true
		end

		-- Recursively find the sub-ingredients for each ingredient
		-- There might be more than one recipe to choose from
		local subrecipes = {}
		local loop_error = nil
		for i,subrecipe in pairs(getRecipes(name)) do
			local subingredients = getRawIngredients(subrecipe, excluded_ingredients)
			if (subingredients.ERROR_INFINITE_LOOP) then
				loop_error = subingredients.ERROR_INFINITE_LOOP
			else
				local value = 0
				for subproduct,subamount in pairs(getProducts(subrecipe)) do
					value = value + subamount
				end

				local divisor = 0
				for subingredient,subamount in pairs(subingredients) do
					if subingredient ~= "intermediates" then
						divisor = divisor + subamount
					end
				end

				if (divisor == 0) then divisor = 1 end

				table.insert(subrecipes, {recipe = subrecipe, ingredients = subingredients, value = value / divisor})
			end
		end
		
		if (#subrecipes == 0) then
			if (loop_error and loop_error ~= name) then
				-- This branch of the recipe tree is invalid
				return {ERROR_INFINITE_LOOP = loop_error}
			else
				-- This is a raw resource
				if (raw_ingredients[name]) then
					raw_ingredients[name] = raw_ingredients[name] + amount
				else 
					raw_ingredients[name] = amount
				end
				
			end
		else
			-- Pick the cheapest recipe
			local best_recipe = nil
			local best_value = 0
			for i,subrecipe in pairs(subrecipes) do
				if (best_value < subrecipe.value) then
					best_value = subrecipe.value
					best_recipe = subrecipe
				end
			end

			local multiple = 0
			for subname,subamount in pairs(getProducts(best_recipe.recipe)) do
				multiple = multiple + subamount
			end

			if not raw_ingredients["intermediates"] then raw_ingredients["intermediates"] = {} end
			for subname,subamount in pairs(best_recipe.ingredients) do
				if subname == "intermediates" then
					for a, b in pairs(subamount) do
						raw_ingredients["intermediates"][a] = (raw_ingredients["intermediates"][a] or 0)+b*amount/multiple
					end
				elseif (raw_ingredients[subname]) then
					raw_ingredients[subname] = raw_ingredients[subname] + amount * subamount / multiple
				else
					raw_ingredients[subname] = amount * subamount / multiple
				end
			end 
			for a, b in pairs(getProducts(best_recipe.recipe)) do
				raw_ingredients["intermediates"][a] = (raw_ingredients["intermediates"][a] or 0)+b*amount/multiple
			end
			raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)/global.best_machine[best_recipe.recipe.category].speed*amount/multiple
			--raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)*amount/multiple
			raw_ingredients["energy"] = raw_ingredients["energy"] + (best_recipe.recipe.energy or 1)/global.best_machine[best_recipe.recipe.category].speed*global.best_machine[best_recipe.recipe.category].energy*amount/multiple
			
		end
	end

	return raw_ingredients	
end
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

mdemp
Burner Inserter
Burner Inserter
Posts: 8
Joined: Thu Aug 13, 2020 3:36 pm
Contact:

Re: "Total raw" calculation

Post by mdemp »

ownlyme wrote:
Mon Apr 15, 2019 4:41 pm
Brilliant script, thank you!
works ingame too, and i added a "time" entry in the return table, which should be 100% correct
call it by rawingredients(recipe)
when you call it on "nuclear fuel reprocessing" it returns the entry ERROR_INFINITE_LOOP = "used-up-uranium-fuel-cell", otherwise it works like a charm

Code: Select all

local exclude = {
["used-up-uranium-fuel-cell"] = true,
}
function rawingredients(recipe)
ret = getRawIngredients(recipe,exclude)
ret.time = (ret.time or 0)+recipe.energy
return ret
end

function getIngredients(recipe)
	local ingredients = {}
	for i,ingredient in pairs(recipe.ingredients) do
		if (ingredient.name and ingredient.amount) then
			ingredients[ingredient.name] = ingredient.amount
		elseif (ingredient[1] and ingredient[2]) then
			ingredients[ingredient[1]] = ingredient[2]
		end
	end
	return ingredients
end

function getProducts(recipe)
	local products = {}
	if (recipe.products) then
		for i,product in pairs(recipe.products) do
			if (product.name and product.amount) then
				products[product.name] = product.amount
			end
		end
	elseif (recipe.products) then
		local amount = 1
		if (recipe.result_count) then
			amount = recipe.result_count
		end
		products[recipe.products] = amount
	end
	return products
end

function getRecipes(item)
	local recipes = {}
	for i,recipe in pairs(game.recipe_prototypes) do
		local products = getProducts(recipe)
		for product,amount in pairs(products) do
			if (product == item) then
				table.insert(recipes, recipe)
			end
		end
	end
	return recipes
end

function getRawIngredients(recipe,excluded)
	local raw_ingredients = {
	["time"] = 0,}
	for name,amount in pairs(getIngredients(recipe)) do
		-- Do not use an item as its own ingredient 
		if (excluded[name]) then
			return {ERROR_INFINITE_LOOP = name}
		end
		local excluded_ingredients = {[name] = true}
		for k,v in pairs(excluded) do
			excluded_ingredients[k] = true
		end

		-- Recursively find the sub-ingredients for each ingredient
		-- There might be more than one recipe to choose from
		local subrecipes = {}
		local loop_error = nil
		for i,subrecipe in pairs(getRecipes(name)) do
			local subingredients = getRawIngredients(subrecipe, excluded_ingredients)
			if (subingredients.ERROR_INFINITE_LOOP) then
				loop_error = subingredients.ERROR_INFINITE_LOOP
			else
				local value = 0
				for subproduct,subamount in pairs(getProducts(subrecipe)) do
					value = value + subamount
				end

				local divisor = 0
				for subingredient,subamount in pairs(subingredients) do
					divisor = divisor + subamount
				end

				if (divisor == 0) then divisor = 1 end

				table.insert(subrecipes, {recipe = subrecipe, ingredients = subingredients, value = value / divisor})
			end
		end
		
		if (#subrecipes == 0) then
			if (loop_error and loop_error ~= name) then
				-- This branch of the recipe tree is invalid
				return {ERROR_INFINITE_LOOP = loop_error}
			else
				-- This is a raw resource
				if (raw_ingredients[name]) then
					raw_ingredients[name] = raw_ingredients[name] + amount
				else 
					raw_ingredients[name] = amount
				end
				
			end
		else
			-- Pick the cheapest recipe
			local best_recipe = nil
			local best_value = 0
			for i,subrecipe in pairs(subrecipes) do
				if (best_value < subrecipe.value) then
					best_value = subrecipe.value
					best_recipe = subrecipe
				end
			end

			local multiple = 0
			for subname,subamount in pairs(getProducts(best_recipe.recipe)) do
				multiple = multiple + subamount
			end

			for subname,subamount in pairs(best_recipe.ingredients) do
				if (raw_ingredients[subname]) then
					raw_ingredients[subname] = raw_ingredients[subname] + amount * subamount / multiple
				else
					raw_ingredients[subname] = amount * subamount / multiple
				end
			end 
			raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)*amount/multiple
		end
	end

	return raw_ingredients	
end
Edit: NEW VERSION!
- Now calculates the time based on the most energy-efficient crafting machine
- Also provides information about the energy required
- Breaks down liquids into crude oil
- Takes into account probabilities of products (doesn't work well with covarex enrichment process - so 1 fuel cell will cost 200 uranium ore)

Code: Select all

exclude = {
["used-up-uranium-fuel-cell"] = true,
}
function rawingredients(recipe) -- call this function
	if not global.best_machine then
		global.best_machine = {}
		for name, proto in pairs(game.entity_prototypes) do
			if proto.crafting_categories and proto.name ~= "player" and proto.name ~= "escape-pod-assembler" and proto.energy_usage and proto.energy_usage > 0 then
				for cat, _ in pairs(proto.crafting_categories) do
					if not global.best_machine[cat] then
						global.best_machine[cat]={speed = proto.crafting_speed or 1, energy = (proto.energy_usage or 1), name = name}
					elseif (proto.crafting_speed or 1)/(proto.energy_usage or 1) > global.best_machine[cat].speed / global.best_machine[cat].energy then
						global.best_machine[cat]={speed = proto.crafting_speed or 1, energy = (proto.energy_usage or 1), name = name}
					end
				end
			end
		end
	end
	ret = getRawIngredients(recipe,exclude)
	ret.time = (ret.time or 0)+(recipe.energy or 1)/global.best_machine[recipe.category].speed
	--ret.time = (ret.time or 0)+(recipe.energy or 1)
	ret.energy = (ret.energy or 0)+(recipe.energy or 1)/global.best_machine[recipe.category].speed*global.best_machine[recipe.category].energy
	return ret
end

function getIngredients(recipe)
	local ingredients = {}
	for i,ingredient in pairs(recipe.ingredients) do
		if (ingredient.name and ingredient.amount) then
			ingredients[ingredient.name] = ingredient.amount
		elseif (ingredient[1] and ingredient[2]) then
			ingredients[ingredient[1]] = ingredient[2]
		end
	end
	return ingredients
end

function getProducts(recipe)
	local products = {}
	if (recipe.products) then
		for i,product in pairs(recipe.products) do
			if (product.name and product.amount) then
				products[product.name] = product.amount
			elseif product.amount_min and product.amount_max then
				products[product.name] =  (product.amount_min+product.amount_max)/2 * (product.probability or 1)
			end
		end
	end
	return products
end

function getRecipes(item)
	local recipes = {}
	for i,recipe in pairs(game.recipe_prototypes) do
		if i ~="coal-liquefaction" and not (string.sub(item,-7) ~= "-barrel" and string.sub(i,-7) == "-barrel" and (string.sub(i,1,5) == "fill-" or string.sub(i,1,6) == "empty-")) then
			local products = getProducts(recipe)
			for product,amount in pairs(products) do
				if (product == item) then
					table.insert(recipes, recipe)
				end
			end
		end
	end
	return recipes
end

function getRawIngredients(recipe,excluded)
	local raw_ingredients = {
	["time"] = 0,
	["energy"] = 0}
	for name,amount in pairs(getIngredients(recipe)) do
		-- Do not use an item as its own ingredient 
		if (excluded[name]) then
			return {ERROR_INFINITE_LOOP = name}
		end
		local excluded_ingredients = {[name] = true}
		for k,v in pairs(excluded) do
			excluded_ingredients[k] = true
		end

		-- Recursively find the sub-ingredients for each ingredient
		-- There might be more than one recipe to choose from
		local subrecipes = {}
		local loop_error = nil
		for i,subrecipe in pairs(getRecipes(name)) do
			local subingredients = getRawIngredients(subrecipe, excluded_ingredients)
			if (subingredients.ERROR_INFINITE_LOOP) then
				loop_error = subingredients.ERROR_INFINITE_LOOP
			else
				local value = 0
				for subproduct,subamount in pairs(getProducts(subrecipe)) do
					value = value + subamount
				end

				local divisor = 0
				for subingredient,subamount in pairs(subingredients) do
					if subingredient ~= "intermediates" then
						divisor = divisor + subamount
					end
				end

				if (divisor == 0) then divisor = 1 end

				table.insert(subrecipes, {recipe = subrecipe, ingredients = subingredients, value = value / divisor})
			end
		end
		
		if (#subrecipes == 0) then
			if (loop_error and loop_error ~= name) then
				-- This branch of the recipe tree is invalid
				return {ERROR_INFINITE_LOOP = loop_error}
			else
				-- This is a raw resource
				if (raw_ingredients[name]) then
					raw_ingredients[name] = raw_ingredients[name] + amount
				else 
					raw_ingredients[name] = amount
				end
				
			end
		else
			-- Pick the cheapest recipe
			local best_recipe = nil
			local best_value = 0
			for i,subrecipe in pairs(subrecipes) do
				if (best_value < subrecipe.value) then
					best_value = subrecipe.value
					best_recipe = subrecipe
				end
			end

			local multiple = 0
			for subname,subamount in pairs(getProducts(best_recipe.recipe)) do
				multiple = multiple + subamount
			end

			if not raw_ingredients["intermediates"] then raw_ingredients["intermediates"] = {} end
			for subname,subamount in pairs(best_recipe.ingredients) do
				if subname == "intermediates" then
					for a, b in pairs(subamount) do
						raw_ingredients["intermediates"][a] = (raw_ingredients["intermediates"][a] or 0)+b*amount/multiple
					end
				elseif (raw_ingredients[subname]) then
					raw_ingredients[subname] = raw_ingredients[subname] + amount * subamount / multiple
				else
					raw_ingredients[subname] = amount * subamount / multiple
				end
			end 
			for a, b in pairs(getProducts(best_recipe.recipe)) do
				raw_ingredients["intermediates"][a] = (raw_ingredients["intermediates"][a] or 0)+b*amount/multiple
			end
			raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)/global.best_machine[best_recipe.recipe.category].speed*amount/multiple
			--raw_ingredients["time"] = raw_ingredients["time"] + (best_recipe.recipe.energy or 1)*amount/multiple
			raw_ingredients["energy"] = raw_ingredients["energy"] + (best_recipe.recipe.energy or 1)/global.best_machine[best_recipe.recipe.category].speed*global.best_machine[best_recipe.recipe.category].energy*amount/multiple
			
		end
	end

	return raw_ingredients	
end


Hey!
Can you give me hint how to run this script in v0.17? And how to extract the raw data? Thank you :)

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: "Total raw" calculation

Post by ssilk »

I think you can use this:
https://mods.factorio.com/mod/MaxRateCalculator

It says it has 0.17 support..
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

mdemp
Burner Inserter
Burner Inserter
Posts: 8
Joined: Thu Aug 13, 2020 3:36 pm
Contact:

Re: "Total raw" calculation

Post by mdemp »

Yep, but that is not the information I was looking for. I basically need the output of that LUA script from 0.17, to do some data mining. So I was looking for a way the script would work for me. But so far Someone's LUA-Console mod didn't help in running the script, as I do not have the experience needed for it. That is why I'm asking about it here :)

[EDIT]
Now I guess I'm looking for the same things but in 0.18 ^_^

Post Reply

Return to “Ideas and Suggestions”