Esempio n. 1
0
        public static bool GenerateBlueprintData(BuildTool_BlueprintCopy __instance, ref bool __result)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return(true);
            }

            __instance.hasErrorInserterData = false;
            if (__instance.selectedObjIds.Count == 0 && reformSelection.Count == 0)
            {
                __instance.blueprint.ResetContentAsEmpty();
                __result = false;
                return(false);
            }

            foreach (int objId in __instance.selectedObjIds)
            {
                if (!__instance.CheckInserterDataLegal(objId))
                {
                    __instance.hasErrorInserterData = true;
                    break;
                }
            }

            CopyToTempArray(__instance);

            BlueprintUtils.GenerateBlueprintData(__instance.blueprint, __instance.planet, __instance.actionBuild.planetAux, __instance._tmp_selected_ids, __instance._tmp_selected_cnt, __instance.divideLineRad);
            __instance.blueprint.CheckBuildingData();

            Array.Clear(__instance._tmp_selected_ids, 0, __instance._tmp_selected_ids.Length);
            __result = true;
            return(false);
        }
Esempio n. 2
0
        private static Vector2 GetMinLongLat(List <int> objectIds, BuildTool_BlueprintCopy copy)
        {
            float minLat  = 10;
            float minLong = 10;

            float objLat  = 0;
            float objLong = 0;

            foreach (int objectId in objectIds)
            {
                if (objectId > 0)
                {
                    ref EntityData data = ref copy.factory.entityPool[objectId];
                    if (data.id == objectId)
                    {
                        BlueprintUtils.GetLongitudeLatitudeRad(data.pos.normalized, ref objLong, ref objLat);
                        if (objLong < minLong)
                        {
                            minLong = objLong;
                        }

                        if (objLat < minLat)
                        {
                            minLat = objLat;
                        }
                    }
                }
Esempio n. 3
0
        public static BlueprintData GenerateBlueprint(List <int> objectIds, out Vector3 position)
        {
            position = Vector3.zero;
            if (GameMain.mainPlayer?.controller == null)
            {
                return(BlueprintData.CreateNew());
            }
            if (GameMain.localPlanet == null)
            {
                return(BlueprintData.CreateNew());
            }

            BuildTool_BlueprintCopy copy = GameMain.mainPlayer.controller.actionBuild.blueprintCopyTool;

            using (UndoManager.IgnoreAllEvents.On())
            {
                copy.InitTool();
                copy.selectedObjIds.Clear();
                foreach (int objectId in objectIds)
                {
                    copy.selectedObjIds.Add(objectId);
                }

                copy.blueprint = BlueprintData.CreateNew();
                copy.RefreshBlueprintData();

                Vector2 minPos = GetMinLongLat(objectIds, copy);

                float radius = GameMain.localPlanet.realRadius;
                position = BlueprintUtils.GetDir(minPos.x, minPos.y) * radius;
                position = copy.actionBuild.planetAux.Snap(position, true);
            }

            return(copy.blueprint);
        }
Esempio n. 4
0
        public static void AddColorData(BuildTool_BlueprintCopy __instance)
        {
            if (GameMain.localPlanet == null || GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlatformSystem system = GameMain.localPlanet.factory.platformSystem;

            __instance.blueprint.customColors = new Color[16];

            Array.Copy(system.reformCustomColors, __instance.blueprint.customColors, 16);
        }
Esempio n. 5
0
        public static void Arrange(BuildTool_BlueprintCopy __instance)
        {
            if (GameMain.localPlanet == null || GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            foreach (var kv in reformPreSelection)
            {
                if (!reformSelection.ContainsKey(kv.Key))
                {
                    reformSelection.Add(kv.Key, kv.Value);
                }
            }
        }
Esempio n. 6
0
 public static void CopyToTempArray(BuildTool_BlueprintCopy __instance)
 {
     Array.Clear(__instance._tmp_selected_ids, 0, __instance._tmp_selected_ids.Length);
     if (__instance.selectedObjIds.Count > 0)
     {
         if (__instance.selectedObjIds.Count > __instance._tmp_selected_ids.Length)
         {
             __instance._tmp_selected_ids = new int[(int)(__instance.selectedObjIds.Count * 1.5)];
         }
         __instance.selectedObjIds.CopyTo(__instance._tmp_selected_ids);
         __instance._tmp_selected_cnt = __instance.selectedObjIds.Count;
     }
     else
     {
         __instance._tmp_selected_cnt = __instance.selectedObjIds.Count;
     }
 }
Esempio n. 7
0
        public static void SelectionSub(BuildTool_BlueprintCopy __instance)
        {
            if (GameMain.localPlanet == null || GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            reformPreSelection.Clear();
            if (Mathf.Abs(__instance.preSelectArcBox.x - __instance.preSelectArcBox.z) < 0.01f &&
                Mathf.Abs(__instance.preSelectArcBox.y - __instance.preSelectArcBox.w) < 0.01f &&
                __instance.castObjectId != 0)
            {
                return;
            }

            ReformBPUtils.currentGrid = GameMain.localPlanet.aux.mainGrid;

            ReformBPUtils.ClearDisplay();

            ReformBPUtils.DisplayPos(__instance.preSelectGratBox.startLatitudeRad, __instance.preSelectGratBox.startLongitudeRad, Color.green);
            ReformBPUtils.DisplayPos(__instance.preSelectGratBox.endLatitudeRad, __instance.preSelectGratBox.endLongitudeRad, Color.yellow);

            bool full = Mathf.Abs(__instance.preSelectArcBox.startLongitudeRad - __instance.preSelectArcBox.endLongitudeRad) > 2 * Mathf.PI - 0.04f;

            BPGratBox[] areas = ReformBPUtils.SplitGratBox(__instance.preSelectGratBox);

            foreach (BPGratBox box in areas)
            {
                ReformBPUtils.ItterateOnReform(__instance, box, (index, data) =>
                {
                    if (reformSelection.ContainsKey(index))
                    {
                        reformSelection.Remove(index);
                    }
                }, full);
            }
        }
Esempio n. 8
0
        public static bool CreateBox(BuildTool_BlueprintCopy __instance)
        {
            __instance.curActiveAreaGratBoxCursor = 0;

            CopyToTempArray(__instance);
            CopyReforms();

            BPGratBox gratbox = ReformBPUtils.GetBoundingRange(__instance.planet, __instance.actionBuild.planetAux, __instance._tmp_selected_ids, __instance._tmp_selected_cnt, tmpReformList, __instance.divideLineRad);

            if (__instance.selectedObjIds.Count > 0 || reformSelection.Count > 0)
            {
                float longitudeRadPerGrid = BlueprintUtils.GetLongitudeRadPerGrid(gratbox.startLatitudeRad, __instance.segment);
                float latitudeRadPerGrid  = BlueprintUtils.GetLatitudeRadPerGrid(__instance.segment);
                float extend_lng_grid     = Math.Max(3f - Mathf.RoundToInt(gratbox.width / longitudeRadPerGrid) / 2, 1f);
                float extend_lat_grid     = Math.Max(3f - Mathf.RoundToInt(gratbox.height / latitudeRadPerGrid) / 2, 1f);
                gratbox = BlueprintUtils.GetExtendedGratBox(gratbox, extend_lng_grid, extend_lat_grid);
                __instance.curActiveAreaGratBoxCursor = BlueprintUtils.SplitGratBoxInTropicAreas(gratbox, __instance.tropicGratBoxRadRangeArr, __instance.displayGratBoxArr, __instance.segment);


                Array.Clear(__instance._tmp_selected_ids, 0, __instance._tmp_selected_ids.Length);
            }

            return(false);
        }
Esempio n. 9
0
 public static void ClearPre(BuildTool_BlueprintCopy __instance)
 {
     reformPreSelection.Clear();
 }
Esempio n. 10
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);
            }
        }