Skip to content

Commit 1d0ffdf

Browse files
committed
Added regroup option
1 parent 989ad8e commit 1d0ffdf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ActivityGhosts/ActivityGhosts.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Globalization;
55
using System.IO;
6+
using System.Linq;
67
using System.Windows.Forms;
78
using Dynastream.Fit;
89
using GTA;
@@ -55,6 +56,13 @@ private void DeleteGhosts()
5556
ghosts.Clear();
5657
}
5758

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+
5866
private void LoadGhosts()
5967
{
6068
int loaded = 0;
@@ -110,12 +118,16 @@ private void CreateMenu()
110118
menuPool.Add(mainMenu);
111119
var loadMenuItem = new UIMenuItem("Load", "Load ghosts");
112120
mainMenu.AddItem(loadMenuItem);
121+
var regroupMenuItem = new UIMenuItem("Regroup", "Regroup ghosts");
122+
mainMenu.AddItem(regroupMenuItem);
113123
var deleteMenuItem = new UIMenuItem("Delete", "Delete ghosts");
114124
mainMenu.AddItem(deleteMenuItem);
115125
mainMenu.OnItemSelect += (sender, item, index) =>
116126
{
117127
if (item == loadMenuItem)
118128
LoadGhosts();
129+
else if (item == regroupMenuItem)
130+
RegroupGhosts();
119131
else if (item == deleteMenuItem)
120132
DeleteGhosts();
121133
mainMenu.Visible = false;
@@ -238,6 +250,28 @@ public void Update()
238250
}
239251
}
240252

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+
241275
private Vector3 GetPoint(int i)
242276
{
243277
return new Vector3(points[i].Lat, points[i].Long, World.GetGroundHeight(new Vector2(points[i].Lat, points[i].Long)));

0 commit comments

Comments
 (0)