Ejemplo n.º 1
0
        public void ModifyCell(int x, int z, DistrictManager.Cell cell)
        {
            if ((int)cell.m_alpha2 > (int)cell.m_alpha1)
            {
                Exchange(this, ref cell.m_alpha1, ref cell.m_alpha2, ref cell.m_district1, ref cell.m_district2);
            }
            if ((int)cell.m_alpha3 > (int)cell.m_alpha1)
            {
                Exchange(this, ref cell.m_alpha1, ref cell.m_alpha3, ref cell.m_district1, ref cell.m_district3);
            }
            if ((int)cell.m_alpha4 > (int)cell.m_alpha1)
            {
                Exchange(this, ref cell.m_alpha1, ref cell.m_alpha4, ref cell.m_district1, ref cell.m_district4);
            }
            //begin mod
            int index = z * GRID + x;

            DistrictManager.Cell cell1 = districtGrid[index];
            districtGrid[index] = cell;
            //end mod
            this.m_districts.m_buffer[(int)cell.m_district1].m_totalAlpha += (uint)cell.m_alpha1;
            this.m_districts.m_buffer[(int)cell.m_district2].m_totalAlpha += (uint)cell.m_alpha2;
            this.m_districts.m_buffer[(int)cell.m_district3].m_totalAlpha += (uint)cell.m_alpha3;
            this.m_districts.m_buffer[(int)cell.m_district4].m_totalAlpha += (uint)cell.m_alpha4;
            EraseDistrict(this, cell1.m_district1, ref this.m_districts.m_buffer[(int)cell1.m_district1], (uint)cell1.m_alpha1);
            EraseDistrict(this, cell1.m_district2, ref this.m_districts.m_buffer[(int)cell1.m_district2], (uint)cell1.m_alpha2);
            EraseDistrict(this, cell1.m_district3, ref this.m_districts.m_buffer[(int)cell1.m_district3], (uint)cell1.m_alpha3);
            EraseDistrict(this, cell1.m_district4, ref this.m_districts.m_buffer[(int)cell1.m_district4], (uint)cell1.m_alpha4);
        }
