private void ImportTmxSpawnLayer_TryVolcanizeRegion(Region region)
        {
            Random       random = new Random((int)region.Id);
            List <Biome> list   = new List <Biome>();

            foreach (Biome biome in base.Context.Settings.Biomes)
            {
                if (biome.IsVolcanic)
                {
                    list.Add(biome);
                }
            }
            if (list.Count == 0)
            {
                return;
            }
            region.Biome = list[random.Next(list.Count)];
            TerrainTransformation transform = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "ELCPAshlandsTrans");

            foreach (HexPos hex in region.Hexes)
            {
                base.Context.ApplyTransformation(transform, hex);
            }
            List <River> list2 = base.Context.Rivers.FindAll((River R) => region.Hexes.Contains(R.StartingHex) && R.Tributaries.Count == 0 && R.FlowsInto == null);

            if (list2 != null)
            {
                foreach (River river in list2)
                {
                    river.Type = River.RiverType.LavaRiver;
                }
            }
        }
 private void CompleteRegionsValues()
 {
     base.Context.RegionSkeletonValues = new int[base.Context.Grid.Rows, base.Context.Grid.Columns];
     foreach (Region region in base.Context.Regions.Values)
     {
         region.LandMassType         = Region.LandMassTypes.Continent;
         region.Districts[0].Content = District.Contents.Land;
         region.ComputeRegionSkeleton(base.Context);
         Terrain terrain = base.Context.GetTerrain(region.Center);
         if (terrain != null)
         {
             foreach (Biome biome in base.Context.Settings.Biomes)
             {
                 for (int i = 0; i < biome.LandTerrainWeights.Length; i++)
                 {
                     if (biome.LandTerrainWeights[i].Name == terrain.Name)
                     {
                         region.Biome = biome;
                         break;
                     }
                 }
                 if (region.Biome != null)
                 {
                     break;
                 }
                 for (int j = 0; j < biome.OceanTerrainWeights.Length; j++)
                 {
                     if (biome.OceanTerrainWeights[j].Name == terrain.Name)
                     {
                         region.Biome = biome;
                         break;
                     }
                 }
                 if (region.Biome != null)
                 {
                     break;
                 }
                 for (int k = 0; k < biome.CoastTerrainWeights.Length; k++)
                 {
                     if (biome.CoastTerrainWeights[k].Name == terrain.Name)
                     {
                         region.Biome = biome;
                         break;
                     }
                 }
                 if (region.Biome != null)
                 {
                     break;
                 }
                 for (int l = 0; l < biome.LakeTerrainWeights.Length; l++)
                 {
                     if (biome.LakeTerrainWeights[l].Name == terrain.Name)
                     {
                         region.Biome = biome;
                         break;
                     }
                 }
                 if (region.Biome != null)
                 {
                     break;
                 }
             }
             if (region.Biome == null)
             {
                 region.Biome = base.Context.Settings.Biomes[0];
             }
             if (terrain.Name.Contains("Ocean"))
             {
                 region.LandMassType         = Region.LandMassTypes.Ocean;
                 region.Districts[0].Content = District.Contents.Ocean;
                 region.Districts[0].CoastalSkeletonValue = -1;
             }
             int num = 0;
             foreach (HexPos hex in region.Districts[0])
             {
                 if (hex.Row == 0 || hex.Row == base.Context.Grid.Rows - 1)
                 {
                     region.LandMassType         = Region.LandMassTypes.WasteNS;
                     region.Districts[0].Content = District.Contents.WasteNS;
                     region.Districts[0].CoastalSkeletonValue = 99;
                     region.LandMassIndex = 255;
                     num = 0;
                     break;
                 }
                 if ((hex.Column == 0 || hex.Column == base.Context.Grid.Columns - 1) && !base.Context.Settings.WorldWrap)
                 {
                     region.LandMassType         = Region.LandMassTypes.WasteEW;
                     region.Districts[0].Content = District.Contents.WasteEW;
                     region.Districts[0].CoastalSkeletonValue = -1;
                     region.LandMassIndex = 255;
                     num = 0;
                     break;
                 }
                 if (base.Context.GetTerrain(hex).Name == "RockyWasteland")
                 {
                     num++;
                 }
             }
             if ((float)num > 0.9f * (float)region.HexCount())
             {
                 region.LandMassType         = Region.LandMassTypes.WasteNS;
                 region.Districts[0].Content = District.Contents.WasteNS;
                 region.Districts[0].CoastalSkeletonValue = 99;
                 region.LandMassIndex = 255;
             }
             if (region.LandMassType == Region.LandMassTypes.WasteNS || region.LandMassType == Region.LandMassTypes.WasteEW)
             {
                 TerrainTransformation transform = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "Wastelands");
                 foreach (HexPos hex2 in region.Districts[0])
                 {
                     base.Context.ApplyTransformation(transform, hex2);
                 }
             }
         }
     }
 }
