Issue-Tracker icon indicating copy to clipboard operation
Issue-Tracker copied to clipboard

About the new_town_min_distance_from_town_plot config

Open MrToirol opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

As you may know, Towny as it is configured on EMC will prevent you from making a town if you are too close to another town's claims (defined in the config, currently 3 chunks). I have been discussing the topic with @Aylywyn and looked at the code to determine exactly how Towny implements this. It turns out that Towny uses Euclidean distance (Pythagoras' theorem), which is not the best practice in this kind of case. Anyway, the getMinDistanceFromOtherTownsPlots method, used to calculate the distance to the closest town, returns a rounded up number. This will be important for the example below:

Example image

In the image, you can see that pale green chunks are only sqrt(2² + 1²) ≈ 2.24 chunks away from the claimed chunk (red). However, as said above, these values are rounded up, in this case to 3. Right, now you might be thinking it will still be protected since the config is 3. Well no, when a player tries to create a town, the testDistancesOrThrow method is used to check if the location meets the conditions. This method calls getMinDistanceFromTownPlotblocks and asserts that the distance to the closest existing town is superior or equal to the config (if it is strictly inferior Towny will throw an error). This means that pale green, dark green and grey chunks are not considered in range and therefore are not protected. This is not clearly communicated by Towny, and I believe more chunks should be protected.

Describe the solution you'd like

To keep it simple, without changing Towny's distance calculation method, my suggestion is to either:

  • increase the new_town_min_distance_from_town_plot config to 4 (same problem but at least further away)
  • replace "strictly inferior" with "inferior or equal" → all the chunks on the image are protected, including the grey ones (This example is only valid with 3)
  • round the square root/distance down instead of up → all the chunks on the image except the grey ones are protected (This example is only valid with 3)

The last two solutions would require editing the code directly, but it's really not much and EMC already uses a tweaked/patched version of Towny.

Additional context

No response

MrToirol avatar Oct 06 '23 17:10 MrToirol

This covers the technical details better than I would have. I'll just add a less technical commentary.

Ideally (not always possible...), you'd use a more intuitive system at "human" scales and something like Euclidean at long distances where the "computer" needs to do math. That transition is probably around the 32 chunk range, especially in EMC given the maximum town size of 940.

Most people will instinctively use Manhattan counting (https://chris3606.github.io/GoRogue/articles/grid_components/measuring-distance.html) and Chebyshev is very obvious for gaming purposes, making obvious rings/zones of control.

Euclidean is both non-obvious and makes fine adjustments at low-scales difficult and giving unintuitive results.

Aylywyn avatar Oct 06 '23 18:10 Aylywyn