-
Notifications
You must be signed in to change notification settings - Fork 1
/
IGE_API_Terrain.lua
791 lines (674 loc) · 25.2 KB
/
IGE_API_Terrain.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
-- Released under GPL v3
--------------------------------------------------------------
--===============================================================================================
-- CITY PLOTS HANDLING
--===============================================================================================
local function GetClosestCity(player, plot)
local newCity = nil;
local newCityDist = 100000000;
for city in player:Cities() do
local dist = Map.PlotDistance(city:GetX(), city:GetY(), plot:GetX(), plot:GetY());
if dist < newCityDist then
newCity = city;
newCityDist = dist
end
end
return newCity;
end
-------------------------------------------------------------------------------------------------
local function GetForcedPlots(city)
local forcedPlots = {};
-- Save which plots were forcefully worked
for i = 0, city:GetNumCityPlots() - 1, 1 do
local plot = city:GetCityIndexPlot( i );
local isForcedWorking = city:IsForcedWorkingPlot(plot);
if isForcedWorking then
table.insert(forcedPlots, plot);
end
end
return forcedPlots;
end
-------------------------------------------------------------------------------------------------
local function SetForcedPlots(city, forcedPlots)
for _, v in ipairs(forcedPlots) do
local index = city:GetCityPlotIndex(v);
if index > 0 then
if city:IsWorkingPlot(v) then
city:AlterWorkingPlot(index);
end
city:AlterWorkingPlot(index);
end
end
end
-------------------------------------------------------------------------------------------------
local function UpdateOwnershipForCityPlot(player, city, plot)
local forcedPlots = GetForcedPlots(city);
-- Stop working that plot
if city:IsWorkingPlot(plot) then
city:AlterWorkingPlot(city:GetCityPlotIndex(plot));
end
-- Update ownership
plot:SetOwner(-1);
plot:SetOwner(player:GetID(), city:GetID(), true, true);
city:DoTask(TaskTypes.TASK_CHANGE_WORKING_PLOT, 0, -1);
--city:DoReallocateCitizens();
SetForcedPlots(city, forcedPlots);
end
-------------------------------------------------------------------------------------------------
local function RemoveOwnershipForCityPlot(city, plot)
local forcedPlots = GetForcedPlots(city);
-- Stop working that plot
if city:IsWorkingPlot(plot) then
city:AlterWorkingPlot(city:GetCityPlotIndex(plot));
end
-- Update ownership
plot:SetOwner(-1);
city:DoTask(TaskTypes.TASK_CHANGE_WORKING_PLOT, 0, -1);
--city:DoReallocateCitizens();
SetForcedPlots(city, forcedPlots);
end
-------------------------------------------------------------------------------------------------
local function UpdateOwnership(plot)
local owner = Players[plot:GetOwner()];
if owner ~= nil then
local city = plot:GetWorkingCity();
if city and city:Plot() ~= plot then
UpdateOwnershipForCityPlot(owner, city, plot);
else
plot:SetOwner(-1);
plot:SetOwner(owner:GetID());
end
end
end
-------------------------------------------------------------------------------------------------
local function RemoveOwnership(plot)
local owner = Players[plot:GetOwner()];
if owner ~= nil then
local city = plot:GetWorkingCity();
if city then
RemoveOwnershipForCityPlot(city, plot);
else
plot:SetOwner(-1);
end
end
end
-------------------------------------------------------------------------------------------------
local function AddOwnership(player, plot)
if player ~= nil then
local city = GetClosestCity(player, plot);
local cityID = city and city:GetID() or -1;
plot:SetOwner(player:GetID(), cityID, true, true);
-- Reveal
local playerTeamID = player:GetTeam();
local hexpos = ToHexFromGrid(Vector2(plot:GetX(), plot:GetY()));
Events.HexFOWStateChanged(hexpos, true, false);
for neighbor in Neighbors(plot) do
plot:SetRevealed(playerTeamID, true);
plot:UpdateFog();
hexpos = ToHexFromGrid(Vector2(plot:GetX(), plot:GetY()));
Events.HexFOWStateChanged(hexpos, true, false);
end
end
end
--===============================================================================================
-- INVALIDATIONS AND COMMITS
--===============================================================================================
local invalidatedPlotsResources = {};
local invalidatedPlots = {};
local plotsToFog = {};
-------------------------------------------------------------------------------------------------
function InvalidateTerrain(plot, resourceChanged)
if resourceChanged then
table.insert(invalidatedPlotsResources, plot);
end
table.insert(invalidatedPlots, plot);
end
-------------------------------------------------------------------------------------------------
function CommitFogChanges()
if #plotsToFog == 0 then return end
print("commit fog changes")
local pPlayer = Players[IGE.currentPlayerID];
local playerTeamID = pPlayer:GetTeam();
local width = Map.GetGridSize();
local data = {};
-- Init data with the current state
for i = 0, Map.GetNumPlots()-1, 1 do
local otherPlot = Map.GetPlotByIndex(i);
data[i] = otherPlot:IsRevealed(playerTeamID, false);
end
-- Modify data
for _, v in ipairs(plotsToFog) do
local index = v:GetY() * width + v:GetX();
data[index] = false;
end
-- Apply data
FOW_SetAll(1);
for i = 0, Map.GetNumPlots()-1, 1 do
local plot = Map.GetPlotByIndex(i);
plot:SetRevealed(playerTeamID, data[i]);
plot:UpdateFog();
end
Game.UpdateFOW(true);
UI:RequestMinimapBroadcast();
plotsToFog = {};
end
-------------------------------------------------------------------------------------------------
function CommitTerrainChanges()
if #invalidatedPlots == 0 then return end
for i, pPlot in ipairs(invalidatedPlotsResources) do
local playerID = pPlot:GetOwner();
if playerID >= 0 then
UpdateOwnership(pPlot);
end
end
for i, pPlot in ipairs(invalidatedPlots) do
if pPlot:IsRevealed(IGE.currentTeamID, false) then
pPlot:UpdateFog();
end
LuaEvents.IGE_ModifiedPlot(pPlot);
for neighbor in Neighbors(pPlot) do
LuaEvents.IGE_ModifiedPlot(neighbor);
end
end
Map.RecalculateAreas();
invalidatedPlots = {};
invalidatedPlotsResources = {};
if IGE.revealMap then
FOW_SetAll(0);
Game.UpdateFOW(true);
UI:RequestMinimapBroadcast();
end
end
--===============================================================================================
-- COMPATIBILITY CHECKS
--===============================================================================================
local function MatchValidTerrainsAndFeatures(item, terrainID, featureID)
-- Scroll through valid features compatible with the current terrain
for _, feature in pairs(item.validFeatures) do
if feature.validTerrains[terrainID] then
if feature.ID == featureID then
return true;
end
end
end
-- Scroll through terrains
return item.validTerrains[terrainID];
end
-------------------------------------------------------------------------------------------------
function CanBeOcean(plot)
-- Lands cannot become oceans
if plot:GetPlotType() ~= PlotTypes.PLOT_OCEAN then
return false;
end
-- False if any neighbor is coastal land
for neighbor in Neighbors(plot) do
if neighbor:IsCoastalLand() then return false end
end
return true
end
-------------------------------------------------------------------------------------------------
function CanBeOwner(player)
if player.ID == -1 then return true end
local row = Players[player.ID];
if not row then return false end
return row:IsAlive();
end
-------------------------------------------------------------------------------------------------
function CanHaveTerrain(plot, terrain)
-- Oceans only for coastal lands.
if terrain.ID == TerrainTypes.TERRAIN_OCEAN then
return CanBeOcean(plot);
else
return true;
end
end
-------------------------------------------------------------------------------------------------
function CanHaveNaturalWonder(plot, wonder)
-- Gibraltar
if IGE_HasMoreWondersVP then
if wonder.type == "FEATURE_GIBRALTAR" or
wonder.type == "FEATURE_CAUSEWAY_B" then
return plot:IsCoastalLand();
end
else
if wonder.type == "FEATURE_GIBRALTAR" then
return plot:IsCoastalLand();
end
end
if IGE_HasMoreWondersVP then
if wonder.type == "FEATURE_VOLCANO" or
wonder.type == "FEATURE_REEF" or
wonder.type == "FEATURE_NEW_REEF_A" or
wonder.type == "FEATURE_NEW_REEF_B" or
wonder.type == "FEATURE_NEW_REEF_C" or
wonder.type == "FEATURE_CAUSEWAY_A" or
wonder.type == "FEATURE_BERMUDA_A" or
wonder.type == "FEATURE_BERMUDA_B" or
wonder.type == "FEATURE_BERMUDA_C" or
wonder.type == "FEATURE_LUMI_BAY" then
return plot:IsWater() and not plot:IsLake();
end
else
if wonder.type == "FEATURE_VOLCANO" or
wonder.type == "FEATURE_REEF" then
return plot:IsWater() and not plot:IsLake();
end
end
-- Others on firm lands
return not plot:IsWater();
end
-------------------------------------------------------------------------------------------------
function CanHaveFeature(plot, feature)
if feature.ID < 0 then return true end
if feature.ID == FeatureTypes.FEATURE_FALLOUT then return true end
local terrainID = plot:GetTerrainType();
return feature.validTerrains[terrainID];
end
-------------------------------------------------------------------------------------------------
function CanHaveResource(plot, resource)
if resource.ID < 0 then return true end
local type = plot:GetPlotType();
if type == PlotTypes.PLOT_HILLS and not resource.hills then
return false;
end
if type == PlotTypes.PLOT_LAND and not resource.flatLands then
return false;
end
local terrainID = plot:GetTerrainType();
local featureID = plot:GetFeatureType();
if not MatchValidTerrainsAndFeatures(resource, terrainID, featureID) then return false end
return true;
end
-------------------------------------------------------------------------------------------------
function CanHaveImprovement(plot, improvement)
if improvement.ID < 0 then return true end
if improvement.hillsMakesValid then
if plot:GetPlotType() == PlotTypes.PLOT_HILLS then return true end -- Sheeps
end
if improvement.freshWaterMakesValid then
if plot:IsFreshWater() then return true end -- Farms
end
if improvement.requiresFlatlandsOrFreshWater then
if not plot:IsFreshWater() then return false end
if not plot:GetPlotType() == PlotTypes.PLOT_LAND then return false end
end
local terrainID = plot:GetTerrainType();
local featureID = plot:GetFeatureType();
if not MatchValidTerrainsAndFeatures(improvement, terrainID, featureID) then return false end
if next(improvement.improvedResources) ~= nil then
local resourceID = plot:GetResourceType();
return improvement.improvedResources[resourceID] ~= nil;
end
return true;
end
--===============================================================================================
-- SETTERS
--===============================================================================================
local function CheckConsistency(plot)
if plot:GetTerrainType() == TerrainTypes.TERRAIN_OCEAN then
for neighbor in Neighbors(plot) do
-- Any neighbor is land? Turn plot into coast, not ocean
if neighbor:GetPlotType() ~= PlotTypes.PLOT_OCEAN then
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
InvalidateTerrain(plot, true);
break
end
end
elseif plot:GetPlotType() ~= PlotTypes.PLOT_OCEAN then
for neighbor in Neighbors(plot) do
if neighbor:GetTerrainType() == TerrainTypes.TERRAIN_OCEAN then
neighbor:SetTerrainType(TerrainTypes.TERRAIN_COAST);
InvalidateTerrain(neighbor, true);
end
end
end
end
-------------------------------------------------------------------------------------------------
function SetTerrain(terrain, plot)
if plot then
-- Want to set coast ?
if terrain.ID ~= plot:GetTerrainType() then
if terrain.water then
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
elseif plot:GetPlotType() == PlotTypes.PLOT_OCEAN then
plot:SetPlotType(PlotTypes.PLOT_LAND);
end
plot:SetTerrainType(terrain.ID);
CheckConsistency(plot)
plot:SetArea(-1)
local art = plot:GetContinentArtType()
if (not art) or (art < 1) then
plot:SetContinentArtType(1)
end
return true, true;
end
end
end
-------------------------------------------------------------------------------------------------
function SetPlotType(type, plot)
if plot and plot:GetPlotType() ~= type then
plot:SetPlotType(type.type);
plot:SetArea(-1)
CheckConsistency(plot)
return true;
end
end
-------------------------------------------------------------------------------------------------
function SetFoggy(plot)
table.insert(plotsToFog, plot);
end
-------------------------------------------------------------------------------------------------
function SetFeature(feature, plot)
if plot and plot:GetFeatureType() ~= feature.ID then
local terrainType = plot:GetTerrainType();
local isOcean = plot:IsWater() and not plot:IsLake();
if feature.naturalWonder then
if feature.type == "FEATURE_GEYSER" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
elseif feature.type == "FEATURE_CRATER" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_TUNDRA or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_GIBRALTAR" then
if not plot:IsCoastalLand() and not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS);
elseif feature.type == "FEATURE_FUJI" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS);
elseif feature.type == "FEATURE_MESA" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_REEF" then
if not isOcean then return end
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_VOLCANO" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS);
elseif feature.type == "FEATURE_FOUNTAIN_YOUTH" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
elseif feature.type == "FEATURE_POTOSI" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_PLAINS or terrainType ~= TerrainTypes.TERRAIN_GRASS or terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_TUNDRA then
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
end
elseif feature.type == "FEATURE_EL_DORADO" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
else
print("unknown wonder");
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
end
CheckConsistency(plot)
end
if IGE_HasGodsAndKings and feature.naturalWonder then
if feature.type == "FEATURE_SRI_PADA" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_GRASS or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS);
end
elseif feature.type == "FEATURE_MT_SINAI" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_MT_KAILASH" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_GRASS or terrainType ~= TerrainTypes.TERRAIN_PLAINS or terrainType ~= TerrainTypes.TERRAIN_TUNDRA then
plot:SetTerrainType(TerrainTypes.TERRAIN_TUNDRA);
end
elseif feature.type == "FEATURE_ULURU" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
end
end
if IGE_HasBraveNewWorld and feature.naturalWonder then
if feature.type == "FEATURE_LAKE_VICTORIA" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
end
elseif feature.type == "FEATURE_KILIMANJARO" then
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN);
if terrainType ~= TerrainTypes.TERRAIN_GRASS or terrainType ~= TerrainTypes.TERRAIN_PLAINS or terrainType ~= TerrainTypes.TERRAIN_TUNDRA then
plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS);
end
elseif feature.type == "FEATURE_SOLOMONS_MINES" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
end
end
if IGE_HasMoreWondersVP and feature.pseudonaturalWonder then
if feature.type == "FEATURE_NEW_REEF_A" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_NEW_REEF_B" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_NEW_REEF_C" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_SALAR_A" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_SALAR_B" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_CAUSEWAY_A" then
if not isOcean then return end
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_CAUSEWAY_B" then
if not plot:IsCoastalLand() and not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_TUNDRA);
elseif feature.type == "FEATURE_MT_EVEREST" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_SNOW);
elseif feature.type == "FEATURE_RETBA" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_PLAINS or terrainType ~= TerrainTypes.TERRAIN_DESERT or terrainType ~= TerrainTypes.TERRAIN_GRASS then
plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS);
end
elseif feature.type == "FEATURE_BERMUDA_A" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_OCEAN);
elseif feature.type == "FEATURE_BERMUDA_B" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_OCEAN);
elseif feature.type == "FEATURE_BERMUDA_C" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_OCEAN);
elseif feature.type == "FEATURE_LUMI_BAY" then
if not isOcean then return end
plot:SetPlotType(PlotTypes.PLOT_OCEAN);
plot:SetTerrainType(TerrainTypes.TERRAIN_COAST);
elseif feature.type == "FEATURE_DALLOL" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT and terrainType ~= TerrainTypes.TERRAIN_PLAINS then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_MT_PAEKTU" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
plot:SetTerrainType(TerrainTypes.TERRAIN_TUNDRA);
elseif feature.type == "FEATURE_EYE_OF_SAHARA_A" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_EYE_OF_SAHARA_B" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
elseif feature.type == "FEATURE_EYE_OF_SAHARA_C" then
plot:SetPlotType(PlotTypes.PLOT_LAND);
if terrainType ~= TerrainTypes.TERRAIN_DESERT then
plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT);
end
end
CheckConsistency(plot)
end
plot:SetFeatureType(feature.ID);
plot:SetArea(-1)
return true, true;
end
end
-------------------------------------------------------------------------------------------------
function SetResource(resource, plot)
if plot and (plot:GetResourceType() ~= resource.ID or plot:GetNumResource() ~= resource.qty) then
plot:SetResourceType(resource.ID, resource.qty);
plot:SetNumResource(resource.qty);
return true, true
end
end
-------------------------------------------------------------------------------------------------
function SetResourceQty(qty, plot)
if plot and plot:GetNumResource() ~= qty then
plot:SetNumResource(qty);
return true, true
end
end
-------------------------------------------------------------------------------------------------
function SetImprovement(improvement, plot)
if plot and (plot:GetImprovementType() ~= improvement.ID or plot:IsImprovementPillaged() ~= IGE.pillaged) then
plot:SetImprovementType(improvement.ID);
plot:SetImprovementPillaged(IGE.pillaged);
return true, true;
end
end
-------------------------------------------------------------------------------------------------
function SetImprovementPillaged(value, plot)
if plot and plot:IsImprovementPillaged() ~= value then
plot:SetImprovementPillaged(value);
return true, true;
end
end
-------------------------------------------------------------------------------------------------
function SetRoute(route, plot)
if plot and plot:GetRouteType() ~= route.ID then
plot:SetRouteType(route.ID);
return true;
end
end
-------------------------------------------------------------------------------------------------
function SetContinentArt(art, plot)
if plot and plot:GetContinentArtType() ~= art.ID then
plot:SetContinentArtType(art.ID);
return true;
end
end
-------------------------------------------------------------------------------------------------
function SetFog(data, plot)
if plot then
local pPlayer = Players[IGE.currentPlayerID];
local team = pPlayer:GetTeam();
if data.value then
SetFoggy(plot);
else
--plot:ChangeVisibilityCount(team, 1, -1, false, false);
plot:SetRevealed(team, true);
end
Game.UpdateFOW(true);
InvalidateTerrain(plot);
return true;
end
end
-------------------------------------------------------------------------------------------------
function SetOwnership(data, plot)
if data.value then
if Players[plot:GetOwner()] == IGE.currentPlayer then
return false
end
AddOwnership(IGE.currentPlayer, plot);
else
if Players[plot:GetOwner()] ~= IGE.currentPlayer then
return false
end
RemoveOwnership(plot);
end
return true;
end
--===============================================================================================
-- BACKUP / RESTORE / UNDO
--===============================================================================================
function BackupPlot(plot)
local team = IGE.currentPlayer:GetTeam();
local backup = {};
backup.x = plot:GetX();
backup.y = plot:GetY();
backup.type = plot:GetPlotType();
backup.terrain = plot:GetTerrainType();
backup.feature = plot:GetFeatureType();
backup.resource = plot:GetResourceType();
backup.resourceQty = plot:GetNumResource();
backup.improvement = plot:GetImprovementType();
backup.pillaged = plot:IsImprovementPillaged();
backup.route = plot:GetRouteType();
backup.owner = plot:GetOwner();
backup.art = plot:GetContinentArtType();
backup.revealed = plot:IsRevealed(team);
backup.rivers = {};
for _, side in ipairs(RiverSides) do
backup.rivers[side] = GetFlowRotation(plot, side);
end
return backup;
end
-------------------------------------------------------------------------------------------------
function RestorePlot(backup)
--print("restore plot");
local team = IGE.currentPlayer:GetTeam();
local plot = Map.GetPlot(backup.x, backup.y);
local resourceChanged = (plot:GetResourceType() ~= backup.resource) or (plot:GetNumResource() ~= backup.resourceQty) or (plot:GetPlotType() ~= backup.type);
plot:SetPlotType(backup.type);
plot:SetTerrainType(backup.terrain);
plot:SetFeatureType(backup.feature);
plot:SetResourceType(backup.resource);
plot:SetNumResource(backup.resourceQty);
plot:SetImprovementType(backup.improvement);
plot:SetImprovementPillaged(backup.pillaged);
plot:SetContinentArtType(backup.art);
plot:SetRouteType(backup.route);
CheckConsistency(plot)
if (plot:GetOwner() ~= backup.owner) then
RemoveOwnership(plot);
local newOwner = Players[backup.owner];
if (newOwner ~= nil) then
AddOwnership(newOwner, plot);
end
else
UpdateOwnership(plot);
end
if backup.revealed ~= plot:IsRevealed(team) then
if backup.revealed then
plot:SetRevealed(team, true);
else
SetFoggy(plot);
end
Game.UpdateFOW(true);
end
for _, side in ipairs(RiverSides) do
SetFlowRotation(plot, side, backup.rivers[side]);
end
LuaEvents.IGE_FlashPlot(plot);
InvalidateTerrain(plot, resourceChanged);
end