-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealModifierAnalysis.lua
More file actions
2946 lines (2631 loc) · 136 KB
/
Copy pathRealModifierAnalysis.lua
File metadata and controls
2946 lines (2631 loc) · 136 KB
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
print("Loading Real Modifier Analysis.lua from Better Report Screen version "..GlobalParameters.BRS_VERSION_MAJOR.."."..GlobalParameters.BRS_VERSION_MINOR);
-- ===========================================================================
-- Real Modifier Analysis
-- Author: Infixo
-- Created: February 25th - March 1st, 2018
-- ===========================================================================
-- exposing functions and variables
if not ExposedMembers.RMA then ExposedMembers.RMA = {} end;
local RMA = ExposedMembers.RMA;
-- insert functions/objects into RMA in Initialize()
-- Expansions check
local bIsRiseAndFallMod:boolean = Modding.IsModActive("1B28771A-C749-434B-9053-D1380C553DE9"); -- Rise & Fall
local bIsGatheringStorm:boolean = Modding.IsModActive("4873eb62-8ccc-4574-b784-dda455e74e68"); -- Gathering Storm
local bIsRiseAndFall:boolean = (bIsRiseAndFallMod or bIsGatheringStorm); -- GS includes gameplay features from RF
-- ===========================================================================
-- DEBUG ROUTINES
-- ===========================================================================
-- debug output routine
function dprint(sStr,p1,p2,p3,p4,p5,p6)
local sOutStr = sStr;
if p1 ~= nil then sOutStr = sOutStr.." [1] "..tostring(p1); end
if p2 ~= nil then sOutStr = sOutStr.." [2] "..tostring(p2); end
if p3 ~= nil then sOutStr = sOutStr.." [3] "..tostring(p3); end
if p4 ~= nil then sOutStr = sOutStr.." [4] "..tostring(p4); end
if p5 ~= nil then sOutStr = sOutStr.." [5] "..tostring(p5); end
if p6 ~= nil then sOutStr = sOutStr.." [6] "..tostring(p6); end
print(sOutStr);
end
-- debug routine - print contents of a table of plot indices
function dshowinttable(pTable:table) -- For debugging purposes. LOT of table data being handled here.
-- for ease of reading they will be printed in rows by 10
dprint("Showing table (t,count)", pTable, table.count(pTable));
local iSize = table.count(pTable);
if iSize == 0 then dprint("...nothing to show"); return; end
for y = 0, math.floor((iSize-1)/10), 1 do
local sOutStr = "";
for x = 0,9,1 do
local idx = 10*y+x;
if idx < iSize then sOutStr = sOutStr..string.format("%5d", pTable[idx+1]); end
end
dprint(" row", y, sOutStr);
end
end
-- debug routine - prints a table (no recursion)
function dshowtable(tTable:table)
for k,v in pairs(tTable) do
print(k, type(v), tostring(v));
end
end
-- debug routine - prints a table, and tables inside recursively (up to 5 levels)
function dshowrectable(tTable:table, iLevel:number)
local level:number = 0;
if iLevel ~= nil then level = iLevel; end
for k,v in pairs(tTable) do
print(string.rep("---:",level), k, type(v), tostring(v));
if type(v) == "table" and level < 5 then dshowrectable(v, level+1); end
end
end
-- debug routine - prints extended yields table in a compacted form (1 line, formatted)
function dshowyields(pYields:table)
local tOut:table = {}; table.insert(tOut, " yields :");
for yield,value in pairs(pYields) do table.insert(tOut, string.format("%s %5.2f :", yield, value)); end
print(table.concat(tOut, " "));
end
-- debug routine - prints extended yields table in a compacted form (1 line, formatted)
function dshowsubject(pSubject:table)
print(" sub: ", pSubject.SubjectType, pSubject.Name);
end
--dprint("Subjects are:"); for k,v in pairs(tSubjects) do print(k,v.SubjectType,v.Name); end -- debug
-- debug routne - prints all subjects in 1 line
function dshowsubjects(pSubjects:table)
local tOut:table = {};
for _,subject in pairs(pSubjects) do table.insert(tOut, subject.Name); end
print("Subjects:", table.count(pSubjects), table.concat(tOut, ","));
end
--------------------------------------------------------------
-- Timer; usage is: Reset -> repeat ()
--------------------------------------------------------------
local MILISECS_PER_TICK: number = 10000;
local m_Timer1: number = 0
local m_Timer2: number = 0
local m_NumTicks1: number = 0;
local m_NumTicks2: number = 0;
local m_StartTime1: number = 0;
local m_StartTime2: number = 0;
function Timer1Reset()
m_Timer1 = 0; m_NumTicks1 = 0;
end
function Timer2Reset()
m_Timer2 = 0; m_NumTicks2 = 0;
end
function Timer1Start()
m_StartTime1 = GetTickCount();
end
function Timer2Start()
m_StartTime2 = GetTickCount();
end
function Timer1Tick()
m_Timer1 = m_Timer1 + (GetTickCount()-m_StartTime1);
m_NumTicks1 = m_NumTicks1 + 1;
--print("Ticker1:", m_NumTicks1, m_Timer1); -- debug
end
function Timer2Tick()
m_Timer2 = m_Timer2 + (GetTickCount()-m_StartTime2);
m_NumTicks2 = m_NumTicks2 + 1;
--print("Ticker2:", m_NumTicks2, m_Timer2); -- debug
end
function Timer1Stop(txt:string)
if m_NumTicks1 == 0 then print("Timer1: no ticks"); return; end
print("Timer1:", txt, math.floor(m_Timer1/MILISECS_PER_TICK), "milisecs", m_NumTicks1, "ticks", math.floor(m_Timer1/m_NumTicks1), "per tick");
end
function Timer2Stop(txt:string)
if m_NumTicks2 == 0 then print("Timer2: no ticks"); return; end
print("Timer2:", txt, math.floor(m_Timer2/MILISECS_PER_TICK), "milisecs", m_NumTicks2, "ticks", math.floor(m_Timer2/m_NumTicks2), "per tick");
end
-- ===========================================================================
-- DATA AND VARIABLES
-- ===========================================================================
local bBaseDataDirty:boolean = true; -- set to true to refresh the data
local tCities: table = nil; -- dynamically filled when needed (e.g. after refresh)
local tPlayer: table = nil; -- dynamically filled when needed (e.g. after refresh)
local tPlots: table = nil; -- only the local player's plots
-- supported Subject types, will be put into SubjectType field of respective tables
local SubjectTypes:table = {
Game = "Game",
Player = "Player",
City = "City",
District = "District",
Building = "Building",
Unit = "Unit",
GreatWork = "GreatWork",
TradeRoute = "TradeRoute",
Plot = "Plot", -- also plot yields
}
-- 230521 #13 Building_YieldDistrictCopies
local tDistrictYieldCopies: table = {};
function InitializeDistrictYieldCopies()
for row in GameInfo.Building_YieldDistrictCopies() do
if tDistrictYieldCopies[row.BuildingType] == nil then tDistrictYieldCopies[row.BuildingType] = {}; end
--table.insert(tDistrictYieldCopies[row.BuildingType], { Old = row.OldYieldType, New = row.NewYieldType}); -- too complex, assume 1=>1 copying
tDistrictYieldCopies[row.BuildingType][row.OldYieldType] = row.NewYieldType;
end
end
InitializeDistrictYieldCopies();
-- ===========================================================================
-- EXTENDED YIELDS
-- extended yields to support other effects, like Amenities, Tourism, etc.
-- ===========================================================================
-- YieldsTypes 0..5 are for FOOD, PRODUCTION, GOLD, SCIENCE, CULTURE and FAITH
-- they correspond to respective YIELD_ type in Yields table
YieldTypes.TOURISM = 6
YieldTypes.AMENITY = 7
YieldTypes.HOUSING = 8
YieldTypes.LOYALTY = 9
--YieldTypes.GPPOINT = 9 -- Great Person Point
--YieldTypes.ENVOY = 10
--YieldTypes.APPEAL = 11
-- whereever possible keep yields in a table named Yields with entries { YieldType = YieldValue }
-- create maps (speed up)
local YieldTypesMap: table = {};
for yield in GameInfo.Yields() do
YieldTypesMap[ yield.YieldType ] = string.gsub(yield.YieldType, "YIELD_","");
end
local YieldTypesOrder: table = {};
for yield,yid in pairs(YieldTypes) do
YieldTypesOrder[yid] = yield;
end
--print("YieldTypes"); dshowtable(YieldTypes);
--print("YieldTypesMap"); dshowtable(YieldTypesMap);
--print("YieldTypesOrder"); --dshowtable(YieldTypesOrder);
--for yid,yield in ipairs(YieldTypesOrder) do dprint("YieldTypesOrder", yid, yield) end
-- get a new table with all 0
function YieldTableNew()
local tNew:table = {};
for yield,_ in pairs(YieldTypes) do tNew[ yield ] = 0; end
return tNew;
end
-- set all values to 0
function YieldTableClear(pYields:table)
for yield,_ in pairs(YieldTypes) do pYields[ yield ] = 0; end
end
-- add two tables
function YieldTableAdd(pYields:table, pYieldsToAdd:table)
for yield,_ in pairs(YieldTypes) do pYields[ yield ] = pYields[ yield ] + pYieldsToAdd[ yield ]; end
end
-- multiply by a given number
function YieldTableMultiply(pYields:table, fModifier:number)
for yield,_ in pairs(YieldTypes) do pYields[ yield ] = pYields[ yield ] * fModifier; end
end
-- 230522 #3 multiply by a table of numbers
function YieldTableMultiplyTable(pYields:table, pModifier:table)
for yield,_ in pairs(YieldTypes) do pYields[ yield ] = pYields[ yield ] * pModifier[ yield ]; end
end
-- multiply by a percentage given as integer 0..100
function YieldTablePercent(pYields:table, iPercent:number)
return YieldTableMultiply(pYields, iPercent/100.0);
end
-- get a specific yield, takes both YieldTypes and "YIELD_XXX" form
function YieldTableGetYield(pYields:table, sYield:string)
if YieldTypesMap[ sYield ] then return pYields[ YieldTypesMap[ sYield ] ];
else return pYields[ sYield ]; end
end
-- set a specific yield, takes both YieldTypes and "YIELD_XXX" form
function YieldTableSetYield(pYields:table, sYield:string, fValue:number)
if YieldTypesMap[ sYield ] then pYields[ YieldTypesMap[ sYield ] ] = fValue;
else pYields[ sYield ] = fValue; end
end
-- returns a compacted string with yields info
function YieldTableGetInfo(pYields:table)
local sYieldInfo:string = "";
for _,yield in ipairs(YieldTypesOrder) do
if pYields[yield] ~= 0 then sYieldInfo = sYieldInfo..(sYieldInfo == "" and "" or " ")..GetYieldString("YIELD_"..yield, pYields[yield]); end
end
return sYieldInfo;
end
-- 2019-06-20 GS introduced multiple yields in one modifier, separated with comma
function YieldTableSetMultipleYields(pYields:table, sYields:string, sValues:string)
sYields = string.gsub(sYields, " ", ""); -- 230522 #3 Some of them have spaces inside, values are converted to number so it's not a problem
sYields = sYields..","; sValues = sValues..",";
while string.len(sYields) > 0 and string.len(sValues) > 0 do
local iCommaYields:number = string.find(sYields, ",");
local iCommaValues:number = string.find(sValues, ",");
--print("YieldTableSetMultipleYields", sYields, iCommaYields, sValues, iCommaValues);
YieldTableSetYield(pYields, string.sub(sYields, 1, iCommaYields-1), tonumber(string.sub(sValues, 1, iCommaValues-1)));
-- remove processed yield
sYields = string.sub(sYields, iCommaYields+1);
sValues = string.sub(sValues, iCommaValues+1);
end
end
-- ===========================================================================
-- GENERIC FUNCTIONS AND HELPERS
-- ===========================================================================
function GetGameInfoIndex(sTableName:string, sTypeName:string)
local tTable = GameInfo[sTableName];
if tTable then
local row = tTable[sTypeName];
if row then return row.Index
else return -1; end
end
return -1;
end
-- check if 'value' exists in table 'pTable'; should work for any type of 'value' and table indices
function IsInTable(pTable:table, value)
for _,data in pairs(pTable) do
if data == value then return true; end
end
return false;
end
-- returns 'key' at which a given 'value' is stored in table 'pTable'; nil if not found; should work for any type of 'value' and table indices
function GetTableKey(pTable:table, value)
for key,data in pairs(pTable) do
if data == value then return key; end
end
return nil;
end
-- changes "AA_BB_CC" string into "Aa Bb Cc"
function Capitalize(sText:string)
--local str:string = sText:gsub("_", " ");
--return tostring( str:gsub("(%a)([%w_']*)", function(first,rest) return first:upper()..rest:lower() end) );
return sText; -- debug
end
-- ===========================================================================
-- Couple of functions from include("Civ6Common");
-- ===========================================================================
-- ===========================================================================
-- Return the inline text-icon for a given yield
-- yieldType A database YIELD_TYPE
-- returns The [ICON_yield] string
-- ===========================================================================
function GetYieldTextIcon( yieldType:string )
local iconString:string = "";
if yieldType == nil or yieldType == "" then
iconString = "Error:NIL";
elseif yieldType == "YIELD_TOURISM" then
iconString = "[ICON_Tourism]"
elseif yieldType == "YIELD_AMENITY" then
iconString = "[ICON_Amenities]" -- [ICON_Therefore] a green arrow pointing to the right
elseif yieldType == "YIELD_HOUSING" then
iconString = "[ICON_Housing]" -- [ICON_LocationPip] a blue pin pointing down
elseif yieldType == "YIELD_LOYALTY" then
iconString = "[ICON_PressureUp]" -- [ICON_PressureDown] is a red arrow pointing down
elseif GameInfo.Yields[yieldType] ~= nil and GameInfo.Yields[yieldType].IconString ~= nil and GameInfo.Yields[yieldType].IconString ~= "" then
iconString = GameInfo.Yields[yieldType].IconString;
else
iconString = "Unknown:"..yieldType;
end
return iconString;
end
-- ===========================================================================
-- Return the inline entry for a yield's color
-- ===========================================================================
function GetYieldTextColor( yieldType:string )
if yieldType == nil or yieldType == "" then return "[COLOR:255,255,255,255]NIL ";
elseif yieldType == "YIELD_FOOD" then return "[COLOR:ResFoodLabelCS]";
elseif yieldType == "YIELD_PRODUCTION" then return "[COLOR:ResProductionLabelCS]";
elseif yieldType == "YIELD_GOLD" then return "[COLOR:ResGoldLabelCS]";
elseif yieldType == "YIELD_SCIENCE" then return "[COLOR:ResScienceLabelCS]";
elseif yieldType == "YIELD_CULTURE" then return "[COLOR:ResCultureLabelCS]";
elseif yieldType == "YIELD_FAITH" then return "[COLOR:ResFaithLabelCS]";
elseif yieldType == "YIELD_TOURISM" then return "[COLOR:ResTourismLabelCS]";
elseif yieldType == "YIELD_AMENITY" then return "[COLOR_White]";
elseif yieldType == "YIELD_HOUSING" then return "[COLOR_White]";
elseif yieldType == "YIELD_LOYALTY" then return "[COLOR_White]";
else return "[COLOR:255,255,255,0]ERROR ";
end
end
-- ===========================================================================
-- Updated functions from Civ6Common, to include rounding to 1 decimal digit
-- ===========================================================================
function toPlusMinusString( value:number )
if value == 0 then return "0"; end
--return Locale.ToNumber(value, "+#,###.#;-#,###.#");
return Locale.ToNumber(math.floor((value*10)+0.5)/10, "+#,###.#;-#,###.#");
end
function toPlusMinusNoneString( value:number )
if value == 0 then return " "; end
--return Locale.ToNumber(value, "+#,###.#;-#,###.#");
return Locale.ToNumber(math.floor((value*10)+0.5)/10, "+#,###.#;-#,###.#");
end
-- ===========================================================================
-- Return a string with a yield icon and a +/- based on yield amount.
-- ===========================================================================
function GetYieldString( yieldType:string, amount:number )
return GetYieldTextIcon(yieldType)..GetYieldTextColor(yieldType)..toPlusMinusString(amount).."[ENDCOLOR]";
end
-- ===========================================================================
-- This function is from SupportFunctions.lua
-- return a table indexed by buildingType, with a table of GameInfo.GreatWorks in that building
-- ===========================================================================
function GetGreatWorksForCity(pCity:table)
local result:table = {};
if pCity then
local pCityBldgs:table = pCity:GetBuildings();
for buildingInfo in GameInfo.Buildings() do
local buildingIndex:number = buildingInfo.Index;
local buildingType:string = buildingInfo.BuildingType;
if(pCityBldgs:HasBuilding(buildingIndex)) then
local numSlots:number = pCityBldgs:GetNumGreatWorkSlots(buildingIndex);
if (numSlots ~= nil and numSlots > 0) then
local greatWorksInBuilding:table = {};
-- populate great works
for index:number=0, numSlots - 1 do
local greatWorkIndex:number = pCityBldgs:GetGreatWorkInSlot(buildingIndex, index);
if greatWorkIndex ~= -1 then
local greatWorkType:number = pCityBldgs:GetGreatWorkTypeFromIndex(greatWorkIndex);
table.insert(greatWorksInBuilding, GameInfo.GreatWorks[greatWorkType]);
-- YIELDS: only Tourism (field Tourism)
end
end
-- create association between building type and great works
if #greatWorksInBuilding > 0 then
result[buildingType] = greatWorksInBuilding;
end
-- THEMED use pCityBldgs:IsBuildingThemedCorrectly()
-- local regularTourism:number = pCityBldgs:GetBuildingTourismFromGreatWorks(false, buildingIndex);
-- local religionTourism:number = pCityBldgs:GetBuildingTourismFromGreatWorks(true, buildingIndex);
-- local yieldValue:number = pCityBldgs:GetBuildingYieldFromGreatWorks(yieldIndex, buildingIndex);
end
end
end
end
return result;
end
-- ===========================================================================
-- A function for grabbing city data - from City Support by Firaxis
-- ===========================================================================
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
DATA_DOMINANT_RELIGION = "_DOMINANTRELIGION";
--YIELD_STATE = {
--NORMAL = 0,
--FAVORED = 1,
--IGNORED = 2
--}
-- 230522 #17 Districts with HitPoints can be garrisoned
local tGarrisonDistricts: table = {};
for row in GameInfo.Districts() do
if row.HitPoints > 0 then tGarrisonDistricts[row.DistrictType] = true; end
end
-- ===========================================================================
-- Obtains the texture for a city's current production.
-- pCity The city
-- optionalIconSize Size of the icon to return.
--
-- RETURNS NIL if error, otherwise a table containing:
-- name of production item
-- description
-- icon texture of the produced item
-- u offset of the icon texture
-- v offset of the icon texture
-- (0-1) percent complete
-- (0-1) percent complete after next turn
-- # of turns
-- progress
-- cost
-- ===========================================================================
function GetCurrentProductionInfoOfCity( pCity:table, iconSize:number )
local pBuildQueue :table = pCity:GetBuildQueue();
if pBuildQueue == nil then
UI.DataError("No production queue in city!");
return nil;
end
local hash :number = pBuildQueue:GetCurrentProductionTypeHash();
local data :table = GetProductionInfoOfCity(pCity, hash);
return data;
end
-- ===========================================================================
-- Update the yield data for a city.
-- ===========================================================================
--[[
function UpdateYieldData( pCity:table, data:table )
data.CulturePerTurn = pCity:GetYield( YieldTypes.CULTURE );
data.CulturePerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.CULTURE);
data.FaithPerTurn = pCity:GetYield( YieldTypes.FAITH );
data.FaithPerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.FAITH);
data.FoodPerTurn = pCity:GetYield( YieldTypes.FOOD );
data.FoodPerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.FOOD);
data.GoldPerTurn = pCity:GetYield( YieldTypes.GOLD );
data.GoldPerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.GOLD);
data.ProductionPerTurn = pCity:GetYield( YieldTypes.PRODUCTION );
data.ProductionPerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.PRODUCTION);
data.SciencePerTurn = pCity:GetYield( YieldTypes.SCIENCE );
data.SciencePerTurnToolTip = pCity:GetYieldToolTip(YieldTypes.SCIENCE);
return data;
end
--]]
-- ===========================================================================
-- ===========================================================================
function GetDistrictYieldText(district)
local yieldText = "";
for yield in GameInfo.Yields() do
local yieldAmount = district:GetYield(yield.Index);
if yieldAmount > 0 then
yieldText = yieldText .. GetYieldString( yield.YieldType, yieldAmount );
end
end
return yieldText;
end
-- ===========================================================================
-- Obtain the total resources for a given city.
-- ===========================================================================
function GetCityResourceData( pCity:table )
-- Loop through all the plots for a given city; tallying the resource amount.
local kResources : table = {};
local cityPlots : table = Map.GetCityPlots():GetPurchasedPlots(pCity)
for _, plotID in ipairs(cityPlots) do
local plot : table = Map.GetPlotByIndex(plotID)
local plotX : number = plot:GetX()
local plotY : number = plot:GetY()
local eResourceType : number = plot:GetResourceType();
-- TODO: Account for trade/diplomacy resources.
if eResourceType ~= -1 and Players[pCity:GetOwner()]:GetResources():IsResourceExtractableAt(plot) then
if kResources[eResourceType] == nil then
kResources[eResourceType] = 1;
else
kResources[eResourceType] = kResources[eResourceType] + 1;
end
end
end
return kResources;
end
-- ===========================================================================
-- Retrieve Governor data, if applicable
-- Is established?, Count how many promotions a governor has
function GetGovernorData(pCity:table)
if not bIsRiseAndFall then return false, 0 end
local pGovernor:table = pCity:GetAssignedGovernor()
if not pGovernor then return false, 0 end
-- count promotions
local iNumPromos:number = 0
local sGovernorType:string = GameInfo.Governors[ pGovernor:GetType() ].GovernorType
for row in GameInfo.GovernorPromotions() do
if row.GovernorType == sGovernorType and pGovernor:HasPromotion(row.Index) then iNumPromos = iNumPromos + 1 end
end
return pGovernor:IsEstablished(), iNumPromos
end
-- ===========================================================================
-- For a given city, return a table o' data for it and the surrounding
-- districts.
-- RETURNS: table of data
-- .City - city object
-- .field - city data
-- .Districts - table of Districts (has Buildings inside)
-- .Buildings - table of Buildings in the District
-- .Wonders - wonders
-- .OutgoingRoutes - trade routes
-- .IncomingRoutes - trade routes
-- ===========================================================================
function GetCityData( pCity:table )
local ownerID :number = pCity:GetOwner();
local pPlayer :table = Players[ownerID];
local pCityDistricts :table = pCity:GetDistricts();
local pMainDistrict :table = pPlayer:GetDistricts():FindID( pCity:GetDistrictID() ); -- Note player GetDistrict's object is different than above.
local districtHitpoints :number = 0;
local currentDistrictDamage :number = 0;
local wallHitpoints :number = 0;
local currentWallDamage :number = 0;
local garrisonDefense :number = 0;
if pCity ~= nil and pMainDistrict ~= nil then
districtHitpoints = pMainDistrict:GetMaxDamage(DefenseTypes.DISTRICT_GARRISON);
currentDistrictDamage = pMainDistrict:GetDamage(DefenseTypes.DISTRICT_GARRISON);
wallHitpoints = pMainDistrict:GetMaxDamage(DefenseTypes.DISTRICT_OUTER);
currentWallDamage = pMainDistrict:GetDamage(DefenseTypes.DISTRICT_OUTER);
garrisonDefense = math.floor(pMainDistrict:GetDefenseStrength() + 0.5);
end
-- Return value is here, 0/nil may be filled out below.
local data :table = {
City = pCity,
SubjectType = SubjectTypes.City,
Name = Locale.Lookup(pCity:GetName()),
Yields = YieldTableNew(), -- extended yields
ContinentType = 0,
Districts = {}, -- Per Entry Format: { Name, YieldType, YieldChange, Buildings={ Name,YieldType,YieldChange,isPillaged,isBuilt} }
FoodSurplus = 0,
IsGovernorEstablished = false,
NumDistricts = 0,
NumSpecialtyDistricts = 0,
Population = pCity:GetPopulation(),
Wonders = {}, -- Format per entry: { Name, YieldType, YieldChange }
Plot = Map.GetPlot(pCity:GetX(), pCity:GetY()),
NumResources = 0, -- 230522 #10 Johannesburg
IsGarrisonUnit = false, -- 230522 #17 Garrison in a city
--- not used yet
AmenitiesNetAmount = 0,
AmenitiesNum = 0,
AmenitiesFromLuxuries = 0,
AmenitiesFromEntertainment = 0,
AmenitiesFromCivics = 0,
AmenitiesFromGreatPeople = 0,
AmenitiesFromCityStates = 0,
AmenitiesFromReligion = 0,
AmenitiesFromNationalParks = 0,
AmenitiesFromStartingEra = 0,
AmenitiesFromImprovements = 0,
AmenitiesRequiredNum = 0,
AmenitiesFromGovernors = 0,
BeliefsOfDominantReligion = {},
Buildings = {}, -- Per Entry Format: { Name, CitizenNum }
BuildingsNum = 0,
CityWallTotalHP = 0,
CityWallHPPercent = 0,
CulturePerTurn = 0,
CurrentFoodPercent = 0;
CurrentProdPercent = 0,
CurrentProductionName = "",
CurrentProductionDescription = "",
CurrentTurnsLeft = 0,
Damage = 0,
Defense = garrisonDefense;
DistrictsNum = pCityDistricts:GetNumZonedDistrictsRequiringPopulation(),
DistrictsPossibleNum = pCityDistricts:GetNumAllowedDistrictsRequiringPopulation(),
FaithPerTurn = 0,
FoodPercentNextTurn = 0,
FoodPerTurn = 0,
GoldPerTurn = 0,
GrowthPercent = 100,
Happiness = 0,
HappinessGrowthModifier = 0, -- Multiplier
HappinessNonFoodYieldModifier = 0, -- Multiplier
Housing = 0,
HousingMultiplier = 0,
IsCapital = pCity:IsCapital(),
IsUnderSiege = false,
OccupationMultiplier = 0,
OwnerID = ownerID,
OtherGrowthModifiers = 0,
PantheonBelief = -1,
ProdPercentNextTurn = 0,
ProductionPerTurn = 0;
ProductionQueue = {},
Religions = {}, -- Format per entry: { Name, Followers }
ReligionFollowers = 0,
SciencePerTurn = 0,
TradingPosts = {}, -- Format per entry: { Player Number }
TurnsUntilGrowth = 0,
TurnsUntilExpansion = 0,
UnitStats = nil,
--YieldFilters = {},
};
-- extended yields
for yield,yid in pairs(YieldTypes) do data.Yields[ yield ] = pCity:GetYield( yid ); end
local pCityGrowth :table = pCity:GetGrowth();
local pCityCulture :table = pCity:GetCulture();
local cityGold :table = pCity:GetGold();
local pBuildQueue :table = pCity:GetBuildQueue();
local currentProduction :string = "LOC_HUD_CITY_PRODUCTION_NOTHING_PRODUCED";
local currentProductionDescription :string = "";
local currentProductionStats :string = "";
local pct :number = 0;
local pctNextTurn :number = 0;
local prodTurnsLeft :number = -1;
local productionInfo :table = nil; --GetCurrentProductionInfoOfCity( pCity, SIZE_PRODUCTION_ICON ); -- Infixo: NO PRODUCTION INFO YET
-- extended yields
data.Yields.HOUSING = pCityGrowth:GetHousing();
data.Yields.AMENITY = pCityGrowth:GetAmenities();
-- additional data
data.IsGovernorEstablished, data.NumGovernorPromotions = GetGovernorData(pCity)
data.ContinentType = Map.GetPlot( pCity:GetX(), pCity:GetY() ):GetContinentType()
data.GreatWorks = GetGreatWorksForCity(pCity)
-- If something is currently being produced, mark it in the queue.
if productionInfo ~= nil then
currentProduction = productionInfo.Name;
currentProductionDescription = productionInfo.Description;
if(productionInfo.StatString ~= nil) then
currentProductionStats = productionInfo.StatString;
end
pct = productionInfo.PercentComplete;
pctNextTurn = productionInfo.PercentCompleteNextTurn;
prodTurnsLeft = productionInfo.Turns;
productionInfo.Index = 1;
data.ProductionQueue[1] = productionInfo; --Place in front
-- Some buildings will not have a description.
if currentProductionDescription == nil then
currentProductionDescription = "";
end
end
-- current production type
data.CurrentProductionType = "NONE";
local iCurrentProductionHash:number = pCity:GetBuildQueue():GetCurrentProductionTypeHash();
if iCurrentProductionHash ~= 0 then
if GameInfo.Buildings[iCurrentProductionHash] ~= nil then data.CurrentProductionType = "BUILDING";
elseif GameInfo.Districts[iCurrentProductionHash] ~= nil then data.CurrentProductionType = "DISTRICT";
elseif GameInfo.Units[iCurrentProductionHash] ~= nil then data.CurrentProductionType = "UNIT";
elseif GameInfo.Projects[iCurrentProductionHash] ~= nil then data.CurrentProductionType = "PROJECT";
end
end
local isGrowing :boolean = pCityGrowth:GetTurnsUntilGrowth() ~= -1;
local isStarving:boolean = pCityGrowth:GetTurnsUntilStarvation() ~= -1;
local turnsUntilGrowth :number = 0; -- It is possible for zero... no growth and no starving.
if isGrowing then
turnsUntilGrowth = pCityGrowth:GetTurnsUntilGrowth();
elseif isStarving then
turnsUntilGrowth = -pCityGrowth:GetTurnsUntilStarvation(); -- Make negative
end
local food :number = pCityGrowth:GetFood();
local growthThreshold :number = pCityGrowth:GetGrowthThreshold();
local foodSurplus :number = pCityGrowth:GetFoodSurplus();
local foodpct :number = math.max( math.min( food / growthThreshold, 1.0 ), 0.0);
local foodpctNextTurn :number = 0;
if turnsUntilGrowth > 0 then
local foodGainNextTurn = foodSurplus * pCityGrowth:GetOverallGrowthModifier();
foodpctNextTurn = (food + foodGainNextTurn) / growthThreshold;
foodpctNextTurn = math.max( math.min( foodpctNextTurn, 1.0), 0.0 );
end
-- Three religion objects to work with: overall game object, the player's religion, and this specific city's religious population
local pGameReligion :table = Game.GetReligion();
local pPlayerReligion :table = pPlayer:GetReligion();
local pAllReligions :table = pGameReligion:GetReligions();
local pReligions :table = pCity:GetReligion():GetReligionsInCity();
local eDominantReligion :number = pCity:GetReligion():GetMajorityReligion();
local followersAll :number = 0;
for _, religionData in pairs(pReligions) do
-- If the value for the religion type is less than 0, there is no religion (citizens working towards a Patheon).
local religionType :string = (religionData.Religion > 0) and GameInfo.Religions[religionData.Religion].ReligionType or "RELIGION_PANTHEON";
local thisReligion :table = { ID=religionData.Religion, ReligionType=religionType, Followers=religionData.Followers };
table.insert( data.Religions, thisReligion );
if religionData.Religion == eDominantReligion and eDominantReligion > -1 then
data.Religions[DATA_DOMINANT_RELIGION] = thisReligion;
for _,kFoundReligion in ipairs(pAllReligions) do
if kFoundReligion.Religion == eDominantReligion then
for _,belief in pairs(kFoundReligion.Beliefs) do
table.insert( data.BeliefsOfDominantReligion, belief );
end
break;
end
end
end
if religionType ~= "RELIGION_PANTHEON" then
followersAll = followersAll + religionData.Followers;
end
end
-- number of followers of the main religion (from ReportScreen.lua)
data.MajorityReligionFollowers = 0;
--local eDominantReligion:number = pCity:GetReligion():GetMajorityReligion();
if eDominantReligion > 0 then -- WARNING! this rules out pantheons!
for _, religionData in pairs(pCity:GetReligion():GetReligionsInCity()) do
if religionData.Religion == eDominantReligion then data.MajorityReligionFollowers = religionData.Followers; end
end
end
--print("Majority religion followers for", cityName, data.MajorityReligionFollowers);
data.AmenitiesNetAmount = pCityGrowth:GetAmenities() - pCityGrowth:GetAmenitiesNeeded();
data.AmenitiesNum = pCityGrowth:GetAmenities();
data.AmenitiesFromLuxuries = pCityGrowth:GetAmenitiesFromLuxuries();
data.AmenitiesFromEntertainment = pCityGrowth:GetAmenitiesFromEntertainment();
data.AmenitiesFromCivics = pCityGrowth:GetAmenitiesFromCivics();
data.AmenitiesFromGreatPeople = pCityGrowth:GetAmenitiesFromGreatPeople();
data.AmenitiesFromCityStates = pCityGrowth:GetAmenitiesFromCityStates();
data.AmenitiesFromReligion = pCityGrowth:GetAmenitiesFromReligion();
data.AmenitiesFromNationalParks = pCityGrowth:GetAmenitiesFromNationalParks();
data.AmenitiesFromStartingEra = pCityGrowth:GetAmenitiesFromStartingEra();
data.AmenitiesFromImprovements = pCityGrowth:GetAmenitiesFromImprovements();
data.AmenitiesLostFromWarWeariness = pCityGrowth:GetAmenitiesLostFromWarWeariness();
data.AmenitiesLostFromBankruptcy = pCityGrowth:GetAmenitiesLostFromBankruptcy();
data.AmenitiesRequiredNum = pCityGrowth:GetAmenitiesNeeded();
--data.AmenitiesFromGovernors = pCityGrowth:GetAmenitiesFromGovernors();
data.AmenityAdvice = pCity:GetAmenityAdvice();
data.CityWallHPPercent = (wallHitpoints-currentWallDamage) / wallHitpoints;
data.CityWallCurrentHP = wallHitpoints-currentWallDamage;
data.CityWallTotalHP = wallHitpoints;
data.CurrentFoodPercent = foodpct;
data.CurrentProductionName = Locale.Lookup( currentProduction );
data.CurrentProdPercent = pct;
data.CurrentProductionDescription = Locale.Lookup( currentProductionDescription );
data.CurrentProductionIcon = productionInfo and productionInfo.Icon;
data.CurrentProductionStats = productionInfo and productionInfo.StatString;
data.CurrentTurnsLeft = prodTurnsLeft;
data.FoodPercentNextTurn = foodpctNextTurn;
data.FoodSurplus = foodSurplus; --Round( foodSurplus, 1); -- this is rounded to integer actually already
data.Happiness = pCityGrowth:GetHappiness();
data.HappinessGrowthModifier = pCityGrowth:GetHappinessGrowthModifier();
data.HappinessNonFoodYieldModifier = pCityGrowth:GetHappinessNonFoodYieldModifier();
data.HitpointPercent = ((districtHitpoints-currentDistrictDamage) / districtHitpoints);
data.HitpointsCurrent = districtHitpoints-currentDistrictDamage;
data.HitpointsTotal = districtHitpoints;
data.Housing = pCityGrowth:GetHousing(); -- incorrect, but not used by RMA
data.HousingFromWater = pCityGrowth:GetHousingFromWater();
data.HousingFromBuildings = pCityGrowth:GetHousingFromBuildings();
data.HousingFromImprovements = pCityGrowth:GetHousingFromImprovements(); -- incorrect, but bnot used by RMA
data.HousingFromDistricts = pCityGrowth:GetHousingFromDistricts();
data.HousingFromCivics = pCityGrowth:GetHousingFromCivics();
data.HousingFromGreatPeople = pCityGrowth:GetHousingFromGreatPeople();
data.HousingFromStartingEra = pCityGrowth:GetHousingFromStartingEra();
data.HousingMultiplier = pCityGrowth:GetHousingGrowthModifier();
data.HousingAdvice = pCity:GetHousingAdvice();
data.OccupationMultiplier = pCityGrowth:GetOccupationGrowthModifier();
data.Occupied = pCity:IsOccupied();
data.OtherGrowthModifiers = pCityGrowth:GetOtherGrowthModifier(); -- Growth modifiers from Religion & Wonders
data.PantheonBelief = pPlayerReligion:GetPantheon();
data.ProdPercentNextTurn = pctNextTurn;
data.ReligionFollowers = followersAll;
data.TurnsUntilExpansion = pCityCulture:GetTurnsUntilExpansion();
data.TurnsUntilGrowth = turnsUntilGrowth;
data.UnitStats = nil; --GetUnitStats( pBuildQueue:GetCurrentProductionTypeHash() ); --NIL if not a unit -- Infixo: NO UNIT STATS
-- Helper to get an internally used enum based on the state of a certain yield.
--[[
local pCitizens :table = pCity:GetCitizens();
function GetYieldState( yieldEnum:number )
if pCitizens:IsFavoredYield(yieldEnum) then return YIELD_STATE.FAVORED;
elseif pCitizens:IsDisfavoredYield(yieldEnum) then return YIELD_STATE.IGNORED;
else return YIELD_STATE.NORMAL;
end
end
data.YieldFilters[YieldTypes.CULTURE] = GetYieldState(YieldTypes.CULTURE);
data.YieldFilters[YieldTypes.FAITH] = GetYieldState(YieldTypes.FAITH);
data.YieldFilters[YieldTypes.FOOD] = GetYieldState(YieldTypes.FOOD);
data.YieldFilters[YieldTypes.GOLD] = GetYieldState(YieldTypes.GOLD);
data.YieldFilters[YieldTypes.PRODUCTION]= GetYieldState(YieldTypes.PRODUCTION);
data.YieldFilters[YieldTypes.SCIENCE] = GetYieldState(YieldTypes.SCIENCE);
--]]
--data = UpdateYieldData( pCity, data );
-- Determine builds, districts, and wonders
local pCityBuildings :table = pCity:GetBuildings();
local kCityPlots :table = Map.GetCityPlots():GetPurchasedPlots( pCity );
if (kCityPlots ~= nil) then
for _,plotID in pairs(kCityPlots) do
local kPlot:table = Map.GetPlotByIndex(plotID);
local kBuildingTypes:table = pCityBuildings:GetBuildingsAtLocation(plotID);
for _, type in ipairs(kBuildingTypes) do
local building = GameInfo.Buildings[type];
table.insert( data.Buildings, {
Name = GameInfo.Buildings[building.BuildingType].Name,
Citizens = kPlot:GetWorkerCount(),
isPillaged = pCityBuildings:IsPillaged(type),
Maintenance = GameInfo.Buildings[building.BuildingType].Maintenance --Expense in gold
});
end
end
end
local pDistrict : table = pPlayer:GetDistricts():FindID( pCity:GetDistrictID() );
if pDistrict ~= nil then
data.IsUnderSiege = pDistrict:IsUnderSiege();
else
UI.DataError("Some data will be missing as unable to obtain the corresponding district for city: "..pCity:GetName());
end
-------------------------------------
-- 230522 CITY PLOTS
-- Loop through all the plots of the city, based on GetCityResourceData())
local kResources: table = {};
local cityPlots : table = Map.GetCityPlots():GetPurchasedPlots(pCity)
for _, plotID in ipairs(cityPlots) do
local plot: table = Map.GetPlotByIndex(plotID);
local eResourceType: number = plot:GetResourceType();
local eImprovementType: number = plot:GetImprovementType();
-- 230522 #10 Johannesburg Count improved different resource types
-- Note: It must be an actual improvement. Strategics under districts do not trigger Johannesburg effect!
if eResourceType ~= -1 and eImprovementType ~= -1 and not plot:IsImprovementPillaged() then
-- must also check if this a valid improvement
local tResults: table =
DB.Query("SELECT * FROM Improvement_ValidResources WHERE ImprovementType = ? AND ResourceType = ?",
GameInfo.Improvements[eImprovementType].ImprovementType,
GameInfo.Resources[eResourceType].ResourceType);
if tResults and #tResults > 0 then -- found a valid improved resource
kResources[eResourceType] = true;
end
end
end
data.NumResources = table.count(kResources);
-------------------------------------
-- DISTRICTS
for i, district in pCityDistricts:Members() do
-- Helper to obtain yields for a district: build a lookup table and then match type.
local kTempDistrictYields :table = {};
for yield in GameInfo.Yields() do
kTempDistrictYields[yield.Index] = yield;
end
-- ==========
function GetDistrictYield( district:table, yieldType:string )
for i,yield in ipairs( kTempDistrictYields ) do
if yield.YieldType == yieldType then
return district:GetYield(i);
end
end
return 0;
end
--I do not know why we make local functions, but I am keeping standard
function GetDistrictBonus( district:table, yieldType:string )
for i,yield in ipairs( kTempDistrictYields ) do
if yield.YieldType == yieldType then
return district:GetAdjacencyYield(i);
end
end
return 0;
end
local districtInfo :table = GameInfo.Districts[district:GetType()];
local districtType :string = districtInfo.DistrictType;
local locX :number = district:GetX();
local locY :number = district:GetY();
local kPlot :table = Map.GetPlot(locX,locY);
local plotID :number = kPlot:GetIndex();
local districtTable :table = {
SubjectType = SubjectTypes.District,
Name = data.Name..": "..Locale.Lookup(districtInfo.Name),
Plot = kPlot,
Yields = YieldTableNew(), -- district yields (from adjacency)
--AdjYields = YieldTableNew(), -- adjacency bonus yields -- Infixo: ADJACENCY = STANDARD YIELD
DistrictType = districtType,
CityCenter = districtInfo.CityCenter,
OnePerCity = districtInfo.OnePerCity,
-- not used yet
YieldBonus = GetDistrictYieldText( district ),
isPillaged = pCityDistricts:IsPillaged(district:GetType()),
isBuilt = district:IsComplete(),--pCityDistricts:HasDistrict(districtInfo.Index, true);
Icon = "ICON_"..districtType,
Buildings = {},
--Culture = GetDistrictYield(district, "YIELD_CULTURE" ),
--Faith = GetDistrictYield(district, "YIELD_FAITH" ),
--Food = GetDistrictYield(district, "YIELD_FOOD" ),
--Gold = GetDistrictYield(district, "YIELD_GOLD" ),
--Production = GetDistrictYield(district, "YIELD_PRODUCTION" ),
--Science = GetDistrictYield(district, "YIELD_SCIENCE" ),
Tourism = 0,
Maintenance = districtInfo.Maintenance,
--[[
AdjacencyBonus = {
Culture = GetDistrictBonus(district, "YIELD_CULTURE"),
Faith = GetDistrictBonus(district, "YIELD_FAITH"),
Food = GetDistrictBonus(district, "YIELD_FOOD"),
Gold = GetDistrictBonus(district, "YIELD_GOLD"),
Production = GetDistrictBonus(district, "YIELD_PRODUCTION"),
Science = GetDistrictBonus(district, "YIELD_SCIENCE"),
},
--]]
};
-- count all districts and specialty ones
if district:IsComplete() and not districtInfo.CityCenter and districtType ~= "DISTRICT_WONDER" then
data.NumDistricts = data.NumDistricts + 1;
end
if district:IsComplete() and not districtInfo.CityCenter and districtInfo.OnePerCity and districtType ~= "DISTRICT_WONDER" then
data.NumSpecialtyDistricts = data.NumSpecialtyDistricts + 1;
end
-- extended yields -- Infixo: CHECK seems that Districts don't produce yields by themselves, only adjacency yields
-- there is no table for that, also both functions produce the same results
-- BUT! There is ADJUST_DISTRICT_YIELD_CHANGE, used by MODIFIER_PLAYER_DISTRICTS_ADJUST_YIELD_CHANGE and MODIFIER_PLAYER_DISTRICT_ADJUST_YIELD_CHANGE and ADJUST_DISTRICT_EXTRA_REGIONAL_YIELD for MODIFIER_PLAYER_DISTRICT_ADJUST_EXTRA_REGIONAL_YIELD
-- the first is used by Minors to adjust yields (e.g. MINOR_CIV_SCIENTIFIC_YIELD_FOR_CAMPUS, attached when Medium influence), the other two are not used
-- the third ise used by GREATPERSON_EXTRA_REGIONAL_BUILDING_PRODUCTION
-- OK, Minors are giving yields to Buildings now, not Districts, different modifiers are used
-- Another problem is that calling it with 6 gives negative big integers, unknown (bug?)
--for yield,yid in pairs(YieldTypes) do districtTable.Yields[ yield ] = district:GetYield( yid ); end
--for yield,yid in pairs(YieldTypes) do districtTable.Yields[ yield ] = district:GetAdjacencyYield( yid ); end -- Infixo: ADJACENCY = STANDARD YIELD
--districtTable.Yields.TOURISM = 0; -- tourism is produced in another way, GetYield() produces stupid numbers here
-- SECOND APPROACH
-- GetYield and GetAdjacencyYield give yields AFTER applying modifiers
-- We can get raw, unmodified yields from Plot:GetAdjacencyYield, however this requires a bit more complex call
-- kPlot holds the plot, district:GetType(), also produces 0 for index=6, so it's ok
for yield,yid in pairs(YieldTypes) do
districtTable.Yields[ yield ] = kPlot:GetAdjacencyYield(ownerID, pCity:GetID(), district:GetType(), yid)
end
-- 230522 #17 Garrison unit can be also in an Encampment, so we will handle all possible districts in one go
if not data.IsGarrisonUnit and tGarrisonDistricts[districtInfo.DistrictType] then -- don't iterate if we already found a garrison
for _,unit in ipairs(Units.GetUnitsInPlot(plotID)) do
if unit:GetCombat() > 0 then data.IsGarrisonUnit = true; break; end
end
end