From d36c7fb0129b88b4464441a8308421d083dec973 Mon Sep 17 00:00:00 2001 From: Rich Dunne Date: Sat, 10 Oct 2020 15:52:48 -0600 Subject: [PATCH] Refactored variable/object references to reflect changes in path creation/edit waypoint menus. --- SceneManager/AITasking.cs | 33 ++++++++++------------ SceneManager/Menus/PathMainMenu.cs | 6 ++-- SceneManager/Object Classes/Path.cs | 4 +-- SceneManager/Object Classes/Waypoint.cs | 37 ++++++++++++++++--------- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/SceneManager/AITasking.cs b/SceneManager/AITasking.cs index 88e46d8..ec9aea3 100644 --- a/SceneManager/AITasking.cs +++ b/SceneManager/AITasking.cs @@ -29,7 +29,7 @@ namespace SceneManager 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); } @@ -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} Dismissed: {collectedVehicle.Dismissed}, Directed: {collectedVehicle.SkipWaypoint}"); - if (currentWaypoint.DrivingFlag == VehicleDrivingFlags.IgnorePathFinding) - { - collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)17040299, acceptedDistance); - } - else - { - collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)263075, acceptedDistance); - } + 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); + //} + //else + //{ + // collectedVehicle.Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)263075, acceptedDistance); + //} } void LoopWhileDrivingToDirectedWaypoint(float acceptedDistance) @@ -111,16 +112,9 @@ namespace SceneManager //Logger.Log($"{collectedVehicle.Vehicle.Model.Name} current waypoint: {collectedVehicle.CurrentWaypoint.Number}"); 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}"); - if (path.Waypoints[currentWaypointTask].DrivingFlag == VehicleDrivingFlags.IgnorePathFinding) - { - 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); - } + driver.Tasks.DriveToPosition(path.Waypoints[currentWaypointTask].Position, path.Waypoints[currentWaypointTask].Speed, path.Waypoints[currentWaypointTask].DrivingFlag, acceptedDistance); LoopWhileDrivingToWaypoint(currentWaypointTask, acceptedDistance); if (!VehicleAndDriverAreValid(collectedVehicle)) @@ -134,7 +128,7 @@ namespace SceneManager 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); } @@ -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) { + //Logger.Log($"Looping while {vehicle.Model.Name} drives to waypoint."); GameFiber.Sleep(100); } } diff --git a/SceneManager/Menus/PathMainMenu.cs b/SceneManager/Menus/PathMainMenu.cs index 3a10a37..f48a7e8 100644 --- a/SceneManager/Menus/PathMainMenu.cs +++ b/SceneManager/Menus/PathMainMenu.cs @@ -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.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 { - 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 diff --git a/SceneManager/Object Classes/Path.cs b/SceneManager/Object Classes/Path.cs index d142e93..af3a743 100644 --- a/SceneManager/Object Classes/Path.cs +++ b/SceneManager/Object Classes/Path.cs @@ -86,7 +86,7 @@ namespace SceneManager { 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); } @@ -101,7 +101,5 @@ namespace SceneManager } }); } - - } } diff --git a/SceneManager/Object Classes/Waypoint.cs b/SceneManager/Object Classes/Waypoint.cs index 7e933fa..fc4db2c 100644 --- a/SceneManager/Object Classes/Waypoint.cs +++ b/SceneManager/Object Classes/Waypoint.cs @@ -4,6 +4,12 @@ using System.Linq; namespace SceneManager { + public enum DrivingFlagType + { + Normal = 263075, + Direct = 17040299 + } + public class Waypoint { internal Path Path { get; set; } @@ -11,6 +17,8 @@ namespace SceneManager internal Vector3 Position { get; set; } internal float Speed { get; set; } internal VehicleDrivingFlags DrivingFlag { get; set; } + internal DrivingFlagType DrivingFlagType { get; private set; } + internal bool IsStopWaypoint { get; set; } internal Blip Blip { get; } internal bool IsCollector { get; set; } internal float CollectorRadius { get; set; } @@ -20,13 +28,15 @@ namespace SceneManager internal bool EnableWaypointMarker { get; set; } = true; 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; Number = waypointNum; Position = waypointPos; Speed = speed; DrivingFlag = drivingFlag; + DrivingFlagType = (DrivingFlagType)DrivingFlag; + IsStopWaypoint = stopWaypoint; Blip = waypointBlip; IsCollector = collector; CollectorRadius = collectorRadius; @@ -50,9 +60,13 @@ namespace SceneManager 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); UpdateCollectorOptions(); if (updateWaypointPositionChecked) @@ -60,25 +74,22 @@ namespace SceneManager 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)) { Logger.Log($"Setting StoppedAtWaypoint to false for {cv.Vehicle.Model.Name}"); cv.Dismiss(DismissOption.FromWaypoint); } } - DrivingFlag = newDrivingFlag; - if (newDrivingFlag == VehicleDrivingFlags.StopAtDestination) + else if(!IsStopWaypoint && stopWaypoint) { Blip.Color = Color.Red; } - else - { - Blip.Color = Color.Green; - } + IsStopWaypoint = stopWaypoint; } 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.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) { @@ -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, 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); }