Advertisement
Guest User

ProductionPanel.lua

a guest
Sep 10th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.86 KB | None | 0 0
  1. -- Copyright 2018-2019, Firaxis Games.
  2.  
  3. include("ProductionPanel");
  4.  
  5. print("ProductionPanel Bugfix for PBC")
  6.  
  7. -- ===========================================================================
  8. --  MEMBERS
  9. -- ===========================================================================
  10. -- Mirrored in CityPanel
  11. local LISTMODE:table = {PRODUCTION = 1, PURCHASE_GOLD = 2, PURCHASE_FAITH = 3, PROD_QUEUE = 4};
  12.  
  13. -- ===========================================================================
  14. --  OVERRIDES
  15. -- ===========================================================================
  16.  
  17. -- ===========================================================================
  18. function GetData()
  19.     print("GetData() ProductionPanel")
  20.     local playerID  :number = Game.GetLocalPlayer();
  21.     local pPlayer   :table = Players[playerID];
  22.     if (pPlayer == nil) then
  23.         Close();
  24.         return nil;
  25.     end
  26.  
  27.     local pSelectedCity:table = UI.GetHeadSelectedCity();
  28.     if pSelectedCity == nil then
  29.         Close();
  30.         return nil;
  31.     end
  32.  
  33.     local cityGrowth    = pSelectedCity:GetGrowth();
  34.     local cityCulture   = pSelectedCity:GetCulture();
  35.     local buildQueue    = pSelectedCity:GetBuildQueue();
  36.     local playerTreasury= pPlayer:GetTreasury();
  37.     local playerReligion= pPlayer:GetReligion();
  38.     local cityGold      = pSelectedCity:GetGold();
  39.     local cityBuildings = pSelectedCity:GetBuildings();
  40.     local cityDistricts = pSelectedCity:GetDistricts();
  41.     local cityID        = pSelectedCity:GetID();
  42.        
  43.     local new_data = {
  44.         City                = pSelectedCity,
  45.         Population          = pSelectedCity:GetPopulation(),
  46.         Owner               = pSelectedCity:GetOwner(),
  47.         Damage              = pPlayer:GetDistricts():FindID( pSelectedCity:GetDistrictID() ):GetDamage(),
  48.         TurnsUntilGrowth    = cityGrowth:GetTurnsUntilGrowth(),
  49.         CurrentTurnsLeft    = buildQueue:GetTurnsLeft(),
  50.         FoodSurplus         = cityGrowth:GetFoodSurplus(),
  51.         CulturePerTurn      = cityCulture:GetCultureYield(),
  52.         TurnsUntilExpansion = cityCulture:GetTurnsUntilExpansion(),
  53.         DistrictItems       = {},
  54.         BuildingItems       = {},
  55.         UnitItems           = {},
  56.         ProjectItems        = {},
  57.         BuildingPurchases   = {},
  58.         UnitPurchases       = {},
  59.         DistrictPurchases   = {},
  60.     };
  61.        
  62.     m_CurrentProductionHash = buildQueue:GetCurrentProductionTypeHash();
  63.     m_PreviousProductionHash = buildQueue:GetPreviousProductionTypeHash();
  64.  
  65.     --Must do districts before buildings
  66.     for row in GameInfo.Districts() do
  67.         if row.Hash == m_CurrentProductionHash then
  68.             new_data.CurrentProduction = row.Name;
  69.                
  70.             if(GameInfo.DistrictReplaces[row.DistrictType] ~= nil) then
  71.                 new_data.CurrentProductionType = GameInfo.DistrictReplaces[row.DistrictType].ReplacesDistrictType;
  72.             else
  73.                 new_data.CurrentProductionType = row.DistrictType;
  74.             end
  75.         end
  76.            
  77.         local isInPanelList         :boolean = (row.Hash ~= m_CurrentProductionHash or not row.OnePerCity) and not row.InternalOnly;
  78.         local bHasProducedDistrict  :boolean = cityDistricts:HasDistrict( row.Index );
  79.         if isInPanelList and ( buildQueue:CanProduce( row.Hash, true ) or bHasProducedDistrict ) then
  80.             local isCanProduceExclusion, results = buildQueue:CanProduce( row.Hash, false, true );
  81.             local isDisabled            :boolean = not isCanProduceExclusion;
  82.                
  83.             -- If at least one valid plot is found where the district can be built, consider it buildable.
  84.             local plots :table = GetCityRelatedPlotIndexesDistrictsAlternative( pSelectedCity, row.Hash );
  85.             if plots == nil or table.count(plots) == 0 then
  86.                 -- No plots available for district. Has player had already started building it?
  87.                 local isPlotAllocated :boolean = false;
  88.                 local pDistricts        :table = pSelectedCity:GetDistricts();
  89.                 for _, pCityDistrict in pDistricts:Members() do
  90.                     if row.Index == pCityDistrict:GetType() then
  91.                         isPlotAllocated = true;
  92.                         break;
  93.                     end
  94.                 end
  95.                 -- If not, this district can't be built. Guarantee that isDisabled is set.
  96.                 if not isPlotAllocated then
  97.                     isDisabled = true;
  98.                 elseif results ~= nil then
  99.                     local pFailureReasons : table = results[CityCommandResults.FAILURE_REASONS];
  100.                     if pFailureReasons ~= nil and table.count( pFailureReasons ) > 0 then
  101.                         for i,v in ipairs(pFailureReasons) do
  102.                             if v == TXT_DISTRICT_REPAIR_LOCATION_FLOODED then
  103.                                 isDisabled = true;
  104.                                 break;
  105.                             end
  106.                         end
  107.                     end
  108.                 end
  109.             elseif isDisabled and results ~= nil then
  110.                 -- TODO this should probably be handled in the exposure, for example:
  111.                 -- BuildQueue::CanProduce(nDistrictHash, bExclusionTest, bReturnResults, bAllowPurchasingPlots)
  112.                 local pFailureReasons : table = results[CityCommandResults.FAILURE_REASONS];
  113.                 if pFailureReasons ~= nil and table.count( pFailureReasons ) > 0 then
  114.                     -- There are available plots to purchase, it could still be available
  115.                     isDisabled = false;
  116.                     for i,v in ipairs(pFailureReasons) do
  117.                         -- If its disabled for another reason, keep it disabled
  118.                         if v ~= "LOC_DISTRICT_ZONE_NO_SUITABLE_LOCATION" then
  119.                             isDisabled = true;
  120.                             break;
  121.                         end
  122.                     end
  123.                 end
  124.             end
  125.                
  126.             local allReasons            :string = ComposeFailureReasonStrings( isDisabled, results );
  127.             local sToolTip              :string = ToolTipHelper.GetToolTip(row.DistrictType, Game.GetLocalPlayer()) .. allReasons;
  128.                
  129.             local iProductionCost       :number = buildQueue:GetDistrictCost( row.Index );
  130.             local iProductionProgress   :number = buildQueue:GetDistrictProgress( row.Index );
  131.  
  132.             sToolTip = sToolTip .. "[NEWLINE][NEWLINE]";
  133.             sToolTip = sToolTip .. ComposeProductionCostString( iProductionProgress, iProductionCost);
  134.  
  135.             local iMaintenanceCost      :number = row.Maintenance or 0;
  136.             if (iMaintenanceCost ~= nil and iMaintenanceCost > 0) then
  137.                 local yield = GameInfo.Yields["YIELD_GOLD"];
  138.                 if(yield) then
  139.                     sToolTip = sToolTip .. "[NEWLINE]" .. Locale.Lookup("LOC_TOOLTIP_MAINTENANCE", iMaintenanceCost, yield.IconString, yield.Name);
  140.                 end
  141.             end
  142.  
  143.             local bIsContaminated:boolean = cityDistricts:IsContaminated( row.Index );
  144.             local iContaminatedTurns:number = 0;
  145.             if bIsContaminated then
  146.                 for _, pDistrict in cityDistricts:Members() do
  147.                     local kDistrictDef:table = GameInfo.Districts[pDistrict:GetType()];
  148.                     if kDistrictDef.PrimaryKey == row.DistrictType then
  149.                         local kFalloutManager = Game.GetFalloutManager();
  150.                         local pDistrictPlot:table = Map.GetPlot(pDistrict:GetX(), pDistrict:GetY());
  151.                         iContaminatedTurns = kFalloutManager:GetFalloutTurnsRemaining(pDistrictPlot:GetIndex());
  152.                     end
  153.                 end
  154.             end
  155.  
  156.             table.insert( new_data.DistrictItems, {
  157.                 Type                = row.DistrictType,
  158.                 Name                = row.Name,
  159.                 ToolTip             = sToolTip,
  160.                 Hash                = row.Hash,
  161.                 Kind                = row.Kind,
  162.                 TurnsLeft           = buildQueue:GetTurnsLeft( row.DistrictType ),
  163.                 Disabled            = isDisabled,
  164.                 Repair              = cityDistricts:IsPillaged( row.Index ),
  165.                 Contaminated        = bIsContaminated,
  166.                 ContaminatedTurns   = iContaminatedTurns,
  167.                 Cost                = iProductionCost,
  168.                 Progress            = iProductionProgress,
  169.                 HasBeenBuilt        = bHasProducedDistrict,
  170.                 IsComplete          = cityDistricts:IsComplete( row.Index )
  171.             });
  172.         end
  173.  
  174.         -- Can it be purchased with gold?
  175.         local isAllowed, kDistrict = ComposeDistrictForPurchase( row, pSelectedCity, "YIELD_GOLD", playerTreasury, "LOC_BUILDING_INSUFFICIENT_FUNDS" );
  176.         if isAllowed then
  177.             table.insert( new_data.DistrictPurchases, kDistrict );
  178.         end
  179.  
  180.         -- Can it be purchased with faith?
  181.         local isAllowed, kDistrict = ComposeDistrictForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  182.         if isAllowed then
  183.             table.insert( new_data.DistrictPurchases, kDistrict );
  184.         end
  185.     end
  186.  
  187.     local unitData;
  188.     unitData = new_data.UnitPurchases;
  189.     for i, item in ipairs(unitData) do
  190.         print("STEP1","item.Yield",item.Yield,"item.Type",item.Type,"item.Name",item.Name) 
  191.     end
  192.  
  193.     --Must do buildings after districts
  194.     for row in GameInfo.Buildings() do
  195.         if row.Hash == m_CurrentProductionHash then
  196.             new_data.CurrentProduction = row.Name;
  197.             new_data.CurrentProductionType= row.BuildingType;
  198.         end
  199.  
  200.         local bCanProduce = buildQueue:CanProduce( row.Hash, true );
  201.         local iPrereqDistrict = "";
  202.         if row.PrereqDistrict ~= nil then
  203.             iPrereqDistrict = row.PrereqDistrict;
  204.                
  205.             --Only add buildings if the prereq district is not the current production (this can happen when repairing)
  206.             if new_data.CurrentProductionType == row.PrereqDistrict then
  207.                 bCanProduce = false;
  208.             end
  209.         end
  210.  
  211.         if row.Hash ~= m_CurrentProductionHash and (not row.MustPurchase or cityBuildings:IsPillaged(row.Hash)) and bCanProduce then
  212.             local isCanStart, results            = buildQueue:CanProduce( row.Hash, false, true );
  213.             local isDisabled            :boolean = not isCanStart;
  214.  
  215.             -- Did it fail and it is a Wonder?  If so, if it failed because of *just* NO_SUITABLE_LOCATION, we can look for an alternate.
  216.             if (isDisabled and row.IsWonder and results ~= nil and results[CityOperationResults.NO_SUITABLE_LOCATION] ~= nil and results[CityOperationResults.NO_SUITABLE_LOCATION] == true) then
  217.                 local pPurchaseablePlots :table = GetCityRelatedPlotIndexesWondersAlternative( pSelectedCity, row.Hash );
  218.                 if (pPurchaseablePlots and #pPurchaseablePlots > 0) then
  219.                     isDisabled = false;
  220.                 end
  221.             end
  222.  
  223.             local allReasons             :string = ComposeFailureReasonStrings( isDisabled, results );
  224.             local sToolTip               :string = ToolTipHelper.GetBuildingToolTip( row.Hash, playerID, pSelectedCity ) .. allReasons;
  225.  
  226.             local iProductionCost       :number = buildQueue:GetBuildingCost( row.Index );
  227.             local iProductionProgress   :number = buildQueue:GetBuildingProgress( row.Index );
  228.             sToolTip = sToolTip .. "[NEWLINE][NEWLINE]";
  229.             sToolTip = sToolTip .. ComposeProductionCostString( iProductionProgress, iProductionCost);
  230.  
  231.             local iMaintenanceCost      :number = row.Maintenance or 0;
  232.             if (iMaintenanceCost ~= nil and iMaintenanceCost > 0) then
  233.                 local yield = GameInfo.Yields["YIELD_GOLD"];
  234.                 if(yield) then
  235.                     sToolTip = sToolTip .. "[NEWLINE]" .. Locale.Lookup("LOC_TOOLTIP_MAINTENANCE", iMaintenanceCost, yield.IconString, yield.Name);
  236.                 end
  237.             end
  238.  
  239.             sToolTip = sToolTip .. "[NEWLINE]" .. AddBuildingExtraCostTooltip(row.Hash);
  240.                
  241.             table.insert( new_data.BuildingItems, {
  242.                 Type            = row.BuildingType,
  243.                 Name            = row.Name,
  244.                 ToolTip         = sToolTip,
  245.                 Hash            = row.Hash,
  246.                 Kind            = row.Kind,
  247.                 TurnsLeft       = buildQueue:GetTurnsLeft( row.Hash ),
  248.                 Disabled        = isDisabled,
  249.                 Repair          = cityBuildings:IsPillaged( row.Hash ),
  250.                 Cost            = iProductionCost,
  251.                 Progress        = iProductionProgress,
  252.                 IsWonder        = row.IsWonder,
  253.                 PrereqDistrict  = iPrereqDistrict,
  254.                 PrereqBuildings = row.PrereqBuildingCollection
  255.             });
  256.         end
  257.            
  258.         -- Can it be purchased with gold?
  259.         if row.PurchaseYield == "YIELD_GOLD" then
  260.             local isAllowed, kBldg = ComposeBldgForPurchase( row, pSelectedCity, "YIELD_GOLD", playerTreasury, "LOC_BUILDING_INSUFFICIENT_FUNDS" );
  261.             if isAllowed then
  262.                 table.insert( new_data.BuildingPurchases, kBldg );
  263.             end
  264.         end
  265.         -- Can it be purchased with faith?
  266.         if row.PurchaseYield == "YIELD_FAITH" or cityGold:IsBuildingFaithPurchaseEnabled( row.Hash ) then
  267.             local isAllowed, kBldg = ComposeBldgForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  268.             if isAllowed then
  269.                 table.insert( new_data.BuildingPurchases, kBldg );
  270.             end
  271.         end
  272.     end
  273.  
  274.     -- Sort BuildingItems to ensure Buildings are placed behind any Prereqs for that building
  275.     table.sort(new_data.BuildingItems,
  276.         function(a, b)
  277.             if a.IsWonder then
  278.                 return false;
  279.             end
  280.             if a.Disabled == false and b.Disabled == true then
  281.                 return true;
  282.             end
  283.             return false;
  284.         end
  285.     );
  286.    
  287.  
  288.     for row in GameInfo.Units() do
  289.         if row.Hash == m_CurrentProductionHash then
  290.             new_data.CurrentProduction = row.Name;
  291.             new_data.CurrentProductionType= row.UnitType;
  292.         end
  293.  
  294.         local kBuildParameters = {};
  295.         kBuildParameters.UnitType = row.Hash;
  296.         kBuildParameters.MilitaryFormationType = MilitaryFormationTypes.STANDARD_MILITARY_FORMATION;
  297.  
  298.         -- Can it be built normally?
  299.         if not row.MustPurchase and buildQueue:CanProduce( kBuildParameters, true ) then
  300.             local isCanProduceExclusion, results     = buildQueue:CanProduce( kBuildParameters, false, true );
  301.             local nProductionCost       :number = buildQueue:GetUnitCost( row.Index );
  302.             local nProductionProgress   :number = buildQueue:GetUnitProgress( row.Index );
  303.             local isDisabled                :boolean = not isCanProduceExclusion;
  304.             local sAllReasons                :string = ComposeFailureReasonStrings( isDisabled, results );
  305.             local sToolTip                   :string = ToolTipHelper.GetUnitToolTip( row.Hash, MilitaryFormationTypes.STANDARD_MILITARY_FORMATION, buildQueue ) .. sAllReasons;
  306.                
  307.             local kUnit :table = {
  308.                 Type                = row.UnitType,
  309.                 Name                = row.Name,
  310.                 ToolTip             = sToolTip,
  311.                 Hash                = row.Hash,
  312.                 Kind                = row.Kind,
  313.                 TurnsLeft           = buildQueue:GetTurnsLeft( row.Hash ),
  314.                 Disabled            = isDisabled,
  315.                 Civilian            = row.FormationClass == "FORMATION_CLASS_CIVILIAN",
  316.                 Cost                = nProductionCost,
  317.                 Progress            = nProductionProgress,
  318.                 Corps               = false,
  319.                 CorpsCost           = 0,
  320.                 CorpsTurnsLeft      = 1,
  321.                 CorpsTooltip        = "",
  322.                 CorpsName           = "",
  323.                 Army                = false,
  324.                 ArmyCost            = 0,
  325.                 ArmyTurnsLeft       = 1,
  326.                 ArmyTooltip         = "",
  327.                 ArmyName            = "",
  328.                 ReligiousStrength   = row.ReligiousStrength,
  329.                 IsCurrentProduction = row.Hash == m_CurrentProductionHash
  330.             };
  331.                
  332.             -- Should we present options for building Corps or Army versions?
  333.             if results ~= nil then
  334.                 if results[CityOperationResults.CAN_TRAIN_CORPS] then
  335.                     kBuildParameters.MilitaryFormationType = MilitaryFormationTypes.CORPS_MILITARY_FORMATION;
  336.                     local bCanProduceCorps, kResults = buildQueue:CanProduce( kBuildParameters, false, true);
  337.                     kUnit.Corps         = true;
  338.                     kUnit.CorpsDisabled = not bCanProduceCorps;
  339.                     kUnit.CorpsCost     = buildQueue:GetUnitCorpsCost( row.Index );
  340.                     kUnit.CorpsTurnsLeft    = buildQueue:GetTurnsLeft( row.Hash, MilitaryFormationTypes.CORPS_MILITARY_FORMATION );
  341.                     kUnit.CorpsTooltip, kUnit.CorpsName = ComposeUnitCorpsStrings( row, nProductionProgress, buildQueue );
  342.                     local sFailureReasons:string = ComposeFailureReasonStrings( kUnit.CorpsDisabled, kResults );
  343.                     kUnit.CorpsTooltip = kUnit.CorpsTooltip .. sFailureReasons;
  344.                     kUnit.Cost= kUnit.CorpsCost;
  345.                 end
  346.                 if results[CityOperationResults.CAN_TRAIN_ARMY] then
  347.                     kBuildParameters.MilitaryFormationType = MilitaryFormationTypes.ARMY_MILITARY_FORMATION;
  348.                     local bCanProduceArmy, kResults = buildQueue:CanProduce( kBuildParameters, false, true );
  349.                     kUnit.Army          = true;
  350.                     kUnit.ArmyDisabled  = not bCanProduceArmy;
  351.                     kUnit.ArmyCost      = buildQueue:GetUnitArmyCost( row.Index );
  352.                     kUnit.ArmyTurnsLeft = buildQueue:GetTurnsLeft( row.Hash, MilitaryFormationTypes.ARMY_MILITARY_FORMATION );
  353.                     kUnit.ArmyTooltip, kUnit.ArmyName = ComposeUnitArmyStrings( row, nProductionProgress, buildQueue );    
  354.                     local sFailureReasons:string = ComposeFailureReasonStrings( kUnit.ArmyDisabled, kResults );
  355.                     kUnit.ArmyTooltip = kUnit.ArmyTooltip .. sFailureReasons;
  356.                     kUnit.Cost = kUnit.CorpsCost;
  357.                 end
  358.             end
  359.                
  360.             table.insert(new_data.UnitItems, kUnit );
  361.         end
  362.         print(row.Name,row.PurchaseYield,row.Hash,"GOLD?",cityGold:IsUnitFaithPurchaseEnabled( row.Hash ),"FAITH?",cityGold:IsUnitFaithPurchaseEnabled( row.Hash ))
  363.            
  364.         -- Can it be purchased with gold?
  365.         if row.PurchaseYield == "YIELD_GOLD" then
  366.             local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_GOLD", playerTreasury, "LOC_BUILDING_INSUFFICIENT_FUNDS" );
  367.             if isAllowed then
  368.                 table.insert( new_data.UnitPurchases, kUnit );
  369.             end
  370.         end
  371.         -- Can it be purchased with faith?
  372.         if row.PurchaseYield == "YIELD_FAITH" or cityGold:IsUnitFaithPurchaseEnabled( row.Hash ) then
  373.             local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  374.             if isAllowed then
  375.                 table.insert( new_data.UnitPurchases, kUnit );
  376.             end
  377.         end
  378.        
  379.         if GameConfiguration.IsPlayByCloud() then
  380.  
  381.             -- Norway Berserker
  382.             if row.Name == "LOC_UNIT_NORWEGIAN_BERSERKER_NAME" and PlayerConfigurations[playerID]:GetCivilizationTypeName() == "CIVILIZATION_NORWAY" then
  383.                 local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  384.                 if isAllowed then
  385.                     table.insert( new_data.UnitPurchases, kUnit );
  386.                 end        
  387.             end
  388.             -- Scythia
  389.             if (row.Name == "LOC_UNIT_NORWEGIAN_BERSERKER_NAME"
  390.                 or row.Name == "LOC_UNIT_HORSEMAN_NAME"
  391.                 or row.Name == "LOC_UNIT_KNIGHT_NAME"
  392.                 or row.Name == "LOC_UNIT_COURSER_NAME"
  393.                 or row.Name == "LOC_UNIT_CUIRASSIER_NAME"
  394.                 or row.Name == "LOC_UNIT_CAVALRY_NAME"
  395.                 or row.Name == "LOC_UNIT_HEAVY_CHARIOT_NAME")
  396.                 and PlayerConfigurations[playerID]:GetCivilizationTypeName() == "CIVILIZATION_SCYTHIA" then
  397.                 local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  398.                 if isAllowed then
  399.                     table.insert( new_data.UnitPurchases, kUnit );
  400.                 end        
  401.             end    
  402.             -- GMC -- LOC_BUILDING_GOV_FAITH_NAME
  403.             local pPlayerCities = pPlayer:GetCities()
  404.             local gmcType = GameInfo.Buildings["BUILDING_GOV_FAITH"].Index
  405.             local hasGMC = false
  406.             for _, city in pPlayerCities:Members() do
  407.                 local pBuildings = city:GetBuildings()
  408.                 if pBuildings ~= nil then
  409.                     if pBuildings:HasBuilding(gmcType) then
  410.                         hasGMC = true
  411.                         break
  412.                     end
  413.                 end
  414.             end
  415.             if hasGMC == true and
  416.                 ( row.Name == "LOC_UNIT_HORSEMAN_NAME"
  417.                 or row.Name == "LOC_UNIT_KNIGHT_NAME"
  418.                 or row.Name == "LOC_UNIT_COURSER_NAME"
  419.                 or row.Name == "LOC_UNIT_CUIRASSIER_NAME"
  420.                 or row.Name == "LOC_UNIT_CAVALRY_NAME"
  421.                 or row.Name == "LOC_UNIT_HEAVY_CHARIOT_NAME"
  422.                 or row.Name == "LOC_UNIT_SWORDSMAN_NAME"
  423.                 or row.Name == "LOC_UNIT_GREEK_HOPLITE_NAME"
  424.                 or row.Name == "LOC_UNIT_JAPANESE_SAMURAI_NAME"
  425.                 or row.Name == "LOC_UNIT_INDIAN_VARU_NAME"
  426.                 or row.Name == "LOC_UNIT_ARABIAN_MAMLUK_NAME"
  427.                 or row.Name == "LOC_UNIT_CROSSBOWMAN_NAME"
  428.                 or row.Name == "LOC_UNIT_CHINESE_CROUCHING_TIGER_NAME"
  429.                 or row.Name == "LOC_UNIT_PIKEMAN_NAME"
  430.                 or row.Name == "LOC_UNIT_MUSKETMAN_NAME"
  431.                 or row.Name == "LOC_UNIT_SPANISH_CONQUISTADOR_NAME"
  432.                 or row.Name == "LOC_UNIT_BOMBARD_NAME"
  433.                 or row.Name == "LOC_UNIT_FIELD_CANNON_NAME"
  434.                 or row.Name == "LOC_UNIT_RUSSIAN_COSSACK_NAME"
  435.                 or row.Name == "LOC_UNIT_ENGLISH_REDCOAT_NAME"
  436.                 or row.Name == "LOC_UNIT_FRENCH_GARDE_IMPERIALE_NAME"
  437.                 or row.Name == "LOC_UNIT_AMERICAN_ROUGH_RIDER_NAME"        
  438.                 or row.Name == "LOC_UNIT_INFANTRY_NAME"
  439.                 or row.Name == "LOC_UNIT_ARTILLERY_NAME"
  440.                 or row.Name == "LOC_UNIT_AT_CREW_NAME"
  441.                 or row.Name == "LOC_UNIT_TANK_NAME"
  442.                 or row.Name == "LOC_UNIT_MACHINE_GUN_NAME" 
  443.                 or row.Name == "LOC_UNIT_MECHANIZED_INFANTRY_NAME"
  444.                 or row.Name == "LOC_UNIT_MODERN_AT_NAME"
  445.                 or row.Name == "LOC_UNIT_MODERN_ARMOR_NAME"
  446.                 or row.Name == "LOC_UNIT_AZTEC_EAGLE_WARRIOR_NAME"
  447.                 or row.Name == "LOC_UNIT_POLISH_HUSSAR_NAME"   
  448.                 or row.Name == "LOC_UNIT_PIKE_AND_SHOT_NAME"
  449.                 or row.Name == "LOC_UNIT_SPEC_OPS_NAME"
  450.                 or row.Name == "LOC_UNIT_MAPUCHE_MALON_RAIDER_NAME"
  451.                 or row.Name == "LOC_UNIT_GIANT_DEATH_ROBOT_NAME"                   
  452.                 ) then
  453.                 local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  454.                 if isAllowed then
  455.                     table.insert( new_data.UnitPurchases, kUnit );
  456.                 end            
  457.             end
  458.             -- Monumentality
  459.             local pGameEras:table = Game.GetEras();
  460.             local activeCommemorations = pGameEras:GetPlayerActiveCommemorations(playerID)
  461.             local hasM = false
  462.             for i,activeCommemoration in ipairs(activeCommemorations) do
  463.                 local commemorationInfo = GameInfo.CommemorationTypes[activeCommemoration];
  464.                 if (commemorationInfo ~= nil) then
  465.                     if commemorationInfo.GoldenAgeBonusDescription == "LOC_MOMENT_CATEGORY_INFRASTRUCTURE_BONUS_GOLDEN_AGE" then
  466.                         hasM = true
  467.                         break
  468.                     end
  469.                 end
  470.             end
  471.             if (row.Name == "LOC_UNIT_SETTLER_NAME" or row.Name == "LOC_UNIT_BUILDER_NAME" or row.Name == "LOC_UNIT_TRADER_NAME")and hasM == true then
  472.                 local isAllowed, kUnit = ComposeUnitForPurchase( row, pSelectedCity, "YIELD_FAITH", playerReligion, "LOC_BUILDING_INSUFFICIENT_FAITH" );
  473.                 if isAllowed then
  474.                     table.insert( new_data.UnitPurchases, kUnit );
  475.                 end        
  476.             end
  477.         end
  478.     end
  479.    
  480.     local unitData;
  481.     unitData = new_data.UnitPurchases;
  482.     for i, item in ipairs(unitData) do
  483.         print("STEP3","item.Yield",item.Yield,"item.Type",item.Type,"item.Name",item.Name) 
  484.     end
  485.    
  486.     if (pBuildQueue == nil) then
  487.         pBuildQueue = pSelectedCity:GetBuildQueue();
  488.     end
  489.  
  490.     for row in GameInfo.Projects() do
  491.         if row.Hash == m_CurrentProductionHash then
  492.             new_data.CurrentProduction = row.Name;
  493.             new_data.CurrentProductionType= row.ProjectType;
  494.         end
  495.  
  496.         if buildQueue:CanProduce( row.Hash, true ) then
  497.             local isCanProduceExclusion, results = buildQueue:CanProduce( row.Hash, false, true );
  498.             local isDisabled            :boolean = not isCanProduceExclusion;
  499.                
  500.             local allReasons        :string = ComposeFailureReasonStrings( isDisabled, results );
  501.             local sToolTip          :string = ToolTipHelper.GetProjectToolTip( row.Hash) .. allReasons;
  502.                
  503.             local iProductionCost       :number = buildQueue:GetProjectCost( row.Index );
  504.             local iProductionProgress   :number = buildQueue:GetProjectProgress( row.Index );
  505.             sToolTip = sToolTip .. "[NEWLINE]" .. ComposeProductionCostString( iProductionProgress, iProductionCost );
  506.                
  507.             table.insert(new_data.ProjectItems, {
  508.                 Type                = row.ProjectType,
  509.                 Name                = row.Name,
  510.                 ToolTip             = sToolTip,
  511.                 Hash                = row.Hash,
  512.                 Kind                = row.Kind,
  513.                 TurnsLeft           = buildQueue:GetTurnsLeft( row.ProjectType ),
  514.                 Disabled            = isDisabled,
  515.                 Cost                = iProductionCost,
  516.                 Progress            = iProductionProgress,
  517.                 IsCurrentProduction = row.Hash == m_CurrentProductionHash,
  518.                 IsRepeatable        = row.MaxPlayerInstances ~= 1 and true or false,
  519.             });
  520.         end
  521.     end
  522.    
  523.  
  524.  
  525.     return new_data;
  526. end
  527.  
  528.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement