Beispiel #1
0
        public static IBitmap ToBitmap(this ITile tile, TileSettings settings = null, Player player = null)
        {
            if (settings == null)
            {
                settings = TileSettings.Default;
            }

            IBitmap output = new Picture(16, 16, Palette);

            output.AddLayer(MapTile.TileBase(tile));
            if (GFX256 && settings.Improvements && tile.DrawIrrigation())
            {
                output.AddLayer(MapTile.Irrigation);
            }
            output.AddLayer(MapTile.TileLayer(tile));
            output.AddLayer(MapTile.TileSpecial(tile));

            // Add tile improvements
            if (tile.Type != Terrain.River && settings.Improvements)
            {
                if (!GFX256 && tile.DrawIrrigation())
                {
                    output.AddLayer(MapTile.Irrigation);
                }
                if (tile.DrawMine())
                {
                    output.AddLayer(MapTile.Mine);
                }
            }
            if (settings.Roads)
            {
                if (tile.DrawRoad())
                {
                    output.AddLayer(MapTile.Road[tile.DrawRoadDirections()]);
                }
                if (tile.DrawRailRoad())
                {
                    output.AddLayer(MapTile.RailRoad[tile.DrawRailRoadDirections()]);
                }
            }
            if (tile.DrawFortress())
            {
                output.AddLayer(MapTile.Fortress);
            }
            if (tile.DrawHut())
            {
                output.AddLayer(MapTile.Hut);
            }

            if (player != null)
            {
                Direction fog = Direction.None;
                foreach (Direction direction in new[] { West, North, East, South })
                {
                    if (player.Visible(tile, direction))
                    {
                        continue;
                    }
                    fog += (int)direction;
                }
                if (fog != None)
                {
                    output.AddLayer(MapTile.Fog[fog]);
                }
            }

            if (settings.Cities && tile.City != null)
            {
                output.AddLayer(Icons.City(tile.City, smallFont: settings.CitySmallFonts));
                if (settings.ActiveUnit && tile.Units.Any(u => u == Game.ActiveUnit && u.Owner != Game.PlayerNumber(player)))
                {
                    output.AddLayer(tile.UnitsToPicture(), -1, -1, dispose: true);
                }
            }

            if ((settings.EnemyUnits || settings.Units) && (tile.City == null || tile.Units.Any(u => u == Game.ActiveUnit)))
            {
                int unitCount = tile.Units.Count(u => settings.Units || player == null || u.Owner != Game.PlayerNumber(player));
                if (unitCount > 0)
                {
                    output.AddLayer(tile.UnitsToPicture(), dispose: true);
                }
            }

            return(output);
        }