aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png
blob: 0d1c7694ca19be3f4454eeaec1de847c6f700244 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 38 00 00 00 39 08 06 00 00 00 63 da e8 .PNG........IHDR...8...9.....c..
0020 bb 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0b 13 00 .....bKGD..............pHYs.....
0040 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 e2 0b 1d 10 0e 0c c9 e8 6c af 00 00 04 63 49 ............tIME.........l....cI
0060 44 41 54 68 de ed da 5d 4c 5b 65 18 07 f0 ff db 16 4a 0a cc 41 4b dd 49 74 65 d0 e0 e2 6c b3 e1 DATh...]L[e......J..AK.Ite...l..
0080 dc 32 68 9b 9a a9 31 6c 93 60 1c 17 08 d1 64 99 b3 e2 cc b2 39 a3 92 2c 84 0b 34 c6 1b e2 fc 58 .2h...1l.`....d.....9..,..4....X
00a0 16 b2 25 ea cd 4c b6 69 74 13 3b 49 95 32 24 c6 35 d1 0c a2 89 3a ea c5 09 6d 85 ad c0 a0 d5 ed ..%..L.it.;I.2$.5....:...m......
00c0 f5 a2 9e ee f4 f4 f4 fb 83 41 de f7 0a 72 c8 e9 fb cb f3 7f 9f a7 a7 94 70 1c 87 d5 bc 14 58 e5 .........A...r..........p.....X.
00e0 8b 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 19 90 01 ................................
0100 0b b8 b6 3d b2 95 16 1b a8 2a c6 8b bc 72 b0 9b 5a ad 16 00 c0 f5 d9 eb 74 ff 01 07 59 91 c0 33 ...=.....*...r..Z.......t...Y..3
0120 3d b5 14 00 46 7e b9 01 00 20 86 0e 08 b0 f9 b9 79 7c e3 74 e2 e6 cd c5 95 19 d1 b6 1d e5 74 ca =...F~..........y|.t..........t.
0140 7f 1b 20 04 c4 d0 01 5b e7 07 b0 5a 2d 98 9f 9b c7 d9 b3 e7 10 f8 3b 80 87 1b 1b 31 37 17 5c 99 .......[...Z-.........;....17.\.
0160 c0 75 55 0a fc a5 de 03 62 ee 97 85 f9 7c 7e 54 ae 59 03 87 e3 45 74 75 76 14 ed 2c 92 6c fe 7d .uU.....b....|~T.Y...Etuv..,.l.}
0180 26 44 51 88 a3 34 8a 4f b6 ec c6 27 1f 9f 06 01 c1 b4 cf 07 a3 d1 88 ea ea 2a 84 42 61 8c 7f 76 &DQ..4.O...'.............*.Ba..v
01a0 08 ef 7d 31 4b ee 5a 60 db 8e 72 da 64 d2 c2 a0 57 e2 dd 21 2d 5e 3d 72 18 44 41 a2 30 e9 72 8f ..}1K.Z`..r.d...W..!-^=r.DA.0.r.
01c0 b8 10 0a 85 51 fa 6b 2f 40 29 c4 67 b4 18 50 55 b6 51 ac 35 5b 70 d4 7c a7 62 94 52 d0 ff 01 84 ....Q.k/@).g..PU.Q.5[p.|.b.R....
01e0 dc d9 f7 f0 e9 17 c0 cf dc 02 00 34 9b 75 30 e8 95 b0 9a ee 11 2e d3 42 43 93 56 30 9d 28 4a 17 ...........4.u0........BC.V0.(J.
0200 a5 34 06 c8 71 1c 01 00 47 4b 25 95 42 8b 51 d1 84 40 71 14 dd 37 5a 92 c2 c6 c7 81 ed db e5 5f .4..q...GK%.B.Q..@q..7Z........_
0220 a0 ff c0 83 31 1b 2f 36 34 69 05 c5 03 5a 98 63 8d 8d 5b d0 d9 f5 7c ca 1b 8f bc df 14 dd b8 b0 ....1./64i...Z.c..[...|.........
0240 f9 e5 80 12 8e e3 52 46 51 80 09 5d f1 f0 91 a3 29 6f ec 68 ab 8f db 78 26 50 6f 00 98 e2 73 87 ......RFQ..]....)o.h...x&Po...s.
0260 92 97 9e 36 52 95 92 60 af bd 26 b2 11 53 7f b4 2b 4a 61 e2 76 bf f3 b1 27 e2 a2 f8 e6 89 89 e8 ...6R..`..&..S..+Ja.v...'.......
0280 ef 7d fb 1a 00 00 fc cc ad 9c a0 e9 54 f4 d4 e0 49 aa 29 d7 c0 e5 fa 1e 1f 7e 74 82 c4 55 50 b8 .}..........T...I.)......~t..UP.
02a0 79 89 4a 01 d5 7d bb 50 52 52 02 93 69 93 2c ac b3 eb 39 22 fc 7d ba 1b 2f 14 f4 d4 e0 49 5a 51 y.J..}.PRR..i.,...9".}../....IZQ
02c0 59 11 b9 36 e2 86 4e ab c5 b1 de 3e 92 f0 0c be f1 fa 6b d4 ed 1e 45 eb 53 7b 52 0e 68 9e e7 69 Y..6..N....>......k...E.S{R.h..i
02e0 df be 06 e4 0a f5 06 22 d7 a7 f8 d4 50 af 9f 62 bd 0e 58 a8 eb 81 14 16 0a 87 e1 f1 78 70 e1 e2 ......."....P..b..X.........xp..
0300 10 49 da 64 da db 9f a1 76 9b 0d 35 fa 9a b8 01 2d b7 71 f1 66 f2 59 51 9e e7 a9 f4 4c b7 ee 1f .I.d....v..5....-.q.f.YQ....L...
0320 90 85 a9 d5 6a 4c 4f fb 60 b3 59 10 f0 fb d1 7d f0 10 49 ab 8b 8a a3 1b 3d a3 05 86 5a ba 2f 83 ....jLO.`.Y....}..I.....=...Z./.
0340 10 12 33 4f bf be f0 65 52 98 dd 6e 03 01 c1 4f 57 ae e0 ad b7 df 21 19 bf 55 cb 17 54 e8 8c 72 ..3O...eR..n...OW.....!..U..T..r
0360 d0 63 83 bf c5 cc 53 4a 29 86 2e 7e 95 36 6c 8b f2 8c 6c 33 ca e8 bd 68 21 2a 2a 8e a2 00 14 2a .c....SJ)..~.6l...l3...h!**....*
0380 36 3c ec 42 59 99 1a 55 6b d7 26 84 4d ba 8e cb 36 23 85 82 60 e0 fc 0c c9 ea 69 22 9f 50 eb cb 6<.BY..Uk.&.M...6#..`.....i".P..
03a0 63 d1 9f e5 a2 38 7a 79 0c cd cd 4d 09 a3 28 6d 46 b5 f7 aa f0 e7 f4 bf 08 ff 73 1b 97 7e f8 23 c....8zy...M..(mF.........s..~.#
03c0 bb c7 a5 54 50 b9 28 ca 41 bd 7e 8a 67 7b c7 12 9e 31 8f c7 83 0d 1b ea e2 a2 98 6c bc cc 06 97 ...TP.(.A.~.g{...1.........l....
03e0 60 32 56 e1 7e 9d 12 3f ff 1e cc 0d 98 6b 45 53 75 45 bb dd 06 a7 f3 12 b4 5a ad 6c 14 01 60 f4 `2V.~..?.....kESuE.......Z.l..`.
0400 6a 10 03 e7 67 a2 f7 df 6b ad a4 e1 a5 20 3e ff 31 d2 a1 48 3e bf 2f 9a 2e 54 6e 40 a7 ea 8a d2 j...g...k.....>.1..H>./..Tn@....
0420 ae 2b 8d a2 6b b2 94 e4 ed 89 3e 53 a8 d7 1f 81 6a b7 f5 64 d4 15 93 8d 97 89 6b 0b 31 51 fc f4 .+..k.....>S....j..d......k.1Q..
0440 bb a5 e2 01 13 41 bf f5 ed 84 46 a3 c9 b8 2b a6 13 c5 bc 7e 26 93 2d b4 bc ae 15 9b 37 9b b1 b8 .....A....F...+....~&.-.....7...
0460 b8 94 74 40 8b 9b 51 ba 51 5c 56 20 00 d4 1a d6 d3 fa 7a 23 36 6e 7c 20 ad 28 0a d0 89 6b 0b d0 ..t@..Q.Q\V.......z#6n|..(...k..
0480 57 97 61 6b 43 45 d2 28 2e 3b 50 58 26 d3 43 74 f7 ae 16 4c ba 8e cb 36 23 69 14 01 e0 f1 4d 61 W.akCE.(.;PX&.Ct...L...6#i....Ma
04a0 ea bc 5a 9a d5 33 21 59 ce 6f dd 8b cf 68 fb a3 fa 9c a2 78 57 02 f3 19 c5 84 40 9d 76 1d 56 f3 ..Z..3!Y.o...h.....xW.....@.v.V.
04c0 fa 0f 90 a6 de 01 97 53 46 e5 00 00 00 00 49 45 4e 44 ae 42 60 82 .......SF.....IEND.B`.
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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
/*
Minetest
Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2015-2018 paramat

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 "dungeongen.h"
#include <cmath>
#include "mapgen.h"
#include "voxel.h"
#include "noise.h"
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
#include "nodedef.h"
#include "settings.h"

//#define DGEN_USE_TORCHES

NoiseParams nparams_dungeon_density(0.9, 0.5, v3f(500.0, 500.0, 500.0), 0, 2, 0.8, 2.0);
NoiseParams nparams_dungeon_alt_wall(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0);


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


DungeonGen::DungeonGen(const NodeDefManager *ndef,
	GenerateNotifier *gennotify, DungeonParams *dparams)
{
	assert(ndef);

	this->ndef      = ndef;
	this->gennotify = gennotify;

#ifdef DGEN_USE_TORCHES
	c_torch  = ndef->getId("default:torch");
#endif

	if (dparams) {
		memcpy(&dp, dparams, sizeof(dp));
	} else {
		// Default dungeon parameters
		dp.seed = 0;

		dp.c_wall     = ndef->getId("mapgen_cobble");
		dp.c_alt_wall = ndef->getId("mapgen_mossycobble");
		dp.c_stair    = ndef->getId("mapgen_stair_cobble");

		dp.diagonal_dirs       = false;
		dp.only_in_ground      = true;
		dp.holesize            = v3s16(1, 2, 1);
		dp.corridor_len_min    = 1;
		dp.corridor_len_max    = 13;
		dp.room_size_min       = v3s16(4, 4, 4);
		dp.room_size_max       = v3s16(8, 6, 8);
		dp.room_size_large_min = v3s16(8, 8, 8);
		dp.room_size_large_max = v3s16(16, 16, 16);
		dp.rooms_min           = 2;
		dp.rooms_max           = 16;
		dp.y_min               = -MAX_MAP_GENERATION_LIMIT;
		dp.y_max               = MAX_MAP_GENERATION_LIMIT;
		dp.notifytype          = GENNOTIFY_DUNGEON;

		dp.np_density  = nparams_dungeon_density;
		dp.np_alt_wall = nparams_dungeon_alt_wall;
	}
}


void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax)
{
	assert(vm);

	//TimeTaker t("gen dungeons");
	if (nmin.Y < dp.y_min || nmax.Y > dp.y_max)
		return;

	float nval_density = NoisePerlin3D(&dp.np_density, nmin.X, nmin.Y, nmin.Z, dp.seed);
	if (nval_density < 1.0f)
		return;

	static const bool preserve_ignore = !g_settings->getBool("projecting_dungeons");

	this->vm = vm;
	this->blockseed = bseed;
	random.seed(bseed + 2);

	// Dungeon generator doesn't modify places which have this set
	vm->clearFlag(VMANIP_FLAG_DUNGEON_INSIDE | VMANIP_FLAG_DUNGEON_PRESERVE);

	if (dp.only_in_ground) {
		// Set all air and liquid drawtypes to be untouchable to make dungeons
		// open to air and liquids. Optionally set ignore to be untouchable to
		// prevent projecting dungeons.
		for (s16 z = nmin.Z; z <= nmax.Z; z++) {
			for (s16 y = nmin.Y; y <= nmax.Y; y++) {
				u32 i = vm->m_area.index(nmin.X, y, z);
				for (s16 x = nmin.X; x <= nmax.X; x++) {
					content_t c = vm->m_data[i].getContent();
					NodeDrawType dtype = ndef->get(c).drawtype;
					if (dtype == NDT_AIRLIKE || dtype == NDT_LIQUID ||
							(preserve_ignore && c == CONTENT_IGNORE))
						vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
					i++;
				}
			}
		}
	}

	// Add them
	for (u32 i = 0; i < std::floor(nval_density); i++)
		makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE);

	// Optionally convert some structure to alternative structure
	if (dp.c_alt_wall == CONTENT_IGNORE)
		return;

	for (s16 z = nmin.Z; z <= nmax.Z; z++)
	for (s16 y = nmin.Y; y <= nmax.Y; y++) {
		u32 i = vm->m_area.index(nmin.X, y, z);
		for (s16 x = nmin.X; x <= nmax.X; x++) {
			if (vm->m_data[i].getContent() == dp.c_wall) {
				if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f)
					vm->m_data[i].setContent(dp.c_alt_wall);
			}
			i++;
		}
	}

	//printf("== gen dungeons: %dms\n", t.stop());
}


void DungeonGen::makeDungeon(v3s16 start_padding)
{
	const v3s16 &areasize = vm->m_area.getExtent();
	v3s16 roomsize;
	v3s16 roomplace;

	/*
		Find place for first room.
		There is a 1 in 4 chance of the first room being 'large',
		all other rooms are not 'large'.
	*/
	bool fits = false;
	for (u32 i = 0; i < 100 && !fits; i++) {
		bool is_large_room = ((random.next() & 3) == 1);
		if (is_large_room) {
			roomsize.Z = random.range(
				dp.room_size_large_min.Z, dp.room_size_large_max.Z);
			roomsize.Y = random.range(
				dp.room_size_large_min.Y, dp.room_size_large_max.Y);
			roomsize.X = random.range(
				dp.room_size_large_min.X, dp.room_size_large_max.X);
		} else {
			roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z);
			roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y);
			roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X);
		}

		// start_padding is used to disallow starting the generation of
		// a dungeon in a neighboring generation chunk
		roomplace = vm->m_area.MinEdge + start_padding;
		roomplace.Z += random.range(0, areasize.Z - roomsize.Z - start_padding.Z);
		roomplace.Y += random.range(0, areasize.Y - roomsize.Y - start_padding.Y);
		roomplace.X += random.range(0, areasize.X - roomsize.X - start_padding.X);

		/*
			Check that we're not putting the room to an unknown place,
			otherwise it might end up floating in the air
		*/
		fits = true;
		for (s16 z = 0; z < roomsize.Z; z++)
		for (s16 y = 0; y < roomsize.Y; y++)
		for (s16 x = 0; x < roomsize.X; x++) {
			v3s16 p = roomplace + v3s16(x, y, z);
			u32 vi = vm->m_area.index(p);
			if ((vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) ||
					vm->m_data[vi].getContent() == CONTENT_IGNORE) {
				fits = false;
				break;
			}
		}
	}
	// No place found
	if (!fits)
		return;

	/*
		Stores the center position of the last room made, so that
		a new corridor can be started from the last room instead of
		the new room, if chosen so.
	*/
	v3s16 last_room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2);

	u32 room_count = random.range(dp.rooms_min, dp.rooms_max);
	for (u32 i = 0; i < room_count; i++) {
		// Make a room to the determined place
		makeRoom(roomsize, roomplace);

		v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2);
		if (gennotify)
			gennotify->addEvent(dp.notifytype, room_center);

#ifdef DGEN_USE_TORCHES
		// Place torch at room center (for testing)
		vm->m_data[vm->m_area.index(room_center)] = MapNode(c_torch);
#endif

		// Quit if last room
		if (i == room_count - 1)
			break;

		// Determine walker start position

		bool start_in_last_room = (random.range(0, 2) != 0);

		v3s16 walker_start_place;

		if (start_in_last_room) {
			walker_start_place = last_room_center;
		} else {
			walker_start_place = room_center;
			// Store center of current room as the last one
			last_room_center = room_center;
		}

		// Create walker and find a place for a door
		v3s16 doorplace;
		v3s16 doordir;

		m_pos = walker_start_place;
		if (!findPlaceForDoor(doorplace, doordir))
			return;

		if (random.range(0, 1) == 0)
			// Make the door
			makeDoor(doorplace, doordir);
		else
			// Don't actually make a door
			doorplace -= doordir;

		// Make a random corridor starting from the door
		v3s16 corridor_end;
		v3s16 corridor_end_dir;
		makeCorridor(doorplace, doordir, corridor_end, corridor_end_dir);

		// Find a place for a random sized room
		roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z);
		roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y);
		roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X);

		m_pos = corridor_end;
		m_dir = corridor_end_dir;
		if (!findPlaceForRoomDoor(roomsize, doorplace, doordir, roomplace))
			return;

		if (random.range(0, 1) == 0)
			// Make the door
			makeDoor(doorplace, doordir);
		else
			// Don't actually make a door
			roomplace -= doordir;

	}
}


void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace)
{
	MapNode n_wall(dp.c_wall);
	MapNode n_air(CONTENT_AIR);

	// Make +-X walls
	for (s16 z = 0; z < roomsize.Z; z++)
	for (s16 y = 0; y < roomsize.Y; y++) {
		{
			v3s16 p = roomplace + v3s16(0, y, z);
			if (!vm->m_area.contains(p))
				continue;
			u32 vi = vm->m_area.index(p);
			if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE)
				continue;
			vm->m_data[vi] = n_wall;
		}
		{
			v3s16 p = roomplace + v3s16(roomsize.X - 1, y, z);
			if (!vm->m_area.contains(p))
				continue;
			u32 vi = vm->m_area.index(p);
			if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE)
				continue;
			vm->m_data[vi] = n_wall;
		}
	}

	// Make +-Z walls
	for (s16 x = 0; x < roomsize.X; x++)
	for (s16 y = 0; y < roomsize.Y; y++) {
		{
			v3s16 p = roomplace + v3s16(x, y, 0);
			if (!vm->m_area.contains(p))
				continue;
			u32 vi = vm->m_area.index(p);
			if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE)
				continue;
			vm->m_data[vi] = n_wall;
		}
		{
			v3s16 p = roomplace + v3s16(x, y, roomsize.Z - 1);
			if (!vm->m_area.contains(p))
				continue;
			u32 vi = vm->m_area.index(p);
			if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE)
				continue;
			vm->m_data[vi] = n_wall;
		}
	}

	// Make +-Y walls (floor and ceiling)
	for (s16 z = 0; z < roomsize.Z; z++)
	for (s16 x = 0; x < roomsize.X; x++) {
		{
			v3s16 p = roomplace + v3s16(x, 0, z);
			if (!vm->m_area.contains(p))
				continue;