Ejemplo n.º 2
0
        static public void WriteDistrictsFile()
        {
            var districts = getDistricts();

            using (StreamWriter writeText = new StreamWriter("D:\\Workspace\\Cities\\districts.txt"))
            {
                int sqrt         = (int)(Math.Sqrt(districts.Length));
                int sqrtDistrict = (int)(Math.Sqrt(districts.Length));
                writeText.WriteLine($"Lenght SQRT: {sqrt} and {sqrtDistrict}");
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < sqrt; j++)
                    {
                        string line = "";
                        for (int k = 0; k < sqrt; k++)
                        {
                            DistrictManager.Cell cell = districts[j * sqrt + k];
                            int districtId            = GetDistrictData(cell, i);

                            if (districtId != 0)
                            {
                                line += Convert.ToChar(districtId);
                            }
                            else
                            {
                                line += "_";
                            }
                        }
                        writeText.WriteLine(line);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static bool ForceDistrictAlpha(int x, int z, DistrictTool.Layer layer, byte district, int min, int max)
        {
            //begin mod
            int num1 = FakeDistrictManager.GRID;

            DistrictManager.Cell cell1 = (layer != DistrictTool.Layer.Districts ? FakeDistrictManager.parkGrid : FakeDistrictManager.districtGrid)[z * num1 + x];
            //end mod
            int num2 = Mathf.Clamp(GetAlpha(ref cell1, district), min, max);

            DistrictManager.Cell cell2 = new DistrictManager.Cell();
            cell2.m_district1 = district;
            cell2.m_district2 = (byte)0;
            cell2.m_alpha1    = (byte)num2;
            cell2.m_alpha2    = (byte)((int)byte.MaxValue - num2);
            if ((int)cell2.m_alpha1 == (int)cell1.m_alpha1 && (int)cell2.m_alpha2 == (int)cell1.m_alpha2 && ((int)cell2.m_alpha3 == (int)cell1.m_alpha3 && (int)cell2.m_alpha4 == (int)cell1.m_alpha4) && ((int)cell2.m_district1 == (int)cell1.m_district1 && (int)cell2.m_district2 == (int)cell1.m_district2 && ((int)cell2.m_district3 == (int)cell1.m_district3 && (int)cell2.m_district4 == (int)cell1.m_district4)))
            {
                return(false);
            }
            if (layer == DistrictTool.Layer.Districts)
            {
                Singleton <DistrictManager> .instance.ModifyCell(x, z, cell2);
            }
            else
            {
                Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell2);
            }
            return(true);
        }
Ejemplo n.º 4
0
        static public int GetDistrictData(DistrictManager.Cell cell, int val)
        {
            switch (val)
            {
            case 0:
                return(cell.m_alpha1);

            case 1:
                return(cell.m_alpha2);

            case 2:
                return(cell.m_alpha3);

            case 3:
                return(cell.m_alpha4);

            case 4:
                return(cell.m_district1);

            case 5:
                return(cell.m_district2);

            case 6:
                return(cell.m_district3);

            case 7:
                return(cell.m_district4);

            default:
                return(-1);
            }
        }
Ejemplo n.º 5
0
            public void AfterDeserialize(DataSerializer s)
            {
                Singleton <LoadingManager> .instance.WaitUntilEssentialScenesLoaded();

                DistrictManager instance = Singleton <DistrictManager> .instance;

                District[]             buffer       = instance.m_districts.m_buffer;
                DistrictManager.Cell[] districtGrid = FakeDistrictManager.districtGrid;
                int num = districtGrid.Length;

                for (int i = 0; i < num; i++)
                {
                    DistrictManager.Cell cell         = districtGrid[i];
                    District[]           expr_60_cp_0 = buffer;
                    byte expr_60_cp_1 = cell.m_district1;
                    expr_60_cp_0[(int)expr_60_cp_1].m_totalAlpha = expr_60_cp_0[(int)expr_60_cp_1].m_totalAlpha + (uint)cell.m_alpha1;
                    District[] expr_80_cp_0 = buffer;
                    byte       expr_80_cp_1 = cell.m_district2;
                    expr_80_cp_0[(int)expr_80_cp_1].m_totalAlpha = expr_80_cp_0[(int)expr_80_cp_1].m_totalAlpha + (uint)cell.m_alpha2;
                    District[] expr_A0_cp_0 = buffer;
                    byte       expr_A0_cp_1 = cell.m_district3;
                    expr_A0_cp_0[(int)expr_A0_cp_1].m_totalAlpha = expr_A0_cp_0[(int)expr_A0_cp_1].m_totalAlpha + (uint)cell.m_alpha3;
                    District[] expr_C0_cp_0 = buffer;
                    byte       expr_C0_cp_1 = cell.m_district4;
                    expr_C0_cp_0[(int)expr_C0_cp_1].m_totalAlpha = expr_C0_cp_0[(int)expr_C0_cp_1].m_totalAlpha + (uint)cell.m_alpha4;
                }
                instance.m_districtCount = (int)(instance.m_districts.ItemCount() - 1u);
                instance.AreaModified(0, 0, 511, 511, true);
                instance.NamesModified();
            }
Ejemplo n.º 6
0
 public DistrictManager.Cell[] generateDistricts()
 {
     string[] lines = System.IO.File.ReadAllLines(@"D:\Workspace\Cities\districtsFile.txt");
     DistrictManager.Cell[] districts = new DistrictManager.Cell[512 * 512];
     for (int i = 0; i < lines.Length; i++)
     {
         string line = lines[i];
         for (int j = 0; j < line.Length; j++)
         {
             char c = line[j];
             districts[i * lines.Length + j].m_district1 = (byte)c;
         }
     }
     return(districts);
 }
Ejemplo n.º 7
0
            public void Deserialize(DataSerializer s)
            {
                var districtGrid = new DistrictManager.Cell[GRID * GRID];

                EncodedArray.Byte @byte = EncodedArray.Byte.BeginRead(s);
                int num2 = districtGrid.Length;

                for (int num21 = 0; num21 < num2; num21++)
                {
                    districtGrid[num21].m_district1 = @byte.Read();
                }
                for (int num22 = 0; num22 < num2; num22++)
                {
                    districtGrid[num22].m_district2 = @byte.Read();
                }
                for (int num23 = 0; num23 < num2; num23++)
                {
                    districtGrid[num23].m_district3 = @byte.Read();
                }
                for (int num24 = 0; num24 < num2; num24++)
                {
                    districtGrid[num24].m_district4 = @byte.Read();
                }
                for (int num25 = 0; num25 < num2; num25++)
                {
                    districtGrid[num25].m_alpha1 = @byte.Read();
                }
                for (int num26 = 0; num26 < num2; num26++)
                {
                    districtGrid[num26].m_alpha2 = @byte.Read();
                }
                for (int num27 = 0; num27 < num2; num27++)
                {
                    districtGrid[num27].m_alpha3 = @byte.Read();
                }
                for (int num28 = 0; num28 < num2; num28++)
                {
                    districtGrid[num28].m_alpha4 = @byte.Read();
                }
                @byte.EndRead();

                FakeDistrictManager.districtGrid = districtGrid;
            }
        private bool ForceDistrictAlpha(int x, int z, byte district, int min, int max)
        {
            //begin mod
            DistrictManager.Cell[] districtGrid = FakeDistrictManager.districtGrid;
            DistrictManager.Cell   cell         = districtGrid[z * FakeDistrictManager.GRID + x];
            //end mod
            int num2 = Mathf.Clamp(GetAlpha(this, ref cell, district), min, max);

            DistrictManager.Cell cell2 = default(DistrictManager.Cell);
            cell2.m_district1 = district;
            cell2.m_district2 = 0;
            cell2.m_alpha1    = (byte)num2;
            cell2.m_alpha2    = (byte)(255 - num2);
            if (cell2.m_alpha1 != cell.m_alpha1 || cell2.m_alpha2 != cell.m_alpha2 || cell2.m_alpha3 != cell.m_alpha3 || cell2.m_alpha4 != cell.m_alpha4 || cell2.m_district1 != cell.m_district1 || cell2.m_district2 != cell.m_district2 || cell2.m_district3 != cell.m_district3 || cell2.m_district4 != cell.m_district4)
            {
                Singleton <DistrictManager> .instance.ModifyCell(x, z, cell2);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
 static public int GetMatchingDistrictId(DistrictManager.Cell cell)
 {
     if (GetDistrictName(cell.m_district1) != null)
     {
         return(cell.m_district1);
     }
     else if (GetDistrictName(cell.m_district2) != null)
     {
         return(cell.m_district2);
     }
     else if (GetDistrictName(cell.m_district3) != null)
     {
         return(cell.m_district3);
     }
     else if (GetDistrictName(cell.m_district4) != null)
     {
         return(cell.m_district4);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 10
0
 private static void Normalize(ref DistrictManager.Cell cell, int ignoreIndex)
 {
     UnityEngine.Debug.Log($"{cell}-{ignoreIndex}");
 }
Ejemplo n.º 11
0
        private static bool SetDistrictAlpha(int x, int z, DistrictTool.Layer layer, byte district, int min, int max)
        {
            //begin mod
            int num1 = FakeDistrictManager.GRID;

            DistrictManager.Cell cell = (layer != DistrictTool.Layer.Districts ? FakeDistrictManager.parkGrid : FakeDistrictManager.districtGrid)[z * num1 + x];
            //end mod
            if ((int)cell.m_district1 == (int)district)
            {
                int num2 = Mathf.Clamp((int)cell.m_alpha1, min, max);
                if (num2 != (int)cell.m_alpha1)
                {
                    cell.m_alpha1 = (byte)num2;
                    Normalize(ref cell, 1);
                    if (layer == DistrictTool.Layer.Districts)
                    {
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                    }
                    else
                    {
                        Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                    }
                    return(true);
                }
            }
            else if ((int)cell.m_district2 == (int)district)
            {
                int num2 = Mathf.Clamp((int)cell.m_alpha2, min, max);
                if (num2 != (int)cell.m_alpha2)
                {
                    cell.m_alpha2 = (byte)num2;
                    Normalize(ref cell, 2);
                    if (layer == DistrictTool.Layer.Districts)
                    {
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                    }
                    else
                    {
                        Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                    }
                    return(true);
                }
            }
            else if ((int)cell.m_district3 == (int)district)
            {
                int num2 = Mathf.Clamp((int)cell.m_alpha3, min, max);
                if (num2 != (int)cell.m_alpha3)
                {
                    cell.m_alpha3 = (byte)num2;
                    Normalize(ref cell, 3);
                    if (layer == DistrictTool.Layer.Districts)
                    {
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                    }
                    else
                    {
                        Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                    }
                    return(true);
                }
            }
            else if ((int)cell.m_district4 == (int)district)
            {
                int num2 = Mathf.Clamp((int)cell.m_alpha4, min, max);
                if (num2 != (int)cell.m_alpha4)
                {
                    cell.m_alpha4 = (byte)num2;
                    Normalize(ref cell, 4);
                    if (layer == DistrictTool.Layer.Districts)
                    {
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                    }
                    else
                    {
                        Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                    }
                    return(true);
                }
            }
            else if (min > 0)
            {
                int num2 = 256;
                int num3 = -1;
                if ((int)cell.m_alpha1 < num2)
                {
                    num2 = (int)cell.m_alpha1;
                    num3 = 1;
                }
                if ((int)cell.m_alpha2 < num2)
                {
                    num2 = (int)cell.m_alpha2;
                    num3 = 2;
                }
                if ((int)cell.m_alpha3 < num2)
                {
                    num2 = (int)cell.m_alpha3;
                    num3 = 3;
                }
                if ((int)cell.m_alpha4 < num2)
                {
                    num2 = (int)cell.m_alpha4;
                    num3 = 4;
                }
                if (num2 <= min)
                {
                    if (num3 == 1)
                    {
                        cell.m_district1 = district;
                        cell.m_alpha1    = (byte)min;
                        Normalize(ref cell, 1);
                        if (layer == DistrictTool.Layer.Districts)
                        {
                            Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                        }
                        else
                        {
                            Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                        }
                        return(true);
                    }
                    if (num3 == 2)
                    {
                        cell.m_district2 = district;
                        cell.m_alpha2    = (byte)min;
                        Normalize(ref cell, 2);
                        if (layer == DistrictTool.Layer.Districts)
                        {
                            Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                        }
                        else
                        {
                            Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                        }
                        return(true);
                    }
                    if (num3 == 3)
                    {
                        cell.m_district3 = district;
                        cell.m_alpha3    = (byte)min;
                        Normalize(ref cell, 3);
                        if (layer == DistrictTool.Layer.Districts)
                        {
                            Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                        }
                        else
                        {
                            Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                        }
                        return(true);
                    }
                    if (num3 == 4)
                    {
                        cell.m_district4 = district;
                        cell.m_alpha4    = (byte)min;
                        Normalize(ref cell, 4);
                        if (layer == DistrictTool.Layer.Districts)
                        {
                            Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);
                        }
                        else
                        {
                            Singleton <DistrictManager> .instance.ModifyParkCell(x, z, cell);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 12
0
        private void UpdateTexture()
        {
            var modifyLock = modifyLockField.GetValue(this);

            do
            {
                ;
            }while (!Monitor.TryEnter(modifyLock, SimulationManager.SYNCHRONIZE_TIMEOUT));
            int  num;
            int  num2;
            int  num3;
            int  num4;
            bool fullUpdate;

            try
            {
                num        = (int)modifiedX1Field.GetValue(this);
                num2       = (int)modifiedZ1Field.GetValue(this);
                num3       = (int)modifiedX2Field.GetValue(this);
                num4       = (int)modifiedZ2Field.GetValue(this);
                fullUpdate = (bool)fullUpdateField.GetValue(this);
                modifiedX1Field.SetValue(this, 10000);
                modifiedZ1Field.SetValue(this, 10000);
                modifiedX2Field.SetValue(this, -10000);
                modifiedZ2Field.SetValue(this, -10000);
                fullUpdateField.SetValue(this, false);
            }
            finally
            {
                Monitor.Exit(modifyLock);
            }
            int[] areaGrid = Singleton <GameAreaManager> .instance.m_areaGrid;
            int   num5     = Mathf.RoundToInt(99.99999f);
            //begin mod
            int num6 = (FakeGameAreaManager.GRID * num5 >> 1) - HALFGRID;

            //end mod
            if ((num3 - num + 1) * (num4 - num2 + 1) > HALFGRID * HALFGRID)
            {
                num  = 1;
                num2 = 1;
                //begin mod
                num3 = GRID - 2;
                num4 = GRID - 2;
                //end mod
                if (fullUpdate)
                {
                    for (int i = num2; i <= num4; i++)
                    {
                        for (int j = num; j <= num3; j++)
                        {
                            //begin mod
                            int num7 = i * GRID + j;
                            DistrictManager.Cell cell = districtGrid[num7];
                            //end mod
                            Color32 color = new Color32(128, 128, 128, 128);
                            AddDistrictColor1(this, cell.m_district1, cell.m_alpha1, ref color);
                            AddDistrictColor1(this, cell.m_district2, cell.m_alpha2, ref color);
                            AddDistrictColor1(this, cell.m_district3, cell.m_alpha3, ref color);
                            AddDistrictColor1(this, cell.m_district4, cell.m_alpha4, ref color);
                            colorBuffer[num7] = color;
                        }
                    }
                    //begin mod
                    districtTexture1.SetPixels32(colorBuffer);
                    districtTexture1.Apply();
                    //end mod
                }
                for (int k = num2; k <= num4; k++)
                {
                    for (int l = num; l <= num3; l++)
                    {
                        //begin mod
                        int num8 = k * GRID + l;
                        DistrictManager.Cell cell2 = districtGrid[num8];
                        //end mod
                        bool inArea = false;
                        int  num9   = (l + num6) / num5;
                        int  num10  = (k + num6) / num5;
                        //begin mod
                        if (num9 >= 0 && num9 < FakeGameAreaManager.GRID && num10 >= 0 && num10 < FakeGameAreaManager.GRID)
                        {
                            inArea = (areaGrid[num10 * FakeGameAreaManager.GRID + num9] != 0);
                        }
                        //end mod
                        Color32 color2 = new Color32(128, 128, 128, 128);
                        AddDistrictColor2(this, cell2.m_district1, this.HighlightPolicy, cell2.m_alpha1, inArea, ref color2);
                        AddDistrictColor2(this, cell2.m_district2, this.HighlightPolicy, cell2.m_alpha2, inArea, ref color2);
                        AddDistrictColor2(this, cell2.m_district3, this.HighlightPolicy, cell2.m_alpha3, inArea, ref color2);
                        AddDistrictColor2(this, cell2.m_district4, this.HighlightPolicy, cell2.m_alpha4, inArea, ref color2);
                        //begin mod
                        colorBuffer[num8] = color2;
                        //end mod
                    }
                }
                //begin mod
                districtTexture2.SetPixels32(colorBuffer);
                districtTexture2.Apply();
                //end mod
            }
            else
            {
                num  = Mathf.Max(1, num);
                num2 = Mathf.Max(1, num2);
                //begin mod
                num3 = Mathf.Min(GRID - 2, num3);
                num4 = Mathf.Min(GRID - 2, num4);
                //end mod
                for (int m = num2; m <= num4; m++)
                {
                    for (int n = num; n <= num3; n++)
                    {
                        //begin mod
                        int num11 = m * GRID + n;
                        DistrictManager.Cell cell3 = districtGrid[num11];
                        //end mod
                        if (fullUpdate)
                        {
                            Color32 c = new Color32(128, 128, 128, 128);
                            AddDistrictColor1(this, cell3.m_district1, cell3.m_alpha1, ref c);
                            AddDistrictColor1(this, cell3.m_district2, cell3.m_alpha2, ref c);
                            AddDistrictColor1(this, cell3.m_district3, cell3.m_alpha3, ref c);
                            AddDistrictColor1(this, cell3.m_district4, cell3.m_alpha4, ref c);
                            districtTexture1.SetPixel(n, m, c);
                        }
                        bool inArea2 = false;
                        int  num12   = (n + num6) / num5;
                        int  num13   = (m + num6) / num5;
                        //begin mod
                        if (num12 >= 0 && num12 < FakeGameAreaManager.GRID && num13 >= 0 && num13 < FakeGameAreaManager.GRID)
                        {
                            inArea2 = (areaGrid[num13 * FakeGameAreaManager.GRID + num12] != 0);
                        }
                        //end mod
                        Color32 c2 = new Color32(128, 128, 128, 128);
                        AddDistrictColor2(this, cell3.m_district1, this.HighlightPolicy, cell3.m_alpha1, inArea2, ref c2);
                        AddDistrictColor2(this, cell3.m_district2, this.HighlightPolicy, cell3.m_alpha2, inArea2, ref c2);
                        AddDistrictColor2(this, cell3.m_district3, this.HighlightPolicy, cell3.m_alpha3, inArea2, ref c2);
                        AddDistrictColor2(this, cell3.m_district4, this.HighlightPolicy, cell3.m_alpha4, inArea2, ref c2);
                        //begin mod
                        districtTexture2.SetPixel(n, m, c2);
                        //end mod
                    }
                }
                //begin mod
                if (fullUpdate)
                {
                    districtTexture1.Apply();
                }
                districtTexture2.Apply();
                //end mod
            }
        }
Ejemplo n.º 13
0
 private static int GetAlpha(ref DistrictManager.Cell cell, byte district)
 {
     UnityEngine.Debug.Log($"{cell}-{district}");
     return(0);
 }
Ejemplo n.º 14
0
 private int GetAlpha(ref DistrictManager.Cell cell, byte district)
 {
     Debug.Log($"{cell}-{district}");
     return(0);
 }
Ejemplo n.º 15
0
 private void Normalize(ref DistrictManager.Cell cell, int ignoreIndex)
 {
     Debug.Log($"{cell}-{ignoreIndex}");
 }
Ejemplo n.º 16
0
 public new void GetDistrictArea(byte district, out int minX, out int minZ, out int maxX, out int maxZ)
 {
     minX = 10000;
     minZ = 10000;
     maxX = -10000;
     maxZ = -10000;
     //begin mod
     for (int index1 = 0; index1 < GRID; ++index1)
     {
         for (int index2 = 0; index2 < GRID; ++index2)
         {
             DistrictManager.Cell cell = districtGrid[index1 * GRID + index2];
             //end mod
             if ((int)cell.m_alpha1 != 0 && (int)cell.m_district1 == (int)district)
             {
                 if (index2 < minX)
                 {
                     minX = index2;
                 }
                 if (index1 < minZ)
                 {
                     minZ = index1;
                 }
                 if (index2 > maxX)
                 {
                     maxX = index2;
                 }
                 if (index1 > maxZ)
                 {
                     maxZ = index1;
                 }
             }
             else if ((int)cell.m_alpha2 != 0 && (int)cell.m_district2 == (int)district)
             {
                 if (index2 < minX)
                 {
                     minX = index2;
                 }
                 if (index1 < minZ)
                 {
                     minZ = index1;
                 }
                 if (index2 > maxX)
                 {
                     maxX = index2;
                 }
                 if (index1 > maxZ)
                 {
                     maxZ = index1;
                 }
             }
             else if ((int)cell.m_alpha3 != 0 && (int)cell.m_district3 == (int)district)
             {
                 if (index2 < minX)
                 {
                     minX = index2;
                 }
                 if (index1 < minZ)
                 {
                     minZ = index1;
                 }
                 if (index2 > maxX)
                 {
                     maxX = index2;
                 }
                 if (index1 > maxZ)
                 {
                     maxZ = index1;
                 }
             }
             else if ((int)cell.m_alpha4 != 0 && (int)cell.m_district4 == (int)district)
             {
                 if (index2 < minX)
                 {
                     minX = index2;
                 }
                 if (index1 < minZ)
                 {
                     minZ = index1;
                 }
                 if (index2 > maxX)
                 {
                     maxX = index2;
                 }
                 if (index1 > maxZ)
                 {
                     maxZ = index1;
                 }
             }
         }
     }
 }
            public void Deserialize(DataSerializer s)
            {
                var districtGrid = new DistrictManager.Cell[GRID * GRID];
                EncodedArray.Byte @byte = EncodedArray.Byte.BeginRead(s);
                int num2 = districtGrid.Length;
                for (int num21 = 0; num21 < num2; num21++)
                {
                    districtGrid[num21].m_district1 = @byte.Read();
                }
                for (int num22 = 0; num22 < num2; num22++)
                {
                    districtGrid[num22].m_district2 = @byte.Read();
                }
                for (int num23 = 0; num23 < num2; num23++)
                {
                    districtGrid[num23].m_district3 = @byte.Read();
                }
                for (int num24 = 0; num24 < num2; num24++)
                {
                    districtGrid[num24].m_district4 = @byte.Read();
                }
                for (int num25 = 0; num25 < num2; num25++)
                {
                    districtGrid[num25].m_alpha1 = @byte.Read();
                }
                for (int num26 = 0; num26 < num2; num26++)
                {
                    districtGrid[num26].m_alpha2 = @byte.Read();
                }
                for (int num27 = 0; num27 < num2; num27++)
                {
                    districtGrid[num27].m_alpha3 = @byte.Read();
                }
                for (int num28 = 0; num28 < num2; num28++)
                {
                    districtGrid[num28].m_alpha4 = @byte.Read();
                }
                @byte.EndRead();

                FakeDistrictManager.m_districtGrid = districtGrid;
            }
        private void CheckNeighbourCells(int x, int z, byte district, out int min, out int max)
        {
            min = 255;
            max = 0;
            //begin mod
            int num = FakeDistrictManager.GRID;

            DistrictManager.Cell[] districtGrid = FakeDistrictManager.districtGrid;
            //end mod
            if (z > 0)
            {
                if (x > 0)
                {
                    DistrictManager.Cell cell = districtGrid[(z - 1) * num + x - 1];
                    int alpha = GetAlpha(this, ref cell, district);
                    min = Mathf.Min(min, alpha);
                    max = Mathf.Max(max, alpha);
                }
                DistrictManager.Cell cell2 = districtGrid[(z - 1) * num + x];
                int alpha2 = GetAlpha(this, ref cell2, district);
                min = Mathf.Min(min, alpha2);
                max = Mathf.Max(max, alpha2);
                if (x < num - 1)
                {
                    DistrictManager.Cell cell3 = districtGrid[(z - 1) * num + x + 1];
                    int alpha3 = GetAlpha(this, ref cell3, district);
                    min = Mathf.Min(min, alpha3);
                    max = Mathf.Max(max, alpha3);
                }
            }
            if (x > 0)
            {
                DistrictManager.Cell cell4 = districtGrid[z * num + x - 1];
                int alpha4 = GetAlpha(this, ref cell4, district);
                min = Mathf.Min(min, alpha4);
                max = Mathf.Max(max, alpha4);
            }
            if (x < num - 1)
            {
                DistrictManager.Cell cell5 = districtGrid[z * num + x + 1];
                int alpha5 = GetAlpha(this, ref cell5, district);
                min = Mathf.Min(min, alpha5);
                max = Mathf.Max(max, alpha5);
            }
            if (z < num - 1)
            {
                if (x > 0)
                {
                    DistrictManager.Cell cell6 = districtGrid[(z + 1) * num + x - 1];
                    int alpha6 = GetAlpha(this, ref cell6, district);
                    min = Mathf.Min(min, alpha6);
                    max = Mathf.Max(max, alpha6);
                }
                DistrictManager.Cell cell7 = districtGrid[(z + 1) * num + x];
                int alpha7 = GetAlpha(this, ref cell7, district);
                min = Mathf.Min(min, alpha7);
                max = Mathf.Max(max, alpha7);
                if (x < num - 1)
                {
                    DistrictManager.Cell cell8 = districtGrid[(z + 1) * num + x + 1];
                    int alpha8 = GetAlpha(this, ref cell8, district);
                    min = Mathf.Min(min, alpha8);
                    max = Mathf.Max(max, alpha8);
                }
            }
        }
        private void ApplyBrush(byte district)
        {
            GameAreaManager instance = Singleton <GameAreaManager> .instance;

            //begin mod
            DistrictManager.Cell[] districtGrid = FakeDistrictManager.districtGrid;
            //end mod
            float num  = 19.2f;
            float num2 = this.m_brushSize * 0.35f + num;
            int   num3 = FakeDistrictManager.GRID;

            Vector3 vector        = (Vector3)m_lastPaintPosition.GetValue(this);
            Vector3 mousePosition = (Vector3)m_mousePosition.GetValue(this);

            if (vector.x < -50000f)
            {
                vector = mousePosition;
            }
            vector.y        = 0f;
            mousePosition.y = 0f;
            Vector3 vector2 = Vector3.Min(vector, mousePosition);
            Vector3 vector3 = Vector3.Max(vector, mousePosition);
            int     num4    = Mathf.Max((int)((vector2.x - num2) / num + (float)num3 * 0.5f), 0);
            int     num5    = Mathf.Max((int)((vector2.z - num2) / num + (float)num3 * 0.5f), 0);
            int     num6    = Mathf.Min((int)((vector3.x + num2) / num + (float)num3 * 0.5f), num3 - 1);
            int     num7    = Mathf.Min((int)((vector3.z + num2) / num + (float)num3 * 0.5f), num3 - 1);
            int     num8    = num3;
            int     num9    = -1;
            int     num10   = num3;
            int     num11   = -1;

            for (int i = num5; i <= num7; i++)
            {
                for (int j = num4; j <= num6; j++)
                {
                    Vector3 vector4 = new Vector3(((float)j - (float)num3 * 0.5f + 0.5f) * num, 0f, ((float)i - (float)num3 * 0.5f + 0.5f) * num);
                    Vector3 a       = vector4;
                    if (instance.ClampPoint(ref a))
                    {
                        float a2    = Mathf.Sqrt(Segment3.DistanceSqr(vector, mousePosition, vector4)) - num2 + num * 2f;
                        float num12 = Vector3.Distance(a, vector4);
                        float num13 = Mathf.Max(a2, num12) - num * 2f;
                        float num14 = Mathf.Clamp01(-num13 / (num * 2f));
                        if (num14 != 0f)
                        {
                            int  min = Mathf.Clamp((int)(256f * num14), 0, 255); //TODO(earalov): should that 256f be replaced with HALFGRID?
                            bool flag;
                            if (num12 > 1f && district != 0)
                            {
                                flag = ForceDistrictAlpha(j, i, district, min, 255);
                            }
                            else
                            {
                                flag = SetDistrictAlpha(j, i, district, min, 255);
                            }
                            if (flag)
                            {
                                num8  = Mathf.Min(num8, j);
                                num9  = Mathf.Max(num9, j);
                                num10 = Mathf.Min(num10, i);
                                num11 = Mathf.Max(num11, i);
                            }
                        }
                    }
                }
            }
            int  num15 = num8;
            int  num16 = num9;
            int  num17 = num10;
            int  num18 = num11;
            int  num19 = 0;
            bool flag2;

            do
            {
                num4  = Mathf.Max(num8 - 1, 0);
                num6  = Mathf.Min(num9 + 1, num3 - 1);
                num5  = Mathf.Max(num10 - 1, 0);
                num7  = Mathf.Min(num11 + 1, num3 - 1);
                num8  = num3;
                num9  = -1;
                num10 = num3;
                num11 = -1;
                flag2 = false;
                for (int k = num5; k <= num7; k++)
                {
                    for (int l = num4; l <= num6; l++)
                    {
                        DistrictManager.Cell cell = districtGrid[k * num3 + l];
                        bool flag3 = false;
                        bool flag4 = false;
                        if (cell.m_alpha1 != 0)
                        {
                            bool flag5 = cell.m_district1 == district;
                            int  num20;
                            int  num21;
                            CheckNeighbourCells(l, k, cell.m_district1, out num20, out num21);
                            if (!flag5 && Mathf.Min((int)(cell.m_alpha1 + 120), 255) > num21)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district1, 0, Mathf.Max(0, num21 - 120)));
                            }
                            else if (flag5 && Mathf.Max((int)(cell.m_alpha1 - 120), 0) < num20)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district1, Mathf.Min(255, num20 + 120), 255));
                            }
                            if (flag5)
                            {
                                flag3 = true;
                            }
                        }
                        if (cell.m_alpha2 != 0)
                        {
                            bool flag6 = cell.m_district2 == district;
                            int  num22;
                            int  num23;
                            CheckNeighbourCells(l, k, cell.m_district2, out num22, out num23);
                            if (!flag6 && Mathf.Min((int)(cell.m_alpha2 + 120), 255) > num23)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district2, 0, Mathf.Max(0, num23 - 120)));
                            }
                            else if (flag6 && Mathf.Max((int)(cell.m_alpha2 - 120), 0) < num22)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district2, Mathf.Min(255, num22 + 120), 255));
                            }
                            if (flag6)
                            {
                                flag3 = true;
                            }
                        }
                        if (cell.m_alpha3 != 0)
                        {
                            bool flag7 = cell.m_district3 == district;
                            int  num24;
                            int  num25;
                            CheckNeighbourCells(l, k, cell.m_district3, out num24, out num25);
                            if (!flag7 && Mathf.Min((int)(cell.m_alpha3 + 120), 255) > num25)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district3, 0, Mathf.Max(0, num25 - 120)));
                            }
                            else if (flag7 && Mathf.Max((int)(cell.m_alpha3 - 120), 0) < num24)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district3, Mathf.Min(255, num24 + 120), 255));
                            }
                            if (flag7)
                            {
                                flag3 = true;
                            }
                        }
                        if (cell.m_alpha4 != 0)
                        {
                            bool flag8 = cell.m_district4 == district;
                            int  num26;
                            int  num27;
                            CheckNeighbourCells(l, k, cell.m_district4, out num26, out num27);
                            if (!flag8 && Mathf.Min((int)(cell.m_alpha4 + 120), 255) > num27)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district4, 0, Mathf.Max(0, num27 - 120)));
                            }
                            else if (flag8 && Mathf.Max((int)(cell.m_alpha4 - 120), 0) < num26)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, cell.m_district4, Mathf.Min(255, num26 + 120), 255));
                            }
                            if (flag8)
                            {
                                flag3 = true;
                            }
                        }
                        if (!flag3)
                        {
                            int num28;
                            int num29;
                            CheckNeighbourCells(l, k, district, out num28, out num29);
                            if (0 < num28)
                            {
                                flag4 = (flag4 || SetDistrictAlpha(l, k, district, Mathf.Min(255, num28 + 120), 255));
                            }
                        }
                        if (flag4)
                        {
                            num8  = Mathf.Min(num8, l);
                            num9  = Mathf.Max(num9, l);
                            num10 = Mathf.Min(num10, k);
                            num11 = Mathf.Max(num11, k);
                            flag2 = true;
                        }
                    }
                }
                num15 = Mathf.Min(num15, num8);
                num16 = Mathf.Max(num16, num9);
                num17 = Mathf.Min(num17, num10);
                num18 = Mathf.Max(num18, num11);
            }while (++num19 < 10 && flag2);
            Singleton <DistrictManager> .instance.AreaModified(num15, num17, num16, num18, true);

            Singleton <DistrictManager> .instance.m_districtsNotUsed.Disable();
        }
