Features of Infinite ressource

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Features of Infinite ressource

Post by Stargateur »

Context: I'm working on a little mod that make infinite resource destroy when they reach their minimum value, there is a number of mod that make infinite resource finite but they just override the infinite property of resource with false. I wanted something that keep the % bonus of infinite resource and the yield number. So, I looked the api/wiki to see what could be done. I found on_resource_depleted that look perfect:
Called when a resource entity reaches 0 or its minimum yield for infinite resources.
Problem:

While working on my mod I noticed yield of some oil field stop to decrease at different yield it's not uniform and so they get deleted too soon. Some reach 20% some not. I also notice that on_resource_depleted is not called if the field was already depleted not sure how I will solve that (probably scan all resources at start) but anyway. After some more digging the wiki have a explanation:
While cycles left is greater than 6000 (20% yield) and greater than 20% of the initially available cycles, each pumpjack cycle reduces the number of cycles left by one. source
While It's a little hard to understand, I conclude that if oil field was greater than 100% at the start you would not reach this minimum. That actually explain a lot I always wonder why when playing some field didn't yield the 2/s minimum, I always thought that it was just very... very slow :lol:

I may have not see all side effect of this but it's look that on_resource_depleted get called when either 20% yield is reach or 20% of the initially available cycles is reach. However, that a little annoying cause that mean I would destroy oil field that could still yell significant resource for oil field that start with high yield.

With more testing it's look this rule doesn't apply to all infinite resource, Infinite Resources - Normal Yields code doesn't look like it's use anything special but yield of "basic-solid" look to not have this rule, yield go from 100% to 5%. Is only "basic-fluid" categories of infinite resource have this 20% of initial cycle behavior ?

My point is that "greater than 20% of the initially available cycles" is kind of hidden property that doesn't really fit the minimum property of resource prototype. It was very unexpected so I create a bug report but Loewchen tell me it should go to API request (hope it's here), again sorry if this is the wrong section, I also may have missed documentation or didn't understand how infinite resource work.

Possible Solutions:

- Remove this "and greater than 20% of the initially available cycles".
- Make it somehow configurable so I can override this behavior.
- Anything you think would solve my problems
Last edited by Stargateur on Sat Sep 17, 2022 5:25 pm, edited 1 time in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14591
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Rseding91 »

Just make it non-infinite. If you want to to be destroyed when it reaches minimum yield; 0 is minimum and it will destroy the resource patch when it reaches 0 automatically.
If you want to get ahold of me I'm almost always on Discord.
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 794
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by ickputzdirwech »

You could replace a “depleted” infinite resource that has more than 20% yield with a new infinite resource with the same yield. It’s yield would then decrease further towards 20% yield until on_resource_depleted is called again.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Stargateur »

Just make it non-infinite. If you want to to be destroyed when it reaches minimum yield; 0 is minimum and it will destroy the resource patch when it reaches 0 automatically.
I try several thing, correct me if I'm wrong.

That was my first idea, the nice thing it that it would have work great with mod like YARM. But I can't "change" infinite property of an ResourceEntity at runtime, this is set by its prototype that isn't supposed to change at runtine. I would need to introduce a new prototype that is finite. On event depleted I would need to destroy the resource then create a new resource that is finite. And that not ideal cause the resource would stop being watched by mod like YARM.

I find some sort of hack:

Code: Select all

if resource.amount <= resource.prototype.minimum_resource_amount then
  resource.destroy()
else
  -- Hacky
  -- This allow to somehow override the behavior the basic-fluid deplete an either minimum value
  -- or 20% of initial amount.
  resource.initial_amount = resource.amount
end
Not exactly what I was having in mind for my mod but close enough.
You could replace a “depleted” infinite resource that has more than 20% yield with a new infinite resource with the same yield. It’s yield would then decrease further towards 20% yield until on_resource_depleted is called again.
Ah yeah also, but again that would "delete" the resource making YARM not track it (thus maybe YARM have a API for that).
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 539
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Silari »