Example #3
0
        public override void Execute(object context)
        {
            base.Report("?CreateTerrains");
            base.Execute(context);
            List <Biome> list = new List <Biome>();

            for (int i = 0; i < base.Context.Settings.Biomes.Count; i++)
            {
                if (!(base.Context.Settings.Biomes[i].DLCPrerequisite != string.Empty) || base.Context.Configuration.IsDLCAvailable(base.Context.Settings.Biomes[i].DLCPrerequisite))
                {
                    list.Add(base.Context.Settings.Biomes[i]);
                }
            }
            int count = list.Count;

            base.Context.OceanSelectors = new WeightedRandomSelector <Terrain> [count];
            base.Context.LandSelectors  = new WeightedRandomSelector <Terrain> [count];
            base.Context.LakeSelectors  = new WeightedRandomSelector <Terrain> [count];
            base.Context.CoastSelectors = new WeightedRandomSelector <Terrain> [count];
            foreach (Biome biome in list)
            {
                base.Context.OceanSelectors[(int)biome.Id]             = new WeightedRandomSelector <Terrain>();
                base.Context.OceanSelectors[(int)biome.Id].ItemsList   = new List <Terrain>();
                base.Context.OceanSelectors[(int)biome.Id].WeightsList = new List <int>();
                base.Context.OceanSelectors[(int)biome.Id].Randomizer  = base.Context.Randomizer;
                Biome.TerrainWeight[] array = biome.OceanTerrainWeights;
                for (int j = 0; j < array.Length; j++)
                {
                    Biome.TerrainWeight tw   = array[j];
                    Terrain             item = base.Context.Settings.Terrains.Find((Terrain t) => t.Name == tw.Name);
                    base.Context.OceanSelectors[(int)biome.Id].ItemsList.Add(item);
                    base.Context.OceanSelectors[(int)biome.Id].WeightsList.Add(tw.Weight);
                }
                base.Context.LandSelectors[(int)biome.Id]             = new WeightedRandomSelector <Terrain>();
                base.Context.LandSelectors[(int)biome.Id].ItemsList   = new List <Terrain>();
                base.Context.LandSelectors[(int)biome.Id].WeightsList = new List <int>();
                base.Context.LandSelectors[(int)biome.Id].Randomizer  = base.Context.Randomizer;
                array = biome.LandTerrainWeights;
                for (int k = 0; k < array.Length; k++)
                {
                    Biome.TerrainWeight tw    = array[k];
                    Terrain             item2 = base.Context.Settings.Terrains.Find((Terrain t) => t.Name == tw.Name);
                    base.Context.LandSelectors[(int)biome.Id].ItemsList.Add(item2);
                    base.Context.LandSelectors[(int)biome.Id].WeightsList.Add(tw.Weight);
                }
                base.Context.LakeSelectors[(int)biome.Id]             = new WeightedRandomSelector <Terrain>();
                base.Context.LakeSelectors[(int)biome.Id].ItemsList   = new List <Terrain>();
                base.Context.LakeSelectors[(int)biome.Id].WeightsList = new List <int>();
                base.Context.LakeSelectors[(int)biome.Id].Randomizer  = base.Context.Randomizer;
                array = biome.LakeTerrainWeights;
                for (int l = 0; l < array.Length; l++)
                {
                    Biome.TerrainWeight tw    = array[l];
                    Terrain             item3 = base.Context.Settings.Terrains.Find((Terrain t) => t.Name == tw.Name);
                    base.Context.LakeSelectors[(int)biome.Id].ItemsList.Add(item3);
                    base.Context.LakeSelectors[(int)biome.Id].WeightsList.Add(tw.Weight);
                }
                base.Context.CoastSelectors[(int)biome.Id]             = new WeightedRandomSelector <Terrain>();
                base.Context.CoastSelectors[(int)biome.Id].ItemsList   = new List <Terrain>();
                base.Context.CoastSelectors[(int)biome.Id].WeightsList = new List <int>();
                base.Context.CoastSelectors[(int)biome.Id].Randomizer  = base.Context.Randomizer;
                array = biome.CoastTerrainWeights;
                for (int m = 0; m < array.Length; m++)
                {
                    Biome.TerrainWeight tw    = array[m];
                    Terrain             item4 = base.Context.Settings.Terrains.Find((Terrain t) => t.Name == tw.Name);
                    base.Context.CoastSelectors[(int)biome.Id].ItemsList.Add(item4);
                    base.Context.CoastSelectors[(int)biome.Id].WeightsList.Add(tw.Weight);
                }
            }
            TerrainTransformation terrainTransformation  = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "HighMountain");
            TerrainTransformation terrainTransformation2 = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "MediumMountain");
            TerrainTransformation transform = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "RidgePresence");

            base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "RiverFlood");
            base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "LavaRiver");
            TerrainTransformation transform2             = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "Wastelands");
            TerrainTransformation terrainTransformation3 = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "Volcano");

            if (terrainTransformation == null)
            {
                base.Trace("ELCP: No 'HighMountain' transformation found - none applied");
            }
            if (terrainTransformation2 == null)
            {
                base.Trace("ELCP: No 'MediumMountain' transformation found - none applied");
            }
            if (terrainTransformation3 == null)
            {
                base.Trace("ELCP: No 'Volcano' transformation found - none applied");
            }
            foreach (District district in base.Context.Districts.Values)
            {
                Region motherRegion = district.MotherRegion;
                if (district.Content == District.Contents.Coastal)
                {
                    district.Terrain = base.Context.CoastSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                }
                else if (district.Content == District.Contents.Lake)
                {
                    district.Terrain = base.Context.LakeSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                }
                else if (district.Content == District.Contents.Land)
                {
                    district.Terrain = base.Context.LandSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                }
                else if (district.Content == District.Contents.Ocean)
                {
                    district.Terrain = base.Context.OceanSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                }
                else if (district.Content == District.Contents.Ridge)
                {
                    district.Terrain = base.Context.LandSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                    base.Context.ApplyTransformation(transform, district);
                }
                else if (district.Content == District.Contents.WasteNS)
                {
                    district.Terrain = base.Context.LandSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                    base.Context.ApplyTransformation(transform2, district);
                }
                else if (district.Content == District.Contents.WasteEW)
                {
                    if (district.Neighbours.Any((District n) => n.Content == District.Contents.Ocean))
                    {
                        district.Terrain   = base.Context.OceanSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                        district.Elevation = -2;
                    }
                    else
                    {
                        district.Terrain   = base.Context.LandSelectors[(int)motherRegion.Biome.Id].RandomSelected;
                        district.Elevation = 0;
                    }
                    base.Context.ApplyTransformation(transform2, district);
                    foreach (HexPos hexPos in district)
                    {
                        base.Context.HeightData[hexPos.Row, hexPos.Column] = district.Elevation;
                    }
                }
                if (district.Elevation >= base.Context.Settings.HighMountainElevation)
                {
                    base.Context.ApplyTransformation(terrainTransformation, district);
                }
                else if (district.Elevation >= base.Context.Settings.MediumMountainElevation)
                {
                    base.Context.ApplyTransformation(terrainTransformation2, district);
                }
            }
            int[] array2 = new int[base.Context.Settings.Terrains.Count];
            foreach (District district2 in base.Context.Districts.Values)
            {
                array2[(int)district2.Terrain.Id] += district2.Count;
                foreach (HexPos hexPos2 in district2)
                {
                    base.Context.TerrainData[hexPos2.Row, hexPos2.Column] = district2.Terrain.Id;
                }
            }
            foreach (River river in base.Context.Rivers)
            {
                if (river.Type == River.RiverType.LavaRiver)
                {
                    base.Context.ApplyTransformation(terrainTransformation3, river.StartingHex);
                }
            }
        }
