1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 15:40:29 +01:00

Fixed vehicles being dismissed prematurely when directed from one path to another.

This commit is contained in:
Rich Dunne 2020-10-10 07:29:39 -06:00
parent b17135814c
commit a68de1d56a
2 changed files with 69 additions and 40 deletions

View file

@ -12,7 +12,8 @@ namespace SceneManager
{
FromPath = 0,
FromWaypoint = 1,
FromWorld = 2
FromWorld = 2,
FromDirect = 3
}
static class PathMainMenu
@ -141,11 +142,7 @@ namespace SceneManager
{
cv.Driver.GetAttachedBlip().Delete();
}
Logger.Log($"{cv.Vehicle.Model.Name} task status before clear/dismiss: {cv.Driver.Tasks.CurrentTaskStatus.ToString()}");
cv.Driver.Tasks.Clear();
cv.Driver.Tasks.ClearSecondary();
cv.Driver.Dismiss();
Logger.Log($"{cv.Vehicle.Model.Name} task status after clear/dismiss: {cv.Driver.Tasks.CurrentTaskStatus.ToString()}");
cv.Vehicle.IsSirenOn = false;
cv.Vehicle.IsSirenSilent = true;
cv.Vehicle.Dismiss();
@ -250,13 +247,6 @@ namespace SceneManager
var firstWaypoint = waypoints.First();
var nearestWaypoint = waypoints.Where(wp => wp.Position.DistanceTo2D(nearbyVehicle.FrontPosition) < wp.Position.DistanceTo2D(nearbyVehicle.RearPosition)).OrderBy(wp => wp.Position.DistanceTo2D(nearbyVehicle)).FirstOrDefault();
if(collectedVehicle != null)
{
collectedVehicle.Dismiss();
collectedVehicle = null;
}
//VehicleCollector.SetVehicleAndDriverPersistence(nearbyVehicle);
// The vehicle should only be added to the collection when it's not null AND if the selected item is First Waypoint OR if the selected item is nearestWaypoint AND nearestWaypoint is not null
if (collectedVehicle == null && directOptions.SelectedItem == "First waypoint" || (directOptions.SelectedItem == "Nearest waypoint" && nearestWaypoint != null))
{
@ -272,17 +262,12 @@ namespace SceneManager
}
collectedVehicle.Directed = true;
collectedVehicle.Driver.Tasks.Clear();
if (collectedVehicle.StoppedAtWaypoint)
{
collectedVehicle.StoppedAtWaypoint = false;
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(collectedVehicle.Vehicle, 0f, 1, true);
}
if (directOptions.SelectedItem == "First waypoint")
{
GameFiber.StartNew(() =>
{
AITasking.AssignWaypointTasks(collectedVehicle, waypoints, firstWaypoint);
AITasking.AssignWaypointTasks(collectedVehicle, path, firstWaypoint);
});
}
else
@ -291,7 +276,7 @@ namespace SceneManager
{
GameFiber.StartNew(() =>
{
AITasking.AssignWaypointTasks(collectedVehicle, waypoints, nearestWaypoint);
AITasking.AssignWaypointTasks(collectedVehicle, path, nearestWaypoint);
});
}
}

View file

@ -14,6 +14,7 @@ namespace SceneManager
internal bool Dismissed { get; set; } = false;
internal bool Directed { get; set; } = false;
internal bool SkipWaypoint { get; set; } = false;
internal bool ReadyForDirectTasks { get; set; } = false;
internal CollectedVehicle(Vehicle vehicle, Path path, Waypoint currentWaypoint)
{
@ -52,14 +53,16 @@ namespace SceneManager
return;
}
Driver.Tasks.Clear();
if(StoppedAtWaypoint)
{
Logger.Log($"Unstucking {Vehicle.Model.Name}");
StoppedAtWaypoint = false;
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
Driver.Tasks.CruiseWithVehicle(5f);
}
Driver.Tasks.Clear();
if(dismissOption == DismissOption.FromWaypoint)
if (dismissOption == DismissOption.FromWaypoint)
{
DismissFromWaypoint();
}
@ -69,6 +72,11 @@ namespace SceneManager
DismissFromPath();
}
if(dismissOption == DismissOption.FromDirect)
{
DismissFromDirect();
}
void DismissFromWorld()
{
Game.LogTrivial($"Dismissed {Vehicle.Model.Name} from the world");
@ -105,12 +113,64 @@ namespace SceneManager
{
Logger.Log($"Dismissing from path");
Dismissed = true;
// Check if the vehicle is near any of the path's collector waypoints
GameFiber.StartNew(() =>
{
// check if the vehicle is near any of the path's collector waypoints
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => Vehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
if(nearestCollectorWaypoint != null)
if (nearestCollectorWaypoint != null)
{
// Enabling this will keep the menu, but the dismissed vehicle is immediately re - collected
while (nearestCollectorWaypoint != null && Vehicle && Vehicle.HasDriver && Driver && Driver.IsAlive && Vehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
{
//Game.LogTrivial($"{Vehicle.Model.Name} is within 2x collector radius, cannot be fully dismissed yet.");
GameFiber.Yield();
}
}
else
{
Logger.Log($"Nearest collector is null");
}
if (!Vehicle || !Driver)
{
return;
}
if (!Directed)
{
VehicleCollector.collectedVehicles.Remove(this);
Logger.Log($"{Vehicle.Model.Name} dismissed successfully.");
if (Driver)
{
if (Driver.GetAttachedBlip())
{
Driver.GetAttachedBlip().Delete();
}
Driver.BlockPermanentEvents = false;
Driver.Dismiss();
}
if (Vehicle)
{
Vehicle.IsSirenOn = false;
Vehicle.IsSirenSilent = true;
Vehicle.Dismiss();
}
}
});
}
void DismissFromDirect()
{
Logger.Log($"Dismissing from direct.");
ReadyForDirectTasks = false;
GameFiber.StartNew(() =>
{
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => Vehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
if (nearestCollectorWaypoint != null)
{
// Enabling this will keep the menu, but the dismissed vehicle is immediately re - collected
while (nearestCollectorWaypoint != null && Vehicle && Driver && Vehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
{
//Game.LogTrivial($"{Vehicle.Model.Name} is within 2x collector radius, cannot be fully dismissed yet.");
@ -122,23 +182,7 @@ namespace SceneManager
Logger.Log($"Nearest collector is null");
}
if (!Vehicle || !Driver)
{
return;
}
VehicleCollector.collectedVehicles.Remove(this);
Logger.Log($"{Vehicle.Model.Name} dismissed successfully.");
if (Driver.GetAttachedBlip())
{
Driver.GetAttachedBlip().Delete();
}
Driver.BlockPermanentEvents = false;
Driver.Dismiss();
Vehicle.IsSirenOn = false;
Vehicle.IsSirenSilent = true;
Vehicle.Dismiss();
ReadyForDirectTasks = true;
});
}
}