Ejemplo n.º 20
0
 private static void SetBitAlphas(DistrictManager manager, DistrictManager.Cell cell, int alpha, ref int b1, ref int b2, ref int b3, ref int b4, ref int b5, ref int b6, ref int b7)
 {
     UnityEngine.Debug.Log($"{manager}-{cell}-{alpha}-{b1}-{b2}-{b3}-{b4}-{b5}-{b6}-{b7}");
 }
Ejemplo n.º 21
0
        public static void ApplyBrush(DistrictTool.Layer layer, byte district, float brushRadius, Vector3 startPosition, Vector3 endPosition)
        {
            GameAreaManager instance = Singleton <GameAreaManager> .instance;

            //begin mod
            DistrictManager.Cell[] cellArray = layer != DistrictTool.Layer.Districts ? FakeDistrictManager.parkGrid : FakeDistrictManager.districtGrid;
            //end mod
            float num1 = 19.2f;
            //begin mod
            int num2 = FakeDistrictManager.GRID;

            //end mod
            if ((double)startPosition.x < -50000.0)
            {
                startPosition = endPosition;
            }
            startPosition.y = 0.0f;
            endPosition.y   = 0.0f;
            Vector3 vector3_1 = Vector3.Min(startPosition, endPosition);
            Vector3 vector3_2 = Vector3.Max(startPosition, endPosition);
            int     num3      = Mathf.Max((int)(((double)vector3_1.x - (double)brushRadius) / (double)num1 + (double)num2 * 0.5), 0);
            int     num4      = Mathf.Max((int)(((double)vector3_1.z - (double)brushRadius) / (double)num1 + (double)num2 * 0.5), 0);
            int     num5      = Mathf.Min((int)(((double)vector3_2.x + (double)brushRadius) / (double)num1 + (double)num2 * 0.5), num2 - 1);
            int     num6      = Mathf.Min((int)(((double)vector3_2.z + (double)brushRadius) / (double)num1 + (double)num2 * 0.5), num2 - 1);
            int     num7      = num2;
            int     num8      = -1;
            int     num9      = num2;
            int     num10     = -1;

            for (int index1 = num4; index1 <= num6; ++index1)
            {
                for (int index2 = num3; index2 <= num5; ++index2)
                {
                    Vector3 vector3_3 = new Vector3((float)((double)index2 - (double)num2 * 0.5 + 0.5) * num1, 0.0f, (float)((double)index1 - (double)num2 * 0.5 + 0.5) * num1);
                    Vector3 position  = vector3_3;
                    if (instance.ClampPoint(ref position))
                    {
                        float a     = (float)((double)Mathf.Sqrt(Segment3.DistanceSqr(startPosition, endPosition, vector3_3)) - (double)brushRadius + (double)num1 * 2.0);
                        float b     = Vector3.Distance(position, vector3_3);
                        float num11 = Mathf.Clamp01((float)(-(double)(Mathf.Max(a, b) - num1 * 2f) / ((double)num1 * 2.0)));
                        if ((double)num11 != 0.0)
                        {
                            int min = Mathf.Clamp((int)(256.0 * (double)num11), 0, (int)byte.MaxValue);
                            if ((double)b <= 1.0 || (int)district == 0 ? SetDistrictAlpha(index2, index1, layer, district, min, (int)byte.MaxValue) : ForceDistrictAlpha(index2, index1, layer, district, min, (int)byte.MaxValue))
                            {
                                num7  = Mathf.Min(num7, index2);
                                num8  = Mathf.Max(num8, index2);
                                num9  = Mathf.Min(num9, index1);
                                num10 = Mathf.Max(num10, index1);
                            }
                        }
                    }
                }
            }
            int  num12 = num7;
            int  num13 = num8;
            int  num14 = num9;
            int  num15 = num10;
            int  num16 = 0;
            bool flag1;

            do
            {
                int num11 = Mathf.Max(num7 - 1, 0);
                int num17 = Mathf.Min(num8 + 1, num2 - 1);
                int num18 = Mathf.Max(num9 - 1, 0);
                int num19 = Mathf.Min(num10 + 1, num2 - 1);
                num7  = num2;
                num8  = -1;
                num9  = num2;
                num10 = -1;
                flag1 = false;
                for (int index1 = num18; index1 <= num19; ++index1)
                {
                    for (int index2 = num11; index2 <= num17; ++index2)
                    {
                        DistrictManager.Cell cell = cellArray[index1 * num2 + index2];
                        bool flag2 = false;
                        bool flag3 = false;
                        if ((int)cell.m_alpha1 != 0)
                        {
                            bool flag4 = (int)cell.m_district1 == (int)district;
                            int  min;
                            int  max;
                            CheckNeighbourCells(index2, index1, layer, cell.m_district1, out min, out max);
                            if (!flag4 && Mathf.Min((int)cell.m_alpha1 + 120, (int)byte.MaxValue) > max)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district1, 0, Mathf.Max(0, max - 120));
                            }
                            else if (flag4 && Mathf.Max((int)cell.m_alpha1 - 120, 0) < min)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district1, Mathf.Min((int)byte.MaxValue, min + 120), (int)byte.MaxValue);
                            }
                            if (flag4)
                            {
                                flag2 = true;
                            }
                        }
                        if ((int)cell.m_alpha2 != 0)
                        {
                            bool flag4 = (int)cell.m_district2 == (int)district;
                            int  min;
                            int  max;
                            CheckNeighbourCells(index2, index1, layer, cell.m_district2, out min, out max);
                            if (!flag4 && Mathf.Min((int)cell.m_alpha2 + 120, (int)byte.MaxValue) > max)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district2, 0, Mathf.Max(0, max - 120));
                            }
                            else if (flag4 && Mathf.Max((int)cell.m_alpha2 - 120, 0) < min)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district2, Mathf.Min((int)byte.MaxValue, min + 120), (int)byte.MaxValue);
                            }
                            if (flag4)
                            {
                                flag2 = true;
                            }
                        }
                        if ((int)cell.m_alpha3 != 0)
                        {
                            bool flag4 = (int)cell.m_district3 == (int)district;
                            int  min;
                            int  max;
                            CheckNeighbourCells(index2, index1, layer, cell.m_district3, out min, out max);
                            if (!flag4 && Mathf.Min((int)cell.m_alpha3 + 120, (int)byte.MaxValue) > max)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district3, 0, Mathf.Max(0, max - 120));
                            }
                            else if (flag4 && Mathf.Max((int)cell.m_alpha3 - 120, 0) < min)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district3, Mathf.Min((int)byte.MaxValue, min + 120), (int)byte.MaxValue);
                            }
                            if (flag4)
                            {
                                flag2 = true;
                            }
                        }
                        if ((int)cell.m_alpha4 != 0)
                        {
                            bool flag4 = (int)cell.m_district4 == (int)district;
                            int  min;
                            int  max;
                            CheckNeighbourCells(index2, index1, layer, cell.m_district4, out min, out max);
                            if (!flag4 && Mathf.Min((int)cell.m_alpha4 + 120, (int)byte.MaxValue) > max)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district4, 0, Mathf.Max(0, max - 120));
                            }
                            else if (flag4 && Mathf.Max((int)cell.m_alpha4 - 120, 0) < min)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, cell.m_district4, Mathf.Min((int)byte.MaxValue, min + 120), (int)byte.MaxValue);
                            }
                            if (flag4)
                            {
                                flag2 = true;
                            }
                        }
                        if (!flag2)
                        {
                            int min;
                            int max;
                            CheckNeighbourCells(index2, index1, layer, district, out min, out max);
                            if (0 < min)
                            {
                                flag3 = flag3 || SetDistrictAlpha(index2, index1, layer, district, Mathf.Min((int)byte.MaxValue, min + 120), (int)byte.MaxValue);
                            }
                        }
                        if (flag3)
                        {
                            num7  = Mathf.Min(num7, index2);
                            num8  = Mathf.Max(num8, index2);
                            num9  = Mathf.Min(num9, index1);
                            num10 = Mathf.Max(num10, index1);
                            flag1 = true;
                        }
                    }
                }
                num12 = Mathf.Min(num12, num7);
                num13 = Mathf.Max(num13, num8);
                num14 = Mathf.Min(num14, num9);
                num15 = Mathf.Max(num15, num10);
            }while (++num16 < 10 && flag1);
            if (layer == DistrictTool.Layer.Districts)
            {
                Singleton <DistrictManager> .instance.AreaModified(num12, num14, num13, num15, true);

                Singleton <DistrictManager> .instance.m_districtsNotUsed.Disable();
            }
            else
            {
                Singleton <DistrictManager> .instance.ParksAreaModified(num12, num14, num13, num15, true);
            }
        }
