예제 #1
0
        protected override void OnPaint(PaintEventArgs p)
        {
            Graphics  g = p.Graphics;
            Rectangle r = new Rectangle(0, 0, Width, Height);

            int widthAttacker;

            if (TotalScore > 0)
            {
                widthAttacker = ((AttackerScore * 100 / TotalScore) * Width) / 100;
            }
            else
            {
                widthAttacker = 0;
            }

            int brdSize;

            if (AutoSizeBorder)
            {
                brdSize = Math.Max(Math.Min(8, Height / 8), 4);
                if (brdSize % 2 != 0)
                {
                    brdSize -= 1;
                }
            }
            else
            {
                brdSize = BorderSize;
            }

            DrawingPlus.DrawBorder(g, r, BorderColor, brdSize);
            DrawingPlus.DrawPanel(g, new Rectangle(brdSize, brdSize, widthAttacker, Height - brdSize * 2), AttackerColor, 2);
            DrawingPlus.DrawPanel(g, new Rectangle(brdSize + widthAttacker, brdSize, Width - brdSize * 2 - widthAttacker, Height - brdSize * 2), DefenderColor, 2);
        }
예제 #2
0
        public UnitCard()
        {
            InitializeComponent();

            pbAttack.Image = DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "AttackBonus.PNG");
            pbHealth.Image = DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "Health.PNG");
        }
예제 #3
0
        public void Load(string map, string assetsPack, int id)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(NarivianClass.MapsDirectory + map + "\\Resources.XML");
            XmlNode xmlNode = xml.SelectNodes("/Resources/Resource")[id];

            Name = xmlNode["Name"].InnerText;
            ID   = id;
            Icon = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + assetsPack + "\\Icons\\Resources\\" + Name + ".PNG");
        }
예제 #4
0
        public frmBattle()
        {
            InitializeComponent();

            BackgroundImage      = Properties.Resources.Stone_Bricks;
            pbAttackBonus.Image  = DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "AttackBonus.PNG");
            pbDefenceBonus.Image = DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "Health.PNG");

            Turn = 0;

            customToolTip.SetToolTip(btnAttack, "Attack");
            customToolTip.SetToolTip(btnSurrender, "Loose the battle but keep all your remaining units alive");
        }
예제 #5
0
        public void Load(string map, string assetsPack, int id)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(NarivianClass.MapsDirectory + map + "\\Units.XML");
            XmlNode xmlNode = xml.SelectNodes("/Units/Unit")[id];

            Name        = xmlNode["Name"].InnerText;
            ID          = id;
            Description = xmlNode["Description"].InnerText;
            Price       = Convert.ToInt32(xmlNode["Price"].InnerText);
            Maintenance = Convert.ToInt32(xmlNode["Maintenance"].InnerText);
            Icon        = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + assetsPack + "\\Units\\" + Name + ".PNG");
            Attack      = Convert.ToInt32(xmlNode["Attack"].InnerText);
            Health      = Convert.ToInt32(xmlNode["Health"].InnerText);
        }
예제 #6
0
        public void Load(string map, string assetsPack, int id)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(NarivianClass.MapsDirectory + map + "\\Factions.XML");
            XmlNode xmlNode = xml.SelectNodes("/Factions/Faction")[id];

            Name        = xmlNode["Name"].InnerText;
            ID          = id;
            Description = xmlNode["Description"].InnerText;
            Color       = ColorTranslator.FromHtml(xmlNode["Color"].InnerText);
            Symbol      = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + assetsPack + "\\Symbols\\" + Name + ".PNG");
            Ability     = Convert.ToInt32(xmlNode["Ability"].InnerText);
            Culture     = Convert.ToInt32(xmlNode["Culture"].InnerText);
            Religion    = Convert.ToInt32(xmlNode["Religion"].InnerText);
            Units       = new int[16];
            Region      = new int[256];
            RegionCount = 0;
        }
