[IDEA] Randomizing the ingredients and times for factories

This is the place to request new mods or give ideas about what could be done.
Post Reply
Reverend
Inserter
Inserter
Posts: 37
Joined: Mon Mar 21, 2016 3:13 pm
Contact:

[IDEA] Randomizing the ingredients and times for factories

Post by Reverend »

I like to build factories with perfect ratios. And we all know some common ratios, such as 1/14/10 for steam, 4/7/1 for oil to gas, 3 to 2, coils to green circuits. etc.

When I first played the game, figuring out those ratios was part of the fun. I'd write down the values, do some quick and easy math, and then plop down my layouts.

My idea is for a mod that randomizes time and/or ingredients for items upon game/map creation.

I feel like it would be a fun challenge to figure out the new ratios that it would come up with.

Tell me what you think.

Mion
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Thu Dec 04, 2014 7:38 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by Mion »

I think it's a good idea if difference between old and new parameters will be not big, because of saving game balance.

Tankh
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Tue Aug 12, 2014 1:35 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by Tankh »

I thought of something similar like an hour ago actually. Funny you made a thread about it yesterday.

I was thinking about "Roguelike Research". (Really just using roguelike as a synonym for random)
At the start of each game, the recipe of science packs are randomized, and you won't know the recipes until you've researched them (to avoid temptation of restarting instantly)
Red pack might be automatically unlocked when building a research lab since you need it to start research.

Got the idea when I found viewtopic.php?f=94&t=24767

randomized challanges can really help with replayability sometimes.

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by sporefreak »

Seems great but you can't hide recipes behind research, when I first started the game I remember looking at the rockets crafting recipes. right off the bat and thinking (Wow that will never happen)
the randomness would have to be limited. red would have to use random items from things you can get/craft without researching anything. green would have to use anything you can research with green and so on. You would have to define what items each science can and cannot use. if red needed rocket fuel then it would be impossible to play,

Another problem i see is people restarting over and over because they don't like the map generation, or they don't like the recipes.

A mod like this is something I would use for sure!

I can look into making it but chances are nothing will come out of it.

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by DedlySpyder »

sporefreak wrote:Seems great but you can't hide recipes behind research
You could. If you remove the normal code that unlocks a recipe and just unlock it manually in the researched event, then it wouldn't show. But that would require quite a bit of work

User avatar
5thHorseman
Smart Inserter
Smart Inserter
Posts: 1193
Joined: Fri Jun 10, 2016 11:21 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by 5thHorseman »

sporefreak wrote:Another problem i see is people restarting over and over because they don't like the map generation, or they don't like the recipes.
I don't see this as a problem. If someone downloads and installs a mod and then goes out of his or her way to circumvent that mod's main purpose, then why are they downloading it in the first place? And if they want randomized recipes but don't want the game to be ridiculously difficult (from their perspective) then what's wrong with restarting when the recipes are (again from their perspective) too difficult?

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by Adil »

sporefreak wrote:Seems great but you can't hide recipes behind research
Why not?
It just would require more thought to generate connected graph of technology and recipes.
The main problem is that you'd need this generator to run exactly after all the other mods have finished adding stuff, and you can't actually guarantee that. Maybe if mod is written as a standalone generator, that first runs the scripts the same way as the game loader does and after that modifies the resulting data.raw table and serializes it down into a single data.lua, that could be used with modified mod files. (Or simply to modify mod files to ensure their ordering.)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by sporefreak »

Adil wrote:
sporefreak wrote:Seems great but you can't hide recipes behind research
Why not?
It just would require more thought to generate connected graph of technology and recipes.
The main problem is that you'd need this generator to run exactly after all the other mods have finished adding stuff, and you can't actually guarantee that. Maybe if mod is written as a standalone generator, that first runs the scripts the same way as the game loader does and after that modifies the resulting data.raw table and serializes it down into a single data.lua, that could be used with modified mod files. (Or simply to modify mod files to ensure their ordering.)
I havnt bothered to learn anything about scripts, so im sure it can be done but as far as i know not without scripts.

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

I think this is a very cool idea and I will try to write this mod

I have thought about how to do this so that it doesn't destroy the balancing and here is what I got so far:
- Every raw material (uncraftable stuff like logs, ores and oil) get a specific value assigned, this would get some kind of "API" so other mods adding raw materials can easily add their stuff
- Craftable items will get a value based on the crafting materials values, crafting time and required crafting machine (it will always use the lowest applicable and really only matter if it is not craftable in hand)
This way we basically created a value for each item with the default recipe (which may be provided by other mods)
Now we can say that we want to have the crafting cost vary by a specified percentage and based on that adjust normal recipes randomly, but so that it remains within the specified percentage of variation

For the randomized science pack recipes we can follow up on the previous approach and and use random items that can be crafted at the respective science stage
To find out if the items are craftable at the current science stage I would try to analyze the tech tree and gather all possible items for the specific science packs, but I don't know if that is possible, if it isn't possible I will add all vanilla items to lists and provide other mods with the ability to add items through an "API"
Then we could randomly select 2-3 items for science pack 1 and 2 and 3-4 items for science pack 3 and 4 (may be changed if needed) that add up to the value of the respective science pack (with the variation factor of course)

I don't know if it would be possible to hide the recipes of later science packs, but I'll try my best to get that to work too

