From 1d0ffdf58d12b8717943306e15b67ce52e442e0a Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Sat, 27 Mar 2021 17:03:16 -0300 Subject: [PATCH] Added regroup option --- ActivityGhosts/ActivityGhosts.cs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ActivityGhosts/ActivityGhosts.cs b/ActivityGhosts/ActivityGhosts.cs index 7ddbde7..e5ee1aa 100644 --- a/ActivityGhosts/ActivityGhosts.cs +++ b/ActivityGhosts/ActivityGhosts.cs @@ -3,6 +3,7 @@ using System.Drawing; using System.Globalization; using System.IO; +using System.Linq; using System.Windows.Forms; using Dynastream.Fit; using GTA; @@ -55,6 +56,13 @@ private void DeleteGhosts() ghosts.Clear(); } + private void RegroupGhosts() + { + foreach (KeyValuePair g in ghosts) + g.Value.Regroup(new PointF(Game.Player.Character.Position.X, Game.Player.Character.Position.Y)); + lastTime = System.DateTime.UtcNow; + } + private void LoadGhosts() { int loaded = 0; @@ -110,12 +118,16 @@ private void CreateMenu() menuPool.Add(mainMenu); var loadMenuItem = new UIMenuItem("Load", "Load ghosts"); mainMenu.AddItem(loadMenuItem); + var regroupMenuItem = new UIMenuItem("Regroup", "Regroup ghosts"); + mainMenu.AddItem(regroupMenuItem); var deleteMenuItem = new UIMenuItem("Delete", "Delete ghosts"); mainMenu.AddItem(deleteMenuItem); mainMenu.OnItemSelect += (sender, item, index) => { if (item == loadMenuItem) LoadGhosts(); + else if (item == regroupMenuItem) + RegroupGhosts(); else if (item == deleteMenuItem) DeleteGhosts(); mainMenu.Visible = false; @@ -238,6 +250,28 @@ public void Update() } } + public void Regroup(PointF point) + { + int closest = points.IndexOf(points.OrderBy(x => Distance(point, x)).First()); + if (points.Count > closest + 1) + { + index = closest + 1; + if (!ped.IsOnBike) + ped.SetIntoVehicle(vehicle, VehicleSeat.Driver); + vehicle.Position = GetPoint(closest); + vehicle.Heading = GetHeading(closest); + ped.Task.ClearAll(); + ped.Task.DriveTo(vehicle, GetPoint(index), 0f, points[closest].Speed, (DrivingStyle)customDrivingStyle); + vehicle.Speed = points[closest].Speed; + skipped = 0; + } + } + + private double Distance(PointF from, GeoPoint to) + { + return Math.Sqrt((to.Long - from.Y) * (to.Long - from.Y) + (to.Lat - from.X) * (to.Lat - from.X)); + } + private Vector3 GetPoint(int i) { return new Vector3(points[i].Lat, points[i].Long, World.GetGroundHeight(new Vector2(points[i].Lat, points[i].Long)));