public static BPGratBox[] SplitGratBox(BPGratBox box) { int areaCount = BlueprintUtils.GetAreaCount(box.y, box.w, currentGrid.segment); BPGratBox[] areas = new BPGratBox[areaCount]; SplitGratBoxInTropicAreas(box, areas, currentGrid.segment); return(areas); }
public static bool IsOnEdgeOfGratBox(this BPGratBox box, float longitudeRad, float latitudeRad, int segmentCount) { float latPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(segmentCount); float longPerGrid = BlueprintUtils.GetLongitudeRadPerGrid(latitudeRad, segmentCount); BPGratBox smallBox = new BPGratBox(box.x + longPerGrid, box.y + latPerGrid, box.z - longPerGrid, box.w - latPerGrid); return(!smallBox.InGratBox(longitudeRad, latitudeRad)); }
public override void _OnClose() { DismantleQueryRemove(); ClearSelection(); ResetBuildPreviews(); startGroundPosSnapped = lastGroundPosSnapped = castGroundPosSnapped = Vector3.zero; lastSelectGratBox = selectGratBox = selectArcBox = BPGratBox.zero; castObjectId = 0; castObjectPos = Vector3.zero; cursorValid = false; cursorTarget = Vector3.zero; waitingForPlayerInput = false; }
public static void CheckAfter(BuildTool_BlueprintPaste __instance, ref bool __result, ref bool __state) { if (__result) { return; } if (!BlueprintCopyExtension.isEnabled || !__state) { return; } if (!__instance.cannotBuild || reformPreviews.Count <= 0) { return; } if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.Value) { return; } BPGratBox box = ReformBPUtils.GetBoundingRange(__instance.planet, __instance.actionBuild.planetAux, new int[0], 0, reformPreviews, reformPreviews[0].longitude); bool allOk = true; for (int i = 0; i < __instance.bpCursor; i++) { BuildPreview preview = __instance.bpPool[i]; if (preview.condition == EBuildCondition.NeedGround) { Vector3 pos = (preview.lpos + preview.lpos2) * 0.5f; if (box.InGratBox(pos)) { preview.condition = EBuildCondition.Ok; } } if (preview.condition != EBuildCondition.Ok && preview.condition != EBuildCondition.NotEnoughItem) { allOk = false; } } if (allOk) { __result = true; } }
public override void _OnOpen() { ClearSelection(); ResetBuildPreviews(); castTerrain = false; castGround = false; castGroundPos = Vector3.zero; startGroundPosSnapped = lastGroundPosSnapped = castGroundPosSnapped = Vector3.zero; lastSelectGratBox = selectGratBox = selectArcBox = BPGratBox.zero; castObjectId = 0; castObjectPos = Vector3.zero; cursorValid = false; cursorTarget = Vector3.zero; isSelecting = false; waitingForPlayerInput = false; }
public void DetermineSelectGratBox() { if (cursorValid) { float longitudeRad = BlueprintUtils.GetLongitudeRad(castGroundPosSnapped.normalized); float longitudeRad2 = BlueprintUtils.GetLongitudeRad(lastGroundPosSnapped.normalized); float latitudeRad = BlueprintUtils.GetLatitudeRad(castGroundPosSnapped.normalized); bool flag = latitudeRad >= 1.5707864f || latitudeRad <= -1.5707864f; float num = flag ? 0f : longitudeRad - longitudeRad2; num = Mathf.Repeat(num + 3.1415927f, 6.2831855f) - 3.1415927f; selectArcBox.endLongitudeRad = selectArcBox.endLongitudeRad + num; selectArcBox.endLatitudeRad = latitudeRad; selectGratBox = selectArcBox; selectGratBox.x = selectArcBox.x < selectArcBox.z ? selectArcBox.x : selectArcBox.z; selectGratBox.z = selectArcBox.x > selectArcBox.z ? selectArcBox.x : selectArcBox.z; if (selectArcBox.x < selectArcBox.z) { if (selectGratBox.z > selectGratBox.x + 6.2831855f - 1E-05f - 4E-06f) { selectGratBox.z = selectGratBox.x + 6.2831855f - 1E-05f - 4E-06f; } selectGratBox.z = Mathf.Repeat(selectGratBox.z + 3.1415927f, 6.2831855f) - 3.1415927f; } else { if (selectGratBox.x < selectGratBox.z - 6.2831855f + 1E-05f + 4E-06f) { selectGratBox.x = selectGratBox.z - 6.2831855f + 1E-05f + 4E-06f; } selectGratBox.x = Mathf.Repeat(selectGratBox.x + 3.1415927f, 6.2831855f) - 3.1415927f; } selectGratBox.y = selectArcBox.y < selectArcBox.w ? selectArcBox.y : selectArcBox.w; selectGratBox.w = selectArcBox.y > selectArcBox.w ? selectArcBox.y : selectArcBox.w; float longitude = BlueprintUtils.GetLongitudeRadPerGrid(Mathf.Abs(castGroundPosSnapped.y) < Mathf.Abs(startGroundPosSnapped.y) ? castGroundPosSnapped.normalized : startGroundPosSnapped.normalized) * 0.33f; selectGratBox.Extend(longitude, 0.002f); if (!flag) { lastGroundPosSnapped = castGroundPosSnapped; } } }
private void InitSelectGratBox() { BlueprintUtils.GetMinimumGratBox(startGroundPosSnapped.normalized, ref selectGratBox); selectArcBox = selectGratBox; if (selectArcBox.y >= 1.5707864f) { selectArcBox.y = selectArcBox.w = 1.5707964f; selectArcBox.z = selectArcBox.x + 628.31854f; } else if (selectArcBox.y <= -1.5707864f) { selectArcBox.y = selectArcBox.w = -1.5707964f; selectArcBox.z = selectArcBox.x + 628.31854f; } lastSelectGratBox = selectGratBox; }
public static bool IsOnEdgeOfGratBox(this BPGratBox box, Vector3 pos, int segmentCount) { pos.Normalize(); float num = pos.y; if (num > 0.999999f) { return(box.w >= 1.5707864f); } if (num < -0.999999f) { return(box.y <= -1.5707864f); } float latitudeRad = Mathf.Asin(num); float longitudeRad = Mathf.Atan2(pos.x, -pos.z); return(box.IsOnEdgeOfGratBox(longitudeRad, latitudeRad, segmentCount)); }
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); }
public void ClearSelection() { selectObjIds.Clear(); edgeObjIds.Clear(); lastSelectGratBox = selectGratBox = selectArcBox = BPGratBox.zero; }
public void Operating() { if (waitingForPlayerInput) { return; } if (!isSelecting && VFInput.blueprintCopyOperate0.onDown && cursorValid) { isSelecting = true; startGroundPosSnapped = castGroundPosSnapped; lastGroundPosSnapped = startGroundPosSnapped; InitSelectGratBox(); VFInput.UseMouseLeft(); } bool point = (castGroundPosSnapped - startGroundPosSnapped).sqrMagnitude > 0.01f; bool onDown = VFInput.blueprintCopyOperate0.onDown || VFInput.blueprintCopyOperate1.onDown; if (isSelecting && (onDown && cursorValid || VFInput.blueprintCopyOperate0.onUp && castObjectId != 0 && !point)) { CheckDismantle(); if (waitingForPlayerInput) { return; } ResetBuildPreviews(); isSelecting = false; VFInput.UseMouseLeft(); VFInput.UseEnterConfirm(); } else if (isSelecting && VFInput.rtsCancel.onUp) { isSelecting = false; startGroundPosSnapped = castGroundPosSnapped; lastGroundPosSnapped = startGroundPosSnapped; ClearSelection(); ResetBuildPreviews(); } if (isSelecting) { DetermineSelectGratBox(); if (lastSelectGratBox != selectGratBox) { DetermineAddSelection(); lastSelectGratBox = selectGratBox; } } else { startGroundPosSnapped = castGroundPosSnapped; ReDeterminePreviews(); } if (point) { ReDeterminePreviews(); } }
public static void SwitchDelete(PlanetFactory factory, List <int> objectIds) { if (objectIds.Count <= 0) { return; } if (NebulaModAPI.IsMultiplayerActive) { IMultiplayerSession session = NebulaModAPI.MultiplayerSession; int planetId = session.Factories.TargetPlanet != NebulaModAPI.PLANET_NONE ? session.Factories.TargetPlanet : factory.planet?.id ?? -1; if (session.LocalPlayer.IsHost || !session.Factories.IsIncomingRequest.Value) { session.Network.SendPacket(new FastRemoveRequestPacket(planetId, objectIds.ToArray(), Array.Empty <int>(), session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? session.LocalPlayer.Id : session.Factories.PacketAuthor, false)); } if (!session.LocalPlayer.IsHost && !session.Factories.IsIncomingRequest.Value) { return; } } if (objectIds.Count < 25) { RegularDeleteEntities(factory, objectIds); return; } if (BlueprintTweaksPlugin.useFastDismantle.Value) { var player = GameMain.mainPlayer; PlayerAction_Build actionBuild = player.controller.actionBuild; float divLine = GetDivideLine(factory, actionBuild, objectIds); BPGratBox boundingBox = BlueprintUtils.GetBoundingRange(factory.planet, factory.planet.aux, objectIds.ToArray(), objectIds.Count, divLine); HashSet <int> edgeObjIds = new HashSet <int>(); int segmentCnt = 200; if (GameMain.localPlanet?.aux?.activeGrid != null) { segmentCnt = GameMain.localPlanet.aux.activeGrid.segment; } foreach (int objectId in objectIds) { if (objectId <= 0 || factory.entityPool[objectId].id != objectId) { continue; } if (boundingBox.IsOnEdgeOfGratBox(factory.entityPool[objectId].pos, segmentCnt)) { edgeObjIds.Add(objectId); } } if (edgeObjIds.Count == 0) { foreach (int objectId in objectIds) { if (objectId <= 0 || factory.entityPool[objectId].beltId <= 0) { continue; } RegularDeleteEntities(factory, objectIds); return; } } FastDeleteEntities(factory, objectIds, edgeObjIds.ToList()); } else { RegularDeleteEntities(factory, objectIds); } }
public static int SplitGratBoxInTropicAreas(BPGratBox _gratbox, BPGratBox[] _areaBoxes, int _segmentCnt = 200) { float startLong = _gratbox.x; float startLat = _gratbox.y; float endLong = _gratbox.z; float endLat = _gratbox.w; if (endLong < startLong - 1E-05f) { endLong += 6.2831855f; } int endIdx = BlueprintUtils.GetSnappedLatitudeGridIdx(endLat, _segmentCnt); int startIdx = BlueprintUtils.GetSnappedLatitudeGridIdx(startLat, _segmentCnt); float radPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(_segmentCnt); int index = 0; int index1 = -1; float curLat = _gratbox.y; _areaBoxes[index] = BPGratBox.zero; _areaBoxes[index].y = _areaBoxes[index].w = curLat; int startSegCount = BlueprintUtils.GetLongitudeSegmentCount(startIdx, _segmentCnt); for (int i = startIdx; i <= endIdx; i++) { int curIdx = i + 1 > endIdx ? endIdx : i + 1; curLat = curIdx * radPerGrid; int curSegCount = startSegCount; int segmentCount = BlueprintUtils.GetLongitudeSegmentCount(curIdx, _segmentCnt); startSegCount = segmentCount; bool different = curSegCount != segmentCount; if (index1 < index) { float radPerGrid2 = BlueprintUtils.GetLongitudeRadPerGrid(curSegCount, _segmentCnt); float startCount = startLong / radPerGrid2; float endCount = endLong / radPerGrid2; float roundStartCount = BlueprintUtils._round(startCount); endCount = BlueprintUtils._round(endCount); float startLong2 = roundStartCount * radPerGrid2; float endLong2 = endCount * radPerGrid2; if (endLong2 > startLong2 + 6.2831855f - 1E-05f - 4E-06f) { endLong2 = startLong2 + 6.2831855f - radPerGrid2; } if (startLong2 < -3.1415927f) { startLong2 += 6.2831855f; } if (startLong2 > 3.1415927f) { startLong2 -= 6.2831855f; } if (endLong2 < -3.1415927f) { endLong2 += 6.2831855f; } if (endLong2 > 3.1415927f) { endLong2 -= 6.2831855f; } _areaBoxes[index].x = startLong2; _areaBoxes[index].z = endLong2; index1 = index; } if (different) { if (curIdx > 0) { curIdx = i > endIdx ? endIdx : i; curLat = curIdx * radPerGrid; } index++; _areaBoxes[index] = BPGratBox.zero; _areaBoxes[index].y = _areaBoxes[index].w = curLat; } else { if (curIdx < 0) { curIdx = i + 2 > endIdx ? endIdx : i + 2; curLat = curIdx * radPerGrid; } _areaBoxes[index].w = curLat; } } return(index + 1); }
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); } }