Testing whether an _area_ has been charted
Posted: Thu Oct 01, 2020 9:04 am
We have force.is_chunk_charted(surface, position) to check if a specific point is in a charted chunk. Is there something similar that would do the same for the complete area (rectangle or circle) around a position?
In this particular case, I want to check if a square area ABCD is fully charted before doing anything. The sides AB, BC, CD, and DA have a maximum length of 600 tiles. The naive way would be to check that the 4 corners A, B, C, and D are all in charted chunks. However, due to the sides being considerably longer than one chunk (600 vs. 32 tiles), it could happen that A and B are in charted chunks, but the line AB goes through uncharted area. Therefore, I'd have to check not only the corner points, but also the lines (in 32 tile intervals) between them, i.e. 4 + 4 * int(side_length/32) times, which amounts to 76 positions for my 600x600 area. EDIT: Thinking again, it's even more! In an area of that size, I should make sure that not only the borders have been charted, but everything within the area, so I should check all positions in a grid, thus 4 + int(side_length/32) * int(side_length/32) positions -- 328 for a 600x600 area.
The maps that I want to be found are loot of trees. Loot is given with a probability of 0.005 for the 600x600 maps, and with a probability of 0.015 for the small 200x200 maps. That's not much per se, but if a player kills a forest with poison, grenades, fire, or nukes, many trees will die at once, so it's not unlikely that several maps are given as loot in a short period. I already make sure that each tree will give at most one map (the biggest one if several are in the loot), and if the tree dies from fire or explosive damage caused by a player (if caused by wild fires and similar mod events, all maps will be removed from the loot) I will even remove small maps and reduce big maps to something between 25% and 90% of their original size, so there's already some optimization. (On second thought, 600 tiles is a lot, perhaps I should use 300 tiles not as radius, but as diameter.) Still, I'm concerned that checking up to 76 positions for each map would take quite a dent out of performance. Is that really so, or can I use force.is_chunk_charted() that often without giving it a second thought?
In this particular case, I want to check if a square area ABCD is fully charted before doing anything. The sides AB, BC, CD, and DA have a maximum length of 600 tiles. The naive way would be to check that the 4 corners A, B, C, and D are all in charted chunks. However, due to the sides being considerably longer than one chunk (600 vs. 32 tiles), it could happen that A and B are in charted chunks, but the line AB goes through uncharted area. Therefore, I'd have to check not only the corner points, but also the lines (in 32 tile intervals) between them, i.e. 4 + 4 * int(side_length/32) times, which amounts to 76 positions for my 600x600 area. EDIT: Thinking again, it's even more! In an area of that size, I should make sure that not only the borders have been charted, but everything within the area, so I should check all positions in a grid, thus 4 + int(side_length/32) * int(side_length/32) positions -- 328 for a 600x600 area.
The maps that I want to be found are loot of trees. Loot is given with a probability of 0.005 for the 600x600 maps, and with a probability of 0.015 for the small 200x200 maps. That's not much per se, but if a player kills a forest with poison, grenades, fire, or nukes, many trees will die at once, so it's not unlikely that several maps are given as loot in a short period. I already make sure that each tree will give at most one map (the biggest one if several are in the loot), and if the tree dies from fire or explosive damage caused by a player (if caused by wild fires and similar mod events, all maps will be removed from the loot) I will even remove small maps and reduce big maps to something between 25% and 90% of their original size, so there's already some optimization. (On second thought, 600 tiles is a lot, perhaps I should use 300 tiles not as radius, but as diameter.) Still, I'm concerned that checking up to 76 positions for each map would take quite a dent out of performance. Is that really so, or can I use force.is_chunk_charted() that often without giving it a second thought?