klassekatze

KTZInv

Jan 24th, 2024 (edited)
2,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 40.21 KB | None | 0 0
  1.     static public double maxMsPerSETickReal = 0.05;
  2.  
  3.     static bool USE_SKITS = false;//whether to use survival kits in autocrafting
  4.     static bool ASSEMBLE = true;//auto assemble items to the quota dictated by Autocraft LCD
  5.     static bool DISASSEMBLE = true;//auto disassemble items in excess of quota
  6.     static bool PRIORITY_DISASSEMBLE = true;// if true, disassemble then assemble. else assemble then disassemble.
  7.     static int ASSEMBLE_MARGIN = 50;//margin of error around quota before doing any of that
  8.  
  9.     //static bool ASM_FLUSH = false;//whether to periodically clear inputs of an assembler that is not producing
  10.     static bool ASM_SHUFFLE = false;//whether to periodically move the first item to back of queue if not producing
  11.  
  12.     //static bool NEVER_SORT_REFINERIES = false;
  13.     //static bool NEVER_SORT_REACTORS = true;//sorting reactors can reset their work state
  14.  
  15.     static string AUTOCRAFT_LCD_KEYWORD = "KTZ Autocraft";
  16.  
  17.     static int connectEventInterval = 10;
  18.     static UpdateFrequency updateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update10 | UpdateFrequency.Update100;
  19.  
  20.  
  21.     static int MAX_TRANSFERS_PER_OP = 4;
  22.     //moving items is fundamentally expensive, moreso that it seems. this limits the amount of actual stacks moved in a given operation.
  23.     //Lower numbers make performance more consistent and thus reliable with things like pblimiter, but
  24.     //can result in it taking several passes over the grid to get things to their final destinations if things are sufficiently disordered.
  25.     static double MAX_TRANSFER_MS = 0.05;//secondary sancheck
  26.  
  27.     static bool SORT = true;//whether to do any of that item sorting stuff at all.
  28.                             //Note: Even if sorting isn't otherwise used, input flushing of jammed assemblers won't
  29.                             //happen without a tagged cargo for Ingots, Components
  30.     static bool MERGE_STACKS = true;
  31.     //whether to merge multiple stacks of the same itemtype in a given container when possible
  32.     //could cause desync, they say? idk. stacks should only be fragmented like this by player action
  33.  
  34.     static bool ISYCOMPAT = true;
  35.  
  36.     //these are blocks by DefinitionDisplayNameText
  37.     //containers that cannot or should not be managed, ever, typically due to lack of conveyor support
  38.     static string[] ignoreBlockTypes = {
  39. "Cargo Crate",
  40. "Lockers",
  41. "Armory Lockers",
  42. "Armory",
  43. "Weapon Rack",
  44. "Control Seat",
  45. "Parachute Hatch",
  46. "Control Station",
  47. "Vending Machine"    };
  48.  
  49.     //PERFORMANCE CONTROLS
  50.     static bool CARGODBG = false;
  51.     static public int blockInterval = 5;//ticks to wait for next block scan when nothing has been moved
  52.     static public int blockIntervalMove = 15;//ticks to wait if the last op required moving items around
  53. class L{List<A>B=new List<A>();class A{public C D=null;public int E=0,F=0;}public L(){foreach(var J in Program.G){var H=
  54. new C();H.I=J;var K=new A();K.D=H;B.Add(K);}}Dictionary<MyDefinitionId,List<IMyAssembler>>M=new Dictionary<MyDefinitionId,
  55. List<IMyAssembler>>();int N=0;public void b(){N=(N+1)%G.Count;if(O%10==0&&G.Count>0){var P=B[N];var I=G[N];if(I.IsQueueEmpty
  56. ||I.IsProducing||!I.Enabled){P.E=P.F=O;}else{if(O-P.E>60*17){Q("flushing "+I.CustomName);List<MyInventoryItem>R=new List<
  57. MyInventoryItem>();I.InputInventory.GetItems(R);List<MyInventoryItem>S=new List<MyInventoryItem>();I.OutputInventory.GetItems(S);R.
  58. AddRange(S);foreach(var Y in R){var W=T.U.V(I);T.X(W,Y.Type,Y.Amount,true);}P.E=O;}if(O-P.F>60*30){Q("rear shuffling "+I.
  59. CustomName);List<MyProductionItem>Z=new List<MyProductionItem>();I.GetQueue(Z);if(Z.Count>1){var a=Z[0];I.RemoveQueueItem(0,a.
  60. Amount);I.AddQueueItem(a.BlueprintId,a.Amount);}P.E=P.F=O;}}}}public void f(MyDefinitionId c,MyAssemblerMode d){foreach(var J
  61. in G){if(J.Mode!=d){List<MyProductionItem>Z=new List<MyProductionItem>();J.GetQueue(Z);for(var e=0;e<Z.Count;e++){var Y=Z[
  62. e];if(Y.BlueprintId==c){J.RemoveQueueItem(e,Y.Amount);Z.RemoveAt(e);e--;}}}}}public void w(MyAssemblerMode d,Dictionary<
  63. MyDefinitionId,MyFixedPoint>g=null){Dictionary<MyDefinitionId,MyFixedPoint>h=new Dictionary<MyDefinitionId,MyFixedPoint>();Dictionary<
  64. IMyAssembler,List<MyProductionItem>>i=new Dictionary<IMyAssembler,List<MyProductionItem>>();foreach(var J in G){if(J.Mode!=d){J.
  65. ClearQueue();J.Mode=d;}{List<MyProductionItem>Z=new List<MyProductionItem>();J.GetQueue(Z);for(var e=0;e<Z.Count;e++){var Y=Z[e];
  66. if(Y.Amount<(MyFixedPoint)1){J.RemoveQueueItem(e,Y.Amount);Z.RemoveAt(e);e--;}else{var c=Y.BlueprintId;if(h.ContainsKey(c)
  67. )h[c]+=Y.Amount;else h[c]=Y.Amount;}}i[J]=Z;}}if(g!=null){foreach(var k in g){MyFixedPoint j=0;h.TryGetValue(k.Key,out j)
  68. ;if(d==MyAssemblerMode.Assembly&&k.Value>j)h[k.Key]=k.Value;else if(d==MyAssemblerMode.Disassembly&&-k.Value>j)h[k.Key]=-
  69. k.Value;}}foreach(var k in h){var c=k.Key;var l=k.Value;List<IMyAssembler>m=new List<IMyAssembler>();foreach(var J in G){
  70. if(J.Mode==d&&J.CanUseBlueprint(c))m.Add(J);}if(m.Count==0)continue;int n=(int)l/m.Count;int o=(int)l-(n*(m.Count-1));for(
  71. int e=0;e<m.Count;e++){var I=m[e];var Z=i[I];var p=e==(m.Count-1)?o:n;if(p>-1&&p<1)p=0;MyProductionItem q=new
  72. MyProductionItem();int r=-1;for(var s=0;s<Z.Count;s++){var t=Z[s];if(t.BlueprintId==c){q=t;r=s;break;}}if(r!=-1){var u=q.Amount;var v=p-
  73. u;if(Math.Abs((int)v)>=3){I.InsertQueueItem(r,c,v);}}else if(p!=0)I.AddQueueItem(c,(MyFixedPoint)p);}}}static x y=new x(
  74. "asmshuf"),z=new x("asmbal");public void ª(){foreach(var H in B)H.D.ª();if(!µ.º)return;y.K();if(O%60*15==0){if(ASM_SHUFFLE)b();}y
  75. .s();z.K();z.s();if(O%60==0&&O-µ.À<=60){Dictionary<MyDefinitionId,MyFixedPoint>Á=new Dictionary<MyDefinitionId,
  76. MyFixedPoint>();foreach(var H in B){foreach(var e in H.D.Â){if(!Á.ContainsKey(e.BlueprintId))Á.Add(e.BlueprintId,e.Amount);else Á[e.
  77. BlueprintId]+=e.Amount;}}Dictionary<MyDefinitionId,MyFixedPoint>h=new Dictionary<MyDefinitionId,MyFixedPoint>();int Ã=0;int Ä=0;
  78. foreach(var k in Å.Æ){var Ç=k.Key;var É=Å.È[Ç];var Ê=k.Value;MyFixedPoint Ë=0;T.Ì.Í.TryGetValue((MyItemType)Ç,out Ë);if(
  79. ASSEMBLE&&Ë+ASSEMBLE_MARGIN<Ê){h[É]=Ê-Ë;Ã+=1;}if(DISASSEMBLE&&Ë-ASSEMBLE_MARGIN>Ê){h[É]=Ê-Ë;Ä+=1;}}if(h.Count>0){if(Ã==0&&Ä!=0){
  80. foreach(var K in G)if(K.IsQueueEmpty)K.Mode=MyAssemblerMode.Disassembly;}else if(Ã!=0&&Ä==0){foreach(var K in G)if(K.
  81. IsQueueEmpty)K.Mode=MyAssemblerMode.Assembly;}bool Î=false;bool Ï=false;foreach(var k in h){if(ASSEMBLE&&k.Value>0)Î=true;else if(
  82. DISASSEMBLE&&k.Value<-ASSEMBLE_MARGIN)Ï=true;}if(Î&&(Ï==false||PRIORITY_DISASSEMBLE==false)){foreach(var k in h){if(k.Value>0)f(k.
  83. Key,MyAssemblerMode.Assembly);}w(MyAssemblerMode.Assembly,h);}else if(Ï&&(Î==false||PRIORITY_DISASSEMBLE==true)){foreach(
  84. var k in h){if(k.Value<0)f(k.Key,MyAssemblerMode.Disassembly);}w(MyAssemblerMode.Disassembly,h);}}}}}class Å{static public
  85. MyItemType Ð=MyItemType.MakeComponent("SteelPlate");static Dictionary<string,MyItemType>Ñ=new Dictionary<string,MyItemType>();
  86. public static bool Õ(string Ò,out MyItemType Ó){if(Ñ.ContainsKey(Ò)){Ó=Ñ[Ò];return true;}foreach(var Ô in È){if(Ô.Key.
  87. SubtypeId.ToString()==Ò){Ñ[Ò]=Ô.Key;Ó=Ô.Key;return true;}}Ó=Ð;return false;}static public Dictionary<string,int>Ö=new Dictionary<
  88. string,int>();static public Dictionary<MyDefinitionId,int>Æ=new Dictionary<MyDefinitionId,int>();static public Dictionary<
  89. MyDefinitionId,MyDefinitionId>È=new Dictionary<MyDefinitionId,MyDefinitionId>();static public void Ú(MyDefinitionId Ø,MyDefinitionId c
  90. ){È[Ø]=c;Ù();}static public void Ù(){string Û="KTZINV;\nitemID;blueprintID";foreach(var k in È){Û+="\n"+k.Key.ToString()+
  91. ";"+k.Value.ToString();}Ü.Me.CustomData=Û;}public Å(){var Ý=Ü.Me.CustomData;var Þ=Ý.Split('\n');foreach(var H in Þ){var ß=H
  92. .Split(';');if(ß.Length>=2){try{var Ç=MyDefinitionId.Parse(ß[0]);try{var É=MyDefinitionId.Parse(ß[1]);È[Ç]=É;}catch(
  93. Exception){}}catch(Exception){}}}}static x à=new x("p1"),á=new x("p2"),â=new x("p3");public string ê(){à.K();Dictionary<string,
  94. int>ã=new Dictionary<string,int>();foreach(var k in T.Ì.Í){string Ò=k.Key.SubtypeId;if(!Ö.ContainsKey(Ò)){var ä=k.Key.
  95. GetItemInfo();if(!ä.IsOre&&!ä.IsIngot)Ö[Ò]=0;else{MyItemType å=Å.Ð;if(Õ(Ò,out å)){Ö[Ò]=0;break;}}}ã[Ò]=(int)k.Value;}à.s();á.K();
  96. StringBuilder æ=new StringBuilder("Component Current | Wanted\n");foreach(var k in Ö){int ç=0;int è=k.Value;ã.TryGetValue(k.Key,out ç
  97. );æ.Append(k.Key);æ.Append(" ");æ.Append(ç);æ.Append(" ");if(ç<è)æ.Append("<");else if(ç==è)æ.Append("=");else æ.Append(
  98. ">");æ.Append(" ");æ.Append(è);bool é=false;â.K();foreach(var Ô in È){if(Ô.Key.SubtypeId.ToString()==k.Key){é=true;Æ[Ô.Key]
  99. =è;break;}}â.s();if(!é)æ.Append(" (no BP)");æ.Append("\n");}á.s();return æ.ToString();}string ë="";public void ô(string K
  100. ){if(ë==K)return;ë=K;var ì=K.Split('\n');foreach(var H in ì){if(H.Contains("|"))continue;var í=H.Split(new char[]{' '},
  101. StringSplitOptions.RemoveEmptyEntries);if(í.Length>=4){string î=í[0];string ï=í[1];char ð=í[2][0];if(ð=='<'||ð=='>'||ð=='='){string ñ=í[3]
  102. ;int ò=0;var ó=int.TryParse(ñ,out ò);if(ó){Ö[î]=ò;}}}}}}class C{public IMyAssembler I=null;public int õ=0;static
  103. MyDefinitionId Ð=MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SpaceCredit");public List<MyProductionItem>Â=new List<
  104. MyProductionItem>();List<MyInventoryItem>ö=new List<MyInventoryItem>();float ø=-1;static x D=new x("bpl");DateTime ù=DateTime.Now;public
  105. void ª(){D.K();if(O%60==0&&I.Mode==MyAssemblerMode.Assembly){ù=DateTime.Now;var ú=I.CurrentProgress;List<MyProductionItem>Z=
  106. new List<MyProductionItem>();List<MyInventoryItem>û=new List<MyInventoryItem>();I.GetQueue(Z);if(Z.Count!=0||Â.Count!=0){I.
  107. OutputInventory.GetItems(û);List<MyItemType>ü=new List<MyItemType>();List<MyInventoryItem>ý=new List<MyInventoryItem>();foreach(var e
  108. in û){var Ó=e.Type;if(ü.Contains(Ó))continue;ü.Add(Ó);MyFixedPoint þ=0;foreach(var ÿ in û){if(ÿ.Type==Ó)þ+=ÿ.Amount;}if(þ>
  109. 0){ý.Add(new MyInventoryItem(e.Type,e.ItemId,þ));}}û=ý;if(Â.Count>0){MyDefinitionId Ā=Ð;foreach(var ă in Â){bool ā=false;
  110. foreach(var Ă in Z){if(Ă.ItemId==ă.ItemId&&Ă.BlueprintId==ă.BlueprintId){ā=true;if(Ă.Amount<ă.Amount){Ā=ă.BlueprintId;break;}}}
  111. if(Ā!=Ð)break;if(!ā){Ā=ă.BlueprintId;break;}}if(Ā!=Ð){MyDefinitionId Ą=Ð;foreach(var e in û){bool ą=true;foreach(var Ć in
  112. ö){if(Ć.Type==e.Type)ą=false;if(Ć.Type==e.Type&&Ć.Amount<e.Amount){try{var t=MyDefinitionId.Parse(e.Type.TypeId+"/"+e.
  113. Type.SubtypeId);Ą=t;ą=false;break;}catch(Exception){}}}if(ą){try{var t=MyDefinitionId.Parse(e.Type.TypeId+"/"+e.Type.
  114. SubtypeId);Ą=t;}catch(Exception){}}if(Ą!=Ð)break;}if(Ā!=Ð&&Ą!=Ð){õ=O;if(!Å.È.ContainsKey(Ą)){Q("Learned recipe "+Ą.ToString()+";"
  115. +Ā.ToString(),ć.Ĉ);Å.Ú(Ą,Ā);}}}}}if(Â.Count==0)ú=0;ø=ú;Â=Z;ö=û;}D.s();}}class T{public static ĉ Ì=new ĉ();public static
  116. Dictionary<string,MyFixedPoint>Ċ=new Dictionary<string,MyFixedPoint>();public static List<MyItemType>ċ=new List<MyItemType>();
  117. static Dictionary<string,MyItemType>Č=new Dictionary<string,MyItemType>();static MyItemType ď(string č,string Ò){var Ď=č+"/"+Ò
  118. ;if(Č.ContainsKey(Ď))return Č[Ď];else{return Č[Ď]=new MyItemType(č,Ò);}}static List<string>Đ=new List<string>(){
  119. "MyObjectBuilder_OxygenContainerObject","MyObjectBuilder_GasContainerObject","MyObjectBuilder_PhysicalGunObject","MyObjectBuilder_PhysicalObject",
  120. "MyObjectBuilder_Datapad",};static Dictionary<string,string>đ=new Dictionary<string,string>(){{"MyObjectBuilder_OxygenContainerObject","Bottles"}
  121. ,{"MyObjectBuilder_GasContainerObject","Bottles"},{"MyObjectBuilder_PhysicalGunObject","Tools"},{
  122. "MyObjectBuilder_PhysicalObject","Tools"},{"MyObjectBuilder_ConsumableItem","Tools"},{"MyObjectBuilder_Datapad","Tools"},{"MyObjectBuilder_AmmoMagazine"
  123. ,"Ammo"},{"MyObjectBuilder_Ore","Ores"},{"MyObjectBuilder_Ingot","Ingots"},{"MyObjectBuilder_Component","Components"},};
  124. public static string ē(string č){string Ē="Unknown";đ.TryGetValue(č,out Ē);return Ē;}static bool Ĕ=false;public class ĉ{public
  125. ĉ(){}public Dictionary<MyItemType,MyFixedPoint>Í=new Dictionary<MyItemType,MyFixedPoint>();public MyFixedPoint ĕ,Ė;public
  126. Dictionary<string,MyFixedPoint>ė=new Dictionary<string,MyFixedPoint>();public void g(U W){Í.Clear();ĕ=Ė=0;var ę=W.Ę(false);int Ě=0
  127. ;DateTime ě=DateTime.Now;foreach(var Ĝ in ę){var ĝ=Ĝ.MaxVolume;var Ğ=Ĝ.CurrentVolume;ĕ+=ĝ;Ė+=ĝ-Ğ;List<MyInventoryItem>R=
  128. new List<MyInventoryItem>();Ĝ.GetItems(R);Dictionary<MyItemType,int>ğ=new Dictionary<MyItemType,int>();for(int e=R.Count-1;
  129. e>=0;e--){var Ġ=R[e];if(MERGE_STACKS&&Ě<MAX_TRANSFERS_PER_OP&&ğ.ContainsKey(Ġ.Type)){var ġ=!Đ.Contains(Ġ.Type.TypeId);if(
  130. ġ){var Ģ=ğ[Ġ.Type];var ä=Ġ.Type.GetItemInfo();var ģ=R[Ģ];if(Ġ.Amount+ģ.Amount<ä.MaxStackAmount){Q(Ġ.Type.SubtypeId+
  131. " msa "+ä.MaxStackAmount+" stacking now ");Ĝ.TransferItemTo(Ĝ,Ģ,e,true);Ě++;if((DateTime.Now-ě).TotalMilliseconds>
  132. MAX_TRANSFER_MS)Ě=MAX_TRANSFERS_PER_OP;}}}ğ[Ġ.Type]=e;if(!Í.ContainsKey(Ġ.Type))Í[Ġ.Type]=Ġ.Amount;else Í[Ġ.Type]+=Ġ.Amount;var Ó=ē(Ġ.
  133. Type.TypeId);MyFixedPoint Ĥ=0;ė.TryGetValue(Ó,out Ĥ);Ĥ+=Ġ.Type.GetItemInfo().Volume*Ġ.Amount;ė[Ó]=Ĥ;}}if(Ě>0){Q(Ě+
  134. " merges in "+W.æ.CustomName+" took "+(DateTime.Now-ě).TotalMilliseconds+"ms");}foreach(var k in Í){var Ď=k.Key;if(!ċ.Contains(Ď)){ċ.
  135. Add(Ď);MyFixedPoint ĥ=(MyFixedPoint)0.01;if(!Ď.GetItemInfo().UsesFractions)ĥ=(MyFixedPoint)Ď.GetItemInfo().Volume;var Ħ=ē(Ď
  136. .TypeId);MyFixedPoint ħ=0;Ċ.TryGetValue(Ħ,out ħ);if(ĥ>ħ)ħ=ĥ;Ċ[Ħ]=ħ;}}}public void ĩ(ĉ Ć){if(Ć==null)return;List<
  137. MyItemType>Ĩ=new List<MyItemType>();foreach(var k in Ć.Í){if(Í.ContainsKey(k.Key)){var Ĝ=Í[k.Key]-k.Value;if(Ĝ>0)Í[k.Key]=Ĝ;else Ĩ
  138. .Add(k.Key);}}foreach(var Ď in Ĩ)Í.Remove(Ď);}public void Ī(ĉ Ć){if(Ć==null)return;foreach(var k in Ć.Í){if(Í.ContainsKey
  139. (k.Key))Í[k.Key]+=k.Value;else Í[k.Key]=k.Value;}}public bool Ĭ(ĉ Ć){if(Ć==null||this.Í.Count!=Ć.Í.Count)return false;
  140. foreach(var k in Í){MyFixedPoint ī=0;if(!Ć.Í.TryGetValue(k.Key,out ī))return false;else if(k.Value!=ī)return false;}foreach(var
  141. k in Ć.Í){if(!Í.ContainsKey(k.Key))return false;}return true;}}static public List<ĭ>Į=new List<ĭ>();static public ĭ ij(int
  142. į){foreach(var İ in Į)if(İ.ı==į)return İ;var IJ=new ĭ();IJ.ı=į;Į.Add(IJ);Į.Sort();return IJ;}static ĭ Ĺ(U W,string Ĵ){var ĵ=0
  143. ;for(int e=0;e<Į.Count;e++){var İ=Į[e];if(İ.ı==W.ı){ĵ=e;break;}}for(int e=0;e<ĵ;e++){var þ=Į[e];MyFixedPoint Ķ=0;þ.ķ.
  144. TryGetValue(Ĵ,out Ķ);MyFixedPoint ĸ=0;Ċ.TryGetValue(Ĵ,out ĸ);if(Ķ>ĸ)return þ;}return null;}public class ĭ:IComparable<ĭ>{int
  145. IComparable<ĭ>.CompareTo(ĭ ĺ){var IJ=this;return IJ.ı.CompareTo(ĺ.ı);}public List<U>Ļ=new List<U>();public int ı=0;public Dictionary<
  146. string,MyFixedPoint>ķ=new Dictionary<string,MyFixedPoint>();public List<string>ļ=new List<string>();public void ª(){ķ.Clear();
  147. ļ.Clear();foreach(var W in Ļ){foreach(var þ in W.ļ){if(!ļ.Contains(þ))ļ.Add(þ);MyFixedPoint ī=0;ķ.TryGetValue(þ,out ī);if
  148. (W.Ľ.Ė>ī){ķ[þ]=W.Ľ.Ė;}}}}}public class U:IComparable<U>{int IComparable<U>.CompareTo(U ĺ){var IJ=this;if(IJ.ı==ĺ.ı){return
  149. IJ.r.CompareTo(ĺ.r);}return IJ.ı.CompareTo(ĺ.ı);}public static List<U>ľ=new List<U>();public static Dictionary<
  150. IMyTerminalBlock,U>Ŀ=new Dictionary<IMyTerminalBlock,U>();public static U V(IMyTerminalBlock æ){U Ē=null;Ŀ.TryGetValue(æ,out Ē);if(Ē==
  151. null)Ē=new U(æ);return Ē;}const string ŀ="MyObjectBuilder_",Ł="alltypes";public static int ł=0;public int r=0;public U(
  152. IMyTerminalBlock æ){this.æ=æ;ľ.Add(this);Ŀ[æ]=this;r=ł;ł++;for(var e=0;e<æ.InventoryCount;e++){Ń.Add(æ.GetInventory(e));}if(æ is
  153. IMyProductionBlock){ń=true;var į=(IMyProductionBlock)æ;Ņ.Add(į.OutputInventory);ņ.Add(į.InputInventory);if(æ is IMyAssembler){Ň=true;ň=(
  154. IMyAssembler)æ;}}else{Ņ.AddRange(Ń);}}public IMyTerminalBlock æ=null;public ĉ Ľ=null;public List<string>ļ=new List<string>();List<
  155. IMyInventory>Ņ=new List<IMyInventory>();List<IMyInventory>ņ=new List<IMyInventory>(),Ń=new List<IMyInventory>();public List<
  156. IMyInventory>Ę(bool ʼn){if(ʼn)return Ń;else{if(ň!=null&&ň.Mode==MyAssemblerMode.Disassembly)return ņ;return Ņ;}}public bool ń=false,Ň=
  157. false,Ŋ=false,ŋ=true,Ō=false,ō=false;IMyAssembler ň=null;public Dictionary<MyItemType,MyFixedPoint>Ŏ=new Dictionary<
  158. MyItemType,MyFixedPoint>();const int ŏ=100000;public int ı=int.MaxValue;public string Ő="-31234",ő="-234523";void Œ(){ŋ=true;Ŋ=
  159. false;}void œ(){ŋ=true;Ō=true;Ŋ=false;}public void ş(){if(æ.CustomName!=ő){ő=æ.CustomName;var Ŕ=ı;ı=ŏ;Ŋ=false;ŋ=false;Ō=false
  160. ;ō=false;var Ó=ő.Split(' ','.');ļ.Clear();if(ignoreBlockTypes.Contains(æ.DefinitionDisplayNameText))Œ();if(!Ō){foreach(
  161. var í in Ó){var ŕ=í.ToLower();if(ŕ.StartsWith("[")&&ŕ.EndsWith("]")){ŕ=ŕ.Substring(1,ŕ.Length-2);}if(ŕ=="special"){Ŋ=true;ı
  162. -=10000;}else if(ŕ=="locked"){Œ();}else if(ŕ=="hidden"){œ();}else if(ŕ.StartsWith("p")){var Ŗ=í.Substring(1);if(Ŗ=="max")ı
  163. =int.MinValue;else if(Ŗ=="min")ı=int.MaxValue;else if(Ŗ.All(char.IsDigit)){ı-=10000;int þ=0;int.TryParse(Ŗ,out þ);if(þ.
  164. ToString()==Ŗ){ı+=þ;}}}else if(ŕ==Ł){ō=true;}else{foreach(var k in đ){if(ŕ==k.Value.ToLower()){if(!ļ.Contains(k.Value))ļ.Add(k.
  165. Value);break;}}}}if(Ĕ&&!Ŋ&&!ŋ&&ļ.Count==0&&!ń){ō=true;ı+=1;}}if(Ŋ){ō=false;ļ.Clear();}if(ō){foreach(var k in đ){if(!ļ.
  166. Contains(k.Value))ļ.Add(k.Value);}}if(!Ŋ&&ļ.Count==0&&ŗ.Ř(æ)){ŋ=true;}if(Ŕ!=ı){ľ.Sort();var ř=ij(Ŕ);ř.Ļ.Remove(this);ř.ª();ř=ij(ı)
  167. ;ř.Ļ.Add(this);ř.ª();}if(!Ŋ)Ŏ.Clear();}if(Ŋ&&æ.CustomData!=Ő){if(Ŋ&&æ.CustomData==""){List<MyItemType>Ś=new List<
  168. MyItemType>();List<MyItemType>Ó=new List<MyItemType>();for(var e=0;e<æ.InventoryCount;e++){æ.GetInventory(e).GetAcceptedItems(Ó);
  169. foreach(var s in Ó)if(!Ś.Contains(s))Ś.Add(s);}List<string>ś=new List<string>();List<string>Ŝ=new List<string>();foreach(var s
  170. in Ś){MyFixedPoint l=0;Ľ.Í.TryGetValue(s,out l);if(l>0)ś.Add(s.TypeId.Substring(ŀ.Length)+"/"+s.SubtypeId+"="+l.ToString()
  171. );else Ŝ.Add(s.TypeId.Substring(ŀ.Length)+"/"+s.SubtypeId+"=0");}ś.Sort();Ŝ.Sort();if(ś.Count==0)ś.AddRange(Ŝ);æ.
  172. CustomData=String.Join("\n",ś);}if(ISYCOMPAT&&æ.CustomData.IndexOf("Special Container modes:")==-1){æ.CustomData=
  173. "@Special Container modes:\n- isycompat\n"+æ.CustomData;}Ő=æ.CustomData;Ŏ.Clear();var ì=Ő.Split('\n');foreach(var H in ì){var ŝ=H.Split('=');if(ŝ.Length==2){var Ş
  174. =ŝ[0].Split('/');if(Ş.Length==2){try{var Ó=ď(ŀ+Ş[0],Ş[1]);if(ŝ[1]=="all"){Ŏ[Ó]=int.MaxValue;}else{var þ=(MyFixedPoint)
  175. double.Parse(ŝ[1]);if(þ>0){Ŏ[Ó]=þ;}else{}}}catch(Exception){}}}}}}public void š(){ĉ Š=new ĉ();if(!Ō)Š.g(this);if(Ľ==null||!Ľ.Ĭ
  176. (Š)){if(Ľ!=null)T.Ì.ĩ(Ľ);T.Ì.Ī(Š);Ľ=Š;ij(this.ı).ª();}}public bool Ų(){if(ŋ)return false;int ţ=Ţ;Ť.g(this,null);{
  177. Dictionary<string,ĭ>ť=new Dictionary<string,ĭ>();List<MyItemType>Ŧ=new List<MyItemType>(Ľ.Í.Keys);foreach(var č in Ŧ){var Ħ=ē(č.
  178. TypeId);ĭ ŧ=null;if(!ť.ContainsKey(Ħ)){ť[Ħ]=ŧ=Ĺ(this,Ħ);}else ŧ=ť[Ħ];int Ũ=0;while(ŧ!=null&&Ũ<10){MyFixedPoint l=0;Ľ.Í.
  179. TryGetValue(č,out l);if(l==0)break;MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);l-=ũ;if(l==0)break;Ũ++;var Ū=Ċ[Ħ];U ū=null;foreach(var W
  180. in ŧ.Ļ){if(W.ļ.Contains(Ħ)&&W.Ľ.Ė>=Ū){ū=W;break;}}if(ū!=null){Ť.g(this,ū);if(l>ū.Ľ.Ė)l=ū.Ľ.Ė;var ŭ=Ŭ(this,ū,č,l,false,true
  181. );if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return true;if(ŭ>0){Ť.Q("Unable to xfer "+ŭ+" of "+č.SubtypeId);}ŧ.ª();
  182. if(ū.Ľ.Ė<Ū){ť[Ħ]=ŧ=Ĺ(this,Ħ);}}}if(Ũ==10){Ť.Q("errchk loop abort");}{if(!ļ.Contains(Ħ)&&!Ŋ){MyFixedPoint l=0;if(Ľ.Í.
  183. TryGetValue(č,out l)&&l>0){MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);if(l>ũ){X(this,č,l-ũ);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>
  184. MAX_TRANSFER_MS)return true;}}}}}}if(Ŋ){List<MyItemType>Ŧ=new List<MyItemType>(Ŏ.Keys);foreach(var k in Ľ.Í)if(!Ŧ.Contains(k.Key))Ŧ.Add
  185. (k.Key);foreach(var č in Ŧ){MyFixedPoint ů=0;Ľ.Í.TryGetValue(č,out ů);MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);if(ũ>ů&&Ľ.Ė
  186. >(MyFixedPoint)č.GetItemInfo().Volume){MyFixedPoint Ű=0;Ì.Í.TryGetValue(č,out Ű);if(Ű>ů){Ť.g(č.SubtypeId);Ť.Q(æ.
  187. CustomName+" globalchk "+č.SubtypeId+" pmove "+ũ+" "+ů);var Ē=ű(this,č,ũ-ů);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return
  188. true;if(Ē>0)Ť.Q("unable to satisfy by "+Ē);}}else if(ũ<ů){Ť.g(č.SubtypeId);Ť.Q("attempt expel "+č.SubtypeId+": "+ũ+" < "+ů+
  189. " in "+this.æ.CustomName);X(this,č,ů-ũ);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return true;}}}return Ţ-ţ>0;}}static
  190. public MyFixedPoint ű(U ū,MyItemType Ó,MyFixedPoint ī){Ť.g(ū,null);Ť.g(Ó.SubtypeId);var ä=Ó.GetItemInfo();int ĵ=U.ľ.IndexOf(ū)
  191. ;Ť.Q("pidx="+ĵ);Ť.Q("BlockInventory.bPriorityList.Count="+U.ľ.Count);for(var e=U.ľ.Count-1;e>ĵ;e--){var ų=U.ľ[e];Ť.g(ū,ų)
  192. ;if(ų.Ľ!=null&&ų.Ľ.Í.ContainsKey(Ó)){MyFixedPoint ã=ų.Ľ.Í[Ó];Ť.Q(ų.æ.CustomName+"has item, stock "+ã);MyFixedPoint Ŵ=ã>ī?
  193. ī:ã;Ť.Q("tamt="+Ŵ);MyFixedPoint ŵ=(ų.Ľ.Ė*(MyFixedPoint)(1/ä.Volume));if(!ä.IsOre&&!ä.IsIngot)ŵ=MyFixedPoint.Floor(ŵ+(
  194. MyFixedPoint)0.001);if(Ŵ>ŵ)Ŵ=ŵ;Ť.Q("tamt_ma="+Ŵ);var ŭ=Ŭ(ų,ū,Ó,Ŵ);ī-=Ŵ;ī+=ŭ;}if(ī<=0)break;}return ī;}static public MyFixedPoint X(U
  195. Ŷ,MyItemType č,MyFixedPoint ŷ,bool Ÿ=false){var ä=č.GetItemInfo();var Ź=ē(č.TypeId);Ť.g(č.SubtypeId);for(var e=0;e<U.ľ.
  196. Count;e++){var ų=U.ľ[e];if(ų!=Ŷ&&!ų.ŋ){Ť.g(Ŷ,ų);MyFixedPoint l=0;MyFixedPoint ŵ=(ų.Ľ.Ė*(MyFixedPoint)(1/ä.Volume));if(!ä.
  197. IsOre&&!ä.IsIngot)ŵ=MyFixedPoint.Floor(ŵ+(MyFixedPoint)0.001);if(!ų.Ŋ&&(ų.ļ.Contains(Ź)))l=ŵ;else if(ų.Ŋ){MyFixedPoint ź=0;ų.
  198. Ľ.Í.TryGetValue(č,out ź);MyFixedPoint Ż=0;ų.Ŏ.TryGetValue(č,out Ż);if(Ż>ź){l=Ż-ź;if(l>ŵ)l=ŵ;}}if(l>0){Ť.Q("maxaccept="+ŵ)
  199. ;Ť.Q("pushing "+l+" to "+ų.æ.CustomName);var ż=Ŭ(Ŷ,ų,č,l,Ÿ,Ÿ);ŷ-=l;ŷ+=ż;}}if(ŷ<=0)break;}if(ŷ>0){StringBuilder Ž=new
  200. StringBuilder();ž(Ž,"Warning: failed to expel ",č.SubtypeId," from \"",Ŷ.ő,"\": nowhere else to store?");µ.ſ(Ž.ToString());}return ŷ;
  201. }static public MyFixedPoint Ŭ(U Ŷ,U ū,MyItemType č,MyFixedPoint ŷ,bool ƀ=false,bool Ɓ=false){Ť.g(Ŷ,ū);Ť.g(č.SubtypeId);if
  202. (ŷ==0)return 0;Ť.Q("transfer_item "+č.SubtypeId+" "+ŷ+" "+Ŷ.ő+" > "+ū.ő);var Ƃ=ŷ;foreach(var ƃ in Ŷ.Ę(ƀ)){foreach(var Ƅ
  203. in ū.Ę(Ɓ)){ŷ=Ŭ(ƃ,Ƅ,č,ŷ);if(ŷ<=0||ƅ)break;}if(ŷ<=0||ƅ)break;}if(ƅ){ƅ=false;StringBuilder Ž=new StringBuilder();ž(Ž,
  204. "Warning: xfer fail: no conveyor \"",Ŷ.ő,"\" > \"",ū.ő+"\"");µ.ſ(Ž.ToString());}if(Ƃ!=ŷ){Ŷ.š();ū.š();}return ŷ;}static int Ţ=0,Ɔ=0;static bool ƅ=false;
  205. static double Ů=0;static public MyFixedPoint Ŭ(IMyInventory Ŷ,IMyInventory ū,MyItemType č,MyFixedPoint ŷ){if(Ɔ!=O){Ɔ=O;Ů=0;}
  206. DateTime K=DateTime.Now;ƅ=false;List<MyInventoryItem>R=new List<MyInventoryItem>();Ŷ.GetItems(R);foreach(MyInventoryItem Ø in R)
  207. {if(Ø.Type==č){MyFixedPoint Ŵ=Ø.Amount>ŷ?ŷ:Ø.Amount;Ť.Q("_transfer_item "+č.SubtypeId+" "+Ŵ);var ä=č.GetItemInfo();
  208. MyFixedPoint ŵ=((ū.MaxVolume-ū.CurrentVolume)*(1f/ä.Volume));if(!ä.UsesFractions)ŵ=MyFixedPoint.Floor(ŵ+(MyFixedPoint)0.001);if(Ŵ>ŵ)
  209. {Ť.Q("_capping amt to "+ŵ);Ŵ=ŵ;}if(Ŵ>0){Ţ++;if(Ŷ.TransferItemTo(ū,Ø,Ŵ)){ŷ-=Ŵ;Ť.Q("_successfully moved "+Ŵ+" of "+Ø.Type.
  210. SubtypeId);}else{bool Ƈ=Ŷ.CanTransferItemTo(ū,č);Ť.Q("_failed to move. checkset conveyor flag");if(!Ƈ)ƅ=true;}}}if(ŷ<=0)break;}Ů
  211. +=(DateTime.Now-K).TotalMilliseconds;return ŷ;}class ƍ{bool ƈ=false;string Ɖ="Nascent.Cargo [1.7].[Barge].AllTypes.P70",Ɗ=
  212. "",Ƌ="",Ă="";U J=null;U æ=null;public void g(U J,U æ){this.J=J;this.æ=æ;}public void g(string Ø){this.Ă=Ø;}public void Q(
  213. string ƌ){if(!ƈ)return;bool H=true;if(Ɖ.Length>0&&(J==null||J.ő!=Ɖ))H=false;if(H&&Ɗ.Length>0&&(æ==null||æ.ő!=Ɗ))H=false;if(H&&
  214. Ƌ.Length>0&&Ă!=Ƌ)H=false;if(H){Program.Q(ƌ);}}}static ƍ Ť=new ƍ();public void Ƒ(List<IMyTerminalBlock>þ){List<
  215. IMyTerminalBlock>Ĩ=new List<IMyTerminalBlock>();foreach(var æ in Ǝ){if(!þ.Contains(æ))Ĩ.Add(æ);}ĉ Ə=new ĉ();foreach(var æ in Ĩ){U W=U.V(
  216. æ);T.Ì.ĩ(W.Ľ);}Ǝ.Clear();foreach(var s in þ)if(s.CubeGrid.EntityId!=Ü.Me.EntityId)Ǝ.Add(s);foreach(var s in þ)if(s.
  217. CubeGrid.EntityId==Ü.Me.EntityId)Ǝ.Add(s);Ɛ();}List<IMyTerminalBlock>Ǝ=new List<IMyTerminalBlock>();int ƒ=0;bool Ɠ=true;public
  218. bool º=false;public int Ɣ=1,À=0,ƕ=0;static x Ɩ=new x("invu");int Ɨ=0;enum Ɯ{Ƙ,ƙ,ƚ,ƛ}string[]Ɲ={"PREINIT","INIT","PROCESSING"
  219. ,"IDLE"};Ɯ ƞ=Ɯ.Ƙ;Queue<string>Ɵ=new Queue<string>();int Ơ=0;bool ơ=false;public void ſ(string K){ơ=true;Ɵ.Enqueue(K);if(Ɵ
  220. .Count>5)Ɵ.Dequeue();Ơ=O;}static x Ƣ=new x("stat");public string ƣ="";public void Ƨ(){Ƣ.K();if(O%5==0){if(ơ&&O-Ơ>10*60){ơ
  221. =false;Ɵ.Clear();}StringBuilder Ƥ=new StringBuilder();var ƥ=Ɲ[(int)ƞ];if(ƞ>=Ɯ.ƚ&&ƞ!=Ɯ.ƛ){ž(Ƥ,"Working ",ƒ+1,"/",Ǝ.Count,
  222. "\n");if(ƒ<Ǝ.Count)ž(Ƥ,Ǝ[ƒ].CustomName,"\n");}ž(Ƥ,ƥ,"\n");ž(Ƥ,Ţ+" xfer ops this runtime\n\n");foreach(var H in Ɵ)ž(Ƥ,H,"\n")
  223. ;var K=Ƥ.ToString();if(K!=ƣ){ƣ=K;if(Ʀ!=null)Ʀ.WriteText(K);}}Ƣ.s();}void ƨ(){Ɠ=false;ƕ=O-À;À=O;ƒ=0;ƞ=Ɯ.ƛ;}void Ɛ(){ƞ=Ɯ.ƙ;
  224. Ɠ=true;À=O;ƒ=0;}bool Ʃ=false;int ƪ=0,ƫ=0,Ƭ=0;static x ƭ=new x("cdbg");public void ª(){ƭ.K();if(!Ɠ&&(O-À>Ɣ)){Ɛ();if(
  225. CARGODBG&&Ʈ!=null){StringBuilder Ư=new StringBuilder();foreach(var s in U.ľ){Ư.Append(s.ı+"|||"+s.æ.CustomName+"\n");}Ʈ.
  226. WriteText(Ư.ToString());}}ƭ.s();Ɩ.K();if(Ɠ){if(ƒ>=Ǝ.Count){ƨ();Q("full run ("+Ǝ.Count+"):"+ƕ+"t ("+(ƕ/60.0d).ToString("0.0")+"s")
  227. ;º=true;Ɨ+=1;}else{var ư=blockInterval;if(Ʃ)ư=blockIntervalMove;if(O-ƪ>ư){IMyTerminalBlock Ó=Ǝ[ƒ];U W=U.V(Ó);var Ʊ=ƫ;ƫ++;
  228. if(Ʊ==0)W.š();if(Ʊ==1)W.ş();if(Ʊ==2){if(SORT){Ʃ=W.Ų();Ƭ++;}if(!Ʃ||Ƭ>10){Ƭ=0;ƪ=O;ƫ=0;ƒ++;}else{ƪ=O;ƫ--;}}ƞ=Ɯ.ƚ;}}}Ɩ.s();Ƨ()
  229. ;}}static string[]Ʋ=new string[]{"missile","ammo","magazine","torpedo","slug","box"};static Dictionary<string,string>Ƴ=
  230. new Dictionary<string,string>(){{"AngleGrinder","Grinder"},{"CrateTomato","Crate of Tomatoes"},{"HeavyArms",
  231. "Heavy Armaments"},{"GravityGenerator","Gravity Comp."},{"RadioCommunication","Radio-comm Comp."},{"Detector","Detector Comp."},{
  232. "LargeTube","Large Steel Tube"},{"Construction","Construction Comp."},{"UltimateAutomatic",""},{"AryxLynxon",""},{"TungstenUranium"
  233. ,"TU"},{"LeadSteel","LS"},{"EStabilizer","Stabilizer"}};static Dictionary<MyItemType,string>ƴ=new Dictionary<MyItemType,
  234. string>();public enum ć{Ĉ=0,Ƶ,ƶ}string[]Ʒ={"INFO","_DBG","DDBG"};public static ć Ƹ=ć.Ĉ;public static ƹ ƺ=new ƹ();public static
  235. void Q(string K,ć ƻ){ƹ.Q(K,ƻ);}public static void Q(string K){ƹ.Q(K,ć.Ĉ);}public class ƹ{public class ƾ{public ƾ(string d,
  236. string Ƽ,ć H){ƌ=d;ƽ=Ƽ;ƻ=H;}public string ƌ="",ƽ="";public int þ=1;public ć ƻ=ć.Ĉ;}static List<ƾ>ƿ=new List<ƾ>(),ǀ=new List<ƾ>(
  237. );static int ǁ=50,ǂ=1000;static public bool ǃ=true;public static void Q(string K,ć ƻ){if(ƻ>Ƹ)return;string ß=K;if(K.
  238. Length>50){List<string>í=new List<string>();while(K.Length>50){int þ=0;if(í.Count>0)þ=2;í.Add(K.Substring(0,50-þ));K=K.
  239. Substring(50-þ);}í.Add(K);K=string.Join("\n ",í);}var į=Ü;ƾ H=null;if(ƿ.Count>0){H=ƿ[ƿ.Count-1];}if(H!=null){if(H.ƌ==K)H.þ+=1;
  240. else ƿ.Add(new ƾ(K,ß,ƻ));}else ƿ.Add(new ƾ(K,ß,ƻ));if(ƿ.Count>ǁ)ƿ.RemoveAt(0);H=null;if(ǀ.Count>0){H=ǀ[ǀ.Count-1];}if(H!=
  241. null){if(H.ƌ==K)H.þ+=1;else ǀ.Add(new ƾ(K,ß,ƻ));}else ǀ.Add(new ƾ(K,ß,ƻ));if(ǀ.Count>ǂ)ǀ.RemoveAt(0);ǃ=true;}static public
  242. string DŽ="";static public void Dž(){if(!ǃ)return;StringBuilder æ=new StringBuilder();foreach(var d in ƿ){æ.Append(d.ƌ);if(d.þ>1
  243. )ž(æ," (",d.þ,")");æ.Append("\n");}string Ć=æ.ToString();ǃ=false;DŽ=Ć;}static public void LJ(){StringBuilder æ=new
  244. StringBuilder();foreach(var d in ǀ){æ.Append(d.ƌ);if(d.þ>1)ž(æ," (",d.þ,")");æ.Append("\n");}string Ć=æ.ToString();dž[0].CustomData=Ć;
  245. Q(dž[0].CustomName,ć.Ĉ);}}static void ž(StringBuilder æ,params object[]Lj){foreach(object J in Lj){æ.Append(J.ToString());}}
  246. public class x{static bool lj=true;static List<x>NJ=new List<x>();const int Nj=60;double[]nj=new double[Nj];double Ǎ=1.0d/Nj;int ǎ=0
  247. ,Ǐ=1,ǐ=int.MinValue,Ǒ=0;DateTime ǒ=DateTime.MinValue;string Ǔ="",ǔ="",Ǖ="";static int ǖ=0;bool Ǘ=true;public int Ǜ(){if(Ǘ
  248. )return int.MaxValue;int Ǚ=(int)Math.Pow(10,8-(ǘ*2));if(ǚ!=null)return ǚ.Ǜ()+(Ǒ*Ǚ);return Ǒ*Ǚ;}static int ǜ=(int)Math.Pow
  249. (10,5);public x(string ǝ){if(lj){Ǔ=ǝ;NJ.Add(this);for(var e=0;e<Nj;e++)nj[e]=0;Ǒ=ǖ;ǖ+=1;}}public void K(){Ǟ();}public void s(
  250. ){ǟ();}static List<x>Ǡ=new List<x>();x ǚ=null;int ǘ=0;bool ǡ=false;public void Ǟ(){if(lj){Ǘ=false;if(O!=ǐ){if(Ǐ==1&&ǐ!=int
  251. .MinValue){Ǐ=O-ǐ;}else{var Ǣ=O-ǐ;if(Ǣ!=Ǐ){Ǐ=1;for(var e=0;e<Nj;e++)nj[e]=0;}}ǐ=O;ǡ=false;}else{ǡ=true;}if(ǘ==0)ǘ=Ǡ.Count;if
  252. (ǘ>11)ǘ=11;if(Ǡ.Count>0&&ǚ==null)ǚ=Ǡ[Ǡ.Count-1];Ǡ.Add(this);ǒ=DateTime.Now;}}double ǣ=0,Ǥ=0;public double ǟ(){double ǥ=0;
  253. if(lj){ǥ=(DateTime.Now-ǒ).TotalMilliseconds;}return ǟ(ǥ);}double ǟ(double Ǧ){double ǥ=0;if(lj){ǥ=Ǧ;Ǡ.Pop();if(ǚ!=null){ǘ=ǚ.ǘ
  254. +1;}if(!ǡ)nj[ǎ]=0;nj[ǎ]+=ǥ;if(!ǡ)ǎ=(ǎ+1)%Nj;Ǥ=0d;foreach(double ǧ in nj)Ǥ+=ǧ;Ǥ*=Ǎ;Ǥ/=Ǐ;ǣ=ǥ;}return ǥ;}public string Ǭ(
  255. StringBuilder Ǩ){if(lj){if(O%120==25){try{NJ.Sort(delegate(x IJ,x ĺ){return IJ.Ǜ().CompareTo(ĺ.Ǜ());});}catch(Exception){}for(int e=0;e<NJ
  256. .Count;e++){x į=NJ[e];į.ǔ="";if(į.ǘ>0&&į.ǚ!=null){bool ǩ=false;bool Ǫ=false;for(int æ=e+1;æ<NJ.Count;æ++){if(NJ[æ].ǘ==į.ǚ.ǘ)
  257. ǩ=true;if(NJ[æ].ǘ==į.ǘ)Ǫ=true;if(NJ[æ].ǘ<į.ǘ)break;}while(į.ǔ.Length<į.ǚ.ǘ){if(ǩ)į.ǔ+="│";else į.ǔ+=" ";}bool ë=false;if(!Ǫ
  258. ){if(e<NJ.Count-1){if(NJ[e+1].ǘ!=į.ǘ)ë=true;}else ë=true;}if(ë)į.ǔ+="└";else į.ǔ+="├";while(į.ǔ.Length<į.ǘ)į.ǔ+="─";}}int ǫ
  259. =0;foreach(x į in NJ)if(į.ǔ.Length+į.Ǔ.Length>ǫ)ǫ=į.ǔ.Length+į.Ǔ.Length;foreach(x į in NJ){į.Ǖ="";int H=į.ǔ.Length+į.Ǔ.
  260. Length+į.Ǖ.Length;if(H<ǫ)į.Ǖ=new string('_',ǫ-H);}}if(Ǘ)ž(Ǩ,"!!!!",Ǔ,"!!!!: NEVER CALLED!");else ž(Ǩ,ǔ,Ǔ,Ǖ,": ",ǣ.ToString(
  261. "0.00"),";",Ǥ.ToString("0.00"));}return"";}static public string Ǯ(){StringBuilder æ=new StringBuilder();if(lj){foreach(x ǭ in NJ
  262. ){ǭ.Ǭ(æ);æ.Append("\n");}}if(Ǡ.Count>0){ž(æ,"profile stack error:\n",Ǡ.Count,"\n");foreach(var K in Ǡ){ž(æ,K.Ǔ,",");}}
  263. return æ.ToString();}}
  264.  
  265.     static public Program Ü=null;static public DateTime ǯ;public
  266.  Program(){Ü=this;ǰ=new DZ();ǰ.į=this;ǯ=DateTime.Now;Q(
  267. "BOOT",ć.Ĉ);Runtime.UpdateFrequency=updateFrequency;}public void
  268.  Save
  269. (){}public static int O=-1;static x Dz=new x("init"),dz=new x("main");DateTime Ǵ=DateTime.Now;static T µ=null;static Å ǵ=
  270. null;static L Ƕ=null;public string Ƿ="";public UpdateType Ǹ=UpdateType.Update1;public void
  271.  Main
  272. (string ǹ,UpdateType Ɛ){Ƿ=ǹ;Ǹ=Ɛ;var ǻ=Ǻ;}static readonly int Ǽ=60;double[]ǽ=new double[Ǽ];double Ǿ=0;int ǿ=0,Ȁ=-1;bool ȁ=
  273. true;bool ȉ{get{double Ȃ=Runtime.LastRunTimeMs;if(ȁ){int Ȅ=ȃ%Ǽ;Ǿ-=ǽ[Ȅ];ǽ[Ȅ]=Ȃ;Ǿ+=Ȃ;if(ǿ<Ǽ)ǿ++;}if(ȃ<Ȁ)return true;double ȅ=Ǿ
  274. /ǿ;var Ȇ=maxMsPerSETickReal;if(ȅ>Ȇ){int ȇ=(int)Math.Ceiling((Ǿ/Ȇ)-ǿ);if(ȇ>0){Ȁ=ȃ+ȇ;Ȉ=true;Q(ȅ.ToString("0.00")+"ms > "+Ȇ.
  275. ToString("0.00")+"ms in tick "+ȃ+"; skipping "+ȇ+"t ("+(((double)ȇ)/60).ToString("0.0")+"s)");}}return false;}}bool Ȉ=false;bool
  276. Ǻ{get{if(Ǹ==UpdateType.Update1)ȃ++;if(Ȉ){Q("Runtime.LastRunTimeMs="+Runtime.LastRunTimeMs.ToString("0.00"));Ȉ=false;}var
  277. IJ=(ȃ!=0&&ȉ)?false:Ȋ;if(ȃ%30==0){Echo("t:"+ȃ);if(ȃ<Ȁ){Echo("rt:"+(ȃ-Ȁ));}}return true;}}public static int ȃ=0;public bool
  278. Ȋ{get{O+=1;if(O%20==0)if(Me.Closed){Runtime.UpdateFrequency=UpdateFrequency.None;return true;}dz.Ǟ();ȋ(Ƿ,Ǹ);dz.ǟ();if(O%5==
  279. 0){Echo(O.ToString());if(Ȍ!=null)Ȍ.WriteText("name:ms1t:ms60t\n"+x.Ǯ());if(µ!=null){Echo(µ.ƣ);}}if(ȍ!=null&&O%5==0){if(ƹ.
  280. ǃ){ƹ.Dž();ȍ.WriteText(ƹ.DŽ);}}return true;}}bool Ȏ=true;void ȋ(string ǹ,UpdateType Ɛ){Dz.Ǟ();if(O%10==0){ǰ.ª();}Dz.ǟ();if(ǰ.ȏ
  281. ){Echo("INITIALIZING: "+ǰ.Ȑ+"/11");if(Ʀ!=null)Ʀ.WriteText("INIT: "+ǰ.Ȑ+"/11");return;}if(Ȏ){Ȏ=false;µ=new T();µ.Ƒ(ȑ);Ƕ=
  282. new L();ǵ=new Å();Q("Basic structures initialized.");}if(O%connectEventInterval==0)Ȓ();if(ȓ)return;if(Ȕ!=null){Ƕ.ª();}µ.ª()
  283. ;if(O%60*5==0){if(Ȕ!=null){ȕ.K();var Ȗ=Ȕ.GetText();ǵ.ô(Ȗ);ȕ.s();ȗ.K();var Ć=ǵ.ê();Ȕ.WriteText(Ć);ȗ.s();}}if(ǹ=="clearasm"
  284. ){foreach(var I in G){I.ClearQueue();}}if(ǹ=="test"){var I=G[0];var c=Å.È.First().Value;List<MyProductionItem>Ș=new List<
  285. MyProductionItem>();I.GetQueue(Ș);if(Ș.Count==0){I.AddQueueItem(c,(MyFixedPoint)1000);}else{var s=Ș[0];I.InsertQueueItem(0,c,(
  286. MyFixedPoint)(-500));}}else if(ǹ=="log"){ƹ.LJ();}}static x ȕ=new x("aclcd1"),ȗ=new x("aclcd2");bool ȓ=false;static string ș=
  287. "No Sorting",Ț="No IIM";class ȡ{bool ț=false;public IMyShipConnector Ȝ=null,ȝ=null;public bool Ȟ=false;public bool Ɛ(){var ȟ=Ȝ.
  288. Status==MyShipConnectorStatus.Connected;var Ć=Ȝ.OtherConnector;if(ț!=ȟ){ț=ȟ;if(!ȟ)Ć=null;ȝ=Ć;Ȟ=false;if(ȝ!=null){var t=Ȝ.
  289. CustomName;var Ƞ=ȝ.CustomName;if(t.Contains(ș)||t.Contains(Ț)||Ƞ.Contains(ș)||Ƞ.Contains(Ț)){Ȟ=false;}else Ȟ=true;}return true;}
  290. else return false;}}Dictionary<IMyShipConnector,ȡ>Ȣ=new Dictionary<IMyShipConnector,ȡ>();Dictionary<IMyCubeGrid,
  291. IMyShipConnector>ȣ=new Dictionary<IMyCubeGrid,IMyShipConnector>();List<IMyCubeGrid>Ȥ=new List<IMyCubeGrid>();int ǐ=-1;IMyShipConnector ȧ
  292. (IMyTerminalBlock æ){if(ǐ!=O){ȣ.Clear();Ȥ.Clear();foreach(var þ in ȥ){var Ć=þ.OtherConnector;if(Ć!=null)ȣ[þ.
  293. OtherConnector.CubeGrid]=þ;}}IMyShipConnector Ȧ=null;ȣ.TryGetValue(æ.CubeGrid,out Ȧ);if(Ȧ!=null)return Ȧ;else{if(!Ȥ.Contains(æ.
  294. CubeGrid)){foreach(var k in Ȣ){var ī=k.Value;;if(ī.ȝ!=null&&ī.ȝ.CubeGrid==æ.CubeGrid){if(ī.Ȟ)return ȣ[æ.CubeGrid]=ī.Ȝ;else{Ȥ.Add
  295. (æ.CubeGrid);return null;}}}foreach(var k in Ȣ){var ī=k.Value;;if(ī.ȝ!=null&&ī.Ȟ){if(æ.IsSameConstructAs(ī.ȝ)){return ȣ[æ
  296. .CubeGrid]=ī.Ȝ;}}}}else return null;}Ȥ.Add(æ.CubeGrid);return null;}public bool ȩ(){bool Ȩ=false;foreach(var þ in ȥ){ȡ ī=
  297. null;Ȣ.TryGetValue(þ,out ī);if(ī==null){ī=new ȡ();ī.Ȝ=þ;Ȣ[þ]=ī;}Ȩ=ī.Ɛ()||Ȩ;}return Ȩ;}public void Ȯ(){List<IMyTerminalBlock>
  298. Ȫ=new List<IMyTerminalBlock>();GridTerminalSystem.GetBlocksOfType(Ȫ);ȑ.Clear();List<IMyCubeGrid>ȫ=new List<IMyCubeGrid>()
  299. ;List<IMyCubeGrid>Ȭ=new List<IMyCubeGrid>();foreach(var æ in Ȫ){if(æ.HasInventory&&æ.HasPlayerAccess(Me.OwnerId)){if(æ.
  300. CubeGrid==Me.CubeGrid)ȑ.Add(æ);else{if(!Ȭ.Contains(æ.CubeGrid)){if(æ.IsSameConstructAs(Me))ȫ.Add(æ.CubeGrid);else Ȭ.Add(æ.
  301. CubeGrid);}if(ȫ.Contains(æ.CubeGrid))ȑ.Add(æ);else{var ȭ=ȧ(æ);if(ȭ!=null){ȡ ī=null;Ȣ.TryGetValue(ȭ,out ī);if(ī!=null&&ī.Ȟ){ȑ.Add
  302. (æ);}}}}}}µ.Ƒ(ȑ);}bool ȯ=false;public void Ȓ(){try{bool Ȩ=ȩ();if(Ȩ){Q("connector change");List<IMyProgrammableBlock>Ȱ=new
  303. List<IMyProgrammableBlock>();GridTerminalSystem.GetBlocksOfType(Ȱ,æ=>æ!=Me&&æ.HasPlayerAccess(Me.OwnerId)&&æ.CustomData.
  304. StartsWith("KTZINV")&&æ.IsWorking);bool ȱ=true;if(Ȱ.Count>0){bool Ȳ=Me.CubeGrid.IsStatic;foreach(var þ in Ȱ){if(þ.CubeGrid.
  305. IsStatic&&!Ȳ){ȱ=false;break;}}if(ȱ){foreach(var þ in Ȱ){if(þ.EntityId<Me.EntityId&&(!Ȳ||þ.CubeGrid.IsStatic)){ȱ=false;break;}}}}
  306. ȓ=!ȱ;if(ȓ){µ.ƣ="Sleeping while a connected KTZInv runs.";if(Ʀ!=null)Ʀ.WriteText(µ.ƣ);return;}Ȯ();}}catch(Exception s){if(
  307. !ȯ){ȯ=true;Q("Exception: "+s.ToString());}}}static IMyTextSurface ȍ=null,Ʀ=null,Ȍ=null,Ʈ=null,Ȕ=null;static List<
  308. IMyAssembler>G=new List<IMyAssembler>();static List<IMyShipController>dž=new List<IMyShipController>();static List<IMyShipConnector>ȥ
  309. =new List<IMyShipConnector>();static List<IMyTerminalBlock>ȑ=new List<IMyTerminalBlock>();static public ȳ ŗ=null;static
  310. public DZ ǰ=null;public class DZ{public Program į;public bool ȏ=true;public DZ(){ȴ();}bool ȵ=false;public void ª(){if(ŗ==null){ŗ=
  311. new ȳ();try{ŗ.ȶ(Ü.Me);}catch(Exception){}}if(!ŗ.ȷ&&O%30==0){try{ŗ.ȶ(Ü.Me);}catch(Exception){}}if(!ŗ.ȷ)return;if(!ȵ||O%60==0
  312. ){ȵ=true;}if(ȸ!=null){if(!ȸ.MoveNext()){ȸ.Dispose();ȸ=null;}}else if(ȵ&&O%(5*60*60)==0)ȴ();}IEnumerator<bool>ȸ=null;void
  313. ȴ(){if(ȸ!=null)ȸ.Dispose();ȸ=ȹ();Ȑ=0;}public int Ȑ=0;public bool Ⱥ(IMyTerminalBlock æ){return æ.GetOwnerFactionTag()==į.
  314. Me.GetOwnerFactionTag()&&æ.CubeGrid==į.Me.CubeGrid;}public IEnumerator<bool>ȹ(){var Ȼ=į.GridTerminalSystem;ȍ=null;Ʀ=null;Ȍ
  315. =null;List<IMyTerminalBlock>ȼ=new List<IMyTerminalBlock>();Ȼ.GetBlocksOfType(ȼ,æ=>(æ is IMyTextSurface)&&æ.CubeGrid==į.Me
  316. .CubeGrid);foreach(var æ in ȼ){IMyTextSurface K=æ as IMyTextSurface;if(æ.CustomData.Contains("statusLog"))Ʀ=K;else if(æ.
  317. CustomData.Contains("consoleLog"))ȍ=K;else if(æ.CustomData.Contains("profileLog"))Ȍ=K;else if(æ.CustomData.Contains("cargodbg"))Ʈ=
  318. K;else if(æ.CustomName.Contains(AUTOCRAFT_LCD_KEYWORD))Ȕ=K;}Ȑ++;yield return true;Ȼ.GetBlocksOfType(dž,Ⱥ);Ȑ++;yield return
  319. true;Ȑ++;ȥ.Clear();Ȼ.GetBlocksOfType(ȥ,Ⱥ);yield return true;Ȑ++;if(USE_SKITS)Ȼ.GetBlocksOfType(G,Ⱥ);else Ȼ.GetBlocksOfType(G
  320. ,æ=>Ⱥ(æ)&&æ.DefinitionDisplayNameText!="Survival Kit");yield return true;Ȑ++;Ȼ.GetBlocksOfType(ȑ,æ=>æ.HasInventory&&æ.
  321. HasPlayerAccess(į.Me.OwnerId));yield return true;Ȑ++;if(ȏ)Q("BOOT DONE. "+O+"t ("+(((float)O)/60).ToString("0.0")+"s)",ć.Ĉ);ȏ=false;Ȑ++
  322. ;yield return false;}}
  323. }
  324. public class ȳ{public string[]Ƚ=new string[]{"Any","Offense","Utility","Power","Production","Thrust","Jumping",
  325. "Steering"};Action<ICollection<MyDefinitionId>>J;Func<IMyTerminalBlock,IDictionary<string,int>,bool>æ;Action<IMyTerminalBlock,
  326. IDictionary<MyDetectedEntityInfo,float>>þ;Func<long,bool>Ⱦ;Func<long,int,MyDetectedEntityInfo>s;Func<IMyTerminalBlock,long,int,bool
  327. >ȿ;Action<IMyTerminalBlock,bool,bool,int>ɀ;Func<IMyTerminalBlock,bool>Ɂ;Action<IMyTerminalBlock,ICollection<
  328. MyDetectedEntityInfo>>e;Func<IMyTerminalBlock,ICollection<string>,int,bool>ɂ;Action<IMyTerminalBlock,ICollection<string>,int>Ď;Func<
  329. IMyTerminalBlock,long,int,Vector3D?>H;Func<IMyTerminalBlock,int,Matrix>d;Func<IMyTerminalBlock,int,Matrix>t;Func<IMyTerminalBlock,long,
  330. int,MyTuple<bool,Vector3D?>>Ć;Func<IMyTerminalBlock,int,string>į;Action<IMyTerminalBlock,int,string>Ƀ;Func<long,float>Ē;
  331. Func<IMyTerminalBlock,int,MyDetectedEntityInfo>K;Action<IMyTerminalBlock,long,int>Ó;Func<long,MyTuple<bool,int,int>>Ʉ;Action
  332. <IMyTerminalBlock,bool,int>ī;Func<IMyTerminalBlock,int,bool,bool,bool>Ʌ;Func<IMyTerminalBlock,int,float>IJ;Func<
  333. IMyTerminalBlock,int,MyTuple<Vector3D,Vector3D>>ĺ;Func<IMyTerminalBlock,float>Ɇ;public Func<Sandbox.ModAPI.Ingame.IMyTerminalBlock,float
  334. >ɇ;public bool ȷ=false;IMyTerminalBlock Ɉ=null;public bool ȶ(IMyTerminalBlock Ɉ){this.Ɉ=Ɉ;var ɉ=Ɉ.GetProperty("WcPbAPI")?
  335. .As<IReadOnlyDictionary<string,Delegate>>().GetValue(Ɉ);if(ɉ==null)throw new Exception("WcPbAPI failed to activate");
  336. return Ɋ(ɉ);}public bool Ɋ(IReadOnlyDictionary<string,Delegate>ɋ){if(ɋ==null)return false;Ɍ(ɋ,"GetCoreWeapons",ref J);Ɍ(ɋ,
  337. "GetBlockWeaponMap",ref æ);Ɍ(ɋ,"GetSortedThreats",ref þ);Ɍ(ɋ,"GetObstructions",ref e);Ɍ(ɋ,"HasGridAi",ref Ⱦ);Ɍ(ɋ,"GetAiFocus",ref s);Ɍ(ɋ,
  338. "SetAiFocus",ref ȿ);Ɍ(ɋ,"HasCoreWeapon",ref Ɂ);Ɍ(ɋ,"GetPredictedTargetPosition",ref H);Ɍ(ɋ,"GetTurretTargetTypes",ref ɂ);Ɍ(ɋ,
  339. "SetTurretTargetTypes",ref Ď);Ɍ(ɋ,"GetWeaponAzimuthMatrix",ref d);Ɍ(ɋ,"GetWeaponElevationMatrix",ref t);Ɍ(ɋ,"IsTargetAlignedExtended",ref Ć);Ɍ
  340. (ɋ,"GetActiveAmmo",ref į);Ɍ(ɋ,"SetActiveAmmo",ref Ƀ);Ɍ(ɋ,"GetConstructEffectiveDps",ref Ē);Ɍ(ɋ,"GetWeaponTarget",ref K);Ɍ
  341. (ɋ,"SetWeaponTarget",ref Ó);Ɍ(ɋ,"GetProjectilesLockedOn",ref Ʉ);Ɍ(ɋ,"FireWeaponOnce",ref ī);Ɍ(ɋ,"ToggleWeaponFire",ref ɀ)
  342. ;Ɍ(ɋ,"IsWeaponReadyToFire",ref Ʌ);Ɍ(ɋ,"GetMaxWeaponRange",ref IJ);Ɍ(ɋ,"GetWeaponScope",ref ĺ);Ɍ(ɋ,"GetCurrentPower",ref Ɇ)
  343. ;Ɍ(ɋ,"GetHeatLevel",ref ɇ);ȷ=true;return true;}void Ɍ<ɍ>(IReadOnlyDictionary<string,Delegate>ɋ,string ǝ,ref ɍ Ɏ)where ɍ:
  344. class{if(ɋ==null){Ɏ=null;return;}Delegate Ĩ;if(!ɋ.TryGetValue(ǝ,out Ĩ))throw new Exception(
  345. $"{GetType().Name} :: Couldn't find {ǝ} delegate of type {typeof(ɍ)}");Ɏ=Ĩ as ɍ;if(Ɏ==null)throw new Exception(
  346. $"{GetType().Name} :: Delegate {ǝ} is not type {typeof(ɍ)}, instead it's: {Ĩ.GetType()}");}public bool Ř(IMyTerminalBlock ɏ)=>Ɂ?.Invoke(ɏ)??false;
Advertisement
Add Comment
Please, Sign In to add comment