aboutsummaryrefslogtreecommitdiff
path: root/advtrains_train_subway
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2017-12-18 21:44:36 +0100
committerorwell96 <orwell@bleipb.de>2017-12-18 23:09:23 +0100
commit46c4447da089146c662f217bf3269d78d4c462c2 (patch)
treee846a588b6ddfb03c456b0c3c4d0653cd3402b85 /advtrains_train_subway
parentfaa60e2bd4d35054f23fda68c06a601f2a197257 (diff)
downloadadvtrains-46c4447da089146c662f217bf3269d78d4c462c2.tar.gz
advtrains-46c4447da089146c662f217bf3269d78d4c462c2.tar.bz2
advtrains-46c4447da089146c662f217bf3269d78d4c462c2.zip
Rewrite rail connection system...
...to support an arbitrary number of connections for rails, which leads to these new features: - switches now get recognized by the trackworker correctly - ability to add real rail crosses During this, I also rewrote the rail registering system and the conway function (important part of path prediction) Note, developers: the track preset format changed, you might need to rewrite them according to the presets in tracks.lua if you wrote your own (possibly breaks advcarts)
Diffstat (limited to 'advtrains_train_subway')
-rw-r--r--advtrains_train_subway/init.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/advtrains_train_subway/init.lua b/advtrains_train_subway/init.lua
index 9dd6f28..310ccf8 100644
--- a/advtrains_train_subway/init.lua
+++ b/advtrains_train_subway/init.lua
@@ -128,8 +128,14 @@ minetest.register_craftitem(":advtrains:subway_train", {
minetest.record_protection_violation(pointed_thing.under, placer:get_player_name())
return
end
- local conn1=advtrains.get_track_connections(node.name, node.param2)
- local id=advtrains.create_new_train_at(pointed_thing.under, advtrains.dirCoordSet(pointed_thing.under, conn1))
+
+ local tconns=advtrains.get_track_connections(node.name, node.param2)
+ local yaw = placer:get_look_horizontal() + (math.pi/2)
+ local plconnid = advtrains.yawToClosestConn(yaw, tconns)
+
+ local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, prototype.drives_on)
+ if not prevpos then return end
+ local id=advtrains.create_new_train_at(pointed_thing.under, prevpos)
for i=1,3 do
local ob=minetest.add_entity(pointed_thing.under, "advtrains:subway_wagon")
a> 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
/*
Minetest
Copyright (C) 2017-2019 vlapsley, Vaughan Lapsley <vlapsley@gmail.com>
Copyright (C) 2017-2019 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 <cmath>
#include "mapgen.h"
#include "voxel.h"
#include "noise.h"
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
#include "settings.h" // For g_settings
#include "emerge.h"
#include "dungeongen.h"
#include "cavegen.h"
#include "mg_biome.h"
#include "mg_ore.h"
#include "mg_decoration.h"
#include "mapgen_carpathian.h"


FlagDesc flagdesc_mapgen_carpathian[] = {
	{"caverns", MGCARPATHIAN_CAVERNS},
	{"rivers",  MGCARPATHIAN_RIVERS},
	{NULL,      0}
};


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


MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager *emerge)
	: MapgenBasic(MAPGEN_CARPATHIAN, params, emerge)
{
	base_level       = params->base_level;
	river_width      = params->river_width;
	river_depth      = params->river_depth;
	valley_width     = params->valley_width;

	spflags            = params->spflags;
	cave_width         = params->cave_width;
	large_cave_depth   = params->large_cave_depth;
	small_cave_num_min = params->small_cave_num_min;
	small_cave_num_max = params->small_cave_num_max;
	large_cave_num_min = params->large_cave_num_min;
	large_cave_num_max = params->large_cave_num_max;
	large_cave_flooded = params->large_cave_flooded;
	cavern_limit       = params->cavern_limit;
	cavern_taper       = params->cavern_taper;
	cavern_threshold   = params->cavern_threshold;
	dungeon_ymin       = params->dungeon_ymin;
	dungeon_ymax       = params->dungeon_ymax;

	grad_wl = 1 - water_level;

	//// 2D Terrain noise
	noise_filler_depth  = new Noise(&params->np_filler_depth,  seed, csize.X, csize.Z);
	noise_height1       = new Noise(&params->np_height1,       seed, csize.X, csize.Z);
	noise_height2       = new Noise(&params->np_height2,       seed, csize.X, csize.Z);
	noise_height3       = new Noise(&params->np_height3,       seed, csize.X, csize.Z);
	noise_height4       = new Noise(&params->np_height4,       seed, csize.X, csize.Z);
	noise_hills_terrain = new Noise(&params->np_hills_terrain, seed, csize.X, csize.Z);
	noise_ridge_terrain = new Noise(&params->np_ridge_terrain, seed, csize.X, csize.Z);
	noise_step_terrain  = new Noise(&params->np_step_terrain,  seed, csize.X, csize.Z);
	noise_hills         = new Noise(&params->np_hills,         seed, csize.X, csize.Z);
	noise_ridge_mnt     = new Noise(&params->np_ridge_mnt,     seed, csize.X, csize.Z);
	noise_step_mnt      = new Noise(&params->np_step_mnt,      seed, csize.X, csize.Z);
	if (spflags & MGCARPATHIAN_RIVERS)
		noise_rivers    = new Noise(&params->np_rivers,        seed, csize.X, csize.Z);

	//// 3D terrain noise
	// 1 up 1 down overgeneration
	noise_mnt_var = new Noise(&params->np_mnt_var, seed, csize.X, csize.Y + 2, csize.Z);

	//// Cave noise
	MapgenBasic::np_cave1  = params->np_cave1;
	MapgenBasic::np_cave2  = params->np_cave2;
	MapgenBasic::np_cavern = params->np_cavern;
	MapgenBasic::np_dungeons = params->np_dungeons;
}


MapgenCarpathian::~MapgenCarpathian()
{
	delete noise_filler_depth;
	delete noise_height1;
	delete noise_height2;
	delete noise_height3;
	delete noise_height4;
	delete noise_hills_terrain;
	delete noise_ridge_terrain;
	delete noise_step_terrain;
	delete noise_hills;
	delete noise_ridge_mnt;
	delete noise_step_mnt;
	if (spflags & MGCARPATHIAN_RIVERS)
		delete noise_rivers;

	delete noise_mnt_var;
}


MapgenCarpathianParams::MapgenCarpathianParams():
	np_filler_depth  (0,   1,   v3f(128,  128,  128),  261,   3, 0.7,  2.0),
	np_height1       (0,   5,   v3f(251,  251,  251),  9613,  5, 0.5,  2.0),
	np_height2       (0,   5,   v3f(383,  383,  383),  1949,  5, 0.5,  2.0),
	np_height3       (0,   5,   v3f(509,  509,  509),  3211,  5, 0.5,  2.0),
	np_height4       (0,   5,   v3f(631,  631,  631),  1583,  5, 0.5,  2.0),
	np_hills_terrain (1,   1,   v3f(1301, 1301, 1301), 1692,  5, 0.5,  2.0),
	np_ridge_terrain (1,   1,   v3f(1889, 1889, 1889), 3568,  5, 0.5,  2.0),
	np_step_terrain  (1,   1,   v3f(1889, 1889, 1889), 4157,  5, 0.5,  2.0),
	np_hills         (0,   3,   v3f(257,  257,  257),  6604,  6, 0.5,  2.0),
	np_ridge_mnt     (0,   12,  v3f(743,  743,  743),  5520,  6, 0.7,  2.0),
	np_step_mnt      (0,   8,   v3f(509,  509,  509),  2590,  6, 0.6,  2.0),
	np_rivers        (0,   1,   v3f(1000, 1000, 1000), 85039, 5, 0.6,  2.0),
	np_mnt_var       (0,   1,   v3f(499,  499,  499),  2490,  5, 0.55, 2.0),
	np_cave1         (0,   12,  v3f(61,   61,   61),   52534, 3, 0.5,  2.0),
	np_cave2         (0,   12,  v3f(67,   67,   67),   10325, 3, 0.5,  2.0),
	np_cavern        (0,   1,   v3f(384,  128,  384),  723,   5, 0.63, 2.0),
	np_dungeons      (0.9, 0.5, v3f(500,  500,  500),  0,     2, 0.8,  2.0)
{