How to interpret "probability" property expression?

Place to get help with not working mods / modding interface.
Post Reply
Natha
Fast Inserter
Fast Inserter
Posts: 199
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

How to interpret "probability" property expression?

Post 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
Unbenannt.PNG (767.87 KiB) Viewed 1082 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?

mmmPI
Smart Inserter
Smart Inserter
Posts: 3372
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: How to interpret "probability" property expression?

Post 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.

Natha
Fast Inserter
Fast Inserter
Posts: 199
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: How to interpret "probability" property expression?

Post by Natha »

mmmPI wrote:
Fri Apr 26, 2024 10:00 am
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.
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).

mmmPI
Smart Inserter
Smart Inserter
Posts: 3372
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: How to interpret "probability" property expression?

Post 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
noobmecantseeproblem.jpg (82.7 KiB) Viewed 916 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 ? :)

Natha
Fast Inserter
Fast Inserter
Posts: 199
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: How to interpret "probability" property expression?

Post by Natha »

mmmPI wrote:
Mon Apr 29, 2024 11:01 am
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 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

Code: Select all

/test gen
.
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.
Attachments
test_0.0.1.zip
(1.08 KiB) Downloaded 31 times

mmmPI
Smart Inserter
Smart Inserter
Posts: 3372
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: How to interpret "probability" property expression?

Post 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 :)

Genhis
Factorio Staff
Factorio Staff
Posts: 397
Joined: Wed Dec 24, 2014 8:19 am
Contact:

Re: How to interpret "probability" property expression?

Post 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).

Natha
Fast Inserter
Fast Inserter
Posts: 199
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: How to interpret "probability" property expression?

Post 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
Unbenannt.PNG (3.09 MiB) Viewed 816 times

Genhis
Factorio Staff
Factorio Staff
Posts: 397
Joined: Wed Dec 24, 2014 8:19 am
Contact:

Re: How to interpret "probability" property expression?

Post 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?

Natha
Fast Inserter
Fast Inserter
Posts: 199
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: How to interpret "probability" property expression?

Post 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.

Post Reply

Return to “Modding help”