Пример #1
0
    private string FormatEmpirePoints(global::Empire empire, bool withNet = false)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();
        float stockValue;

        if (!agency.TryGetResourceStockValue(empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out stockValue, false))
        {
            Diagnostics.LogError("Can't get resource stock value {0} on simulation object {1}.", new object[]
            {
                DepartmentOfTheTreasury.Resources.EmpirePoint,
                empire.SimulationObject
            });
        }
        if (!withNet)
        {
            return(GuiFormater.FormatStock(stockValue, SimulationProperties.EmpirePoint, 1, false));
        }
        float netValue;

        if (!agency.TryGetNetResourceValue(empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out netValue, false))
        {
            Diagnostics.LogError("Can't get resource net value {0} on simulation object {1}.", new object[]
            {
                DepartmentOfTheTreasury.Resources.EmpirePoint,
                empire.SimulationObject
            });
        }
        return(GuiFormater.FormatStockAndNet(stockValue, netValue, SimulationProperties.EmpirePoint, false));
    }
Пример #2
0
    private void UpdateResourceStatus(PointOfInterest pointOfInterest, global::Empire empire, Region region, AIRegionData regionData, DepartmentOfTheTreasury departmentOfTheTreasury)
    {
        regionData.ResourcePointOfInterestCount++;
        if (pointOfInterest.PointOfInterestImprovement != null)
        {
            regionData.BuiltExtractor++;
        }
        if (!DepartmentOfTheInterior.IsPointOfInterestVisible(empire, pointOfInterest))
        {
            return;
        }
        string empty     = string.Empty;
        bool   condition = pointOfInterest.PointOfInterestDefinition.TryGetValue("ResourceName", out empty);

        Diagnostics.Assert(condition);
        ResourceDefinition.Type resourceType = departmentOfTheTreasury.GetResourceType(empty);
        float num        = 0f;
        bool  condition2 = departmentOfTheTreasury.TryGetNetResourceValue(empire, empty, out num, true);

        Diagnostics.Assert(condition2);
        if (num > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.ProducedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.ProducedStrategicRessourcesCount++;
            }
            return;
        }
        float num2       = 0f;
        bool  condition3 = departmentOfTheTreasury.TryGetResourceStockValue(empire, empty, out num2, true);

        Diagnostics.Assert(condition3);
        if (num2 > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.OwnedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.OwnedStrategicRessourcesCount++;
            }
            return;
        }
        if (resourceType == ResourceDefinition.Type.Luxury)
        {
            regionData.NewLuxuryRessourcesCount++;
        }
        else if (resourceType == ResourceDefinition.Type.Strategic)
        {
            regionData.NewStrategicRessourcesCount++;
        }
    }