Instead of deleting it couldn't you just set the initial_amount to the current value when on_resource_depleted fires? From my understanding that should make it start depleting to a new minimum, since the initial_amount is what determines what the minimum yield is. Haven't tried it though to confirm.
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Stargateur »

Silari wrote: Sat Sep 17, 2022 12:16 am Instead of deleting it couldn't you just set the initial_amount to the current value when on_resource_depleted fires? From my understanding that should make it start depleting to a new minimum, since the initial_amount is what determines what the minimum yield is. Haven't tried it though to confirm.
See the code snipped of my previous message, yeah, that work, it's even trigger a new depleted event again when time come and resource get deleted.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by FuryoftheStars »

Stargateur wrote: Fri Sep 16, 2022 3:34 pm I would need to introduce a new prototype that is finite.
You don’t need to create a new one. Just edit the existing in the data stage.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Stargateur »

FuryoftheStars wrote: Sat Sep 17, 2022 1:49 am
Stargateur wrote: Fri Sep 16, 2022 3:34 pm I would need to introduce a new prototype that is finite.
You don’t need to create a new one. Just edit the existing in the data stage.
My purpose is to keep the behavior of infinite resource, they have bonus to productivity when > 100%, I want to make a mod that keep "yield" mechanic of the game but make resource disappear at some time. Most other mod make infinite ressource finite losing the bonus productivity of infinite resource and it's not my purpose.
I'm working on a little mod that make infinite resource destroy when they reach their minimum value, there is a number of mod that make infinite resource finite but they just override the infinite property of resource with false. I wanted something that keep the % bonus of infinite resource and the yield number.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by FuryoftheStars »

Ok, I’ll admit, I didn’t fully read your initial post, so I was replying off from your reply to Rseding.

I do have to say, despawning an infinite resource after it depletes seems completely counter to the point of having infinite resources. To me at least.

As for the difference in behavior between solid infinite resources and fluid infinite, if I had to take a guess based on the dev response you received in the other thread, I’d say that this is because there’s code in the base game’s vanilla resource generation specifically for fluid resources that causes this. You have to remember, the base game was designed for fluid resources to be infinite, not solid (although it supports it, it’s not quite the same), so they probably only included handling for the fluids.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Infinite ressource like Oil doesn't respect minimum property for depletion

Post by Stargateur »

FuryoftheStars wrote: Sat Sep 17, 2022 1:06 pm I do have to say, despawning an infinite resource after it depletes seems completely counter to the point of having infinite resources. To me at least.
Thus I also like play with infinite resource I wanted to explore finite oil, I wanted a more "real" behavior. I will try to explain the rational of why I keep them infinite:

As I said, the behavior of infinite resource and finite resource are different, when you have 255% you have 100% of chance to mine 2 and 55% of chance to mine +1. This multiply the speed and productivity of a resource, while by making oil resource finite you could calculate the real amount the oil would have been you loose the speed bonus. Infinite and finite difference is deeper that just being infinite or not in factorio.

Also, this mean that for the same amount of oil the more % the field is the slower its deplete, for a field with 500-600% you will loose 1% by 300 cycles but you will produce like 165 000 * 10 oil while at 100-200% with 300 cycle you would produce 45 000 * 10. Cause a infinite amount resource only loose fixed amount of resource even when it's produce more and only when it's at least produced some (mean that infinite get depleted faster the closer they go to 100% (for the same amount of resource) then they get depleted slower the closer to 0%, actually go from 10 % to 0% is insanely long for almost no oil.)

As far as I understand that something like that (could be wrong):

Image
FuryoftheStars wrote: Sat Sep 17, 2022 1:06 pm As for the difference in behavior between solid infinite resources and fluid infinite, if I had to take a guess based on the dev response you received in the other thread, I’d say that this is because there’s code in the base game’s vanilla resource generation specifically for fluid resources that causes this. You have to remember, the base game was designed for fluid resources to be infinite, not solid (although it supports it, it’s not quite the same), so they probably only included handling for the fluids.
That mostly it, but my question is about why the rule is different, it's obvious to say it's in the code. Why fluid have this property and not infinite solid or say otherwise why not ? And also more importantly, how could we get the same thing for solid resource and how could we override the 20% of initial resource to let's say 40% ?
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Features of Infinite ressource

