Page 1 of 1

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

Posted: Fri Sep 16, 2022 4:06 am
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.

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 that may fit in "mod request", I'm not used to this forum so pardon me. 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

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

Posted: Fri Sep 16, 2022 8:51 am
by Loewchen
This is not a bug, make an API request.

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

Posted: Fri Sep 16, 2022 10:42 am
by Stargateur
This is not a bug
I would have expect an argument about this. I raise my case with some strong argument. More testing of my side show very weird inconsistency, it's look this 20% of initial cycle doesn't affect other infinite resource. Are you as a moderator allowed to judge if something about game design and ambiguous behavior is not a bug ? It's a complex case, I would have prefer at least an argument about why.
make an API request.
Will do so. Thanks.

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

Posted: Fri Sep 16, 2022 11:24 am
by Loewchen
Maybe I am misunderstanding. Is the problem that crude oil resources that start at a higher initial yield, fire on_resource_depleted at a point where their yield can still decrease or is the problem their lowest yield (the actual point where the yield does not decrease anymore) is just higher than for those that start between 20% to 100%?

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

Posted: Fri Sep 16, 2022 11:36 am
by Stargateur
Maybe I am misunderstanding.
Sorry, english not my native language and I have dyslexia problem. I'm not the best for english writing.
Is the problem that crude oil resources that start at a higher initial yield, fire on_resource_depleted at a point where their yield can still decrease
No, it's look `on_resource_depleted()` event trigger when either 20% of initial cycle is reach or that 20% minimum yield is reach (that is great, cause if not the resource would never trigger depleted).
is the problem their lowest yield (the actual point where the yield does not decrease anymore) is just higher than for those that start between 20% to 100%?
Yes, this is the problem cause there is no way (AFAIK) to override this behavior, also this behavior break the expectation of minimum property of prototypes resource and finally look like it's may be a special rule just for oil or all "basic-fluid" resource categories (I would need to install some mod that add other infinite fluid to check I hoped a dev could quickly answer this, I will probably check that latter, testing this take a lot of time, I'm a beginner in factorio modding).

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

Posted: Fri Sep 16, 2022 2:39 pm
by Rseding91
That behavior is intended. It makes finding higher yield oil deposits actually meaningful rather than having no difference after they are depleted.

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

