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

Refactored variable/object references to reflect changes in path creation/edit waypoint menus.

This commit is contained in:
Rich Dunne 2020-10-10 15:52:48 -06:00
parent 526ff83f90
commit d36c7fb012
4 changed files with 42 additions and 38 deletions

View file

@ -29,7 +29,7 @@ namespace SceneManager
Logger.Log($"{collectedVehicle.Vehicle.Model.Name} directed task is complete, directed is now false"); Logger.Log($"{collectedVehicle.Vehicle.Model.Name} directed task is complete, directed is now false");
} }
if (currentWaypoint.DrivingFlag == VehicleDrivingFlags.StopAtDestination) if (currentWaypoint.IsStopWaypoint)
{ {
StopVehicleAtWaypoint(currentWaypoint, collectedVehicle); StopVehicleAtWaypoint(currentWaypoint, collectedVehicle);
} }
@ -58,14 +58,15 @@ namespace SceneManager
Logger.Log($"{collectedVehicle.Vehicle.Model.Name} is driving to path {currentWaypoint.Path.Number} waypoint {currentWaypoint.Number} (directed)"); Logger.Log($"{collectedVehicle.Vehicle.Model.Name} is driving to path {currentWaypoint.Path.Number} waypoint {currentWaypoint.Number} (directed)");
Logger.Log($"{collectedVehicle.Vehicle.Model.Name} Dismissed: {collectedVehicle.Dismissed}, Directed: {collectedVehicle.SkipWaypoint}"); Logger.Log($"{collectedVehicle.Vehicle.Model.Name} Dismissed: {collectedVehicle.Dismissed}, Directed: {collectedVehicle.SkipWaypoint}");
if (currentWaypoint.DrivingFlag == VehicleDrivingFlags.IgnorePathFinding) collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, currentWaypoint.DrivingFlag, acceptedDistance);
{ //if (currentWaypoint.DrivingFlag == VehicleDrivingFlags.IgnorePathFinding)
collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)17040299, acceptedDistance); //{
} // collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)17040299, acceptedDistance);
else //}
{ //else
collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)263075, acceptedDistance); //{
} // collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)263075, acceptedDistance);
//}
} }
void LoopWhileDrivingToDirectedWaypoint(float acceptedDistance) void LoopWhileDrivingToDirectedWaypoint(float acceptedDistance)
@ -111,16 +112,9 @@ namespace SceneManager
//Logger.Log($"{collectedVehicle.Vehicle.Model.Name} current waypoint: {collectedVehicle.CurrentWaypoint.Number}"); //Logger.Log($"{collectedVehicle.Vehicle.Model.Name} current waypoint: {collectedVehicle.CurrentWaypoint.Number}");
float acceptedDistance = GetAcceptedStoppingDistance(path.Waypoints, currentWaypointTask); float acceptedDistance = GetAcceptedStoppingDistance(path.Waypoints, currentWaypointTask);
Logger.Log($"{vehicle.Model.Name} is driving to path {currentWaypoint.Path.Number} waypoint {path.Waypoints[currentWaypointTask].Number}"); Logger.Log($"{vehicle.Model.Name} is driving to path {currentWaypoint.Path.Number} waypoint {path.Waypoints[currentWaypointTask].Number} (Stop: {currentWaypoint.IsStopWaypoint}, Driving flag: {(DrivingFlagType)currentWaypoint.DrivingFlag})");
Logger.Log($"{vehicle.Model.Name} driver is persistent: {driver.IsPersistent}"); Logger.Log($"{vehicle.Model.Name} driver is persistent: {driver.IsPersistent}");
if (path.Waypoints[currentWaypointTask].DrivingFlag == VehicleDrivingFlags.IgnorePathFinding) driver.Tasks.DriveToPosition(path.Waypoints[currentWaypointTask].Position, path.Waypoints[currentWaypointTask].Speed, path.Waypoints[currentWaypointTask].DrivingFlag, acceptedDistance);
{
driver.Tasks.DriveToPosition(path.Waypoints[currentWaypointTask].Position, path.Waypoints[currentWaypointTask].Speed, (VehicleDrivingFlags)17040299, acceptedDistance);
}
else
{
driver.Tasks.DriveToPosition(path.Waypoints[currentWaypointTask].Position, path.Waypoints[currentWaypointTask].Speed, (VehicleDrivingFlags)263075, acceptedDistance);
}
LoopWhileDrivingToWaypoint(currentWaypointTask, acceptedDistance); LoopWhileDrivingToWaypoint(currentWaypointTask, acceptedDistance);
if (!VehicleAndDriverAreValid(collectedVehicle)) if (!VehicleAndDriverAreValid(collectedVehicle))
@ -134,7 +128,7 @@ namespace SceneManager
continue; continue;
} }
if (!collectedVehicle.Dismissed && path.Waypoints.ElementAtOrDefault(currentWaypointTask) != null && path.Waypoints[currentWaypointTask].DrivingFlag == VehicleDrivingFlags.StopAtDestination) if (!collectedVehicle.Dismissed && path.Waypoints.ElementAtOrDefault(currentWaypointTask) != null && path.Waypoints[currentWaypointTask].IsStopWaypoint)
{ {
StopVehicleAtWaypoint(path.Waypoints[currentWaypointTask], collectedVehicle); StopVehicleAtWaypoint(path.Waypoints[currentWaypointTask], collectedVehicle);
} }
@ -157,6 +151,7 @@ namespace SceneManager
{ {
while (VehicleAndDriverAreValid(collectedVehicle) && !collectedVehicle.Dismissed && !collectedVehicle.SkipWaypoint && path.Waypoints.ElementAtOrDefault(nextWaypoint) != null && collectedVehicle.Vehicle.FrontPosition.DistanceTo2D(path.Waypoints[nextWaypoint].Position) > acceptedDistance) while (VehicleAndDriverAreValid(collectedVehicle) && !collectedVehicle.Dismissed && !collectedVehicle.SkipWaypoint && path.Waypoints.ElementAtOrDefault(nextWaypoint) != null && collectedVehicle.Vehicle.FrontPosition.DistanceTo2D(path.Waypoints[nextWaypoint].Position) > acceptedDistance)
{ {
//Logger.Log($"Looping while {vehicle.Model.Name} drives to waypoint.");
GameFiber.Sleep(100); GameFiber.Sleep(100);
} }
} }

