|
3 | 3 | using System.Drawing;
|
4 | 4 | using System.Globalization;
|
5 | 5 | using System.IO;
|
| 6 | +using System.Linq; |
6 | 7 | using System.Windows.Forms;
|
7 | 8 | using Dynastream.Fit;
|
8 | 9 | using GTA;
|
@@ -55,6 +56,13 @@ private void DeleteGhosts()
|
55 | 56 | ghosts.Clear();
|
56 | 57 | }
|
57 | 58 |
|
| 59 | + private void RegroupGhosts() |
| 60 | + { |
| 61 | + foreach (KeyValuePair<string, Ghost> g in ghosts) |
| 62 | + g.Value.Regroup(new PointF(Game.Player.Character.Position.X, Game.Player.Character.Position.Y)); |
| 63 | + lastTime = System.DateTime.UtcNow; |
| 64 | + } |
| 65 | + |
58 | 66 | private void LoadGhosts()
|
59 | 67 | {
|
60 | 68 | int loaded = 0;
|
@@ -110,12 +118,16 @@ private void CreateMenu()
|
110 | 118 | menuPool.Add(mainMenu);
|
111 | 119 | var loadMenuItem = new UIMenuItem("Load", "Load ghosts");
|
112 | 120 | mainMenu.AddItem(loadMenuItem);
|
| 121 | + var regroupMenuItem = new UIMenuItem("Regroup", "Regroup ghosts"); |
| 122 | + mainMenu.AddItem(regroupMenuItem); |
113 | 123 | var deleteMenuItem = new UIMenuItem("Delete", "Delete ghosts");
|
114 | 124 | mainMenu.AddItem(deleteMenuItem);
|
115 | 125 | mainMenu.OnItemSelect += (sender, item, index) =>
|
116 | 126 | {
|
117 | 127 | if (item == loadMenuItem)
|
118 | 128 | LoadGhosts();
|
| 129 | + else if (item == regroupMenuItem) |
| 130 | + RegroupGhosts(); |
119 | 131 | else if (item == deleteMenuItem)
|
120 | 132 | DeleteGhosts();
|
121 | 133 | mainMenu.Visible = false;
|
@@ -238,6 +250,28 @@ public void Update()
|
238 | 250 | }
|
239 | 251 | }
|
240 | 252 |
|
| 253 | + public void Regroup(PointF point) |
| 254 | + { |
| 255 | + int closest = points.IndexOf(points.OrderBy(x => Distance(point, x)).First()); |
| 256 | + if (points.Count > closest + 1) |
| 257 | + { |
| 258 | + index = closest + 1; |
| 259 | + if (!ped.IsOnBike) |
| 260 | + ped.SetIntoVehicle(vehicle, VehicleSeat.Driver); |
| 261 | + vehicle.Position = GetPoint(closest); |
| 262 | + vehicle.Heading = GetHeading(closest); |
| 263 | + ped.Task.ClearAll(); |
| 264 | + ped.Task.DriveTo(vehicle, GetPoint(index), 0f, points[closest].Speed, (DrivingStyle)customDrivingStyle); |
| 265 | + vehicle.Speed = points[closest].Speed; |
| 266 | + skipped = 0; |
| 267 | + } |
| 268 | + } |
| 269 | + |
| 270 | + private double Distance(PointF from, GeoPoint to) |
| 271 | + { |
| 272 | + return Math.Sqrt((to.Long - from.Y) * (to.Long - from.Y) + (to.Lat - from.X) * (to.Lat - from.X)); |
| 273 | + } |
| 274 | + |
241 | 275 | private Vector3 GetPoint(int i)
|
242 | 276 | {
|
243 | 277 | return new Vector3(points[i].Lat, points[i].Long, World.GetGroundHeight(new Vector2(points[i].Lat, points[i].Long)));
|
|
0 commit comments