public static TaskResults Run(Coaster coaster, List <float> angles) { List <BuildAction> buildActions = new List <BuildAction>(); TaskResults results = TaskResults.Fail; buildActions.Clear(); for (int i = 0; i < 15; i++) { float startPitch = coaster.LastTrack.Pitch; foreach (float angle in angles) { results = Builder.BuildTracks(DetermineActions(angle, i, startPitch), coaster); if (results == TaskResults.Successful) { return(results); } else { coaster.Reset(); } } } return(results); }
public static TaskResults Run(Coaster coaster, float x, float y, float z, float xRange, float yRange, float zRange) { TaskResults results; results = GoToXYZ(coaster, x, y, z, xRange, yRange, zRange); return(results); }
public IActionResult Index() { var assembly = Assembly.GetExecutingAssembly(); var resourceName = "../ThemePark/Data/Ride.json"; List <Park> myParks = new List <Park>(); using (StreamReader reader = new StreamReader(resourceName)) { string jsonFile = reader.ReadToEnd(); //Make string equal to full file JsonDocument responseList = JsonDocument.Parse(jsonFile); var parks = responseList.RootElement.GetProperty("result"); for (int i = 0; i < parks.GetArrayLength(); i++) { myParks.Add(new Park() { parkName = parks[i].GetProperty("parkName").ToString(), parkCity = parks[i].GetProperty("parkCity").ToString(), parkState = parks[i].GetProperty("parkState").ToString(), parkYear = parks[i].GetProperty("parkInfo").ToString(), isOpen = parks[i].GetProperty("isOpen").GetBoolean() }); } } Coaster Maverick = new Coaster() { rideName = "Maverick", ridePark = myParks[0], opStatus = true }; return(View("Index", Maverick)); }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float XPosition, float YPosition, float withIn) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); //Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; bool passed = false; if (GoToXY(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, XPosition, YPosition, withIn)) { passed = GoToXY(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, XPosition, YPosition, withIn); } return(passed); }
public bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { //Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; if (RunFlatten(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke)) { return(RunFlatten(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke)); } else { return(false); } }
public async Task <IActionResult> Edit(int id, [Bind("CoasterID,CoasterName,CoasterManufacturer,CoasterStatus,CoasterType,CoasterStyle,CoasterHeight,CoasterLength,CoasterSpeed,CoasterInversions,CoasterParkID")] Coaster coaster) { if (id != coaster.CoasterID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coaster); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoasterExists(coaster.CoasterID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(coaster)); }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float XPosition, float withIn) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); //Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; bool passed = false; bool left = true; float yawGoal = 0; //Goal Yaw if (XPosition > tracks.Last().Position.X) { yawGoal = 0; } else { yawGoal = 180; } left = true; if (GoToX(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, XPosition, withIn, TrackType.Left, yawGoal)) { passed = GoToX(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, XPosition, withIn, TrackType.Left, yawGoal); } if (!passed) { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; if (GoToX(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, XPosition, withIn, TrackType.Right, yawGoal)) { passed = GoToX(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, XPosition, withIn, TrackType.Right, yawGoal); } } return(passed); }
public static TaskResults Run(Coaster coaster, float z, float withIn) { TaskResults results; results = GoToZ(coaster, z, withIn); return(results); }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float ZPosition, float withIn) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); //Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; bool passed = false; float pitchGoal = 0; //Goal Yaw if (ZPosition > tracks.Last().Position.Z) { pitchGoal = 90; } else { pitchGoal = 270; } if (GoToZ(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, ZPosition, withIn, TrackType.Up, pitchGoal)) { passed = GoToZ(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, ZPosition, withIn, TrackType.Up, pitchGoal); } if (!passed) { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; if (GoToZ(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, ZPosition, withIn, TrackType.Down, pitchGoal)) { passed = GoToZ(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, ZPosition, withIn, TrackType.Down, pitchGoal); } } return(passed); }
public async Task <IActionResult> Create([Bind("CoasterID,CoasterName,CoasterManufacturer,CoasterStatus,CoasterType,CoasterStyle,CoasterHeight,CoasterLength,CoasterSpeed,CoasterInversions,CoasterParkID")] Coaster coaster) { if (ModelState.IsValid) { _context.Add(coaster); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(coaster)); }
public void StartBuild(Coaster _Coaster) { taskHandler = new TaskHandler(_Coaster); userRequest = new List <string>(); Coaster = _Coaster; Globals.BuildRules = SetupBuildRules(); Globals.RemoveRules = SetupRemoveRules(); Globals.RulesWithFix = SetupTaskForOnRuleFail(); CreateStartTracks(); }
private static TaskResults GoToZ(Coaster coaster, float z, float withIn) { List <BuildAction> buildActions = new List <BuildAction>(); TaskResults results = TaskResults.Successful; float pitchGoal = 0; float lastDistance = Math.Abs(coaster.LastTrack.Z - z); if (z > coaster.LastTrack.Z) { pitchGoal = 90; } else { pitchGoal = 270; } results = BuildToPitch.Run(coaster, new List <float>() { pitchGoal }); if (results != TaskResults.Successful) { return(results); } while (!((coaster.LastTrack.Z < z + (withIn / 2) && coaster.LastTrack.Z > z - (withIn / 2))) && results == TaskResults.Successful) { buildActions.Add(new BuildAction(TrackType.Stright)); results = Builder.BuildTracks(buildActions, coaster); buildActions.Clear(); float distance = Math.Abs(coaster.LastTrack.Z - z); if (distance >= lastDistance) { return(TaskResults.Fail); } lastDistance = distance; } if (coaster.LastTrack.Z < z + (withIn / 2) && coaster.LastTrack.Z > z - (withIn / 2)) { return(TaskResults.Successful); } else { return(TaskResults.Fail); } }
public static TaskResults Run(Coaster coaster, float y, float withIn) { TaskResults results; //Go Left results = GoToY(coaster, y, withIn, TrackType.Left); //Go Right if (results != TaskResults.Successful) { results = GoToY(coaster, y, withIn, TrackType.Right); } return(results); }
public void onEnabled() { assetLoader = new GameObject(); AssetLoader loader = assetLoader.AddComponent <AssetLoader>(); loader.Path = Path; loader.LoadAssets(); specialSegments = AssetManager.Instance.specialSegments; SpecialSegmentSettings[] newSpecialSegments = new SpecialSegmentSettings[specialSegments.Length + 1]; for (int i = 0; i < specialSegments.Length; i++) { newSpecialSegments[i] = specialSegments[i]; } GameObject track = new GameObject(); track.AddComponent <MeshFilter>(); track.AddComponent <MeshRenderer>(); //track.AddComponent<CustomColors>(); BoosterTrackSegment bseg = track.AddComponent <BoosterTrackSegment>(); SpecialSegmentSettings lowSpeed = ScriptableObject.CreateInstance <SpecialSegmentSettings>(); lowSpeed.displayName = "Low Speed Booster Track"; bseg.setAcceleration(20f); lowSpeed.segmentPrefab = bseg; lowSpeed.curveAngle = 0; lowSpeed.preview = UnityEngine.Object.Instantiate(loader.test); lowSpeed.isInverted = false; newSpecialSegments[newSpecialSegments.Length - 1] = lowSpeed; AssetManager.Instance.registerObject(bseg); AssetManager.Instance.specialSegments = newSpecialSegments; foreach (Attraction a in AssetManager.Instance.getAttractionObjects()) { if (a is Coaster) { Coaster c = (Coaster)a; c.specialSegments.addSpecialSegment(lowSpeed); } } }
public void StartBuild(Coaster _Coaster, List <string> _UserRequest) { taskHandler = new TaskHandler(_Coaster); if (_UserRequest != null) { userRequest = _UserRequest; } else { userRequest = new List <string>(); } Coaster = _Coaster; Globals.BuildRules = SetupBuildRules(); Globals.RemoveRules = SetupRemoveRules(); Globals.RulesWithFix = SetupTaskForOnRuleFail(); CreateStartTracks(); }
public bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { //Make a Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); BuildLoop buildLoop = new BuildLoop(); RemoveChunk removeChunk = new RemoveChunk(); bool successful = false; //Test for (int i = 0; i < 14; i++) { removeChunk.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); } successful = buildLoop.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); if (successful) { for (int i = 0; i < 14; i++) { removeChunk.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); } return(buildLoop.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke)); } else { return(false); } }
private bool TryRidingAttraction(Attraction attr) { _coaster = attr as Coaster; if (attr == null) { return(false); } _seats.Clear(); _seatIndex = 0; Utility.recursiveFindTransformsStartingWith("seat", attr.transform, _seats); if (_seats.Count <= 0) { return(false); } EnterCoasterCam(_seats[_seatIndex].gameObject); return(true); }
public void SetupCoaster(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, int removeChunks, List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { RemoveChunk rc = new RemoveChunk(); Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; for (int j = 0; j < removeChunks; j++) { rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); } }
public void onDisabled() { foreach (Attraction a in AssetManager.Instance.getAttractionObjects()) { if (a is Coaster) { Coaster c = (Coaster)a; c.specialSegments.removeSpecialSegment(AssetManager.Instance.specialSegments[AssetManager.Instance.specialSegments.Length - 1]); } } foreach (BuildableObject i in _sceneryObjects) { AssetManager.Instance.unregisterObject(i); UnityEngine.Object.DestroyImmediate(i.gameObject); } UnityEngine.Object.DestroyImmediate(AssetManager.Instance.specialSegments[AssetManager.Instance.specialSegments.Length - 1]); AssetManager.Instance.specialSegments = specialSegments; UnityEngine.Object.DestroyImmediate(assetLoader); }
public bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { bool resolved = false; Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; float currentYaw = _tracks.Last().Orientation.Yaw; float goalYawOne = KeepBetween360Degrees(currentYaw + 90); float goalYawTwo = KeepBetween360Degrees(currentYaw - 90); int totalNewTacksOne = 0; int totalNewTacksTwo = 0; for (int i = 1; i < 15; i++) { { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); for (int j = 0; j < i; j++) { commands.Add(new Command(false, TrackType.Stright)); } float startYaw = _tracks[_tracks.Count - 1 - i].Orientation.Yaw; int newTracks = (int)(calculateDifferenceBetweenAngles(startYaw, goalYawOne) / Globals.STANDARD_ANGLE_CHANGE); for (int k = 0; k < newTracks; k++) { commands.Add(new Command(true, TrackType.Right, new Orientation(0, 0, 0))); } if (commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)) { commandHandeler.Run(commands, _tracks, _chunks, _tracksFinshed, _tracksStarted, ref _ruleBroke); resolved = true; break; } else { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; } } // } // for (int i = 1; i < 15; i++) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); for (int j = 0; j < i; j++) { commands.Add(new Command(false, TrackType.Stright)); } float startYaw = _tracks[_tracks.Count - 1 - i].Orientation.Yaw; int newTracks = (int)(calculateDifferenceBetweenAngles(startYaw, goalYawTwo) / Globals.STANDARD_ANGLE_CHANGE); for (int k = 0; k < newTracks; k++) { commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); } if (commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)) { commandHandeler.Run(commands, _tracks, _chunks, _tracksFinshed, _tracksStarted, ref _ruleBroke); resolved = true; break; } else { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; } } } return(resolved); }
public bool GetToFinshArea(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { //Copy Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; //260, 70, 150, 25 Debug.LogError("HERERERER"); //Get To Finsh Area bool pass = false; float x = 260f; float y = 5; float z = 150; int zRange = 100; int withIn = 50; //Try Many Routes. //At LEAST //XYZ, XZY, YXZ, YZX, ZXY, ZYX, XY Z, Z XY, XYZ, XZ Y, YZ X. Use 3 Heights, Then Back up 1 Track at a time. pass = BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, 50); pass = BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, 50); pass = BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, 45); RemoveChunk rc = new RemoveChunk(); for (int i = 0; i < 20; i++) { //XY //SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; for (int j = 0; j < i; j++) { rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); } if (BuildToXY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, y, withIn)) { for (int j = 0; j < i; j++) { rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); } BuildToXY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, y, withIn); return(true); } ////X-Y ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn) && BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // return true; //} ////Y-X ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn) && BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // return true; //} //XYZ //SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; for (int j = 0; j < i; j++) { rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); } if (BuildToXYZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, y, z, withIn)) { for (int j = 0; j < i; j++) { rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); } BuildToXYZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, y, z, withIn); return(true); } //Z - XY //SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; for (int j = 0; j < i; j++) { rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); } if (BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, withIn) && BuildToXY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, y, withIn)) { for (int j = 0; j < i; j++) { rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); } BuildToZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, z, withIn); BuildToXY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, y, withIn); return(true); } ////Z-X-Y ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, withIn) && BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn) && BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, z, withIn); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // return true; //} ////Z-Y-X ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, withIn) && BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn) && BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, z, withIn); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // return true; //} ////X-Z-Y ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn) && BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, withIn) && BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // BuildToZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, z, withIn); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // return true; //} ////Y-Z-X ////SetupCoaster(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, i, tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //coaster.SetTracks = _tracks; //coaster.SetChunks = _chunks; //coaster.SetTracksStarted = _tracksStarted; //coaster.SetTracksFinshed = _tracksFinshed; //tracks = coaster.GetCurrentTracks; //chunks = coaster.GetCurrentChunks; //tracksStarted = coaster.GetCurrentTracksStarted; //tracksFinshed = coaster.GetCurrentTracksFinshed; //ruleBroke = _ruleBroke; //for (int j = 0; j < i; j++) // rc.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); //if (BuildToY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, y, withIn) && BuildToZ.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, z, withIn) && BuildToX.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, x, withIn)) //{ // for (int j = 0; j < i; j++) // rc.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke); // BuildToY.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, y, withIn); // BuildToZ.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, z, withIn); // BuildToX.Run(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, x, withIn); // return true; //} } return(false); }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float _yaw) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool resolved = false; bool left = false; Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; float yaw = _yaw; if (yaw <= tracks.Last().Orientation.Yaw) { if ((tracks.Last().Orientation.Yaw - yaw) <= 180) { left = true; } else { left = false; } } else { if (yaw - tracks.Last().Orientation.Yaw <= 180) { left = true; } else { left = false; } } if (left) { resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, yaw, TrackType.Left); if (!resolved) { left = false; //Reset tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, yaw, TrackType.Right); } } else { resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, yaw, TrackType.Right); if (!resolved) { left = true; //Reset tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, yaw, TrackType.Left); } } if (resolved) { if (left) { resolved = TryTrackType(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, _yaw, TrackType.Left); } else { resolved = TryTrackType(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, _yaw, TrackType.Right); } } return(resolved); }
public TaskHandler(Coaster _coaster) { coaster = _coaster; }
public bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { if (_tracks.Last().Orientation.Yaw == 90 || _tracks.Last().Orientation.Yaw == 270) { return(false); } bool resolved = false; Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; for (int i = 1; i < 15; i++) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); int removeTracks = 0; for (int j = 0; j < i; j++) { commands.Add(new Command(false, TrackType.Stright)); removeTracks++; } float startYaw = _tracks[_tracks.Count - 1 - i].Orientation.Yaw; if (startYaw <= 90) { int totalNewTacks = Math.Abs((int)((90 - startYaw) / Globals.STANDARD_ANGLE_CHANGE)); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); } } else if ((startYaw > 90) && (startYaw < 180)) { int totalNewTacks = Math.Abs((int)((startYaw - 90) / Globals.STANDARD_ANGLE_CHANGE)); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Right, new Orientation(0, 0, 0))); } } else if (startYaw >= 180 && startYaw < 270) { int totalNewTacks = Math.Abs((int)((270 - startYaw) / Globals.STANDARD_ANGLE_CHANGE)); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); } } else if (startYaw >= 270) { int totalNewTacks = Math.Abs((int)((startYaw - 270) / Globals.STANDARD_ANGLE_CHANGE)); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Right, new Orientation(0, 0, 0))); } } if (commands.Count != removeTracks) { if (commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)) { commandHandeler.Run(commands, _tracks, _chunks, _tracksFinshed, _tracksStarted, ref _ruleBroke); resolved = true; break; } else { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; } } } return(resolved); }
private static TaskResults Runner(Coaster coaster, int RemoveTracks, float x, float y, float xRange, float yRange, bool TurnLeft, float ChangeZ = 0, bool changeYawAfterZChange = false, float ChangeZWithin = 50) { bool TurnedToAngleForceDirectionOnce = false; TaskResults results = TaskResults.Fail; List <BuildAction> buildActions = new List <BuildAction>(); float yawGoal = Convert.ToSingle(Math.Atan2( (y - coaster.LastTrack.Y), (x - coaster.LastTrack.X)) * 180 / Math.PI); if (yawGoal < 0) { yawGoal = yawGoal + 360; } int totalAdjustments = (int)(yawGoal / Globals.STANDARD_ANGLE_CHANGE); if ((yawGoal % 15) > Globals.STANDARD_ANGLE_CHANGE / 2) { totalAdjustments++; } yawGoal = totalAdjustments * Globals.STANDARD_ANGLE_CHANGE; RemoveChunk removeChunk = new RemoveChunk(); for (int j = 0; j < RemoveTracks * 5; j++) { removeChunk.Run(coaster); } results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } if (ChangeZ != 0) { results = BuildToZ.Run(coaster, coaster.LastTrack.Z + ChangeZ, 50); if (results != TaskResults.Successful) { return(results); } } if (changeYawAfterZChange) { while (coaster.LastTrack.Yaw != yawGoal) { if (TurnLeft) { buildActions.Add(new BuildAction(TrackType.Left)); } else { buildActions.Add(new BuildAction(TrackType.Right)); } results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } buildActions.Clear(); } TurnedToAngleForceDirectionOnce = true; } results = BuildToPitch.Run(coaster, new List <float>() { 0 }); if (results != TaskResults.Successful) { return(results); } while (!((coaster.LastTrack.X < x + (xRange / 2) && coaster.LastTrack.X > x - (xRange / 2)) && (coaster.LastTrack.Y < y + (yRange / 2) && coaster.LastTrack.Y > y - (yRange / 2))) && results == TaskResults.Successful) { yawGoal = Convert.ToSingle(Math.Atan2( (y - coaster.LastTrack.Y), (x - coaster.LastTrack.X)) * 180 / Math.PI); if (yawGoal < 0) { yawGoal = yawGoal + 360; } //Get YawGoal To Nearest Angle Game Can Handle totalAdjustments = (int)(yawGoal / Globals.STANDARD_ANGLE_CHANGE); if ((yawGoal % 15) > Globals.STANDARD_ANGLE_CHANGE / 2) { totalAdjustments++; } yawGoal = totalAdjustments * Globals.STANDARD_ANGLE_CHANGE; if (coaster.LastTrack.Yaw == yawGoal) { TurnedToAngleForceDirectionOnce = true; float lastDistance = Math.Abs((coaster.LastTrack.X - x) + (coaster.LastTrack.Y - y)); buildActions.Add(new BuildAction(TrackType.Stright)); results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } buildActions.Clear(); float distance = Math.Abs((coaster.LastTrack.X - x) + (coaster.LastTrack.Y - y)); if (distance >= lastDistance) { return(TaskResults.Fail); } lastDistance = distance; } else if (!TurnedToAngleForceDirectionOnce) { if (TurnLeft) { buildActions.Add(new BuildAction(TrackType.Left)); } else { buildActions.Add(new BuildAction(TrackType.Right)); } results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } buildActions.Clear(); } else { TrackType type = new TrackType(); if (coaster.LastTrack.Yaw - yawGoal > 0) { if (Math.Abs(coaster.LastTrack.Yaw - yawGoal) < 180) { type = TrackType.Right; } else { type = TrackType.Left; } } else { if (Math.Abs(yawGoal - coaster.LastTrack.Yaw) < 180) { type = TrackType.Left; } else { type = TrackType.Right; } } buildActions.Add(new BuildAction(type)); results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } buildActions.Clear(); } } if (coaster.LastTrack.X < x + (xRange / 2) && coaster.LastTrack.X > x - (xRange / 2) && (coaster.LastTrack.Y < y + (yRange / 2) && coaster.LastTrack.Y > y - (yRange / 2))) { return(TaskResults.Successful); } else { return(TaskResults.Fail); } }
public static TaskResults Run(Coaster coaster, float x, float y, float xRange, float yRange) { //Determine Left, Or Right to Try first TaskResults results = TaskResults.Fail; bool Left = true; float yawGoal = Convert.ToSingle(Math.Atan2( (y - coaster.LastTrack.Y), (x - coaster.LastTrack.X)) * 180 / Math.PI); int totalAdjustments = (int)(yawGoal / Globals.STANDARD_ANGLE_CHANGE); if ((yawGoal % 15) > Globals.STANDARD_ANGLE_CHANGE / 2) { totalAdjustments++; } List <BuildAction> buildActions = new List <BuildAction>(); yawGoal = totalAdjustments * Globals.STANDARD_ANGLE_CHANGE; Left = (Math.Abs(yawGoal - coaster.LastTrack.Yaw) < 180); for (int i = 0; i <= 3; i++) { //Try Level coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, Left); if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, !Left); } //Try Going Up First if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, Left, 100); } if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, !Left, 100); } if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, Left, 100, true); } //Try Going Down First if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, Left, -100); } if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, !Left, -100); } if (results != TaskResults.Successful) { coaster.Reset(); results = Runner(coaster, i, x, y, xRange, yRange, Left, -100, true); } //Reset Coaster if (results != TaskResults.Successful) { coaster.Reset(); } } return(results); }
public bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke) { bool resolved = false; Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; for (int i = 1; i < 45; i++) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); for (int j = 0; j < i; j++) { commands.Add(new Command(false, TrackType.Stright)); } float startPitch = _tracks[_tracks.Count - 1 - i].Orientation.Pitch; if (startPitch > 180 && startPitch < 270) { int totalNewTacks = (int)((360 - startPitch) / Globals.STANDARD_ANGLE_CHANGE); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Up, new Orientation(0, 0, 0))); } } else if (startPitch >= 270) { int totalNewTacks = (int)((360 - startPitch) / Globals.STANDARD_ANGLE_CHANGE); for (int k = 0; k < totalNewTacks; k++) { commands.Add(new Command(true, TrackType.Up, new Orientation(0, 0, 0))); } } if (commands.Count != i) { if (commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)) { commandHandeler.Run(commands, _tracks, _chunks, _tracksFinshed, _tracksStarted, ref _ruleBroke); resolved = true; break; } else { tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; } } } return(resolved); }
private static TaskResults GoToXYZ(Coaster coaster, float x, float y, float z, float xRange, float yRange, float zRange) { List <BuildAction> buildActions = new List <BuildAction>(); TaskResults results = TaskResults.Successful; bool firstStrightTrack = true; float last = 0; float lastDiffernce = 0; float yawGoal = 0; float pitchGoal = 0; while (!( (coaster.LastTrack.X < x + (xRange / 2) && coaster.LastTrack.X > x - (xRange / 2)) && (coaster.LastTrack.Y < y + (yRange / 2) && coaster.LastTrack.Y > y - (yRange / 2)) && (coaster.LastTrack.Z <= (z + (zRange / 2)) && coaster.LastTrack.Z >= (z - (zRange / 2)))) && results == TaskResults.Successful) { //Determine Best Yaw yawGoal = Convert.ToSingle(Math.Atan2((double)(coaster.LastTrack.Y), (double)(x - coaster.LastTrack.X)) * 180 / Math.PI); if (yawGoal < 0) { yawGoal = yawGoal + 360; } //Get YawGoal To Nearest Angle Game Can Handle int totalAdjustments = (int)(yawGoal / Globals.STANDARD_ANGLE_CHANGE); if ((yawGoal % 15) > Globals.STANDARD_ANGLE_CHANGE / 2) { totalAdjustments++; } yawGoal = totalAdjustments * Globals.STANDARD_ANGLE_CHANGE; //If Z to High, Z To Low if (coaster.LastTrack.Z <= (z + (zRange / 2)) && coaster.LastTrack.Z >= (z - (zRange / 2))) { pitchGoal = 0; } else if ((z - coaster.LastTrack.Z) > 0) { pitchGoal = 90; } else { pitchGoal = 270; } //Determine Best Yaw if (coaster.LastTrack.Yaw == yawGoal && coaster.LastTrack.Pitch == pitchGoal) { buildActions.Add(new BuildAction(TrackType.Stright)); results = Builder.BuildTracks(buildActions, coaster); buildActions.Clear(); float differnce = Math.Abs((coaster.LastTrack.X - x) + (coaster.LastTrack.Y - y)); if (!firstStrightTrack) { //This Means You Passed The Goal Point, This could have been done by turning, Or After the Fact. But You Are now going the wrong way. if (differnce > lastDiffernce) { return(TaskResults.Fail); } } else { firstStrightTrack = true; } last = coaster.LastTrack.X + coaster.LastTrack.Y; lastDiffernce = differnce; } else { int yawDirection = 0; int pitchDirection = 0; if (!(coaster.LastTrack.Yaw == yawGoal)) { if (coaster.LastTrack.Yaw - yawGoal > 0) { if (Math.Abs(coaster.LastTrack.Yaw - yawGoal) < 180) { yawDirection = -1; //Right } else { yawDirection = 1; //Left } } else { if (Math.Abs(yawGoal - coaster.LastTrack.Yaw) < 180) { yawDirection = 1; //Left } else { yawDirection = -1; //Right } } } // if (!(coaster.LastTrack.Pitch == pitchGoal)) { if (coaster.LastTrack.Pitch - pitchGoal > 0) { if ((coaster.LastTrack.Pitch - pitchGoal > 360 - coaster.LastTrack.Pitch)) { pitchDirection = 1; //Up } else { pitchDirection = -1; //Down } } else { if ((pitchGoal - coaster.LastTrack.Pitch > 360 - pitchGoal)) { pitchDirection = -1; //Down } else { pitchDirection = 1; //Up } } } buildActions.Add(new BuildAction(TrackType.Custom, Globals.STANDARD_ANGLE_CHANGE * yawDirection, Globals.STANDARD_ANGLE_CHANGE * pitchDirection)); results = Builder.BuildTracks(buildActions, coaster); buildActions.Clear(); } } if ((coaster.LastTrack.X < x + (xRange / 2) && coaster.LastTrack.X > x - (xRange / 2)) && (coaster.LastTrack.Y < y + (yRange / 2) && coaster.LastTrack.Y > y - (yRange / 2)) && (coaster.LastTrack.Z <= (z + (zRange / 2)) && coaster.LastTrack.Z >= (z - (zRange / 2)))) { return(TaskResults.Successful); } else { return(TaskResults.Fail); } }
private static TaskResults GoToY(Coaster coaster, float y, float withIn, TrackType type) { List <BuildAction> buildActions = new List <BuildAction>(); TaskResults results = TaskResults.Successful; float yawGoal = 0; if (y > coaster.LastTrack.Y) { yawGoal = 0; } else { yawGoal = 180; } bool firstStrightTrack = true; float lastY = 0; float lastDiffernce = 0; results = BuildToPitch.Run(coaster, new List <float>() { 0 }); if (results != TaskResults.Successful) { return(results); } while (!((coaster.LastTrack.Y < y + (withIn / 2) && coaster.LastTrack.Y > y - (withIn / 2))) && results == TaskResults.Successful) { if (coaster.LastTrack.Yaw == yawGoal) { buildActions.Add(new BuildAction(TrackType.Stright)); results = Builder.BuildTracks(buildActions, coaster); if (results != TaskResults.Successful) { return(results); } buildActions.Clear(); float differnce = Math.Abs(coaster.LastTrack.Y - lastY); if (!firstStrightTrack) { //This Means You Passed The Goal Point, This could have been done by turning, Or After the Fact. But You Are now going the wrong way. if (differnce > lastDiffernce) { return(TaskResults.Fail); } } else { firstStrightTrack = true; } lastY = coaster.LastTrack.Y; lastDiffernce = differnce; } else { buildActions.Add(new BuildAction(type)); results = Builder.BuildTracks(buildActions, coaster); buildActions.Clear(); } } if (coaster.LastTrack.Y < y + (withIn / 2) && coaster.LastTrack.Y > y - (withIn / 2)) { return(TaskResults.Successful); } else { return(TaskResults.Fail); } }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float _pitch) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool resolved = false; bool up = false; Coaster coaster = new Coaster(); coaster.SetTracks = _tracks; coaster.SetChunks = _chunks; coaster.SetTracksStarted = _tracksStarted; coaster.SetTracksFinshed = _tracksFinshed; List <Track> tracks = coaster.GetCurrentTracks; List <int> chunks = coaster.GetCurrentChunks; bool tracksStarted = coaster.GetCurrentTracksStarted; bool tracksFinshed = coaster.GetCurrentTracksFinshed; Rule ruleBroke = _ruleBroke; float pitch = _pitch; if (pitch < tracks.Last().Orientation.Pitch) { if ((tracks.Last().Orientation.Pitch - pitch) < 180) { up = false; } else { up = true; } } else { if (pitch - tracks.Last().Orientation.Pitch < 180) { up = true; } else { up = false; } } if (up) { resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, pitch, TrackType.Up); if (!resolved) { up = false; //Reset tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, pitch, TrackType.Down); } } else { resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, pitch, TrackType.Down); if (!resolved) { up = true; //Reset tracks = coaster.GetCurrentTracks; chunks = coaster.GetCurrentChunks; tracksStarted = coaster.GetCurrentTracksStarted; tracksFinshed = coaster.GetCurrentTracksFinshed; ruleBroke = _ruleBroke; resolved = TryTrackType(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, pitch, TrackType.Up); } } if (resolved) { if (up) { resolved = TryTrackType(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, _pitch, TrackType.Up); } else { resolved = TryTrackType(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, _pitch, TrackType.Down); } } return(resolved); }