public void DeliveryOnBigInput() { string actual = Delivery.CreateDelivery(Inputs.ChallengeInput, 4, 40).ToString(); string expected = "PacketsNumber:1500 DronesNumber:400 Round:0 MaxRound:1000 autonomyRatio:40 maxDistance:1000 Drone.MaxPackets:4 Grid:(Rows:499 Columns:499 StartCell:R4C199 PacketNumber:1500)"; Assert.AreEqual(expected, actual); }
public void AddRoute() { StringBuilder actual = new StringBuilder(); Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 3, 10); Path path = new Path(new Cell(8, 12), delivery.Grid); Route currentRoute = path.MapRoute(Route.Specs.Route); Cell cell = new Cell(14, 17); Packet gridPacket = delivery.Grid.GetPacket(cell); actual.Append(delivery.Grid.GetPacket(cell).CurrentState.ToString() + ";"); actual.Append(delivery.Grid.GetPacket(cell).Distance + "°"); Path newRoutePath = new Path(cell, delivery.Grid, currentRoute.ReachCell); Route newRoute = newRoutePath.MapRoute(Route.Specs.Route); actual.Append(gridPacket.CurrentState.ToString() + ";"); actual.Append(gridPacket.Distance + ";"); currentRoute.AddRoute(newRoute); actual.Append(gridPacket.CurrentState.ToString() + ";"); actual.Append(gridPacket.Distance + ";"); actual.Append(currentRoute?.ToString() ?? "null"); Write.Trace($"{actual.ToString()}"); string expected = "Pending;0°Assigned;11;Assigned;19;StartCell:R4C16 ReachCell:R14C17 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R8C16(Down);R8C15(Left);R8C14(Left);R8C13(Left);R8C12(Left);R9C12(Down);R10C12(Down);R11C12(Down);R12C12(Down);R13C12(Down);R14C12(Down);R14C13(Right);R14C14(Right);R14C15(Right);R14C16(Right);R14C17(Right) Packets:R8C12(8);R14C17(19) MaxPackets:3 Distance:19"; Assert.AreEqual(expected, actual.ToString()); }
public void RouteAndGridPacketsBehaviors() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 3, 10); Cell cell = new Cell(8, 12); Path path = new Path(cell, delivery.Grid); Route route = path.MapRoute(Route.Specs.Route); StringBuilder actual = new StringBuilder(); StringBuilder expected = new StringBuilder(); Packet gridPacket = delivery.Grid.GetPacket(cell); Packet routePacket = route.Packets.Last(); actual.AppendLine($"{gridPacket};{routePacket}"); expected.AppendLine($"{gridPacket};{routePacket}"); actual.AppendLine($"{gridPacket};{routePacket}"); expected.AppendLine($"{gridPacket};{routePacket}"); path.MapRoute(Route.Specs.Route); actual.AppendLine($"{gridPacket};{routePacket}"); expected.AppendLine($"{gridPacket};{routePacket}"); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void RouteOnMapRouteDownLeft() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); Path path = new Path(new Cell(16, 7), delivery.Grid); StringBuilder actual = new StringBuilder(); Route route = path.MapRoute(Route.Specs.Route); actual.AppendLine(route?.ToString() ?? "null"); route?.Reset(); route = path.MapRoute(Route.Specs.Free); actual.AppendLine(route?.ToString() ?? "null"); route?.Reset(); route = path.MapRoute(Route.Specs.Route | Route.Specs.Alternative); actual.AppendLine(route?.ToString() ?? "null"); route?.Reset(); route = path.MapRoute(Route.Specs.Route | Route.Specs.Opposite); actual.AppendLine(route?.ToString() ?? "null"); route?.Reset(); StringBuilder expected = new StringBuilder(); expected.AppendLine("StartCell:R4C16 ReachCell:R16C7 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R8C16(Down);R8C15(Left);R8C14(Left);R8C13(Left);R8C12(Left);R9C12(Down);R10C12(Down);R11C12(Down);R12C12(Down);R13C12(Down);R14C12(Down);R15C12(Down);R16C12(Down);R16C11(Left);R16C10(Left);R16C9(Left);R16C8(Left);R16C7(Left) Packets:R8C12(8);R16C7(21) MaxPackets:3 Distance:21"); expected.AppendLine("StartCell:R4C16 ReachCell:R16C7 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R7C15(Left);R7C14(Left);R7C13(Left);R8C13(Down);R9C13(Down);R10C13(Down);R11C13(Down);R12C13(Down);R13C13(Down);R14C13(Down);R15C13(Down);R16C13(Down);R16C12(Left);R16C11(Left);R16C10(Left);R16C9(Left);R16C8(Left);R16C7(Left) Packets:R16C7(21) MaxPackets:3 Distance:21"); expected.AppendLine("StartCell:R4C16 ReachCell:R16C7 Cells:R4C15(Left);R4C14(Left);R4C13(Left);R4C12(Left);R5C12(Down);R6C12(Down);R7C12(Down);R8C12(Down);R8C11(Left);R8C10(Left);R8C9(Left);R8C8(Left);R8C7(Left);R9C7(Down);R10C7(Down);R11C7(Down);R12C7(Down);R13C7(Down);R14C7(Down);R15C7(Down);R16C7(Down) Packets:R8C12(8);R16C7(21) MaxPackets:3 Distance:21"); expected.AppendLine("StartCell:R4C16 ReachCell:R16C7 Cells:R4C17(Right);R5C17(Down);R6C17(Down);R7C17(Down);R8C17(Down);R9C17(Down);R10C17(Down);R11C17(Down);R12C17(Down);R13C17(Down);R14C17(Down);R15C17(Down);R16C17(Down);R16C18(Right);R16C19(Right);R16C0(Right);R16C1(Right);R16C2(Right);R16C3(Right);R16C4(Right);R16C5(Right);R16C6(Right);R16C7(Right) Packets:R14C17(11);R16C7(23) MaxPackets:3 Distance:23"); Write.Trace(actual.ToString()); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void RouteWait() { string editedExampleFile = System.IO.Path.Combine(Environment.CurrentDirectory, "newExample.txt"); if (System.IO.File.Exists(editedExampleFile)) { System.IO.File.Delete(editedExampleFile); } System.IO.File.Copy(Inputs.ExampleInput, editedExampleFile); System.IO.File.AppendAllText(editedExampleFile, $"{Environment.NewLine}9 13{Environment.NewLine}9 12{Environment.NewLine}8 11"); Delivery delivery = Delivery.CreateDelivery(editedExampleFile, 4, 10); Cell pack1 = new Cell(8, 11); Cell pack2 = new Cell(8, 12); Cell pack3 = new Cell(9, 12); Cell pack4 = new Cell(9, 13); Packet pa = delivery.Grid.GetPacket(pack2); delivery.Grid.SetPacketState(pack2, Packet.State.Assigned); delivery.Grid.SetPacketDistance(pack2, 0); Packet pb = delivery.Grid.GetPacket(pack4); delivery.Grid.SetPacketState(pack4, Packet.State.Assigned); delivery.Grid.SetPacketDistance(pack4, 5); Packet pc = delivery.Grid.GetPacket(pack3); delivery.Grid.SetPacketState(pack3, Packet.State.Assigned); delivery.Grid.SetPacketDistance(pack3, 5); Packet pd = delivery.Grid.GetPacket(pack1); delivery.Grid.SetPacketState(pack1, Packet.State.Assigned); delivery.Grid.SetPacketDistance(pack1, 5); Write.Trace($"{pa}, state :{pa.CurrentState}"); Write.Trace($"{pb}, state :{pb.CurrentState}"); Write.Trace($"{pc}, state :{pc.CurrentState}"); Write.Trace($"{pd}, state :{pd.CurrentState}"); Path path = new Path(new Cell(16, 7), delivery.Grid, new Cell(8, 13)); Route route = path.MapRoute(Route.Specs.All | Route.Specs.Wait); string actual = route.ToString(); Write.Trace(actual); string expected = "StartCell:R8C13 ReachCell:R16C7 Cells:R8C13(Stay);R8C13(Stay);R8C13(Stay);R8C12(Left);R9C12(Down);R10C12(Down);R11C12(Down);R12C12(Down);R13C12(Down);R14C12(Down);R15C12(Down);R16C12(Down);R16C11(Left);R16C10(Left);R16C9(Left);R16C8(Left);R16C7(Left) Packets:R16C7(17) MaxPackets:4 Distance:17"; Assert.AreEqual(expected, actual); }
public void ClosePaths() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); Path path = new Path(new Cell(8, 7), delivery.Grid); string actual = path.ClosestPendingPath(path.ReachCell).ToString(); string expected = "StartCell:R8C7 ReachCell:R8C12 Distance:5"; Assert.AreEqual(expected, actual); }
public void RouteOnMapBubble() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); Path path = new Path(new Cell(4, 16), delivery.Grid); Route route = path.MapBubbleRoute(Route.Specs.Free); string actual = route.ToString(); string expected = "StartCell:R4C16 ReachCell:R14C17 Cells:R3C16(Up);R2C16(Up);R2C17(Right);R2C18(Right);R2C19(Right);R2C0(Right);R2C1(Right);R2C2(Right);R3C2(Down);R4C2(Down);R5C2(Down);R6C2(Down);R7C2(Down);R8C2(Down);R9C2(Down);R10C2(Down);R11C2(Down);R12C2(Down);R12C1(Left);R13C1(Down);R13C0(Left);R13C19(Left);R13C18(Left);R14C18(Down);R14C17(Left) Packets:R2C2(8);R12C1(19);R14C17(25) MaxPackets:3 Distance:25"; Assert.AreEqual(expected, actual); }
public void AutonomyOnPacketsNumber() { Delivery delivery = Delivery.CreateDelivery(Inputs.ChallengeInput, 4, 40); string actual = Write.Invariant($"{Delivery.Autonomy(0)};{Delivery.Autonomy(1)};{Delivery.Autonomy(2)};{Delivery.Autonomy(3)};{Delivery.Autonomy(4)}"); string expected = "1000;960;920;880;840"; delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); actual += Write.Invariant($"{Delivery.Autonomy(0)};{Delivery.Autonomy(1)};{Delivery.Autonomy(2)};{Delivery.Autonomy(3)};{Delivery.Autonomy(4)}"); expected += "60;50;40;30;20"; Assert.AreEqual(expected, actual); }
public void RouteOnMapBubbleWithStart() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); Path path = new Path(new Cell(8, 12), delivery.Grid); Route route = path.MapBubbleRoute(Route.Specs.Free); string actual = route.ToString(); string expected = "StartCell:R4C16 ReachCell:R12C1 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R7C15(Left);R7C14(Left);R7C13(Left);R8C13(Down);R8C12(Left);R9C12(Down);R9C13(Right);R10C13(Down);R11C13(Down);R11C14(Right);R11C15(Right);R11C16(Right);R12C16(Down);R13C16(Down);R14C16(Down);R14C17(Right);R13C17(Up);R13C18(Right);R13C19(Right);R13C0(Right);R12C0(Up);R12C1(Right) Packets:R8C12(8);R14C17(19);R12C1(25) MaxPackets:3 Distance:25"; Write.Trace(actual); Assert.AreEqual(expected, actual); }
public void PerformanceFromFarthestPath() { Stopwatch timer = new Stopwatch(); timer.Start(); Delivery ndelivery = Delivery.CreateDelivery(Inputs.ChallengeInput, 4, 40); Write.Trace($"{Environment.NewLine} - - creating challenge delivery :{timer.ElapsedMilliseconds} ms{Environment.NewLine}"); timer.Restart(); List <Path> paths = new List <Path>(); foreach (ICell cell in ndelivery.Grid.Packets) { paths.Add(new Path(cell, ndelivery.Grid)); } Write.Trace($"{Environment.NewLine} - - mapping all path :{timer.ElapsedMilliseconds} ms{Environment.NewLine}"); // get farthest packet, should be distance 726 Path path = paths.OrderByDescending(x => x.Distance).Take(1).First(); timer.Restart(); Route route = path.MapRoute(Route.Specs.Route); route?.Reset(); Write.Trace($"{Environment.NewLine} - - Route ({path.Distance}) mapping time :{timer.ElapsedMilliseconds} ms{Environment.NewLine}"); timer.Restart(); route = path.MapRoute(Route.Specs.Free); route?.Reset(); Write.Trace($"{Environment.NewLine} - - Free ({path.Distance}) mapping time :{timer.ElapsedMilliseconds} ms{Environment.NewLine}"); timer.Restart(); route = path.MapRoute(Route.Specs.All); Write.Trace($"{Environment.NewLine} - - All ({path.Distance}) mapping time :{timer.ElapsedMilliseconds} ms{Environment.NewLine}"); }
public void StartScorePrint() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 2, 10); delivery.MapRoutes(); delivery.Start(); int score = delivery.Score(); List <string> moves = delivery.DronesMoves.ToList(); string filePath = $"{Environment.CurrentDirectory}\\{score}_{DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.CurrentCulture)}.txt"; File.WriteAllLines(filePath, moves); string actual = Write.Collection(File.ReadAllLines(filePath), ";") + ";score : " + score; string expected = "2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 1 0 0 0 0 0 0 0 0 0 0 0;2 4 4 4 1 1 1 4 1 4 3 4 4 3 3 3 4 4 4 3 0 0 0 0 0 0 0 0 0 0 0;1 4 4 4 1 1 1 4 4 4 4 4 4 4 4 4 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;score : 355"; Assert.AreEqual(expected, actual); }
public void Directions() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); StringBuilder actual = new StringBuilder(); actual.AppendLine(new Path(new Cell(2, 2), delivery.Grid, new Cell(12, 7)).Directions.ToString()); actual.AppendLine(new Path(new Cell(12, 1), delivery.Grid, new Cell(12, 7)).Directions.ToString()); actual.AppendLine(new Path(new Cell(16, 7), delivery.Grid, new Cell(12, 7)).Directions.ToString()); actual.AppendLine(new Path(new Cell(8, 12), delivery.Grid, new Cell(12, 7)).Directions.ToString()); actual.AppendLine(new Path(new Cell(14, 17), delivery.Grid, new Cell(12, 7)).Directions.ToString()); StringBuilder expected = new StringBuilder(); expected.AppendLine("D15 (10Up 5Left)"); expected.AppendLine("D6 (0Stay 6Left)"); expected.AppendLine("D4 (4Down 0Stay)"); expected.AppendLine("D9 (4Up 5Right)"); expected.AppendLine("D12 (2Down 10Right)"); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void AddRemoveCell() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 3, 10); Path path = new Path(new Cell(8, 12), delivery.Grid); Route route = path.MapRoute(Route.Specs.Route); route.AddCell(new RouteCell(8, 13, Drone.Direction.Right), delivery.Grid); StringBuilder actual = new StringBuilder(); actual.AppendLine(route?.ToString() ?? "null"); StringBuilder expected = new StringBuilder(); expected.AppendLine("StartCell:R4C16 ReachCell:R8C13 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R8C16(Down);R8C15(Left);R8C14(Left);R8C13(Left);R8C12(Left);R8C13(Right) Packets:R8C12(8) MaxPackets:3 Distance:9"); route.RemoveLastCell(); actual.AppendLine(route?.ToString() ?? "null"); expected.AppendLine("StartCell:R4C16 ReachCell:R8C12 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R8C16(Down);R8C15(Left);R8C14(Left);R8C13(Left);R8C12(Left) Packets:R8C12(8) MaxPackets:3 Distance:8"); Assert.AreEqual(expected.ToString(), actual.ToString()); }
private static void Main() { // create delivery Delivery delivery = Delivery.CreateDelivery(Inputs.ChallengeInput, DronesMaxPacket, AutonomyRatio); // process delivery delivery.MapRoutes(); delivery.Start(); // log delivery string filePath = Path.Combine(Environment.CurrentDirectory, delivery.Score() + ".txt"); File.WriteAllLines(filePath, delivery.DronesMoves); Write.Print($"press l for more loggin, any other key to exit"); ConsoleKeyInfo key = Console.ReadKey(); if (key.KeyChar == 'l') { MoreLoggin(delivery); } }
public void MapRoutes() { Delivery delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 2, 10); for (int i = 0; i < 3; i++) { Write.Trace($"max distance with {i} packets : {Delivery.Autonomy(i)}"); } delivery.MapRoutes(); string actual = Write.Collection(delivery.Routes, Environment.NewLine); StringBuilder expected = new StringBuilder(); expected.AppendLine("StartCell:R4C16 ReachCell:R12C1 Cells:R3C16(Up);R2C16(Up);R2C17(Right);R2C18(Right);R2C19(Right);R2C0(Right);R2C1(Right);R2C2(Right);R3C2(Down);R4C2(Down);R5C2(Down);R6C2(Down);R7C2(Down);R8C2(Down);R9C2(Down);R10C2(Down);R11C2(Down);R12C2(Down);R12C1(Left) Packets:R2C2(8);R12C1(19) MaxPackets:2 Distance:19"); expected.AppendLine("StartCell:R4C16 ReachCell:R14C17 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R7C15(Left);R7C14(Left);R7C13(Left);R8C13(Down);R8C12(Left);R9C12(Down);R9C13(Right);R10C13(Down);R11C13(Down);R11C14(Right);R11C15(Right);R11C16(Right);R12C16(Down);R13C16(Down);R14C16(Down);R14C17(Right) Packets:R8C12(8);R14C17(19) MaxPackets:2 Distance:19"); expected.Append("StartCell:R4C16 ReachCell:R16C7 Cells:R5C16(Down);R6C16(Down);R7C16(Down);R7C15(Left);R7C14(Left);R7C13(Left);R8C13(Down);R9C13(Down);R10C13(Down);R11C13(Down);R12C13(Down);R13C13(Down);R14C13(Down);R15C13(Down);R16C13(Down);R16C12(Left);R16C11(Left);R16C10(Left);R16C9(Left);R16C8(Left);R16C7(Left) Packets:R16C7(21) MaxPackets:2 Distance:21"); Write.Trace(actual); Assert.AreEqual(expected.ToString(), actual); }
public static void InitializeDelivery(TestContext context) { DroneTests.delivery = Delivery.CreateDelivery(Inputs.ChallengeInput, 4, 40); }
public static void InitializeDelivery(TestContext context) { GridTests.delivery = Delivery.CreateDelivery(Inputs.ExampleInput, 4, 10); }
public void OnTick(object sender, EventArgs e) { if (DateTime.Now.Second != _lasttime.Second) { _seconds++; _lasttime = DateTime.Now; if (_isInRace && _countdown > 0) { var screen = UIMenu.GetScreenResolutionMantainRatio(); var w = Convert.ToInt32(screen.Width / 2); _countdown--; if (_countdown > 3) { return; } _fadeoutSprite = new Sprite("mpinventory", "in_world_circle", new Point(w - 125, 200), new Size(250, 250), 0f, _countdown == 0 ? Color.FromArgb(49, 235, 126) : Color.FromArgb(241, 247, 57)); Function.Call(Hash.REQUEST_SCRIPT_AUDIO_BANK, "HUD_MINI_GAME_SOUNDSET", true); Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET"); if (_countdown == 0) { _participants.ForEach(car => car.FreezePosition = false); _missionStart = _seconds; } } else if (_isInRace && _countdown == 0) { _countdown = -1; } } GUI.MainMenu.ProcessControl(); GUI.MainMenu.ProcessMouse(); GUI.MainMenu.Draw(); _quitMenu.ProcessControl(); _quitMenu.ProcessMouse(); _quitMenu.Draw(); GUI.DrawSettings(_previewRace, _previewVehicle); _passed?.Draw(); if (_countdown > -1 && _countdown <= 3) { var screen = UIMenu.GetScreenResolutionMantainRatio(); var w = Convert.ToInt32(screen.Width / 2); new UIResText(_countdown == 0 ? "GO" : _countdown.ToString(), new Point(w, 260), 2f, Color.White, Font.Pricedown, UIResText.Alignment.Centered).Draw(); } if (_fadeoutSprite?.Color.A > 5) { _fadeoutSprite.Color = Color.FromArgb(_fadeoutSprite.Color.A - 5, _fadeoutSprite.Color.R, _fadeoutSprite.Color.G, _fadeoutSprite.Color.B); _fadeoutSprite.Draw(); } /* COURIER */ GUICourier.Init(); GUICourier.MainMenu.ProcessControl(); GUICourier.MainMenu.ProcessMouse(); var safe = UIMenu.GetSafezoneBounds(); var res = UIMenu.GetScreenResolutionMantainRatio(); new UIResRectangle(new Point(((int)res.Width - 200), 0), new Size(200, 400), Color.FromArgb(200, 0, 0, 0)).Draw(); GUICourier.MainMenu.Draw(); if (activeDeliveries.Count == 0 || (_seconds - lastSpawn > 60 && activeDeliveries.Count < 3)) { Delivery d = Delivery.CreateDelivery(); d.activate(); activeDeliveries.Add(d); lastSpawn = _seconds; UI.Notify("New delivery available"); } int pick = 0, drop = 0; Vector3 me = Game.Player.Character.Position; String posStr = String.Format("{0} {1} {2}", me.X.ToString("F02"), me.Y.ToString("F02"), me.Z.ToString("F02")); new UIResText("Pickup", new Point(Convert.ToInt32(res.Width) - 190, 20), .45f, Color.White, Font.HouseScript, UIResText.Alignment.Left) { DropShadow = true }.Draw(); new UIResText("Dropoff", new Point(Convert.ToInt32(res.Width) - 190, 210), .45f, Color.White, Font.HouseScript, UIResText.Alignment.Left) { DropShadow = true }.Draw(); foreach (Delivery d in activeDeliveries.GetRange(0, activeDeliveries.Count)) { d.tick(); if (d.isActive == false) { activeDeliveries.Remove(d); continue; } if (d._isStarted) { float dist = me.DistanceTo(d.end); String posStr2 = String.Format("{0} {1} {2}", d.end.X.ToString("F02"), d.end.Y.ToString("F02"), d.end.Z.ToString("F02")); new UIResText(String.Format("{0} {1}", dist.ToString("F02"), d.end_text), new Point(Convert.ToInt32(res.Width) - 190, 20 * (drop + 2) + 210), .35f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw(); drop++; } else { float dist = me.DistanceTo(d.start); String posStr2 = String.Format("{0} {1} {2}", d.start.X.ToString("F02"), d.start.Y.ToString("F02"), d.start.Z.ToString("F02")); new UIResText(String.Format("{0} {1}", dist.ToString("F02"), d.start_text), new Point(Convert.ToInt32(res.Width) - 190, 20 * (pick + 2)), .35f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw(); pick++; } //new UIResText("WORLD", new Point(Convert.ToInt32(res.Width) - 190, 40), .35f, Color.DodgerBlue, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw(); } /* COURIER */ if (!_isInRace) { if (GUI.IsInMenu) { return; } foreach (var race in _races) { World.DrawMarker(MarkerType.VerticalCylinder, race.Trigger, new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(5f, 5f, 1f), Color.FromArgb(200, 255, 255, 255)); if (!Game.Player.Character.IsInRangeOf(race.Trigger, 50f)) { continue; } var tmpSF = new Scaleform(0); tmpSF.Load("PLAYER_NAME_01"); tmpSF.CallFunction("SET_PLAYER_NAME", race.Name); tmpSF.Render3D(race.Trigger + new Vector3(0f, 0f, 2f), new Vector3(0f, 0f, _oldAngle), new Vector3(12, 6, 2)); var tmpT = new Scaleform(0); tmpT.Load("PLAYER_NAME_02"); tmpT.CallFunction("SET_PLAYER_NAME", "Community Race"); tmpT.Render3D(race.Trigger + new Vector3(0f, 0f, 1.5f), new Vector3(0f, 0f, _oldAngle), new Vector3(6, 3, 1)); _oldAngle += 2f; if (!Game.Player.Character.IsInRangeOf(race.Trigger, 5f)) { continue; } Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING"); Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, "Press ~INPUT_CONTEXT~ to participate in this Community Race."); Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1); if (Game.IsControlJustPressed(0, GTA.Control.Context)) { Game.Player.CanControlCharacter = false; Game.Player.Character.Position = race.Trigger + new Vector3(4f, 0f, -1f); _previewRace = race; BuildMenu(race); GUI.MainMenu.Visible = true; GUI.IsInMenu = true; break; } } } else if (_isInRace) { if (!_raceSettings["Wanted"]) { Function.Call(Hash.SET_MAX_WANTED_LEVEL, 0); } //if(Game.Player.Character.IsInVehicle()) Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)GTA.Control.VehicleExit); if ((Game.IsControlJustPressed(0, GTA.Control.VehicleExit) && Game.Player.Character.IsInVehicle()) || (!Game.Player.Character.IsInVehicle() && !Game.Player.Character.IsGettingIntoAVehicle && Game.IsControlJustPressed(0, GTA.Control.Enter))) { _quitMenu.RefreshIndex(); _quitMenu.Visible = !_quitMenu.Visible; } if (!Convert.ToBoolean(_raceSettings["Traffic"])) { Vehicle[] close = World.GetNearbyVehicles(Game.Player.Character, 10000f); foreach (Vehicle vehicle in close) { if (_currentRivals.Any(riv => riv.Vehicle.Handle == vehicle.Handle) || Game.Player.Character.IsInVehicle(vehicle)) { continue; } vehicle.GetPedOnSeat(VehicleSeat.Driver)?.Delete(); vehicle?.Delete(); } } // var res = UIMenu.GetScreenResolutionMantainRatio(); // var safe = UIMenu.GetSafezoneBounds(); const int interval = 45; if (_countdown <= 0) { new UIResText("TIME", new Point(Convert.ToInt32(res.Width) - safe.X - 180, Convert.ToInt32(res.Height) - safe.Y - (90 + (1 * interval))), 0.3f, Color.White).Draw(); new UIResText(FormatTime((int)unchecked (_seconds - _missionStart)), new Point(Convert.ToInt32(res.Width) - safe.X - 20, Convert.ToInt32(res.Height) - safe.Y - (102 + (1 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point(Convert.ToInt32(res.Width) - safe.X - 248, Convert.ToInt32(res.Height) - safe.Y - (100 + (1 * interval))), new Size(250, 37), 0f, Color.FromArgb(200, 255, 255, 255)).Draw(); new UIResText("POSITION", new Point(Convert.ToInt32(res.Width) - safe.X - 180, Convert.ToInt32(res.Height) - safe.Y - (90 + (2 * interval))), 0.3f, Color.White).Draw(); new UIResText((CalculatePlayerPositionInRace() + 1) + "/" + (_currentRivals.Count + 1), new Point(Convert.ToInt32(res.Width) - safe.X - 20, Convert.ToInt32(res.Height) - safe.Y - (102 + (2 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point(Convert.ToInt32(res.Width) - safe.X - 248, Convert.ToInt32(res.Height) - safe.Y - (100 + (2 * interval))), new Size(250, 37), 0f, Color.FromArgb(200, 255, 255, 255)).Draw(); if (_raceSettings["Laps"] > 1) { int playerCheckpoint = _currentRace.Checkpoints.Length - _checkpoints.Count; int currentLap = Convert.ToInt32(Math.Floor(playerCheckpoint / (decimal)_totalLaps)) + 1; new UIResText("LAP", new Point(Convert.ToInt32(res.Width) - safe.X - 180, Convert.ToInt32(res.Height) - safe.Y - (90 + (3 * interval))), 0.3f, Color.White).Draw(); new UIResText(currentLap + "/" + _raceSettings["Laps"], new Point(Convert.ToInt32(res.Width) - safe.X - 20, Convert.ToInt32(res.Height) - safe.Y - (102 + (3 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point(Convert.ToInt32(res.Width) - safe.X - 248, Convert.ToInt32(res.Height) - safe.Y - (100 + (3 * interval))), new Size(250, 37), 0f, Color.FromArgb(200, 255, 255, 255)).Draw(); } } for (int i = 0; i < _rivalCheckpointStatus.Count; i++) { Tuple <Rival, int> tuple = _rivalCheckpointStatus[i]; if (tuple.Item1.Vehicle.IsInRangeOf(_currentRace.Checkpoints[tuple.Item2], 10f)) { tuple.Item1.Character.Task.ClearAll(); if (_currentRace.Checkpoints.Length <= tuple.Item2 + 1) { if (!_finishedParticipants.Contains(tuple.Item1)) { _finishedParticipants.Add(tuple.Item1); } tuple.Item1.Vehicle.HandbrakeOn = true; continue; } _rivalCheckpointStatus[i] = new Tuple <Rival, int>(tuple.Item1, tuple.Item2 + 1); Function.Call(Hash.TASK_VEHICLE_MISSION_COORS_TARGET, tuple.Item1.Character.Handle, tuple.Item1.Vehicle.Handle, _currentRace.Checkpoints[tuple.Item2 + 1].X, _currentRace.Checkpoints[tuple.Item2 + 1].Y, _currentRace.Checkpoints[tuple.Item2 + 1].Z, Mode, 200f, Rival.MainDrivingStyle, 5f, 0f, 0); // TODO: Debuggin // old - 6 } } World.DrawMarker(MarkerType.VerticalCylinder, _checkpoints[0], new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(10f, 10f, 2f), Color.FromArgb(100, 241, 247, 57)); if (_nextBlip == null) { _nextBlip = World.CreateBlip(_checkpoints[0]); } if (_checkpoints.Count >= 2) { if (_secondBlip == null) { _secondBlip = World.CreateBlip(_checkpoints[1]); _secondBlip.Scale = 0.5f; if (_checkpoints.Count == 2) { _secondBlip.Sprite = BlipSprite.RaceFinish; } } Vector3 dir = _checkpoints[1] - _checkpoints[0]; dir.Normalize(); World.DrawMarker(MarkerType.ChevronUpx1, _checkpoints[0] + new Vector3(0f, 0f, 2f), dir, new Vector3(60f, 0f, 0f), new Vector3(4f, 4f, 4f), Color.FromArgb(200, 87, 193, 250)); } else { Vector3 dir = Game.Player.Character.Position - _checkpoints[0]; dir.Normalize(); World.DrawMarker(MarkerType.CheckeredFlagRect, _checkpoints[0] + new Vector3(0f, 0f, 2f), dir, new Vector3(0f, 0f, 0f), new Vector3(4f, 4f, 4f), Color.FromArgb(200, 87, 193, 250)); _nextBlip.Sprite = BlipSprite.RaceFinish; } if (Game.Player.Character.IsInVehicle() && Game.Player.Character.IsInRangeOf(_checkpoints[0], 10f)) { Function.Call(Hash.REQUEST_SCRIPT_AUDIO_BANK, "HUD_MINI_GAME_SOUNDSET", true); Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET"); _checkpoints.RemoveAt(0); _nextBlip?.Remove(); _secondBlip?.Remove(); _nextBlip = null; _secondBlip = null; if (_checkpoints.Count == 0) { Game.Player.CanControlCharacter = false; Function.Call(Hash._START_SCREEN_EFFECT, "HeistCelebPass", 0, true); if (Game.Player.Character.IsInVehicle()) { Game.Player.Character.CurrentVehicle.HandbrakeOn = true; } World.DestroyAllCameras(); World.RenderingCamera = World.CreateCamera(GameplayCamera.Position, GameplayCamera.Rotation, 60f); Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_UNDER_THE_BRIDGE", "HUD_MINI_GAME_SOUNDSET"); int position = _finishedParticipants.Count + 1; int peoplecount = _currentRivals.Count + 1; int score = 100 - ((position - 1) * 10); if (score < 0) { score = 0; } _passed = new MissionPassedScreen(_currentRace.Name, score, score > 50 ? score > 90 ? MissionPassedScreen.Medal.Gold : MissionPassedScreen.Medal.Silver : MissionPassedScreen.Medal.Bronze); _passed.AddItem("Time Elapsed", FormatTime((int)unchecked (_seconds - _missionStart)), MissionPassedScreen.TickboxState.None); _passed.AddItem("Position", position + "/" + peoplecount, position == 1 ? MissionPassedScreen.TickboxState.Tick : MissionPassedScreen.TickboxState.Empty); _passed.OnContinueHit += () => { Game.FadeScreenOut(1000); Wait(1000); Function.Call(Hash._STOP_SCREEN_EFFECT, "HeistCelebPass"); Game.Player.Character.Position = _currentRace.Trigger; Game.Player.CanControlCharacter = true; World.RenderingCamera = null; EndRace(); _passed = null; Game.FadeScreenIn(1500); }; _passed.Show(); _isInRace = false; } } } }