[MOD 0.18.x] KenirasRandomRecipes

Topics and discussion about specific mods
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

[MOD 0.18.x] KenirasRandomRecipes

Post by Kenira »

Type: Mod
Name: KenirasRandomRecipes
Description: Randomizes recipes for different ratios in every game.
License: MIT
Version: 1.6.5
Latest release: 2020-04-13
Tested-With-Factorio-Version: 0.18

Mod Portal Link

Long description
Mod compatibility
Known Issues
Last edited by Kenira on Thu Apr 30, 2020 12:17 pm, edited 28 times in total.
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.2

Post by system »

bug/feature: When some mod updated, its recipes got randomized again.
E.g. after updating angel smelting, rates for iron processing changed a lot.
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.2

Post by Kenira »

I definitely see it as a bug and yeah, things will also change if you either add or remove mods - anything that adds or removes recipes. So far very few people downloaded the mod so i didn't think it was worth putting too much effort into it, but i'll give it a shot tomorrow.
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.2

Post by Kenira »

Sorry, i don't think this is possible after all - i'd need to store some data permanently, but at the time where you can change recipes you don't have access to the global table yet which afaik is the only way to store data permanently.

I'll still upload a new version in a bit but that's just for some balancing, as it was the probability of recipes getting more expensive was a bit too high from my experience.
zxr
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue May 23, 2017 9:41 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.3

Post by zxr »

Hey, stumbled upon your mod today and I think I've got a fix for your issue.

Generating a new random number for each recipe in order based on the same initial seed means that when a mod adds/removes a recipe, all other recipes after that one will be assigned a different random number than they were previously. Instead, if you create a new seed for each recipe based on the recipes name and the random seed from the settings, each recipe will be assigned the same random number every time (regardless of order) assuming the random seed is unchanged.

Since math.randomseed expects a 32bit integer, we need to generate a 32bit integer hash from the item.name and rand_seed. CRC32 seems perfect for this, and theres an open source lua implementation available here.

All in all its only a few extra lines required. Here's how I did it (in data-final-fixes.lua):

Code: Select all

require("config")
require("functions")
local crc32 = require("crc32") -- <== new require, use the crc32 library above or some other

rand_seed = settings.startup["keniras-random-recipes-random-seed"].value
rand_all = settings.startup["keniras-random-recipes-randomize-all"].value
rand_products = settings.startup["keniras-random-recipes-products"].value

local function reseed (recipeName) -- <== new function
    local seed = crc32.Hash(recipeName .. tostring(rand_seed)) -- generate new seed based on recipe name and rand_seed
    math.randomseed(seed)
end

-- ...bulk of code here... (can remove the math.randomseed initialization stuff here since we're reseeding for each recipe anyway)

if listed == true then
   for _, recipe in pairs(item_recipes) do
      if recipe then
         reseed(item.name) -- <== new function call here
         local ingredient_one = false
         -- etc...
I tested it a few times adding/removing recipe-changing mods, and recipe numbers stayed the same and only changed when I changed the random seed, so it appears to work but more testing is probably required if you decide to go with this method.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.3

Post by darkfrei »

Thanks! It was my suggestion :)
viewtopic.php?f=33&t=41569

If you need your number generator, I've write this in excel. The seed must be not integer, but rational / irrational.
Rnd_01.xlsx
(110.4 KiB) Downloaded 234 times
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.3

Post by Kenira »

I hadn't thought of that, that's a great idea! Thanks zxr, new version out.

@darkfrei: And you were apparently not the only one wanting this: Personally I got the idea from someone on reddit and thought "that can't be too hard to make into a mod"
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.4

Post by system »

Wow, that was a fast fix! I'll try on new modpack that i'm making.
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.4

Post by system »

Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.4

Post by Kenira »

Indeed an easy fix, didn't take long to figure out that there's an upper limit for ingredient count which you could get over with that Yuoki recipe with 30k ingredients. Just a matter of checking for the random value to not exceed that limit.
Should be fixed in new version.
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by system »

Thx again.

Is there way to blacklist recipes based on name or ingridient name or result name?

E.g. i want to blacklist all that contain any of these words:
"barrel", "unicomp", "empty", "fill", "water", "gas"
Barreling, yuoki unicomp, etc allow to convert resources from one to another, and often it generate possibility to make resource infinite.

E.g. 2 recipes:
79 oil to barrel
oil barrel to 115 oil

Another alternative would be somehow to set these values equal.
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by system »

Something like:

Code: Select all

   {
    type = "string-setting",
    name = "keniras-random-recipes-blacklist-extra",
    setting_type = "startup",
    default_value = "enrichment-process,uranium-process,-barrel,2uc-recipe,y-ac-uc2,y_uc2",
    order = "e",
   },

------------------------------