Пример #3
0
    public override void RefreshContent()
    {
        base.RefreshContent();
        base.Empire.Refresh(false);
        DepartmentOfScience     agency  = base.Empire.GetAgency <DepartmentOfScience>();
        DepartmentOfTheTreasury agency2 = base.Empire.GetAgency <DepartmentOfTheTreasury>();

        this.ComputeCurrentEraNumber();
        this.CurrentEraNumber.Text = AgeUtils.ToRoman(this.currentEraNumber);
        this.ResearchErasTable.RefreshChildrenIList <ResearchEraFrame.TechnologyEra>(this.eras, this.refreshEraDelegate, true, false);
        Construction construction = agency.ResearchQueue.Peek();
        bool         flag         = construction != null;
        float        quantity;

        if (flag)
        {
            quantity = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.Empire.SimulationObject, construction.ConstructibleElement, DepartmentOfTheTreasury.Resources.EmpireResearch);
        }
        else
        {
            quantity = agency.GetResearchPropertyValue(SimulationProperties.TechnologyCost);
        }
        this.TechnologyCostValue.Text = GuiFormater.FormatQuantity(quantity, SimulationProperties.EmpireResearch, 1);
        float quantity2;

        agency2.TryGetNetResourceValue(base.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpireResearch, out quantity2, false);
        this.EmpireOutputValue.Text = GuiFormater.FormatQuantity(quantity2, SimulationProperties.EmpireResearch, 0);
        if (flag)
        {
            float num = agency2.ComputeConstructionProgress(base.Empire, construction);
            this.ResearchProgress.Text = Mathf.RoundToInt(num * 100f).ToString() + "%";
            int num2 = agency2.ComputeConstructionRemainingTurn(base.Empire, construction);
            num2 = Mathf.Max(num2, 1);
            if (num2 == 2147483647)
            {
                this.ResearchTurns.Text = GuiFormater.Infinite.ToString();
            }
            else
            {
                this.ResearchTurns.Text = num2.ToString();
            }
            TechnologyDefinition technologyDefinition = construction.ConstructibleElement as TechnologyDefinition;
            if (technologyDefinition != null)
            {
                this.TechnologyName.Text   = DepartmentOfScience.GetTechnologyTitle(technologyDefinition);
                this.TechnologyImage.Image = DepartmentOfScience.GetTechnologyImage(technologyDefinition, GuiPanel.IconSize.Small);
            }
            DepartmentOfScience.BuildTechnologyTooltip(technologyDefinition, base.Empire, this.TechnologyName.AgeTransform.AgeTooltip, MultipleConstructibleTooltipData.TechnologyState.Normal);
        }
        else
        {
            this.TechnologyName.Text   = "%ResearchNoneTitle";
            this.TechnologyImage.Image = null;
            this.ResearchProgress.Text = "%ResearchVoidSymbol";
            this.ResearchTurns.Text    = "%ResearchVoidSymbol";
            if (this.TechnologyName.AgeTransform.AgeTooltip != null)
            {
                this.TechnologyName.AgeTransform.AgeTooltip.Class      = string.Empty;
                this.TechnologyName.AgeTransform.AgeTooltip.Content    = string.Empty;
                this.TechnologyName.AgeTransform.AgeTooltip.ClientData = null;
            }
            if (this.TechnologyImage.AgeTransform.AgeTooltip != null)
            {
                this.TechnologyImage.AgeTransform.AgeTooltip.Class      = string.Empty;
                this.TechnologyImage.AgeTransform.AgeTooltip.Content    = string.Empty;
                this.TechnologyImage.AgeTransform.AgeTooltip.ClientData = null;
            }
        }
        IDownloadableContentService service = Services.GetService <IDownloadableContentService>();

        if (service != null && service.IsShared(DownloadableContent11.ReadOnlyName) && base.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1))
        {
            this.TechnologyStatsGroup.Visible = false;
            this.ResearchBuyoutButton.AgeTransform.Visible = true;
            this.ResearchCompletionGroup.Visible           = false;
            this.RefreshBuyout(this.ResearchBuyoutButton);
            return;
        }
        this.TechnologyStatsGroup.Visible = true;
        this.ResearchBuyoutButton.AgeTransform.Visible = false;
        this.ResearchCompletionGroup.Visible           = true;
    }