예제 #7
0
        public void DrawMap(Control ctrl)
        {
            int    i, j, dir;
            int    bordersColorValue = 16;
            Bitmap bmpMap            = new Bitmap(640, 640);

            if (Options.MapOverlay)
            {
                bordersColorValue = 48;
            }

            ctrl.BackColor = Faction[0].Color;

            Graphics g = Graphics.FromImage(bmpMap);

            #region Drawing
            {
                for (i = 0; i < 640; i++)
                {
                    for (j = 0; j < 640; j++)
                    {
                        g.FillRectangle(
                            new SolidBrush(Faction[Region[world[i, j]].Faction].Color),
                            new Rectangle(i, j, 1, 1));

                        if (Region[world[i, j]].Faction == 0)
                        {
                            g.FillRectangle(
                                new SolidBrush(Region[world[i, j]].Color),
                                new Rectangle(i, j, 1, 1));
                        }
                    }
                }

                int[] dx = new int[4] {
                    -1, 0, 1, 0
                };                                     //int[] dx = new int[8] { -1, -1, -1, 0, 1, 1, 1, 0 };
                int[] dy = new int[4] {
                    0, 1, 0, -1
                };                                     //int[] dy = new int[8] { -1, 0, 1, 1, 1, 0, -1, -1 };

                for (i = 1; i < Height - 1; i++)
                {
                    for (j = 1; j < Width - 1; j++)
                    {
                        for (dir = 0; dir < Math.Min(dx.Length, dy.Length); dir++)
                        {
                            if (Region[world[i, j]].Faction != 0)
                            {
                                if (world[i, j] != world[i + dx[dir], j + dy[dir]] && world[i + dx[dir], j + dy[dir]] != 0)
                                {
                                    g.FillRectangle(
                                        new SolidBrush(DrawingPlus.DarkenColor(Faction[Region[world[i, j]].Faction].Color, bordersColorValue)),
                                        new Rectangle(i, j, 1, 1));
                                }

                                if (Region[world[i, j]].Faction != Region[world[i + dx[dir], j + dy[dir]]].Faction && Region[world[i + dx[dir], j + dy[dir]]].Faction != 0)
                                {
                                    for (int k = 0; k < 2; k++)
                                    {
                                        g.FillRectangle(Brushes.Black, new Rectangle(i, j, 1, 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (Options.MapOverlay)
            {
                bmpMap = DrawingPlus.OverlayImages(bmpMap, (Bitmap)Overlay);
            }

            Image = bmpMap;
            ctrl.BackgroundImage = Image;
        }
예제 #8
0
        public void Load(string map)
        {
            world        = new int[640, 640];
            InternalName = map;

            loadingProgress = 0;
            Log.WriteLine("Loading Map '" + map + "'...");
            XmlDocument xml = new XmlDocument();

            try
            {
                #region World.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\World.XML");

                DisplayName = xml.SelectSingleNode("World/DisplayName").InnerText;
                AssetsPack  = xml.SelectSingleNode("World/Assets").InnerText;

                BaseRegionIncome      = Convert.ToInt32(xml.SelectSingleNode("World/BaseRegionIncome").InnerText);
                BaseRegionRecruitment = Convert.ToInt32(xml.SelectSingleNode("World/BaseRegionRecruitment").InnerText);

                StartingMoney    = Convert.ToInt32(xml.SelectSingleNode("World/StartingMoney").InnerText);
                StartingTroops   = Convert.ToInt32(xml.SelectSingleNode("World/StartingTroops").InnerText);
                StartingReligion = Convert.ToInt32(xml.SelectSingleNode("World/StartingReligion").InnerText);

                RecruitmentRate = new MinMax(
                    Convert.ToInt32(xml.SelectSingleNode("World/RecruitmentRate").Attributes["Min"].InnerText),
                    Convert.ToInt32(xml.SelectSingleNode("World/RecruitmentRate").Attributes["Max"].InnerText));

                AttackerBonus = new MinMax(
                    Convert.ToInt32(xml.SelectSingleNode("World/AttackerBonus").Attributes["Min"].InnerText),
                    Convert.ToInt32(xml.SelectSingleNode("World/AttackerBonus").Attributes["Max"].InnerText));

                DefenderBonus = new MinMax(
                    Convert.ToInt32(xml.SelectSingleNode("World/DefenderBonus").Attributes["Min"].InnerText),
                    Convert.ToInt32(xml.SelectSingleNode("World/DefenderBonus").Attributes["Max"].InnerText));

                MinTroopsAttack = Convert.ToInt32(xml.SelectSingleNode("World/MinTroopsAttack").InnerText);
                HealingRate     = Convert.ToSingle(xml.SelectSingleNode("World/HealingRate").InnerText);
                #endregion
                loadingProgress += 1;
                #region Abilities.XML
                xml.Load(NarivianClass.MapsDirectory + InternalName + "\\Abilities.XML");

                for (int abl = 0; abl < xml.SelectNodes("/Abilities/Ability").Count; abl++)
                {
                    Ability ability = new Ability();
                    ability.Load(InternalName, abl);

                    Ability.Add(ability);
                }
                #endregion
                loadingProgress += 1;
                #region Biomes.XML
                xml.Load(NarivianClass.MapsDirectory + InternalName + "\\Biomes.XML");

                for (int bio = 0; bio < xml.SelectNodes("/Biomes/Biome").Count; bio++)
                {
                    Biome biome = new Biome();
                    biome.Load(InternalName, AssetsPack, bio);

                    Biome.Add(biome);
                }
                #endregion
                loadingProgress += 1;
                #region Resources.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\Resources.XML");

                for (int res = 0; res < xml.SelectNodes("/Resources/Resource").Count; res++)
                {
                    Resource resource = new Resource();
                    resource.Load(InternalName, AssetsPack, res);

                    Resource.Add(resource);
                }
                #endregion
                loadingProgress += 1;
                #region Cultures.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\Cultures.XML");

                for (int cul = 0; cul < xml.SelectNodes("/Cultures/Culture").Count; cul++)
                {
                    Culture culture = new Culture();
                    culture.Load(map, cul);

                    Culture.Add(culture);
                }
                #endregion
                loadingProgress += 1;
                #region Religions.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\Religions.XML");

                for (int rel = 0; rel < xml.SelectNodes("/Religions/Religion").Count; rel++)
                {
                    Religion religion = new Religion();
                    religion.Load(InternalName, AssetsPack, rel);

                    Religion.Add(religion);
                }
                #endregion
                loadingProgress += 1;
                #region Buildings.XML
                xml.Load(NarivianClass.MapsDirectory + InternalName + "\\Buildings.XML");

                for (int bld = 0; bld < xml.SelectNodes("/Buildings/Building").Count; bld++)
                {
                    Building building = new Building();
                    building.Load(InternalName, bld);

                    building.Icon    = new Image[Culture.Count];
                    building.Preview = new Image[Culture.Count];

                    for (int clt = 0; clt < Culture.Count; clt++)
                    {
                        building.Icon[clt]    = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + AssetsPack + "\\Buildings\\" + Culture[clt].Name + "\\Small\\" + building.Name + ".PNG", false);
                        building.Preview[clt] = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + AssetsPack + "\\Buildings\\" + Culture[clt].Name + "\\Large\\" + building.Name + ".PNG", false);

                        if (building.Icon[clt] == null)
                        {
                            building.Icon[clt] = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + AssetsPack + "\\Buildings\\" + Culture[0].Name + "\\Small\\" + building.Name + ".PNG");
                        }
                        if (building.Preview[clt] == null)
                        {
                            building.Preview[clt] = DrawingPlus.LoadImage(NarivianClass.AssetsDirectory + AssetsPack + "\\Buildings\\" + Culture[0].Name + "\\Large\\" + building.Name + ".PNG", false);

                            if (building.Preview[clt] == null)
                            {
                                building.Preview[clt] = building.Icon[clt];
                            }
                        }
                    }

                    Building.Add(building);
                }
                #endregion
                loadingProgress += 1;
                #region Units.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\Units.XML");

                for (int unt = 0; unt < xml.SelectNodes("/Units/Unit").Count; unt++)
                {
                    Unit unit = new Unit();
                    unit.Load(map, AssetsPack, unt);

                    Unit.Add(unit);
                }
                #endregion
                loadingProgress += 1;
                #region Factions.XML
                xml.Load(NarivianClass.MapsDirectory + InternalName + "\\Factions.XML");

                for (int fct = 0; fct < xml.SelectNodes("/Factions/Faction").Count; fct++)
                {
                    Faction faction = new Faction();
                    faction.Load(InternalName, AssetsPack, fct);

                    Faction.Add(faction);
                }

                #endregion
                loadingProgress += 1;
                #region Regions.XML
                xml.Load(NarivianClass.MapsDirectory + map + "\\Regions.XML");

                for (int reg = 0; reg < xml.SelectNodes("/Regions/Region").Count; reg++)
                {
                    Region region = new Region();
                    region.Load(map, reg);

                    Faction[region.Faction].Region[Faction[region.Faction].RegionCount] = reg;
                    Faction[region.Faction].RegionCount += 1;

                    if (Faction[region.Faction].RegionCount == 1)
                    {
                        region.Type = RegionType.Capital;
                    }
                    else
                    {
                        region.Type = RegionType.Province;
                    }

                    Region.Add(region);
                }
                #endregion
                loadingProgress += 1;

                #region Load Map.PNG
                Bitmap     bmp     = new Bitmap(NarivianClass.MapsDirectory + InternalName + "\\Map.PNG");
                FastBitmap fastBmp = new FastBitmap(bmp);

                fastBmp.LockBits();
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        Color clr = fastBmp.GetPixel(i, j);

                        for (int k = 0; k < Region.Count; k++)
                        {
                            if (clr == Region[k].Color)
                            {
                                world[i, j] = k;
                                break;
                            }
                        }
                    }

                    if (i % 80 == 0)
                    {
                        loadingProgress += 64 / (Width / 80);
                    }
                }
                fastBmp.UnlockBits();

                Image = bmp;
                #endregion
                loadingProgress += 3;
                #region Load Overlay.PNG
                if (File.Exists(NarivianClass.MapsDirectory + InternalName + "\\Overlay.PNG"))
                {
                    Overlay = Image.FromFile(NarivianClass.MapsDirectory + InternalName + "\\Overlay.PNG");
                }
                else
                {
                    Overlay = new Bitmap(Width, Height);
                }
                #endregion
                loadingProgress += 2;

                border    = new bool[Region.Count, Region.Count];
                relations = new int[Region.Count, Region.Count];

                #region Detect Borders
                int[] dx = new int[24] {
                    -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2
                };
                int[] dy = new int[24] {
                    0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2
                };

                for (int x = 0; x < Width; x++)
                {
                    for (int y = 0; y < Height; y++)
                    {
                        for (int dir = 23; dir >= 0; dir--)
                        {
                            if (x + dx[dir] >= 0 && x + dx[dir] < Width &&
                                y + dy[dir] >= 0 && y + dy[dir] < Height)
                            {
                                int reg = world[x + dx[dir], y + dy[dir]];

                                if (reg != world[x, y])
                                {
                                    border[world[x, y], reg] = true;
                                    border[reg, world[x, y]] = true;
                                }
                            }
                        }
                    }

                    if (x % 40 == 0)
                    {
                        loadingProgress += 16 / (Width / 40);
                    }
                }
                #endregion

                InitializeFactions();
                loadingProgress += 1;

                InitializeRegions();
                loadingProgress += 1;

                loadingProgress = 100;
                Loaded          = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading map!" + Environment.NewLine + Environment.NewLine + ex,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Log.WriteLine("ERROR: Error loading Map! " + ex);
            }
        }