Exemple #1
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (!_update)
            {
                return(false);
            }

            this.FillRectangle(8, 32, 304, 160, 3);

            for (int i = (_page * 7); i < _wonders.Length && i < ((_page + 1) * 7); i++)
            {
                IWonder wonder = _wonders[i].Wonder;
                City    city   = _wonders[i].City;

                int xx = 8;
                int yy = 32 + (24 * (i % 7));
                int ww = 304;
                int hh = 16;

                byte colour = 12;
                if (city != null && city.Size > 0)
                {
                    colour = Common.ColourLight[city.Owner];
                }
                this.FillRectangle(xx, yy, ww, hh, colour)
                .FillRectangle(xx + 1, yy + 1, ww - 2, hh - 2, 3)
                .AddLayer(wonder.SmallIcon, xx + 8, yy + 3)
                .DrawText(wonder.FormatWorldWonder(city), 0, 15, xx + 32, yy + 5);
            }

            _update = false;
            return(true);
        }
Exemple #2
0
 public bool WonderObsolete(IWonder wonder)
 {
     if (wonder.ObsoleteTech == null)
     {
         return(false);
     }
     if (_advances.Any(a => wonder.ObsoleteTech.Id == a))
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
 public void AddWonder(IWonder wonder)
 {
     _wonders.Add(wonder);
     if (Game.Started)
     {
         if (wonder is Colossus && !Game.WonderObsolete <Colossus>())
         {
             ResetResourceTiles();
         }
         if ((wonder is Lighthouse && !Game.WonderObsolete <Lighthouse>()) ||
             (wonder is MagellansExpedition && !Game.WonderObsolete <MagellansExpedition>()))
         {
             // Apply Lighthouse/Magellan's Expedition wonder effects in the first turn
             foreach (IUnit unit in Game.GetUnits().Where(x => x.Owner == Owner && x.Class == UnitClass.Water && x.MovesLeft == x.Move))
             {
                 unit.MovesLeft++;
             }
         }
     }
 }
Exemple #4
0
        private void DrawWonder(IWonder wonder, int offset)
        {
            int xx = (offset % 2 == 0) ? 21 : 1;
            int yy = -1 + (6 * offset);

            if (yy < 0)
            {
                AddLayer(wonder.SmallIcon.GetPart(0, Math.Abs(yy), wonder.SmallIcon.Width, wonder.SmallIcon.Height + yy), xx, 0);
            }
            else
            {
                AddLayer(wonder.SmallIcon, xx, yy);
            }

            string name = wonder.Name;

            while (Resources.Instance.GetTextSize(1, name).Width > 62)
            {
                name = $"{name.Substring(0, name.Length - 2)}.";
            }
            _canvas.DrawText(name, 1, 15, 42, 3 + (6 * offset));
        }
Exemple #5
0
        private bool WonderAvailable(IWonder wonder)
        {
            // Determine if the wonder has already been built
            if (Game.Instance.BuiltWonders.Any(w => w.Id == wonder.Id))
            {
                return(false);
            }

            // Determine if the building requires a tech
            if (wonder.RequiredTech == null)
            {
                return(true);
            }

            // Determine if the Player has the required tech
            if (_advances.Any(a => wonder.RequiredTech.Id == a))
            {
                return(true);
            }

            return(false);
        }
Exemple #6
0
 public bool HasWonder(IWonder wonder) => _wonders.Any(w => w.Id == wonder.Id);
Exemple #7
0
 public bool WonderObsolete(IWonder wonder) => (wonder.ObsoleteTech != null && _players.Any(x => x.HasAdvance(wonder.ObsoleteTech)));
Exemple #8
0
 public bool WonderBuilt(IWonder wonder) => BuiltWonders.Any(w => w.Id == wonder.Id);
Exemple #9
0
 public ImprovementBuilt(City city, IWonder wonder)
 {
     _city        = city;
     _improvement = wonder;
 }
Exemple #10
0
 public void SetWonder(IWonder wonder)
 {
     this.wonder = wonder;
 }
Exemple #11
0
 public bool HasWonder(IWonder wonder)
 {
     return(_wonders.Any(w => w.Id == wonder.Id));
 }
        public override bool HasUpdate(uint gameTick)
        {
            if (_update)
            {
                _canvas.FillRectangle(0, 0, 0, 320, 200);

                List <string> menuItems      = new List <string>();
                string        menuHeaderText = $"What shall we build in {_city.Name}?";
                int           itemWidth      = Resources.Instance.GetTextSize(_fontId, menuHeaderText).Width;
                foreach (IProduction production in _pages[_page])
                {
                    string menuText = string.Empty;
                    if (production is IUnit)
                    {
                        IUnit unit  = (production as IUnit);
                        int   turns = ((int)unit.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{unit.Name} ({turns} turns, ADM:{unit.Attack}/{unit.Defense}/{unit.Move})";
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IBuilding)
                    {
                        IBuilding building = (production as IBuilding);
                        int       turns    = ((int)building.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{building.Name} ({turns} turns)";
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IWonder)
                    {
                        IWonder wonder = (production as IWonder);
                        int     turns  = ((int)wonder.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{wonder.Name} ({turns} turns)";
                        if (Human.WonderObsolete(wonder))
                        {
                            menuText = $"*{menuText}";
                        }
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    menuItems.Add(menuText);
                }
                if (_pages.Count > 1)
                {
                    menuItems.Add("More...");
                }
                itemWidth += 10;

                int     width   = itemWidth + 14;
                int     height  = _menuHeight + 10 + Resources.Instance.GetFontHeight(_fontId);
                Picture menuGfx = new Picture(width, height);
                menuGfx.FillLayerTile(_background);
                menuGfx.AddBorder(15, 8, 0, 0, width, height);
                menuGfx.DrawText(menuHeaderText, _fontId, 15, 4, 4);
                menuGfx.DrawText($"(Help available)", 1, 10, width, height - Resources.Instance.GetFontHeight(1), TextAlign.Right);

                _canvas.FillRectangle(5, 80, 8, width + 2, height + 2);
                AddLayer(menuGfx, 81, 9);

                Picture background = menuGfx.GetPart(2, 3 + Resources.Instance.GetFontHeight(_fontId), itemWidth, Resources.Instance.GetFontHeight(_fontId) * menuItems.Count + 4);
                Picture.ReplaceColours(background, new byte[] { 7, 22 }, new byte[] { 11, 3 });

                Menu menu = new Menu(Canvas.Palette, background)
                {
                    X            = 83,
                    Y            = 12 + Resources.Instance.GetFontHeight(_fontId),
                    Width        = itemWidth,
                    ActiveColour = 11,
                    TextColour   = 5,
                    FontId       = _fontId
                };
                Menu.Item menuItem;
                int       i = 0;

                foreach (string item in menuItems)
                {
                    menu.Items.Add(menuItem = new Menu.Item(item, i++));
                    menuItem.Selected      += ProductionChoice;
                    menuItem.RightClick    += ProductionContext;
                }
                menu.Width     += 10;
                menu.MissClick += MenuCancel;
                menu.Cancel    += MenuCancel;

                AddMenu(menu);

                _update = false;
            }
            return(true);
        }
Exemple #13
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (_update)
            {
                this.FillRectangle(0, 0, 320, 200, 0);

                List <string> menuItems      = new List <string>();
                string        menuHeaderText = $"What shall we build in {_city.Name}?";
                int           itemWidth      = Resources.GetTextSize(_fontId, menuHeaderText).Width;
                foreach (IProduction production in _pages[_page])
                {
                    string menuText = string.Empty;
                    if (production is IUnit)
                    {
                        IUnit unit  = (production as IUnit);
                        int   turns = ((int)unit.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{unit.Name} ({turns} turns, ADM:{unit.Attack}/{unit.Defense}/{unit.Move})";
                        if (Resources.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IBuilding)
                    {
                        IBuilding building = (production as IBuilding);
                        int       turns    = ((int)building.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{building.Name} ({turns} turns)";
                        if (Resources.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IWonder)
                    {
                        IWonder wonder = (production as IWonder);
                        int     turns  = ((int)wonder.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{wonder.Name} ({turns} turns)";
                        if (Game.WonderObsolete(wonder))
                        {
                            menuText = $"*{menuText}";
                        }
                        if (Resources.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    menuItems.Add(menuText);
                }
                if (_pages.Count > 1)
                {
                    menuItems.Add("More...");
                }
                itemWidth += 10;

                int width  = itemWidth + 14;
                int height = _menuHeight + 10 + Resources.GetFontHeight(_fontId);

                using (Picture menuGfx = new Picture(width, height))
                {
                    menuGfx.Tile(Pattern.PanelGrey)
                    .DrawRectangle3D()
                    .DrawText(menuHeaderText, _fontId, 15, 4, 4)
                    .DrawText($"(Help available)", 1, 10, width, height - Resources.GetFontHeight(1), TextAlign.Right);

                    this.FillRectangle(80, 8, width + 2, height + 2, 5)
                    .AddLayer(menuGfx, 81, 9);

                    using (Picture background = menuGfx[2, 3 + Resources.GetFontHeight(_fontId), itemWidth, Resources.GetFontHeight(_fontId) * menuItems.Count + 4])
                    {
                        background.ColourReplace((7, 11), (22, 3));

                        Menu menu = new Menu(Palette, background)
                        {
                            X            = 83,
                            Y            = 12 + Resources.GetFontHeight(_fontId),
                            MenuWidth    = itemWidth,
                            ActiveColour = 11,
                            TextColour   = 5,
                            FontId       = _fontId
                        };

                        int i = 0;
                        foreach (string item in menuItems)
                        {
                            menu.Items.Add(item, i++)
                            .OnSelect(ProductionChoice)
                            .OnContext(ProductionContext);
                        }
                        menu.MenuWidth += 10;
                        menu.MissClick += MenuCancel;
                        menu.Cancel    += MenuCancel;

                        AddMenu(menu);
                    }
                }
                _update = false;
            }
            return(true);
        }