Page 1 of 1

How to set up a custom infinite research

Posted: Thu May 10, 2018 4:39 am
by Villfuk02
I'd like to create my own infinite research to increase speed and/or productivity of a certain machine. The problem is I only know how to add regular researches and I don't know how to make the research apply bonuses to my machine.

Re: How to set up a custom infinite research

Posted: Thu May 10, 2018 4:57 am
by Optera
As with all questions on how to mod something I first look at how the base game or small mods by the developers do things.
For example Klonans Robot Battery research.

Re: How to set up a custom infinite research

Posted: Thu May 10, 2018 6:42 am
by eradicator
Adding productivity to specific machines is impossible. Only labs and drills as a general category have productivity reserach right now. Assuming you're thinking about some kind of assembling machine, then you're completely out of luck because assemblers can not have "built-in" productivity.

Re: How to set up a custom infinite research

Posted: Thu May 10, 2018 7:39 am
by Villfuk02
@ Optera
Thanks, i was searching for a mod with an infinite research to learn from.

Re: How to set up a custom infinite research

Posted: Thu May 10, 2018 7:45 am
by Villfuk02
So it looks like I can't access speed or productivity. Is it at least possible to modify a global variable with a research? I could then do some stuff in control.lua

Re: How to set up a custom infinite research

Posted: Thu May 10, 2018 8:00 am
by betrok
Villfuk02 wrote:So it looks like I can't access speed or productivity. Is it at least possible to modify a global variable with a research? I could then do some stuff in control.lua
You can se handlers for on_research_finished and on_technology_effects_reset.

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 4:42 am
by Villfuk02
Is it possible to somehow change module values or change it's prototype in control.lua?

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 6:36 am
by Bilka
Villfuk02 wrote:Is it possible to somehow change module values or change it's prototype in control.lua?
No.

You could make tons of prototypes, one per research, level and replace the modules in each machine when the research finishes. That will be just as performance intensive as doing the same with machines though.

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 11:27 am
by eradicator
Bilka wrote: You could make tons of prototypes, one per research, level and replace the modules in each machine when the research finishes. That will be just as performance intensive as doing the same with machines though.
I.e given the fact that on_research_finished is amongst the most rare events in the game, the performance impact would be negligible if done right, and worst case cause a minor lag spike after each relevant reserach if done wrong. But you'd have to deal with preventing the player from taking the modules out and stuffing them into something they're not intended for. Bleh. Replacing the machine itself is far easier to handle. Though still a fair bit of annoying code to get right in all cases. Also replacing the whole machine is more expensive than replacing a single module because you have to replicate the whole machine state (circuits, power, ingredients, crafting process, module slots, etcpp).

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 12:10 pm
by Bilka
eradicator wrote:Also replacing the whole machine is more expensive than replacing a single module because you have to replicate the whole machine state (circuits, power, ingredients, crafting process, module slots, etcpp).
That should be possible to handle by fast_replacing the machine per script.

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 4:32 pm
by Villfuk02
I could also make the modules change their stats when inserted into the machine (they will be usable only in one machine). After every research finishes the code will check if it was the research I wanted. If yes, update all modules in the machine.

Re: How to set up a custom infinite research

Posted: Fri May 11, 2018 5:37 pm
by eradicator
Bilka wrote:That should be possible to handle by fast_replacing the machine per script.
Oh. I wasn't aware that create_entity can fast_replace. I suspect that would still be more expensive (if only slightly) than changing a single module.
Villfuk02 wrote:I could also make the modules change their stats when inserted into the machine (they will be usable only in one machine).
Both of these are impossible, as already mentioned above (including hack-arounds).