summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-10-02 17:32:45 +0000
committerrubidium <rubidium@openttd.org>2014-10-02 17:32:45 +0000
commita14fad13ed6dda49e8c5a93b08b7f9d5893b33b5 (patch)
tree29332e13c70a89dbd576060c43d8cd9c8e88f993
parent896fa18bc019033b3a6167ab613367798c0eeb52 (diff)
downloadopenttd-a14fad13ed6dda49e8c5a93b08b7f9d5893b33b5.tar.xz
(svn r26945) -Fix-ish: better scaling of the "cells" in which variety distribution happens for non-square maps (attempt to make reasonably square areas)
-rw-r--r--src/tgp.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tgp.cpp b/src/tgp.cpp
index f12d15505..4a865ed55 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -511,9 +511,10 @@ static void HeightMapCurves(uint level)
height_t ht[lengthof(_curve_maps)];
MemSetT(ht, 0, lengthof(ht));
- /* Set up a grid to choose curve maps based on location */
- uint sx = Clamp(1 << level, 2, 32);
- uint sy = Clamp(1 << level, 2, 32);
+ /* Set up a grid to choose curve maps based on location; attempt to get a somewhat square grid */
+ float factor = sqrt((float)_height_map.size_x / (float)_height_map.size_y);
+ uint sx = Clamp(round((1 << level) * factor), 1, 128);
+ uint sy = Clamp(round((1 << level) / factor), 1, 128);
byte *c = AllocaM(byte, sx * sy);
for (uint i = 0; i < sx * sy; i++) {
@@ -524,7 +525,7 @@ static void HeightMapCurves(uint level)
for (uint x = 0; x < _height_map.size_x; x++) {
/* Get our X grid positions and bi-linear ratio */
- float fx = (float)(sx * x) / _height_map.size_x + 0.5f;
+ float fx = (float)(sx * x) / _height_map.size_x + 1.0f;
uint x1 = (uint)fx;
uint x2 = x1;
float xr = 2.0f * (fx - x1) - 1.0f;
@@ -541,7 +542,7 @@ static void HeightMapCurves(uint level)
for (uint y = 0; y < _height_map.size_y; y++) {
/* Get our Y grid position and bi-linear ratio */
- float fy = (float)(sy * y) / _height_map.size_y + 0.5f;
+ float fy = (float)(sy * y) / _height_map.size_y + 1.0f;
uint y1 = (uint)fy;
uint y2 = y1;
float yr = 2.0f * (fy - y1) - 1.0f;