Do not show disabled technologies in the technology list

Aidiakapi
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 14, 2017 6:13 pm
Contact:

Do not show disabled technologies in the technology list

Post by Aidiakapi »

This post has two parts, the first is a relatively simple thing that would fix my particular scenario, but doesn't address the underlying issue, the latter proposes a solution that'd fix the underlying issue, but is more complex.

Simple solution for me
Make it so that technologies that not enabled do not show up in the technology list, even if they're researched.

Context
The mod I wrote (https://mods.factorio.com/mod/qol_research) adds a bunch of quality of life modifiers (think movement speed, reach, etc.), that are calculated based on runtime settings.
As most mods of this caliber did, I started out using modifiers on LuaForce to set these bonuses. This however causes numerous problems:
  • reset_technology_effects() Popular mods such as bobsplates will reset the technology effects in the control stage, and even though I went through several implementation, adding several heuristics to detect whether the effects were reset, and reapplying them. There was no way to get it to be bullet-proof, and numerous times in weird situations with different modpacks, stuff would just break. I've asked about an event to detect the reset situations, and Klonan responded with:

    Code: Select all

    If its called from a running script in the middle of nowhere, then there is no way to detect it
    Just like if a mod randomly decides to disable any recipes, technology, change some bonus etc.
    But it is incorrect usage to use it that way
    As much as this could be considered incorrect usage, it's the real-world usage, and it's not the mod that does it incorrectly that breaks, it's the one which relies on LuaForce modifiers.
  • Bad user experience modifying mods. The user removes a mod, but its effects persist.
  • Mod incompatibility. Even besides the reset_technology_effects(), the LuaForce method is nearly impossible to make compatible with other mods modifying the same values. If every mod was properly coded and coordinated, it's potentially possible, but that doesn't happen in real-life.
  • Immediate application. Because property changes are not deferred, you easily run into situations where you get things like inventory explosions. It's not hard to code around, but annoying to say the least.
  • Inconsistent behavior. Different properties behave different, most of them are relative modifiers, but for example quickbar_count is not. I had to write code that scans which technologies have effects that add quickbars, store that, then every time the value needs to be updated, inspect which of those technologies are researched on the current force, and then add that to the relative modifier my mod should provide. Again, not hard to code, but extra hurdles in the way of using modifiers on LuaForce.
So with these huge issues with LuaForce modifiers, I decided to implement a hacky way around the limitations. I add a series of technologies, adding a pattern of effects following x*2^n, where x is a multiplier I've chosen per effect, and n ranges [0, m) where m is another arbitrary value I've chosen per field (to get reasonable coverage).

As an example (x = 0.01, m = 12):

Code: Select all

0.01 movement speed
0.02 movement speed
0.04 movement speed
...
1310.72 movement speed
2621.44 movement speed
5242.88 movement speed
After doing loads of experimentation, I discovered that if I:
  • Disable all these internal technologies, they would not get researched by research_all_technologies().
  • Research a disabled technology, its effects would still apply.
  • Put them in the same upgrade-tree, add a dummy research (with no effects) at the end, and disable that dummy research, they'd never show up in the technology list.
Using these tricks, I've managed to create a mod which doesn't suffer from the incompatibility issues all other mods that provide runtime settings for this stuff do. It uninstalls cleanly (since technology effects get removed), works reliably, and even reset_technology_effects() doesn't break it.

The last hack, which allowed me to hide those technologies broke in a recent patch. Although I'm not entirely certain, I think the bugfix in viewtopic.php?t=57600 is the likely culprit. So whilst right now, the mod still functions perfectly fine, the previously hidden technologies are visible in the technology window, which isn't the prettiest sight.

Solution
For my specific mod, the simple solution posted above would resolve the issue, however, I propose a more general solution, that'd fix this issue for all mods, allow for more new and varied situations to be fixed, and doesn't require these gross workarounds (I'm registering over 150 technologies to get all the fields working properly).

A method for applying technology effects during control stage.
Give every mod a set of modifiers they can edit. Concrete API:
On LuaForce, add the following:

Code: Select all

add_mod_effect(name: string, modifiers: Modifier[]): void
mod_effects: read only dictionary of [string => array of Modifier]
remove_mod_effect(name: string): void === add_mod_effect(name, nil)
See Modifier concept.
Mod effects should not be shared between mods. Each mod should have its own dictionary of mod effects, this is so that upon uninstallation of the mod, these are removed.
In the Factorio code base, by the very nature of being able to research and unresearch technologies, this should be possible to implement. (Though I'm not sure about the nature of the LuaObject system, so the functionality might have to be moved to LuaBootstrap or LuaGameScript.)

Implementing this or similar functionality through a different API would prevent pretty much all mod incompatibility issues related to these kinds of things.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Do not show disabled technologies in the technology list

Post by eradicator »

+10

I have pondered the idea of having some RPG like systems in one of my mods and have too come to the conclusion that due to the way force modifiers are shared by everyone the only currently possible solution would be to add a bunch of technologies and even trying to use the shared modifiers would be utterly pointless. Sadly even with technologies per-character bonusses still remain broken. And the only solution to that seems indeed to make all modifiers (per-force and per-character) also per-mod. And i'm not sure how that would affect performance... if everything is cached and only updated when anything actually changes it shouldn't be too bad?

As for OPs current "stuff shouldn't be visible" i wonder if a seperate .hidden flag like on other things (recipes, etc) wouldn't be better. Though i like the even better solution of being able to create arbitrary modifier flags.
Aidiakapi
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 14, 2017 6:13 pm
Contact:

Re: Do not show disabled technologies in the technology list

Post by Aidiakapi »

eradicator wrote:As for OPs current "stuff shouldn't be visible" i wonder if a seperate .hidden flag like on other things (recipes, etc) wouldn't be better. Though i like the even better solution of being able to create arbitrary modifier flags.
Yeah, I initially thought that too, but considering a technology with enabled = false and researched = true still contributes to effect bonuses, all that "enabled" currently does is hiding anyways. If enabled could actually disabled the effects from taking effect, a different field would make more sense.

I've also thought about how to do per-character, but I honestly think the devs themselves are better at coming up with an idea for that, since they have access to the source code and all.
What I also considered is just making a mod that can be used as a dependency, that'd take care of all these modifiers, both per-force and per-character. However, since mods don't automatically download their dependencies, I've found using dependencies to often be quite painful for the end-user.

An alternative is to distribute it as a library, similarly to how stdlib does it, however I'd have to experiment with how remotes work in for example the data stage. It might be something I could do for per-character only stuff, since that wouldn't require data stage. Even so, there's still the difficulty of having a fairly scattered modding community, and getting people aware that such a library exists would be hard.
Aidiakapi
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 14, 2017 6:13 pm
Contact:

Re: Do not show disabled technologies in the technology list

Post by Aidiakapi »

I'm bumping this since it's still a big issue.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Do not show disabled technologies in the technology list

Post by bobingabout »

Arch666Angel wrote:hidden = true ?
I was thinking... I'm sure there's a way to do this already. That tag is what I was thinking of.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Do not show disabled technologies in the technology list

Post by eradicator »

bobingabout wrote:
Arch666Angel wrote:hidden = true ?
I was thinking... I'm sure there's a way to do this already. That tag is what I was thinking of.
Technologies do not currently have a .hidden property.
Aidiakapi
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 14, 2017 6:13 pm
Contact:

Re: Do not show disabled technologies in the technology list

Post by Aidiakapi »

Arch666Angel wrote:hidden = true ?
I wish. But that's pretty much what the enabled flag used to do. Since technologies with enabled = true and researched = true would still give bonuses, but not show up (under the condition they had another upgrade that wasn't researched yet in the same tree).
Aidiakapi
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 14, 2017 6:13 pm
Contact:

Re: Do not show disabled technologies in the technology list

Post by Aidiakapi »

Bump. Still an issue... Still breaking people's games all over the place.

At least there's now an event for when technology effects are reset, so I guess that's one thing. Other problems still remain.
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Do not show disabled technologies in the technology list

Post by Bilka »

I added TechnologyPrototype::hidden for 0.17.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Do not show disabled technologies in the technology list

Post by eradicator »

Bilka wrote:I added TechnologyPrototype::hidden for 0.17.
Thank you :).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Implemented mod requests”