View file

@ -348,13 +348,13 @@ namespace SceneManager
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.collectorRadius.Value * 2, (float)PathCreationMenu.collectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.collectorRadius.Value * 2, (float)PathCreationMenu.collectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false);
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.speedZoneRadius.Value * 2, (float)PathCreationMenu.speedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.speedZoneRadius.Value * 2, (float)PathCreationMenu.speedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false);
} }
else if (PathCreationMenu.waypointType.SelectedItem.Contains("Drive To")) else if (PathCreationMenu.stopWaypointType.Checked)
{ {
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false);
} }
else else
{ {
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false);
} }
} }
else else

View file

@ -86,7 +86,7 @@ namespace SceneManager
{ {
if (i != Waypoints.Count - 1) if (i != Waypoints.Count - 1)
{ {
if (Waypoints[i + 1].DrivingFlag == VehicleDrivingFlags.StopAtDestination) if (Waypoints[i + 1].IsStopWaypoint)
{ {
Debug.DrawLine(Waypoints[i].Position, Waypoints[i + 1].Position, Color.Orange); Debug.DrawLine(Waypoints[i].Position, Waypoints[i + 1].Position, Color.Orange);
} }
@ -101,7 +101,5 @@ namespace SceneManager
} }
}); });
} }
} }
} }

View file