Ejemplo n.º 22
0
        //these overrides are not necessary, but obviously helpful
        //this seems to be called initially
        public override void Start()
        {
            //this makes the panel "visible", I don't know what sprites are available, but found this value to work
            this.backgroundSprite = "GenericPanel";
            this.color            = new Color32(0, 0, 255, 100);
            this.width            = 100;
            this.height           = 200;

            uint totalOre, totalOil, totalForest, totalFertility, totalWater;
            uint unlockableOre, unlockableOil, unlockableForest, unlockableFertility, unlockableWater;
            uint unlockedOre, unlockedOil, unlockedForest, unlockedFertility, unlockedWater;
            uint usedOre, usedOil, usedForest, usedFertility;

            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "hatters");
            NaturalResourceManager.instance.CalculateTotalResources(out totalOre, out totalOil, out totalForest, out totalFertility, out totalWater);
            NaturalResourceManager.instance.CalculateUnlockableResources(out unlockableOre, out unlockableOil, out unlockableForest, out unlockableFertility, out unlockableWater);
            NaturalResourceManager.instance.CalculateUnlockedResources(out unlockedOre, out unlockedOil, out unlockedForest, out unlockedFertility, out unlockedWater);
            NaturalResourceManager.instance.CalculateUsedResources(out usedOre, out usedOil, out usedForest, out usedFertility);

            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "mad hatters");
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "total:" + " " + totalOre + " " + totalOil + " " + totalForest + " " + totalFertility + " " + totalWater);
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "unlockable:" + " " + unlockableOre + " " + unlockableOil + " " + unlockableForest + " " + unlockableFertility + " " + unlockableWater);
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "unlocked:" + " " + unlockedOre + " " + unlockedOil + " " + unlockedForest + " " + unlockedFertility + " " + unlockedWater);
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "used:" + " " + usedOre + " " + usedOil + " " + usedForest + " " + usedFertility);
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "areaResource: " + NaturalResourceManager.instance.m_areaResources.Length + " naturalResource" + NaturalResourceManager.instance.m_naturalResources.Length);

            for (int i = 0; i < NaturalResourceManager.instance.m_areaResources.Length; i++)
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "" + i + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_finalOre + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_finalOil + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_finalForest + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_finalFertility + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_tempOre + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_tempOre + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_tempForest + ": " +
                                            NaturalResourceManager.instance.m_areaResources[i].m_tempFertility);
            }



            using (StreamWriter w = File.AppendText(("D:\\Workspace\\Cities\\test.txt")))
            {
                /*for (int i = 0; i < NaturalResourceManager.instance.m_naturalResources.Length; i++)
                 * {
                 *  var item = NaturalResourceManager.instance.m_naturalResources[i];
                 *
                 *  //m_fertility
                 *  //m_forest;
                 *  //m_modified;
                 *  //m_oil;
                 *  //m_ore;
                 *  //m_pollution;
                 *  //m_sand;
                 *  //m_tree;
                 *  //m_water;
                 *  w.WriteLine("natural resource:" + item.m_fertility + ">");
                 * }*/

                for (int i = 0; i < DistrictManager.instance.m_districtGrid.Length; i++)
                {
                    DistrictManager.Cell cell = DistrictManager.instance.m_districtGrid[i];
                    w.WriteLine("district:"
                                + ">" + cell.m_alpha1
                                + ">" + cell.m_alpha2
                                + ">" + cell.m_alpha3
                                + ">" + cell.m_alpha4
                                + ">" + cell.m_district1
                                + ">" + cell.m_district2
                                + ">" + cell.m_district3
                                + ">" + cell.m_district4
                                );
                }
            }

            UILabel x = this.AddUIComponent <UILabel>();
            UILabel y = this.AddUIComponent <UILabel>();
            UILabel z = this.AddUIComponent <UILabel>();

