summaryrefslogtreecommitdiff
path: root/src/tgp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tgp.cpp')
-rw-r--r--src/tgp.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/tgp.cpp b/src/tgp.cpp
index d7f9722f9..897aad3bf 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -14,6 +14,7 @@
#include "tgp.h"
#include "console.h"
#include "genworld.h"
+#include "helpers.hpp"
/*
* OTTD Perlin Noise Landscape Generator, aka TerraGenesis Perlin
@@ -190,9 +191,8 @@ static HeightMap _height_map = {NULL, 0, 0, 0, 0};
#define A2I(i) ((i) >> amplitude_decimal_bits)
/** Conversion: amplitude_t to height_t */
-#define A2H(a) ((height_decimal_bits < amplitude_decimal_bits) \
- ? ((a) >> (amplitude_decimal_bits - height_decimal_bits)) \
- : ((a) << (height_decimal_bits - amplitude_decimal_bits)))
+#define A2H(a) ((a) >> (amplitude_decimal_bits - height_decimal_bits))
+
/** Walk through all items of _height_map.h */
#define FOR_ALL_TILES_IN_HEIGHT(h) for (h = _height_map.h; h < &_height_map.h[_height_map.total_size]; h++)
@@ -239,7 +239,7 @@ static inline bool AllocHeightMap(void)
/* Allocate memory block for height map row pointers */
_height_map.total_size = (_height_map.size_x + 1) * (_height_map.size_y + 1);
_height_map.dim_x = _height_map.size_x + 1;
- _height_map.h = calloc(_height_map.total_size, sizeof(*_height_map.h));
+ CallocT(&_height_map.h, _height_map.total_size);
if (_height_map.h == NULL) return false;
/* Iterate through height map initialize values */
@@ -455,7 +455,7 @@ static void HeightMapSineTransform(height_t h_min, height_t h_max)
break;
}
/* Transform it back into h_min..h_max space */
- *h = fheight * (h_max - h_min) + h_min;
+ *h = (height_t)(fheight * (h_max - h_min) + h_min);
if (*h < 0) *h = I2H(0);
if (*h >= h_max) *h = h_max - 1;
}
@@ -472,7 +472,7 @@ static void HeightMapAdjustWaterLevel(amplitude_t water_percent, height_t h_max_
HeightMapGetMinMaxAvg(&h_min, &h_max, &h_avg);
/* Allocate histogram buffer and clear its cells */
- hist_buf = calloc(h_max - h_min + 1, sizeof(*hist_buf));
+ CallocT(&hist_buf, h_max - h_min + 1);
/* Fill histogram */
hist = HeightMapMakeHistogram(h_min, h_max, hist_buf);
@@ -529,14 +529,14 @@ static void HeightMapCoastLines(void)
int smallest_size = min(_patches.map_x, _patches.map_y);
const int margin = 4;
uint y, x;
- uint max_x;
- uint max_y;
+ double max_x;
+ double max_y;
/* Lower to sea level */
for (y = 0; y <= _height_map.size_y; y++) {
/* Top right */
max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
- max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
+ max_x = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = 0; x < max_x; x++) {
HeightMapXY(x, y) = 0;
@@ -544,7 +544,7 @@ static void HeightMapCoastLines(void)
/* Bottom left */
max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45, 67) + 0.75) * 8);
- max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
+ max_x = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
HeightMapXY(x, y) = 0;
@@ -555,7 +555,7 @@ static void HeightMapCoastLines(void)
for (x = 0; x <= _height_map.size_x; x++) {
/* Top left */
max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
- max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
+ max_y = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = 0; y < max_y; y++) {
HeightMapXY(x, y) = 0;
@@ -564,7 +564,7 @@ static void HeightMapCoastLines(void)
/* Bottom right */
max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
- max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
+ max_y = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
HeightMapXY(x, y) = 0;