Posted: Fri Sep 16, 2022 3:36 pm
by Stargateur
Rseding91 wrote: Fri Sep 16, 2022 2:39 pm That behavior is intended. It makes finding higher yield oil deposits actually meaningful rather than having no difference after they are depleted.
Make sense, thank for the answer, but why this behavior is not apply to infinite basic-solid resource category ? (unless I'm wrong about that)

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

Posted: Sat Sep 17, 2022 2:29 am
by Rseding91
Stargateur wrote: Fri Sep 16, 2022 3:36 pm
Rseding91 wrote: Fri Sep 16, 2022 2:39 pm That behavior is intended. It makes finding higher yield oil deposits actually meaningful rather than having no difference after they are depleted.
Make sense, thank for the answer, but why this behavior is not apply to infinite basic-solid resource category ? (unless I'm wrong about that)
It is, the produces items vs fluids makes no difference to the infinite part of the resource.

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

Posted: Sat Sep 17, 2022 9:56 am
by Stargateur
Rseding91 wrote: Sat Sep 17, 2022 2:29 am
Stargateur wrote: Fri Sep 16, 2022 3:36 pm Make sense, thank for the answer, but why this behavior is not apply to infinite basic-solid resource category ? (unless I'm wrong about that)
It is, the produces items vs fluids makes no difference to the infinite part of the resource.
Sorry to bother you again but I'm was not talking about the productivity. My point is that "solid" resource doesn't have the 20% of initial value limit like fluid have. (At least according to my testing)

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

Posted: Sat Sep 17, 2022 1:38 pm
by Rseding91
There is no concept of solid vs fluid when it comes to resources. The resource entity itself only knows if it's infinite or not. It can be infinite, and produce nothing, fluid, fluid and items, or just items. It's all the same logic when it comes to infinite vs not.

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

Posted: Sat Sep 17, 2022 3:36 pm
by Stargateur
This is not the case according to my observation of oil behavior and behavior of infinite ore of Infinite Resources - Normal Yields with setting start at 100% (so initial amount = 100) and min to 5%, the resource doesn't stop at 20% but at 5%. So I don't understand the rule "minimum = max(minimum , 20% initial amount)" for infinite resource seem to only apply to oil.

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

Posted: Sat Sep 17, 2022 4:45 pm
by Nidan
Stargateur wrote: Sat Sep 17, 2022 3:36 pm This is not the case according to my observation of oil behavior and behavior of infinite ore of Infinite Resources - Normal Yields with setting start at 100% (so initial amount = 100) and min to 5%, the resource doesn't stop at 20% but at 5%. So I don't understand the rule "minimum = max(minimum , 20% initial amount)" for infinite resource seem to only apply to oil.
Have you considered the idea that the 20% aren't hardcoded, but are also affected by the minimum specified in the prototype? I.e. minimum_yield = prototype_minimum * max(100%, initial_yield)

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

Posted: Sat Sep 17, 2022 5:06 pm
by Stargateur
Nidan wrote: Sat Sep 17, 2022 4:45 pm Have you considered the idea that the 20% aren't hardcoded, but are also affected by the minimum specified in the prototype? I.e. minimum_yield = prototype_minimum * max(100%, initial_yield)
I already looked but didn't find such field, the wiki doesn't, and the source code neither. I search for difference but didn't found any. Thanks for the suggestion, if you find something tell me ^^.

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

Posted: Sat Sep 17, 2022 5:48 pm
by Nidan
Stargateur wrote: Sat Sep 17, 2022 5:06 pm
Nidan wrote: Sat Sep 17, 2022 4:45 pm Have you considered the idea that the 20% aren't hardcoded, but are also affected by the minimum specified in the prototype? I.e. minimum_yield = prototype_minimum * max(100%, initial_yield)
I already looked but didn't find such field, the wiki doesn't, and the source code neither. I search for difference but didn't found any. Thanks for the suggestion, if you find something tell me ^^.
The names I used were to avoid having all things named the same. Yield in particular because that's what displayed ingame and can apparently be converted to the actual properties (someone quoted https://wiki.factorio.com/Crude_oil saying 6000 "cycles" being 20% yield. (With cycles being https://lua-api.factorio.com/latest/Lua ... rce_amount / https://wiki.factorio.com/Prototype/Res ... ty#minimum? The documentation, or at least that part, seems to have "getX() -- gets X"-quality))

Your observation of
Stargateur wrote: [W]ith setting start at 100% (so initial amount = 100) and min to 5%, the resource doesn't stop at 20% but at 5%.
would at least line up with my suggested formula.

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

Posted: Sat Sep 17, 2022 6:23 pm
by Rseding91
A resource minimum amount when set to infinite is calculated like this:

Code: Select all

math.max(initial_amount / (normal / minimum), minimum)
And the depletion logic works like this:

Code: Select all

if (prototype.infinite)
{
  local richness_modifier = resource.amount / prototype.normal;
  local minimum = math.max(resource.initial_amount / (prototype.normal / prototype.minimum), prototype.minimum);
  if (resource.amount > minimum and math.random() < richness_modifier)
  {
    resource.amount = resource.amount - math.min(resource.amount, prototype.infinite_depletion_amount);
    if (resource.amount <= minimum)
    {
      resource.amount = minimum;
      -- send resource depleted lua event
    }
  }
}
None of the logic cares about fluids vs items.

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

Posted: Sat Sep 17, 2022 6:31 pm
by Stargateur
@Nidan minimum and minimum_resource_amount is the same, but you are a genius, that was exactly that, so the behavior IS the same, I get fouled by the mod, I should have tested with a field starting at 200%, my bad. Thank you very much ! And Rseding91 just confirmed ^^, thank you all for your time It's way more clear now.

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

Posted: Sat Sep 17, 2022 7:22 pm
by Nidan
Could someone with a wiki account expand https://wiki.factorio.com/Prototype/ResourceEntity with some explanation how the individual properties tie together? Likewise, a dev add a link to that text to the corresponding properties of LuaEntity?

Text suggestion that probably can be improved on:
Infinite resources ("infinite = true") behave differently from finite resources. Each mining operation decreases the resources richness by "infinite_depletion_amount". Ingame the remaining resources are displayed as remaining "yield", which is a percentage and defined as the current richness divided by "normal". Fluid results scale their output by this yield (is this actually correct?); item results are produced once for every 100% yield, any remaining yield is treated as a chance to produce an extra set of results. The richness of each resource will only decrease to a set minimum, calculated as "max((minimum / normal) * initial_richness, minimum)". Upon reaching that minimum the on_resource_depleted event is fired.

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

Posted: Sat Sep 17, 2022 7:24 pm
by Nidan
Stargateur wrote: Sat Sep 17, 2022 6:31 pm @Nidan minimum and minimum_resource_amount is the same.
I linked both since the name is different in data and control stage. The / wasn't meant as division.