/*
 *          x.text = "X";
 *          y.text = "Y";
 *          z.text = "Z";
 *          x.position = new Vector3(10, 100);
 *          y.position = new Vector3(10, 80);
 *          z.position = new Vector3(10, 60);
 */



            /*for (int i = 0; i < districtCount; i++)
             * {
             *  labelList[i] = this.AddUIComponent<UILabel>();
             *  labelList[i].text = DistrictManager.instance.GetDistrictName(i);
             * }
             *
             * UIListBox districtList = this.AddUIComponent<UIListBox>();
             * districtList.Enable();
             * districtList.size = new Vector2(80, 80);
             * districtList.color = new Color32(255, 0, 0, 100);
             * districtList.animateHover = true;
             * districtList.itemHeight = 10;
             * districtList.itemHighlight = "penis";
             * districtList.itemHover = "poonani";
             * districtList.itemPadding = new RectOffset(1, 2, 3, 4);
             * districtList.itemTextColor = new Color32(255, 255, 255, 100);
             * districtList.listPadding = new RectOffset(1, 2, 3, 4);
             * districtList.scrollbar = new UIScrollbar();
             * districtList.scrollPosition = 0;
             * districtList.selectedIndex = 1;
             *
             *
             *
             *
             * districtList.items[0] = "Hello";
             * districtList.items[1] = "Caca";
             */

            //x.text = DistrictManager.instance.GetDistrictName(1);
        }
