Example #1
0
        public override bool HasUpdate(uint gameTick)
        {
            if (_update)
            {
                _canvas.FillLayerTile(_background);
                _canvas.AddBorder(1, 1, 0, 0, 82, 82);
                _canvas.FillRectangle(0, 82, 0, 2, 82);

                ITile[,] tiles = _city.CityRadius;
                for (int xx = 0; xx < 5; xx++)
                {
                    for (int yy = 0; yy < 5; yy++)
                    {
                        ITile tile = tiles[xx, yy];
                        if (tile == null)
                        {
                            continue;
                        }
                        AddLayer(Resources.Instance.GetTile(tile), (xx * 16) + 1, (yy * 16) + 1);
                        if (tile.City != null)
                        {
                            AddLayer(Icons.City(tile.City, smallFont: true), (xx * 16) + 1, (yy * 16) + 1);
                        }
                        else if (tile.Units.Any(u => u.Owner != _city.Owner))
                        {
                            IUnit[] units = tile.Units.Where(u => u.Owner != _city.Owner).ToArray();
                            AddLayer(units[0].GetUnit(units[0].Owner), (xx * 16) + 1, (yy * 16) + 1);
                            if (units.Length > 1)
                            {
                                AddLayer(units[0].GetUnit(units[0].Owner), (xx * 16), (yy * 16));
                            }
                        }
                        if (!Settings.RevealWorld)
                        {
                            if (!Human.Visible(tile, Direction.West))
                            {
                                AddLayer(Resources.Instance.GetFog(Direction.West), (xx * 16) + 1, (yy * 16) + 1);
                            }
                            if (!Human.Visible(tile, Direction.North))
                            {
                                AddLayer(Resources.Instance.GetFog(Direction.North), (xx * 16) + 1, (yy * 16) + 1);
                            }
                            if (!Human.Visible(tile, Direction.East))
                            {
                                AddLayer(Resources.Instance.GetFog(Direction.East), (xx * 16) + 1, (yy * 16) + 1);
                            }
                            if (!Human.Visible(tile, Direction.South))
                            {
                                AddLayer(Resources.Instance.GetFog(Direction.South), (xx * 16) + 1, (yy * 16) + 1);
                            }
                        }

                        if (_city.OccupiedTile(tile))
                        {
                            _canvas.FillRectangle(12, (xx * 16) + 1, (yy * 16) + 1, 16, 1);
                            _canvas.FillRectangle(12, (xx * 16) + 1, (yy * 16) + 2, 1, 14);
                            _canvas.FillRectangle(12, (xx * 16) + 1, (yy * 16) + 16, 16, 1);
                            _canvas.FillRectangle(12, (xx * 16) + 16, (yy * 16) + 2, 1, 14);
                        }

                        if (_city.ResourceTiles.Contains(tile))
                        {
                            DrawResources(tile, (xx * 16) + 1, (yy * 16) + 1);
                        }
                    }
                }

                _update = false;
            }
            return(true);
        }
Example #2
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);
        }
