Example #1
0
 static TownEngine()
 {
     TownEngine.Towns = new List <Town>();
     foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
     {
         foreach (Type t in a.GetTypes())
         {
             if (typeof(Town).IsAssignableFrom(t) && !t.IsAbstract)
             {
                 TownEngine.Towns.Add(TownEngine.NewTown(t));
             }
         }
     }
 }
Example #2
0
 public override Dictionary <int, LayerColor> GetLayerColors()
 {
     return(TownEngine.GetTownBrushes());
 }
Example #3
0
        protected override int[] GenerateDataImpl(long x, long y, long width, long height)
        {
            if (this.Parents.Length < 5 || this.Parents[0] == null || this.Parents[1] == null || this.Parents[2] == null || this.Parents[3] == null || this.Parents[4] == null)
            {
                return(new int[width * height]);
            }

            int[]      soilfertility     = this.Parents[0].GenerateData(x, y, width, height);
            int[]      oredensity        = this.Parents[1].GenerateData(x, y, width, height);
            int[]      rareoredensity    = this.Parents[2].GenerateData(x, y, width, height);
            int[]      distancefromwater = this.Parents[3].GenerateData(x, y, width, height);
            int[]      townscatter       = this.Parents[4].GenerateData(x, y, width, height);
            int[]      data        = new int[width * height];
            List <int> ViableTowns = new List <int>();

            // Write out the secondary biomes.
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (townscatter[i + j * width] == 1)
                    {
                        if (distancefromwater[i + j * width] <= MaxDistanceFromWater)
                        {
                            // Normalize values.
                            double nsoilfertility     = (soilfertility[i + j * width] - this.MinSoilFertility) / (double)(this.MaxSoilFertility - this.MinSoilFertility);
                            double noredensity        = (oredensity[i + j * width] - this.MinOreDensity) / (double)(this.MaxOreDensity - this.MinOreDensity);
                            double nrareoredensity    = (rareoredensity[i + j * width] - this.MinRareOreDensity) / (double)(this.MaxRareOreDensity - this.MinRareOreDensity);
                            double ndistancefromwater = (distancefromwater[i + j * width]);

                            // Store result.
                            ViableTowns = TownEngine.GetTownsForCell(nsoilfertility, noredensity, nrareoredensity, ndistancefromwater);

                            // If no towns are viable then it returns 0
                            if (ViableTowns.Count == 0)
                            {
                                data[i + j * width] = 0;
                            }
                            else
                            {
                                // Define Variables
                                double[] TownScore            = new double[ViableTowns.Count];
                                int      currentbesttown      = 0;
                                double   currentbesttownscore = 0;

                                // Checks the list of viable towns.
                                for (int k = 0; k < ViableTowns.Count; k++)
                                {
                                    TownScore[k] = TownEngine.Towns[ViableTowns[k]].MinOreDensity + TownEngine.Towns[ViableTowns[k]].MinRareOreDensity + TownEngine.Towns[ViableTowns[k]].MinSoilFertility;
                                }

                                // Checks each town score to check which is the highest
                                for (int l = 0; l < ViableTowns.Count; l++)
                                {
                                    if (TownScore[l] > currentbesttownscore)
                                    {
                                        currentbesttownscore = TownScore[l];
                                        currentbesttown      = l;
                                    }
                                    else if (TownScore[l] == currentbesttownscore)
                                    {
                                        int selected = this.GetRandomRange(x + i, y + j, 0, 2);

                                        if (selected == 0)
                                        {
                                            currentbesttown = l;
                                        }
                                    }
                                }

                                // Set the point to be equal to the town that is placed.
                                data[i + j * width] = ViableTowns[currentbesttown] + 1;
                            }
                        }
                    }
                    else
                    {
                        data[i + j * width] = 0;
                    }
                }
            }

            return(data);
        }