private void ExecutePopulationBuyout()
    {
        if (!DepartmentOfTheInterior.CanBuyoutPopulation(this.aiEntityCity.City))
        {
            return;
        }
        List <EvaluableMessage_PopulationBuyout> list = new List <EvaluableMessage_PopulationBuyout>(this.aiEntityCity.Blackboard.GetMessages <EvaluableMessage_PopulationBuyout>(BlackboardLayerID.City, (EvaluableMessage_PopulationBuyout message) => message.CityGuid == this.aiEntityCity.City.GUID));

        if (list.Count == 0)
        {
            return;
        }
        if (list.Count > 1)
        {
            AILayer.LogWarning("There should not be several PopulationBuyout EvaluableMessages for the same city ({0})", new object[]
            {
                this.aiEntityCity.City
            });
        }
        EvaluableMessage_PopulationBuyout evaluableMessage_PopulationBuyout = list[0];

        Diagnostics.Log("ELCP {0}/{1} ExecutePopulationBuyout {2}", new object[]
        {
            this.Empire,
            this.aiEntityCity.City,
            evaluableMessage_PopulationBuyout.EvaluationState
        });
        if (evaluableMessage_PopulationBuyout.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate)
        {
            AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>().RegisterSynchronousJob(new SynchronousJob(this.SynchronousJob_BuyoutPopulation));
        }
    }
    private SynchronousJobState SynchronousJob_BuyoutPopulation()
    {
        if (this.aiEntityCity == null || this.aiEntityCity.City == null)
        {
            return(SynchronousJobState.Failure);
        }
        if (!DepartmentOfTheInterior.CanBuyoutPopulation(this.aiEntityCity.City))
        {
            return(SynchronousJobState.Failure);
        }
        OrderBuyOutPopulation order = new OrderBuyOutPopulation(this.Empire.Index, this.aiEntityCity.City.GUID);
        Ticket ticket;

        this.Empire.PlayerControllers.AI.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.BuyOutPopulation_TicketRaised));
        return(SynchronousJobState.Success);
    }
    public static void ShowHidePopulationBuyoutButton(Amplitude.Unity.Game.Empire observer, City city, AgeTransform populationBuyoutButton, AgeTransform populationGaugeBackground, AgeTransform nextPopulationTurns, AgeTransform nextPopulationHourglass, AgeTransform gaugePopulationTooltip)
    {
        bool flag = false;
        IDownloadableContentService service = Services.GetService <IDownloadableContentService>();

        if (service != null && service.IsShared(DownloadableContent11.ReadOnlyName))
        {
            DepartmentOfIntelligence agency = observer.GetAgency <DepartmentOfIntelligence>();
            if (agency != null)
            {
                flag = agency.IsEmpireInfiltrated(city.Empire);
            }
        }
        if (DepartmentOfTheInterior.CanBuyoutPopulation(city) && city.Empire == observer)
        {
            populationBuyoutButton.Visible = true;
            if (populationGaugeBackground != null)
            {
                populationGaugeBackground.Visible = false;
            }
            gaugePopulationTooltip.Visible  = false;
            nextPopulationTurns.Visible     = false;
            nextPopulationHourglass.Visible = false;
        }
        else if (DepartmentOfTheInterior.CanBuyoutPopulation(city) && flag)
        {
            populationBuyoutButton.Visible = false;
            if (populationGaugeBackground != null)
            {
                populationGaugeBackground.Visible = false;
            }
            gaugePopulationTooltip.Visible  = false;
            nextPopulationTurns.Visible     = false;
            nextPopulationHourglass.Visible = false;
        }
        else
        {
            populationBuyoutButton.Visible = false;
            if (populationGaugeBackground != null)
            {
                populationGaugeBackground.Visible = true;
            }
            gaugePopulationTooltip.Visible  = true;
            nextPopulationTurns.Visible     = true;
            nextPopulationHourglass.Visible = true;
        }
    }
    public override void RefreshContent()
    {
        if (this.City == null)
        {
            return;
        }
        base.RefreshContent();
        float            num      = 0f;
        WorkersDragPanel guiPanel = base.GuiService.GetGuiPanel <WorkersDragPanel>();

        for (int i = 0; i < this.workerTypes.Count; i++)
        {
            int num2 = Mathf.FloorToInt(this.City.GetPropertyValue(this.workerTypes[i]));
            if (guiPanel.DragInProgress && guiPanel.DragMoved && this.workerTypes[i] == guiPanel.StartingWorkerType)
            {
                num2 -= guiPanel.NumberOfWorkers;
            }
            if (i < this.WorkersGroups.Length)
            {
                this.WorkersGroups[i].RefreshContent(this.City, num2, this.workerTypes[i], guiPanel);
                this.WorkersGroups[i].GetComponent <AgeTransform>().Enable = (this.interactionsAllowed && !this.IsOtherEmpire);
            }
            int num3 = num2 / this.workersPerLine;
            if (num3 * this.workersPerLine != num2)
            {
                num3++;
            }
            if (num3 < 1)
            {
                num3 = 1;
            }
            if (i < this.WorkersGroups.Length && this.WorkersGroups[i] != null)
            {
                AgeTransform workersTable = this.WorkersGroups[i].WorkersTable;
                float        num4         = workersTable.VerticalMargin + (float)num3 * (this.childHeight + workersTable.VerticalSpacing);
                if (num4 > num)
                {
                    num = num4;
                }
            }
        }
        for (int j = 0; j < this.prodPerPopFIDSTypes.Count; j++)
        {
            float num5 = 0f;
            if (j < this.ProdPerPopFIDSValues.Length)
            {
                float propertyValue = this.City.GetPropertyValue(this.prodPerPopFIDSTypes[j]);
                this.ProdPerPopFIDSValues[j].Text = GuiFormater.FormatGui(propertyValue, false, false, false, 0);
            }
            float propertyValue2 = this.City.GetPropertyValue(this.workedFIDSTypes[j]);
            if (j < this.CityTileFIDSValues.Length)
            {
                float propertyValue3 = this.City.GetPropertyValue(this.cityTileFIDSTypes[j]);
                this.CityTileFIDSValues[j].Text = GuiFormater.FormatGui(propertyValue3, false, false, false, 0);
            }
            if (j < this.TotalFIDSValues.Length)
            {
                num5 = this.City.GetPropertyValue(this.totalFIDSTypes[j]);
                if (this.City.SimulationObject.Tags.Contains(City.MimicsCity) && this.TotalFIDSValues[j].AgeTransform.AgeTooltip.ClientData != null && this.TotalFIDSValues[j].AgeTransform.AgeTooltip.ClientData is SimulationPropertyTooltipData)
                {
                    SimulationPropertyTooltipData simulationPropertyTooltipData = this.TotalFIDSValues[j].AgeTransform.AgeTooltip.ClientData as SimulationPropertyTooltipData;
                    if (simulationPropertyTooltipData.Title == SimulationProperties.NetCityProduction)
                    {
                        num5 = 0f;
                    }
                    else if (simulationPropertyTooltipData.Title == SimulationProperties.NetCityGrowth)
                    {
                        num5 = this.City.GetPropertyValue("AlmostNetCityGrowth");
                    }
                }
                this.TotalFIDSValues[j].Text = GuiFormater.FormatGui(num5, false, false, false, 0);
            }
            if (j < this.ModifierFIDSValues.Length)
            {
                float num6 = num5 - propertyValue2;
                if (Mathf.RoundToInt(num6) != 0)
                {
                    this.ModifierFIDSValues[j].Text = GuiFormater.FormatGui(num6, false, false, true, 0);
                }
                else
                {
                    this.ModifierFIDSValues[j].Text = string.Empty;
                }
            }
        }
        this.WorkerGroupsTable.Height = num;
        this.WorkersTitle.Height      = num;
        for (int k = 0; k < this.WorkersGroups.Length; k++)
        {
            this.WorkersGroups[k].WorkersTable.Height    = num;
            this.WorkersGroups[k].ActiveHighlight.Height = num;
            this.WorkersGroups[k].GetComponent <AgeTransform>().Height = num;
        }
        base.AgeTransform.Height = this.TopMargin * AgeUtils.CurrentUpscaleFactor() + num + this.WorkerGroupsTable.PixelMarginBottom;
        bool flag  = DepartmentOfTheInterior.CanBuyoutPopulation(this.City);
        bool flag2 = this.City.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1);
        bool flag3 = this.City.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitMimics2);
        int  rowIndex;

        Func <WorkersGroup, bool> < > 9__0;
        int rowIndex2;

        for (rowIndex = 0; rowIndex < this.FoodColumnCells.Length; rowIndex = rowIndex2 + 1)
        {
            bool flag4 = false;
            if (this.IsOtherEmpire)
            {
                IEnumerable <WorkersGroup> workersGroups = this.WorkersGroups;
                Func <WorkersGroup, bool>  predicate;
                if ((predicate = < > 9__0) == null)
                {
                    predicate = (< > 9__0 = ((WorkersGroup cell) => cell.GetComponent <AgeTransform>() == this.FoodColumnCells[rowIndex]));
                }
                flag4 = workersGroups.Any(predicate);
            }
            this.FoodColumnCells[rowIndex].Enable     = (!flag && this.interactionsAllowed && !flag4);
            this.ScienceColumnCells[rowIndex].Enable  = (!flag2 && this.interactionsAllowed && !flag4);
            this.IndustryColumnCells[rowIndex].Enable = (!flag3 && this.interactionsAllowed && !flag4);
            rowIndex2 = rowIndex;
        }
        if (this.BoostersTable == null)
        {
            bool highDefinition = AgeUtils.HighDefinition;
            AgeUtils.HighDefinition              = false;
            this.BoostersTable                   = base.AgeTransform.InstanciateChild(this.BoostersEnumerator.BoostersTable.transform, "WorkerPanelBoostersTable1");
            this.BoostersTable.TableArrangement  = false;
            this.BoostersTable2                  = base.AgeTransform.InstanciateChild(this.BoostersEnumerator.BoostersTable.transform, "WorkerPanelBoostersTable2");
            this.BoostersTable2.TableArrangement = false;
            AgeUtils.HighDefinition              = highDefinition;
        }
        this.stackedBoosters.Clear();
        this.stackedBoosters2.Clear();
        float num7  = 0f;
        bool  flag5 = false;
        bool  flag6 = false;
        bool  flag7 = false;
        bool  flag8 = false;
        float num8  = AgeUtils.HighDefinition ? 3f : 2f;

        if (!this.IsOtherEmpire)
        {
            foreach (string text in new List <string>
            {
                "BoosterFood",
                "BoosterCadavers",
                "BoosterIndustry",
                "FlamesIndustryBooster",
                "BoosterScience"
            })
            {
                BoosterDefinition boosterDefinition2;
                if (this.database.TryGetValue(text, out boosterDefinition2))
                {
                    GuiStackedBooster item = new GuiStackedBooster(boosterDefinition2);
                    this.stackedBoosters.Add(item);
                    if (!this.ParentIsCityListScreen && (text == "BoosterCadavers" || text == "FlamesIndustryBooster"))
                    {
                        this.stackedBoosters2.Add(item);
                    }
                }
            }
            bool flag9 = false;
            this.vaultBoosters = this.departmentOfEducation.GetVaultItems <BoosterDefinition>();
            for (int l = 0; l < this.vaultBoosters.Count; l++)
            {
                BoosterDefinition boosterDefinition = this.vaultBoosters[l].Constructible as BoosterDefinition;
                if (boosterDefinition != null)
                {
                    flag9 = true;
                    if (boosterDefinition.Name == "BoosterFood")
                    {
                        flag5 = true;
                    }
                    else if (boosterDefinition.Name == "BoosterIndustry")
                    {
                        flag6 = true;
                    }
                    else if (boosterDefinition.Name == "BoosterCadavers")
                    {
                        flag7 = true;
                    }
                    else if (boosterDefinition.Name == "FlamesIndustryBooster")
                    {
                        flag8 = true;
                    }
                    this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.RewardType == boosterDefinition.RewardType).AddVaultBooster(this.vaultBoosters[l]);
                }
            }
            if (!flag9)
            {
                this.stackedBoosters.Clear();
                this.stackedBoosters2.Clear();
            }
            else
            {
                num7 = this.FidsGroups[0].Height;
                if (!this.ParentIsCityListScreen)
                {
                    if (!flag6)
                    {
                        GuiStackedBooster item2 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterIndustry");
                        this.stackedBoosters.Remove(item2);
                    }
                    else
                    {
                        GuiStackedBooster item3 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "FlamesIndustryBooster");
                        this.stackedBoosters.Remove(item3);
                    }
                    if (!flag5)
                    {
                        GuiStackedBooster item4 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterFood");
                        this.stackedBoosters.Remove(item4);
                    }
                    else
                    {
                        GuiStackedBooster item5 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterCadavers");
                        this.stackedBoosters.Remove(item5);
                    }
                    if (!flag6 && !flag5)
                    {
                        this.stackedBoosters2.Clear();
                    }
                }
                else
                {
                    if (flag8 && !flag6)
                    {
                        GuiStackedBooster item6 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterIndustry");
                        this.stackedBoosters.Remove(item6);
                    }
                    else if (!flag8)
                    {
                        GuiStackedBooster item7 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "FlamesIndustryBooster");
                        this.stackedBoosters.Remove(item7);
                    }
                    if (!flag5 && flag7)
                    {
                        GuiStackedBooster item8 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterFood");
                        this.stackedBoosters.Remove(item8);
                    }
                    else if (!flag7)
                    {
                        GuiStackedBooster item9 = this.stackedBoosters.Find((GuiStackedBooster booster) => booster.BoosterDefinition.Name == "BoosterCadavers");
                        this.stackedBoosters.Remove(item9);
                    }
                }
            }
        }
        this.BoostersTable2.ReserveChildren(this.stackedBoosters2.Count, this.BoostersEnumerator.BoosterStockPrefab, "Item2");
        this.BoostersTable2.RefreshChildrenIList <GuiStackedBooster>(this.stackedBoosters2, this.refreshDelegate, true, true);
        this.BoostersTable.ReserveChildren(this.stackedBoosters.Count, this.BoostersEnumerator.BoosterStockPrefab, "Item");
        this.BoostersTable.RefreshChildrenIList <GuiStackedBooster>(this.stackedBoosters, this.refreshDelegate, true, true);
        this.BoostersTable.PixelMarginTop  = base.AgeTransform.Height;
        this.BoostersTable2.PixelMarginTop = base.AgeTransform.Height + this.FidsGroups[0].Height + num8;
        float num9 = 0f;

        foreach (BoosterStock boosterStock in this.BoostersTable.GetChildren <BoosterStock>(true))
        {
            float num10 = num8;
            if (this.ParentIsCityListScreen && ((flag5 && flag7 && (boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterFood" || boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterCadavers")) || (flag6 && flag8 && (boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterIndustry" || boosterStock.GuiStackedBooster.BoosterDefinition.Name == "FlamesIndustryBooster"))))
            {
                boosterStock.AgeTransform.Width = this.FidsGroups[0].Width / 2f - 1f;
                if (boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterFood" || boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterIndustry")
                {
                    num10 = 2f;
                }
            }
            else
            {
                boosterStock.AgeTransform.Width = this.FidsGroups[0].Width;
            }
            if (boosterStock.GuiStackedBooster.Quantity == 0 || (flag && (num9 == 0f || boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterCadavers")) || (flag2 && boosterStock.GuiStackedBooster.BoosterDefinition.Name == "BoosterScience"))
            {
                boosterStock.AgeTransform.Enable  = false;
                boosterStock.AgeTransform.Visible = false;
            }
            else
            {
                num7 = boosterStock.AgeTransform.Height;
                boosterStock.AgeTransform.Enable  = this.interactionsAllowed;
                boosterStock.AgeTransform.Visible = true;
                boosterStock.QuickActivation      = true;
                boosterStock.Guid = this.City.GUID;
                boosterStock.QuantityLabel.AgeTransform.AttachTop       = true;
                boosterStock.QuantityLabel.AgeTransform.AttachRight     = true;
                boosterStock.QuantityLabel.AgeTransform.PixelMarginLeft = 0f;
                boosterStock.QuantityLabel.Alignement = AgeTextAnchor.AscendMiddleRight;
                if (!this.ParentIsCityListScreen)
                {
                    boosterStock.IconImage.AgeTransform.PixelMarginLeft      = num8 * 2.5f;
                    boosterStock.QuantityLabel.AgeTransform.PixelMarginRight = num8 * 2f;
                }
                else
                {
                    boosterStock.IconImage.AgeTransform.PixelMarginLeft      = ((boosterStock.AgeTransform.Width == this.FidsGroups[0].Width) ? (boosterStock.AgeTransform.Width / 3f) : (boosterStock.AgeTransform.Width / 5f));
                    boosterStock.QuantityLabel.AgeTransform.PixelMarginRight = ((boosterStock.AgeTransform.Width == this.FidsGroups[0].Width) ? (boosterStock.AgeTransform.Width / 3f) : (boosterStock.AgeTransform.Width / 5f));
                }
            }
            boosterStock.AgeTransform.X           = num9;
            boosterStock.AgeTransform.AttachRight = false;
            boosterStock.AgeTransform.AttachLeft  = true;
            num9 += boosterStock.AgeTransform.Width + num10;
        }
        if (this.BoostersTable2.GetChildren <BoosterStock>(true).Count > 0)
        {
            bool flag10 = false;
            num9 = 0f;
            foreach (BoosterStock boosterStock2 in this.BoostersTable2.GetChildren <BoosterStock>(true))
            {
                boosterStock2.AgeTransform.Width = this.FidsGroups[0].Width;
                if (boosterStock2.GuiStackedBooster.Quantity == 0 || (num9 == 0f && !flag5) || (num9 > 0f && !flag6) || (flag && num9 == 0f))
                {
                    boosterStock2.AgeTransform.Enable  = false;
                    boosterStock2.AgeTransform.Visible = false;
                }
                else
                {
                    flag10 = true;
                    boosterStock2.AgeTransform.Enable  = this.interactionsAllowed;
                    boosterStock2.AgeTransform.Visible = true;
                    boosterStock2.QuickActivation      = true;
                    boosterStock2.Guid = this.City.GUID;
                    boosterStock2.IconImage.AgeTransform.PixelMarginLeft      = num8 * 2.5f;
                    boosterStock2.QuantityLabel.AgeTransform.AttachTop        = true;
                    boosterStock2.QuantityLabel.AgeTransform.AttachRight      = true;
                    boosterStock2.QuantityLabel.AgeTransform.PixelMarginLeft  = 0f;
                    boosterStock2.QuantityLabel.AgeTransform.PixelMarginRight = num8 * 2f;
                    boosterStock2.QuantityLabel.Alignement = AgeTextAnchor.AscendMiddleRight;
                }
                boosterStock2.AgeTransform.X           = num9;
                boosterStock2.AgeTransform.AttachRight = false;
                boosterStock2.AgeTransform.AttachLeft  = true;
                num9 += this.FidsGroups[0].Width + this.BoostersTable2.HorizontalSpacing;
            }
            num7 += (flag10 ? (this.FidsGroups[0].Height + num8) : 0f);
        }
        base.AgeTransform.Height          += num7;
        this.AgeModifierPosition.EndHeight = base.AgeTransform.Height;
        foreach (AgeTransform ageTransform in base.AgeTransform.GetChildren())
        {
            if (ageTransform.name.Contains("CityTile") || ageTransform.name.Contains("Total") || ageTransform.name.Contains("Modifiers"))
            {
                ageTransform.PixelMarginBottom = this.OriginalMargins[ageTransform.name] * (AgeUtils.HighDefinition ? 1.5f : 1f) + num7;
            }
        }
    }
    private void GeneratePopulationBuyoutMessage()
    {
        if (!DepartmentOfTheInterior.CanBuyoutPopulation(this.aiEntityCity.City))
        {
            return;
        }
        this.GeneratePopulationBuyoutMessage_ELCPGlobalPopulationInfo();
        List <EvaluableMessage_PopulationBuyout> list = new List <EvaluableMessage_PopulationBuyout>(this.aiEntityCity.Blackboard.GetMessages <EvaluableMessage_PopulationBuyout>(BlackboardLayerID.City, (EvaluableMessage_PopulationBuyout message) => message.CityGuid == this.aiEntityCity.City.GUID && message.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained && message.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel));
        EvaluableMessage_PopulationBuyout        evaluableMessage_PopulationBuyout;

        if (list.Count == 0)
        {
            evaluableMessage_PopulationBuyout = new EvaluableMessage_PopulationBuyout(this.aiEntityCity.City.GUID, 1, AILayer_AccountManager.EconomyAccountName);
            this.aiEntityCity.Blackboard.AddMessage(evaluableMessage_PopulationBuyout);
        }
        else
        {
            evaluableMessage_PopulationBuyout = list[0];
        }
        float num = 0f;

        for (int i = 0; i < AILayer_Population.GainPerPopulation.Length; i++)
        {
            num += this.aiEntityCity.City.GetPropertyValue(AILayer_Population.GainPerPopulation[i]);
        }
        float num2          = num / AILayer_Population.GlobalPopulationInfos[this.Empire.Index].bestGainPerPop * 0.5f;
        float propertyValue = this.aiEntityCity.City.GetPropertyValue(SimulationProperties.Population);

        if (propertyValue == AILayer_Population.GlobalPopulationInfos[this.Empire.Index].lowestPopulation)
        {
            num2 = AILayer.Boost(num2, 0.2f);
        }
        float populationBuyOutCost = DepartmentOfTheTreasury.GetPopulationBuyOutCost(this.aiEntityCity.City);
        float num3;

        if (!this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpireMoney, out num3, false))
        {
            num3 = 1f;
        }
        float num4 = (num3 - populationBuyOutCost) / num3 / 0.8f;

        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            num4 -= 0.05f;
        }
        num2 = AILayer.Boost(num2, num4);
        ConstructionQueue constructionQueue = this.departmentOfIndustry.GetConstructionQueue(this.aiEntityCity.City);

        if (propertyValue > 1f)
        {
            for (int j = constructionQueue.Length - 1; j >= 0; j--)
            {
                if (constructionQueue.PeekAt(j).ConstructibleElementName.ToString().Contains("Settler"))
                {
                    num2 = AILayer.Boost(num2, -1f);
                    break;
                }
            }
        }
        Diagnostics.Log("ELCP {0}/{1} GeneratePopulationBuyoutMessage score: {2}, cost: {3}", new object[]
        {
            this.Empire,
            this.aiEntityCity.City.LocalizedName,
            num2,
            populationBuyOutCost
        });
        evaluableMessage_PopulationBuyout.Refresh(1f, num2, populationBuyOutCost, int.MaxValue);
    }