Esempio n. 1
0
 public void Clear()
 {
     Religion = new Religion[0];
 }
Esempio n. 2
0
 public ReligionCollection()
 {
     Religion = new Religion[0];
 }
Esempio n. 3
0
 public void Add(Religion religion)
 {
     Array.Resize(ref this.religion, this.religion.Length + 1);
     Religion[Religion.Length - 1] = religion;
 }
Esempio n. 4
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);
            }
        }