using System.Collections; using UnityEngine; namespace GrassCutter { public partial class DemoBot { /// /// -demosink: a tractor on the steepest bit of meadow round the base. Each round drives it up the slope, hops off, /// and drops it from eight metres; the log says how far below the ground its lowest corner or its nose went. The /// first round has the hard floor off (how it was), the second on. /// IEnumerator SinkDemo() { TeamState.DeleteSave(); yield return new WaitForSeconds(2f); NetSession.Instance.HostLocal(); while (!Me || !Ts) yield return null; yield return new WaitForSeconds(3f); Clock(11f); Ts.ServerSetMoney(100000d); // the steepest clear slope within 70 m Vector3 steep = Soil17(60f, 40f), downhill = Vector3.forward; float worst = -1f; for (int a = 0; a < 48; a++) for (float r = 30f; r <= 70f; r += 8f) { var q = Soil17(Mathf.Cos(a * 7.5f * Mathf.Deg2Rad) * r, Mathf.Sin(a * 7.5f * Mathf.Deg2Rad) * r); var u = Planet.Up(q); var e1 = Vector3.Cross(u, Vector3.forward).normalized; var e2 = Vector3.Cross(u, e1); float h1 = Planet.Altitude(q + e1 * 2f + u * 0f) - Planet.Altitude(q - e1 * 2f); float h2 = Planet.Altitude(q + e2 * 2f) - Planet.Altitude(q - e2 * 2f); float slope = Mathf.Atan2(new Vector2(h1, h2).magnitude, 4f) * Mathf.Rad2Deg; if (slope > worst && !Ts.OnDeck(q) && !(Ground.Instance && Ground.Instance.RockAt(q)) && !Physics.CheckSphere(q + u * 3f, 9f, 1 << Layers.Default, QueryTriggerInteraction.Ignore)) { worst = slope; steep = q; // altitude grows the way the ground falls away under the probe, so "uphill" is against it downhill = (e1 * h1 + e2 * h2).normalized; } } var up = Planet.Up(steep); var start = steep + downhill * 18f; start = Planet.Surface(start); var uphill = Vector3.ProjectOnPlane(-downhill, Planet.Up(start)).normalized; Log($"slope {worst:0} deg at {steep}"); var v = Spawner.Instance.SpawnVehicle(VehicleKind.Tractor, Me.SaveId, start + Planet.Up(start) * 0.6f, Quaternion.LookRotation(uphill, Planet.Up(start))); yield return new WaitForSeconds(1.5f); if (!v) { Log("tractor NOT spawned"); Application.Quit(); yield break; } for (int round = 0; round < 2; round++) { Vehicle.NoFloor = round == 0; string tag = round == 0 ? "floor OFF" : "floor ON "; v.ServerPut(start + Planet.Up(start) * 0.6f, Quaternion.LookRotation(uphill, Planet.Up(start))); yield return new WaitForSeconds(2f); int sinks = Vehicle.Sinks; // up the slope, flat out v.Interact(); yield return new WaitForSeconds(0.6f); Ctl.BotMove = Vector2.up; float climb = 0f; for (float t = 0f; t < 5f; t += Time.fixedDeltaTime) { climb = Mathf.Min(climb, Lowest(v)); yield return new WaitForFixedUpdate(); } Ctl.BotMove = Vector2.zero; yield return new WaitForSeconds(1f); if (round == 1) yield return Look("sink_climb", v.transform.position + Planet.Up(v.transform.position) * 1.5f + v.transform.right * 7f, v.transform.position, 0.3f); // hop off and watch it stand v.RequestExit(); float off = 0f; for (float t = 0f; t < 4f; t += Time.fixedDeltaTime) { off = Mathf.Min(off, Lowest(v)); yield return new WaitForFixedUpdate(); } float rest = Lowest(v); // and dropped from eight metres var p = v.transform.position; v.ServerPut(p + Planet.Up(p) * 8f, v.transform.rotation); float land = 0f; for (float t = 0f; t < 5f; t += Time.fixedDeltaTime) { land = Mathf.Min(land, Lowest(v)); yield return new WaitForFixedUpdate(); } Log($"{tag}: deepest on the climb {climb:0.00} m, after hopping off {off:0.00} m (at rest {rest:0.00}), landing {land:0.00} m, caught {Vehicle.Sinks - sinks} times, now {Planet.Altitude(v.transform.position):0.00} m up"); } Vehicle.NoFloor = false; // and the map, close in, with the sectors round here Cheats.Run("tool all"); Me.Teleport(v.transform.position + v.transform.right * 4f + Planet.Up(v.transform.position)); yield return Sweep(Me.transform.position, new Vector3(0f, 0f, 1.6f), 3f); UIRoot.I.OpenMap(); yield return new WaitForSeconds(1.5f); BotCapture.From = null; yield return Shot("sink_map"); Log($"map: {MapScreen.Drawn} sectors drawn close in, {MapScreen.Flipped} turned round"); UIRoot.I.CloseTopModal(); yield return new WaitForSeconds(0.3f); UIRoot.I.OpenMap(1.6f); yield return new WaitForSeconds(1.5f); yield return Shot("sink_map_far"); Log("sink done"); Application.Quit(); } /// The lowest of its four corners, nose and tail, against the ground (below it is negative). static float Lowest(Vehicle v) { float low = float.MaxValue; var t = v.transform; for (int x = -1; x <= 1; x += 2) for (int z = -1; z <= 1; z += 2) low = Mathf.Min(low, Planet.Altitude(t.TransformPoint(new Vector3(x * 0.5f * v.width, 0f, z * 0.42f * v.length)))); low = Mathf.Min(low, Planet.Altitude(t.TransformPoint(new Vector3(0f, 0f, 0.5f * v.length)))); low = Mathf.Min(low, Planet.Altitude(t.TransformPoint(new Vector3(0f, 0f, -0.5f * v.length)))); return low; } } }