Example #3
0
        public override bool HasUpdate(uint gameTick)
        {
            if (_update || _centerChanged)
            {
                RenderTile[] renderTiles = RenderTiles.ToArray();
                if (Game.MovingUnit != null && !_centerChanged)
                {
                    IUnit   unit  = Game.MovingUnit;
                    ITile[] tiles = Map.QueryMapPart(unit.X - 1, unit.Y - 1, 3, 3).ToArray();
                    renderTiles = renderTiles.Where(t => tiles.Any(x => x != null && x.X == t.Tile.X && x.Y == t.Tile.Y)).ToArray();
                }
                else
                {
                    _centerChanged = false;
                    _canvas        = new Picture(_canvas.Width, _canvas.Height, _palette);
                }

                foreach (RenderTile t in renderTiles)
                {
                    if (!Settings.RevealWorld && !t.Visible)
                    {
                        _canvas.FillRectangle(5, t.X * 16, t.Y * 16, 16, 16);
                        continue;
                    }
                    AddLayer(t.Image, t.Position);
                    if (Settings.RevealWorld)
                    {
                        continue;
                    }

                    if (!Human.Visible(t.Tile, Direction.West))
                    {
                        AddLayer(Resources.Instance.GetFog(Direction.West), t.Position);
                    }
                    if (!Human.Visible(t.Tile, Direction.North))
                    {
                        AddLayer(Resources.Instance.GetFog(Direction.North), t.Position);
                    }
                    if (!Human.Visible(t.Tile, Direction.East))
                    {
                        AddLayer(Resources.Instance.GetFog(Direction.East), t.Position);
                    }
                    if (!Human.Visible(t.Tile, Direction.South))
                    {
                        AddLayer(Resources.Instance.GetFog(Direction.South), t.Position);
                    }
                }

                foreach (RenderTile t in renderTiles)
                {
                    if (!Settings.RevealWorld && !t.Visible)
                    {
                        continue;
                    }

                    if (t.Tile.City != null)
                    {
                        continue;
                    }

                    IUnit[] units = t.Tile.Units.Where(u => !u.Moving).ToArray();
                    if (t.Tile.Type == Terrain.Ocean)
                    {
                        // Always show naval units first at sea
                        units = units.OrderBy(u => (u.Class == UnitClass.Water) ? 1 : 0).ToArray();
                    }
                    if (units.Length == 0)
                    {
                        continue;
                    }

                    IUnit drawUnit = units.FirstOrDefault(u => u == Game.ActiveUnit);

                    if (drawUnit == null)
                    {
                        // No active unit on this tile, show top unit
                        if (t.Tile.IsOcean)
                        {
                            drawUnit = units.OrderBy(x => x.Class == UnitClass.Land ? 1 : 0).FirstOrDefault();
                        }
                        else
                        {
                            drawUnit = units[0];
                        }
                    }
                    else if (!Common.HasScreenType <Input>() && ((gameTick % 4) >= 2 || drawUnit.Moving))
                    {
                        // Active unit on this tile or unit is currently moving. Drawing happens later.
                        continue;
                    }

                    if (t.Tile.IsOcean && drawUnit.Class != UnitClass.Water && drawUnit.Sentry)
                    {
                        // Do not draw sentried land units at sea
                        continue;
                    }

                    AddLayer(drawUnit.GetUnit(drawUnit.Owner), t.Position);
                    if (units.Length == 1)
                    {
                        continue;
                    }
                    AddLayer(drawUnit.GetUnit(drawUnit.Owner), t.Position.X - 1, t.Position.Y - 1);
                }

                foreach (RenderTile t in renderTiles.Reverse())
                {
                    if (!Settings.RevealWorld && !t.Visible)
                    {
                        continue;
                    }

                    City city = t.Tile.City;
                    if (city == null)
                    {
                        continue;
                    }

                    AddLayer(Icons.City(city), t.Position);

                    if (t.Y == 11)
                    {
                        continue;
                    }
                    int labelX = (t.X == 0) ? t.Position.X : t.Position.X - 8;
                    int labelY = t.Position.Y + 16;
                    _canvas.DrawText(city.Name, 0, 5, labelX, labelY + 1, TextAlign.Left);
                    _canvas.DrawText(city.Name, 0, 11, labelX, labelY, TextAlign.Left);
                }

                foreach (RenderTile t in renderTiles)
                {
                    if (!Settings.RevealWorld && !t.Visible)
                    {
                        continue;
                    }

                    IUnit[] units = t.Tile.Units.Where(u => !u.Moving).ToArray();
                    if (units.Length == 0)
                    {
                        continue;
                    }

                    IUnit drawUnit = units.FirstOrDefault(u => u == Game.ActiveUnit);

                    if (drawUnit == null)
                    {
                        continue;
                    }

                    // Active unit on this tile

                    if (drawUnit.Moving)
                    {
                        // Unit is currently moving, do not draw the unit here.
                        continue;
                    }

                    if (Human == drawUnit.Owner && (gameTick % 4) >= 2 && !GameTask.Any())
                    {
                        // Unit is owned by human player, blink status is off and no tasks are running. Do not draw unit.
                        continue;
                    }

                    if (t.Tile.City != null && units.Length == 1 && !GameTask.Any())
                    {
                        AddLayer(drawUnit.GetUnit(units[0].Owner), t.Position.X - 1, t.Position.Y - 1);
                        continue;
                    }

                    AddLayer(drawUnit.GetUnit(units[0].Owner), t.Position);
                    if (units.Length == 1)
                    {
                        continue;
                    }
                    AddLayer(drawUnit.GetUnit(units[0].Owner), t.Position.X - 1, t.Position.Y - 1);
                }

                if (Game.MovingUnit != null && (Settings.RevealWorld || Game.Human == Game.MovingUnit.Owner || Game.Human.Visible(Game.MovingUnit.Tile)))
                {
                    IUnit unit = Game.MovingUnit;
                    if (renderTiles.Any(t => (t.Tile.X == unit.X && t.Tile.Y == unit.Y)))
                    {
                        RenderTile tile = renderTiles.First(t => (t.Tile.X == unit.X && t.Tile.Y == unit.Y));
                        AddLayer(unit.GetUnit(unit.Owner), tile.Position.X + unit.Movement.X, tile.Position.Y + unit.Movement.Y);
                        if (unit is IBoardable && tile.Tile.Units.Any(u => u.Class == UnitClass.Land && (tile.Tile.City == null || (tile.Tile.City != null && unit.Sentry))))
                        {
                            // If there are units on the ship, draw a stack
                            AddLayer(unit.GetUnit(unit.Owner), tile.Position.X + unit.Movement.X - 1, tile.Position.Y + unit.Movement.Y - 1);
                        }
                    }
                    return(true);
                }

                _update = false;
                return(true);
            }

            return(false);
        }