Exemple #1
0
        /// <summary>
        /// Gets, for a <see cref="CityPivot"/>, the list of available <see cref="MapSquarePivot"/> (for regular citizens).
        /// </summary>
        /// <param name="city">The city.</param>
        /// <returns>List of <see cref="MapSquarePivot"/>.</returns>
        internal IReadOnlyCollection <MapSquarePivot> ComputeCityAvailableMapSquares(CityPivot city)
        {
            var sq = city.MapSquareLocation;

            var citySquares = new List <MapSquarePivot>();

            for (var i = sq.Row - 2; i <= sq.Row + 2; i++)
            {
                for (var j = sq.Column - 2; j <= sq.Column + 2; j++)
                {
                    var mapSquare = Map[i, j];
                    if (mapSquare != null &&
                        mapSquare != sq &&
                        !IsCity(mapSquare) &&
                        !OccupiedByCity(mapSquare) &&
                        !(i == sq.Row - 2 && (j == sq.Column - 2 || j == sq.Column + 2)) &&
                        !(i == sq.Row + 2 && (j == sq.Column - 2 || j == sq.Column + 2)))
                    {
                        citySquares.Add(mapSquare);
                    }
                }
            }

            return(citySquares);
        }
Exemple #2
0
        /// <summary>
        /// Changes the city's production.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <param name="buildableDefaultInstance">The buildable item (instance template).</param>
        /// <exception cref="ArgumentNullException"><paramref name="city"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="buildableDefaultInstance"/> is <c>Null</c>.</exception>
        /// <exception cref="InvalidOperationException">Failure to create an instance of the specified production type !</exception>
        /// <exception cref="ArgumentException">The city is not manage by the human player !</exception>
        public void ChangeCityProduction(CityPivot city, BuildablePivot buildableDefaultInstance)
        {
            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            if (buildableDefaultInstance == null)
            {
                throw new ArgumentNullException(nameof(buildableDefaultInstance));
            }

            if (!HumanPlayer.Cities.Contains(city))
            {
                throw new ArgumentException("The city is not manage by the human player !", nameof(city));
            }

            BuildablePivot instanceToBuild = buildableDefaultInstance;

            if (buildableDefaultInstance.Is <UnitPivot>())
            {
                instanceToBuild = (buildableDefaultInstance as UnitPivot).CreateInstance(city, null, null);
                if (instanceToBuild == null)
                {
                    throw new InvalidOperationException($"Failure to create an instance of the specified production type !");
                }
            }

            city.ChangeProduction(instanceToBuild);
        }
Exemple #3
0
        /// <summary>
        /// Reset the <see cref="CitizenTypePivot"/> of every citizens of a city.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <exception cref="ArgumentNullException"><paramref name="city"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentException">The city is not manage by the human player !</exception>
        public void ResetCitizens(CityPivot city)
        {
            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            if (!HumanPlayer.Cities.Contains(city))
            {
                throw new ArgumentException("The city is not manage by the human player !", nameof(city));
            }

            city.ResetCitizens();
        }
Exemple #4
0
        internal static void DrawMapCity(this Panel panel, CityPivot city, double defaultDim, int cityZindex, bool skipPreviousCheck,
                                         Tuple <int, int> gridPositionOffset = null, Action <object, MouseButtonEventArgs> mouseLeftButtonDownCallback = null)
        {
            if (panel == null)
            {
                return;
            }

            if (!skipPreviousCheck)
            {
                panel.CleanPreviousChildrenByTag(city);
            }

            Label lbl = new Label
            {
                Width      = defaultDim,
                Height     = defaultDim,
                Content    = string.Concat(city.CitizensCount, "\r\n", city.Name),
                Background = Brushes.Transparent,
                FontSize   = 14,
                VerticalContentAlignment   = VerticalAlignment.Center,
                HorizontalContentAlignment = HorizontalAlignment.Center
            };

            lbl.SetValue(Grid.RowProperty, city.MapSquareLocation.Row - (gridPositionOffset == null ? 0 : gridPositionOffset.Item1));
            lbl.SetValue(Grid.ColumnProperty, city.MapSquareLocation.Column - (gridPositionOffset == null ? 0 : gridPositionOffset.Item2));
            lbl.SetValue(Panel.ZIndexProperty, cityZindex + 1);
            lbl.Tag = city;

            Rectangle img = new Rectangle
            {
                Width  = defaultDim,
                Height = defaultDim,
                Fill   = new SolidColorBrush((Color)ColorConverter.ConvertFromString(CIVILIZATION_COLORS[city.Player.Civilization.Name]))
            };

            img.SetValue(Grid.RowProperty, city.MapSquareLocation.Row - (gridPositionOffset == null ? 0 : gridPositionOffset.Item1));
            img.SetValue(Grid.ColumnProperty, city.MapSquareLocation.Column - (gridPositionOffset == null ? 0 : gridPositionOffset.Item2));
            img.SetValue(Panel.ZIndexProperty, cityZindex);
            img.Tag = city;

            if (mouseLeftButtonDownCallback != null)
            {
                img.MouseLeftButtonDown += new MouseButtonEventHandler(mouseLeftButtonDownCallback);
            }

            panel.Children.Add(lbl);
            panel.Children.Add(img);
        }
