public static ItemClass.Zone GetBlockZoneOverride(ref ZoneBlock block, int x, int z, ItemClass.Zone zone1, ItemClass.Zone zone2) { ItemClass.Zone targetZone = block.GetZone(x, z); switch ((int)targetZone) { case 8: case 9: case 10: case 11: case 12: case 13: case 14: if (ZMController.m_ghostMode) { ItemClass.Zone newValue = CustomZoneData.Instance[targetZone].HasZone(zone1) ? zone1 : CustomZoneData.Instance[targetZone].HasZone(zone2) ? zone2 : CustomZoneData.Instance[targetZone].GetLowerestZone(); block.SetZone(x, z, newValue); block.RefreshZoning(0); return(newValue); } else { return(CustomZoneData.Instance[targetZone].HasZone(zone1) ? zone1 : CustomZoneData.Instance[targetZone].HasZone(zone2) ? zone2 : targetZone); } default: return(targetZone); } }
private static void ApplyBrush(ZoneTool z, ushort blockIndex, ref ZoneBlock data, Vector3 position, float brushRadius) { Vector3 a = data.m_position - position; if (Mathf.Abs(a.x) > 46f + brushRadius || Mathf.Abs(a.z) > 46f + brushRadius) { return; } bool m_zoning = (bool)z.GetType().GetField("m_zoning", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z); bool m_dezoning = (bool)z.GetType().GetField("m_dezoning", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z); int num = (int)((data.m_flags & 65280u) >> 8); Vector3 a2 = new Vector3(Mathf.Cos(data.m_angle), 0f, Mathf.Sin(data.m_angle)) * 8f; Vector3 a3 = new Vector3(a2.z, 0f, -a2.x); bool flag = false; for (int i = 0; i < num; i++) { Vector3 b = ((float)i - 3.5f) * a3; for (int j = 0; j < 4; j++) { Vector3 b2 = ((float)j - 3.5f) * a2; Vector3 vector = a + b2 + b; float num2 = vector.x * vector.x + vector.z * vector.z; if (num2 <= brushRadius * brushRadius) { if (m_zoning) { if ((z.m_zone == ItemClass.Zone.Unzoned || data.GetZone(j, i) == ItemClass.Zone.Unzoned) && data.SetZone(j, i, z.m_zone)) { flag = true; } } else if (m_dezoning && data.SetZone(j, i, ItemClass.Zone.Unzoned)) { flag = true; } } } } if (!flag) { return; } data.RefreshZoning(blockIndex); if (!m_zoning) { return; } UsedZone(z, z.m_zone); }
public static bool GetBlockZoneSanitize(ref ZoneBlock block, int x, int z) { ItemClass.Zone targetZone = block.GetZone(x, z); switch ((int)targetZone) { case 8: case 9: case 10: case 11: case 12: case 13: case 14: if (ZMController.m_ghostMode) { ItemClass.Zone newValue = CustomZoneData.Instance[targetZone].GetLowerestZone(); block.SetZone(x, z, newValue); return(true); } break; } return(false); }
private static void ApplyBrush(ZoneTool z,ushort blockIndex, ref ZoneBlock data, Vector3 position, float brushRadius) { Vector3 a = data.m_position - position; if (Mathf.Abs(a.x) > 46f + brushRadius || Mathf.Abs(a.z) > 46f + brushRadius) { return; } bool m_zoning = (bool)z.GetType().GetField("m_zoning", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z); bool m_dezoning = (bool)z.GetType().GetField("m_dezoning", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z); int num = (int)((data.m_flags & 65280u) >> 8); Vector3 a2 = new Vector3(Mathf.Cos(data.m_angle), 0f, Mathf.Sin(data.m_angle)) * 8f; Vector3 a3 = new Vector3(a2.z, 0f, -a2.x); bool flag = false; for (int i = 0; i < num; i++) { Vector3 b = ((float)i - 3.5f) * a3; for (int j = 0; j < 4; j++) { Vector3 b2 = ((float)j - 3.5f) * a2; Vector3 vector = a + b2 + b; float num2 = vector.x * vector.x + vector.z * vector.z; if (num2 <= brushRadius * brushRadius) { if (m_zoning) { if ((z.m_zone == ItemClass.Zone.Unzoned || data.GetZone(j, i) == ItemClass.Zone.Unzoned) && data.SetZone(j, i, z.m_zone)) { flag = true; } } else if (m_dezoning && data.SetZone(j, i, ItemClass.Zone.Unzoned)) { flag = true; } } } } if (flag) { data.RefreshZoning(blockIndex); if (m_zoning) { UsedZone(z.m_zone); } } }
private static void CalculateImplementation2(ref ZoneBlock z, ushort blockID, ref ZoneBlock other, ref ulong valid, ref ulong shared, float minX, float minZ, float maxX, float maxZ) { if (((int)other.m_flags & 1) == 0 || (double)Mathf.Abs(other.m_position.x - z.m_position.x) >= 92.0 || (double)Mathf.Abs(other.m_position.z - z.m_position.z) >= 92.0) return; bool flag1 = ((int)other.m_flags & 2) != 0; int rowCount1 = z.RowCount; int rowCount2 = other.RowCount; Vector2 vector2_1 = new Vector2(Mathf.Cos(z.m_angle), Mathf.Sin(z.m_angle)) * 8f; Vector2 vector2_2 = new Vector2(vector2_1.y, -vector2_1.x); Vector2 vector2_3 = new Vector2(Mathf.Cos(other.m_angle), Mathf.Sin(other.m_angle)) * 8f; Vector2 vector2_4 = new Vector2(vector2_3.y, -vector2_3.x); Vector2 vector2_5 = VectorUtils.XZ(other.m_position); Quad2 quad = new Quad2(); quad.a = vector2_5 - 4f * vector2_3 - 4f * vector2_4; quad.b = vector2_5 + 0.0f * vector2_3 - 4f * vector2_4; quad.c = vector2_5 + 0.0f * vector2_3 + (float)(rowCount2 - 4) * vector2_4; quad.d = vector2_5 - 4f * vector2_3 + (float)(rowCount2 - 4) * vector2_4; Vector2 vector2_6 = quad.Min(); Vector2 vector2_7 = quad.Max(); if ((double)vector2_6.x > (double)maxX || (double)vector2_6.y > (double)maxZ || ((double)minX > (double)vector2_7.x || (double)minZ > (double)vector2_7.y)) return; Vector2 vector2_8 = VectorUtils.XZ(z.m_position); Quad2 quad2_1 = new Quad2(); quad2_1.a = vector2_8 - 4f * vector2_1 - 4f * vector2_2; quad2_1.b = vector2_8 + 0.0f * vector2_1 - 4f * vector2_2; quad2_1.c = vector2_8 + 0.0f * vector2_1 + (float)(rowCount1 - 4) * vector2_2; quad2_1.d = vector2_8 - 4f * vector2_1 + (float)(rowCount1 - 4) * vector2_2; if (!quad2_1.Intersect(quad)) return; for (int z1 = 0; z1 < rowCount1; ++z1) { Vector2 vector2_9 = ((float)z1 - 3.99f) * vector2_2; Vector2 vector2_10 = ((float)z1 - 3.01f) * vector2_2; quad2_1.a = vector2_8 - 4f * vector2_1 + vector2_9; quad2_1.b = vector2_8 + 0.0f * vector2_1 + vector2_9; quad2_1.c = vector2_8 + 0.0f * vector2_1 + vector2_10; quad2_1.d = vector2_8 - 4f * vector2_1 + vector2_10; if (quad2_1.Intersect(quad)) { for (int x1 = 0; (long)x1 < 4L && ((long)valid & 1L << (z1 << 3 | x1)) != 0L; ++x1) { Vector2 vector2_11 = ((float)x1 - 3.99f) * vector2_1; Vector2 vector2_12 = ((float)x1 - 3.01f) * vector2_1; Vector2 p = vector2_8 + (vector2_12 + vector2_11 + vector2_10 + vector2_9) * 0.5f; if (Quad2.Intersect(quad.a - vector2_3 - vector2_4, quad.b + vector2_3 - vector2_4, quad.c + vector2_3 + vector2_4, quad.d - vector2_3 + vector2_4, p)) { Quad2 quad2_2 = new Quad2(); quad2_2.a = vector2_8 + vector2_11 + vector2_9; quad2_2.b = vector2_8 + vector2_12 + vector2_9; quad2_2.c = vector2_8 + vector2_12 + vector2_10; quad2_2.d = vector2_8 + vector2_11 + vector2_10; bool flag2 = true; bool flag3 = false; for (int z2 = 0; z2 < rowCount2 && flag2; ++z2) { Vector2 vector2_13 = ((float)z2 - 3.99f) * vector2_4; Vector2 vector2_14 = ((float)z2 - 3.01f) * vector2_4; for (int x2 = 0; (long)x2 < 4L && flag2; ++x2) { if (((long)other.m_valid & ~(long)other.m_shared & 1L << (z2 << 3 | x2)) != 0L) { Vector2 vector2_15 = ((float)x2 - 3.99f) * vector2_3; Vector2 vector2_16 = ((float)x2 - 3.01f) * vector2_3; float num1 = Vector2.SqrMagnitude(vector2_5 + (vector2_16 + vector2_15 + vector2_14 + vector2_13) * 0.5f - p); if ((double)num1 < 144.0) { if (!flag1) { float f = Mathf.Abs(other.m_angle - z.m_angle) * 0.6366197f; float num2 = f - Mathf.Floor(f); if ((double)num1 < 0.00999999977648258 && ((double)num2 < 0.00999999977648258 || (double)num2 > 0.990000009536743)) { if (x1 < x2 || x1 == x2 && z.m_buildIndex < other.m_buildIndex) other.m_shared |= (ulong)(1L << (z2 << 3 | x2)); else flag3 = true; } else if (quad2_2.Intersect(new Quad2() { a = vector2_5 + vector2_15 + vector2_13, b = vector2_5 + vector2_16 + vector2_13, c = vector2_5 + vector2_16 + vector2_14, d = vector2_5 + vector2_15 + vector2_14 })) { if (x2 >= 4 && x1 >= 4 || x2 < 4 && x1 < 4) { if (x2 >= 2 && x1 >= 2 || x2 < 2 && x1 < 2) { if (z.m_buildIndex < other.m_buildIndex) other.m_valid &= (ulong)~(1L << (z2 << 3 | x2)); else flag2 = false; } else if (x2 < 2) flag2 = false; else other.m_valid &= (ulong)~(1L << (z2 << 3 | x2)); } else if (x2 < 4) flag2 = false; else other.m_valid &= (ulong)~(1L << (z2 << 3 | x2)); } } if ((double)num1 < 36.0 && x1 < 4 && x2 < 4) { ItemClass.Zone zone1 = z.GetZone(x1, z1); ItemClass.Zone zone2 = other.GetZone(x2, z2); if (zone1 == ItemClass.Zone.Unzoned) z.SetZone(x1, z1, zone2); else if (zone2 == ItemClass.Zone.Unzoned && !flag1) other.SetZone(x2, z2, zone1); } } } } } if (!flag2) { valid = valid & (ulong)~(1L << (z1 << 3 | x1)); break; } if (flag3) shared = shared | (ulong)(1L << (z1 << 3 | x1)); } } } } }