aboutsummaryrefslogtreecommitdiff
path: root/.github
diff options
context:
space:
mode:
authorMatteo Gheza <matteo.gheza07@gmail.com>2020-04-28 14:15:21 +0000
committersfan5 <sfan5@live.de>2020-06-13 23:13:43 +0200
commit1c6970ace072e55b3e97df098d214b1cfec7b11c (patch)
treea74c4b41485bfedad185322f902b9fc33a02b43b /.github
parent372506bc944cb132e39880612b629dc1df8c2969 (diff)
downloadminetest-1c6970ace072e55b3e97df098d214b1cfec7b11c.tar.gz
minetest-1c6970ace072e55b3e97df098d214b1cfec7b11c.tar.bz2
minetest-1c6970ace072e55b3e97df098d214b1cfec7b11c.zip
Translated using Weblate (Italian)
Currently translated at 95.4% (1229 of 1288 strings)
Diffstat (limited to '.github')
0 files changed, 0 insertions, 0 deletions
2' href='#n112'>112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "mapgen_indev.h"
#include "constants.h"
#include "map.h"
#include "main.h"
#include "util/numeric.h"
#include "log.h"

/////////////////// Mapgen Indev perlin noise (default values - not used, from config or defaultsettings)

NoiseIndevParams nparams_indev_def;

/*
NoiseIndevParams nparams_indev_def_terrain_base;
//	(-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6, 1);
NoiseIndevParams nparams_indev_def_terrain_higher;
//	(20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6, 1);
NoiseIndevParams nparams_indev_def_steepness;
//	(0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7, 1);
NoiseIndevParams nparams_indev_def_mud;
//	(AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55, 1);
NoiseIndevParams nparams_indev_def_float_islands;
//	(1, 10.0, v3f(500.0, 500.0, 500.0), 32451, 5, 0.6, 1);
NoiseIndevParams nparams_indev_def_biome;
*/

///////////////////////////////////////////////////////////////////////////////

void NoiseIndev::init(NoiseIndevParams *np, int seed, int sx, int sy, int sz) {
	Noise::init((NoiseParams*)np, seed, sx, sy, sz);
	this->npindev   = np;
}

NoiseIndev::NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy) : Noise(np, seed, sx, sy) {
        init(np, seed, sx, sy, 1);
}

NoiseIndev::NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz) : Noise(np, seed, sx, sy, sz) {
        init(np, seed, sx, sy, sz);
}

float farscale(float scale, float z) {
	return ( 1 + ( 1 - (MAP_GENERATION_LIMIT * 1 - (fabs(z))                     ) / (MAP_GENERATION_LIMIT * 1) ) * (scale - 1) );
}

float farscale(float scale, float x, float z) {
	return ( 1 + ( 1 - (MAP_GENERATION_LIMIT * 2 - (fabs(x) + fabs(z))           ) / (MAP_GENERATION_LIMIT * 2) ) * (scale - 1) );
}

float farscale(float scale, float x, float y, float z) {
	return ( 1 + ( 1 - (MAP_GENERATION_LIMIT * 3 - (fabs(x) + fabs(y) + fabs(z)) ) / (MAP_GENERATION_LIMIT * 3) ) * (scale - 1) );
}

void NoiseIndev::transformNoiseMapFarScale(float xx, float yy, float zz) {
        int i = 0;
        for (int z = 0; z != sz; z++) {
                for (int y = 0; y != sy; y++) {
                        for (int x = 0; x != sx; x++) {
                                result[i] = result[i] * npindev->scale * farscale(npindev->farscale, xx, yy, zz) + npindev->offset;
                                i++;
                        }
                }
        }
}

MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge) 
	: MapgenV6(mapgenid, params, emerge)
{
	noiseindev_terrain_base    = new NoiseIndev(&params->npindev_terrain_base,   seed, csize.X, csize.Z);
	noiseindev_terrain_higher  = new NoiseIndev(&params->npindev_terrain_higher, seed, csize.X, csize.Z);
	noiseindev_steepness       = new NoiseIndev(&params->npindev_steepness,      seed, csize.X, csize.Z);
	noiseindev_mud             = new NoiseIndev(&params->npindev_mud,            seed, csize.X, csize.Z);
	noiseindev_float_islands1  = new NoiseIndev(&params->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z);
	noiseindev_float_islands2  = new NoiseIndev(&params->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
	noiseindev_float_islands3  = new NoiseIndev(&params->npindev_float_islands3, seed, csize.X, csize.Z);
	noiseindev_biome           = new NoiseIndev(&params->npindev_biome,          seed, csize.X, csize.Z);
}

MapgenIndev::~MapgenIndev() {
	delete noiseindev_terrain_base;
	delete noiseindev_terrain_higher;
	delete noiseindev_steepness;
	//delete noise_height_select;
	//delete noise_trees;
	delete noiseindev_mud;
	//delete noise_beach;
	delete noiseindev_float_islands1;
	delete noiseindev_float_islands2;
	delete noiseindev_float_islands3;
	delete noiseindev_biome;
}

void MapgenIndev::calculateNoise() {
	int x = node_min.X;
	int y = node_min.Y;
	int z = node_min.Z;
	// Need to adjust for the original implementation's +.5 offset...
	if (!(flags & MG_FLAT)) {
		noiseindev_terrain_base->perlinMap2D(
			x + 0.5 * noiseindev_terrain_base->npindev->spread.X * farscale(noiseindev_terrain_base->npindev->farspread, x, z),
			z + 0.5 * noiseindev_terrain_base->npindev->spread.Z * farscale(noiseindev_terrain_base->npindev->farspread, x, z));
		noiseindev_terrain_base->transformNoiseMapFarScale(x, y, z);

		noiseindev_terrain_higher->perlinMap2D(
			x + 0.5 * noiseindev_terrain_higher->npindev->spread.X * farscale(noiseindev_terrain_higher->npindev->farspread, x, z),
			z + 0.5 * noiseindev_terrain_higher->npindev->spread.Z * farscale(noiseindev_terrain_higher->npindev->farspread, x, z));
		noiseindev_terrain_higher->transformNoiseMapFarScale(x, y, z);

		noiseindev_steepness->perlinMap2D(
			x + 0.5 * noiseindev_steepness->npindev->spread.X * farscale(noiseindev_steepness->npindev->farspread, x, z),
			z + 0.5 * noiseindev_steepness->npindev->spread.Z * farscale(noiseindev_steepness->npindev->farspread, x, z));
		noiseindev_steepness->transformNoiseMapFarScale(x, y, z);

		noise_height_select->perlinMap2D(
			x + 0.5 * noise_height_select->np->spread.X,
			z + 0.5 * noise_height_select->np->spread.Z);

		noiseindev_float_islands1->perlinMap3D(
			x + 0.33 * noiseindev_float_islands1->npindev->spread.X * farscale(noiseindev_float_islands1->npindev->farspread, x, y, z),
			y + 0.33 * noiseindev_float_islands1->npindev->spread.Y * farscale(noiseindev_float_islands1->npindev->farspread, x, y, z),
			z + 0.33 * noiseindev_float_islands1->npindev->spread.Z * farscale(noiseindev_float_islands1->npindev->farspread, x, y, z)
		);
		noiseindev_float_islands1->transformNoiseMapFarScale(x, y, z);

		noiseindev_float_islands2->perlinMap3D(
			x + 0.33 * noiseindev_float_islands2->npindev->spread.X * farscale(noiseindev_float_islands2->npindev->farspread, x, y, z),
			y + 0.33 * noiseindev_float_islands2->npindev->spread.Y * farscale(noiseindev_float_islands2->npindev->farspread, x, y, z),
			z + 0.33 * noiseindev_float_islands2->npindev->spread.Z * farscale(noiseindev_float_islands2->npindev->farspread, x, y, z)
		);
		noiseindev_float_islands2->transformNoiseMapFarScale(x, y, z);

		noiseindev_float_islands3->perlinMap2D(
			x + 0.5 * noiseindev_float_islands3->npindev->spread.X * farscale(noiseindev_float_islands3->npindev->farspread, x, z),
			z + 0.5 * noiseindev_float_islands3->npindev->spread.Z * farscale(noiseindev_float_islands3->npindev->farspread, x, z));
		noiseindev_float_islands3->transformNoiseMapFarScale(x, y, z);

		noiseindev_mud->perlinMap2D(
			x + 0.5 * noiseindev_mud->npindev->spread.X * farscale(noiseindev_mud->npindev->farspread, x, y, z),
			z + 0.5 * noiseindev_mud->npindev->spread.Z * farscale(noiseindev_mud->npindev->farspread, x, y, z));
		noiseindev_mud->transformNoiseMapFarScale(x, y, z);
	}
	noise_beach->perlinMap2D(
		x + 0.2 * noise_beach->np->spread.X,
		z + 0.7 * noise_beach->np->spread.Z);

	noise_biome->perlinMap2D(
		x + 0.6 * noiseindev_biome->npindev->spread.X * farscale(noiseindev_biome->npindev->farspread, x, z),
		z + 0.2 * noiseindev_biome->npindev->spread.Z * farscale(noiseindev_biome->npindev->farspread, x, z));
}

bool MapgenIndevParams::readParams(Settings *settings) {
	freq_desert = settings->getFloat("mgv6_freq_desert");
	freq_beach  = settings->getFloat("mgv6_freq_beach");

	bool success = 
		settings->getNoiseIndevParams("mgindev_np_terrain_base",   npindev_terrain_base)   &&
		settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher) &&
		settings->getNoiseIndevParams("mgindev_np_steepness",      npindev_steepness)      &&
		settings->getNoiseParams("mgv6_np_height_select",          np_height_select)       &&
		settings->getNoiseParams("mgv6_np_trees",                  np_trees)               &&
		settings->getNoiseIndevParams("mgindev_np_mud",            npindev_mud)            &&
		settings->getNoiseParams("mgv6_np_beach",                  np_beach)               &&
		settings->getNoiseIndevParams("mgindev_np_biome",          npindev_biome)          &&
		settings->getNoiseParams("mgv6_np_cave",                   np_cave)                &&
		settings->getNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1) &&
		settings->getNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2) &&
		settings->getNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
	return success;
}