Пример #4
0
    public static void GetCostAndTurn(Amplitude.Unity.Gui.IGuiService guiService, DepartmentOfTheTreasury departmentOfTheTreasury, SimulationObjectWrapper context, out string costString, out int turn)
    {
        turn = 0;
        StringBuilder stringBuilder = new StringBuilder();

        if (PanelFeatureCost.costByResource.Count > 0)
        {
            bool flag = false;
            IDatabase <ResourceDefinition> database = Databases.GetDatabase <ResourceDefinition>(false);
            foreach (KeyValuePair <StaticString, PanelFeatureCost.CostResume> keyValuePair in PanelFeatureCost.costByResource)
            {
                if (keyValuePair.Key == SimulationProperties.Population)
                {
                    stringBuilder.Append(GuiFormater.FormatGui(keyValuePair.Value.Cost, false, true, false, 1));
                    stringBuilder.Append(guiService.FormatSymbol(keyValuePair.Key));
                }
                else if (keyValuePair.Key == DepartmentOfTheTreasury.Resources.FreeBorough)
                {
                    stringBuilder.Append(GuiFormater.FormatGui(keyValuePair.Value.Cost, false, true, false, 1));
                    stringBuilder.Append(guiService.FormatSymbol(keyValuePair.Key));
                    float num;
                    if (!departmentOfTheTreasury.TryGetResourceStockValue(context.SimulationObject, DepartmentOfTheTreasury.Resources.QueuedFreeBorough, out num, true))
                    {
                        Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                        {
                            DepartmentOfTheTreasury.Resources.QueuedFreeBorough,
                            context.SimulationObject.Name
                        });
                    }
                    else
                    {
                        stringBuilder.Append(string.Format(AgeLocalizer.Instance.LocalizeString("%CityFreeBoroughsLeft"), num));
                    }
                }
                else
                {
                    float              cost = keyValuePair.Value.Cost;
                    StaticString       key  = keyValuePair.Key;
                    ResourceDefinition resourceDefinition;
                    if (!database.TryGetValue(key, out resourceDefinition))
                    {
                        Diagnostics.LogError("Invalid resource name. The resource {0} does not exist in the resource database.", new object[]
                        {
                            key
                        });
                    }
                    else
                    {
                        string value = guiService.FormatSymbol(resourceDefinition.GetName(departmentOfTheTreasury.Empire));
                        if (!string.IsNullOrEmpty(value))
                        {
                            global::Empire empire = null;
                            if (context is City)
                            {
                                empire = (context as City).Empire;
                            }
                            else if (context is global::Empire)
                            {
                                empire = (context as global::Empire);
                            }
                            if (empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitMimics2) && key == DepartmentOfTheTreasury.Resources.Production)
                            {
                                ResourceDefinition resourceDefinition2;
                                if (!database.TryGetValue(SimulationProperties.CityGrowth, out resourceDefinition2))
                                {
                                    Diagnostics.LogError("Invalid resource name. The resource {0} does not exist in the resource database.", new object[]
                                    {
                                        key
                                    });
                                    continue;
                                }
                                value = guiService.FormatSymbol(resourceDefinition2.GetName(departmentOfTheTreasury.Empire));
                                if (string.IsNullOrEmpty(value))
                                {
                                    continue;
                                }
                            }
                            float num2;
                            if (!departmentOfTheTreasury.TryGetResourceStockValue(context.SimulationObject, key, out num2, true))
                            {
                                num2 = 0f;
                            }
                            if (keyValuePair.Value.Instant && num2 < cost)
                            {
                                AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                                flag = true;
                            }
                            stringBuilder.Append(GuiFormater.FormatGui(cost, false, true, false, 1));
                            stringBuilder.Append(value);
                            if (flag)
                            {
                                stringBuilder.Append("#REVERT#");
                                flag = false;
                            }
                            if (!keyValuePair.Value.Instant)
                            {
                                float num3;
                                if (!departmentOfTheTreasury.TryGetNetResourceValue(context.SimulationObject, key, out num3, true))
                                {
                                    num3 = 0f;
                                }
                                if (cost > num2)
                                {
                                    if (num3 <= 0f)
                                    {
                                        turn = int.MaxValue;
                                    }
                                    else
                                    {
                                        int num4 = Mathf.CeilToInt((cost - num2) / num3);
                                        if (num4 > turn)
                                        {
                                            turn = num4;
                                        }
                                    }
                                }
                            }
                            stringBuilder.Append(" ");
                        }
                    }
                }
            }
        }
        costString = stringBuilder.ToString();
        if (string.IsNullOrEmpty(costString))
        {
            costString = "-";
        }
    }
    private void UpdateAccountBalance(StaticString resourceName, int[] accountIndexForResource)
    {
        DepartmentOfTheTreasury agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheTreasury>();
        float num = 0f;
        float estimatedNetOutcome = 0f;

        agency.TryGetNetResourceValue(base.AIEntity.Empire, resourceName, out estimatedNetOutcome, false);
        float num2 = 0f;

        for (int i = 0; i < accountIndexForResource.Length; i++)
        {
            Account account = this.accounts[accountIndexForResource[i]];
            account.EstimatedNetOutcome = estimatedNetOutcome;
            if (account.MaxAccount >= 0f && account.MaxAccount <= account.EstimatedBalance)
            {
                account.EstimatedBalance = account.MaxAccount;
                num += account.MaxAccount;
            }
            else
            {
                num  += account.EstimatedBalance;
                num2 += account.CurrentProfitPercent;
            }
        }
        float num3 = 0f;

        if (num2 == 0f || !agency.TryGetResourceStockValue(base.AIEntity.Empire, resourceName, out num3, false) || num3 == 0f)
        {
            num3 = 0f;
            for (int j = 0; j < accountIndexForResource.Length; j++)
            {
                this.accounts[accountIndexForResource[j]].EstimatedBalance = 0f;
            }
            return;
        }
        float num4 = num3;

        num4 -= num;
        if (Mathf.Abs(num4) <= (float)accountIndexForResource.Length)
        {
            return;
        }
        if (num4 < 0f)
        {
            for (int k = 0; k < accountIndexForResource.Length; k++)
            {
                Account account2 = this.accounts[accountIndexForResource[k]];
                if (account2.CurrentProfitPercent < 0.01f)
                {
                    num4 += account2.EstimatedBalance;
                    account2.EstimatedBalance = 0f;
                    if (num4 >= 0f)
                    {
                        account2.EstimatedBalance = num4;
                        break;
                    }
                }
            }
        }
        int num5 = 0;

        while (Mathf.Abs(num4) > 0.1f && num5 < 100)
        {
            num5++;
            float num6 = 0f;
            for (int l = 0; l < accountIndexForResource.Length; l++)
            {
                Account account3 = this.accounts[accountIndexForResource[l]];
                if (num4 <= 0f || account3.MaxAccount < 0f || account3.MaxAccount > account3.EstimatedBalance)
                {
                    int   index = accountIndexForResource[l];
                    float num7  = num4 * (account3.CurrentProfitPercent / num2);
                    account3.EstimatedBalance += num7;
                    num6 += num7;
                    if (account3.EstimatedBalance < 0f)
                    {
                        num6 -= this.accounts[index].EstimatedBalance;
                        account3.EstimatedBalance = 0f;
                    }
                    if (account3.MaxAccount >= 0f && account3.MaxAccount < account3.EstimatedBalance)
                    {
                        num6 += account3.EstimatedBalance - account3.MaxAccount;
                        account3.EstimatedBalance = account3.MaxAccount;
                    }
                    if (num6 == num4)
                    {
                        break;
                    }
                }
            }
            num4 -= num6;
            num2  = 0f;
            for (int m = 0; m < accountIndexForResource.Length; m++)
            {
                Account account4 = this.accounts[accountIndexForResource[m]];
                if (account4.MaxAccount < 0f || account4.MaxAccount > account4.EstimatedBalance)
                {
                    num2 += this.accounts[accountIndexForResource[m]].CurrentProfitPercent;
                }
            }
        }
        if (num5 >= 100)
        {
            num2 = 0f;
            for (int n = 0; n < accountIndexForResource.Length; n++)
            {
                num2 += this.accounts[accountIndexForResource[n]].CurrentProfitPercent;
            }
            for (int num8 = 0; num8 < accountIndexForResource.Length; num8++)
            {
                Account account5 = this.accounts[accountIndexForResource[num8]];
                account5.EstimatedBalance = num3 * (this.accounts[accountIndexForResource[num8]].CurrentProfitPercent / num2);
            }
            Diagnostics.LogWarning("Account manager took too much time. Empire = {0}, resource = {1}", new object[]
            {
                base.AIEntity.Empire.Index,
                resourceName
            });
        }
    }