Esempio n. 1
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (Common.TopScreen is GamePlay && !GameTask.Any())
            {
                Game.Update();
            }

            if (gameTick == _lastGameTick)
            {
                _gameMap.MustUpdate(gameTick);
                DrawLayer(_gameMap, gameTick, _rightSideBar ? 0 : 80, 8);
                return(true);
            }

            if (_gameMap.MustUpdate(gameTick))
            {
                _update = true;
            }
            if (_sideBar.Update(gameTick))
            {
                _update = true;
            }
            if (gameTick % 3 == 0)
            {
                this.Cycle(96, 103).Cycle(104, 111);
            }
            if (!_update && !_redraw)
            {
                return(gameTick % 3 == 0);
            }

            DrawLayer(_menuBar, gameTick, 0, 0);
            DrawLayer(_sideBar, gameTick, _rightSideBar ? (Width - 80) : 0, 8);
            DrawLayer(_gameMap, gameTick, _rightSideBar ? 0 : 80, 8);
            DrawLayer(_gameMenu, gameTick, _menuX, _menuY);

            _redraw       = false;
            _update       = false;
            _lastGameTick = gameTick;
            return(true);
        }
Esempio n. 2
0
        private void DrawGameInfo(uint gameTick = 0)
        {
            IUnit unit = Game.ActiveUnit;

            _gameInfo.Tile(Pattern.PanelGrey)
            .DrawRectangle3D();

            if (Game.CurrentPlayer != Human || (unit != null && Human != unit.Owner) || (GameTask.Any() && !GameTask.Is <Show>() && !GameTask.Is <Message>()))
            {
                _gameInfo.FillRectangle(2, _gameInfo.Height - 8, 6, 6, (byte)((gameTick % 4 < 2) ? 15 : 8));
                return;
            }

            if (unit != null)
            {
                int yy = 2;
                _gameInfo.DrawText(Human.TribeName, 0, 5, 4, 2, TextAlign.Left);
                _gameInfo.DrawText(unit.Name, 0, 5, 4, (yy += 8), TextAlign.Left);

                if (unit.Veteran)
                {
                    _gameInfo.DrawText("Veteran", 0, 5, 8, (yy += 8), TextAlign.Left);
                }

                if (unit is BaseUnitAir)
                {
                    _gameInfo.DrawText($"Moves: {unit.MovesLeft}({(unit as BaseUnitAir).FuelLeft})", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                else if (unit.PartMoves > 0)
                {
                    _gameInfo.DrawText($"Moves: {unit.MovesLeft}.{unit.PartMoves}", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                else
                {
                    _gameInfo.DrawText($"Moves: {unit.MovesLeft}", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                _gameInfo.DrawText((unit.Home == null ? "NONE" : unit.Home.Name), 0, 5, 4, (yy += 8), TextAlign.Left);
                _gameInfo.DrawText($"({Map[unit.X, unit.Y].Name})", 0, 5, 4, (yy += 8), TextAlign.Left);

                if (Map[unit.X, unit.Y].RailRoad)
                {
                    _gameInfo.DrawText("(RailRoad)", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                else if (Map[unit.X, unit.Y].Road)
                {
                    _gameInfo.DrawText("(Road)", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                if (Map[unit.X, unit.Y].Irrigation)
                {
                    _gameInfo.DrawText("(Irrigation)", 0, 5, 4, (yy += 8), TextAlign.Left);
                }
                else if (Map[unit.X, unit.Y].Mine)
                {
                    _gameInfo.DrawText("(Mining)", 0, 5, 4, (yy += 8), TextAlign.Left);
                }

                yy += 11;

                IUnit[] units = Map[unit.X, unit.Y].Units.Where(u => u != unit).Take(8).ToArray();
                for (int i = 0; i < units.Length; i++)
                {
                    int ix = 7 + ((i % 4) * 16);
                    int iy = yy + (((i - (i % 4)) / 4) * 16);
                    _gameInfo.AddLayer(units[i].ToBitmap(), ix, iy);
                }
            }
            else
            {
                if (gameTick % 4 < 2)
                {
                    _gameInfo.DrawText($"End of Turn", 0, 5, 4, 26, TextAlign.Left);
                }
                _gameInfo.DrawText($"Press Enter", 0, 5, 4, 42, TextAlign.Left);
                _gameInfo.DrawText($"to continue", 0, 5, 4, 50, TextAlign.Left);
            }
        }
Esempio n. 3
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (!(_update || _fullRedraw))
            {
                return(false);
            }
            if (Game.MovingUnit == null && (gameTick % 2 == 1))
            {
                return(false);
            }

            Player renderPlayer = Settings.RevealWorld ? null : Human;

            IUnit activeUnit = ActiveUnit;

            if (Game.MovingUnit != null && !_fullRedraw)
            {
                IUnit movingUnit = Game.MovingUnit;
                ITile tile       = movingUnit.Tile;
                int   dx         = GetX(tile);
                int   dy         = GetY(tile);
                if (dx < _tilesX && dy < _tilesY)
                {
                    dx *= 16; dy *= 16;

                    MoveUnit movement = movingUnit.Movement;
                    this.FillRectangle(dx - 16, dy - 16, 48, 48, 5)
                    .AddLayer(Map[movingUnit.X - 1, movingUnit.Y - 1, 3, 3].ToBitmap(player: renderPlayer), dx - 16, dy - 16, dispose: true);
                    Bytemap unitPicture = movingUnit.ToBitmap();
                    this.AddLayer(unitPicture, dx + movement.X, dy + movement.Y);
                    if (movingUnit is IBoardable && tile.Units.Any(u => u.Class == UnitClass.Land && (tile.City == null || (tile.City != null && u.Sentry))))
                    {
                        this.AddLayer(unitPicture, dx + movement.X - 1, dy + movement.Y - 1);
                    }
                    return(true);
                }
            }
            else if (_fullRedraw)
            {
                _fullRedraw = false;
                this.Clear(5)
                .AddLayer(Tiles.ToBitmap(player: renderPlayer), dispose: true);
            }

            if (activeUnit != null && Game.CurrentPlayer == Human && !GameTask.Any())
            {
                ITile tile = activeUnit.Tile;
                int   dx   = GetX(tile);
                int   dy   = GetY(tile);
                if (dx < _tilesX && dy < _tilesY)
                {
                    dx *= 16; dy *= 16;

                    // blink status
                    TileSettings setting = ((gameTick % 4) < 2) ? TileSettings.BlinkOn : TileSettings.BlinkOff;
                    this.AddLayer(tile.ToBitmap(setting), dx, dy, dispose: true);

                    DrawHelperArrows(dx, dy);
                }
                return(true);
            }

            _update = false;
            return(true);
        }
Esempio n. 4
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (GameTask.Any())
            {
                return(true);
            }

            if (CheckShift56(args))
            {
                return(true);
            }

            if (_gameMenu != null)
            {
                if (!_gameMenu.KeyDown(args))
                {
                    _gameMenu = null;
                    _redraw   = true;
                }
                return(true);
            }

            if (_menuBar.KeyDown(args) && _gameMenu != null)
            {
                _gameMenu.KeepOpen = true;
                return(true);
            }

            switch (args.Key)
            {
            case Key.F1:
                Common.AddScreen(new CityStatus());
                return(true);

            case Key.F2:
                Common.AddScreen(new MilitaryLosses());
                Common.AddScreen(new MilitaryStatus());
                return(true);

            case Key.F3:
                Common.AddScreen(new IntelligenceReport());
                return(true);

            case Key.F4:
                Common.AddScreen(new AttitudeSurvey());
                return(true);

            case Key.F5:
                Common.AddScreen(new TradeReport());
                return(true);

            case Key.F6:
                Common.AddScreen(new ScienceReport());
                return(true);

            case Key.F7:
                if (Game.BuiltWonders.Length == 0)
                {
                    GameTask.Enqueue(Show.Empty);
                }
                else
                {
                    Common.AddScreen(new WorldWonders());
                }
                return(true);

            case Key.F8:
                Common.AddScreen(new TopCities());
                return(true);

            case Key.F9:
                Common.AddScreen(new CivilizationScore());
                return(true);

            case Key.F10:
                Common.AddScreen(new WorldMap());
                return(true);

            case Key.Plus:
                GameTask.Enqueue(Show.TaxRate);
                return(true);

            case Key.Minus:
                GameTask.Enqueue(Show.LuxuryRate);
                return(true);

            case Key.Slash:
                GameTask.Enqueue(Show.Search);
                return(true);
            }
            return(_gameMap.KeyDown(args));
        }
Esempio n. 5
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);
        }