public static string LabelFrom(ImprovementLevel improvementLevel)
        {
            if (string.IsNullOrWhiteSpace(improvementLevel.BuildLabel))
            {
                return($"{Labels.For(LabelIndex.Build)} {improvementLevel.Name}");
            }

            if (!improvementLevel.BuildLabel.StartsWith("~") || !Enum.TryParse(typeof(LabelIndex),
                                                                               improvementLevel.BuildLabel.Substring(1), out var index))
            {
                return(improvementLevel.BuildLabel);
            }

            var labelIndex = (LabelIndex)index;

            return(Labels.For(labelIndex));
        }
Exemplo n.º 2
0
    public void DrawStatusPanel(Graphics eGraphics, PanelStyle style, int unitPanelHeight)
    {
        var activeTile = _unit.CurrentLocation;

        Draw.Text(eGraphics, Labels.For(LabelIndex.MovingUnits), style.Font, Colors.White, new Point(119, 10), true, true, Colors.Black,
                  1, 0);

        // Show active unit info
        var activeUnit = _game.ActiveUnit;

        Draw.Unit(eGraphics, activeUnit, false, 1, new Point(7, 27));

        // Show move points correctly
        var commonMultiplier    = _game.Rules.Cosmic.MovementMultiplier;
        var remainingFullPoints = activeUnit.MovePoints / commonMultiplier;
        var fractionalMove      = activeUnit.MovePoints % commonMultiplier;

        string moveText;

        if (fractionalMove > 0)
        {
            var gcf = Utils.GreatestCommonFactor(fractionalMove, commonMultiplier);
            moveText =
                $"{Labels.For(LabelIndex.Moves)}: {(remainingFullPoints > 0 ? remainingFullPoints : "")} {fractionalMove / gcf}/{commonMultiplier / gcf}";
        }
        else
        {
            moveText = $"{Labels.For(LabelIndex.Moves)}: {remainingFullPoints}";
        }

        Draw.Text(eGraphics, moveText, style.Font, style.FrontColor, new Point(79, 25), false, false,
                  style.BackColor, 1, 1);

        // Show other unit info
        var cityName = (activeUnit.HomeCity == null) ? Labels.For(LabelIndex.NONE) : activeUnit.HomeCity.Name;

        Draw.Text(eGraphics, cityName, style.Font, style.FrontColor, new Point(79, 43), false, false,
                  style.BackColor, 1, 1);
        Draw.Text(eGraphics, _game.GetActiveCiv.Adjective, style.Font, style.FrontColor, new Point(79, 61), false,
                  false, style.BackColor, 1, 1);
        var column = 83;

        Draw.Text(eGraphics, activeUnit.Veteran ? $"{activeUnit.Name} ({Labels.For(LabelIndex.Veteran)})" :activeUnit.Name, style.Font, style.FrontColor, new Point(5, column), false,
                  false, style.BackColor, 1, 1);
        column += 18;

        if (activeTile != null)
        {
            Draw.Text(eGraphics, $"({activeTile.Name})", style.Font, style.FrontColor, new Point(5, column),
                      false,
                      false, style.BackColor, 1, 1);

            // If road/railroad/irrigation/farmland/mine present
            var improvements = activeTile.Improvements.Select(c => new
                                                              { Imp = _game.TerrainImprovements[c.Improvement], Const = c }).ToList();

            var improvementText = string.Join(", ",
                                              improvements.Where(i => i.Imp.ExclusiveGroup != ImprovementTypes.DefenceGroup && !i.Imp.Negative)
                                              .Select(i => i.Imp.Levels[i.Const.Level].Name));

            if (!string.IsNullOrWhiteSpace(improvementText))
            {
                column += 18;
                Draw.Text(eGraphics, $"({improvementText})", style.Font, style.FrontColor,
                          new Point(5, column), false,
                          false, style.BackColor, 1, 1);
            }

            // If airbase/fortress present
            if (improvements.Any(i => i.Imp.ExclusiveGroup == ImprovementTypes.DefenceGroup))
            {
                column += 18;
                var airbaseText = string.Join(", ",
                                              improvements.Where(i => i.Imp.ExclusiveGroup == ImprovementTypes.DefenceGroup)
                                              .Select(i => i.Imp.Levels[i.Const.Level].Name));
                Draw.Text(eGraphics, $"({airbaseText})", style.Font, style.FrontColor, new Point(5, column),
                          false,
                          false, style.BackColor, 1, 1);
            }

            // If pollution present
            var pollutionText = string.Join(", ",
                                            improvements.Where(i => i.Imp.Negative)
                                            .Select(i => i.Imp.Levels[i.Const.Level].Name));
            if (!string.IsNullOrWhiteSpace(pollutionText))
            {
                column += 18;
                Draw.Text(eGraphics, $"({pollutionText})", style.Font, style.FrontColor, new Point(5, column), false,
                          false,
                          style.BackColor, 1, 1);
            }

            column += 5;

            // Show info for other units on the tile
            int drawCount = 0;
            foreach (var unit in activeTile.UnitsHere.Where(u => u != activeUnit))
            {
                // First check if there is vertical space still left for drawing in panel
                if (column + 69 > unitPanelHeight)
                {
                    break;
                }

                // Draw unit
                Draw.Unit(eGraphics, unit, false, 1, new Point(7, column + 27));
                // Show other unit info
                column  += 20;
                cityName = (unit.HomeCity == null) ? Labels.For(LabelIndex.NONE) : unit.HomeCity.Name;
                Draw.Text(eGraphics, cityName, style.Font, style.FrontColor, new Point(80, column), false,
                          false,
                          style.BackColor, 1, 1);
                column += 18;
                Draw.Text(eGraphics, _game.Order2string(unit.Order), style.Font, style.FrontColor,
                          new Point(80, column),
                          false, false, style.BackColor, 1, 1);
                column += 18;
                Draw.Text(eGraphics, unit.Veteran ? $"{unit.Name} ({Labels.For(LabelIndex.Veteran)})" : unit.Name, style.Font, style.FrontColor, new Point(80, column), false,
                          false,
                          style.BackColor, 1, 1);

                //System.Diagnostics.Debug.WriteLine($"{unit.Name} drawn");

                drawCount++;
            }

            // If not all units were drawn print a message
            if (activeTile.UnitsHere.Count - 1 != drawCount)     // -1 because you must not count in active unit
            {
                column  += 22;
                moveText = activeTile.UnitsHere.Count - 1 - drawCount == 1 ? "Unit" : "Units";
                Draw.Text(eGraphics, $"({activeTile.UnitsHere.Count - 1 - drawCount} More {moveText})",
                          style.Font,
                          style.FrontColor, new Point(9, column), false, false, style.BackColor, 1, 1);
            }
        }
    }