I will split this into 3 mods, one core that does the whole value assigning and calculation, core will be needed for both of the others, then one mod for the general crafting and one for the science pack crafting
That way everyone can choose if they want both parts or just one of them and other modders can use this value system without forcing people to have randomized crafting stuff

If you have any complaints or further ideas, let me know
I'm off to working on this mod and will provide updates on my work :)

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

So, here is a little update on the development status:
The core mod is now working but still unbalanced
Since I don't have any experience with balancing it would be nice if someone could help me out there by assigning reasonable values for logs, iron ore, copper ore, coal, stone, alien artifacts, raw fish, crude oil and water and providing a formula to calculate values for crafted items from their ingredients and the energy required (energy is translated to crafting time for in hand crafting by the game) and, if needed, other factors

Now that the core mod is working (even though unbalanced) I can work on the other parts
I will start by building the randomized science pack recipes, this will happen with a static list at first and afterwards I will try to build the analysis part to automatically figure out which items could be used for each science pack

The next update will probably take me a little more time as I have to work and the described features seem to be somewhat more complex to implement, but I think that next sunday should be a realistic goal
Also, from the next update on I can provide the mod files since then they actually change something in the game that is not arbitrary background stuff

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by sporefreak »

nepcore wrote:assigning reasonable values for logs, iron ore, copper ore, coal, stone, alien artifacts, raw fish, crude oil and water and providing a formula to calculate values for crafted items from their ingredients and the energy required (energy is translated to crafting time for in hand crafting by the game)
Values for what? what is the purpose of the values for those items? (I'm actually not sure)
Also maybe the crafting times should just be random between x - y seconds? X * Y where X is random (3-6) and Y is the number of crafting ingredients, Obviously, X would be different for each science pack.

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

sporefreak wrote:Values for what? what is the purpose of the values for those items?
You could think of these values like a price when trading with an imaginary NPC using some imaginary currency instead of $, €, ...
Since these "prices" should be derived from the crafting ingredients and the time to craft the item you can then generate recipes with a similar price up to a specified variation when generating a new world, this way you can have random ingredients without destroying the balance, because it still has a similar "price"
But you need a basis and a formula with which you calculate these "prices" and since logs, ores, ... cannot be crafted from something they are the obvious choice for a basis
This basis and the formula for deriving the "prices" of crafted items need to be balanced though (obviously)
sporefreak wrote:Also maybe the crafting times should just be random between x - y seconds? X * Y where X is random (3-6) and Y is the number of crafting ingredients, Obviously, X would be different for each science pack.
That could be one way, what I thought of was to specify a base crafting time for each science pack and randomly adding or subtracting a little but so that the recipe stays within the predefined variation
I will test which approach has the better results and use the winner until someone comes up with something even better

I hope I could clear up any confusions, if not, just ask and I'll try again :D

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2130
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by Ranakastrasz »

Using a seed set in config would allow consistency between saves. Player changes seed for new balance.

I would set crafting times as +-50% and each ingredient cost the same way.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

Now I feel really stupid... :?

In my enthusiasm I overlooked some very important facts
It is actually not possible to make random recipes because Factorio loads recipes on start during the loading screen and it is impossible to actually modify recipes after that :cry:
At least that is what I found, if I am wrong on that, someone please tell me what I missed...

If you want more info on why it is impossible here is some rather technical stuff:
Basically a mod in Factorio consists of multiple parts which are separated into multiple files, info.json which holds basic information about the mod, this does not change the game in any way
Then there is data.lua which is used to add/modify/remove game data like items and recipes, there are also 2 other files you could use for this, but they are just there to ensure that certain modifications only run after certain other operations
data.lua and the other 2 are only loaded during the loading screen when starting Factorio and cannot be forced to run at a later point in time
Next we have control.lua which is the script part of the mod, it is used for everything that cannot be done through data adjustments in data.lua, but it has some limitations and one of those is that recipes cannot be modified from here as the new recipe will never get loaded
There are more parts to a mod but I could not find anything that would let me adjust recipes after loading and I doubt that there is anything capable of changing recipes after load

The only ways to make this work would be:
- The Factorio team adds a way to change recipes after load to the mod API but I guess that would be very hard because of how replays work
- The Factorio team decides this is a good thing and implements the mod idea as an offical feature (maybe with an option to enable/disable it)
- Someone writes a patch that actually modifies the games binaries on a low level, this is very complex, can break a lot and the Factorio team would probably not like to see this kind of mod

If devs are readingthis thread, I would love to see the features needed implemented in the mod API if it is possible in any way

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by orzelek »

You can currently write a mod that will randomly rearrange recipes.
With some care it could use a random seed thats placed in config file. You are right that it can't be randomized during the game in any way.

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by sporefreak »

While it wouldn't really be a mod any longer, maybe you could make an EXE that finds all the recipes in the mod files and randomizes them in a newly generated mod file that edits said recipes?
I would imagine this would be rather complex.

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

That would be a possibility
I will look into that once my ISP decides to solve their problems because mobile network isn't very good here...
But given there is a library for one of the programming languages I know that can parse or interpret Lua it should not be that complicated

nepcore
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 25, 2016 3:45 pm
Contact:

Re: [IDEA] Randomizing the ingredients and times for factories

Post by nepcore »

Since I will be a little busy with some unexpected personal stuff I won't get to write a program like proposed by sporefreak in the near future
If someone wants to do that, I would love to see something when I get a chance to play again but if not I will probably do it when I'm back

Post Reply

Return to “Ideas and Requests For Mods”