示例#1
0
        private void MoveTowards(Tile tile, List <Unit> units, IMapItem target)
        {
            var destination = MovementFunctions.GetPossibleMoves(this, tile, units[0])
                              .OrderBy(t => Utilities.DistanceTo(t, target, _options.FlatEarth)).FirstOrDefault();

            if (destination == null)
            {
                return;
            }

            units.ForEach(b => MovementFunctions.UnitMoved(this, b, destination, tile));
            if (units.Any(b => b.MovePoints > 0))
            {
                MoveTowards(destination, units.Where(b => b.MovePoints > 0).ToList(), target);
            }
        }
示例#2
0
    protected override void Execute(LocalPlayer player)
    {
        //_mainForm.CurrentGameMode = new Goto(_game);
        var popup      = _mainForm.popupBoxList["GOTO"];
        var activeUnit = player.ActiveUnit;
        var islands    = MovementFunctions.GetIslandsFor(activeUnit);
        var cities     = player.Civ.Cities.Where(c =>
                                                 islands.Contains(c.Location.Island) || c.Location.Neighbours().Any(l => islands.Contains(l.Island)))
                         .ToList();
        var dialog = new Civ2dialog(_mainForm, popup, new List <string> {
            activeUnit.Name
        },
                                    listbox: new ListboxDefinition
        {
            LeftText = cities.Select(c => c.Name).ToList()
        });

        dialog.ShowModal();
        if (dialog.SelectedButton == Labels.Ok)
        {
            var city = cities[dialog.SelectedIndex];
            var path = Path.CalculatePathBetween(_game, player.ActiveTile, city.Location, activeUnit.Domain,
                                                 activeUnit.MaxMovePoints, activeUnit.Owner, activeUnit.Alpine, activeUnit.IgnoreZonesOfControl);
            if (path != null)
            {
                activeUnit.Order = OrderType.GoTo;
                activeUnit.GoToX = city.Location.X;
                activeUnit.GoToY = city.Location.Y;
                path.Follow(_game, activeUnit);
                if (activeUnit.MovePoints <= 0)
                {
                    _game.ChooseNextUnit();
                }
            }
        }
    }
示例#3
0
        private void AiTurn()
        {
            foreach (var unit in _activeCiv.Units.Where(u => !u.Dead).ToList())
            {
                var currentTile = unit.CurrentLocation;
                switch (unit.AIrole)
                {
                case AIroleType.Attack:
                    break;

                case AIroleType.Defend:
                    if (currentTile.CityHere != null)
                    {
                        if (currentTile.UnitsHere.Count(u => u != unit && u.AIrole == AIroleType.Defend) <
                            2 + currentTile.CityHere.Size / 3)
                        {
                            if (unit.Order == OrderType.Fortify || unit.Order == OrderType.Fortified)
                            {
                                unit.Order = OrderType.Fortified;
                            }
                            else
                            {
                                unit.Order = OrderType.Fortify;
                            }
                            unit.MovePointsLost = unit.MovePoints;
                        }
                    }
                    else
                    {
                    }
                    break;

                case AIroleType.NavalSuperiority:
                    break;

                case AIroleType.AirSuperiority:
                    break;

                case AIroleType.SeaTransport:
                    break;

                case AIroleType.Settle:
                    if (currentTile.Fertility == -2)
                    {
                        CityActions.AIBuildCity(unit, this);
                    }
                    var cityTile = CurrentMap.CityRadius(currentTile)
                                   .FirstOrDefault(t => t.CityHere != null);
                    if (cityTile == null)
                    {
                        var moreFertile = MovementFunctions.GetPossibleMoves(this, currentTile, unit)
                                          .Where(n => n.Fertility > currentTile.Fertility).OrderByDescending(n => n.Fertility)
                                          .FirstOrDefault();
                        if (moreFertile == null)
                        {
                            CityActions.AIBuildCity(unit, this);
                        }
                        else
                        {
                            if (MovementFunctions.UnitMoved(this, unit, moreFertile, currentTile))
                            {
                                currentTile = moreFertile;
                                if (unit.MovePoints > 0)
                                {
                                    CityActions.AIBuildCity(unit, this);
                                }
                            }
                        }
                    }

                    break;

                case AIroleType.Diplomacy:
                    break;

                case AIroleType.Trade:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                while (unit.MovePoints > 0)
                {
                    var possibleMoves = MovementFunctions.GetPossibleMoves(this, currentTile, unit).ToList();
                    if (unit.AttackBase == 0)
                    {
                        possibleMoves = possibleMoves
                                        .Where(m => m.UnitsHere.Count == 0 || m.UnitsHere[0].Owner == unit.Owner).ToList();
                    }
                    if (possibleMoves.Count == 0)
                    {
                        unit.SkipTurn();
                    }
                    else
                    {
                        var destination = Random.ChooseFrom(possibleMoves);
                        if (destination.UnitsHere.Count > 0 && destination.UnitsHere[0].Owner != unit.Owner)
                        {
                            unit.Order = OrderType.NoOrders;
                            MovementFunctions.AttackAtTile(unit, this, destination);
                        }
                        else if (MovementFunctions.UnitMoved(this, unit, destination, currentTile))
                        {
                            currentTile = destination;
                        }
                    }
                }
            }
            ChoseNextCiv();
        }