Example #4
0
        private void GetPointOfInterests()
        {
            this.customRandomizationGroups = new Dictionary <int, List <int> >();
            this.randomAnomalyPositions    = new List <HexPos>();
            TerrainTransformation transform = base.Context.Settings.Transformations.Find((TerrainTransformation t) => t.Name == "Volcano");
            bool flag  = base.Context.Configuration.IsDLCAvailable("SummerFlamesPack");
            bool flag2 = base.Context.Configuration.IsDLCAvailable("NavalPack");

            for (int i = 0; i < base.Context.Grid.Columns; i++)
            {
                for (int j = 0; j < base.Context.Grid.Rows; j++)
                {
                    if (this.tmxPointOfInterestLayer.Data[j, i] != 0)
                    {
                        HexPos hexPos       = new HexPos(i, j);
                        bool   flag3        = false;
                        string tileProperty = base.Context.Settings.TmxMap.GetTileProperty(this.tmxPointOfInterestLayer.Data[hexPos.Row, hexPos.Column], "Values");
                        string poiName;
                        if (!string.IsNullOrEmpty(tileProperty))
                        {
                            poiName = this.GetPointOfInterest_CustomRandomization(hexPos, tileProperty);
                        }
                        else
                        {
                            poiName = base.Context.Settings.TmxMap.GetTileProperty(this.tmxPointOfInterestLayer.Data[j, i], ImportTmxPointOfInterestLayer.poiTypeNameProperty);
                        }
                        if (string.IsNullOrEmpty(poiName))
                        {
                            base.ReportTmx(string.Concat(new object[]
                            {
                                "?MissingPropertyTile&$Coordinate=",
                                i,
                                ",",
                                j - base.Context.Grid.Rows + 1,
                                "&$MissingProperty=",
                                ImportTmxPointOfInterestLayer.poiTypeNameProperty
                            }));
                        }
                        else
                        {
                            if (poiName.Contains("Facility"))
                            {
                                if (poiName == ImportTmxPointOfInterestLayer.randomFacilityName)
                                {
                                    string[] array = (from template in base.Context.Settings.POITemplates.Values
                                                      select template.Name into name
                                                      where name.Contains("Facility")
                                                      select name).ToArray <string>();
                                    poiName = array[this.random.Next(array.Length)];
                                }
                                bool flag4 = false;
                                for (int k = 0; k < 6; k++)
                                {
                                    HexPos hexPos2 = hexPos.Neighbour((HexPos.Direction)k);
                                    if (hexPos2.Row >= 0 && hexPos2.Row <= base.Context.Settings.Height && hexPos2.Column >= 0 && hexPos2.Column <= base.Context.Settings.Width && this.tmxPointOfInterestLayer.Data[hexPos2.Row, hexPos2.Column] != 0)
                                    {
                                        string tileProperty2 = base.Context.Settings.TmxMap.GetTileProperty(this.tmxPointOfInterestLayer.Data[hexPos2.Row, hexPos2.Column], ImportTmxPointOfInterestLayer.poiTypeNameProperty);
                                        if (!string.IsNullOrEmpty(tileProperty2) && tileProperty2.Contains("Citadel"))
                                        {
                                            if (flag4)
                                            {
                                                base.ReportTmx(string.Concat(new object[]
                                                {
                                                    "?CitadelIncorrectPosition&$Coordinate=",
                                                    hexPos2.Column,
                                                    ",",
                                                    hexPos2.Row - base.Context.Grid.Rows + 1
                                                }));
                                                throw new TmxImportException();
                                            }
                                            flag4 = true;
                                        }
                                    }
                                }
                                if (!flag4)
                                {
                                    goto IL_9F7;
                                }
                                flag3 = true;
                            }
                            if (poiName.Contains("Citadel"))
                            {
                                if (poiName == ImportTmxPointOfInterestLayer.randomCitadelName)
                                {
                                    string[] array2 = (from template in base.Context.Settings.POITemplates.Values
                                                       select template.Name into name
                                                       where name.Contains("Citadel")
                                                       select name).ToArray <string>();
                                    poiName = array2[this.random.Next(array2.Length)];
                                }
                                flag3 = true;
                            }
                            flag3 |= poiName.Contains("NavalQuestLocation_SunkenRuin");
                            Terrain terrain = base.Context.GetTerrain(hexPos);
                            if ((!flag3 && terrain.IsWaterTile) || terrain.Name.Contains("Waste"))
                            {
                                base.ReportTmx(string.Concat(new object[]
                                {
                                    "?POIIncompatibleTerrain&$Coordinate=",
                                    hexPos.Column,
                                    ",",
                                    hexPos.Row - base.Context.Grid.Rows + 1
                                }));
                            }
                            else if (flag3 && !terrain.IsWaterTile)
                            {
                                base.ReportTmx(string.Concat(new object[]
                                {
                                    "?POIIncompatibleTerrain&$Coordinate=",
                                    hexPos.Column,
                                    ",",
                                    hexPos.Row - base.Context.Grid.Rows + 1
                                }));
                            }
                            else if (poiName == "Ridge")
                            {
                                this.ridgesHexes.Add(hexPos);
                            }
                            else if (poiName == "Volcano")
                            {
                                this.ridgesHexes.Add(hexPos);
                                if (flag)
                                {
                                    base.Context.ApplyTransformation(transform, hexPos);
                                }
                            }
                            else
                            {
                                if (poiName.Contains("Anomaly"))
                                {
                                    if (poiName == ImportTmxPointOfInterestLayer.randomAnomalyName)
                                    {
                                        this.randomAnomalyPositions.Add(hexPos);
                                    }
                                    else if (base.Context.Anomalies.Keys.Contains(poiName))
                                    {
                                        if (!base.Context.Anomalies[poiName].Contains(hexPos))
                                        {
                                            base.Context.Anomalies[poiName].Add(hexPos);
                                        }
                                    }
                                    else
                                    {
                                        base.Context.Anomalies.Add(poiName, new List <HexPos>());
                                        base.Context.Anomalies[poiName].Add(hexPos);
                                    }
                                }
                                if (poiName.Contains("Village"))
                                {
                                    if (poiName == ImportTmxPointOfInterestLayer.randomMinorFactionVillage)
                                    {
                                        string[] array3 = (from template in base.Context.Settings.POITemplates.Values
                                                           select template.Name into name
                                                           where name.Contains("Village_")
                                                           select name).ToArray <string>();
                                        poiName = array3[this.random.Next(array3.Length)];
                                    }
                                    short  key    = base.Context.RegionData[j, i];
                                    Region region = base.Context.Regions[key];
                                    if (region == null || poiName.Split(new char[]
                                    {
                                        '_'
                                    }).Count <string>() < 2)
                                    {
                                        goto IL_9F7;
                                    }
                                    Region region2  = region;
                                    int    villages = region2.Villages;
                                    region2.Villages = villages + 1;
                                    if (string.IsNullOrEmpty(region.MinorFactionName))
                                    {
                                        region.MinorFactionName = poiName.Split(new char[]
                                        {
                                            '_'
                                        })[1];
                                    }
                                    else
                                    {
                                        poiName = "Village_" + region.MinorFactionName;
                                    }
                                }
                                if (poiName == ImportTmxPointOfInterestLayer.randomStrategicResourceDepositName)
                                {
                                    string[] array4 = (from template in base.Context.Settings.POITemplates.Values
                                                       select template.Name into name
                                                       where name.Contains("ResourceDeposit_Strategic")
                                                       select name).ToArray <string>();
                                    poiName = array4[this.random.Next(array4.Length)];
                                }
                                if (poiName == ImportTmxPointOfInterestLayer.randomLuxuryResourceDepositName)
                                {
                                    string[] array5 = (from template in base.Context.Settings.POITemplates.Values
                                                       select template.Name into name
                                                       where name.Contains("ResourceDeposit_Luxury")
                                                       select name).ToArray <string>();
                                    poiName = array5[this.random.Next(array5.Length)];
                                }
                                PointOfInterestTemplate pointOfInterestTemplate = base.Context.Settings.POITemplates.Values.FirstOrDefault((PointOfInterestTemplate template) => template.Name == poiName);
                                if (!flag2 && (poiName.Contains("Facility") || poiName.Contains("Citadel") || poiName.Contains("NavalQuestLocation_SunkenRuin")))
                                {
                                    pointOfInterestTemplate = null;
                                }
                                if (pointOfInterestTemplate != null)
                                {
                                    if (poiName.Contains("ResourceDeposit"))
                                    {
                                        short  key2    = base.Context.RegionData[j, i];
                                        Region region3 = base.Context.Regions[key2];
                                        if (region3 != null)
                                        {
                                            region3.Resources.Add(new PointOfInterestDefinition
                                            {
                                                Position     = new HexPos(i, j),
                                                TemplateName = pointOfInterestTemplate.Name
                                            });
                                        }
                                    }
                                    base.Context.POIDefinitions.Add(new PointOfInterestDefinition
                                    {
                                        Position     = new HexPos(i, j),
                                        TemplateName = pointOfInterestTemplate.Name
                                    });
                                }
                            }
                        }
                    }
                    IL_9F7 :;
                }
            }
            this.customRandomizationGroups.Clear();
        }