@ -4,6 +4,12 @@ using System.Linq;
namespace SceneManager namespace SceneManager
{ {
public enum DrivingFlagType
{
Normal = 263075,
Direct = 17040299
}
public class Waypoint public class Waypoint
{ {
internal Path Path { get; set; } internal Path Path { get; set; }
@ -11,6 +17,8 @@ namespace SceneManager
internal Vector3 Position { get; set; } internal Vector3 Position { get; set; }
internal float Speed { get; set; } internal float Speed { get; set; }
internal VehicleDrivingFlags DrivingFlag { get; set; } internal VehicleDrivingFlags DrivingFlag { get; set; }
internal DrivingFlagType DrivingFlagType { get; private set; }
internal bool IsStopWaypoint { get; set; }
internal Blip Blip { get; } internal Blip Blip { get; }
internal bool IsCollector { get; set; } internal bool IsCollector { get; set; }
internal float CollectorRadius { get; set; } internal float CollectorRadius { get; set; }
@ -20,13 +28,15 @@ namespace SceneManager
internal bool EnableWaypointMarker { get; set; } = true; internal bool EnableWaypointMarker { get; set; } = true;
internal bool EnableEditMarker { get; set; } internal bool EnableEditMarker { get; set; }
internal Waypoint(Path path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector = false, float collectorRadius = 1, float speedZoneRadius = 5) internal Waypoint(Path path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, bool stopWaypoint, Blip waypointBlip, bool collector = false, float collectorRadius = 1, float speedZoneRadius = 5)
{ {
Path = path; Path = path;
Number = waypointNum; Number = waypointNum;
Position = waypointPos; Position = waypointPos;
Speed = speed; Speed = speed;
DrivingFlag = drivingFlag; DrivingFlag = drivingFlag;
DrivingFlagType = (DrivingFlagType)DrivingFlag;
IsStopWaypoint = stopWaypoint;
Blip = waypointBlip; Blip = waypointBlip;
IsCollector = collector; IsCollector = collector;
CollectorRadius = collectorRadius; CollectorRadius = collectorRadius;
@ -50,9 +60,13 @@ namespace SceneManager
DrawWaypointMarker(); DrawWaypointMarker();
} }
internal void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float speed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked) internal void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, bool stopWaypoint, float speed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked)
{ {
UpdateDrivingFlag(drivingFlag); if(IsStopWaypoint != stopWaypoint)
{
UpdateIfStopWaypoint();
}
DrivingFlag = drivingFlag;
UpdateWaypointSpeed(speed); UpdateWaypointSpeed(speed);
UpdateCollectorOptions(); UpdateCollectorOptions();
if (updateWaypointPositionChecked) if (updateWaypointPositionChecked)
@ -60,25 +74,22 @@ namespace SceneManager
UpdateWaypointPosition(Game.LocalPlayer.Character.Position); UpdateWaypointPosition(Game.LocalPlayer.Character.Position);
} }
void UpdateDrivingFlag(VehicleDrivingFlags newDrivingFlag) void UpdateIfStopWaypoint()
{ {
if(DrivingFlag == VehicleDrivingFlags.StopAtDestination && newDrivingFlag != VehicleDrivingFlags.StopAtDestination) if (IsStopWaypoint && !stopWaypoint)
{ {
Blip.Color = Color.Green;
foreach(CollectedVehicle cv in VehicleCollector.collectedVehicles.Where(cv => cv.Vehicle && cv.Path == Path && cv.CurrentWaypoint == this && cv.StoppedAtWaypoint)) foreach(CollectedVehicle cv in VehicleCollector.collectedVehicles.Where(cv => cv.Vehicle && cv.Path == Path && cv.CurrentWaypoint == this && cv.StoppedAtWaypoint))
{ {
Logger.Log($"Setting StoppedAtWaypoint to false for {cv.Vehicle.Model.Name}"); Logger.Log($"Setting StoppedAtWaypoint to false for {cv.Vehicle.Model.Name}");
cv.Dismiss(DismissOption.FromWaypoint); cv.Dismiss(DismissOption.FromWaypoint);
} }
} }
DrivingFlag = newDrivingFlag; else if(!IsStopWaypoint && stopWaypoint)
if (newDrivingFlag == VehicleDrivingFlags.StopAtDestination)
{ {
Blip.Color = Color.Red; Blip.Color = Color.Red;
} }
else IsStopWaypoint = stopWaypoint;
{
Blip.Color = Color.Green;
}
} }
void UpdateWaypointSpeed(float newWaypointSpeed) void UpdateWaypointSpeed(float newWaypointSpeed)
@ -184,7 +195,7 @@ namespace SceneManager
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 2f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 2f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 2f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 2f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
} }
else if (EditWaypointMenu.changeWaypointType.SelectedItem == "Stop") else if (EditWaypointMenu.stopWaypointType.Checked)
{ {
if (EditWaypointMenu.updateWaypointPosition.Checked) if (EditWaypointMenu.updateWaypointPosition.Checked)
{ {
@ -213,7 +224,7 @@ namespace SceneManager
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, CollectorRadius * 2, CollectorRadius * 2, markerHeight, 80, 130, 255, 100, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, CollectorRadius * 2, CollectorRadius * 2, markerHeight, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, SpeedZoneRadius * 2, SpeedZoneRadius * 2, markerHeight, 255, 185, 80, 100, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, SpeedZoneRadius * 2, SpeedZoneRadius * 2, markerHeight, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
} }
else if (DrivingFlag == VehicleDrivingFlags.StopAtDestination) else if (IsStopWaypoint)
{ {
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 255, 65, 65, 100, false, false, 2, false, 0, 0, false); Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
} }