Post by FuryoftheStars »

Yes, I do know about the mining behavior of infinite resources. I did create a mod specifically designed to avoid the >100% behavior. :)

I guess my point is more this: a regular resource patch full of miners already easily fills red & blue belts, so why go for the behavior where the miners are outputting so much at once that they choke? And then delete the patch as if it were finite?
Stargateur wrote: Sat Sep 17, 2022 3:21 pmbut my question is about why the rule is different
Because it’s not needed or used for item resources. It’s code that would require another IF check for every tile laid and would never be used in vanilla.

It should be noted, this isn’t a difference in the prototypes or the fields used. It’s a difference in the values set as each tile of the resource is spawned.

It sounds to me like this was special case code added by the devs to make finding larger oil patches still meaningful even after depleting them. As item resources are never infinite in vanilla, and it would add an extra few cycles to each tile’s spawn time to run an IF check that would always evaluate the same, they just never included them.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Features of Infinite ressource

Post by Stargateur »

FuryoftheStars wrote: Sat Sep 17, 2022 5:52 pm I guess my point is more this: a regular resource patch full of miners already easily fills red & blue belts, so why go for the behavior where the miners are outputting so much at once that they choke? And then delete the patch as if it were finite?
Already explained productivity bonus behavior of infinite resource. Also, mostly talking about oil use case here. I have the feeling you don't understand my point of view you are only see your point of view "I did create a mod specifically designed to avoid the >100% behavior." You seem to not understand/accept I would like to keep this behavior cause you did the exact opposite with your mod :lol: .
FuryoftheStars wrote: Sat Sep 17, 2022 5:52 pm Because it’s not needed or used for item resources. It’s code that would require another IF check for every tile laid and would never be used in vanilla.
If there is a different between solid and fluid behavior (that I still not sure, my test are limited and answer are hard to find) so the IF is already there... on the contrary what I'm asking would remove this IF.
FuryoftheStars wrote: Sat Sep 17, 2022 5:52 pm It sounds to me like this was special case code added by the devs to make finding larger oil patches still meaningful even after depleting them.
Yes, that what Rseding91 said in other thread and that ok for me. Again my point is that I can't control this percentage (thus you can hack initial_amount but that clearly a hack) and seem It only affect oil.

P.S: turn out my premise was wrong, viewtopic.php?p=574243#p574243
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Features of Infinite ressource

Post by FuryoftheStars »

Stargateur wrote: Sat Sep 17, 2022 6:13 pm Already explained productivity bonus behavior of infinite resource.
Yes, and I’m trying to understand why (when without already fills belts) and why this method (miners have a base_productivity property to them that would allow for a productivity bonus).
Stargateur wrote: Sat Sep 17, 2022 6:13 pm I have the feeling you don't understand my point of view you are only see your point of view "I did create a mod specifically designed to avoid the >100% behavior." You seem to not understand/accept I would like to keep this behavior cause you did the exact opposite with your mod
Erm, no, I’m simply asking to understand and see if there’s another way. Your idea does seem counter intuitive to me, but that doesn’t necessarily mean it’s wrong. I just don’t understand what you hope to gain from it. Productivity… yes, but to what end? To fill the belts more? To get more resources out of a field? To me, this does not seem like a good solution to either, so I’m wondering if there is something else?

And I brought out the “I’ve done a mod on infinite resources” card because you started explaining to me how infinite resources work. Thus: Yes, I’m already aware of that. "I did create a mod specifically designed to avoid the >100% behavior."
Stargateur wrote: Sat Sep 17, 2022 6:13 pm
FuryoftheStars wrote: Sat Sep 17, 2022 5:52 pm Because it’s not needed or used for item resources. It’s code that would require another IF check for every tile laid and would never be used in vanilla.
If there is a different between solid and fluid behavior (that I still not sure, my test are limited and answer are hard to find) so the IF is already there... on the contrary what I'm asking would remove this IF.
FuryoftheStars wrote: Sat Sep 17, 2022 5:52 pm It sounds to me like this was special case code added by the devs to make finding larger oil patches still meaningful even after depleting them.
Yes, that what Rseding91 said in other thread and that ok for me. Again my point is that I can't control this percentage (thus you can hack initial_amount but that clearly a hack) and seem It only affect oil.

