diff --git a/SceneManager/DebugGraphics.cs b/SceneManager/DebugGraphics.cs index ee97d0c..dbd1d4d 100644 --- a/SceneManager/DebugGraphics.cs +++ b/SceneManager/DebugGraphics.cs @@ -10,11 +10,11 @@ namespace SceneManager { while (debugGraphics.Checked && path != null) { - for (int i = 0; i < path.Waypoint.Count; i++) + for (int i = 0; i < path.Waypoints.Count; i++) { DrawSpheresAtWaypoints(path, i); - if (i != path.Waypoint.Count - 1) + if (i != path.Waypoints.Count - 1) { DrawLinesBetweenWaypoints(path, i); } @@ -25,29 +25,29 @@ namespace SceneManager public static void DrawLinesBetweenWaypoints(Path path, int i) { - if (path.Waypoint[i + 1].DrivingFlag == VehicleDrivingFlags.StopAtDestination) + if (path.Waypoints[i + 1].DrivingFlag == VehicleDrivingFlags.StopAtDestination) { - Debug.DrawLine(path.Waypoint[i].Position, path.Waypoint[i + 1].Position, Color.Orange); + Debug.DrawLine(path.Waypoints[i].Position, path.Waypoints[i + 1].Position, Color.Orange); } else { - Debug.DrawLine(path.Waypoint[i].Position, path.Waypoint[i + 1].Position, Color.Green); + Debug.DrawLine(path.Waypoints[i].Position, path.Waypoints[i + 1].Position, Color.Green); } } public static void DrawSpheresAtWaypoints(Path path, int i) { - if (path.Waypoint[i].Collector) + if (path.Waypoints[i].Collector) { - Debug.DrawSphere(path.Waypoint[i].Position, path.Waypoint[i].CollectorRadius, Color.FromArgb(80, Color.Blue)); + Debug.DrawSphere(path.Waypoints[i].Position, path.Waypoints[i].CollectorRadius, Color.FromArgb(80, Color.Blue)); } - else if (path.Waypoint[i].DrivingFlag == VehicleDrivingFlags.StopAtDestination) + else if (path.Waypoints[i].DrivingFlag == VehicleDrivingFlags.StopAtDestination) { - Debug.DrawSphere(path.Waypoint[i].Position, 1f, Color.FromArgb(80, Color.Red)); + Debug.DrawSphere(path.Waypoints[i].Position, 1f, Color.FromArgb(80, Color.Red)); } else { - Debug.DrawSphere(path.Waypoint[i].Position, 1f, Color.FromArgb(80, Color.Green)); + Debug.DrawSphere(path.Waypoints[i].Position, 1f, Color.FromArgb(80, Color.Green)); } } } diff --git a/SceneManager/Menus/PathCreationMenu.cs b/SceneManager/Menus/PathCreationMenu.cs index 0a86f93..7a74059 100644 --- a/SceneManager/Menus/PathCreationMenu.cs +++ b/SceneManager/Menus/PathCreationMenu.cs @@ -47,7 +47,7 @@ namespace SceneManager var firstNonNullPath = TrafficMenu.paths.Where(p => p != null && !p.PathFinished).First(); var pathIndex = TrafficMenu.paths.IndexOf(firstNonNullPath); var currentPath = pathIndex + 1; - var currentWaypoint = TrafficMenu.paths[pathIndex].Waypoint.Count + 1; + var currentWaypoint = TrafficMenu.paths[pathIndex].Waypoints.Count + 1; var drivingFlag = drivingFlags[waypointType.Index]; var blip = CreateWaypointBlip(pathIndex); @@ -57,11 +57,11 @@ namespace SceneManager ? (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index])) : (uint)World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeeds[waypointSpeed.Index])); - TrafficMenu.paths[pathIndex].Waypoint.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadii[collectorRadius.Index], yieldZone)); + TrafficMenu.paths[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadii[collectorRadius.Index], yieldZone)); } else { - TrafficMenu.paths[pathIndex].Waypoint.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip)); + TrafficMenu.paths[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip)); } Game.LogTrivial($"[Path {currentPath}] Waypoint {currentWaypoint} ({drivingFlag.ToString()}) added"); @@ -76,16 +76,16 @@ namespace SceneManager { if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !TrafficMenu.paths[i].PathFinished) { - Game.LogTrivial($"[Path {i + 1}] {TrafficMenu.paths[i].Waypoint.Last().DrivingFlag.ToString()} waypoint removed"); - TrafficMenu.paths[i].Waypoint.Last().Blip.Delete(); - if (TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip) + Game.LogTrivial($"[Path {i + 1}] {TrafficMenu.paths[i].Waypoints.Last().DrivingFlag.ToString()} waypoint removed"); + TrafficMenu.paths[i].Waypoints.Last().Blip.Delete(); + if (TrafficMenu.paths[i].Waypoints.Last().CollectorRadiusBlip) { - TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip.Delete(); + TrafficMenu.paths[i].Waypoints.Last().CollectorRadiusBlip.Delete(); } - TrafficMenu.paths[i].Waypoint.RemoveAt(TrafficMenu.paths[i].Waypoint.IndexOf(TrafficMenu.paths[i].Waypoint.Last())); + TrafficMenu.paths[i].Waypoints.RemoveAt(TrafficMenu.paths[i].Waypoints.IndexOf(TrafficMenu.paths[i].Waypoints.Last())); // If the path has no waypoints, disable the menu option to remove a waypoint - if (TrafficMenu.paths[i].Waypoint.Count == 0) + if (TrafficMenu.paths[i].Waypoints.Count == 0) { trafficRemoveWaypoint.Enabled = false; } @@ -98,28 +98,29 @@ namespace SceneManager // Loop through each path and find the first one which isn't finished for (int i = 0; i < TrafficMenu.paths.Count; i++) { - if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !TrafficMenu.paths[i].PathFinished) + var currentPath = TrafficMenu.paths[i]; + if (TrafficMenu.paths.ElementAtOrDefault(i) != null && !currentPath.PathFinished) { // If the path has one stop waypoint or at least two waypoints, finish the path and start the vehicle collector loop, else show user the error and delete any waypoints they made and clear the invalid path - if (TrafficMenu.paths[i].Waypoint.Count >= 2 || (TrafficMenu.paths[i].Waypoint.Count == 1 && TrafficMenu.paths[i].Waypoint[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination)) + if (currentPath.Waypoints.Count >= 2 || (currentPath.Waypoints.Count == 1 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination)) { - Game.LogTrivial($"[Path Creation] Path {i + 1} finished with {TrafficMenu.paths[i].Waypoint.Count} waypoints."); + Game.LogTrivial($"[Path Creation] Path {i + 1} finished with {currentPath.Waypoints.Count} waypoints."); Game.DisplayNotification($"~o~Scene Manager\n~g~[Success]~w~ Path {i + 1} complete."); - TrafficMenu.paths[i].Waypoint.Last().Blip.Color = Color.OrangeRed; - if (TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip) + currentPath.Waypoints.Last().Blip.Color = Color.OrangeRed; + if (currentPath.Waypoints.Last().CollectorRadiusBlip) { - TrafficMenu.paths[i].Waypoint.Last().CollectorRadiusBlip.Color = Color.OrangeRed; + currentPath.Waypoints.Last().CollectorRadiusBlip.Color = Color.OrangeRed; } - TrafficMenu.paths[i].PathFinished = true; - TrafficMenu.paths[i].PathDisabled = false; - TrafficMenu.paths[i].PathNum = i + 1; - TrafficMenu.pathsNum.Insert(i, TrafficMenu.paths[i].PathNum); + currentPath.FinishPath(); + currentPath.EnablePath(); + currentPath.SetPathNumber(i + 1); + TrafficMenu.pathsNum.Insert(i, currentPath.PathNum); //GameFiber InitialWaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.InitialWaypointVehicleCollector(paths[i])); //InitialWaypointVehicleCollectorFiber.Start(); // For each waypoint in the path's WaypointData, start a collector game fiber and loop while the path and waypoint exist, and while the path is enabled - foreach (Waypoint wd in TrafficMenu.paths[i].Waypoint) + foreach (Waypoint wd in TrafficMenu.paths[i].Waypoints) { GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => TrafficPathing.WaypointVehicleCollector(TrafficMenu.paths, TrafficMenu.paths[i], wd)); WaypointVehicleCollectorFiber.Start(); @@ -138,7 +139,7 @@ namespace SceneManager { Game.LogTrivial($"[Path Error] A minimum of 2 waypoints is required."); Game.DisplayNotification($"~o~Scene Manager\n~r~[Error]~w~ A minimum of 2 waypoints or one stop waypoint is required to create a path."); - foreach (Waypoint wp in TrafficMenu.paths[i].Waypoint) + foreach (Waypoint wp in TrafficMenu.paths[i].Waypoints) { wp.Blip.Delete(); if (wp.CollectorRadiusBlip) @@ -146,7 +147,7 @@ namespace SceneManager wp.CollectorRadiusBlip.Delete(); } } - TrafficMenu.paths[i].Waypoint.Clear(); + TrafficMenu.paths[i].Waypoints.Clear(); TrafficMenu.paths.RemoveAt(i); break; } @@ -186,7 +187,7 @@ namespace SceneManager Sprite = (BlipSprite)spriteNumericalEnum }; - if (TrafficMenu.paths[pathIndex].Waypoint.Count == 0) + if (TrafficMenu.paths[pathIndex].Waypoints.Count == 0) { blip.Color = Color.Orange; } diff --git a/SceneManager/Menus/TrafficMenu.cs b/SceneManager/Menus/TrafficMenu.cs index e0eb6e0..5315522 100644 --- a/SceneManager/Menus/TrafficMenu.cs +++ b/SceneManager/Menus/TrafficMenu.cs @@ -103,7 +103,7 @@ namespace SceneManager // Remove the speed zone so cars don't continue to be affected after the path is deleted Game.LogTrivial($"Removing yield zone and waypoint blips"); - foreach (Waypoint wp in path.Waypoint) + foreach (Waypoint wp in path.Waypoints) { if (wp.YieldZone != 0) { @@ -120,7 +120,7 @@ namespace SceneManager } Game.LogTrivial($"Clearing path.WaypointData"); - path.Waypoint.Clear(); + path.Waypoints.Clear(); // Manipulating the menu to reflect specific paths being deleted if (pathsToDelete == "Single") { @@ -190,7 +190,7 @@ namespace SceneManager } foreach (Path path in paths) { - path.Waypoint.Clear(); + path.Waypoints.Clear(); } paths.Clear(); pathsNum.Clear(); @@ -209,24 +209,25 @@ namespace SceneManager if (nearbyVehicle.IsInCollectedVehicles()) { var vehicle = TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate]; + var nearestWaypoint = paths[directDriver.Index].Waypoints.OrderBy(wp => wp.Position).Take(1) as Waypoint; Game.LogTrivial($"[Direct Driver] {nearbyVehicle.Model.Name} already in collection. Clearing tasks."); nearbyVehicle.Driver.Tasks.Clear(); - vehicle.Path = paths[directDriver.Index].Waypoint[0].Path; - vehicle.TotalWaypoints = paths[directDriver.Index].Waypoint.Count; + vehicle.Path = paths[directDriver.Index].Waypoints[0].Path; + vehicle.TotalWaypoints = paths[directDriver.Index].Waypoints.Count; vehicle.CurrentWaypoint = 1; vehicle.DismissNow = true; vehicle.StoppedAtWaypoint = false; vehicle.Redirected = true; - GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(vehicle, paths[directDriver.Index].Waypoint)); + GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(vehicle, paths[directDriver.Index].Waypoints)); DirectTaskFiber.Start(); } else { - TrafficPathing.collectedVehicles.Add(nearbyVehicle.LicensePlate, new CollectedVehicle(nearbyVehicle, nearbyVehicle.LicensePlate, paths[directDriver.Index].Waypoint[0].Path, paths[directDriver.Index].Waypoint.Count, 1, false, false, true)); - Game.LogTrivial($"[Direct Driver] {nearbyVehicle.Model.Name} not in collection, adding to collection for path {paths[directDriver.Index].Waypoint[0].Path} with {paths[directDriver.Index].Waypoint.Count} waypoints"); + TrafficPathing.collectedVehicles.Add(nearbyVehicle.LicensePlate, new CollectedVehicle(nearbyVehicle, nearbyVehicle.LicensePlate, paths[directDriver.Index].Waypoints[0].Path, paths[directDriver.Index].Waypoints.Count, 1, false, false, true)); + Game.LogTrivial($"[Direct Driver] {nearbyVehicle.Model.Name} not in collection, adding to collection for path {paths[directDriver.Index].Waypoints[0].Path} with {paths[directDriver.Index].Waypoints.Count} waypoints"); - GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate], paths[directDriver.Index].Waypoint)); + GameFiber DirectTaskFiber = new GameFiber(() => TrafficPathing.DirectTask(TrafficPathing.collectedVehicles[nearbyVehicle.LicensePlate], paths[directDriver.Index].Waypoints)); DirectTaskFiber.Start(); } } @@ -316,8 +317,8 @@ namespace SceneManager { foreach (Path path in paths) { - path.PathDisabled = true; - foreach (Waypoint waypoint in path.Waypoint) + path.DisablePath(); + foreach (Waypoint waypoint in path.Waypoints) { waypoint.Blip.Alpha = 0.5f; if (waypoint.CollectorRadiusBlip) @@ -332,8 +333,8 @@ namespace SceneManager { foreach (Path path in paths) { - path.PathDisabled = false; - foreach (Waypoint waypoint in path.Waypoint) + path.EnablePath(); + foreach (Waypoint waypoint in path.Waypoints) { waypoint.Blip.Alpha = 1f; if (waypoint.CollectorRadiusBlip) diff --git a/SceneManager/TrafficPathing.cs b/SceneManager/TrafficPathing.cs index fd9a5df..011a7c7 100644 --- a/SceneManager/TrafficPathing.cs +++ b/SceneManager/TrafficPathing.cs @@ -15,7 +15,7 @@ namespace SceneManager //GameFiber AssignStopForVehiclesFlagFiber = new GameFiber(() => AssignStopForVehiclesFlag(paths, path, waypointData)); //AssignStopForVehiclesFlagFiber.Start(); - while (paths.Contains(path) && path.Waypoint.Contains(waypoint)) + while (paths.Contains(path) && path.Waypoints.Contains(waypoint)) { if (!path.PathDisabled && waypoint.Collector) { @@ -29,14 +29,14 @@ namespace SceneManager // If the vehicle is not in the collection yet if (!collectedVehicles.ContainsKey(v.LicensePlate)) { - var collectedVehicle = new CollectedVehicle(v, v.LicensePlate, path.PathNum, path.Waypoint.Count, waypoint.Number, true, false, false); + var collectedVehicle = new CollectedVehicle(v, v.LicensePlate, path.PathNum, path.Waypoints.Count, waypoint.Number, true, false, false); collectedVehicles.Add(v.LicensePlate, collectedVehicle); Game.LogTrivial($"[WaypointVehicleCollector] Added {v.Model.Name} to collection from path {path.PathNum}, waypoint {waypoint.Number}."); - GameFiber DismissCheckFiber = new GameFiber(() => VehicleDismissed(collectedVehicle, path.Waypoint)); + GameFiber DismissCheckFiber = new GameFiber(() => VehicleDismissed(collectedVehicle, path.Waypoints)); DismissCheckFiber.Start(); - AssignTasks(collectedVehicle, path.Waypoint, waypoint); + AssignTasks(collectedVehicle, path.Waypoints, waypoint); } // If the vehicle is in the collection, but has no tasks else if (collectedVehicles.ContainsKey(v.LicensePlate) && !collectedVehicles[v.LicensePlate].TasksAssigned) @@ -44,7 +44,7 @@ namespace SceneManager Game.LogTrivial($"[WaypointVehicleCollector] {v.Model.Name} already in collection, but with no tasks. Assigning tasks."); collectedVehicles[v.LicensePlate].TasksAssigned = true; - AssignTasks(collectedVehicles[v.LicensePlate], path.Waypoint, waypoint); + AssignTasks(collectedVehicles[v.LicensePlate], path.Waypoints, waypoint); } // If the vehicle is in the collection and has tasks else @@ -201,7 +201,7 @@ namespace SceneManager public static void AssignStopForVehiclesFlag(List paths, Path path, Waypoint waypointData) { - while (paths.Contains(path) && path.Waypoint.Contains(waypointData)) + while (paths.Contains(path) && path.Waypoints.Contains(waypointData)) { if (!path.PathDisabled) { @@ -214,7 +214,7 @@ namespace SceneManager } } - public static void DirectTask(CollectedVehicle cv, List waypointData) + public static void DirectTask(CollectedVehicle cv, List waypoints) { cv.DismissNow = false; if (cv.Vehicle && cv.Vehicle.Driver) @@ -227,10 +227,10 @@ namespace SceneManager // Give vehicle task to initial waypoint of desired path, then run a loop to keep giving the task until they're close enough in case they try to wander away too early // Need to figure out how to only get waypoints which are in front of or within 90 degrees of either side of the vehicle - var nearestWaypoint = waypointData.OrderBy(wp => wp.Position).Take(1) as Waypoint; + var nearestWaypoint = waypoints.OrderBy(wp => wp.Position).Take(1) as Waypoint; cv.Vehicle.Driver.Tasks.DriveToPosition(nearestWaypoint.Position, nearestWaypoint.Speed, (VehicleDrivingFlags)262539, 1f); // waypointData[0].WaypointPos - while (waypointData.ElementAtOrDefault(0) != null && cv.Vehicle && cv.Vehicle.Driver && cv.Vehicle.DistanceTo(waypointData[0].Position) > 3f && !cv.DismissNow) + while (nearestWaypoint != null && cv.Vehicle && cv.Vehicle.Driver && cv.Vehicle.DistanceTo(waypoints[0].Position) > 3f && !cv.DismissNow) { cv.Vehicle.Driver.Tasks.DriveToPosition(nearestWaypoint.Position, nearestWaypoint.Speed, (VehicleDrivingFlags)262539, 1f); GameFiber.Sleep(500);