void MapgenIndevParams::writeParams(Settings *settings) {
	settings->setFloat("mgv6_freq_desert", freq_desert);
	settings->setFloat("mgv6_freq_beach",  freq_beach);

	settings->setNoiseIndevParams("mgindev_np_terrain_base",   npindev_terrain_base);
	settings->setNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
	settings->setNoiseIndevParams("mgindev_np_steepness",      npindev_steepness);
	settings->setNoiseParams("mgv6_np_height_select",          np_height_select);
	settings->setNoiseParams("mgv6_np_trees",                  np_trees);
	settings->setNoiseIndevParams("mgindev_np_mud",            npindev_mud);
	settings->setNoiseParams("mgv6_np_beach",                  np_beach);
	settings->setNoiseIndevParams("mgindev_np_biome",          npindev_biome);
	settings->setNoiseParams("mgv6_np_cave",                   np_cave);
	settings->setNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1);
	settings->setNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2);
	settings->setNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
}


float MapgenIndev::baseTerrainLevelFromNoise(v2s16 p) {
	if (flags & MG_FLAT)
		return water_level;
		
	float terrain_base   = NoisePerlin2DPosOffset(noiseindev_terrain_base->npindev,
							p.X, 0.5, p.Y, 0.5, seed);
	float terrain_higher = NoisePerlin2DPosOffset(noiseindev_terrain_higher->npindev,
							p.X, 0.5, p.Y, 0.5, seed);
	float steepness      = NoisePerlin2DPosOffset(noiseindev_steepness->npindev,
							p.X, 0.5, p.Y, 0.5, seed);
	float height_select  = NoisePerlin2DNoTxfmPosOffset(noise_height_select->np,
							p.X, 0.5, p.Y, 0.5, seed);

	return baseTerrainLevel(terrain_base, terrain_higher,
							steepness,    height_select);
}

float MapgenIndev::baseTerrainLevelFromMap(int index) {
	if (flags & MG_FLAT)
		return water_level;
	
	float terrain_base   = noiseindev_terrain_base->result[index];
	float terrain_higher = noiseindev_terrain_higher->result[index];
	float steepness      = noiseindev_steepness->result[index];
	float height_select  = noise_height_select->result[index];
	
	return baseTerrainLevel(terrain_base, terrain_higher,
							steepness,    height_select);
}

float MapgenIndev::getMudAmount(int index) {
	if (flags & MG_FLAT)
		return AVERAGE_MUD_AMOUNT;
		
	/*return ((float)AVERAGE_MUD_AMOUNT + 2.0 * noise2d_perlin(
			0.5+(float)p.X/200, 0.5+(float)p.Y/200,
			seed+91013, 3, 0.55));*/
	
	return noiseindev_mud->result[index];
}

void MapgenIndev::generateCaves(int max_stone_y) {
	float cave_amount = NoisePerlin2D(np_cave, node_min.X, node_min.Y, seed);
	int volume_nodes = (node_max.X - node_min.X + 1) *
					   (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE;
	cave_amount = MYMAX(0.0, cave_amount);
	u32 caves_count = cave_amount * volume_nodes / 50000;
	u32 bruises_count = 1;
	PseudoRandom ps(blockseed + 21343);
	PseudoRandom ps2(blockseed + 1032);
	
	if (ps.range(1, 6) == 1)
		bruises_count = ps.range(0, ps.range(0, 2));
	
	if (getBiome(v2s16(node_min.X, node_min.Z)) == BT_DESERT) {
		caves_count   /= 3;
		bruises_count /= 3;
	}
	
	for (u32 i = 0; i < caves_count + bruises_count; i++) {
		bool large_cave = (i >= caves_count);
		CaveIndev cave(this, &ps, &ps2, node_min, large_cave);

		cave.makeCave(node_min, node_max, max_stone_y);
	}
}

CaveIndev::CaveIndev(MapgenIndev *mg, PseudoRandom *ps, PseudoRandom *ps2,
				v3s16 node_min, bool is_large_cave) {
	this->vm = mg->vm;
	this->water_level = mg->water_level;
	this->large_cave = is_large_cave;
	this->ps  = ps;
	this->ps2 = ps2;
	this->c_water_source = mg->c_water_source;