-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCityView.lua.cuc
2249 lines (2010 loc) · 88.2 KB
/
CityView.lua.cuc
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
--==========================================================
-- City View
-- Re-written by bc1 using Notepad++
-- code is common using switches
-- compatible with Gazebo's City-State Diplomacy Mod (CSD) for Brave New World v21
-- compatible with JFD's Piety & Prestige for Brave New World
-- compatible with GameInfo.Yields() iterator broken by Communitas
--todo: upper left corner
--todo: selection list with all buildable items
--todo: mod case where several buildings are allowed
--==========================================================
Events.SequenceGameInitComplete.Add(function()
local IsCiv5 = InStrategicView ~= nil
local IsCivBE = not IsCiv5
local IsCiv5vanilla = IsCiv5 and not Game.GetReligionName
local IsCiv5BNW = IsCiv5 and Game.GetActiveLeague ~= nil
include "UserInterfaceSettings"
local UserInterfaceSettings = UserInterfaceSettings
include "GameInfoCache" -- warning! booleans are true, not 1, and use iterator ONLY with table field conditions, NOT string SQL query
local GameInfo = GameInfoCache
include "IconHookup"
local IconHookup = IconHookup
local CivIconHookup = CivIconHookup
local ColorCulture = Color( 1, 0, 1, 1 )
include "StackInstanceManager"
local StackInstanceManager = StackInstanceManager
include "ShowProgress"
local ShowProgress = ShowProgress
if IsCiv5BNW then
include "GreatPeopleIcons"
end
local GreatPeopleIcons = GreatPeopleIcons
if IsCivBE then
include "IntrigueHelper"
end
--==========================================================
-- Minor lua optimizations
--==========================================================
local ipairs = ipairs
local abs = math.abs
local ceil = math.ceil
local floor = math.floor
local max = math.max
local min = math.min
local sqrt = math.sqrt
local pairs = pairs
local tonumber = tonumber
local tostring = tostring
local unpack = unpack
local concat = table.concat
local insert = table.insert
local sort = table.sort
local ButtonPopupTypes = ButtonPopupTypes
local CityAIFocusTypes = CityAIFocusTypes
local CityUpdateTypes = CityUpdateTypes
local ContextPtr = ContextPtr
local Controls = Controls
local Events = Events
local EventsClearHexHighlightStyle = Events.ClearHexHighlightStyle.Call
local EventsRequestYieldDisplay = Events.RequestYieldDisplay.Call
local EventsSerialEventHexHighlight = Events.SerialEventHexHighlight.Call
local Game = Game
local GameDefines = GameDefines
local GameInfoTypes = GameInfoTypes
local GameMessageTypes = GameMessageTypes
local GameOptionTypes = GameOptionTypes
local HexToWorld = HexToWorld
local InStrategicView = InStrategicView or function() return false end
local KeyEvents = KeyEvents
local Keys = Keys
local L = Locale.ConvertTextKey
local Locale = Locale
local eLClick = Mouse.eLClick
local eRClick = Mouse.eRClick
local eMouseEnter = Mouse.eMouseEnter
local Network = Network
local NotificationTypes = NotificationTypes
local OptionsManager = OptionsManager
local Players = Players
local PopupPriority = PopupPriority
local TaskTypes = TaskTypes
local ToHexFromGrid = ToHexFromGrid
local UI = UI
local GetHeadSelectedCity = UI.GetHeadSelectedCity
local GetUnitPortraitIcon = UI.GetUnitPortraitIcon
local YieldDisplayTypesAREA = YieldDisplayTypes.AREA
local YieldTypes = YieldTypes
local ORDER_TRAIN = OrderTypes.ORDER_TRAIN
local ORDER_CONSTRUCT = OrderTypes.ORDER_CONSTRUCT
local ORDER_CREATE = OrderTypes.ORDER_CREATE
local ORDER_MAINTAIN = OrderTypes.ORDER_MAINTAIN
--==========================================================
-- Globals
--==========================================================
local g_currencyIcon = IsCiv5 and "[ICON_GOLD]" or "[ICON_ENERGY]"
local g_maintenanceCurrency = IsCiv5 and "GoldMaintenance" or "EnergyMaintenance"
local g_yieldCurrency = IsCiv5 and YieldTypes.YIELD_GOLD or YieldTypes.YIELD_ENERGY
local g_isAdvisor = true
local g_activePlayerID = Game.GetActivePlayer()
local g_activePlayer = Players[ g_activePlayerID ]
local g_finishedItems = {}
local g_workerHeadingOpen = OptionsManager.IsNoCitizenWarning()
local g_worldPositionOffset = { x = 0, y = 0, z = 30 }
local g_worldPositionOffset2 = { x = 0, y = 35, z = 0 }
local g_portraitSize = Controls.PQportrait:GetSizeX()
local g_screenHeight = select(2, UIManager.GetScreenSizeVal() )
local g_leftStackHeigth = g_screenHeight - 40 - Controls.CityInfoBG:GetOffsetY() - Controls.CityInfoBG:GetSizeY()
local g_PlotButtonIM = StackInstanceManager( "PlotButtonInstance", "PlotButtonAnchor", Controls.PlotButtonContainer )
local g_BuyPlotButtonIM = StackInstanceManager( "BuyPlotButtonInstance", "BuyPlotButtonAnchor", Controls.PlotButtonContainer )
local g_GreatWorksIM = StackInstanceManager( "Work", "Button", false )
local g_SpecialistsIM = StackInstanceManager( "Slot", "Button", false )
local g_ProdQueueIM, g_SpecialBuildingsIM, g_GreatWorkIM, g_WondersIM, g_BuildingsIM, g_GreatPeopleIM, g_SlackerIM, g_UnitSelectIM, g_BuildingSelectIM, g_WonderSelectIM, g_ProcessSelectIM, g_FocusSelectIM
local g_queuedItemNumber, g_isDebugMode, g_BuyPlotMode, g_previousCity, g_isButtonPopupChooseProduction, g_isScreenAutoClose, g_isResetCityPlotPurchase, g_isNextCityProduction
local g_citySpecialists = {}
local g_isViewingMode = true
local g_slotTexture = {
SPECIALIST_CITIZEN = "CitizenUnemployed.dds",
SPECIALIST_SCIENTIST = "CitizenScientist.dds",
SPECIALIST_MERCHANT = "CitizenMerchant.dds",
SPECIALIST_ARTIST = "CitizenArtist.dds",
SPECIALIST_MUSICIAN = "CitizenArtist.dds",
SPECIALIST_WRITER = "CitizenArtist.dds",
SPECIALIST_ENGINEER = "CitizenEngineer.dds",
SPECIALIST_CIVIL_SERVANT = "CitizenCivilServant.dds", -- Compatibility with Gazebo's City-State Diplomacy Mod (CSD) for Brave New World
SPECIALIST_JFD_MONK = "CitizenMonk.dds", -- Compatibility with JFD's Piety & Prestige for Brave New World
SPECIALIST_PMMM_ENTERTAINER = "PMMMEntertainmentSpecialist.dds", --Compatibility with Vicevirtuoso's Madoka Magica: Wish for the World for Brave New World
}
for specialist in GameInfo.Specialists() do
if specialist.SlotTexture then
g_slotTexture[ specialist.Type ] = specialist.SlotTexture
end
end
local g_slackerTexture = IsCivBE and "UnemployedIndicator.dds" or g_slotTexture[ (GameInfo.Specialists[GameDefines.DEFAULT_SPECIALIST] or {}).Type ]
local g_gameInfo = {
[ORDER_TRAIN] = GameInfo.Units,
[ORDER_CONSTRUCT] = GameInfo.Buildings,
[ORDER_CREATE] = GameInfo.Projects,
[ORDER_MAINTAIN] = GameInfo.Processes,
}
local g_avisorRecommended = {
[ORDER_TRAIN] = Game.IsUnitRecommended,
[ORDER_CONSTRUCT] = Game.IsBuildingRecommended,
[ORDER_CREATE] = Game.IsProjectRecommended,
}
local g_advisors = {
[AdvisorTypes.ADVISOR_ECONOMIC] = "EconomicRecommendation",
[AdvisorTypes.ADVISOR_MILITARY] = "MilitaryRecommendation",
[AdvisorTypes.ADVISOR_SCIENCE] = "ScienceRecommendation",
[AdvisorTypes.ADVISOR_FOREIGN] = "ForeignRecommendation",
}
local function GetSelectedCity()
return ( not Game.IsNetworkMultiPlayer() or g_activePlayer:IsTurnActive() ) and GetHeadSelectedCity()
end
local function GetSelectedModifiableCity()
return not g_isViewingMode and GetSelectedCity()
end
----------------
-- Citizen Focus
local g_cityFocusButtons = {
a = Controls.AvoidGrowthButton,
b = Controls.ResetButton,
c = Controls.BoxOSlackers,
d = Controls.EditButton,
}
do
local g_cityFocusControls = {
[ Controls.BalancedFocusButton or -1 ] = CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE or false,
[ Controls.FoodFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD or false,
[ Controls.ProductionFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION or false,
[ Controls.GoldFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD or CityAIFocusTypes.CITY_AI_FOCUS_TYPE_ENERGY or false,
[ Controls.ResearchFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE or false,
[ Controls.CultureFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE or false,
[ Controls.GPFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE or false,
[ Controls.FaithFocusButton or -1 ] = CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FAITH or false,
} g_cityFocusControls[-1] = nil
local function FocusButtonBehavior( focus )
local city = GetSelectedModifiableCity()
if city then
Network.SendSetCityAIFocus( city:GetID(), focus )
return Network.SendUpdateCityCitizens( city:GetID() )
end
end
for control, focus in pairs( g_cityFocusControls ) do
if focus then
g_cityFocusButtons[ focus ] = control
control:SetVoid1( focus )
control:RegisterCallback( eLClick, FocusButtonBehavior )
else
control:SetHide( true )
end
end
end
local function HexRadius( a )
return ( sqrt( 1 + 4*a/3 ) - 1 ) / 2
end
local function SetupCallbacks( controls, toolTips, tootTipType, callBacks )
local control
-- Setup Tootips
for name, callback in pairs( toolTips ) do
control = controls[name]
if control then
control:SetToolTipCallback( callback )
control:SetToolTipType( tootTipType )
end
end
-- Setup Callbacks
for name, eventCallbacks in pairs( callBacks ) do
control = controls[name]
if control then
for event, callback in pairs( eventCallbacks ) do
control:RegisterCallback( event, callback )
end
end
end
end
local function ResizeProdQueue()
local selectionPanelHeight = 0
local queuePanelHeight = min( 190, Controls.QueueStack:IsHidden() and 0 or Controls.QueueStack:GetSizeY() ) -- 190 = 5 x 38=instance height
if not Controls.SelectionScrollPanel:IsHidden() then
Controls.SelectionStacks:CalculateSize()
selectionPanelHeight = max( min( g_leftStackHeigth - queuePanelHeight, Controls.SelectionStacks:GetSizeY() ), 64 )
-- Controls.SelectionBackground:SetSizeY( selectionPanelHeight + 85 )
Controls.SelectionScrollPanel:SetSizeY( selectionPanelHeight )
Controls.SelectionScrollPanel:CalculateInternalSize()
Controls.SelectionScrollPanel:ReprocessAnchoring()
end
Controls.QueueSlider:SetSizeY( queuePanelHeight + 38 ) -- 38 = Controls.PQbox:GetSizeY()
Controls.QueueScrollPanel:SetSizeY( queuePanelHeight )
Controls.QueueScrollPanel:CalculateInternalSize()
Controls.QueueBackground:SetSizeY( queuePanelHeight + selectionPanelHeight + 152 ) -- 125 = 38=Controls.PQbox:GetSizeY() + 87 + 27
return Controls.QueueBackground:ReprocessAnchoring()
end
local function ResizeRightStack()
Controls.BoxOSlackers:SetHide( Controls.SlackerStack:IsHidden() )
Controls.BoxOSlackers:SetSizeY( Controls.SlackerStack:GetSizeY() )
Controls.WorkerManagementBox:CalculateSize()
Controls.WorkerManagementBox:ReprocessAnchoring()
Controls.RightStack:CalculateSize()
local rightStackHeight = Controls.RightStack:GetSizeY() + 85
Controls.BuildingListBackground:SetSizeY( max( min( g_screenHeight + 48, rightStackHeight ), 160 ) )
Controls.RightScrollPanel:SetSizeY( min( g_screenHeight - 38, rightStackHeight ) )
Controls.RightScrollPanel:CalculateInternalSize()
return Controls.RightScrollPanel:ReprocessAnchoring()
end
local cityIsCanPurchase
if IsCiv5vanilla then
function cityIsCanPurchase( city, bTestPurchaseCost, bTestTrainable, unitID, buildingID, projectID, yieldID )
if yieldID == g_yieldCurrency then
return city:IsCanPurchase( not bTestPurchaseCost, unitID, buildingID, projectID )
-- bOnlyTestVisible
else
return false
end
end
else
function cityIsCanPurchase( city, ... )
return city:IsCanPurchase( ... )
end
end
--==========================================================
-- Clear out the UI so that when a player changes
-- the next update doesn't show the previous player's
-- values for a frame
--==========================================================
local function ClearCityUIInfo()
g_ProdQueueIM:ResetInstances()
g_ProdQueueIM.Commit()
Controls.PQremove:SetHide( true )
Controls.PQrank:SetText()
Controls.PQname:SetText()
Controls.PQturns:SetText()
return Controls.ProductionPortraitButton:SetHide(true)
end
--==========================================================
-- Selling Buildings
--==========================================================
local function SellBuilding( buildingID )
local city = GetSelectedModifiableCity()
local building = GameInfo.Buildings[ buildingID ]
-- Can this building be sold?
if building and city and city:IsBuildingSellable( buildingID ) then
Controls.YesButton:SetVoids( city:GetID(), buildingID )
Controls.SellBuildingTitle:SetText( building._Name:upper() )
Controls.SellBuildingText:LocalizeAndSetText( "TXT_KEY_SELL_BUILDING_INFO", city:GetSellBuildingRefund(buildingID), building[g_maintenanceCurrency] or 0 )
Controls.SellBuildingImage:SetHide( not IconHookup( building.PortraitIndex, 256, building.IconAtlas, Controls.SellBuildingImage ) )
Controls.SellBuildingStack:CalculateSize()
Controls.SellBuildingFrame:DoAutoSize()
--todo energy
return Controls.SellBuildingConfirm:SetHide( false )
end
end
local function CancelBuildingSale()
Controls.SellBuildingConfirm:SetHide(true)
return Controls.YesButton:SetVoids( -1, -1 )
end
local function CleanupCityScreen()
-- clear any rogue leftover tooltip
g_isButtonPopupChooseProduction = false
Controls.RightScrollPanel:SetScrollValue(0)
return CancelBuildingSale()
end
local function GotoNextCity()
if not g_isViewingMode then
CleanupCityScreen()
return Game.DoControl( GameInfoTypes.CONTROL_NEXTCITY )
end
end
local function GotoPrevCity()
if not g_isViewingMode then
CleanupCityScreen()
return Game.DoControl( GameInfoTypes.CONTROL_PREVCITY )
end
end
local function ExitCityScreen()
--print("request exit city screen")
-- CleanupCityScreen()
return Events.SerialEventExitCityScreen()
end
--==========================================================
-- Key Down Processing
--==========================================================
do
local VK_RETURN = Keys.VK_RETURN
local VK_ESCAPE = Keys.VK_ESCAPE
local VK_LEFT = Keys.VK_LEFT
local VK_RIGHT = Keys.VK_RIGHT
local KeyDown = KeyEvents.KeyDown
ContextPtr:SetInputHandler( function ( uiMsg, wParam )
if uiMsg == KeyDown then
if wParam == VK_ESCAPE or wParam == VK_RETURN then
if Controls.SellBuildingConfirm:IsHidden() then
ExitCityScreen()
else
CancelBuildingSale()
end
return true
elseif wParam == VK_LEFT then
GotoPrevCity()
return true
elseif wParam == VK_RIGHT then
GotoNextCity()
return true
end
end
end)
end
--==========================================================
-- Pedia
--==========================================================
local SearchForPediaEntry = Events.SearchForPediaEntry.Call
local function Pedia( row )
return SearchForPediaEntry( row and row._Name )
end
local function UnitClassPedia( unitClassID )
return Pedia( GameInfo.UnitClasses[ unitClassID ] )
end
local function BuildingPedia( buildingID )
return Pedia( GameInfo.Buildings[ buildingID ] )
end
local function SpecialistPedia( buildingID )
return Pedia( GameInfo.Specialists[ GameInfoTypes[(GameInfo.Buildings[buildingID]or{}).SpecialistType] or GameDefines.DEFAULT_SPECIALIST ] )
end
local function SelectionPedia( orderID, itemID )
return Pedia( (g_gameInfo[ orderID ]or{})[ itemID ] )
end
local function ProductionPedia( queuedItemNumber )
local city = GetHeadSelectedCity()
if city and queuedItemNumber then
return SelectionPedia( city:GetOrderFromQueue( queuedItemNumber ) )
end
end
--==========================================================
-- Tooltips
--==========================================================
local GreatPeopleIcon = GreatPeopleIcons and function (k)
return GreatPeopleIcons[k]
end or function()
return "[ICON_GREAT_PEOPLE]"
end
local function GetSpecialistYields( city, specialist )
local yieldTips = {}
if city and specialist then
local specialistYield, specialistYieldModifier, yieldInfo
local specialistID = specialist.ID
local cityOwner = Players[ city:GetOwner() ]
-- Culture
local cultureFromSpecialist = city:GetCultureFromSpecialist( specialistID )
local specialistCultureModifier = city:GetCultureRateModifier() + ( cityOwner and ( cityOwner:GetCultureCityModifier() + ( city:GetNumWorldWonders() > 0 and cityOwner:GetCultureWonderMultiplier() or 0 ) or 0 ) )
-- Yield
for yieldID = 0, YieldTypes.NUM_YIELD_TYPES-1 do
yieldInfo = GameInfo.Yields[yieldID]
if yieldInfo then
specialistYield = city:GetSpecialistYield( specialistID, yieldID )
specialistYieldModifier = city:GetBaseYieldRateModifier( yieldID )
if yieldID == YieldTypes.YIELD_CULTURE then
specialistYield = specialistYield + cultureFromSpecialist
specialistYieldModifier = specialistYieldModifier + specialistCultureModifier
cultureFromSpecialist = 0
end
if specialistYield ~= 0 then
insert( yieldTips, specialistYield * specialistYieldModifier / 100 .. yieldInfo.IconString )
end
end
end
if cultureFromSpecialist ~= 0 then
insert( yieldTips, cultureFromSpecialist .. "[ICON_CULTURE]" )
end
if IsCiv5 and (specialist.GreatPeopleRateChange or 0) ~= 0 then
insert( yieldTips, specialist.GreatPeopleRateChange .. GreatPeopleIcon( specialist.Type ) )
end
end
return concat( yieldTips, " " )
end
local ShowTextToolTipAndPicture = LuaEvents.ShowTextToolTipAndPicture.Call
local BuildingToolTip = LuaEvents.CityViewBuildingToolTip.Call
local CityOrderItemTooltip = LuaEvents.CityOrderItemTooltip.Call
local function SpecialistTooltip( control )
local buildingID = control:GetVoid1()
local building = GameInfo.Buildings[ buildingID ]
local specialistType = building and building.SpecialistType
local specialistID = specialistType and GameInfoTypes[specialistType] or GameDefines.DEFAULT_SPECIALIST
local specialist = GameInfo.Specialists[ specialistID ]
local tip = specialist._Name .. " " .. GetSpecialistYields( GetHeadSelectedCity(), specialist )
local slotTable = building and g_citySpecialists[buildingID]
if slotTable and not slotTable[control:GetVoid2()] then
tip = L"TXT_KEY_CITYVIEW_EMPTY_SLOT".."[NEWLINE]("..tip..")"
end
return ShowTextToolTipAndPicture( tip, specialist.PortraitIndex, specialist.IconAtlas )
end
local function ProductionToolTip( control )
local city = GetHeadSelectedCity()
local queuedItemNumber = control:GetVoid1()
if city and not Controls.QueueSlider:IsTrackingLeftMouseButton() then
return CityOrderItemTooltip( city, false, false, city:GetOrderFromQueue( queuedItemNumber ) )
end
end
--==========================================================
-- Specialist Managemeent
--==========================================================
local function OnSlackersSelected( buildingID, slotID )
local city = GetSelectedModifiableCity()
if city then
for _=1, slotID<=0 and city:GetSpecialistCount( GameDefines.DEFAULT_SPECIALIST ) or 1 do
Network.SendDoTask( city:GetID(), TaskTypes.TASK_REMOVE_SLACKER, 0, -1, false )
end
return Network.SendUpdateCityCitizens( city:GetID() )
end
end
local function ToggleSpecialist( buildingID, slotID )
local city = buildingID and slotID and GetSelectedModifiableCity()
if city then
-- If Specialists are automated then you can't change things with them
if IsCiv5 and not city:IsNoAutoAssignSpecialists() then
Game.SelectedCitiesGameNetMessage(GameMessageTypes.GAMEMESSAGE_DO_TASK, TaskTypes.TASK_NO_AUTO_ASSIGN_SPECIALISTS, -1, -1, true)
Controls.NoAutoSpecialistCheckbox:SetCheck(true)
if IsCiv5BNW then
Controls.NoAutoSpecialistCheckbox2:SetCheck(true)
end
end
local specialistID = GameInfoTypes[(GameInfo.Buildings[ buildingID ] or {}).SpecialistType] or -1
local specialistTable = g_citySpecialists[buildingID]
if specialistTable[slotID] then
if city:GetNumSpecialistsInBuilding(buildingID) > 0 then
specialistTable[slotID] = false
specialistTable.n = specialistTable.n - 1
Game.SelectedCitiesGameNetMessage( GameMessageTypes.GAMEMESSAGE_DO_TASK, TaskTypes.TASK_REMOVE_SPECIALIST, specialistID, buildingID )
return Network.SendUpdateCityCitizens( city:GetID() )
end
elseif city:IsCanAddSpecialistToBuilding(buildingID) then
specialistTable[slotID] = true
specialistTable.n = specialistTable.n + 1
Game.SelectedCitiesGameNetMessage( GameMessageTypes.GAMEMESSAGE_DO_TASK, TaskTypes.TASK_ADD_SPECIALIST, specialistID, buildingID )
return Network.SendUpdateCityCitizens( city:GetID() )
end
end
end
--==========================================================
-- Great Work Managemeent
--==========================================================
local function GreatWorkPopup( greatWorkID )
local greatWork = GameInfo.GreatWorks[ Game.GetGreatWorkType( greatWorkID or -1 ) or -1 ]
if greatWork and greatWork.GreatWorkClassType ~= "GREAT_WORK_ARTIFACT" then
return Events.SerialEventGameMessagePopup{
Type = ButtonPopupTypes.BUTTONPOPUP_GREAT_WORK_COMPLETED_ACTIVE_PLAYER,
Data1 = greatWorkID,
Priority = PopupPriority.Current
}
end
end
local function YourCulturePopup( greatWorkID )
return Events.SerialEventGameMessagePopup{
Type = ButtonPopupTypes.BUTTONPOPUP_CULTURE_OVERVIEW,
Data1 = 1,
Data2 = 1,
}
end
local function ThemingTooltip( buildingClassID, _, control )
control:SetToolTipString( GetHeadSelectedCity():GetThemingTooltip( buildingClassID ) )
end
local function GreatWorkTooltip( greatWorkID, greatWorkSlotID, slot )
if greatWorkID >= 0 then
return slot:SetToolTipString( Game.GetGreatWorkTooltip( greatWorkID, GetHeadSelectedCity():GetOwner() ) )
else
return slot:LocalizeAndSetToolTip( tostring(( GameInfo.GreatWorkSlots[ greatWorkSlotID ] or {}).EmptyToolTipText) )
end
end
--==========================================================
-- City Buildings List
--==========================================================
local function sortBuildings(a,b)
if a and b then
if a[4] ~= b[4] then
return a[4] < b[4]
elseif a[3] ~= b[3] then
return a[3] > b[3]
end
return a[2] < b[2]
end
end
local function SetupBuildingList( city, buildings, buildingIM )
buildingIM:ResetInstances()
sort( buildings, sortBuildings )
local cityOwnerID = city:GetOwner()
local cityOwner = Players[ cityOwnerID ]
local isNotResistance = not city:IsResistance()
-- Get the active perk types for civ BE
local cityOwnerPerks = IsCivBE and cityOwner:GetAllActivePlayerPerkTypes()
local building, buildingID, buildingClassID, buildingName, greatWorkCount, greatWorkID, slotStack, slot, new, instance, buildingButton, sellButton, textButton
for i = 1, #buildings do
building, buildingName, greatWorkCount = unpack(buildings[i])
buildingID = building.ID
buildingClassID = GameInfoTypes[ building.BuildingClass ] or -1
instance, new = buildingIM:GetInstance()
slotStack = instance.SlotStack
buildingButton = instance.Button
sellButton = instance.SellButton
textButton = instance.TextButton
textButton:SetHide( true )
if new then
buildingButton:RegisterCallback( eRClick, BuildingPedia )
buildingButton:SetToolTipCallback( BuildingToolTip )
sellButton:RegisterCallback( eLClick, SellBuilding )
textButton:RegisterCallback( eLClick, YourCulturePopup )
textButton:RegisterCallback( eMouseEnter, ThemingTooltip )
end
buildingButton:SetVoid1( buildingID )
-- Can we sell this building?
if not g_isViewingMode and city:IsBuildingSellable( buildingID ) then
sellButton:SetText( city:GetSellBuildingRefund( buildingID ) .. g_currencyIcon )
sellButton:SetHide( false )
sellButton:SetVoid1( buildingID )
else
sellButton:SetHide( true )
end
--!!!BE portrait size is bigger
instance.Portrait:SetHide( not IconHookup( building.PortraitIndex, 64, building.IconAtlas, instance.Portrait ) )
-------------------
-- Great Work Slots
if greatWorkCount > 0 then
local buildingGreatWorkSlotType = building.GreatWorkSlotType
if buildingGreatWorkSlotType then
local buildingGreatWorkSlot = GameInfo.GreatWorkSlots[ buildingGreatWorkSlotType ]
if city:IsThemingBonusPossible( buildingClassID ) then
textButton:SetText( " +" .. city:GetThemingBonus( buildingClassID ) )
textButton:SetVoid1( buildingClassID )
textButton:SetHide( false )
end
for i = 0, greatWorkCount - 1 do
slot, new = g_GreatWorksIM:GetInstance( slotStack )
slot = slot.Button
if new then
slot:RegisterCallback( eLClick, YourCulturePopup )
slot:RegisterCallback( eMouseEnter, GreatWorkTooltip )
end
greatWorkID = city:GetBuildingGreatWork( buildingClassID, i )
slot:SetVoids( greatWorkID, buildingGreatWorkSlot.ID )
if greatWorkID >= 0 then
slot:SetTexture( buildingGreatWorkSlot.FilledIcon )
slot:RegisterCallback( eRClick, GreatWorkPopup )
else
slot:SetTexture( buildingGreatWorkSlot.EmptyIcon )
slot:ClearCallback( eRClick )
end
end
end
end
-------------------
-- Specialist Slots
local numSpecialistsInBuilding = city:GetNumSpecialistsInBuilding( buildingID )
local specialistTable = g_citySpecialists[buildingID] or {}
if specialistTable.n ~= numSpecialistsInBuilding then
specialistTable = { n = numSpecialistsInBuilding }
for i = 1, numSpecialistsInBuilding do
specialistTable[i] = true
end
g_citySpecialists[buildingID] = specialistTable
end
local specialistType = building.SpecialistType
local specialist = GameInfo.Specialists[specialistType]
if specialist then
for slotID = 1, city:GetNumSpecialistsAllowedByBuilding( buildingID ) do
slot, new = g_SpecialistsIM:GetInstance( slotStack )
slot = slot.Button
if new then
slot:RegisterCallback( eRClick, SpecialistPedia )
slot:SetToolTipCallback( SpecialistTooltip )
end
if IsCiv5 then
slot:SetTexture( specialistTable[ slotID ] and g_slotTexture[ specialistType ] or "CitizenEmpty.dds" )
else
-- todo (does not look right)
IconHookup( specialist.PortraitIndex, 45, specialist.IconAtlas, slot )
slot:SetHide( not specialistTable[ slotID ] )
end
slot:SetVoids( buildingID, slotID )
if g_isViewingMode then
slot:ClearCallback( eLClick )
else
slot:RegisterCallback( eLClick, ToggleSpecialist )
end
end -- Specialist Slots
end
-- Building stats/bonuses
local maintenanceCost = tonumber(building[g_maintenanceCurrency]) or 0
local defenseChange = tonumber(building.Defense) or 0
local hitPointChange = tonumber(building.ExtraCityHitPoints) or 0
local buildingCultureRate = (IsCiv5vanilla and tonumber(building.Culture) or 0) + (specialist and city:GetCultureFromSpecialist( specialist.ID ) or 0) * numSpecialistsInBuilding
local buildingCultureModifier = tonumber(building.CultureRateModifier) or 0
local cityCultureRateModifier = cityOwner:GetCultureCityModifier() + city:GetCultureRateModifier() + (city:GetNumWorldWonders() > 0 and cityOwner and cityOwner:GetCultureWonderMultiplier() or 0)
local cityCultureRate
local population = city:GetPopulation()
local tips = {}
local thisBuildingAndYieldTypes = { BuildingType = building.Type }
if IsCiv5 then
cityCultureRate = city:GetBaseJONSCulturePerTurn()
-- Happiness
local happinessChange = (tonumber(building.Happiness) or 0) + (tonumber(building.UnmoddedHappiness) or 0)
+ cityOwner:GetExtraBuildingHappinessFromPolicies( buildingID )
+ (cityOwner:IsHalfSpecialistUnhappiness() and GameDefines.UNHAPPINESS_PER_POPULATION * numSpecialistsInBuilding * ((city:IsCapital() and cityOwner:GetCapitalUnhappinessMod() or 0)+100) * (cityOwner:GetUnhappinessMod() + 100) * (cityOwner:GetTraitPopUnhappinessMod() + 100) / 2e6 or 0) -- missing getHandicapInfo().getPopulationUnhappinessMod()
if happinessChange ~=0 then
insert( tips, happinessChange .. "[ICON_HAPPINESS_1]" )
end
else -- IsCivBE
cityCultureRate = city:GetBaseCulturePerTurn()
-- Health
local healthChange = (tonumber(building.Health) or 0) + (tonumber(building.UnmoddedHealth) or 0) + cityOwner:GetExtraBuildingHealthFromPolicies( buildingID )
local healthModifier = tonumber(building.HealthModifier) or 0
-- Effect of player perks
for _, perkID in ipairs(cityOwnerPerks) do
healthChange = healthChange + Game.GetPlayerPerkBuildingClassPercentHealthChange( perkID, buildingClassID )
healthModifier = healthModifier + Game.GetPlayerPerkBuildingClassPercentHealthChange( perkID, buildingClassID )
defenseChange = defenseChange + Game.GetPlayerPerkBuildingClassCityStrengthChange( perkID, buildingClassID )
hitPointChange = hitPointChange + Game.GetPlayerPerkBuildingClassCityHPChange( perkID, buildingClassID )
maintenanceCost = maintenanceCost + Game.GetPlayerPerkBuildingClassEnergyMaintenanceChange( perkID, buildingClassID )
end
if healthChange ~=0 then
insert( tips, healthChange .. "[ICON_HEALTH_1]" )
end
-- if healthModifier~=0 then insert( tips, L( "TXT_KEY_STAT_POSITIVE_YIELD_MOD", "[ICON_HEALTH_1]", healthModifier ) ) end
end
local buildingYieldRate, buildingYieldPerPop, buildingYieldModifier, cityYieldRate, cityYieldRateModifier, isProducing, yieldInfo
for yieldID = 0, YieldTypes.NUM_YIELD_TYPES-1 do
yieldInfo = GameInfo.Yields[yieldID]
if yieldInfo then
isProducing = isNotResistance
thisBuildingAndYieldTypes.YieldType = yieldInfo.Type or -1
-- Yield changes from the building
buildingYieldRate = Game.GetBuildingYieldChange( buildingID, yieldID )
+ (not IsCiv5vanilla and cityOwner:GetPlayerBuildingClassYieldChange( buildingClassID, yieldID )
+ city:GetReligionBuildingClassYieldChange( buildingClassID, yieldID ) or 0)
+ (IsCiv5BNW and city:GetLeagueBuildingClassYieldChange( buildingClassID, yieldID ) or 0)
-- Yield modifiers from the building
buildingYieldModifier = Game.GetBuildingYieldModifier( buildingID, yieldID )
+ cityOwner:GetPolicyBuildingClassYieldModifier( buildingClassID, yieldID )
-- Effect of player perks
if IsCivBE then
for _, perkID in ipairs(cityOwnerPerks) do
buildingYieldRate = buildingYieldRate + Game.GetPlayerPerkBuildingClassFlatYieldChange( perkID, buildingClassID, yieldID )
buildingYieldModifier = buildingYieldModifier + Game.GetPlayerPerkBuildingClassPercentYieldChange( perkID, buildingClassID, yieldID )
end
end
-- Specialists yield
if specialist then
buildingYieldRate = buildingYieldRate + numSpecialistsInBuilding * city:GetSpecialistYield( specialist.ID, yieldID )
end
cityYieldRateModifier = city:GetBaseYieldRateModifier( yieldID )
cityYieldRate = city:GetYieldPerPopTimes100( yieldID ) * population / 100 + city:GetBaseYieldRate( yieldID )
-- Special culture case
if yieldID == YieldTypes.YIELD_CULTURE then
buildingYieldRate = buildingYieldRate + buildingCultureRate
buildingYieldModifier = buildingYieldModifier + buildingCultureModifier
cityYieldRateModifier = cityYieldRateModifier + cityCultureRateModifier
cityYieldRate = cityYieldRate + cityCultureRate
buildingCultureRate = 0
buildingCultureModifier = 0
elseif yieldID == YieldTypes.YIELD_FOOD then
local foodPerPop = GameDefines.FOOD_CONSUMPTION_PER_POPULATION
local foodConsumed = city:FoodConsumption()
buildingYieldRate = buildingYieldRate + (foodConsumed < foodPerPop * population and foodPerPop * numSpecialistsInBuilding / 2 or 0)
buildingYieldModifier = buildingYieldModifier + (tonumber(building.FoodKept) or 0)
cityYieldRate = city:FoodDifferenceTimes100() / 100 -- cityYieldRate - foodConsumed
cityYieldRateModifier = cityYieldRateModifier + city:GetMaxFoodKeptPercent()
isProducing = true
end
-- Population yield
buildingYieldPerPop = 0
for row in GameInfo.Building_YieldChangesPerPop( thisBuildingAndYieldTypes ) do
buildingYieldPerPop = buildingYieldPerPop + (row.Yield or 0)
end
buildingYieldRate = buildingYieldRate + buildingYieldPerPop * population / 100
buildingYieldRate = buildingYieldRate * cityYieldRateModifier + ( cityYieldRate - buildingYieldRate ) * buildingYieldModifier
if isProducing and buildingYieldRate ~= 0 then
insert( tips, buildingYieldRate / 100 .. yieldInfo.IconString )
end
end
end
-- Culture leftovers
buildingCultureRate = buildingCultureRate * (100+cityCultureRateModifier) + ( cityCultureRate - buildingCultureRate ) * buildingCultureModifier
if isNotResistance and buildingCultureRate ~=0 then
insert( tips, buildingCultureRate / 100 .. "[ICON_CULTURE]" )
end
-- TODO TOURISM
if IsCiv5BNW then
local tourism = ( ( (building.FaithCost or 0) > 0
and building.UnlockedByBelief
and building.Cost == -1
and city and city:GetFaithBuildingTourism()
) or 0 )
-- local enhancedYieldTechID = GameInfoTypes[ building.EnhancedYieldTech ]
tourism = tourism + (tonumber(building.TechEnhancedTourism) or 0)
if tourism ~= 0 then
insert( tips, tourism.."[ICON_TOURISM]" )
end
end
if IsCiv5 and building.IsReligious then
buildingName = L( "TXT_KEY_RELIGIOUS_BUILDING", buildingName, Players[city:GetOwner()]:GetStateReligionKey() )
end
if city:GetNumFreeBuilding( buildingID ) > 0 then
buildingName = buildingName .. " (" .. L"TXT_KEY_FREE" .. ")"
elseif maintenanceCost ~=0 then
insert( tips, -maintenanceCost .. g_currencyIcon )
end
instance.Name:SetText( buildingName )
if defenseChange ~=0 then
insert( tips, defenseChange / 100 .. "[ICON_STRENGTH]" )
end
if hitPointChange ~= 0 then
insert( tips, L( "TXT_KEY_PEDIA_DEFENSE_HITPOINTS", hitPointChange ) )
end
instance.Label:ChangeParent( instance.Stack )
instance.Label:SetText( concat( tips, " ") )
slotStack:CalculateSize()
if slotStack:GetSizeX() + instance.Label:GetSizeX() < 254 then
instance.Label:ChangeParent( slotStack )
end
instance.Stack:CalculateSize()
-- slotStack:ReprocessAnchoring()
-- instance.Stack:ReprocessAnchoring()
buildingButton:SetSizeY( max(64, instance.Stack:GetSizeY() + 16) )
end
return buildingIM.Commit()
end
--==========================================================
-- Production Selection List Management
--==========================================================
local function SelectionPurchase( orderID, itemID, yieldID, soundKey )
local city = GetHeadSelectedCity()
if city then
local cityOwnerID = city:GetOwner()
if cityOwnerID == g_activePlayerID
and ( not city:IsPuppet() or ( IsCiv5BNW and g_activePlayer:MayNotAnnex() ) )
----------- Venice exception -----------
then
local cityID = city:GetID()
local isPurchase
if orderID == ORDER_TRAIN then
if cityIsCanPurchase( city, true, true, itemID, -1, -1, yieldID ) then
Game.CityPurchaseUnit( city, itemID, yieldID )
isPurchase = true
end
elseif orderID == ORDER_CONSTRUCT then
if cityIsCanPurchase( city, true, true, -1, itemID, -1, yieldID ) then
Game.CityPurchaseBuilding( city, itemID, yieldID )
Network.SendUpdateCityCitizens( cityID )
isPurchase = true
end
elseif orderID == ORDER_CREATE then
if cityIsCanPurchase( city, true, true, -1, -1, itemID, yieldID ) then
Game.CityPurchaseProject( city, itemID, yieldID )
isPurchase = true
end
end
if isPurchase then
Events.SpecificCityInfoDirty( cityOwnerID, cityID, CityUpdateTypes.CITY_UPDATE_TYPE_BANNER )
Events.SpecificCityInfoDirty( cityOwnerID, cityID, CityUpdateTypes.CITY_UPDATE_TYPE_PRODUCTION )
if soundKey then
Events.AudioPlay2DSound( soundKey )
end
end
end
end
end
local function AddSelectionItem( city, item,
selectionList,
orderID,
cityCanProduce,
unitID, buildingID, projectID,
cityGetProductionTurnsLeft,
cityGetGoldCost,
cityGetFaithCost )
local itemID = item.ID
local name = item._Name
local turnsLeft = not g_isViewingMode and cityCanProduce( city, itemID, 0, 1 ) -- 0 = /continue, 1 = testvisible, nil = /ignore cost
local canProduce = not g_isViewingMode and cityCanProduce( city, itemID ) -- nil = /continue, nil = /testvisible, nil = /ignore cost
local canBuyWithGold, goldCost, canBuyWithFaith, faithCost
if unitID then
if IsCivBE then
local bestUpgradeInfo = GameInfo.UnitUpgrades[ g_activePlayer:GetBestUnitUpgrade(unitID) ]
name = bestUpgradeInfo and bestUpgradeInfo._Name or name
end
if cityGetGoldCost then
canBuyWithGold = cityIsCanPurchase( city, true, true, unitID, buildingID, projectID, g_yieldCurrency )
goldCost = cityIsCanPurchase( city, false, false, unitID, buildingID, projectID, g_yieldCurrency )
and cityGetGoldCost( city, itemID )
end
if cityGetFaithCost then
canBuyWithFaith = cityIsCanPurchase( city, true, true, unitID, buildingID, projectID, YieldTypes.YIELD_FAITH )
faithCost = cityIsCanPurchase( city, false, false, unitID, buildingID, projectID, YieldTypes.YIELD_FAITH )
and cityGetFaithCost( city, itemID, true )
end
end
if turnsLeft or goldCost or faithCost then --or (g_isDebugMode and not city:IsHasBuilding(buildingID)) then
turnsLeft = turnsLeft and ( cityGetProductionTurnsLeft and cityGetProductionTurnsLeft( city, itemID ) or -1 )
return insert( selectionList, { item, orderID, name, turnsLeft, canProduce, goldCost, canBuyWithGold, faithCost, canBuyWithFaith } )
end
end
local function SortSelectionList(a,b)
return a[3]<b[3]
end
local g_SelectionListCallBacks = {
Button = {
[eLClick] = function( orderID, itemID )
local city = GetSelectedModifiableCity()
if city then
local cityOwnerID = city:GetOwner()
if cityOwnerID == g_activePlayerID and not city:IsPuppet() then
-- cityPushOrder( city, orderID, itemID, bAlt, bShift, bCtrl )
-- cityPushOrder( city, orderID, itemID, repeatBuild, replaceQueue, bottomOfQueue )
Game.CityPushOrder( city, orderID, itemID, UI.AltKeyDown(), UI.ShiftKeyDown(), not UI.CtrlKeyDown() )
Events.SpecificCityInfoDirty( cityOwnerID, city:GetID(), CityUpdateTypes.CITY_UPDATE_TYPE_BANNER )
Events.SpecificCityInfoDirty( cityOwnerID, city:GetID(), CityUpdateTypes.CITY_UPDATE_TYPE_PRODUCTION )
if g_isButtonPopupChooseProduction then
-- is there another city without production order ?
if g_isNextCityProduction then
for cityX in g_activePlayer:Cities() do
if cityX ~= city and not cityX:IsPuppet() and cityX:GetOrderQueueLength() < 1 then
UI.SelectCity( cityX )
return UI.LookAtSelectionPlot()
end
end
end
if g_isScreenAutoClose then
return ExitCityScreen()
end
end
end
end
end,
[eRClick] = SelectionPedia,
},
GoldButton = {
[eLClick] = function( orderID, itemID )
return SelectionPurchase( orderID, itemID, g_yieldCurrency, "AS2D_INTERFACE_CITY_SCREEN_PURCHASE" )
end,
},
FaithButton = {
[eLClick] = function( orderID, itemID )
return SelectionPurchase( orderID, itemID, YieldTypes.YIELD_FAITH, "AS2D_INTERFACE_FAITH_PURCHASE" )
end,
},
}
local g_SelectionListTooltips = {
Button = function( control )
return CityOrderItemTooltip( GetHeadSelectedCity(), true, false, control:GetVoid1(), control:GetVoid2() )
end,
GoldButton = function( control )
return CityOrderItemTooltip( GetHeadSelectedCity(), control:IsDisabled(), g_yieldCurrency, control:GetVoid1(), control:GetVoid2() )
end,
FaithButton = function( control )
return CityOrderItemTooltip( GetHeadSelectedCity(), control:IsDisabled(), YieldTypes.YIELD_FAITH, control:GetVoid1(), control:GetVoid2() )
end,
}
local function SetupSelectionList( itemList, selectionIM, cityOwnerID, getUnitPortraitIcon )
sort( itemList, SortSelectionList )
selectionIM:ResetInstances()
local cash = g_activePlayer:GetGold()
local faith = not IsCiv5vanilla and g_activePlayer:GetFaith() or 0
for i = 1, #itemList do
local item, orderID, itemDescription, turnsLeft, canProduce, goldCost, canBuyWithGold, faithCost, canBuyWithFaith = unpack( itemList[i] )
local itemID = item.ID
local avisorRecommended = g_isAdvisor and g_avisorRecommended[ orderID ]
local instance, new = selectionIM:GetInstance()
if new then
SetupCallbacks( instance, g_SelectionListTooltips, "EUI_ItemTooltip", g_SelectionListCallBacks )
end
instance.DisabledProduction:SetHide( canProduce or not(canBuyWithGold or canBuyWithFaith) )