aboutsummaryrefslogtreecommitdiff
path: root/assets/interlocking.html.LyXconv/interlocking.idv
blob: 752dcf9bc4ca8b0551fd58b6bafc0abd7d1e503f (plain)
ofshex dumpascii
0000 f7 02 01 83 92 c0 1c 3b 00 00 00 00 03 e8 1b 20 54 65 58 20 6f 75 74 70 75 74 20 32 30 31 39 2e .......;........TeX.output.2019.
0020 30 31 2e 31 35 3a 32 31 30 36 8b 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01.15:2106......................
0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 8d 92 00 00 00 00 a0 00 00 ................................
0060 00 00 f2 00 00 00 1f 70 61 70 65 72 73 69 7a 65 3d 36 31 34 2e 32 39 35 70 74 2c 37 39 34 2e 39 .......papersize=614.295pt,794.9
0080 36 39 39 39 70 74 f2 00 00 00 1f 70 61 70 65 72 73 69 7a 65 3d 36 31 34 2e 32 39 35 70 74 2c 37 6999pt.....papersize=614.295pt,7
00a0 39 34 2e 39 36 39 39 39 70 74 f3 0e 0c 31 ea b1 00 0a 00 00 00 0a 00 00 00 08 65 63 72 6d 31 30 94.96999pt...1............ecrm10
00c0 30 30 b9 f3 11 13 d1 4e 3c 00 11 47 ae 00 11 47 ae 00 08 65 63 73 78 31 37 32 38 bc f3 18 c4 4e 00.....N<..G...G...ecsx1728....N
00e0 bd bf 00 0e 66 66 00 0e 66 66 00 08 65 63 73 74 31 34 34 30 c3 f3 1b 00 02 7d 15 00 0c 00 00 00 ....ff..ff..ecst1440.....}......
0100 0c 00 00 00 08 65 63 73 78 31 32 30 30 c6 b9 c6 b9 c6 b9 c6 f3 1d bb 79 26 b3 00 0a 00 00 00 0a .....ecsx1200..........y&.......
0120 00 00 00 08 65 63 73 78 31 30 30 30 c8 b9 c8 b9 c8 b9 c8 b9 c6 b9 c6 b9 b9 c6 b9 c6 b9 c6 b9 c6 ....ecsx1000....................
0140 b9 f3 1e 02 5d 66 8c 00 0a 00 00 00 0a 00 00 00 08 65 63 62 78 31 30 30 30 c9 b9 b9 c6 b9 c6 c9 ....]f...........ecbx1000.......
0160 b9 b9 c6 b9 c6 b9 b9 c6 b9 c6 b9 b9 c6 b9 c6 b9 c6 b9 b9 c6 b9 c6 b9 c8 b9 b9 c8 b9 c6 b9 8e 8c ................................
0180 f8 00 00 00 2a 01 83 92 c0 1c 3b 00 00 00 00 03 e8 02 d4 3f 4c 02 2d 63 b7 00 08 00 01 f3 1e 02 ....*.....;........?L.-c........
01a0 5d 66 8c 00 0a 00 00 00 0a 00 00 00 08 65 63 62 78 31 30 30 30 f3 1d bb 79 26 b3 00 0a 00 00 00 ]f...........ecbx1000...y&......
01c0 0a 00 00 00 08 65 63 73 78 31 30 30 30 f3 1b 00 02 7d 15 00 0c 00 00 00 0c 00 00 00 08 65 63 73 .....ecsx1000....}...........ecs
01e0 78 31 32 30 30 f3 18 c4 4e bd bf 00 0e 66 66 00 0e 66 66 00 08 65 63 73 74 31 34 34 30 f3 11 13 x1200...N....ff..ff..ecst1440...
0200 d1 4e 3c 00 11 47 ae 00 11 47 ae 00 08 65 63 73 78 31 37 32 38 f3 0e 0c 31 ea b1 00 0a 00 00 00 .N<..G...G...ecsx1728...1.......
0220 0a 00 00 00 08 65 63 72 6d 31 30 30 30 f9 00 00 01 80 02 df df df df df df .....ecrm1000............
ref='#n147'>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 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 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
/*
Minetest
Copyright (C) 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 "lua_api/l_mapgen.h"
#include "lua_api/l_internal.h"
#include "lua_api/l_vmanip.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "util/serialize.h"
#include "server.h"
#include "environment.h"
#include "emerge.h"
#include "mg_biome.h"
#include "mg_ore.h"
#include "mg_decoration.h"
#include "mg_schematic.h"
#include "mapgen_v5.h"
#include "mapgen_v7.h"
#include "settings.h"
#include "log.h"


struct EnumString ModApiMapgen::es_BiomeTerrainType[] =
{
	{BIOME_NORMAL, "normal"},
	{BIOME_LIQUID, "liquid"},
	{BIOME_NETHER, "nether"},
	{BIOME_AETHER, "aether"},
	{BIOME_FLAT,   "flat"},
	{0, NULL},
};

struct EnumString ModApiMapgen::es_DecorationType[] =
{
	{DECO_SIMPLE,    "simple"},
	{DECO_SCHEMATIC, "schematic"},
	{DECO_LSYSTEM,   "lsystem"},
	{0, NULL},
};

struct EnumString ModApiMapgen::es_MapgenObject[] =
{
	{MGOBJ_VMANIP,    "voxelmanip"},
	{MGOBJ_HEIGHTMAP, "heightmap"},
	{MGOBJ_BIOMEMAP,  "biomemap"},
	{MGOBJ_HEATMAP,   "heatmap"},
	{MGOBJ_HUMIDMAP,  "humiditymap"},
	{MGOBJ_GENNOTIFY, "gennotify"},
	{0, NULL},
};

struct EnumString ModApiMapgen::es_OreType[] =
{
	{ORE_SCATTER, "scatter"},
	{ORE_SHEET,   "sheet"},
	{ORE_BLOB,    "blob"},
	{ORE_VEIN,    "vein"},
	{0, NULL},
};

struct EnumString ModApiMapgen::es_Rotation[] =
{
	{ROTATE_0,    "0"},
	{ROTATE_90,   "90"},
	{ROTATE_180,  "180"},
	{ROTATE_270,  "270"},
	{ROTATE_RAND, "random"},
	{0, NULL},
};


ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr);

Biome *get_or_load_biome(lua_State *L, int index,
	BiomeManager *biomemgr);
Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef);
size_t get_biome_list(lua_State *L, int index,
	BiomeManager *biomemgr, std::set<u8> *biome_id_list);

Schematic *get_or_load_schematic(lua_State *L, int index,
	SchematicManager *schemmgr, StringMap *replace_names);
Schematic *read_schematic_def(lua_State *L, int index,
	INodeDefManager *ndef, StringMap *replace_names);
Schematic *load_schematic(lua_State *L, int index,
	SchematicManager *schemmgr, StringMap *replace_names);

bool read_deco_simple(lua_State *L, NodeResolveInfo *nri, DecoSimple *deco);
bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic *deco);


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


ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	// If a number, assume this is a handle to an object def
	if (lua_isnumber(L, index))
		return objmgr->get(lua_tointeger(L, index));

	// If a string, assume a name is given instead
	if (lua_isstring(L, index))
		return objmgr->getByName(lua_tostring(L, index));

	return NULL;
}


Schematic *load_schematic(lua_State *L, int index,
	SchematicManager *schemmgr, StringMap *replace_names)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	Schematic *schem;

	if (lua_istable(L, index)) {
		schem = read_schematic_def(L, index, schemmgr->getNodeDef(), replace_names);
		if (!schem) {
			delete schem;
			return NULL;
		}
	} else if (lua_isnumber(L, index)) {
		return NULL;
	} else if (lua_isstring(L, index)) {
		schem = SchematicManager::create(SCHEMATIC_NORMAL);
		if (!schem->loadSchematicFromFile(lua_tostring(L, index),
				schemmgr->getNodeDef(), replace_names)) {
			delete schem;
			return NULL;
		}
	} else {
		return NULL;
	}

	return schem;
}


Biome *get_or_load_biome(lua_State *L, int index, BiomeManager *biomemgr)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	Biome *biome = (Biome *)get_objdef(L, index, biomemgr);
	if (biome)
		return biome;

	biome = read_biome_def(L, index, biomemgr->getNodeDef());
	if (!biome)
		return NULL;

	if (biomemgr->add(biome) == OBJDEF_INVALID_HANDLE) {
		delete biome;
		return NULL;
	}

	return biome;
}


Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
{
	if (!lua_istable(L, index))
		return NULL;

	BiomeType biometype = (BiomeType)getenumfield(L, index, "type",
		ModApiMapgen::es_BiomeTerrainType, BIOME_NORMAL);
	Biome *b = BiomeManager::create(biometype);

	b->name            = getstringfield_default(L, index, "name", "");
	b->depth_top       = getintfield_default(L, index, "depth_top",          1);
	b->depth_filler    = getintfield_default(L, index, "depth_filler",       2);
	b->depth_water_top = getintfield_default(L, index, "depth_water_top",    0);
	b->y_min           = getintfield_default(L, index, "y_min",         -31000);
	b->y_max           = getintfield_default(L, index, "y_max",          31000);
	b->heat_point      = getfloatfield_default(L, index, "heat_point",     0.f);
	b->humidity_point  = getfloatfield_default(L, index, "humidity_point", 0.f);
	b->flags           = 0; //reserved

	NodeResolveInfo *nri = new NodeResolveInfo(b);
	std::list<std::string> &nnames = nri->nodenames;
	nnames.push_back(getstringfield_default(L, index, "node_top",       ""));
	nnames.push_back(getstringfield_default(L, index, "node_filler",    ""));
	nnames.push_back(getstringfield_default(L, index, "node_stone",     ""));
	nnames.push_back(getstringfield_default(L, index, "node_water_top", ""));
	nnames.push_back(getstringfield_default(L, index, "node_water",     ""));
	nnames.push_back(getstringfield_default(L, index, "node_dust",      ""));
	ndef->pendNodeResolve(nri);

	return b;
}


size_t get_biome_list(lua_State *L, int index,
	BiomeManager *biomemgr, std::set<u8> *biome_id_list)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	if (lua_isnil(L, index))
		return 0;

	bool is_single = true;
	if (lua_istable(L, index)) {
		lua_getfield(L, index, "name");
		is_single = !lua_isnil(L, -1);
		lua_pop(L, 1);
	}

	if (is_single) {
		Biome *biome = get_or_load_biome(L, index, biomemgr);
		if (!biome) {
			errorstream << "get_biome_list: failed to get biome" << std::endl;
			return 1;
		}

		biome_id_list->insert(biome->index);
		return 0;
	}

	// returns number of failed resolutions
	size_t fail_count = 0;
	size_t count = 0;

	for (lua_pushnil(L); lua_next(L, index); lua_pop(L, 1)) {
		count++;
		Biome *biome = get_or_load_biome(L, -1, biomemgr);
		if (!biome) {
			fail_count++;
			errorstream << "get_biome_list: failed to load biome (index "
				<< count << ")" << std::endl;
			continue;
		}

		biome_id_list->insert(biome->index);
	}

	return fail_count;
}


Schematic *get_or_load_schematic(lua_State *L, int index,
	SchematicManager *schemmgr, StringMap *replace_names)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	Schematic *schem = (Schematic *)get_objdef(L, index, schemmgr);
	if (schem)
		return schem;

	schem = load_schematic(L, index, schemmgr, replace_names);
	if (!schem)
		return NULL;

	if (schemmgr->add(schem) == OBJDEF_INVALID_HANDLE) {
		delete schem;
		return NULL;
	}

	return schem;
}


Schematic *read_schematic_def(lua_State *L, int index,
	INodeDefManager *ndef, StringMap *replace_names)
{
	if (!lua_istable(L, index))
		return NULL;

	//// Get schematic size
	lua_getfield(L, index, "size");
	v3s16 size = read_v3s16(L, -1);
	lua_pop(L, 1);

	//// Get schematic data
	lua_getfield(L, index, "data");
	luaL_checktype(L, -1, LUA_TTABLE);

	int numnodes = size.X * size.Y * size.Z;
	MapNode *schemdata = new MapNode[numnodes];
	int i = 0;

	lua_pushnil(L);
	while (lua_next(L, -2)) {
		if (i >= numnodes) {
			i++;
			lua_pop(L, 1);
			continue;
		}

		// same as readnode, except param1 default is MTSCHEM_PROB_CONST
		lua_getfield(L, -1, "name");
		std::string name = luaL_checkstring(L, -1);
		lua_pop(L, 1);

		u8 param1;
		lua_getfield(L, -1, "param1");
		param1 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : MTSCHEM_PROB_ALWAYS;
		lua_pop(L, 1);

		u8 param2;
		lua_getfield(L, -1, "param2");
		param2 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : 0;
		lua_pop(L, 1);

		StringMap::iterator it = replace_names->find(name);
		if (it != replace_names->end())
			name = it->second;

		schemdata[i] = MapNode(ndef, name, param1, param2);

		i++;
		lua_pop(L, 1);
	}

	if (i != numnodes) {
		errorstream << "read_schematic: incorrect number of "
			"nodes provided in raw schematic data (got " << i <<
			", expected " << numnodes << ")." << std::endl;
		delete schemdata;
		return NULL;
	}

	//// Get Y-slice probability values (if present)
	u8 *slice_probs = new u8[size.Y];
	for (i = 0; i != size.Y; i++)
		slice_probs[i] = MTSCHEM_PROB_ALWAYS;

	lua_getfield(L, index, "yslice_prob");
	if (lua_istable(L, -1)) {
		lua_pushnil(L);
		while (lua_next(L, -2)) {
			if (getintfield(L, -1, "ypos", i) && i >= 0 && i < size.Y) {
				slice_probs[i] = getintfield_default(L, -1,
					"prob", MTSCHEM_PROB_ALWAYS);
			}
			lua_pop(L, 1);
		}
	}

	Schematic *schem = SchematicManager::create(SCHEMATIC_NORMAL);

	// Here, we read the nodes directly from the INodeDefManager - there is no
	// need for pending node resolutions so we'll mark this schematic as updated
	schem->flags       = SCHEM_CIDS_UPDATED;

	schem->size        = size;
	schem->schemdata   = schemdata;
	schem->slice_probs = slice_probs;
	return schem;
}


void read_schematic_replacements(lua_State *L, int index, StringMap *replace_names)
{
	if (index < 0)
		index = lua_gettop(L) + 1 + index;

	lua_pushnil(L);
	while (lua_next(L, index)) {
		std::string replace_from;
		std::string replace_to;

		if (lua_istable(L, -1)) { // Old {{"x", "y"}, ...} format
			lua_rawgeti(L, -1, 1);
			replace_from = lua_tostring(L, -1);
			lua_pop(L, 1);

			lua_rawgeti(L, -1, 2);
			replace_to = lua_tostring(L, -1);
			lua_pop(L, 1);
		} else { // New {x = "y", ...} format
			replace_from = lua_tostring(L, -2);
			replace_to = lua_tostring(L, -1);
		}

		replace_names->insert(std::make_pair(replace_from, replace_to));
		lua_pop(L, 1);
	}
}


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


// get_mapgen_object(objectname)
// returns the requested object used during map generation
int ModApiMapgen::l_get_mapgen_object(lua_State *L)
{
	const char *mgobjstr = lua_tostring(L, 1);

	int mgobjint;
	if (!string_to_enum(es_MapgenObject, mgobjint, mgobjstr ? mgobjstr : ""))
		return 0;

	enum MapgenObject mgobj = (MapgenObject)mgobjint;

	EmergeManager *emerge = getServer(L)->getEmergeManager();
	Mapgen *mg = emerge->getCurrentMapgen();
	if (!mg)
		return 0;