Exemple #5
0
        /// <summary>
        /// Gets the list of available buildable items for the specified city.
        /// </summary>
        /// <param name="city">The city</param>
        /// <param name="indexOfDefault">Out; the index of current production in the output list. <c>-1</c> if not found.</param>
        /// <returns>List of <see cref="BuildablePivot"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="city"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentException">The city is not manage by the human player !</exception>
        public IReadOnlyCollection <BuildablePivot> GetBuildableItemsForCity(CityPivot city, out int indexOfDefault)
        {
            indexOfDefault = -1;

            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            if (!HumanPlayer.Cities.Contains(city))
            {
                throw new ArgumentException("The city is not manage by the human player !", nameof(city));
            }

            return(HumanPlayer.GetBuildableItemsForCity(city, out indexOfDefault));
        }
Exemple #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="engine">The <see cref="EnginePivot"/>.</param>
        /// <param name="city">The <see cref="CityPivot"/> to manage.</param>
        public CityWindow(EnginePivot engine, CityPivot city)
        {
            InitializeComponent();

            for (int i = 0; i < COUNT_SHOW_CITY_SQUARES; i++)
            {
                GridCityMap.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(CITY_GRID_SIZE)
                });
                GridCityMap.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(CITY_GRID_SIZE)
                });
            }

            _engine = engine;
            _city   = city;

            RefreshDisplay();
        }
Exemple #7
0
        private void DrawMiniMapCity(CityPivot city, bool skipPreviousCheck)
        {
            if (!skipPreviousCheck)
            {
                MiniMapCanvas.CleanPreviousChildrenByTag(city);
            }

            Rectangle imgMini = new Rectangle
            {
                Width  = _minimapSquareSize,
                Height = _minimapSquareSize,
                Fill   = Brushes.White
            };

            imgMini.SetValue(Canvas.TopProperty, city.MapSquareLocation.Row * _minimapSquareSize);
            imgMini.SetValue(Canvas.LeftProperty, city.MapSquareLocation.Column * _minimapSquareSize);
            imgMini.Tag = city;
            MiniMapCanvas.Children.Add(imgMini);
        }