Exemplo n.º 3
0
 public override Order Update(Tile activeTile, Unit activeUnit)
 {
     if (activeTile == null || activeUnit == null)
     {
         SetCommandState(OrderStatus.Illegal);
     }
     else
     {
         if (activeUnit.AIrole != AIroleType.Settle)
         {
             SetCommandState(OrderStatus.Illegal, errorPopupKeyword: "ONLYSETTLERS");
         }
         else if (activeTile.Terrain.Impassable)
         {
             SetCommandState();
         }
         else if (activeTile.Type == TerrainType.Ocean)
         {
             SetCommandState(OrderStatus.Disabled, errorPopupKeyword: "CITYATSEA");
         }
         else if (activeTile.IsCityPresent)
         {
             SetCommandState(activeTile.CityHere.Size < _game.Rules.Cosmic.ToExceedCitySizeAqueductNeeded ? OrderStatus.Active : OrderStatus.Disabled, Labels.For(LabelIndex.JoinCity), errorPopupKeyword: "ONLY10");
         }
         else if (activeTile.Neighbours().Any(t => t.IsCityPresent))
         {
             SetCommandState(OrderStatus.Disabled, errorPopupKeyword: "ADJACENTCITY");
         }
         else
         {
             SetCommandState(OrderStatus.Active);
         }
     }
     return(this);
 }