-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoveMapContinentsv3.6.lua
1149 lines (989 loc) · 32.2 KB
/
LoveMapContinentsv3.6.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
------------------------------------------------------------------------------
-- FILE: Lekmapv2.2.lua (Modified Pangaea_Plus.lua)
-- AUTHOR: Original Bob Thomas, Changes HellBlazer, lek10, EnormousApplePie, Cirra, Meota
-- PURPOSE: Global map script - Simulates a Pan-Earth Supercontinent, with
-- numerous tectonic island chains.
------------------------------------------------------------------------------
-- Copyright (c) 2011 Firaxis Games, Inc. All rights reserved.
------------------------------------------------------------------------------
include("HBMapGenerator3.6");
include("HBFractalWorld3.6");
include("HBFeatureGenerator3.6");
include("HBTerrainGenerator3.6");
include("IslandMaker");
include("MultilayeredFractal");
------------------------------------------------------------------------------
function GetMapScriptInfo()
local world_age, temperature, rainfall, sea_level, resources = GetCoreMapOptions()
local opt = {
{
Name = "TXT_KEY_MAP_OPTION_WORLD_AGE", -- 1
Values = {
"TXT_KEY_MAP_OPTION_THREE_BILLION_YEARS",
"TXT_KEY_MAP_OPTION_FOUR_BILLION_YEARS",
"TXT_KEY_MAP_OPTION_FIVE_BILLION_YEARS",
"No Mountains",
"TXT_KEY_MAP_OPTION_RANDOM",
},
DefaultValue = 2,
SortPriority = -99,
},
{
Name = "TXT_KEY_MAP_OPTION_TEMPERATURE", -- 2 add temperature defaults to random
Values = {
"TXT_KEY_MAP_OPTION_COOL",
"TXT_KEY_MAP_OPTION_TEMPERATE",
"TXT_KEY_MAP_OPTION_HOT",
"TXT_KEY_MAP_OPTION_RANDOM",
},
DefaultValue = 2,
SortPriority = -98,
},
{
Name = "TXT_KEY_MAP_OPTION_RAINFALL", -- 3 add rainfall defaults to random
Values = {
"TXT_KEY_MAP_OPTION_ARID",
"TXT_KEY_MAP_OPTION_NORMAL",
"TXT_KEY_MAP_OPTION_WET",
"TXT_KEY_MAP_OPTION_RANDOM",
},
DefaultValue = 2,
SortPriority = -97,
},
{
Name = "TXT_KEY_MAP_OPTION_SEA_LEVEL", -- 4 add sea level defaults to random.
Values = {
"TXT_KEY_MAP_OPTION_LOW",
"TXT_KEY_MAP_OPTION_MEDIUM",
"TXT_KEY_MAP_OPTION_HIGH",
"TXT_KEY_MAP_OPTION_RANDOM",
},
DefaultValue = 2,
SortPriority = -96,
},
{
Name = "Start Quality", -- 5 add resources defaults to random
Values = {
"Legendary Start - Strat Balance",
"Legendary - Strat Balance + Uranium",
"TXT_KEY_MAP_OPTION_STRATEGIC_BALANCE",
"Strategic Balance With Coal",
"Strategic Balance With Aluminum",
"Strategic Balance With Coal & Aluminum",
"Strategic Balance With Coal & Aluminum & Uran",
"TXT_KEY_MAP_OPTION_RANDOM",
},
DefaultValue = 2,
SortPriority = -95,
},
{
Name = "Start Distance", -- 6 add resources defaults to random
Values = {
"Close",
"Normal",
"Far - Warning: May sometimes crash during map generation",
},
DefaultValue = 2,
SortPriority = -94,
},
{
Name = "Natural Wonders", -- 7 number of natural wonders to spawn
Values = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"Random",
"Default",
},
DefaultValue = 15,
SortPriority = -93,
},
{
Name = "Grass Moisture", -- add setting for grassland mositure (8)
Values = {
"Wet",
"Normal",
"Dry",
},
DefaultValue = 2,
SortPriority = -92,
},
{
Name = "Rivers", -- add setting for rivers (9)
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -91,
},
{
Name = "Tundra Size", -- add setting for tundra (10)
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -90,
},
{
Name = "Forest Size", -- (11) forestSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -80,
},
{
Name = "Jungle Size", -- (12) jungleSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -79,
},
{
Name = "TXT_KEY_MAP_OPTION_RESOURCES", -- add setting for resources (13)
Values = {
"1 -- Nearly Nothing",
"2",
"3",
"4",
"5 -- Default",
"6",
"7",
"8",
"9",
"10 -- Almost no normal tiles left",
},
DefaultValue = 5,
SortPriority = -87,
},
{
Name = "Islands", -- add setting for islands (14)
Values = {
"sparse",
"average",
"plentiful",
"abundant",
},
DefaultValue = 2,
SortPriority = -86,
},
{
Name = "Coastal Spawns", -- Can inland civ spawn on the coast (15)
Values = {
"Coastal Civs Only",
"Random",
"Random+ (~2 coastals)",
},
DefaultValue = 1,
SortPriority = -85,
},
{
Name = "Coastal Luxes", -- Can coast spawns have non-coastal luxes (16)
Values = {
"Guaranteed",
"Random",
},
DefaultValue = 1,
SortPriority = -84,
},
{
Name = "Inland Sea Spawns", -- Can coastal civ spawn on inland seas (17)
Values = {
"Allowed",
"Not Allowed for Coastal Civs",
},
DefaultValue = 1,
SortPriority = -83,
},
{
Name = "Start type", -- add setting for land type (18)
Values = {
"One Continent Challenge",
"regular",
},
DefaultValue = 2,
SortPriority = -82,
},
{
Name = "Must be coast", -- (19) force coastal start
Values = {
"Yes",
"No",
},
DefaultValue = 1,
SortPriority = -81,
},
{
Name = "Desert Size", -- (20) desertSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -80,
},
{
Name = "Marsh Size", -- (21) marshSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -78,
},
{
Name = "Map Dimensions", -- (22) mapSize
Values = {
"Cage",
"Standard",
"Big",
"Random",
},
DefaultValue = 2,
SortPriority = -100,
},
}
opt["Tech Speed"] = {
Name = Locale.ConvertTextKey("TXT_KEY_MAP_OPTION_TECH_SPEED_ID"),
Values = {
"Online",
"Quick",
"Fair",
"Standard",
"Optimal",
"Epic",
"Marathon",
},
DefaultValue = 4,
SortPriority = -101,
}
return {
Name = "LoveMaps: Continents (v3.6)",
Description = "A map script made for Lekmod based of HB's Mapscript v8.1. Continents",
IsAdvancedMap = false,
IconIndex = 1,
SortIndex = 2,
SupportsMultiplayer = true,
CustomOptions = opt
};
end
------------------------------------------------------------------------------
function GetMapInitData(worldSize)
local mapSize = Map.GetCustomOption(22)
if mapSize == 4 then
mapSize = 1 + Map.Rand(3, "Random Map - Lua");
end
local curWidth = 25;
local curHeight = 20;
local factorW = 15;
local factorH = 10;
if mapSize == 1 then
curWidth = math.floor(curWidth * 0.8);
curHeight = math.floor(curHeight * 0.8);
factorW = math.floor(factorW * 0.8);
factorH = math.floor(factorH * 0.8);
end
if mapSize == 3 then
curWidth = math.floor(curWidth * 1.15);
curHeight = math.floor(curHeight * 1.15);
factorW = math.floor(factorW * 1.15);
factorH = math.floor(factorH * 1.15);
end
local worldsizes = {};
worldsizes = {
[GameInfo.Worlds.WORLDSIZE_DUEL.ID] = {curWidth + factorW, curHeight + factorH},
[GameInfo.Worlds.WORLDSIZE_TINY.ID] = {curWidth + 2 * factorW, curHeight + 2 * factorH},
[GameInfo.Worlds.WORLDSIZE_SMALL.ID] = {curWidth + 3 * factorW, curHeight + 3 * factorH},
[GameInfo.Worlds.WORLDSIZE_STANDARD.ID] = {curWidth + 4 * factorW, curHeight + 4 * factorH},
[GameInfo.Worlds.WORLDSIZE_LARGE.ID] = {curWidth + 5 * factorW, curHeight + 5 * factorH},
[GameInfo.Worlds.WORLDSIZE_HUGE.ID] = {curWidth + 6 * factorW, curHeight + 6 * factorH}
}
local grid_size = worldsizes[worldSize];
--
local world = GameInfo.Worlds[worldSize];
if (world ~= nil) then
return {
Width = grid_size[1],
Height = grid_size[2],
WrapX = true,
};
end
end
------------------------------------------------------------------------------
-- START OF CONTINENTS CREATION CODE
------------------------------------------------------------------------------
ContinentsFractalWorld = {};
------------------------------------------------------------------------------
function ContinentsFractalWorld.Create(fracXExp, fracYExp)
local gridWidth, gridHeight = Map.GetGridSize();
local data = {
InitFractal = FractalWorld.InitFractal,
ShiftPlotTypes = FractalWorld.ShiftPlotTypes,
ShiftPlotTypesBy = FractalWorld.ShiftPlotTypesBy,
DetermineXShift = FractalWorld.DetermineXShift,
DetermineYShift = FractalWorld.DetermineYShift,
GenerateCenterRift = FractalWorld.GenerateCenterRift,
GeneratePlotTypes = ContinentsFractalWorld.GeneratePlotTypes, -- Custom method
iFlags = Map.GetFractalFlags(),
fracXExp = fracXExp,
fracYExp = fracYExp,
iNumPlotsX = gridWidth,
iNumPlotsY = gridHeight,
plotTypes = table.fill(PlotTypes.PLOT_OCEAN, gridWidth * gridHeight)
};
return data;
end
------------------------------------------------------------------------------
function ContinentsFractalWorld:GeneratePlotTypes(args)
if(args == nil) then args = {}; end
local sea_level_low = 67;
local sea_level_normal = 72;
local sea_level_high = 76;
local world_age_old = 2;
local world_age_normal = 5;
local world_age_new = 15;
--
local extra_mountains = 25;
local grain_amount = 0;
local adjust_plates = 1.3;
local shift_plot_types = true;
local tectonic_islands = false;
local hills_ridge_flags = self.iFlags;
local peaks_ridge_flags = self.iFlags;
local has_center_rift = true;
local adjadj = 1.4;
local sea_level = Map.GetCustomOption(4)
if sea_level == 4 then
sea_level = 1 + Map.Rand(3, "Random Sea Level - Lua");
end
local world_age = Map.GetCustomOption(1)
if world_age == 5 then
world_age = 1 + Map.Rand(3, "Random World Age - Lua");
end
-- Set Sea Level according to user selection.
local water_percent = sea_level_normal;
if sea_level == 1 then -- Low Sea Level
water_percent = sea_level_low
elseif sea_level == 3 then -- High Sea Level
water_percent = sea_level_high
else -- Normal Sea Level
end
-- Set values for hills and mountains according to World Age chosen by user.
local adjustment = world_age_normal;
if world_age == 4 then -- No Moutains
adjustment = world_age_old;
adjust_plates = adjust_plates * 0.5;
elseif world_age == 3 then -- 5 Billion Years
adjustment = world_age_old;
adjust_plates = adjust_plates * 0.5;
elseif world_age == 1 then -- 3 Billion Years
adjustment = world_age_new;
adjust_plates = adjust_plates * 1;
else -- 4 Billion Years
end
-- Apply adjustment to hills and peaks settings.
local hillsBottom1 = 28 - (adjustment * adjadj);
local hillsTop1 = 28 + (adjustment * adjadj);
local hillsBottom2 = 72 - (adjustment * adjadj);
local hillsTop2 = 72 + (adjustment * adjadj);
local hillsClumps = 1 + (adjustment * adjadj);
local hillsNearMountains = 120 - (adjustment * 2) - extra_mountains;
local mountains = 100 - adjustment - extra_mountains;
if world_age == 4 then
mountains = 300 - adjustment - extra_mountains;
end
-- Hills and Mountains handled differently according to map size
local WorldSizeTypes = {};
for row in GameInfo.Worlds() do
WorldSizeTypes[row.Type] = row.ID;
end
local sizekey = Map.GetWorldSize();
-- Fractal Grains
local sizevalues = {
[WorldSizeTypes.WORLDSIZE_DUEL] = 3,
[WorldSizeTypes.WORLDSIZE_TINY] = 3,
[WorldSizeTypes.WORLDSIZE_SMALL] = 3,
[WorldSizeTypes.WORLDSIZE_STANDARD] = 3,
[WorldSizeTypes.WORLDSIZE_LARGE] = 3,
[WorldSizeTypes.WORLDSIZE_HUGE] = 3
};
local grain = sizevalues[sizekey] or 3;
-- Tectonics Plate Counts
local platevalues = {
[WorldSizeTypes.WORLDSIZE_DUEL] = 100,
[WorldSizeTypes.WORLDSIZE_TINY] = 100,
[WorldSizeTypes.WORLDSIZE_SMALL] = 100,
[WorldSizeTypes.WORLDSIZE_STANDARD] = 100,
[WorldSizeTypes.WORLDSIZE_LARGE] = 100,
[WorldSizeTypes.WORLDSIZE_HUGE] = 100
};
local numPlates = platevalues[sizekey] or 5;
-- Add in any plate count modifications passed in from the map script.
numPlates = numPlates * adjust_plates;
-- Generate continental fractal layer and examine the largest landmass. Reject
-- the result until the largest landmass occupies 45% to 55% of the total land.
local done = false;
local iAttempts = 0;
local iWaterThreshold, biggest_area, iNumTotalLandTiles, iNumBiggestAreaTiles, iBiggestID;
while done == false do
local plusminus = 0.3;
local grain_dice = Map.Rand(7, "Continental Grain roll - LUA Continents");
if grain_dice < 4 then
grain_dice = 1;
else
grain_dice = 2;
end
local rift_dice = Map.Rand(3, "Rift Grain roll - LUA Continents");
if rift_dice < 1 then
rift_dice = -1;
end
rift_dice = -1;
grain_dice = 1;
self.continentsFrac = nil;
self:InitFractal{continent_grain = grain_dice, rift_grain = rift_dice};
iWaterThreshold = self.continentsFrac:GetHeight(water_percent);
iNumTotalLandTiles = 0;
for x = 0, self.iNumPlotsX - 1 do
for y = 0, self.iNumPlotsY - 1 do
local i = y * self.iNumPlotsX + x;
local val = self.continentsFrac:GetHeight(x, y);
if(val <= iWaterThreshold) then
self.plotTypes[i] = PlotTypes.PLOT_OCEAN;
else
self.plotTypes[i] = PlotTypes.PLOT_LAND;
iNumTotalLandTiles = iNumTotalLandTiles + 1;
end
end
end
self:ShiftPlotTypes();
self:GenerateCenterRift()
SetPlotTypes(self.plotTypes);
Map.RecalculateAreas();
biggest_area = Map.FindBiggestArea(false);
iNumBiggestAreaTiles = biggest_area:GetNumTiles();
local oneContinent = Map.GetCustomOption(18);
-- Now test the biggest landmass to see if it is large enough.
if oneContinent == 1 then
print("One Continent challenge true");
if (iNumBiggestAreaTiles >= (iNumTotalLandTiles * 0.75)) then
done = true;
iBiggestID = biggest_area:GetID();
end
elseif (iNumBiggestAreaTiles <= (iNumTotalLandTiles * 0.53)) and (iNumBiggestAreaTiles >= (iNumTotalLandTiles * 0.47)) then
done = true;
print("One Continent challenge false");
iBiggestID = biggest_area:GetID();
end
iAttempts = iAttempts + 1;
-- Printout for debug use only
print("-"); print("--- Continents landmass generation, Attempt#", iAttempts, "---");
print("- This attempt successful: ", done);
print("- Total Land Plots in world:", iNumTotalLandTiles);
print("- Land Plots belonging to biggest landmass:", iNumBiggestAreaTiles);
print("- Percentage of land belonging to biggest: ", 100 * iNumBiggestAreaTiles / iNumTotalLandTiles);
print("- Continent Grain for this attempt: ", grain_dice);
print("- Rift Grain for this attempt: ", rift_dice);
print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
print(".");
end
-- Generate fractals to govern hills and mountains
self.hillsFrac = Fractal.Create(self.iNumPlotsX, self.iNumPlotsY, grain, self.iFlags, self.fracXExp, self.fracYExp);
self.mountainsFrac = Fractal.Create(self.iNumPlotsX, self.iNumPlotsY, grain, self.iFlags, self.fracXExp, self.fracYExp);
self.hillsFrac:BuildRidges(numPlates, hills_ridge_flags, 1, 2);
self.mountainsFrac:BuildRidges((numPlates * 2) / 3, peaks_ridge_flags, 6, 1);
-- Get height values
local iHillsBottom1 = self.hillsFrac:GetHeight(hillsBottom1);
local iHillsTop1 = self.hillsFrac:GetHeight(hillsTop1);
local iHillsBottom2 = self.hillsFrac:GetHeight(hillsBottom2);
local iHillsTop2 = self.hillsFrac:GetHeight(hillsTop2);
local iHillsClumps = self.mountainsFrac:GetHeight(hillsClumps);
local iHillsNearMountains = self.mountainsFrac:GetHeight(hillsNearMountains);
local iMountainThreshold = self.mountainsFrac:GetHeight(mountains);
local iPassThreshold = self.hillsFrac:GetHeight(hillsNearMountains);
-- Set Hills and Mountains
for x = 0, self.iNumPlotsX - 1 do
for y = 0, self.iNumPlotsY - 1 do
local plot = Map.GetPlot(x, y);
local i = y * self.iNumPlotsX + x;
local val = self.continentsFrac:GetHeight(x, y);
local mountainVal = self.mountainsFrac:GetHeight(x, y);
local hillVal = self.hillsFrac:GetHeight(x, y);
if plot:GetPlotType() ~= PlotTypes.PLOT_OCEAN then
if (mountainVal >= iMountainThreshold) then
if (hillVal >= iPassThreshold) then -- Mountain Pass though the ridgeline - Brian
self.plotTypes[i] = PlotTypes.PLOT_HILLS;
else -- Mountain
-- set some randomness to moutains next to each other
local iIsMount = Map.Rand(100, "Mountain Spwan Chance");
--print("-"); print("Mountain Spawn Chance: ", iIsMount);
local iIsMountAdj = 55 - adjustment;
if iIsMount >= iIsMountAdj then
self.plotTypes[i] = PlotTypes.PLOT_MOUNTAIN;
else
-- set some randomness to hills or flat land next to the mountain
local iIsHill = Map.Rand(100, "Hill Spwan Chance");
--print("-"); print("Mountain Spawn Chance: ", iIsMount);
local iIsHillAdj = 40 - adjustment;
if iIsHillAdj >= iIsHill then
self.plotTypes[i] = PlotTypes.PLOT_HILLS;
else
self.plotTypes[i] = PlotTypes.PLOT_LAND;
end
end
end
elseif (mountainVal >= iHillsNearMountains) then
self.plotTypes[i] = PlotTypes.PLOT_HILLS; -- Foot hills - Bob
else
if ((hillVal >= iHillsBottom1 and hillVal <= iHillsTop1) or (hillVal >= iHillsBottom2 and hillVal <= iHillsTop2)) then
self.plotTypes[i] = PlotTypes.PLOT_HILLS;
else
self.plotTypes[i] = PlotTypes.PLOT_LAND;
end
end
end
end
end
self:ShiftPlotTypes();
-- Create islands. Try to make more useful islands than the default code.
-- pick a random tile and check if it is ocean, if it is check tiles around it
-- to see how big an island we can make, then make an island from size 1 up to the biggest we can make
-- Hex Adjustment tables. These tables direct plot by plot scans in a radius
-- around a center hex, starting to Northeast, moving clockwise.
local islandQty = {
[WorldSizeTypes.WORLDSIZE_DUEL] = 5,
[WorldSizeTypes.WORLDSIZE_TINY] = 16,
[WorldSizeTypes.WORLDSIZE_SMALL] = 24,
[WorldSizeTypes.WORLDSIZE_STANDARD] = 32,
[WorldSizeTypes.WORLDSIZE_LARGE] = 52,
[WorldSizeTypes.WORLDSIZE_HUGE] = 77
}
local firstRingYIsEven = {{0, 1}, {1, 0}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
local secondRingYIsEven = {
{1, 2}, {1, 1}, {2, 0}, {1, -1}, {1, -2}, {0, -2},
{-1, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-1, 2}, {0, 2}
};
local thirdRingYIsEven = {
{1, 3}, {2, 2}, {2, 1}, {3, 0}, {2, -1}, {2, -2},
{1, -3}, {0, -3}, {-1, -3}, {-2, -3}, {-2, -2}, {-3, -1},
{-3, 0}, {-3, 1}, {-2, 2}, {-2, 3}, {-1, 3}, {0, 3}
};
local firstRingYIsOdd = {{1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, 0}, {0, 1}};
local secondRingYIsOdd = {
{1, 2}, {2, 1}, {2, 0}, {2, -1}, {1, -2}, {0, -2},
{-1, -2}, {-1, -1}, {-2, 0}, {-1, 1}, {-1, 2}, {0, 2}
};
local thirdRingYIsOdd = {
{2, 3}, {2, 2}, {3, 1}, {3, 0}, {3, -1}, {2, -2},
{2, -3}, {1, -3}, {0, -3}, {-1, -3}, {-2, -2}, {-2, -1},
{-3, 0}, {-2, 1}, {-2, 2}, {-1, 3}, {0, 3}, {1, 3}
};
-- Direction types table, another method of handling hex adjustments, in combination with Map.PlotDirection()
local direction_types = {
DirectionTypes.DIRECTION_NORTHEAST,
DirectionTypes.DIRECTION_EAST,
DirectionTypes.DIRECTION_SOUTHEAST,
DirectionTypes.DIRECTION_SOUTHWEST,
DirectionTypes.DIRECTION_WEST,
DirectionTypes.DIRECTION_NORTHWEST
};
plotTypesTwo = self.plotTypes;
local iW, iH = Map.GetGridSize();
local islMax = islandQty[sizekey] or 24;
local mapSize = iW * iH;
local islCount = 0;
local islLandInRing = 0;
local goodX = 0;
local goodY = 0;
local wrapX = Map:IsWrapX();
local wrapY = false; --Map:IsWrapY();
local nextX, nextY, plot_adjustments;
local odd = firstRingYIsOdd;
local even = firstRingYIsEven;
local failedattemps = 0;
local bIslandsFailure = false;
local minIslandSize = 1;
local maxIslandSize = 5;
local escapeRedo = 500;
local redoMap = false;
print("######### Creating Islands #########");
islandSetting = Map.GetCustomOption(14);
islCount = 20;
if islandSetting == 1 then --sparse
islCount = 12;
elseif islandSetting == 3 then -- plentiful
islCount = 30;
elseif islandSetting == 4 then -- abundant
islCount = 40;
end
while islCount > 0 and escapeRedo > 0 do
local islLandInRing = 0;
local startingPlot = 0;
local landX = 0;
local landY = 0;
local landPlot = 0;
--pick random location
local x = Map.Rand(iW, "");
local y = 3 + Map.Rand((iH-6), "");
local plotIndex = y * iW + x + 1;
local radius = 3 + 3 + math.floor(Map.Rand(2, ""));
--print("----------------------------------------------------------------------------------------");
--print("Count: ", islCount);
--print ("Radius: ", radius);
--print("X=", x);
--print("Y=", y);
--print("--------");
--print("Random Plot Is: ", plotIndex);
--check if random location is ocean
if self.plotTypes[plotIndex] == PlotTypes.PLOT_OCEAN then
startingPlot = plotIndex;
--print("Location is Ocean");
--local radius = 5;
for ripple_radius = 1, radius do
local ripple_value = radius - ripple_radius + 1;
local currentX = x - ripple_radius;
local currentY = y;
for direction_index = 1, 6 do
for plot_to_handle = 1, ripple_radius do
if currentY / 2 > math.floor(currentY / 2) then
plot_adjustments = odd[direction_index];
else
plot_adjustments = even[direction_index];
end
nextX = currentX + plot_adjustments[1];
nextY = currentY + plot_adjustments[2];
if wrapX == false and (nextX < 0 or nextX >= iW) then
-- X is out of bounds.
elseif wrapY == false and (nextY < 0 or nextY >= iH) then
-- Y is out of bounds.
else
local realX = nextX;
local realY = nextY;
if wrapX then
realX = realX % iW;
end
if wrapY then
realY = realY % iH;
end
-- We've arrived at the correct x and y for the current plot.
--local plot = Map.GetPlot(realX, realY);
local plotIndex = realY * iW + realX + 1;
--print("--------");
--print("Plot Is: ", plotIndex);
-- Check this plot for land.
if self.plotTypes[plotIndex] == PlotTypes.PLOT_LAND then
islLandInRing = ripple_radius;
landPlot = plotIndex;
landX = realX;
landY = realY;
--print("PlotID: " .. tostring(plotIndex));
--print("RealX: " .. tostring(realX));
--print("RealY: " .. tostring(realY));
break;
end
currentX, currentY = nextX, nextY;
end
end
if islLandInRing ~= 0 then
break;
end
end
if islLandInRing ~= 0 then
break;
end
end
if islLandInRing ~= 0 then
--print("We hit land, check if it is the Mainland");
local biggest_area = Map.FindBiggestArea(false);
local biggest_ID = biggest_area:GetID();
local plotCheck = Map.GetPlot(landX, landY);
local plotArea = plotCheck:Area();
local iAreaID = plotArea:GetID();
local pullBack = 3;
-- pull back the radius by 2 to 3 tiles and as long as island will be a radius of 2 then plunk it in da water init bruv!
if plotTypesTwo[landPlot] == PlotTypes.PLOT_LAND then
-- create us an island
islLandInRing = islLandInRing - pullBack;
--self.plotTypes[startingPlot] = PlotTypes.PLOT_LAND
if islLandInRing > minIslandSize and islLandInRing < maxIslandSize then
local islThresh = 0;
local landvarDefault = 20;
local locationRnd = Map.Rand(100, "");
if (locationRnd > 49) then
self.plotTypes[startingPlot] = PlotTypes.PLOT_LAND;
else
self.plotTypes[startingPlot] = PlotTypes.PLOT_HILLS;
end
for ripple_radius = 1, islLandInRing do
local ripple_value = islLandInRing - ripple_radius + 1;
local currentX = x - ripple_radius;
local currentY = y;
for direction_index = 1, 6 do
for plot_to_handle = 1, ripple_radius do
if currentY / 2 > math.floor(currentY / 2) then
plot_adjustments = odd[direction_index];
else
plot_adjustments = even[direction_index];
end
nextX = currentX + plot_adjustments[1];
nextY = currentY + plot_adjustments[2];
if wrapX == false and (nextX < 0 or nextX >= iW) then
-- X is out of bounds.
elseif wrapY == false and (nextY < 0 or nextY >= iH) then
-- Y is out of bounds.
else
local realX = nextX;
local realY = nextY;
if wrapX then
realX = realX % iW;
end
if wrapY then
realY = realY % iH;
end
-- We've arrived at the correct x and y for the current plot.
--local plot = Map.GetPlot(realX, realY);
local plotIndex = realY * iW + realX + 1;
local thisislandvar = Map.Rand(60, "") + landvarDefault;
-- closer we get to outer edge increase chance of ocean.
if ripple_radius == 1 then --100%
islThresh = Map.Rand(50, "") + thisislandvar;
elseif ripple_radius == 2 then -- 57% to 74%
islThresh = Map.Rand(45, "") + (thisislandvar / 1.25);
elseif ripple_radius == 3 then --40% to 57%
islThresh = Map.Rand(37, "") + (thisislandvar / 1.25);
else --30% to 50%
islThresh = Map.Rand(30, "") + (thisislandvar / 1.5);
end
local islRand = Map.Rand(100, "");
local islHill = Map.Rand(100, "");
--print("Rand: ", islRand, "Thresh: ", islThresh);
if islRand > islThresh then
self.plotTypes[plotIndex] = PlotTypes.PLOT_OCEAN
landvarDefault = landvarDefault + 5;
else
if islHill <= 40 then
self.plotTypes[plotIndex] = PlotTypes.PLOT_LAND
else
self.plotTypes[plotIndex] = PlotTypes.PLOT_HILLS
end
end
currentX, currentY = nextX, nextY;
end
end
end
end
islCount = islCount -1;
end
end
end
end
escapeRedo = escapeRedo - 1;
end
-- make sure islands were created
if escapeRedo == 0 then
--oh boy something went wrong, regen a new map
redoMap = true
end
print("######### Finished Islands #########");
local iW, iH = Map.GetGridSize();
local centerX = iW / 2;
local centerY = iH / 2;
local fracFlags = {FRAC_POLAR = true};
local baysFrac = Fractal.Create(iW, iH, 3, fracFlags, -1, -1);
local iBaysThreshold = baysFrac:GetHeight(96); --lakes lavel size
local axis_list = {0.87, 0.81, 0.75};
local axis_multiplier = axis_list[sea_level];
local cohesion_list = {0.36, 0.33, 0.30};
local cohesion_multiplier = cohesion_list[sea_level];
majorAxis = centerX * cohesion_multiplier;
minorAxis = centerY * cohesion_multiplier;
majorAxisSquared = majorAxis * majorAxis;
minorAxisSquared = minorAxis * minorAxis;
for y = 0, iH - 1 do
for x = 0, iW - 1 do
local deltaX = x - centerX;
local deltaY = y - centerY;
local deltaXSquared = deltaX * deltaX;
local deltaYSquared = deltaY * deltaY;
local d = deltaXSquared/majorAxisSquared + deltaYSquared/minorAxisSquared;
if d > 1 then
local i = y * iW + x + 1;
local baysVal = baysFrac:GetHeight(x, y);
if baysVal >= iBaysThreshold then
self.plotTypes[i] = PlotTypes.PLOT_OCEAN;
end
end
end
end
return self.plotTypes;
end
------------------------------------------------------------------------------
------------------------------------------------------------------------------
function GeneratePlotTypes()
-- Plot generation customized to ensure enough land belongs to the Pangaea.
print("Generating Plot Types (Lua Continents) ...");
local fractal_world = ContinentsFractalWorld.Create();
local plotTypes = fractal_world:GeneratePlotTypes();
SetPlotTypes(plotTypes);
GenerateCoasts();
end
------------------------------------------------------------------------------
function GenerateTerrain()
-- Get Temperature setting input by user.
local temp = Map.GetCustomOption(2)
if temp == 4 then
temp = 1 + Map.Rand(3, "Random Temperature - Lua");
end
local args = {
temperature = temp,
iDesertPercent = 2 + 10 * Map.GetCustomOption(20),-- desertSize 12/22/32
rainfall = Map.GetCustomOption(3),
iGrassMoist = Map.GetCustomOption(8),
tundra = Map.GetCustomOption(10),
};
local terraingen = TerrainGenerator.Create(args);
terrainTypes = terraingen:GenerateTerrain();
SetTerrainTypes(terrainTypes);
FixIslands();