Beispiel #1
0
        public override void Start()
        {
            try
            {
                if (_gameAreaManager == null)
                {
                    _gameAreaManager = Singleton <GameAreaManager> .instance;
                }

                if (_gameAreaInfoPanel == null)
                {
                    _gameAreaInfoPanel = GameObject.Find("(Library) GameAreaInfoPanel").GetComponent <GameAreaInfoPanel>();
                }

                _gameAreaInfoPanel.component.eventVisibilityChanged += (component, value) =>
                {
                    if (value && ModConfig.Instance.PurchasableWithoutMilestones && _gameAreaManager.m_maxAreaCount == 25 && _gameAreaManager.m_areaCount < _gameAreaManager.m_maxAreaCount)
                    {
                        isVisible = true;
                    }
                    else
                    {
                        isVisible = false;
                    }
                };

                CreateUI();
            }
            catch (Exception e)
            {
                Debug.Log("[Purchase It!] PurchasePanel:Start -> Exception: " + e.Message);
            }
        }
Beispiel #2
0
        static bool Postfix(bool __result, GameAreaManager __instance, int x, int z)
        {
            try
            {
                if (ModConfig.Instance.PurchasableWithoutMilestones)
                {
                    if (x < 0 || z < 0 || x >= 5 || z >= 5)
                    {
                        return(false);
                    }

                    bool result = __instance.IsUnlocked(x, z - 1) || __instance.IsUnlocked(x - 1, z) || __instance.IsUnlocked(x + 1, z) || __instance.IsUnlocked(x, z + 1);
                    __instance.m_AreasWrapper.OnCanUnlockArea(x, z, ref result);
                    return(result);
                }
                else
                {
                    return(__result);
                }
            }
            catch (Exception e)
            {
                Debug.Log("[Purchase It!] GameAreaManagerCanUnlockPatch:Postfix -> Exception: " + e.Message);
                return(__result);
            }
        }
        public static void Init()
        {
            GameAreaManager.Reset();

            // Set only ONCE
            ApplyAspectRatioFix(Game.ScriptWidth,
                                Game.ScriptHeight,
                                Game.ImageWidth,
                                Game.ImageHeight);
        }
            public void Deserialize(DataSerializer s)
            {
                Singleton <LoadingManager> .instance.m_loadingProfilerSimulation.BeginDeserialize(s, "GameAreaManager");

                GameAreaManager instance = Singleton <GameAreaManager> .instance;

                //begin mod
                instance.m_areaGrid = new int[AREAGRID_RESOLUTION * AREAGRID_RESOLUTION];
                //end mod
                int[] numArray = instance.m_areaGrid;
                int   length   = numArray.Length;

                instance.m_areaCount = (int)s.ReadUInt8();
                //begin mod
                instance.m_maxAreaCount = AREAGRID_RESOLUTION * AREAGRID_RESOLUTION;
                //end mod
                _startTileField.SetValue(instance, s.version < 137U ? 12 : (int)s.ReadUInt8());
                EncodedArray.Byte @byte = EncodedArray.Byte.BeginRead(s);
                for (int index = 0; index < length; ++index)
                {
                    numArray[index] = (int)@byte.Read();
                }
                @byte.EndRead();
                instance.m_areaNotUnlocked = s.version < 87U ? (GenericGuide)null : s.ReadObject <GenericGuide>();
                if (s.version >= 199U)
                {
                    _fieldInfo1.SetValue(instance, s.ReadFloat());
                    _fieldInfo2.SetValue(instance, s.ReadFloat());
                    _fieldInfo3.SetValue(instance, s.ReadFloat());
                    _fieldInfo4.SetValue(instance, s.ReadFloat());
                }
                else
                {
                    _fieldInfo1.SetValue(instance, -1f);
                    _fieldInfo2.SetValue(instance, -1f);
                    _fieldInfo3.SetValue(instance, -1f);
                    _fieldInfo4.SetValue(instance, -1f);
                }
                if (s.version >= 112032U && !RecoveryMode)
                {
                    var instanceSavedCameraView = (CameraController.SavedCameraView)_fieldInfo5.GetValue(instance);
                    instanceSavedCameraView.Deserialize(s);
                }
                else
                {
                    RecoveryMode = false;
                    var instanceSavedCameraView = new CameraController.SavedCameraView();
                    instanceSavedCameraView.m_mode = -1;
                    _fieldInfo5.SetValue(instance, instanceSavedCameraView);
                }
                Singleton <LoadingManager> .instance.m_loadingProfilerSimulation.EndDeserialize(s, "GameAreaManager");
            }