Exemple #8
0
        /// <summary>
        /// Checks of a <see cref="CityPivot"/> is near the coast.
        /// </summary>
        /// <param name="city">The city to check.</param>
        /// <returns><c>True</c> if near the coast; <c>False otherwise.</c></returns>
        internal bool GetCityIsCoast(CityPivot city)
        {
            var sq = city.MapSquareLocation;

            var citySquares = new List <MapSquarePivot>();

            for (var i = sq.Row - 1; i <= sq.Row + 1; i++)
            {
                for (var j = sq.Column - 1; j <= sq.Column + 1; j++)
                {
                    var mapSquare = Map[i, j];
                    if (mapSquare != null && mapSquare.Biome.IsSeaType)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #9
0
        private void DisplayCityName(CityPivot city)
        {
            bool stuckOnLeft  = city.OnLeftBorder();
            bool stuckOnRight = city.OnRightBorder(_engine.Map.Width);

            var citynameBlock = new TextBlock
            {
                HorizontalAlignment = stuckOnLeft ? HorizontalAlignment.Left :
                                      (stuckOnRight ? HorizontalAlignment.Right : HorizontalAlignment.Center),
                VerticalAlignment = VerticalAlignment.Bottom,
                Text          = $"{city.Name} - {city.CitizensCount}",
                TextAlignment = TextAlignment.Center,
                Background    = Brushes.White
            };

            citynameBlock.SetValue(Grid.RowProperty, city.MapSquareLocation.Row);
            citynameBlock.SetValue(Grid.ColumnProperty, city.MapSquareLocation.Column - (stuckOnLeft ? 0 : 1));
            citynameBlock.SetValue(Grid.ColumnSpanProperty, stuckOnLeft || stuckOnRight ? 2 : 3);
            citynameBlock.SetValue(Panel.ZIndexProperty, CITY_ZINDEX + 1);
            citynameBlock.Tag = city;
            MapGrid.Children.Add(citynameBlock);
        }
Exemple #10
0
        /// <summary>
        /// Gets a specialist citizen of the specified city (if any), and makes it a regular worker on the specified location.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <param name="mapSquare">The location.</param>
        /// <exception cref="ArgumentNullException"><paramref name="city"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapSquare"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentException">The city is not manage by the human player !</exception>
        /// <exception cref="ArgumentException">The specified square can't be used by the citizen !</exception>
        public void ChangeAnySpecialistToRegular(CityPivot city, MapSquarePivot mapSquare)
        {
            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            if (mapSquare == null)
            {
                throw new ArgumentNullException(nameof(mapSquare));
            }

            if (!HumanPlayer.Cities.Contains(city))
            {
                throw new ArgumentException("The city is not manage by the human player !", nameof(city));
            }

            if (!ComputeCityAvailableMapSquares(city).Contains(mapSquare))
            {
                throw new ArgumentException("The specified square can't be used by the citizen !");
            }

            city.ChangeAnySpecialistToRegular(mapSquare);
        }
Exemple #11
0
 private TransportPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 0, 3, 4, 50, AdvancePivot.Industrialization, null, 450, null, location, player, false, false, 1, 8, false, 1)
 {
 }
Exemple #12
0
 private ArmorPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 10, 5, 3, 80, AdvancePivot.Automobile, null, 960, null, 0, location, player)
 {
 }
Exemple #13
0
 private LegionPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 3, 1, 1, 20, AdvancePivot.IronWorking, AdvancePivot.Conscription, 120, null, 0, location, player)
 {
 }
Exemple #14
0
 private CaravanPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 0, 1, 1, 50, AdvancePivot.Trade, null, 450, null, 0, location, player, ignoreControlZone: true, maintenanceCost: 0)
 {
 }
Exemple #15
0
 private KnightPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 4, 2, 2, 40, AdvancePivot.Chivalry, AdvancePivot.Automobile, 320, null, 0, location, player)
 {
 }
Exemple #16
0
 private TriremePivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 1, 0, 3, 40, AdvancePivot.MapMaking, AdvancePivot.Navigation, 320, null, location, player, false, false, 1, 2, false, 1)
 {
 }
Exemple #17
0
 private CarrierPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 1, 12, 5, 160, AdvancePivot.AdvancedFlight, null, 3200, null, location, player, false, false, 2, 8, false, 1)
 {
 }
Exemple #18
0
 /// <summary>
 /// Static constructior.
 /// </summary>
 /// <param name="city">The <see cref="UnitPivot.City"/> value.</param>
 /// <param name="location">The <see cref="UnitPivot.MapSquareLocation"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <param name="player">The <see cref="UnitPivot.Player"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <returns>An instance of <see cref="TransportPivot"/>.</returns>
 internal static TransportPivot CreateAtLocation(CityPivot city, MapSquarePivot location, PlayerPivot player)
 {
     return(new TransportPivot(city, location, player));
 }
Exemple #19
0
        /// <summary>
        /// Gets an area of 7x7 <see cref="MapSquarePivot"/> around a city.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <returns>A dictionary with the map square as key, and a tuple [citizen on square / square used by another city] as value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="city"/> is <c>Null</c>.</exception>
        public Dictionary <MapSquarePivot, Tuple <CitizenPivot, bool> > GetMapSquaresAroundCity(CityPivot city)
        {
            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            var result = new Dictionary <MapSquarePivot, Tuple <CitizenPivot, bool> >();

            for (var i = city.MapSquareLocation.Row - 3; i <= city.MapSquareLocation.Row + 3; i++)
            {
                for (var j = city.MapSquareLocation.Column - 3; j <= city.MapSquareLocation.Column + 3; j++)
                {
                    var msq = Map[i, j];
                    if (msq != null)
                    {
                        result.Add(msq, new Tuple <CitizenPivot, bool>(
                                       city.AreaWithoutCityMapSquares.SingleOrDefault(ams => ams.MapSquare == msq)?.Citizen, OccupiedByCity(msq, city)));
                    }
                }
            }

            return(result);
        }
