Page 1 of 1
How to interpret "probability" property expression?
Posted: Tue Apr 23, 2024 10:18 pm
by Natha
I try to replicate crude oil placement. But I don't really know how the probability expression works.
The following code prints probability (white) and richness (yellow) values on each position:
Code: Select all
local calcresult = surface.calculate_tile_properties({"entity:crude-oil:probability", "entity:crude-oil:richness"}, pos_arr)
for i,v in ipairs(calcresult["entity:crude-oil:probability"]) do
rendering.draw_text{text=string.format("%.2f", v), surface=surface, target={pos_arr[i][1], pos_arr[i][2]}, color={1, 1, 1}, scale=0.5}
rendering.draw_text{text=string.format("%.2f", calcresult["entity:crude-oil:richness"][i]), surface=surface, target={pos_arr[i][1], pos_arr[i][2]+0.2}, color={1, 1, 0}, scale=0.3}
end
which looks like this:

- Unbenannt.PNG (767.87 KiB) Viewed 1729 times
The game engine sets crude oil resources on positions with probability values of -39.66 and -16.34. I don't see a determinism there, as there are lower and higher values around without a resource entity.
So how do I know, where to place them?
Re: How to interpret "probability" property expression?
Posted: Fri Apr 26, 2024 10:00 am
by mmmPI
Sorry if that's not very helpful : i attempted to use the code linked because i was curious, but i got an error when using it as console command.
I wanted to test an hypothesis, because i think i read something one time but couldn't find source that there are special rules for crude oil placement to make sure it is always possible to place a pumpjack and/or a pipe connected to it, in the vanilla generation.
On the screenshot i see 2 values above 0 and 2 crude oil patch, i was wondering if it was a coincidence.
If there could be a relation between the number of positive number show in white, the probability, when positive, means "1" crude oil patch. But then some other rules applies to locate it on the map so they do not overlap or be placed next to each other directly which would prevent players to place 2 pumpjacks.
I may have attempted something that make no sense, due to ignorance, i copied the code in the console, with "/c" before. Then tried on a surface called surface.
Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 9:43 am
by Natha
mmmPI wrote: Fri Apr 26, 2024 10:00 amI wanted to test an hypothesis, because i think i read something one time but couldn't find source that there are special rules for crude oil placement to make sure it is always possible to place a pumpjack and/or a pipe connected to it, in the vanilla generation.
Thats a good point. I just tried generating an oil patch anywhere with a probability > 0 and there are way more patches per oil field than I would expect (with around 1 or 2 pairs colliding).
Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 11:01 am
by mmmPI
That must be at least 3 or 4 years maybe double that since i read that in an FFF maybe not sure, i tried looking at the changelog for crude oil in the wiki to see if at some version of the game it was mentionned a rule for placement that would differ, but i couldn't find anything.
I would have tried to look at the map for other spot with positive probabilities, and see if there was always 1 pumpjack attached, are some of them moved away ? or removed ? when colliding.
I didn't expected another number for yield, i thought when one pumpjack was removed, its yield was split around the other pumpjack and that would explain the differences in yield from pumpjack with the same distance from the origin.
I'm still interested in trying out the code btw, is it supposed to be in a mod and not a console command ?
When naively copy pasting the code i'm getting this :

- noobmecantseeproblem.jpg (82.7 KiB) Viewed 1563 times
Cannot execute command. Error [string"local calcresult = surface.calculate_tile_pro..."] 1: attempt too index global 'surface' (a nil value)
I have no idea what i'm doing, is it far from showing something useful ?

Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 2:38 pm
by Natha
mmmPI wrote: Mon Apr 29, 2024 11:01 amI would have tried to look at the map for other spot with positive probabilities, and see if there was always 1 pumpjack attached, are some of them moved away ? or removed ? when colliding.
I don't know if there are spots outside of whole oil patches with positive probability, but then richness would be negative which is also important.
The code was a debugging snippet inside my mod, the whole code is too much for just a console command. I put it together in a small mod and attached it here. It shows numbers where richness > 0 with a blue dot where probability > 0, when running the command
.
Another thing I just found: when moving after executing the command and executing it again, completely new probability values show up! Apparently the random numbers are influenced by the given position array, which changes the result for one specific position.
Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 5:48 pm
by mmmPI
Thank you for the explanations, i've been looking at it, will check further ,but no guarantees, i'd only update if i find something or if cannot make it work still

Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 7:20 pm
by Genhis
Natha wrote: Mon Apr 29, 2024 2:38 pm
Another thing I just found: when moving after executing the command and executing it again, completely new probability values show up! Apparently the random numbers are influenced by the given position array, which changes the result for one specific position.
This is indeed true when a noise expression uses the random-penalty function which resource entities do. To replicate game behavior, you should start at chunk boundaries and ask for a full chunk, going row by row (32x32 tiles total). Then, an entity with the highest probability is picked to appear on that tile. Probability value is checked against a randomly-generated [0, 1] value. 0 or less means the entity won't spawn, 1 or more means it will certainly spawn (unless prevented by other rules, such as collision checks).
Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 9:26 pm
by Natha
Genhis wrote: Mon Apr 29, 2024 7:20 pm
Natha wrote: Mon Apr 29, 2024 2:38 pm
Another thing I just found: when moving after executing the command and executing it again, completely new probability values show up! Apparently the random numbers are influenced by the given position array, which changes the result for one specific position.
This is indeed true when a noise expression uses the random-penalty function which resource entities do. To replicate game behavior, you should start at chunk boundaries and ask for a full chunk, going row by row (32x32 tiles total). Then, an entity with the highest probability is picked to appear on that tile. Probability value is checked against a randomly-generated [0, 1] value. 0 or less means the entity won't spawn, 1 or more means it will certainly spawn (unless prevented by other rules, such as collision checks).
Thanks a lot! I could now produce blue dots (probability > 0) on all crude oil entities for sure, but also some more.
An entity appeared on the tile with the highest probability of 0.71. But as you see, the bottom entity has a probability of 0.43 while the tile above has 0.54. If I understand correctly, all but the first one (0.71) are generated based on that random value you mentioned. Am I able to reproduce this random value or is this based on map generation progress and therefore near to "real" random?

- Unbenannt.PNG (3.09 MiB) Viewed 1463 times
Re: How to interpret "probability" property expression?
Posted: Mon Apr 29, 2024 10:30 pm
by Genhis
It's hard to say. Assuming it didn't fail on richness, it could have collided with other entities, although it doesn't seem to be the case.
What is your use case?
Re: How to interpret "probability" property expression?
Posted: Tue Apr 30, 2024 5:48 am
by Natha
Genhis wrote: Mon Apr 29, 2024 10:30 pm
What is your use case?
I want to mirror resources onto another surface. For patches like crude oil, the excat position is not that important but the probability should stay the same.
According to prototype stage, crude oil should have a probability of 1/48, which is the blue dots, but after applying another random value check the resulting probability is much lower than that.