drabont

Space Engineers - SPCE HACK 4 big grids

Apr 27th, 2021 (edited)
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. //instruction: https://youtu.be/cfX7hymQsiM
  2. List<T> gts<T>(Func<T, bool>b=null) where T:class {b=b??(x=>true);List<T>l=new List<T>();
  3. Func<T,bool>f=x=>((IMyTerminalBlock)x).IsSameConstructAs(Me);GridTerminalSystem.GetBlocksOfType(l,k=>f(k)&&b(k));return l;}
  4. public Program() { m = Me.GetSurface(0); m.ContentType = ContentType.TEXT_AND_IMAGE; m.FontSize = 26.4f/21;
  5.   m.TextPadding = 0; m.Font = "Monospace"; m.FontColor = Color.DarkSlateGray; m.BackgroundColor = Color.Black;
  6.   sm = sMain(); Runtime.UpdateFrequency = UpdateFrequency.Update10;}
  7. IMyTextSurface m; IEnumerator sm; IMyCubeGrid tg; string s; int j;
  8. public void Main(string arg) { tg= gts<IMyShipConnector>()?.First().OtherConnector?.CubeGrid;
  9.   if ( tg != null ) sm.MoveNext(); else { sm = sMain(); s = $"{"search".PadRight(j<21?++j:j=0,'.')}\n";}
  10.   m.WriteText($"SPCE HACK v0.1 by SWG\n{"".PadRight(21,'≡')}\n{s}{sm.Current}"); var і=Runtime;
  11.   Echo($"{System.DateTime.Now} :{і.LastRunTimeMs:F2} {і.CurrentInstructionCount} {і.CurrentCallChainDepth}\n");}
  12. public IEnumerator sMain() {
  13.   yield return ""; var cl = new List <IMyCubeBlock>();
  14.   var p = (tg.Max - tg.Min +1).Volume(); int i=0; string ts="";  
  15.   s=$"get {(tg.IsStatic?"base":"ship")} {tg.Name}\ngid {tg.EntityId}\n"; yield return "";
  16.   foreach (var v in Vector3I.EnumerateRange(tg.Min, tg.Max +1) ) { var cb =tg.GetCubeBlock(v)?.FatBlock; if (cb!=null) cl.Add( cb );
  17.     if (++i%(p/100)==0 || i==p) yield return ts=$"scan {100*i/p,3}% from {p}c\n{"".PadRight(21*i/p,'≡')}\nfound{cl.Count,5} raw blocks";};
  18.   var fb = cl.Distinct(); s=$"total{fb.Count(),5} flt blocks\n{"".PadRight(21,'≡')}\n"; yield return "";
  19.   //do what we need with blocks in fb
  20.   var ftur = from b in fb where b is IMyLargeTurretBase select b as IMyLargeTurretBase;
  21.   var ftim = from b in fb where b is IMyTimerBlock select b as IMyTimerBlock;
  22.   var fdor = from b in fb where b is IMyDoor select b as IMyDoor;
  23.   foreach (var b in ftur) b.Enabled = false;
  24.   foreach (var b in ftim) b.StopCountdown();
  25.   foreach (var b in fdor) b.OpenDoor();
  26.   s+= $"disabled {ftur.Count()} turrets\nstopped {ftim.Count()} timers\nopened {fdor.Count()} doors\n{"".PadRight(21,'≡')}\nSPCE HACK complete...";
  27.   yield return "";
  28. }
Add Comment
Please, Sign In to add comment