Exemple #20
0
 private SubmarinePivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 8, 2, 3, 50, AdvancePivot.MassProduction, null, 450, null, location, player, false, false, 2, 0, false, 1)
 {
 }
Exemple #21
0
 /// <summary>
 /// Static constructior.
 /// </summary>
 /// <param name="city">The <see cref="UnitPivot.City"/> value.</param>
 /// <param name="location">The <see cref="UnitPivot.MapSquareLocation"/> value if <paramref name="city"/> is <c>Null</c>.</param>
 /// <param name="player">The <see cref="UnitPivot.Player"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <returns>An instance of <see cref="MusketeerPivot"/>.</returns>
 internal static MusketeerPivot CreateAtLocation(CityPivot city, MapSquarePivot location, PlayerPivot player)
 {
     return(new MusketeerPivot(city, location, player));
 }
Exemple #22
0
 private CavalryPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 2, 1, 2, 20, AdvancePivot.HorsebackRiding, AdvancePivot.Conscription, 120, null, 0, location, player)
 {
 }
Exemple #23
0
 private DiplomatPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 0, 0, 2, 30, AdvancePivot.Writing, null, 210, null, 0, location, player, ignoreControlZone: true, maintenanceCost: 0)
 {
 }
Exemple #24
0
 private bool OccupiedByCity(MapSquarePivot mapSquare, CityPivot exceptCity = null)
 {
     return(GetEveryCities().Any(c => (exceptCity == null || exceptCity != c) && c.AreaMapSquares.Any(ams => ams.MapSquare == mapSquare)));
 }
Exemple #25
0
 private MusketeerPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 2, 3, 1, 30, AdvancePivot.Gunpowder, AdvancePivot.Conscription, 210, null, 0, location, player)
 {
 }
Exemple #26
0
 private BomberPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 12, 1, 8, 120, AdvancePivot.AdvancedFlight, null, 1920, null, location, player, false, false, true, 2, 2, 1)
 {
 }
Exemple #27
0
 private FrigatePivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 2, 2, 3, 40, AdvancePivot.Magnetism, AdvancePivot.Industrialization, 320, null, location, player, false, false, 1, 4, true, 1)
 {
 }
Exemple #28
0
 private CatapultPivot(CityPivot city, MapSquarePivot location, PlayerPivot player) :
     base(city, 6, 1, 1, 40, AdvancePivot.Mathematics, AdvancePivot.Metallurgy, 320, null, 0, location, player)
 {
 }
Exemple #29
0
 /// <summary>
 /// Static constructior.
 /// </summary>
 /// <param name="city">The <see cref="UnitPivot.City"/> value.</param>
 /// <param name="location">The <see cref="UnitPivot.MapSquareLocation"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <param name="player">The <see cref="UnitPivot.Player"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <returns>An instance of <see cref="SubmarinePivot"/>.</returns>
 internal static SubmarinePivot CreateAtLocation(CityPivot city, MapSquarePivot location, PlayerPivot player)
 {
     return(new SubmarinePivot(city, location, player));
 }
Exemple #30
0
 /// <summary>
 /// Static constructior.
 /// </summary>
 /// <param name="city">The <see cref="UnitPivot.City"/> value.</param>
 /// <param name="location">The <see cref="UnitPivot.MapSquareLocation"/> value if <paramref name="city"/> is <c>Null</c>.</param>
 /// <param name="player">The <see cref="UnitPivot.Player"/> value, if <paramref name="city"/> is <c>Null</c>.</param>
 /// <returns>An instance of <see cref="CatapultPivot"/>.</returns>
 internal static CatapultPivot CreateAtLocation(CityPivot city, MapSquarePivot location, PlayerPivot player)
 {
     return(new CatapultPivot(city, location, player));
 }