Ejemplo n.º 1
0
    public static string FormatInstantCost(Empire empire, float cost, StaticString resourceName, bool monochromatic = false, int decimals = 1)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();
        float num;

        if (!agency.TryGetResourceStockValue(empire.SimulationObject, resourceName, out num, false))
        {
            Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
            {
                resourceName,
                empire.SimulationObject.Name
            });
        }
        StringBuilder stringBuilder = new StringBuilder();
        bool          flag          = false;

        if (!monochromatic && num < cost)
        {
            AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
            flag = true;
        }
        stringBuilder.Append(GuiFormater.FormatGui(cost, false, decimals == 0, false, decimals));
        if (!monochromatic && flag)
        {
            stringBuilder.Append("#REVERT#");
        }
        stringBuilder.Append(" ");
        stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(resourceName));
        return(stringBuilder.ToString());
    }
Ejemplo n.º 2
0
    private void RefreshOtherEmpiresDropList()
    {
        global::Game game = base.Game as global::Game;

        Diagnostics.Assert(game != null);
        List <DiplomaticRelation> list = (from relation in this.DepartmentOfForeignAffairs.DiplomaticRelations
                                          where relation.OwnerEmpireIndex == this.Empire.Index
                                          select relation).ToList <DiplomaticRelation>();

        list.RemoveAll((DiplomaticRelation diplomaticRelation) => diplomaticRelation.State == null || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Unknown || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Dead);
        this.otherEmpires = (from relation in list
                             select game.Empires[relation.OtherEmpireIndex]).ToArray <global::Empire>();
        List <string> list2 = new List <string>();
        List <string> list3 = new List <string>();

        for (int i = 0; i < this.otherEmpires.Length; i++)
        {
            string text;
            AgeUtils.ColorToHexaKey(this.otherEmpires[i].Color, out text);
            string text2 = string.Concat(new string[]
            {
                text,
                this.otherEmpires[i].LocalizedName,
                " - ",
                this.otherEmpires[i].Faction.LocalizedName,
                "#REVERT#"
            });
            list2.Add(text2);
            list3.Add((!this.otherEmpires[i].IsControlledByAI) ? (text2 + "\n" + AgeLocalizer.Instance.LocalizeString("%CompetitorEmpireTypeHumanDescription")) : (text2 + "\n" + AgeLocalizer.Instance.LocalizeString("%CompetitorEmpireTypeComputerDescription")));
        }
        this.TheirEmpireNameDropList.ItemTable    = list2.ToArray();
        this.TheirEmpireNameDropList.TooltipTable = list3.ToArray();
    }
Ejemplo n.º 3
0
    public static string Colorize(Empire empire, string name)
    {
        string str;

        AgeUtils.ColorToHexaKey(empire.Color, out str);
        return(str + name + "#REVERT#");
    }
Ejemplo n.º 4
0
    public static string FormatCost(Empire empire, IConstructionCost[] costs, bool monochromatic = false, int decimals = 1, SimulationObject context = null)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();

        if (context == null)
        {
            context = empire.SimulationObject;
        }
        StringBuilder stringBuilder = new StringBuilder();

        if (costs != null)
        {
            bool flag = false;
            for (int i = 0; i < costs.Length; i++)
            {
                float value = costs[i].GetValue(empire);
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(" ");
                }
                float num;
                if (!agency.TryGetResourceStockValue(context, costs[i].ResourceName, out num, false))
                {
                    Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                    {
                        costs[i].ResourceName,
                        empire.SimulationObject.Name
                    });
                }
                if (!monochromatic && (costs[i].Instant || costs[i].InstantOnCompletion) && num < value)
                {
                    AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                    flag = true;
                }
                stringBuilder.Append(GuiFormater.FormatGui(value, false, decimals == 0, false, decimals));
                if (!monochromatic && flag)
                {
                    stringBuilder.Append("#REVERT#");
                    flag = false;
                }
                stringBuilder.Append(" ");
                stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(costs[i].ResourceName));
            }
        }
        return(stringBuilder.ToString());
    }
Ejemplo n.º 5
0
    public static string FormatStockCost(Empire empire, ConstructionResourceStock[] stockCosts, bool monochromatic = false, int decimals = 1)
    {
        DepartmentOfTheTreasury agency        = empire.GetAgency <DepartmentOfTheTreasury>();
        StringBuilder           stringBuilder = new StringBuilder();

        if (stockCosts != null)
        {
            bool flag = false;
            for (int i = 0; i < stockCosts.Length; i++)
            {
                float stock = stockCosts[i].Stock;
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(" ");
                }
                float num;
                if (!agency.TryGetResourceStockValue(empire.SimulationObject, stockCosts[i].PropertyName, out num, false))
                {
                    Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                    {
                        stockCosts[i].PropertyName,
                        empire.SimulationObject.Name
                    });
                }
                if (!monochromatic)
                {
                    AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                    flag = true;
                }
                stringBuilder.Append(GuiFormater.FormatGui(stock, false, decimals == 0, false, decimals));
                if (!monochromatic && flag)
                {
                    stringBuilder.Append("#REVERT#");
                    flag = false;
                }
                stringBuilder.Append(" ");
                stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(stockCosts[i].PropertyName));
            }
        }
        return(stringBuilder.ToString());
    }
Ejemplo n.º 6
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 = "-";
        }
    }