public static List <Vector3> GenerateOceanPatrolPath(float minDistanceFromShore = 50f, float minWaterDepth = 8f) { RaycastHit raycastHit; object obj = Interface.CallHook("OnBoatPathGenerate"); if (obj is List <Vector3> ) { return((List <Vector3>)obj); } float size = TerrainMeta.Size.x; float single = 30f; int num = Mathf.CeilToInt(size * 2f * 3.14159274f / single); List <Vector3> vector3s = new List <Vector3>(); float single1 = size; float single2 = 0f; for (int i = 0; i < num; i++) { float single3 = (float)i / (float)num * 360f; vector3s.Add(new Vector3(Mathf.Sin(single3 * 0.0174532924f) * single1, single2, Mathf.Cos(single3 * 0.0174532924f) * single1)); } float single4 = 4f; float single5 = 200f; bool flag = true; for (int j = 0; j < AI.ocean_patrol_path_iterations & flag; j++) { flag = false; for (int k = 0; k < num; k++) { Vector3 item = vector3s[k]; int num1 = (k == 0 ? num - 1 : k - 1); Vector3 vector3 = vector3s[(k == num - 1 ? 0 : k + 1)]; Vector3 item1 = vector3s[num1]; Vector3 vector31 = item; Vector3 vector32 = Vector3.zero - item; Vector3 vector33 = vector32.normalized; Vector3 vector34 = item + (vector33 * single4); if (Vector3.Distance(vector34, vector3) <= single5 && Vector3.Distance(vector34, item1) <= single5) { bool flag1 = true; int num2 = 16; int num3 = 0; while (num3 < num2) { float single6 = (float)num3 / (float)num2 * 360f; vector32 = new Vector3(Mathf.Sin(single6 * 0.0174532924f), single2, Mathf.Cos(single6 * 0.0174532924f)); Vector3 vector35 = vector34 + (vector32.normalized * 1f); BaseBoat.GetWaterDepth(vector35); Vector3 vector36 = vector33; if (vector35 != Vector3.zero) { vector32 = vector35 - vector34; vector36 = vector32.normalized; } if (!UnityEngine.Physics.SphereCast(vector31, 3f, vector36, out raycastHit, minDistanceFromShore, 1218511105)) { num3++; } else { flag1 = false; break; } } if (flag1) { flag = true; vector3s[k] = vector34; } } } } if (flag) { Debug.LogWarning("Failed to generate ocean patrol path"); return(null); } List <int> nums = new List <int>(); LineUtility.Simplify(vector3s, 5f, nums); List <Vector3> vector3s1 = vector3s; vector3s = new List <Vector3>(); foreach (int num4 in nums) { vector3s.Add(vector3s1[num4]); } Debug.Log(string.Concat("Generated ocean patrol path with node count: ", vector3s.Count)); return(vector3s); }
public static List <Vector3> GenerateOceanPatrolPath( float minDistanceFromShore = 50f, float minWaterDepth = 8f) { // ISSUE: variable of the null type __Null x = TerrainMeta.Size.x; int num1 = Mathf.CeilToInt((float)(x * 2.0 * 3.14159274101257) / 30f); List <Vector3> vector3List1 = new List <Vector3>(); float num2 = (float)x; float num3 = 0.0f; for (int index = 0; index < num1; ++index) { float num4 = (float)((double)index / (double)num1 * 360.0); vector3List1.Add(new Vector3(Mathf.Sin(num4 * ((float)Math.PI / 180f)) * num2, num3, Mathf.Cos(num4 * ((float)Math.PI / 180f)) * num2)); } float num5 = 4f; float num6 = 200f; bool flag1 = true; for (int index1 = 0; index1 < AI.ocean_patrol_path_iterations & flag1; ++index1) { flag1 = false; for (int index2 = 0; index2 < num1; ++index2) { Vector3 vector3_1 = vector3List1[index2]; int index3 = index2 == 0 ? num1 - 1 : index2 - 1; int index4 = index2 == num1 - 1 ? 0 : index2 + 1; Vector3 vector3_2 = vector3List1[index4]; Vector3 vector3_3 = vector3List1[index3]; Vector3 vector3_4 = vector3_1; Vector3 vector3_5 = Vector3.op_Subtraction(Vector3.get_zero(), vector3_1); Vector3 normalized1 = ((Vector3) ref vector3_5).get_normalized(); Vector3 vector3_6 = Vector3.op_Addition(vector3_1, Vector3.op_Multiply(normalized1, num5)); if ((double)Vector3.Distance(vector3_6, vector3_2) <= (double)num6 && (double)Vector3.Distance(vector3_6, vector3_3) <= (double)num6) { bool flag2 = true; int num4 = 16; for (int index5 = 0; index5 < num4; ++index5) { float num7 = (float)((double)index5 / (double)num4 * 360.0); vector3_5 = new Vector3(Mathf.Sin(num7 * ((float)Math.PI / 180f)), num3, Mathf.Cos(num7 * ((float)Math.PI / 180f))); Vector3 normalized2 = ((Vector3) ref vector3_5).get_normalized(); Vector3 pos = Vector3.op_Addition(vector3_6, Vector3.op_Multiply(normalized2, 1f)); double waterDepth = (double)BaseBoat.GetWaterDepth(pos); Vector3 vector3_7 = normalized1; if (Vector3.op_Inequality(pos, Vector3.get_zero())) { vector3_5 = Vector3.op_Subtraction(pos, vector3_6); vector3_7 = ((Vector3) ref vector3_5).get_normalized(); } RaycastHit raycastHit; if (Physics.SphereCast(vector3_4, 3f, vector3_7, ref raycastHit, minDistanceFromShore, 1218511105)) { flag2 = false; break; } } if (flag2) { flag1 = true; vector3List1[index2] = vector3_6; } } } } if (flag1) { Debug.LogWarning((object)"Failed to generate ocean patrol path"); return((List <Vector3>)null); } List <int> intList = new List <int>(); LineUtility.Simplify(vector3List1, 5f, intList); List <Vector3> vector3List2 = vector3List1; List <Vector3> vector3List3 = new List <Vector3>(); foreach (int index in intList) { vector3List3.Add(vector3List2[index]); } Debug.Log((object)("Generated ocean patrol path with node count: " + (object)vector3List3.Count)); return(vector3List3); }