Ejemplo n.º 23
0
        static public void Calculate2()
        {
            List <DistrictResourceData> latestDistrictResourceList = new List <DistrictResourceData>();

            NaturalResourceManager.ResourceCell[] resourcesFromMap = getResource();
            DistrictManager.Cell[] districts = getDistricts();

            for (int i = 0; i < resourcesFromMap.Length; i++)
            {
                int oreFromMap     = resourcesFromMap[i].m_ore;
                int oilFromMap     = resourcesFromMap[i].m_oil;
                int forestFromMap  = resourcesFromMap[i].m_forest;
                int farmingFromMap = resourcesFromMap[i].m_fertility;
                if (oreFromMap + oilFromMap + forestFromMap + farmingFromMap != 0)
                {
                    int districtIndex = GetDistrictIndex(i);
                    if (districtIndex == -1)
                    {
                        // this resource cannot be in a district
                        continue;
                    }
                    DistrictManager.Cell cell = districts[districtIndex];
                    int    districtId         = GetMatchingDistrictId(cell);
                    string districtName       = GetDistrictName(districtId);
                    if (districtName != null)
                    {
                        DistrictResourceData result = latestDistrictResourceList.Find(x => x.Name.Contains(districtName));
                        if (result == null)
                        {
                            // need to add this distric
                            District district     = (District)getDistrictNames().m_buffer.GetValue(districtId);
                            int      districtType = (int)district.m_specializationPolicies;
                            latestDistrictResourceList.Add(new DistrictResourceData()
                            {
                                Name = districtName, Type = districtType
                            });
                            result = latestDistrictResourceList[latestDistrictResourceList.Count - 1];
                        }
                        // add the resources
                        result.Ore     += oreFromMap;
                        result.Oil     += oilFromMap;
                        result.Forest  += forestFromMap;
                        result.Farming += farmingFromMap;

                        result.Size++;
                    }
                }
            }

            for (int i = 0; i < districts.Length; i++)
            {
                DistrictManager.Cell cell = districts[i];
                int    districtId         = GetMatchingDistrictId(cell);
                string districtName       = GetDistrictName(districtId);
                if (districtName != null)
                {
                    DistrictResourceData result = latestDistrictResourceList.Find(x => x.Name.Contains(districtName));
                    if (result == null)
                    {
                        District district     = (District)getDistrictNames().m_buffer.GetValue(districtId);
                        int      districtType = (int)district.m_specializationPolicies;
                        latestDistrictResourceList.Add(new DistrictResourceData()
                        {
                            Name = districtName, Type = districtType
                        });
                        result = latestDistrictResourceList[latestDistrictResourceList.Count - 1];
                    }
                }
            }

            // now check for decline
            foreach (DistrictResourceData d in latestDistrictResourceList)
            {
                var oldData = districtResourceList.Find(f => f.Name == d.Name);
                if (oldData != null)
                {
                    if (oldData.Oil > d.Oil && d.GetPrecentage(d.Oil) < 0.05)
                    {
                        d.OilDecline = true;
                    }
                    if (oldData.Ore > d.Ore && d.GetPrecentage(d.Ore) < 0.05)
                    {
                        d.OreDecline = true;
                    }
                }
            }
            districtResourceList = latestDistrictResourceList;
        }
