Beispiel #1
0
 private void DetectDensity()
 {
     if (pixelCount == 64)
     {
         density = DensityType.SOLID;
     }
     else if (pixelCount >= 48)
     {
         density = DensityType.HIGH;
     }
     else if (pixelCount >= 32)
     {
         density = DensityType.MEDIUM;
     }
     else if (pixelCount >= 16)
     {
         density = DensityType.AVERAGE;
     }
     else if (pixelCount > 0)
     {
         density = DensityType.LOW;
     }
     else
     {
         density = DensityType.EMPTY;
     }
 }
Beispiel #2
0
    void Awake()
    {
        sName = "Region Name " + Math.Round(UnityEngine.Random.value * 100, 1);

        int type = UnityEngine.Random.Range(0, (int)DensityType.count);

        eDensityType = (DensityType)type;
        if (type >= 0 && type < (int)DensityType.count)
        {
            GetComponent <SpriteRenderer>().sprite = regionSprites[type];
        }
    }
Beispiel #3
0
        private int to_upgrade;         // Amount left to upgrade density

        // Constructor
        public Building()
        {
            this.lotSize         = 0;
            this.density         = DensityType.Low;
            this.occupants       = 0;
            this.happiness       = 10;
            this.isEnergy        = false;
            this.isWater         = false;
            this.income          = 0;
            this.expenses        = 0;
            this.liquid_earnings = this.income - this.expenses;
            this.to_upgrade      = 10;
        }
Beispiel #4
0
 public DensityType ReadDensity()
 {
     DensityType pid = (DensityType)this.GetPID(); ;
     switch (pid)
     {
         case DensityType.LOW_DENSITY:
         case DensityType.MEDIUM_DENSITY:
             this.PageSize = 1024;
             break;
         case DensityType.HIGH_DENSITY:
         case DensityType.XL_DENSITY:
         case DensityType.CONNECTIVITY_DENSITY:
             this.PageSize = 2048;
             break;
         default:
             this.PageSize = 1024;
             break;
     }
     return pid;
 }
Beispiel #5
0
 public Tile(DensityType type, float value)
 {
     Type  = type;
     Value = value;
     Color = type.Color;
 }
Beispiel #6
0
    public void Generate()
    {
        MapData.CalculateData(Noise);
        MeshData.Calculate(MapData.Values);

        float max = float.MinValue;

        for (int z = 0; z < Length; z++)
        {
            for (int x = 0; x < Width; x++)
            {
                if (Tiles[x, z] == null)
                {
                    Stack <Vector2> stack = new Stack <Vector2>();
                    stack.Push(new Vector2(x, z));

                    int T = GetTypeIndex(MapData.Values[x, z]);

                    while (stack.Count > 0)
                    {
                        Vector2 current = stack.Pop();
                        int     x1      = (int)current.x;
                        int     z1      = (int)current.y;
                        float   val     = MapData.Values[x1, z1];

                        if (x1 > 0)
                        {
                            CheckAndPush(x1 - 1, z1, T, stack);
                        }
                        if (x1 < Width - 1)
                        {
                            CheckAndPush(x1 + 1, z1, T, stack);
                        }
                        if (z1 > 0)
                        {
                            CheckAndPush(x1, z1 - 1, T, stack);
                        }
                        if (z1 < Length - 1)
                        {
                            CheckAndPush(x1, z1 + 1, T, stack);
                        }

                        if (val > max)
                        {
                            max         = val;
                            MaxPosition = new Vector3(x1, 0, z1);
                        }

                        DensityType type = Types[GetTypeIndex(val)];
                        Colors[x1 + z1 * Length] = type.Color;
                        Tiles[x1, z1]            = new Tile(type, val);
                    }
                }
            }
        }
        Texture = TextureGenerator.GenerateDensityTexture(Width, Length, Colors);

        int CheckAndPush(int x, int z, int t, Stack <Vector2> stack)
        {
            float value = MapData.Values[x, z];

            if (GetTypeIndex(value) == t)
            {
                if (Tiles[x, z] == null)
                {
                    stack.Push(new Vector2(x, z));
                }
                return(1);
            }
            return(0);
        }

        int GetTypeIndex(float val)
        {
            for (int i = 0; i < Types.Length; i++)
            {
                if (val <= Types[i].Percentile)
                {
                    return(i);
                }
            }
            return(-1);
        }
    }