Beispiel #5
0
        static void Main(string[] args)
        {
            int    h = 11, w = 11;
            string input;

            GameShipManager shipManager = new GameShipManager();

            GameAreaManager npc         = new GameAreaManager(new BattleArea(h, w), shipManager);

            npc.CreateArea();

            GameAreaManager player = new GameAreaManager(new BattleArea(h, w), shipManager);

            player.CreateEmptyArea();

            GameManager manager = new GameManager(DifficultLevel.Hard, npc);

            manager.Configure();

            do
            {
                Console.Clear();
                Console.WriteLine("Welcome to BattleShip");
                Console.WriteLine("Please specify points to hit. (example A1)");
                Console.WriteLine();

                player.ShowArea();

                Console.WriteLine();
                Console.WriteLine("You hit: {0}/{1} ships.", player.ShipCount, npc.ShipCount);
                Console.WriteLine("Moves {0}.", manager.Turns);
                Console.WriteLine();

                manager.WinnerConditions(player.ShipCount, npc.ShipCount, manager.Turns);

                if (!manager.IsGameOver)
                {
                    input = Console.ReadLine();


                    manager.MatchPlayerArea(player.Area, npc.Area, input, npc.ShipContainer);
                    manager.EndTurn();
                }
                else
                {
                    Console.WriteLine();
                    npc.ShowArea();
                }
            }while (!manager.IsGameOver);

            Console.ReadLine();
        }
            public void Serialize(DataSerializer s)
            {
                Singleton <LoadingManager> .instance.m_loadingProfilerSimulation.BeginSerialize(s, "GameAreaManager");

                GameAreaManager instance = Singleton <GameAreaManager> .instance;

                //begin mod
                int[] numArray  = new int[AREAGRID_RESOLUTION * AREAGRID_RESOLUTION];
                int   length    = numArray.Length;
                int   areaCount = 0;

                for (var i = 0; i < 5; i += 1)
                {
                    for (var j = 0; j < 5; j += 1)
                    {
                        var grid = GameAreaManager.instance.m_areaGrid[(j + 2) * GRID + (i + 2)];
                        numArray[j * AREAGRID_RESOLUTION + i] = grid;
                        if (grid != 0)
                        {
                            areaCount += 1;
                        }
                    }
                }
                s.WriteUInt8((uint)areaCount);
                //end mod
                s.WriteUInt8((uint)(int)_startTileField.GetValue(instance));
                EncodedArray.Byte @byte = EncodedArray.Byte.BeginWrite(s);
                for (int index = 0; index < length; ++index)
                {
                    @byte.Write((byte)numArray[index]);
                }
                @byte.EndWrite();

                s.WriteObject <GenericGuide>(instance.m_areaNotUnlocked);
                s.WriteFloat((float)_fieldInfo1.GetValue(instance));
                s.WriteFloat((float)_fieldInfo2.GetValue(instance));
                s.WriteFloat((float)_fieldInfo3.GetValue(instance));
                s.WriteFloat((float)_fieldInfo4.GetValue(instance));
                var instanceSavedCameraView = new CameraController.SavedCameraView((CameraController)_fieldInfo6.GetValue(instance));

                _fieldInfo5.SetValue(instance, instanceSavedCameraView);
                instanceSavedCameraView.Serialize(s);
                Singleton <LoadingManager> .instance.m_loadingProfilerSimulation.EndSerialize(s, "GameAreaManager");
            }
        private static IEnumerator Purchase(int x, int y)
        {
            try
            {
                GameAreaManager gameAreaManager = Singleton <GameAreaManager> .instance;

                if (gameAreaManager != null)
                {
                    if (!gameAreaManager.IsUnlocked(x, y))
                    {
                        int tileIndex = gameAreaManager.GetTileIndex(x, y);
                        gameAreaManager.UnlockArea(tileIndex);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log("[Rebuild It!] PurchaseUtils:Purchase -> Exception: " + e.Message);
            }

            yield return(null);
        }
Beispiel #8
0
        public void CalculateUnlockedResources(out uint ore, out uint oil, out uint forest, out uint fertility, out uint water)
        {
            ore       = 0U;
            oil       = 0U;
            forest    = 0U;
            fertility = 0U;
            water     = 0U;
            GameAreaManager instance = Singleton <GameAreaManager> .instance;
            //begin mod
            int num = 0;

            for (int z = 0; z < FakeGameAreaManager.GRID; ++z)
            {
                for (int x = 0; x < FakeGameAreaManager.GRID; ++x)
                {
                    //end mod
                    if (instance.IsUnlocked(x, z))
                    {
                        this.GetTileResourcesImpl(x + num, z + num, ref ore, ref oil, ref forest, ref fertility, ref water);
                    }
                }
            }
        }
        private bool findRandomTargetEverywhere(out Vector3 target, out float angle)
        {
            GameAreaManager   gam = Singleton <GameAreaManager> .instance;
            SimulationManager sm  = Singleton <SimulationManager> .instance;
            int   i = sm.m_randomizer.Int32(0, 4);
            int   j = sm.m_randomizer.Int32(0, 4);
            float minX;
            float minZ;
            float maxX;
            float maxZ;

            gam.GetAreaBounds(i, j, out minX, out minZ, out maxX, out maxZ);

            float randX = (float)sm.m_randomizer.Int32(0, 10000) * 0.0001f;
            float randZ = (float)sm.m_randomizer.Int32(0, 10000) * 0.0001f;

            target.x = minX + (maxX - minX) * randX;
            target.y = 0f;
            target.z = minZ + (maxZ - minZ) * randZ;
            target.y = Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(target, false, 0f);

            angle = (float)sm.m_randomizer.Int32(0, 10000) * 0.0006283185f;
            return(true);
        }
Beispiel #10
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);
            }
        }
 static int GetTileIndex(GameAreaManager g,int x, int z)
 {
     return z * GRID + x;
 }
 public static void GetTileXZ(GameAreaManager gm,  int tile, out int x, out int z)
 {
     x = tile % GRID;
     z = tile / GRID;
 }
        private bool findRandomTargetInLockedAreas(out Vector3 target, out float angle)
        {
            GameAreaManager   gam = Singleton <GameAreaManager> .instance;
            SimulationManager sm  = Singleton <SimulationManager> .instance;

            // No locked areas
            if (gam.m_areaCount >= 25)
            {
                target = Vector3.zero;
                angle  = 0f;
                return(false);
            }

            int lockedAreaCounter = sm.m_randomizer.Int32(1, 25 - gam.m_areaCount);

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (isUnlocked(i, j))
                    {
                        continue;
                    }

                    if (--lockedAreaCounter == 0)
                    {
                        float minX;
                        float minZ;
                        float maxX;
                        float maxZ;
                        gam.GetAreaBounds(j, i, out minX, out minZ, out maxX, out maxZ);
                        float minimumEdgeDistance = 100f;
                        if (isUnlocked(j - 1, i))
                        {
                            minX += minimumEdgeDistance;
                        }
                        if (isUnlocked(j, i - 1))
                        {
                            minZ += minimumEdgeDistance;
                        }
                        if (isUnlocked(j + 1, i))
                        {
                            maxX -= minimumEdgeDistance;
                        }
                        if (isUnlocked(j, i + 1))
                        {
                            maxZ -= minimumEdgeDistance;
                        }

                        float randX = (float)sm.m_randomizer.Int32(0, 10000) * 0.0001f;
                        float randZ = (float)sm.m_randomizer.Int32(0, 10000) * 0.0001f;
                        target.x = minX + (maxX - minX) * randX;
                        target.y = 0f;
                        target.z = minZ + (maxZ - minZ) * randZ;
                        target.y = Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(target, false, 0f);

                        angle = (float)sm.m_randomizer.Int32(0, 10000) * 0.0006283185f;
                        DebugLogger.Log(string.Format("findRandomTargetInLockedAreas, j = {0}, i = {1}, areaCount = {2}", j, i, gam.m_areaCount));
                        return(true);
                    }
                }
            }

            target = Vector3.zero;
            angle  = 0f;
            return(false);
        }
        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();
        }
