Skip to content

Commit

Permalink
Added regroup option
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Mar 27, 2021
1 parent 989ad8e commit 1d0ffdf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ActivityGhosts/ActivityGhosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,13 @@ private void DeleteGhosts()
ghosts.Clear();
}

private void RegroupGhosts()
{
foreach (KeyValuePair<string, Ghost> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 1d0ffdf

Please sign in to comment.