forked from DokimiCU/mg_tectonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
2154 lines (1849 loc) · 61.6 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
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
---============================================================================
--MG TECTONIC
--By Dokimi
--A naturalistic mapgen.
--This is the main mapgen code.
--=============================================================================
--PRELIMINARIES
mgtec = {}
local mod_storage = minetest.get_mod_storage()
---------------------
--SINGLENODE
minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
--Despite being the up to date method this doesn't work
--minetest.set_mapgen_setting("mgname", "singlenode", true)
--minetest.set_mapgen_setting("flags", "nolight", true)
-----------------
--PLANTS API
dofile(minetest.get_modpath("mg_tectonic").."/trees.lua")
dofile(minetest.get_modpath("mg_tectonic").."/plants_api.lua")
dofile(minetest.get_modpath("mg_tectonic").."/plants.lua")
--may cause bugs????
if minetest.get_modpath("mgt_flora") ~= nil then
dofile(minetest.get_modpath("mgt_flora").."/plants_reg.lua")
end
if mgtec.registered_on_first_mapgen then -- Run callbacks
for _, f in ipairs(mgtec.registered_on_first_mapgen) do
f()
end
mgtec.registered_on_first_mapgen = nil
mgtec.register_on_first_mapgen = nil
end
--=============================================================================
-- PARAMETERS
----------------------
--MISC
-- the edge of the map
local YMAX = 31000
local YMIN = -31000
--sealevel
local SEA = 0
--height of lava
local MAXMAG = -15000
-------------------
--BASE LAYER:
-- Wave Roll Size: i.e Period
--Controls distance between ranges, and thickness.
--This is the period at the map centre. Grows to double at map edges
--will effect gradient and number of major mt ranges
local XRS = 537--617
--Where does the continental shelf end?
local SHELFX = 25000
local SHELFZ = 28000
--How deep are the oceans?
local SEABED = -15000
--Strength of noise on continental shelf boundaries lines
local CONOI = 2500
--Cave size.
--Base cave threshold for fissures
local BCAVTF = 0.0079
--Base cave threshold for caves
local BCAVT = 0.996
--Ore threshold
local ORET = 0.975
--==================================================================
--FUNCTIONS
--Checks if this is a place for ore deposits.
local function ore(nocave, ab_stra, ab_cave, ab_cave2, y, ORET, ybig, n_strata, data, vi, OREID)
--c_coal, c_iron, c_copp, c_tin, c_gold, c_diam, c_mese
--strata thickness
local thick = 100 + (50 * ab_stra)
--strata splits for ore types..
local t1 = 0.25
local t2 = 0.5
local t3 = 0.83
local ystrata = math.sin(y/thick)
--a fair sine wave split, with low value ores dominant
--[[for reference... if the above gets confusing
local ysmin_coal = 0 * TSTRA
local ysmax_coal = 0.25 * TSTRA
local ysmin_cop = 0.25 * TSTRA
local ysmax_cop = 0.5 * TSTRA
local ysmin_gol = 0.5 * TSTRA
local ysmax_gol = 0.83 * TSTRA
local ys_mese1 = 0.83 * TSTRA --mese is on the ends of the range
local ysmin_iron = -0.25 * TSTRA
local ysmax_iron = 0 * TSTRA
local ysmax_tin = -0.25 * TSTRA
local ysmin_tin = -0.5 * TSTRA
local ysmax_dia = -0.5 * TSTRA
local ysmin_dia = -0.83 * TSTRA
local ys_mese2 = -0.83 * TSTRA
--]]
--threshold adjusted with depth to get bigger down deep.
local ore_t = ORET + ybig
--harder if actually in the cave.
if not nocave then
ore_t = ore_t + 0.05
end
--height limits
local blend = n_strata * 50
local orehmin_c = -10000 + (n_strata * 500) --min height for coal (a shallow ore)
local orehmax_g = -30 + blend --dig a little for gold
local orehmax_d = -600 + blend --diamonds are deep
local orehmax_m = -400 + blend --mese is deep
--above their threshold
--add some of the cave noise to increase chance of finding ores near caves
--working with caves: should be less inside the actual cave (less floaters), but..
--..reduced threshold should boost approaching cave
if ab_stra >= ore_t - (ab_cave2 * 0.02) then
--split them by height and strata
--coal.
if y > orehmin_c
and ystrata >= 0 --strata splits
and ystrata < t1
then
data[vi] = OREID.c_coal
return true
--iron
elseif ystrata > -t1 --strata splits
and ystrata < 0 then
data[vi] = OREID.c_iron
return true
--copper
elseif ystrata > t1 --strata splits
and ystrata < t2 then
data[vi] = OREID.c_copp
return true
--tin
elseif ystrata > -t2 --strata splits
and ystrata < -t1 then
data[vi] = OREID.c_tin
return true
--Gold
elseif y < orehmax_g
and ystrata > t2 --strata splits
and ystrata < t3 then
data[vi] = OREID.c_gold
return true
--Diamonds
elseif y < orehmax_d
and ystrata > -t3 --strata splits
and ystrata < -t2 then
data[vi] = OREID.c_diam
return true
--Mese
elseif y < orehmax_m
and (ystrata > t3 --strata splits, end of range
or ystrata < -t3) then
data[vi] = OREID.c_mese
return true
end
--end of ores
else
--have to let it know so it can set void etc
return false
end
--end of all ores
end
--End of Ore function
------------------------------
--Climate Calculations.
--this function can be called by other mods instead of default biome climate checks
mgtec.climate = function(x, z, y, n_terr, n_terr2)
--east = + x, west = - x, south = -z, n = + z
--Climate is decided by:
-- -Ranges: rains come from the west (-x), rise over the ranges dumping cooling rain, descending hot and dry (east +x)
-- - Altitude: it's cold up there.
-- - Latitude: hot north, cold south
--blending
local blend = math.random(-4, 4)
--to help climate be accessed by other mods (mainly weather)
--we will ignore noise (thorn0906's solution crashes when actually used,
-- accessing noise repeatedly likely very heavy for little gain
-- reducing noiseyness better? Randomness can make things throw a fit)
if n_terr == nil or n_terr2 == nil then
blend = 0
n_terr = 0
n_terr2 = 0
end
--We are Southern Hemisphererers here!
--decreasing temp from max z to min z (latitude) (from 100 to 0 i.e north desert to south ice)
-- linear increase, intercept at 50
local temp_z = (0.00163*z) + 50 - blend
-- no Fohn? Westies are controlled by z only
local temp_x = 0
local lon_blend = (blend*3) + n_terr * 200 --offset east-west border with some noise
-- Easterners?
if x > lon_blend then
--Fohn Winds! They are hot! The East Coast gets a temp boost
-- adds + 20 at centre of map, declines to zero
temp_x = (-0.00065*x) + 20 - blend
end
--Mountain tops ought to be cold!
--decreasing temp with hieght...and combine previous two as baseline
local temp = temp_z + temp_x - blend
--only apply height adjustment above sea level, otherwise cooking oceans
--large parts of "lowlands" are very high too, so start cooling high.
--i.e. -0.05 = -50 at 1000m
if y >= 200 + (n_terr *75) then
temp = (-0.05*y) + temp_z + temp_x - blend
end
---------------
--what's the humidity? Rainshadow!
--decreasing humid from far x to x= 0,(rain shadow)
--tip a little past 50 for greater variety
--i.e. 0-60, so have wet islands on the dry side, dry islands on wet side
--if in doubt ...
local hum = 50
----poitive, east coast. Dry inland
--linear increase,
if x > lon_blend then
hum = (0.00194*x) + blend
--increasing humid from far x to x= 0,(rain shadow)
else --negative , west coast. Wet inland
--linear increase,
--starts a little lower than max (i.e. + <100)
--so that altitude boosts it to max
hum = (0.00145*x) + 85 + blend
end
--Transition humidity
--this is to avoid a sharp line East West
-- not perfect but better than nothing?
if x > lon_blend and x < lon_blend + 400 then
--east must be wetter
if x < lon_blend + 100 then
hum = hum + 35
elseif x < lon_blend + 200 then
hum = hum + 20
else
hum = hum + 15
end
elseif x < lon_blend and x > lon_blend - 300 then
--west must be drier
if x > lon_blend - 100 then
hum = hum - 20
elseif x > lon_blend - 200 then
hum = hum - 10
else
hum = hum - 5
end
end
--disturbance regime
--i.e. ecological succession
local distu = math.abs(n_terr * 100 + blend)
--altitude effects..
--coast is wet, but disturbed
-- hill tops catch rain but are more disturbed
if y > 490 or (y < 10 and y > -3) then
--alpine (force snowy)
if y > 1200 + math.random(-30, 5) then
hum = hum + 48
temp = temp - 32
distu = distu + 12
--subalpine
elseif y > 1100 + blend then
hum = hum + 24
temp = temp - 16
distu = distu + 6
elseif y > 1000 + blend then
hum = hum + 12
temp = temp - 8
distu = distu + 3
--montane
elseif y > 900 + blend then
temp = temp - 4
hum = hum + 6
elseif y > 700 + blend then
temp = temp - 2
hum = hum + 3
elseif y > 500 + blend then
hum = hum + 2
--coast
elseif (y <= 3 and y >= -1) then
-- generally wetter, but sometimes drier
--..coasts are more variable
hum = hum + 3 + blend
distu = distu + 5
end
end
--disturbance Feedsback on micro-climate
--calm areas hold water.
--exposed areas are hotter
--sheltered a little colder
if distu <15 or distu >80 then
if distu < 10 then
if distu <5 then
hum = hum + 8
temp = temp - 4
elseif distu <15 then
hum = hum + 4
temp = temp - 2
end
elseif distu > 80 then
if distu > 95 then
hum = hum - 12
temp = temp + 12
elseif distu > 90 then
hum = hum - 6
temp = temp + 6
elseif distu > 80 then
hum = hum - 3
temp = temp + 3
end
end
end
return temp, hum, distu
--done climate calculations
end
-------------------------------------
--Create Swamp
local function swamp(data, vi, chance, mud, water)
--let's place a messy swampy mire
local roll = math.random(1, chance)
if roll == 1 then
data[vi] = water
else
data[vi] = mud
end
--end of swamp
end
--End of functions
--=============================================================================
--IDs
-- Get the content IDs for the nodes used.
--rocks
local c_stone = minetest.get_content_id("default:stone")
local c_stone2 = minetest.get_content_id("default:desert_stone")
local c_sandstone = minetest.get_content_id("default:desert_sandstone")
local c_sandstone2 = minetest.get_content_id("default:sandstone")
local c_sandstone3 = minetest.get_content_id("default:silver_sandstone")
local c_obsid = minetest.get_content_id("default:obsidian")
local c_coral = minetest.get_content_id("default:coral_skeleton")
local c_coralb = minetest.get_content_id("default:coral_brown")
local c_coralo = minetest.get_content_id("default:coral_orange")
--sediments
local SEDID = {
c_gravel = minetest.get_content_id("default:gravel"),
c_clay = minetest.get_content_id("default:clay"),
c_sand = minetest.get_content_id("default:sand"),
c_sand2 = minetest.get_content_id("default:silver_sand"),
c_dirt = minetest.get_content_id("default:dirt"),
c_perma = minetest.get_content_id("default:permafrost"),
}
--surfaces
local c_dirtgr = minetest.get_content_id("default:dirt_with_grass")
local c_dirtdgr = minetest.get_content_id("default:dirt_with_dry_grass")
local c_dirtsno = minetest.get_content_id("default:dirt_with_snow")
local c_dirtlit = minetest.get_content_id("default:dirt_with_rainforest_litter")
local c_dirtconlit = minetest.get_content_id("default:dirt_with_coniferous_litter")
local c_snowbl = minetest.get_content_id("default:snowblock")
local c_snow = minetest.get_content_id("default:snow")
local c_ice = minetest.get_content_id("default:ice")
local c_dsand = minetest.get_content_id("default:desert_sand")
local c_permamoss = minetest.get_content_id("default:permafrost_with_moss")
local c_permastone = minetest.get_content_id("default:permafrost_with_stones")
--Miscellaneous
local MISCID = {
c_water = minetest.get_content_id("default:water_source"),
c_river = minetest.get_content_id("default:river_water_source"),
c_air = minetest.get_content_id("air"),
c_ignore = minetest.get_content_id("ignore"),
c_lava = minetest.get_content_id("default:lava_source"),
c_kelpsand = minetest.get_content_id("default:sand_with_kelp"),
c_coral_cyan = minetest.get_content_id("default:coral_cyan"),
c_coral_green = minetest.get_content_id("default:coral_green"),
c_coral_pink = minetest.get_content_id("default:coral_pink"),
}
--ores
local OREID = {
c_diam = minetest.get_content_id("default:stone_with_diamond"),
c_mese = minetest.get_content_id("default:stone_with_mese"),
c_gold = minetest.get_content_id("default:stone_with_gold"),
c_copp = minetest.get_content_id("default:stone_with_copper"),
c_tin = minetest.get_content_id("default:stone_with_tin"),
c_iron = minetest.get_content_id("default:stone_with_iron"),
c_coal = minetest.get_content_id("default:stone_with_coal")
}
--=============================================================================
--NOISES
-- 2D Mountain Terrain.
--controls: large rounded mountains.
local np_terrain = {
offset = 0,
scale = 1,
spread = {x = 1944, y = 3078, z = 1944},
seed = 110013,
octaves = 5,
persist = 0.3,
lacunarity = 3,
--flags = 'noeased',
}
-- 2D Soft rock Terrain.
--controls: sharp peaks
local np_terrain2 = {
offset = 0,
scale = 1,
spread = {x = 405, y = 243, z = 405},
seed = 5938033,
octaves = 3,
persist = 0.6,
lacunarity = 3,
flags = 'noeased',
}
-- 3D Caves 1
--used by: fissures in basement rock,
local np_cave = {
offset = 0,
scale = 1,
spread = {x = 108, y = 243, z = 324},
seed = -9103323,
octaves = 3,
persist = 0.2,
lacunarity = 3,
--flags = 'noeased',
}
-- 3D Caves 2
--used by: breaks in fissures, caves in basement rock
local np_cave2 = {
offset = 0,
scale = 1,
spread = {x = 81, y = 27, z = 81},
seed = 205301,
octaves = 3,
persist = 0.5,
lacunarity = 3,
flags = 'noeased',
}
--3D Strata
-- used by: ore thresholds.
local np_strata = {
offset = 0,
scale = 1,
spread = {x = 81, y = 81, z = 81},
seed = 51055033,
octaves = 3,
persist = 0.7, --high or get few ore
lacunarity = 3,
}
---============================================================================
--NOISE MEMORY
-- Initialize noise object to nil. It will be created once only during the
-- generation of the first mapchunk, to minimise memory use.
local nobj_terrain = nil
local nobj_terrain2 = nil
local nobj_cave = nil
local nobj_cave2 = nil
local nobj_strata = nil
-- For getting individual n_terr values
--nobj_terr_i = nil
--nobj_terr2_i = nil
-- Localise noise buffer table outside the loop, to be re-used for all
-- mapchunks, therefore minimising memory use.
local nvals_terrain = {}
local nvals_terrain2 = {}
local nvals_cave = {}
local nvals_cave2 = {}
local nvals_strata = {}
-- Localise data buffer table outside the loop, to be re-used for all
-- mapchunks, therefore minimising memory use.
local data = {}
-- param2 data
local data2 = {}
--=============================================================================
-- GENERATION
local num_lakes = nil
local lakes = nil
local spawnpoint = {x = 0, z = 0}
minetest.register_on_mapgen_init(function(mapgen_params)
math.randomseed(mapgen_params.seed)
spawnpoint = {x = math.random(-23000, 23000), z = math.random(-27000, 27000)}
-- some things need to be random, but stay constant throughout the loop
-- number of lakes
if lakes == nil then
num_lakes = math.random(15,18)
lakes = {}
for i = 0, num_lakes do
--keep back from "shelf" as the coastline is actually much further back
--need to keep them out of main ranges...too much erosion.
--choose east or west.
if math.random(1,3) <=2 then
--west lake
lakes[i] = {x = math.random(-13000,-5500), z = math.random(-25000,25000), r = math.random(1,5)}
else
--East lake.
lakes[i] = {x = math.random(13000,5500), z = math.random(-25000,25000), r = math.random(1,4)}
end
--save location for bug checking
mod_storage:set_int("Lake"..i.."x", lakes[i].x)
mod_storage:set_int("Lake"..i.."z", lakes[i].z)
mod_storage:set_int("Lake"..i.."river", lakes[i].r)
end
end
end)
table.insert(minetest.registered_on_generateds, 1, (function(minp, maxp, seed)
math.randomseed(seed)
--------------------------------
--don't do out of bounds!
--world is a square, ymin will do for z and x too.
if minp.x < YMIN
or maxp.x > YMAX
or minp.y < YMIN
or maxp.y > YMAX
or minp.z < YMIN
or maxp.z > YMAX
then
return
end
-----------------------------
-- Start time of mapchunk generation.
local t0 = os.clock()
--------------------------------
-- NOISE
-- Side length of mapchunk.
local sidelen = maxp.x - minp.x + 1
-- Required dimensions noise perlin map.
--3d
local chulen = {x = sidelen, y = sidelen, z = sidelen}
--2d
local chulenxz = {x = sidelen, y = sidelen, z = 1}
local minposxyz = {x = minp.x, y = minp.y - 1, z = minp.z}
local minposxz = {x = minp.x, y = minp.z}
-- strides for voxelmanip
local ystridevm = sidelen + 32
local zstridevm = ystridevm ^ 2
-- Create the perlin map noise object once only, during the generation of
-- the first mapchunk when 'nobj_terrain' is 'nil'.
nobj_terrain = nobj_terrain or minetest.get_perlin_map(np_terrain, chulenxz)
nobj_terrain2 = nobj_terrain2 or minetest.get_perlin_map(np_terrain2, chulenxz)
nobj_cave = nobj_cave or minetest.get_perlin_map(np_cave, chulen)
nobj_cave2 = nobj_cave2 or minetest.get_perlin_map(np_cave2, chulen)
nobj_strata = nobj_strata or minetest.get_perlin_map(np_strata, chulen)
--nobj_terr_i = nobj_terr_i or minetest.get_perlin(np_terrain.seed, np_terrain.octaves, np_terrain.persist, np_terrain.scale)
--nobj_terr2_i = nobj_terr_i or minetest.get_perlin(np_terrain2.seed, np_terrain2.octaves, np_terrain2.persist, np_terrain2.scale)
-- Create a flat array of noise values from the perlin map, with the
-- minimum point being 'minp'.
-- Set the buffer parameter to use and reuse 'nvals_X' for this.
nobj_terrain:get2dMap_flat(minposxz, nvals_terrain)
nobj_terrain2:get2dMap_flat(minposxz, nvals_terrain2)
nobj_cave:get3dMap_flat(minposxyz, nvals_cave)
nobj_cave2:get3dMap_flat(minposxyz, nvals_cave2)
nobj_strata:get3dMap_flat(minposxyz, nvals_strata)
-----------------------------------------------------------
-- VOXELMANIP
-- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
-- mapgen is used this will be a mapchunk of air nodes.
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
-- 'area' is used later to get the voxelmanip indexes for positions.
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
-- Get the content ID data from the voxelmanip in the form of a flat array.
-- Set the buffer parameter to use and reuse 'data' for this.
vm:get_data(data)
vm:get_param2_data(data2)
---------------------------------------------
-- GENERATION LOOP
----------------------------
--Begin the Loop
-- Noise index for the flat array of noise values.
-- 3D perlinmap indexes
local nixyz = 1
-- 2D perlinmap indexes
local nixz = 1
-- Process the content IDs in 'data'.
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
-- Voxelmanip index for the flat array of content IDs.
-- Initialise to first node in this x row.
local vi = area:index(minp.x, y, z)
for x = minp.x, maxp.x do
----------------------------------------------------
--Welcome to the Loop
-----------
--Noises
local n_terr = nvals_terrain[nixz]
local n_terr2 = nvals_terrain2[nixz]
local ab_t = math.abs(n_terr)
local ab_t2 = math.abs(n_terr2)
local n_cave = nvals_cave[nixyz]
local n_cave2 = nvals_cave2[nixyz]
local ab_cave = math.abs(n_cave)
local ab_cave2 = math.abs(n_cave2)
local n_strata = nvals_strata[nixyz]
local ab_stra = math.abs(n_strata)
--Get the node underneath
local nodu = data[(vi - ystridevm)]
-----------
-- Math
--absolute for x (for symmetry on both sides of map)
local xab = math.abs(x)
--x axis terrain gradient. 0 at centre. 1 at edges.
--Used by equations to adjust along x axis
local xtgrad = (xab/YMAX)
--amplitude... going from 1 to zero at map edge
local whs = 1-xtgrad
--Move up/down along x axis. Goes from +1 to -1
--mup raises and lowers along x axis. the two terms cancel out in middle of x range (15k).
--aimed for equations that need to lift map centre, sink edges
local mup = whs + (-1 * xtgrad)
------------------
--Base Layer Waves
--creates the underlying, undulating and mountainous terrain
--Wave period. "Roll". i.e. how wide/steep and they are.
--Gradient widens the ranges towards the edges.
local x_roll = XRS + (XRS * xtgrad) --x axis
--The Wave!
local xwav = (whs*math.cos(x/x_roll)) -- north south wave (main ranges)
local xwav2 = (whs*math.cos(x/(x_roll/6.89))) --smaller more detailed wave
--Base Wave Density.
--This is checked against the threshold to decide where the base layer can go.
--the wave controls the landscape folding i.e. the bunching up caused by the plates hitting eachother.
--variation along this fold is caused by erosion, so is much more random...
--cubing/squaring flattens out the middle range, squaring eliminates negatives
--for the wave that gives it a flat shelf at sea level.
--for the noise it mellows part of it out, so it adds mainly extreme peaks and dips
--mup lowers the landscape at the edges (ocean), otherwise the flattening of height would lead to endless plains
--wave + raise + large hills 2 + sharp hills (moderated by large or gives sky needles) + cliffs 2
--waves
local dwav = ((xwav2 ^ 3)*1.67) + ((xwav ^ 3)*6.89) + (mup*10.81)--+ (mup*12.16)
--noise
local dnoi = ((n_terr ^3) + ((n_terr)*0.5) + ((n_terr2*n_terr)*0.8)) * 2.8 * (whs + 0.02)
--cliffs..
local dclif1 = ((ab_stra)*0.16)
local dclif2 = ((ab_cave*ab_cave2)*0.05)
local den_base = dwav + dnoi - dclif1 - dclif2
---Base Threshold (use for all of them now)
--effects heights of landscape
local t_base = 0.00969*y --0.01036*y
-------------------------------------
--Soft Rock
--layered on top of the base layer.
--adding to previous: x >1 = steeper. x < 1 flatter
--soft sandstone... easily erobable rocks sedimentary rocks
--creates regions of soft rock on top of the base layer in lowlands
--base + boost + noise - cliff
--density
local den_soft = (den_base*0.4) + 1.3 + ((1-n_terr) * (2.22 - (xtgrad*2))) - dclif2
--threshold (redundant)
--local t_soft = 0.006*y -0.15
------------------------------------
--Alluvium
--eroded rock etc, deposited on lowlands
--density
local den_allu = (den_soft*0.95) + 0.1 - dclif2
--threshold (redundant)
--local t_allu = 0.0075*y -0.17
------------------------------------
--Sediment
--subsurface soils and sands
--density
local den_sedi = den_allu + 0.03 -- dclif2
--threshold (redundant)
--local t_sedi = 0.0085*y -0.18
-------------------------------------
--Checks
--This is so we know if we placed something.
local void = true -- we have yet to set anything
local nocave = true --basement rock caves
local basin = false --ocean basin
local river_basin = false --river basin
--------------------------------------------------
--THE DECISION TREE
-------------------------------------------------
-------------------------------
--Seperate Earth and Sky
if den_base > t_base
or den_soft > t_base
or den_allu > t_base
or den_sedi > t_base then
--Seperate Earth from oceans, rivers, caves.
----------------------------
-- Ocean Basins/Erosion
--carves out a continental shelf.
--lowers mountains so can have sea at North and South
local zab = math.abs(z)
-- coastline
local shelfnoi = (((n_terr ^3) + (n_terr2 *0.08)) * CONOI) - dclif2
local shelfsl = (3 - (n_terr^3))*y --sets slope for x
--local bed = SEABED + ((n_terr^3)*SEABED)
--Are we in the right place for oceans?
if (xab > ((SHELFX + (shelfnoi*2)) - shelfsl)
or zab > ((SHELFZ + shelfnoi) - shelfsl))
and y >= SEABED then --max depth,
basin = true
end
-----------------------------
--Lakes and rivers.
--These are put in "manually" as doing it based on noise does not work well for rivers
--The point of these is:
-- to bring water to the dry interior, provide access, features of interest, greater altitude variation.
--they have a large erosion effect on the surrounding area. So need very steep sides
------------------------------
--[[
--Central Caldera
--To give a water feature in the middle of the map.
--define a square which will be the lake, then soften it with noise
local calr = (350 + (150 * n_terr) + (50 * n_terr2)) * (1 + (y/50))
local cald = -90 + (47 * n_terr) + (47 * n_terr2)
if xab < calr
and zab < calr
and y > cald then
basin = true
end
-----------------------------
--caldera island
local calir = (55 + (25 * n_terr) + (25 * n_terr2)) * (1 - (y/(25 + n_terr2)))
local calid = -1000 - (250 * n_terr) - (250 * n_terr2)
if xab < calir
and zab < calir
and y > calid
then
if xab < calir/3
and zab < calir/3
and y < -150 + (50 * n_terr2) --match to calir y cut off
then
--we have a lava chamber.
data[vi] = MISCID.c_lava
void = false
else
--obsidian and ore
--small chance of minerals from volcanism..
local roll = math.random(1,200)
if roll == 1 then
data[vi] = OREID.c_gold
void = false
elseif roll == 2 then
data[vi] = OREID.c_copp
void = false
elseif roll == 3 then
data[vi] = OREID.c_tin
void = false
elseif roll == 4 then
data[vi] = OREID.c_mese
void = false
else
data[vi] = c_obsid
void = false
end
end
end
--]]
----------------------------------
--Random lakes
if not basin and not river_basin then
for n = 0, num_lakes do
local laked = -25 + (10 * n_terr2)
local laker = (160 + (100 * n_terr) + (25 * n_terr2)) * (1 + (y/(160 + (20 * n_terr))))
if x < lakes[n].x + (laker*1.6) and x > lakes[n].x - (laker*1.6)
and z < lakes[n].z + laker and z > lakes[n].z - laker
and y > laked then
river_basin = true
end
--Rivers draining them
if lakes[n].r <= 4 then
--local interr = 1-n_terr
local interr2 = 1-n_terr2
--rivers have real world mathmatical geometry
--width (actually half the width)
local wp = (8 + (0.0003*xab))
local w = (wp * (1 + (y/(8 + (n_terr*2))))) - ((n_terr2^3)*3)
--period of channel
local per_ch = ((3.5 * n_terr) + 22) * wp
--local per_ch = 176
--amplitude
local am_ch = (interr2 + 4.6) * wp
--local am_ch = 37
--wave for channel
local c1 = ((am_ch)*math.sin(x/per_ch))
local c2 = (12 + (interr2*3))*math.sin(x/(56 + (n_terr*8)))
local channel = c1 + c2
--line it up north-south
if z <= lakes[n].z + channel + w
and z >= lakes[n].z + channel - w then
--make sure the river is on the same side East-west of the map as the lake!
--east lakes, only place the river further east
if lakes[n].x > 0 and x + w > lakes[n].x then
river_basin = true
--west lakes, only place river further west
elseif lakes[n].x < 0 and x - w < lakes[n].x then
river_basin = true
end
end
end
end
end
--[[
----------------------------------
--A river running out of the caldera in some direction
local cx = (n_terr2*30)*math.cos(xab/42)
local cz = (n_terr*30)*math.cos(xab/21)
local w = (22 + (n_terr2*9) + (10*xtgrad)) * (1 + (y/(12 - (3*xtgrad))))
if x <= cx + w and x >= cx - w and z <= cz + w and z >= cz - w then
basin = true
end
----------------------------------
--a river running bisecting the land East/west
local channel = (50 +(n_terr2*30))*math.cos(xab/42)
local w = (22 + (n_terr2*9) + (10*xtgrad)) * (1 + (y/(12 - (3*xtgrad))))
if z <= channel + w and z >= channel - w then
basin = true
end
-----------------------------------
--Mirror lake
--gives four lakes.
local laker = (140 + (75 * n_terr) + (75 * n_terr2)) * (1 + (y/(55 + (5 * n_terr2))))
local laked = -25 + (20 * n_terr) + (8 * n_terr2)
if xab < 5000 + laker and xab > 5000 - laker
and zab < 15000 + laker and zab > 15000 - laker
and y > laked then
basin = true
end
---------------------------------
--Mirror Rivers
--give four rivers draining the four lakes
local channel = (40 +(n_terr2*30))*math.cos(xab/36)
local w = (16 + (n_terr2*7) + (10*xtgrad)) * (1 + (y/(14 - (3*xtgrad))))
if zab <= 15000 + channel + w
and zab >= 15000 + channel - w
and xab > 5000 then