Beispiel #15
0
        private void GetAmountAndCapacity(string name, out int amount, out int capacity, out bool modded)
        {
            CitizenManager citizenManager;
            NetManager     netManager;
            AudioManager   audioManager;
            VehicleManager vehicleManager;

            switch (name)
            {
            case "Areas":
                GameAreaManager gameAreaManager = Singleton <GameAreaManager> .instance;
                amount   = gameAreaManager.m_areaCount;
                capacity = gameAreaManager.m_maxAreaCount;
                modded   = gameAreaManager.m_maxAreaCount > 9 ? true : false;
                break;

            case "Buildings":
                BuildingManager buildingManager = Singleton <BuildingManager> .instance;
                amount   = buildingManager.m_buildingCount;
                capacity = BuildingManager.MAX_BUILDING_COUNT;
                modded   = false;
                break;

            case "Citizens":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_citizenCount;
                capacity       = CitizenManager.MAX_CITIZEN_COUNT;
                modded         = false;
                break;

            case "Citizen Units":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_unitCount;
                capacity       = CitizenManager.MAX_UNIT_COUNT;
                modded         = false;
                break;

            case "Citizen Instances":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_instanceCount;
                capacity       = CitizenManager.MAX_INSTANCE_COUNT;
                modded         = false;
                break;

            case "Disasters":
                DisasterManager disasterManager = Singleton <DisasterManager> .instance;
                amount   = disasterManager.m_disasterCount;
                capacity = DisasterManager.MAX_DISASTER_COUNT;
                modded   = false;
                break;

            case "Districts":
                DistrictManager districtManager = Singleton <DistrictManager> .instance;
                amount   = districtManager.m_districtCount;
                capacity = DistrictManager.MAX_DISTRICT_COUNT;
                modded   = false;
                break;

            case "Events":
                EventManager eventManager = Singleton <EventManager> .instance;
                amount   = eventManager.m_eventCount;
                capacity = EventManager.MAX_EVENT_COUNT;
                modded   = false;
                break;

            case "Loans":
                EconomyManager economyManager = Singleton <EconomyManager> .instance;
                amount   = economyManager.CountLoans();
                capacity = EconomyManager.MAX_LOANS;
                modded   = false;
                break;

            case "Net Segments":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_segmentCount;
                capacity   = NetManager.MAX_SEGMENT_COUNT;
                modded     = false;
                break;

            case "Net Nodes":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_nodeCount;
                capacity   = NetManager.MAX_NODE_COUNT;
                modded     = false;
                break;

            case "Net Lanes":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_laneCount;
                capacity   = NetManager.MAX_LANE_COUNT;
                modded     = false;
                break;

            case "Path Units":
                PathManager pathManager = Singleton <PathManager> .instance;
                amount   = pathManager.m_pathUnitCount;
                capacity = PathManager.MAX_PATHUNIT_COUNT;
                modded   = false;
                break;

            case "Props":
                PropManager propManager = Singleton <PropManager> .instance;
                amount   = propManager.m_propCount;
                capacity = PropManager.MAX_PROP_COUNT;
                modded   = false;
                break;

            case "Radio Channels":
                audioManager = Singleton <AudioManager> .instance;
                amount       = audioManager.m_radioChannelCount;
                capacity     = AudioManager.MAX_RADIO_CHANNEL_COUNT;
                modded       = false;
                break;

            case "Radio Contents":
                audioManager = Singleton <AudioManager> .instance;
                amount       = audioManager.m_radioContentCount;
                capacity     = AudioManager.MAX_RADIO_CONTENT_COUNT;
                modded       = false;
                break;

            case "Transport Lines":
                TransportManager transportManager = Singleton <TransportManager> .instance;
                amount   = transportManager.m_lineCount;
                capacity = TransportManager.MAX_LINE_COUNT;
                modded   = false;
                break;

            case "Trees":
                TreeManager treeManager = Singleton <TreeManager> .instance;
                amount   = treeManager.m_treeCount;
                capacity = treeManager.m_trees.m_size > 262144 ? (int)treeManager.m_trees.m_size : TreeManager.MAX_TREE_COUNT;
                modded   = treeManager.m_trees.m_size > 262144 ? true : false;
                break;

            case "Vehicles":
                vehicleManager = Singleton <VehicleManager> .instance;
                amount         = vehicleManager.m_vehicleCount;
                capacity       = VehicleManager.MAX_VEHICLE_COUNT;
                modded         = false;
                break;

            case "Vehicles Parked":
                vehicleManager = Singleton <VehicleManager> .instance;
                amount         = vehicleManager.m_parkedCount;
                capacity       = VehicleManager.MAX_PARKED_COUNT;
                modded         = false;
                break;

            case "Zoned Blocks":
                ZoneManager zoneManager = Singleton <ZoneManager> .instance;
                amount   = zoneManager.m_blockCount;
                capacity = ZoneManager.MAX_BLOCK_COUNT;
                modded   = false;
                break;

            default:
                amount   = 0;
                capacity = 0;
                modded   = false;
                break;
            }
        }
        public override void Handle(TerrainModificationCommand command)
        {
            ushort[] m_tempBuffer = (ushort[])typeof(TerrainTool).GetField("m_tempBuffer", AccessTools.all).GetValue(ToolsModifierControl.GetTool <TerrainTool>());


            TerrainManager    instance = Singleton <TerrainManager> .instance;
            GameAreaManager   manager2 = Singleton <GameAreaManager> .instance;
            SimulationManager manager3 = Singleton <SimulationManager> .instance;

            float[] brushData = command.BrushData;
            float   num       = command.BrushSize * 0.5f;
            float   num2      = 16f;
            int     b         = 0x438;

            ushort[] rawHeights    = instance.RawHeights;
            ushort[] finalHeights  = instance.FinalHeights;
            ushort[] backupHeights = instance.BackupHeights;
            float    strength      = command.Strength;
            int      num5          = 3;
            float    num6          = 0.015625f;
            float    num7          = 64f;
            Vector3  mousePosition = command.mousePosition;
            Vector3  vector2       = command.EndPosition - command.StartPosition;

            vector2.y = 0f;
            float sqrMagnitude = vector2.sqrMagnitude;

            if (sqrMagnitude != 0f)
            {
                sqrMagnitude = 1f / sqrMagnitude;
            }
            float num9  = 20f;
            bool  flag  = true; //(base.m_toolController.m_mode & ItemClass.Availability.Game) != ItemClass.Availability.None;
            int   a     = 0;
            int   num11 = 0;
            //int currentCost = this.m_currentCost;
            int dirtBuffer = instance.DirtBuffer;
            int num14      = 0x80000;
            int dirtPrice  = 0;

            if (flag)
            {
                if (manager2.PointOutOfArea(mousePosition))
                {
                    //this.m_toolErrors = ToolBase.ToolErrors.None | ToolBase.ToolErrors.OutOfArea;
                    return;
                }
                TerrainProperties properties = instance.m_properties;
                if (properties != null)
                {
                    dirtPrice = properties.m_dirtPrice;
                }
            }

            int num16 = Mathf.Max((int)(((mousePosition.x - num) / num2) + (b * 0.5f)), 0);
            int num17 = Mathf.Max((int)(((mousePosition.z - num) / num2) + (b * 0.5f)), 0);
            int num18 = Mathf.Min(((int)(((mousePosition.x + num) / num2) + (b * 0.5f))) + 1, b);
            int num19 = Mathf.Min(((int)(((mousePosition.z + num) / num2) + (b * 0.5f))) + 1, b);

            if (command.mode == Mode.Shift)
            {
                if (command.MouseRightDown)
                {
                    num9 = -num9;
                }
            }
            else if ((command.mode == Mode.Soften) && command.MouseRightDown)
            {
                num5 = 10;
            }
            if ((m_tempBuffer == null) || (m_tempBuffer.Length < (((num19 - num17) + 1) * ((num18 - num16) + 1))))
            {
                m_tempBuffer = new ushort[((num19 - num17) + 1) * ((num18 - num16) + 1)];
            }
            for (int i = num17; i <= num19; i++)
            {
                float z     = (i - (b * 0.5f)) * num2;
                float f     = ((((z - mousePosition.z) + num) / command.BrushSize) * 64f) - 0.5f;
                int   num23 = Mathf.Clamp(Mathf.FloorToInt(f), 0, 0x3f);
                int   num24 = Mathf.Clamp(Mathf.CeilToInt(f), 0, 0x3f);
                for (int k = num16; k <= num18; k++)
                {
                    float x     = (k - (b * 0.5f)) * num2;
                    float num27 = ((((x - mousePosition.x) + num) / command.BrushSize) * 64f) - 0.5f;
                    int   num28 = Mathf.Clamp(Mathf.FloorToInt(num27), 0, 0x3f);
                    int   num29 = Mathf.Clamp(Mathf.CeilToInt(num27), 0, 0x3f);
                    int   num30 = rawHeights[(i * (b + 1)) + k];
                    float num31 = num30 * num6;
                    float y     = 0f;
                    if (flag && manager2.PointOutOfArea(new Vector3(x, mousePosition.y, z), num2 * 0.5f))
                    {
                        m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num30;
                    }
                    else
                    {
                        float num33 = brushData[(num23 * 0x40) + num28];
                        float num34 = brushData[(num23 * 0x40) + num29];
                        float num35 = brushData[(num24 * 0x40) + num28];
                        float num36 = brushData[(num24 * 0x40) + num29];
                        float num37 = num33 + ((num34 - num33) * (num27 - num28));
                        float num38 = num35 + ((num36 - num35) * (num27 - num28));
                        float t     = num37 + ((num38 - num37) * (f - num23));
                        t *= strength;
                        if (t <= 0f)
                        {
                            m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num30;
                        }
                        else
                        {
                            if (command.mode == Mode.Shift)
                            {
                                y = (finalHeights[(i * (b + 1)) + k] * num6) + num9;
                            }
                            else if (command.mode == Mode.Level)
                            {
                                y = command.StartPosition.y;
                            }
                            else if (command.mode == Mode.Soften)
                            {
                                int   num40 = Mathf.Max(k - num5, 0);
                                int   num41 = Mathf.Max(i - num5, 0);
                                int   num42 = Mathf.Min(k + num5, b);
                                int   num43 = Mathf.Min(i + num5, b);
                                float num44 = 0f;
                                for (int m = num41; m <= num43; m++)
                                {
                                    for (int n = num40; n <= num42; n++)
                                    {
                                        float num47 = 1f - (((float)(((n - k) * (n - k)) + ((m - i) * (m - i)))) / ((float)(num5 * num5)));
                                        if (num47 > 0f)
                                        {
                                            y     += finalHeights[(m * (b + 1)) + n] * (num6 * num47);
                                            num44 += num47;
                                        }
                                    }
                                }
                                if (num44 > 0.001f)
                                {
                                    y /= num44;
                                }
                                else
                                {
                                    y = finalHeights[(i * (b + 1)) + k];
                                }
                            }
                            else if (command.mode == Mode.Slope)
                            {
                                float num48 = (k - (b * 0.5f)) * num2;
                                float num49 = (i - (b * 0.5f)) * num2;
                                float num50 = (((num48 - command.StartPosition.x) * vector2.x) + ((num49 - command.StartPosition.z) * vector2.z)) * sqrMagnitude;
                                y = Mathf.Lerp(command.StartPosition.y, command.EndPosition.y, num50);
                            }
                            float num51 = y;
                            y = Mathf.Lerp(num31, y, t);
                            int num52 = Mathf.Clamp(Mathf.RoundToInt(y * num7), 0, 0xffff);
                            if (num52 == num30)
                            {
                                int num53 = Mathf.Clamp(Mathf.RoundToInt(num51 * num7), 0, 0xffff);
                                if (num53 > num30)
                                {
                                    if (((y - num31) * num7) > (manager3.m_randomizer.Int32(0, 0x2710) * 0.0001f))
                                    {
                                        num52++;
                                    }
                                }
                                else if ((num53 < num30) && (((num31 - y) * num7) > (manager3.m_randomizer.Int32(0, 0x2710) * 0.0001f)))
                                {
                                    num52--;
                                }
                            }
                            m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num52;
                            if (flag)
                            {
                                if (num52 > num30)
                                {
                                    a += num52 - num30;
                                }
                                else if (num52 < num30)
                                {
                                    num11 += num30 - num52;
                                }
                                int num54 = backupHeights[(i * (b + 1)) + k];
                                int num55 = Mathf.Abs((int)(num52 - num54)) - Mathf.Abs((int)(num30 - num54));
                                //currentCost += num55 * dirtPrice;
                            }
                        }
                    }
                }
            }
            int num56 = a;
            int num57 = num11;

            ToolBase.ToolErrors none = ToolBase.ToolErrors.None;
            if (flag)
            {
                if (a > num11)
                {
                    num56 = Mathf.Min(a, dirtBuffer + num11);
                    if (num56 < a)
                    {
                        none |= ToolBase.ToolErrors.None | ToolBase.ToolErrors.NotEnoughDirt;
                        GuideController properties = Singleton <GuideManager> .instance.m_properties;
                        if (properties != null)
                        {
                            Singleton <TerrainManager> .instance.m_notEnoughDirt.Activate(properties.m_notEnoughDirt);
                        }
                    }
                    GenericGuide tooMuchDirt = Singleton <TerrainManager> .instance.m_tooMuchDirt;
                    if (tooMuchDirt != null)
                    {
                        tooMuchDirt.Deactivate();
                    }
                }
                else if (num11 > a)
                {
                    num57 = Mathf.Min(num11, (num14 - dirtBuffer) + a);
                    if (num57 < num11)
                    {
                        none |= ToolBase.ToolErrors.None | ToolBase.ToolErrors.TooMuchDirt;
                        GuideController properties = Singleton <GuideManager> .instance.m_properties;
                        if (properties != null)
                        {
                            Singleton <TerrainManager> .instance.m_tooMuchDirt.Activate(properties.m_tooMuchDirt);
                        }
                    }
                    GenericGuide notEnoughDirt = Singleton <TerrainManager> .instance.m_notEnoughDirt;
                    if (notEnoughDirt != null)
                    {
                        notEnoughDirt.Deactivate();
                    }
                }

                /*if (currentCost != Singleton<EconomyManager>.instance.PeekResource(EconomyManager.Resource.Landscaping, currentCost))
                 * {
                 *  this.m_toolErrors = none | (ToolBase.ToolErrors.None | ToolBase.ToolErrors.NotEnoughMoney);
                 *  return;
                 * }
                 * currentCost = this.m_currentCost;
                 */
            }
            //Singleton<TerrainTool>.instance.m_toolErrors = none;
            if ((num56 != 0) || (num57 != 0))
            {
                GenericGuide terrainToolNotUsed = Singleton <TerrainManager> .instance.m_terrainToolNotUsed;
                if ((terrainToolNotUsed != null) && !terrainToolNotUsed.m_disabled)
                {
                    terrainToolNotUsed.Disable();
                }
            }
            for (int j = num17; j <= num19; j++)
            {
                for (int k = num16; k <= num18; k++)
                {
                    int num60 = rawHeights[(j * (b + 1)) + k];
                    int num61 = m_tempBuffer[(((j - num17) * ((num18 - num16) + 1)) + k) - num16];
                    if (flag)
                    {
                        int num62 = num61 - num60;
                        if (num62 > 0)
                        {
                            if (a > num56)
                            {
                                num62 = ((a - 1) + (num62 * num56)) / a;
                            }
                            a          -= num61 - num60;
                            num56      -= num62;
                            num61       = num60 + num62;
                            dirtBuffer -= num62;
                        }
                        else if (num62 < 0)
                        {
                            if (num11 > num57)
                            {
                                num62 = -(((num11 - 1) - (num62 * num57)) / num11);
                            }
                            num11      -= num60 - num61;
                            num57      += num62;
                            num61       = num60 + num62;
                            dirtBuffer -= num62;
                        }
                        int num63 = backupHeights[(j * (b + 1)) + k];
                        int num64 = Mathf.Abs((int)(num61 - num63)) - Mathf.Abs((int)(num60 - num63));
                        //currentCost += num64 * dirtPrice;
                    }
                    if (num61 != num60)
                    {
                        rawHeights[(j * (b + 1)) + k] = (ushort)num61;


                        int _strokeXmin = Math.Min(command.StrokeXmin, k);
                        int _strokeXmax = Math.Max(command.StrokeXmax, k);
                        int _strokeZmin = Math.Min(command.StrokeZmin, j);
                        int _strokeZmax = Math.Max(command.StrokeZmax, j);

                        typeof(TerrainTool).GetField("m_strokeXmin", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeXmin);
                        typeof(TerrainTool).GetField("m_strokeXmax", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeXmax);
                        typeof(TerrainTool).GetField("m_strokeZmin", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeZmin);
                        typeof(TerrainTool).GetField("m_strokeZmax", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeZmax);
                    }
                }
            }
            if (flag)
            {
                instance.DirtBuffer = dirtBuffer;
                //this.m_currentCost = currentCost;
            }
            TerrainModify.UpdateArea((int)(num16 - 2), (int)(num17 - 2), (int)(num18 + 2), (int)(num19 + 2), true, false, false);
        }