From 54c2bd8c1247da285f42889efe33a95f437aa3c3 Mon Sep 17 00:00:00 2001 From: Rich Dunne Date: Sun, 30 Aug 2020 10:05:58 -0600 Subject: [PATCH] Added separate menu option for collector waypoint speed zone. --- SceneManager/Menus/EditWaypointMenu.cs | 17 ++++++++++--- SceneManager/Menus/PathCreationMenu.cs | 27 +++++++++----------- SceneManager/Object Classes/Waypoint.cs | 33 +++++++++++++++++++++---- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/SceneManager/Menus/EditWaypointMenu.cs b/SceneManager/Menus/EditWaypointMenu.cs index 7dc3d72..780e8b7 100644 --- a/SceneManager/Menus/EditWaypointMenu.cs +++ b/SceneManager/Menus/EditWaypointMenu.cs @@ -18,8 +18,9 @@ namespace SceneManager public static UIMenuNumericScrollerItem editWaypoint; private static UIMenuListScrollerItem changeWaypointType = new UIMenuListScrollerItem("New Waypoint Type", "", waypointTypes); private static UIMenuNumericScrollerItem changeWaypointSpeed; - private static UIMenuNumericScrollerItem changeCollectorRadius = new UIMenuNumericScrollerItem("New Collection Radius", "The distance from this waypoint in meters vehicles will be collected", 1, 50, 1); private static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path"); + private static UIMenuNumericScrollerItem changeCollectorRadius = new UIMenuNumericScrollerItem("New Collection Radius", "The distance from this waypoint (in meters) vehicles will be collected", 1, 50, 1); + private static UIMenuNumericScrollerItem changeSpeedZoneRadius = new UIMenuNumericScrollerItem("New Speed Zone Radius", "The distance from this collector waypoint (in meters) non-collected vehicles will drive at this waypoint's speed", 1, 50, 1); private static UIMenuCheckboxItem updateWaypointPosition; internal static void InstantiateMenu() @@ -47,7 +48,6 @@ namespace SceneManager editWaypointMenu.AddItem(changeWaypointType); changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag); - //Game.LogTrivial($"Waypoint speed: {PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed}"); editWaypointMenu.AddItem(changeWaypointSpeed = new UIMenuNumericScrollerItem("New Waypoint Speed", $"How fast the AI will drive to the waypoint in ~b~{SettingsMenu.speedUnits.SelectedItem}", 5, 80, 5)); changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed); @@ -58,6 +58,14 @@ namespace SceneManager ? (int)PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].CollectorRadius : changeCollectorRadius.Minimum; + editWaypointMenu.AddItem(changeSpeedZoneRadius); + changeSpeedZoneRadius.Value = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].CollectorRadius != 0 + ? (int)PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].SpeedZoneRadius + : changeSpeedZoneRadius.Minimum; + + changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false; + changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false; + editWaypointMenu.AddItem(updateWaypointPosition = new UIMenuCheckboxItem("Update Waypoint Position", false)); editWaypointMenu.AddItem(editUpdateWaypoint = new UIMenuItem("Update Waypoint")); editUpdateWaypoint.ForeColor = Color.Gold; @@ -78,10 +86,10 @@ namespace SceneManager if(scrollerItem == editWaypoint) { changeWaypointType.Index = Array.IndexOf(drivingFlags, PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].DrivingFlag); - //changeWaypointSpeed.Index = Array.IndexOf(waypointSpeeds, MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed)); changeWaypointSpeed.Value = (int)MathHelper.ConvertMetersPerSecondToMilesPerHour(PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].Speed); collectorWaypoint.Checked = PathMainMenu.GetPaths()[PathMainMenu.editPath.Index].Waypoints[editWaypoint.Index].IsCollector; changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false; + changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false; } } @@ -90,6 +98,7 @@ namespace SceneManager if (checkboxItem == collectorWaypoint) { changeCollectorRadius.Enabled = collectorWaypoint.Checked ? true : false; + changeSpeedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false; } } @@ -100,7 +109,7 @@ namespace SceneManager if (selectedItem == editUpdateWaypoint) { - currentWaypoint.UpdateWaypoint(currentWaypoint, drivingFlags[changeWaypointType.Index], SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, updateWaypointPosition.Checked); + currentWaypoint.UpdateWaypoint(currentWaypoint, drivingFlags[changeWaypointType.Index], SetDriveSpeedForWaypoint(), collectorWaypoint.Checked, changeCollectorRadius.Value, changeSpeedZoneRadius.Value, updateWaypointPosition.Checked); Game.LogTrivial($"Updated path {currentPath.PathNum} waypoint {currentWaypoint.Number}: Driving flag is {drivingFlags[changeWaypointType.Index].ToString()}, speed is {changeWaypointSpeed.Value}, collector is {currentWaypoint.IsCollector}"); if (currentPath.Waypoints.Count < 2 && currentPath.Waypoints[0].DrivingFlag == VehicleDrivingFlags.StopAtDestination) diff --git a/SceneManager/Menus/PathCreationMenu.cs b/SceneManager/Menus/PathCreationMenu.cs index 244d889..8471681 100644 --- a/SceneManager/Menus/PathCreationMenu.cs +++ b/SceneManager/Menus/PathCreationMenu.cs @@ -16,8 +16,9 @@ namespace SceneManager private static UIMenuItem trafficAddWaypoint, trafficRemoveWaypoint, trafficEndPath; public static UIMenuListScrollerItem waypointType = new UIMenuListScrollerItem("Waypoint Type", "", waypointTypes); private static UIMenuNumericScrollerItem waypointSpeed; - public static UIMenuNumericScrollerItem collectorRadius = new UIMenuNumericScrollerItem("Collection Radius", "The distance from this waypoint in meters vehicles will be collected", 1, 50, 1); public static UIMenuCheckboxItem collectorWaypoint = new UIMenuCheckboxItem("Collector", true, "If this waypoint will collect vehicles to follow the path"); + public static UIMenuNumericScrollerItem collectorRadius = new UIMenuNumericScrollerItem("Collection Radius", "The distance from this waypoint (in meters) vehicles will be collected", 1, 50, 1); + public static UIMenuNumericScrollerItem speedZoneRadius = new UIMenuNumericScrollerItem("Speed Zone Radius", "The distance from this collector waypoint (in meters) non-collected vehicles will drive at this waypoint's speed", 1, 50, 1); internal static void InstantiateMenu() { @@ -34,6 +35,8 @@ namespace SceneManager pathCreationMenu.AddItem(collectorWaypoint); pathCreationMenu.AddItem(collectorRadius); collectorRadius.Index = 0; + pathCreationMenu.AddItem(speedZoneRadius); + speedZoneRadius.Index = 0; pathCreationMenu.AddItem(trafficAddWaypoint = new UIMenuItem("Add waypoint")); trafficAddWaypoint.ForeColor = Color.Gold; pathCreationMenu.AddItem(trafficRemoveWaypoint = new UIMenuItem("Remove last waypoint")); @@ -53,6 +56,7 @@ namespace SceneManager if(checkboxItem == collectorWaypoint) { collectorRadius.Enabled = collectorWaypoint.Checked ? true : false; + speedZoneRadius.Enabled = collectorWaypoint.Checked ? true : false; } } @@ -70,10 +74,7 @@ namespace SceneManager if (SettingsMenu.debugGraphics.Checked) { - GameFiber.StartNew(() => - { - DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths()[0]); - }); + DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths()[0]); } } else if(anyPathsExist && !PathMainMenu.GetPaths().Any(p => p != null && p.State == State.Creating)) @@ -82,10 +83,7 @@ namespace SceneManager if (SettingsMenu.debugGraphics.Checked) { - GameFiber.StartNew(() => - { - DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths().Where(p => p != null && p.State == State.Creating).First()); - }); + DebugGraphics.LoopToDrawDebugGraphics(SettingsMenu.debugGraphics, PathMainMenu.GetPaths().Where(p => p != null && p.State == State.Creating).First()); } } @@ -99,10 +97,9 @@ namespace SceneManager if (collectorWaypoint.Checked) { var yieldZone = SettingsMenu.speedUnits.SelectedItem == SettingsMenu.SpeedUnitsOfMeasure.MPH - ? World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeed.Value)) - : World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeed.Value)); - - PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadius.Value, yieldZone)); + ? World.AddSpeedZone(Game.LocalPlayer.Character.Position, speedZoneRadius.Value, MathHelper.ConvertMilesPerHourToMetersPerSecond(waypointSpeed.Value)) + : World.AddSpeedZone(Game.LocalPlayer.Character.Position, speedZoneRadius.Value, MathHelper.ConvertKilometersPerHourToMetersPerSecond(waypointSpeed.Value)); + PathMainMenu.GetPaths()[pathIndex].Waypoints.Add(new Waypoint(currentPath, currentWaypoint, Game.LocalPlayer.Character.Position, SetDriveSpeedForWaypoint(), drivingFlag, blip, true, collectorRadius.Value, speedZoneRadius.Value, yieldZone)); } else { @@ -166,9 +163,9 @@ namespace SceneManager PathMainMenu.AddPathToPathCountList(i, currentPath.PathNum); // 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 PathMainMenu.GetPaths()[i].Waypoints) + foreach (Waypoint waypoint in PathMainMenu.GetPaths()[i].Waypoints) { - GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], wd)); + GameFiber WaypointVehicleCollectorFiber = new GameFiber(() => VehicleCollector.StartCollectingAtWaypoint(PathMainMenu.GetPaths(), PathMainMenu.GetPaths()[i], waypoint)); WaypointVehicleCollectorFiber.Start(); } diff --git a/SceneManager/Object Classes/Waypoint.cs b/SceneManager/Object Classes/Waypoint.cs index 793a830..eac2f10 100644 --- a/SceneManager/Object Classes/Waypoint.cs +++ b/SceneManager/Object Classes/Waypoint.cs @@ -13,6 +13,7 @@ namespace SceneManager public uint YieldZone { get; private set; } public bool IsCollector { get; private set; } public float CollectorRadius { get; private set; } + public float SpeedZoneRadius { get; private set; } public Blip CollectorRadiusBlip { get; private set; } public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip) @@ -26,7 +27,7 @@ namespace SceneManager } - public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector, float collectorRadius, uint yieldZone) + public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector, float collectorRadius, float speedZoneRadius, uint yieldZone) { Path = path; Number = waypointNum; @@ -36,6 +37,7 @@ namespace SceneManager Blip = waypointBlip; IsCollector = collector; CollectorRadius = collectorRadius; + SpeedZoneRadius = speedZoneRadius; YieldZone = yieldZone; CollectorRadiusBlip = new Blip(waypointBlip.Position, collectorRadius) { @@ -44,24 +46,24 @@ namespace SceneManager }; } - public void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, bool updateWaypointPositionChecked) + public void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked) { UpdateDrivingFlag(drivingFlag); UpdateWaypointSpeed(drivingSpeed); - UpdateCollectorOptions(currentWaypoint, drivingSpeed, collectorWaypointChecked, collectorRadius); + UpdateCollectorOptions(currentWaypoint, drivingSpeed, collectorWaypointChecked, collectorRadius, speedZoneRadius); if (updateWaypointPositionChecked) { UpdateWaypointPosition(Game.LocalPlayer.Character.Position); } } - private void UpdateCollectorOptions(Waypoint currentWaypoint, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius) + private void UpdateCollectorOptions(Waypoint currentWaypoint, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius) { if (collectorWaypointChecked) { IsCollector = true; World.RemoveSpeedZone(YieldZone); - YieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, drivingSpeed); + YieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, SpeedZoneRadius, drivingSpeed); if (CollectorRadiusBlip) { currentWaypoint.CollectorRadiusBlip.Alpha = 0.5f; @@ -76,6 +78,7 @@ namespace SceneManager }; } CollectorRadius = collectorRadius; + SpeedZoneRadius = speedZoneRadius; } else { @@ -118,5 +121,25 @@ namespace SceneManager { Number = newWaypointNumber; } + + public void DrawWaypointMarker() + { + if(IsCollector && CollectorRadius > 0) + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, CollectorRadius, CollectorRadius, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false); + if(SpeedZoneRadius > 0) + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, SpeedZoneRadius, SpeedZoneRadius, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false); + } + } + else if(DrivingFlag == VehicleDrivingFlags.StopAtDestination) + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false); + } + else + { + Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false); + } + } } }