-
Notifications
You must be signed in to change notification settings - Fork 0
/
LekmapPangaeaFractalv3.6.lua
1573 lines (1346 loc) · 43 KB
/
LekmapPangaeaFractalv3.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 start quality
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 = 7,
SortPriority = -95,
},
{
Name = "Start Distance", -- 6 start distance
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 tundraSize (10)
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -90,
},
{
Name = "Forest Size", -- (11) forestSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -89,
},
{
Name = "Jungle Size", -- (12) jungleSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -87,
},
{
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 = -86,
},
{
Name = "Islands", -- add setting for islands (14)
Values = {
"No Islands",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12 - Default",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
},
DefaultValue = 13,
SortPriority = -85,
},
{
Name = "Coastal Spawns", -- Can inland civ spawn on the coast (15)
Values = {
"Coastal Civs Only",
"Random",
"Random+ (~2 coastals)",
},
DefaultValue = 1,
SortPriority = -84,
},
{
Name = "Coastal Luxes", -- Can coast spawns have non-coastal luxes (16)
Values = {
"Guaranteed",
"Random",
},
DefaultValue = 1,
SortPriority = -83,
},
{
Name = "Inland Sea Spawns", -- Can coastal civ spawn on inland seas (17)
Values = {
"Allowed",
"Not Allowed for Coastal Civs",
},
DefaultValue = 1,
SortPriority = -82,
},
{
Name = "Desert Size", -- (18) desertSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -81,
},
{
Name = "Marsh Size", -- (19) marshSize
Values = {
"sparse",
"average",
"plentiful",
},
DefaultValue = 2,
SortPriority = -80,
},
{
Name = "Map Dimensions", -- (20) 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 = "Lekmap: Pangaea - Fractal (v3.6)",
Description = "A map script made for Lekmod based of HB's Mapscript v8.1. Pangaea - Fractal",
IsAdvancedMap = false,
IconIndex = 0,
SortIndex = 2,
SupportsMultiplayer = true,
CustomOptions = opt
};
end
------------------------------------------------------------------------------
function GetMapInitData(worldSize)
local mapSize = Map.GetCustomOption(20)
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 FRACTAL PANGAEA CREATION CODE
------------------------------------------------------------------------------
PangaeaFractalWorld = {};
------------------------------------------------------------------------------
function PangaeaFractalWorld.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 = PangaeaFractalWorld.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 PangaeaFractalWorld:GeneratePlotTypes(args)
if(args == nil) then args = {}; end
local allcomplete = false;
while allcomplete == false do
local sea_level_low = 63;
local sea_level_normal = 67;
local sea_level_high = 73;
local world_age_old = 2;
local world_age_normal = 4;
local world_age_new = 8;
--
local extra_mountains = 6;
local grain_amount = 0;
local adjust_plates = 1.3;
local shift_plot_types = true;
local tectonic_islands = true;
local hills_ridge_flags = self.iFlags;
local peaks_ridge_flags = self.iFlags;
local has_center_rift = true;
local adjadj = 1.4;
local xshift = 0;
local yshift = 0;
local yshiftamt = 0;
local xshiftamt = 0;
local xstart, xend = 0,0;
local ystart, yend = 0,0;
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 = 94 - (adjustment * 2) - extra_mountains;
local mountains = 96 - adjustment - extra_mountains;
if world_age == 4 then
mountains = 300 - adjustment - extra_mountains;
end
-- Hills and Mountains handled differently according to map size - Bob
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. - Bob
numPlates = numPlates * adjust_plates;
-- Generate continental fractal layer and examine the largest landmass. Reject
-- the result until the largest landmass occupies 90% or more of the total land.
local bMapOK = false;
while bMapOK == false do
local done = false;
local iAttempts = 0;
local iWaterThreshold, biggest_area, iNumTotalLandTiles, iNumBiggestAreaTiles, iBiggestID;
while done == false do
local grain_dice = Map.Rand(7, "Continental Grain roll - LUA Pangaea");
if grain_dice < 4 then
grain_dice = 1;
else
grain_dice = 2;
end
local rift_dice = Map.Rand(3, "Rift Grain roll - LUA Pangaea");
if rift_dice < 1 then
rift_dice = -1;
end
rift_dice = -1;
grain_dice = 7;
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
SetPlotTypes(self.plotTypes);
Map.RecalculateAreas();
biggest_area = Map.FindBiggestArea(false);
iNumBiggestAreaTiles = biggest_area:GetNumTiles();
-- Now test the biggest landmass to see if it is large enough.
if iNumBiggestAreaTiles >= iNumTotalLandTiles * 1 then
done = true;
iBiggestID = biggest_area:GetID();
end
iAttempts = iAttempts + 1;
print("-"); print("--- Pangaea 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 Pangaea: ", 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);
-- Get height values for tectonic islands
local iMountain100 = self.mountainsFrac:GetHeight(100);
local iMountain99 = self.mountainsFrac:GetHeight(99);
local iMountain97 = self.mountainsFrac:GetHeight(97);
local iMountain95 = self.mountainsFrac:GetHeight(95);
-- Because we haven't yet shifted the plot types, we will not be able to take advantage
-- of having water and flatland plots already set. We still have to generate all data
-- for hills and mountains, too, then shift everything, then set plots one more time.
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);
local mountainVal = self.mountainsFrac:GetHeight(x, y);
local hillVal = self.hillsFrac:GetHeight(x, y);
if(val <= iWaterThreshold) then
self.plotTypes[i] = PlotTypes.PLOT_OCEAN;
if tectonic_islands then -- Build islands in oceans along tectonic ridge lines - Brian
if (mountainVal == iMountain100) then -- Isolated peak in the ocean
self.plotTypes[i] = PlotTypes.PLOT_MOUNTAIN;
elseif (mountainVal == iMountain99) then
self.plotTypes[i] = PlotTypes.PLOT_HILLS;
elseif (mountainVal == iMountain97) or (mountainVal == iMountain95) then
self.plotTypes[i] = PlotTypes.PLOT_LAND;
end
end
else
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();
--#####################
--check landmass
local iW, iH = Map.GetGridSize();
local bfland = false;
local startcol = 0;
local cont = 0;
local bprev = false;
local biggest = 0;
local mainstart = 0;
local mainend = 0;
local cencol = 0;
local colshift = 0;
local landincol = 0;
local chkstart = 0;
local chkend = 0;
local chokepoint = 16;
local bXChkFail = false;
local bYChkFail = false;
local bLastLand = false;
local contlandincol = 0;
local xcen = 0;
local ycen = 0;
--check y choke points
print("-----------------------------------");
print("Checking Y Chokes");
print("-----------------------------------");
for x = 1, iW do
bfland = false;
landincol = 0;
for y = 2, iH-2 do
local i = iW * y + x;
--print("Plot Location = ", i);
if self.plotTypes[i] ~= PlotTypes.PLOT_OCEAN then
landincol = landincol + 1;
bfland = true;
end
end
if bfland == false then
--print("No Land Found in Col: ", x);
bprev = false;
if cont > biggest then
biggest = cont;
mainstart = startcol;
mainend = x-1;
end
cont = 0;
startcol = 0;
else
--print("Land Found In Col: ", x, "Qty: ", landincol);
if startcol == 0 then
startcol = x;
end
bprev = true;
cont = cont + 1;
end
end
xstart = mainstart;
xend = mainend;
chkstart = mainstart + 8;
chkend = mainend - 8;
local landincol_prev1 = chokepoint;
local landincol_prev2 = chokepoint;
for x = chkstart, chkend do
landincol = 0;
contlandincol = 0;
for y = 2, iH-2 do
local i = iW * y + x;
--print("Plot Location = ", i);
if self.plotTypes[i] ~= PlotTypes.PLOT_OCEAN then
if bLastLand == true then
landincol = landincol + 1;
bLastLand = true;
else
landincol = 1;
bLastLand = true;
end
else
if contlandincol < landincol then
contlandincol = landincol;
end
bLastLand = false;
landincol = 0;
end
end
--print("Checking Col:", x, "Continuous Land In Col: ", contlandincol);
if landincol_prev1 + landincol_prev2 + contlandincol < 3 * chokepoint then
--print("Choke Point in Col: ", x);
bXChkFail = true;
end
landincol_prev2 = contlandincol;
landincol_prev1 = landincol_prev2;
end
--check x choke points
print("-----------------------------------");
print("Checking X Chokes");
print("-----------------------------------");
startcol = 0;
cont = 0;
biggest = 0;
for y = 2, iH-2 do
bfland = false;
landincol = 0;
for x = 1, iW do
local i = iW * y + x;
--print("Plot Location = ", i);
if self.plotTypes[i] ~= PlotTypes.PLOT_OCEAN then
landincol = landincol + 1;
bfland = true;
end
end
if bfland == false then
--print("No Land Found in Row: ", y);
bprev = false;
if cont > biggest then
biggest = cont;
mainstart = startcol;
mainend = y-1;
end
cont = 0;
startcol = 0;
else
--print("Land Found In Row: ", y, "Qty: ", landincol);
if startcol == 0 then
startcol = y;
end
bprev = true;
cont = cont + 1;
end
end
ystart = mainstart;
yend = mainend;
chkstart = mainstart + 5;
chkend = mainend - 5;
--print("-----");
--print("Mainland Start Row: ", chkstart);
--print("Mainland End Row: ", chkend);
--print("-----");
for y = chkstart, chkend do
landincol = 0;
contlandincol = 0;
for x = 1, iW do
local i = iW * y + x;
--print("Plot Location = ", i);
if self.plotTypes[i] ~= PlotTypes.PLOT_OCEAN then
if bLastLand == true then
landincol = landincol + 1;
bLastLand = true;
else
landincol = 1;
bLastLand = true;
end
else
if contlandincol < landincol then
contlandincol = landincol;
end
bLastLand = false;
landincol = 0;
end
end
--print("Checking Col:", y, "Continuous Land In Col: ", contlandincol);
if contlandincol < chokepoint then
--print("Choke Point in Row: ", y);
bYChkFail = true;
end
end
if bXChkFail == true then
print("X Check: False");
else
print("X Check: True");
end
if bYChkFail == true then
print("Y Check: False");
else
print("Y Check: True");
end
if (bXChkFail == true or bYChkFail == true) then
print("##############################################");
print("Map No Good");
print("##############################################");
bMapOK = false;
else
print("##############################################");
print("Map Passes");
print("##############################################");
bMapOK = true;
cencol = xstart + ((xend - xstart) / 2);
colshift = (iW/2)-cencol;
print("Pangaea X Starts At Col: ", xstart, " And Edns At Col: ", xend);
print("Center X of Lanmass is at Col: ", cencol, "Shift Need: ", colshift);
xshiftamt = math.ceil(colshift);
print("Actual Integer Shift Applied: ", xshiftamt);
if xshiftamt > 0 then
xshift = 1;
elseif xshiftamt < 0 then
xshift = 2;
else
xshift = 0;
end
print("##############################################");
cencol = ystart + ((yend - ystart) / 2);
colshift = (iH/2)-cencol;
print("Pangaea Y Starts At Col: ", ystart, " And Edns At Col: ", yend);
print("Center Y of Lanmass is at Col: ", cencol, "Shift Need: ", colshift);
yshiftamt = math.ceil(colshift);
print("Actual Integer Shift Applied: ", yshiftamt);
print("##############################################");
if yshiftamt > 0 then
yshift = 1;
elseif yshiftamt < 0 then
yshift = 2;
else
yshift = 0;
end
end
end
--####################################################
--clear area around pangaea
local iW, iH = Map.GetGridSize();
for x = 0, xstart - 1 do --clear west side of map
for y = 0, iH do
destPlotIndex = iW * y + x;
self.plotTypes[destPlotIndex] = PlotTypes.PLOT_OCEAN;
end
end
for x = xend + 1, iW do --clear east side of map
for y = 0, iH do
destPlotIndex = iW * y + x;
self.plotTypes[destPlotIndex] = PlotTypes.PLOT_OCEAN;
end
end
for y = 0, ystart - 1 do --clear south side of map
for x = 0, iW do
destPlotIndex = iW * y + x;
self.plotTypes[destPlotIndex] = PlotTypes.PLOT_OCEAN;
end
end
for y = yend + 1, iH do --clear north side of map
for x = 0, iW do
destPlotIndex = iW * y + x;
self.plotTypes[destPlotIndex] = PlotTypes.PLOT_OCEAN;
end
end
--map generated now shift to center
-- x shift first
if xshift == 1 then --shift east
print("-----------------------------------");
print("Shifting East........");
print("-----------------------------------");
for x = iW, 0, -1 do
for y = iH, 0, -1 do
local destPlotIndex = iW * y + x;
local sourcePlotIndex = destPlotIndex - math.abs(xshiftamt);
--print("Moving Plot: ", sourcePlotIndex, "To Location: ",destPlotIndex );
self.plotTypes[destPlotIndex] = self.plotTypes[sourcePlotIndex]
end
end
elseif xshift == 2 then --shift west
print("-----------------------------------");
print("Shifting West........");
print("-----------------------------------");
for x = 0, iW do
for y = 0, iH do
local destPlotIndex = iW * y + x;
local sourcePlotIndex = destPlotIndex + math.abs(xshiftamt);
--print("Moving Plot: ", sourcePlotIndex, "To Location: ",destPlotIndex );
self.plotTypes[destPlotIndex] = self.plotTypes[sourcePlotIndex]
end
end
else
--no shift
end
-- now shift y
if yshift == 1 then --shift north
print("-----------------------------------");
print("Shifting North........");
print("-----------------------------------");
for y = iH, 0, -1 do
for x = iW, 0, -1 do
local destPlotIndex = iW * y + x;
local sourcePlotIndex = destPlotIndex - iW * (math.abs(yshiftamt));
--print("Moving Plot: ", sourcePlotIndex, "To Location: ",destPlotIndex );
self.plotTypes[destPlotIndex] = self.plotTypes[sourcePlotIndex]
end
end
local i = math.abs(yshiftamt);
for y = 0, i do
for x = 0, iW do
destPlotIndex = iW * y + x;
self.plotTypes[destPlotIndex] = PlotTypes.PLOT_OCEAN;
end
end
elseif yshift == 2 then --shift south
print("-----------------------------------");
print("Shifting South........");
print("-----------------------------------");
for y = 0, iH do
for x = 0, iW do
local destPlotIndex = iW * y + x;
local sourcePlotIndex = destPlotIndex + iW * (math.abs(yshiftamt));
--print("Moving Plot: ", sourcePlotIndex, "To Location: ",destPlotIndex );