Ejemplo n.º 24
0
        private static void CheckNeighbourCells(int x, int z, DistrictTool.Layer layer, byte district, out int min, out int max)
        {
            min = (int)byte.MaxValue;
            max = 0;
            //begin mod
            int num = FakeDistrictManager.GRID;

            DistrictManager.Cell[] cellArray = layer != DistrictTool.Layer.Districts ? FakeDistrictManager.parkGrid : FakeDistrictManager.districtGrid;
            //end mod
            if (z > 0)
            {
                if (x > 0)
                {
                    DistrictManager.Cell cell = cellArray[(z - 1) * num + x - 1];
                    int alpha = GetAlpha(ref cell, district);
                    min = Mathf.Min(min, alpha);
                    max = Mathf.Max(max, alpha);
                }
                DistrictManager.Cell cell1 = cellArray[(z - 1) * num + x];
                int alpha1 = GetAlpha(ref cell1, district);
                min = Mathf.Min(min, alpha1);
                max = Mathf.Max(max, alpha1);
                if (x < num - 1)
                {
                    DistrictManager.Cell cell2 = cellArray[(z - 1) * num + x + 1];
                    int alpha2 = GetAlpha(ref cell2, district);
                    min = Mathf.Min(min, alpha2);
                    max = Mathf.Max(max, alpha2);
                }
            }
            if (x > 0)
            {
                DistrictManager.Cell cell = cellArray[z * num + x - 1];
                int alpha = GetAlpha(ref cell, district);
                min = Mathf.Min(min, alpha);
                max = Mathf.Max(max, alpha);
            }
            if (x < num - 1)
            {
                DistrictManager.Cell cell = cellArray[z * num + x + 1];
                int alpha = GetAlpha(ref cell, district);
                min = Mathf.Min(min, alpha);
                max = Mathf.Max(max, alpha);
            }
            if (z >= num - 1)
            {
                return;
            }
            if (x > 0)
            {
                DistrictManager.Cell cell = cellArray[(z + 1) * num + x - 1];
                int alpha = GetAlpha(ref cell, district);
                min = Mathf.Min(min, alpha);
                max = Mathf.Max(max, alpha);
            }
            DistrictManager.Cell cell3 = cellArray[(z + 1) * num + x];
            int alpha3 = GetAlpha(ref cell3, district);

            min = Mathf.Min(min, alpha3);
            max = Mathf.Max(max, alpha3);
            if (x >= num - 1)
            {
                return;
            }
            DistrictManager.Cell cell4 = cellArray[(z + 1) * num + x + 1];
            int alpha4 = GetAlpha(ref cell4, district);

            min = Mathf.Min(min, alpha4);
            max = Mathf.Max(max, alpha4);
        }
        private bool SetDistrictAlpha(int x, int z, byte district, int min, int max)
        {
            //begin mod
            DistrictManager.Cell cell = FakeDistrictManager.districtGrid[z * FakeDistrictManager.GRID + x];
            //end mod
            if (cell.m_district1 == district)
            {
                int num2 = Mathf.Clamp((int)cell.m_alpha1, min, max);
                if (num2 != (int)cell.m_alpha1)
                {
                    cell.m_alpha1 = (byte)num2;
                    Normalize(this, ref cell, 1);
                    Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                    return(true);
                }
            }
            else if (cell.m_district2 == district)
            {
                int num3 = Mathf.Clamp((int)cell.m_alpha2, min, max);
                if (num3 != (int)cell.m_alpha2)
                {
                    cell.m_alpha2 = (byte)num3;
                    Normalize(this, ref cell, 2);
                    Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                    return(true);
                }
            }
            else if (cell.m_district3 == district)
            {
                int num4 = Mathf.Clamp((int)cell.m_alpha3, min, max);
                if (num4 != (int)cell.m_alpha3)
                {
                    cell.m_alpha3 = (byte)num4;
                    Normalize(this, ref cell, 3);
                    Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                    return(true);
                }
            }
            else if (cell.m_district4 == district)
            {
                int num5 = Mathf.Clamp((int)cell.m_alpha4, min, max);
                if (num5 != (int)cell.m_alpha4)
                {
                    cell.m_alpha4 = (byte)num5;
                    Normalize(this, ref cell, 4);
                    Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                    return(true);
                }
            }
            else if (min > 0)
            {
                int num6 = 256;
                int num7 = -1;
                if ((int)cell.m_alpha1 < num6)
                {
                    num6 = (int)cell.m_alpha1;
                    num7 = 1;
                }
                if ((int)cell.m_alpha2 < num6)
                {
                    num6 = (int)cell.m_alpha2;
                    num7 = 2;
                }
                if ((int)cell.m_alpha3 < num6)
                {
                    num6 = (int)cell.m_alpha3;
                    num7 = 3;
                }
                if ((int)cell.m_alpha4 < num6)
                {
                    num6 = (int)cell.m_alpha4;
                    num7 = 4;
                }
                if (num6 <= min)
                {
                    if (num7 == 1)
                    {
                        cell.m_district1 = district;
                        cell.m_alpha1    = (byte)min;
                        Normalize(this, ref cell, 1);
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                        return(true);
                    }
                    if (num7 == 2)
                    {
                        cell.m_district2 = district;
                        cell.m_alpha2    = (byte)min;
                        Normalize(this, ref cell, 2);
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                        return(true);
                    }
                    if (num7 == 3)
                    {
                        cell.m_district3 = district;
                        cell.m_alpha3    = (byte)min;
                        Normalize(this, ref cell, 3);
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                        return(true);
                    }
                    if (num7 == 4)
                    {
                        cell.m_district4 = district;
                        cell.m_alpha4    = (byte)min;
                        Normalize(this, ref cell, 4);
                        Singleton <DistrictManager> .instance.ModifyCell(x, z, cell);

                        return(true);
                    }
                }
            }
            return(false);
        }