Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class part
- {
- public string partName;
- public int count;
- public part(string name,int c)
- {
- this.partName = name;
- this.count = c;
- }
- }
- class partList
- {
- public List<part> myParts;
- public partList() {
- myParts = new List<part>();
- myParts.Add(new part("SteelPlate",2000));
- myParts.Add(new part("Construction",500));
- myParts.Add(new part("InteriorPlate",300));
- myParts.Add(new part("Computer",200));
- myParts.Add(new part("Motor",250));
- myParts.Add(new part("SmallTube",400));
- myParts.Add(new part("LargeTube",100));
- myParts.Add(new part("MetalGrid",150));
- myParts.Add(new part("Display",100));
- myParts.Add(new part("BulletproofGlass",100));
- myParts.Add(new part("Thrust",50));
- myParts.Add(new part("Reactor",50));
- myParts.Add(new part("RadioCommunication",10));
- }
- public part getPart(string name) {
- for ( int i = 0; i < myParts.Count ; i++ ) {
- part myPart = myParts[i];
- if ( myPart.partName == name ) { return myPart; }
- }
- return null;
- }
- public void addCount(string name,int count) {
- part myPart = getPart(name);
- if ( myPart != null ) { myPart.count += count; }
- }
- public int getPartCount(string name) {
- part myPart = getPart(name);
- if ( myPart != null ) { return myPart.count; }
- return -1;
- }
- public bool areAllPartsFufilled() {
- for ( int i = 0; i < myParts.Count; i++ ) {
- if ( myParts[i].count > 0 ) { return false; }
- }
- return true;
- }
- }
- void Main(string argument)
- {
- // IMyTextPanel tPanel = GridTerminalSystem.GetBlockWithName("Metal-Panel") as IMyTextPanel;
- IMyCargoContainer bCargo = GridTerminalSystem.GetBlockWithName("Cargo - Builder") as IMyCargoContainer;
- if ( bCargo == null ) {
- Echo("No Build Ship Found");
- return;
- }
- else { Echo("Found ship."); }
- partList parts = new partList();
- IMyInventory cargoInv = bCargo.GetInventory(0);
- List<IMyInventoryItem> cItems = new List<IMyInventoryItem>();
- cItems = cargoInv.GetItems();
- for ( int i = 0; i < cItems.Count; i++ ) {
- IMyInventoryItem item = cItems[i];
- int decreaser = 0 - (int)item.Amount;
- parts.addCount(item.Content.SubtypeName, decreaser);
- }
- if ( parts.areAllPartsFufilled() ) { return; }
- List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocks(containers);
- for ( int i = 0; i < containers.Count; i++ ) {
- if ( !( containers[i] is IMyAssembler ) && !(containers[i] is IMyCargoContainer) ) { continue; }
- if ( containers[i] == bCargo ) { continue; }
- if ( !containers[i].IsFunctional ) { continue; }
- IMyInventory inventory;
- if ( containers[i] is IMyAssembler ) { inventory = containers[i].GetInventory(1); }
- else { inventory = containers[i].GetInventory(0); }
- //Echo("Checking: " + containers[i].CustomName);
- if ( inventory != null ) {
- //if ( !cargoInv.IsConnected(inventory) ) { continue; } BOOOOOOO
- List<IMyInventoryItem> items = new List<IMyInventoryItem>();
- items = inventory.GetItems();
- if ( items == null ) { Echo("Bad item list"); continue; }
- for ( int i2 = items.Count-1; i2 >= 0; i2-- ) {
- IMyInventoryItem item = items[i2];
- if ( item == null ) { Echo("Bad item in slot " + i2.ToString()); continue; }
- part iPart = parts.getPart(item.Content.SubtypeName);
- if ( iPart != null && iPart.count >= 0 ) {
- int cAmount = (int)item.Amount;
- int toRemove = Math.Min(cAmount,iPart.count);
- iPart.count -= toRemove;
- //Echo("Pulling " + toRemove.ToString() + " " + item.Content.SubtypeName + " from " + containers[i].CustomName);
- //if ( cargoInv.TransferItemFrom(inventory,i2,null,null,(VRage.MyFixedPoint)toRemove) ) { return; }
- cargoInv.TransferItemFrom(inventory,i2,null,null,(VRage.MyFixedPoint)toRemove);
- //i2--;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement