Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public double maxMsPerSETickReal = 0.05;
- static bool USE_SKITS = false;//whether to use survival kits in autocrafting
- static bool ASSEMBLE = true;//auto assemble items to the quota dictated by Autocraft LCD
- static bool DISASSEMBLE = true;//auto disassemble items in excess of quota
- static bool PRIORITY_DISASSEMBLE = true;// if true, disassemble then assemble. else assemble then disassemble.
- static int ASSEMBLE_MARGIN = 50;//margin of error around quota before doing any of that
- //static bool ASM_FLUSH = false;//whether to periodically clear inputs of an assembler that is not producing
- static bool ASM_SHUFFLE = false;//whether to periodically move the first item to back of queue if not producing
- //static bool NEVER_SORT_REFINERIES = false;
- //static bool NEVER_SORT_REACTORS = true;//sorting reactors can reset their work state
- static string AUTOCRAFT_LCD_KEYWORD = "KTZ Autocraft";
- static int connectEventInterval = 10;
- static UpdateFrequency updateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update10 | UpdateFrequency.Update100;
- static int MAX_TRANSFERS_PER_OP = 4;
- //moving items is fundamentally expensive, moreso that it seems. this limits the amount of actual stacks moved in a given operation.
- //Lower numbers make performance more consistent and thus reliable with things like pblimiter, but
- //can result in it taking several passes over the grid to get things to their final destinations if things are sufficiently disordered.
- static double MAX_TRANSFER_MS = 0.05;//secondary sancheck
- static bool SORT = true;//whether to do any of that item sorting stuff at all.
- //Note: Even if sorting isn't otherwise used, input flushing of jammed assemblers won't
- //happen without a tagged cargo for Ingots, Components
- static bool MERGE_STACKS = true;
- //whether to merge multiple stacks of the same itemtype in a given container when possible
- //could cause desync, they say? idk. stacks should only be fragmented like this by player action
- static bool ISYCOMPAT = true;
- //these are blocks by DefinitionDisplayNameText
- //containers that cannot or should not be managed, ever, typically due to lack of conveyor support
- static string[] ignoreBlockTypes = {
- "Cargo Crate",
- "Lockers",
- "Armory Lockers",
- "Armory",
- "Weapon Rack",
- "Control Seat",
- "Parachute Hatch",
- "Control Station",
- "Vending Machine" };
- //PERFORMANCE CONTROLS
- static bool CARGODBG = false;
- static public int blockInterval = 5;//ticks to wait for next block scan when nothing has been moved
- static public int blockIntervalMove = 15;//ticks to wait if the last op required moving items around
- 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=
- new C();H.I=J;var K=new A();K.D=H;B.Add(K);}}Dictionary<MyDefinitionId,List<IMyAssembler>>M=new Dictionary<MyDefinitionId,
- 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
- ||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<
- MyInventoryItem>();I.InputInventory.GetItems(R);List<MyInventoryItem>S=new List<MyInventoryItem>();I.OutputInventory.GetItems(S);R.
- 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.
- CustomName);List<MyProductionItem>Z=new List<MyProductionItem>();I.GetQueue(Z);if(Z.Count>1){var a=Z[0];I.RemoveQueueItem(0,a.
- Amount);I.AddQueueItem(a.BlueprintId,a.Amount);}P.E=P.F=O;}}}}public void f(MyDefinitionId c,MyAssemblerMode d){foreach(var J
- 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[
- e];if(Y.BlueprintId==c){J.RemoveQueueItem(e,Y.Amount);Z.RemoveAt(e);e--;}}}}}public void w(MyAssemblerMode d,Dictionary<
- MyDefinitionId,MyFixedPoint>g=null){Dictionary<MyDefinitionId,MyFixedPoint>h=new Dictionary<MyDefinitionId,MyFixedPoint>();Dictionary<
- IMyAssembler,List<MyProductionItem>>i=new Dictionary<IMyAssembler,List<MyProductionItem>>();foreach(var J in G){if(J.Mode!=d){J.
- 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];
- if(Y.Amount<(MyFixedPoint)1){J.RemoveQueueItem(e,Y.Amount);Z.RemoveAt(e);e--;}else{var c=Y.BlueprintId;if(h.ContainsKey(c)
- )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)
- ;if(d==MyAssemblerMode.Assembly&&k.Value>j)h[k.Key]=k.Value;else if(d==MyAssemblerMode.Disassembly&&-k.Value>j)h[k.Key]=-
- 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){
- 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(
- 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
- 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-
- 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(
- "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
- .s();z.K();z.s();if(O%60==0&&O-µ.À<=60){Dictionary<MyDefinitionId,MyFixedPoint>Á=new Dictionary<MyDefinitionId,
- MyFixedPoint>();foreach(var H in B){foreach(var e in H.D.Â){if(!Á.ContainsKey(e.BlueprintId))Á.Add(e.BlueprintId,e.Amount);else Á[e.
- BlueprintId]+=e.Amount;}}Dictionary<MyDefinitionId,MyFixedPoint>h=new Dictionary<MyDefinitionId,MyFixedPoint>();int Ã=0;int Ä=0;
- foreach(var k in Å.Æ){var Ç=k.Key;var É=Å.È[Ç];var Ê=k.Value;MyFixedPoint Ë=0;T.Ì.Í.TryGetValue((MyItemType)Ç,out Ë);if(
- ASSEMBLE&&Ë+ASSEMBLE_MARGIN<Ê){h[É]=Ê-Ë;Ã+=1;}if(DISASSEMBLE&&Ë-ASSEMBLE_MARGIN>Ê){h[É]=Ê-Ë;Ä+=1;}}if(h.Count>0){if(Ã==0&&Ä!=0){
- foreach(var K in G)if(K.IsQueueEmpty)K.Mode=MyAssemblerMode.Disassembly;}else if(Ã!=0&&Ä==0){foreach(var K in G)if(K.
- IsQueueEmpty)K.Mode=MyAssemblerMode.Assembly;}bool Î=false;bool Ï=false;foreach(var k in h){if(ASSEMBLE&&k.Value>0)Î=true;else if(
- DISASSEMBLE&&k.Value<-ASSEMBLE_MARGIN)Ï=true;}if(Î&&(Ï==false||PRIORITY_DISASSEMBLE==false)){foreach(var k in h){if(k.Value>0)f(k.
- Key,MyAssemblerMode.Assembly);}w(MyAssemblerMode.Assembly,h);}else if(Ï&&(Î==false||PRIORITY_DISASSEMBLE==true)){foreach(
- var k in h){if(k.Value<0)f(k.Key,MyAssemblerMode.Disassembly);}w(MyAssemblerMode.Disassembly,h);}}}}}class Å{static public
- MyItemType Ð=MyItemType.MakeComponent("SteelPlate");static Dictionary<string,MyItemType>Ñ=new Dictionary<string,MyItemType>();
- public static bool Õ(string Ò,out MyItemType Ó){if(Ñ.ContainsKey(Ò)){Ó=Ñ[Ò];return true;}foreach(var Ô in È){if(Ô.Key.
- SubtypeId.ToString()==Ò){Ñ[Ò]=Ô.Key;Ó=Ô.Key;return true;}}Ó=Ð;return false;}static public Dictionary<string,int>Ö=new Dictionary<
- string,int>();static public Dictionary<MyDefinitionId,int>Æ=new Dictionary<MyDefinitionId,int>();static public Dictionary<
- MyDefinitionId,MyDefinitionId>È=new Dictionary<MyDefinitionId,MyDefinitionId>();static public void Ú(MyDefinitionId Ø,MyDefinitionId c
- ){È[Ø]=c;Ù();}static public void Ù(){string Û="KTZINV;\nitemID;blueprintID";foreach(var k in È){Û+="\n"+k.Key.ToString()+
- ";"+k.Value.ToString();}Ü.Me.CustomData=Û;}public Å(){var Ý=Ü.Me.CustomData;var Þ=Ý.Split('\n');foreach(var H in Þ){var ß=H
- .Split(';');if(ß.Length>=2){try{var Ç=MyDefinitionId.Parse(ß[0]);try{var É=MyDefinitionId.Parse(ß[1]);È[Ç]=É;}catch(
- Exception){}}catch(Exception){}}}}static x à=new x("p1"),á=new x("p2"),â=new x("p3");public string ê(){à.K();Dictionary<string,
- int>ã=new Dictionary<string,int>();foreach(var k in T.Ì.Í){string Ò=k.Key.SubtypeId;if(!Ö.ContainsKey(Ò)){var ä=k.Key.
- GetItemInfo();if(!ä.IsOre&&!ä.IsIngot)Ö[Ò]=0;else{MyItemType å=Å.Ð;if(Õ(Ò,out å)){Ö[Ò]=0;break;}}}ã[Ò]=(int)k.Value;}à.s();á.K();
- StringBuilder æ=new StringBuilder("Component Current | Wanted\n");foreach(var k in Ö){int ç=0;int è=k.Value;ã.TryGetValue(k.Key,out ç
- );æ.Append(k.Key);æ.Append(" ");æ.Append(ç);æ.Append(" ");if(ç<è)æ.Append("<");else if(ç==è)æ.Append("=");else æ.Append(
- ">");æ.Append(" ");æ.Append(è);bool é=false;â.K();foreach(var Ô in È){if(Ô.Key.SubtypeId.ToString()==k.Key){é=true;Æ[Ô.Key]
- =è;break;}}â.s();if(!é)æ.Append(" (no BP)");æ.Append("\n");}á.s();return æ.ToString();}string ë="";public void ô(string K
- ){if(ë==K)return;ë=K;var ì=K.Split('\n');foreach(var H in ì){if(H.Contains("|"))continue;var í=H.Split(new char[]{' '},
- StringSplitOptions.RemoveEmptyEntries);if(í.Length>=4){string î=í[0];string ï=í[1];char ð=í[2][0];if(ð=='<'||ð=='>'||ð=='='){string ñ=í[3]
- ;int ò=0;var ó=int.TryParse(ñ,out ò);if(ó){Ö[î]=ò;}}}}}}class C{public IMyAssembler I=null;public int õ=0;static
- MyDefinitionId Ð=MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SpaceCredit");public List<MyProductionItem>Â=new List<
- MyProductionItem>();List<MyInventoryItem>ö=new List<MyInventoryItem>();float ø=-1;static x D=new x("bpl");DateTime ù=DateTime.Now;public
- void ª(){D.K();if(O%60==0&&I.Mode==MyAssemblerMode.Assembly){ù=DateTime.Now;var ú=I.CurrentProgress;List<MyProductionItem>Z=
- new List<MyProductionItem>();List<MyInventoryItem>û=new List<MyInventoryItem>();I.GetQueue(Z);if(Z.Count!=0||Â.Count!=0){I.
- OutputInventory.GetItems(û);List<MyItemType>ü=new List<MyItemType>();List<MyInventoryItem>ý=new List<MyInventoryItem>();foreach(var e
- in û){var Ó=e.Type;if(ü.Contains(Ó))continue;ü.Add(Ó);MyFixedPoint þ=0;foreach(var ÿ in û){if(ÿ.Type==Ó)þ+=ÿ.Amount;}if(þ>
- 0){ý.Add(new MyInventoryItem(e.Type,e.ItemId,þ));}}û=ý;if(Â.Count>0){MyDefinitionId Ā=Ð;foreach(var ă in Â){bool ā=false;
- foreach(var Ă in Z){if(Ă.ItemId==ă.ItemId&&Ă.BlueprintId==ă.BlueprintId){ā=true;if(Ă.Amount<ă.Amount){Ā=ă.BlueprintId;break;}}}
- if(Ā!=Ð)break;if(!ā){Ā=ă.BlueprintId;break;}}if(Ā!=Ð){MyDefinitionId Ą=Ð;foreach(var e in û){bool ą=true;foreach(var Ć in
- ö){if(Ć.Type==e.Type)ą=false;if(Ć.Type==e.Type&&Ć.Amount<e.Amount){try{var t=MyDefinitionId.Parse(e.Type.TypeId+"/"+e.
- Type.SubtypeId);Ą=t;ą=false;break;}catch(Exception){}}}if(ą){try{var t=MyDefinitionId.Parse(e.Type.TypeId+"/"+e.Type.
- SubtypeId);Ą=t;}catch(Exception){}}if(Ą!=Ð)break;}if(Ā!=Ð&&Ą!=Ð){õ=O;if(!Å.È.ContainsKey(Ą)){Q("Learned recipe "+Ą.ToString()+";"
- +Ā.ToString(),ć.Ĉ);Å.Ú(Ą,Ā);}}}}}if(Â.Count==0)ú=0;ø=ú;Â=Z;ö=û;}D.s();}}class T{public static ĉ Ì=new ĉ();public static
- Dictionary<string,MyFixedPoint>Ċ=new Dictionary<string,MyFixedPoint>();public static List<MyItemType>ċ=new List<MyItemType>();
- static Dictionary<string,MyItemType>Č=new Dictionary<string,MyItemType>();static MyItemType ď(string č,string Ò){var Ď=č+"/"+Ò
- ;if(Č.ContainsKey(Ď))return Č[Ď];else{return Č[Ď]=new MyItemType(č,Ò);}}static List<string>Đ=new List<string>(){
- "MyObjectBuilder_OxygenContainerObject","MyObjectBuilder_GasContainerObject","MyObjectBuilder_PhysicalGunObject","MyObjectBuilder_PhysicalObject",
- "MyObjectBuilder_Datapad",};static Dictionary<string,string>đ=new Dictionary<string,string>(){{"MyObjectBuilder_OxygenContainerObject","Bottles"}
- ,{"MyObjectBuilder_GasContainerObject","Bottles"},{"MyObjectBuilder_PhysicalGunObject","Tools"},{
- "MyObjectBuilder_PhysicalObject","Tools"},{"MyObjectBuilder_ConsumableItem","Tools"},{"MyObjectBuilder_Datapad","Tools"},{"MyObjectBuilder_AmmoMagazine"
- ,"Ammo"},{"MyObjectBuilder_Ore","Ores"},{"MyObjectBuilder_Ingot","Ingots"},{"MyObjectBuilder_Component","Components"},};
- public static string ē(string č){string Ē="Unknown";đ.TryGetValue(č,out Ē);return Ē;}static bool Ĕ=false;public class ĉ{public
- ĉ(){}public Dictionary<MyItemType,MyFixedPoint>Í=new Dictionary<MyItemType,MyFixedPoint>();public MyFixedPoint ĕ,Ė;public
- Dictionary<string,MyFixedPoint>ė=new Dictionary<string,MyFixedPoint>();public void g(U W){Í.Clear();ĕ=Ė=0;var ę=W.Ę(false);int Ě=0
- ;DateTime ě=DateTime.Now;foreach(var Ĝ in ę){var ĝ=Ĝ.MaxVolume;var Ğ=Ĝ.CurrentVolume;ĕ+=ĝ;Ė+=ĝ-Ğ;List<MyInventoryItem>R=
- new List<MyInventoryItem>();Ĝ.GetItems(R);Dictionary<MyItemType,int>ğ=new Dictionary<MyItemType,int>();for(int e=R.Count-1;
- e>=0;e--){var Ġ=R[e];if(MERGE_STACKS&&Ě<MAX_TRANSFERS_PER_OP&&ğ.ContainsKey(Ġ.Type)){var ġ=!Đ.Contains(Ġ.Type.TypeId);if(
- ġ){var Ģ=ğ[Ġ.Type];var ä=Ġ.Type.GetItemInfo();var ģ=R[Ģ];if(Ġ.Amount+ģ.Amount<ä.MaxStackAmount){Q(Ġ.Type.SubtypeId+
- " msa "+ä.MaxStackAmount+" stacking now ");Ĝ.TransferItemTo(Ĝ,Ģ,e,true);Ě++;if((DateTime.Now-ě).TotalMilliseconds>
- MAX_TRANSFER_MS)Ě=MAX_TRANSFERS_PER_OP;}}}ğ[Ġ.Type]=e;if(!Í.ContainsKey(Ġ.Type))Í[Ġ.Type]=Ġ.Amount;else Í[Ġ.Type]+=Ġ.Amount;var Ó=ē(Ġ.
- Type.TypeId);MyFixedPoint Ĥ=0;ė.TryGetValue(Ó,out Ĥ);Ĥ+=Ġ.Type.GetItemInfo().Volume*Ġ.Amount;ė[Ó]=Ĥ;}}if(Ě>0){Q(Ě+
- " merges in "+W.æ.CustomName+" took "+(DateTime.Now-ě).TotalMilliseconds+"ms");}foreach(var k in Í){var Ď=k.Key;if(!ċ.Contains(Ď)){ċ.
- Add(Ď);MyFixedPoint ĥ=(MyFixedPoint)0.01;if(!Ď.GetItemInfo().UsesFractions)ĥ=(MyFixedPoint)Ď.GetItemInfo().Volume;var Ħ=ē(Ď
- .TypeId);MyFixedPoint ħ=0;Ċ.TryGetValue(Ħ,out ħ);if(ĥ>ħ)ħ=ĥ;Ċ[Ħ]=ħ;}}}public void ĩ(ĉ Ć){if(Ć==null)return;List<
- MyItemType>Ĩ=new List<MyItemType>();foreach(var k in Ć.Í){if(Í.ContainsKey(k.Key)){var Ĝ=Í[k.Key]-k.Value;if(Ĝ>0)Í[k.Key]=Ĝ;else Ĩ
- .Add(k.Key);}}foreach(var Ď in Ĩ)Í.Remove(Ď);}public void Ī(ĉ Ć){if(Ć==null)return;foreach(var k in Ć.Í){if(Í.ContainsKey
- (k.Key))Í[k.Key]+=k.Value;else Í[k.Key]=k.Value;}}public bool Ĭ(ĉ Ć){if(Ć==null||this.Í.Count!=Ć.Í.Count)return false;
- foreach(var k in Í){MyFixedPoint ī=0;if(!Ć.Í.TryGetValue(k.Key,out ī))return false;else if(k.Value!=ī)return false;}foreach(var
- k in Ć.Í){if(!Í.ContainsKey(k.Key))return false;}return true;}}static public List<ĭ>Į=new List<ĭ>();static public ĭ ij(int
- į){foreach(var İ in Į)if(İ.ı==į)return İ;var IJ=new ĭ();IJ.ı=į;Į.Add(IJ);Į.Sort();return IJ;}static ĭ Ĺ(U W,string Ĵ){var ĵ=0
- ;for(int e=0;e<Į.Count;e++){var İ=Į[e];if(İ.ı==W.ı){ĵ=e;break;}}for(int e=0;e<ĵ;e++){var þ=Į[e];MyFixedPoint Ķ=0;þ.ķ.
- TryGetValue(Ĵ,out Ķ);MyFixedPoint ĸ=0;Ċ.TryGetValue(Ĵ,out ĸ);if(Ķ>ĸ)return þ;}return null;}public class ĭ:IComparable<ĭ>{int
- IComparable<ĭ>.CompareTo(ĭ ĺ){var IJ=this;return IJ.ı.CompareTo(ĺ.ı);}public List<U>Ļ=new List<U>();public int ı=0;public Dictionary<
- string,MyFixedPoint>ķ=new Dictionary<string,MyFixedPoint>();public List<string>ļ=new List<string>();public void ª(){ķ.Clear();
- ļ.Clear();foreach(var W in Ļ){foreach(var þ in W.ļ){if(!ļ.Contains(þ))ļ.Add(þ);MyFixedPoint ī=0;ķ.TryGetValue(þ,out ī);if
- (W.Ľ.Ė>ī){ķ[þ]=W.Ľ.Ė;}}}}}public class U:IComparable<U>{int IComparable<U>.CompareTo(U ĺ){var IJ=this;if(IJ.ı==ĺ.ı){return
- IJ.r.CompareTo(ĺ.r);}return IJ.ı.CompareTo(ĺ.ı);}public static List<U>ľ=new List<U>();public static Dictionary<
- IMyTerminalBlock,U>Ŀ=new Dictionary<IMyTerminalBlock,U>();public static U V(IMyTerminalBlock æ){U Ē=null;Ŀ.TryGetValue(æ,out Ē);if(Ē==
- null)Ē=new U(æ);return Ē;}const string ŀ="MyObjectBuilder_",Ł="alltypes";public static int ł=0;public int r=0;public U(
- IMyTerminalBlock æ){this.æ=æ;ľ.Add(this);Ŀ[æ]=this;r=ł;ł++;for(var e=0;e<æ.InventoryCount;e++){Ń.Add(æ.GetInventory(e));}if(æ is
- IMyProductionBlock){ń=true;var į=(IMyProductionBlock)æ;Ņ.Add(į.OutputInventory);ņ.Add(į.InputInventory);if(æ is IMyAssembler){Ň=true;ň=(
- IMyAssembler)æ;}}else{Ņ.AddRange(Ń);}}public IMyTerminalBlock æ=null;public ĉ Ľ=null;public List<string>ļ=new List<string>();List<
- IMyInventory>Ņ=new List<IMyInventory>();List<IMyInventory>ņ=new List<IMyInventory>(),Ń=new List<IMyInventory>();public List<
- IMyInventory>Ę(bool ʼn){if(ʼn)return Ń;else{if(ň!=null&&ň.Mode==MyAssemblerMode.Disassembly)return ņ;return Ņ;}}public bool ń=false,Ň=
- false,Ŋ=false,ŋ=true,Ō=false,ō=false;IMyAssembler ň=null;public Dictionary<MyItemType,MyFixedPoint>Ŏ=new Dictionary<
- MyItemType,MyFixedPoint>();const int ŏ=100000;public int ı=int.MaxValue;public string Ő="-31234",ő="-234523";void Œ(){ŋ=true;Ŋ=
- false;}void œ(){ŋ=true;Ō=true;Ŋ=false;}public void ş(){if(æ.CustomName!=ő){ő=æ.CustomName;var Ŕ=ı;ı=ŏ;Ŋ=false;ŋ=false;Ō=false
- ;ō=false;var Ó=ő.Split(' ','.');ļ.Clear();if(ignoreBlockTypes.Contains(æ.DefinitionDisplayNameText))Œ();if(!Ō){foreach(
- var í in Ó){var ŕ=í.ToLower();if(ŕ.StartsWith("[")&&ŕ.EndsWith("]")){ŕ=ŕ.Substring(1,ŕ.Length-2);}if(ŕ=="special"){Ŋ=true;ı
- -=10000;}else if(ŕ=="locked"){Œ();}else if(ŕ=="hidden"){œ();}else if(ŕ.StartsWith("p")){var Ŗ=í.Substring(1);if(Ŗ=="max")ı
- =int.MinValue;else if(Ŗ=="min")ı=int.MaxValue;else if(Ŗ.All(char.IsDigit)){ı-=10000;int þ=0;int.TryParse(Ŗ,out þ);if(þ.
- ToString()==Ŗ){ı+=þ;}}}else if(ŕ==Ł){ō=true;}else{foreach(var k in đ){if(ŕ==k.Value.ToLower()){if(!ļ.Contains(k.Value))ļ.Add(k.
- Value);break;}}}}if(Ĕ&&!Ŋ&&!ŋ&&ļ.Count==0&&!ń){ō=true;ı+=1;}}if(Ŋ){ō=false;ļ.Clear();}if(ō){foreach(var k in đ){if(!ļ.
- Contains(k.Value))ļ.Add(k.Value);}}if(!Ŋ&&ļ.Count==0&&ŗ.Ř(æ)){ŋ=true;}if(Ŕ!=ı){ľ.Sort();var ř=ij(Ŕ);ř.Ļ.Remove(this);ř.ª();ř=ij(ı)
- ;ř.Ļ.Add(this);ř.ª();}if(!Ŋ)Ŏ.Clear();}if(Ŋ&&æ.CustomData!=Ő){if(Ŋ&&æ.CustomData==""){List<MyItemType>Ś=new List<
- MyItemType>();List<MyItemType>Ó=new List<MyItemType>();for(var e=0;e<æ.InventoryCount;e++){æ.GetInventory(e).GetAcceptedItems(Ó);
- foreach(var s in Ó)if(!Ś.Contains(s))Ś.Add(s);}List<string>ś=new List<string>();List<string>Ŝ=new List<string>();foreach(var s
- in Ś){MyFixedPoint l=0;Ľ.Í.TryGetValue(s,out l);if(l>0)ś.Add(s.TypeId.Substring(ŀ.Length)+"/"+s.SubtypeId+"="+l.ToString()
- );else Ŝ.Add(s.TypeId.Substring(ŀ.Length)+"/"+s.SubtypeId+"=0");}ś.Sort();Ŝ.Sort();if(ś.Count==0)ś.AddRange(Ŝ);æ.
- CustomData=String.Join("\n",ś);}if(ISYCOMPAT&&æ.CustomData.IndexOf("Special Container modes:")==-1){æ.CustomData=
- "@Special Container modes:\n- isycompat\n"+æ.CustomData;}Ő=æ.CustomData;Ŏ.Clear();var ì=Ő.Split('\n');foreach(var H in ì){var ŝ=H.Split('=');if(ŝ.Length==2){var Ş
- =ŝ[0].Split('/');if(Ş.Length==2){try{var Ó=ď(ŀ+Ş[0],Ş[1]);if(ŝ[1]=="all"){Ŏ[Ó]=int.MaxValue;}else{var þ=(MyFixedPoint)
- double.Parse(ŝ[1]);if(þ>0){Ŏ[Ó]=þ;}else{}}}catch(Exception){}}}}}}public void š(){ĉ Š=new ĉ();if(!Ō)Š.g(this);if(Ľ==null||!Ľ.Ĭ
- (Š)){if(Ľ!=null)T.Ì.ĩ(Ľ);T.Ì.Ī(Š);Ľ=Š;ij(this.ı).ª();}}public bool Ų(){if(ŋ)return false;int ţ=Ţ;Ť.g(this,null);{
- Dictionary<string,ĭ>ť=new Dictionary<string,ĭ>();List<MyItemType>Ŧ=new List<MyItemType>(Ľ.Í.Keys);foreach(var č in Ŧ){var Ħ=ē(č.
- TypeId);ĭ ŧ=null;if(!ť.ContainsKey(Ħ)){ť[Ħ]=ŧ=Ĺ(this,Ħ);}else ŧ=ť[Ħ];int Ũ=0;while(ŧ!=null&&Ũ<10){MyFixedPoint l=0;Ľ.Í.
- TryGetValue(č,out l);if(l==0)break;MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);l-=ũ;if(l==0)break;Ũ++;var Ū=Ċ[Ħ];U ū=null;foreach(var W
- in ŧ.Ļ){if(W.ļ.Contains(Ħ)&&W.Ľ.Ė>=Ū){ū=W;break;}}if(ū!=null){Ť.g(this,ū);if(l>ū.Ľ.Ė)l=ū.Ľ.Ė;var ŭ=Ŭ(this,ū,č,l,false,true
- );if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return true;if(ŭ>0){Ť.Q("Unable to xfer "+ŭ+" of "+č.SubtypeId);}ŧ.ª();
- if(ū.Ľ.Ė<Ū){ť[Ħ]=ŧ=Ĺ(this,Ħ);}}}if(Ũ==10){Ť.Q("errchk loop abort");}{if(!ļ.Contains(Ħ)&&!Ŋ){MyFixedPoint l=0;if(Ľ.Í.
- TryGetValue(č,out l)&&l>0){MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);if(l>ũ){X(this,č,l-ũ);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>
- MAX_TRANSFER_MS)return true;}}}}}}if(Ŋ){List<MyItemType>Ŧ=new List<MyItemType>(Ŏ.Keys);foreach(var k in Ľ.Í)if(!Ŧ.Contains(k.Key))Ŧ.Add
- (k.Key);foreach(var č in Ŧ){MyFixedPoint ů=0;Ľ.Í.TryGetValue(č,out ů);MyFixedPoint ũ=0;Ŏ.TryGetValue(č,out ũ);if(ũ>ů&&Ľ.Ė
- >(MyFixedPoint)č.GetItemInfo().Volume){MyFixedPoint Ű=0;Ì.Í.TryGetValue(č,out Ű);if(Ű>ů){Ť.g(č.SubtypeId);Ť.Q(æ.
- CustomName+" globalchk "+č.SubtypeId+" pmove "+ũ+" "+ů);var Ē=ű(this,č,ũ-ů);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return
- true;if(Ē>0)Ť.Q("unable to satisfy by "+Ē);}}else if(ũ<ů){Ť.g(č.SubtypeId);Ť.Q("attempt expel "+č.SubtypeId+": "+ũ+" < "+ů+
- " in "+this.æ.CustomName);X(this,č,ů-ũ);if(Ţ-ţ>MAX_TRANSFERS_PER_OP||Ů>MAX_TRANSFER_MS)return true;}}}return Ţ-ţ>0;}}static
- public MyFixedPoint ű(U ū,MyItemType Ó,MyFixedPoint ī){Ť.g(ū,null);Ť.g(Ó.SubtypeId);var ä=Ó.GetItemInfo();int ĵ=U.ľ.IndexOf(ū)
- ;Ť.Q("pidx="+ĵ);Ť.Q("BlockInventory.bPriorityList.Count="+U.ľ.Count);for(var e=U.ľ.Count-1;e>ĵ;e--){var ų=U.ľ[e];Ť.g(ū,ų)
- ;if(ų.Ľ!=null&&ų.Ľ.Í.ContainsKey(Ó)){MyFixedPoint ã=ų.Ľ.Í[Ó];Ť.Q(ų.æ.CustomName+"has item, stock "+ã);MyFixedPoint Ŵ=ã>ī?
- ī:ã;Ť.Q("tamt="+Ŵ);MyFixedPoint ŵ=(ų.Ľ.Ė*(MyFixedPoint)(1/ä.Volume));if(!ä.IsOre&&!ä.IsIngot)ŵ=MyFixedPoint.Floor(ŵ+(
- MyFixedPoint)0.001);if(Ŵ>ŵ)Ŵ=ŵ;Ť.Q("tamt_ma="+Ŵ);var ŭ=Ŭ(ų,ū,Ó,Ŵ);ī-=Ŵ;ī+=ŭ;}if(ī<=0)break;}return ī;}static public MyFixedPoint X(U
- Ŷ,MyItemType č,MyFixedPoint ŷ,bool Ÿ=false){var ä=č.GetItemInfo();var Ź=ē(č.TypeId);Ť.g(č.SubtypeId);for(var e=0;e<U.ľ.
- Count;e++){var ų=U.ľ[e];if(ų!=Ŷ&&!ų.ŋ){Ť.g(Ŷ,ų);MyFixedPoint l=0;MyFixedPoint ŵ=(ų.Ľ.Ė*(MyFixedPoint)(1/ä.Volume));if(!ä.
- IsOre&&!ä.IsIngot)ŵ=MyFixedPoint.Floor(ŵ+(MyFixedPoint)0.001);if(!ų.Ŋ&&(ų.ļ.Contains(Ź)))l=ŵ;else if(ų.Ŋ){MyFixedPoint ź=0;ų.
- Ľ.Í.TryGetValue(č,out ź);MyFixedPoint Ż=0;ų.Ŏ.TryGetValue(č,out Ż);if(Ż>ź){l=Ż-ź;if(l>ŵ)l=ŵ;}}if(l>0){Ť.Q("maxaccept="+ŵ)
- ;Ť.Q("pushing "+l+" to "+ų.æ.CustomName);var ż=Ŭ(Ŷ,ų,č,l,Ÿ,Ÿ);ŷ-=l;ŷ+=ż;}}if(ŷ<=0)break;}if(ŷ>0){StringBuilder Ž=new
- StringBuilder();ž(Ž,"Warning: failed to expel ",č.SubtypeId," from \"",Ŷ.ő,"\": nowhere else to store?");µ.ſ(Ž.ToString());}return ŷ;
- }static public MyFixedPoint Ŭ(U Ŷ,U ū,MyItemType č,MyFixedPoint ŷ,bool ƀ=false,bool Ɓ=false){Ť.g(Ŷ,ū);Ť.g(č.SubtypeId);if
- (ŷ==0)return 0;Ť.Q("transfer_item "+č.SubtypeId+" "+ŷ+" "+Ŷ.ő+" > "+ū.ő);var Ƃ=ŷ;foreach(var ƃ in Ŷ.Ę(ƀ)){foreach(var Ƅ
- in ū.Ę(Ɓ)){ŷ=Ŭ(ƃ,Ƅ,č,ŷ);if(ŷ<=0||ƅ)break;}if(ŷ<=0||ƅ)break;}if(ƅ){ƅ=false;StringBuilder Ž=new StringBuilder();ž(Ž,
- "Warning: xfer fail: no conveyor \"",Ŷ.ő,"\" > \"",ū.ő+"\"");µ.ſ(Ž.ToString());}if(Ƃ!=ŷ){Ŷ.š();ū.š();}return ŷ;}static int Ţ=0,Ɔ=0;static bool ƅ=false;
- static double Ů=0;static public MyFixedPoint Ŭ(IMyInventory Ŷ,IMyInventory ū,MyItemType č,MyFixedPoint ŷ){if(Ɔ!=O){Ɔ=O;Ů=0;}
- DateTime K=DateTime.Now;ƅ=false;List<MyInventoryItem>R=new List<MyInventoryItem>();Ŷ.GetItems(R);foreach(MyInventoryItem Ø in R)
- {if(Ø.Type==č){MyFixedPoint Ŵ=Ø.Amount>ŷ?ŷ:Ø.Amount;Ť.Q("_transfer_item "+č.SubtypeId+" "+Ŵ);var ä=č.GetItemInfo();
- MyFixedPoint ŵ=((ū.MaxVolume-ū.CurrentVolume)*(1f/ä.Volume));if(!ä.UsesFractions)ŵ=MyFixedPoint.Floor(ŵ+(MyFixedPoint)0.001);if(Ŵ>ŵ)
- {Ť.Q("_capping amt to "+ŵ);Ŵ=ŵ;}if(Ŵ>0){Ţ++;if(Ŷ.TransferItemTo(ū,Ø,Ŵ)){ŷ-=Ŵ;Ť.Q("_successfully moved "+Ŵ+" of "+Ø.Type.
- SubtypeId);}else{bool Ƈ=Ŷ.CanTransferItemTo(ū,č);Ť.Q("_failed to move. checkset conveyor flag");if(!Ƈ)ƅ=true;}}}if(ŷ<=0)break;}Ů
- +=(DateTime.Now-K).TotalMilliseconds;return ŷ;}class ƍ{bool ƈ=false;string Ɖ="Nascent.Cargo [1.7].[Barge].AllTypes.P70",Ɗ=
- "",Ƌ="",Ă="";U J=null;U æ=null;public void g(U J,U æ){this.J=J;this.æ=æ;}public void g(string Ø){this.Ă=Ø;}public void Q(
- string ƌ){if(!ƈ)return;bool H=true;if(Ɖ.Length>0&&(J==null||J.ő!=Ɖ))H=false;if(H&&Ɗ.Length>0&&(æ==null||æ.ő!=Ɗ))H=false;if(H&&
- Ƌ.Length>0&&Ă!=Ƌ)H=false;if(H){Program.Q(ƌ);}}}static ƍ Ť=new ƍ();public void Ƒ(List<IMyTerminalBlock>þ){List<
- IMyTerminalBlock>Ĩ=new List<IMyTerminalBlock>();foreach(var æ in Ǝ){if(!þ.Contains(æ))Ĩ.Add(æ);}ĉ Ə=new ĉ();foreach(var æ in Ĩ){U W=U.V(
- æ);T.Ì.ĩ(W.Ľ);}Ǝ.Clear();foreach(var s in þ)if(s.CubeGrid.EntityId!=Ü.Me.EntityId)Ǝ.Add(s);foreach(var s in þ)if(s.
- CubeGrid.EntityId==Ü.Me.EntityId)Ǝ.Add(s);Ɛ();}List<IMyTerminalBlock>Ǝ=new List<IMyTerminalBlock>();int ƒ=0;bool Ɠ=true;public
- bool º=false;public int Ɣ=1,À=0,ƕ=0;static x Ɩ=new x("invu");int Ɨ=0;enum Ɯ{Ƙ,ƙ,ƚ,ƛ}string[]Ɲ={"PREINIT","INIT","PROCESSING"
- ,"IDLE"};Ɯ ƞ=Ɯ.Ƙ;Queue<string>Ɵ=new Queue<string>();int Ơ=0;bool ơ=false;public void ſ(string K){ơ=true;Ɵ.Enqueue(K);if(Ɵ
- .Count>5)Ɵ.Dequeue();Ơ=O;}static x Ƣ=new x("stat");public string ƣ="";public void Ƨ(){Ƣ.K();if(O%5==0){if(ơ&&O-Ơ>10*60){ơ
- =false;Ɵ.Clear();}StringBuilder Ƥ=new StringBuilder();var ƥ=Ɲ[(int)ƞ];if(ƞ>=Ɯ.ƚ&&ƞ!=Ɯ.ƛ){ž(Ƥ,"Working ",ƒ+1,"/",Ǝ.Count,
- "\n");if(ƒ<Ǝ.Count)ž(Ƥ,Ǝ[ƒ].CustomName,"\n");}ž(Ƥ,ƥ,"\n");ž(Ƥ,Ţ+" xfer ops this runtime\n\n");foreach(var H in Ɵ)ž(Ƥ,H,"\n")
- ;var K=Ƥ.ToString();if(K!=ƣ){ƣ=K;if(Ʀ!=null)Ʀ.WriteText(K);}}Ƣ.s();}void ƨ(){Ɠ=false;ƕ=O-À;À=O;ƒ=0;ƞ=Ɯ.ƛ;}void Ɛ(){ƞ=Ɯ.ƙ;
- Ɠ=true;À=O;ƒ=0;}bool Ʃ=false;int ƪ=0,ƫ=0,Ƭ=0;static x ƭ=new x("cdbg");public void ª(){ƭ.K();if(!Ɠ&&(O-À>Ɣ)){Ɛ();if(
- CARGODBG&&Ʈ!=null){StringBuilder Ư=new StringBuilder();foreach(var s in U.ľ){Ư.Append(s.ı+"|||"+s.æ.CustomName+"\n");}Ʈ.
- WriteText(Ư.ToString());}}ƭ.s();Ɩ.K();if(Ɠ){if(ƒ>=Ǝ.Count){ƨ();Q("full run ("+Ǝ.Count+"):"+ƕ+"t ("+(ƕ/60.0d).ToString("0.0")+"s")
- ;º=true;Ɨ+=1;}else{var ư=blockInterval;if(Ʃ)ư=blockIntervalMove;if(O-ƪ>ư){IMyTerminalBlock Ó=Ǝ[ƒ];U W=U.V(Ó);var Ʊ=ƫ;ƫ++;
- if(Ʊ==0)W.š();if(Ʊ==1)W.ş();if(Ʊ==2){if(SORT){Ʃ=W.Ų();Ƭ++;}if(!Ʃ||Ƭ>10){Ƭ=0;ƪ=O;ƫ=0;ƒ++;}else{ƪ=O;ƫ--;}}ƞ=Ɯ.ƚ;}}}Ɩ.s();Ƨ()
- ;}}static string[]Ʋ=new string[]{"missile","ammo","magazine","torpedo","slug","box"};static Dictionary<string,string>Ƴ=
- new Dictionary<string,string>(){{"AngleGrinder","Grinder"},{"CrateTomato","Crate of Tomatoes"},{"HeavyArms",
- "Heavy Armaments"},{"GravityGenerator","Gravity Comp."},{"RadioCommunication","Radio-comm Comp."},{"Detector","Detector Comp."},{
- "LargeTube","Large Steel Tube"},{"Construction","Construction Comp."},{"UltimateAutomatic",""},{"AryxLynxon",""},{"TungstenUranium"
- ,"TU"},{"LeadSteel","LS"},{"EStabilizer","Stabilizer"}};static Dictionary<MyItemType,string>ƴ=new Dictionary<MyItemType,
- string>();public enum ć{Ĉ=0,Ƶ,ƶ}string[]Ʒ={"INFO","_DBG","DDBG"};public static ć Ƹ=ć.Ĉ;public static ƹ ƺ=new ƹ();public static
- void Q(string K,ć ƻ){ƹ.Q(K,ƻ);}public static void Q(string K){ƹ.Q(K,ć.Ĉ);}public class ƹ{public class ƾ{public ƾ(string d,
- string Ƽ,ć H){ƌ=d;ƽ=Ƽ;ƻ=H;}public string ƌ="",ƽ="";public int þ=1;public ć ƻ=ć.Ĉ;}static List<ƾ>ƿ=new List<ƾ>(),ǀ=new List<ƾ>(
- );static int ǁ=50,ǂ=1000;static public bool ǃ=true;public static void Q(string K,ć ƻ){if(ƻ>Ƹ)return;string ß=K;if(K.
- Length>50){List<string>í=new List<string>();while(K.Length>50){int þ=0;if(í.Count>0)þ=2;í.Add(K.Substring(0,50-þ));K=K.
- 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;
- else ƿ.Add(new ƾ(K,ß,ƻ));}else ƿ.Add(new ƾ(K,ß,ƻ));if(ƿ.Count>ǁ)ƿ.RemoveAt(0);H=null;if(ǀ.Count>0){H=ǀ[ǀ.Count-1];}if(H!=
- null){if(H.ƌ==K)H.þ+=1;else ǀ.Add(new ƾ(K,ß,ƻ));}else ǀ.Add(new ƾ(K,ß,ƻ));if(ǀ.Count>ǂ)ǀ.RemoveAt(0);ǃ=true;}static public
- string DŽ="";static public void Dž(){if(!ǃ)return;StringBuilder æ=new StringBuilder();foreach(var d in ƿ){æ.Append(d.ƌ);if(d.þ>1
- )ž(æ," (",d.þ,")");æ.Append("\n");}string Ć=æ.ToString();ǃ=false;DŽ=Ć;}static public void LJ(){StringBuilder æ=new
- StringBuilder();foreach(var d in ǀ){æ.Append(d.ƌ);if(d.þ>1)ž(æ," (",d.þ,")");æ.Append("\n");}string Ć=æ.ToString();dž[0].CustomData=Ć;
- Q(dž[0].CustomName,ć.Ĉ);}}static void ž(StringBuilder æ,params object[]Lj){foreach(object J in Lj){æ.Append(J.ToString());}}
- 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
- ,Ǐ=1,ǐ=int.MinValue,Ǒ=0;DateTime ǒ=DateTime.MinValue;string Ǔ="",ǔ="",Ǖ="";static int ǖ=0;bool Ǘ=true;public int Ǜ(){if(Ǘ
- )return int.MaxValue;int Ǚ=(int)Math.Pow(10,8-(ǘ*2));if(ǚ!=null)return ǚ.Ǜ()+(Ǒ*Ǚ);return Ǒ*Ǚ;}static int ǜ=(int)Math.Pow
- (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(
- ){ǟ();}static List<x>Ǡ=new List<x>();x ǚ=null;int ǘ=0;bool ǡ=false;public void Ǟ(){if(lj){Ǘ=false;if(O!=ǐ){if(Ǐ==1&&ǐ!=int
- .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
- (ǘ>11)ǘ=11;if(Ǡ.Count>0&&ǚ==null)ǚ=Ǡ[Ǡ.Count-1];Ǡ.Add(this);ǒ=DateTime.Now;}}double ǣ=0,Ǥ=0;public double ǟ(){double ǥ=0;
- if(lj){ǥ=(DateTime.Now-ǒ).TotalMilliseconds;}return ǟ(ǥ);}double ǟ(double Ǧ){double ǥ=0;if(lj){ǥ=Ǧ;Ǡ.Pop();if(ǚ!=null){ǘ=ǚ.ǘ
- +1;}if(!ǡ)nj[ǎ]=0;nj[ǎ]+=ǥ;if(!ǡ)ǎ=(ǎ+1)%Nj;Ǥ=0d;foreach(double ǧ in nj)Ǥ+=ǧ;Ǥ*=Ǎ;Ǥ/=Ǐ;ǣ=ǥ;}return ǥ;}public string Ǭ(
- 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
- .Count;e++){x į=NJ[e];į.ǔ="";if(į.ǘ>0&&į.ǚ!=null){bool ǩ=false;bool Ǫ=false;for(int æ=e+1;æ<NJ.Count;æ++){if(NJ[æ].ǘ==į.ǚ.ǘ)
- ǩ=true;if(NJ[æ].ǘ==į.ǘ)Ǫ=true;if(NJ[æ].ǘ<į.ǘ)break;}while(į.ǔ.Length<į.ǚ.ǘ){if(ǩ)į.ǔ+="│";else į.ǔ+=" ";}bool ë=false;if(!Ǫ
- ){if(e<NJ.Count-1){if(NJ[e+1].ǘ!=į.ǘ)ë=true;}else ë=true;}if(ë)į.ǔ+="└";else į.ǔ+="├";while(į.ǔ.Length<į.ǘ)į.ǔ+="─";}}int ǫ
- =0;foreach(x į in NJ)if(į.ǔ.Length+į.Ǔ.Length>ǫ)ǫ=į.ǔ.Length+į.Ǔ.Length;foreach(x į in NJ){į.Ǖ="";int H=į.ǔ.Length+į.Ǔ.
- Length+į.Ǖ.Length;if(H<ǫ)į.Ǖ=new string('_',ǫ-H);}}if(Ǘ)ž(Ǩ,"!!!!",Ǔ,"!!!!: NEVER CALLED!");else ž(Ǩ,ǔ,Ǔ,Ǖ,": ",ǣ.ToString(
- "0.00"),";",Ǥ.ToString("0.00"));}return"";}static public string Ǯ(){StringBuilder æ=new StringBuilder();if(lj){foreach(x ǭ in NJ
- ){ǭ.Ǭ(æ);æ.Append("\n");}}if(Ǡ.Count>0){ž(æ,"profile stack error:\n",Ǡ.Count,"\n");foreach(var K in Ǡ){ž(æ,K.Ǔ,",");}}
- return æ.ToString();}}
- static public Program Ü=null;static public DateTime ǯ;public
- Program(){Ü=this;ǰ=new DZ();ǰ.į=this;ǯ=DateTime.Now;Q(
- "BOOT",ć.Ĉ);Runtime.UpdateFrequency=updateFrequency;}public void
- Save
- (){}public static int O=-1;static x Dz=new x("init"),dz=new x("main");DateTime Ǵ=DateTime.Now;static T µ=null;static Å ǵ=
- null;static L Ƕ=null;public string Ƿ="";public UpdateType Ǹ=UpdateType.Update1;public void
- Main
- (string ǹ,UpdateType Ɛ){Ƿ=ǹ;Ǹ=Ɛ;var ǻ=Ǻ;}static readonly int Ǽ=60;double[]ǽ=new double[Ǽ];double Ǿ=0;int ǿ=0,Ȁ=-1;bool ȁ=
- true;bool ȉ{get{double Ȃ=Runtime.LastRunTimeMs;if(ȁ){int Ȅ=ȃ%Ǽ;Ǿ-=ǽ[Ȅ];ǽ[Ȅ]=Ȃ;Ǿ+=Ȃ;if(ǿ<Ǽ)ǿ++;}if(ȃ<Ȁ)return true;double ȅ=Ǿ
- /ǿ;var Ȇ=maxMsPerSETickReal;if(ȅ>Ȇ){int ȇ=(int)Math.Ceiling((Ǿ/Ȇ)-ǿ);if(ȇ>0){Ȁ=ȃ+ȇ;Ȉ=true;Q(ȅ.ToString("0.00")+"ms > "+Ȇ.
- ToString("0.00")+"ms in tick "+ȃ+"; skipping "+ȇ+"t ("+(((double)ȇ)/60).ToString("0.0")+"s)");}}return false;}}bool Ȉ=false;bool
- Ǻ{get{if(Ǹ==UpdateType.Update1)ȃ++;if(Ȉ){Q("Runtime.LastRunTimeMs="+Runtime.LastRunTimeMs.ToString("0.00"));Ȉ=false;}var
- IJ=(ȃ!=0&&ȉ)?false:Ȋ;if(ȃ%30==0){Echo("t:"+ȃ);if(ȃ<Ȁ){Echo("rt:"+(ȃ-Ȁ));}}return true;}}public static int ȃ=0;public bool
- Ȋ{get{O+=1;if(O%20==0)if(Me.Closed){Runtime.UpdateFrequency=UpdateFrequency.None;return true;}dz.Ǟ();ȋ(Ƿ,Ǹ);dz.ǟ();if(O%5==
- 0){Echo(O.ToString());if(Ȍ!=null)Ȍ.WriteText("name:ms1t:ms60t\n"+x.Ǯ());if(µ!=null){Echo(µ.ƣ);}}if(ȍ!=null&&O%5==0){if(ƹ.
- ǃ){ƹ.Dž();ȍ.WriteText(ƹ.DŽ);}}return true;}}bool Ȏ=true;void ȋ(string ǹ,UpdateType Ɛ){Dz.Ǟ();if(O%10==0){ǰ.ª();}Dz.ǟ();if(ǰ.ȏ
- ){Echo("INITIALIZING: "+ǰ.Ȑ+"/11");if(Ʀ!=null)Ʀ.WriteText("INIT: "+ǰ.Ȑ+"/11");return;}if(Ȏ){Ȏ=false;µ=new T();µ.Ƒ(ȑ);Ƕ=
- new L();ǵ=new Å();Q("Basic structures initialized.");}if(O%connectEventInterval==0)Ȓ();if(ȓ)return;if(Ȕ!=null){Ƕ.ª();}µ.ª()
- ;if(O%60*5==0){if(Ȕ!=null){ȕ.K();var Ȗ=Ȕ.GetText();ǵ.ô(Ȗ);ȕ.s();ȗ.K();var Ć=ǵ.ê();Ȕ.WriteText(Ć);ȗ.s();}}if(ǹ=="clearasm"
- ){foreach(var I in G){I.ClearQueue();}}if(ǹ=="test"){var I=G[0];var c=Å.È.First().Value;List<MyProductionItem>Ș=new List<
- MyProductionItem>();I.GetQueue(Ș);if(Ș.Count==0){I.AddQueueItem(c,(MyFixedPoint)1000);}else{var s=Ș[0];I.InsertQueueItem(0,c,(
- MyFixedPoint)(-500));}}else if(ǹ=="log"){ƹ.LJ();}}static x ȕ=new x("aclcd1"),ȗ=new x("aclcd2");bool ȓ=false;static string ș=
- "No Sorting",Ț="No IIM";class ȡ{bool ț=false;public IMyShipConnector Ȝ=null,ȝ=null;public bool Ȟ=false;public bool Ɛ(){var ȟ=Ȝ.
- Status==MyShipConnectorStatus.Connected;var Ć=Ȝ.OtherConnector;if(ț!=ȟ){ț=ȟ;if(!ȟ)Ć=null;ȝ=Ć;Ȟ=false;if(ȝ!=null){var t=Ȝ.
- CustomName;var Ƞ=ȝ.CustomName;if(t.Contains(ș)||t.Contains(Ț)||Ƞ.Contains(ș)||Ƞ.Contains(Ț)){Ȟ=false;}else Ȟ=true;}return true;}
- else return false;}}Dictionary<IMyShipConnector,ȡ>Ȣ=new Dictionary<IMyShipConnector,ȡ>();Dictionary<IMyCubeGrid,
- IMyShipConnector>ȣ=new Dictionary<IMyCubeGrid,IMyShipConnector>();List<IMyCubeGrid>Ȥ=new List<IMyCubeGrid>();int ǐ=-1;IMyShipConnector ȧ
- (IMyTerminalBlock æ){if(ǐ!=O){ȣ.Clear();Ȥ.Clear();foreach(var þ in ȥ){var Ć=þ.OtherConnector;if(Ć!=null)ȣ[þ.
- OtherConnector.CubeGrid]=þ;}}IMyShipConnector Ȧ=null;ȣ.TryGetValue(æ.CubeGrid,out Ȧ);if(Ȧ!=null)return Ȧ;else{if(!Ȥ.Contains(æ.
- CubeGrid)){foreach(var k in Ȣ){var ī=k.Value;;if(ī.ȝ!=null&&ī.ȝ.CubeGrid==æ.CubeGrid){if(ī.Ȟ)return ȣ[æ.CubeGrid]=ī.Ȝ;else{Ȥ.Add
- (æ.CubeGrid);return null;}}}foreach(var k in Ȣ){var ī=k.Value;;if(ī.ȝ!=null&&ī.Ȟ){if(æ.IsSameConstructAs(ī.ȝ)){return ȣ[æ
- .CubeGrid]=ī.Ȝ;}}}}else return null;}Ȥ.Add(æ.CubeGrid);return null;}public bool ȩ(){bool Ȩ=false;foreach(var þ in ȥ){ȡ ī=
- null;Ȣ.TryGetValue(þ,out ī);if(ī==null){ī=new ȡ();ī.Ȝ=þ;Ȣ[þ]=ī;}Ȩ=ī.Ɛ()||Ȩ;}return Ȩ;}public void Ȯ(){List<IMyTerminalBlock>
- Ȫ=new List<IMyTerminalBlock>();GridTerminalSystem.GetBlocksOfType(Ȫ);ȑ.Clear();List<IMyCubeGrid>ȫ=new List<IMyCubeGrid>()
- ;List<IMyCubeGrid>Ȭ=new List<IMyCubeGrid>();foreach(var æ in Ȫ){if(æ.HasInventory&&æ.HasPlayerAccess(Me.OwnerId)){if(æ.
- CubeGrid==Me.CubeGrid)ȑ.Add(æ);else{if(!Ȭ.Contains(æ.CubeGrid)){if(æ.IsSameConstructAs(Me))ȫ.Add(æ.CubeGrid);else Ȭ.Add(æ.
- CubeGrid);}if(ȫ.Contains(æ.CubeGrid))ȑ.Add(æ);else{var ȭ=ȧ(æ);if(ȭ!=null){ȡ ī=null;Ȣ.TryGetValue(ȭ,out ī);if(ī!=null&&ī.Ȟ){ȑ.Add
- (æ);}}}}}}µ.Ƒ(ȑ);}bool ȯ=false;public void Ȓ(){try{bool Ȩ=ȩ();if(Ȩ){Q("connector change");List<IMyProgrammableBlock>Ȱ=new
- List<IMyProgrammableBlock>();GridTerminalSystem.GetBlocksOfType(Ȱ,æ=>æ!=Me&&æ.HasPlayerAccess(Me.OwnerId)&&æ.CustomData.
- StartsWith("KTZINV")&&æ.IsWorking);bool ȱ=true;if(Ȱ.Count>0){bool Ȳ=Me.CubeGrid.IsStatic;foreach(var þ in Ȱ){if(þ.CubeGrid.
- IsStatic&&!Ȳ){ȱ=false;break;}}if(ȱ){foreach(var þ in Ȱ){if(þ.EntityId<Me.EntityId&&(!Ȳ||þ.CubeGrid.IsStatic)){ȱ=false;break;}}}}
- ȓ=!ȱ;if(ȓ){µ.ƣ="Sleeping while a connected KTZInv runs.";if(Ʀ!=null)Ʀ.WriteText(µ.ƣ);return;}Ȯ();}}catch(Exception s){if(
- !ȯ){ȯ=true;Q("Exception: "+s.ToString());}}}static IMyTextSurface ȍ=null,Ʀ=null,Ȍ=null,Ʈ=null,Ȕ=null;static List<
- IMyAssembler>G=new List<IMyAssembler>();static List<IMyShipController>dž=new List<IMyShipController>();static List<IMyShipConnector>ȥ
- =new List<IMyShipConnector>();static List<IMyTerminalBlock>ȑ=new List<IMyTerminalBlock>();static public ȳ ŗ=null;static
- public DZ ǰ=null;public class DZ{public Program į;public bool ȏ=true;public DZ(){ȴ();}bool ȵ=false;public void ª(){if(ŗ==null){ŗ=
- new ȳ();try{ŗ.ȶ(Ü.Me);}catch(Exception){}}if(!ŗ.ȷ&&O%30==0){try{ŗ.ȶ(Ü.Me);}catch(Exception){}}if(!ŗ.ȷ)return;if(!ȵ||O%60==0
- ){ȵ=true;}if(ȸ!=null){if(!ȸ.MoveNext()){ȸ.Dispose();ȸ=null;}}else if(ȵ&&O%(5*60*60)==0)ȴ();}IEnumerator<bool>ȸ=null;void
- ȴ(){if(ȸ!=null)ȸ.Dispose();ȸ=ȹ();Ȑ=0;}public int Ȑ=0;public bool Ⱥ(IMyTerminalBlock æ){return æ.GetOwnerFactionTag()==į.
- Me.GetOwnerFactionTag()&&æ.CubeGrid==į.Me.CubeGrid;}public IEnumerator<bool>ȹ(){var Ȼ=į.GridTerminalSystem;ȍ=null;Ʀ=null;Ȍ
- =null;List<IMyTerminalBlock>ȼ=new List<IMyTerminalBlock>();Ȼ.GetBlocksOfType(ȼ,æ=>(æ is IMyTextSurface)&&æ.CubeGrid==į.Me
- .CubeGrid);foreach(var æ in ȼ){IMyTextSurface K=æ as IMyTextSurface;if(æ.CustomData.Contains("statusLog"))Ʀ=K;else if(æ.
- CustomData.Contains("consoleLog"))ȍ=K;else if(æ.CustomData.Contains("profileLog"))Ȍ=K;else if(æ.CustomData.Contains("cargodbg"))Ʈ=
- K;else if(æ.CustomName.Contains(AUTOCRAFT_LCD_KEYWORD))Ȕ=K;}Ȑ++;yield return true;Ȼ.GetBlocksOfType(dž,Ⱥ);Ȑ++;yield return
- true;Ȑ++;ȥ.Clear();Ȼ.GetBlocksOfType(ȥ,Ⱥ);yield return true;Ȑ++;if(USE_SKITS)Ȼ.GetBlocksOfType(G,Ⱥ);else Ȼ.GetBlocksOfType(G
- ,æ=>Ⱥ(æ)&&æ.DefinitionDisplayNameText!="Survival Kit");yield return true;Ȑ++;Ȼ.GetBlocksOfType(ȑ,æ=>æ.HasInventory&&æ.
- HasPlayerAccess(į.Me.OwnerId));yield return true;Ȑ++;if(ȏ)Q("BOOT DONE. "+O+"t ("+(((float)O)/60).ToString("0.0")+"s)",ć.Ĉ);ȏ=false;Ȑ++
- ;yield return false;}}
- }
- public class ȳ{public string[]Ƚ=new string[]{"Any","Offense","Utility","Power","Production","Thrust","Jumping",
- "Steering"};Action<ICollection<MyDefinitionId>>J;Func<IMyTerminalBlock,IDictionary<string,int>,bool>æ;Action<IMyTerminalBlock,
- IDictionary<MyDetectedEntityInfo,float>>þ;Func<long,bool>Ⱦ;Func<long,int,MyDetectedEntityInfo>s;Func<IMyTerminalBlock,long,int,bool
- >ȿ;Action<IMyTerminalBlock,bool,bool,int>ɀ;Func<IMyTerminalBlock,bool>Ɂ;Action<IMyTerminalBlock,ICollection<
- MyDetectedEntityInfo>>e;Func<IMyTerminalBlock,ICollection<string>,int,bool>ɂ;Action<IMyTerminalBlock,ICollection<string>,int>Ď;Func<
- IMyTerminalBlock,long,int,Vector3D?>H;Func<IMyTerminalBlock,int,Matrix>d;Func<IMyTerminalBlock,int,Matrix>t;Func<IMyTerminalBlock,long,
- int,MyTuple<bool,Vector3D?>>Ć;Func<IMyTerminalBlock,int,string>į;Action<IMyTerminalBlock,int,string>Ƀ;Func<long,float>Ē;
- Func<IMyTerminalBlock,int,MyDetectedEntityInfo>K;Action<IMyTerminalBlock,long,int>Ó;Func<long,MyTuple<bool,int,int>>Ʉ;Action
- <IMyTerminalBlock,bool,int>ī;Func<IMyTerminalBlock,int,bool,bool,bool>Ʌ;Func<IMyTerminalBlock,int,float>IJ;Func<
- IMyTerminalBlock,int,MyTuple<Vector3D,Vector3D>>ĺ;Func<IMyTerminalBlock,float>Ɇ;public Func<Sandbox.ModAPI.Ingame.IMyTerminalBlock,float
- >ɇ;public bool ȷ=false;IMyTerminalBlock Ɉ=null;public bool ȶ(IMyTerminalBlock Ɉ){this.Ɉ=Ɉ;var ɉ=Ɉ.GetProperty("WcPbAPI")?
- .As<IReadOnlyDictionary<string,Delegate>>().GetValue(Ɉ);if(ɉ==null)throw new Exception("WcPbAPI failed to activate");
- return Ɋ(ɉ);}public bool Ɋ(IReadOnlyDictionary<string,Delegate>ɋ){if(ɋ==null)return false;Ɍ(ɋ,"GetCoreWeapons",ref J);Ɍ(ɋ,
- "GetBlockWeaponMap",ref æ);Ɍ(ɋ,"GetSortedThreats",ref þ);Ɍ(ɋ,"GetObstructions",ref e);Ɍ(ɋ,"HasGridAi",ref Ⱦ);Ɍ(ɋ,"GetAiFocus",ref s);Ɍ(ɋ,
- "SetAiFocus",ref ȿ);Ɍ(ɋ,"HasCoreWeapon",ref Ɂ);Ɍ(ɋ,"GetPredictedTargetPosition",ref H);Ɍ(ɋ,"GetTurretTargetTypes",ref ɂ);Ɍ(ɋ,
- "SetTurretTargetTypes",ref Ď);Ɍ(ɋ,"GetWeaponAzimuthMatrix",ref d);Ɍ(ɋ,"GetWeaponElevationMatrix",ref t);Ɍ(ɋ,"IsTargetAlignedExtended",ref Ć);Ɍ
- (ɋ,"GetActiveAmmo",ref į);Ɍ(ɋ,"SetActiveAmmo",ref Ƀ);Ɍ(ɋ,"GetConstructEffectiveDps",ref Ē);Ɍ(ɋ,"GetWeaponTarget",ref K);Ɍ
- (ɋ,"SetWeaponTarget",ref Ó);Ɍ(ɋ,"GetProjectilesLockedOn",ref Ʉ);Ɍ(ɋ,"FireWeaponOnce",ref ī);Ɍ(ɋ,"ToggleWeaponFire",ref ɀ)
- ;Ɍ(ɋ,"IsWeaponReadyToFire",ref Ʌ);Ɍ(ɋ,"GetMaxWeaponRange",ref IJ);Ɍ(ɋ,"GetWeaponScope",ref ĺ);Ɍ(ɋ,"GetCurrentPower",ref Ɇ)
- ;Ɍ(ɋ,"GetHeatLevel",ref ɇ);ȷ=true;return true;}void Ɍ<ɍ>(IReadOnlyDictionary<string,Delegate>ɋ,string ǝ,ref ɍ Ɏ)where ɍ:
- class{if(ɋ==null){Ɏ=null;return;}Delegate Ĩ;if(!ɋ.TryGetValue(ǝ,out Ĩ))throw new Exception(
- $"{GetType().Name} :: Couldn't find {ǝ} delegate of type {typeof(ɍ)}");Ɏ=Ĩ as ɍ;if(Ɏ==null)throw new Exception(
- $"{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