Exemple #1
0
        public static void ItterateOnReform(BuildTool_BlueprintCopy __instance, BPGratBox box, Action <int, ReformData> action, bool fullCircle = false)
        {
            if (Mathf.Abs(box.y - box.w) < 0.005f)
            {
                return;
            }

            PlatformSystem platform = __instance.factory.platformSystem;

            if (platform == null)
            {
                return;
            }
            platform.EnsureReformData();

            GetSegmentCount(box.startLatitudeRad, box.startLongitudeRad, out float startLatCount, out float startLongCount, out int startCount);
            GetSegmentCount(box.endLatitudeRad, box.endLongitudeRad, out float endLatCount, out float endLongCount, out int endCount);

            startLatCount  = GridSnappingPatches.Snap(startLatCount);
            startLongCount = GridSnappingPatches.Snap(startLongCount);
            endLatCount    = GridSnappingPatches.Snap(endLatCount);
            endLongCount   = GridSnappingPatches.Snap(endLongCount);

            startLatCount  = Mathf.Round(startLatCount * 10f);
            endLatCount    = Mathf.Round(endLatCount * 10f);
            startLongCount = Mathf.Round(startLongCount * 10f);
            endLongCount   = Mathf.Round(endLongCount * 10f);

            float latDelta = endLatCount - startLatCount;
            int   segmentCount;

            float longDelta;

            if (startCount != endCount)
            {
                Vector2 center = GetSphericalCenter(box.startLatitudeRad, box.startLongitudeRad, box.endLatitudeRad, box.endLongitudeRad);

                GetSegmentCount(center.x, center.y, out float _, out float _, out int midCount);
                segmentCount = midCount;
                if (startCount == midCount)
                {
                    GetSegmentCount(box.startLatitudeRad, box.endLongitudeRad, out float _, out float nlongCount);
                    nlongCount = Mathf.Round(nlongCount * 10f);
                    longDelta  = nlongCount - startLongCount;
                }
                else
                {
                    GetSegmentCount(box.endLatitudeRad, box.startLongitudeRad, out float _, out float nlongCount);
                    nlongCount     = Mathf.Round(nlongCount * 10f);
                    longDelta      = endLongCount - nlongCount;
                    startLongCount = nlongCount;
                }
            }
            else
            {
                segmentCount = startCount;
                longDelta    = endLongCount - startLongCount;
            }

            if (fullCircle)
            {
                longDelta = segmentCount * 10;
            }

            if (longDelta < 0)
            {
                longDelta = segmentCount * 10 + longDelta;
            }

            int latSize  = Mathf.RoundToInt(latDelta) / 2;
            int longSize = Mathf.RoundToInt(longDelta) / 2;

            if (latSize == 0)
            {
                latSize = 1;
            }
            if (longSize == 0)
            {
                longSize = 1;
            }

            startLatCount  += 1;
            startLongCount += 1;

            int latOffset   = 0;
            int longOffset  = 0;
            int longCounter = 0;

            float latCount = platform.latitudeCount / 10f;

            for (int i = 0; i < longSize * latSize; i++)
            {
                longCounter++;
                float currentLat  = (startLatCount + latOffset) / 10f;
                float currentLong = (startLongCount + longOffset) / 10f;

                currentLong = Mathf.Repeat(currentLong, segmentCount);

                float latRad  = (currentLat + 0.1f) / currentGrid.segment * 6.2831855f;
                float longRad = (currentLong + 0.1f) / segmentCount * 6.2831855f;

                longOffset += 2;
                if (longCounter % longSize == 0)
                {
                    longOffset = 0;
                    latOffset += 2;
                }

                if (currentLat >= latCount || currentLat <= -latCount)
                {
                    continue;
                }

                int reformIndex = platform.GetReformIndexForSegment(currentLat, currentLong);

                int reformType  = platform.GetReformType(reformIndex);
                int reformColor = platform.GetReformColor(reformIndex);

                if (!platform.IsTerrainReformed(reformType))
                {
                    continue;
                }

                ReformData reform = new ReformData
                {
                    latitude  = latRad,
                    longitude = longRad,
                    type      = reformType,
                    color     = reformColor
                };

                action(reformIndex, reform);
            }
        }
Exemple #2
0
        public static void Update(UIBuildingGrid __instance)
        {
            if (!BlueprintCopyExtension.isEnabled)
            {
                return;
            }

            Player mainPlayer = GameMain.mainPlayer;

            PlanetFactory planetFactory = GameMain.localPlanet?.factory;

            if (planetFactory == null)
            {
                return;
            }

            if (GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlayerAction_Build actionBuild = mainPlayer?.controller.actionBuild;

            if (actionBuild == null)
            {
                return;
            }

            if (__instance.reformCursorMap == null)
            {
                return;
            }

            int            maxLen = __instance.reformCursorMap.Length;
            PlatformSystem system = planetFactory.platformSystem;

            if (system == null)
            {
                return;
            }
            system.EnsureReformData();

            if (actionBuild.blueprintMode == EBlueprintMode.None)
            {
                __instance.material.SetColor(cursorColor, Color.white);
                return;
            }

            float realRadius = GameMain.localPlanet.realRadius;

            __instance.displayScale = (realRadius + 0.2f) * 2f;

            if (currentFactory == null || currentFactory.index != planetFactory.index)
            {
                currentFactory = planetFactory;

                fakeReformData = new byte[system.maxReformCount];
                Array.Copy(system.reformData, fakeReformData, system.maxReformCount);
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Copy)
            {
                bool any = false;
                if (BlueprintCopyExtension.reformSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, displayColor);
                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = 0;
                            }

                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (BlueprintCopyExtension.reformPreSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, selectColor);

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = 0;
                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (any)
                {
                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.gridRnd.enabled = true;
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    ComputeBuffer reformDataBuffer = system.reformDataBuffer;
                    reformDataBuffer.SetData(fakeReformData);
                    __instance.material.SetBuffer(dataBuffer, reformDataBuffer);

                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = system.reformData[index];
                            }

                            __instance.reformCursorMap[index] = 0;
                        }
                    }

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = system.reformData[index];
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Paste)
            {
                ReformBPUtils.currentGrid = GameMain.localPlanet.aux.mainGrid;

                __instance.material.SetColor(cursorColor, displayColor);
                __instance.gridRnd.enabled = true;
                PlatformSystem platformSystem = __instance.reformMapPlanet.factory.platformSystem;
                if (BlueprintPasteExtension.reformPreviews.Count > 0)
                {
                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 1;
                        }
                    }

                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }
        }