abaines / Resource-Marker

Factorio Mod
Other
5 stars 7 forks source link

Incorrect resource counts (most commonly for oil fields) #18

Open alexbarrett opened 2 years ago

alexbarrett commented 2 years ago

I noticed some incorrect totals for some markers created by this mod so I did some testing to investigate. My findings were:

  1. Most oil patches are marked incorrectly.
  2. Most ore resources are marked correctly.

I made a small mod to count resources in a large radius (32) around the player, and compared them to the amount shown in the markers created by this mod. Here are the screenshots:

Examples of incorrectly totaled oil fields

  1. Marker shows 2.7M, real total is 1.3M oil-1

  2. Marker shows 6.9M, real total is 5.9M oil-3-6 9M

  3. Marker shows 3.9M, real total is 3.6M oil-4

  4. Marker shows 10.4M, real total is 9.7M oil-6

  5. Marker shows 7.6M, real total is 6.7M oil-7

Examples of correctly totaled oil fields

  1. Marker correctly shows 864k oil-2-correct

  2. Marker correctly shows 2.6M oil-5-correct

Example of an incorrectly totaled stone patch

  1. Marker shows 5.3M, real total is 4.7M. I tested a lot of ore patches and they were all correct except this one. stone-1
abaines commented 2 years ago

Thank you for the report! ๐Ÿฐ

My mod just:

  1. For each resource:
  2. sums the amount of that resource in each chunk
  3. then loop the following until nothing happens
  4. for each chunk, if there is a neighboring chunk (N,S,E,W) with >0 of the same resource, group and add them into one "total"
  5. continue trying to merge and group chunks until there are no neighboring chunks with the same resource
  6. (when grouping, use a weighted centering (to pick center of new merged patch))
  7. profit

I forget the logic when new chunks get added, but I'd suspect it is very similar.

The mod doesn't try to do any math related to amounts or efficiency, it just reports what the Factorio Mod API reports and adds them.

Is the mod always over-reporting? ๐Ÿค” Do you know if it only happens on starting chunks or newly generated chunks? ๐Ÿ‘ถ How do the numbers reported by the base Factorio map compare? Do you have a link to your mod/source-code that does the ore counting?

And thanks again for collecting these details! ๐Ÿงก

alexbarrett commented 2 years ago

Is the mod always over-reporting? ๐Ÿค”

Yes, from what I have seen it is always correct or over-reporting. I've never seen it under-report.

Do you know if it only happens on starting chunks or newly generated chunks? ๐Ÿ‘ถ

Most of these screenshots were taken from the same map. I manually ran around checking many resource patches. I don't recall if the incorrect stone patch was a starting chunk or not, but the oil fields are usually incorrect no matter where they are.

How do the numbers reported by the base Factorio map compare?

The number shown by base Factorio on the map always matches the one shown as "Nearby Resources" in the screenshot (rounded down). I checked them all to make sure my mod was working.

Do you have a link to your mod/source-code that does the ore counting?

It's not published anywhere because I only made it to learn how the Factorio modding API works. I have pasted it as a Gist for you so you can see it: https://gist.github.com/alexbarrett/4bc8c4d1cf271861357af87ae3ccfba1. Lines 51-69 is where it sums the total.

abaines commented 2 years ago

Would it be possible the chunks are generating with the amounts my mod says on the first tick, but later in that tick or the next one, some of the resources are removed via trees, cliffs, spawners, other terrain generation, etc.? ๐Ÿค”