public bool FinshTheCoaster(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { tracksFinshed = true; //Debug.Print("CALLED?!?!?!?!"); bool pass = true; //Finsh Coaster //Vars BuildFlaten buildFlaten = new BuildFlaten(); CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool buildPass = true; commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); BuildToXY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 260, -100, 50); buildFlaten.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke); BuildToXY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 260, -230, 25); BuildToXY.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, Globals.START_X, Globals.START_Y, 25); //500, -275, 25); commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); ruleBroke = null; return(pass); }
public static bool Run(List <Track> _tracks, List <int> _chunks, ref bool _tracksStarted, ref bool _tracksFinshed, ref Rule _ruleBroke, float XPosition, float YPosition, 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; if (GoToXYZ(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, XPosition, YPosition, ZPosition, withIn)) { passed = GoToXYZ(_tracks, _chunks, ref _tracksStarted, ref _tracksFinshed, ref _ruleBroke, XPosition, YPosition, ZPosition, withIn); } return(passed); }
public bool Run(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); //Stright for (int i = 0; i < (8 * 3); i++) { // Debug.LogError("HERE!~!!!!"); commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); } // // //Left for (int i = 0; i < (4 * 3); i++) { commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); } //Stright for (int i = 0; i < (28); i++) { commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); } return(commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)); }
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); }
static bool GoToX(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke, float XPosition, float withIn, TrackType type, float yawGoal) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool buildPass = true; bool firstStrightTrack = true; float lastX = 0; float lastDiffernce = 0; buildPass = BuildToPitch.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 0); if (!buildPass) { return(false); } while (!((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2))) && buildPass) { if (tracks.Last().Orientation.Yaw == yawGoal) { commands.Clear(); commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); float differnce = Math.Abs(tracks.Last().Position.X - lastX); 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(false); } } else { firstStrightTrack = true; } lastX = tracks.Last().Position.X; lastDiffernce = differnce; } else { commands.Clear(); commands.Add(new Command(true, type, new Orientation(0, 0, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); } } if (tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2)) { return(true); } else { return(false); } }
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 bool Run(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); commands.Add(new Command(true, TrackType.Left, new Orientation(0, 0, 0))); return(commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)); }
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); } }
public bool Run(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); int totalChunks = chunks.Count(); //Remove Track commands.Add(new Command(false, TrackType.Stright, new Orientation(0, 0, 0))); bool pass = false; do { pass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); }while(pass && totalChunks == chunks.Count()); return(pass); }
/// <summary> /// Initialise new console command, <see cref="KS_Console.RegisterCommand(ConsoleCommand)"> Used only with KS_Console </see>. /// </summary> /// <param name="command">The command activate name for users</param> /// <param name="handler">The callback method when activated. <see cref="KS_ConsoleCommands">See KS_ConsoleCommands for use</see></param> /// <param name="help">The Commands help text, Displayed in console</param> /// <param name="paramFormat">Commands Paramaters format, Supported formats: $I = int, $S = string, $F = float, $B = bool</param> /// <param name="requiresAllParams">All parameters need to be filled?</param> /// <example> /// The following example is the findcmd command, that uses a string parameter for searching and int parameter for page. /// /// <code language="c#"> /// ConsoleCommand example = new ConsoleCommand("findcmd", findCmd, "Search commands by string, page number can be used after search string", "$s $i", false) /// </code> /// </example> public ConsoleCommand(string command, CommandHandeler handler, string help, string paramFormat, bool requiresAllParams = true) { this.command = command; this.handler = handler; this.help = help; this.requiresAllParams = requiresAllParams; if (!string.IsNullOrEmpty(paramFormat)) { string[] formatSplit = paramFormat.Split(' '); this.numParams = formatSplit.Length; this.format = ParseFormat(formatSplit); } else { this.numParams = 0; this.format = null; } }
public static bool TryTrackType(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke, float yaw, TrackType type) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool buildPass = true; commands.Add(new Command(true, type, new Orientation(0, 0, 0))); while (tracks.Last().Orientation.Yaw != yaw && buildPass) { buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); if (buildPass == false) { return(false); } } return(true); }
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 void OnCommand(CommandHandeler handler, string[] args) { handler(args); }
static bool GoToXY(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>(); bool buildPass = true; bool firstStrightTrack = true; float last = 0; float lastDiffernce = 0; float yawGoal = 0; buildPass = BuildToPitch.Run(tracks, chunks, ref tracksStarted, ref tracksFinshed, ref ruleBroke, 0); if (!buildPass) { return(false); } while (!((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2)) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2))) && buildPass) { float x = XPosition - tracks.Last().Position.X; float y = YPosition - tracks.Last().Position.Y; //Determine Best Yaw yawGoal = Convert.ToSingle(Math.Atan2((double)y, (double)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 (tracks.Last().Orientation.Yaw == yawGoal) { commands.Clear(); commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); float xDistance = tracks.Last().Position.X - XPosition; float YDistance = tracks.Last().Position.Y - YPosition; float differnce = Math.Abs(xDistance + xDistance); 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(false); } } else { firstStrightTrack = true; } last = tracks.Last().Position.X + tracks.Last().Position.Y; lastDiffernce = differnce; } else { TrackType type = new TrackType(); if (tracks.Last().Orientation.Yaw - yawGoal > 0) { if (Math.Abs(tracks.Last().Orientation.Yaw - yawGoal) < 180) { type = TrackType.Right; } else { type = TrackType.Left; } } else { if (Math.Abs(yawGoal - tracks.Last().Orientation.Yaw) < 180) { type = TrackType.Left; } else { type = TrackType.Right; } } commands.Clear(); commands.Add(new Command(true, type, new Orientation(0, 0, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); } } if (tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2))) { return(true); } else { return(false); } }
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); }
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); }
static bool GoToXYZ(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke, float XPosition, float YPosition, float ZPosition, float withIn) { CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); bool buildPass = true; bool firstStrightTrack = true; float last = 0; float lastDiffernce = 0; float yawGoal = 0; float pitchGoal = 0; float withInZ = 200; if (!buildPass) { return(false); } while (!((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2)) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2)) && (tracks.Last().Position.Z <= (ZPosition + (withInZ / 2)) && tracks.Last().Position.Z >= (ZPosition - (withInZ / 2)))) && buildPass) { float x = XPosition - tracks.Last().Position.X; float y = YPosition - tracks.Last().Position.Y; float z = ZPosition - tracks.Last().Position.Z; //Determine Best Yaw yawGoal = Convert.ToSingle(Math.Atan2((double)y, (double)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 (tracks.Last().Position.Z <= (ZPosition + (withInZ / 2)) && tracks.Last().Position.Z >= (ZPosition - (withInZ / 2))) { pitchGoal = 0; } else if (z > 0) { pitchGoal = 90; } else { pitchGoal = 270; } //Determine Best Yaw if (tracks.Last().Orientation.Yaw == yawGoal && tracks.Last().Orientation.Pitch == pitchGoal) { commands.Clear(); commands.Add(new Command(true, TrackType.Stright, new Orientation(0, 0, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); float xDistance = tracks.Last().Position.X - XPosition; float YDistance = tracks.Last().Position.Y - YPosition; float differnce = Math.Abs(xDistance + xDistance); 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(false); } } else { firstStrightTrack = true; } last = tracks.Last().Position.X + tracks.Last().Position.Y; lastDiffernce = differnce; } else { int yawDirection = 0; int pitchDirection = 0; if (!(tracks.Last().Orientation.Yaw == yawGoal)) { if (tracks.Last().Orientation.Yaw - yawGoal > 0) { if (Math.Abs(tracks.Last().Orientation.Yaw - yawGoal) < 180) { yawDirection = -1; //Right } else { yawDirection = 1; //Left } } else { if (Math.Abs(yawGoal - tracks.Last().Orientation.Yaw) < 180) { yawDirection = 1; //Left } else { yawDirection = -1; //Right } } } // if (!(tracks.Last().Orientation.Pitch == pitchGoal)) { if (tracks.Last().Orientation.Pitch - pitchGoal > 0) { if ((tracks.Last().Orientation.Pitch - pitchGoal > 360 - tracks.Last().Orientation.Pitch)) { pitchDirection = 1; //Up } else { pitchDirection = -1; //Down } } else { if ((pitchGoal - tracks.Last().Orientation.Pitch > 360 - pitchGoal)) { pitchDirection = -1; //Down } else { pitchDirection = 1; //Up } } } commands.Clear(); commands.Add(new Command(true, TrackType.Custom, new Orientation(Globals.STANDARD_ANGLE_CHANGE * yawDirection, Globals.STANDARD_ANGLE_CHANGE * pitchDirection, 0))); buildPass = commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke); } } if ((tracks.Last().Position.X < XPosition + (withIn / 2) && tracks.Last().Position.X > XPosition - (withIn / 2)) && (tracks.Last().Position.Y < YPosition + (withIn / 2) && tracks.Last().Position.Y > YPosition - (withIn / 2)) && (tracks.Last().Position.Z <= (ZPosition + (withIn / 2)) && tracks.Last().Position.Z >= (ZPosition - (withInZ / 2)))) { return(true); } else { return(false); } }
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); }
public bool Run(List <Track> tracks, List <int> chunks, ref bool tracksStarted, ref bool tracksFinshed, ref Rule ruleBroke) { //Build Upward. First Half Angle Right, Then Angle Left (yaw) CommandHandeler commandHandeler = new CommandHandeler(); List <Command> commands = new List <Command>(); for (int i = 0; i < 24; i++) { commands.Add(new Command(true, TrackType.Custom, new Orientation(.5f, Globals.STANDARD_ANGLE_CHANGE, 0))); } for (int i = 0; i < 24; i++) { commands.Add(new Command(true, TrackType.Custom, new Orientation(-.5f, Globals.STANDARD_ANGLE_CHANGE, 0))); } return(commandHandeler.Run(commands, tracks, chunks, tracksStarted, tracksFinshed, ref ruleBroke)); //int x = myTracks.Count; //double theLastAngle = 0; //Vector3 origen = new Vector3(); //int tracksBuilt = 0; ////Remove Tracks First //for (int i = 0; i < (15 * 3); i++) //{ // if (!(directions.Last() == Direction.Up || directions.Last() == Direction.Special) || myTracks.Last().Orientation.X == 0.0f) // { // break; // } // //Safely Remove from last grouping. // RemoveTracks(1, myTracks, ref directions); //} //origen = new Vector3(7.5f, .5f, 0); //do //{ // Special = origen; // tracksBuilt += BuildTrack(Direction.Special, myTracks, ref directions); // // BulidChuckAdv(1, 1, Direction.Special, myTracks, ref directions, origen); //} //while (myTracks.Last().Orientation.X != 180.0); //origen = new Vector3(7.5f, -.5f, 0); //do //{ // theLastAngle = myTracks.Last().Orientation.X; // Special = origen; // tracksBuilt += BuildTrack(Direction.Special, myTracks, ref directions); //} //while (myTracks.Last().Orientation.X != 0.0); //float TEST = myTracks.Last().Orientation.X % (float)7.5; //float TEST2 = myTracks.Last().Orientation.Y % (float)7.5; //if (TEST != 0 || TEST2 != 0) //{ // float offsetX = 0; // if (TEST != 0) // { // offsetX = myTracks.Last().Orientation.X; // while (TEST < 0) // { // offsetX = offsetX + 360; // } // offsetX = offsetX % (float)7.5; // } // float offsetY = 0; // if (TEST2 != 0) // { // offsetY = myTracks.Last().Orientation.Y; // while (TEST2 < 0) // { // offsetY = offsetY + 360; // } // offsetY = offsetY % (float)7.5; // } // Special = new Vector3(-offsetX, -offsetY, 0); // tracksBuilt += BuildTrack(Direction.Special, myTracks, ref directions); //} //Chunks.Add(tracksBuilt); // return false; }
/// <summary> /// Register a new command to the console. /// </summary> /// <param name="command">The command activate name for users</param> /// <param name="handler">The callback method when activated. <see cref="KS_ConsoleCommands">See KS_ConsoleCommands for use</see></param> /// <param name="help">The Commands help text, Displayed in console</param> /// <param name="format">Commands Paramaters format, Supported formats: $I = int, $S = string, $F = float, $B = bool</param> /// <param name="requiresAllParams">All parameters need to be filled?</param> /// <example> /// Example of the findcmd command being registered. /// /// <code language="c#"> /// KS_Console.Instance.RegisterCommand("findcmd", findCmd, "Search commands by string, page number can be used after search string", "$s $i", false); /// </code> /// </example> public void RegisterCommand(string command, CommandHandeler handler, string help, string format, bool requiresAllParams = true) { commands.Add(command, new ConsoleCommand(command, handler, help, format, requiresAllParams)); }
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); }