P.S: turn out my premise was wrong, viewtopic.php?p=574243#p574243
That’s good Rseding explained that piece to you.

I won’t have computer access for at least a couple more days, so I can’t log in to verify, but from memory, what I suspect is happening between oil and item resources to cause oil to have different minimums from items (when spawned in game) is in these 2 properties of resource entities: amount and initial_amount. These can be set independently. In the specific case of oil, I believe it is setting the initial_amount differently from item based resources.

Now yes, maybe it would be a case of removing the check, but then you’re still opening it up so that every tile of spawned item resource will need to run the extra code. I’m not saying that it couldn’t or shouldn’t be done, I’m just saying I understand why it wasn’t done. I’m not sure that allowing it would have any value, either, though. For a field of hundreds or even thousands of tiles of a resource, there’s not much point in either having the whole field’s minimum be higher, or allowing some within the field be higher than others (however the code logic works).
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
Stargateur
Fast Inserter
Fast Inserter
Posts: 195
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: Features of Infinite ressource

Post by Stargateur »

FuryoftheStars wrote: Sat Sep 17, 2022 9:19 pm Yes, and I’m trying to understand why (when without already fills belts) and why this method (miners have a base_productivity property to them that would allow for a productivity bonus).

Erm, no, I’m simply asking to understand and see if there’s another way. Your idea does seem counter intuitive to me, but that doesn’t necessarily mean it’s wrong. I just don’t understand what you hope to gain from it. Productivity… yes, but to what end? To fill the belts more? To get more resources out of a field? To me, this does not seem like a good solution to either, so I’m wondering if there is something else?
Cause I don't want to change the behavior of oil/fluid resource, oil in reality behave mostly like in factorio, you get a lot of petroleum in the beginning and the pressure will decrease until you get nothing.

If I understand correctly let say a field is 1000% that mean the amount is 3_000_000 the real amount you would get would be something like 3_000_000 * 5, and you would get it fast at start and slow at the end. Removing the infinite aspect of course, cause with vanilla behavior you would stop at 200% yield and get infinity resource.

My purpose is too keep the behavior of fluid output that slow over time. I don't want tweak a pumpjack productivity or make the resource finite and multiply the amount to reflect real expected amount. I want to keep vanilla oil balancing while just removing the minimum infinite yield to not allow infinite mining of oil. It may seem weird I don't know :lol: it's make sense for me.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Features of Infinite ressource

Post by FuryoftheStars »

Ah, ok, I understand better now. :) And the fact that oil seems to trigger the depletion event at different percentages is messing up the idea (some)?

Without rereading everything, so not knowing if someone has suggested this (and without being able to fire up the game to test), my off-the-cuff suggestion is to continue using the on_resource_depleted event, check if the calling resource is oil (and infinite!), then check if the initial_amount > normal_resource_amount. If it is, set initial_amount = normal_resource_amount. Otherwise, delete the resource.

This is, of course, assuming I’ve done my math correctly and that a resource entity can call on_resource_depleted a second time (if not, then you’ll want to destroy() and recreate it).

And you can, of course, use a different value from normal_resource_amount if you prefer to have them deplete for the second time at a different value than the prototype’s set minimum.

This will allow oil to deplete to its current minimum (based on its set initial_amount), then continue depleting to the resource entity’s prototype set minimum (or other if you choose a different value above) before finally triggering its deletion.

You can also, as you’ve discovered, set the prototype’s infinite_depletion_amount to allow it to deplete slower (or faster) if you desire.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Post Reply

Return to “Modding interface requests”