--extra blacklist
local function split_string(sep, csv)
   local sep, fields = sep or ",", {}
   local pattern = string.format("([^%s]+)", sep)
   csv:gsub(pattern, function(c) fields[#fields+1] = c end)
   return fields
end
recipe_blacklist_extra = split_string(settings.startup["keniras-random-recipes-blacklist-extra"].value, ",")

	-- check all items set as "listed" so far if they're on the blacklist
	if listed == true and blacklist_enabled == true then
		for _, item_from_blacklist in pairs(recipe_blacklist_extra) do
			if (item.name ~= nil and string.find(item.name,item_from_blacklist)) then
				listed = false
			end
		end
	end


Can't find what i'm doing wrong, but they are not blacklisted...
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by system »

This split function actually works :)

Code: Select all

function split_string(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end
But I gave up, as there are recipes with catalysts (ingredients that not consumed) and reusable (like slag slurry processing). Too hard to exclude short chain replications.


PS: few more ideas to randomize: inserter/belt speed, damage, produced energy.

Last time i had: 1 raw wood -> 5 wood, 1 wood -> 1 chest. Making chests almost best fuel in game :D
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by Kenira »

If nothing else excluding barreling seems like a good idea, those i already have working, with unicomp as ingredient or product i'm still struggling and not sure where my error is. I made it easier for myself to put the second blacklist in the config.lua like the regular blacklist so i don't even need a function to split the strings :P

As for your other suggestions, i'll include them since it's not much work, although by default deactivate them - at least personally, i think it can be challenge enough to figure out how to build things now without having to worry about if the result sucks on top of that. Also, you can't check these things before starting the game, so you might end up finding out blue belts are even slower than yellow belts later into the game. Same with inserters, if stack inserters are super slow they're suddenly completely useless. With just recipe ingredients and crafting time random, at least you can check your luck before actually starting your game (which i do). It would be a truly chaotic experience. Which now that i say it could be fun, at least once (and maybe without biters). Having said that, anything else you think would be fun to randomize? Robot energy, roboport charging ports / charging speed, assembly machine speed, beacon stats, module stats, radar range, mining speed, energy consumption of everything, pollution? :P
system
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Oct 18, 2016 3:05 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by system »

I prefer to drop-in replacement for newer version of mods, that is why i made list configurable through UI.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2171
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by Ranakastrasz »

Shouldn't you use the map's seed for the seed?

Or is it not possible to retrieve it?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by Kenira »

That's not possible because you need the random seed at the very beginning when booting up the game, before you even get to the main menu and could load a map. Same for any other places where you think you could get a random number from, factorio is made to be deterministic. Plus i like it better so that with a given seed the random numbers will always be the same, even independant of other mods installed.
Kenira
Fast Inserter
Fast Inserter
Posts: 111
Joined: Fri Nov 04, 2016 10:21 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by Kenira »

New version up.

Added a new blacklist for keywords. Recipes will be searched for recipe name, ingredient names, and product names for these keywords and not randomize any that have these keywords anywhere. Currently only used for barrel to preserve barreling recipes, and Yuoki's unicomp to preserve trading. As with the regular blacklist items can easily be added yourself in the magical config.lua.

Probabilities are finally working as well, up to 2 products with a probability at least. That means uranium processing is now also randomized.

And finally, a ton of new features that can be toggled on and off individually (or also in bulk): Randomize inserter speed, belt speed, turret damage, weapon damage, energy usage, pollution produced, energy produced, accumulator capacity and power, reactor power, item fuel values, mining speed, assembling machine speed, furnace speed, module stats (for extra hilarity, i don't really recommend it with how silly that can get).
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2171
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 0.0.5

Post by Ranakastrasz »

Kenira wrote:That's not possible because you need the random seed at the very beginning when booting up the game, before you even get to the main menu and could load a map. Same for any other places where you think you could get a random number from, factorio is made to be deterministic. Plus i like it better so that with a given seed the random numbers will always be the same, even independant of other mods installed.
Oh, right. Forgot about that. Yea, it wouldn't work since you can't get the seed on startup, only once you choose a map.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
FuzzCat927
Inserter
Inserter
Posts: 23
Joined: Sat Apr 08, 2017 3:04 pm
Contact:

Re: [MOD 0.15.x] KenirasRandomRecipes 1.0.0

Post by FuzzCat927 »

EDIT:

Code: Select all

	-- if an item has normal and expensive recipes, randomize both.
	if item.normal and item.expensive then
		item_recipes = {	item.normal,
							item.expensive,
							}
	else
		item_recipes = {	item,
							}
	end
should be

Code: Select all

	-- if an item has normal and expensive recipes, randomize both.
	if item.normal and item.expensive then
		item_recipes = {	item.normal,
							item.expensive,
							}
	else
		item_recipes = {	item.normal,
							}
	end

Crash on startup in data-final-fixes.lua:135 -- bad argument to pairs (table expected, got nil) Taking a look at it myself. If I figure it out, I'll post private message you the new files.

EDIT:

Here's my modlist:
  • Factorissimo2
  • Fabrication
  • KenirasRandomRecipes
EDIT (again):

from looking through your code, I think it's from the second blacklist, although I'm not entirely sure
Last edited by FuzzCat927 on Thu May 25, 2017 10:04 pm, edited 3 times in total.
Post Reply

Return to “Mods”